WP_Customize_Nav_Menus
- Since
- 4.3.0
- Source
wp-includes/class-wp-customize-nav-menus.php:19
Customize Nav Menus class.
Description
Implements menu management in the Customizer.
Compatibility
- WordPress
- since 4.3.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 3
Every hook that fires from inside WP_Customize_Nav_Menus, in the order it appears in the class, grouped by the method that fires it.
WP_Customize_Nav_Menus::load_available_items_query()
- apply_filters( customize_nav_menu_available_items )filter line 307
Properties · 3
$managerWP_Customize_Managerpublic- WP_Customize_Manager instance.
Methods · 30
- __construct()Constructor.
- filter_nonces()Adds a nonce for customizing menus.
- ajax_load_available_items()Ajax handler for loading available menu items.
- load_available_items_query()Performs the post_type and taxonomy queries for loading available menu items.
- ajax_search_available_items()Ajax handler for searching available menu items.
- search_available_items_query()Performs post queries for available-item searching.
- enqueue_scripts()Enqueues scripts and styles for Customizer pane.
- filter_dynamic_setting_args()Filters a dynamic setting's constructor args.
- filter_dynamic_setting_class()Allows non-statically created settings to be constructed with custom WP_Customize_Setting subclass.
- customize_register()Adds the customizer settings and controls.
- intval_base10()Gets the base10 intval.
- available_item_types()Returns an array of all the available item types.
- insert_auto_draft_post()Adds a new `auto-draft` post.
- ajax_insert_auto_draft_post()Ajax handler for adding a new auto-draft post.
- print_templates()Prints the JavaScript templates used to render Menu Customizer components.
- available_items_template()Prints the HTML template used to render the add-menu-item frame.
- print_post_type_container()Prints the markup for new menu items.
- print_custom_links_available_menu_item()Prints the markup for available menu item custom links.
- customize_dynamic_partial_args()Filters arguments for dynamic nav_menu selective refresh partials.
- customize_preview_init()Adds hooks for the Customizer preview.
- make_auto_draft_status_previewable()Makes the auto-draft status protected so that it can be queried.
- sanitize_nav_menus_created_posts()Sanitizes post IDs for posts created for nav menu items to be published.
- save_nav_menus_created_posts()Publishes the auto-draft posts that were created for nav menu items.
- filter_wp_nav_menu_args()Keeps track of the arguments that are being passed to wp_nav_menu().
- filter_wp_nav_menu()Prepares wp_nav_menu() calls for partial refresh.
- hash_nav_menu_args()Hashes (hmac) the nav menu arguments to ensure they are not tampered with when submitted in the Ajax request.
- customize_preview_enqueue_deps()Enqueues scripts for the Customizer preview.
- export_preview_data()Exports data from PHP to JS.
- export_partial_rendered_nav_menu_instances()Exports any wp_nav_menu() calls during the rendering of any partials.
- render_nav_menu_partial()Renders a specific menu via wp_nav_menu() using the supplied arguments.
Source code
#[AllowDynamicProperties]final class WP_Customize_Nav_Menus { /** * WP_Customize_Manager instance. * * @since 4.3.0 * @var WP_Customize_Manager */ public $manager; /** * Original nav menu locations before the theme was switched. * * @since 4.9.0 * @var array */ protected $original_nav_menu_locations; /** * Constructor. * * @since 4.3.0 * * @param WP_Customize_Manager $manager Customizer bootstrap instance. */ public function __construct( $manager ) { $this->manager = $manager; $this->original_nav_menu_locations = get_nav_menu_locations(); // See https://github.com/xwp/wp-customize-snapshots/blob/962586659688a5b1fd9ae93618b7ce2d4e7a421c/php/class-customize-snapshot-manager.php#L469-L499 add_action( 'customize_register', array( $this, 'customize_register' ), 11 ); add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_dynamic_setting_args' ), 10, 2 ); add_filter( 'customize_dynamic_setting_class', array( $this, 'filter_dynamic_setting_class' ), 10, 3 ); add_action( 'customize_save_nav_menus_created_posts', array( $this, 'save_nav_menus_created_posts' ) ); // Skip remaining hooks when the user can't manage nav menus anyway. if ( ! current_user_can( 'edit_theme_options' ) ) { return; } add_filter( 'customize_refresh_nonces', array( $this, 'filter_nonces' ) ); add_action( 'wp_ajax_load-available-menu-items-customizer', array( $this, 'ajax_load_available_items' ) ); add_action( 'wp_ajax_search-available-menu-items-customizer', array( $this, 'ajax_search_available_items' ) ); add_action( 'wp_ajax_customize-nav-menus-insert-auto-draft', array( $this, 'ajax_insert_auto_draft_post' ) ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_templates' ) ); add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) ); add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) ); add_action( 'customize_preview_init', array( $this, 'make_auto_draft_status_previewable' ) ); // Selective Refresh partials. add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 ); } /** * 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' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); }Changelog
Introduced in 4.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/class-wp-customize-nav-menus.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.