Class: WP_Customize_Nav_Menus

Customize Nav Menus class.

Implements menu management in the Customizer.


Properties

Name Type(s) Default Value Summary
manager WP_Customize_Manager WP_Customize_Manager instance.
original_nav_menu_locations array Original nav menu locations before the theme was switched.
preview_nav_menu_instance_args array Nav menu args used for each instance, keyed by the args HMAC.

Methods

WP_Customize_Nav_Menus:: __construct( object $manager )

Constructor. Since 4.3.0.

Arguments

Name Type(s) Default Value Description
$manager object

An instance of the WP_Customize_Manager class.


WP_Customize_Nav_Menus:: ajax_insert_auto_draft_post( )

Ajax handler for adding a new auto-draft post. Since 4.7.0.


WP_Customize_Nav_Menus:: ajax_load_available_items( )

Ajax handler for loading available menu items. Since 4.3.0.


WP_Customize_Nav_Menus:: ajax_search_available_items( )

Ajax handler for searching available menu items. Since 4.3.0.


WP_Customize_Nav_Menus:: available_item_types( )

Return an array of all the available item types. Since 4.3.0. Since 4.7.0.

Returns

array

The available menu item types.


WP_Customize_Nav_Menus:: available_items_template( )

Print the html template used to render the add-menu-item frame. Since 4.3.0.


WP_Customize_Nav_Menus:: customize_dynamic_partial_args( array | false $partial_args, string $partial_id )

Filters arguments for dynamic nav_menu selective refresh partials. Since 4.5.0.

Arguments

Name Type(s) Default Value Description
$partial_args array | false

Partial args.

$partial_id string

Partial ID.

Returns

array

Partial args.


WP_Customize_Nav_Menus:: customize_preview_enqueue_deps( )

Enqueue scripts for the Customizer preview. Since 4.3.0.


WP_Customize_Nav_Menus:: customize_preview_init( )

Add hooks for the Customizer preview. Since 4.3.0.


WP_Customize_Nav_Menus:: customize_register( )

Add the customizer settings and controls. Since 4.3.0.


WP_Customize_Nav_Menus:: enqueue_scripts( )

Enqueue scripts and styles for Customizer pane. Since 4.3.0.


WP_Customize_Nav_Menus:: export_partial_rendered_nav_menu_instances( array $response )

Export any wp_nav_menu() calls during the rendering of any partials. Since 4.5.0.

Arguments

Name Type(s) Default Value Description
$response array

Response.

Returns

array

Response.


WP_Customize_Nav_Menus:: export_preview_data( )

Exports data from PHP to JS. Since 4.3.0.


WP_Customize_Nav_Menus:: filter_dynamic_setting_args( false | array $setting_args, string $setting_id )

Filters a dynamic setting's constructor args. Since 4.3.0.

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.

Arguments

Name Type(s) Default Value Description
$setting_args false | array

The arguments to the WP_Customize_Setting constructor.

$setting_id string

ID for dynamic setting, usually coming from $_POST['customized'].

Returns

array | false


WP_Customize_Nav_Menus:: filter_dynamic_setting_class( string $setting_class, string $setting_id, array $setting_args )

Allow non-statically created settings to be constructed with custom WP_Customize_Setting subclass. Since 4.3.0.

Arguments

Name Type(s) Default Value Description
$setting_class string

WP_Customize_Setting or a subclass.

$setting_id string

ID for dynamic setting, usually coming from $_POST['customized'].

$setting_args array

WP_Customize_Setting or a subclass.

Returns

string


WP_Customize_Nav_Menus:: filter_nonces( array<mixed,string> $nonces )

Adds a nonce for customizing menus. Since 4.5.0.

Arguments

Name Type(s) Default Value Description
$nonces array<mixed,string>

Array of nonces.

Returns

array<mixed,string>

$nonces Modified array of nonces.


WP_Customize_Nav_Menus:: filter_wp_nav_menu( string $nav_menu_content, object $args )

Prepares wp_nav_menu() calls for partial refresh. Since 4.3.0.

Injects attributes into container element.

Arguments

Name Type(s) Default Value Description
$nav_menu_content string

The HTML content for the navigation menu.

$args object

An object containing wp_nav_menu() arguments.

Returns

string

Nav menu HTML with selective refresh attributes added if partial can be refreshed.


WP_Customize_Nav_Menus:: filter_wp_nav_menu_args( array $args )

Keep track of the arguments that are being passed to wp_nav_menu(). Since 4.3.0.

Arguments

Name Type(s) Default Value Description
$args array

An array containing wp_nav_menu() arguments.

Returns

array

Arguments.


WP_Customize_Nav_Menus:: hash_nav_menu_args( array $args )

Hashes (hmac) the nav menu arguments to ensure they are not tampered with when submitted in the Ajax request. Since 4.3.0.

Note that the array is expected to be pre-sorted.

Arguments

Name Type(s) Default Value Description
$args array

The arguments to hash.

Returns

string

Hashed nav menu arguments.


WP_Customize_Nav_Menus:: insert_auto_draft_post( array $postarr )

Add a new `auto-draft` post. Since 4.7.0.

Arguments

Name Type(s) Default Value Description
$postarr array

{ Post array. Note that post_status is overridden to be auto-draft.

Returns

WP_Post | WP_Error

Inserted auto-draft post object or error.


WP_Customize_Nav_Menus:: intval_base10( mixed $value )

Get the base10 intval. Since 4.3.0.

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.

Arguments

Name Type(s) Default Value Description
$value mixed

Number to convert.

Returns

integer

Integer.


WP_Customize_Nav_Menus:: load_available_items_query( string $type = 'post_type', string $object = 'page', integer $page )

Performs the post_type and taxonomy queries for loading available menu items. Since 4.3.0.

Arguments

Name Type(s) Default Value Description
$type string

Optional. Accepts any custom object type and has built-in support for 'post_type' and 'taxonomy'. Default is 'post_type'.

$object string

Optional. Accepts any registered taxonomy or post type name. Default is 'page'.

$page integer

Optional. The page number used to generate the query offset. Default is '0'.

Returns

WP_Error | array

Returns either a WP_Error object or an array of menu items.


WP_Customize_Nav_Menus:: make_auto_draft_status_previewable( )

Make the auto-draft status protected so that it can be queried. Since 4.7.0.


Print the markup for available menu item custom links. Since 4.7.0.


WP_Customize_Nav_Menus:: print_post_type_container( array $available_item_type )

Print the markup for new menu items. Since 4.7.0.

To be used in the template #available-menu-items.

Arguments

Name Type(s) Default Value Description
$available_item_type array

Menu item data to output, including title, type, and label.


WP_Customize_Nav_Menus:: print_templates( )

Print the JavaScript templates used to render Menu Customizer components. Since 4.3.0.

Templates are imported into the JS use wp.template.


WP_Customize_Nav_Menus:: render_nav_menu_partial( WP_Customize_Partial $partial, array $nav_menu_args )

Render a specific menu via wp_nav_menu() using the supplied arguments. Since 4.3.0.

Arguments

Name Type(s) Default Value Description
$partial WP_Customize_Partial

Partial.

$nav_menu_args array

Nav menu args supplied as container context.

Returns

string | false


WP_Customize_Nav_Menus:: sanitize_nav_menus_created_posts( array $value )

Sanitize post IDs for posts created for nav menu items to be published. Since 4.7.0.

Arguments

Name Type(s) Default Value Description
$value array

Post IDs.


WP_Customize_Nav_Menus:: save_nav_menus_created_posts( WP_Customize_Setting $setting )

Publish the auto-draft posts that were created for nav menu items. Since 4.7.0.

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.

Arguments

Name Type(s) Default Value Description
$setting WP_Customize_Setting

Customizer setting object.


WP_Customize_Nav_Menus:: search_available_items_query( array $args = array() )

Performs post queries for available-item searching. Since 4.3.0.

Based on WP_Editor::wp_link_query().

Arguments

Name Type(s) Default Value Description
$args array

Optional. Accepts 'pagenum' and 's' (search) arguments.

Returns

array

Menu items.


WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.