IP : 18.191.50.203Hostname : server86.web-hosting.comKernel : Linux server86.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64Disable Function : None :) OS : Linux
PATH:
/
home/
./
servlmvm/
public_html/
wp-includes/
class-wp-customize-nav-menus.php/
/
/** * Customize Nav Menus class. * * Implements menu management in the Customizer. * * @since 4.3.0 * * @see WP_Customize_Manager */ #[AllowDynamicProperties] final class WP_Customize_Nav_Menus {
/** * Adds a nonce for customizing menus. * * @since 4.5.0 * * @param string[] $nonces Array of nonces. * @return string[] Modified array of nonces. */ public function filter_nonces( $nonces ) { $nonces['customize-menus'] = wp_create_nonce( 'customize-menus' ); return $nonces; }
/** * Ajax handler for loading available menu items. * * @since 4.3.0 */ public function ajax_load_available_items() { check_ajax_referer( 'customize-menus', 'customize-menus-nonce' );
/** * Performs the post_type and taxonomy queries for loading available menu items. * * @since 4.3.0 * * @param string $object_type Optional. Accepts any custom object type and has built-in support for * 'post_type' and 'taxonomy'. Default is 'post_type'. * @param string $object_name Optional. Accepts any registered taxonomy or post type name. Default is 'page'. * @param int $page Optional. The page number used to generate the query offset. Default is '0'. * @return array|WP_Error An array of menu items on success, a WP_Error object on failure. */ public function load_available_items_query( $object_type = 'post_type', $object_name = 'page', $page = 0 ) { $items = array();
if ( 'post_type' === $object_type ) { $post_type = get_post_type_object( $object_name ); if ( ! $post_type ) { return new WP_Error( 'nav_menus_invalid_post_type' ); }
/* * If we're dealing with pages, let's prioritize the Front Page, * Posts Page and Privacy Policy Page at the top of the list. */ $important_pages = array(); $suppress_page_ids = array(); if ( 0 === $page && 'page' === $object_name ) { // Insert Front Page or custom "Home" link. $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; if ( ! empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $important_pages[] = $front_page_obj; $suppress_page_ids[] = $front_page_obj->ID; } else { // Add "Home" link. Treat as a page, but switch to custom on add. $items[] = array( 'id' => 'home', 'title' => _x( 'Home', 'nav menu home label' ), 'type' => 'custom', 'type_label' => __( 'Custom Link' ), 'object' => '', 'url' => home_url(), ); }
/** * Filters the available menu items. * * @since 4.3.0 * * @param array $items The array of menu items. * @param string $object_type The object type. * @param string $object_name The object name. * @param int $page The current page number. */ $items = apply_filters( 'customize_nav_menu_available_items', $items, $object_type, $object_name, $page );
return $items; }
/** * Ajax handler for searching available menu items. * * @since 4.3.0 */ public function ajax_search_available_items() { check_ajax_referer( 'customize-menus', 'customize-menus-nonce' );
// Add "Home" link if search term matches. Treat as a page, but switch to custom on add. if ( isset( $args['s'] ) ) { // Only insert custom "Home" link if there's no Front Page $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; if ( empty( $front_page ) ) { $title = _x( 'Home', 'nav menu home label' ); $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] ); if ( $matches ) { $items[] = array( 'id' => 'home', 'title' => $title, 'type' => 'custom', 'type_label' => __( 'Custom Link' ), 'object' => '', 'url' => home_url(), ); } } }
/** * Filters the available menu items during a search request. * * @since 4.5.0 * * @param array $items The array of menu items. * @param array $args Includes 'pagenum' and 's' (search) arguments. */ $items = apply_filters( 'customize_nav_menu_searched_items', $items, $args );
return $items; }
/** * Enqueues scripts and styles for Customizer pane. * * @since 4.3.0 */ public function enqueue_scripts() { wp_enqueue_style( 'customize-nav-menus' ); wp_enqueue_script( 'customize-nav-menus' );
$temp_nav_menu_setting = new WP_Customize_Nav_Menu_Setting( $this->manager, 'nav_menu[-1]' ); $temp_nav_menu_item_setting = new WP_Customize_Nav_Menu_Item_Setting( $this->manager, 'nav_menu_item[-1]' );
// This is copied from nav-menus.php, and it has an unfortunate object name of `menus`. $nav_menus_l10n = array( 'oneThemeLocationNoMenus' => null, 'moveUp' => __( 'Move up one' ), 'moveDown' => __( 'Move down one' ), 'moveToTop' => __( 'Move to the top' ), /* translators: %s: Previous item name. */ 'moveUnder' => __( 'Move under %s' ), /* translators: %s: Previous item name. */ 'moveOutFrom' => __( 'Move out from under %s' ), /* translators: %s: Previous item name. */ 'under' => __( 'Under %s' ), /* translators: %s: Previous item name. */ 'outFrom' => __( 'Out from under %s' ), /* translators: 1: Item name, 2: Item type, 3: Item index, 4: Total items. */ 'menuFocus' => __( 'Edit %1$s (%2$s, %3$d of %4$d)' ), /* translators: 1: Item name, 2: Item type, 3: Item index, 4: Total items, 5: Item parent. */ 'subMenuFocus' => __( 'Edit %1$s (%2$s, sub-item %3$d of %4$d under %5$s)' ), /* translators: 1: Item name, 2: Item type, 3: Item index, 4: Total items, 5: Item parent, 6: Item depth. */ 'subMenuMoreDepthFocus' => __( 'Edit %1$s (%2$s, sub-item %3$d of %4$d under %5$s, level %6$d)' ), ); wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); }
/** * Filters a dynamic setting's constructor args. * * For a dynamic setting to be registered, this filter must be employed * to override the default false value with an array of args to pass to * the WP_Customize_Setting constructor. * * @since 4.3.0 * * @param false|array $setting_args The arguments to the WP_Customize_Setting constructor. * @param string $setting_id ID for dynamic setting, usually coming from `$_POST['customized']`. * @return array|false */ public function filter_dynamic_setting_args( $setting_args, $setting_id ) { if ( preg_match( WP_Customize_Nav_Menu_Setting::ID_PATTERN, $setting_id ) ) { $setting_args = array( 'type' => WP_Customize_Nav_Menu_Setting::TYPE, 'transport' => 'postMessage', ); } elseif ( preg_match( WP_Customize_Nav_Menu_Item_Setting::ID_PATTERN, $setting_id ) ) { $setting_args = array( 'type' => WP_Customize_Nav_Menu_Item_Setting::TYPE, 'transport' => 'postMessage', ); } return $setting_args; }
/** * Allows non-statically created settings to be constructed with custom WP_Customize_Setting subclass. * * @since 4.3.0 * * @param string $setting_class WP_Customize_Setting or a subclass. * @param string $setting_id ID for dynamic setting, usually coming from `$_POST['customized']`. * @param array $setting_args WP_Customize_Setting or a subclass. * @return string */ public function filter_dynamic_setting_class( $setting_class, $setting_id, $setting_args ) { unset( $setting_id );
/** * Adds the customizer settings and controls. * * @since 4.3.0 */ public function customize_register() { $changeset = $this->manager->unsanitized_post_values();
// Preview settings for nav menus early so that the sections and controls will be added properly. $nav_menus_setting_ids = array(); foreach ( array_keys( $changeset ) as $setting_id ) { if ( preg_match( '/^(nav_menu_locations|nav_menu|nav_menu_item)\[/', $setting_id ) ) { $nav_menus_setting_ids[] = $setting_id; } } $settings = $this->manager->add_dynamic_settings( $nav_menus_setting_ids ); if ( $this->manager->settings_previewed() ) { foreach ( $settings as $setting ) { $setting->preview(); } }
// Create a panel for Menus. $description = '<p>' . __( 'This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.' ) . '</p>'; if ( current_theme_supports( 'widgets' ) ) { $description .= '<p>' . sprintf( /* translators: %s: URL to the Widgets panel of the Customizer. */ __( 'Menus can be displayed in locations defined by your theme or in <a href="%s">widget areas</a> by adding a “Navigation Menu” widget.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '</p>'; } else { $description .= '<p>' . __( 'Menus can be displayed in locations defined by your theme.' ) . '</p>'; }
/* * Once multiple theme supports are allowed in WP_Customize_Panel, * this panel can be restricted to themes that support menus or widgets. */ $this->manager->add_panel( new WP_Customize_Nav_Menus_Panel( $this->manager, 'nav_menus', array( 'title' => __( 'Menus' ), 'description' => $description, 'priority' => 100, ) ) ); $menus = wp_get_nav_menus();
if ( 1 === $num_locations ) { $description = '<p>' . __( 'Your theme can display menus in one location. Select which menu you would like to use.' ) . '</p>'; } else { /* translators: %s: Number of menu locations. */ $description = '<p>' . sprintf( _n( 'Your theme can display menus in %s location. Select which menu you would like to use.', 'Your theme can display menus in %s locations. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>'; }
if ( current_theme_supports( 'widgets' ) ) { /* translators: URL to the Widgets panel of the Customizer. */ $description .= '<p>' . sprintf( __( 'If your theme has widget areas, you can also add menus there. Visit the <a href="%s">Widgets panel</a> and add a “Navigation Menu widget” to display a menu in a sidebar or footer.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '</p>'; }
// Attempt to re-map the nav menu location assignments when previewing a theme switch. $mapped_nav_menu_locations = array(); if ( ! $this->manager->is_theme_active() ) { $theme_mods = get_option( 'theme_mods_' . $this->manager->get_stylesheet(), array() );
// If there is no data from a previous activation, start fresh. if ( empty( $theme_mods['nav_menu_locations'] ) ) { $theme_mods['nav_menu_locations'] = array(); }
// Used to denote post states for special pages. if ( ! function_exists( 'get_post_states' ) ) { require_once ABSPATH . 'wp-admin/includes/template.php'; }
// Register each menu as a Customizer section, and add each menu item to each menu. foreach ( $menus as $menu ) { $menu_id = $menu->term_id;
// Create a section for each menu. $section_id = 'nav_menu[' . $menu_id . ']'; $this->manager->add_section( new WP_Customize_Nav_Menu_Section( $this->manager, $section_id, array( 'title' => html_entity_decode( $menu->name, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'priority' => 10, 'panel' => 'nav_menus', ) ) );
// Create a control for each menu item. $this->manager->add_control( new WP_Customize_Nav_Menu_Item_Control( $this->manager, $menu_item_setting_id, array( 'label' => $item->title, 'section' => $section_id, 'priority' => 10 + $i, ) ) ); }
// Note: other controls inside of this section get added dynamically in JS via the MenuSection.ready() function. }
/** * Gets the base10 intval. * * This is used as a setting's sanitize_callback; we can't use just plain * intval because the second argument is not what intval() expects. * * @since 4.3.0 * * @param mixed $value Number to convert. * @return int Integer. */ public function intval_base10( $value ) { return intval( $value, 10 ); }
/** * Returns an array of all the available item types. * * @since 4.3.0 * @since 4.7.0 Each array item now includes a `$type_label` in addition to `$title`, `$type`, and `$object`. * * @return array The available menu item types. */ public function available_item_types() { $item_types = array();
/** * Filters the available menu item types. * * @since 4.3.0 * @since 4.7.0 Each array item now includes a `$type_label` in addition to `$title`, `$type`, and `$object`. * * @param array $item_types Navigation menu item types. */ $item_types = apply_filters( 'customize_nav_menu_available_item_types', $item_types );
return $item_types; }
/** * Adds a new `auto-draft` post. * * @since 4.7.0 * * @param array $postarr { * Post array. Note that post_status is overridden to be `auto-draft`. * * @type string $post_title Post title. Required. * @type string $post_type Post type. Required. * @type string $post_name Post name. * @type string $post_content Post content. * } * @return WP_Post|WP_Error Inserted auto-draft post object or error. */ public function insert_auto_draft_post( $postarr ) { if ( ! isset( $postarr['post_type'] ) ) { return new WP_Error( 'unknown_post_type', __( 'Invalid post type.' ) ); } if ( empty( $postarr['post_title'] ) ) { return new WP_Error( 'empty_title', __( 'Empty title.' ) ); } if ( ! empty( $postarr['post_status'] ) ) { return new WP_Error( 'status_forbidden', __( 'Status is forbidden.' ) ); }
/* * If the changeset is a draft, this will change to draft the next time the changeset * is updated; otherwise, auto-draft will persist in autosave revisions, until save. */ $postarr['post_status'] = 'auto-draft';
// Auto-drafts are allowed to have empty post_names, so it has to be explicitly set. if ( empty( $postarr['post_name'] ) ) { $postarr['post_name'] = sanitize_title( $postarr['post_title'] ); } if ( ! isset( $postarr['meta_input'] ) ) { $postarr['meta_input'] = array(); } $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name']; $postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid(); unset( $postarr['post_name'] );
/** * Ajax handler for adding a new auto-draft post. * * @since 4.7.0 */ public function ajax_insert_auto_draft_post() { if ( ! check_ajax_referer( 'customize-menus', 'customize-menus-nonce', false ) ) { wp_send_json_error( 'bad_nonce', 400 ); }
<script type="text/html" id="tmpl-nav-menu-create-menu-section-title"> <p class="add-new-menu-notice"> <?php _e( 'It does not look like your site has any menus yet. Want to build one? Click the button to start.' ); ?> </p> <p class="add-new-menu-notice"> <?php _e( 'You’ll create a menu, assign it a location, and add menu items like links to pages and categories. If your theme has multiple menu areas, you might need to create more than one.' ); ?> </p> <h3> <button type="button" class="button customize-add-menu-button"> <?php _e( 'Create New Menu' ); ?> </button> </h3> </script> <?php }
/** * Prints the HTML template used to render the add-menu-item frame. * * @since 4.3.0 */ public function available_items_template() { ?> <div id="available-menu-items" class="accordion-container"> <div class="customize-section-title"> <button type="button" class="customize-section-back" tabindex="-1"> <span class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'Back' ); ?> </span> </button> <h3> <span class="customize-action"> <?php /* translators: ▸ is the unicode right-pointing triangle. %s: Section title in the Customizer. */ printf( __( 'Customizing ▸ %s' ), esc_html( $this->manager->get_panel( 'nav_menus' )->title ) ); ?> </span> <?php _e( 'Add Menu Items' ); ?> </h3> </div> <div id="available-menu-items-search" class="accordion-section cannot-expand"> <div class="accordion-section-title"> <label for="menu-items-search"><?php _e( 'Search Menu Items' ); ?></label> <input type="text" id="menu-items-search" aria-describedby="menu-items-search-desc" /> <p class="screen-reader-text" id="menu-items-search-desc"> <?php /* translators: Hidden accessibility text. */ _e( 'The search results will be updated as you type.' ); ?> </p> <span class="spinner"></span> <div class="search-icon" aria-hidden="true"></div> <button type="button" class="clear-results"><span class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'Clear Results' ); ?> </span></button> </div> <ul class="accordion-section-content available-menu-items-list" data-type="search"></ul> </div> <?php
// Ensure the page post type comes first in the list. $item_types = $this->available_item_types(); $page_item_type = null; foreach ( $item_types as $i => $item_type ) { if ( isset( $item_type['object'] ) && 'page' === $item_type['object'] ) { $page_item_type = $item_type; unset( $item_types[ $i ] ); } }
$this->print_custom_links_available_menu_item(); if ( $page_item_type ) { $this->print_post_type_container( $page_item_type ); } // Containers for per-post-type item browsing; items are added with JS. foreach ( $item_types as $item_type ) { $this->print_post_type_container( $item_type ); } ?> </div><!-- #available-menu-items --> <?php }
if ( preg_match( '/^nav_menu_instance\[[0-9a-f]{32}\]$/', $partial_id ) ) { if ( false === $partial_args ) { $partial_args = array(); } $partial_args = array_merge( $partial_args, array( 'type' => 'nav_menu_instance', 'render_callback' => array( $this, 'render_nav_menu_partial' ), 'container_inclusive' => true, 'settings' => array(), // Empty because the nav menu instance may relate to a menu or a location. 'capability' => 'edit_theme_options', ) ); }
/** * Makes the auto-draft status protected so that it can be queried. * * @since 4.7.0 * * @global stdClass[] $wp_post_statuses List of post statuses. */ public function make_auto_draft_status_previewable() { global $wp_post_statuses; $wp_post_statuses['auto-draft']->protected = true; }
/** * Sanitizes post IDs for posts created for nav menu items to be published. * * @since 4.7.0 * * @param array $value Post IDs. * @return array Post IDs. */ public function sanitize_nav_menus_created_posts( $value ) { $post_ids = array(); foreach ( wp_parse_id_list( $value ) as $post_id ) { if ( empty( $post_id ) ) { continue; } $post = get_post( $post_id ); if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) { continue; } $post_type_obj = get_post_type_object( $post->post_type ); if ( ! $post_type_obj ) { continue; } if ( ! current_user_can( $post_type_obj->cap->publish_posts ) || ! current_user_can( 'edit_post', $post_id ) ) { continue; } $post_ids[] = $post->ID; } return $post_ids; }
/** * Publishes the auto-draft posts that were created for nav menu items. * * The post IDs will have been sanitized by already by * `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to * remove any post IDs for which the user cannot publish or for which the * post is not an auto-draft. * * @since 4.7.0 * * @param WP_Customize_Setting $setting Customizer setting object. */ public function save_nav_menus_created_posts( $setting ) { $post_ids = $setting->post_value(); if ( ! empty( $post_ids ) ) { foreach ( $post_ids as $post_id ) {
// Prevent overriding the status that a user may have prematurely updated the post to. $current_status = get_post_status( $post_id ); if ( 'auto-draft' !== $current_status && 'draft' !== $current_status ) { continue; }
/** * Keeps track of the arguments that are being passed to wp_nav_menu(). * * @since 4.3.0 * * @see wp_nav_menu() * @see WP_Customize_Widgets::filter_dynamic_sidebar_params() * * @param array $args An array containing wp_nav_menu() arguments. * @return array Arguments. */ public function filter_wp_nav_menu_args( $args ) { /* * The following conditions determine whether or not this instance of * wp_nav_menu() can use selective refreshed. A wp_nav_menu() can be * selective refreshed if... */ $can_partial_refresh = ( // ...if wp_nav_menu() is directly echoing out the menu (and thus isn't manipulating the string after generated), ! empty( $args['echo'] ) && // ...and if the fallback_cb can be serialized to JSON, since it will be included in the placement context data, ( empty( $args['fallback_cb'] ) || is_string( $args['fallback_cb'] ) ) && // ...and if the walker can also be serialized to JSON, since it will be included in the placement context data as well, ( empty( $args['walker'] ) || is_string( $args['walker'] ) ) // ...and if it has a theme location assigned or an assigned menu to display, && ( ! empty( $args['theme_location'] ) || ( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) ) ) && // ...and if the nav menu would be rendered with a wrapper container element (upon which to attach data-* attributes). ( ! empty( $args['container'] ) || ( isset( $args['items_wrap'] ) && str_starts_with( $args['items_wrap'], '<' ) ) ) ); $args['can_partial_refresh'] = $can_partial_refresh;
$exported_args = $args;
// Empty out args which may not be JSON-serializable. if ( ! $can_partial_refresh ) { $exported_args['fallback_cb'] = ''; $exported_args['walker'] = ''; }
/* * Replace object menu arg with a term_id menu arg, as this exports better * to JS and is easier to compare hashes. */ if ( ! empty( $exported_args['menu'] ) && is_object( $exported_args['menu'] ) ) { $exported_args['menu'] = $exported_args['menu']->term_id; }
/** * Prepares wp_nav_menu() calls for partial refresh. * * Injects attributes into container element. * * @since 4.3.0 * * @see wp_nav_menu() * * @param string $nav_menu_content The HTML content for the navigation menu. * @param object $args An object containing wp_nav_menu() arguments. * @return string Nav menu HTML with selective refresh attributes added if partial can be refreshed. */ public function filter_wp_nav_menu( $nav_menu_content, $args ) { if ( isset( $args->customize_preview_nav_menus_args['can_partial_refresh'] ) && $args->customize_preview_nav_menus_args['can_partial_refresh'] ) { $attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'nav_menu_instance[' . $args->customize_preview_nav_menus_args['args_hmac'] . ']' ) ); $attributes .= ' data-customize-partial-type="nav_menu_instance"'; $attributes .= sprintf( ' data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $args->customize_preview_nav_menus_args ) ) ); $nav_menu_content = preg_replace( '#^(<\w+)#', '$1 ' . str_replace( '\\', '\\\\', $attributes ), $nav_menu_content, 1 ); } return $nav_menu_content; }
/** * Hashes (hmac) the nav menu arguments to ensure they are not tampered with when * submitted in the Ajax request. * * Note that the array is expected to be pre-sorted. * * @since 4.3.0 * * @param array $args The arguments to hash. * @return string Hashed nav menu arguments. */ public function hash_nav_menu_args( $args ) { return wp_hash( serialize( $args ) ); }
/** * Enqueues scripts for the Customizer preview. * * @since 4.3.0 */ public function customize_preview_enqueue_deps() { wp_enqueue_script( 'customize-preview-nav-menus' ); // Note that we have overridden this. }
/** * Exports data from PHP to JS. * * @since 4.3.0 */ public function export_preview_data() {
// Why not wp_localize_script? Because we're not localizing, and it forces values into strings. $exports = array( 'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args, ); wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports ) ) ); }
/** * Exports any wp_nav_menu() calls during the rendering of any partials. * * @since 4.5.0 * * @param array $response Response. * @return array Response. */ public function export_partial_rendered_nav_menu_instances( $response ) { $response['nav_menu_instance_args'] = $this->preview_nav_menu_instance_args; return $response; }
/** * Renders a specific menu via wp_nav_menu() using the supplied arguments. * * @since 4.3.0 * * @see wp_nav_menu() * * @param WP_Customize_Partial $partial Partial. * @param array $nav_menu_args Nav menu args supplied as container context. * @return string|false */ public function render_nav_menu_partial( $partial, $nav_menu_args ) { unset( $partial );