PHP Class WP_Customize_Nav_Menus, wordpress

Implements menu management in the Customizer.
See also: WP_Customize_Manager
Since: 4.3.0
显示文件 Open project: johnpbloch/wordpress Class Usage Examples

Public Properties

Property Type Description
$manager WP_Customize_Manager WP_Customize_Manager instance.
$preview_nav_menu_instance_args array Nav menu args used for each instance, keyed by the args HMAC.
$previewed_menus array Previewed Menus.

Public Methods

Method Description
__construct ( object $manager ) Constructor.
ajax_insert_auto_draft_post ( ) Ajax handler for adding a new auto-draft post.
ajax_load_available_items ( ) Ajax handler for loading available menu items.
ajax_search_available_items ( ) Ajax handler for searching available menu items.
available_item_types ( ) : array Return an array of all the available item types.
available_items_template ( ) Print the html template used to render the add-menu-item frame.
customize_dynamic_partial_args ( array | false $partial_args, string $partial_id ) : array Filters arguments for dynamic nav_menu selective refresh partials.
customize_preview_enqueue_deps ( ) Enqueue scripts for the Customizer preview.
customize_preview_init ( ) Add hooks for the Customizer preview.
customize_register ( ) Add the customizer settings and controls.
enqueue_scripts ( ) Enqueue scripts and styles for Customizer pane.
export_partial_rendered_nav_menu_instances ( array $response ) : array Export any wp_nav_menu() calls during the rendering of any partials.
export_preview_data ( ) Exports data from PHP to JS.
filter_dynamic_setting_args ( false | array $setting_args, string $setting_id ) : array | false Filters a dynamic setting's constructor args.
filter_dynamic_setting_class ( string $setting_class, string $setting_id, array $setting_args ) : string Allow non-statically created settings to be constructed with custom WP_Customize_Setting subclass.
filter_nonces ( array $nonces ) : array Adds a nonce for customizing menus.
filter_wp_nav_menu ( string $nav_menu_content, object $args ) : null Prepares wp_nav_menu() calls for partial refresh.
filter_wp_nav_menu_args ( array $args ) : array Keep track of the arguments that are being passed to wp_nav_menu().
hash_nav_menu_args ( array $args ) : string Hashes (hmac) the nav menu arguments to ensure they are not tampered with when submitted in the Ajax request.
insert_auto_draft_post ( array $postarr ) : WP_Post | WP_Error Add a new auto-draft post.
intval_base10 ( mixed $value ) : integer Get the base10 intval.
load_available_items_query ( string $type = 'post_type', string $object = 'page', integer $page ) : WP_Error | array Performs the post_type and taxonomy queries for loading available menu items.
make_auto_draft_status_previewable ( ) Make the auto-draft status protected so that it can be queried.
print_templates ( ) Print the JavaScript templates used to render Menu Customizer components.
render_nav_menu_partial ( WP_Customize_Partial $partial, array $nav_menu_args ) : string | false Render a specific menu via wp_nav_menu() using the supplied arguments.
sanitize_nav_menus_created_posts ( array $value ) Sanitize post IDs for auto-draft posts created for nav menu items to be published.
save_nav_menus_created_posts ( WP_Customize_Setting $setting ) Publish the auto-draft posts that were created for nav menu items.
search_available_items_query ( array $args = [] ) : array Performs post queries for available-item searching.

Protected Methods

Method Description
print_custom_links_available_menu_item ( ) : void Print the markup for available menu item custom links.
print_post_type_container ( array $available_item_type ) : void Print the markup for new menu items.

Method Details

__construct() public method

Constructor.
Since: 4.3.0
public __construct ( object $manager )
$manager object An instance of the WP_Customize_Manager class.

ajax_insert_auto_draft_post() public method

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

ajax_load_available_items() public method

Ajax handler for loading available menu items.
Since: 4.3.0

ajax_search_available_items() public method

Ajax handler for searching available menu items.
Since: 4.3.0

available_item_types() public method

Return 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 in addition to `$title`, `$type`, and `$object`.
public available_item_types ( ) : array
return array The available menu item types.

available_items_template() public method

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

customize_dynamic_partial_args() public method

Filters arguments for dynamic nav_menu selective refresh partials.
Since: 4.5.0
public customize_dynamic_partial_args ( array | false $partial_args, string $partial_id ) : array
$partial_args array | false Partial args.
$partial_id string Partial ID.
return array Partial args.

customize_preview_enqueue_deps() public method

Enqueue scripts for the Customizer preview.
Since: 4.3.0

customize_preview_init() public method

Add hooks for the Customizer preview.
Since: 4.3.0

customize_register() public method

Add the customizer settings and controls.
Since: 4.3.0
public customize_register ( )

enqueue_scripts() public method

Enqueue scripts and styles for Customizer pane.
Since: 4.3.0
public enqueue_scripts ( )

export_partial_rendered_nav_menu_instances() public method

Export any wp_nav_menu() calls during the rendering of any partials.
Since: 4.5.0
public export_partial_rendered_nav_menu_instances ( array $response ) : array
$response array Response.
return array Response.

export_preview_data() public method

Exports data from PHP to JS.
Since: 4.3.0
public export_preview_data ( )

filter_dynamic_setting_args() public method

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
public filter_dynamic_setting_args ( false | array $setting_args, string $setting_id ) : array | false
$setting_args false | array The arguments to the WP_Customize_Setting constructor.
$setting_id string ID for dynamic setting, usually coming from `$_POST['customized']`.
return array | false

filter_dynamic_setting_class() public method

Allow non-statically created settings to be constructed with custom WP_Customize_Setting subclass.
Since: 4.3.0
public filter_dynamic_setting_class ( string $setting_class, string $setting_id, array $setting_args ) : string
$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.
return string

filter_nonces() public method

Adds a nonce for customizing menus.
Since: 4.5.0
public filter_nonces ( array $nonces ) : array
$nonces array Array of nonces.
return array $nonces Modified array of nonces.

filter_wp_nav_menu() public method

Injects attributes into container element.
See also: wp_nav_menu()
Since: 4.3.0
public filter_wp_nav_menu ( string $nav_menu_content, object $args ) : null
$nav_menu_content string The HTML content for the navigation menu.
$args object An object containing wp_nav_menu() arguments.
return null

filter_wp_nav_menu_args() public method

Keep track of the arguments that are being passed to wp_nav_menu().
See also: wp_nav_menu()
See also: WP_Customize_Widgets_Partial_Refresh::filter_dynamic_sidebar_params()
Since: 4.3.0
public filter_wp_nav_menu_args ( array $args ) : array
$args array An array containing wp_nav_menu() arguments.
return array Arguments.

hash_nav_menu_args() public method

Note that the array is expected to be pre-sorted.
Since: 4.3.0
public hash_nav_menu_args ( array $args ) : string
$args array The arguments to hash.
return string Hashed nav menu arguments.

insert_auto_draft_post() public method

Add a new auto-draft post.
Since: 4.7.0
public insert_auto_draft_post ( array $postarr ) : WP_Post | WP_Error
$postarr array { Post array. Note that post_status is overridden to be `auto-draft`. @var string $post_title Post title. Required. @var string $post_type Post type. Required. @var string $post_name Post name. @var string $post_content Post content. }
return WP_Post | WP_Error Inserted auto-draft post object or error.

intval_base10() public method

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
public intval_base10 ( mixed $value ) : integer
$value mixed Number to convert.
return integer Integer.

load_available_items_query() public method

Performs the post_type and taxonomy queries for loading available menu items.
Since: 4.3.0
public load_available_items_query ( string $type = 'post_type', string $object = 'page', integer $page ) : WP_Error | array
$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'.
return WP_Error | array Returns either a WP_Error object or an array of menu items.

make_auto_draft_status_previewable() public method

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

print_post_type_container() protected method

To be used in the template #available-menu-items.
Since: 4.7.0
protected print_post_type_container ( array $available_item_type ) : void
$available_item_type array Menu item data to output, including title, type, and label.
return void

print_templates() public method

Templates are imported into the JS use wp.template.
Since: 4.3.0
public print_templates ( )

render_nav_menu_partial() public method

Render a specific menu via wp_nav_menu() using the supplied arguments.
See also: wp_nav_menu()
Since: 4.3.0
public render_nav_menu_partial ( WP_Customize_Partial $partial, array $nav_menu_args ) : string | false
$partial WP_Customize_Partial Partial.
$nav_menu_args array Nav menu args supplied as container context.
return string | false

sanitize_nav_menus_created_posts() public method

Sanitize post IDs for auto-draft posts created for nav menu items to be published.
Since: 4.7.0
public sanitize_nav_menus_created_posts ( array $value )
$value array Post IDs.

save_nav_menus_created_posts() public method

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
public save_nav_menus_created_posts ( WP_Customize_Setting $setting )
$setting WP_Customize_Setting Customizer setting object.

search_available_items_query() public method

Based on WP_Editor::wp_link_query().
Since: 4.3.0
public search_available_items_query ( array $args = [] ) : array
$args array Optional. Accepts 'pagenum' and 's' (search) arguments.
return array Menu items.

Property Details

$manager public_oe property

WP_Customize_Manager instance.
Since: 4.3.0
public WP_Customize_Manager $manager
return WP_Customize_Manager

$preview_nav_menu_instance_args public_oe property

Nav menu args used for each instance, keyed by the args HMAC.
Since: 4.3.0
public array $preview_nav_menu_instance_args
return array

$previewed_menus public_oe property

Previewed Menus.
Since: 4.3.0
public array $previewed_menus
return array