X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/8ab4a4532479e8db471032b51042ec8c4716d091..e3ff8f35458a959c1879c0a4976701ed8dcfe651:/wp-admin/custom-background.php diff --git a/wp-admin/custom-background.php b/wp-admin/custom-background.php index fc320f9f..bea4084c 100644 --- a/wp-admin/custom-background.php +++ b/wp-admin/custom-background.php @@ -18,7 +18,7 @@ class Custom_Background { /** * Callback for administration header. * - * @var callback + * @var callable * @since 3.0.0 */ public $admin_header_callback; @@ -26,12 +26,16 @@ class Custom_Background { /** * 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 + * @access private * @var bool */ private $updated; @@ -40,8 +44,8 @@ class Custom_Background { * 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 +97,8 @@ class Custom_Background { 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 +112,6 @@ class Custom_Background { * @since 3.0.0 */ public function take_action() { - if ( empty($_POST) ) return; @@ -130,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 - $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-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-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-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-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 ); + } + + 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 +222,7 @@ class Custom_Background { public function admin_page() { ?>
-

+

@@ -216,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;"; } ?>
@@ -239,7 +291,7 @@ class Custom_Background {
-
+
@@ -253,13 +305,14 @@ class Custom_Background {
-
+
+
@@ -268,7 +321,7 @@ class Custom_Background { - +


@@ -279,53 +332,85 @@ class Custom_Background {

+ -

+

+ + + array( 'label' => __( 'Top Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), + 'center top' => array( 'label' => __( 'Top' ), 'icon' => 'dashicons dashicons-arrow-up-alt' ), + 'right top' => array( 'label' => __( 'Top Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), + ), + array( + 'left center' => array( 'label' => __( 'Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), + 'center center' => array( 'label' => __( 'Center' ), 'icon' => 'background-position-center-icon' ), + 'right center' => array( 'label' => __( 'Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), + ), + array( + 'left bottom' => array( 'label' => __( 'Bottom Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), + 'center bottom' => array( 'label' => __( 'Bottom' ), 'icon' => 'dashicons dashicons-arrow-down-alt' ), + 'right bottom' => array( 'label' => __( 'Bottom Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), + ), +); +?> + + + + + - - + - - + - - + @@ -337,7 +422,7 @@ $default_color = ''; if ( current_theme_supports( 'custom-background', 'default-color' ) ) $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"'; ?> - /> +> @@ -357,7 +442,6 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) ) * @since 3.0.0 */ public function handle_upload() { - if ( empty($_FILES) ) return; @@ -406,7 +490,7 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) ) } /** - * AJAX handler for adding custom background context to an attachment. + * Ajax handler for adding custom background context to an attachment. * * Triggered when the user adds a new background image from the * Media Manager. @@ -434,6 +518,9 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) ) * * @since 3.4.0 * @deprecated 3.5.0 + * + * @param array $form_fields + * @return array $form_fields */ public function attachment_fields_to_edit( $form_fields ) { return $form_fields; @@ -443,6 +530,9 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) ) * * @since 3.4.0 * @deprecated 3.5.0 + * + * @param array $tabs + * @return array $tabs */ public function filter_upload_tabs( $tabs ) { return $tabs;
+
+ +
+ $input ) : ?> + + +
+ +
+
- - - +
+
- - - - +
+ +
- - +
+ +