Skip to content

Commit

Permalink
Merge pull request #376 from mainwp/mainwp-child-dev
Browse files Browse the repository at this point in the history
Mainwp child dev
  • Loading branch information
thanghv authored Apr 11, 2023
2 parents ade5c5d + aa1bb81 commit 62224d5
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 28 deletions.
2 changes: 1 addition & 1 deletion class/class-mainwp-child-misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public function code_snippet() {
}
}

$code = isset( $_POST['code'] ) ? stripslashes( wp_unslash( $_POST['code'] ) ) : '';
$code = isset( $_POST['code'] ) ? wp_unslash( $_POST['code'] ) : '';

$information = array();
if ( 'run_snippet' === $action ) {
Expand Down
2 changes: 1 addition & 1 deletion class/class-mainwp-child-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ private function set_post_custom_data( &$new_post, $post_custom, $post_tags, &$e
$new_post['post_author'] = isset( $new_post['post_author'] ) && ! empty( $new_post['post_author'] ) ? $new_post['post_author'] : $current_uid;

if ( isset( $new_post['post_title'] ) ) {
$new_post['post_title'] = htmlspecialchars( $new_post['post_title'] );
$new_post['post_title'] = MainWP_Utility::esc_content( $new_post['post_title'], 'mixed' );
}

if ( isset( $new_post['post_excerpt'] ) ) {
Expand Down
5 changes: 4 additions & 1 deletion class/class-mainwp-child-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function get_site_stats_no_auth( $information = array() ) {
$information['version'] = MainWP_Child::$version;
$information['wpversion'] = $wp_version;
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
$information['wphost'] = MainWP_Helper::get_wp_host();
MainWP_Helper::write( $information );
}

Expand Down Expand Up @@ -257,7 +258,7 @@ public function get_site_stats( $information = array(), $exit = true ) {

$max_his = MainWP_Connect::instance()->get_max_history();
$auths = get_option( 'mainwp_child_auth' );
$information['extauth'] = ( $auths && isset( $auths[ $max_his ] ) ? $auths[ $max_his ] : null );
$information['extauth'] = ( is_array( $auths ) && isset( $auths[ $max_his ] ) ? $auths[ $max_his ] : null );

$information['plugins'] = $this->get_all_plugins_int( false );
$information['themes'] = $this->get_all_themes_int( false );
Expand Down Expand Up @@ -480,6 +481,8 @@ private function stats_get_info( &$information ) {
$information['wpversion'] = $wp_version;
$information['siteurl'] = get_option( 'siteurl' );
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
$information['wphost'] = MainWP_Helper::get_wp_host();

$theme_name = wp_get_theme()->get( 'Name' );
$information['site_info'] = array(
'wpversion' => $wp_version,
Expand Down
33 changes: 26 additions & 7 deletions class/class-mainwp-child-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ public function upgrade_plugin_theme() {
$mwp_premium_updates_todo_slugs = array();
$premiumUpgrader = false;

$plugin_update = false;

if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) {
$this->upgrade_plugin( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
$plugin_update = true;
} elseif ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) {
$this->upgrade_theme( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
} else {
Expand All @@ -152,8 +155,10 @@ public function upgrade_plugin_theme() {
*/
MainWP_Child_Cache_Purge::instance()->auto_purge_cache( $information );

// Save Status results.
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
if ( ! $plugin_update ) {
// Save Status results.
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false ); // causing sync plugins updates info are not correct.
}

// ** Send data to MainWP Dashboard. **//

Expand Down Expand Up @@ -366,14 +371,23 @@ private function to_update_plugins( &$information, $plugins ) {
$information['upgrades'][ $plugin ] = false;
$api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) );

if ( is_wp_error( $api ) ) {
$information['upgrades_error'][ $plugin ] = $api->get_error_message();
}

if ( ! is_wp_error( $api ) && ! empty( $api ) ) {
if ( isset( $api->download_link ) ) {
$res = $upgrader->install( $api->download_link );
if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) {
$information['upgrades'][ $plugin ] = true;
}
if ( is_wp_error( $res ) ) {
$information['upgrades_error'][ $plugin ] = $res->get_error_message();
}
}
}
} elseif ( is_wp_error( $info ) ) {
$information['upgrades_error'][ $plugin ] = $info->get_error_message();
} else {
$information['upgrades'][ $plugin ] = true;
}
Expand Down Expand Up @@ -991,11 +1005,16 @@ private function do_upgrade_wp( &$information ) {
* @return bool true locked.
*/
private function check_core_updater_locked() {
global $wpdb;
$query = "SELECT option_name, option_value FROM $wpdb->options ";
$query .= 'WHERE option_name = "core_updater.lock"';
$found = $wpdb->get_results( $query ); // phpcs:ignore -- safe query, required to achieve desired results, pull request solutions appreciated.
if ( $found ) {
$lock_option = 'core_updater.lock';
$lock_result = get_option( $lock_option );
// There isn't a lock, bail.
if ( ! $lock_result ) {
return false;
}

$release_timeout = 15 * MINUTE_IN_SECONDS;
// Check to see if the lock is still valid. If it is, bail.
if ( $lock_result > ( time() - $release_timeout ) ) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion class/class-mainwp-child.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainWP_Child {
*
* @var string MainWP Child plugin version.
*/
public static $version = '4.4.0.4';
public static $version = '4.4.1-beta1';

/**
* Private variable containing the latest MainWP Child update version.
Expand Down
13 changes: 8 additions & 5 deletions class/class-mainwp-clone-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,15 @@ public function recursive_unserialize_replace( $from = '', $to = '', $data = '',
$data = $_tmp;
unset( $_tmp );
} elseif ( is_object( $data ) ) {
$_tmp = $data;
$props = get_object_vars( $data );
foreach ( $props as $key => $value ) {
$_tmp->{$key} = $this->recursive_unserialize_replace( $from, $to, $value, false );
$_tmp = $data;
$cls_name = get_class( $data );
// to fix: The script tried to modify a property on an incomplete object.
if ( '__PHP_Incomplete_Class' !== $cls_name ) {
$props = get_object_vars( $data );
foreach ( $props as $key => $value ) {
$_tmp->{$key} = $this->recursive_unserialize_replace( $from, $to, $value, false );
}
}

$data = $_tmp;
unset( $_tmp );
} elseif ( is_serialized_string( $data ) && is_serialized( $data ) ) {
Expand Down
4 changes: 2 additions & 2 deletions class/class-mainwp-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public function login( $username, $doAction = false ) {
public function check_other_auth() {
$auths = get_option( 'mainwp_child_auth' );

if ( ! $auths ) {
if ( ! is_array( $auths ) ) {
$auths = array();
}

Expand Down Expand Up @@ -690,7 +690,7 @@ public function check_other_auth() {
*/
public function is_valid_auth( $key ) {
$auths = get_option( 'mainwp_child_auth' );
if ( ! $auths ) {
if ( ! is_array( $auths ) ) {
return false;
}
for ( $i = 0; $i <= $this->maxHistory; $i ++ ) {
Expand Down
35 changes: 35 additions & 0 deletions class/class-mainwp-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,41 @@ public static function is_wp_engine_php8() {
return false;
}

/**
* Method get_wp_host()
*
* Get host if hosted on the FLYWHEEL or Pressable host.
*
* @return string flywheel|pressable If the child site is hosted on FLYWHEEL or Pressable host.
*/
public static function get_wp_host() {
return self::is_flywheel_host() ? 'flywheel' : ( self::is_pressable_host() ? 'pressable' : '' );
}

/**
* Method is_flywheel_host()
*
* Check if the child site is hosted on the FLYWHEEL server.
*
* @return bool true|false If the child site is hosted on the FLYWHEEL, return true, if not, return false.
*/
public static function is_flywheel_host() {
return defined( 'FLYWHEEL_PLUGIN_DIR' ) && ! empty( FLYWHEEL_PLUGIN_DIR );
}

/**
* Method is_pressable_host()
*
* Check if the child site is hosted on the Pressable host.
*
* @return bool true|false If the child site is hosted on the Pressable host, return true, if not, return false.
*/
public static function is_pressable_host() {
$press_site_id = get_option( 'pressable_site_id', false );
return ! empty( $press_site_id );
}


/**
* Method maybe_set_doing_cron()
*
Expand Down
17 changes: 9 additions & 8 deletions class/class-mainwp-security.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,16 @@ public static function remove_readme( $force = false ) {
* @global object $wp_filesystem Filesystem object.
*/
global $wp_filesystem;

$abs_path = $wp_filesystem->abspath();
if ( $force || self::get_security_option( 'readme' ) ) {
if ( $wp_filesystem->exists( $abs_path . 'readme.html' ) ) {
if ( ! unlink( ABSPATH . 'readme.html' ) ) {
$wp_filesystem->delete( $abs_path . 'readme.html' );
if ( $wp_filesystem->exists( $abs_path . 'readme.html' ) ) {
// prevent repeat delete.
self::update_security_option( 'readme', false );
if ( $wp_filesystem->connect() ) {
$abs_path = $wp_filesystem->abspath();
if ( $wp_filesystem->exists( $abs_path . 'readme.html' ) ) {
if ( ! unlink( ABSPATH . 'readme.html' ) ) {
$wp_filesystem->delete( $abs_path . 'readme.html' );
if ( $wp_filesystem->exists( $abs_path . 'readme.html' ) ) {
// prevent repeat delete.
self::update_security_option( 'readme', false );
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mainwp-child.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Author: MainWP
* Author URI: https://mainwp.com
* Text Domain: mainwp-child
* Version: 4.4.0.4
* Version: 4.4.1-beta1
* Requires at least: 5.4
* Requires PHP: 7.4
*/
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com
Requires at least: 5.4
Tested up to: 6.2
Requires PHP: 7.0
Stable tag: 4.4.0.4
Stable tag: 4.4.1-beta1
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down

0 comments on commit 62224d5

Please sign in to comment.