*/
class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
/**
+ * Starts the list before the elements are added.
+ *
* @see Walker_Nav_Menu::start_lvl()
+ *
* @since 3.0.0
*
* @param string $output Passed by reference.
+ * @param int $depth Depth of menu item. Used for padding.
+ * @param array $args Not used.
*/
function start_lvl( &$output, $depth = 0, $args = array() ) {}
/**
+ * Ends the list of after the elements are added.
+ *
* @see Walker_Nav_Menu::end_lvl()
+ *
* @since 3.0.0
*
* @param string $output Passed by reference.
+ * @param int $depth Depth of menu item. Used for padding.
+ * @param array $args Not used.
*/
function end_lvl( &$output, $depth = 0, $args = array() ) {}
/**
- * @see Walker::start_el()
+ * Start the element output.
+ *
+ * @see Walker_Nav_Menu::start_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
- * @param object $item Menu item data object.
- * @param int $depth Depth of menu item. Used for padding.
- * @param object $args
+ * @param object $item Menu item data object.
+ * @param int $depth Depth of menu item. Used for padding.
+ * @param array $args Not used.
+ * @param int $id Not used.
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $_wp_nav_menu_max_depth;
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
- $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
-
ob_start();
$item_id = esc_attr( $item->ID );
$removed_args = array(
$original_title = false;
} elseif ( 'post_type' == $item->type ) {
$original_object = get_post( $item->object_id );
- $original_title = $original_object->post_title;
+ $original_title = get_the_title( $original_object->ID );
}
$classes = array(
<?php
$output .= ob_get_clean();
}
-}
+
+} // Walker_Nav_Menu_Edit
/**
* Create HTML list of nav menu input items.
}
}
+ /**
+ * Starts the list before the elements are added.
+ *
+ * @see Walker_Nav_Menu::start_lvl()
+ *
+ * @since 3.0.0
+ *
+ * @param string $output Passed by reference. Used to append additional content.
+ * @param int $depth Depth of page. Used for padding.
+ * @param array $args Not used.
+ */
function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class='children'>\n";
}
+ /**
+ * Ends the list of after the elements are added.
+ *
+ * @see Walker_Nav_Menu::end_lvl()
+ *
+ * @since 3.0.0
+ *
+ * @param string $output Passed by reference. Used to append additional content.
+ * @param int $depth Depth of page. Used for padding.
+ * @param array $args Not used.
+ */
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent</ul>";
}
/**
- * @see Walker::start_el()
+ * Start the element output.
+ *
+ * @see Walker_Nav_Menu::start_el()
+ *
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
- * @param object $item Menu item data object.
- * @param int $depth Depth of menu item. Used for padding.
- * @param object $args
+ * @param object $item Menu item data object.
+ * @param int $depth Depth of menu item. Used for padding.
+ * @param array $args Not used.
+ * @param int $id Not used.
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $_nav_menu_placeholder;
$output .= $indent . '<li>';
$output .= '<label class="menu-item-title">';
$output .= '<input type="checkbox" class="menu-item-checkbox';
- if ( property_exists( $item, 'front_or_home' ) && $item->front_or_home ) {
- $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $item->post_title );
+
+ if ( ! empty( $item->front_or_home ) )
$output .= ' add-to-top';
- } elseif ( property_exists( $item, 'label' ) ) {
+
+ $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
+
+ if ( ! empty( $item->label ) ) {
$title = $item->label;
+ } elseif ( isset( $item->post_type ) ) {
+ /** This filter is documented in wp-includes/post-template.php */
+ $title = apply_filters( 'the_title', $item->post_title, $item->ID );
+ if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title )
+ $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $title );
}
- $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
+
$output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
- $output .= '</label>';
+ $output .= '</label>';
// Menu item hidden fields
$output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
}
-}
+
+} // Walker_Nav_Menu_Checklist
/**
* Prints the appropriate response to a menu quick search.
return;
foreach ( $post_types as $post_type ) {
+ /**
+ * Filter whether a menu items meta box will be added for the current post type.
+ *
+ * If a falsey value is returned instead of a post type object,
+ * the post type menu items meta box will not be added.
+ *
+ * @since 3.0.0
+ *
+ * @param object $post_type The post type object to be used as a meta box.
+ */
$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
if ( $post_type ) {
$id = $post_type->name;
return;
foreach ( $taxonomies as $tax ) {
+ /**
+ * Filter whether a menu items meta box will be added for the current taxonomy.
+ *
+ * If a falsey value is returned instead of a taxonomy object,
+ * the taxonomy menu items meta box will not be added.
+ *
+ * @since 3.0.0
+ *
+ * @param object $tax The taxonomy object to be used as a meta box.
+ */
$tax = apply_filters( 'nav_menu_meta_box_object', $tax );
if ( $tax ) {
$id = $tax->name;
}
}
-/**
- * Displays a metabox for the nav menu theme locations.
- *
- * @since 3.0.0
- */
-function wp_nav_menu_locations_meta_box() {
- global $nav_menu_selected_id;
-
- if ( ! current_theme_supports( 'menus' ) ) {
- // We must only support widgets. Leave a message and bail.
- echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p>';
- return;
- }
-
- $locations = get_registered_nav_menus();
- $menus = wp_get_nav_menus();
- $menu_locations = get_nav_menu_locations();
- $num_locations = count( array_keys($locations) );
-
- echo '<p class="howto">' . _n( 'Select a menu to use within your theme.', 'Select the menus you will use in your theme.', $num_locations ) . '</p>';
-
- foreach ( $locations as $location => $description ) {
- ?>
- <p>
- <label class="howto" for="locations-<?php echo $location; ?>">
- <span><?php echo $description; ?></span>
- <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>">
- <option value="0"></option>
- <?php foreach ( $menus as $menu ) : ?>
- <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
- value="<?php echo $menu->term_id; ?>"><?php echo wp_html_excerpt( $menu->name, 40, '…' ); ?></option>
- <?php endforeach; ?>
- </select>
- </label>
- </p>
- <?php
- }
- ?>
- <p class="button-controls">
- <?php submit_button( __( 'Save' ), 'primary right', 'nav-menu-locations', false, wp_nav_menu_disabled_check( $nav_menu_selected_id ) ); ?>
- <span class="spinner"></span>
- </p>
- <?php
-}
-
/**
* Check whether to disable the Menu Locations meta box submit button
*
}
}
- $posts = apply_filters( 'nav_menu_items_'.$post_type_name, $posts, $args, $post_type );
+ /**
+ * Filter the posts displayed in the 'View All' tab of the current
+ * post type's menu items meta box.
+ *
+ * The dynamic portion of the hook name, $post_type_name,
+ * refers to the slug of the current post type.
+ *
+ * @since 3.2.0
+ *
+ * @see WP_Query::query()
+ *
+ * @param array $posts The posts for the current post type.
+ * @param array $args An array of WP_Query arguments.
+ * @param object $post_type The current post type object for this menu item meta box.
+ */
+ $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type );
$checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
</span>
<span class="add-to-menu">
- <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-' . $post_type_name ); ?>" />
+ <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="<?php echo esc_attr( 'submit-posttype-' . $post_type_name ); ?>" />
<span class="spinner"></span>
</span>
</p>
</span>
<span class="add-to-menu">
- <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-taxonomy-menu-item" id="<?php esc_attr_e( 'submit-taxonomy-' . $taxonomy_name ); ?>" />
+ <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-taxonomy-menu-item" id="<?php echo esc_attr( 'submit-taxonomy-' . $taxonomy_name ); ?>" />
<span class="spinner"></span>
</span>
</p>
if( empty($menu_items) )
return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';
+ /**
+ * Filter the Walker class used to render a menu formatted for editing.
+ *
+ * @since 3.0.0
+ *
+ * @param string $walker_class_name The Walker class used to render a menu formatted for editing.
+ * @param int $menu_id The ID of the menu being rendered.
+ */
$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
if ( class_exists( $walker_class_name ) )
wp_defer_term_counting( false );
+ /** This action is documented in wp-includes/nav-menu.php */
do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
$messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%1$s</strong> has been updated.' ), $nav_menu_selected_title ) . '</p></div>';