Make WordPress Core


Ignore:
Timestamp:
10/26/2023 10:54:15 PM (11 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.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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' );
Note: See TracChangeset for help on using the changeset viewer.