Skip to content

Commit

Permalink
Merge pull request #424 from mainwp/mainwp-child-dev
Browse files Browse the repository at this point in the history
MainWP Child Dev
  • Loading branch information
thanghv authored Nov 26, 2024
2 parents fd1fa31 + 7d246b7 commit 8e63ad7
Show file tree
Hide file tree
Showing 36 changed files with 17,297 additions and 4,846 deletions.
23 changes: 12 additions & 11 deletions class/class-mainwp-child-back-wp-up.php
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,16 @@ protected function verify_nonce_without_session( $nonce, $action = - 1 ) { //php
return $result;
}

/**
* MainWP BackWPup WP Die ajax handler.
*
* @param string $message Error message container.
* @return string Error message.
*/
public static function mainwp_backwpup_wp_die_ajax_handler() {
return '__return_true';
}

/**
* BackWPup Ajax Working.
*
Expand All @@ -1131,16 +1141,6 @@ protected function ajax_working() {

$this->wp_list_table_dependency();

/**
* MainWP BackWPup WP Die ajax handler.
*
* @param string $message Error message container.
* @return string Error message.
*/
function mainwp_backwpup_wp_die_ajax_handler() {
return 'mainwp_backwpup_wp_die_ajax_handler';
}

// We do this in order to not die when using wp_die.
if ( ! defined( 'DOING_AJAX' ) ) {

Expand All @@ -1153,7 +1153,7 @@ function mainwp_backwpup_wp_die_ajax_handler() {
define( 'DOING_AJAX', true );
}

add_filter( 'wp_die_ajax_handler', 'mainwp_backwpup_wp_die_ajax_handler' );
add_filter( 'wp_die_ajax_handler', array( __CLASS__ , 'mainwp_backwpup_wp_die_ajax_handler' ) );
remove_filter( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );

ob_start();
Expand Down Expand Up @@ -1792,6 +1792,7 @@ protected function insert_or_update_jobs() { // phpcs:ignore -- NOSONAR - comple
}
}

// this assign not work with filter_input - INPUT_POST.
foreach ( $settings['value'] as $key => $val ) {
$_POST[ $key ] = $val;
}
Expand Down
12 changes: 11 additions & 1 deletion class/class-mainwp-child-callable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,8 @@ public function disconnect() {
*/
global $mainWPChild;

$mainWPChild->deactivation( false );
$mainWPChild->delete_connection_data();

MainWP_Helper::write( array( 'result' => 'success' ) );
}

Expand Down Expand Up @@ -1087,6 +1088,15 @@ public function deactivate() {
if ( is_plugin_active( $mainWPChild->plugin_slug ) ) {
MainWP_Helper::instance()->error( 'Plugin still active' );
}

/**
* MainWP Child instance.
*
* @global object
*/
global $mainWPChild;

$mainWPChild->delete_connection_data();
$information['deactivated'] = true;
MainWP_Helper::write( $information );
}
Expand Down
7 changes: 4 additions & 3 deletions class/class-mainwp-child-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ public function plugin_action() { //phpcs:ignore -- NOSONAR - complex.

$action_items = array();

if ( 'activate' === $action ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php'; // NOSONAR -- WP compatible.
include_once ABSPATH . '/wp-admin/includes/misc.php'; // NOSONAR -- WP compatible.
include_once ABSPATH . '/wp-admin/includes/plugin.php'; // NOSONAR -- WP compatible.
include_once ABSPATH . 'wp-admin/includes/file.php'; // NOSONAR -- WP compatible get_home_path().
include_once ABSPATH . 'wp-admin/includes/misc.php'; // NOSONAR -- WP compatible extract_from_markers().

if ( 'activate' === $action ) {
foreach ( $plugins as $plugin ) {
if ( $plugin !== $mainWPChild->plugin_slug ) {
$thePlugin = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
Expand Down
14 changes: 9 additions & 5 deletions class/class-mainwp-child-ithemes-security.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,19 @@ public function sync_others_data( $information, $data = array() ) { //phpcs:igno
$response = rest_do_request( $request );
$scans = rest_get_server()->response_to_data( $response, true );


if ( is_array( $scans ) && count( $scans ) > 0 ) {
$scan = current( $scans );
$information['syncIThemeData']['scan_info'] = array(
'time' => $scan['time'],
'description' => $scan['description'],
'status' => $scan['status'],
);
if( is_array($scan ) && isset( $scan['time'] ) ){ // to fix error: "you cannot view site scans".
$information['syncIThemeData']['scan_info'] = array(
'time' => $scan['time'],
'description' => $scan['description'],
'status' => $scan['status'],
);
}
}


if ( class_exists( '\iThemesSecurity\Ban_Users\Database_Repository' ) ) {
try{
$repository = \ITSEC_Modules::get_container()->get( \iThemesSecurity\Ban_Users\Database_Repository::class );
Expand Down
24 changes: 19 additions & 5 deletions class/class-mainwp-child-jetpack-protect.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,25 @@ public function set_connect_disconnect() {
* @return array $return scan result.
*/
public function get_scan_status() {
MainWP_Helper::instance()->check_classes_exists( '\Automattic\Jetpack\Protect\Status' );
MainWP_Helper::instance()->check_methods( '\Automattic\Jetpack\Protect\Status', 'get_status' );
return array(
'status' => \Automattic\Jetpack\Protect\Status::get_status(),
);
$version_error = false;
try {
MainWP_Helper::instance()->check_classes_exists( '\Automattic\Jetpack\Protect\Status' );
MainWP_Helper::instance()->check_methods( '\Automattic\Jetpack\Protect\Status', 'get_status' );
return array(
'status' => \Automattic\Jetpack\Protect\Status::get_status(),
);
} catch ( MainWP_Exception $e ) {
$version_error = true;
}

if ( $version_error ) {
MainWP_Helper::instance()->check_classes_exists( '\Automattic\Jetpack\Protect_Status\Status' );
MainWP_Helper::instance()->check_methods( '\Automattic\Jetpack\Protect_Status\Status', 'get_status' );
return array(
'status' => \Automattic\Jetpack\Protect_Status\Status::get_status(),
);
}
return array();
}

/**
Expand Down
38 changes: 17 additions & 21 deletions class/class-mainwp-child-server-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,28 +1278,24 @@ public static function render_connection_details() {
);
// phpcs:disable WordPress.Security.EscapeOutput
?>
<div class="postbox" id="connection_detail">
<h3 class="mainwp_box_title"><span><?php esc_html_e( 'Connection details', 'mainwp-child' ); ?></span></h3>
<div class="inside">
<div class="mainwp-postbox-actions-top mainwp-padding-5">
<?php printf( esc_html__( 'If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child' ), esc_html( stripslashes( $branding_title ) ) ); ?>
</div>
<table id="mainwp-table" class="wp-list-table widefat" style="border: 0;border-spacing:0;">
<tbody>
<?php
foreach ( $details as $row ) {
?>
<tr>
<th style="width: 20%"><strong><?php echo esc_html( $row['title'] ); ?></strong></th>
<td style="width: 20%"><strong><?php echo esc_html( $row['value'] ); ?></strong></td>
<td><?php echo esc_html( $row['desc'] ); ?></td>
</tr>
<?php
}
<div class="connection-detail-info" id="connection_detail">
<h3><?php esc_html_e( 'Connection details', 'mainwp-child' ); ?></h3>
<p><?php printf( esc_html__( 'If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child' ), esc_html( stripslashes( $branding_title ) ) ); ?></p>
<table class="wp-list-table widefat" style="border: 0;border-spacing:0;">
<tbody>
<?php
foreach ( $details as $row ) {
?>
</tbody>
</table>
</div>
<tr>
<th style="width: 20%"><strong><?php echo esc_html( $row['title'] ); ?></strong></th>
<td style="width: 20%"><strong><?php echo esc_html( $row['value'] ); ?></strong></td>
<td><?php echo esc_html( $row['desc'] ); ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
// phpcs:enable
Expand Down
5 changes: 5 additions & 0 deletions class/class-mainwp-child-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ public function get_site_stats( $information = array(), $exit_done = true ) { //
}
}

// still generate if regverify the connect user disabled pw auth.
if ( ! empty( $_POST['sync_regverify'] ) ) {
$information['regverify_info'] = MainWP_Connect::instance()->validate_register( false, 'generate' );
}

if ( $exit_done ) {
MainWP_Helper::write( $information );
}
Expand Down
86 changes: 86 additions & 0 deletions class/class-mainwp-child-wp-cli-command.php
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.' );
}
}
Loading

0 comments on commit 8e63ad7

Please sign in to comment.