]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/nav-menu.php
WordPress 3.8.2
[autoinstalls/wordpress.git] / wp-admin / includes / nav-menu.php
index 7e9fe6ad6425c7f6aff9bdc0ffbf166928ebbc19..c98e32fb978ceea520658d60cde61ed74a6b3c50 100644 (file)
@@ -9,36 +9,47 @@
  */
 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(
@@ -57,7 +68,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
                                $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(
@@ -214,7 +225,8 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
                <?php
                $output .= ob_get_clean();
        }
-}
+
+} // Walker_Nav_Menu_Edit
 
 /**
  * Create HTML list of nav menu input items.
@@ -230,24 +242,50 @@ class Walker_Nav_Menu_Checklist 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. 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;
@@ -261,15 +299,23 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
                $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 . '" />';
@@ -283,7 +329,8 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
                $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.
@@ -456,6 +503,16 @@ function wp_nav_menu_post_type_meta_boxes() {
                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;
@@ -478,6 +535,16 @@ function wp_nav_menu_taxonomy_meta_boxes() {
                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;
@@ -486,51 +553,6 @@ function wp_nav_menu_taxonomy_meta_boxes() {
        }
 }
 
-/**
- * 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 &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;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, '&hellip;' ); ?></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
  *
@@ -778,7 +800,22 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
                                        }
                                }
 
-                               $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'] ) ) {
@@ -810,7 +847,7 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
                        </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>
@@ -998,7 +1035,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
                        </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>
@@ -1135,6 +1172,14 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
                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 ) )
@@ -1279,6 +1324,7 @@ function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_select
 
        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>';