time(); } public static function grant( $user_id = 0, $ttl = self::DEFAULT_TTL ) { $user_id = $user_id ?: get_current_user_id(); if ( ! $user_id ) { return false; } return update_user_meta( $user_id, self::META_KEY, time() + (int) $ttl ); } public static function revoke( $user_id = 0 ) { $user_id = $user_id ?: get_current_user_id(); return delete_user_meta( $user_id, self::META_KEY ); } /** * Verify a freshly-supplied password belongs to the current user. */ public static function confirm_password( $password ) { $user = wp_get_current_user(); if ( ! $user || ! $user->ID ) { return false; } $ok = wp_check_password( (string) $password, $user->user_pass, $user->ID ); if ( $ok ) { self::grant( $user->ID ); } return (bool) $ok; } }