diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-admin/custom-background.php --- a/wp/wp-admin/custom-background.php Tue Jun 09 11:14:17 2015 +0000 +++ b/wp/wp-admin/custom-background.php Mon Oct 14 17:39:30 2019 +0200 @@ -10,15 +10,13 @@ * The custom background class. * * @since 3.0.0 - * @package WordPress - * @subpackage Administration */ class Custom_Background { /** * Callback for administration header. * - * @var callback + * @var callable * @since 3.0.0 */ public $admin_header_callback; @@ -26,12 +24,15 @@ /** * Callback for header div. * - * @var callback + * @var callable * @since 3.0.0 */ public $admin_image_div_callback; /** + * Used to trigger a success message when settings updated and set to true. + * + * @since 3.0.0 * @var bool */ private $updated; @@ -40,8 +41,8 @@ * Constructor - Register administration header callback. * * @since 3.0.0 - * @param callback $admin_header_callback - * @param callback $admin_image_div_callback Optional custom image div output callback. + * @param callable $admin_header_callback + * @param callable $admin_image_div_callback Optional custom image div output callback. */ public function __construct($admin_header_callback = '', $admin_image_div_callback = '') { $this->admin_header_callback = $admin_header_callback; @@ -93,8 +94,8 @@ get_current_screen()->set_help_sidebar( '
' . __( 'For more information:' ) . '
' . - '' . __( 'Documentation on Custom Background' ) . '
' . - '' . __( 'Support Forums' ) . '
' + '' . __( 'Documentation on Custom Background' ) . '
' . + '' . __( 'Support Forums' ) . '
' ); wp_enqueue_media(); @@ -108,7 +109,6 @@ * @since 3.0.0 */ public function take_action() { - if ( empty($_POST) ) return; @@ -130,31 +130,73 @@ 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 - $repeat = 'repeat'; - set_theme_mod('background_repeat', $repeat); + 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-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-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-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); + 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 ); + } + + if ( isset( $_POST['background-attachment'] ) ) { + check_admin_referer( 'custom-background' ); + + $attachment = $_POST['background-attachment']; + + if ( 'fixed' !== $attachment ) { + $attachment = 'scroll'; + } + + set_theme_mod( 'background_attachment', $attachment ); } if ( isset($_POST['background-color']) ) { @@ -177,7 +219,7 @@ public function admin_page() { ?>