Ticket #50807: approach-2.diff
File approach-2.diff, 11.2 KB (added by , 4 years ago) |
---|
-
src/wp-includes/functions.php
5156 5156 } 5157 5157 5158 5158 /** 5159 * Marks a deprecated option as deprecated and throws a notice. 5160 * 5161 * Use the {@see 'deprecated_option_used'} action to get the backtrace describing where 5162 * the deprecated option was called. 5163 * 5164 * Default behavior is to trigger a user error if `WP_DEBUG` is true. 5165 * 5166 * This function is called by the options API functions, and so generally does not 5167 * need to be called directly. 5168 * 5169 * @since 5.5.0 5170 * @access private 5171 * 5172 * @param string $option The option that was used. 5173 * @param string $version The version of WordPress that deprecated the option. 5174 * @param string $replacement Optional. The option that should have been used. Default empty. 5175 * @param string $message Optional. A message regarding the change. Default empty. 5176 */ 5177 function _deprecated_option( $option, $version, $replacement = '', $message = '' ) { 5178 /** 5179 * Fires when a deprecated option is used. 5180 * 5181 * @since 5.5.0 5182 * 5183 * @param string $hook The option that was used. 5184 * @param string $replacement The option that should be used as a replacement. 5185 * @param string $version The version of WordPress that deprecated the option. 5186 * @param string $message A message regarding the change. 5187 */ 5188 do_action( 'deprecated_option_used', $option, $replacement, $version, $message ); 5189 5190 /** 5191 * Filters whether to trigger deprecated option errors. 5192 * 5193 * @since 5.5.0 5194 * 5195 * @param bool $trigger Whether to trigger deprecated option errors. Requires 5196 * `WP_DEBUG` to be defined true. 5197 */ 5198 if ( WP_DEBUG && apply_filters( 'deprecated_option_trigger_error', true ) ) { 5199 $message = empty( $message ) ? '' : ' ' . $message; 5200 5201 if ( $replacement ) { 5202 trigger_error( 5203 sprintf( 5204 /* translators: 1: WordPress option name, 2: Version number, 3: Alternative option name. */ 5205 __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), 5206 $option, 5207 $version, 5208 $replacement 5209 ) . $message, 5210 E_USER_DEPRECATED 5211 ); 5212 } else { 5213 trigger_error( 5214 sprintf( 5215 /* translators: 1: WordPress option name, 2: Version number. */ 5216 __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), 5217 $option, 5218 $version 5219 ) . $message, 5220 E_USER_DEPRECATED 5221 ); 5222 } 5223 } 5224 } 5225 5226 /** 5159 5227 * Mark something as being incorrectly called. 5160 5228 * 5161 5229 * There is a hook {@see 'doing_it_wrong_run'} that will be called that can be used … … 7627 7695 function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) { 7628 7696 return abs( (float) $expected - (float) $actual ) <= $precision; 7629 7697 } 7698 7699 /** 7700 * Retrieves a list of deprecated options. 7701 * 7702 * @return array List of deprecated options in the 'old_option_key' => 'new_option_key' format. 7703 */ 7704 function get_deprecated_options() { 7705 $deprecated_options = array( 7706 'blacklist_keys' => 'blocklist_keys', 7707 'comment_whitelist' => 'comment_previously_approved', 7708 ); 7709 7710 /** 7711 * Filters the list of deprecated options. 7712 * 7713 * @since 5.5.0 7714 * 7715 * @param array $deprecated_options A list of deprecated options in the 'old_option_key' => 'new_option_key' format. 7716 */ 7717 return apply_filters( 'deprecated_options', $deprecated_options ); 7718 } -
src/wp-includes/option.php
35 35 return false; 36 36 } 37 37 38 $is_deprecated = false; 39 $deprecated_options = get_deprecated_options(); 40 41 if ( isset( $deprecated_options[ $option ] ) ) { 42 $deprecated = true; 43 _deprecated_option( $option, '5.5.0', $deprecated_options[ $option ] ); 44 } 45 38 46 /** 39 47 * Filters the value of an existing option before it is retrieved. 40 48 * … … 57 65 */ 58 66 $pre = apply_filters( "pre_option_{$option}", false, $option, $default ); 59 67 68 if ( $is_deprecated ) { 69 /** This filter is documented in wp-includes/option.php */ 70 apply_filters( "pre_option_{$deprecated_options[ $option ]}", false, $deprecated_options[ $option ], $default ); 71 } 72 60 73 if ( false !== $pre ) { 61 74 return $pre; 62 75 } … … 87 100 * @param string $option Option name. 88 101 * @param bool $passed_default Was `get_option()` passed a default value? 89 102 */ 90 return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); 103 $default = apply_filters( "default_option_{$option}", $default, $option, $passed_default ); 104 105 if ( $is_deprecated ) { 106 /** This filter is documented in wp-includes/option.php */ 107 $default = apply_filters( "default_option_{$deprecated_options[ $option ]}", $default, $deprecated_options[ $option ], $passed_default ); 108 } 109 110 return $default; 91 111 } 92 112 93 113 $alloptions = wp_load_alloptions(); … … 113 133 wp_cache_set( 'notoptions', $notoptions, 'options' ); 114 134 115 135 /** This filter is documented in wp-includes/option.php */ 116 return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); 136 $default = apply_filters( "default_option_{$option}", $default, $option, $passed_default ); 137 138 if ( $is_deprecated ) { 139 /** This filter is documented in wp-includes/option.php */ 140 $default = apply_filters( "default_option_{$deprecated_options[ $option ]}", $default, $deprecated_options[ $option ], $passed_default ); 141 } 142 143 return $default; 117 144 } 118 145 } 119 146 } … … 126 153 $value = $row->option_value; 127 154 } else { 128 155 /** This filter is documented in wp-includes/option.php */ 129 return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); 156 $default = apply_filters( "default_option_{$option}", $default, $option, $passed_default ); 157 158 if ( $is_deprecated ) { 159 /** This filter is documented in wp-includes/option.php */ 160 $default = apply_filters( "default_option_{$deprecated_options[ $option ]}", $default, $deprecated_options[ $option ], $passed_default ); 161 } 162 163 return $default; 130 164 } 131 165 } 132 166 … … 152 186 * unserialized prior to being returned. 153 187 * @param string $option Option name. 154 188 */ 155 return apply_filters( "option_{$option}", maybe_unserialize( $value ), $option ); 189 $value = apply_filters( "option_{$option}", maybe_unserialize( $value ), $option ); 190 191 if ( $is_deprecated ) { 192 /** This filter is documented in wp-includes/option.php */ 193 $default = apply_filters( "option_{$deprecated_options[ $option ]}", maybe_unserialize( $value ), $option ); 194 } 195 196 return $value; 156 197 } 157 198 158 199 /** … … 313 354 return false; 314 355 } 315 356 357 $is_deprecated = false; 358 $deprecated_options = get_deprecated_options(); 359 360 if ( isset( $deprecated_options[ $option ] ) ) { 361 $deprecated = true; 362 _deprecated_option( $option, '5.5.0', $deprecated_options[ $option ] ); 363 } 364 316 365 wp_protect_special_option( $option ); 317 366 318 367 if ( is_object( $value ) ) { … … 336 385 */ 337 386 $value = apply_filters( "pre_update_option_{$option}", $value, $old_value, $option ); 338 387 388 if ( $is_deprecated ) { 389 /** This filter is documented in wp-includes/option.php */ 390 $value = apply_filters( "pre_update_option_{$deprecated_options[$option]}", $value, $old_value, $option ); 391 } 392 339 393 /** 340 394 * Filters an option before its value is (maybe) serialized and updated. 341 395 * … … 347 401 */ 348 402 $value = apply_filters( 'pre_update_option', $value, $option, $old_value ); 349 403 404 if ( $is_deprecated ) { 405 /** This filter is documented in wp-includes/option.php */ 406 $value = apply_filters( 'pre_update_option', $value, $old_value, $deprecated_options[ $option ] ); 407 } 408 350 409 /* 351 410 * If the new and old values are the same, no need to update. 352 411 * … … 383 442 */ 384 443 do_action( 'update_option', $option, $old_value, $value ); 385 444 445 if ( $is_deprecated ) { 446 /** This action is documented in wp-includes/option.php */ 447 do_action( 'update_option', $deprecated_options[ $option ], $old_value, $value ); 448 } 449 386 450 $update_args = array( 387 451 'option_value' => $serialized_value, 388 452 ); … … 427 491 */ 428 492 do_action( "update_option_{$option}", $old_value, $value, $option ); 429 493 494 if ( $is_deprecated ) { 495 /** This action is documented in wp-includes/option.php */ 496 do_action( "update_option_{$deprecated_options[$option]}", $old_value, $value, $deprecated_options[ $option ] ); 497 } 498 430 499 /** 431 500 * Fires after the value of an option has been successfully updated. 432 501 * … … 438 507 */ 439 508 do_action( 'updated_option', $option, $old_value, $value ); 440 509 510 if ( $is_deprecated ) { 511 /** This action is documented in wp-includes/option.php */ 512 do_action( 'updated_option', $deprecated_options[ $option ], $old_value, $value ); 513 } 514 441 515 return true; 442 516 } 443 517 … … 477 551 return false; 478 552 } 479 553 554 $is_deprecated = false; 555 $deprecated_options = get_deprecated_options(); 556 557 if ( isset( $deprecated_options[ $option ] ) ) { 558 $deprecated = true; 559 _deprecated_option( $option, '5.5.0', $deprecated_options[ $option ] ); 560 } 561 480 562 wp_protect_special_option( $option ); 481 563 482 564 if ( is_object( $value ) ) { … … 509 591 */ 510 592 do_action( 'add_option', $option, $value ); 511 593 594 if ( $is_deprecated ) { 595 /** This filter is documented in wp-includes/option.php */ 596 do_action( 'add_option', $deprecated_options[ $option ], $value ); 597 } 598 512 599 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); 513 600 if ( ! $result ) { 514 601 return false; … … 545 632 */ 546 633 do_action( "add_option_{$option}", $option, $value ); 547 634 635 if ( $is_deprecated ) { 636 /** This filter is documented in wp-includes/option.php */ 637 do_action( "add_option__{$deprecated_options[ $option ]}", $deprecated_options[ $option ], $value ); 638 } 639 548 640 /** 549 641 * Fires after an option has been added. 550 642 * … … 555 647 */ 556 648 do_action( 'added_option', $option, $value ); 557 649 650 if ( $is_deprecated ) { 651 /** This filter is documented in wp-includes/option.php */ 652 do_action( 'added_option', $deprecated_options[ $option ], $value ); 653 } 654 558 655 return true; 559 656 } 560 657 … … 576 673 return false; 577 674 } 578 675 676 $is_deprecated = false; 677 $deprecated_options = get_deprecated_options(); 678 679 if ( isset( $deprecated_options[ $option ] ) ) { 680 $deprecated = true; 681 _deprecated_option( $option, '5.5.0', $deprecated_options[ $option ] ); 682 } 683 579 684 wp_protect_special_option( $option ); 580 685 581 686 // Get the ID, if no ID then return. … … 620 725 */ 621 726 do_action( "delete_option_{$option}", $option ); 622 727 728 if ( $is_deprecated ) { 729 /** This action is documented in wp-includes/option.php */ 730 do_action( "delete_option_{$deprecated_options[$option]}", $deprecated_options[ $option ] ); 731 } 732 623 733 /** 624 734 * Fires after an option has been deleted. 625 735 * … … 629 739 */ 630 740 do_action( 'deleted_option', $option ); 631 741 742 if ( $is_deprecated ) { 743 /** This action is documented in wp-includes/option.php */ 744 do_action( 'deleted_option', $deprecated_options[ $option ] ); 745 } 746 632 747 return true; 633 748 } 634 749