11
11
12
12
class Client {
13
13
const POST_TYPE = 'oauth2_client ' ;
14
- const CLIENT_ID_KEY = '_oauth2_client_id ' ;
15
14
const CLIENT_SECRET_KEY = '_oauth2_client_secret ' ;
16
15
const TYPE_KEY = '_oauth2_client_type ' ;
17
16
const REDIRECT_URI_KEY = '_oauth2_redirect_uri ' ;
@@ -41,12 +40,7 @@ protected function __construct( WP_Post $post ) {
41
40
* @return string Client ID.
42
41
*/
43
42
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 ;
50
44
}
51
45
52
46
/**
@@ -284,12 +278,9 @@ public static function get_by_id( $id ) {
284
278
'post_status ' => 'publish ' ,
285
279
'posts_per_page ' => 1 ,
286
280
'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 ,
293
284
];
294
285
$ query = new WP_Query ( $ args );
295
286
if ( empty ( $ query ->posts ) ) {
@@ -322,10 +313,12 @@ public static function get_by_post_id( $id ) {
322
313
* @return WP_Error|Client Client instance on success, error otherwise.
323
314
*/
324
315
public static function create ( $ data ) {
316
+ $ client_id = wp_generate_password ( static ::CLIENT_ID_LENGTH , false );
325
317
$ post_data = [
326
318
'post_type ' => static ::POST_TYPE ,
327
319
'post_title ' => $ data ['name ' ],
328
320
'post_content ' => $ data ['description ' ],
321
+ 'post_name ' => $ client_id ,
329
322
'post_status ' => 'draft ' ,
330
323
];
331
324
@@ -338,7 +331,6 @@ public static function create( $data ) {
338
331
$ meta = [
339
332
static ::REDIRECT_URI_KEY => $ data ['meta ' ]['callback ' ],
340
333
static ::TYPE_KEY => $ data ['meta ' ]['type ' ],
341
- static ::CLIENT_ID_KEY => wp_generate_password ( static ::CLIENT_ID_LENGTH , false ),
342
334
static ::CLIENT_SECRET_KEY => wp_generate_password ( static ::CLIENT_SECRET_LENGTH , false ),
343
335
];
344
336
0 commit comments