WPDKUser::getTransientWithUser PHP Метод

getTransientWithUser() публичный статический Метод

If the transient does not exist or does not have a value, then the return value will be false.
С версии: 1.4.8
public static getTransientWithUser ( string $transient, integer $user_id = null ) : mixed
$transient string Transient name. Expected to not be SQL-escaped
$user_id integer Optional. User ID. If null the current user id is used instead
Результат mixed Value of transient
    public static function getTransientWithUser($transient, $user_id = null)
    {
        $user_id = is_null($user_id) ? get_current_user_id() : $user_id;
        $pre = apply_filters('pre_user_transient_' . $transient, false, $user_id);
        if (false !== $pre) {
            return $pre;
        }
        $transient_timeout = '_transient_timeout_' . $transient;
        $transient = '_transient_' . $transient;
        if (get_user_meta($user_id, $transient_timeout, true) < time()) {
            delete_user_meta($user_id, $transient);
            delete_user_meta($user_id, $transient_timeout);
            return false;
        }
        $value = get_user_meta($user_id, $transient, true);
        return apply_filters('user_transient_' . $transient, $value, $user_id);
    }

Usage Example

Пример #1
0
 /**
  * Get the value of a user transient.
  * If the transient does not exist or does not have a value, then the return value will be false.
  *
  * @brief      Get
  * @since      1.0.0
  * @deprecated since 1.4.8 - Use WPDKUser::getTransientWithUser() instead
  *
  * @uses       apply_filters() Calls 'pre_user_transient_$transient' hook before checking the transient. Any value
  *             other than false will "short-circuit" the retrieval of the transient and return the returned value.
  * @uses       apply_filters() Calls 'user_transient_$transient' hook, after checking the transient, with the transient
  *             value.
  *
  * @param string $transient Transient name. Expected to not be SQL-escaped
  * @param int    $user_id   Optional. User ID. If null the current user id is used instead
  *
  * @return mixed Value of transient
  */
 function wpdk_get_user_transient($transient, $user_id = null)
 {
     _deprecated_function(__CLASS__ . '::' . __FUNCTION__, '1.4.8', 'WPDKUser::getTransientWithUser()');
     return WPDKUser::getTransientWithUser($transient, $user_id);
 }