Changeset 57920
- Timestamp:
- 04/03/2024 09:29:13 PM (5 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r57919 r57920 287 287 288 288 // Misc filters. 289 add_filter( 'wp_default_autoload_value', 'wp_filter_default_autoload_value_via_option_size', 10, 4 ); 289 290 add_filter( 'option_ping_sites', 'privacy_ping_filter' ); 290 291 add_filter( 'option_blog_charset', '_wp_specialchars' ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop. -
trunk/src/wp-includes/option.php
r57110 r57920 393 393 394 394 $grouped_options = array( 395 ' yes'=> array(),396 ' no'=> array(),395 'on' => array(), 396 'off' => array(), 397 397 ); 398 398 $results = array(); 399 399 foreach ( $options as $option => $autoload ) { 400 400 wp_protect_special_option( $option ); // Ensure only valid options can be passed. 401 if ( ' no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly.402 $grouped_options[' no'][] = $option;401 if ( 'off' === $autoload || 'no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly. 402 $grouped_options['off'][] = $option; 403 403 } else { 404 $grouped_options[' yes'][] = $option;404 $grouped_options['on'][] = $option; 405 405 } 406 406 $results[ $option ] = false; // Initialize result value. … … 466 466 467 467 /* 468 * If any options were changed to ' yes', delete their individual caches, and delete 'alloptions' cache so that it468 * If any options were changed to 'on', delete their individual caches, and delete 'alloptions' cache so that it 469 469 * is refreshed as needed. 470 * If no options were changed to ' yes' but any options were changed to 'no', delete them from the 'alloptions'471 * cache. This is not necessary when options were changed to ' yes', since in that situation the entire cache is470 * If no options were changed to 'on' but any options were changed to 'no', delete them from the 'alloptions' 471 * cache. This is not necessary when options were changed to 'on', since in that situation the entire cache is 472 472 * deleted anyway. 473 473 */ 474 if ( $grouped_options[' yes'] ) {475 wp_cache_delete_multiple( $grouped_options[' yes'], 'options' );474 if ( $grouped_options['on'] ) { 475 wp_cache_delete_multiple( $grouped_options['on'], 'options' ); 476 476 wp_cache_delete( 'alloptions', 'options' ); 477 } elseif ( $grouped_options[' no'] ) {477 } elseif ( $grouped_options['off'] ) { 478 478 $alloptions = wp_load_alloptions( true ); 479 479 480 foreach ( $grouped_options[' no'] as $option ) {480 foreach ( $grouped_options['off'] as $option ) { 481 481 if ( isset( $alloptions[ $option ] ) ) { 482 482 unset( $alloptions[ $option ] ); … … 607 607 if ( ! $alloptions ) { 608 608 $suppress = $wpdb->suppress_errors(); 609 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ); 609 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload IN ( '" . implode( "', '", wp_autoload_values_to_autoload() ) . "' )" ); 610 610 611 if ( ! $alloptions_db ) { 611 612 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); … … 706 707 * @global wpdb $wpdb WordPress database abstraction object. 707 708 * 708 * @param string $option Name of the option to update. Expected to not be SQL-escaped. 709 * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. 710 * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, 711 * `$autoload` can only be updated using `update_option()` if `$value` is also changed. 712 * Accepts 'yes'|true to enable or 'no'|false to disable. 713 * Autoloading too many options can lead to performance problems, especially if the 714 * options are not frequently used. For options which are accessed across several places 715 * in the frontend, it is recommended to autoload them, by using 'yes'|true. 716 * For options which are accessed only on few specific URLs, it is recommended 717 * to not autoload them, by using 'no'|false. For non-existent options, the default value 718 * is 'yes'. Default null. 709 * @param string $option Name of the option to update. Expected to not be SQL-escaped. 710 * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. 711 * @param bool|null $autoload Optional. Whether to load the option when WordPress starts up. 712 * Accepts a boolean, or `null` to stick with the initial value or, if no initial value is set, 713 * to leave the decision up to default heuristics in WordPress. 714 * For existing options, 715 * `$autoload` can only be updated using `update_option()` if `$value` is also changed. 716 * For backward compatibility 'yes' and 'no' are also accepted. 717 * Autoloading too many options can lead to performance problems, especially if the 718 * options are not frequently used. For options which are accessed across several places 719 * in the frontend, it is recommended to autoload them, by using true. 720 * For options which are accessed only on few specific URLs, it is recommended 721 * to not autoload them, by using false. 722 * For non-existent options, the default is null, which means WordPress will determine 723 * the autoload value. 719 724 * @return bool True if the value was updated, false otherwise. 720 725 */ … … 802 807 /** This filter is documented in wp-includes/option.php */ 803 808 if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { 804 // Default setting for new options is 'yes'.805 if ( null === $autoload ) {806 $autoload = 'yes';807 }808 809 809 return add_option( $option, $value, '', $autoload ); 810 810 } … … 828 828 829 829 if ( null !== $autoload ) { 830 $update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; 830 $update_args['autoload'] = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); 831 } else { 832 // Retrieve the current autoload value to reevaluate it in case it was set automatically. 833 $raw_autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); 834 $allow_values = array( 'auto-on', 'auto-off', 'auto' ); 835 if ( in_array( $raw_autoload, $allow_values, true ) ) { 836 $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); 837 if ( $autoload !== $raw_autoload ) { 838 $update_args['autoload'] = $autoload; 839 } 840 } 831 841 } 832 842 … … 854 864 wp_cache_set( $option, $serialized_value, 'options' ); 855 865 } 856 } elseif ( 'yes' === $update_args['autoload']) {866 } elseif ( in_array( $update_args['autoload'], wp_autoload_values_to_autoload(), true ) ) { 857 867 // Delete the individual cache, then set in alloptions cache. 858 868 wp_cache_delete( $option, 'options' ); … … 916 926 * 917 927 * @since 1.0.0 928 * @since 6.6.0 The $autoload parameter's default value was changed to null. 918 929 * 919 930 * @global wpdb $wpdb WordPress database abstraction object. 920 931 * 921 * @param string $option Name of the option to add. Expected to not be SQL-escaped. 922 * @param mixed $value Optional. Option value. Must be serializable if non-scalar. 923 * Expected to not be SQL-escaped. 924 * @param string $deprecated Optional. Description. Not used anymore. 925 * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. 926 * Accepts 'yes'|true to enable or 'no'|false to disable. 927 * Autoloading too many options can lead to performance problems, especially if the 928 * options are not frequently used. For options which are accessed across several places 929 * in the frontend, it is recommended to autoload them, by using 'yes'|true. 930 * For options which are accessed only on few specific URLs, it is recommended 931 * to not autoload them, by using 'no'|false. Default 'yes'. 932 * @param string $option Name of the option to add. Expected to not be SQL-escaped. 933 * @param mixed $value Optional. Option value. Must be serializable if non-scalar. 934 * Expected to not be SQL-escaped. 935 * @param string $deprecated Optional. Description. Not used anymore. 936 * @param bool|null $autoload Optional. Whether to load the option when WordPress starts up. 937 * Accepts a boolean, or `null` to leave the decision up to default heuristics in WordPress. 938 * For backward compatibility 'yes' and 'no' are also accepted. 939 * Autoloading too many options can lead to performance problems, especially if the 940 * options are not frequently used. For options which are accessed across several places 941 * in the frontend, it is recommended to autoload them, by using 'yes'|true. 942 * For options which are accessed only on few specific URLs, it is recommended 943 * to not autoload them, by using false. 944 * Default is null, which means WordPress will determine the autoload value. 932 945 * @return bool True if the option was added, false otherwise. 933 946 */ 934 function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes') {947 function add_option( $option, $value = '', $deprecated = '', $autoload = null ) { 935 948 global $wpdb; 936 949 … … 992 1005 993 1006 $serialized_value = maybe_serialize( $value ); 994 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; 1007 1008 $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); 995 1009 996 1010 /** … … 1010 1024 1011 1025 if ( ! wp_installing() ) { 1012 if ( 'yes' === $autoload) {1026 if ( in_array( $autoload, wp_autoload_values_to_autoload(), true ) ) { 1013 1027 $alloptions = wp_load_alloptions( true ); 1014 1028 $alloptions[ $option ] = $serialized_value; … … 1094 1108 1095 1109 if ( ! wp_installing() ) { 1096 if ( 'yes' === $row->autoload) {1110 if ( in_array( $row->autoload, wp_autoload_values_to_autoload(), true ) ) { 1097 1111 $alloptions = wp_load_alloptions( true ); 1098 1112 … … 1132 1146 1133 1147 return false; 1148 } 1149 1150 /** 1151 * Determines the appropriate autoload value for an option based on input. 1152 * 1153 * This function checks the provided autoload value and returns a standardized value 1154 * ('on', 'off', 'auto-on', 'auto-off', or 'auto') based on specific conditions. 1155 * 1156 * If no explicit autoload value is provided, the function will check for certain heuristics around the given option. 1157 * It will return `auto-on` to indicate autoloading, `auto-off` to indicate not autoloading, or `auto` if no clear 1158 * decision could be made. 1159 * 1160 * @since 6.6.0 1161 * @access private 1162 * 1163 * @param string $option The name of the option. 1164 * @param mixed $value The value of the option to check its autoload value. 1165 * @param mixed $serialized_value The serialized value of the option to check its autoload value. 1166 * @param bool|null $autoload The autoload value to check. 1167 * Accepts 'on'|true to enable or 'off'|false to disable, or 1168 * 'auto-on', 'auto-off', or 'auto' for internal purposes. 1169 * Any other autoload value will be forced to either 'auto-on', 1170 * 'auto-off', or 'auto'. 1171 * 'yes' and 'no' are supported for backward compatibility. 1172 * @return string Returns the original $autoload value if explicit, or 'auto-on', 'auto-off', 1173 * or 'auto' depending on default heuristics. 1174 */ 1175 function wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ) { 1176 1177 // Check if autoload is a boolean. 1178 if ( is_bool( $autoload ) ) { 1179 return $autoload ? 'on' : 'off'; 1180 } 1181 1182 switch ( $autoload ) { 1183 case 'on': 1184 case 'yes': 1185 return 'on'; 1186 case 'off': 1187 case 'no': 1188 return 'off'; 1189 } 1190 1191 /** 1192 * Allows to determine the default autoload value for an option where no explicit value is passed. 1193 * 1194 * @since 6.6.0 1195 * 1196 * @param bool|null $autoload The default autoload value to set. Returning true will be set as 'auto-on' in the 1197 * database, false will be set as 'auto-off', and null will be set as 'auto'. 1198 * @param string $option The passed option name. 1199 * @param mixed $value The passed option value to be saved. 1200 */ 1201 $autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value ); 1202 if ( is_bool( $autoload ) ) { 1203 return $autoload ? 'auto-on' : 'auto-off'; 1204 } 1205 1206 return 'auto'; 1207 } 1208 1209 /** 1210 * Filters the default autoload value to disable autoloading if the option value is too large. 1211 * 1212 * @since 6.6.0 1213 * @access private 1214 * 1215 * @param bool|null $autoload The default autoload value to set. 1216 * @param string $option The passed option name. 1217 * @param mixed $value The passed option value to be saved. 1218 * @param mixed $serialized_value The passed option value to be saved, in serialized form. 1219 * @return bool|null Potentially modified $default. 1220 */ 1221 function wp_filter_default_autoload_value_via_option_size( $autoload, $option, $value, $serialized_value ) { 1222 /** 1223 * Filters the maximum size of option value in bytes. 1224 * 1225 * @since 6.6.0 1226 * 1227 * @param int $max_option_size The option-size threshold, in bytes. Default 150000. 1228 * @param string $option The name of the option. 1229 */ 1230 $max_option_size = (int) apply_filters( 'wp_max_autoloaded_option_size', 150000, $option ); 1231 $size = ! empty( $serialized_value ) ? strlen( $serialized_value ) : 0; 1232 1233 if ( $size > $max_option_size ) { 1234 return false; 1235 } 1236 1237 return $autoload; 1134 1238 } 1135 1239 … … 2925 3029 return $registered[ $option ]['default']; 2926 3030 } 3031 3032 /** 3033 * Returns the values that trigger autoloading from the options table. 3034 * 3035 * @since 6.6.0 3036 * 3037 * @return array The values that trigger autoloading. 3038 */ 3039 function wp_autoload_values_to_autoload() { 3040 $autoload_values = array( 'yes', 'on', 'auto-on', 'auto' ); 3041 3042 /** 3043 * Filters the autoload values that should be considered for autoloading from the options table. 3044 * 3045 * The filter can only be used to remove autoload values from the default list. 3046 * 3047 * @since 6.6.0 3048 * 3049 * @param array $autoload_values Autoload values used to autoload option. 3050 * Default list contains 'yes', 'on', 'auto-on', and 'auto'. 3051 */ 3052 $filtered_values = apply_filters( 'wp_autoload_values_to_autoload', $autoload_values ); 3053 3054 return array_intersect( $filtered_values, $autoload_values ); 3055 } -
trunk/tests/phpunit/tests/customize/setting.php
r56536 r57920 611 611 $setting->save(); 612 612 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) ); 613 $this->assertSame( ' yes', $autoload );613 $this->assertSame( 'on', $autoload ); 614 614 $this->assertSame( $value, get_option( $name ) ); 615 615 … … 627 627 $setting->save(); 628 628 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) ); 629 $this->assertSame( ' yes', $autoload );629 $this->assertSame( 'on', $autoload ); 630 630 $this->assertSame( $value, get_option( $name ) ); 631 631 … … 643 643 $setting->save(); 644 644 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) ); 645 $this->assertSame( ' no', $autoload );645 $this->assertSame( 'off', $autoload ); 646 646 $this->assertSame( $value, get_option( $name ) ); 647 647 … … 666 666 $setting1->save(); 667 667 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $id_base ) ); 668 $this->assertSame( ' no', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no' );668 $this->assertSame( 'off', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no' ); 669 669 } 670 670 -
trunk/tests/phpunit/tests/option/option.php
r56946 r57920 309 309 'string 123' => array( '123' ), 310 310 'integer 123' => array( 123 ), 311 'integer -123' => array( - 123 ),311 'integer -123' => array( - 123 ), 312 312 'float 12.3' => array( 12.3 ), 313 'float -1.23' => array( - 1.23 ),313 'float -1.23' => array( - 1.23 ), 314 314 'boolean true' => array( true ), 315 315 ); … … 360 360 public function data_option_autoloading() { 361 361 return array( 362 array( 'autoload_yes', 'yes', 'yes' ), 363 array( 'autoload_true', true, 'yes' ), 364 array( 'autoload_string', 'foo', 'yes' ), 365 array( 'autoload_int', 123456, 'yes' ), 366 array( 'autoload_array', array(), 'yes' ), 367 array( 'autoload_no', 'no', 'no' ), 368 array( 'autoload_false', false, 'no' ), 369 ); 362 // Supported values. 363 array( 'autoload_yes', 'yes', 'on' ), 364 array( 'autoload_true', true, 'on' ), 365 array( 'autoload_no', 'no', 'off' ), 366 array( 'autoload_false', false, 'off' ), 367 array( 'autoload_null', null, 'auto' ), 368 369 // Technically unsupported values. 370 array( 'autoload_string', 'foo', 'auto' ), 371 array( 'autoload_int', 123456, 'auto' ), 372 array( 'autoload_array', array(), 'auto' ), 373 ); 374 } 375 376 /** 377 * @ticket 42441 378 * 379 * @covers ::update_option 380 * 381 * @dataProvider data_option_autoloading_large_option 382 */ 383 public function test_update_option_autoloading_large_option( $autoload, $expected ) { 384 global $wpdb; 385 $name = 'foo'; 386 add_option( $name, 'bar' ); 387 add_filter( 'wp_max_autoloaded_option_size', array( $this, 'filter_max_option_size' ) ); 388 $value = file( DIR_TESTDATA . '/formatting/entities.txt' ); 389 $updated = update_option( $name, $value, $autoload ); 390 $this->assertTrue( $updated ); 391 392 $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) ); 393 $this->assertSame( $expected, $actual->autoload ); 394 } 395 396 public function data_option_autoloading_large_option() { 397 return array( 398 'on' => array( 399 'autoload' => 'on', 400 'expected' => 'on', 401 ), 402 'off' => array( 403 'autoload' => 'off', 404 'expected' => 'off', 405 ), 406 'yes' => array( 407 'autoload' => 'yes', 408 'expected' => 'on', 409 ), 410 'true' => array( 411 'autoload' => true, 412 'expected' => 'on', 413 ), 414 'no' => array( 415 'autoload' => 'no', 416 'expected' => 'off', 417 ), 418 'false' => array( 419 'autoload' => false, 420 'expected' => 'off', 421 ), 422 'null' => array( 423 'autoload' => null, 424 'expected' => 'auto-off', 425 ), 426 ); 427 } 428 429 public function filter_max_option_size( $current ) { 430 return 1000; 431 } 432 433 /** 434 * @ticket 42441 435 * 436 * @covers ::update_option 437 */ 438 public function test_update_option_autoloading_small_option_auto() { 439 global $wpdb; 440 441 $name = 'foo'; 442 add_option( $name, 'bar' ); 443 $updated = update_option( $name, 'small_option_data' ); 444 $this->assertTrue( $updated ); 445 446 $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) ); 447 $this->assertSame( 'auto', $actual->autoload ); 370 448 } 371 449 -
trunk/tests/phpunit/tests/option/wpLoadAlloptions.php
r55745 r57920 18 18 public function test_if_alloptions_is_cached() { 19 19 $this->assertNotEmpty( wp_cache_get( 'alloptions', 'options' ) ); 20 } 21 22 /** 23 * @ticket 42441 24 * 25 * @covers ::wp_load_alloptions 26 */ 27 public function test_default_and_yes() { 28 add_option( 'foo', 'bar' ); 29 add_option( 'bar', 'foo', '', 'yes' ); 30 $alloptions = wp_load_alloptions(); 31 $this->assertArrayHasKey( 'foo', $alloptions ); 32 $this->assertArrayHasKey( 'bar', $alloptions ); 33 } 34 35 /** 36 * @ticket 42441 37 * 38 * @covers ::wp_load_alloptions 39 */ 40 public function test_default_and_no() { 41 add_option( 'foo', 'bar' ); 42 add_option( 'bar', 'foo', '', 'no' ); 43 $alloptions = wp_load_alloptions(); 44 $this->assertArrayHasKey( 'foo', $alloptions ); 45 $this->assertArrayNotHasKey( 'bar', $alloptions ); 20 46 } 21 47 -
trunk/tests/phpunit/tests/option/wpSetOptionAutoload.php
r56508 r57920 23 23 24 24 $this->assertTrue( wp_set_option_autoload( $option, 'yes' ), 'Function did not succeed' ); 25 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );25 $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 26 26 $this->assertFalse( wp_cache_get( $option, 'options' ), 'Option not deleted from individual cache' ); 27 27 $this->assertFalse( wp_cache_get( 'alloptions', 'options' ), 'Alloptions cache not cleared' ); … … 42 42 43 43 $this->assertTrue( wp_set_option_autoload( $option, 'no' ), 'Function did not succeed' ); 44 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );44 $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 45 45 $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), 'Option not deleted from alloptions cache' ); 46 46 } … … 60 60 61 61 $this->assertFalse( wp_set_option_autoload( $option, 'yes' ), 'Function did unexpectedly succeed' ); 62 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value unexpectedly updated in database' );62 $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value unexpectedly updated in database' ); 63 63 } 64 64 … … 93 93 94 94 $this->assertTrue( wp_set_option_autoload( $option, true ), 'Function did not succeed' ); 95 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );95 $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 96 96 } 97 97 … … 110 110 111 111 $this->assertTrue( wp_set_option_autoload( $option, false ), 'Function did not succeed' ); 112 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );112 $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 113 113 } 114 114 } -
trunk/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php
r56559 r57920 31 31 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 32 32 $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' ); 33 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );33 $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 34 34 foreach ( $options as $option => $autoload ) { 35 35 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 62 62 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 63 63 $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' ); 64 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );64 $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 65 65 foreach ( $options as $option => $autoload ) { 66 66 $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s not deleted from alloptions cache', $option ) ); … … 90 90 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 91 91 $this->assertSame( $num_queries + 1, get_num_queries(), 'Function made unexpected amount of database queries' ); 92 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );92 $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 93 93 foreach ( $options as $option => $autoload ) { 94 94 $this->assertArrayHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s unexpectedly deleted from alloptions cache', $option ) ); … … 125 125 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 126 126 $this->assertSame( $num_queries + 3, get_num_queries(), 'Function made unexpected amount of database queries' ); 127 $this->assertSameSets( array( ' yes', 'no', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );127 $this->assertSameSets( array( 'on', 'off', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 128 128 foreach ( $options as $option => $autoload ) { 129 129 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 159 159 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 160 160 $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' ); 161 $this->assertSameSets( array( ' yes', 'no', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );161 $this->assertSameSets( array( 'on', 'off', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 162 162 foreach ( $options as $option => $autoload ) { 163 163 if ( 'no' === $autoload ) { … … 200 200 201 201 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 202 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );202 $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 203 203 } 204 204 … … 225 225 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 226 226 $this->assertSame( $num_queries + 3, get_num_queries(), 'Function made unexpected amount of database queries' ); 227 $this->assertSameSets( array( ' yes', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );227 $this->assertSameSets( array( 'on', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 228 228 } 229 229 -
trunk/tests/phpunit/tests/option/wpSetOptionsAutoload.php
r56508 r57920 31 31 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function did not succeed' ); 32 32 $this->assertSame( $num_queries + 2, get_num_queries(), 'Updating options autoload value ran too many queries' ); 33 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );33 $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 34 34 foreach ( $options as $option => $value ) { 35 35 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 60 60 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'no' ), 'Function did not succeed' ); 61 61 $this->assertSame( $num_queries + 2, get_num_queries(), 'Updating options autoload value ran too many queries' ); 62 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );62 $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 63 63 foreach ( $options as $option => $value ) { 64 64 $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s not deleted from alloptions cache', $option ) ); … … 88 88 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function did unexpectedly succeed' ); 89 89 $this->assertSame( $num_queries + 1, get_num_queries(), 'Function attempted to update options autoload value in database' ); 90 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Options autoload value unexpectedly updated in database' );90 $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Options autoload value unexpectedly updated in database' ); 91 91 } 92 92 … … 134 134 135 135 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function produced unexpected result' ); 136 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );136 $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 137 137 foreach ( $options as $option => $value ) { 138 138 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 162 162 163 163 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), true ), 'Function produced unexpected result' ); 164 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );164 $this->assertSame( array( 'on', 'on' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 165 165 } 166 166 … … 186 186 187 187 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), false ), 'Function produced unexpected result' ); 188 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );188 $this->assertSame( array( 'off', 'off' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 189 189 } 190 190 } -
trunk/tests/phpunit/tests/theme/autoloadThemeMods.php
r57153 r57920 29 29 switch_theme( $new_theme_stylesheet ); 30 30 31 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );32 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );31 $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' ); 32 $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' ); 33 33 34 34 switch_theme( $current_theme_stylesheet ); 35 35 36 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );37 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );36 $this->assertSame( 'on', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' ); 37 $this->assertSame( 'off', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' ); 38 38 39 39 // Basic assertion to make sure that we haven't lost the mods.
Note: See TracChangeset
for help on using the changeset viewer.