Make WordPress Core

Opened 10 years ago

Last modified 6 years ago

#33955 new enhancement

get_posts() menu args filter

Reported by: sebastianpisula's profile sebastian.pisula Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

Before I get menu items by get_posts() I can't filter args (Example: I want ignore item of menu for not logged users)

add_filter( 'wp_get_nav_menu_items_args', 'wp_get_nav_menu_items_args', 10, 3 );

function wp_get_nav_menu_items_args( $args, $menu, $items )
{
    if ( ! is_user_logged_in()) {
        if (( $key = array_search( 2778, $items ) ) !== false) {
            unset( $items[$key] );
        }

        $args['include'] = implode( ',', $items );
    }

    return $args;
}

Attachments (3)

33955.patch (27.9 KB) - added by sebastian.pisula 10 years ago.
33955_1.patch (621 bytes) - added by sebastian.pisula 10 years ago.
33955.diff (699 bytes) - added by iamfriendly 9 years ago.
Refreshed the patch and added docs

Download all attachments as: .zip

Change History (7)

#1 @swissspidy
10 years ago

  • Keywords has-patch needs-refresh added

Did you create this patch against trunk? Doesn't look like it.
I'd suggest using svn diff or git patch --no-prefix against trunk to also remove those IntelliJ/PhpStorm headers.

@iamfriendly
9 years ago

Refreshed the patch and added docs

#2 @iamfriendly
9 years ago

  • Keywords needs-refresh removed

Added the requisite filter docs based on @sebastian.pisula's work and refreshed the patch to remove the headers

#3 @sebastian.pisula
9 years ago

What with this filter ?

This ticket was mentioned in Slack in #core by sebastian.pisula. View the logs.


9 years ago

Note: See TracTickets for help on using tickets.