-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from mainwp/mainwp-child-dev
MainWP Child Dev
- Loading branch information
Showing
36 changed files
with
17,297 additions
and
4,846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* MainWP-Child-CLI | ||
* | ||
* This file extends the WP-CLI and provides a set of SubCommands to Control your | ||
* Child Sites that are added to the MainWP Child. | ||
* | ||
* @package MainWP/Child | ||
*/ | ||
|
||
namespace MainWP\Child; | ||
|
||
// Exit if access directly. | ||
if ( ! defined( 'WP_CLI' ) ) { | ||
return; // NOSONAR - jump to avoid CLI. | ||
} | ||
|
||
/** | ||
* Class MainWP_Child_WP_CLI_Command | ||
* | ||
* @package MainWP\Child | ||
*/ | ||
class MainWP_Child_WP_CLI_Command extends \WP_CLI_Command { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | ||
|
||
/** | ||
* Method init() | ||
* | ||
* Initiate the MainWP CLI after all Plugins have loaded. | ||
*/ | ||
public static function init() { | ||
add_action( 'plugins_loaded', array( static::class, 'init_wpcli_commands' ), 99999 ); | ||
} | ||
|
||
/** | ||
* Method init_wpcli_commands | ||
* | ||
* Adds the MainWP WP CLI Commands via WP_CLI::add_command | ||
*/ | ||
public static function init_wpcli_commands() { | ||
\WP_CLI::add_command( 'mainwp-child', static::class ); | ||
} | ||
|
||
/** | ||
* Settings. | ||
* | ||
* ## OPTIONS | ||
* | ||
* [--disable-pwd-auth] | ||
* : Disable connect passwd authentication | ||
* | ||
* | ||
* ## EXAMPLES | ||
* | ||
* wp mainwp-child settings --disable-pwd-auth [<username>] [<disabled>]. | ||
* | ||
* ## Synopsis [--disable-pwd-auth] [<username>] [<disabled>]. | ||
* | ||
* @param array $args Function arguments. | ||
* @param array $assoc_args Function associate arguments. | ||
*/ | ||
public function settings( $args, $assoc_args ) { //phpcs:ignore -- NOSONAR - complexity. | ||
|
||
if ( isset( $assoc_args['disable-pwd-auth'] ) ) { | ||
if ( empty( $args ) || empty( $args[0] ) ) { | ||
\WP_CLI::error( 'Please enter the username to apply this setting. A valid username is required to proceed.' ); | ||
return true; | ||
} else { | ||
$user_name = $args[0]; | ||
$user = get_user_by( 'login', $user_name ); | ||
|
||
if ( ! $user || empty( $user->ID ) ) { | ||
\WP_CLI::error( 'The username you entered does not match any account. Please verify the username and try again.' ); | ||
return true; | ||
} | ||
|
||
$disabled = ! isset( $args[1] ) || '1' === $args[1] ? true : false; | ||
|
||
update_user_option( $user->ID, 'mainwp_child_user_enable_passwd_auth_connect', $disabled ? 0 : 1 ); | ||
\WP_CLI::success( 'Your changes have been saved successfully!' ); | ||
return true; | ||
} | ||
} | ||
|
||
\WP_CLI::error( 'Invalid arguments. Please try again, or contact support if the issue persists.' ); | ||
} | ||
} |
Oops, something went wrong.