Make WordPress Core

Changeset 57013


Ignore:
Timestamp:
10/26/2023 10:54:15 PM (6 months ago)
Author:
peterwilsoncc
Message:

Options, Meta APIs: Rename option cache priming functions.

Rename the option cache priming functions to more closely follow the naming convention used by other cache priming functions.

  • wp_load_options() becomes wp_prime_option_caches()
  • wp_load_options_by_group() becomes wp_prime_option_caches_by_group()

The unit test files and classes are renamed accordingly.

Unlike the existing cache priming functions, these functions were introduced with the intention of being public so use the wp_ prefix rather than the _ prefix used by the functions initially introduced as private functions but since made public.

Follow up to [56445],[56990].

Props flixos90, peterwilsoncc, joemcgill, SergeyBiryukov, desrosj.
Fixes #58962.

Location:
trunk
Files:
1 edited
2 moved

Legend:

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

    r56990 r57013  
    249249
    250250/**
    251  * Loads specific options into the cache with a single database query.
     251 * Primes specific options into the cache with a single database query.
    252252 *
    253253 * Only options that do not already exist in cache will be loaded.
     
    259259 * @param array $options An array of option names to be loaded.
    260260 */
    261 function wp_load_options( $options ) {
     261function wp_prime_option_caches( $options ) {
    262262    $alloptions     = wp_load_alloptions();
    263263    $cached_options = wp_cache_get_multiple( $options, 'options' );
     
    322322
    323323/**
    324  * Loads all options registered with a specific option group.
     324 * Primes the cache of all options registered with a specific option group.
    325325 *
    326326 * @since 6.4.0
     
    330330 * @param string $option_group The option group to load options for.
    331331 */
    332 function wp_load_options_by_group( $option_group ) {
     332function wp_prime_option_caches_by_group( $option_group ) {
    333333    global $new_allowed_options;
    334334
    335335    if ( isset( $new_allowed_options[ $option_group ] ) ) {
    336         wp_load_options( $new_allowed_options[ $option_group ] );
     336        wp_prime_option_caches( $new_allowed_options[ $option_group ] );
    337337    }
    338338}
     
    349349 */
    350350function get_options( $options ) {
    351     wp_load_options( $options );
     351    wp_prime_option_caches( $options );
    352352
    353353    $result = array();
  • trunk/tests/phpunit/tests/option/wpPrimeOptionCaches.php

    r57012 r57013  
    11<?php
    22/**
    3  * Test wp_load_options().
     3 * Test wp_prime_option_caches().
    44 *
    55 * @group option
    66 *
    7  * @covers ::wp_load_options
     7 * @covers ::wp_prime_option_caches
    88 */
    9 class Tests_Option_PrimeOptions extends WP_UnitTestCase {
     9class Tests_Option_WpPrimeOptionCaches extends WP_UnitTestCase {
    1010
    1111    /**
    12      * Tests that wp_load_options() loads multiple options.
     12     * Tests that wp_prime_option_caches() primes multiple options.
    1313     *
    1414     * @ticket 58962
    1515     */
    16     public function test_wp_load_options() {
    17         // Create some options to load.
    18         $options_to_load = array(
     16    public function test_wp_prime_option_caches() {
     17        // Create some options to prime.
     18        $options_to_prime = array(
    1919            'option1',
    2020            'option2',
     
    2727         * check options are not in cache initially.
    2828         */
    29         foreach ( $options_to_load as $option ) {
     29        foreach ( $options_to_prime as $option ) {
    3030            update_option( $option, "value_$option", false );
    3131            wp_cache_delete( $option, 'options' );
     
    3333        }
    3434
    35         // Call the wp_load_options function to load the options.
    36         wp_load_options( $options_to_load );
     35        // Call the wp_prime_option_caches function to prime the options.
     36        wp_prime_option_caches( $options_to_prime );
    3737
    3838        // Store the initial database query count.
     
    4040
    4141        // Check that options are only in the 'options' cache group.
    42         foreach ( $options_to_load as $option ) {
     42        foreach ( $options_to_prime as $option ) {
    4343            $this->assertSame(
    4444                wp_cache_get( $option, 'options' ),
    4545                get_option( $option ),
    46                 "$option was not loaded to the 'options' cache group."
     46                "$option was not primed in the 'options' cache group."
    4747            );
    4848
     
    5050                wp_cache_get( $option, 'notoptions' ),
    5151                get_option( $option ),
    52                 "$option was loaded to the 'notoptions' cache group."
     52                "$option was primed in the 'notoptions' cache group."
    5353            );
    5454        }
     
    6363
    6464    /**
    65      * Tests wp_load_options() with options that do not exist in the database.
     65     * Tests wp_prime_option_caches() with options that do not exist in the database.
    6666     *
    6767     * @ticket 58962
    6868     */
    69     public function test_wp_load_options_with_nonexistent_options() {
    70         // Create some options to load.
    71         $options_to_load = array(
     69    public function test_wp_prime_option_caches_with_nonexistent_options() {
     70        // Create some options to prime.
     71        $options_to_prime = array(
    7272            'option1',
    7373            'option2',
     
    7979         * check options are not in cache initially.
    8080         */
    81         foreach ( $options_to_load as $option ) {
     81        foreach ( $options_to_prime as $option ) {
    8282            $this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." );
    8383        }
    8484
    85         // Call the wp_load_options function to load the options.
    86         wp_load_options( $options_to_load );
     85        // Call the wp_prime_option_caches function to prime the options.
     86        wp_prime_option_caches( $options_to_prime );
    8787
    8888        // Check that options are not in the cache or database.
    89         foreach ( $options_to_load as $option ) {
     89        foreach ( $options_to_prime as $option ) {
    9090            $this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." );
    9191        }
     
    9494        $new_notoptions = wp_cache_get( 'notoptions', 'options' );
    9595        $this->assertIsArray( $new_notoptions, 'The notoptions cache should be an array.' );
    96         foreach ( $options_to_load as $option ) {
     96        foreach ( $options_to_prime as $option ) {
    9797            $this->assertArrayHasKey( $option, $new_notoptions, "$option was not added to the notoptions cache." );
    9898        }
     
    100100
    101101    /**
    102      * Tests wp_load_options() with an empty array.
     102     * Tests wp_prime_option_caches() with an empty array.
    103103     *
    104104     * @ticket 58962
    105105     */
    106     public function test_wp_load_options_with_empty_array() {
     106    public function test_wp_prime_option_caches_with_empty_array() {
    107107        $alloptions = wp_load_alloptions();
    108108        $notoptions = wp_cache_get( 'notoptions', 'options' );
    109109
    110         wp_load_options( array() );
     110        wp_prime_option_caches( array() );
    111111
    112112        $this->assertSame( $alloptions, wp_cache_get( 'alloptions', 'options' ), 'The alloptions cache was modified.' );
     
    115115
    116116    /**
    117      * Tests that wp_load_options handles an empty "notoptions" cache.
     117     * Tests that wp_prime_option_caches() handles an empty "notoptions" cache.
    118118     *
    119119     * @ticket 58962
    120120     */
    121     public function test_wp_load_options_handles_empty_notoptions_cache() {
     121    public function test_wp_prime_option_caches_handles_empty_notoptions_cache() {
    122122        wp_cache_delete( 'notoptions', 'options' );
    123123
    124         wp_load_options( array( 'nonexistent_option' ) );
     124        wp_prime_option_caches( array( 'nonexistent_option' ) );
    125125
    126126        $notoptions = wp_cache_get( 'notoptions', 'options' );
  • trunk/tests/phpunit/tests/option/wpPrimeOptionCachesByGroup.php

    r57012 r57013  
    11<?php
    22/**
    3  * Test wp_load_options_by_group().
     3 * Test wp_prime_option_caches_by_group().
    44 *
    55 * @group option
    66 *
    7  * @covers ::wp_load_options_by_group
     7 * @covers ::wp_prime_option_caches_by_group
    88 */
    9 class Tests_Option_PrimeOptionsByGroup extends WP_UnitTestCase {
     9class Tests_Option_WpPrimeOptionCachesByGroup extends WP_UnitTestCase {
    1010
    1111    /**
    12      * Tests that wp_load_options_by_group() only loads options in the specified group.
     12     * Tests that wp_prime_option_caches_by_group() only primes options in the specified group.
    1313     *
    1414     * @ticket 58962
    1515     */
    16     public function test_wp_load_options_by_group() {
     16    public function test_wp_prime_option_caches_by_group() {
    1717        global $new_allowed_options;
    1818
    19         // Create some options to load.
     19        // Create some options to prime.
    2020        $new_allowed_options = array(
    2121            'group1' => array(
     
    2828        );
    2929
    30         $options_to_load = array(
     30        $options_to_prime = array(
    3131            'option1',
    3232            'option2',
     
    3939         * check options are not in cache initially.
    4040         */
    41         foreach ( $options_to_load as $option ) {
     41        foreach ( $options_to_prime as $option ) {
    4242            update_option( $option, "value_$option", false );
    4343            wp_cache_delete( $option, 'options' );
     
    4545        }
    4646
    47         // Call the wp_load_options_by_group function to load the options.
    48         wp_load_options_by_group( 'group1' );
     47        // Call the wp_prime_option_caches_by_group function to prime the options.
     48        wp_prime_option_caches_by_group( 'group1' );
    4949
    5050        // Check that options are now in the cache.
    51         $this->assertSame( get_option( 'option1' ), wp_cache_get( 'option1', 'options' ), 'option1 was not loaded.' );
    52         $this->assertSame( get_option( 'option2' ), wp_cache_get( 'option2', 'options' ), 'option2 was not loaded.' );
     51        $this->assertSame( get_option( 'option1' ), wp_cache_get( 'option1', 'options' ), 'option1\'s cache was not primed.' );
     52        $this->assertSame( get_option( 'option2' ), wp_cache_get( 'option2', 'options' ), 'option2\'s cache was not primed.' );
    5353
    5454        // Make sure option3 is still not in cache.
     
    5757
    5858    /**
    59      * Tests wp_load_options_by_group() with a nonexistent option group.
     59     * Tests wp_prime_option_caches_by_group() with a nonexistent option group.
    6060     *
    6161     * @ticket 58962
    6262     */
    63     public function test_wp_load_options_by_group_with_nonexistent_group() {
     63    public function test_wp_prime_option_caches_by_group_with_nonexistent_group() {
    6464        // Make sure options are not in cache or database initially.
    6565        $this->assertFalse( wp_cache_get( 'option1', 'options' ), 'option1 was not deleted from the cache.' );
    6666        $this->assertFalse( wp_cache_get( 'option2', 'options' ), 'option2 was not deleted from the cache.' );
    6767
    68         // Call the wp_load_options_by_group function with a nonexistent group.
    69         wp_load_options_by_group( 'nonexistent_group' );
     68        // Call the wp_prime_option_caches_by_group function with a nonexistent group.
     69        wp_prime_option_caches_by_group( 'nonexistent_group' );
    7070
    7171        // Check that options are still not in the cache or database.
Note: See TracChangeset for help on using the changeset viewer.