예제 #1
0
 /**
  * Update the value of a site temporary with existing timeout.
  *
  * You do not need to serialize values. If the value needs to be serialized, then
  * it will be serialized before it is updated.
  *
  * @since 1.0.0
  * @access public
  *
  * @see WP_Temporary::update()
  *
  * @param string $temporary  Temporary name. Expected to not be SQL-escaped. Must be
  *                           45 characters or fewer in length.
  * @param mixed  $value      Temporary value. Must be serializable if non-scalar.
  *                           Expected to not be SQL-escaped.
  * @param int    $expiration Optional. Time until expiration in seconds. Default 0.
  * @return bool False if value was not updated and true if value was updated.
  */
 public static function update_site($temporary, $value, $expiration = 0)
 {
     /**
      * Filter a specific temporary before its value is updated.
      *
      * The dynamic portion of the hook name, `$temporary`, refers to the temporary name.
      *
      * @since 1.0.0
      *
      * @param mixed  $value     New value of temporary.
      * @param string $temporary Temporary name.
      */
     $value = apply_filters('pre_update_site_temporary_' . $temporary, $value, $temporary);
     $temporary_option = '_site_temporary_' . $temporary;
     // If temporary doesn't exist, create new one,
     // otherwise update it with new value
     if (false === WP_Temporary::get_site($temporary)) {
         $result = WP_Temporary::set_site($temporary, $value, $expiration);
     } else {
         $temporary_option = '_site_temporary_' . $temporary;
         $result = update_site_option($temporary_option, $value);
     }
     if ($result) {
         /**
          * Fires after the value for a specific temporary has been updated.
          *
          * The dynamic portion of the hook name, `$temporary`, refers to the temporary name.
          *
          * @since 1.0.0
          *
          * @param mixed  $value      Temporary value.
          * @param int    $expiration Time until expiration in seconds. Default 0.
          * @param string $temporary  Temporary name.
          */
         do_action('update_site_temporary_' . $temporary, $value, $expiration, $temporary);
         /**
          * Fires after the value for a temporary has been updated.
          *
          * @since 1.0.0
          *
          * @param string $temporary  The name of the temporary.
          * @param mixed  $value      Temporary value.
          * @param int    $expiration Time until expiration in seconds. Default 0.
          */
         do_action('updated_site_temporary', $temporary, $value, $expiration);
     }
     return $result;
 }