Allow pages to be added automattically to menus. see #13447.
git-svn-id: https://develop.svn.wordpress.org/trunk@14878 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f2e1eaf40a
commit
00fda9f10b
File diff suppressed because one or more lines are too long
@ -498,10 +498,16 @@ clear:both;
|
||||
float: right;
|
||||
padding-right: 15px;
|
||||
}
|
||||
.menu-name-label span {
|
||||
.menu-name-label span, .auto-add-pages label {
|
||||
font-size: 11px;
|
||||
font-style: normal;
|
||||
}
|
||||
.auto-add-pages label.howto {
|
||||
display: inline;
|
||||
}
|
||||
.auto-add-pages {
|
||||
clear: both;
|
||||
}
|
||||
.submitbox .submitcancel {
|
||||
color: #21759B;
|
||||
border-bottom: 1px solid #21759B;
|
||||
|
@ -356,6 +356,20 @@ switch ( $action ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Store 'auto-add' pages.
|
||||
$auto_add = ! empty( $_POST['auto-add-pages'] );
|
||||
$nav_menu_option = (array) get_option( 'nav_menu_options' );
|
||||
if ( ! isset( $nav_menu_option['auto_add'] ) )
|
||||
$nav_menu_option['auto_add'] = array();
|
||||
if ( $auto_add ) {
|
||||
if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) )
|
||||
$nav_menu_option['auto_add'][] = $nav_menu_selected_id;
|
||||
} else {
|
||||
if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) )
|
||||
unset( $nav_menu_option['auto_add'][$key] );
|
||||
}
|
||||
update_option( 'nav_menu_options', $nav_menu_option );
|
||||
|
||||
wp_defer_term_counting(false);
|
||||
|
||||
do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
|
||||
@ -510,6 +524,21 @@ require_once( 'admin-header.php' );
|
||||
<a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( admin_url('nav-menus.php?action=delete&menu=' . $nav_menu_selected_id), 'delete-nav_menu-' . $nav_menu_selected_id ) ); ?>"><?php _e('Delete Menu'); ?></a>
|
||||
</div><!--END .delete-action-->
|
||||
<?php endif; ?>
|
||||
<?php if ( !empty( $nav_menu_selected_id ) ) :
|
||||
if ( ! isset( $auto_add ) ) {
|
||||
$auto_add = get_option( 'nav_menu_options' );
|
||||
if ( ! isset( $auto_add['auto_add'] ) )
|
||||
$auto_add = false;
|
||||
elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) )
|
||||
$auto_add = true;
|
||||
else
|
||||
$auto_add = false;
|
||||
}
|
||||
?>
|
||||
<div class="auto-add-pages">
|
||||
<label class="howto"><input type="checkbox"<?php checked( $auto_add ); ?> name="auto-add-pages" value="1" /> <?php printf( __('Automatically add new top-level pages to this menu' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div><!--END .major-publishing-actions-->
|
||||
</div><!--END #submitpost .submitbox-->
|
||||
<?php
|
||||
|
@ -748,4 +748,31 @@ function _wp_delete_tax_menu_item( $object_id = 0 ) {
|
||||
}
|
||||
}
|
||||
|
||||
function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
|
||||
if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
|
||||
return;
|
||||
$auto_add = get_option( 'nav_menu_options' );
|
||||
if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )
|
||||
return;
|
||||
$auto_add = $auto_add['auto_add'];
|
||||
if ( empty( $auto_add ) || ! is_array( $auto_add ) )
|
||||
return;
|
||||
|
||||
$args = array(
|
||||
'menu-item-object-id' => $post->ID,
|
||||
'menu-item-object' => $post->post_type,
|
||||
'menu-item-type' => 'post_type',
|
||||
);
|
||||
|
||||
foreach ( $auto_add as $menu_id ) {
|
||||
$items = (array) wp_get_nav_menu_items( $menu_id );
|
||||
foreach ( $items as $item ) {
|
||||
if ( $post->ID == $item->object_id )
|
||||
continue 2;
|
||||
}
|
||||
wp_update_nav_menu_item( $menu_id, 0, $args );
|
||||
}
|
||||
}
|
||||
add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu', 10, 3 );
|
||||
|
||||
?>
|
||||
|
@ -467,7 +467,7 @@ function wp_default_styles( &$styles ) {
|
||||
$styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.2' );
|
||||
$styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' );
|
||||
$styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.1' );
|
||||
$styles->add( 'nav-menu', "/wp-admin/css/nav-menu$suffix.css", array(), '20100524' );
|
||||
$styles->add( 'nav-menu', "/wp-admin/css/nav-menu$suffix.css", array(), '20100525' );
|
||||
|
||||
foreach ( $rtl_styles as $rtl_style ) {
|
||||
$styles->add_data( $rtl_style, 'rtl', true );
|
||||
|
Loading…
Reference in New Issue
Block a user