update
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Site Kit Authentication CLI Commands
|
||||
*
|
||||
* @package Google\Site_Kit\Core\CLI
|
||||
* @copyright 2021 Google LLC
|
||||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://sitekit.withgoogle.com
|
||||
*/
|
||||
|
||||
namespace Google\Site_Kit\Core\CLI;
|
||||
|
||||
use Google\Site_Kit\Core\Storage\Options;
|
||||
use Google\Site_Kit\Core\Storage\User_Options;
|
||||
use Google\Site_Kit\Core\Storage\Transients;
|
||||
use Google\Site_Kit\Core\Authentication\Authentication;
|
||||
use WP_CLI;
|
||||
|
||||
/**
|
||||
* Manages Site Kit user authentication for Google APIs.
|
||||
*
|
||||
* @since 1.11.0
|
||||
* @access private
|
||||
* @ignore
|
||||
*/
|
||||
class Authentication_CLI_Command extends CLI_Command {
|
||||
|
||||
/**
|
||||
* Disconnects a user from Site Kit, removing their relevant user options and revoking their token.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* --id=<id>
|
||||
* : User ID to disconnect.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp google-site-kit auth disconnect --id=11
|
||||
*
|
||||
* @alias revoke
|
||||
*
|
||||
* @since 1.11.0
|
||||
*
|
||||
* @param array $args Array of arguments.
|
||||
* @param array $assoc_args Array of associated arguments.
|
||||
*/
|
||||
public function disconnect( $args, $assoc_args ) {
|
||||
$user_id = absint( $assoc_args['id'] );
|
||||
|
||||
$authentication = new Authentication(
|
||||
$this->context,
|
||||
new Options( $this->context ),
|
||||
new User_Options( $this->context, $user_id ),
|
||||
new Transients( $this->context )
|
||||
);
|
||||
$authentication->disconnect();
|
||||
|
||||
WP_CLI::success( sprintf( 'User with ID %d successfully disconnected.', $user_id ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Site Kit CLI Command
|
||||
*
|
||||
* @package Google\Site_Kit\Core\CLI
|
||||
* @copyright 2021 Google LLC
|
||||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://sitekit.withgoogle.com
|
||||
*/
|
||||
|
||||
namespace Google\Site_Kit\Core\CLI;
|
||||
|
||||
use Google\Site_Kit\Context;
|
||||
use WP_CLI_Command;
|
||||
|
||||
/**
|
||||
* Base CLI Command class.
|
||||
*
|
||||
* @since 1.11.0
|
||||
* @access private
|
||||
* @ignore
|
||||
*/
|
||||
class CLI_Command extends WP_CLI_Command {
|
||||
|
||||
/**
|
||||
* Plugin context.
|
||||
*
|
||||
* @since 1.11.0
|
||||
*
|
||||
* @var Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.11.0
|
||||
*
|
||||
* @param Context $context Plugin context.
|
||||
*/
|
||||
public function __construct( Context $context ) {
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Google\Site_Kit\Core\CLI\CLI_Commands
|
||||
*
|
||||
* @package Google\Site_Kit\Core\CLI
|
||||
* @copyright 2021 Google LLC
|
||||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://sitekit.withgoogle.com
|
||||
*/
|
||||
|
||||
namespace Google\Site_Kit\Core\CLI;
|
||||
|
||||
use Google\Site_Kit\Context;
|
||||
use WP_CLI;
|
||||
|
||||
/**
|
||||
* CLI commands hub class.
|
||||
*
|
||||
* @since 1.11.0
|
||||
* @access private
|
||||
* @ignore
|
||||
*/
|
||||
class CLI_Commands {
|
||||
|
||||
/**
|
||||
* Plugin context.
|
||||
*
|
||||
* @since 1.11.0
|
||||
*
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.11.0
|
||||
*
|
||||
* @param Context $context Plugin context.
|
||||
*/
|
||||
public function __construct( Context $context ) {
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers WP CLI commands.
|
||||
*
|
||||
* @since 1.11.0
|
||||
*/
|
||||
public function register() {
|
||||
WP_CLI::add_command( 'google-site-kit auth', new Authentication_CLI_Command( $this->context ) );
|
||||
WP_CLI::add_command( 'google-site-kit reset', new Reset_CLI_Command( $this->context ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Site Kit Cache CLI Commands
|
||||
*
|
||||
* @package Google\Site_Kit\Core\CLI
|
||||
* @copyright 2021 Google LLC
|
||||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://sitekit.withgoogle.com
|
||||
*/
|
||||
|
||||
namespace Google\Site_Kit\Core\CLI;
|
||||
|
||||
use Google\Site_Kit\Core\Util\Reset;
|
||||
use Google\Site_Kit\Core\Util\Reset_Persistent;
|
||||
use WP_CLI;
|
||||
|
||||
/**
|
||||
* Resets Site Kit Settings and Data.
|
||||
*
|
||||
* @since 1.11.0
|
||||
* @access private
|
||||
* @ignore
|
||||
*/
|
||||
class Reset_CLI_Command extends CLI_Command {
|
||||
|
||||
/**
|
||||
* Deletes options, user stored options, transients and clears object cache for stored options.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* [--persistent]
|
||||
* : Additionally deletes persistent options.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp google-site-kit reset
|
||||
* wp google-site-kit reset --persistent
|
||||
*
|
||||
* @since 1.11.0
|
||||
* @since 1.27.0 Added --persistent flag to delete persistent options.
|
||||
*
|
||||
* @param array $args Positional args.
|
||||
* @param array $assoc_args Additional flags.
|
||||
*/
|
||||
public function __invoke( $args, $assoc_args ) {
|
||||
$reset = new Reset( $this->context );
|
||||
$reset->all();
|
||||
|
||||
if ( isset( $assoc_args['persistent'] ) && true === $assoc_args['persistent'] ) {
|
||||
$reset_persistent = new Reset_Persistent( $this->context );
|
||||
$reset_persistent->all();
|
||||
}
|
||||
|
||||
WP_CLI::success( 'Settings successfully reset.' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user