Update WP and plugins

This commit is contained in:
Oliver Davies 2019-04-16 20:56:22 +01:00
parent 10a4713229
commit 1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions

View file

@ -26,10 +26,14 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
*/
public function __construct( $manager ) {
parent::__construct( $manager, 'background_image', array(
'label' => __( 'Background Image' ),
'section' => 'background_image',
) );
parent::__construct(
$manager,
'background_image',
array(
'label' => __( 'Background Image' ),
'section' => 'background_image',
)
);
}
/**
@ -41,11 +45,15 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
parent::enqueue();
$custom_background = get_theme_support( 'custom-background' );
wp_localize_script( 'customize-controls', '_wpCustomizeBackground', array(
'defaults' => ! empty( $custom_background[0] ) ? $custom_background[0] : array(),
'nonces' => array(
'add' => wp_create_nonce( 'background-add' ),
),
) );
wp_localize_script(
'customize-controls',
'_wpCustomizeBackground',
array(
'defaults' => ! empty( $custom_background[0] ) ? $custom_background[0] : array(),
'nonces' => array(
'add' => wp_create_nonce( 'background-add' ),
),
)
);
}
}

View file

@ -39,19 +39,46 @@ class WP_Customize_Background_Position_Control extends WP_Customize_Control {
public function content_template() {
$options = array(
array(
'left top' => 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' ),
'left top' => 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' ),
'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' ),
'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',
),
),
);
?>

View file

@ -47,16 +47,18 @@ class WP_Customize_Code_Editor_Control extends WP_Customize_Control {
* @since 4.9.0
*/
public function enqueue() {
$this->editor_settings = wp_enqueue_code_editor( array_merge(
array(
'type' => $this->code_type,
'codemirror' => array(
'indentUnit' => 2,
'tabSize' => 2,
$this->editor_settings = wp_enqueue_code_editor(
array_merge(
array(
'type' => $this->code_type,
'codemirror' => array(
'indentUnit' => 2,
'tabSize' => 2,
),
),
),
$this->editor_settings
) );
$this->editor_settings
)
);
}
/**
@ -68,9 +70,9 @@ class WP_Customize_Code_Editor_Control extends WP_Customize_Control {
* @return array Array of parameters passed to the JavaScript.
*/
public function json() {
$json = parent::json();
$json = parent::json();
$json['editor_settings'] = $this->editor_settings;
$json['input_attrs'] = $this->input_attrs;
$json['input_attrs'] = $this->input_attrs;
return $json;
}

View file

@ -48,7 +48,7 @@ class WP_Customize_Color_Control extends WP_Customize_Control {
* @param array $args Optional. Arguments to override class property defaults.
*/
public function __construct( $manager, $id, $args = array() ) {
$this->statuses = array( '' => __('Default') );
$this->statuses = array( '' => __( 'Default' ) );
parent::__construct( $manager, $id, $args );
}
@ -70,9 +70,9 @@ class WP_Customize_Color_Control extends WP_Customize_Control {
*/
public function to_json() {
parent::to_json();
$this->json['statuses'] = $this->statuses;
$this->json['statuses'] = $this->statuses;
$this->json['defaultValue'] = $this->setting->default;
$this->json['mode'] = $this->mode;
$this->json['mode'] = $this->mode;
}
/**
@ -111,7 +111,7 @@ class WP_Customize_Color_Control extends WP_Customize_Control {
<input class="color-picker-hue" type="text" data-type="hue" />
<# } else { #>
<input class="color-picker-hex" type="text" maxlength="7" placeholder="{{ defaultValue }}" {{ defaultValueAttr }} />
<# } #>
<# } #>
</label>
</div>
<?php

View file

@ -127,8 +127,8 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
}
}
$id_base = $this->id_data['base'];
$value = '';
$post = wp_get_custom_css_post( $this->stylesheet );
$value = '';
$post = wp_get_custom_css_post( $this->stylesheet );
if ( $post ) {
$value = $post->post_content;
}
@ -161,7 +161,7 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
$validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) );
}
if ( empty( $validity->errors ) ) {
if ( ! $validity->has_errors() ) {
$validity = parent::validate( $css );
}
return $validity;
@ -180,9 +180,12 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
$css = '';
}
$r = wp_update_custom_css_post( $css, array(
'stylesheet' => $this->stylesheet,
) );
$r = wp_update_custom_css_post(
$css,
array(
'stylesheet' => $this->stylesheet,
)
);
if ( $r instanceof WP_Error ) {
return false;

View file

@ -81,11 +81,11 @@ class WP_Customize_Date_Time_Control extends WP_Customize_Control {
public function json() {
$data = parent::json();
$data['maxYear'] = intval( $this->max_year );
$data['minYear'] = intval( $this->min_year );
$data['allowPastDate'] = (bool) $this->allow_past_date;
$data['maxYear'] = intval( $this->max_year );
$data['minYear'] = intval( $this->min_year );
$data['allowPastDate'] = (bool) $this->allow_past_date;
$data['twelveHourFormat'] = (bool) $this->twelve_hour_format;
$data['includeTime'] = (bool) $this->include_time;
$data['includeTime'] = (bool) $this->include_time;
return $data;
}
@ -96,7 +96,7 @@ class WP_Customize_Date_Time_Control extends WP_Customize_Control {
* @since 4.9.0
*/
public function content_template() {
$data = array_merge( $this->json(), $this->get_month_choices() );
$data = array_merge( $this->json(), $this->get_month_choices() );
$timezone_info = $this->get_timezone_info();
$date_format = get_option( 'date_format' );
@ -189,6 +189,8 @@ class WP_Customize_Date_Time_Control extends WP_Customize_Control {
* @since 4.9.0
* @see touch_time()
*
* @global WP_Locale $wp_locale
*
* @return array
*/
public function get_month_choices() {
@ -198,7 +200,7 @@ class WP_Customize_Date_Time_Control extends WP_Customize_Control {
$month_text = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
/* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
$months[ $i ]['text'] = sprintf( __( '%1$s-%2$s' ), $i, $month_text );
$months[ $i ]['text'] = sprintf( __( '%1$s-%2$s' ), $i, $month_text );
$months[ $i ]['value'] = $i;
}
return array(
@ -214,7 +216,7 @@ class WP_Customize_Date_Time_Control extends WP_Customize_Control {
* @return array abbr and description.
*/
public function get_timezone_info() {
$tz_string = get_option( 'timezone_string' );
$tz_string = get_option( 'timezone_string' );
$timezone_info = array();
if ( $tz_string ) {
@ -225,9 +227,9 @@ class WP_Customize_Date_Time_Control extends WP_Customize_Control {
}
if ( $tz ) {
$now = new DateTime( 'now', $tz );
$formatted_gmt_offset = sprintf( 'UTC%s', $this->format_gmt_offset( $tz->getOffset( $now ) / 3600 ) );
$tz_name = str_replace( '_', ' ', $tz->getName() );
$now = new DateTime( 'now', $tz );
$formatted_gmt_offset = sprintf( 'UTC%s', $this->format_gmt_offset( $tz->getOffset( $now ) / 3600 ) );
$tz_name = str_replace( '_', ' ', $tz->getName() );
$timezone_info['abbr'] = $now->format( 'T' );
/* translators: 1: timezone name, 2: timezone abbreviation, 3: gmt offset */
@ -236,7 +238,7 @@ class WP_Customize_Date_Time_Control extends WP_Customize_Control {
$timezone_info['description'] = '';
}
} else {
$formatted_gmt_offset = $this->format_gmt_offset( intval( get_option( 'gmt_offset', 0 ) ) );
$formatted_gmt_offset = $this->format_gmt_offset( intval( get_option( 'gmt_offset', 0 ) ) );
$timezone_info['abbr'] = sprintf( 'UTC%s', $formatted_gmt_offset );
/* translators: %s: UTC offset */

View file

@ -15,8 +15,28 @@
* @see WP_Customize_Image_Control
*/
class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
/**
* Customize control type.
*
* @since 4.2.0
* @var string
*/
public $type = 'header';
/**
* Uploaded header images.
*
* @since 3.9.0
* @var string
*/
public $uploaded_headers;
/**
* Default header images.
*
* @since 3.9.0
* @var string
*/
public $default_headers;
/**
@ -27,16 +47,20 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
*/
public function __construct( $manager ) {
parent::__construct( $manager, 'header_image', array(
'label' => __( 'Header Image' ),
'settings' => array(
'default' => 'header_image',
'data' => 'header_image_data',
),
'section' => 'header_image',
'removed' => 'remove-header',
'get_url' => 'get_header_image',
) );
parent::__construct(
$manager,
'header_image',
array(
'label' => __( 'Header Image' ),
'settings' => array(
'default' => 'header_image',
'data' => 'header_image_data',
),
'section' => 'header_image',
'removed' => 'remove-header',
'get_url' => 'get_header_image',
)
);
}
@ -48,27 +72,30 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
$this->prepare_control();
wp_localize_script( 'customize-views', '_wpCustomizeHeader', array(
'data' => array(
'width' => absint( get_theme_support( 'custom-header', 'width' ) ),
'height' => absint( get_theme_support( 'custom-header', 'height' ) ),
'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),
'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),
'currentImgSrc' => $this->get_current_image_src(),
),
'nonces' => array(
'add' => wp_create_nonce( 'header-add' ),
'remove' => wp_create_nonce( 'header-remove' ),
),
'uploads' => $this->uploaded_headers,
'defaults' => $this->default_headers
) );
wp_localize_script(
'customize-views',
'_wpCustomizeHeader',
array(
'data' => array(
'width' => absint( get_theme_support( 'custom-header', 'width' ) ),
'height' => absint( get_theme_support( 'custom-header', 'height' ) ),
'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),
'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),
'currentImgSrc' => $this->get_current_image_src(),
),
'nonces' => array(
'add' => wp_create_nonce( 'header-add' ),
'remove' => wp_create_nonce( 'header-remove' ),
),
'uploads' => $this->uploaded_headers,
'defaults' => $this->default_headers,
)
);
parent::enqueue();
}
/**
*
* @global Custom_Image_Header $custom_image_header
*/
public function prepare_control() {
@ -81,7 +108,7 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
// Process default headers and uploaded headers.
$custom_image_header->process_default_headers();
$this->default_headers = $custom_image_header->get_default_header_images();
$this->default_headers = $custom_image_header->get_default_header_images();
$this->uploaded_headers = $custom_image_header->get_uploaded_header_images();
}
@ -160,31 +187,36 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
*/
public function render_content() {
$visibility = $this->get_current_image_src() ? '' : ' style="display:none" ';
$width = absint( get_theme_support( 'custom-header', 'width' ) );
$height = absint( get_theme_support( 'custom-header', 'height' ) );
$width = absint( get_theme_support( 'custom-header', 'width' ) );
$height = absint( get_theme_support( 'custom-header', 'height' ) );
?>
<div class="customize-control-content">
<?php if ( current_theme_supports( 'custom-header', 'video' ) ) {
<?php
if ( current_theme_supports( 'custom-header', 'video' ) ) {
echo '<span class="customize-control-title">' . $this->label . '</span>';
} ?>
}
?>
<div class="customize-control-notifications-container"></div>
<p class="customizer-section-intro customize-control-description">
<?php
if ( current_theme_supports( 'custom-header', 'video' ) ) {
_e( 'Click &#8220;Add new image&#8221; to upload an image file from your computer. Your theme works best with an image that matches the size of your video &#8212; you&#8217;ll be able to crop your image once you upload it for a perfect fit.' );
} elseif ( $width && $height ) {
/* translators: %s: header size in pixels */
printf( __( 'Click &#8220;Add new image&#8221; to upload an image file from your computer. Your theme works best with an image with a header size of %s pixels &#8212; you&#8217;ll be able to crop your image once you upload it for a perfect fit.' ),
printf(
/* translators: %s: header size in pixels */
__( 'Click &#8220;Add new image&#8221; to upload an image file from your computer. Your theme works best with an image with a header size of %s pixels &#8212; you&#8217;ll be able to crop your image once you upload it for a perfect fit.' ),
sprintf( '<strong>%s &times; %s</strong>', $width, $height )
);
} elseif ( $width ) {
/* translators: %s: header width in pixels */
printf( __( 'Click &#8220;Add new image&#8221; to upload an image file from your computer. Your theme works best with an image with a header width of %s pixels &#8212; you&#8217;ll be able to crop your image once you upload it for a perfect fit.' ),
printf(
/* translators: %s: header width in pixels */
__( 'Click &#8220;Add new image&#8221; to upload an image file from your computer. Your theme works best with an image with a header width of %s pixels &#8212; you&#8217;ll be able to crop your image once you upload it for a perfect fit.' ),
sprintf( '<strong>%s</strong>', $width )
);
} else {
/* translators: %s: header height in pixels */
printf( __( 'Click &#8220;Add new image&#8221; to upload an image file from your computer. Your theme works best with an image with a header height of %s pixels &#8212; you&#8217;ll be able to crop your image once you upload it for a perfect fit.' ),
printf(
/* translators: %s: header height in pixels */
__( 'Click &#8220;Add new image&#8221; to upload an image file from your computer. Your theme works best with an image with a header height of %s pixels &#8212; you&#8217;ll be able to crop your image once you upload it for a perfect fit.' ),
sprintf( '<strong>%s</strong>', $height )
);
}
@ -200,7 +232,7 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
</div>
</div>
<div class="actions">
<?php if ( current_user_can( 'upload_files' ) ): ?>
<?php if ( current_user_can( 'upload_files' ) ) : ?>
<button type="button"<?php echo $visibility; ?> class="button remove" aria-label="<?php esc_attr_e( 'Hide header image' ); ?>"><?php _e( 'Hide image' ); ?></button>
<button type="button" class="button new" id="header_image-button" aria-label="<?php esc_attr_e( 'Add new header image' ); ?>"><?php _e( 'Add new image' ); ?></button>
<?php endif; ?>

View file

@ -32,20 +32,22 @@ final class WP_Customize_Header_Image_Setting extends WP_Customize_Setting {
// If _custom_header_background_just_in_time() fails to initialize $custom_image_header when not is_admin().
if ( empty( $custom_image_header ) ) {
require_once( ABSPATH . 'wp-admin/custom-header.php' );
$args = get_theme_support( 'custom-header' );
$admin_head_callback = isset( $args[0]['admin-head-callback'] ) ? $args[0]['admin-head-callback'] : null;
$args = get_theme_support( 'custom-header' );
$admin_head_callback = isset( $args[0]['admin-head-callback'] ) ? $args[0]['admin-head-callback'] : null;
$admin_preview_callback = isset( $args[0]['admin-preview-callback'] ) ? $args[0]['admin-preview-callback'] : null;
$custom_image_header = new Custom_Image_Header( $admin_head_callback, $admin_preview_callback );
$custom_image_header = new Custom_Image_Header( $admin_head_callback, $admin_preview_callback );
}
// If the value doesn't exist (removed or random),
// use the header_image value.
if ( ! $value )
$value = $this->manager->get_setting('header_image')->post_value();
if ( ! $value ) {
$value = $this->manager->get_setting( 'header_image' )->post_value();
}
if ( is_array( $value ) && isset( $value['choice'] ) )
if ( is_array( $value ) && isset( $value['choice'] ) ) {
$custom_image_header->set_header_image( $value['choice'] );
else
} else {
$custom_image_header->set_header_image( $value );
}
}
}

View file

@ -15,7 +15,7 @@
* @see WP_Customize_Upload_Control
*/
class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
public $type = 'image';
public $type = 'image';
public $mime_type = 'image';
/**
@ -34,7 +34,7 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
*/
public function add_tab( $id, $label, $callback ) {
_deprecated_function( __METHOD__, '4.1.0' );
}
}
/**
* @since 3.4.0
@ -44,7 +44,7 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
*/
public function remove_tab( $id ) {
_deprecated_function( __METHOD__, '4.1.0' );
}
}
/**
* @since 3.4.0
@ -55,5 +55,5 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
*/
public function print_tab_image( $url, $thumbnail_url = null ) {
_deprecated_function( __METHOD__, '4.1.0' );
}
}
}

View file

@ -75,10 +75,10 @@ class WP_Customize_Media_Control extends WP_Customize_Control {
*/
public function to_json() {
parent::to_json();
$this->json['label'] = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) );
$this->json['mime_type'] = $this->mime_type;
$this->json['label'] = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) );
$this->json['mime_type'] = $this->mime_type;
$this->json['button_labels'] = $this->button_labels;
$this->json['canUpload'] = current_user_can( 'upload_files' );
$this->json['canUpload'] = current_user_can( 'upload_files' );
$value = $this->value();
@ -86,12 +86,12 @@ class WP_Customize_Media_Control extends WP_Customize_Control {
if ( $this->setting->default ) {
// Fake an attachment model - needs all fields used by template.
// Note that the default value must be a URL, NOT an attachment ID.
$type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
$type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
$default_attachment = array(
'id' => 1,
'url' => $this->setting->default,
'type' => $type,
'icon' => wp_mime_type_icon( $type ),
'id' => 1,
'url' => $this->setting->default,
'type' => $type,
'icon' => wp_mime_type_icon( $type ),
'title' => basename( $this->setting->default ),
);

View file

@ -67,14 +67,18 @@ class WP_Customize_Nav_Menu_Item_Control extends WP_Customize_Control {
<span class="menu-item-title<# if ( ! data.title && ! data.original_title ) { #> no-title<# } #>">{{ data.title || data.original_title || wp.customize.Menus.data.l10n.untitled }}</span>
</span>
<span class="item-controls">
<button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text"><?php
<button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text">
<?php
/* translators: 1: Title of a menu item, 2: Type of a menu item */
printf( __( 'Edit menu item: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.item_type_label }}' );
?></span><span class="toggle-indicator" aria-hidden="true"></span></button>
<button type="button" class="button-link item-delete submitdelete deletion"><span class="screen-reader-text"><?php
?>
</span><span class="toggle-indicator" aria-hidden="true"></span></button>
<button type="button" class="button-link item-delete submitdelete deletion"><span class="screen-reader-text">
<?php
/* translators: 1: Title of a menu item, 2: Type of a menu item */
printf( __( 'Remove Menu Item: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.item_type_label }}' );
?></span></button>
?>
</span></button>
</span>
</div>
</div>
@ -130,7 +134,7 @@ class WP_Customize_Nav_Menu_Item_Control extends WP_Customize_Control {
<# if ( ( 'post_type' === data.item_type || 'taxonomy' === data.item_type ) && '' !== data.original_title ) { #>
<p class="link-to-original">
<?php
/* translators: Nav menu item original title. 1: Original title */
/* translators: Nav menu item original title. %s: Original title */
printf( __( 'Original: %s' ), '<a class="original-link" href="{{ data.url }}">{{ data.original_title }}</a>' );
?>
</p>

View file

@ -233,7 +233,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
$post = get_post( $this->post_id );
if ( $post && self::POST_TYPE === $post->post_type ) {
$is_title_empty = empty( $post->post_title );
$value = (array) wp_setup_nav_menu_item( $post );
$value = (array) wp_setup_nav_menu_item( $post );
if ( $is_title_empty ) {
$value['title'] = '';
}
@ -352,9 +352,13 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
}
if ( ! isset( $this->value['nav_menu_term_id'] ) && $this->post_id > 0 ) {
$menus = wp_get_post_terms( $this->post_id, WP_Customize_Nav_Menu_Setting::TAXONOMY, array(
'fields' => 'ids',
) );
$menus = wp_get_post_terms(
$this->post_id,
WP_Customize_Nav_Menu_Setting::TAXONOMY,
array(
'fields' => 'ids',
)
);
if ( ! empty( $menus ) ) {
$this->value['nav_menu_term_id'] = array_shift( $menus );
} else {
@ -379,7 +383,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
if ( ! isset( $this->value['_invalid'] ) ) {
$this->value['_invalid'] = false;
$is_known_invalid = (
$is_known_invalid = (
( ( 'post_type' === $this->value['type'] || 'post_type_archive' === $this->value['type'] ) && ! post_type_exists( $this->value['object'] ) )
||
( 'taxonomy' === $this->value['type'] && ! taxonomy_exists( $this->value['object'] ) )
@ -435,9 +439,9 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
return false;
}
$undefined = new stdClass();
$undefined = new stdClass();
$is_placeholder = ( $this->post_id < 0 );
$is_dirty = ( $undefined !== $this->post_value( $undefined ) );
$is_dirty = ( $undefined !== $this->post_value( $undefined ) );
if ( ! $is_placeholder && ! $is_dirty ) {
return false;
}
@ -466,13 +470,13 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
*
* @see wp_get_nav_menu_items()
*
* @param array $items An array of menu item post objects.
* @param object $menu The menu object.
* @param array $args An array of arguments used to retrieve menu item objects.
* @return array Array of menu items,
* @param WP_Post[] $items An array of menu item post objects.
* @param WP_Term $menu The menu object.
* @param array $args An array of arguments used to retrieve menu item objects.
* @return WP_Post[] Array of menu item objects.
*/
public function filter_wp_get_nav_menu_items( $items, $menu, $args ) {
$this_item = $this->value();
$this_item = $this->value();
$current_nav_menu_term_id = $this_item['nav_menu_term_id'];
unset( $this_item['nav_menu_term_id'] );
@ -507,7 +511,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
return $filtered_items;
}
$mutated = false;
$mutated = false;
$should_update = (
is_array( $this_item )
&&
@ -536,14 +540,13 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
* Re-apply the tail logic also applied on $items by wp_get_nav_menu_items().
*
* @since 4.3.0
* @static
*
* @see wp_get_nav_menu_items()
*
* @param array $items An array of menu item post objects.
* @param object $menu The menu object.
* @param array $args An array of arguments used to retrieve menu item objects.
* @return array Array of menu items,
* @param WP_Post[] $items An array of menu item post objects.
* @param WP_Term $menu The menu object.
* @param array $args An array of arguments used to retrieve menu item objects.
* @return WP_Post[] Array of menu item objects.
*/
public static function sort_wp_get_nav_menu_items( $items, $menu, $args ) {
// @todo We should probably re-apply some constraints imposed by $args.
@ -555,10 +558,13 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
}
if ( ARRAY_A === $args['output'] ) {
$items = wp_list_sort( $items, array(
$args['output_key'] => 'ASC',
) );
$i = 1;
$items = wp_list_sort(
$items,
array(
$args['output_key'] => 'ASC',
)
);
$i = 1;
foreach ( $items as $k => $item ) {
$items[ $k ]->{$args['output_key']} = $i++;
@ -582,7 +588,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
$item->post_status = $item->status;
unset( $item->status );
$item->post_type = 'nav_menu_item';
$item->post_type = 'nav_menu_item';
$item->menu_order = $item->position;
unset( $item->position );
@ -596,9 +602,9 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
$item->post_title = $item->title;
}
$item->ID = $this->post_id;
$item->ID = $this->post_id;
$item->db_id = $this->post_id;
$post = new WP_Post( (object) $item );
$post = new WP_Post( (object) $item );
if ( empty( $post->post_author ) ) {
$post->post_author = get_current_user_id();
@ -655,7 +661,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
return null;
}
$default = array(
$default = array(
'object_id' => 0,
'object' => '',
'menu_item_parent' => 0,
@ -673,8 +679,8 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
'nav_menu_term_id' => 0,
'_invalid' => false,
);
$menu_item_value = array_merge( $default, $menu_item_value );
$menu_item_value = wp_array_slice_assoc( $menu_item_value, array_keys( $default ) );
$menu_item_value = array_merge( $default, $menu_item_value );
$menu_item_value = wp_array_slice_assoc( $menu_item_value, array_keys( $default ) );
$menu_item_value['position'] = intval( $menu_item_value['position'] );
foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) {
@ -849,12 +855,12 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
if ( is_wp_error( $r ) ) {
$this->update_status = 'error';
$this->update_error = $r;
$this->update_error = $r;
} else {
if ( $is_placeholder ) {
$this->previous_post_id = $this->post_id;
$this->post_id = $r;
$this->update_status = 'inserted';
$this->post_id = $r;
$this->update_status = 'inserted';
} else {
$this->update_status = 'updated';
}

View file

@ -56,6 +56,13 @@ class WP_Customize_Nav_Menu_Location_Control extends WP_Customize_Control {
if ( empty( $this->choices ) ) {
return;
}
$value_hidden_class = $no_value_hidden_class = '';
if ( $this->value() ) {
$value_hidden_class = ' hidden';
} else {
$no_value_hidden_class = ' hidden';
}
?>
<label>
<?php if ( ! empty( $this->label ) ) : ?>
@ -74,8 +81,8 @@ class WP_Customize_Nav_Menu_Location_Control extends WP_Customize_Control {
?>
</select>
</label>
<button type="button" class="button-link create-menu<?php if ( $this->value() ) { echo ' hidden'; } ?>" data-location-id="<?php echo esc_attr( $this->location_id ); ?>" aria-label="<?php esc_attr_e( 'Create a menu for this location' ); ?>"><?php _e( '+ Create New Menu' ); ?></button>
<button type="button" class="button-link edit-menu<?php if ( ! $this->value() ) { echo ' hidden'; } ?>" aria-label="<?php esc_attr_e( 'Edit selected menu' ); ?>"><?php _e( 'Edit Menu' ); ?></button>
<button type="button" class="button-link create-menu<?php echo $value_hidden_class; ?>" data-location-id="<?php echo esc_attr( $this->location_id ); ?>" aria-label="<?php esc_attr_e( 'Create a menu for this location' ); ?>"><?php _e( '+ Create New Menu' ); ?></button>
<button type="button" class="button-link edit-menu<?php echo $no_value_hidden_class; ?>" aria-label="<?php esc_attr_e( 'Edit selected menu' ); ?>"><?php _e( 'Edit Menu' ); ?></button>
<?php
}
}

View file

@ -11,6 +11,8 @@
* Customize Nav Menu Locations Control Class.
*
* @since 4.9.0
*
* @see WP_Customize_Control
*/
class WP_Customize_Nav_Menu_Locations_Control extends WP_Customize_Control {
@ -51,9 +53,10 @@ class WP_Customize_Nav_Menu_Locations_Control extends WP_Customize_Control {
_x( '(If you plan to use a menu <a href="%1$s" %2$s>widget%3$s</a>, skip this step.)', 'menu locations' ),
__( 'https://codex.wordpress.org/WordPress_Widgets' ),
' class="external-link" target="_blank"',
sprintf( '<span class="screen-reader-text"> %s</span>',
sprintf(
'<span class="screen-reader-text"> %s</span>',
/* translators: accessibility text */
__( '(opens in a new window)' )
__( '(opens in a new tab)' )
)
);
?>
@ -73,8 +76,9 @@ class WP_Customize_Nav_Menu_Locations_Control extends WP_Customize_Control {
<?php echo $description; ?>
<span class="theme-location-set">
<?php
/* translators: %s: menu name */
printf( _x( '(Current: %s)', 'menu location' ),
printf(
/* translators: %s: menu name */
_x( '(Current: %s)', 'menu location' ),
'<span class="current-menu-location-name-' . esc_attr( $location ) . '"></span>'
);
?>

View file

@ -33,7 +33,7 @@ class WP_Customize_Nav_Menu_Section extends WP_Customize_Section {
* @return array Exported parameters.
*/
public function json() {
$exported = parent::json();
$exported = parent::json();
$exported['menu_id'] = intval( preg_replace( '/^nav_menu\[(-?\d+)\]/', '$1', $this->id ) );
return $exported;

View file

@ -206,9 +206,9 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
return false;
}
$undefined = new stdClass();
$undefined = new stdClass();
$is_placeholder = ( $this->term_id < 0 );
$is_dirty = ( $undefined !== $this->post_value( $undefined ) );
$is_dirty = ( $undefined !== $this->post_value( $undefined ) );
if ( ! $is_placeholder && ! $is_dirty ) {
return false;
}
@ -232,9 +232,9 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
*
* @see wp_get_nav_menus()
*
* @param array $menus An array of menu objects.
* @param array $args An array of arguments used to retrieve menu objects.
* @return array
* @param WP_Term[] $menus An array of menu objects.
* @param array $args An array of arguments used to retrieve menu objects.
* @return WP_Term[] Array of menu objects.
*/
public function filter_wp_get_nav_menus( $menus, $args ) {
if ( get_current_blog_id() !== $this->_previewed_blog_id ) {
@ -242,8 +242,8 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
}
$setting_value = $this->value();
$is_delete = ( false === $setting_value );
$index = -1;
$is_delete = ( false === $setting_value );
$index = -1;
// Find the existing menu item's position in the list.
foreach ( $menus as $i => $menu ) {
@ -260,24 +260,30 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
}
} else {
// Handle menus being updated or inserted.
$menu_obj = (object) array_merge( array(
'term_id' => $this->term_id,
'term_taxonomy_id' => $this->term_id,
'slug' => sanitize_title( $setting_value['name'] ),
'count' => 0,
'term_group' => 0,
'taxonomy' => self::TAXONOMY,
'filter' => 'raw',
), $setting_value );
$menu_obj = (object) array_merge(
array(
'term_id' => $this->term_id,
'term_taxonomy_id' => $this->term_id,
'slug' => sanitize_title( $setting_value['name'] ),
'count' => 0,
'term_group' => 0,
'taxonomy' => self::TAXONOMY,
'filter' => 'raw',
),
$setting_value
);
array_splice( $menus, $index, ( -1 === $index ? 0 : 1 ), array( $menu_obj ) );
}
// Make sure the menu objects get re-sorted after an update/insert.
if ( ! $is_delete && ! empty( $args['orderby'] ) ) {
$menus = wp_list_sort( $menus, array(
$args['orderby'] => 'ASC',
) );
$menus = wp_list_sort(
$menus,
array(
$args['orderby'] => 'ASC',
)
);
}
// @todo add support for $args['hide_empty'] === true
@ -353,7 +359,8 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
return $menu_obj;
}
$menu_obj = (object) array_merge( array(
$menu_obj = (object) array_merge(
array(
'term_id' => $this->term_id,
'term_taxonomy_id' => $this->term_id,
'slug' => sanitize_title( $setting_value['name'] ),
@ -361,7 +368,9 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
'term_group' => 0,
'taxonomy' => self::TAXONOMY,
'filter' => 'raw',
), $setting_value );
),
$setting_value
);
return $menu_obj;
}
@ -379,7 +388,7 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
return $nav_menu_options;
}
$menu = $this->value();
$menu = $this->value();
$nav_menu_options = $this->filter_nav_menu_options_value(
$nav_menu_options,
$this->term_id,
@ -418,8 +427,8 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
'parent' => 0,
'auto_add' => false,
);
$value = array_merge( $default, $value );
$value = wp_array_slice_assoc( $value, array_keys( $default ) );
$value = array_merge( $default, $value );
$value = wp_array_slice_assoc( $value, array_keys( $default ) );
$value['name'] = trim( esc_html( $value['name'] ) ); // This sanitization code is used in wp-admin/nav-menus.php.
$value['description'] = sanitize_text_field( $value['description'] );
@ -494,23 +503,23 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
$this->update_error = $r;
} else {
$this->update_status = 'deleted';
$auto_add = false;
$auto_add = false;
}
}
} else {
// Insert or update menu.
$menu_data = wp_array_slice_assoc( $value, array( 'description', 'parent' ) );
$menu_data = wp_array_slice_assoc( $value, array( 'description', 'parent' ) );
$menu_data['menu-name'] = $value['name'];
$menu_id = $is_placeholder ? 0 : $this->term_id;
$r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) );
$original_name = $menu_data['menu-name'];
$menu_id = $is_placeholder ? 0 : $this->term_id;
$r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) );
$original_name = $menu_data['menu-name'];
$name_conflict_suffix = 1;
while ( is_wp_error( $r ) && 'menu_exists' === $r->get_error_code() ) {
$name_conflict_suffix += 1;
/* translators: 1: original menu name, 2: duplicate count */
$menu_data['menu-name'] = sprintf( __( '%1$s (%2$d)' ), $original_name, $name_conflict_suffix );
$r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) );
$r = wp_update_nav_menu_object( $menu_id, wp_slash( $menu_data ) );
}
if ( is_wp_error( $r ) ) {
@ -565,7 +574,7 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
}
$widget_instance['nav_menu'] = $this->term_id;
$updated_widget_instance = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance );
$updated_widget_instance = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance );
$this->manager->set_post_value( $nav_menu_widget_setting->id, $updated_widget_instance );
$nav_menu_widget_setting->save();
@ -633,7 +642,7 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
$data['widget_nav_menu_updates'],
$this->_widget_nav_menu_updates
);
$this->_widget_nav_menu_updates = array();
$this->_widget_nav_menu_updates = array();
return $data;
}

View file

@ -96,6 +96,6 @@ class WP_Customize_Nav_Menus_Panel extends WP_Customize_Panel {
// NOTE: The following is a workaround for an inability to treat (and thus label) a list of sections as a whole.
?>
<li class="customize-control-title customize-section-title-nav_menus-heading"><?php _e( 'Menus' ); ?></li>
<?php
<?php
}
}

View file

@ -159,7 +159,7 @@ class WP_Customize_Partial {
// Process settings.
if ( ! isset( $this->settings ) ) {
$this->settings = array( $id );
} else if ( is_string( $this->settings ) ) {
} elseif ( is_string( $this->settings ) ) {
$this->settings = array( $this->settings );
}
@ -201,7 +201,7 @@ class WP_Customize_Partial {
if ( ! empty( $this->render_callback ) ) {
ob_start();
$return_render = call_user_func( $this->render_callback, $this, $container_context );
$ob_render = ob_get_clean();
$ob_render = ob_get_clean();
if ( null !== $return_render && '' !== $ob_render ) {
_doing_it_wrong( __FUNCTION__, __( 'Partial render must echo the content or return the content string (or array), but not both.' ), '4.5.0' );

View file

@ -188,12 +188,12 @@ final class WP_Customize_Selective_Refresh {
}
$switched_locale = switch_to_locale( get_user_locale() );
$l10n = array(
$l10n = array(
'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
'clickEditMenu' => __( 'Click to edit this menu.' ),
'clickEditWidget' => __( 'Click to edit this widget.' ),
'clickEditTitle' => __( 'Click to edit the site title.' ),
'clickEditMisc' => __( 'Click to edit this element.' ),
'clickEditMenu' => __( 'Click to edit this menu.' ),
'clickEditWidget' => __( 'Click to edit this widget.' ),
'clickEditTitle' => __( 'Click to edit the site title.' ),
'clickEditMisc' => __( 'Click to edit this element.' ),
/* translators: %s: document.write() */
'badDocumentWrite' => sprintf( __( '%s is forbidden' ), 'document.write()' ),
);
@ -218,8 +218,8 @@ final class WP_Customize_Selective_Refresh {
*
* @see WP_Customize_Manager::add_dynamic_settings()
*
* @param array $partial_ids The partial ID to add.
* @return array Added WP_Customize_Partial instances.
* @param string[] $partial_ids Array of the partial IDs to add.
* @return WP_Customize_Partial[] Array of added WP_Customize_Partial instances.
*/
public function add_dynamic_partials( $partial_ids ) {
$new_partials = array();
@ -232,7 +232,7 @@ final class WP_Customize_Selective_Refresh {
continue;
}
$partial_args = false;
$partial_args = false;
$partial_class = 'WP_Customize_Partial';
/**
@ -415,8 +415,8 @@ final class WP_Customize_Selective_Refresh {
$response['errors'] = $this->triggered_errors;
}
$setting_validities = $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() );
$exported_setting_validities = array_map( array( $this->manager, 'prepare_setting_validity_for_js' ), $setting_validities );
$setting_validities = $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() );
$exported_setting_validities = array_map( array( $this->manager, 'prepare_setting_validity_for_js' ), $setting_validities );
$response['setting_validities'] = $exported_setting_validities;
/**

View file

@ -40,7 +40,7 @@ class WP_Customize_Sidebar_Section extends WP_Customize_Section {
* @return array The array to be exported to the client as JSON.
*/
public function json() {
$json = parent::json();
$json = parent::json();
$json['sidebarId'] = $this->sidebar_id;
return $json;
}

View file

@ -82,10 +82,12 @@ class WP_Customize_Theme_Control extends WP_Customize_Control {
<span class="more-details theme-details" id="{{ data.section }}-{{ data.theme.id }}-action" aria-label="<?php echo esc_attr( $details_label ); ?>"><?php _e( 'Theme Details' ); ?></span>
<div class="theme-author"><?php
<div class="theme-author">
<?php
/* translators: Theme author name */
printf( _x( 'By %s', 'theme author' ), '{{ data.theme.author }}' );
?></div>
?>
</div>
<# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #>
<div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}">
@ -128,6 +130,6 @@ class WP_Customize_Theme_Control extends WP_Customize_Control {
</div>
<# } #>
</div>
<?php
<?php
}
}

View file

@ -54,8 +54,8 @@ class WP_Customize_Themes_Section extends WP_Customize_Section {
* @return array Exported parameters.
*/
public function json() {
$exported = parent::json();
$exported['action'] = $this->action;
$exported = parent::json();
$exported['action'] = $this->action;
$exported['filter_type'] = $this->filter_type;
return $exported;
@ -87,8 +87,9 @@ class WP_Customize_Themes_Section extends WP_Customize_Section {
<p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
<p class="no-themes-local">
<?php
/* translators: %s: "Search WordPress.org themes" button */
printf( __( 'No themes found. Try a different search, or %s.' ),
printf(
/* translators: %s: "Search WordPress.org themes" button text */
__( 'No themes found. Try a different search, or %s.' ),
sprintf( '<button type="button" class="button-link search-dotorg-themes">%s</button>', __( 'Search WordPress.org themes' ) )
);
?>

View file

@ -18,7 +18,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Media_Control {
public $type = 'upload';
public $mime_type = '';
public $button_labels = array();
public $removed = ''; // unused
public $removed = ''; // unused
public $context; // unused
public $extensions = array(); // unused

View file

@ -15,13 +15,68 @@
* @see WP_Customize_Control
*/
class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
/**
* Customize control type.
*
* @since 3.9.0
* @var string
*/
public $type = 'widget_form';
/**
* Widget ID.
*
* @since 3.9.0
* @var string
*/
public $widget_id;
/**
* Widget ID base.
*
* @since 3.9.0
* @var string
*/
public $widget_id_base;
/**
* Sidebar ID.
*
* @since 3.9.0
* @var string
*/
public $sidebar_id;
/**
* Widget status.
*
* @since 3.9.0
* @var bool True if new, false otherwise. Default false.
*/
public $is_new = false;
/**
* Widget width.
*
* @since 3.9.0
* @var int
*/
public $width;
/**
* Widget height.
*
* @since 3.9.0
* @var int
*/
public $height;
/**
* Widget mode.
*
* @since 3.9.0
* @var bool True if wide, false otherwise. Default false.
*/
public $is_wide = false;
/**
@ -49,11 +104,16 @@ class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
}
$args = array(
'widget_id' => $widget['id'],
'widget_id' => $widget['id'],
'widget_name' => $widget['name'],
);
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
$args = wp_list_widget_controls_dynamic_sidebar(
array(
0 => $args,
1 => $widget['params'][0],
)
);
$widget_control_parts = $this->manager->widgets->get_widget_control_parts( $args );
$this->json['widget_control'] = $widget_control_parts['control'];