Make WordPress Core

Changeset 55868


Ignore:
Timestamp:
05/30/2023 02:11:46 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Docs: Add a @since tag for the pre_wp_setup_nav_menu_item filter.

Includes moving the unit test next to the other wp_setup_nav_menu_item() tests and using the MockAction class to confirm that the filter runs.

Follow-up to [55867].

Props TobiasBg.
Fixes #56577.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r55867 r55868  
    823823
    824824    /**
    825      * Short-circuit the wp_setup_nav_menu_item() output.
     825     * Filters whether to short-circuit the wp_setup_nav_menu_item() output.
    826826     *
    827827     * Returning a non-null value from the filter will short-circuit wp_setup_nav_menu_item(),
    828      * and return that value.
     828     * returning that value instead.
     829     *
     830     * @since 6.3.0
    829831     *
    830832     * @param object|null $modified_menu_item Modified menu item. Default null.
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r55867 r55868  
    593593
    594594    /**
     595     * @ticket 56577
     596     */
     597    public function test_wp_setup_nav_menu_item_short_circuit_filter() {
     598        $post_id = self::factory()->post->create();
     599
     600        $menu_item_id = wp_update_nav_menu_item(
     601            $this->menu_id,
     602            0,
     603            array(
     604                'menu-item-type'      => 'post_type',
     605                'menu-item-object'    => 'post',
     606                'menu-item-object-id' => $post_id,
     607                'menu-item-status'    => 'publish',
     608            )
     609        );
     610
     611        $filter = new MockAction();
     612        add_filter( 'pre_wp_setup_nav_menu_item', array( &$filter, 'filter' ) );
     613
     614        wp_setup_nav_menu_item( get_post( $menu_item_id ) );
     615
     616        $this->assertSame( 1, $filter->get_call_count() );
     617    }
     618
     619    /**
    595620     * @ticket 35206
    596621     */
     
    13451370        $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
    13461371    }
    1347 
    1348     /**
    1349      * @ticket 56577
    1350      */
    1351     public function test_nav_menu_item_short_circuit_filter() {
    1352         // Create a nav menu item.
    1353         $menu_item_args = array(
    1354             'menu-item-type'   => 'custom',
    1355             'menu-item-title'  => 'Wordpress.org',
    1356             'menu-item-url'    => 'http://wordpress.org',
    1357             'menu-item-status' => 'publish',
    1358         );
    1359 
    1360         $custom_item_id = wp_update_nav_menu_item( 0, 0, $menu_item_args );
    1361 
    1362         $pre_setup_callback = function() {
    1363             return '--empty nav menu item--';
    1364         };
    1365 
    1366         add_filter( 'pre_wp_setup_nav_menu_item', $pre_setup_callback );
    1367 
    1368         // Confirm the short-circuit.
    1369         $custom_item = wp_setup_nav_menu_item( get_post( $custom_item_id ) );
    1370         $this->assertSame( '--empty nav menu item--', $custom_item );
    1371 
    1372         remove_filter( 'pre_wp_setup_nav_menu_item', $pre_setup_callback );
    1373     }
    1374 
    13751372}
Note: See TracChangeset for help on using the changeset viewer.