Changeset 57013
- Timestamp:
- 10/26/2023 10:54:15 PM (13 months ago)
- Location:
- trunk
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/option.php
r56990 r57013 249 249 250 250 /** 251 * Loads specific options into the cache with a single database query.251 * Primes specific options into the cache with a single database query. 252 252 * 253 253 * Only options that do not already exist in cache will be loaded. … … 259 259 * @param array $options An array of option names to be loaded. 260 260 */ 261 function wp_ load_options( $options ) {261 function wp_prime_option_caches( $options ) { 262 262 $alloptions = wp_load_alloptions(); 263 263 $cached_options = wp_cache_get_multiple( $options, 'options' ); … … 322 322 323 323 /** 324 * Loadsall options registered with a specific option group.324 * Primes the cache of all options registered with a specific option group. 325 325 * 326 326 * @since 6.4.0 … … 330 330 * @param string $option_group The option group to load options for. 331 331 */ 332 function wp_ load_options_by_group( $option_group ) {332 function wp_prime_option_caches_by_group( $option_group ) { 333 333 global $new_allowed_options; 334 334 335 335 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 ] ); 337 337 } 338 338 } … … 349 349 */ 350 350 function get_options( $options ) { 351 wp_ load_options( $options );351 wp_prime_option_caches( $options ); 352 352 353 353 $result = array(); -
trunk/tests/phpunit/tests/option/wpPrimeOptionCaches.php
r57012 r57013 1 1 <?php 2 2 /** 3 * Test wp_ load_options().3 * Test wp_prime_option_caches(). 4 4 * 5 5 * @group option 6 6 * 7 * @covers ::wp_ load_options7 * @covers ::wp_prime_option_caches 8 8 */ 9 class Tests_Option_ PrimeOptions extends WP_UnitTestCase {9 class Tests_Option_WpPrimeOptionCaches extends WP_UnitTestCase { 10 10 11 11 /** 12 * Tests that wp_ load_options() loads multiple options.12 * Tests that wp_prime_option_caches() primes multiple options. 13 13 * 14 14 * @ticket 58962 15 15 */ 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( 19 19 'option1', 20 20 'option2', … … 27 27 * check options are not in cache initially. 28 28 */ 29 foreach ( $options_to_ loadas $option ) {29 foreach ( $options_to_prime as $option ) { 30 30 update_option( $option, "value_$option", false ); 31 31 wp_cache_delete( $option, 'options' ); … … 33 33 } 34 34 35 // Call the wp_ load_options function to loadthe 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 ); 37 37 38 38 // Store the initial database query count. … … 40 40 41 41 // Check that options are only in the 'options' cache group. 42 foreach ( $options_to_ loadas $option ) {42 foreach ( $options_to_prime as $option ) { 43 43 $this->assertSame( 44 44 wp_cache_get( $option, 'options' ), 45 45 get_option( $option ), 46 "$option was not loaded tothe 'options' cache group."46 "$option was not primed in the 'options' cache group." 47 47 ); 48 48 … … 50 50 wp_cache_get( $option, 'notoptions' ), 51 51 get_option( $option ), 52 "$option was loaded tothe 'notoptions' cache group."52 "$option was primed in the 'notoptions' cache group." 53 53 ); 54 54 } … … 63 63 64 64 /** 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. 66 66 * 67 67 * @ticket 58962 68 68 */ 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( 72 72 'option1', 73 73 'option2', … … 79 79 * check options are not in cache initially. 80 80 */ 81 foreach ( $options_to_ loadas $option ) {81 foreach ( $options_to_prime as $option ) { 82 82 $this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." ); 83 83 } 84 84 85 // Call the wp_ load_options function to loadthe 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 ); 87 87 88 88 // Check that options are not in the cache or database. 89 foreach ( $options_to_ loadas $option ) {89 foreach ( $options_to_prime as $option ) { 90 90 $this->assertFalse( wp_cache_get( $option, 'options' ), "$option was not deleted from the cache." ); 91 91 } … … 94 94 $new_notoptions = wp_cache_get( 'notoptions', 'options' ); 95 95 $this->assertIsArray( $new_notoptions, 'The notoptions cache should be an array.' ); 96 foreach ( $options_to_ loadas $option ) {96 foreach ( $options_to_prime as $option ) { 97 97 $this->assertArrayHasKey( $option, $new_notoptions, "$option was not added to the notoptions cache." ); 98 98 } … … 100 100 101 101 /** 102 * Tests wp_ load_options() with an empty array.102 * Tests wp_prime_option_caches() with an empty array. 103 103 * 104 104 * @ticket 58962 105 105 */ 106 public function test_wp_ load_options_with_empty_array() {106 public function test_wp_prime_option_caches_with_empty_array() { 107 107 $alloptions = wp_load_alloptions(); 108 108 $notoptions = wp_cache_get( 'notoptions', 'options' ); 109 109 110 wp_ load_options( array() );110 wp_prime_option_caches( array() ); 111 111 112 112 $this->assertSame( $alloptions, wp_cache_get( 'alloptions', 'options' ), 'The alloptions cache was modified.' ); … … 115 115 116 116 /** 117 * Tests that wp_ load_optionshandles an empty "notoptions" cache.117 * Tests that wp_prime_option_caches() handles an empty "notoptions" cache. 118 118 * 119 119 * @ticket 58962 120 120 */ 121 public function test_wp_ load_options_handles_empty_notoptions_cache() {121 public function test_wp_prime_option_caches_handles_empty_notoptions_cache() { 122 122 wp_cache_delete( 'notoptions', 'options' ); 123 123 124 wp_ load_options( array( 'nonexistent_option' ) );124 wp_prime_option_caches( array( 'nonexistent_option' ) ); 125 125 126 126 $notoptions = wp_cache_get( 'notoptions', 'options' ); -
trunk/tests/phpunit/tests/option/wpPrimeOptionCachesByGroup.php
r57012 r57013 1 1 <?php 2 2 /** 3 * Test wp_ load_options_by_group().3 * Test wp_prime_option_caches_by_group(). 4 4 * 5 5 * @group option 6 6 * 7 * @covers ::wp_ load_options_by_group7 * @covers ::wp_prime_option_caches_by_group 8 8 */ 9 class Tests_Option_ PrimeOptionsByGroup extends WP_UnitTestCase {9 class Tests_Option_WpPrimeOptionCachesByGroup extends WP_UnitTestCase { 10 10 11 11 /** 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. 13 13 * 14 14 * @ticket 58962 15 15 */ 16 public function test_wp_ load_options_by_group() {16 public function test_wp_prime_option_caches_by_group() { 17 17 global $new_allowed_options; 18 18 19 // Create some options to load.19 // Create some options to prime. 20 20 $new_allowed_options = array( 21 21 'group1' => array( … … 28 28 ); 29 29 30 $options_to_ load= array(30 $options_to_prime = array( 31 31 'option1', 32 32 'option2', … … 39 39 * check options are not in cache initially. 40 40 */ 41 foreach ( $options_to_ loadas $option ) {41 foreach ( $options_to_prime as $option ) { 42 42 update_option( $option, "value_$option", false ); 43 43 wp_cache_delete( $option, 'options' ); … … 45 45 } 46 46 47 // Call the wp_ load_options_by_group function to loadthe 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' ); 49 49 50 50 // 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.' ); 53 53 54 54 // Make sure option3 is still not in cache. … … 57 57 58 58 /** 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. 60 60 * 61 61 * @ticket 58962 62 62 */ 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() { 64 64 // Make sure options are not in cache or database initially. 65 65 $this->assertFalse( wp_cache_get( 'option1', 'options' ), 'option1 was not deleted from the cache.' ); 66 66 $this->assertFalse( wp_cache_get( 'option2', 'options' ), 'option2 was not deleted from the cache.' ); 67 67 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' ); 70 70 71 71 // Check that options are still not in the cache or database.
Note: See TracChangeset
for help on using the changeset viewer.