diff --git a/src/wp-admin/css/customize-controls.css b/src/wp-admin/css/customize-controls.css index adbd862be8..f2fbc86ef4 100644 --- a/src/wp-admin/css/customize-controls.css +++ b/src/wp-admin/css/customize-controls.css @@ -1090,6 +1090,11 @@ p.customize-section-description { float: right; } +/* Background position control */ +.customize-control-background_position .background-position-control .button-group { + display: block; +} + /** * Custom CSS Section * diff --git a/src/wp-admin/css/themes.css b/src/wp-admin/css/themes.css index 885f3a0755..42721d2bee 100644 --- a/src/wp-admin/css/themes.css +++ b/src/wp-admin/css/themes.css @@ -1176,6 +1176,135 @@ div#custom-background-image img { max-height: 300px; } +.background-position-control input[type="radio"]:checked ~ .button { + background: #eee; + border-color: #999; + -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, .5 ); + box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, .5 ); + z-index: 1; +} + +.background-position-control input[type="radio"]:focus ~ .button { + border-color: #5b9dd9; + -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, .5 ), 0 0 3px rgba( 0, 115, 170, .8 ); + box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, .5 ), 0 0 3px rgba( 0, 115, 170, .8 ); + color: #23282d; +} + +.background-position-control .background-position-center-icon, +.background-position-control .background-position-center-icon:before { + display: inline-block; + line-height: 1; + text-align: center; + -webkit-transition: background-color .1s ease-in 0; + transition: background-color .1s ease-in 0; +} + +.background-position-control .background-position-center-icon { + height: 20px; + margin-top: 13px; + vertical-align: top; + width: 20px; +} + +.background-position-control .background-position-center-icon:before { + background-color: #555; + -webkit-border-radius: 50%; + border-radius: 50%; + content: ""; + height: 12px; + width: 12px; +} + +.background-position-control .button:hover .background-position-center-icon:before, +.background-position-control input[type="radio"]:focus ~ .button .background-position-center-icon:before { + background-color: #23282d; +} + +.background-position-control .button-group { + display: block; +} + +.background-position-control .button-group .button { + -webkit-border-radius: 0; + border-radius: 0; + -webkit-box-shadow: none; + box-shadow: none; + /* Following properties are overridden by buttons responsive styles (see: wp-includes/css/buttons.css). */ + height: 40px !important; + line-height: 37px !important; + margin: 0 -1px 0 0 !important; + padding: 0 10px 1px !important; + position: relative; +} + +.background-position-control .button-group .button:active, +.background-position-control .button-group .button:hover, +.background-position-control .button-group .button:focus { + z-index: 1; +} + +.background-position-control .button-group:last-child .button { + -webkit-box-shadow: 0 1px 0 #ccc; + box-shadow: 0 1px 0 #ccc; +} + +.background-position-control .button-group > label { + margin: 0 !important; +} + +.background-position-control .button-group:first-child > label:first-child .button { + -webkit-border-radius: 3px 0 0; + border-radius: 3px 0 0; +} + +.background-position-control .button-group:first-child > label:first-child .dashicons { + -webkit-transform: rotate( 45deg ); + -ms-transform: rotate( 45deg ); + transform: rotate( 45deg ); +} + +.background-position-control .button-group:first-child > label:last-child .button { + -webkit-border-radius: 0 3px 0 0; + border-radius: 0 3px 0 0; +} + +.background-position-control .button-group:first-child > label:last-child .dashicons { + -webkit-transform: rotate( -45deg ); + -ms-transform: rotate( -45deg ); + transform: rotate( -45deg ); +} + +.background-position-control .button-group:last-child > label:first-child .button { + -webkit-border-radius: 0 0 0 3px; + border-radius: 0 0 0 3px; +} + +.background-position-control .button-group:last-child > label:first-child .dashicons { + -webkit-transform: rotate( -45deg ); + -ms-transform: rotate( -45deg ); + transform: rotate( -45deg ); +} + +.background-position-control .button-group:last-child > label:last-child .button { + -webkit-border-radius: 0 0 3px 0; + border-radius: 0 0 3px 0; +} + +.background-position-control .button-group:last-child > label:last-child .dashicons { + -webkit-transform: rotate( 45deg ); + -ms-transform: rotate( 45deg ); + transform: rotate( 45deg ); +} + +.background-position-control .button-group .dashicons { + margin-top: 9px; +} + +.background-position-control .button-group + .button-group { + margin-top: -1px; +} + /*------------------------------------------------------------------------------ 23.0 - Full Overlay w/ Sidebar ------------------------------------------------------------------------------*/ diff --git a/src/wp-admin/custom-background.php b/src/wp-admin/custom-background.php index a2dcfa8964..bea4084c30 100644 --- a/src/wp-admin/custom-background.php +++ b/src/wp-admin/custom-background.php @@ -133,31 +133,73 @@ class Custom_Background { return; } - if ( isset($_POST['background-repeat']) ) { - check_admin_referer('custom-background'); - if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) ) - $repeat = $_POST['background-repeat']; - else + if ( isset( $_POST['background-preset'] ) ) { + check_admin_referer( 'custom-background' ); + + if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) { + $preset = $_POST['background-preset']; + } else { + $preset = 'default'; + } + + set_theme_mod( 'background_preset', $preset ); + } + + if ( isset( $_POST['background-position'] ) ) { + check_admin_referer( 'custom-background' ); + + $position = explode( ' ', $_POST['background-position'] ); + + if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) { + $position_x = $position[0]; + } else { + $position_x = 'left'; + } + + if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) { + $position_y = $position[1]; + } else { + $position_y = 'top'; + } + + set_theme_mod( 'background_position_x', $position_x ); + set_theme_mod( 'background_position_y', $position_y ); + } + + if ( isset( $_POST['background-size'] ) ) { + check_admin_referer( 'custom-background' ); + + if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) { + $size = $_POST['background-size']; + } else { + $size = 'auto'; + } + + set_theme_mod( 'background_size', $size ); + } + + if ( isset( $_POST['background-repeat'] ) ) { + check_admin_referer( 'custom-background' ); + + $repeat = $_POST['background-repeat']; + + if ( 'no-repeat' !== $repeat ) { $repeat = 'repeat'; - set_theme_mod('background_repeat', $repeat); + } + + set_theme_mod( 'background_repeat', $repeat ); } - if ( isset($_POST['background-position-x']) ) { - check_admin_referer('custom-background'); - if ( in_array($_POST['background-position-x'], array('center', 'right', 'left')) ) - $position = $_POST['background-position-x']; - else - $position = 'left'; - set_theme_mod('background_position_x', $position); - } + if ( isset( $_POST['background-attachment'] ) ) { + check_admin_referer( 'custom-background' ); - if ( isset($_POST['background-attachment']) ) { - check_admin_referer('custom-background'); - if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) ) - $attachment = $_POST['background-attachment']; - else - $attachment = 'fixed'; - set_theme_mod('background_attachment', $attachment); + $attachment = $_POST['background-attachment']; + + if ( 'fixed' !== $attachment ) { + $attachment = 'scroll'; + } + + set_theme_mod( 'background_attachment', $attachment ); } if ( isset($_POST['background-color']) ) { @@ -219,11 +261,18 @@ class Custom_Background { $background_image_thumb = get_background_image(); if ( $background_image_thumb ) { $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); + $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); + $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); + $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); + $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); + $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); // Background-image URL must be single quote, see below. - $background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');' - . ' background-repeat: ' . get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) . ';' - . ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); + $background_styles .= " background-image: url('$background_image_thumb');" + . " background-size: $background_size;" + . " background-position: $background_position_x $background_position_y;" + . " background-repeat: $background_repeat;" + . " background-attachment: $background_attachment;"; } ?>