Make WordPress Core

Changeset 13148


Ignore:
Timestamp:
02/14/2010 10:39:46 AM (17 years ago)
Author:
nacin
Message:

Add hooks across options and transients APIs. Focuses on site transients/options functions. Attempts to standardize where possible. See #10788

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r13142 r13148  
    346346                                $wpdb->suppress_errors( $suppress );
    347347
    348                         if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
     348                        // Has to be get_row instead of get_var because of funkiness with 0, false, null values
     349                        if ( is_object( $row ) ) {
    349350                                $value = $row->option_value;
    350351                                wp_cache_add( $option, $value, 'options' );
     
    480481 * @uses apply_filters() Calls 'pre_update_option_$option' hook to allow overwriting the
    481482 *      option value to be stored.
     483 * @uses do_action() Calls 'update_option' hook before updating the option.
    482484 * @uses do_action() Calls 'update_option_$option' and 'updated_option' hooks on success.
    483485 *
     
    512514        $newvalue = maybe_serialize( $newvalue );
    513515
    514         do_action( 'update_option', $option, $oldvalue, $newvalue );
     516        do_action( 'update_option', $option, $oldvalue, $newvalue ); // $newvalue may be serialized.
    515517        if ( ! defined( 'WP_INSTALLING' ) ) {
    516518                $alloptions = wp_load_alloptions();
     
    551553 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
    552554 *
     555 * @uses do_action() Calls 'add_option' hook before adding the option.
    553556 * @uses do_action() Calls 'add_option_$option' and 'added_option' hooks on success.
    554557 *
     
    609612 *
    610613 * @package WordPress
    611  * @subpackage Option
     614 * @subpackage Option 
    612615 * @since 1.2.0
    613616 *
    614617 * @uses do_action() Calls 'delete_option' hook before option is deleted.
    615  * @uses do_action() Calls 'deleted_option' hook on success.
     618 * @uses do_action() Calls 'deleted_option' and 'delete_option_$option' hooks on success.
    616619 *
    617620 * @param string $option Name of option to remove.
    618  * @return bool True, if succeed. False, if failure.
     621 * @return bool True, if option is successfully deleted. False on failure.
    619622 */
    620623function delete_option( $option ) {
     
    643646        }
    644647        if ( $result ) {
     648                do_action( "delete_option_$option", $option );
    645649                do_action( 'deleted_option', $option );
    646650                return true;
     
    656660 * @subpackage Transient
    657661 *
     662 * @uses do_action() Calls 'delete_transient_$transient' hook before transient is deleted.
     663 * @uses do_action() Calls 'deleted_transient' hook on success.
     664 *
    658665 * @param string $transient Transient name. Expected to not be SQL-escaped
    659666 * @return bool true if successful, false otherwise
     
    662669        global $_wp_using_ext_object_cache;
    663670
    664     do_action( 'delete_transient_' . $transient );
     671    do_action( 'delete_transient_' . $transient, $transient );
    665672
    666673        if ( $_wp_using_ext_object_cache ) {
    667                 return wp_cache_delete( $transient, 'transient' );
     674                $result = wp_cache_delete( $transient, 'transient' );
    668675        } else {
    669                 $transient = '_transient_' . esc_sql( $transient );
    670                 return delete_option( $transient );
    671         }
     676                $option = '_transient_' . esc_sql( $transient );
     677                $result = delete_option( $option );
     678        }
     679
     680        if ( $result )
     681                do_action( 'deleted_transient', $transient );
     682        return $result;
    672683}
    673684
     
    734745 * @uses apply_filters() Calls 'pre_set_transient_$transient' hook to allow overwriting the
    735746 *      transient value to be stored.
     747 * @uses do_action() Calls 'set_transient_$transient' and 'setted_transient' hooks on success.
    736748 *
    737749 * @param string $transient Transient name. Expected to not be SQL-escaped
     
    746758
    747759        if ( $_wp_using_ext_object_cache ) {
    748                 return wp_cache_set( $transient, $value, 'transient', $expiration );
     760                $result = wp_cache_set( $transient, $value, 'transient', $expiration );
    749761        } else {
    750762                $transient_timeout = '_transient_timeout_' . $transient;
     
    755767                        if ( $expiration ) {
    756768                                $autoload = 'no';
    757                                 add_option($transient_timeout, time() + $expiration, '', 'no');
     769                                add_option( $transient_timeout, time() + $expiration, '', 'no' );
    758770                        }
    759                         return add_option($transient, $value, '', $autoload);
     771                        $result = add_option( $transient, $value, '', $autoload );
    760772                } else {
    761773                        if ( $expiration )
    762774                                update_option( $transient_timeout, time() + $expiration );
    763                         return update_option($transient, $value);
     775                        $result = update_option( $transient, $value );
    764776                }
    765777        }
     778        if ( $result ) {
     779                do_action( 'set_transient_' . $transient );
     780                do_action( 'setted_transient', $transient );
     781        }
     782        return $result;
    766783}
    767784
     
    34673484        }
    34683485
    3469         do_action( "delete_site_option_{$option}", $option );
    3470         do_action( "delete_site_option", $option );
    3471         return $result;
     3486        if ( $result ) {
     3487                do_action( "delete_site_option_{$option}", $option );
     3488                do_action( "delete_site_option", $option );
     3489                return true;
     3490        }
     3491        return false;
    34723492}
    34733493
     
    35263546 * @subpackage Transient
    35273547 *
     3548 * @uses do_action() Calls 'delete_site_transient_$transient' hook before transient is deleted.
     3549 * @uses do_action() Calls 'deleted_site_transient' hook on success.
     3550 *
    35283551 * @param string $transient Transient name. Expected to not be SQL-escaped
    35293552 * @return bool True if successful, false otherwise
     
    35323555        global $_wp_using_ext_object_cache;
    35333556
     3557        do_action( 'delete_site_transient_' . $transient, $transient );
    35343558        if ( $_wp_using_ext_object_cache ) {
    35353559                $result = wp_cache_delete( $transient, 'site-transient' );
    35363560        } else {
    3537                 $transient = '_site_transient_' . esc_sql( $transient );
    3538                 $result = delete_site_option( $transient );
    3539         }
     3561                $option = '_site_transient_' . esc_sql( $transient );
     3562                $result = delete_site_option( $option );
     3563        }
     3564        if ( $result )
     3565                do_action( 'deleted_site_transient', $transient );
    35403566        return $result;
    35413567}
     
    36013627 * @subpackage Transient
    36023628 *
     3629 * @uses apply_filters() Calls 'pre_set_site_transient_$transient' hook to allow overwriting the
     3630 *      transient value to be stored.
     3631 * @uses do_action() Calls 'set_site_transient_$transient' and 'setted_site_transient' hooks on success.
     3632 *
    36033633 * @param string $transient Transient name. Expected to not be SQL-escaped
    36043634 * @param mixed $value Transient value.
     
    36083638function set_site_transient( $transient, $value, $expiration = 0 ) {
    36093639        global $_wp_using_ext_object_cache;
     3640
     3641    $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
    36103642
    36113643        if ( $_wp_using_ext_object_cache ) {
     
    36243656                        $result = update_site_option( $transient, $value );
    36253657                }
     3658        }
     3659        if ( $result ) {
     3660                do_action( 'set_site_transient_' . $transient );
     3661                do_action( 'setted_site_transient', $transient );
    36263662        }
    36273663        return $result;
Note: See TracChangeset for help on using the changeset viewer.