Make WordPress Core


Ignore:
Timestamp:
02/07/2023 12:47:30 PM (2 years ago)
Author:
spacedmonkey
Message:

Options, Meta APIs: Add a filter to allow the shortcut return to wp_load_alloptions function.

Add a new filter pre_wp_load_alloptions in the wp_load_alloptions function to short circuit the return value.

Props pbearne, spacedmonkey, joyously, SergeyBiryukov, mukesh27, costdev.
Fixes #56045.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/option/wpLoadAlloptions.php

    r53865 r55256  
    121121        return $this->alloptions;
    122122    }
     123
     124    /**
     125     * Tests that `$alloptions` can be filtered with a custom value, short circuiting `wp_load_alloptions()`.
     126     *
     127     * @ticket 56045
     128     *
     129     * @covers ::wp_load_alloptions
     130     */
     131    public function test_filter_pre_wp_load_alloptions_filter_is_called() {
     132        $filter = new MockAction();
     133
     134        add_filter( 'pre_wp_load_alloptions', array( &$filter, 'filter' ) );
     135
     136        wp_load_alloptions();
     137
     138        $this->assertSame(
     139            1,
     140            $filter->get_call_count(),
     141            'The filter was not called 1 time.'
     142        );
     143
     144        $this->assertSame(
     145            array( 'pre_wp_load_alloptions' ),
     146            $filter->get_hook_names(),
     147            'The hook name was incorrect.'
     148        );
     149    }
    123150}
Note: See TracChangeset for help on using the changeset viewer.