]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/nav-menu.php
WordPress 3.3.2-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / nav-menu.php
index 6e92928666cef0d99519509ee24c8190d39752c3..7c3380275fcadec882aaf407cc758d49ad8e984c 100644 (file)
@@ -54,6 +54,8 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
                $original_title = '';
                if ( 'taxonomy' == $item->type ) {
                        $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
+                       if ( is_wp_error( $original_title ) )
+                               $original_title = false;
                } elseif ( 'post_type' == $item->type ) {
                        $original_object = get_post( $item->object_id );
                        $original_title = $original_object->post_title;
@@ -67,7 +69,11 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
 
                $title = $item->title;
 
-               if ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
+               if ( ! empty( $item->_invalid ) ) {
+                       $classes[] = 'menu-item-invalid';
+                       /* translators: %s: title of menu item which is invalid */
+                       $title = sprintf( __( '%s (Invalid)' ), $item->title );
+               } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
                        $classes[] = 'pending';
                        /* translators: %s: title of menu item in draft status */
                        $title = sprintf( __('%s (Pending)'), $item->title );
@@ -82,7 +88,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
                                        <span class="item-title"><?php echo esc_html( $title ); ?></span>
                                        <span class="item-controls">
                                                <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
-                                               <span class="item-order">
+                                               <span class="item-order hide-if-js">
                                                        <a href="<?php
                                                                echo wp_nonce_url(
                                                                        add_query_arg(
@@ -109,7 +115,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
                                                                );
                                                        ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
                                                </span>
-                                               <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php _e('Edit Menu Item'); ?>" href="<?php
+                                               <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
                                                        echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
                                                ?>"><?php _e( 'Edit Menu Item' ); ?></a>
                                        </span>
@@ -137,13 +143,10 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
                                                <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
                                        </label>
                                </p>
-                               <p class="field-link-target description description-thin">
+                               <p class="field-link-target description">
                                        <label for="edit-menu-item-target-<?php echo $item_id; ?>">
-                                               <?php _e( 'Link Target' ); ?><br />
-                                               <select id="edit-menu-item-target-<?php echo $item_id; ?>" class="widefat edit-menu-item-target" name="menu-item-target[<?php echo $item_id; ?>]">
-                                                       <option value="" <?php selected( $item->target, ''); ?>><?php _e('Same window or tab'); ?></option>
-                                                       <option value="_blank" <?php selected( $item->target, '_blank'); ?>><?php _e('New window or tab'); ?></option>
-                                               </select>
+                                               <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
+                                               <?php _e( 'Open link in a new window/tab' ); ?>
                                        </label>
                                </p>
                                <p class="field-css-classes description description-thin">
@@ -167,7 +170,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
                                </p>
 
                                <div class="menu-item-actions description-wide submitbox">
-                                       <?php if( 'custom' != $item->type ) : ?>
+                                       <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
                                                <p class="link-to-original">
                                                        <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
                                                </p>
@@ -182,7 +185,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
                                                        remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
                                                ),
                                                'delete-menu_item_' . $item_id
-                                       ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) );
+                                       ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ) );
                                                ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
                                </div>
 
@@ -207,6 +210,21 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu  {
  * @uses Walker_Nav_Menu
  */
 class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu  {
+       function __construct( $fields = false ) {
+               if ( $fields ) {
+                       $this->db_fields = $fields;
+               }
+       }
+
+       function start_lvl( &$output, $depth ) {
+               $indent = str_repeat( "\t", $depth );
+               $output .= "\n$indent<ul class='children'>\n";
+       }
+
+       function end_lvl( &$output, $depth ) {
+               $indent = str_repeat( "\t", $depth );
+               $output .= "\n$indent</ul>";
+       }
 
        /**
         * @see Walker::start_el()
@@ -319,7 +337,8 @@ function _wp_ajax_menu_quick_search( $request = array() ) {
                        while ( have_posts() ) {
                                the_post();
                                if ( 'markup' == $response_format ) {
-                                       echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref = get_the_ID() ) ) ), 0, (object) $args );
+                                       $var_by_ref = get_the_ID();
+                                       echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
                                } elseif ( 'json' == $response_format ) {
                                        echo json_encode(
                                                array(
@@ -614,7 +633,12 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
        if ( !$posts )
                $error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>';
 
-       $walker = new Walker_Nav_Menu_Checklist;
+       $db_fields = false;
+       if ( is_post_type_hierarchical( $post_type_name ) ) {
+               $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
+       }
+
+       $walker = new Walker_Nav_Menu_Checklist( $db_fields );
 
        $current_tab = 'most-recent';
        if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) {
@@ -670,7 +694,7 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
                        <p class="quick-search-wrap">
                                <input type="text" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" />
                                <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
-                               <?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false ); ?>
+                               <?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
                        </p>
 
                        <ul id="<?php echo $post_type_name; ?>-search-checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear">
@@ -716,6 +740,7 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
                                                        'object_id' => $_nav_menu_placeholder,
                                                        'post_content' => '',
                                                        'post_excerpt' => '',
+                                                       'post_parent' => '',
                                                        'post_title' => _x('Home', 'nav menu home label'),
                                                        'post_type' => 'nav_menu_item',
                                                        'type' => 'custom',
@@ -724,6 +749,7 @@ 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 );
                                $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
 
                                if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
@@ -821,7 +847,12 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
                'current' => $pagenum
        ));
 
-       $walker = new Walker_Nav_Menu_Checklist;
+       $db_fields = false;
+       if ( is_taxonomy_hierarchical( $taxonomy_name ) ) {
+               $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
+       }
+
+       $walker = new Walker_Nav_Menu_Checklist( $db_fields );
 
        $current_tab = 'most-used';
        if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) {
@@ -897,7 +928,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
                        <p class="quick-search-wrap">
                                <input type="text" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" />
                                <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
-                               <?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false ); ?>
+                               <?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
                        </p>
 
                        <ul id="<?php echo $taxonomy_name; ?>-search-checklist" class="list:<?php echo $taxonomy_name?> categorychecklist form-no-clear">
@@ -1072,15 +1103,20 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
                else
                        return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) );
 
-               $some_pending_menu_items = false;
+               $some_pending_menu_items = $some_invalid_menu_items = false;
                foreach( (array) $menu_items as $menu_item ) {
                        if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
                                $some_pending_menu_items = true;
+                       if ( ! empty( $menu_item->_invalid ) )
+                               $some_invalid_menu_items = true;
                }
 
                if ( $some_pending_menu_items )
                        $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>';
 
+               if ( $some_invalid_menu_items )
+                       $result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>';
+
                $result .= '<ul class="menu" id="menu-to-edit"> ';
                $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
                $result .= ' </ul> ';