Skip to content

Commit fc8ba60

Browse files
committed
Correctly query for token by ID
1 parent ca81558 commit fc8ba60

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

inc/tokens/class-access-token.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use WP_Error;
66
use WP\OAuth2\Client;
7+
use WP_Query;
78
use WP_User;
89

910
class Access_Token extends Token {
@@ -21,14 +22,15 @@ protected static function get_meta_prefix() {
2122
* @return static|null Token if ID is found, null otherwise.
2223
*/
2324
public static function get_by_id( $id ) {
25+
$key = static::META_PREFIX . $id;
2426
$args = array(
2527
'post_type' => Client::POST_TYPE,
2628
'post_status' => 'publish',
2729
'posts_per_page' => 1,
2830
'no_found_rows' => true,
2931
'meta_query' => array(
3032
array(
31-
'key' => static::META_PREFIX . $id,
33+
'key' => $key,
3234
'compare' => 'EXISTS',
3335
),
3436
),
@@ -38,7 +40,12 @@ public static function get_by_id( $id ) {
3840
return null;
3941
}
4042

41-
return new static( $query->posts[0] );
43+
$value = get_post_meta( $query->posts[0]->ID, wp_slash( $key ), false );
44+
if ( empty( $value ) ) {
45+
return null;
46+
}
47+
48+
return new static( $key, $value[0] );
4249
}
4350

4451
public static function create( Client $client, WP_User $user ) {

0 commit comments

Comments
 (0)