Move the "Add Home Link" functionality to a checkbox on the View All tab of the Pages metabox. Also makes it work non-JS. props filosofo, fixes #13213.
git-svn-id: http://svn.automattic.com/wordpress/trunk@14971 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5f66aba55e
commit
da7b990fb5
|
@ -473,9 +473,6 @@ function wp_nav_menu_item_link_meta_box() {
|
|||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<span class="list-controls">
|
||||
<a href="#" class="select-all add-home-link"><?php _e('Add Home Link'); ?></a>
|
||||
</span>
|
||||
<span class="add-to-menu">
|
||||
<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
|
||||
<input type="submit" class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
|
||||
|
@ -495,6 +492,8 @@ function wp_nav_menu_item_link_meta_box() {
|
|||
* @param string $post_type The post type object.
|
||||
*/
|
||||
function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
|
||||
global $_nav_menu_placeholder;
|
||||
|
||||
$post_type_name = $post_type['args']->name;
|
||||
|
||||
// paginate browsing for large numbers of post objects
|
||||
|
@ -632,12 +631,38 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
|
|||
<ul id="<?php echo $post_type_name; ?>checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear">
|
||||
<?php
|
||||
$args['walker'] = $walker;
|
||||
|
||||
// if we're dealing with pages, let's put a checkbox for the front page at the top of the list
|
||||
if ( 'page' == $post_type_name ) {
|
||||
$front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0;
|
||||
if ( ! empty( $front_page ) ) {
|
||||
$front_page_obj = get_post( $front_page );
|
||||
$front_page_obj->_add_to_top = true;
|
||||
$front_page_obj->label = sprintf( _x('Home: %s', 'nav menu front page title'), $front_page_obj->post_title );
|
||||
array_unshift( $posts, $front_page_obj );
|
||||
} else {
|
||||
$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
|
||||
array_unshift( $posts, (object) array(
|
||||
'_add_to_top' => true,
|
||||
'ID' => 0,
|
||||
'object_id' => $_nav_menu_placeholder,
|
||||
'post_content' => '',
|
||||
'post_excerpt' => '',
|
||||
'post_title' => _x('Home', 'nav menu home label'),
|
||||
'post_type' => 'nav_menu_item',
|
||||
'type' => 'custom',
|
||||
'url' => home_url('/'),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
$checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
|
||||
|
||||
if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
|
||||
$checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items);
|
||||
|
||||
}
|
||||
|
||||
echo $checkbox_items;
|
||||
?>
|
||||
</ul>
|
||||
|
|
|
@ -38,8 +38,6 @@ var wpNavMenu;
|
|||
|
||||
this.attachTabsPanelListeners();
|
||||
|
||||
this.attachHomeLinkListener();
|
||||
|
||||
this.attachUnsavedChangesListener();
|
||||
|
||||
if( api.menuList.length ) // If no menu, we're in the + tab.
|
||||
|
@ -134,8 +132,11 @@ var wpNavMenu;
|
|||
var t = $(this),
|
||||
listItemDBIDMatch = re.exec( t.attr('name') ),
|
||||
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
|
||||
if ( this.className && -1 != this.className.indexOf('add-to-top') )
|
||||
processMethod = api.addMenuItemToTop;
|
||||
menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID );
|
||||
});
|
||||
|
||||
// Add the items
|
||||
api.addItemToMenu(menuItems, processMethod, function(){
|
||||
// Deselect the items and hide the ajax spinner
|
||||
|
@ -540,13 +541,6 @@ var wpNavMenu;
|
|||
$(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
|
||||
},
|
||||
|
||||
attachHomeLinkListener : function() {
|
||||
$('.add-home-link', '.customlinkdiv').click(function(e) {
|
||||
api.addLinkToMenu( navMenuL10n.homeurl, navMenuL10n.home, api.addMenuItemToTop );
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
attachUnsavedChangesListener : function() {
|
||||
$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea').change(function(){
|
||||
api.registerChange();
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -318,7 +318,7 @@ switch ( $action ) {
|
|||
// Update menu items
|
||||
|
||||
if ( ! is_wp_error( $_menu_object ) ) {
|
||||
$unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
|
||||
$unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish') );
|
||||
$menu_items = array();
|
||||
// Index menu items by db ID
|
||||
foreach( $unsorted_menu_items as $_item )
|
||||
|
|
|
@ -157,8 +157,13 @@ 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" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
|
||||
$output .= esc_html( $item->title ) .'</label>';
|
||||
$output .= '<input type="checkbox" class="menu-item-checkbox';
|
||||
if ( ! empty( $item->_add_to_top ) ) {
|
||||
$output .= ' add-to-top';
|
||||
}
|
||||
$output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
|
||||
$output .= empty( $item->label ) ? esc_html( $item->title ) : esc_html( $item->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 . '" />';
|
||||
|
|
|
@ -545,10 +545,10 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
|||
if ( isset( $menu_item->post_type ) ) {
|
||||
if ( 'nav_menu_item' == $menu_item->post_type ) {
|
||||
$menu_item->db_id = (int) $menu_item->ID;
|
||||
$menu_item->menu_item_parent = get_post_meta( $menu_item->ID, '_menu_item_menu_item_parent', true );
|
||||
$menu_item->object_id = get_post_meta( $menu_item->ID, '_menu_item_object_id', true );
|
||||
$menu_item->object = get_post_meta( $menu_item->ID, '_menu_item_object', true );
|
||||
$menu_item->type = get_post_meta( $menu_item->ID, '_menu_item_type', true );
|
||||
$menu_item->menu_item_parent = empty( $menu_item->menu_item_parent ) ? get_post_meta( $menu_item->ID, '_menu_item_menu_item_parent', true ) : $menu_item->menu_item_parent;
|
||||
$menu_item->object_id = empty( $menu_item->object_id ) ? get_post_meta( $menu_item->ID, '_menu_item_object_id', true ) : $menu_item->object_id;
|
||||
$menu_item->object = empty( $menu_item->object ) ? get_post_meta( $menu_item->ID, '_menu_item_object', true ) : $menu_item->object;
|
||||
$menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type;
|
||||
|
||||
if ( 'post_type' == $menu_item->type ) {
|
||||
$object = get_post_type_object( $menu_item->object );
|
||||
|
@ -571,16 +571,16 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
|||
} else {
|
||||
$menu_item->type_label = __('Custom');
|
||||
$menu_item->title = $menu_item->post_title;
|
||||
$menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
|
||||
$menu_item->url = empty( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url;
|
||||
}
|
||||
|
||||
$menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true );
|
||||
$menu_item->target = empty( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target;
|
||||
|
||||
$menu_item->attr_title = apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt );
|
||||
$menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
|
||||
$menu_item->attr_title = empty( $menu_item->attr_title ) ? apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt ) : $menu_item->attr_title;
|
||||
$menu_item->description = empty( $menu_item->description ) ? apply_filters( 'nav_menu_description', $menu_item->post_content ) : $menu_item->description;
|
||||
|
||||
$menu_item->classes = (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true );
|
||||
$menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
|
||||
$menu_item->classes = empty( $menu_item->classes ) ? (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true ) : $menu_item->classes;
|
||||
$menu_item->xfn = empty( $menu_item->xfn ) ? get_post_meta( $menu_item->ID, '_menu_item_xfn', true ) : $menu_item->xfn;
|
||||
} else {
|
||||
$menu_item->db_id = 0;
|
||||
$menu_item->menu_item_parent = 0;
|
||||
|
|
|
@ -385,7 +385,7 @@ function wp_default_scripts( &$scripts ) {
|
|||
) );
|
||||
|
||||
// Custom Navigation
|
||||
$scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100525' );
|
||||
$scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100526' );
|
||||
$scripts->localize( 'nav-menu', 'navMenuL10n', array(
|
||||
'home' => _x('Home', 'nav menu home label'),
|
||||
'homeurl' => home_url('/'),
|
||||
|
|
Loading…
Reference in New Issue