Skip to content

Commit 7363a83

Browse files
committed
Add CLI command to add consumers
1 parent 05dc19b commit 7363a83

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
class WP_JSON_Authentication_OAuth1_CLI extends WP_CLI_Command {
4+
5+
/**
6+
* ## OPTIONS
7+
*
8+
* [--name=<name>]
9+
* : Consumer name
10+
*
11+
* [--description=<description>]
12+
* : Consumer description
13+
*/
14+
public function add( $_, $args ) {
15+
$authenticator = new WP_JSON_Authentication_OAuth1();
16+
$consumer = $authenticator->add_consumer( $args );
17+
WP_CLI::line( sprintf( 'ID: %d', $consumer->ID ) );
18+
WP_CLI::line( sprintf( 'Key: %s', $consumer->key ) );
19+
WP_CLI::line( sprintf( 'Secret: %s', $consumer->secret ) );
20+
}
21+
}

oauth-server.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
include_once( dirname( __FILE__ ) . '/lib/class-wp-json-authentication-oauth1.php' );
99
include_once( dirname( __FILE__ ) . '/lib/class-wp-json-authentication-oauth1-authorize.php' );
1010

11+
if ( defined( 'WP_CLI' ) && WP_CLI ) {
12+
include_once( dirname( __FILE__ ) . '/lib/class-wp-json-authentication-oauth1-cli.php' );
13+
14+
WP_CLI::add_command( 'oauth1', 'WP_JSON_Authentication_OAuth1_CLI' );
15+
}
16+
1117
/**
1218
* Register our rewrite rules for the API
1319
*/

0 commit comments

Comments
 (0)