WordPress.org

Make WordPress Core

Ticket #21773: 21773.diff

File 21773.diff, 1.4 KB (added by dkotter, 4 years ago)
  • wp-includes/nav-menu.php

     
    603603}
    604604
    605605/**
     606 * Return if a menu item is published.
     607 *
     608 * If the menu item is of the type post_type and
     609 * the status isn't publish, don't output this item,
     610 * as the links for these will 404.
     611 *
     612 * @link https://core.trac.wordpress.org/ticket/21773
     613 *
     614 * @since 4.6.0
     615 * @access private
     616 *
     617 * @param object $item The menu item to check.
     618 * @return bool False if invalid, otherwise true.
     619 */
     620function _is_nav_menu_item_published( $item ) {
     621        $type      = get_post_meta( $item->ID, '_menu_item_type',      true );
     622        $object_id = get_post_meta( $item->ID, '_menu_item_object_id', true );
     623
     624        if ( 'post_type' === $type && 'publish' !== get_post_status( $object_id ) ) {
     625                return false;
     626        }
     627
     628        return true;
     629}
     630
     631/**
    606632 * Return all menu items of a navigation menu.
    607633 *
    608634 * @since 3.0.0
     
    675701
    676702        $items = array_map( 'wp_setup_nav_menu_item', $items );
    677703
    678         if ( ! is_admin() ) { // Remove invalid items only in front end
     704        if ( ! is_admin() ) { // Remove invalid items only on front end
    679705                $items = array_filter( $items, '_is_valid_nav_menu_item' );
     706                $items = array_filter( $items, '_is_nav_menu_item_published' );
    680707        }
    681708
    682709        if ( ARRAY_A == $args['output'] ) {