Make WordPress Core


Ignore:
Timestamp:
05/27/2010 10:22:09 PM (15 years ago)
Author:
nacin
Message:

New pending menu item behavior. props filosofo, see #13579.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/nav-menu.php

    r15007 r15008  
    5959            $original_title = $original_object->post_title;
    6060        }
     61
     62        $classes = array(
     63            'menu-item menu-item-depth-' . $depth,
     64            'menu-item-' . esc_attr( $item->object ),
     65            'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
     66        );
     67
     68        $title = $item->title;
     69
     70        if ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
     71            $classes[] = 'pending';
     72            /* translators: %s: title of menu item in draft status */
     73            $title = sprintf( __('%s (Pending)'), $item->title );
     74        }
     75
    6176        ?>
    62         <li id="menu-item-<?php echo $item_id; ?>" class="menu-item menu-item-depth-<?php echo $depth; ?> menu-item-<?php echo esc_attr( $item->object ); ?> menu-item-edit-<?php echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'; ?>">
     77        <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
    6378            <dl class="menu-item-bar">
    6479                <dt class="menu-item-handle">
    65                     <span class="item-title"><?php echo esc_html( $item->title ); ?></span>
     80                    <span class="item-title"><?php echo esc_html( $title ); ?></span>
    6681                    <span class="item-controls">
    6782                        <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
     
    866881 * @since 3.0.0
    867882 *
    868  * @param int $menu_id The menu ID for which to save this item.
     883 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item.
    869884 * @param array $menu_data The unsanitized posted menu item data.
    870885 * @return array The database IDs of the items saved
     
    874889    $items_saved = array();
    875890
    876     if ( is_nav_menu( $menu_id ) ) {
     891    if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
    877892
    878893        // Loop through all the menu items' POST values
     
    883898                    ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set
    884899                    in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default
    885                     'custom' != $_item_object_data['menu-item-type'] ||  // or it's not a custom menu item
     900                    ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) ||  // or it's not a custom menu item (but not the custom home page)
    886901                    ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists
    887902                )
     
    9991014            return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) );
    10001015
     1016        $some_pending_menu_items = false;
     1017        foreach( (array) $menu_items as $menu_item ) {
     1018            if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
     1019                $some_pending_menu_items = true;
     1020        }
     1021
     1022        if ( $some_pending_menu_items )
     1023            $result .= '<div class="updated inline"><p>' . __('Click <em>Save Menu</em> to make pending menu items public.') . '</p></div>';
     1024
    10011025        $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
    10021026        return $result;
     
    10271051}
    10281052
     1053/**
     1054 * Deletes orphaned draft menu items
     1055 *
     1056 * @access private
     1057 * @since 3.0.0
     1058 *
     1059 */
     1060function _wp_delete_orphaned_draft_menu_items() {
     1061    global $wpdb;
     1062    $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
     1063
     1064    // delete orphaned draft menu items
     1065    $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
     1066
     1067    foreach( (array) $menu_items_to_delete as $menu_item_id )
     1068        wp_delete_post( $menu_item_id, true );
     1069}
     1070
     1071add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
     1072
    10291073?>
Note: See TracChangeset for help on using the changeset viewer.