Skip to content

Commit 5e887e4

Browse files
committed
Store client ID in post_name
1 parent b34b101 commit 5e887e4

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

inc/class-client.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
class Client {
1313
const POST_TYPE = 'oauth2_client';
14-
const CLIENT_ID_KEY = '_oauth2_client_id';
1514
const CLIENT_SECRET_KEY = '_oauth2_client_secret';
1615
const TYPE_KEY = '_oauth2_client_type';
1716
const REDIRECT_URI_KEY = '_oauth2_redirect_uri';
@@ -41,12 +40,7 @@ protected function __construct( WP_Post $post ) {
4140
* @return string Client ID.
4241
*/
4342
public function get_id() {
44-
$result = get_post_meta( $this->get_post_id(), static::CLIENT_ID_KEY, false );
45-
if ( empty( $result ) ) {
46-
return null;
47-
}
48-
49-
return $result[0];
43+
return $this->post->post_name;
5044
}
5145

5246
/**
@@ -284,12 +278,9 @@ public static function get_by_id( $id ) {
284278
'post_status' => 'publish',
285279
'posts_per_page' => 1,
286280
'no_found_rows' => true,
287-
'meta_query' => [
288-
[
289-
'key' => static::CLIENT_ID_KEY,
290-
'value' => $id,
291-
],
292-
],
281+
282+
// Query by slug.
283+
'name' => $id,
293284
];
294285
$query = new WP_Query( $args );
295286
if ( empty( $query->posts ) ) {
@@ -322,10 +313,12 @@ public static function get_by_post_id( $id ) {
322313
* @return WP_Error|Client Client instance on success, error otherwise.
323314
*/
324315
public static function create( $data ) {
316+
$client_id = wp_generate_password( static::CLIENT_ID_LENGTH, false );
325317
$post_data = [
326318
'post_type' => static::POST_TYPE,
327319
'post_title' => $data['name'],
328320
'post_content' => $data['description'],
321+
'post_name' => $client_id,
329322
'post_status' => 'draft',
330323
];
331324

@@ -338,7 +331,6 @@ public static function create( $data ) {
338331
$meta = [
339332
static::REDIRECT_URI_KEY => $data['meta']['callback'],
340333
static::TYPE_KEY => $data['meta']['type'],
341-
static::CLIENT_ID_KEY => wp_generate_password( static::CLIENT_ID_LENGTH, false ),
342334
static::CLIENT_SECRET_KEY => wp_generate_password( static::CLIENT_SECRET_LENGTH, false ),
343335
];
344336

0 commit comments

Comments
 (0)