Ticket #15058: 15058.2.diff
File 15058.2.diff, 3.6 KB (added by , 10 years ago) |
---|
-
tests/phpunit/tests/option/transient.php
83 83 update_option( '_transient_timeout_' . $key, $now - 1 ); 84 84 $this->assertFalse( get_transient( $key ) ); 85 85 } 86 87 /** 88 * ticket 15058 89 */ 90 function test_transient_long() { 91 $long_name = "thisisaverylongnamethatwillnotfitincolumnbecauseitistoolongforthecolumn"; 92 set_transient( $long_name, true, 60 ); 93 $this->assertTrue( get_transient( $long_name ) ); 94 } 86 95 } -
tests/phpunit/tests/option/option.php
99 99 function test_special_option_name_notoptions() { 100 100 delete_option( 'notoptions' ); 101 101 } 102 103 function test_option_add_long() { 104 $long_name = "thisisaverylongnamethatwillnotfitincolumnbecauseitistoolongforthecolumn"; 105 add_option( $long_name, true ); 106 $this->assertTrue( get_option( $long_name ) ); 107 } 108 109 function test_option_update_long() { 110 $long_name = "thisisaverylongnamethatwillnotfitincolumnbecauseitistoolongforthecolumn"; 111 add_option( $long_name, true ); 112 update_option( $long_name, 5 ); 113 $this->assertEquals( 5, get_option( $long_name ) ); 114 } 102 115 } -
src/wp-includes/option.php
29 29 if ( empty( $option ) ) 30 30 return false; 31 31 32 $option = long_option_name( $option ); 33 32 34 /** 33 35 * Filter the value of an existing option before it is retrieved. 34 36 * … … 212 214 } 213 215 214 216 /** 217 * This function allows long option names to work. 218 * 219 * @since 4.1.0 220 * 221 * @param string $option Option name. 222 * @param int $max_length Max length of the option name. 223 * @return string $option Modified option name if longer than $max_length. 224 */ 225 function long_option_name( $option, $max_length = 64 ) { 226 if( strlen( $option ) > 64 ) { 227 $option = md5( $option ); 228 $option = "md5_" . $option; 229 } else { 230 return $option; 231 } 232 } 233 234 /** 215 235 * Update the value of an option that was already added. 216 236 * 217 237 * You do not need to serialize values. If the value needs to be serialized, then … … 240 260 if ( is_object( $value ) ) 241 261 $value = clone $value; 242 262 263 $option = long_option_name( $option ); 264 243 265 $value = sanitize_option( $option, $value ); 244 266 $old_value = get_option( $option ); 245 267 … … 377 399 $serialized_value = maybe_serialize( $value ); 378 400 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes'; 379 401 402 $option = long_option_name( $option ); 403 380 404 /** 381 405 * Fires before an option is added. 382 406 * … … 582 606 if ( wp_using_ext_object_cache() ) { 583 607 $value = wp_cache_get( $transient, 'transient' ); 584 608 } else { 609 610 $transient = long_option_name( $transient, 40 ); 611 585 612 $transient_option = '_transient_' . $transient; 586 613 if ( ! defined( 'WP_INSTALLING' ) ) { 587 614 // If option is not in alloptions, it is not autoloaded and thus has a timeout … … 645 672 if ( wp_using_ext_object_cache() ) { 646 673 $result = wp_cache_set( $transient, $value, 'transient', $expiration ); 647 674 } else { 675 676 $transient = long_option_name( $transient, 40 ); 677 648 678 $transient_timeout = '_transient_timeout_' . $transient; 649 679 $transient = '_transient_' . $transient; 680 650 681 if ( false === get_option( $transient ) ) { 651 682 $autoload = 'yes'; 652 683 if ( $expiration ) {