WordPress.org

Make WordPress Core

Ticket #19415: 19415.diff

File 19415.diff, 1.6 KB (added by ninnypants, 6 years ago)
  • src/wp-includes/default-filters.php

     
    267267add_action( 'delete_post',                '_wp_delete_post_menu_item'         );
    268268add_action( 'delete_term',                '_wp_delete_tax_menu_item',   10, 3 );
    269269add_action( 'transition_post_status',     '_wp_auto_add_pages_to_menu', 10, 3 );
     270add_action( 'transition_post_status',     '_wp_auto_remove_posts_from_menu', 10, 3 );
    270271
    271272// Post Thumbnail CSS class filtering
    272273add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_add'    );
  • src/wp-includes/nav-menu.php

     
    898898                wp_update_nav_menu_item( $menu_id, 0, $args );
    899899        }
    900900}
     901
     902/**
     903 * Automatically remove post objects from nav menus when transitioned to a non public status.
     904 *
     905 * @since 4.2.0
     906 * @access private
     907 *
     908 * @param string $new_status The new status of the post object.
     909 * @param string $old_status The old status of the post object.
     910 * @param object $post The post object being transitioned from one status to another.
     911 * @return void
     912 */
     913function _wp_auto_remove_posts_from_menu( $new_status, $old_status, $post ) {
     914        if ( ! in_array( $new_status, array( 'private', 'draft', 'trash', 'future' ) ) ) {
     915                return;
     916        }
     917
     918        _wp_delete_post_menu_item( $post->ID );
     919}