Файловый менеджер - Редактировать - /home2/nishantp/public_html/wp-includes/widgets/customize.zip
Назад
PK [CrZȊ���k �k , class-wp-customize-nav-menu-item-setting.phpnu �[��� <?php /** * Customize API: WP_Customize_Nav_Menu_Item_Setting class * * @package WordPress * @subpackage Customize * @since 4.4.0 */ /** * Customize Setting to represent a nav_menu. * * Subclass of WP_Customize_Setting to represent a nav_menu taxonomy term, and * the IDs for the nav_menu_items associated with the nav menu. * * @since 4.3.0 * * @see WP_Customize_Setting */ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { const ID_PATTERN = '/^nav_menu_item\[(?P<id>-?\d+)\]$/'; const POST_TYPE = 'nav_menu_item'; const TYPE = 'nav_menu_item'; /** * Setting type. * * @since 4.3.0 * @var string */ public $type = self::TYPE; /** * Default setting value. * * @since 4.3.0 * @var array * * @see wp_setup_nav_menu_item() */ public $default = array( // The $menu_item_data for wp_update_nav_menu_item(). 'object_id' => 0, 'object' => '', // Taxonomy name. 'menu_item_parent' => 0, // A.K.A. menu-item-parent-id; note that post_parent is different, and not included. 'position' => 0, // A.K.A. menu_order. 'type' => 'custom', // Note that type_label is not included here. 'title' => '', 'url' => '', 'target' => '', 'attr_title' => '', 'description' => '', 'classes' => '', 'xfn' => '', 'status' => 'publish', 'original_title' => '', 'nav_menu_term_id' => 0, // This will be supplied as the $menu_id arg for wp_update_nav_menu_item(). '_invalid' => false, ); /** * Default transport. * * @since 4.3.0 * @since 4.5.0 Default changed to 'refresh' * @var string */ public $transport = 'refresh'; /** * The post ID represented by this setting instance. This is the db_id. * * A negative value represents a placeholder ID for a new menu not yet saved. * * @since 4.3.0 * @var int */ public $post_id; /** * Storage of pre-setup menu item to prevent wasted calls to wp_setup_nav_menu_item(). * * @since 4.3.0 * @var array|null */ protected $value; /** * Previous (placeholder) post ID used before creating a new menu item. * * This value will be exported to JS via the customize_save_response filter * so that JavaScript can update the settings to refer to the newly-assigned * post ID. This value is always negative to indicate it does not refer to * a real post. * * @since 4.3.0 * @var int * * @see WP_Customize_Nav_Menu_Item_Setting::update() * @see WP_Customize_Nav_Menu_Item_Setting::amend_customize_save_response() */ public $previous_post_id; /** * When previewing or updating a menu item, this stores the previous nav_menu_term_id * which ensures that we can apply the proper filters. * * @since 4.3.0 * @var int */ public $original_nav_menu_term_id; /** * Whether or not update() was called. * * @since 4.3.0 * @var bool */ protected $is_updated = false; /** * Status for calling the update method, used in customize_save_response filter. * * See {@see 'customize_save_response'}. * * When status is inserted, the placeholder post ID is stored in $previous_post_id. * When status is error, the error is stored in $update_error. * * @since 4.3.0 * @var string updated|inserted|deleted|error * * @see WP_Customize_Nav_Menu_Item_Setting::update() * @see WP_Customize_Nav_Menu_Item_Setting::amend_customize_save_response() */ public $update_status; /** * Any error object returned by wp_update_nav_menu_item() when setting is updated. * * @since 4.3.0 * @var WP_Error * * @see WP_Customize_Nav_Menu_Item_Setting::update() * @see WP_Customize_Nav_Menu_Item_Setting::amend_customize_save_response() */ public $update_error; /** * Constructor. * * Any supplied $args override class property defaults. * * @since 4.3.0 * * @throws Exception If $id is not valid for this setting type. * * @param WP_Customize_Manager $manager Customizer bootstrap instance. * @param string $id A specific ID of the setting. * Can be a theme mod or option name. * @param array $args Optional. Setting arguments. */ public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) { if ( empty( $manager->nav_menus ) ) { throw new Exception( 'Expected WP_Customize_Manager::$nav_menus to be set.' ); } if ( ! preg_match( self::ID_PATTERN, $id, $matches ) ) { throw new Exception( "Illegal widget setting ID: $id" ); } $this->post_id = (int) $matches['id']; add_action( 'wp_update_nav_menu_item', array( $this, 'flush_cached_value' ), 10, 2 ); parent::__construct( $manager, $id, $args ); // Ensure that an initially-supplied value is valid. if ( isset( $this->value ) ) { $this->populate_value(); foreach ( array_diff( array_keys( $this->default ), array_keys( $this->value ) ) as $missing ) { throw new Exception( "Supplied nav_menu_item value missing property: $missing" ); } } } /** * Clear the cached value when this nav menu item is updated. * * @since 4.3.0 * * @param int $menu_id The term ID for the menu. * @param int $menu_item_id The post ID for the menu item. */ public function flush_cached_value( $menu_id, $menu_item_id ) { unset( $menu_id ); if ( $menu_item_id === $this->post_id ) { $this->value = null; } } /** * Get the instance data for a given nav_menu_item setting. * * @since 4.3.0 * * @see wp_setup_nav_menu_item() * * @return array|false Instance data array, or false if the item is marked for deletion. */ public function value() { if ( $this->is_previewed && get_current_blog_id() === $this->_previewed_blog_id ) { $undefined = new stdClass(); // Symbol. $post_value = $this->post_value( $undefined ); if ( $undefined === $post_value ) { $value = $this->_original_value; } else { $value = $post_value; } if ( ! empty( $value ) && empty( $value['original_title'] ) ) { $value['original_title'] = $this->get_original_title( (object) $value ); } } elseif ( isset( $this->value ) ) { $value = $this->value; } else { $value = false; // Note that an ID of less than one indicates a nav_menu not yet inserted. if ( $this->post_id > 0 ) { $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 ); if ( $is_title_empty ) { $value['title'] = ''; } } } if ( ! is_array( $value ) ) { $value = $this->default; } // Cache the value for future calls to avoid having to re-call wp_setup_nav_menu_item(). $this->value = $value; $this->populate_value(); $value = $this->value; } if ( ! empty( $value ) && empty( $value['type_label'] ) ) { $value['type_label'] = $this->get_type_label( (object) $value ); } return $value; } /** * Get original title. * * @since 4.7.0 * * @param object $item Nav menu item. * @return string The original title. */ protected function get_original_title( $item ) { $original_title = ''; if ( 'post_type' === $item->type && ! empty( $item->object_id ) ) { $original_object = get_post( $item->object_id ); if ( $original_object ) { /** This filter is documented in wp-includes/post-template.php */ $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID ); if ( '' === $original_title ) { /* translators: %d: ID of a post. */ $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID ); } } } elseif ( 'taxonomy' === $item->type && ! empty( $item->object_id ) ) { $original_term_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); if ( ! is_wp_error( $original_term_title ) ) { $original_title = $original_term_title; } } elseif ( 'post_type_archive' === $item->type ) { $original_object = get_post_type_object( $item->object ); if ( $original_object ) { $original_title = $original_object->labels->archives; } } $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) ); return $original_title; } /** * Get type label. * * @since 4.7.0 * * @param object $item Nav menu item. * @return string The type label. */ protected function get_type_label( $item ) { if ( 'post_type' === $item->type ) { $object = get_post_type_object( $item->object ); if ( $object ) { $type_label = $object->labels->singular_name; } else { $type_label = $item->object; } } elseif ( 'taxonomy' === $item->type ) { $object = get_taxonomy( $item->object ); if ( $object ) { $type_label = $object->labels->singular_name; } else { $type_label = $item->object; } } elseif ( 'post_type_archive' === $item->type ) { $type_label = __( 'Post Type Archive' ); } else { $type_label = __( 'Custom Link' ); } return $type_label; } /** * Ensure that the value is fully populated with the necessary properties. * * Translates some properties added by wp_setup_nav_menu_item() and removes others. * * @since 4.3.0 * * @see WP_Customize_Nav_Menu_Item_Setting::value() */ protected function populate_value() { if ( ! is_array( $this->value ) ) { return; } if ( isset( $this->value['menu_order'] ) ) { $this->value['position'] = $this->value['menu_order']; unset( $this->value['menu_order'] ); } if ( isset( $this->value['post_status'] ) ) { $this->value['status'] = $this->value['post_status']; unset( $this->value['post_status'] ); } if ( ! isset( $this->value['original_title'] ) ) { $this->value['original_title'] = $this->get_original_title( (object) $this->value ); } 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', ) ); if ( ! empty( $menus ) ) { $this->value['nav_menu_term_id'] = array_shift( $menus ); } else { $this->value['nav_menu_term_id'] = 0; } } foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) { if ( ! is_int( $this->value[ $key ] ) ) { $this->value[ $key ] = (int) $this->value[ $key ]; } } foreach ( array( 'classes', 'xfn' ) as $key ) { if ( is_array( $this->value[ $key ] ) ) { $this->value[ $key ] = implode( ' ', $this->value[ $key ] ); } } if ( ! isset( $this->value['title'] ) ) { $this->value['title'] = ''; } if ( ! isset( $this->value['_invalid'] ) ) { $this->value['_invalid'] = false; $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'] ) ) ); if ( $is_known_invalid ) { $this->value['_invalid'] = true; } } // Remove remaining properties available on a setup nav_menu_item post object which aren't relevant to the setting value. $irrelevant_properties = array( 'ID', 'comment_count', 'comment_status', 'db_id', 'filter', 'guid', 'ping_status', 'pinged', 'post_author', 'post_content', 'post_content_filtered', 'post_date', 'post_date_gmt', 'post_excerpt', 'post_mime_type', 'post_modified', 'post_modified_gmt', 'post_name', 'post_parent', 'post_password', 'post_title', 'post_type', 'to_ping', ); foreach ( $irrelevant_properties as $property ) { unset( $this->value[ $property ] ); } } /** * Handle previewing the setting. * * @since 4.3.0 * @since 4.4.0 Added boolean return value. * * @see WP_Customize_Manager::post_value() * * @return bool False if method short-circuited due to no-op. */ public function preview() { if ( $this->is_previewed ) { return false; } $undefined = new stdClass(); $is_placeholder = ( $this->post_id < 0 ); $is_dirty = ( $undefined !== $this->post_value( $undefined ) ); if ( ! $is_placeholder && ! $is_dirty ) { return false; } $this->is_previewed = true; $this->_original_value = $this->value(); $this->original_nav_menu_term_id = $this->_original_value['nav_menu_term_id']; $this->_previewed_blog_id = get_current_blog_id(); add_filter( 'wp_get_nav_menu_items', array( $this, 'filter_wp_get_nav_menu_items' ), 10, 3 ); $sort_callback = array( __CLASS__, 'sort_wp_get_nav_menu_items' ); if ( ! has_filter( 'wp_get_nav_menu_items', $sort_callback ) ) { add_filter( 'wp_get_nav_menu_items', array( __CLASS__, 'sort_wp_get_nav_menu_items' ), 1000, 3 ); } // @todo Add get_post_metadata filters for plugins to add their data. return true; } /** * Filters the wp_get_nav_menu_items() result to supply the previewed menu items. * * @since 4.3.0 * * @see wp_get_nav_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(); $current_nav_menu_term_id = null; if ( isset( $this_item['nav_menu_term_id'] ) ) { $current_nav_menu_term_id = $this_item['nav_menu_term_id']; unset( $this_item['nav_menu_term_id'] ); } $should_filter = ( $menu->term_id === $this->original_nav_menu_term_id || $menu->term_id === $current_nav_menu_term_id ); if ( ! $should_filter ) { return $items; } // Handle deleted menu item, or menu item moved to another menu. $should_remove = ( false === $this_item || ( isset( $this_item['_invalid'] ) && true === $this_item['_invalid'] ) || ( $this->original_nav_menu_term_id === $menu->term_id && $current_nav_menu_term_id !== $this->original_nav_menu_term_id ) ); if ( $should_remove ) { $filtered_items = array(); foreach ( $items as $item ) { if ( $item->db_id !== $this->post_id ) { $filtered_items[] = $item; } } return $filtered_items; } $mutated = false; $should_update = ( is_array( $this_item ) && $current_nav_menu_term_id === $menu->term_id ); if ( $should_update ) { foreach ( $items as $item ) { if ( $item->db_id === $this->post_id ) { foreach ( get_object_vars( $this->value_as_wp_post_nav_menu_item() ) as $key => $value ) { $item->$key = $value; } $mutated = true; } } // Not found so we have to append it.. if ( ! $mutated ) { $items[] = $this->value_as_wp_post_nav_menu_item(); } } return $items; } /** * Re-apply the tail logic also applied on $items by wp_get_nav_menu_items(). * * @since 4.3.0 * * @see wp_get_nav_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. unset( $args['include'] ); // Remove invalid items only in front end. if ( ! is_admin() ) { $items = array_filter( $items, '_is_valid_nav_menu_item' ); } if ( ARRAY_A === $args['output'] ) { $items = wp_list_sort( $items, array( $args['output_key'] => 'ASC', ) ); $i = 1; foreach ( $items as $k => $item ) { $items[ $k ]->{$args['output_key']} = $i++; } } return $items; } /** * Get the value emulated into a WP_Post and set up as a nav_menu_item. * * @since 4.3.0 * * @return WP_Post With wp_setup_nav_menu_item() applied. */ public function value_as_wp_post_nav_menu_item() { $item = (object) $this->value(); unset( $item->nav_menu_term_id ); $item->post_status = $item->status; unset( $item->status ); $item->post_type = 'nav_menu_item'; $item->menu_order = $item->position; unset( $item->position ); if ( empty( $item->original_title ) ) { $item->original_title = $this->get_original_title( $item ); } if ( empty( $item->title ) && ! empty( $item->original_title ) ) { $item->title = $item->original_title; } if ( $item->title ) { $item->post_title = $item->title; } // 'classes' should be an array, as in wp_setup_nav_menu_item(). if ( isset( $item->classes ) && is_scalar( $item->classes ) ) { $item->classes = explode( ' ', $item->classes ); } $item->ID = $this->post_id; $item->db_id = $this->post_id; $post = new WP_Post( (object) $item ); if ( empty( $post->post_author ) ) { $post->post_author = get_current_user_id(); } if ( ! isset( $post->type_label ) ) { $post->type_label = $this->get_type_label( $post ); } // Ensure nav menu item URL is set according to linked object. if ( 'post_type' === $post->type && ! empty( $post->object_id ) ) { $post->url = get_permalink( $post->object_id ); } elseif ( 'taxonomy' === $post->type && ! empty( $post->object ) && ! empty( $post->object_id ) ) { $post->url = get_term_link( (int) $post->object_id, $post->object ); } elseif ( 'post_type_archive' === $post->type && ! empty( $post->object ) ) { $post->url = get_post_type_archive_link( $post->object ); } if ( is_wp_error( $post->url ) ) { $post->url = ''; } /** This filter is documented in wp-includes/nav-menu.php */ $post->attr_title = apply_filters( 'nav_menu_attr_title', $post->attr_title ); /** This filter is documented in wp-includes/nav-menu.php */ $post->description = apply_filters( 'nav_menu_description', wp_trim_words( $post->description, 200 ) ); /** This filter is documented in wp-includes/nav-menu.php */ $post = apply_filters( 'wp_setup_nav_menu_item', $post ); return $post; } /** * Sanitize an input. * * Note that parent::sanitize() erroneously does wp_unslash() on $value, but * we remove that in this override. * * @since 4.3.0 * @since 5.9.0 Renamed `$menu_item_value` to `$value` for PHP 8 named parameter support. * * @param array $value The menu item value to sanitize. * @return array|false|null|WP_Error Null or WP_Error if an input isn't valid. False if it is marked for deletion. * Otherwise the sanitized value. */ public function sanitize( $value ) { // Restores the more descriptive, specific name for use within this method. $menu_item_value = $value; // Menu is marked for deletion. if ( false === $menu_item_value ) { return $menu_item_value; } // Invalid. if ( ! is_array( $menu_item_value ) ) { return null; } $default = array( 'object_id' => 0, 'object' => '', 'menu_item_parent' => 0, 'position' => 0, 'type' => 'custom', 'title' => '', 'url' => '', 'target' => '', 'attr_title' => '', 'description' => '', 'classes' => '', 'xfn' => '', 'status' => 'publish', 'original_title' => '', '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['position'] = (int) $menu_item_value['position']; foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) { // Note we need to allow negative-integer IDs for previewed objects not inserted yet. $menu_item_value[ $key ] = (int) $menu_item_value[ $key ]; } foreach ( array( 'type', 'object', 'target' ) as $key ) { $menu_item_value[ $key ] = sanitize_key( $menu_item_value[ $key ] ); } foreach ( array( 'xfn', 'classes' ) as $key ) { $value = $menu_item_value[ $key ]; if ( ! is_array( $value ) ) { $value = explode( ' ', $value ); } $menu_item_value[ $key ] = implode( ' ', array_map( 'sanitize_html_class', $value ) ); } $menu_item_value['original_title'] = sanitize_text_field( $menu_item_value['original_title'] ); // Apply the same filters as when calling wp_insert_post(). /** This filter is documented in wp-includes/post.php */ $menu_item_value['title'] = wp_unslash( apply_filters( 'title_save_pre', wp_slash( $menu_item_value['title'] ) ) ); /** This filter is documented in wp-includes/post.php */ $menu_item_value['attr_title'] = wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $menu_item_value['attr_title'] ) ) ); /** This filter is documented in wp-includes/post.php */ $menu_item_value['description'] = wp_unslash( apply_filters( 'content_save_pre', wp_slash( $menu_item_value['description'] ) ) ); if ( '' !== $menu_item_value['url'] ) { $menu_item_value['url'] = sanitize_url( $menu_item_value['url'] ); if ( '' === $menu_item_value['url'] ) { return new WP_Error( 'invalid_url', __( 'Invalid URL.' ) ); // Fail sanitization if URL is invalid. } } if ( 'publish' !== $menu_item_value['status'] ) { $menu_item_value['status'] = 'draft'; } $menu_item_value['_invalid'] = (bool) $menu_item_value['_invalid']; /** This filter is documented in wp-includes/class-wp-customize-setting.php */ return apply_filters( "customize_sanitize_{$this->id}", $menu_item_value, $this ); } /** * Creates/updates the nav_menu_item post for this setting. * * Any created menu items will have their assigned post IDs exported to the client * via the {@see 'customize_save_response'} filter. Likewise, any errors will be * exported to the client via the customize_save_response() filter. * * To delete a menu, the client can send false as the value. * * @since 4.3.0 * * @see wp_update_nav_menu_item() * * @param array|false $value The menu item array to update. If false, then the menu item will be deleted * entirely. See WP_Customize_Nav_Menu_Item_Setting::$default for what the value * should consist of. * @return null|void */ protected function update( $value ) { if ( $this->is_updated ) { return; } $this->is_updated = true; $is_placeholder = ( $this->post_id < 0 ); $is_delete = ( false === $value ); // Update the cached value. $this->value = $value; add_filter( 'customize_save_response', array( $this, 'amend_customize_save_response' ) ); if ( $is_delete ) { // If the current setting post is a placeholder, a delete request is a no-op. if ( $is_placeholder ) { $this->update_status = 'deleted'; } else { $r = wp_delete_post( $this->post_id, true ); if ( false === $r ) { $this->update_error = new WP_Error( 'delete_failure' ); $this->update_status = 'error'; } else { $this->update_status = 'deleted'; } // @todo send back the IDs for all associated nav menu items deleted, so these settings (and controls) can be removed from Customizer? } } else { // Handle saving menu items for menus that are being newly-created. if ( $value['nav_menu_term_id'] < 0 ) { $nav_menu_setting_id = sprintf( 'nav_menu[%s]', $value['nav_menu_term_id'] ); $nav_menu_setting = $this->manager->get_setting( $nav_menu_setting_id ); if ( ! $nav_menu_setting || ! ( $nav_menu_setting instanceof WP_Customize_Nav_Menu_Setting ) ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_nav_menu_setting' ); return; } if ( false === $nav_menu_setting->save() ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'nav_menu_setting_failure' ); return; } if ( (int) $value['nav_menu_term_id'] !== $nav_menu_setting->previous_term_id ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_previous_term_id' ); return; } $value['nav_menu_term_id'] = $nav_menu_setting->term_id; } // Handle saving a nav menu item that is a child of a nav menu item being newly-created. if ( $value['menu_item_parent'] < 0 ) { $parent_nav_menu_item_setting_id = sprintf( 'nav_menu_item[%s]', $value['menu_item_parent'] ); $parent_nav_menu_item_setting = $this->manager->get_setting( $parent_nav_menu_item_setting_id ); if ( ! $parent_nav_menu_item_setting || ! ( $parent_nav_menu_item_setting instanceof WP_Customize_Nav_Menu_Item_Setting ) ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_nav_menu_item_setting' ); return; } if ( false === $parent_nav_menu_item_setting->save() ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'nav_menu_item_setting_failure' ); return; } if ( (int) $value['menu_item_parent'] !== $parent_nav_menu_item_setting->previous_post_id ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_previous_post_id' ); return; } $value['menu_item_parent'] = $parent_nav_menu_item_setting->post_id; } // Insert or update menu. $menu_item_data = array( 'menu-item-object-id' => $value['object_id'], 'menu-item-object' => $value['object'], 'menu-item-parent-id' => $value['menu_item_parent'], 'menu-item-position' => $value['position'], 'menu-item-type' => $value['type'], 'menu-item-title' => $value['title'], 'menu-item-url' => $value['url'], 'menu-item-description' => $value['description'], 'menu-item-attr-title' => $value['attr_title'], 'menu-item-target' => $value['target'], 'menu-item-classes' => $value['classes'], 'menu-item-xfn' => $value['xfn'], 'menu-item-status' => $value['status'], ); $r = wp_update_nav_menu_item( $value['nav_menu_term_id'], $is_placeholder ? 0 : $this->post_id, wp_slash( $menu_item_data ) ); if ( is_wp_error( $r ) ) { $this->update_status = 'error'; $this->update_error = $r; } else { if ( $is_placeholder ) { $this->previous_post_id = $this->post_id; $this->post_id = $r; $this->update_status = 'inserted'; } else { $this->update_status = 'updated'; } } } } /** * Export data for the JS client. * * @since 4.3.0 * * @see WP_Customize_Nav_Menu_Item_Setting::update() * * @param array $data Additional information passed back to the 'saved' event on `wp.customize`. * @return array Save response data. */ public function amend_customize_save_response( $data ) { if ( ! isset( $data['nav_menu_item_updates'] ) ) { $data['nav_menu_item_updates'] = array(); } $data['nav_menu_item_updates'][] = array( 'post_id' => $this->post_id, 'previous_post_id' => $this->previous_post_id, 'error' => $this->update_error ? $this->update_error->get_error_code() : null, 'status' => $this->update_status, ); return $data; } } PK [CrZ3�8<� � ) class-wp-sidebar-block-editor-control.phpnu �[��� <?php /** * Customize API: WP_Sidebar_Block_Editor_Control class. * * @package WordPress * @subpackage Customize * @since 5.8.0 */ /** * Core class used to implement the widgets block editor control in the * customizer. * * @since 5.8.0 * * @see WP_Customize_Control */ class WP_Sidebar_Block_Editor_Control extends WP_Customize_Control { /** * The control type. * * @since 5.8.0 * * @var string */ public $type = 'sidebar_block_editor'; /** * Render the widgets block editor container. * * @since 5.8.0 */ public function render_content() { // Render an empty control. The JavaScript in // @wordpress/customize-widgets will do the rest. } } PK [CrZ;a�C % class-wp-customize-themes-section.phpnu �[��� <?php /** * Customize API: WP_Customize_Themes_Section class * * @package WordPress * @subpackage Customize * @since 4.4.0 */ /** * Customize Themes Section class. * * A UI container for theme controls, which are displayed within sections. * * @since 4.2.0 * * @see WP_Customize_Section */ class WP_Customize_Themes_Section extends WP_Customize_Section { /** * Section type. * * @since 4.2.0 * @var string */ public $type = 'themes'; /** * Theme section action. * * Defines the type of themes to load (installed, wporg, etc.). * * @since 4.9.0 * @var string */ public $action = ''; /** * Theme section filter type. * * Determines whether filters are applied to loaded (local) themes or by initiating a new remote query (remote). * When filtering is local, the initial themes query is not paginated by default. * * @since 4.9.0 * @var string */ public $filter_type = 'local'; /** * Gets section parameters for JS. * * @since 4.9.0 * @return array Exported parameters. */ public function json() { $exported = parent::json(); $exported['action'] = $this->action; $exported['filter_type'] = $this->filter_type; return $exported; } /** * Renders a themes section as a JS template. * * The template is only rendered by PHP once, so all actions are prepared at once on the server side. * * @since 4.9.0 */ protected function render_template() { ?> <li id="accordion-section-{{ data.id }}" class="theme-section"> <button type="button" class="customize-themes-section-title themes-section-{{ data.id }}">{{ data.title }}</button> <?php if ( current_user_can( 'install_themes' ) || is_multisite() ) : // @todo Upload support. ?> <?php endif; ?> <div class="customize-themes-section themes-section-{{ data.id }} control-section-content themes-php"> <div class="theme-overlay" tabindex="0" role="dialog" aria-label="<?php esc_attr_e( 'Theme Details' ); ?>"></div> <div class="theme-browser rendered"> <div class="customize-preview-header themes-filter-bar"> <?php $this->filter_bar_content_template(); ?> </div> <?php $this->filter_drawer_content_template(); ?> <div class="error unexpected-error" style="display: none; "> <p> <?php printf( /* translators: %s: Support forums URL. */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'https://wordpress.org/support/forums/' ) ); ?> </p> </div> <ul class="themes"> </ul> <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p> <p class="no-themes-local"> <?php 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' ) ) ); ?> </p> <p class="spinner"></p> </div> </div> </li> <?php } /** * Renders the filter bar portion of a themes section as a JS template. * * The template is only rendered by PHP once, so all actions are prepared at once on the server side. * The filter bar container is rendered by {@see render_template()}. * * @since 4.9.0 */ protected function filter_bar_content_template() { ?> <button type="button" class="button button-primary customize-section-back customize-themes-mobile-back"><?php _e( 'Go to theme sources' ); ?></button> <# if ( 'wporg' === data.action ) { #> <div class="search-form"> <label for="wp-filter-search-input-{{ data.id }}"><?php _e( 'Search themes' ); ?></label> <div class="search-form-input"> <input type="search" id="wp-filter-search-input-{{ data.id }}" aria-describedby="{{ data.id }}-live-search-desc" class="wp-filter-search"> <div class="search-icon" aria-hidden="true"></div> <span id="{{ data.id }}-live-search-desc" class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'The search results will be updated as you type.' ); ?> </span> </div> </div> <# } else { #> <div class="themes-filter-container"> <label for="{{ data.id }}-themes-filter"><?php _e( 'Search themes' ); ?></label> <div class="search-form-input"> <input type="search" id="{{ data.id }}-themes-filter" aria-describedby="{{ data.id }}-live-search-desc" class="wp-filter-search wp-filter-search-themes" /> <div class="search-icon" aria-hidden="true"></div> <span id="{{ data.id }}-live-search-desc" class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'The search results will be updated as you type.' ); ?> </span> </div> </div> <# } #> <div class="filter-themes-wrapper"> <# if ( 'wporg' === data.action ) { #> <button type="button" class="button feature-filter-toggle"> <span class="filter-count-0"><?php _e( 'Filter themes' ); ?></span><span class="filter-count-filters"> <?php /* translators: %s: Number of filters selected. */ printf( __( 'Filter themes (%s)' ), '<span class="theme-filter-count">0</span>' ); ?> </span> </button> <# } #> <div class="filter-themes-count"> <span class="themes-displayed"> <?php /* translators: %s: Number of themes displayed. */ printf( __( '%s themes' ), '<span class="theme-count">0</span>' ); ?> </span> </div> </div> <?php } /** * Renders the filter drawer portion of a themes section as a JS template. * * The filter bar container is rendered by {@see render_template()}. * * @since 4.9.0 */ protected function filter_drawer_content_template() { /* * @todo Use the .org API instead of the local core feature list. * The .org API is currently outdated and will be reconciled when the .org themes directory is next redesigned. */ $feature_list = get_theme_feature_list( false ); ?> <# if ( 'wporg' === data.action ) { #> <div class="filter-drawer filter-details"> <?php foreach ( $feature_list as $feature_name => $features ) : ?> <fieldset class="filter-group"> <legend><?php echo esc_html( $feature_name ); ?></legend> <div class="filter-group-feature"> <?php foreach ( $features as $feature => $feature_name ) : ?> <input type="checkbox" id="filter-id-<?php echo esc_attr( $feature ); ?>" value="<?php echo esc_attr( $feature ); ?>" /> <label for="filter-id-<?php echo esc_attr( $feature ); ?>"><?php echo esc_html( $feature_name ); ?></label> <?php endforeach; ?> </div> </fieldset> <?php endforeach; ?> </div> <# } #> <?php } } PK [CrZFo�q. q. $ class-wp-customize-theme-control.phpnu �[��� <?php /** * Customize API: WP_Customize_Theme_Control class * * @package WordPress * @subpackage Customize * @since 4.4.0 */ /** * Customize Theme Control class. * * @since 4.2.0 * * @see WP_Customize_Control */ class WP_Customize_Theme_Control extends WP_Customize_Control { /** * Customize control type. * * @since 4.2.0 * @var string */ public $type = 'theme'; /** * Theme object. * * @since 4.2.0 * @var WP_Theme */ public $theme; /** * Refresh the parameters passed to the JavaScript via JSON. * * @since 4.2.0 * * @see WP_Customize_Control::to_json() */ public function to_json() { parent::to_json(); $this->json['theme'] = $this->theme; } /** * Don't render the control content from PHP, as it's rendered via JS on load. * * @since 4.2.0 */ public function render_content() {} /** * Render a JS template for theme display. * * @since 4.2.0 */ public function content_template() { /* translators: %s: Theme name. */ $details_label = sprintf( __( 'Details for theme: %s' ), '{{ data.theme.name }}' ); /* translators: %s: Theme name. */ $customize_label = sprintf( __( 'Customize theme: %s' ), '{{ data.theme.name }}' ); /* translators: %s: Theme name. */ $preview_label = sprintf( __( 'Live preview theme: %s' ), '{{ data.theme.name }}' ); /* translators: %s: Theme name. */ $install_label = sprintf( __( 'Install and preview theme: %s' ), '{{ data.theme.name }}' ); ?> <# if ( data.theme.active ) { #> <div class="theme active" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action"> <# } else { #> <div class="theme" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action"> <# } #> <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #> <div class="theme-screenshot"> <img data-src="{{ data.theme.screenshot[0] }}?ver={{ data.theme.version }}" alt="" /> </div> <# } else { #> <div class="theme-screenshot blank"></div> <# } #> <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 /* translators: Theme author name. */ printf( _x( 'By %s', 'theme author' ), '{{ data.theme.author }}' ); ?> </div> <# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #> <# if ( data.theme.updateResponse.compatibleWP && data.theme.updateResponse.compatiblePHP ) { #> <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}"> <p> <?php if ( is_multisite() ) { _e( 'New version available.' ); } else { printf( /* translators: %s: "Update now" button. */ __( 'New version available. %s' ), '<button class="button-link update-theme" type="button">' . __( 'Update now' ) . '</button>' ); } ?> </p> </div> <# } else { #> <div class="update-message notice inline notice-error notice-alt" data-slug="{{ data.theme.id }}"> <p> <# if ( ! data.theme.updateResponse.compatibleWP && ! data.theme.updateResponse.compatiblePHP ) { #> <?php printf( /* translators: %s: Theme name. */ __( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ), '{{{ data.theme.name }}}' ); if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { printf( /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), self_admin_url( 'update-core.php' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } elseif ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } elseif ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } else if ( ! data.theme.updateResponse.compatibleWP ) { #> <?php printf( /* translators: %s: Theme name. */ __( 'There is a new version of %s available, but it does not work with your version of WordPress.' ), '{{{ data.theme.name }}}' ); if ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } ?> <# } else if ( ! data.theme.updateResponse.compatiblePHP ) { #> <?php printf( /* translators: %s: Theme name. */ __( 'There is a new version of %s available, but it does not work with your version of PHP.' ), '{{{ data.theme.name }}}' ); if ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } #> </p> </div> <# } #> <# } #> <# if ( ! data.theme.compatibleWP || ! data.theme.compatiblePHP ) { #> <div class="notice notice-error notice-alt"><p> <# if ( ! data.theme.compatibleWP && ! data.theme.compatiblePHP ) { #> <?php _e( 'This theme does not work with your versions of WordPress and PHP.' ); if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { printf( /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), self_admin_url( 'update-core.php' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } elseif ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } elseif ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } else if ( ! data.theme.compatibleWP ) { #> <?php _e( 'This theme does not work with your version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } ?> <# } else if ( ! data.theme.compatiblePHP ) { #> <?php _e( 'This theme does not work with your version of PHP.' ); if ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } #> </p></div> <# } #> <# if ( data.theme.active ) { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name"> <span><?php _ex( 'Previewing:', 'theme' ); ?></span> {{ data.theme.name }} </h3> <div class="theme-actions"> <button type="button" class="button button-primary customize-theme" aria-label="<?php echo esc_attr( $customize_label ); ?>"><?php _e( 'Customize' ); ?></button> </div> </div> <?php wp_admin_notice( _x( 'Installed', 'theme' ), array( 'type' => 'success', 'additional_classes' => array( 'notice-alt' ), ) ); ?> <# } else if ( 'installed' === data.theme.type ) { #> <# if ( data.theme.blockTheme ) { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <div class="theme-actions"> <# if ( data.theme.actions.activate ) { #> <?php /* translators: %s: Theme name. */ $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' ); ?> <a href="{{{ data.theme.actions.activate }}}" class="button button-primary activate" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a> <# } #> </div> </div> <?php $customizer_not_supported_message = __( 'This theme doesn\'t support Customizer.' ); ?> <# if ( data.theme.actions.activate ) { #> <?php $customizer_not_supported_message .= ' ' . sprintf( /* translators: %s: URL to the themes page (also it activates the theme). */ __( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ), '{{{ data.theme.actions.activate }}}' ); ?> <# } #> <?php wp_admin_notice( $customizer_not_supported_message, array( 'type' => 'error', 'additional_classes' => array( 'notice-alt' ), ) ); ?> <# } else { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <div class="theme-actions"> <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #> <button type="button" class="button button-primary preview-theme" aria-label="<?php echo esc_attr( $preview_label ); ?>" data-slug="{{ data.theme.id }}"><?php _e( 'Live Preview' ); ?></button> <# } else { #> <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $preview_label ); ?>"><?php _e( 'Live Preview' ); ?></button> <# } #> </div> </div> <?php wp_admin_notice( _x( 'Installed', 'theme' ), array( 'type' => 'success', 'additional_classes' => array( 'notice-alt' ), ) ); ?> <# } #> <# } else { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <div class="theme-actions"> <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #> <button type="button" class="button button-primary theme-install preview" aria-label="<?php echo esc_attr( $install_label ); ?>" data-slug="{{ data.theme.id }}" data-name="{{ data.theme.name }}"><?php _e( 'Install & Preview' ); ?></button> <# } else { #> <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $install_label ); ?>" disabled><?php _e( 'Install & Preview' ); ?></button> <# } #> </div> </div> <# } #> </div> <?php } } PK [CrZ!LX9 9 # class-wp-customize-themes-panel.phpnu �[��� <?php /** * Customize API: WP_Customize_Themes_Panel class * * @package WordPress * @subpackage Customize * @since 4.9.0 */ /** * Customize Themes Panel Class * * @since 4.9.0 * * @see WP_Customize_Panel */ class WP_Customize_Themes_Panel extends WP_Customize_Panel { /** * Panel type. * * @since 4.9.0 * @var string */ public $type = 'themes'; /** * An Underscore (JS) template for rendering this panel's container. * * The themes panel renders a custom panel heading with the active theme and a switch themes button. * * @see WP_Customize_Panel::print_template() * * @since 4.9.0 */ protected function render_template() { ?> <li id="accordion-section-{{ data.id }}" class="accordion-section control-panel-themes"> <h3 class="accordion-section-title"> <?php if ( $this->manager->is_theme_active() ) { echo '<span class="customize-action">' . __( 'Active theme' ) . '</span> {{ data.title }}'; } else { echo '<span class="customize-action">' . __( 'Previewing theme' ) . '</span> {{ data.title }}'; } ?> <?php if ( current_user_can( 'switch_themes' ) ) : ?> <button type="button" class="button change-theme" aria-label="<?php esc_attr_e( 'Change theme' ); ?>"><?php _ex( 'Change', 'theme' ); ?></button> <?php endif; ?> </h3> <ul class="accordion-sub-container control-panel-content"></ul> </li> <?php } /** * An Underscore (JS) template for this panel's content (but not its container). * * Class variables for this panel class are available in the `data` JS object; * export custom variables by overriding WP_Customize_Panel::json(). * * @since 4.9.0 * * @see WP_Customize_Panel::print_template() */ protected function content_template() { ?> <li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>"> <button class="customize-panel-back" tabindex="-1" type="button"><span class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'Back' ); ?> </span></button> <div class="accordion-section-title"> <span class="preview-notice"> <?php printf( /* translators: %s: Themes panel title in the Customizer. */ __( 'You are browsing %s' ), '<strong class="panel-title">' . __( 'Themes' ) . '</strong>' ); // Separate strings for consistency with other panels. ?> </span> <?php if ( current_user_can( 'install_themes' ) && ! is_multisite() ) : ?> <# if ( data.description ) { #> <button class="customize-help-toggle dashicons dashicons-editor-help" type="button" aria-expanded="false"><span class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'Help' ); ?> </span></button> <# } #> <?php endif; ?> </div> <?php if ( current_user_can( 'install_themes' ) && ! is_multisite() ) : ?> <# if ( data.description ) { #> <div class="description customize-panel-description"> {{{ data.description }}} </div> <# } #> <?php endif; ?> <div class="customize-control-notifications-container"></div> </li> <li class="customize-themes-full-container-container"> <div class="customize-themes-full-container"> <div class="customize-themes-notifications"></div> </div> </li> <?php } } PK [CrZ�Y�V V * class-wp-widget-form-customize-control.phpnu �[��� <?php /** * Customize API: WP_Widget_Form_Customize_Control class * * @package WordPress * @subpackage Customize * @since 4.4.0 */ /** * Widget Form Customize Control class. * * @since 3.9.0 * * @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; /** * Gather control params for exporting to JavaScript. * * @since 3.9.0 * * @global array $wp_registered_widgets */ public function to_json() { global $wp_registered_widgets; parent::to_json(); $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' ); foreach ( $exported_properties as $key ) { $this->json[ $key ] = $this->$key; } // Get the widget_control and widget_content. require_once ABSPATH . 'wp-admin/includes/widgets.php'; $widget = $wp_registered_widgets[ $this->widget_id ]; if ( ! isset( $widget['params'][0] ) ) { $widget['params'][0] = array(); } $args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], ); $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']; $this->json['widget_content'] = $widget_control_parts['content']; } /** * Override render_content to be no-op since content is exported via to_json for deferred embedding. * * @since 3.9.0 */ public function render_content() {} /** * Whether the current widget is rendered on the page. * * @since 4.0.0 * * @return bool Whether the widget is rendered. */ public function active_callback() { return $this->manager->widgets->is_widget_rendered( $this->widget_id ); } } PK [CrZe�v v + class-wp-customize-header-image-control.phpnu �[��� <?php /** * Customize API: WP_Customize_Header_Image_Control class * * @package WordPress * @subpackage Customize * @since 4.4.0 */ /** * Customize Header Image Control class. * * @since 3.4.0 * * @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; /** * Constructor. * * @since 3.4.0 * * @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', ) ); } /** */ public function enqueue() { wp_enqueue_media(); wp_enqueue_script( 'customize-views' ); $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, ) ); parent::enqueue(); } /** * @global Custom_Image_Header $custom_image_header */ public function prepare_control() { global $custom_image_header; if ( empty( $custom_image_header ) ) { return; } add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_header_image_template' ) ); // Process default headers and uploaded headers. $custom_image_header->process_default_headers(); $this->default_headers = $custom_image_header->get_default_header_images(); $this->uploaded_headers = $custom_image_header->get_uploaded_header_images(); } /** */ public function print_header_image_template() { ?> <script type="text/template" id="tmpl-header-choice"> <# if (data.random) { #> <button type="button" class="button display-options random"> <span class="dashicons dashicons-randomize dice"></span> <# if ( data.type === 'uploaded' ) { #> <?php _e( 'Randomize uploaded headers' ); ?> <# } else if ( data.type === 'default' ) { #> <?php _e( 'Randomize suggested headers' ); ?> <# } #> </button> <# } else { #> <button type="button" class="choice thumbnail" data-customize-image-value="{{data.header.url}}" data-customize-header-image-data="{{JSON.stringify(data.header)}}"> <span class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'Set image' ); ?> </span> <img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" /> </button> <# if ( data.type === 'uploaded' ) { #> <button type="button" class="dashicons dashicons-no close"> <span class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'Remove image' ); ?> </span> </button> <# } #> <# } #> </script> <script type="text/template" id="tmpl-header-current"> <# if (data.choice) { #> <# if (data.random) { #> <div class="placeholder"> <span class="dashicons dashicons-randomize dice"></span> <# if ( data.type === 'uploaded' ) { #> <?php _e( 'Randomizing uploaded headers' ); ?> <# } else if ( data.type === 'default' ) { #> <?php _e( 'Randomizing suggested headers' ); ?> <# } #> </div> <# } else { #> <img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" /> <# } #> <# } else { #> <div class="placeholder"> <?php _e( 'No image set' ); ?> </div> <# } #> </script> <?php } /** * @return string|void */ public function get_current_image_src() { $src = $this->value(); if ( isset( $this->get_url ) ) { $src = call_user_func( $this->get_url, $src ); return $src; } } /** */ 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' ) ); ?> <div class="customize-control-content"> <?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 “Add New Image” to upload an image file from your computer. Your theme works best with an image that matches the size of your video — you’ll be able to crop your image once you upload it for a perfect fit.' ); } elseif ( $width && $height ) { printf( /* translators: %s: Header size in pixels. */ __( 'Click “Add New Image” to upload an image file from your computer. Your theme works best with an image with a header size of %s pixels — you’ll be able to crop your image once you upload it for a perfect fit.' ), sprintf( '<strong>%s × %s</strong>', $width, $height ) ); } elseif ( $width ) { printf( /* translators: %s: Header width in pixels. */ __( 'Click “Add New Image” to upload an image file from your computer. Your theme works best with an image with a header width of %s pixels — you’ll be able to crop your image once you upload it for a perfect fit.' ), sprintf( '<strong>%s</strong>', $width ) ); } else { printf( /* translators: %s: Header height in pixels. */ __( 'Click “Add New Image” to upload an image file from your computer. Your theme works best with an image with a header height of %s pixels — you’ll be able to crop your image once you upload it for a perfect fit.' ), sprintf( '<strong>%s</strong>', $height ) ); } ?> </p> <div class="current"> <label for="header_image-button"> <span class="customize-control-title"> <?php _e( 'Current header' ); ?> </span> </label> <div class="container"> </div> </div> <div class="actions"> <?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; ?> </div> <div class="choices"> <span class="customize-control-title header-previously-uploaded"> <?php _ex( 'Previously uploaded', 'custom headers' ); ?> </span> <div class="uploaded"> <div class="list"> </div> </div> <span class="customize-control-title header-default"> <?php _ex( 'Suggested', 'custom headers' ); ?> </span> <div class="default"> <div class="list"> </div> </div> </div> </div> <?php } } PK [CrZE���H) H) class-wp-customize-partial.phpnu �[��� <?php /** * Customize API: WP_Customize_Partial class * * @package WordPress * @subpackage Customize * @since 4.5.0 */ /** * Core Customizer class for implementing selective refresh partials. * * Representation of a rendered region in the previewed page that gets * selectively refreshed when an associated setting is changed. * This class is analogous of WP_Customize_Control. * * @since 4.5.0 */ #[AllowDynamicProperties] class WP_Customize_Partial { /** * Component. * * @since 4.5.0 * @var WP_Customize_Selective_Refresh */ public $component; /** * Unique identifier for the partial. * * If the partial is used to display a single setting, this would generally * be the same as the associated setting's ID. * * @since 4.5.0 * @var string */ public $id; /** * Parsed ID. * * @since 4.5.0 * @var array { * @type string $base ID base. * @type array $keys Keys for multidimensional. * } */ protected $id_data = array(); /** * Type of this partial. * * @since 4.5.0 * @var string */ public $type = 'default'; /** * The jQuery selector to find the container element for the partial. * * @since 4.5.0 * @var string */ public $selector; /** * IDs for settings tied to the partial. * * @since 4.5.0 * @var string[] */ public $settings; /** * The ID for the setting that this partial is primarily responsible for rendering. * * If not supplied, it will default to the ID of the first setting. * * @since 4.5.0 * @var string */ public $primary_setting; /** * Capability required to edit this partial. * * Normally this is empty and the capability is derived from the capabilities * of the associated `$settings`. * * @since 4.5.0 * @var string */ public $capability; /** * Render callback. * * @since 4.5.0 * * @see WP_Customize_Partial::render() * @var callable Callback is called with one argument, the instance of * WP_Customize_Partial. The callback can either echo the * partial or return the partial as a string, or return false if error. */ public $render_callback; /** * Whether the container element is included in the partial, or if only the contents are rendered. * * @since 4.5.0 * @var bool */ public $container_inclusive = false; /** * Whether to refresh the entire preview in case a partial cannot be refreshed. * * A partial render is considered a failure if the render_callback returns false. * * @since 4.5.0 * @var bool */ public $fallback_refresh = true; /** * Constructor. * * Supplied `$args` override class property defaults. * * If `$args['settings']` is not defined, use the $id as the setting ID. * * @since 4.5.0 * * @param WP_Customize_Selective_Refresh $component Customize Partial Refresh plugin instance. * @param string $id Control ID. * @param array $args { * Optional. Array of properties for the new Partials object. Default empty array. * * @type string $type Type of the partial to be created. * @type string $selector The jQuery selector to find the container element for the partial, that is, * a partial's placement. * @type string[] $settings IDs for settings tied to the partial. If undefined, `$id` will be used. * @type string $primary_setting The ID for the setting that this partial is primarily responsible for * rendering. If not supplied, it will default to the ID of the first setting. * @type string $capability Capability required to edit this partial. * Normally this is empty and the capability is derived from the capabilities * of the associated `$settings`. * @type callable $render_callback Render callback. * Callback is called with one argument, the instance of WP_Customize_Partial. * The callback can either echo the partial or return the partial as a string, * or return false if error. * @type bool $container_inclusive Whether the container element is included in the partial, or if only * the contents are rendered. * @type bool $fallback_refresh Whether to refresh the entire preview in case a partial cannot be refreshed. * A partial render is considered a failure if the render_callback returns * false. * } */ public function __construct( WP_Customize_Selective_Refresh $component, $id, $args = array() ) { $keys = array_keys( get_object_vars( $this ) ); foreach ( $keys as $key ) { if ( isset( $args[ $key ] ) ) { $this->$key = $args[ $key ]; } } $this->component = $component; $this->id = $id; $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); $this->id_data['base'] = array_shift( $this->id_data['keys'] ); if ( empty( $this->render_callback ) ) { $this->render_callback = array( $this, 'render_callback' ); } // Process settings. if ( ! isset( $this->settings ) ) { $this->settings = array( $id ); } elseif ( is_string( $this->settings ) ) { $this->settings = array( $this->settings ); } if ( empty( $this->primary_setting ) ) { $this->primary_setting = current( $this->settings ); } } /** * Retrieves parsed ID data for multidimensional setting. * * @since 4.5.0 * * @return array { * ID data for multidimensional partial. * * @type string $base ID base. * @type array $keys Keys for multidimensional array. * } */ final public function id_data() { return $this->id_data; } /** * Renders the template partial involving the associated settings. * * @since 4.5.0 * * @param array $container_context Optional. Array of context data associated with the target container (placement). * Default empty array. * @return string|array|false The rendered partial as a string, raw data array (for client-side JS template), * or false if no render applied. */ final public function render( $container_context = array() ) { $partial = $this; $rendered = false; if ( ! empty( $this->render_callback ) ) { ob_start(); $return_render = call_user_func( $this->render_callback, $this, $container_context ); $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' ); } /* * Note that the string return takes precedence because the $ob_render may just\ * include PHP warnings or notices. */ $rendered = null !== $return_render ? $return_render : $ob_render; } /** * Filters partial rendering. * * @since 4.5.0 * * @param string|array|false $rendered The partial value. Default false. * @param WP_Customize_Partial $partial WP_Customize_Setting instance. * @param array $container_context Optional array of context data associated with * the target container. */ $rendered = apply_filters( 'customize_partial_render', $rendered, $partial, $container_context ); /** * Filters partial rendering for a specific partial. * * The dynamic portion of the hook name, `$partial->ID` refers to the partial ID. * * @since 4.5.0 * * @param string|array|false $rendered The partial value. Default false. * @param WP_Customize_Partial $partial WP_Customize_Setting instance. * @param array $container_context Optional array of context data associated with * the target container. */ $rendered = apply_filters( "customize_partial_render_{$partial->id}", $rendered, $partial, $container_context ); return $rendered; } /** * Default callback used when invoking WP_Customize_Control::render(). * * Note that this method may echo the partial *or* return the partial as * a string or array, but not both. Output buffering is performed when this * is called. Subclasses can override this with their specific logic, or they * may provide an 'render_callback' argument to the constructor. * * This method may return an HTML string for straight DOM injection, or it * may return an array for supporting Partial JS subclasses to render by * applying to client-side templating. * * @since 4.5.0 * * @param WP_Customize_Partial $partial Partial. * @param array $context Context. * @return string|array|false */ public function render_callback( WP_Customize_Partial $partial, $context = array() ) { unset( $partial, $context ); return false; } /** * Retrieves the data to export to the client via JSON. * * @since 4.5.0 * * @return array Array of parameters passed to the JavaScript. */ public function json() { $exports = array( 'settings' => $this->settings, 'primarySetting' => $this->primary_setting, 'selector' => $this->selector, 'type' => $this->type, 'fallbackRefresh' => $this->fallback_refresh, 'containerInclusive' => $this->container_inclusive, ); return $exports; } /** * Checks if the user can refresh this partial. * * Returns false if the user cannot manipulate one of the associated settings, * or if one of the associated settings does not exist. * * @since 4.5.0 * * @return bool False if user can't edit one of the related settings, * or if one of the associated settings does not exist. */ final public function check_capabilities() { if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) { return false; } foreach ( $this->settings as $setting_id ) { $setting = $this->component->manager->get_setting( $setting_id ); if ( ! $setting || ! $setting->check_capabilities() ) { return false; } } return true; } } PK [CrZ�Mf�# # &