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: https://develop.svn.wordpress.org/trunk@14971 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin
2010-05-27 02:24:33 +00:00
parent fdf4f195df
commit 9b4a85cdaf
7 changed files with 51 additions and 27 deletions
+28 -3
View File
@@ -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>
+3 -9
View File
@@ -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
+1 -1
View File
@@ -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 )