Changeset 48193
- Timestamp:
- 06/27/2020 04:54:29 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/option.php
r48185 r48193 41 41 * The dynamic portion of the hook name, `$option`, refers to the option name. 42 42 * 43 * Returning a truthy value from the filter will short-circuit retrieving44 * the option value, returningthe passed value instead.43 * Returning a truthy value from the filter will effectively short-circuit retrieval 44 * and return the passed value instead. 45 45 * 46 46 * @since 1.5.0 … … 48 48 * @since 4.9.0 The `$default` parameter was added. 49 49 * 50 * @param bool|mixed $pre_option The value to return instead of the option value. This differs from51 * `$default`, which is used as the fallback value in the event the option52 * doesn't exist elsewhere in get_option(). Default false (to skip past the53 * 54 * @param string 55 * @param mixed 56 * Default isfalse.50 * @param mixed $pre_option The value to return instead of the option value. This differs 51 * from `$default`, which is used as the fallback value in the event 52 * the option doesn't exist elsewhere in get_option(). 53 * Default false (to skip past the short-circuit). 54 * @param string $option Option name. 55 * @param mixed $default The fallback value to return if the option does not exist. 56 * Default false. 57 57 */ 58 58 $pre = apply_filters( "pre_option_{$option}", false, $option, $default ); … … 72 72 // Prevent non-existent options from triggering multiple queries. 73 73 $notoptions = wp_cache_get( 'notoptions', 'options' ); 74 74 75 if ( isset( $notoptions[ $option ] ) ) { 75 76 /** … … 108 109 $notoptions = array(); 109 110 } 111 110 112 $notoptions[ $option ] = true; 111 113 wp_cache_set( 'notoptions', $notoptions, 'options' ); … … 120 122 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); 121 123 $wpdb->suppress_errors( $suppress ); 124 122 125 if ( is_object( $row ) ) { 123 126 $value = $row->option_value; … … 229 232 */ 230 233 $alloptions = apply_filters( 'pre_cache_alloptions', $alloptions ); 234 231 235 wp_cache_add( 'alloptions', $alloptions, 'options' ); 232 236 } … … 394 398 395 399 $notoptions = wp_cache_get( 'notoptions', 'options' ); 400 396 401 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 397 402 unset( $notoptions[ $option ] ); … … 433 438 */ 434 439 do_action( 'updated_option', $option, $old_value, $value ); 440 435 441 return true; 436 442 } … … 483 489 // We can check the 'notoptions' cache before we ask for a DB query. 484 490 $notoptions = wp_cache_get( 'notoptions', 'options' ); 491 485 492 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 486 493 /** This filter is documented in wp-includes/option.php */ … … 520 527 // This option exists now. 521 528 $notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh. 529 522 530 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 523 531 unset( $notoptions[ $option ] ); … … 547 555 */ 548 556 do_action( 'added_option', $option, $value ); 557 549 558 return true; 550 559 } … … 586 595 587 596 $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) ); 597 588 598 if ( ! wp_installing() ) { 589 599 if ( 'yes' === $row->autoload ) { … … 597 607 } 598 608 } 609 599 610 if ( $result ) { 600 611 … … 618 629 */ 619 630 do_action( 'deleted_option', $option ); 631 620 632 return true; 621 633 } 634 622 635 return false; 623 636 } … … 650 663 $option = '_transient_' . $transient; 651 664 $result = delete_option( $option ); 665 652 666 if ( $result ) { 653 667 delete_option( $option_timeout ); … … 684 698 685 699 /** 686 * Filters the value of an existing transient .700 * Filters the value of an existing transient before it is retrieved. 687 701 * 688 702 * The dynamic portion of the hook name, `$transient`, refers to the transient name. 689 703 * 690 704 * Returning a truthy value from the filter will effectively short-circuit retrieval 691 * of the transient, returningthe passed value instead.705 * and return the passed value instead. 692 706 * 693 707 * @since 2.8.0 … … 696 710 * @param mixed $pre_transient The default value to return if the transient does not exist. 697 711 * Any value other than false will short-circuit the retrieval 698 * of the transient, and return th e returnedvalue.712 * of the transient, and return that value. 699 713 * @param string $transient Transient name. 700 714 */ 701 715 $pre = apply_filters( "pre_transient_{$transient}", false, $transient ); 716 702 717 if ( false !== $pre ) { 703 718 return $pre; … … 793 808 $transient_timeout = '_transient_timeout_' . $transient; 794 809 $transient_option = '_transient_' . $transient; 810 795 811 if ( false === get_option( $transient_option ) ) { 796 812 $autoload = 'yes'; … … 804 820 // delete, then re-create transient rather than update. 805 821 $update = true; 822 806 823 if ( $expiration ) { 807 824 if ( false === get_option( $transient_timeout ) ) { … … 814 831 } 815 832 } 833 816 834 if ( $update ) { 817 835 $result = update_option( $transient_option, $value ); … … 849 867 do_action( 'setted_transient', $transient, $value, $expiration ); 850 868 } 869 851 870 return $result; 852 871 } … … 1234 1253 1235 1254 /** 1236 * Filters an existing network option before it is retrieved.1255 * Filters the value of an existing network option before it is retrieved. 1237 1256 * 1238 1257 * The dynamic portion of the hook name, `$option`, refers to the option name. … … 1247 1266 * @since 4.9.0 The `$default` parameter was added. 1248 1267 * 1249 * @param mixed $pre_option The value to return instead of the option value. This differs from1250 * `$default`, which is used as the fallback value in the event the1251 * option doesn't exist elsewhere in get_network_option(). Default1252 * isfalse (to skip past the short-circuit).1268 * @param mixed $pre_option The value to return instead of the option value. This differs 1269 * from `$default`, which is used as the fallback value in the event 1270 * the option doesn't exist elsewhere in get_network_option(). 1271 * Default false (to skip past the short-circuit). 1253 1272 * @param string $option Option name. 1254 1273 * @param int $network_id ID of the network. 1255 1274 * @param mixed $default The fallback value to return if the option does not exist. 1256 * Default isfalse.1275 * Default false. 1257 1276 */ 1258 1277 $pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default ); … … 1305 1324 $notoptions = array(); 1306 1325 } 1326 1307 1327 $notoptions[ $option ] = true; 1308 1328 wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); … … 1394 1414 // We can check the 'notoptions' cache before we ask for a DB query. 1395 1415 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1416 1396 1417 if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { 1397 1418 if ( false !== get_network_option( $network_id, $option, false ) ) { … … 1420 1441 // This option exists now. 1421 1442 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // Yes, again... we need it to be fresh. 1443 1422 1444 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1423 1445 unset( $notoptions[ $option ] ); … … 1622 1644 $notoptions_key = "$network_id:notoptions"; 1623 1645 $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 1646 1624 1647 if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { 1625 1648 unset( $notoptions[ $option ] ); … … 1712 1735 $option = '_site_transient_' . $transient; 1713 1736 $result = delete_site_option( $option ); 1737 1714 1738 if ( $result ) { 1715 1739 delete_site_option( $option_timeout ); 1716 1740 } 1717 1741 } 1742 1718 1743 if ( $result ) { 1719 1744 … … 1747 1772 1748 1773 /** 1749 * Filters the value of an existing site transient .1774 * Filters the value of an existing site transient before it is retrieved. 1750 1775 * 1751 1776 * The dynamic portion of the hook name, `$transient`, refers to the transient name. … … 1759 1784 * @param mixed $pre_site_transient The default value to return if the site transient does not exist. 1760 1785 * Any value other than false will short-circuit the retrieval 1761 * of the transient, and return th e returnedvalue.1786 * of the transient, and return that value. 1762 1787 * @param string $transient Transient name. 1763 1788 */ … … 1854 1879 $transient_timeout = '_site_transient_timeout_' . $transient; 1855 1880 $option = '_site_transient_' . $transient; 1881 1856 1882 if ( false === get_site_option( $option ) ) { 1857 1883 if ( $expiration ) { … … 1866 1892 } 1867 1893 } 1894 1868 1895 if ( $result ) { 1869 1896 … … 1893 1920 do_action( 'setted_site_transient', $transient, $value, $expiration ); 1894 1921 } 1922 1895 1923 return $result; 1896 1924 } … … 2144 2172 */ 2145 2173 $args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name ); 2174 2146 2175 $args = wp_parse_args( $args, $defaults ); 2147 2176
Note: See TracChangeset
for help on using the changeset viewer.