2015-10-15 22:52:37 +10:00
< ? php
2020-05-05 20:13:38 +07:00
namespace MainWP\Child ;
2020-03-26 14:05:04 +00:00
if ( defined ( 'MAINWP_DEBUG' ) && MAINWP_DEBUG === true ) {
2020-04-23 19:16:35 +02:00
error_reporting ( E_ALL );
ini_set ( 'display_errors' , true );
ini_set ( 'display_startup_errors' , true );
2020-02-25 19:41:28 +07:00
} else {
2020-04-07 16:53:05 +02:00
if ( isset ( $_REQUEST [ 'mainwpsignature' ] ) ) {
2020-04-23 19:16:35 +02:00
ini_set ( 'display_errors' , false );
error_reporting ( 0 );
2020-03-26 19:51:58 +00:00
}
2016-03-15 20:54:21 +01:00
}
2015-10-15 22:52:37 +10:00
2020-03-26 14:11:33 +00:00
require_once ABSPATH . '/wp-admin/includes/file.php' ;
require_once ABSPATH . '/wp-admin/includes/plugin.php' ;
2015-10-15 22:52:37 +10:00
class MainWP_Child {
2020-05-04 23:02:02 +07:00
public static $version = '4.0.7.1' ;
2019-02-14 22:38:14 +07:00
private $update_version = '1.5' ;
2015-10-15 22:52:37 +10:00
private $callableFunctions = array (
2020-05-06 00:47:59 +07:00
'stats' => 'get_site_stats' ,
'upgrade' => 'upgrade_wp' ,
'newpost' => 'new_post' ,
2015-10-15 22:52:37 +10:00
'deactivate' => 'deactivate' ,
2020-05-06 00:47:59 +07:00
'newuser' => 'new_user' ,
'newadminpassword' => 'new_admin_password' ,
'installplugintheme' => 'install_plugin_theme' ,
'upgradeplugintheme' => 'upgrade_plugin_theme' ,
'upgradetranslation' => 'upgrade_translation' ,
2015-10-15 22:52:37 +10:00
'backup' => 'backup' ,
'backup_checkpid' => 'backup_checkpid' ,
'cloneinfo' => 'cloneinfo' ,
2020-05-06 00:47:59 +07:00
'security' => 'get_security_stats' ,
'securityFix' => 'do_security_fix' ,
'securityUnFix' => 'do_security_un_fix' ,
2015-10-15 22:52:37 +10:00
'post_action' => 'post_action' ,
'get_all_posts' => 'get_all_posts' ,
'comment_action' => 'comment_action' ,
'comment_bulk_action' => 'comment_bulk_action' ,
'get_all_comments' => 'get_all_comments' ,
'get_all_themes' => 'get_all_themes' ,
'theme_action' => 'theme_action' ,
'get_all_plugins' => 'get_all_plugins' ,
'plugin_action' => 'plugin_action' ,
'get_all_pages' => 'get_all_pages' ,
'get_all_users' => 'get_all_users' ,
'user_action' => 'user_action' ,
'search_users' => 'search_users' ,
'get_terms' => 'get_terms' ,
'set_terms' => 'set_terms' ,
'insert_comment' => 'insert_comment' ,
'get_post_meta' => 'get_post_meta' ,
'get_total_ezine_post' => 'get_total_ezine_post' ,
'get_next_time_to_post' => 'get_next_time_to_post' ,
'cancel_scheduled_post' => 'cancel_scheduled_post' ,
2020-05-06 00:47:59 +07:00
'serverInformation' => 'server_information' ,
2015-10-15 22:52:37 +10:00
'maintenance_site' => 'maintenance_site' ,
'keyword_links_action' => 'keyword_links_action' ,
'branding_child_plugin' => 'branding_child_plugin' ,
'code_snippet' => 'code_snippet' ,
'uploader_action' => 'uploader_action' ,
'wordpress_seo' => 'wordpress_seo' ,
'client_report' => 'client_report' ,
2020-05-06 00:47:59 +07:00
'createBackupPoll' => 'backup_poll' ,
2015-10-15 22:52:37 +10:00
'page_speed' => 'page_speed' ,
'woo_com_status' => 'woo_com_status' ,
'links_checker' => 'links_checker' ,
'wordfence' => 'wordfence' ,
'delete_backup' => 'delete_backup' ,
'update_values' => 'update_values' ,
'ithemes' => 'ithemes' ,
'updraftplus' => 'updraftplus' ,
'backup_wp' => 'backup_wp' ,
'backwpup' => 'backwpup' ,
'wp_rocket' => 'wp_rocket' ,
'settings_tools' => 'settings_tools' ,
'skeleton_key' => 'skeleton_key' ,
2020-03-26 15:29:54 +00:00
'custom_post_type' => 'custom_post_type' ,
2020-03-27 15:13:11 +00:00
'backup_buddy' => 'backup_buddy' ,
'get_site_icon' => 'get_site_icon' ,
'vulner_checker' => 'vulner_checker' ,
'wp_staging' => 'wp_staging' ,
2018-06-26 19:52:53 +02:00
'disconnect' => 'disconnect' ,
'time_capsule' => 'time_capsule' ,
2020-04-07 18:33:47 +02:00
'extra_excution' => 'extra_execution' , // deprecated!
2020-03-27 15:13:11 +00:00
'extra_execution' => 'extra_execution' ,
'wpvivid_backuprestore' => 'wpvivid_backuprestore' ,
2015-10-15 22:52:37 +10:00
);
2016-10-24 20:33:37 +02:00
private $FTP_ERROR = 'Failed! Please, add FTP details for automatic updates.' ;
2015-10-15 22:52:37 +10:00
private $callableFunctionsNoAuth = array (
2020-05-06 00:47:59 +07:00
'stats' => 'get_site_stats_no_auth' ,
2015-10-15 22:52:37 +10:00
);
private $posts_where_suffix ;
private $comments_and_clauses ;
private $plugin_slug ;
private $plugin_dir ;
private $slug ;
private $maxHistory = 5 ;
2020-03-26 19:45:07 +00:00
private $filterFunction = null ;
2016-04-27 21:54:28 +02:00
public static $brandingTitle = null ;
2015-10-15 22:52:37 +10:00
2016-04-27 21:54:28 +02:00
public static $subPages ;
public static $subPagesLoaded = false ;
2015-10-15 22:52:37 +10:00
public function __construct ( $plugin_file ) {
$this -> update ();
2020-03-27 15:13:11 +00:00
$this -> load_all_options ();
2020-03-27 13:05:05 +00:00
$this -> filterFunction = function ( $a ) {
2020-04-07 18:33:47 +02:00
if ( null == $a ) {
2020-03-26 19:51:58 +00:00
return false ; }
2020-04-07 16:53:05 +02:00
if ( is_object ( $a ) && property_exists ( $a , 'last_checked' ) && ! property_exists ( $a , 'checked' ) ) {
2018-09-27 19:52:32 +02:00
return false ;
2020-03-27 15:13:11 +00:00
}
2018-04-17 20:33:10 +02:00
return $a ;
2018-09-27 19:52:32 +02:00
};
2015-10-15 22:52:37 +10:00
$this -> plugin_dir = dirname ( $plugin_file );
$this -> plugin_slug = plugin_basename ( $plugin_file );
2020-03-26 19:45:07 +00:00
list ( $t1 , $t2 ) = explode ( '/' , $this -> plugin_slug );
$this -> slug = str_replace ( '.php' , '' , $t2 );
2015-10-15 22:52:37 +10:00
$this -> posts_where_suffix = '' ;
$this -> comments_and_clauses = '' ;
add_action ( 'template_redirect' , array ( $this , 'template_redirect' ) );
2016-04-27 19:25:53 +02:00
add_action ( 'init' , array ( & $this , 'check_login' ), 1 );
2018-09-27 19:52:32 +02:00
add_action ( 'init' , array ( & $this , 'parse_init' ), 9999 );
2015-10-15 22:52:37 +10:00
add_action ( 'admin_menu' , array ( & $this , 'admin_menu' ) );
add_action ( 'admin_init' , array ( & $this , 'admin_init' ) );
2016-12-08 20:54:26 +01:00
add_action ( 'admin_head' , array ( & $this , 'admin_head' ) );
2016-03-15 20:54:21 +01:00
add_action ( 'init' , array ( & $this , 'localization' ), 33 );
2020-04-07 17:12:41 +02:00
add_action ( 'pre_current_active_plugins' , array ( & $this , 'detect_premium_themesplugins_updates' ) ); // to support detect premium plugins update.
add_action ( 'core_upgrade_preamble' , array ( & $this , 'detect_premium_themesplugins_updates' ) ); // to support detect premium themes.
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
if ( is_admin () ) {
2015-12-12 18:39:23 +01:00
MainWP_Helper :: update_option ( 'mainwp_child_plugin_version' , self :: $version , 'yes' );
2015-10-15 22:52:37 +10:00
}
2020-05-06 00:47:59 +07:00
$this -> check_other_auth ();
2015-10-15 22:52:37 +10:00
2016-12-08 20:54:26 +01:00
MainWP_Clone :: get () -> init ();
2015-10-15 22:52:37 +10:00
MainWP_Child_Server_Information :: init ();
2020-05-06 20:22:11 +07:00
MainWP_Client_Report :: instance () -> init ();
MainWP_Child_Plugins_Check :: instance ();
MainWP_Child_Themes_Check :: instance ();
2015-10-15 22:52:37 +10:00
$this -> run_saved_snippets ();
if ( ! get_option ( 'mainwp_child_pubkey' ) ) {
2020-05-06 20:22:11 +07:00
MainWP_Child_Branding :: instance () -> save_branding_options ( 'branding_disconnected' , 'yes' );
2020-04-07 16:53:05 +02:00
MainWP_Helper :: update_option ( 'mainwp_child_branding_disconnected' , 'yes' , 'yes' );
2015-10-15 22:52:37 +10:00
}
add_action ( 'admin_notices' , array ( & $this , 'admin_notice' ) );
add_filter ( 'plugin_row_meta' , array ( & $this , 'plugin_row_meta' ), 10 , 2 );
2016-03-03 20:28:07 +01:00
if ( defined ( 'DOING_CRON' ) && DOING_CRON ) {
2020-04-07 16:53:05 +02:00
if ( isset ( $_GET [ 'mainwp_child_run' ] ) && ! empty ( $_GET [ 'mainwp_child_run' ] ) ) {
2016-03-03 20:28:07 +01:00
add_action ( 'init' , array ( $this , 'cron_active' ), PHP_INT_MAX );
}
}
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function load_all_options () {
2017-08-24 20:41:12 +02:00
global $wpdb ;
2020-03-26 17:03:00 +00:00
if ( ! defined ( 'WP_INSTALLING' ) || ! is_multisite () ) {
2017-08-24 20:41:12 +02:00
$alloptions = wp_cache_get ( 'alloptions' , 'options' );
2020-03-26 14:11:33 +00:00
} else {
2017-08-24 20:41:12 +02:00
$alloptions = false ;
2020-03-27 15:13:11 +00:00
}
2017-08-24 20:41:12 +02:00
2020-03-26 17:03:00 +00:00
if ( ! defined ( 'WP_INSTALLING' ) || ! is_multisite () ) {
2017-08-24 20:41:12 +02:00
$notoptions = wp_cache_get ( 'notoptions' , 'options' );
2020-03-26 14:11:33 +00:00
} else {
2017-08-24 20:41:12 +02:00
$notoptions = false ;
2020-03-27 15:13:11 +00:00
}
2017-08-24 20:41:12 +02:00
2020-04-07 16:53:05 +02:00
if ( ! isset ( $alloptions [ 'mainwp_db_version' ] ) ) {
2017-08-24 20:41:12 +02:00
$suppress = $wpdb -> suppress_errors ();
2020-03-26 19:45:07 +00:00
$options = array (
2020-03-27 15:13:11 +00:00
'mainwp_child_auth' ,
'mainwp_branding_plugin_header' ,
'mainwp_child_reports_db' ,
'mainwp_child_fix_htaccess' ,
'mainwp_child_pluginDir' ,
'mainwp_updraftplus_hide_plugin' ,
'mainwp_backwpup_ext_enabled' ,
'mainwpKeywordLinks' ,
'mainwp_child_server' ,
'mainwp_kwl_options' ,
'mainwp_kwl_keyword_links' ,
'mainwp_keyword_links_htaccess_set' ,
'mainwp_pagespeed_hide_plugin' ,
'mainwp_kwl_enable_statistic' ,
'mainwp_child_clone_permalink' ,
'mainwp_child_restore_permalink' ,
'mainwp_ext_snippets_enabled' ,
'mainwp_child_pubkey' ,
'mainwp_child_nossl' ,
'mainwp_security' ,
'mainwp_backupwordpress_ext_enabled' ,
2020-04-07 16:53:05 +02:00
'mainwp_branding_button_contact_label' ,
2020-03-27 15:13:11 +00:00
'mainwp_branding_extra_settings' ,
'mainwp_branding_child_hide' ,
'mainwp_branding_ext_enabled' ,
'mainwp_pagespeed_ext_enabled' ,
'mainwp_linkschecker_ext_enabled' ,
'mainwp_child_branding_settings' ,
'mainwp_child_plugintheme_days_outdate' ,
);
2020-03-26 19:45:07 +00:00
$query = " SELECT option_name, option_value FROM $wpdb->options WHERE option_name in ( " ;
2020-03-27 13:05:05 +00:00
foreach ( $options as $option ) {
2017-08-24 20:41:12 +02:00
$query .= " ' " . $option . " ', " ;
}
2020-04-07 16:53:05 +02:00
$query = substr ( $query , 0 , strlen ( $query ) - 2 );
2020-04-07 19:32:01 +02:00
$query .= " ) " ; // phpcs:ignore
2017-08-24 20:41:12 +02:00
$alloptions_db = $wpdb -> get_results ( $query );
2020-04-07 16:53:05 +02:00
$wpdb -> suppress_errors ( $suppress );
2020-03-26 17:03:00 +00:00
if ( ! is_array ( $alloptions ) ) {
2020-03-26 19:51:58 +00:00
$alloptions = array ();
2020-03-27 15:13:11 +00:00
}
2017-08-24 20:41:12 +02:00
if ( is_array ( $alloptions_db ) ) {
foreach ( ( array ) $alloptions_db as $o ) {
$alloptions [ $o -> option_name ] = $o -> option_value ;
2020-04-07 16:53:05 +02:00
unset ( $options [ array_search ( $o -> option_name , $options ) ] );
2017-08-24 20:41:12 +02:00
}
2020-03-27 13:05:05 +00:00
foreach ( $options as $option ) {
2017-08-24 20:41:12 +02:00
$notoptions [ $option ] = true ;
}
if ( ! defined ( 'WP_INSTALLING' ) || ! is_multisite () ) {
wp_cache_set ( 'alloptions' , $alloptions , 'options' );
wp_cache_set ( 'notoptions' , $notoptions , 'options' );
}
}
}
return $alloptions ;
}
2020-04-07 19:04:20 +02:00
public function update () {
2015-10-15 22:52:37 +10:00
$update_version = get_option ( 'mainwp_child_update_version' );
if ( $update_version === $this -> update_version ) {
return ;
}
if ( false === $update_version ) {
$options = array (
'mainwp_child_legacy' ,
'mainwp_child_auth' ,
'mainwp_child_uniqueId' ,
'mainwp_child_htaccess_set' ,
'mainwp_child_fix_htaccess' ,
'mainwp_child_pubkey' ,
'mainwp_child_server' ,
'mainwp_child_nonce' ,
'mainwp_child_nossl' ,
'mainwp_child_nossl_key' ,
'mainwp_child_remove_wp_version' ,
'mainwp_child_remove_rsd' ,
'mainwp_child_remove_wlw' ,
'mainwp_child_remove_core_updates' ,
'mainwp_child_remove_plugin_updates' ,
'mainwp_child_remove_theme_updates' ,
'mainwp_child_remove_php_reporting' ,
'mainwp_child_remove_scripts_version' ,
'mainwp_child_remove_styles_version' ,
'mainwp_child_remove_readme' ,
'mainwp_child_clone_sites' ,
'mainwp_child_pluginDir' ,
'mainwp_premium_updates' ,
'mainwp_child_activated_once' ,
'mainwp_maintenance_opt_alert_404' ,
'mainwp_maintenance_opt_alert_404_email' ,
'mainwp_ext_code_snippets' ,
'mainwp_ext_snippets_enabled' ,
'mainwp_temp_clone_plugins' ,
'mainwp_temp_clone_themes' ,
'mainwp_child_click_data' ,
'mainwp_child_clone_from_server_last_folder' ,
'mainwp_child_clone_permalink' ,
'mainwp_child_restore_permalink' ,
'mainwp_keyword_links_htaccess_set' ,
'mainwp_kwl_options' ,
'mainwp_kwl_keyword_links' ,
'mainwp_kwl_click_statistic_data' ,
'mainwp_kwl_statistic_data_' ,
'mainwp_kwl_enable_statistic' ,
'mainwpKeywordLinks' ,
);
foreach ( $options as $option ) {
MainWP_Helper :: fix_option ( $option );
}
2020-03-26 14:11:33 +00:00
} elseif ( ( '1.0' === $update_version ) || ( '1.1' === $update_version ) ) {
2015-10-15 22:52:37 +10:00
$options = array (
'mainwp_child_pubkey' ,
'mainwp_child_update_version' ,
'mainwp_child_auth' ,
'mainwp_child_clone_permalink' ,
'mainwp_child_restore_permalink' ,
'mainwp_ext_snippets_enabled' ,
'mainwp_child_fix_htaccess' ,
'mainwp_child_pluginDir' ,
'mainwp_child_htaccess_set' ,
'mainwp_child_nossl' ,
'mainwp_updraftplus_ext_enabled' ,
'mainwpKeywordLinks' ,
'mainwp_keyword_links_htaccess_set' ,
'mainwp_pagespeed_ext_enabled' ,
'mainwp_linkschecker_ext_enabled' ,
'mainwp_maintenance_opt_alert_404' ,
);
foreach ( $options as $option ) {
MainWP_Helper :: fix_option ( $option , 'yes' );
}
if ( ! is_array ( get_option ( 'mainwp_security' ) ) ) {
$securityOptions = array (
'wp_version' => 'mainwp_child_remove_wp_version' ,
'rsd' => 'mainwp_child_remove_rsd' ,
'wlw' => 'mainwp_child_remove_wlw' ,
'core_updates' => 'mainwp_child_remove_core_updates' ,
'plugin_updates' => 'mainwp_child_remove_plugin_updates' ,
'theme_updates' => 'mainwp_child_remove_theme_updates' ,
'php_reporting' => 'mainwp_child_remove_php_reporting' ,
'scripts_version' => 'mainwp_child_remove_scripts_version' ,
'styles_version' => 'mainwp_child_remove_styles_version' ,
'readme' => 'mainwp_child_remove_readme' ,
);
$security = array ();
foreach ( $securityOptions as $option => $old ) {
$value = get_option ( $old );
$security [ $option ] = ( 'T' === $value );
}
MainWP_Helper :: update_option ( 'mainwp_security' , $security , 'yes' );
}
2019-02-14 22:38:14 +07:00
}
2020-04-07 16:53:05 +02:00
if ( ! empty ( $update_version ) && version_compare ( $update_version , '1.4' , '<=' ) ) {
2020-03-27 15:13:11 +00:00
if ( ! is_array ( get_option ( 'mainwp_child_branding_settings' ) ) ) {
$brandingOptions = array (
'hide' => 'mainwp_branding_child_hide' ,
'extra_settings' => 'mainwp_branding_extra_settings' ,
'branding_disconnected' => 'mainwp_child_branding_disconnected' ,
'preserve_branding' => 'mainwp_branding_preserve_branding' ,
'branding_header' => 'mainwp_branding_plugin_header' ,
'support_email' => 'mainwp_branding_support_email' ,
'support_message' => 'mainwp_branding_support_message' ,
'remove_restore' => 'mainwp_branding_remove_restore' ,
'remove_setting' => 'mainwp_branding_remove_setting' ,
'remove_server_info' => 'mainwp_branding_remove_server_info' ,
'remove_connection_detail' => 'mainwp_branding_remove_connection_detail' ,
'remove_wp_tools' => 'mainwp_branding_remove_wp_tools' ,
'remove_wp_setting' => 'mainwp_branding_remove_wp_setting' ,
'remove_permalink' => 'mainwp_branding_remove_permalink' ,
'contact_label' => 'mainwp_branding_button_contact_label' ,
'email_message' => 'mainwp_branding_send_email_message' ,
'message_return_sender' => 'mainwp_branding_message_return_sender' ,
'submit_button_title' => 'mainwp_branding_submit_button_title' ,
'disable_wp_branding' => 'mainwp_branding_disable_wp_branding' ,
'show_support' => 'mainwp_branding_show_support' ,
'disable_change' => 'mainwp_branding_disable_change' ,
'disable_switching_theme' => 'mainwp_branding_disable_switching_theme' ,
'branding_ext_enabled' => 'mainwp_branding_ext_enabled' ,
);
$convertBranding = array ();
2019-02-14 22:38:14 +07:00
foreach ( $brandingOptions as $option => $old ) {
2020-03-26 19:45:07 +00:00
$value = get_option ( $old );
2019-02-14 22:38:14 +07:00
$convertBranding [ $option ] = $value ;
}
2020-03-27 15:13:11 +00:00
MainWP_Helper :: update_option ( 'mainwp_child_branding_settings' , $convertBranding );
}
2015-10-15 22:52:37 +10:00
}
MainWP_Helper :: update_option ( 'mainwp_child_update_version' , $this -> update_version , 'yes' );
}
2020-04-07 19:04:20 +02:00
public function cron_active () {
2016-03-03 20:28:07 +01:00
if ( ! defined ( 'DOING_CRON' ) || ! DOING_CRON ) {
return ;
}
2020-03-26 15:29:54 +00:00
if ( empty ( $_GET [ 'mainwp_child_run' ] ) || 'test' !== $_GET [ 'mainwp_child_run' ] ) {
2016-03-03 20:28:07 +01:00
return ;
}
2020-04-23 19:16:35 +02:00
session_write_close ();
2020-05-05 20:13:38 +07:00
header ( 'Content-Type: text/html; charset=' . get_bloginfo ( 'charset' ), true );
header ( 'X-Robots-Tag: noindex, nofollow' , true );
header ( 'X-MainWP-Child-Version: ' . self :: $version , true );
2016-03-03 20:28:07 +01:00
nocache_headers ();
2020-04-07 18:33:47 +02:00
if ( 'test' == $_GET [ 'mainwp_child_run' ] ) {
2016-03-03 20:28:07 +01:00
die ( 'MainWP Test' );
}
die ( '' );
}
2015-10-15 22:52:37 +10:00
public function admin_notice () {
2020-03-26 20:01:04 +00:00
// Admin Notice...
2020-05-06 00:47:59 +07:00
if ( ! get_option ( 'mainwp_child_pubkey' ) && MainWP_Helper :: is_admin () && is_admin () ) {
2020-05-06 20:22:11 +07:00
$branding_opts = MainWP_Child_Branding :: instance () -> get_branding_options ();
2020-04-07 18:33:47 +02:00
$child_name = ( '' === $branding_opts [ 'branding_preserve_title' ] ) ? 'MainWP Child' : $branding_opts [ 'branding_preserve_title' ];
$dashboard_name = ( '' === $branding_opts [ 'branding_preserve_title' ] ) ? 'MainWP Dashboard' : $branding_opts [ 'branding_preserve_title' ] . ' Dashboard' ;
2020-03-27 15:13:11 +00:00
$msg = '<div class="wrap"><div class="postbox" style="margin-top: 4em;"><p style="background: #a00; color: #fff; font-size: 22px; font-weight: bold; margin: 0; padding: .3em;">' ;
$msg .= __ ( 'Attention!' , 'mainwp-child' );
$msg .= '</p><div style="padding-left: 1em; padding-right: 1em;"><p style="font-size: 16px;">' ;
$msg .= __ ( 'Please add this site to your ' , 'mainwp-child' ) . $dashboard_name . ' ' . __ ( '<b>NOW</b> or deactivate the ' , 'mainwp-child' ) . $child_name . __ ( ' plugin until you are ready to connect this site to your Dashboard in order to avoid unexpected security issues.' , 'mainwp-child' );
$msg .= '</p>' ;
$msg .= '<p style="font-size: 16px;">' ;
$msg .= __ ( 'If you are not sure how to add this site to your Dashboard, <a href="https://mainwp.com/help/docs/set-up-the-mainwp-plugin/add-site-to-your-dashboard/" target="_blank">please review these instructions</a>.' , 'mainwp-child' );
$msg .= '</p>' ;
2020-05-06 20:22:11 +07:00
if ( ! MainWP_Child_Branding :: instance () -> is_branding () ) {
2020-03-27 15:13:11 +00:00
$msg .= '<p>' ;
$msg .= __ ( 'You can also turn on the unique security ID option in <a href="admin.php?page=mainwp_child_tab">' , 'mainwp-child' ) . $child_name . __ ( ' settings</a> if you would like extra security and additional time to add this site to your Dashboard. <br/>Find out more in this help document <a href="https://mainwp.com/help/docs/set-up-the-mainwp-plugin/set-unique-security-id/" target="_blank">How do I use the child unique security ID?</a>' , 'mainwp-child' );
$msg .= '</p>' ;
}
$msg .= '</div></div></div>' ;
echo wp_kses_post ( $msg );
}
2020-05-06 20:22:11 +07:00
MainWP_Child_Server_Information :: show_warnings ();
2015-10-15 22:52:37 +10:00
}
public function localization () {
load_plugin_textdomain ( 'mainwp-child' , false , dirname ( dirname ( plugin_basename ( __FILE__ ) ) ) . '/languages/' );
}
2019-02-14 22:38:14 +07:00
public function detect_premium_themesplugins_updates () {
2019-03-06 22:45:51 +07:00
2020-04-07 18:33:47 +02:00
if ( isset ( $_GET [ '_detect_plugins_updates' ] ) && 'yes' == $_GET [ '_detect_plugins_updates' ] ) {
2020-04-07 19:32:01 +02:00
// to fix some premium plugins update notification.
2020-03-27 15:13:11 +00:00
$current = get_site_transient ( 'update_plugins' );
set_site_transient ( 'update_plugins' , $current );
add_filter ( 'pre_site_transient_update_plugins' , $this -> filterFunction , 99 );
$plugins = get_plugin_updates ();
remove_filter ( 'pre_site_transient_update_plugins' , $this -> filterFunction , 99 );
2020-04-07 18:33:47 +02:00
set_site_transient ( 'mainwp_update_plugins_cached' , $plugins , DAY_IN_SECONDS );
2020-03-27 15:13:11 +00:00
}
2020-04-07 18:33:47 +02:00
if ( isset ( $_GET [ '_detect_themes_updates' ] ) && 'yes' == $_GET [ '_detect_themes_updates' ] ) {
2020-03-27 15:13:11 +00:00
add_filter ( 'pre_site_transient_update_themes' , $this -> filterFunction , 99 );
$themes = get_theme_updates ();
remove_filter ( 'pre_site_transient_update_themes' , $this -> filterFunction , 99 );
2020-04-07 18:33:47 +02:00
set_site_transient ( 'mainwp_update_themes_cached' , $themes , DAY_IN_SECONDS );
2020-03-27 15:13:11 +00:00
}
2020-04-07 16:53:05 +02:00
$type = isset ( $_GET [ '_request_update_premiums_type' ] ) ? $_GET [ '_request_update_premiums_type' ] : '' ;
2020-04-07 18:33:47 +02:00
if ( 'plugin' == $type || 'theme' == $type ) {
2020-03-27 15:13:11 +00:00
$list = isset ( $_GET [ 'list' ] ) ? $_GET [ 'list' ] : '' ;
2020-04-07 16:53:05 +02:00
if ( ! empty ( $list ) ) {
2020-05-06 00:47:59 +07:00
// to call function upgrade_plugin_theme().
2020-03-27 15:13:11 +00:00
$_POST [ 'type' ] = $type ;
$_POST [ 'list' ] = $list ;
$function = 'upgradeplugintheme' ;
2020-04-07 16:53:05 +02:00
if ( isset ( $this -> callableFunctions [ $function ] ) ) {
2020-03-27 15:13:11 +00:00
call_user_func ( array ( $this , $this -> callableFunctions [ $function ] ) );
}
}
}
}
2016-02-15 22:08:39 +01:00
2020-05-06 00:47:59 +07:00
public function check_other_auth () {
2015-10-15 22:52:37 +10:00
$auths = get_option ( 'mainwp_child_auth' );
if ( ! $auths ) {
$auths = array ();
}
if ( ! isset ( $auths [ 'last' ] ) || $auths [ 'last' ] < mktime ( 0 , 0 , 0 , date ( 'm' ), date ( 'd' ), date ( 'Y' ) ) ) {
2020-04-07 17:12:41 +02:00
// Generate code for today.
2015-10-15 22:52:37 +10:00
for ( $i = 0 ; $i < $this -> maxHistory ; $i ++ ) {
if ( ! isset ( $auths [ $i + 1 ] ) ) {
continue ;
}
$auths [ $i ] = $auths [ $i + 1 ];
}
$newI = $this -> maxHistory + 1 ;
while ( isset ( $auths [ $newI ] ) ) {
unset ( $auths [ $newI ++ ] );
}
2020-05-06 00:47:59 +07:00
$auths [ $this -> maxHistory ] = md5 ( MainWP_Helper :: rand_string ( 14 ) );
2015-10-15 22:52:37 +10:00
$auths [ 'last' ] = time ();
MainWP_Helper :: update_option ( 'mainwp_child_auth' , $auths , 'yes' );
}
}
2020-05-06 00:47:59 +07:00
public function is_valid_auth ( $key ) {
2015-10-15 22:52:37 +10:00
$auths = get_option ( 'mainwp_child_auth' );
if ( ! $auths ) {
return false ;
}
for ( $i = 0 ; $i <= $this -> maxHistory ; $i ++ ) {
if ( isset ( $auths [ $i ] ) && ( $auths [ $i ] === $key ) ) {
return true ;
}
}
return false ;
}
2020-04-07 19:04:20 +02:00
public function template_redirect () {
2016-02-17 20:38:44 +01:00
$this -> maintenance_alert_404 ();
2015-10-15 22:52:37 +10:00
}
public function plugin_row_meta ( $plugin_meta , $plugin_file ) {
if ( $this -> plugin_slug !== $plugin_file ) {
return $plugin_meta ;
}
return apply_filters ( 'mainwp_child_plugin_row_meta' , $plugin_meta , $plugin_file , $this -> plugin_slug );
}
2020-04-07 19:04:20 +02:00
public function admin_menu () {
2020-05-06 20:22:11 +07:00
$branding_opts = MainWP_Child_Branding :: instance () -> get_branding_options ();
2020-03-27 15:13:11 +00:00
$is_hide = isset ( $branding_opts [ 'hide' ] ) ? $branding_opts [ 'hide' ] : '' ;
$cancelled_branding = $branding_opts [ 'cancelled_branding' ];
2015-10-15 22:52:37 +10:00
2020-04-07 16:53:05 +02:00
if ( isset ( $branding_opts [ 'remove_wp_tools' ] ) && $branding_opts [ 'remove_wp_tools' ] && ! $cancelled_branding ) {
2015-10-15 22:52:37 +10:00
remove_menu_page ( 'tools.php' );
2020-04-07 16:53:05 +02:00
$pos = stripos ( $_SERVER [ 'REQUEST_URI' ], 'tools.php' ) || stripos ( $_SERVER [ 'REQUEST_URI' ], 'import.php' ) || stripos ( $_SERVER [ 'REQUEST_URI' ], 'export.php' );
2015-10-15 22:52:37 +10:00
if ( false !== $pos ) {
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( get_option ( 'siteurl' ) . '/wp-admin/index.php' );
2015-10-15 22:52:37 +10:00
}
}
2020-04-07 16:53:05 +02:00
// if preserve branding and do not remove menus.
if ( isset ( $branding_opts [ 'remove_wp_setting' ] ) && $branding_opts [ 'remove_wp_setting' ] && ! $cancelled_branding ) {
2015-10-15 22:52:37 +10:00
remove_menu_page ( 'options-general.php' );
2020-04-07 16:53:05 +02:00
$pos = stripos ( $_SERVER [ 'REQUEST_URI' ], 'options-general.php' ) || stripos ( $_SERVER [ 'REQUEST_URI' ], 'options-writing.php' ) || stripos ( $_SERVER [ 'REQUEST_URI' ], 'options-reading.php' ) || stripos ( $_SERVER [ 'REQUEST_URI' ], 'options-discussion.php' ) || stripos ( $_SERVER [ 'REQUEST_URI' ], 'options-media.php' ) || stripos ( $_SERVER [ 'REQUEST_URI' ], 'options-permalink.php' );
2015-10-15 22:52:37 +10:00
if ( false !== $pos ) {
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( get_option ( 'siteurl' ) . '/wp-admin/index.php' );
2015-10-15 22:52:37 +10:00
exit ();
}
}
2020-04-07 16:53:05 +02:00
if ( isset ( $branding_opts [ 'remove_permalink' ] ) && $branding_opts [ 'remove_permalink' ] && ! $cancelled_branding ) {
2015-10-15 22:52:37 +10:00
remove_submenu_page ( 'options-general.php' , 'options-permalink.php' );
$pos = stripos ( $_SERVER [ 'REQUEST_URI' ], 'options-permalink.php' );
if ( false !== $pos ) {
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( get_option ( 'siteurl' ) . '/wp-admin/index.php' );
2015-10-15 22:52:37 +10:00
exit ();
}
}
$remove_all_child_menu = false ;
2020-04-07 16:53:05 +02:00
if ( isset ( $branding_opts [ 'remove_setting' ] ) && isset ( $branding_opts [ 'remove_restore' ] ) && isset ( $branding_opts [ 'remove_server_info' ] ) && $branding_opts [ 'remove_setting' ] && $branding_opts [ 'remove_restore' ] && $branding_opts [ 'remove_server_info' ] ) {
2015-10-15 22:52:37 +10:00
$remove_all_child_menu = true ;
}
2020-04-07 16:53:05 +02:00
// if preserve branding and do not hide menus.
2020-04-07 18:33:47 +02:00
if ( ( ! $remove_all_child_menu && 'T' !== $is_hide ) || $cancelled_branding ) {
2020-03-27 15:13:11 +00:00
$branding_header = isset ( $branding_opts [ 'branding_header' ] ) ? $branding_opts [ 'branding_header' ] : array ();
2016-04-27 21:54:28 +02:00
if ( ( is_array ( $branding_header ) && ! empty ( $branding_header [ 'name' ] ) ) && ! $cancelled_branding ) {
2020-04-07 19:32:01 +02:00
self :: $brandingTitle = stripslashes ( $branding_header [ 'name' ] );
$child_menu_title = stripslashes ( $branding_header [ 'name' ] );
2020-03-26 19:45:07 +00:00
$child_page_title = $child_menu_title . ' Settings' ;
2016-04-27 21:54:28 +02:00
} else {
2020-03-26 19:45:07 +00:00
$child_menu_title = 'MainWP Child' ;
2016-04-27 21:54:28 +02:00
$child_page_title = 'MainWPSettings' ;
}
2015-10-15 22:52:37 +10:00
2016-04-27 21:54:28 +02:00
$settingsPage = add_submenu_page ( 'options-general.php' , $child_menu_title , $child_menu_title , 'manage_options' , 'mainwp_child_tab' , array ( & $this , 'render_pages' ) );
2015-10-15 22:52:37 +10:00
2020-05-05 20:13:38 +07:00
add_action ( 'admin_print_scripts-' . $settingsPage , array ( MainWP_Clone :: get_class_name (), 'print_scripts' ) );
2016-04-27 21:54:28 +02:00
$subpageargs = array (
2020-04-07 17:12:41 +02:00
'child_slug' => 'options-general.php' ,
2020-04-07 18:33:47 +02:00
'branding' => ( null === self :: $brandingTitle ) ? 'MainWP' : self :: $brandingTitle ,
2020-03-26 14:05:04 +00:00
'parent_menu' => $settingsPage ,
2016-04-27 21:54:28 +02:00
);
2020-04-07 17:12:41 +02:00
do_action ( 'mainwp-child-subpages' , $subpageargs );
2016-04-27 21:54:28 +02:00
$sub_pages = array ();
2019-02-14 22:38:14 +07:00
2016-04-28 20:22:43 +02:00
$all_subpages = apply_filters ( 'mainwp-child-init-subpages' , array () );
2020-03-26 17:03:00 +00:00
if ( ! is_array ( $all_subpages ) ) {
2016-04-28 20:22:43 +02:00
$all_subpages = array ();
2020-03-27 15:13:11 +00:00
}
2016-04-28 20:22:43 +02:00
2020-03-26 17:03:00 +00:00
if ( ! self :: $subPagesLoaded ) {
foreach ( $all_subpages as $page ) {
2016-04-28 20:22:43 +02:00
$slug = isset ( $page [ 'slug' ] ) ? $page [ 'slug' ] : '' ;
2020-03-26 14:11:33 +00:00
if ( empty ( $slug ) ) {
2016-04-27 21:54:28 +02:00
continue ;
2020-03-27 15:13:11 +00:00
}
2020-03-26 19:45:07 +00:00
$subpage = array ();
$subpage [ 'slug' ] = $slug ;
2016-04-27 21:54:28 +02:00
$subpage [ 'title' ] = $page [ 'title' ];
2020-03-26 14:05:04 +00:00
$subpage [ 'page' ] = 'mainwp-' . str_replace ( ' ' , '-' , strtolower ( str_replace ( '-' , ' ' , $slug ) ) );
2016-04-28 20:22:43 +02:00
if ( isset ( $page [ 'callback' ] ) ) {
2020-03-26 17:03:00 +00:00
$subpage [ 'callback' ] = $page [ 'callback' ];
2020-03-26 19:45:07 +00:00
$created_page = add_submenu_page ( 'options-general.php' , $subpage [ 'title' ], '<div class="mainwp-hidden">' . $subpage [ 'title' ] . '</div>' , 'manage_options' , $subpage [ 'page' ], $subpage [ 'callback' ] );
2016-04-28 20:22:43 +02:00
if ( isset ( $page [ 'load_callback' ] ) ) {
2020-03-26 17:03:00 +00:00
$subpage [ 'load_callback' ] = $page [ 'load_callback' ];
2016-04-27 21:54:28 +02:00
add_action ( 'load-' . $created_page , $subpage [ 'load_callback' ] );
}
}
$sub_pages [] = $subpage ;
}
2020-03-26 19:45:07 +00:00
self :: $subPages = $sub_pages ;
2016-04-27 21:54:28 +02:00
self :: $subPagesLoaded = true ;
}
add_action ( 'mainwp-child-pageheader' , array ( __CLASS__ , 'render_header' ) );
add_action ( 'mainwp-child-pagefooter' , array ( __CLASS__ , 'render_footer' ) );
global $submenu ;
if ( isset ( $submenu [ 'options-general.php' ] ) ) {
foreach ( $submenu [ 'options-general.php' ] as $index => $item ) {
2020-03-27 13:05:05 +00:00
if ( 'mainwp-reports-page' === $item [ 2 ] || 'mainwp-reports-settings' === $item [ 2 ] ) {
2016-04-27 21:54:28 +02:00
unset ( $submenu [ 'options-general.php' ][ $index ] );
2015-10-15 22:52:37 +10:00
}
}
}
}
2016-04-27 21:54:28 +02:00
}
2015-10-15 22:52:37 +10:00
2020-04-07 19:04:20 +02:00
public function render_pages ( $shownPage ) {
2020-03-27 15:13:11 +00:00
$shownPage = '' ;
2020-04-07 16:53:05 +02:00
if ( isset ( $_GET [ 'tab' ] ) ) {
2016-04-27 21:54:28 +02:00
$shownPage = $_GET [ 'tab' ];
}
2020-05-06 20:22:11 +07:00
$branding_opts = MainWP_Child_Branding :: instance () -> get_branding_options ();
2016-04-27 21:54:28 +02:00
2020-03-26 19:45:07 +00:00
$hide_settings = isset ( $branding_opts [ 'remove_setting' ] ) && $branding_opts [ 'remove_setting' ] ? true : false ;
$hide_restore = isset ( $branding_opts [ 'remove_restore' ] ) && $branding_opts [ 'remove_restore' ] ? true : false ;
$hide_server_info = isset ( $branding_opts [ 'remove_server_info' ] ) && $branding_opts [ 'remove_server_info' ] ? true : false ;
2020-03-27 15:13:11 +00:00
$hide_connection_detail = isset ( $branding_opts [ 'remove_connection_detail' ] ) && $branding_opts [ 'remove_connection_detail' ] ? true : false ;
2016-04-27 21:54:28 +02:00
$hide_style = 'style="display:none"' ;
2020-04-07 18:33:47 +02:00
if ( '' == $shownPage ) {
2020-03-27 15:13:11 +00:00
if ( ! $hide_settings ) {
$shownPage = 'settings' ;
} elseif ( ! $hide_restore ) {
$shownPage = 'restore-clone' ;
} elseif ( ! $hide_server_info ) {
$shownPage = 'server-info' ;
} elseif ( ! $hide_connection_detail ) {
$shownPage = 'connection-detail' ;
}
}
2017-05-11 21:07:42 +02:00
2020-04-07 16:53:05 +02:00
self :: render_header ( $shownPage , false );
2016-04-27 21:54:28 +02:00
?>
2020-03-26 17:03:00 +00:00
< ? php if ( ! $hide_settings ) { ?>
< div class = " mainwp-child-setting-tab settings " < ? php echo ( 'settings' !== $shownPage ) ? $hide_style : '' ; ?> >
2016-05-09 19:34:51 +02:00
< ? php $this -> settings (); ?>
</ div >
2016-04-27 21:54:28 +02:00
< ? php } ?>
2020-03-26 17:03:00 +00:00
< ? php if ( ! $hide_restore ) { ?>
2016-04-28 19:06:52 +02:00
< div class = " mainwp-child-setting-tab restore-clone " < ? php echo ( 'restore-clone' !== $shownPage ) ? $hide_style : '' ; ?> >
2016-05-09 19:34:51 +02:00
< ? php
if ( '' === session_id () ) {
2020-04-23 19:16:35 +02:00
session_start ();
2016-05-09 19:34:51 +02:00
}
2016-04-28 19:06:52 +02:00
2016-05-09 19:34:51 +02:00
if ( isset ( $_SESSION [ 'file' ] ) ) {
2020-05-06 20:22:11 +07:00
MainWP_Clone :: render_restore ();
2016-04-28 19:06:52 +02:00
} else {
2016-05-09 19:34:51 +02:00
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
if ( 0 !== ( int ) $sitesToClone ) {
MainWP_Clone :: render ();
} else {
2020-05-06 20:22:11 +07:00
MainWP_Clone :: render_normal_restore ();
2016-05-09 19:34:51 +02:00
}
2016-04-28 19:06:52 +02:00
}
2016-05-09 19:34:51 +02:00
?>
</ div >
2016-04-27 21:54:28 +02:00
< ? php } ?>
2020-03-27 13:05:05 +00:00
< ? php if ( ! $hide_server_info ) { ?>
2020-03-26 17:03:00 +00:00
< div class = " mainwp-child-setting-tab server-info " < ? php echo ( 'server-info' !== $shownPage ) ? $hide_style : '' ; ?> >
2020-05-06 20:22:11 +07:00
< ? php MainWP_Child_Server_Information :: render_page (); ?>
2016-05-09 19:34:51 +02:00
</ div >
2016-04-27 21:54:28 +02:00
< ? php } ?>
2016-10-24 20:33:37 +02:00
2020-03-27 15:13:11 +00:00
< ? php if ( ! $hide_connection_detail ) { ?>
2020-03-26 17:03:00 +00:00
< div class = " mainwp-child-setting-tab connection-detail " < ? php echo ( 'connection-detail' !== $shownPage ) ? $hide_style : '' ; ?> >
2020-05-06 20:22:11 +07:00
< ? php MainWP_Child_Server_Information :: render_connection_details (); ?>
2016-10-24 20:33:37 +02:00
</ div >
< ? php } ?>
2016-04-27 21:54:28 +02:00
< ? php
self :: render_footer ();
}
2020-03-27 13:05:05 +00:00
public static function render_header ( $shownPage , $subpage = true ) {
2020-04-07 16:53:05 +02:00
if ( isset ( $_GET [ 'tab' ] ) ) {
2016-04-27 21:54:28 +02:00
$shownPage = $_GET [ 'tab' ];
}
2020-04-07 16:53:05 +02:00
if ( empty ( $shownPage ) ) {
2016-04-27 21:54:28 +02:00
$shownPage = 'settings' ;
2020-03-27 15:13:11 +00:00
}
2016-04-27 21:54:28 +02:00
2020-05-06 20:22:11 +07:00
$branding_opts = MainWP_Child_Branding :: instance () -> get_branding_options ();
2019-02-14 22:38:14 +07:00
2020-03-26 19:45:07 +00:00
$hide_settings = isset ( $branding_opts [ 'remove_setting' ] ) && $branding_opts [ 'remove_setting' ] ? true : false ;
$hide_restore = isset ( $branding_opts [ 'remove_restore' ] ) && $branding_opts [ 'remove_restore' ] ? true : false ;
$hide_server_info = isset ( $branding_opts [ 'remove_server_info' ] ) && $branding_opts [ 'remove_server_info' ] ? true : false ;
2020-03-27 15:13:11 +00:00
$hide_connection_detail = isset ( $branding_opts [ 'remove_connection_detail' ] ) && $branding_opts [ 'remove_connection_detail' ] ? true : false ;
2016-04-27 21:54:28 +02:00
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
?>
< style type = " text/css " >
. mainwp - tabs
{
margin - top : 2 em ;
border - bottom : 1 px solid #e5e5e5;
2015-10-15 22:52:37 +10:00
}
2016-04-27 21:54:28 +02:00
#mainwp-tabs {
clear : both ;
}
#mainwp-tabs .nav-tab-active {
background : #fafafa ;
border - top : 1 px solid #7fb100 !important;
border - left : 1 px solid #e5e5e5;
border - right : 1 px solid #e5e5e5;
border - bottom : 1 px solid #fafafa !important ;
color : #7fb100;
}
2015-10-15 22:52:37 +10:00
2016-04-27 21:54:28 +02:00
#mainwp-tabs .nav-tab {
border - top : 1 px solid #e5e5e5;
border - left : 1 px solid #e5e5e5;
border - right : 1 px solid #e5e5e5;
border - bottom : 1 px solid #e5e5e5;
padding : 10 px 16 px ;
font - size : 14 px ;
text - transform : uppercase ;
2015-10-15 22:52:37 +10:00
}
2016-04-27 21:54:28 +02:00
#mainwp_wrap-inside {
min - height : 80 vh ;
height : 100 % ;
margin - top : 0 em ;
padding : 10 px ;
background : #fafafa ;
border - top : none ;
border - bottom : 1 px solid #e5e5e5;
border - left : 1 px solid #e5e5e5;
border - right : 1 px solid #e5e5e5;
box - shadow : 0 1 px 1 px rgba ( 0 , 0 , 0 , . 04 );
position : relative ;
2015-10-15 22:52:37 +10:00
}
2016-04-27 21:54:28 +02:00
#mainwp_wrap-inside h2.hndle {
font - size : 14 px ;
padding : 8 px 12 px ;
margin : 0 ;
line - height : 1.4 ;
2015-10-15 22:52:37 +10:00
}
2016-04-27 21:54:28 +02:00
. mainwp - hidden {
display : none ;
}
</ style >
< div class = " wrap " >
2020-04-07 18:33:47 +02:00
< h2 >< i class = " fa fa-file " ></ i > < ? php echo ( null === self :: $brandingTitle ? 'MainWP Child' : self :: $brandingTitle ); ?> </h2>
2016-05-09 19:34:51 +02:00
< div style = " clear: both; " ></ div >< br />
< div class = " mainwp-tabs " id = " mainwp-tabs " >
2020-03-26 17:03:00 +00:00
< ? php if ( ! $hide_settings ) { ?>
2020-04-07 16:53:05 +02:00
< a class = " nav-tab pos-nav-tab
2020-03-27 15:13:11 +00:00
< ? php
2020-04-07 18:33:47 +02:00
if ( 'settings' === $shownPage ) {
2020-03-26 19:51:58 +00:00
echo 'nav-tab-active' ; }
?>
2020-03-26 17:03:00 +00:00
" tab-slug= " settings " href= " < ? php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=settings' : '#' ; ?> " style="margin-left: 0 !important;"><?php _e( 'Settings', 'mainwp-child' ); ?></a>
2016-05-09 19:34:51 +02:00
< ? php } ?>
2020-03-26 17:03:00 +00:00
< ? php if ( ! $hide_restore ) { ?>
2020-04-07 16:53:05 +02:00
< a class = " nav-tab pos-nav-tab
2020-03-27 15:13:11 +00:00
< ? php
2020-04-07 18:33:47 +02:00
if ( 'restore-clone' === $shownPage ) {
2020-03-26 19:51:58 +00:00
echo 'nav-tab-active' ; }
?>
2020-03-26 17:03:00 +00:00
" tab-slug= " restore - clone " href= " < ? php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=restore-clone' : '#' ; ?> "><?php echo ( 0 !== (int) $sitesToClone ) ? __( 'Restore / Clone', 'mainwp-child' ) : __( 'Restore', 'mainwp-child' ); ?></a>
2016-05-09 19:34:51 +02:00
< ? php } ?>
2020-03-26 17:03:00 +00:00
< ? php if ( ! $hide_server_info ) { ?>
2020-04-07 16:53:05 +02:00
< a class = " nav-tab pos-nav-tab
2020-03-27 15:13:11 +00:00
< ? php
2020-04-07 18:33:47 +02:00
if ( 'server-info' === $shownPage ) {
2020-03-26 19:51:58 +00:00
echo 'nav-tab-active' ; }
?>
2020-03-26 17:03:00 +00:00
" tab-slug= " server - info " href= " < ? php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=server-info' : '#' ; ?> "><?php _e( 'Server information', 'mainwp-child' ); ?></a>
2016-05-09 19:34:51 +02:00
< ? php } ?>
2020-03-27 15:13:11 +00:00
< ? php if ( ! $hide_connection_detail ) { ?>
2020-04-07 16:53:05 +02:00
< a class = " nav-tab pos-nav-tab
2020-03-26 19:51:58 +00:00
< ? php
2020-04-07 18:33:47 +02:00
if ( 'connection-detail' === $shownPage ) {
2020-03-26 19:51:58 +00:00
echo 'nav-tab-active' ; }
?>
2020-03-26 17:03:00 +00:00
" tab-slug= " connection - detail " href= " < ? php echo $subpage ? 'options-general.php?page=mainwp_child_tab&tab=connection-detail' : '#' ; ?> "><?php _e( 'Connection Details', 'mainwp-child' ); ?></a>
2016-10-24 20:33:37 +02:00
< ? php } ?>
2016-05-09 19:34:51 +02:00
< ? php
if ( isset ( self :: $subPages ) && is_array ( self :: $subPages ) ) {
foreach ( self :: $subPages as $subPage ) {
2016-04-27 21:54:28 +02:00
?>
2020-04-07 16:53:05 +02:00
< a class = " nav-tab pos-nav-tab
2020-03-27 15:13:11 +00:00
< ? php
if ( $shownPage == $subPage [ 'slug' ] ) {
2020-03-26 19:51:58 +00:00
echo 'nav-tab-active' ; }
?>
2020-04-07 16:53:05 +02:00
" tab-slug= " < ? php echo esc_attr ( $subPage [ 'slug' ] ); ?> " href="options-general.php?page=<?php echo rawurlencode( $subPage['page'] ); ?>"><?php echo esc_html( $subPage['title'] ); ?></a>
2016-05-09 19:34:51 +02:00
< ? php
}
}
?>
< div style = " clear:both; " ></ div >
</ div >
< div style = " clear:both; " ></ div >
< script type = " text/javascript " >
jQuery ( document ) . ready ( function () {
2020-04-07 16:53:05 +02:00
$hideMenu = jQuery ( '#menu-settings li a .mainwp-hidden' );
$hideMenu . each ( function () {
jQuery ( this ) . closest ( 'li' ) . hide ();
} );
2016-05-09 19:34:51 +02:00
2020-04-07 16:53:05 +02:00
var $tabs = jQuery ( '.mainwp-tabs' );
$tabs . on ( 'click' , 'a' , function () {
if ( jQuery ( this ) . attr ( 'href' ) !== '#' )
2016-05-09 19:34:51 +02:00
return true ;
2020-04-07 16:53:05 +02:00
jQuery ( '.mainwp-tabs > a' ) . removeClass ( 'nav-tab-active' );
jQuery ( this ) . addClass ( 'nav-tab-active' );
jQuery ( '.mainwp-child-setting-tab' ) . hide ();
var _tab = jQuery ( this ) . attr ( 'tab-slug' );
jQuery ( '.mainwp-child-setting-tab.' + _tab ) . show ();
2016-05-09 19:34:51 +02:00
return false ;
2020-04-07 16:53:05 +02:00
} );
} );
2016-05-09 19:34:51 +02:00
</ script >
< div id = " mainwp_wrap-inside " >
2016-04-27 21:54:28 +02:00
< ? php
}
public static function render_footer () {
?>
2016-05-09 19:34:51 +02:00
</ div >
2016-04-27 21:54:28 +02:00
</ div >
< ? php
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function admin_init () {
2020-05-06 00:47:59 +07:00
if ( MainWP_Helper :: is_admin () && is_admin () ) {
2016-12-09 08:44:15 +01:00
MainWP_Clone :: get () -> init_ajax ();
}
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function admin_head () {
2020-04-07 18:33:47 +02:00
if ( isset ( $_GET [ 'page' ] ) && 'mainwp_child_tab' == $_GET [ 'page' ] ) {
2020-03-27 15:13:11 +00:00
?>
< style type = " text/css " >
. mainwp - postbox - actions - top {
padding : 10 px ;
clear : both ;
border - bottom : 1 px solid #ddd;
background : #f5f5f5;
}
h3 . mainwp_box_title {
font - family : " Open Sans " , sans - serif ;
font - size : 14 px ;
font - weight : 600 ;
line - height : 1.4 ;
margin : 0 ;
padding : 8 px 12 px ;
border - bottom : 1 px solid #eee;
}
. mainwp - child - setting - tab . connection - detail . postbox . inside {
margin : 0 ;
padding : 0 ;
}
</ style >
< ? php
}
2016-10-24 20:33:37 +02:00
}
2020-04-07 19:04:20 +02:00
public function settings () {
2015-12-05 17:38:52 +01:00
if ( isset ( $_POST [ 'submit' ] ) && isset ( $_POST [ 'nonce' ] ) && wp_verify_nonce ( $_POST [ 'nonce' ], 'child-settings' ) ) {
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'requireUniqueSecurityId' ] ) ) {
2020-05-06 00:47:59 +07:00
MainWP_Helper :: update_option ( 'mainwp_child_uniqueId' , MainWP_Helper :: rand_string ( 8 ) );
2015-10-15 22:52:37 +10:00
} else {
MainWP_Helper :: update_option ( 'mainwp_child_uniqueId' , '' );
}
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
?>
2016-04-27 21:54:28 +02:00
< div class = " postbox " >
2016-10-24 20:33:37 +02:00
< h2 class = " hndle " >< span >< ? php esc_html_e ( 'Connection settings' , 'mainwp-child' ); ?> </span></h2>
2016-04-27 21:54:28 +02:00
< div class = " inside " >
< form method = " post " action = " options-general.php?page=mainwp_child_tab " >
2016-10-24 20:33:37 +02:00
< div class = " howto " >< ? php esc_html_e ( 'The unique security ID adds additional protection between the child plugin and your Dashboard. The unique security ID will need to match when being added to the Dashboard. This is additional security and should not be needed in most situations.' , 'mainwp-child' ); ?> </div>
2016-04-27 21:54:28 +02:00
< div style = " margin: 1em 0 4em 0; " >
2020-04-07 19:32:01 +02:00
< input name = " requireUniqueSecurityId " type = " checkbox " id = " requireUniqueSecurityId "
< ? php
if ( '' != get_option ( 'mainwp_child_uniqueId' ) ) {
echo 'checked' ; }
?>
/>
< label for = " requireUniqueSecurityId " style = " font-size: 15px; " >< ? php esc_html_e ( 'Require unique security ID' , 'mainwp-child' ); ?> </label>
2016-04-27 21:54:28 +02:00
</ div >
< div >
2020-03-26 14:05:04 +00:00
< ? php
2020-03-27 15:13:11 +00:00
if ( '' != get_option ( 'mainwp_child_uniqueId' ) ) {
2016-10-24 20:33:37 +02:00
echo '<span style="border: 1px dashed #e5e5e5; background: #fafafa; font-size: 24px; padding: 1em 2em;">' . esc_html__ ( 'Your unique security ID is:' , 'mainwp-child' ) . ' <span style="font-weight: bold; color: #7fb100;">' . esc_html ( get_option ( 'mainwp_child_uniqueId' ) ) . '</span></span>' ;
2020-03-26 14:05:04 +00:00
}
2020-03-27 15:13:11 +00:00
?>
2016-04-27 21:54:28 +02:00
</ div >
< p class = " submit " style = " margin-top: 4em; " >
2020-04-07 19:32:01 +02:00
< input type = " submit " name = " submit " id = " submit " class = " button button-primary button-hero " value = " <?php esc_attr_e( 'Save changes', 'mainwp-child' ); ?> " >
2016-04-27 21:54:28 +02:00
</ p >
2020-03-26 14:05:04 +00:00
< input type = " hidden " name = " nonce " value = " <?php echo wp_create_nonce( 'child-settings' ); ?> " >
2016-04-27 21:54:28 +02:00
</ form >
2015-10-15 22:52:37 +10:00
</ div >
</ div >
2016-04-27 21:54:28 +02:00
2015-10-15 22:52:37 +10:00
< ? php
}
2020-04-07 19:04:20 +02:00
public function mod_rewrite_rules ( $pRules ) {
2015-10-15 22:52:37 +10:00
2020-04-22 18:37:14 +02:00
$home_root = wp_parse_url ( home_url () );
2015-10-15 22:52:37 +10:00
if ( isset ( $home_root [ 'path' ] ) ) {
$home_root = trailingslashit ( $home_root [ 'path' ] );
} else {
$home_root = '/' ;
}
2020-03-26 19:45:07 +00:00
$rules = " <IfModule mod_rewrite.c> \n " ;
2015-10-15 22:52:37 +10:00
$rules .= " RewriteEngine On \n " ;
$rules .= " RewriteBase $home_root\n " ;
2020-04-07 18:33:47 +02:00
// add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all).
2015-10-15 22:52:37 +10:00
foreach ( $pRules as $match => $query ) {
// Apache 1.3 does not support the reluctant (non-greedy) modifier.
$match = str_replace ( '.+?' , '.+' , $match );
$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L] \n " ;
}
$rules .= " </IfModule> \n " ;
return $rules ;
}
2020-04-07 19:04:20 +02:00
public function update_htaccess ( $hard = false ) {
2020-03-26 17:03:00 +00:00
if ( ! $hard && defined ( 'DOING_CRON' ) && DOING_CRON ) {
2015-10-15 22:52:37 +10:00
return ;
}
2020-03-27 15:13:11 +00:00
if ( $hard ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
2015-10-15 22:52:37 +10:00
$home_path = ABSPATH ;
$htaccess_file = $home_path . '.htaccess' ;
if ( function_exists ( 'save_mod_rewrite_rules' ) ) {
$rules = explode ( " \n " , '' );
insert_with_markers ( $htaccess_file , 'MainWP' , $rules );
}
}
}
2020-04-07 19:04:20 +02:00
public function check_login () {
2020-05-04 23:02:02 +07:00
if ( ! isset ( $_POST [ 'mainwpsignature' ] ) || empty ( $_POST [ 'mainwpsignature' ] ) ) {
2020-05-01 00:05:03 +07:00
return false ;
2020-05-04 23:02:02 +07:00
}
2020-03-26 19:45:07 +00:00
$file = '' ;
2016-04-28 19:06:52 +02:00
if ( isset ( $_REQUEST [ 'f' ] ) ) {
$file = $_REQUEST [ 'f' ];
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_REQUEST [ 'file' ] ) ) {
2016-04-28 19:06:52 +02:00
$file = $_REQUEST [ 'file' ];
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_REQUEST [ 'fdl' ] ) ) {
2016-04-28 19:06:52 +02:00
$file = $_REQUEST [ 'fdl' ];
}
$auth = $this -> auth ( isset ( $_POST [ 'mainwpsignature' ] ) ? rawurldecode ( $_POST [ 'mainwpsignature' ] ) : '' , isset ( $_POST [ 'function' ] ) ? $_POST [ 'function' ] : rawurldecode ( ( isset ( $_REQUEST [ 'where' ] ) ? $_REQUEST [ 'where' ] : $file ) ), isset ( $_POST [ 'nonce' ] ) ? $_POST [ 'nonce' ] : '' , isset ( $_POST [ 'nossl' ] ) ? $_POST [ 'nossl' ] : 0 );
2016-04-27 19:25:53 +02:00
if ( ! $auth && isset ( $_POST [ 'mainwpsignature' ] ) ) {
MainWP_Helper :: error ( __ ( 'Authentication failed! Please deactivate and re-activate the MainWP Child plugin on this site.' , 'mainwp-child' ) );
}
if ( ! $auth && isset ( $_POST [ 'function' ] ) && isset ( $this -> callableFunctions [ $_POST [ 'function' ] ] ) && ! isset ( $this -> callableFunctionsNoAuth [ $_POST [ 'function' ] ] ) ) {
MainWP_Helper :: error ( __ ( 'Authentication failed! Please deactivate and re-activate the MainWP Child plugin on this site.' , 'mainwp-child' ) );
}
2020-03-27 15:13:11 +00:00
$auth_user = false ;
2016-04-27 19:25:53 +02:00
if ( $auth ) {
2020-04-07 17:12:41 +02:00
// disable duo auth for mainwp.
2020-04-07 16:53:05 +02:00
remove_action ( 'init' , 'duo_verify_auth' , 10 );
2016-08-02 19:23:13 +02:00
2020-04-07 17:12:41 +02:00
// Check if the user exists & is an administrator.
2016-04-27 19:25:53 +02:00
if ( isset ( $_POST [ 'function' ] ) && isset ( $_POST [ 'user' ] ) ) {
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$user = null ;
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( isset ( $_POST [ 'alt_user' ] ) && ! empty ( $_POST [ 'alt_user' ] ) ) {
if ( $this -> check_login_as ( $_POST [ 'alt_user' ] ) ) {
$auth_user = $_POST [ 'alt_user' ];
$user = get_user_by ( 'login' , $auth_user );
}
}
2019-02-14 22:38:14 +07:00
2020-04-07 17:12:41 +02:00
// if not valid alternative admin.
2020-03-27 15:13:11 +00:00
if ( ! $user ) {
2020-04-07 17:12:41 +02:00
// check connected admin existed.
2020-03-27 15:13:11 +00:00
$user = get_user_by ( 'login' , $_POST [ 'user' ] );
$auth_user = $_POST [ 'user' ];
}
2019-02-14 22:38:14 +07:00
2016-04-27 19:25:53 +02:00
if ( ! $user ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'That administrator username was not found on this child site. Please verify that it is an existing administrator.' , 'mainwp-child' ) );
2016-04-27 19:25:53 +02:00
}
if ( 10 != $user -> wp_user_level && ( ! isset ( $user -> user_level ) || 10 != $user -> user_level ) && ! $user -> has_cap ( 'level_10' ) ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'That user is not an administrator. Please use an administrator user to establish the connection.' , 'mainwp-child' ) );
2016-04-27 19:25:53 +02:00
}
2019-02-14 22:38:14 +07:00
$this -> login ( $auth_user );
2016-04-27 19:25:53 +02:00
}
if ( isset ( $_POST [ 'function' ] ) && 'visitPermalink' === $_POST [ 'function' ] ) {
2019-02-14 22:38:14 +07:00
2020-04-07 16:53:05 +02:00
if ( empty ( $auth_user ) ) {
2020-03-27 15:13:11 +00:00
$auth_user = $_POST [ 'user' ];
}
2019-02-14 22:38:14 +07:00
if ( $this -> login ( $auth_user , true ) ) {
2016-04-27 19:25:53 +02:00
return ;
} else {
exit ();
}
}
2020-04-07 16:53:05 +02:00
// Redirect to the admin part if needed.
2016-04-27 19:25:53 +02:00
if ( isset ( $_POST [ 'admin' ] ) && '1' === $_POST [ 'admin' ] ) {
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( get_option ( 'siteurl' ) . '/wp-admin/' );
2016-04-27 19:25:53 +02:00
die ();
}
}
}
2020-04-07 19:04:20 +02:00
public function parse_init () {
2015-10-15 22:52:37 +10:00
if ( isset ( $_REQUEST [ 'cloneFunc' ] ) ) {
if ( ! isset ( $_REQUEST [ 'key' ] ) ) {
return ;
}
if ( ! isset ( $_REQUEST [ 'f' ] ) || ( '' === $_REQUEST [ 'f' ] ) ) {
return ;
}
2020-05-06 00:47:59 +07:00
if ( ! $this -> is_valid_auth ( $_REQUEST [ 'key' ] ) ) {
2015-10-15 22:52:37 +10:00
return ;
}
if ( 'dl' === $_REQUEST [ 'cloneFunc' ] ) {
2020-05-06 00:47:59 +07:00
$this -> upload_file ( $_REQUEST [ 'f' ] );
2015-10-15 22:52:37 +10:00
exit ;
2020-03-26 14:11:33 +00:00
} elseif ( 'deleteCloneBackup' === $_POST [ 'cloneFunc' ] ) {
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
$result = glob ( $backupdir . $_POST [ 'f' ] );
if ( 0 === count ( $result ) ) {
return ;
}
2020-04-23 19:16:35 +02:00
unlink ( $result [ 0 ] );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( array ( 'result' => 'ok' ) );
2020-03-26 14:11:33 +00:00
} elseif ( 'createCloneBackupPoll' === $_POST [ 'cloneFunc' ] ) {
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
$result = glob ( $backupdir . 'backup-' . $_POST [ 'f' ] . '-*' );
$archiveFile = false ;
foreach ( $result as $file ) {
2020-05-06 00:47:59 +07:00
if ( MainWP_Helper :: is_archive ( $file , 'backup-' . $_POST [ 'f' ] . '-' ) ) {
2015-10-15 22:52:37 +10:00
$archiveFile = $file ;
break ;
}
}
if ( false === $archiveFile ) {
return ;
}
MainWP_Helper :: write ( array ( 'size' => filesize ( $archiveFile ) ) );
2020-03-26 14:11:33 +00:00
} elseif ( 'createCloneBackup' === $_POST [ 'cloneFunc' ] ) {
2020-05-06 00:47:59 +07:00
MainWP_Helper :: end_session ();
2015-12-22 19:18:07 +01:00
$files = glob ( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) {
2020-04-23 19:16:35 +02:00
unlink ( $file );
2015-10-15 22:52:37 +10:00
}
if ( file_exists ( ABSPATH . 'clone/config.txt' ) ) {
2020-04-23 19:16:35 +02:00
unlink ( ABSPATH . 'clone/config.txt' );
2015-10-15 22:52:37 +10:00
}
if ( MainWP_Helper :: is_dir_empty ( ABSPATH . 'clone' ) ) {
2020-04-23 19:16:35 +02:00
rmdir ( ABSPATH . 'clone' );
2015-10-15 22:52:37 +10:00
}
$wpversion = $_POST [ 'wpversion' ];
global $wp_version ;
$includeCoreFiles = ( $wpversion !== $wp_version );
$excludes = ( isset ( $_POST [ 'exclude' ] ) ? explode ( ',' , $_POST [ 'exclude' ] ) : array () );
$excludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/uploads/mainwp' ;
2020-05-06 00:47:59 +07:00
$uploadDir = MainWP_Helper :: get_mainwp_dir ();
2015-10-15 22:52:37 +10:00
$uploadDir = $uploadDir [ 0 ];
$excludes [] = str_replace ( ABSPATH , '' , $uploadDir );
$excludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/object-cache.php' ;
2020-04-07 18:33:47 +02:00
if ( version_compare ( phpversion (), '5.3.0' ) >= 0 || ! ini_get ( 'safe_mode' ) ) {
2020-04-23 19:16:35 +02:00
set_time_limit ( 6000 );
2015-10-15 22:52:37 +10:00
}
$newExcludes = array ();
foreach ( $excludes as $exclude ) {
$newExcludes [] = rtrim ( $exclude , '/' );
}
$method = ( ! isset ( $_POST [ 'zipmethod' ] ) ? 'tar.gz' : $_POST [ 'zipmethod' ] );
if ( 'tar.gz' === $method && ! function_exists ( 'gzopen' ) ) {
$method = 'zip' ;
}
2020-05-06 20:22:11 +07:00
$res = MainWP_Backup :: get () -> create_full_backup ( $newExcludes , ( isset ( $_POST [ 'f' ] ) ? $_POST [ 'f' ] : $_POST [ 'file' ] ), true , $includeCoreFiles , 0 , false , false , false , false , $method );
2015-10-15 22:52:37 +10:00
if ( ! $res ) {
$information [ 'backup' ] = false ;
} else {
$information [ 'backup' ] = $res [ 'file' ];
$information [ 'size' ] = $res [ 'filesize' ];
}
$plugins = array ();
$dir = WP_CONTENT_DIR . '/plugins/' ;
2020-04-23 19:16:35 +02:00
$fh = opendir ( $dir );
$entry = readdir ( $fh );
while ( $entry ) {
2015-10-15 22:52:37 +10:00
if ( ! is_dir ( $dir . $entry ) ) {
continue ;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue ;
}
$plugins [] = $entry ;
}
2020-04-23 19:16:35 +02:00
closedir ( $fh );
2015-10-15 22:52:37 +10:00
$information [ 'plugins' ] = $plugins ;
$themes = array ();
$dir = WP_CONTENT_DIR . '/themes/' ;
2020-04-23 19:16:35 +02:00
$fh = opendir ( $dir );
while ( $entry = readdir ( $fh ) ) {
2015-10-15 22:52:37 +10:00
if ( ! is_dir ( $dir . $entry ) ) {
continue ;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue ;
}
$themes [] = $entry ;
}
2020-04-23 19:16:35 +02:00
closedir ( $fh );
2015-10-15 22:52:37 +10:00
$information [ 'themes' ] = $themes ;
MainWP_Helper :: write ( $information );
}
}
global $wp_rewrite ;
$snPluginDir = basename ( $this -> plugin_dir );
if ( isset ( $wp_rewrite -> non_wp_rules [ 'wp-content/plugins/' . $snPluginDir . '/([^js\/]*)$' ] ) ) {
unset ( $wp_rewrite -> non_wp_rules [ 'wp-content/plugins/' . $snPluginDir . '/([^js\/]*)$' ] );
}
if ( isset ( $wp_rewrite -> non_wp_rules [ 'wp-content/plugins/' . $snPluginDir . '/(.*)$' ] ) ) {
unset ( $wp_rewrite -> non_wp_rules [ 'wp-content/plugins/' . $snPluginDir . '/(.*)$' ] );
}
if ( get_option ( 'mainwp_child_fix_htaccess' ) === false ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
2015-10-15 22:52:37 +10:00
$wp_rewrite -> flush_rules ();
MainWP_Helper :: update_option ( 'mainwp_child_fix_htaccess' , 'yes' , 'yes' );
}
$this -> update_htaccess ();
2020-04-07 16:53:05 +02:00
global $current_user ;
2015-12-06 19:05:27 +01:00
if ( isset ( $_REQUEST [ 'login_required' ] ) && ( '1' === $_REQUEST [ 'login_required' ] ) && isset ( $_REQUEST [ 'user' ] ) ) {
2020-03-27 15:13:11 +00:00
$alter_login_required = false ;
$username = rawurldecode ( $_REQUEST [ 'user' ] );
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( isset ( $_REQUEST [ 'alt_user' ] ) && ! empty ( $_REQUEST [ 'alt_user' ] ) ) {
$alter_login_required = $this -> check_login_as ( $_REQUEST [ 'alt_user' ] );
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( $alter_login_required ) {
$username = rawurldecode ( $_REQUEST [ 'alt_user' ] );
}
}
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
if ( is_user_logged_in () ) {
global $current_user ;
if ( 10 !== $current_user -> wp_user_level && ( ! isset ( $current_user -> user_level ) || 10 !== $current_user -> user_level ) && ! current_user_can ( 'level_10' ) ) {
do_action ( 'wp_logout' );
}
}
$signature = rawurldecode ( isset ( $_REQUEST [ 'mainwpsignature' ] ) ? $_REQUEST [ 'mainwpsignature' ] : '' );
$file = '' ;
if ( isset ( $_REQUEST [ 'f' ] ) ) {
$file = $_REQUEST [ 'f' ];
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_REQUEST [ 'file' ] ) ) {
2015-10-15 22:52:37 +10:00
$file = $_REQUEST [ 'file' ];
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_REQUEST [ 'fdl' ] ) ) {
2015-10-15 22:52:37 +10:00
$file = $_REQUEST [ 'fdl' ];
}
$auth = $this -> auth ( $signature , rawurldecode ( ( isset ( $_REQUEST [ 'where' ] ) ? $_REQUEST [ 'where' ] : $file ) ), isset ( $_REQUEST [ 'nonce' ] ) ? $_REQUEST [ 'nonce' ] : '' , isset ( $_REQUEST [ 'nossl' ] ) ? $_REQUEST [ 'nossl' ] : 0 );
if ( ! $auth ) {
return ;
}
if ( ! is_user_logged_in () || $username !== $current_user -> user_login ) {
if ( ! $this -> login ( $username ) ) {
return ;
}
global $current_user ;
if ( 10 !== $current_user -> wp_user_level && ( ! isset ( $current_user -> user_level ) || 10 !== $current_user -> user_level ) && ! current_user_can ( 'level_10' ) ) {
2020-04-07 18:33:47 +02:00
// if is not alternative admin login.
// it is connected admin login.
2020-03-27 15:13:11 +00:00
if ( ! $alter_login_required ) {
2020-04-07 18:33:47 +02:00
// log out if connected admin is not admin level 10.
2020-03-27 15:13:11 +00:00
do_action ( 'wp_logout' );
2015-10-15 22:52:37 +10:00
2020-03-27 15:13:11 +00:00
return ;
}
2015-10-15 22:52:37 +10:00
}
}
if ( isset ( $_REQUEST [ 'fdl' ] ) ) {
if ( stristr ( $_REQUEST [ 'fdl' ], '..' ) ) {
return ;
}
2020-05-06 00:47:59 +07:00
$this -> upload_file ( $_REQUEST [ 'fdl' ], isset ( $_REQUEST [ 'foffset' ] ) ? $_REQUEST [ 'foffset' ] : 0 );
2015-10-15 22:52:37 +10:00
exit ;
}
$where = isset ( $_REQUEST [ 'where' ] ) ? $_REQUEST [ 'where' ] : '' ;
if ( isset ( $_POST [ 'f' ] ) || isset ( $_POST [ 'file' ] ) ) {
$file = '' ;
if ( isset ( $_POST [ 'f' ] ) ) {
$file = $_POST [ 'f' ];
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_POST [ 'file' ] ) ) {
2015-10-15 22:52:37 +10:00
$file = $_POST [ 'file' ];
}
2016-04-28 19:06:52 +02:00
$where = 'admin.php?page=mainwp_child_tab&tab=restore-clone' ;
2015-10-15 22:52:37 +10:00
if ( '' === session_id () ) {
session_start ();
}
$_SESSION [ 'file' ] = $file ;
$_SESSION [ 'size' ] = $_POST [ 'size' ];
}
2020-04-07 18:33:47 +02:00
// to support open not wp-admin url.
2015-10-15 22:52:37 +10:00
$open_location = isset ( $_REQUEST [ 'open_location' ] ) ? $_REQUEST [ 'open_location' ] : '' ;
if ( ! empty ( $open_location ) ) {
2020-04-07 19:32:01 +02:00
$open_location = base64_decode ( $open_location ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$_vars = MainWP_Helper :: parse_query ( $open_location );
2020-04-22 18:37:14 +02:00
$_path = wp_parse_url ( $open_location , PHP_URL_PATH );
2015-10-15 22:52:37 +10:00
if ( isset ( $_vars [ '_mwpNoneName' ] ) && isset ( $_vars [ '_mwpNoneValue' ] ) ) {
$_vars [ $_vars [ '_mwpNoneName' ] ] = wp_create_nonce ( $_vars [ '_mwpNoneValue' ] );
unset ( $_vars [ '_mwpNoneName' ] );
unset ( $_vars [ '_mwpNoneValue' ] );
$open_url = '' ;
foreach ( $_vars as $key => $value ) {
$open_url .= $key . '=' . $value . '&' ;
}
$open_url = rtrim ( $open_url , '&' );
$open_location = '/wp-admin/' . $_path . '?' . $open_url ;
} else {
if ( strpos ( $open_location , 'nonce=child_temp_nonce' ) !== false ) {
$open_location = str_replace ( 'nonce=child_temp_nonce' , 'nonce=' . wp_create_nonce ( 'wp-ajax' ), $open_location );
}
}
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( site_url () . $open_location );
2015-10-15 22:52:37 +10:00
exit ();
}
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( admin_url ( $where ) );
2015-10-15 22:52:37 +10:00
exit ();
}
/**
* Security
*/
2020-05-06 20:22:11 +07:00
MainWP_Security :: fix_all ();
2020-04-07 16:53:05 +02:00
MainWP_Debug :: process ( $this );
2015-10-15 22:52:37 +10:00
2020-04-07 16:53:05 +02:00
// Register does not require auth, so we register here.
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'function' ] ) && 'register' === $_POST [ 'function' ] ) {
2016-02-17 20:38:44 +01:00
define ( 'DOING_CRON' , true );
2020-03-26 14:05:04 +00:00
self :: fix_for_custom_themes ();
2020-05-06 00:47:59 +07:00
$this -> register_site ();
2015-10-15 22:52:37 +10:00
}
$auth = $this -> auth ( isset ( $_POST [ 'mainwpsignature' ] ) ? $_POST [ 'mainwpsignature' ] : '' , isset ( $_POST [ 'function' ] ) ? $_POST [ 'function' ] : '' , isset ( $_POST [ 'nonce' ] ) ? $_POST [ 'nonce' ] : '' , isset ( $_POST [ 'nossl' ] ) ? $_POST [ 'nossl' ] : 0 );
if ( ! $auth && isset ( $_POST [ 'mainwpsignature' ] ) ) {
2019-11-11 23:17:10 +07:00
MainWP_Helper :: error ( __ ( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this site and try again.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
if ( ! $auth && isset ( $_POST [ 'function' ] ) && isset ( $this -> callableFunctions [ $_POST [ 'function' ] ] ) && ! isset ( $this -> callableFunctionsNoAuth [ $_POST [ 'function' ] ] ) ) {
2019-11-11 23:17:10 +07:00
MainWP_Helper :: error ( __ ( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this site and try again.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
2020-03-27 15:13:11 +00:00
$auth_user = false ;
2015-10-15 22:52:37 +10:00
if ( $auth ) {
2020-04-07 18:33:47 +02:00
// Check if the user exists & is an administrator.
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'function' ] ) && isset ( $_POST [ 'user' ] ) ) {
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$user = null ;
if ( isset ( $_POST [ 'alt_user' ] ) && ! empty ( $_POST [ 'alt_user' ] ) ) {
if ( $this -> check_login_as ( $_POST [ 'alt_user' ] ) ) {
$auth_user = $_POST [ 'alt_user' ];
$user = get_user_by ( 'login' , $auth_user );
}
}
2020-04-07 17:12:41 +02:00
// if alternative admin not existed.
2020-03-27 15:13:11 +00:00
if ( ! $user ) {
2020-04-07 17:12:41 +02:00
// check connected admin existed.
2020-03-27 15:13:11 +00:00
$user = get_user_by ( 'login' , $_POST [ 'user' ] );
$auth_user = $_POST [ 'user' ];
}
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
if ( ! $user ) {
2019-11-11 23:17:10 +07:00
MainWP_Helper :: error ( __ ( 'Unexising administrator username. Please verify that it is an existing administrator.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
2016-04-27 19:25:53 +02:00
if ( 10 != $user -> wp_user_level && ( ! isset ( $user -> user_level ) || 10 != $user -> user_level ) && ! $user -> has_cap ( 'level_10' ) ) {
2019-11-11 23:17:10 +07:00
MainWP_Helper :: error ( __ ( 'Invalid user. Please verify that the user has administrator privileges.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
2019-02-14 22:38:14 +07:00
$this -> login ( $auth_user );
2015-10-15 22:52:37 +10:00
}
if ( isset ( $_POST [ 'function' ] ) && 'visitPermalink' === $_POST [ 'function' ] ) {
2019-02-14 22:38:14 +07:00
2020-04-07 16:53:05 +02:00
if ( empty ( $auth_user ) ) {
2020-03-27 15:13:11 +00:00
$auth_user = $_POST [ 'user' ];
}
2019-02-14 22:38:14 +07:00
if ( $this -> login ( $auth_user , true ) ) {
2015-10-15 22:52:37 +10:00
return ;
} else {
exit ();
}
}
2020-04-07 18:33:47 +02:00
// Redirect to the admin part if needed.
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'admin' ] ) && '1' === $_POST [ 'admin' ] ) {
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( get_option ( 'siteurl' ) . '/wp-admin/' );
2015-10-15 22:52:37 +10:00
die ();
}
}
2020-04-07 18:33:47 +02:00
// Init extensions.
// Handle fatal errors for those init if needed.
2020-05-06 20:22:11 +07:00
MainWP_Child_IThemes_Security :: instance () -> ithemes_init ();
MainWP_Child_Updraft_Plus_Backups :: instance () -> updraftplus_init ();
MainWP_Child_Back_Up_Wordpress :: instance () -> init ();
MainWP_Child_WP_Rocket :: instance () -> init ();
MainWP_Child_Back_WP_Up :: instance () -> init ();
MainWP_Child_Back_Up_Buddy :: instance ();
MainWP_Child_Wordfence :: instance () -> wordfence_init ();
MainWP_Child_Timecapsule :: instance () -> init ();
MainWP_Child_Staging :: instance () -> init ();
MainWP_Child_Branding :: instance () -> branding_init ();
MainWP_Client_Report :: instance () -> creport_init ();
MainWP_Child_Pagespeed :: instance () -> init ();
MainWP_Child_Links_Checker :: instance () -> init ();
MainWP_Child_WPvivid_BackupRestore :: instance () -> init ();
2020-05-05 13:19:34 +00:00
2020-03-27 15:13:11 +00:00
global $_wp_submenu_nopriv ;
2020-04-07 18:33:47 +02:00
if ( null === $_wp_submenu_nopriv ) {
2020-05-05 00:56:15 +07:00
$_wp_submenu_nopriv = array (); // phpcs:ignore -- to fix warning.
2020-03-27 15:13:11 +00:00
}
2016-08-02 19:51:22 +02:00
2020-04-07 17:12:41 +02:00
// Call the function required.
2015-10-15 22:52:37 +10:00
if ( $auth && isset ( $_POST [ 'function' ] ) && isset ( $this -> callableFunctions [ $_POST [ 'function' ] ] ) ) {
2016-02-17 20:38:44 +01:00
define ( 'DOING_CRON' , true );
2018-09-27 19:52:32 +02:00
2020-03-27 15:13:11 +00:00
MainWP_Helper :: handle_fatal_error ();
2020-03-26 14:05:04 +00:00
self :: fix_for_custom_themes ();
2015-10-15 22:52:37 +10:00
call_user_func ( array ( $this , $this -> callableFunctions [ $_POST [ 'function' ] ] ) );
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_POST [ 'function' ] ) && isset ( $this -> callableFunctionsNoAuth [ $_POST [ 'function' ] ] ) ) {
2016-02-17 20:38:44 +01:00
define ( 'DOING_CRON' , true );
2020-03-26 14:05:04 +00:00
self :: fix_for_custom_themes ();
2015-10-15 22:52:37 +10:00
call_user_func ( array ( $this , $this -> callableFunctionsNoAuth [ $_POST [ 'function' ] ] ) );
2020-04-07 16:53:05 +02:00
} elseif ( isset ( $_POST [ 'function' ] ) && isset ( $_POST [ 'mainwpsignature' ] ) && ! isset ( $this -> callableFunctions [ $_POST [ 'function' ] ] ) && ! isset ( $this -> callableFunctionsNoAuth [ $_POST [ 'function' ] ] ) ) {
2020-03-27 15:13:11 +00:00
MainWP_Helper :: error ( __ ( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.' , 'mainwp-child' ) );
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
if ( 1 === ( int ) get_option ( 'mainwpKeywordLinks' ) ) {
new MainWP_Keyword_Links ();
if ( ! is_admin () ) {
2020-05-06 20:22:11 +07:00
add_filter ( 'the_content' , array ( MainWP_Keyword_Links :: instance (), 'filter_content' ), 100 );
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
MainWP_Keyword_Links :: instance () -> update_htaccess ();
MainWP_Keyword_Links :: instance () -> redirect_cloak ();
2020-03-26 14:11:33 +00:00
} elseif ( 'yes' === get_option ( 'mainwp_keyword_links_htaccess_set' ) ) {
2020-04-07 18:33:47 +02:00
MainWP_Keyword_Links :: clear_htaccess ();
2015-10-15 22:52:37 +10:00
}
}
2020-04-07 18:33:47 +02:00
// Check to support login by alternative admin.
// return false will login by connected admin user.
// return true will try to login as alternative user.
2020-04-07 19:04:20 +02:00
public function check_login_as ( $alter_login ) {
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( ! empty ( $alter_login ) ) {
2020-04-07 18:33:47 +02:00
// check alternative admin existed.
2020-03-27 15:13:11 +00:00
$user = get_user_by ( 'login' , $alter_login );
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( ! $user ) {
2020-04-07 18:33:47 +02:00
// That administrator username was not found on this child site.
2020-03-27 15:13:11 +00:00
return false ;
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( 10 != $user -> wp_user_level && ( ! isset ( $user -> user_level ) || 10 != $user -> user_level ) && ! $user -> has_cap ( 'level_10' ) ) {
2020-04-07 18:33:47 +02:00
// That user is not an administrator.
2020-03-27 15:13:11 +00:00
return false ;
}
2019-02-14 22:38:14 +07:00
2020-04-07 18:33:47 +02:00
return true ; // ok, will try to login by alternative user.
2020-03-27 15:13:11 +00:00
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
return false ;
}
2019-02-14 22:38:14 +07:00
2020-04-07 19:04:20 +02:00
public function default_option_active_plugins ( $default ) {
2015-10-15 22:52:37 +10:00
if ( ! is_array ( $default ) ) {
$default = array ();
}
if ( ! in_array ( 'managewp/init.php' , $default ) ) {
$default [] = 'managewp/init.php' ;
}
return $default ;
}
2020-04-07 19:04:20 +02:00
public function auth ( $signature , $func , $nonce , $pNossl ) {
2020-04-29 00:24:45 +07:00
if ( empty ( $signature ) || ! isset ( $func ) || ( ! get_option ( 'mainwp_child_pubkey' ) && ! get_option ( 'mainwp_child_nossl_key' ) ) ) {
2015-10-15 22:52:37 +10:00
$auth = false ;
} else {
$nossl = get_option ( 'mainwp_child_nossl' );
$serverNoSsl = ( isset ( $pNossl ) && 1 === ( int ) $pNossl );
if ( ( 1 === ( int ) $nossl ) || $serverNoSsl ) {
2020-05-04 23:02:02 +07:00
$nossl_key = get_option ( 'mainwp_child_nossl_key' );
$auth = hash_equals ( md5 ( $func . $nonce . $nossl_key ), base64_decode ( $signature ) ); // // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
2015-10-15 22:52:37 +10:00
} else {
2020-04-07 19:32:01 +02:00
$auth = openssl_verify ( $func . $nonce , base64_decode ( $signature ), base64_decode ( get_option ( 'mainwp_child_pubkey' ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2020-04-07 18:33:47 +02:00
if ( 1 !== $auth ) {
2020-03-27 15:13:11 +00:00
$auth = false ;
}
2015-10-15 22:52:37 +10:00
}
}
return $auth ;
}
2020-04-07 18:33:47 +02:00
// Login.
2020-04-07 19:04:20 +02:00
public function login ( $username , $doAction = false ) {
2015-10-15 22:52:37 +10:00
global $current_user ;
2020-04-07 18:33:47 +02:00
// Logout if required.
2015-10-15 22:52:37 +10:00
if ( isset ( $current_user -> user_login ) ) {
if ( $current_user -> user_login === $username ) {
2020-04-07 18:33:47 +02:00
// to fix issue multi user session.
2020-03-27 15:13:11 +00:00
$user_id = wp_validate_auth_cookie ();
if ( $user_id && $user_id === $current_user -> ID ) {
return true ;
}
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
wp_set_auth_cookie ( $current_user -> ID );
return true ;
}
do_action ( 'wp_logout' );
}
$user = get_user_by ( 'login' , $username );
2020-04-07 16:53:05 +02:00
if ( $user ) {
2015-10-15 22:52:37 +10:00
wp_set_current_user ( $user -> ID );
2020-03-27 15:13:11 +00:00
wp_set_auth_cookie ( $user -> ID );
2015-10-15 22:52:37 +10:00
if ( $doAction ) {
do_action ( 'wp_login' , $user -> user_login );
}
return ( is_user_logged_in () && $current_user -> user_login === $username );
}
return false ;
}
2020-05-06 00:47:59 +07:00
public function no_ssl_filter_function ( $r , $url ) {
2015-10-15 22:52:37 +10:00
$r [ 'sslverify' ] = false ;
return $r ;
}
public function http_request_reject_unsafe_urls ( $r , $url ) {
$r [ 'reject_unsafe_urls' ] = false ;
2020-04-07 16:53:05 +02:00
if ( isset ( $_POST [ 'wpadmin_user' ] ) && ! empty ( $_POST [ 'wpadmin_user' ] ) && isset ( $_POST [ 'wpadmin_passwd' ] ) && ! empty ( $_POST [ 'wpadmin_passwd' ] ) ) {
2020-04-07 19:32:01 +02:00
$auth = base64_encode ( $_POST [ 'wpadmin_user' ] . ':' . $_POST [ 'wpadmin_passwd' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2019-12-13 20:27:05 +07:00
$r [ 'headers' ][ 'Authorization' ] = " Basic $auth " ;
}
2015-10-15 22:52:37 +10:00
return $r ;
}
/**
* Functions to support core functionality
*/
2020-05-06 00:47:59 +07:00
public function install_plugin_theme () {
$wp_filesystem = $this -> get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
if ( ! isset ( $_POST [ 'type' ] ) || ! isset ( $_POST [ 'url' ] ) || ( 'plugin' !== $_POST [ 'type' ] && 'theme' !== $_POST [ 'type' ] ) || '' === $_POST [ 'url' ] ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'Invalid request!' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2015-10-15 22:52:37 +10:00
}
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/template.php' ;
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ;
include_once ABSPATH . '/wp-admin/includes/plugin.php' ;
2015-10-15 22:52:37 +10:00
$urlgot = json_decode ( stripslashes ( $_POST [ 'url' ] ) );
$urls = array ();
if ( ! is_array ( $urlgot ) ) {
$urls [] = $urlgot ;
} else {
$urls = $urlgot ;
}
$result = array ();
foreach ( $urls as $url ) {
2020-03-26 19:45:07 +00:00
$installer = new WP_Upgrader ();
2016-01-18 19:40:51 +01:00
$ssl_verify = true ;
2020-03-26 20:01:04 +00:00
// @see wp-admin/includes/class-wp-upgrader.php
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'sslVerify' ] ) && '0' === $_POST [ 'sslVerify' ] ) {
2020-05-06 00:47:59 +07:00
add_filter ( 'http_request_args' , array ( & $this , 'no_ssl_filter_function' ), 99 , 2 );
2016-01-18 19:40:51 +01:00
$ssl_verify = false ;
2015-10-15 22:52:37 +10:00
}
add_filter ( 'http_request_args' , array ( & $this , 'http_request_reject_unsafe_urls' ), 99 , 2 );
2020-04-07 17:12:41 +02:00
$result = $installer -> run (
array (
'package' => $url ,
'destination' => ( 'plugin' === $_POST [ 'type' ] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
'clear_destination' => ( isset ( $_POST [ 'overwrite' ] ) && $_POST [ 'overwrite' ] ),
'clear_working' => true ,
'hook_extra' => array (),
)
);
2015-10-15 22:52:37 +10:00
if ( is_wp_error ( $result ) ) {
2020-03-27 13:05:05 +00:00
if ( true == $ssl_verify && strpos ( $url , 'https://' ) === 0 ) {
2020-05-06 00:47:59 +07:00
add_filter ( 'http_request_args' , array ( & $this , 'no_ssl_filter_function' ), 99 , 2 );
2016-01-18 19:40:51 +01:00
$ssl_verify = false ;
2020-04-07 17:12:41 +02:00
$result = $installer -> run (
array (
'package' => $url ,
'destination' => ( 'plugin' === $_POST [ 'type' ] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
'clear_destination' => ( isset ( $_POST [ 'overwrite' ] ) && $_POST [ 'overwrite' ] ),
'clear_working' => true ,
'hook_extra' => array (),
)
);
2015-10-15 22:52:37 +10:00
}
2016-01-18 19:40:51 +01:00
if ( is_wp_error ( $result ) ) {
2016-02-15 22:08:39 +01:00
$err_code = $result -> get_error_code ();
2016-01-18 19:40:51 +01:00
if ( $result -> get_error_data () && is_string ( $result -> get_error_data () ) ) {
$error = $result -> get_error_data ();
2016-02-15 22:08:39 +01:00
MainWP_Helper :: error ( $error , $err_code );
2016-01-18 19:40:51 +01:00
} else {
2016-02-15 22:08:39 +01:00
MainWP_Helper :: error ( implode ( ', ' , $error ), $err_code );
2016-01-18 19:40:51 +01:00
}
}
}
remove_filter ( 'http_request_args' , array ( & $this , 'http_request_reject_unsafe_urls' ), 99 , 2 );
if ( false == $ssl_verify ) {
2020-05-06 00:47:59 +07:00
remove_filter ( 'http_request_args' , array ( & $this , 'no_ssl_filter_function' ), 99 );
2015-10-15 22:52:37 +10:00
}
2020-03-26 15:29:54 +00:00
$args = array (
'success' => 1 ,
'action' => 'install' ,
);
2015-10-15 22:52:37 +10:00
if ( 'plugin' === $_POST [ 'type' ] ) {
$path = $result [ 'destination' ];
$fileName = '' ;
$rslt = null ;
wp_cache_set ( 'plugins' , array (), 'plugins' );
foreach ( $result [ 'source_files' ] as $srcFile ) {
if ( is_dir ( $path . $srcFile ) ) {
continue ;
}
$thePlugin = get_plugin_data ( $path . $srcFile );
if ( null !== $thePlugin && '' !== $thePlugin && '' !== $thePlugin [ 'Name' ] ) {
$args [ 'type' ] = 'plugin' ;
$args [ 'Name' ] = $thePlugin [ 'Name' ];
$args [ 'Version' ] = $thePlugin [ 'Version' ];
$args [ 'slug' ] = $result [ 'destination_name' ] . '/' . $srcFile ;
$fileName = $srcFile ;
break ;
}
}
if ( ! empty ( $fileName ) ) {
do_action ( 'mainwp_child_installPluginTheme' , $args );
if ( isset ( $_POST [ 'activatePlugin' ] ) && 'yes' === $_POST [ 'activatePlugin' ] ) {
2020-04-07 19:32:01 +02:00
// to fix activate issue.
2020-03-27 15:13:11 +00:00
if ( 'quotes-collection/quotes-collection.php' == $args [ 'slug' ] ) {
activate_plugin ( $path . $fileName , '' , false , true );
} else {
2020-04-07 18:33:47 +02:00
activate_plugin ( $path . $fileName , '' );
2020-03-27 15:13:11 +00:00
}
2015-10-15 22:52:37 +10:00
}
}
} else {
$args [ 'type' ] = 'theme' ;
$args [ 'slug' ] = $result [ 'destination_name' ];
do_action ( 'mainwp_child_installPluginTheme' , $args );
}
}
$information [ 'installation' ] = 'SUCCESS' ;
$information [ 'destination_name' ] = $result [ 'destination_name' ];
MainWP_Helper :: write ( $information );
}
2020-04-07 16:53:05 +02:00
// This will upgrade WP!
2020-05-06 00:47:59 +07:00
public function upgrade_wp () {
2015-10-15 22:52:37 +10:00
global $wp_version ;
2020-05-06 00:47:59 +07:00
$wp_filesystem = $this -> get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
$information = array ();
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/update.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ;
2020-04-07 16:53:05 +02:00
2015-10-15 22:52:37 +10:00
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2015-10-15 22:52:37 +10:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/template.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/template.php' ;
2015-10-15 22:52:37 +10:00
}
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/file.php' ;
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
2015-10-15 22:52:37 +10:00
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_site_transient_update_core' , $this -> filterFunction , 99 );
}
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_transient_update_core' , $this -> filterFunction , 99 );
}
2020-04-07 16:53:05 +02:00
// Check for new versions.
2020-04-23 19:16:35 +02:00
wp_version_check ();
2015-10-15 22:52:37 +10:00
$core_updates = get_core_updates ();
2020-04-07 16:53:05 +02:00
if ( is_array ( $core_updates ) && count ( $core_updates ) > 0 ) {
2015-10-15 22:52:37 +10:00
foreach ( $core_updates as $core_update ) {
if ( 'latest' === $core_update -> response ) {
$information [ 'upgrade' ] = 'SUCCESS' ;
2020-04-07 18:33:47 +02:00
} elseif ( 'upgrade' === $core_update -> response && get_locale () === $core_update -> locale && version_compare ( $wp_version , $core_update -> current , '<=' ) ) {
2020-03-26 20:01:04 +00:00
// Upgrade!
2015-10-15 22:52:37 +10:00
$upgrade = false ;
if ( class_exists ( 'Core_Upgrader' ) ) {
$core = new Core_Upgrader ();
$upgrade = $core -> upgrade ( $core_update );
}
2020-04-07 16:53:05 +02:00
// If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions.
2020-03-26 20:01:04 +00:00
// So users can upgrade older versions too.
2020-04-07 16:53:05 +02:00
// 3rd option: 'wp_update_core'.
2015-10-15 22:52:37 +10:00
if ( ! is_wp_error ( $upgrade ) ) {
$information [ 'upgrade' ] = 'SUCCESS' ;
} else {
$information [ 'upgrade' ] = 'WPERROR' ;
}
break ;
}
}
if ( ! isset ( $information [ 'upgrade' ] ) ) {
foreach ( $core_updates as $core_update ) {
if ( 'upgrade' === $core_update -> response && version_compare ( $wp_version , $core_update -> current , '<=' ) ) {
2020-03-26 20:01:04 +00:00
// Upgrade!
2015-10-15 22:52:37 +10:00
$upgrade = false ;
if ( class_exists ( 'Core_Upgrader' ) ) {
$core = new Core_Upgrader ();
$upgrade = $core -> upgrade ( $core_update );
}
2020-03-26 20:01:04 +00:00
// If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions
// So users can upgrade older versions too.
2020-04-23 16:42:30 +02:00
// 3rd option: 'wp_update_core'.
2015-10-15 22:52:37 +10:00
if ( ! is_wp_error ( $upgrade ) ) {
$information [ 'upgrade' ] = 'SUCCESS' ;
} else {
$information [ 'upgrade' ] = 'WPERROR' ;
}
break ;
}
}
}
} else {
$information [ 'upgrade' ] = 'NORESPONSE' ;
}
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_site_transient_update_core' , $this -> filterFunction , 99 );
}
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_transient_update_core' , $this -> filterFunction , 99 );
}
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function upgrade_translation () {
2020-04-07 18:33:47 +02:00
// Prevent disable/re-enable at upgrade.
2016-02-15 22:08:39 +01:00
define ( 'DOING_CRON' , true );
2020-05-06 00:47:59 +07:00
MainWP_Helper :: get_wp_filesystem ();
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ;
2016-02-15 22:08:39 +01:00
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2016-02-15 22:08:39 +01:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/template.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/template.php' ;
2016-02-15 22:08:39 +01:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/misc.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
2016-02-15 22:08:39 +01:00
}
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/file.php' ;
2016-02-15 22:08:39 +01:00
2020-03-26 14:11:33 +00:00
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ;
2016-02-15 22:08:39 +01:00
2020-04-23 19:16:35 +02:00
wp_version_check ();
wp_update_themes ();
wp_update_plugins ();
2018-09-27 19:52:32 +02:00
2020-03-26 19:45:07 +00:00
$upgrader = new Language_Pack_Upgrader ( new Language_Pack_Upgrader_Skin ( compact ( 'url' , 'nonce' , 'title' , 'context' ) ) );
$translations = explode ( ',' , urldecode ( $_POST [ 'list' ] ) );
2016-02-15 22:08:39 +01:00
$all_language_updates = wp_get_translation_updates ();
$language_updates = array ();
foreach ( $all_language_updates as $current_language_update ) {
if ( in_array ( $current_language_update -> slug , $translations ) ) {
$language_updates [] = $current_language_update ;
}
}
$result = count ( $language_updates ) == 0 ? false : $upgrader -> bulk_upgrade ( $language_updates );
if ( ! empty ( $result ) ) {
2020-04-23 16:42:30 +02:00
$count_result = count ( $result );
for ( $i = 0 ; $i < $count_result ; $i ++ ) {
2020-03-26 15:29:54 +00:00
if ( empty ( $result [ $i ] ) || is_wp_error ( $result [ $i ] ) ) {
$information [ 'upgrades' ][ $language_updates [ $i ] -> slug ] = false ;
2016-02-15 22:08:39 +01:00
} else {
2020-03-26 15:29:54 +00:00
$information [ 'upgrades' ][ $language_updates [ $i ] -> slug ] = true ;
2016-02-15 22:08:39 +01:00
}
}
} else {
2020-04-07 16:53:05 +02:00
$information [ 'upgrades' ] = array (); // to fix error message when translations updated.
2016-02-15 22:08:39 +01:00
}
2020-05-06 00:47:59 +07:00
$information [ 'sync' ] = $this -> get_site_stats ( array (), false );
2016-02-15 22:08:39 +01:00
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function upgrade_plugin_theme () {
2020-04-07 16:53:05 +02:00
// Prevent disable/re-enable at upgrade.
if ( ! defined ( 'DOING_CRON' ) ) {
2020-03-27 15:13:11 +00:00
define ( 'DOING_CRON' , true );
}
2015-10-15 22:52:37 +10:00
2020-05-06 00:47:59 +07:00
MainWP_Helper :: get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ;
2020-04-07 16:53:05 +02:00
2015-10-15 22:52:37 +10:00
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2015-10-15 22:52:37 +10:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/template.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/template.php' ;
2015-10-15 22:52:37 +10:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/misc.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
2015-10-15 22:52:37 +10:00
}
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/file.php' ;
include_once ABSPATH . '/wp-admin/includes/plugin.php' ;
2020-03-27 15:13:11 +00:00
include_once ABSPATH . '/wp-admin/includes/plugin-install.php' ;
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
$information = array ();
$information [ 'upgrades' ] = array ();
$mwp_premium_updates_todo = array ();
$mwp_premium_updates_todo_slugs = array ();
if ( isset ( $_POST [ 'type' ] ) && 'plugin' === $_POST [ 'type' ] ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/update.php' ;
2015-10-15 22:52:37 +10:00
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_site_transient_update_plugins' , $this -> filterFunction , 99 );
}
2020-03-27 15:13:11 +00:00
$plugins = explode ( ',' , urldecode ( $_POST [ 'list' ] ) );
2015-10-15 22:52:37 +10:00
if ( in_array ( 'backupbuddy/backupbuddy.php' , $plugins ) ) {
if ( isset ( $GLOBALS [ 'ithemes_updater_path' ] ) ) {
if ( ! class_exists ( 'Ithemes_Updater_Settings' ) ) {
2020-03-26 14:11:33 +00:00
require $GLOBALS [ 'ithemes_updater_path' ] . '/settings.php' ;
2015-10-15 22:52:37 +10:00
}
if ( class_exists ( 'Ithemes_Updater_Settings' ) ) {
$ithemes_updater = new Ithemes_Updater_Settings ();
$ithemes_updater -> update ();
}
}
}
2020-04-07 16:53:05 +02:00
// to fix: smart-manager-for-wp-e-commerce update.
if ( in_array ( 'smart-manager-for-wp-e-commerce/smart-manager.php' , $plugins ) ) {
if ( file_exists ( plugin_dir_path ( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php' ) && file_exists ( plugin_dir_path ( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php' ) ) {
2016-03-15 20:54:21 +01:00
include_once plugin_dir_path ( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php' ;
2020-03-26 14:11:33 +00:00
include_once plugin_dir_path ( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php' ;
2016-03-15 20:54:21 +01:00
}
}
2015-10-15 22:52:37 +10:00
global $wp_current_filter ;
2020-05-05 00:56:15 +07:00
$wp_current_filter [] = 'load-plugins.php' ; // phpcs:ignore -- to custom plugin installation.
2020-04-23 19:16:35 +02:00
wp_update_plugins ();
2018-09-27 19:52:32 +02:00
2020-04-07 16:53:05 +02:00
// trick to prevent some premium plugins re-create update info.
remove_all_filters ( 'pre_set_site_transient_update_plugins' );
2018-09-27 19:52:32 +02:00
2020-04-07 16:53:05 +02:00
// support cached premium plugins update info, hooking in the bulk_upgrade().
2020-03-27 15:13:11 +00:00
add_filter ( 'pre_site_transient_update_plugins' , array ( $this , 'set_cached_update_plugins' ) );
2018-11-14 21:33:36 +07:00
2015-10-15 22:52:37 +10:00
$information [ 'plugin_updates' ] = get_plugin_updates ();
$plugins = explode ( ',' , urldecode ( $_POST [ 'list' ] ) );
$premiumPlugins = array ();
$premiumUpdates = get_option ( 'mainwp_premium_updates' );
if ( is_array ( $premiumUpdates ) ) {
$newPlugins = array ();
foreach ( $plugins as $plugin ) {
if ( in_array ( $plugin , $premiumUpdates ) ) {
$premiumPlugins [] = $plugin ;
} else {
$newPlugins [] = $plugin ;
}
}
$plugins = $newPlugins ;
}
if ( count ( $plugins ) > 0 ) {
2020-03-27 15:13:11 +00:00
$failed = true ;
2020-04-07 16:53:05 +02:00
// to fix update of Yithemes premiums plugins that hooked to upgrader_pre_download.
$url = 'update.php?action=update-selected&plugins=' . rawurlencode ( implode ( ',' , $plugins ) );
2020-03-27 15:13:11 +00:00
$nonce = 'bulk-update-plugins' ;
$upgrader = new Plugin_Upgrader ( new Bulk_Plugin_Upgrader_Skin ( compact ( 'nonce' , 'url' ) ) );
$result = $upgrader -> bulk_upgrade ( $plugins );
if ( ! empty ( $result ) ) {
foreach ( $result as $plugin => $info ) {
if ( empty ( $info ) ) {
$information [ 'upgrades' ][ $plugin ] = false ;
2020-04-07 16:53:05 +02:00
// try to fix if that is premiums update.
2020-03-27 15:13:11 +00:00
$api = apply_filters ( 'plugins_api' , false , 'plugin_information' , array ( 'slug' => $plugin ) );
2020-04-07 16:53:05 +02:00
if ( ! is_wp_error ( $api ) && ! empty ( $api ) ) {
if ( isset ( $api -> download_link ) ) {
$res = $upgrader -> install ( $api -> download_link );
2020-03-27 15:13:11 +00:00
if ( ! is_wp_error ( $res ) && ! ( is_null ( $res ) ) ) {
$information [ 'upgrades' ][ $plugin ] = true ;
}
}
}
2020-03-27 13:05:05 +00:00
} else {
2020-03-27 15:13:11 +00:00
$information [ 'upgrades' ][ $plugin ] = true ;
}
}
$failed = false ;
}
2017-07-11 14:10:22 +02:00
2020-03-27 15:13:11 +00:00
if ( $failed ) {
MainWP_Helper :: error ( __ ( 'Invalid request!' , 'mainwp-child' ) );
}
2015-10-15 22:52:37 +10:00
}
2018-11-14 21:33:36 +07:00
2020-03-27 15:13:11 +00:00
remove_filter ( 'pre_site_transient_update_plugins' , array ( $this , 'set_cached_update_plugins' ), 10 );
2020-04-07 17:12:41 +02:00
delete_site_transient ( 'mainwp_update_plugins_cached' ); // fix cached update info.
2018-11-14 21:33:36 +07:00
2015-10-15 22:52:37 +10:00
if ( count ( $premiumPlugins ) > 0 ) {
$mwp_premium_updates = apply_filters ( 'mwp_premium_perform_update' , array () );
if ( is_array ( $mwp_premium_updates ) && is_array ( $premiumPlugins ) ) {
foreach ( $premiumPlugins as $premiumPlugin ) {
foreach ( $mwp_premium_updates as $key => $update ) {
$slug = ( isset ( $update [ 'slug' ] ) ? $update [ 'slug' ] : $update [ 'Name' ] );
if ( 0 === strcmp ( $slug , $premiumPlugin ) ) {
$mwp_premium_updates_todo [ $key ] = $update ;
$mwp_premium_updates_todo_slugs [] = $premiumPlugin ;
}
}
}
}
unset ( $mwp_premium_updates );
$premiumUpgrader = new Plugin_Upgrader ( new Bulk_Plugin_Upgrader_Skin ( compact ( 'nonce' , 'url' ) ) );
}
if ( count ( $plugins ) <= 0 && count ( $premiumPlugins ) <= 0 ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'Invalid request!' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_site_transient_update_plugins' , $this -> filterFunction , 99 );
}
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_POST [ 'type' ] ) && 'theme' === $_POST [ 'type' ] ) {
2016-02-15 22:08:39 +01:00
$last_update = get_site_transient ( 'update_themes' );
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/update.php' ;
2015-10-15 22:52:37 +10:00
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_site_transient_update_themes' , $this -> filterFunction , 99 );
}
2016-02-15 22:08:39 +01:00
2020-04-23 19:16:35 +02:00
wp_update_themes ();
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/theme.php' ;
2019-02-14 22:38:14 +07:00
2020-04-07 17:12:41 +02:00
// to support cached premium themes update info, hooking in the bulk_upgrade().
2020-03-27 15:13:11 +00:00
add_filter ( 'pre_site_transient_update_themes' , array ( $this , 'set_cached_update_themes' ) );
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
$information [ 'theme_updates' ] = $this -> upgrade_get_theme_updates ();
$themes = explode ( ',' , $_POST [ 'list' ] );
$premiumThemes = array ();
$premiumUpdates = get_option ( 'mainwp_premium_updates' );
if ( is_array ( $premiumUpdates ) ) {
$newThemes = array ();
foreach ( $themes as $theme ) {
if ( in_array ( $theme , $premiumUpdates ) ) {
$premiumThemes [] = $theme ;
} else {
$newThemes [] = $theme ;
}
}
$themes = $newThemes ;
}
if ( count ( $themes ) > 0 ) {
$addFilterToFixUpdate_optimizePressTheme = false ;
if ( in_array ( 'optimizePressTheme' , $themes ) ) {
$addFilterToFixUpdate_optimizePressTheme = true ;
2020-05-06 00:47:59 +07:00
add_filter ( 'site_transient_update_themes' , array ( $this , 'hook_fix_optimize_press_theme_update' ), 99 );
2015-10-15 22:52:37 +10:00
}
2016-02-15 22:08:39 +01:00
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_site_transient_update_plugins' , $this -> filterFunction , 99 );
}
$last_update2 = get_site_transient ( 'update_themes' );
set_site_transient ( 'update_themes' , $last_update );
2020-03-27 15:13:11 +00:00
$failed = true ;
$upgrader = new Theme_Upgrader ( new Bulk_Theme_Upgrader_Skin ( compact ( 'nonce' , 'url' ) ) );
$result = $upgrader -> bulk_upgrade ( $themes );
if ( ! empty ( $result ) ) {
foreach ( $result as $theme => $info ) {
if ( empty ( $info ) ) {
$information [ 'upgrades' ][ $theme ] = false ;
} else {
$information [ 'upgrades' ][ $theme ] = true ;
}
}
$failed = false ;
}
2017-07-11 14:10:22 +02:00
2020-03-27 15:13:11 +00:00
if ( $failed ) {
MainWP_Helper :: error ( __ ( 'Invalid request!' , 'mainwp-child' ) );
}
2016-02-15 22:08:39 +01:00
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_site_transient_update_themes' , $this -> filterFunction , 99 );
}
set_site_transient ( 'update_themes' , $last_update2 );
2015-10-15 22:52:37 +10:00
if ( $addFilterToFixUpdate_optimizePressTheme ) {
2020-04-07 18:33:47 +02:00
remove_filter (
'site_transient_update_themes' ,
array (
$this ,
2020-05-06 00:47:59 +07:00
'hook_fix_optimize_press_theme_update' ,
2020-04-07 18:33:47 +02:00
),
99
);
2015-10-15 22:52:37 +10:00
}
}
2016-02-15 22:08:39 +01:00
2020-03-27 15:13:11 +00:00
remove_filter ( 'pre_site_transient_update_themes' , array ( $this , 'set_cached_update_themes' ), 10 );
2020-04-07 17:12:41 +02:00
delete_site_transient ( 'mainwp_update_themes_cached' ); // fix cached update info.
2016-02-15 22:08:39 +01:00
2015-10-15 22:52:37 +10:00
if ( count ( $premiumThemes ) > 0 ) {
$mwp_premium_updates = apply_filters ( 'mwp_premium_perform_update' , array () );
$mwp_premium_updates_todo = array ();
$mwp_premium_updates_todo_slugs = array ();
if ( is_array ( $premiumThemes ) && is_array ( $mwp_premium_updates ) ) {
foreach ( $premiumThemes as $premiumTheme ) {
foreach ( $mwp_premium_updates as $key => $update ) {
$slug = ( isset ( $update [ 'slug' ] ) ? $update [ 'slug' ] : $update [ 'Name' ] );
if ( 0 === strcmp ( $slug , $premiumTheme ) ) {
$mwp_premium_updates_todo [ $key ] = $update ;
$mwp_premium_updates_todo_slugs [] = $slug ;
}
}
}
}
unset ( $mwp_premium_updates );
$premiumUpgrader = new Theme_Upgrader ( new Bulk_Theme_Upgrader_Skin ( compact ( 'nonce' , 'url' ) ) );
}
if ( count ( $themes ) <= 0 && count ( $premiumThemes ) <= 0 ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'Invalid request!' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_site_transient_update_themes' , $this -> filterFunction , 99 );
}
} else {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'Invalid request!' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
if ( count ( $mwp_premium_updates_todo ) > 0 ) {
2020-04-07 16:53:05 +02:00
// Upgrade via WP.
// @see wp-admin/update.php.
2015-10-15 22:52:37 +10:00
$result = $premiumUpgrader -> bulk_upgrade ( $mwp_premium_updates_todo_slugs );
if ( ! empty ( $result ) ) {
foreach ( $result as $plugin => $info ) {
if ( ! empty ( $info ) ) {
$information [ 'upgrades' ][ $plugin ] = true ;
foreach ( $mwp_premium_updates_todo as $key => $update ) {
$slug = ( isset ( $update [ 'slug' ] ) ? $update [ 'slug' ] : $update [ 'Name' ] );
}
}
}
}
2020-04-07 17:12:41 +02:00
// Upgrade via callback.
2015-10-15 22:52:37 +10:00
foreach ( $mwp_premium_updates_todo as $update ) {
$slug = ( isset ( $update [ 'slug' ] ) ? $update [ 'slug' ] : $update [ 'Name' ] );
if ( isset ( $update [ 'url' ] ) ) {
2020-04-22 17:57:46 +02:00
$installer = new WP_Upgrader ();
$result = $installer -> run (
2020-04-07 17:12:41 +02:00
array (
'package' => $update [ 'url' ],
'destination' => ( 'plugin' === $update [ 'type' ] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
'clear_destination' => true ,
'clear_working' => true ,
'hook_extra' => array (),
)
);
2015-10-15 22:52:37 +10:00
$information [ 'upgrades' ][ $slug ] = ( ! is_wp_error ( $result ) && ! empty ( $result ) );
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $update [ 'callback' ] ) ) {
2015-10-15 22:52:37 +10:00
if ( is_array ( $update [ 'callback' ] ) && isset ( $update [ 'callback' ][ 0 ] ) && isset ( $update [ 'callback' ][ 1 ] ) ) {
2020-04-23 19:16:35 +02:00
$update_result = call_user_func (
2020-04-07 17:12:41 +02:00
array (
$update [ 'callback' ][ 0 ],
$update [ 'callback' ][ 1 ],
)
);
2015-10-15 22:52:37 +10:00
$information [ 'upgrades' ][ $slug ] = $update_result && true ;
2020-03-26 14:11:33 +00:00
} elseif ( is_string ( $update [ 'callback' ] ) ) {
2020-04-23 19:16:35 +02:00
$update_result = call_user_func ( $update [ 'callback' ] );
2015-10-15 22:52:37 +10:00
$information [ 'upgrades' ][ $slug ] = $update_result && true ;
} else {
$information [ 'upgrades' ][ $slug ] = false ;
}
} else {
$information [ 'upgrades' ][ $slug ] = false ;
}
}
}
2020-05-06 00:47:59 +07:00
$information [ 'sync' ] = $this -> get_site_stats ( array (), false );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $information );
}
2020-03-27 15:13:11 +00:00
public function set_cached_update_plugins ( $false = false , $_transient_data = null ) {
2018-11-14 21:33:36 +07:00
if ( ! is_object ( $_transient_data ) ) {
2020-03-26 14:05:04 +00:00
$_transient_data = new stdClass ();
2018-11-14 21:33:36 +07:00
}
2020-03-27 15:13:11 +00:00
$pre = false ;
2018-11-14 21:33:36 +07:00
$cached_update_info = get_site_transient ( 'mainwp_update_plugins_cached' );
2020-04-07 16:53:05 +02:00
if ( is_array ( $cached_update_info ) && count ( $cached_update_info ) > 0 ) {
2020-03-27 15:13:11 +00:00
foreach ( $cached_update_info as $slug => $info ) {
2020-04-07 16:53:05 +02:00
if ( ! isset ( $_transient_data -> response [ $slug ] ) && isset ( $info -> update ) ) {
2020-03-27 15:13:11 +00:00
$_transient_data -> response [ $slug ] = $info -> update ;
$pre = true ;
}
}
}
2019-02-14 22:38:14 +07:00
2020-04-07 18:33:47 +02:00
if ( false == $pre ) {
2020-03-27 15:13:11 +00:00
return $false ;
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
return $_transient_data ;
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
public function set_cached_update_themes ( $false = false , $_transient_data = null ) {
2019-02-14 22:38:14 +07:00
if ( ! is_object ( $_transient_data ) ) {
2020-03-26 14:05:04 +00:00
$_transient_data = new stdClass ();
2019-02-14 22:38:14 +07:00
}
2020-03-27 15:13:11 +00:00
$pre = false ;
2019-02-14 22:38:14 +07:00
$cached_update_info = get_site_transient ( 'mainwp_update_themes_cached' );
2020-04-07 16:53:05 +02:00
if ( is_array ( $cached_update_info ) && count ( $cached_update_info ) > 0 ) {
2020-03-27 15:13:11 +00:00
foreach ( $cached_update_info as $slug => $info ) {
2020-04-07 16:53:05 +02:00
if ( ! isset ( $_transient_data -> response [ $slug ] ) && isset ( $info -> update ) ) {
2020-03-27 15:13:11 +00:00
$_transient_data -> response [ $slug ] = $info -> update ;
$pre = true ;
}
}
}
2020-04-07 18:33:47 +02:00
if ( false == $pre ) {
2020-03-27 15:13:11 +00:00
return $false ;
}
return $_transient_data ;
}
2018-11-14 21:33:36 +07:00
2020-05-06 00:47:59 +07:00
public function hook_fix_optimize_press_theme_update ( $transient ) {
2015-10-15 22:52:37 +10:00
if ( ! defined ( 'OP_FUNC' ) ) {
return $transient ;
}
$theme_slug = 'optimizePressTheme' ;
if ( ! function_exists ( 'op_sl_update' ) ) {
require_once OP_FUNC . 'options.php' ;
require_once OP_FUNC . 'sl_api.php' ;
}
$apiResponse = op_sl_update ( 'theme' );
if ( is_wp_error ( $apiResponse ) ) {
return $transient ;
}
$obj = new stdClass ();
$obj -> slug = $theme_slug ;
$obj -> new_version = $apiResponse -> new_version ;
$obj -> url = $apiResponse -> url ;
$obj -> package = $apiResponse -> s3_package ;
$obj -> sections = array (
'description' => $apiResponse -> section -> description ,
'changelog' => $apiResponse -> section -> changelog ,
);
$transient -> response [ $theme_slug ] = ( array ) $obj ;
return $transient ;
}
2020-04-07 16:53:05 +02:00
// This will register the current wp - thus generating the public key etc.
2020-05-06 00:47:59 +07:00
public function register_site () {
2015-10-15 22:52:37 +10:00
global $current_user ;
$information = array ();
2020-04-07 16:53:05 +02:00
// Check if the user is valid & login.
2015-10-15 22:52:37 +10:00
if ( ! isset ( $_POST [ 'user' ] ) || ! isset ( $_POST [ 'pubkey' ] ) ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'Invalid request!' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
2020-04-07 16:53:05 +02:00
// Already added - can't readd. Deactivate plugin.
2015-10-15 22:52:37 +10:00
if ( get_option ( 'mainwp_child_pubkey' ) ) {
2020-04-07 16:53:05 +02:00
// set disconnect status to yes here, it will empty after reconnected.
2020-05-06 20:22:11 +07:00
MainWP_Child_Branding :: instance () -> save_branding_options ( 'branding_disconnected' , 'yes' );
2020-04-07 16:53:05 +02:00
MainWP_Helper :: update_option ( 'mainwp_child_branding_disconnected' , 'yes' , 'yes' );
2019-11-11 23:17:10 +07:00
MainWP_Helper :: error ( __ ( 'Public key already set. Please deactivate & reactivate the MainWP Child plugin and try again.' , 'mainwp-child' ) );
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
}
2015-12-07 19:49:58 +01:00
if ( '' != get_option ( 'mainwp_child_uniqueId' ) ) {
2015-10-15 22:52:37 +10:00
if ( ! isset ( $_POST [ 'uniqueId' ] ) || ( '' === $_POST [ 'uniqueId' ] ) ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'This child site is set to require a unique security ID. Please enter it before the connection can be established.' , 'mainwp-child' ) );
2020-03-26 14:11:33 +00:00
} elseif ( get_option ( 'mainwp_child_uniqueId' ) !== $_POST [ 'uniqueId' ] ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'The unique security ID mismatch! Please correct it before the connection can be established.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
}
2020-04-07 18:33:47 +02:00
// Check SSL Requirement.
2020-05-06 00:47:59 +07:00
if ( ! MainWP_Helper :: is_ssl_enabled () && ( ! defined ( 'MAINWP_ALLOW_NOSSL_CONNECT' ) || ! MAINWP_ALLOW_NOSSL_CONNECT ) ) {
2016-12-25 14:38:20 +01:00
MainWP_Helper :: error ( __ ( 'SSL is required on the child site to set up a secure connection.' , 'mainwp-child' ) );
}
2020-04-07 18:33:47 +02:00
// Login.
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'user' ] ) ) {
if ( ! $this -> login ( $_POST [ 'user' ] ) ) {
2020-04-07 16:53:05 +02:00
$hint = '<br/>' . __ ( 'Hint: Check if the administrator user exists on the child site, if not, you need to use an existing administrator.' , 'mainwp-child' );
MainWP_Helper :: error ( __ ( 'That administrator username was not found on this child site. Please verify that it is an existing administrator.' . $hint , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
2016-04-27 19:25:53 +02:00
if ( 10 !== $current_user -> wp_user_level && ( ! isset ( $current_user -> user_level ) || 10 !== $current_user -> user_level ) && ! $current_user -> has_cap ( 'level_10' ) ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'That user is not an administrator. Please use an administrator user to establish the connection.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
}
2020-04-07 19:32:01 +02:00
MainWP_Helper :: update_option ( 'mainwp_child_pubkey' , base64_encode ( $_POST [ 'pubkey' ] ), 'yes' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2020-04-07 18:33:47 +02:00
MainWP_Helper :: update_option ( 'mainwp_child_server' , $_POST [ 'server' ] ); // Save the public key.
MainWP_Helper :: update_option ( 'mainwp_child_nonce' , 0 ); // Save the nonce.
2015-10-15 22:52:37 +10:00
2020-05-06 00:47:59 +07:00
MainWP_Helper :: update_option ( 'mainwp_child_nossl' , ( '-1' === $_POST [ 'pubkey' ] || ! MainWP_Helper :: is_ssl_enabled () ? 1 : 0 ), 'yes' );
$information [ 'nossl' ] = ( '-1' === $_POST [ 'pubkey' ] || ! MainWP_Helper :: is_ssl_enabled () ? 1 : 0 );
2020-04-29 00:24:45 +07:00
if ( function_exists ( 'random_bytes' ) ) {
2020-05-04 23:02:02 +07:00
$nossl_key = random_bytes ( 32 );
$nossl_key = bin2hex ( $nossl_key );
2020-04-29 00:24:45 +07:00
} else {
2020-05-04 23:02:02 +07:00
$nossl_key = uniqid ( '' , true );
2020-04-29 00:24:45 +07:00
}
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_nossl_key' , $nossl_key , 'yes' );
$information [ 'nosslkey' ] = $nossl_key ;
$information [ 'register' ] = 'OK' ;
$information [ 'uniqueId' ] = get_option ( 'mainwp_child_uniqueId' , '' );
$information [ 'user' ] = $_POST [ 'user' ];
2020-05-06 00:47:59 +07:00
$this -> get_site_stats ( $information );
2015-10-15 22:52:37 +10:00
}
2020-05-06 00:47:59 +07:00
public function new_post () {
2020-04-07 19:32:01 +02:00
$new_post = maybe_unserialize ( base64_decode ( $_POST [ 'new_post' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
$post_custom = maybe_unserialize ( base64_decode ( $_POST [ 'post_custom' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
$post_category = rawurldecode ( isset ( $_POST [ 'post_category' ] ) ? base64_decode ( $_POST [ 'post_category' ] ) : null ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$post_tags = rawurldecode ( isset ( $new_post [ 'post_tags' ] ) ? $new_post [ 'post_tags' ] : null );
2020-04-07 19:32:01 +02:00
$post_featured_image = base64_decode ( $_POST [ 'post_featured_image' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
$upload_dir = maybe_unserialize ( base64_decode ( $_POST [ 'mainwp_upload_dir' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ '_ezin_post_category' ] ) ) {
2020-04-07 19:32:01 +02:00
$new_post [ '_ezin_post_category' ] = maybe_unserialize ( base64_decode ( $_POST [ '_ezin_post_category' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
}
2020-03-27 15:13:11 +00:00
$others = array ();
2020-04-07 16:53:05 +02:00
if ( isset ( $_POST [ 'featured_image_data' ] ) && ! empty ( $_POST [ 'featured_image_data' ] ) ) {
2020-04-07 19:32:01 +02:00
$others [ 'featured_image_data' ] = unserialize ( base64_decode ( $_POST [ 'featured_image_data' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2020-03-27 15:13:11 +00:00
}
2018-09-27 19:52:32 +02:00
2020-05-06 00:47:59 +07:00
$res = MainWP_Helper :: create_post ( $new_post , $post_custom , $post_category , $post_featured_image , $upload_dir , $post_tags , $others );
2017-08-24 20:41:12 +02:00
2020-04-07 16:53:05 +02:00
if ( is_array ( $res ) && isset ( $res [ 'error' ] ) ) {
2020-03-27 15:13:11 +00:00
MainWP_Helper :: error ( $res [ 'error' ] );
}
2017-08-24 20:41:12 +02:00
2015-10-15 22:52:37 +10:00
$created = $res [ 'success' ];
if ( true !== $created ) {
2017-08-24 20:41:12 +02:00
MainWP_Helper :: error ( 'Undefined error' );
2015-10-15 22:52:37 +10:00
}
$information [ 'added' ] = true ;
$information [ 'added_id' ] = $res [ 'added_id' ];
$information [ 'link' ] = $res [ 'link' ];
2020-04-07 16:53:05 +02:00
do_action ( 'mainwp_child_after_newpost' , $res );
2020-02-25 22:31:13 +07:00
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function post_action () {
2020-03-26 19:45:07 +00:00
$action = $_POST [ 'action' ];
$postId = $_POST [ 'id' ];
2020-03-27 15:13:11 +00:00
$my_post = array ();
2015-10-15 22:52:37 +10:00
if ( 'publish' === $action ) {
2020-03-27 15:13:11 +00:00
$post_current = get_post ( $postId );
2020-04-07 16:53:05 +02:00
if ( empty ( $post_current ) ) {
2020-03-27 15:13:11 +00:00
$information [ 'status' ] = 'FAIL' ;
} else {
if ( 'future' == $post_current -> post_status ) {
2020-04-07 16:53:05 +02:00
wp_publish_post ( $postId );
wp_update_post (
array (
'ID' => $postId ,
'post_date' => current_time ( 'mysql' , false ),
'post_date_gmt' => current_time ( 'mysql' , true ),
)
);
2020-03-27 15:13:11 +00:00
} else {
2020-04-07 16:53:05 +02:00
wp_update_post (
array (
'ID' => $postId ,
'post_status' => 'publish' ,
)
);
2020-03-27 15:13:11 +00:00
}
}
2020-03-26 14:11:33 +00:00
} elseif ( 'update' === $action ) {
2015-10-15 22:52:37 +10:00
$postData = $_POST [ 'post_data' ];
$my_post = is_array ( $postData ) ? $postData : array ();
wp_update_post ( $my_post );
2020-03-26 14:11:33 +00:00
} elseif ( 'unpublish' === $action ) {
2015-10-15 22:52:37 +10:00
$my_post [ 'ID' ] = $postId ;
$my_post [ 'post_status' ] = 'draft' ;
wp_update_post ( $my_post );
2020-03-26 14:11:33 +00:00
} elseif ( 'trash' === $action ) {
2015-10-15 22:52:37 +10:00
add_action ( 'trash_post' , array ( 'MainWP_Child_Links_Checker' , 'hook_post_deleted' ) );
wp_trash_post ( $postId );
2020-03-26 14:11:33 +00:00
} elseif ( 'delete' === $action ) {
2015-10-15 22:52:37 +10:00
add_action ( 'delete_post' , array ( 'MainWP_Child_Links_Checker' , 'hook_post_deleted' ) );
wp_delete_post ( $postId , true );
2020-03-26 14:11:33 +00:00
} elseif ( 'restore' === $action ) {
2015-10-15 22:52:37 +10:00
wp_untrash_post ( $postId );
2020-03-26 14:11:33 +00:00
} elseif ( 'update_meta' === $action ) {
2020-04-07 19:32:01 +02:00
$values = maybe_unserialize ( base64_decode ( $_POST [ 'values' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$meta_key = $values [ 'meta_key' ];
$meta_value = $values [ 'meta_value' ];
$check_prev = $values [ 'check_prev' ];
foreach ( $meta_key as $i => $key ) {
if ( 1 === intval ( $check_prev [ $i ] ) ) {
update_post_meta ( $postId , $key , get_post_meta ( $postId , $key , true ) ? get_post_meta ( $postId , $key , true ) : $meta_value [ $i ] );
} else {
update_post_meta ( $postId , $key , $meta_value [ $i ] );
}
}
2020-03-26 14:11:33 +00:00
} elseif ( 'get_edit' === $action ) {
2020-03-27 15:13:11 +00:00
$postId = $_POST [ 'id' ];
$post_type = $_POST [ 'post_type' ];
2020-04-07 18:33:47 +02:00
if ( 'post' == $post_type ) {
2020-03-27 15:13:11 +00:00
$my_post = $this -> get_post_edit ( $postId );
} else {
$my_post = $this -> get_page_edit ( $postId );
}
2015-10-15 22:52:37 +10:00
} else {
$information [ 'status' ] = 'FAIL' ;
}
if ( ! isset ( $information [ 'status' ] ) ) {
$information [ 'status' ] = 'SUCCESS' ;
}
$information [ 'my_post' ] = $my_post ;
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function get_post_edit ( $id ) {
2020-03-27 15:13:11 +00:00
$post = get_post ( $id );
if ( $post ) {
$categoryObjects = get_the_category ( $post -> ID );
$categories = '' ;
foreach ( $categoryObjects as $cat ) {
if ( '' !== $categories ) {
$categories .= ', ' ;
}
$categories .= $cat -> name ;
}
$post_category = $categories ;
$tagObjects = get_the_tags ( $post -> ID );
$tags = '' ;
if ( is_array ( $tagObjects ) ) {
foreach ( $tagObjects as $tag ) {
if ( '' !== $tags ) {
$tags .= ', ' ;
}
$tags .= $tag -> name ;
}
}
$post_tags = $tags ;
$post_custom = get_post_custom ( $id );
$galleries = get_post_gallery ( $id , false );
$post_gallery_images = array ();
2020-04-07 16:53:05 +02:00
if ( is_array ( $galleries ) && isset ( $galleries [ 'ids' ] ) ) {
2020-03-27 15:13:11 +00:00
$attached_images = explode ( ',' , $galleries [ 'ids' ] );
foreach ( $attached_images as $attachment_id ) {
$attachment = get_post ( $attachment_id );
if ( $attachment ) {
$post_gallery_images [] = array (
'id' => $attachment_id ,
'alt' => get_post_meta ( $attachment -> ID , '_wp_attachment_image_alt' , true ),
'caption' => $attachment -> post_excerpt ,
'description' => $attachment -> post_content ,
'src' => $attachment -> guid ,
'title' => $attachment -> post_title ,
);
}
}
}
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php' ;
$post_featured_image = get_post_thumbnail_id ( $id );
$child_upload_dir = wp_upload_dir ();
$new_post = array (
'edit_id' => $id ,
'is_sticky' => is_sticky ( $id ) ? 1 : 0 ,
'post_title' => $post -> post_title ,
'post_content' => $post -> post_content ,
'post_status' => $post -> post_status ,
'post_date' => $post -> post_date ,
'post_date_gmt' => $post -> post_date_gmt ,
'post_tags' => $post_tags ,
'post_name' => $post -> post_name ,
'post_excerpt' => $post -> post_excerpt ,
'comment_status' => $post -> comment_status ,
'ping_status' => $post -> ping_status ,
);
2020-04-07 18:33:47 +02:00
if ( null != $post_featured_image ) { // Featured image is set, retrieve URL.
2020-03-27 15:13:11 +00:00
$img = wp_get_attachment_image_src ( $post_featured_image , 'full' );
$post_featured_image = $img [ 0 ];
}
require_once ABSPATH . 'wp-admin/includes/post.php' ;
2020-04-07 16:53:05 +02:00
wp_set_post_lock ( $id );
2020-03-27 15:13:11 +00:00
$post_data = array (
2020-04-07 19:32:01 +02:00
'new_post' => base64_encode ( serialize ( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'post_custom' => base64_encode ( serialize ( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'post_category' => base64_encode ( $post_category ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'post_featured_image' => base64_encode ( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'post_gallery_images' => base64_encode ( serialize ( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'child_upload_dir' => base64_encode ( serialize ( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2020-03-27 15:13:11 +00:00
);
return $post_data ;
}
return false ;
}
2020-04-07 19:04:20 +02:00
public function get_page_edit ( $id ) {
2020-03-27 15:13:11 +00:00
$post = get_post ( $id );
if ( $post ) {
$post_custom = get_post_custom ( $id );
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php' ;
$post_featured_image = get_post_thumbnail_id ( $id );
$child_upload_dir = wp_upload_dir ();
$new_post = array (
2020-03-26 14:11:33 +00:00
'edit_id' => $id ,
2020-03-26 15:29:54 +00:00
'post_title' => $post -> post_title ,
'post_content' => $post -> post_content ,
'post_status' => $post -> post_status ,
'post_date' => $post -> post_date ,
'post_date_gmt' => $post -> post_date_gmt ,
'post_type' => 'page' ,
'post_name' => $post -> post_name ,
'post_excerpt' => $post -> post_excerpt ,
2020-03-26 14:11:33 +00:00
'comment_status' => $post -> comment_status ,
2020-03-26 15:29:54 +00:00
'ping_status' => $post -> ping_status ,
2020-03-27 15:13:11 +00:00
);
2016-11-24 20:46:47 +01:00
2020-04-07 18:33:47 +02:00
if ( null != $post_featured_image ) {
2020-03-27 15:13:11 +00:00
$img = wp_get_attachment_image_src ( $post_featured_image , 'full' );
$post_featured_image = $img [ 0 ];
}
2016-11-24 20:46:47 +01:00
2020-03-27 15:13:11 +00:00
$galleries = get_post_gallery ( $id , false );
$post_gallery_images = array ();
2016-11-24 20:46:47 +01:00
2020-04-07 16:53:05 +02:00
if ( is_array ( $galleries ) && isset ( $galleries [ 'ids' ] ) ) {
2020-03-27 15:13:11 +00:00
$attached_images = explode ( ',' , $galleries [ 'ids' ] );
2020-03-26 19:51:58 +00:00
foreach ( $attached_images as $attachment_id ) {
$attachment = get_post ( $attachment_id );
if ( $attachment ) {
$post_gallery_images [] = array (
'id' => $attachment_id ,
'alt' => get_post_meta ( $attachment -> ID , '_wp_attachment_image_alt' , true ),
'caption' => $attachment -> post_excerpt ,
'description' => $attachment -> post_content ,
'src' => $attachment -> guid ,
'title' => $attachment -> post_title ,
);
}
}
2020-03-27 15:13:11 +00:00
}
2016-11-24 20:46:47 +01:00
2020-03-27 15:13:11 +00:00
require_once ABSPATH . 'wp-admin/includes/post.php' ;
2020-04-07 16:53:05 +02:00
wp_set_post_lock ( $id );
2017-08-24 20:41:12 +02:00
2020-03-27 15:13:11 +00:00
$post_data = array (
2020-04-07 19:32:01 +02:00
'new_post' => base64_encode ( serialize ( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'post_custom' => base64_encode ( serialize ( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'post_featured_image' => base64_encode ( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'post_gallery_images' => base64_encode ( serialize ( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
'child_upload_dir' => base64_encode ( serialize ( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2020-03-27 15:13:11 +00:00
);
return $post_data ;
}
return false ;
}
2016-11-24 20:46:47 +01:00
2020-04-07 19:04:20 +02:00
public function user_action () {
2015-10-15 22:52:37 +10:00
$action = $_POST [ 'action' ];
$extra = $_POST [ 'extra' ];
$userId = $_POST [ 'id' ];
$user_pass = $_POST [ 'user_pass' ];
2020-03-27 15:13:11 +00:00
$failed = false ;
2015-10-15 22:52:37 +10:00
global $current_user ;
$reassign = ( isset ( $current_user ) && isset ( $current_user -> ID ) ) ? $current_user -> ID : 0 ;
2020-03-27 15:13:11 +00:00
include_once ABSPATH . '/wp-admin/includes/user.php' ;
2015-10-15 22:52:37 +10:00
if ( 'delete' === $action ) {
wp_delete_user ( $userId , $reassign );
2020-03-26 14:11:33 +00:00
} elseif ( 'changeRole' === $action ) {
2015-10-15 22:52:37 +10:00
$my_user = array ();
$my_user [ 'ID' ] = $userId ;
$my_user [ 'role' ] = $extra ;
wp_update_user ( $my_user );
2020-03-26 14:11:33 +00:00
} elseif ( 'update_password' === $action ) {
2015-10-15 22:52:37 +10:00
$my_user = array ();
$my_user [ 'ID' ] = $userId ;
$my_user [ 'user_pass' ] = $user_pass ;
wp_update_user ( $my_user );
2020-03-26 14:11:33 +00:00
} elseif ( 'edit' === $action ) {
2020-04-07 16:53:05 +02:00
$user_data = $this -> get_user_to_edit ( $userId );
if ( ! empty ( $user_data ) ) {
2020-03-26 19:51:58 +00:00
$information [ 'user_data' ] = $user_data ;
} else {
$failed = true ;
}
2020-03-26 14:11:33 +00:00
} elseif ( 'update_user' === $action ) {
2020-03-27 15:13:11 +00:00
$my_user = $_POST [ 'extra' ];
2020-04-07 16:53:05 +02:00
if ( is_array ( $my_user ) ) {
2020-03-27 13:05:05 +00:00
foreach ( $my_user as $idx => $val ) {
2020-04-07 18:33:47 +02:00
if ( 'donotupdate' === $val || ( empty ( $val ) && 'role' !== $idx ) ) {
2020-04-07 16:53:05 +02:00
unset ( $my_user [ $idx ] );
2020-03-26 19:51:58 +00:00
}
}
$result = $this -> edit_user ( $userId , $my_user );
2020-04-07 16:53:05 +02:00
if ( is_array ( $result ) && isset ( $result [ 'error' ] ) ) {
2020-03-26 19:51:58 +00:00
$information [ 'error' ] = $result [ 'error' ];
}
} else {
$failed = true ;
}
2015-10-15 22:52:37 +10:00
} else {
2016-10-24 20:33:37 +02:00
$failed = true ;
2015-10-15 22:52:37 +10:00
}
2020-03-27 13:05:05 +00:00
if ( $failed ) {
2020-03-26 19:51:58 +00:00
$information [ 'status' ] = 'FAIL' ;
}
2015-10-15 22:52:37 +10:00
2020-04-07 16:53:05 +02:00
if ( ! isset ( $information [ 'status' ] ) && ! isset ( $information [ 'error' ] ) ) {
2015-10-15 22:52:37 +10:00
$information [ 'status' ] = 'SUCCESS' ;
2020-04-07 16:53:05 +02:00
if ( 'update_user' === $action && isset ( $_POST [ 'optimize' ] ) && ! empty ( $_POST [ 'optimize' ] ) ) {
$information [ 'users' ] = $this -> get_all_users_int ( 500 );
2020-03-26 19:51:58 +00:00
}
2015-10-15 22:52:37 +10:00
}
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function edit_user ( $user_id , $data ) {
2020-04-07 19:32:01 +02:00
$wp_roles = wp_roles ();
$user = new stdClass ();
2018-09-27 19:52:32 +02:00
2020-04-07 19:32:01 +02:00
$update = true ;
2018-09-27 19:52:32 +02:00
2020-03-26 19:51:58 +00:00
if ( $user_id ) {
2020-04-07 19:32:01 +02:00
$user -> ID = ( int ) $user_id ;
$userdata = get_userdata ( $user_id );
$user -> user_login = wp_slash ( $userdata -> user_login );
2020-03-26 19:51:58 +00:00
} else {
2020-04-07 19:32:01 +02:00
return array ( 'error' => 'ERROR: Empty user id.' );
2020-03-26 19:51:58 +00:00
}
2016-10-24 20:33:37 +02:00
2020-04-07 19:32:01 +02:00
$pass1 = '' ;
$pass2 = '' ;
2020-03-26 19:51:58 +00:00
if ( isset ( $data [ 'pass1' ] ) ) {
2020-04-07 19:32:01 +02:00
$pass1 = $data [ 'pass1' ];
2020-03-26 19:51:58 +00:00
}
2020-04-07 19:32:01 +02:00
2020-03-26 19:51:58 +00:00
if ( isset ( $data [ 'pass2' ] ) ) {
$pass2 = $data [ 'pass2' ];
}
2016-10-24 20:33:37 +02:00
2020-03-26 19:51:58 +00:00
if ( isset ( $data [ 'role' ] ) && current_user_can ( 'edit_users' ) ) {
2020-04-07 19:32:01 +02:00
$new_role = sanitize_text_field ( $data [ 'role' ] );
$potential_role = isset ( $wp_roles -> role_objects [ $new_role ] ) ? $wp_roles -> role_objects [ $new_role ] : false ;
// Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
// Multisite super admins can freely edit their blog roles -- they possess all caps.
2020-04-07 18:33:47 +02:00
if ( ( is_multisite () && current_user_can ( 'manage_sites' ) ) || get_current_user_id () != $user_id || ( $potential_role && $potential_role -> has_cap ( 'edit_users' ) ) ) {
2020-03-26 19:51:58 +00:00
$user -> role = $new_role ;
}
2020-04-07 19:32:01 +02:00
// If the new role isn't editable by the logged-in user die with error.
$editable_roles = get_editable_roles ();
2020-03-26 19:51:58 +00:00
if ( ! empty ( $new_role ) && empty ( $editable_roles [ $new_role ] ) ) {
return array ( 'error' => 'You can’t give users that role.' );
}
}
2016-10-24 20:33:37 +02:00
2020-04-07 19:32:01 +02:00
$email = '' ;
2020-03-26 19:51:58 +00:00
if ( isset ( $data [ 'email' ] ) ) {
$email = trim ( $data [ 'email' ] );
}
2017-01-18 22:33:53 +01:00
2020-03-26 19:51:58 +00:00
if ( ! empty ( $email ) ) {
2020-04-07 19:32:01 +02:00
$user -> user_email = sanitize_text_field ( wp_unslash ( $email ) );
2020-03-26 19:51:58 +00:00
} else {
2020-04-07 19:32:01 +02:00
$user -> user_email = $userdata -> user_email ;
2020-03-26 19:51:58 +00:00
}
2018-09-27 19:52:32 +02:00
2020-03-26 19:51:58 +00:00
if ( isset ( $data [ 'url' ] ) ) {
2020-04-07 18:33:47 +02:00
if ( empty ( $data [ 'url' ] ) || 'http://' == $data [ 'url' ] ) {
2020-04-07 19:32:01 +02:00
$user -> user_url = '' ;
2020-03-26 19:51:58 +00:00
} else {
2020-04-07 19:32:01 +02:00
$user -> user_url = esc_url_raw ( $data [ 'url' ] );
$protocols = implode ( '|' , array_map ( 'preg_quote' , wp_allowed_protocols () ) );
$user -> user_url = preg_match ( '/^(' . $protocols . '):/is' , $user -> user_url ) ? $user -> user_url : 'http://' . $user -> user_url ;
2020-03-26 19:51:58 +00:00
}
}
2018-09-27 19:52:32 +02:00
2020-03-26 19:51:58 +00:00
if ( isset ( $data [ 'first_name' ] ) ) {
2020-04-07 19:32:01 +02:00
$user -> first_name = sanitize_text_field ( $data [ 'first_name' ] );
2020-03-26 19:51:58 +00:00
}
if ( isset ( $data [ 'last_name' ] ) ) {
2020-04-07 19:32:01 +02:00
$user -> last_name = sanitize_text_field ( $data [ 'last_name' ] );
2020-03-26 19:51:58 +00:00
}
2020-04-07 16:53:05 +02:00
if ( isset ( $data [ 'nickname' ] ) && ! empty ( $data [ 'nickname' ] ) ) {
2020-04-07 19:32:01 +02:00
$user -> nickname = sanitize_text_field ( $data [ 'nickname' ] );
2020-03-26 19:51:58 +00:00
}
if ( isset ( $data [ 'display_name' ] ) ) {
2020-04-07 19:32:01 +02:00
$user -> display_name = sanitize_text_field ( $data [ 'display_name' ] );
2020-03-26 19:51:58 +00:00
}
if ( isset ( $data [ 'description' ] ) ) {
2020-04-07 19:32:01 +02:00
$user -> description = trim ( $data [ 'description' ] );
2020-03-26 19:51:58 +00:00
}
2018-09-27 19:52:32 +02:00
2020-04-07 19:32:01 +02:00
$errors = new WP_Error ();
2016-10-24 20:33:37 +02:00
2020-04-07 17:12:41 +02:00
// checking that username has been typed.
2020-04-07 18:33:47 +02:00
if ( '' == $user -> user_login ) {
2020-04-07 19:32:01 +02:00
$errors -> add ( 'user_login' , __ ( '<strong>ERROR</strong>: Please enter a username.' ) );
2020-03-26 19:51:58 +00:00
}
2016-10-24 20:33:37 +02:00
2020-04-07 19:32:01 +02:00
do_action_ref_array ( 'check_passwords' , array ( $user -> user_login , & $pass1 , & $pass2 ) );
2018-09-27 19:52:32 +02:00
2020-04-07 16:53:05 +02:00
if ( ! empty ( $pass1 ) || ! empty ( $pass2 ) ) {
2020-03-26 19:51:58 +00:00
// Check for blank password when adding a user.
if ( ! $update && empty ( $pass1 ) ) {
2020-04-07 19:32:01 +02:00
$errors -> add ( 'pass' , __ ( '<strong>ERROR</strong>: Please enter a password.' ), array ( 'form-field' => 'pass1' ) );
2020-03-26 19:51:58 +00:00
}
// Check for "\" in password.
if ( false !== strpos ( wp_unslash ( $pass1 ), '\\' ) ) {
2020-04-07 19:32:01 +02:00
$errors -> add ( 'pass' , __ ( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array ( 'form-field' => 'pass1' ) );
2020-03-26 19:51:58 +00:00
}
// Checking the password has been typed twice the same.
if ( ( $update || ! empty ( $pass1 ) ) && $pass1 != $pass2 ) {
2020-04-07 19:32:01 +02:00
$errors -> add ( 'pass' , __ ( '<strong>ERROR</strong>: Please enter the same password in both password fields.' ), array ( 'form-field' => 'pass1' ) );
2020-03-26 19:51:58 +00:00
}
2016-10-24 20:33:37 +02:00
2020-03-26 19:51:58 +00:00
if ( ! empty ( $pass1 ) ) {
2020-04-07 19:32:01 +02:00
$user -> user_pass = $pass1 ;
2020-03-26 19:51:58 +00:00
}
} else {
2020-04-07 19:32:01 +02:00
$user -> user_pass = $userdata -> user_pass ;
2020-03-26 19:51:58 +00:00
}
2018-09-27 19:52:32 +02:00
2020-04-07 17:12:41 +02:00
$illegal_logins = ( array ) apply_filters ( 'illegal_user_logins' , array () );
2016-10-24 20:33:37 +02:00
2020-03-26 19:51:58 +00:00
if ( in_array ( strtolower ( $user -> user_login ), array_map ( 'strtolower' , $illegal_logins ) ) ) {
2020-04-07 19:32:01 +02:00
$errors -> add ( 'invalid_username' , __ ( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) );
2020-03-26 19:51:58 +00:00
}
2016-10-24 20:33:37 +02:00
2020-04-07 19:32:01 +02:00
$owner_id = email_exists ( $user -> user_email );
2020-03-26 19:51:58 +00:00
if ( empty ( $user -> user_email ) ) {
2020-04-07 19:32:01 +02:00
$errors -> add ( 'empty_email' , __ ( '<strong>ERROR</strong>: Please enter an email address.' ), array ( 'form-field' => 'email' ) );
2020-03-26 19:51:58 +00:00
} elseif ( ! is_email ( $user -> user_email ) ) {
2020-04-07 19:32:01 +02:00
$errors -> add ( 'invalid_email' , __ ( '<strong>ERROR</strong>: The email address isn’t correct.' ), array ( 'form-field' => 'email' ) );
} elseif ( ( $owner_id ) && ( ! $update || ( $owner_id != $user -> ID ) ) ) {
$errors -> add ( 'email_exists' , __ ( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ), array ( 'form-field' => 'email' ) );
2020-03-26 19:51:58 +00:00
}
2016-10-24 20:33:37 +02:00
2020-04-07 19:32:01 +02:00
do_action_ref_array ( 'user_profile_update_errors' , array ( & $errors , $update , & $user ) );
2016-10-24 20:33:37 +02:00
2020-03-26 19:51:58 +00:00
if ( $errors -> get_error_codes () ) {
$error_str = '' ;
foreach ( $errors -> get_error_messages () as $message ) {
if ( is_string ( $message ) ) {
2020-04-22 19:00:01 +02:00
$error_str .= ' ' . esc_html ( wp_strip_all_tags ( $message ) );
2020-03-26 19:51:58 +00:00
}
}
return array ( 'error' => $error_str );
}
2016-10-24 20:33:37 +02:00
2020-04-07 19:32:01 +02:00
$user_id = wp_update_user ( $user );
2018-09-27 19:52:32 +02:00
2020-04-07 19:32:01 +02:00
return $user_id ;
2020-03-26 19:51:58 +00:00
}
2018-09-27 19:52:32 +02:00
2020-04-07 19:04:20 +02:00
public function get_user_to_edit ( $user_id ) {
2020-03-26 19:51:58 +00:00
require_once ABSPATH . 'wp-admin/includes/user.php' ;
2020-04-07 16:53:05 +02:00
$profileuser = get_user_to_edit ( $user_id );
2016-10-24 20:33:37 +02:00
2020-03-26 19:51:58 +00:00
$edit_data = array ();
2020-04-07 16:53:05 +02:00
if ( is_object ( $profileuser ) ) {
2020-03-26 19:51:58 +00:00
$user_roles = array_intersect ( array_values ( $profileuser -> roles ), array_keys ( get_editable_roles () ) );
$user_role = reset ( $user_roles );
$edit_data [ 'role' ] = $user_role ;
$edit_data [ 'first_name' ] = $profileuser -> first_name ;
$edit_data [ 'last_name' ] = $profileuser -> last_name ;
$edit_data [ 'nickname' ] = $profileuser -> nickname ;
2016-10-24 20:33:37 +02:00
2020-03-26 19:51:58 +00:00
$public_display = array ();
$public_display [ 'display_nickname' ] = $profileuser -> nickname ;
$public_display [ 'display_username' ] = $profileuser -> user_login ;
2016-10-24 20:33:37 +02:00
2020-04-07 16:53:05 +02:00
if ( ! empty ( $profileuser -> first_name ) ) {
2020-03-26 19:51:58 +00:00
$public_display [ 'display_firstname' ] = $profileuser -> first_name ;
}
2016-10-24 20:33:37 +02:00
2020-04-07 16:53:05 +02:00
if ( ! empty ( $profileuser -> last_name ) ) {
2020-03-26 19:51:58 +00:00
$public_display [ 'display_lastname' ] = $profileuser -> last_name ;
}
2016-10-24 20:33:37 +02:00
2020-04-07 16:53:05 +02:00
if ( ! empty ( $profileuser -> first_name ) && ! empty ( $profileuser -> last_name ) ) {
2020-03-26 19:51:58 +00:00
$public_display [ 'display_firstlast' ] = $profileuser -> first_name . ' ' . $profileuser -> last_name ;
$public_display [ 'display_lastfirst' ] = $profileuser -> last_name . ' ' . $profileuser -> first_name ;
}
2020-04-07 16:53:05 +02:00
if ( ! in_array ( $profileuser -> display_name , $public_display ) ) { // Only add this if it isn't duplicated elsewhere!
2020-03-26 19:51:58 +00:00
$public_display = array ( 'display_displayname' => $profileuser -> display_name ) + $public_display ;
}
$public_display = array_map ( 'trim' , $public_display );
$public_display = array_unique ( $public_display );
$edit_data [ 'public_display' ] = $public_display ;
$edit_data [ 'display_name' ] = $profileuser -> display_name ;
$edit_data [ 'user_email' ] = $profileuser -> user_email ;
$edit_data [ 'user_url' ] = $profileuser -> user_url ;
foreach ( wp_get_user_contact_methods ( $profileuser ) as $name => $desc ) {
$edit_data [ 'contact_methods' ][ $name ] = $profileuser -> $name ;
}
$edit_data [ 'description' ] = $profileuser -> description ;
}
return $edit_data ;
}
2018-09-27 19:52:32 +02:00
2020-04-07 19:04:20 +02:00
public function comment_action () {
2015-10-15 22:52:37 +10:00
$action = $_POST [ 'action' ];
$commentId = $_POST [ 'id' ];
if ( 'approve' === $action ) {
wp_set_comment_status ( $commentId , 'approve' );
2020-03-26 14:11:33 +00:00
} elseif ( 'unapprove' === $action ) {
2015-10-15 22:52:37 +10:00
wp_set_comment_status ( $commentId , 'hold' );
2020-03-26 14:11:33 +00:00
} elseif ( 'spam' === $action ) {
2015-10-15 22:52:37 +10:00
wp_spam_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'unspam' === $action ) {
2015-10-15 22:52:37 +10:00
wp_unspam_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'trash' === $action ) {
2015-10-15 22:52:37 +10:00
add_action ( 'trashed_comment' , array ( 'MainWP_Child_Links_Checker' , 'hook_trashed_comment' ), 10 , 1 );
wp_trash_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'restore' === $action ) {
2015-10-15 22:52:37 +10:00
wp_untrash_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'delete' === $action ) {
2015-10-15 22:52:37 +10:00
wp_delete_comment ( $commentId , true );
} else {
$information [ 'status' ] = 'FAIL' ;
}
if ( ! isset ( $information [ 'status' ] ) ) {
$information [ 'status' ] = 'SUCCESS' ;
}
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function comment_bulk_action () {
2015-10-15 22:52:37 +10:00
$action = $_POST [ 'action' ];
$commentIds = explode ( ',' , $_POST [ 'ids' ] );
$information [ 'success' ] = 0 ;
foreach ( $commentIds as $commentId ) {
if ( $commentId ) {
$information [ 'success' ] ++ ;
if ( 'approve' === $action ) {
wp_set_comment_status ( $commentId , 'approve' );
2020-03-26 14:11:33 +00:00
} elseif ( 'unapprove' === $action ) {
2015-10-15 22:52:37 +10:00
wp_set_comment_status ( $commentId , 'hold' );
2020-03-26 14:11:33 +00:00
} elseif ( 'spam' === $action ) {
2015-10-15 22:52:37 +10:00
wp_spam_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'unspam' === $action ) {
2015-10-15 22:52:37 +10:00
wp_unspam_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'trash' === $action ) {
2015-10-15 22:52:37 +10:00
wp_trash_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'restore' === $action ) {
2015-10-15 22:52:37 +10:00
wp_untrash_comment ( $commentId );
2020-03-26 14:11:33 +00:00
} elseif ( 'delete' === $action ) {
2015-10-15 22:52:37 +10:00
wp_delete_comment ( $commentId , true );
} else {
$information [ 'success' ] -- ;
}
}
}
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function new_admin_password () {
2020-04-07 19:32:01 +02:00
$new_password = maybe_unserialize ( base64_decode ( $_POST [ 'new_password' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$user = get_user_by ( 'login' , $_POST [ 'user' ] );
2020-03-26 14:11:33 +00:00
require_once ABSPATH . WPINC . '/registration.php' ;
2015-10-15 22:52:37 +10:00
2020-04-07 17:12:41 +02:00
$id = wp_update_user (
array (
'ID' => $user -> ID ,
'user_pass' => $new_password [ 'user_pass' ],
)
);
2015-10-15 22:52:37 +10:00
if ( $id !== $user -> ID ) {
if ( is_wp_error ( $id ) ) {
MainWP_Helper :: error ( $id -> get_error_message () );
} else {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'Administrator password could not be changed.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
}
$information [ 'added' ] = true ;
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function new_user () {
2020-04-07 19:32:01 +02:00
$new_user = maybe_unserialize ( base64_decode ( $_POST [ 'new_user' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$send_password = $_POST [ 'send_password' ];
2020-03-27 13:05:05 +00:00
if ( isset ( $new_user [ 'role' ] ) ) {
2020-03-26 17:03:00 +00:00
if ( ! get_role ( $new_user [ 'role' ] ) ) {
2019-11-11 23:17:10 +07:00
$new_user [ 'role' ] = 'subscriber' ;
}
}
2015-10-15 22:52:37 +10:00
$new_user_id = wp_insert_user ( $new_user );
if ( is_wp_error ( $new_user_id ) ) {
MainWP_Helper :: error ( $new_user_id -> get_error_message () );
}
if ( 0 === $new_user_id ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'Undefined error!' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
if ( $send_password ) {
$user = new WP_User ( $new_user_id );
$user_login = stripslashes ( $user -> user_login );
$user_email = stripslashes ( $user -> user_email );
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2020-03-26 19:45:07 +00:00
$message = sprintf ( __ ( 'Username: %s' ), $user_login ) . " \r \n " ;
2015-10-15 22:52:37 +10:00
$message .= sprintf ( __ ( 'Password: %s' ), $new_user [ 'user_pass' ] ) . " \r \n " ;
$message .= wp_login_url () . " \r \n " ;
2020-04-23 19:16:35 +02:00
wp_mail ( $user_email , sprintf ( __ ( '[%s] Your username and password' ), $blogname ), $message , '' );
2015-10-15 22:52:37 +10:00
}
$information [ 'added' ] = true ;
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function cloneinfo () {
2015-10-15 22:52:37 +10:00
global $table_prefix ;
$information [ 'dbCharset' ] = DB_CHARSET ;
$information [ 'dbCollate' ] = DB_COLLATE ;
$information [ 'table_prefix' ] = $table_prefix ;
$information [ 'site_url' ] = get_option ( 'site_url' );
$information [ 'home' ] = get_option ( 'home' );
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function backup_poll () {
2015-10-15 22:52:37 +10:00
$fileNameUID = ( isset ( $_POST [ 'fileNameUID' ] ) ? $_POST [ 'fileNameUID' ] : '' );
$fileName = ( isset ( $_POST [ 'fileName' ] ) ? $_POST [ 'fileName' ] : '' );
if ( 'full' === $_POST [ 'type' ] ) {
if ( '' !== $fileName ) {
$backupFile = $fileName ;
} else {
$backupFile = 'backup-' . $fileNameUID . '-' ;
}
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
$result = glob ( $backupdir . $backupFile . '*' );
$archiveFile = false ;
foreach ( $result as $file ) {
2020-05-06 00:47:59 +07:00
if ( MainWP_Helper :: is_archive ( $file , $backupFile , '(.*)' ) ) {
2015-10-15 22:52:37 +10:00
$archiveFile = $file ;
break ;
}
}
if ( false === $archiveFile ) {
MainWP_Helper :: write ( array () );
}
MainWP_Helper :: write ( array ( 'size' => filesize ( $archiveFile ) ) );
} else {
$backupFile = 'dbBackup-' . $fileNameUID . '-*.sql' ;
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
$result = glob ( $backupdir . $backupFile . '*' );
if ( 0 === count ( $result ) ) {
MainWP_Helper :: write ( array () );
}
2015-12-22 19:18:07 +01:00
$size = 0 ;
foreach ( $result as $f ) {
2020-04-07 16:53:05 +02:00
$size += filesize ( $f );
2015-12-22 19:18:07 +01:00
}
MainWP_Helper :: write ( array ( 'size' => $size ) );
2015-10-15 22:52:37 +10:00
exit ();
}
}
2020-04-07 19:04:20 +02:00
public function backup_checkpid () {
2015-10-15 22:52:37 +10:00
$pid = $_POST [ 'pid' ];
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
$information = array ();
/** @var $wp_filesystem WP_Filesystem_Base */
global $wp_filesystem ;
2020-05-06 00:47:59 +07:00
MainWP_Helper :: get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
$pidFile = trailingslashit ( $backupdir ) . 'backup-' . $pid . '.pid' ;
$doneFile = trailingslashit ( $backupdir ) . 'backup-' . $pid . '.done' ;
if ( $wp_filesystem -> is_file ( $pidFile ) ) {
$time = $wp_filesystem -> mtime ( $pidFile );
$minutes = date ( 'i' , time () );
$seconds = date ( 's' , time () );
$file_minutes = date ( 'i' , $time );
$file_seconds = date ( 's' , $time );
$minuteDiff = $minutes - $file_minutes ;
if ( 59 === $minuteDiff ) {
$minuteDiff = 1 ;
}
$secondsdiff = ( $minuteDiff * 60 ) + $seconds - $file_seconds ;
$file = $wp_filesystem -> get_contents ( $pidFile );
$information [ 'file' ] = basename ( $file );
if ( $secondsdiff < 80 ) {
$information [ 'status' ] = 'busy' ;
} else {
$information [ 'status' ] = 'stalled' ;
}
2020-03-26 14:11:33 +00:00
} elseif ( $wp_filesystem -> is_file ( $doneFile ) ) {
2015-10-15 22:52:37 +10:00
$file = $wp_filesystem -> get_contents ( $doneFile );
$information [ 'status' ] = 'done' ;
$information [ 'file' ] = basename ( $file );
2020-04-23 19:16:35 +02:00
$information [ 'size' ] = filesize ( $file );
2015-10-15 22:52:37 +10:00
} else {
$information [ 'status' ] = 'invalid' ;
}
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function backup ( $pWrite = true ) {
2020-04-07 18:33:47 +02:00
$timeout = 20 * 60 * 60 ;
2020-04-23 19:16:35 +02:00
set_time_limit ( $timeout );
ini_set ( 'max_execution_time' , $timeout );
2020-05-06 00:47:59 +07:00
MainWP_Helper :: end_session ();
2015-10-15 22:52:37 +10:00
2020-03-26 20:01:04 +00:00
// Cleanup pid files!
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = trailingslashit ( $dirs [ 0 ] );
/** @var $wp_filesystem WP_Filesystem_Base */
global $wp_filesystem ;
2020-05-06 00:47:59 +07:00
MainWP_Helper :: get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
$files = glob ( $backupdir . '*' );
foreach ( $files as $file ) {
2020-05-06 00:47:59 +07:00
if ( MainWP_Helper :: ends_with ( $file , '/index.php' ) | MainWP_Helper :: ends_with ( $file , '/.htaccess' ) ) {
2015-10-15 22:52:37 +10:00
continue ;
}
if ( ( time () - filemtime ( $file ) ) > ( 60 * 60 * 3 ) ) {
2020-04-23 19:16:35 +02:00
unlink ( $file );
2015-10-15 22:52:37 +10:00
}
}
$fileName = ( isset ( $_POST [ 'fileUID' ] ) ? $_POST [ 'fileUID' ] : '' );
if ( 'full' === $_POST [ 'type' ] ) {
$excludes = ( isset ( $_POST [ 'exclude' ] ) ? explode ( ',' , $_POST [ 'exclude' ] ) : array () );
$excludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/uploads/mainwp' ;
2020-05-06 00:47:59 +07:00
$uploadDir = MainWP_Helper :: get_mainwp_dir ();
2015-10-15 22:52:37 +10:00
$uploadDir = $uploadDir [ 0 ];
$excludes [] = str_replace ( ABSPATH , '' , $uploadDir );
$excludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/object-cache.php' ;
if ( function_exists ( 'posix_uname' ) ) {
2020-04-23 19:16:35 +02:00
$uname = posix_uname ();
2015-10-15 22:52:37 +10:00
if ( is_array ( $uname ) && isset ( $uname [ 'nodename' ] ) ) {
if ( stristr ( $uname [ 'nodename' ], 'hostgator' ) ) {
2015-12-09 20:32:56 +01:00
if ( ! isset ( $_POST [ 'file_descriptors' ] ) || '0' == $_POST [ 'file_descriptors' ] || $_POST [ 'file_descriptors' ] > 1000 ) {
2015-10-15 22:52:37 +10:00
$_POST [ 'file_descriptors' ] = 1000 ;
}
$_POST [ 'file_descriptors_auto' ] = 0 ;
$_POST [ 'loadFilesBeforeZip' ] = false ;
}
}
}
$file_descriptors = ( isset ( $_POST [ 'file_descriptors' ] ) ? $_POST [ 'file_descriptors' ] : 0 );
$file_descriptors_auto = ( isset ( $_POST [ 'file_descriptors_auto' ] ) ? $_POST [ 'file_descriptors_auto' ] : 0 );
if ( 1 === ( int ) $file_descriptors_auto ) {
if ( function_exists ( 'posix_getrlimit' ) ) {
2020-04-23 19:16:35 +02:00
$result = posix_getrlimit ();
2015-10-15 22:52:37 +10:00
if ( isset ( $result [ 'soft openfiles' ] ) ) {
$file_descriptors = $result [ 'soft openfiles' ];
}
}
}
$loadFilesBeforeZip = ( isset ( $_POST [ 'loadFilesBeforeZip' ] ) ? $_POST [ 'loadFilesBeforeZip' ] : true );
$newExcludes = array ();
foreach ( $excludes as $exclude ) {
$newExcludes [] = rtrim ( $exclude , '/' );
}
2015-12-09 20:32:56 +01:00
$excludebackup = ( isset ( $_POST [ 'excludebackup' ] ) && '1' == $_POST [ 'excludebackup' ] );
$excludecache = ( isset ( $_POST [ 'excludecache' ] ) && '1' == $_POST [ 'excludecache' ] );
$excludezip = ( isset ( $_POST [ 'excludezip' ] ) && '1' == $_POST [ 'excludezip' ] );
$excludenonwp = ( isset ( $_POST [ 'excludenonwp' ] ) && '1' == $_POST [ 'excludenonwp' ] );
2015-10-15 22:52:37 +10:00
if ( $excludebackup ) {
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/uploads/backupbuddy_backups' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/uploads/backupbuddy_temp' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/uploads/pb_backupbuddy' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/managewp' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/infinitewp' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/backups' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/backups' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/uploads/backwpup*' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/plugins/wp-complete-backup/storage' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/backups' ;
$newExcludes [] = '/administrator/backups' ;
}
if ( $excludecache ) {
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/w3tc-cache' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/w3tc' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/config' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/minify' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/page_enhanced' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/tmp' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/supercache' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/quick-cache' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/hyper-cache/cache' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/all' ;
$newExcludes [] = str_replace ( ABSPATH , '' , WP_CONTENT_DIR ) . '/cache/wp-rocket' ;
}
$file = false ;
if ( isset ( $_POST [ 'f' ] ) ) {
$file = $_POST [ 'f' ];
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_POST [ 'file' ] ) ) {
2015-10-15 22:52:37 +10:00
$file = $_POST [ 'file' ];
}
$ext = 'zip' ;
if ( isset ( $_POST [ 'ext' ] ) ) {
$ext = $_POST [ 'ext' ];
}
$pid = false ;
if ( isset ( $_POST [ 'pid' ] ) ) {
$pid = $_POST [ 'pid' ];
}
2015-12-09 20:32:56 +01:00
$append = ( isset ( $_POST [ 'append' ] ) && ( '1' == $_POST [ 'append' ] ) );
2015-10-15 22:52:37 +10:00
2020-05-06 20:22:11 +07:00
$res = MainWP_Backup :: get () -> create_full_backup ( $newExcludes , $fileName , true , true , $file_descriptors , $file , $excludezip , $excludenonwp , $loadFilesBeforeZip , $ext , $pid , $append );
2015-10-15 22:52:37 +10:00
if ( ! $res ) {
$information [ 'full' ] = false ;
} else {
$information [ 'full' ] = $res [ 'file' ];
$information [ 'size' ] = $res [ 'filesize' ];
}
$information [ 'db' ] = false ;
2020-03-26 14:11:33 +00:00
} elseif ( 'db' == $_POST [ 'type' ] ) {
2015-10-15 22:52:37 +10:00
$ext = 'zip' ;
if ( isset ( $_POST [ 'ext' ] ) ) {
$ext = $_POST [ 'ext' ];
}
2020-05-06 00:47:59 +07:00
$res = $this -> backup_db ( $fileName , $ext );
2015-10-15 22:52:37 +10:00
if ( ! $res ) {
$information [ 'db' ] = false ;
} else {
$information [ 'db' ] = $res [ 'file' ];
$information [ 'size' ] = $res [ 'filesize' ];
}
$information [ 'full' ] = false ;
} else {
$information [ 'full' ] = false ;
$information [ 'db' ] = false ;
}
if ( $pWrite ) {
MainWP_Helper :: write ( $information );
}
return $information ;
}
2020-05-06 00:47:59 +07:00
protected function backup_db ( $fileName = '' , $ext = 'zip' ) {
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$dir = $dirs [ 0 ];
$timestamp = time ();
2015-12-22 19:18:07 +01:00
2015-10-15 22:52:37 +10:00
if ( '' !== $fileName ) {
$fileName .= '-' ;
}
2015-12-22 19:18:07 +01:00
$filepath_prefix = $dir . 'dbBackup-' . $fileName . $timestamp ;
2015-10-15 22:52:37 +10:00
2020-04-07 19:32:01 +02:00
$dh = opendir ( $dir );
if ( $dh ) {
2015-10-15 22:52:37 +10:00
while ( ( $file = readdir ( $dh ) ) !== false ) {
2015-12-22 19:18:07 +01:00
if ( '.' !== $file && '..' !== $file && ( preg_match ( '/dbBackup-(.*).sql(\.zip|\.tar|\.tar\.gz|\.tar\.bz2|\.tmp)?$/' , $file ) ) ) {
2020-04-23 19:16:35 +02:00
unlink ( $dir . $file );
2015-10-15 22:52:37 +10:00
}
}
closedir ( $dh );
}
2020-05-06 20:22:11 +07:00
$result = MainWP_Backup :: get () -> create_backup_db ( $filepath_prefix , $ext );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_last_db_backup_size' , filesize ( $result [ 'filepath' ] ) );
return ( ! $result ) ? false : array (
'timestamp' => $timestamp ,
'file' => basename ( $result [ 'filepath' ] ),
'filesize' => filesize ( $result [ 'filepath' ] ),
);
}
2020-05-06 00:47:59 +07:00
public function do_security_fix () {
2015-10-15 22:52:37 +10:00
$sync = false ;
if ( 'all' === $_POST [ 'feature' ] ) {
$sync = true ;
}
$information = array ();
$security = get_option ( 'mainwp_security' );
if ( ! is_array ( $security ) ) {
$security = array ();
}
if ( 'all' === $_POST [ 'feature' ] || 'listing' === $_POST [ 'feature' ] ) {
MainWP_Security :: prevent_listing ();
$information [ 'listing' ] = ( ! MainWP_Security :: prevent_listing_ok () ? 'N' : 'Y' );
}
if ( 'all' === $_POST [ 'feature' ] || 'wp_version' === $_POST [ 'feature' ] ) {
$security [ 'wp_version' ] = true ;
MainWP_Security :: remove_wp_version ( true );
$information [ 'wp_version' ] = ( ! MainWP_Security :: remove_wp_version_ok () ? 'N' : 'Y' );
}
if ( 'all' === $_POST [ 'feature' ] || 'rsd' === $_POST [ 'feature' ] ) {
$security [ 'rsd' ] = true ;
MainWP_Security :: remove_rsd ( true );
$information [ 'rsd' ] = ( ! MainWP_Security :: remove_rsd_ok () ? 'N' : 'Y' );
}
if ( 'all' === $_POST [ 'feature' ] || 'wlw' === $_POST [ 'feature' ] ) {
$security [ 'wlw' ] = true ;
MainWP_Security :: remove_wlw ( true );
$information [ 'wlw' ] = ( ! MainWP_Security :: remove_wlw_ok () ? 'N' : 'Y' );
}
if ( 'all' === $_POST [ 'feature' ] || 'db_reporting' === $_POST [ 'feature' ] ) {
MainWP_Security :: remove_database_reporting ();
$information [ 'db_reporting' ] = ( ! MainWP_Security :: remove_database_reporting_ok () ? 'N' : 'Y' );
}
if ( 'all' === $_POST [ 'feature' ] || 'php_reporting' === $_POST [ 'feature' ] ) {
$security [ 'php_reporting' ] = true ;
MainWP_Security :: remove_php_reporting ( true );
$information [ 'php_reporting' ] = ( ! MainWP_Security :: remove_php_reporting_ok () ? 'N' : 'Y' );
}
if ( 'all' === $_POST [ 'feature' ] || 'versions' === $_POST [ 'feature' ] ) {
2020-03-26 19:45:07 +00:00
$security [ 'scripts_version' ] = true ;
$security [ 'styles_version' ] = true ;
$security [ 'generator_version' ] = true ;
2016-02-15 22:08:39 +01:00
MainWP_Security :: remove_generator_version ( true );
$information [ 'versions' ] = 'Y' ;
2015-10-15 22:52:37 +10:00
}
2020-03-27 15:13:11 +00:00
if ( 'all' === $_POST [ 'feature' ] || 'registered_versions' === $_POST [ 'feature' ] ) {
2020-03-26 19:45:07 +00:00
$security [ 'registered_versions' ] = true ;
2018-09-27 19:52:32 +02:00
$information [ 'registered_versions' ] = 'Y' ;
}
2015-10-15 22:52:37 +10:00
if ( 'all' === $_POST [ 'feature' ] || 'admin' === $_POST [ 'feature' ] ) {
$information [ 'admin' ] = ( ! MainWP_Security :: admin_user_ok () ? 'N' : 'Y' );
}
if ( 'all' === $_POST [ 'feature' ] || 'readme' === $_POST [ 'feature' ] ) {
$security [ 'readme' ] = true ;
MainWP_Security :: remove_readme ( true );
$information [ 'readme' ] = ( MainWP_Security :: remove_readme_ok () ? 'Y' : 'N' );
}
MainWP_Helper :: update_option ( 'mainwp_security' , $security , 'yes' );
if ( $sync ) {
2020-05-06 00:47:59 +07:00
$information [ 'sync' ] = $this -> get_site_stats ( array (), false );
2015-10-15 22:52:37 +10:00
}
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function do_security_un_fix () {
2015-10-15 22:52:37 +10:00
$information = array ();
$sync = false ;
if ( 'all' === $_POST [ 'feature' ] ) {
$sync = true ;
}
$security = get_option ( 'mainwp_security' );
if ( 'all' === $_POST [ 'feature' ] || 'wp_version' === $_POST [ 'feature' ] ) {
$security [ 'wp_version' ] = false ;
$information [ 'wp_version' ] = 'N' ;
}
if ( 'all' === $_POST [ 'feature' ] || 'rsd' === $_POST [ 'feature' ] ) {
$security [ 'rsd' ] = false ;
$information [ 'rsd' ] = 'N' ;
}
if ( 'all' === $_POST [ 'feature' ] || 'wlw' === $_POST [ 'feature' ] ) {
$security [ 'wlw' ] = false ;
$information [ 'wlw' ] = 'N' ;
}
if ( 'all' === $_POST [ 'feature' ] || 'php_reporting' === $_POST [ 'feature' ] ) {
$security [ 'php_reporting' ] = false ;
$information [ 'php_reporting' ] = 'N' ;
}
if ( 'all' === $_POST [ 'feature' ] || 'versions' === $_POST [ 'feature' ] ) {
2020-03-26 19:45:07 +00:00
$security [ 'scripts_version' ] = false ;
$security [ 'styles_version' ] = false ;
$security [ 'generator_version' ] = false ;
$information [ 'versions' ] = 'N' ;
2015-10-15 22:52:37 +10:00
}
2020-03-27 15:13:11 +00:00
if ( 'all' === $_POST [ 'feature' ] || 'registered_versions' === $_POST [ 'feature' ] ) {
2020-03-26 19:45:07 +00:00
$security [ 'registered_versions' ] = false ;
2018-09-27 19:52:32 +02:00
$information [ 'registered_versions' ] = 'N' ;
}
2015-10-15 22:52:37 +10:00
if ( 'all' === $_POST [ 'feature' ] || 'readme' === $_POST [ 'feature' ] ) {
$security [ 'readme' ] = false ;
$information [ 'readme' ] = MainWP_Security :: remove_readme_ok ();
}
MainWP_Helper :: update_option ( 'mainwp_security' , $security , 'yes' );
if ( $sync ) {
2020-05-06 00:47:59 +07:00
$information [ 'sync' ] = $this -> get_site_stats ( array (), false );
2015-10-15 22:52:37 +10:00
}
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function get_security_stats () {
2015-10-15 22:52:37 +10:00
$information = array ();
2020-04-07 19:32:01 +02:00
$information [ 'listing' ] = ( ! MainWP_Security :: prevent_listing_ok () ? 'N' : 'Y' );
$information [ 'wp_version' ] = ( ! MainWP_Security :: remove_wp_version_ok () ? 'N' : 'Y' );
$information [ 'rsd' ] = ( ! MainWP_Security :: remove_rsd_ok () ? 'N' : 'Y' );
$information [ 'wlw' ] = ( ! MainWP_Security :: remove_wlw_ok () ? 'N' : 'Y' );
2020-03-26 19:45:07 +00:00
$information [ 'db_reporting' ] = ( ! MainWP_Security :: remove_database_reporting_ok () ? 'N' : 'Y' );
$information [ 'php_reporting' ] = ( ! MainWP_Security :: remove_php_reporting_ok () ? 'N' : 'Y' );
2020-04-07 19:32:01 +02:00
$information [ 'versions' ] = ( ! MainWP_Security :: remove_scripts_version_ok () || ! MainWP_Security :: remove_styles_version_ok () || ! MainWP_Security :: remove_generator_version_ok () ? 'N' : 'Y' );
2020-03-27 15:13:11 +00:00
$information [ 'registered_versions' ] = ( MainWP_Security :: remove_registered_versions_ok () ? 'Y' : 'N' );
2020-03-26 19:45:07 +00:00
$information [ 'admin' ] = ( MainWP_Security :: admin_user_ok () ? 'Y' : 'N' );
$information [ 'readme' ] = ( MainWP_Security :: remove_readme_ok () ? 'Y' : 'N' );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function update_external_settings () {
2015-10-15 22:52:37 +10:00
$update_htaccess = false ;
if ( isset ( $_POST [ 'cloneSites' ] ) ) {
if ( '0' !== $_POST [ 'cloneSites' ] ) {
2020-04-23 19:16:35 +02:00
$arr = json_decode ( urldecode ( $_POST [ 'cloneSites' ] ), 1 );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_clone_sites' , ( ! is_array ( $arr ) ? array () : $arr ) );
} else {
MainWP_Helper :: update_option ( 'mainwp_child_clone_sites' , '0' );
}
}
2020-02-03 22:55:50 +07:00
if ( isset ( $_POST [ 'siteId' ] ) ) {
2020-04-07 16:53:05 +02:00
MainWP_Helper :: update_option ( 'mainwp_child_siteid' , intval ( $_POST [ 'siteId' ] ) );
2020-01-17 19:42:57 +07:00
}
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'pluginDir' ] ) ) {
if ( get_option ( 'mainwp_child_pluginDir' ) !== $_POST [ 'pluginDir' ] ) {
MainWP_Helper :: update_option ( 'mainwp_child_pluginDir' , $_POST [ 'pluginDir' ], 'yes' );
$update_htaccess = true ;
}
2020-03-26 14:11:33 +00:00
} elseif ( false !== get_option ( 'mainwp_child_pluginDir' ) ) {
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_pluginDir' , false , 'yes' );
$update_htaccess = true ;
}
if ( $update_htaccess ) {
$this -> update_htaccess ( true );
}
}
2020-04-07 18:33:47 +02:00
// Show stats.
2020-05-06 00:47:59 +07:00
public function get_site_stats ( $information = array (), $exit = true ) {
2015-10-15 22:52:37 +10:00
global $wp_version ;
if ( $exit ) {
2020-05-06 00:47:59 +07:00
$this -> update_external_settings ();
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
MainWP_Child_Branding :: instance () -> save_branding_options ( 'branding_disconnected' , '' );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_branding_disconnected' , '' , 'yes' );
if ( isset ( $_POST [ 'server' ] ) ) {
MainWP_Helper :: update_option ( 'mainwp_child_server' , $_POST [ 'server' ] );
}
2019-02-14 22:38:14 +07:00
if ( isset ( $_POST [ 'numberdaysOutdatePluginTheme' ] ) ) {
2015-10-15 22:52:37 +10:00
$days_outdate = get_option ( 'mainwp_child_plugintheme_days_outdate' , 365 );
2019-02-14 22:38:14 +07:00
if ( $days_outdate != $_POST [ 'numberdaysOutdatePluginTheme' ] ) {
2020-04-07 16:53:05 +02:00
$days_outdate = intval ( $_POST [ 'numberdaysOutdatePluginTheme' ] );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_plugintheme_days_outdate' , $days_outdate );
2020-05-06 20:22:11 +07:00
MainWP_Child_Plugins_Check :: instance () -> cleanup_deactivation ( false );
MainWP_Child_Themes_Check :: instance () -> cleanup_deactivation ( false );
2015-10-15 22:52:37 +10:00
}
}
2015-12-12 18:39:23 +01:00
$information [ 'version' ] = self :: $version ;
2015-10-15 22:52:37 +10:00
$information [ 'wpversion' ] = $wp_version ;
$information [ 'siteurl' ] = get_option ( 'siteurl' );
2020-03-26 19:45:07 +00:00
$information [ 'wpe' ] = MainWP_Helper :: is_wp_engine () ? 1 : 0 ;
$theme_name = wp_get_theme () -> get ( 'Name' );
2020-03-27 15:13:11 +00:00
$information [ 'site_info' ] = array (
'wpversion' => $wp_version ,
2020-04-07 16:53:05 +02:00
'debug_mode' => ( defined ( 'WP_DEBUG' ) && true === WP_DEBUG ) ? true : false ,
2020-03-27 15:13:11 +00:00
'phpversion' => phpversion (),
'child_version' => self :: $version ,
2020-05-06 20:22:11 +07:00
'memory_limit' => MainWP_Child_Server_Information :: get_php_memory_limit (),
'mysql_version' => MainWP_Child_Server_Information :: get_my_sql_version (),
2019-12-09 22:02:19 +07:00
'themeactivated' => $theme_name ,
2020-03-27 15:13:11 +00:00
'ip' => $_SERVER [ 'SERVER_ADDR' ],
);
2017-01-14 13:16:52 +01:00
2020-03-26 20:01:04 +00:00
// Try to switch to SSL if SSL is enabled in between!
2016-12-25 14:38:20 +01:00
$pubkey = get_option ( 'mainwp_child_pubkey' );
2020-03-26 19:45:07 +00:00
$nossl = get_option ( 'mainwp_child_nossl' );
2020-03-26 17:03:00 +00:00
if ( 1 == $nossl ) {
2020-05-06 00:47:59 +07:00
if ( isset ( $pubkey ) && MainWP_Helper :: is_ssl_enabled () ) {
2016-12-25 14:38:20 +01:00
MainWP_Helper :: update_option ( 'mainwp_child_nossl' , 0 , 'yes' );
$nossl = 0 ;
}
}
2020-03-26 19:45:07 +00:00
$information [ 'nossl' ] = ( 1 == $nossl ? 1 : 0 );
2015-10-15 22:52:37 +10:00
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/update.php' ;
2015-10-15 22:52:37 +10:00
2020-04-07 18:33:47 +02:00
$timeout = 3 * 60 * 60 ;
2020-04-23 19:16:35 +02:00
set_time_limit ( $timeout );
ini_set ( 'max_execution_time' , $timeout );
2015-10-15 22:52:37 +10:00
2020-04-07 18:33:47 +02:00
// Check for new versions.
2015-10-15 22:52:37 +10:00
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_site_transient_update_core' , $this -> filterFunction , 99 );
}
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_transient_update_core' , $this -> filterFunction , 99 );
}
2020-04-23 19:16:35 +02:00
wp_version_check ();
2015-10-15 22:52:37 +10:00
$core_updates = get_core_updates ();
2020-04-07 16:53:05 +02:00
if ( is_array ( $core_updates ) && count ( $core_updates ) > 0 ) {
2015-10-15 22:52:37 +10:00
foreach ( $core_updates as $core_update ) {
if ( 'latest' === $core_update -> response ) {
break ;
}
if ( 'upgrade' === $core_update -> response && version_compare ( $wp_version , $core_update -> current , '<=' ) ) {
$information [ 'wp_updates' ] = $core_update -> current ;
}
}
}
if ( ! isset ( $information [ 'wp_updates' ] ) ) {
$information [ 'wp_updates' ] = null ;
}
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_site_transient_update_core' , $this -> filterFunction , 99 );
}
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_transient_update_core' , $this -> filterFunction , 99 );
}
add_filter ( 'default_option_active_plugins' , array ( & $this , 'default_option_active_plugins' ) );
add_filter ( 'option_active_plugins' , array ( & $this , 'default_option_active_plugins' ) );
2020-04-07 17:12:41 +02:00
// First check for new premium updates.
2015-10-15 22:52:37 +10:00
$update_check = apply_filters ( 'mwp_premium_update_check' , array () );
if ( ! empty ( $update_check ) ) {
foreach ( $update_check as $updateFeedback ) {
if ( is_array ( $updateFeedback [ 'callback' ] ) && isset ( $updateFeedback [ 'callback' ][ 0 ] ) && isset ( $updateFeedback [ 'callback' ][ 1 ] ) ) {
2020-04-23 19:16:35 +02:00
call_user_func ( array ( $updateFeedback [ 'callback' ][ 0 ], $updateFeedback [ 'callback' ][ 1 ] ) );
2020-03-26 14:11:33 +00:00
} elseif ( is_string ( $updateFeedback [ 'callback' ] ) ) {
2020-04-23 19:16:35 +02:00
call_user_func ( $updateFeedback [ 'callback' ] );
2015-10-15 22:52:37 +10:00
}
}
}
$informationPremiumUpdates = apply_filters ( 'mwp_premium_update_notification' , array () );
$premiumPlugins = array ();
$premiumThemes = array ();
if ( is_array ( $informationPremiumUpdates ) ) {
2020-03-26 19:45:07 +00:00
$premiumUpdates = array ();
$information [ 'premium_updates' ] = array ();
2015-10-15 22:52:37 +10:00
$informationPremiumUpdatesLength = count ( $informationPremiumUpdates );
for ( $i = 0 ; $i < $informationPremiumUpdatesLength ; $i ++ ) {
if ( ! isset ( $informationPremiumUpdates [ $i ][ 'new_version' ] ) ) {
continue ;
}
$slug = ( isset ( $informationPremiumUpdates [ $i ][ 'slug' ] ) ? $informationPremiumUpdates [ $i ][ 'slug' ] : $informationPremiumUpdates [ $i ][ 'Name' ] );
if ( 'plugin' === $informationPremiumUpdates [ $i ][ 'type' ] ) {
$premiumPlugins [] = $slug ;
2020-03-26 14:11:33 +00:00
} elseif ( 'theme' === $informationPremiumUpdates [ $i ][ 'type' ] ) {
2015-10-15 22:52:37 +10:00
$premiumThemes [] = $slug ;
}
$new_version = $informationPremiumUpdates [ $i ][ 'new_version' ];
unset ( $informationPremiumUpdates [ $i ][ 'old_version' ] );
unset ( $informationPremiumUpdates [ $i ][ 'new_version' ] );
$information [ 'premium_updates' ][ $slug ] = $informationPremiumUpdates [ $i ];
$information [ 'premium_updates' ][ $slug ][ 'update' ] = ( object ) array (
'new_version' => $new_version ,
'premium' => true ,
'slug' => $slug ,
);
if ( ! in_array ( $slug , $premiumUpdates ) ) {
$premiumUpdates [] = $slug ;
}
}
MainWP_Helper :: update_option ( 'mainwp_premium_updates' , $premiumUpdates );
}
remove_filter ( 'default_option_active_plugins' , array ( & $this , 'default_option_active_plugins' ) );
remove_filter ( 'option_active_plugins' , array ( & $this , 'default_option_active_plugins' ) );
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_site_transient_update_plugins' , $this -> filterFunction , 99 );
}
global $wp_current_filter ;
2020-05-05 00:56:15 +07:00
$wp_current_filter [] = 'load-plugins.php' ; // phpcs:ignore -- to custom plugin installation.
2015-10-15 22:52:37 +10:00
2020-04-23 19:16:35 +02:00
wp_update_plugins ();
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/plugin.php' ;
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
$plugin_updates = get_plugin_updates ();
if ( is_array ( $plugin_updates ) ) {
$information [ 'plugin_updates' ] = array ();
foreach ( $plugin_updates as $slug => $plugin_update ) {
if ( in_array ( $plugin_update -> Name , $premiumPlugins ) ) {
continue ;
}
2020-04-07 18:33:47 +02:00
// to fix incorrect info.
2020-04-07 16:53:05 +02:00
if ( ! property_exists ( $plugin_update , 'update' ) || ! property_exists ( $plugin_update -> update , 'new_version' ) || empty ( $plugin_update -> update -> new_version ) ) {
2020-03-27 15:13:11 +00:00
continue ;
}
2016-02-15 22:08:39 +01:00
2015-10-15 22:52:37 +10:00
$information [ 'plugin_updates' ][ $slug ] = $plugin_update ;
2016-02-15 22:08:39 +01:00
}
2015-10-15 22:52:37 +10:00
}
2016-02-15 22:08:39 +01:00
2015-10-15 22:52:37 +10:00
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_site_transient_update_plugins' , $this -> filterFunction , 99 );
}
2019-02-14 22:38:14 +07:00
2020-04-07 18:33:47 +02:00
// to fix premium plugs update.
2020-03-27 15:13:11 +00:00
$cached_plugins_update = get_site_transient ( 'mainwp_update_plugins_cached' );
if ( is_array ( $cached_plugins_update ) && ( count ( $cached_plugins_update ) > 0 ) ) {
2020-04-07 16:53:05 +02:00
if ( ! isset ( $information [ 'plugin_updates' ] ) ) {
2020-03-27 15:13:11 +00:00
$information [ 'plugin_updates' ] = array ();
}
foreach ( $cached_plugins_update as $slug => $plugin_update ) {
2020-02-25 22:31:13 +07:00
2020-04-07 18:33:47 +02:00
// to fix incorrect info.
2020-03-27 15:13:11 +00:00
if ( ! property_exists ( $plugin_update , 'new_version' ) || empty ( $plugin_update -> new_version ) ) { // may do not need to check this?
2020-04-07 18:33:47 +02:00
// to fix for some premiums update info.
2020-02-25 19:41:28 +07:00
if ( property_exists ( $plugin_update , 'update' ) ) {
2020-03-26 17:03:00 +00:00
if ( ! property_exists ( $plugin_update -> update , 'new_version' ) || empty ( $plugin_update -> update -> new_version ) ) {
2020-03-26 19:51:58 +00:00
continue ;
}
2020-02-25 19:41:28 +07:00
} else {
continue ;
}
2020-03-27 13:05:05 +00:00
}
2020-02-25 22:31:13 +07:00
2020-03-27 15:13:11 +00:00
if ( ! isset ( $information [ 'plugin_updates' ][ $slug ] ) ) {
$information [ 'plugin_updates' ][ $slug ] = $plugin_update ;
}
}
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
if ( null !== $this -> filterFunction ) {
add_filter ( 'pre_site_transient_update_themes' , $this -> filterFunction , 99 );
}
2020-04-23 19:16:35 +02:00
wp_update_themes ();
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/theme.php' ;
2015-10-15 22:52:37 +10:00
$theme_updates = $this -> upgrade_get_theme_updates ();
if ( is_array ( $theme_updates ) ) {
$information [ 'theme_updates' ] = array ();
foreach ( $theme_updates as $slug => $theme_update ) {
$name = ( is_array ( $theme_update ) ? $theme_update [ 'Name' ] : $theme_update -> Name );
if ( in_array ( $name , $premiumThemes ) ) {
continue ;
}
$information [ 'theme_updates' ][ $slug ] = $theme_update ;
}
}
if ( null !== $this -> filterFunction ) {
remove_filter ( 'pre_site_transient_update_themes' , $this -> filterFunction , 99 );
}
2016-02-15 22:08:39 +01:00
2020-04-07 16:53:05 +02:00
// to fix premium themes update.
2020-03-27 15:13:11 +00:00
$cached_themes_update = get_site_transient ( 'mainwp_update_themes_cached' );
if ( is_array ( $cached_themes_update ) && ( count ( $cached_themes_update ) > 0 ) ) {
2020-04-07 16:53:05 +02:00
if ( ! isset ( $information [ 'theme_updates' ] ) ) {
2020-03-27 15:13:11 +00:00
$information [ 'theme_updates' ] = array ();
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
foreach ( $cached_themes_update as $slug => $theme_update ) {
2019-02-14 22:38:14 +07:00
$name = ( is_array ( $theme_update ) ? $theme_update [ 'Name' ] : $theme_update -> Name );
if ( in_array ( $name , $premiumThemes ) ) {
continue ;
}
2020-03-27 15:13:11 +00:00
if ( isset ( $information [ 'theme_updates' ][ $slug ] ) ) {
continue ;
}
2019-02-14 22:38:14 +07:00
$information [ 'theme_updates' ][ $slug ] = $theme_update ;
}
2020-03-27 15:13:11 +00:00
}
2019-02-14 22:38:14 +07:00
2016-02-15 22:08:39 +01:00
$translation_updates = wp_get_translation_updates ();
2020-03-26 17:03:00 +00:00
if ( ! empty ( $translation_updates ) ) {
2016-02-15 22:08:39 +01:00
$information [ 'translation_updates' ] = array ();
2020-03-27 13:05:05 +00:00
foreach ( $translation_updates as $translation_update ) {
2020-03-26 15:29:54 +00:00
$new_translation_update = array (
'type' => $translation_update -> type ,
'slug' => $translation_update -> slug ,
'language' => $translation_update -> language ,
'version' => $translation_update -> version ,
);
2016-02-15 22:08:39 +01:00
if ( 'plugin' === $translation_update -> type ) {
$all_plugins = get_plugins ();
foreach ( $all_plugins as $file => $plugin ) {
2020-04-07 16:53:05 +02:00
$path = dirname ( $file );
2019-03-25 22:11:41 +07:00
if ( $path == $translation_update -> slug ) {
2016-02-15 22:08:39 +01:00
$new_translation_update [ 'name' ] = $plugin [ 'Name' ];
break ;
}
}
2020-03-26 14:11:33 +00:00
} elseif ( 'theme' === $translation_update -> type ) {
2020-04-07 16:53:05 +02:00
$theme = wp_get_theme ( $translation_update -> slug );
2016-02-15 22:08:39 +01:00
$new_translation_update [ 'name' ] = $theme -> name ;
2020-03-26 14:11:33 +00:00
} elseif ( ( 'core' === $translation_update -> type ) && ( 'default' === $translation_update -> slug ) ) {
2019-03-06 22:45:51 +07:00
$new_translation_update [ 'name' ] = 'WordPress core' ;
2016-02-15 22:08:39 +01:00
}
$information [ 'translation_updates' ][] = $new_translation_update ;
}
}
2015-10-15 22:52:37 +10:00
$information [ 'recent_comments' ] = $this -> get_recent_comments ( array ( 'approve' , 'hold' ), 5 );
2019-08-26 23:29:16 +07:00
2020-03-27 15:13:11 +00:00
$recent_number = 5 ;
2019-08-26 23:29:16 +07:00
2020-04-07 16:53:05 +02:00
if ( isset ( $_POST ) && isset ( $_POST [ 'recent_number' ] ) ) {
2020-03-27 15:13:11 +00:00
$recent_number = $_POST [ 'recent_number' ];
2020-04-07 18:33:47 +02:00
if ( get_option ( 'mainwp_child_recent_number' , 5 ) != $recent_number ) {
2020-03-27 15:13:11 +00:00
update_option ( 'mainwp_child_recent_number' , $recent_number );
}
} else {
2020-04-07 16:53:05 +02:00
$recent_number = get_option ( 'mainwp_child_recent_number' , 5 );
2020-03-27 15:13:11 +00:00
}
2019-08-26 23:29:16 +07:00
2020-03-27 15:13:11 +00:00
if ( $recent_number <= 0 || $recent_number > 30 ) {
$recent_number = 5 ;
}
2019-08-26 23:29:16 +07:00
2020-03-26 19:45:07 +00:00
$information [ 'recent_posts' ] = $this -> get_recent_posts ( array ( 'publish' , 'draft' , 'pending' , 'trash' , 'future' ), $recent_number );
2020-04-07 19:32:01 +02:00
$information [ 'recent_pages' ] = $this -> get_recent_posts ( array ( 'publish' , 'draft' , 'pending' , 'trash' , 'future' ), $recent_number , 'page' );
2015-10-15 22:52:37 +10:00
$securityIssuess = 0 ;
if ( ! MainWP_Security :: prevent_listing_ok () ) {
$securityIssuess ++ ;
}
if ( ! MainWP_Security :: remove_wp_version_ok () ) {
$securityIssuess ++ ;
}
if ( ! MainWP_Security :: remove_rsd_ok () ) {
$securityIssuess ++ ;
}
if ( ! MainWP_Security :: remove_wlw_ok () ) {
$securityIssuess ++ ;
}
if ( ! MainWP_Security :: remove_database_reporting_ok () ) {
$securityIssuess ++ ;
}
if ( ! MainWP_Security :: remove_php_reporting_ok () ) {
$securityIssuess ++ ;
}
2016-02-15 22:08:39 +01:00
if ( ! MainWP_Security :: remove_scripts_version_ok () || ! MainWP_Security :: remove_styles_version_ok () || ! MainWP_Security :: remove_generator_version_ok () ) {
2015-10-15 22:52:37 +10:00
$securityIssuess ++ ;
}
2020-03-27 15:13:11 +00:00
if ( ! MainWP_Security :: remove_registered_versions_ok () ) {
2018-09-27 19:52:32 +02:00
$securityIssuess ++ ;
}
2015-10-15 22:52:37 +10:00
if ( ! MainWP_Security :: admin_user_ok () ) {
$securityIssuess ++ ;
}
if ( ! MainWP_Security :: remove_readme_ok () ) {
$securityIssuess ++ ;
}
$information [ 'securityIssues' ] = $securityIssuess ;
2020-03-26 20:01:04 +00:00
// Directory listings!
2020-05-06 00:47:59 +07:00
$information [ 'directories' ] = $this -> scan_dir ( ABSPATH , 3 );
2020-04-07 17:12:41 +02:00
$cats = get_categories (
array (
'hide_empty' => 0 ,
'hierarchical' => true ,
'number' => 300 ,
)
);
2015-10-15 22:52:37 +10:00
$categories = array ();
foreach ( $cats as $cat ) {
$categories [] = $cat -> name ;
}
$information [ 'categories' ] = $categories ;
2020-04-07 16:53:05 +02:00
$get_file_size = apply_filters ( 'mainwp-child-get-total-size' , true );
2020-03-27 15:13:11 +00:00
if ( $get_file_size && isset ( $_POST [ 'cloneSites' ] ) && ( '0' !== $_POST [ 'cloneSites' ] ) ) {
2020-04-07 16:53:05 +02:00
$max_exe = ini_get ( 'max_execution_time' );
2020-03-27 15:13:11 +00:00
if ( $max_exe > 20 ) {
2020-05-06 00:47:59 +07:00
$information [ 'totalsize' ] = $this -> get_total_file_size ();
2020-03-27 15:13:11 +00:00
}
}
2020-03-26 19:45:07 +00:00
$information [ 'dbsize' ] = MainWP_Child_DB :: get_size ();
2015-10-15 22:52:37 +10:00
$auths = get_option ( 'mainwp_child_auth' );
$information [ 'extauth' ] = ( $auths && isset ( $auths [ $this -> maxHistory ] ) ? $auths [ $this -> maxHistory ] : null );
$plugins = $this -> get_all_plugins_int ( false );
$themes = $this -> get_all_themes_int ( false );
$information [ 'plugins' ] = $plugins ;
$information [ 'themes' ] = $themes ;
if ( isset ( $_POST [ 'optimize' ] ) && ( '1' === $_POST [ 'optimize' ] ) ) {
2020-04-07 16:53:05 +02:00
$information [ 'users' ] = $this -> get_all_users_int ( 500 );
2015-10-15 22:52:37 +10:00
}
2020-04-07 16:53:05 +02:00
if ( isset ( $_POST [ 'primaryBackup' ] ) && ! empty ( $_POST [ 'primaryBackup' ] ) ) {
2020-03-27 15:13:11 +00:00
$primary_bk = $_POST [ 'primaryBackup' ];
2020-04-07 16:53:05 +02:00
$information [ 'primaryLasttimeBackup' ] = MainWP_Helper :: get_lasttime_backup ( $primary_bk );
2020-03-27 15:13:11 +00:00
}
2015-10-15 22:52:37 +10:00
$last_post = wp_get_recent_posts ( array ( 'numberposts' => absint ( '1' ) ) );
if ( isset ( $last_post [ 0 ] ) ) {
$last_post = $last_post [ 0 ];
}
if ( isset ( $last_post ) && isset ( $last_post [ 'post_modified_gmt' ] ) ) {
$information [ 'last_post_gmt' ] = strtotime ( $last_post [ 'post_modified_gmt' ] );
}
2020-05-06 00:47:59 +07:00
$information [ 'mainwpdir' ] = ( MainWP_Helper :: validate_mainwp_dir () ? 1 : - 1 );
2015-10-15 22:52:37 +10:00
$information [ 'uniqueId' ] = get_option ( 'mainwp_child_uniqueId' , '' );
2020-05-06 20:22:11 +07:00
$information [ 'plugins_outdate_info' ] = MainWP_Child_Plugins_Check :: instance () -> get_plugins_outdate_info ();
$information [ 'themes_outdate_info' ] = MainWP_Child_Themes_Check :: instance () -> get_themes_outdate_info ();
2015-10-15 22:52:37 +10:00
2020-03-27 15:13:11 +00:00
if ( isset ( $_POST [ 'user' ] ) ) {
$user = get_user_by ( 'login' , $_POST [ 'user' ] );
2020-04-07 16:53:05 +02:00
if ( $user && property_exists ( $user , 'ID' ) && $user -> ID ) {
2020-03-27 15:13:11 +00:00
$information [ 'admin_nicename' ] = $user -> data -> user_nicename ;
$information [ 'admin_useremail' ] = $user -> data -> user_email ;
}
}
2019-05-06 22:42:18 +07:00
2020-03-27 15:13:11 +00:00
try {
2020-04-07 16:53:05 +02:00
do_action ( 'mainwp_child_site_stats' );
2020-03-27 15:13:11 +00:00
} catch ( Exception $e ) {
2020-04-07 16:53:05 +02:00
// ok.
2020-03-27 15:13:11 +00:00
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'othersData' ] ) ) {
$othersData = json_decode ( stripslashes ( $_POST [ 'othersData' ] ), true );
if ( ! is_array ( $othersData ) ) {
$othersData = array ();
2018-09-27 19:52:32 +02:00
}
2020-02-03 22:55:50 +07:00
2019-10-01 22:38:34 +07:00
if ( isset ( $othersData [ 'wpvulndbToken' ] ) ) {
2020-02-03 22:55:50 +07:00
$wpvulndb_token = get_option ( 'mainwp_child_wpvulndb_token' , '' );
if ( $wpvulndb_token != $othersData [ 'wpvulndbToken' ] ) {
MainWP_Helper :: update_option ( 'mainwp_child_wpvulndb_token' , $othersData [ 'wpvulndbToken' ] );
2019-10-01 22:38:34 +07:00
}
}
2020-02-03 22:55:50 +07:00
2020-03-27 15:13:11 +00:00
try {
$information = apply_filters ( 'mainwp-site-sync-others-data' , $information , $othersData );
} catch ( Exception $e ) {
2020-04-23 16:42:30 +02:00
// ok!
2020-03-27 15:13:11 +00:00
}
2015-10-15 22:52:37 +10:00
}
2016-03-03 20:28:07 +01:00
2015-10-15 22:52:37 +10:00
if ( $exit ) {
MainWP_Helper :: write ( $information );
}
return $information ;
}
2020-04-07 19:04:20 +02:00
public function get_site_icon () {
2020-03-27 15:13:11 +00:00
$information = array ();
$url = $this -> get_favicon ( true );
if ( ! empty ( $url ) ) {
$information [ 'faviIconUrl' ] = $url ;
}
MainWP_Helper :: write ( $information );
}
2015-10-15 22:52:37 +10:00
2020-04-07 19:04:20 +02:00
public function get_favicon ( $parse_page = false ) {
2016-12-29 22:19:20 +01:00
2020-04-07 19:04:20 +02:00
$favi_url = '' ;
$favi = '' ;
$site_url = get_option ( 'siteurl' );
2020-03-26 19:51:58 +00:00
if ( substr ( $site_url , - 1 ) != '/' ) {
$site_url .= '/' ;
}
2015-10-15 22:52:37 +10:00
2016-10-24 20:33:37 +02:00
if ( function_exists ( 'get_site_icon_url' ) && has_site_icon () ) {
2020-04-07 19:32:01 +02:00
$favi = get_site_icon_url ();
$favi_url = $favi ;
2015-10-15 22:52:37 +10:00
}
2018-09-27 19:52:32 +02:00
if ( empty ( $favi ) ) {
2020-03-27 15:13:11 +00:00
if ( file_exists ( ABSPATH . 'favicon.ico' ) ) {
2020-04-07 19:04:20 +02:00
$favi = 'favicon.ico' ;
2020-03-27 15:13:11 +00:00
} elseif ( file_exists ( ABSPATH . 'favicon.png' ) ) {
2020-04-07 19:04:20 +02:00
$favi = 'favicon.png' ;
2020-03-27 15:13:11 +00:00
}
if ( ! empty ( $favi ) ) {
$favi_url = $site_url . $favi ;
}
}
if ( $parse_page ) {
2020-04-07 16:53:05 +02:00
// try to parse page.
if ( empty ( $favi_url ) ) {
2020-03-27 15:13:11 +00:00
$request = wp_remote_get ( $site_url , array ( 'timeout' => 50 ) );
$favi = '' ;
if ( is_array ( $request ) && isset ( $request [ 'body' ] ) ) {
2020-03-26 19:51:58 +00:00
$preg_str1 = '/(<link\s+(?:[^\>]*)(?:rel="shortcut\s+icon"\s*)(?:[^>]*)?href="([^"]+)"(?:[^>]*)?>)/is' ;
$preg_str2 = '/(<link\s+(?:[^\>]*)(?:rel="(?:shortcut\s+)?icon"\s*)(?:[^>]*)?href="([^"]+)"(?:[^>]*)?>)/is' ;
if ( preg_match ( $preg_str1 , $request [ 'body' ], $matches ) ) {
$favi = $matches [ 2 ];
} elseif ( preg_match ( $preg_str2 , $request [ 'body' ], $matches ) ) {
$favi = $matches [ 2 ];
}
2020-03-27 15:13:11 +00:00
}
2016-12-29 22:19:20 +01:00
2020-03-27 15:13:11 +00:00
if ( ! empty ( $favi ) ) {
if ( false === strpos ( $favi , 'http' ) ) {
2020-03-27 13:05:05 +00:00
if ( 0 === strpos ( $favi , '//' ) ) {
if ( 0 === strpos ( $site_url , 'https' ) ) {
2020-04-07 19:04:20 +02:00
$favi_url = 'https:' . $favi ;
2020-03-26 19:51:58 +00:00
} else {
$favi_url = 'http:' . $favi ;
}
} else {
2020-03-27 15:13:11 +00:00
$favi_url = $site_url . $favi ;
2020-03-26 19:51:58 +00:00
}
2020-03-27 15:13:11 +00:00
} else {
$favi_url = $favi ;
}
}
}
if ( ! empty ( $favi_url ) ) {
return $favi_url ;
} else {
return false ;
}
} else {
return $favi_url ;
}
2015-10-15 22:52:37 +10:00
}
2020-05-06 00:47:59 +07:00
public function scan_dir ( $pDir , $pLvl ) {
2015-10-15 22:52:37 +10:00
$output = array ();
if ( file_exists ( $pDir ) && is_dir ( $pDir ) ) {
if ( 'logs' === basename ( $pDir ) ) {
return empty ( $output ) ? null : $output ;
}
if ( 0 === $pLvl ) {
return empty ( $output ) ? null : $output ;
}
2020-05-06 00:47:59 +07:00
$files = $this -> int_scan_dir ( $pDir );
2020-04-07 19:32:01 +02:00
if ( $files ) {
2015-10-15 22:52:37 +10:00
foreach ( $files as $file ) {
if ( ( '.' === $file ) || ( '..' === $file ) ) {
continue ;
}
$newDir = $pDir . $file . DIRECTORY_SEPARATOR ;
2020-04-23 19:16:35 +02:00
if ( is_dir ( $newDir ) ) {
2020-05-06 00:47:59 +07:00
$output [ $file ] = $this -> scan_dir ( $newDir , $pLvl - 1 , false );
2015-10-15 22:52:37 +10:00
}
}
unset ( $files );
$files = null ;
}
}
return empty ( $output ) ? null : $output ;
}
2020-05-06 00:47:59 +07:00
public function int_scan_dir ( $dir ) {
2020-04-23 19:16:35 +02:00
$dh = opendir ( $dir );
if ( is_dir ( $dir ) && $dh ) {
$cnt = 0 ;
$out = array ();
$file = readdir ( $dh );
while ( false !== $file ) {
2015-10-15 22:52:37 +10:00
$newDir = $dir . $file . DIRECTORY_SEPARATOR ;
2020-04-23 19:16:35 +02:00
if ( ! is_dir ( $newDir ) ) {
2015-10-15 22:52:37 +10:00
continue ;
}
$out [] = $file ;
if ( $cnt ++ > 10 ) {
return $out ;
}
}
2020-04-23 19:16:35 +02:00
closedir ( $dh );
2015-10-15 22:52:37 +10:00
return $out ;
}
return false ;
}
2020-04-07 19:04:20 +02:00
public function upgrade_get_theme_updates () {
2015-10-15 22:52:37 +10:00
$themeUpdates = get_theme_updates ();
$newThemeUpdates = array ();
if ( is_array ( $themeUpdates ) ) {
foreach ( $themeUpdates as $slug => $themeUpdate ) {
$newThemeUpdate = array ();
$newThemeUpdate [ 'update' ] = $themeUpdate -> update ;
$newThemeUpdate [ 'Name' ] = MainWP_Helper :: search ( $themeUpdate , 'Name' );
$newThemeUpdate [ 'Version' ] = MainWP_Helper :: search ( $themeUpdate , 'Version' );
$newThemeUpdates [ $slug ] = $newThemeUpdate ;
}
}
return $newThemeUpdates ;
}
2020-04-07 19:04:20 +02:00
public function get_recent_posts ( $pAllowedStatuses , $pCount , $type = 'post' , $extra = null ) {
2015-10-15 22:52:37 +10:00
$allPosts = array ();
if ( null !== $pAllowedStatuses ) {
foreach ( $pAllowedStatuses as $status ) {
$this -> get_recent_posts_int ( $status , $pCount , $type , $allPosts , $extra );
}
} else {
$this -> get_recent_posts_int ( 'any' , $pCount , $type , $allPosts , $extra );
}
return $allPosts ;
}
2020-04-07 19:04:20 +02:00
public function get_recent_posts_int ( $status , $pCount , $type = 'post' , & $allPosts , $extra = null ) {
2015-10-15 22:52:37 +10:00
$args = array (
'post_status' => $status ,
'suppress_filters' => false ,
'post_type' => $type ,
);
$tokens = array ();
if ( is_array ( $extra ) && isset ( $extra [ 'tokens' ] ) ) {
$tokens = $extra [ 'tokens' ];
2016-08-02 19:51:22 +02:00
if ( 1 == $extra [ 'extract_post_type' ] ) {
2015-10-15 22:52:37 +10:00
$args [ 'post_type' ] = 'post' ;
2020-03-26 14:11:33 +00:00
} elseif ( 2 == $extra [ 'extract_post_type' ] ) {
2015-10-15 22:52:37 +10:00
$args [ 'post_type' ] = 'page' ;
2020-03-26 14:11:33 +00:00
} elseif ( 3 == $extra [ 'extract_post_type' ] ) {
2015-10-15 22:52:37 +10:00
$args [ 'post_type' ] = array ( 'post' , 'page' );
}
}
$tokens = array_flip ( $tokens );
if ( 0 !== $pCount ) {
$args [ 'numberposts' ] = $pCount ;
}
2020-03-27 15:13:11 +00:00
/*
*
* Credits
*
* Plugin - Name : Yoast SEO
* Plugin URI : https :// yoast . com / wordpress / plugins / seo / #utm_source=wpadmin&utm_medium=plugin&utm_campaign=wpseoplugin
* Author : Team Yoast
* Author URI : https :// yoast . com /
* Licence : GPL v3
*
* The code is used for the MainWP WordPress SEO Extension
* Extension URL : https :// mainwp . com / extension / wordpress - seo /
*
2020-03-26 19:51:58 +00:00
*/
2019-02-19 23:52:21 +07:00
2020-03-27 15:13:11 +00:00
$wp_seo_enabled = false ;
if ( isset ( $_POST [ 'WPSEOEnabled' ] ) && $_POST [ 'WPSEOEnabled' ] ) {
2020-04-07 16:53:05 +02:00
if ( is_plugin_active ( 'wordpress-seo/wp-seo.php' ) && class_exists ( 'WPSEO_Link_Column_Count' ) && class_exists ( 'WPSEO_Meta' ) ) {
2020-03-27 15:13:11 +00:00
$wp_seo_enabled = true ;
2020-03-26 19:51:58 +00:00
}
2020-03-27 15:13:11 +00:00
}
2017-08-24 20:41:12 +02:00
2015-10-15 22:52:37 +10:00
$posts = get_posts ( $args );
if ( is_array ( $posts ) ) {
2020-03-27 15:13:11 +00:00
if ( $wp_seo_enabled ) {
$post_ids = array ();
foreach ( $posts as $post ) {
$post_ids [] = $post -> ID ;
}
$link_count = new WPSEO_Link_Column_Count ();
$link_count -> set ( $post_ids );
}
2015-10-15 22:52:37 +10:00
foreach ( $posts as $post ) {
2020-04-07 19:32:01 +02:00
$outPost = array ();
$outPost [ 'id' ] = $post -> ID ;
$outPost [ 'post_type' ] = $post -> post_type ;
$outPost [ 'status' ] = $post -> post_status ;
$outPost [ 'title' ] = $post -> post_title ;
2015-10-15 22:52:37 +10:00
$outPost [ 'comment_count' ] = $post -> comment_count ;
2020-03-26 17:03:00 +00:00
if ( isset ( $extra [ 'where_post_date' ] ) && ! empty ( $extra [ 'where_post_date' ] ) ) {
2015-12-05 17:38:52 +01:00
$outPost [ 'dts' ] = strtotime ( $post -> post_date_gmt );
} else {
$outPost [ 'dts' ] = strtotime ( $post -> post_modified_gmt );
}
2018-09-27 19:52:32 +02:00
2020-04-07 18:33:47 +02:00
if ( 'future' == $post -> post_status ) {
2020-03-27 15:13:11 +00:00
$outPost [ 'dts' ] = strtotime ( $post -> post_date_gmt );
}
2018-09-27 19:52:32 +02:00
2020-03-26 19:45:07 +00:00
$usr = get_user_by ( 'id' , $post -> post_author );
$outPost [ 'author' ] = ! empty ( $usr ) ? $usr -> user_nicename : 'removed' ;
$categoryObjects = get_the_category ( $post -> ID );
$categories = '' ;
2015-10-15 22:52:37 +10:00
foreach ( $categoryObjects as $cat ) {
if ( '' !== $categories ) {
$categories .= ', ' ;
}
$categories .= $cat -> name ;
}
$outPost [ 'categories' ] = $categories ;
$tagObjects = get_the_tags ( $post -> ID );
$tags = '' ;
if ( is_array ( $tagObjects ) ) {
foreach ( $tagObjects as $tag ) {
if ( '' !== $tags ) {
$tags .= ', ' ;
}
$tags .= $tag -> name ;
}
}
$outPost [ 'tags' ] = $tags ;
if ( is_array ( $tokens ) ) {
if ( isset ( $tokens [ '[post.url]' ] ) ) {
$outPost [ '[post.url]' ] = get_permalink ( $post -> ID );
}
if ( isset ( $tokens [ '[post.website.url]' ] ) ) {
$outPost [ '[post.website.url]' ] = get_site_url ();
}
if ( isset ( $tokens [ '[post.website.name]' ] ) ) {
$outPost [ '[post.website.name]' ] = get_bloginfo ( 'name' );
}
}
2017-08-24 20:41:12 +02:00
2020-03-27 15:13:11 +00:00
if ( $wp_seo_enabled ) {
$post_id = $post -> ID ;
$outPost [ 'seo_data' ] = array (
'count_seo_links' => $link_count -> get ( $post_id , 'internal_link_count' ),
'count_seo_linked' => $link_count -> get ( $post_id , 'incoming_link_count' ),
2020-05-06 20:22:11 +07:00
'seo_score' => MainWP_Wordpress_SEO :: instance () -> parse_column_score ( $post_id ),
'readability_score' => MainWP_Wordpress_SEO :: instance () -> parse_column_score_readability ( $post_id ),
2020-03-27 15:13:11 +00:00
);
}
2017-08-24 20:41:12 +02:00
2015-10-15 22:52:37 +10:00
$allPosts [] = $outPost ;
}
}
}
2020-04-07 19:04:20 +02:00
public function posts_where ( $where ) {
2015-10-15 22:52:37 +10:00
if ( $this -> posts_where_suffix ) {
$where .= ' ' . $this -> posts_where_suffix ;
}
return $where ;
}
2020-04-07 19:04:20 +02:00
public function get_all_posts () {
2020-04-07 16:53:05 +02:00
$post_type = ( isset ( $_POST [ 'post_type' ] ) ? $_POST [ 'post_type' ] : 'post' );
2016-05-22 17:16:34 +02:00
$this -> get_all_posts_by_type ( $post_type );
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function get_terms () {
2020-04-07 19:32:01 +02:00
$taxonomy = base64_decode ( $_POST [ 'taxonomy' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$rslt = get_terms ( taxonomy_exists ( $taxonomy ) ? $taxonomy : 'category' , 'hide_empty=0' );
MainWP_Helper :: write ( $rslt );
}
2020-04-07 19:04:20 +02:00
public function set_terms () {
2020-04-07 19:32:01 +02:00
$id = base64_decode ( $_POST [ 'id' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
$terms = base64_decode ( $_POST [ 'terms' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
$taxonomy = base64_decode ( $_POST [ 'taxonomy' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
if ( '' !== trim ( $terms ) ) {
$terms = explode ( ',' , $terms );
if ( count ( $terms ) > 0 ) {
wp_set_object_terms ( $id , array_map ( 'intval' , $terms ), taxonomy_exists ( $taxonomy ) ? $taxonomy : 'category' );
}
}
}
2020-04-07 19:04:20 +02:00
public function insert_comment () {
2015-10-15 22:52:37 +10:00
$postId = $_POST [ 'id' ];
2020-04-07 19:32:01 +02:00
$comments = maybe_unserialize ( base64_decode ( $_POST [ 'comments' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$ids = array ();
foreach ( $comments as $comment ) {
2020-04-07 17:12:41 +02:00
$ids [] = wp_insert_comment (
array (
'comment_post_ID' => $postId ,
'comment_author' => $comment [ 'author' ],
'comment_content' => $comment [ 'content' ],
'comment_date' => $comment [ 'date' ],
)
);
2015-10-15 22:52:37 +10:00
}
MainWP_Helper :: write ( $ids );
}
2020-04-07 19:04:20 +02:00
public function get_post_meta () {
2015-10-15 22:52:37 +10:00
/** @var $wpdb wpdb */
global $wpdb ;
$postId = $_POST [ 'id' ];
2020-04-07 19:32:01 +02:00
$keys = base64_decode ( unserialize ( $_POST [ 'keys' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$meta_value = $_POST [ 'value' ];
$where = '' ;
if ( ! empty ( $postId ) ) {
$where .= " AND `post_id` = $postId " ;
}
if ( ! empty ( $keys ) ) {
$str_keys = '\'' . implode ( '\',\'' , $keys ) . '\'' ;
2020-03-26 19:45:07 +00:00
$where .= " AND `meta_key` IN = $str_keys " ;
2015-10-15 22:52:37 +10:00
}
if ( ! empty ( $meta_value ) ) {
$where .= " AND `meta_value` = $meta_value " ;
}
2015-12-05 17:38:52 +01:00
$results = $wpdb -> get_results ( $wpdb -> prepare ( " SELECT * FROM %s WHERE 1 = 1 $where " , $wpdb -> postmeta ) );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $results );
}
2020-04-07 19:04:20 +02:00
public function get_total_ezine_post () {
2015-10-15 22:52:37 +10:00
/** @var $wpdb wpdb */
global $wpdb ;
2020-04-07 19:32:01 +02:00
$start_date = base64_decode ( $_POST [ 'start_date' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
$end_date = base64_decode ( $_POST [ 'end_date' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
$keyword_meta = base64_decode ( $_POST [ 'keyword_meta' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$where = ' WHERE ' ;
if ( ! empty ( $start_date ) && ! empty ( $end_date ) ) {
$where .= " p.post_date>=' $start_date ' AND p.post_date<=' $end_date ' AND " ;
2020-03-26 14:11:33 +00:00
} elseif ( ! empty ( $start_date ) && empty ( $end_date ) ) {
2015-10-15 22:52:37 +10:00
$where .= " p.post_date=' $start_date ' AND " ;
}
2020-04-07 17:12:41 +02:00
$where .= " ( p.post_status='publish' OR p.post_status='future' OR p.post_status='draft' ) AND (pm.meta_key='_ezine_keyword' AND pm.meta_value=' $keyword_meta ') " ;
$total = $wpdb -> get_var ( " SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->postmeta pm ON p.ID=pm.post_id $where " );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $total );
}
2020-04-07 19:04:20 +02:00
public function cancel_scheduled_post () {
2015-10-15 22:52:37 +10:00
global $wpdb ;
$postId = $_POST [ 'post_id' ];
$cancel_all = $_POST [ 'cancel_all' ];
$result = false ;
$information = array ();
if ( $postId > 0 ) {
if ( 'yes' === get_post_meta ( $postId , '_is_auto_generate_content' , true ) ) {
2020-04-07 17:12:41 +02:00
$post = $wpdb -> get_row (
$wpdb -> prepare (
" SELECT * FROM $wpdb->posts WHERE ID = %d AND post_status = 'future' " ,
$postId
)
);
2015-10-15 22:52:37 +10:00
if ( $post ) {
$result = wp_trash_post ( $postId );
} else {
$result = true ;
}
}
if ( ! $result ) {
$information [ 'status' ] = 'SUCCESS' ;
}
2020-03-26 14:11:33 +00:00
} elseif ( $cancel_all ) {
2015-10-15 22:52:37 +10:00
$post_type = $_POST [ 'post_type' ];
2015-12-05 17:38:52 +01:00
$where = " WHERE p.post_status='future' AND p.post_type = %s AND pm.meta_key = '_is_auto_generate_content' AND pm.meta_value = 'yes' " ;
2020-04-07 17:12:41 +02:00
$posts = $wpdb -> get_results ( $wpdb -> prepare ( " SELECT p.ID FROM $wpdb->posts p JOIN $wpdb->postmeta pm ON p.ID=pm.post_id $where " , $post_type ) );
2015-10-15 22:52:37 +10:00
$count = 0 ;
if ( is_array ( $posts ) ) {
foreach ( $posts as $post ) {
if ( $post ) {
if ( false !== wp_trash_post ( $post -> ID ) ) {
$count ++ ;
}
}
}
} else {
$posts = array ();
}
$information [ 'status' ] = 'SUCCESS' ;
$information [ 'count' ] = $count ;
}
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function get_next_time_to_post () {
2015-10-15 22:52:37 +10:00
$post_type = $_POST [ 'post_type' ];
if ( 'post' !== $post_type && 'page' !== $post_type ) {
MainWP_Helper :: write ( array ( 'error' => 'Data error.' ) );
return ;
}
$information = array ();
try {
global $wpdb ;
$ct = current_time ( 'mysql' );
2020-04-07 17:12:41 +02:00
$next_post = $wpdb -> get_row (
$wpdb -> prepare (
' SELECT *
FROM ' . $wpdb->posts . ' p JOIN ' . $wpdb -> postmeta . " pm ON p.ID=pm.post_id
2015-10-15 22:52:37 +10:00
WHERE
2020-04-07 17:12:41 +02:00
pm . meta_key = '_is_auto_generate_content' AND
pm . meta_value = 'yes' AND
p . post_status = 'future' AND
p . post_type = % s AND
p . post_date > NOW ()
2015-10-15 22:52:37 +10:00
ORDER BY p . post_date
2020-04-07 17:12:41 +02:00
LIMIT 1 " ,
$post_type
)
);
2015-10-15 22:52:37 +10:00
if ( ! $next_post ) {
2016-10-24 20:33:37 +02:00
$information [ 'error' ] = __ ( 'No scheduled posts.' , 'mainwp-child' );
2015-10-15 22:52:37 +10:00
} else {
$timestamp = strtotime ( $next_post -> post_date );
$timestamp_gmt = $timestamp - get_option ( 'gmt_offset' ) * 60 * 60 ;
$information [ 'next_post_date_timestamp_gmt' ] = $timestamp_gmt ;
$information [ 'next_post_id' ] = $next_post -> ID ;
}
MainWP_Helper :: write ( $information );
} catch ( Exception $e ) {
$information [ 'error' ] = $e -> getMessage ();
MainWP_Helper :: write ( $information );
}
}
2020-04-07 19:04:20 +02:00
public function get_all_pages () {
2015-10-15 22:52:37 +10:00
$this -> get_all_posts_by_type ( 'page' );
}
2020-04-07 19:04:20 +02:00
public function get_all_pages_int () {
2015-10-15 22:52:37 +10:00
$rslt = $this -> get_recent_posts ( null , - 1 , 'page' );
return $rslt ;
}
2020-04-07 19:04:20 +02:00
public function get_all_posts_by_type ( $type ) {
2015-10-15 22:52:37 +10:00
global $wpdb ;
add_filter ( 'posts_where' , array ( & $this , 'posts_where' ) );
2020-04-07 16:53:05 +02:00
$where_post_date = isset ( $_POST [ 'where_post_date' ] ) && ! empty ( $_POST [ 'where_post_date' ] ) ? true : false ;
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'postId' ] ) ) {
$this -> posts_where_suffix .= " AND $wpdb->posts .ID = " . $_POST [ 'postId' ];
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $_POST [ 'userId' ] ) ) {
2015-10-15 22:52:37 +10:00
$this -> posts_where_suffix .= " AND $wpdb->posts .post_author = " . $_POST [ 'userId' ];
} else {
if ( isset ( $_POST [ 'keyword' ] ) ) {
2020-04-07 16:53:05 +02:00
$search_on = isset ( $_POST [ 'search_on' ] ) ? $_POST [ 'search_on' ] : '' ;
2020-04-07 18:33:47 +02:00
if ( 'title' == $search_on ) {
2020-03-27 15:13:11 +00:00
$this -> posts_where_suffix .= " AND ( $wpdb->posts .post_title LIKE '% " . $_POST [ 'keyword' ] . " %' ) " ;
2020-04-07 18:33:47 +02:00
} elseif ( 'content' == $search_on ) {
2020-03-27 15:13:11 +00:00
$this -> posts_where_suffix .= " AND ( $wpdb->posts .post_content LIKE '% " . $_POST [ 'keyword' ] . " %' ) " ;
} else {
$this -> posts_where_suffix .= " AND ( $wpdb->posts .post_content LIKE '% " . $_POST [ 'keyword' ] . " %' OR $wpdb->posts .post_title LIKE '% " . $_POST [ 'keyword' ] . " %' ) " ;
}
2015-10-15 22:52:37 +10:00
}
if ( isset ( $_POST [ 'dtsstart' ] ) && '' !== $_POST [ 'dtsstart' ] ) {
2020-03-27 13:05:05 +00:00
if ( $where_post_date ) {
2015-12-05 17:38:52 +01:00
$this -> posts_where_suffix .= " AND $wpdb->posts .post_date > ' " . $_POST [ 'dtsstart' ] . " ' " ;
} else {
$this -> posts_where_suffix .= " AND $wpdb->posts .post_modified > ' " . $_POST [ 'dtsstart' ] . " ' " ;
}
2015-10-15 22:52:37 +10:00
}
if ( isset ( $_POST [ 'dtsstop' ] ) && '' !== $_POST [ 'dtsstop' ] ) {
2020-03-27 13:05:05 +00:00
if ( $where_post_date ) {
2015-12-05 17:38:52 +01:00
$this -> posts_where_suffix .= " AND $wpdb->posts .post_date < ' " . $_POST [ 'dtsstop' ] . " ' " ;
} else {
$this -> posts_where_suffix .= " AND $wpdb->posts .post_modified < ' " . $_POST [ 'dtsstop' ] . " ' " ;
}
2015-10-15 22:52:37 +10:00
}
2017-08-24 20:41:12 +02:00
2020-03-27 15:13:11 +00:00
if ( isset ( $_POST [ 'exclude_page_type' ] ) && $_POST [ 'exclude_page_type' ] ) {
$this -> posts_where_suffix .= " AND $wpdb->posts .post_type NOT IN ('page') " ;
}
2015-10-15 22:52:37 +10:00
}
2020-05-05 20:13:38 +07:00
$maxPages = 50 ;
2020-05-05 13:19:34 +00:00
if ( defined ( 'MAINWP_CHILD_NR_OF_PAGES' ) ) {
2020-05-05 20:13:38 +07:00
$maxPages = MAINWP_CHILD_NR_OF_PAGES ;
2020-05-05 13:19:34 +00:00
}
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'maxRecords' ] ) ) {
$maxPages = $_POST [ 'maxRecords' ];
}
if ( 0 === $maxPages ) {
$maxPages = 99999 ;
}
$extra = array ();
if ( isset ( $_POST [ 'extract_tokens' ] ) ) {
2020-04-07 19:32:01 +02:00
$extra [ 'tokens' ] = maybe_unserialize ( base64_decode ( $_POST [ 'extract_tokens' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$extra [ 'extract_post_type' ] = $_POST [ 'extract_post_type' ];
}
2015-12-05 17:38:52 +01:00
$extra [ 'where_post_date' ] = $where_post_date ;
2015-10-15 22:52:37 +10:00
$rslt = $this -> get_recent_posts ( explode ( ',' , $_POST [ 'status' ] ), $maxPages , $type , $extra );
$this -> posts_where_suffix = '' ;
MainWP_Helper :: write ( $rslt );
}
2020-04-07 19:04:20 +02:00
public function comments_clauses ( $clauses ) {
2015-10-15 22:52:37 +10:00
if ( $this -> comments_and_clauses ) {
$clauses [ 'where' ] .= ' ' . $this -> comments_and_clauses ;
}
return $clauses ;
}
2020-04-07 19:04:20 +02:00
public function get_all_comments () {
2015-10-15 22:52:37 +10:00
global $wpdb ;
add_filter ( 'comments_clauses' , array ( & $this , 'comments_clauses' ) );
if ( isset ( $_POST [ 'postId' ] ) ) {
$this -> comments_and_clauses .= " AND $wpdb->comments .comment_post_ID = " . $_POST [ 'postId' ];
} else {
if ( isset ( $_POST [ 'keyword' ] ) ) {
$this -> comments_and_clauses .= " AND $wpdb->comments .comment_content LIKE '% " . $_POST [ 'keyword' ] . " %' " ;
}
if ( isset ( $_POST [ 'dtsstart' ] ) && '' !== $_POST [ 'dtsstart' ] ) {
$this -> comments_and_clauses .= " AND $wpdb->comments .comment_date > ' " . $_POST [ 'dtsstart' ] . " ' " ;
}
if ( isset ( $_POST [ 'dtsstop' ] ) && '' !== $_POST [ 'dtsstop' ] ) {
$this -> comments_and_clauses .= " AND $wpdb->comments .comment_date < ' " . $_POST [ 'dtsstop' ] . " ' " ;
}
}
2020-05-05 13:19:34 +00:00
$maxComments = 50 ;
if ( defined ( 'MAINWP_CHILD_NR_OF_COMMENTS' ) ) {
2020-05-05 20:13:38 +07:00
$maxComments = MAINWP_CHILD_NR_OF_COMMENTS ; // to compatible.
2020-05-05 13:19:34 +00:00
}
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'maxRecords' ] ) ) {
$maxComments = $_POST [ 'maxRecords' ];
}
if ( 0 === $maxComments ) {
$maxComments = 99999 ;
}
$rslt = $this -> get_recent_comments ( explode ( ',' , $_POST [ 'status' ] ), $maxComments );
$this -> comments_and_clauses = '' ;
MainWP_Helper :: write ( $rslt );
}
2020-04-07 19:04:20 +02:00
public function get_recent_comments ( $pAllowedStatuses , $pCount ) {
2015-10-15 22:52:37 +10:00
if ( ! function_exists ( 'get_comment_author_url' ) ) {
2020-03-26 14:11:33 +00:00
include_once WPINC . '/comment-template.php' ;
2015-10-15 22:52:37 +10:00
}
$allComments = array ();
foreach ( $pAllowedStatuses as $status ) {
$params = array ( 'status' => $status );
if ( 0 !== $pCount ) {
$params [ 'number' ] = $pCount ;
}
$comments = get_comments ( $params );
if ( is_array ( $comments ) ) {
foreach ( $comments as $comment ) {
2020-04-07 19:32:01 +02:00
$post = get_post ( $comment -> comment_post_ID );
$email = apply_filters ( 'comment_email' , $comment -> comment_author_email );
$outComment = array ();
$outComment [ 'id' ] = $comment -> comment_ID ;
$outComment [ 'status' ] = wp_get_comment_status ( $comment -> comment_ID );
$outComment [ 'author' ] = $comment -> comment_author ;
$outComment [ 'author_url' ] = get_comment_author_url ( $comment -> comment_ID );
$outComment [ 'author_ip' ] = get_comment_author_IP ( $comment -> comment_ID );
$outComment [ 'author_email' ] = apply_filters ( 'comment_email' , $comment -> comment_author_email );
2015-10-15 22:52:37 +10:00
$outComment [ 'postId' ] = $comment -> comment_post_ID ;
$outComment [ 'postName' ] = $post -> post_title ;
$outComment [ 'comment_count' ] = $post -> comment_count ;
$outComment [ 'content' ] = $comment -> comment_content ;
$outComment [ 'dts' ] = strtotime ( $comment -> comment_date_gmt );
$allComments [] = $outComment ;
}
}
}
return $allComments ;
}
2020-04-07 19:04:20 +02:00
public function theme_action () {
2015-10-15 22:52:37 +10:00
$action = $_POST [ 'action' ];
$theme = $_POST [ 'theme' ];
if ( 'activate' === $action ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/theme.php' ;
2018-06-26 19:52:53 +02:00
$theTheme = wp_get_theme ( $theme );
2015-10-15 22:52:37 +10:00
if ( null !== $theTheme && '' !== $theTheme ) {
switch_theme ( $theTheme [ 'Template' ], $theTheme [ 'Stylesheet' ] );
}
2020-03-26 14:11:33 +00:00
} elseif ( 'delete' === $action ) {
include_once ABSPATH . '/wp-admin/includes/theme.php' ;
2015-10-15 22:52:37 +10:00
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2015-10-15 22:52:37 +10:00
}
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/file.php' ;
include_once ABSPATH . '/wp-admin/includes/template.php' ;
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php' ;
2015-10-15 22:52:37 +10:00
2020-05-06 00:47:59 +07:00
$wp_filesystem = $this -> get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
if ( empty ( $wp_filesystem ) ) {
$wp_filesystem = new WP_Filesystem_Direct ( null );
}
$themeUpgrader = new Theme_Upgrader ();
$theme_name = wp_get_theme () -> get ( 'Name' );
$themes = explode ( '||' , $theme );
2020-04-07 16:53:05 +02:00
if ( count ( $themes ) == 1 ) {
$themeToDelete = current ( $themes );
2020-03-27 15:13:11 +00:00
if ( $themeToDelete == $theme_name ) {
$information [ 'error' ] = 'IsActivatedTheme' ;
MainWP_Helper :: write ( $information );
return ;
}
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
foreach ( $themes as $idx => $themeToDelete ) {
if ( $themeToDelete !== $theme_name ) {
2018-06-26 19:52:53 +02:00
$theTheme = wp_get_theme ( $themeToDelete );
2015-10-15 22:52:37 +10:00
if ( null !== $theTheme && '' !== $theTheme ) {
$tmp [ 'theme' ] = $theTheme [ 'Template' ];
if ( true === $themeUpgrader -> delete_old_theme ( null , null , null , $tmp ) ) {
2020-03-26 15:29:54 +00:00
$args = array (
'action' => 'delete' ,
'Name' => $theTheme [ 'Name' ],
);
2015-10-15 22:52:37 +10:00
do_action ( 'mainwp_child_theme_action' , $args );
}
}
}
}
} else {
$information [ 'status' ] = 'FAIL' ;
}
if ( ! isset ( $information [ 'status' ] ) ) {
$information [ 'status' ] = 'SUCCESS' ;
}
2020-05-06 00:47:59 +07:00
$information [ 'sync' ] = $this -> get_site_stats ( array (), false );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function get_all_themes () {
2015-10-15 22:52:37 +10:00
$keyword = $_POST [ 'keyword' ];
$status = $_POST [ 'status' ];
$filter = isset ( $_POST [ 'filter' ] ) ? $_POST [ 'filter' ] : true ;
$rslt = $this -> get_all_themes_int ( $filter , $keyword , $status );
MainWP_Helper :: write ( $rslt );
}
2020-04-07 19:04:20 +02:00
public function get_all_themes_int ( $filter , $keyword = '' , $status = '' ) {
2015-10-15 22:52:37 +10:00
$rslt = array ();
$themes = wp_get_themes ();
if ( is_array ( $themes ) ) {
$theme_name = wp_get_theme () -> get ( 'Name' );
/** @var $theme WP_Theme */
foreach ( $themes as $theme ) {
$out = array ();
$out [ 'name' ] = $theme -> get ( 'Name' );
$out [ 'title' ] = $theme -> display ( 'Name' , true , false );
$out [ 'description' ] = $theme -> display ( 'Description' , true , false );
$out [ 'version' ] = $theme -> display ( 'Version' , true , false );
$out [ 'active' ] = ( $theme -> get ( 'Name' ) === $theme_name ) ? 1 : 0 ;
$out [ 'slug' ] = $theme -> get_stylesheet ();
if ( ! $filter ) {
2016-10-24 20:33:37 +02:00
if ( '' == $keyword || stristr ( $out [ 'title' ], $keyword ) ) {
2015-10-15 22:52:37 +10:00
$rslt [] = $out ;
}
2020-04-07 18:33:47 +02:00
} elseif ( ( ( 'active' === $status ) ? 1 : 0 ) === $out [ 'active' ] ) {
2016-10-24 20:33:37 +02:00
if ( '' == $keyword || stristr ( $out [ 'title' ], $keyword ) ) {
2015-10-15 22:52:37 +10:00
$rslt [] = $out ;
}
}
}
}
return $rslt ;
}
2020-04-07 19:04:20 +02:00
public function plugin_action () {
2015-10-15 22:52:37 +10:00
$action = $_POST [ 'action' ];
$plugins = explode ( '||' , $_POST [ 'plugin' ] );
if ( 'activate' === $action ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/plugin.php' ;
2015-10-15 22:52:37 +10:00
foreach ( $plugins as $idx => $plugin ) {
if ( $plugin !== $this -> plugin_slug ) {
$thePlugin = get_plugin_data ( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) {
2020-03-27 13:05:05 +00:00
if ( 'quotes-collection/quotes-collection.php' == $plugin ) {
2020-03-27 15:13:11 +00:00
activate_plugin ( $plugin , '' , false , true );
} else {
activate_plugin ( $plugin );
}
2015-10-15 22:52:37 +10:00
}
}
}
2020-03-26 14:11:33 +00:00
} elseif ( 'deactivate' === $action ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php' ;
2015-10-15 22:52:37 +10:00
foreach ( $plugins as $idx => $plugin ) {
if ( $plugin !== $this -> plugin_slug ) {
$thePlugin = get_plugin_data ( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) {
deactivate_plugins ( $plugin );
}
}
}
2020-03-26 14:11:33 +00:00
} elseif ( 'delete' === $action ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php' ;
2015-10-15 22:52:37 +10:00
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2015-10-15 22:52:37 +10:00
}
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/file.php' ;
include_once ABSPATH . '/wp-admin/includes/template.php' ;
include_once ABSPATH . '/wp-admin/includes/misc.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php' ;
include_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php' ;
2015-10-15 22:52:37 +10:00
2020-05-06 00:47:59 +07:00
$wp_filesystem = $this -> get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
if ( null === $wp_filesystem ) {
$wp_filesystem = new WP_Filesystem_Direct ( null );
}
$pluginUpgrader = new Plugin_Upgrader ();
$all_plugins = get_plugins ();
foreach ( $plugins as $idx => $plugin ) {
if ( $plugin !== $this -> plugin_slug ) {
if ( isset ( $all_plugins [ $plugin ] ) ) {
2020-04-07 16:53:05 +02:00
if ( is_plugin_active ( $plugin ) ) {
2020-03-27 15:13:11 +00:00
$thePlugin = get_plugin_data ( $plugin );
if ( null !== $thePlugin && '' !== $thePlugin ) {
deactivate_plugins ( $plugin );
}
}
$tmp [ 'plugin' ] = $plugin ;
2015-10-15 22:52:37 +10:00
if ( true === $pluginUpgrader -> delete_old_plugin ( null , null , null , $tmp ) ) {
2020-03-26 15:29:54 +00:00
$args = array (
'action' => 'delete' ,
'Name' => $all_plugins [ $plugin ][ 'Name' ],
);
2015-10-15 22:52:37 +10:00
do_action ( 'mainwp_child_plugin_action' , $args );
}
}
}
}
} else {
$information [ 'status' ] = 'FAIL' ;
}
if ( ! isset ( $information [ 'status' ] ) ) {
$information [ 'status' ] = 'SUCCESS' ;
}
2020-05-06 00:47:59 +07:00
$information [ 'sync' ] = $this -> get_site_stats ( array (), false );
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function get_all_plugins () {
2015-10-15 22:52:37 +10:00
$keyword = $_POST [ 'keyword' ];
$status = $_POST [ 'status' ];
$filter = isset ( $_POST [ 'filter' ] ) ? $_POST [ 'filter' ] : true ;
$rslt = $this -> get_all_plugins_int ( $filter , $keyword , $status );
MainWP_Helper :: write ( $rslt );
}
2020-04-07 19:04:20 +02:00
public function get_all_plugins_int ( $filter , $keyword = '' , $status = '' ) {
2015-10-15 22:52:37 +10:00
if ( ! function_exists ( 'get_plugins' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . 'wp-admin/includes/plugin.php' ;
2015-10-15 22:52:37 +10:00
}
$rslt = array ();
$plugins = get_plugins ();
if ( is_array ( $plugins ) ) {
$active_plugins = get_option ( 'active_plugins' );
foreach ( $plugins as $pluginslug => $plugin ) {
$out = array ();
2020-03-26 19:45:07 +00:00
$out [ 'mainwp' ] = ( $pluginslug == $this -> plugin_slug ? 'T' : 'F' );
2015-10-15 22:52:37 +10:00
$out [ 'name' ] = $plugin [ 'Name' ];
$out [ 'slug' ] = $pluginslug ;
$out [ 'description' ] = $plugin [ 'Description' ];
$out [ 'version' ] = $plugin [ 'Version' ];
2020-04-07 16:53:05 +02:00
$out [ 'active' ] = is_plugin_active ( $pluginslug ) ? 1 : 0 ;
2015-10-15 22:52:37 +10:00
if ( ! $filter ) {
2015-12-22 19:18:07 +01:00
if ( '' == $keyword || stristr ( $out [ 'name' ], $keyword ) ) {
2015-10-15 22:52:37 +10:00
$rslt [] = $out ;
}
2020-04-07 18:33:47 +02:00
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out [ 'active' ] ) {
2015-12-22 19:18:07 +01:00
if ( '' == $keyword || stristr ( $out [ 'name' ], $keyword ) ) {
2015-10-15 22:52:37 +10:00
$rslt [] = $out ;
}
}
}
}
2016-04-27 19:25:53 +02:00
$muplugins = get_mu_plugins ();
if ( is_array ( $muplugins ) ) {
foreach ( $muplugins as $pluginslug => $plugin ) {
$out = array ();
2020-03-26 19:45:07 +00:00
$out [ 'mainwp' ] = ( $pluginslug == $this -> plugin_slug ? 'T' : 'F' );
2016-04-27 19:25:53 +02:00
$out [ 'name' ] = $plugin [ 'Name' ];
$out [ 'slug' ] = $pluginslug ;
$out [ 'description' ] = $plugin [ 'Description' ];
$out [ 'version' ] = $plugin [ 'Version' ];
$out [ 'active' ] = 1 ;
$out [ 'mu' ] = 1 ;
if ( ! $filter ) {
if ( '' == $keyword || stristr ( $out [ 'name' ], $keyword ) ) {
$rslt [] = $out ;
}
2020-04-07 18:33:47 +02:00
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out [ 'active' ] ) {
2016-04-27 19:25:53 +02:00
if ( '' == $keyword || stristr ( $out [ 'name' ], $keyword ) ) {
$rslt [] = $out ;
}
}
}
}
2015-10-15 22:52:37 +10:00
return $rslt ;
}
2020-04-07 19:04:20 +02:00
public function get_all_users ( $return = false ) {
2020-03-26 19:45:07 +00:00
$roles = explode ( ',' , $_POST [ 'role' ] );
2015-10-15 22:52:37 +10:00
$allusers = array ();
if ( is_array ( $roles ) ) {
foreach ( $roles as $role ) {
$new_users = get_users ( 'role=' . $role );
foreach ( $new_users as $new_user ) {
$usr = array ();
$usr [ 'id' ] = $new_user -> ID ;
$usr [ 'login' ] = $new_user -> user_login ;
$usr [ 'nicename' ] = $new_user -> user_nicename ;
$usr [ 'email' ] = $new_user -> user_email ;
$usr [ 'registered' ] = $new_user -> user_registered ;
$usr [ 'status' ] = $new_user -> user_status ;
$usr [ 'display_name' ] = $new_user -> display_name ;
$usr [ 'role' ] = $role ;
$usr [ 'post_count' ] = count_user_posts ( $new_user -> ID );
$usr [ 'avatar' ] = get_avatar ( $new_user -> ID , 32 );
$allusers [] = $usr ;
}
}
}
2020-03-27 13:05:05 +00:00
if ( $return ) {
2020-03-26 19:51:58 +00:00
return $allusers ;
}
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $allusers );
}
2020-04-07 19:04:20 +02:00
public function get_all_users_int ( $number = false ) {
2015-10-15 22:52:37 +10:00
$allusers = array ();
2020-03-27 15:13:11 +00:00
$params = array ();
if ( $number ) {
$params [ 'number' ] = $number ;
}
2018-09-27 19:52:32 +02:00
2020-04-07 16:53:05 +02:00
$new_users = get_users ( $params );
2015-10-15 22:52:37 +10:00
if ( is_array ( $new_users ) ) {
foreach ( $new_users as $new_user ) {
$usr = array ();
$usr [ 'id' ] = $new_user -> ID ;
$usr [ 'login' ] = $new_user -> user_login ;
$usr [ 'nicename' ] = $new_user -> user_nicename ;
$usr [ 'email' ] = $new_user -> user_email ;
$usr [ 'registered' ] = $new_user -> user_registered ;
$usr [ 'status' ] = $new_user -> user_status ;
$usr [ 'display_name' ] = $new_user -> display_name ;
$userdata = get_userdata ( $new_user -> ID );
$user_roles = $userdata -> roles ;
$user_role = array_shift ( $user_roles );
$usr [ 'role' ] = $user_role ;
$usr [ 'post_count' ] = count_user_posts ( $new_user -> ID );
$allusers [] = $usr ;
}
}
return $allusers ;
}
2020-04-07 19:04:20 +02:00
public function search_users () {
2018-09-27 19:52:32 +02:00
2019-11-11 23:17:10 +07:00
$search_user_role = array ();
$check_users_role = false ;
2018-09-27 19:52:32 +02:00
2020-04-07 16:53:05 +02:00
if ( isset ( $_POST [ 'role' ] ) && ! empty ( $_POST [ 'role' ] ) ) {
2019-11-11 23:17:10 +07:00
$check_users_role = true ;
2020-04-07 17:12:41 +02:00
$all_users_role = $this -> get_all_users ( true );
2020-03-27 13:05:05 +00:00
foreach ( $all_users_role as $user ) {
2019-11-11 23:17:10 +07:00
$search_user_role [] = $user [ 'id' ];
}
2020-04-07 16:53:05 +02:00
unset ( $all_users_role );
2019-11-11 23:17:10 +07:00
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
$columns = explode ( ',' , $_POST [ 'search_columns' ] );
$allusers = array ();
$exclude = array ();
foreach ( $columns as $col ) {
if ( empty ( $col ) ) {
continue ;
}
2020-04-07 17:12:41 +02:00
$user_query = new WP_User_Query (
array (
'search' => $_POST [ 'search' ],
'fields' => 'all_with_meta' ,
'search_columns' => array ( $col ),
'query_orderby' => array ( $col ),
'exclude' => $exclude ,
)
);
2015-10-15 22:52:37 +10:00
if ( ! empty ( $user_query -> results ) ) {
foreach ( $user_query -> results as $new_user ) {
2020-03-27 13:05:05 +00:00
if ( $check_users_role ) {
2020-04-07 16:53:05 +02:00
if ( ! in_array ( $new_user -> ID , $search_user_role ) ) {
2020-03-26 19:51:58 +00:00
continue ;
}
}
2015-10-15 22:52:37 +10:00
$exclude [] = $new_user -> ID ;
$usr = array ();
$usr [ 'id' ] = $new_user -> ID ;
$usr [ 'login' ] = $new_user -> user_login ;
$usr [ 'nicename' ] = $new_user -> user_nicename ;
$usr [ 'email' ] = $new_user -> user_email ;
$usr [ 'registered' ] = $new_user -> user_registered ;
$usr [ 'status' ] = $new_user -> user_status ;
$usr [ 'display_name' ] = $new_user -> display_name ;
$userdata = get_userdata ( $new_user -> ID );
$user_roles = $userdata -> roles ;
$user_role = array_shift ( $user_roles );
$usr [ 'role' ] = $user_role ;
$usr [ 'post_count' ] = count_user_posts ( $new_user -> ID );
$usr [ 'avatar' ] = get_avatar ( $new_user -> ID , 32 );
$allusers [] = $usr ;
}
}
}
MainWP_Helper :: write ( $allusers );
}
2020-04-07 17:12:41 +02:00
// Show stats without login - only allowed while no account is added yet.
2020-05-06 00:47:59 +07:00
public function get_site_stats_no_auth ( $information = array () ) {
2015-10-15 22:52:37 +10:00
if ( get_option ( 'mainwp_child_pubkey' ) ) {
2020-04-07 16:53:05 +02:00
$hint = '<br/>' . __ ( 'Hint: Go to the child site, deactivate and reactivate the MainWP Child plugin and try again.' , 'mainwp-child' );
MainWP_Helper :: error ( __ ( 'This site already contains a link. Please deactivate and reactivate the MainWP plugin.' , 'mainwp-child' ) . $hint );
2015-10-15 22:52:37 +10:00
}
global $wp_version ;
2015-12-12 18:39:23 +01:00
$information [ 'version' ] = self :: $version ;
2015-10-15 22:52:37 +10:00
$information [ 'wpversion' ] = $wp_version ;
2020-03-26 19:45:07 +00:00
$information [ 'wpe' ] = MainWP_Helper :: is_wp_engine () ? 1 : 0 ;
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $information );
}
2020-04-07 17:12:41 +02:00
// Deactivating the plugin.
2020-04-07 19:04:20 +02:00
public function deactivate () {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . 'wp-admin/includes/plugin.php' ;
2015-10-15 22:52:37 +10:00
deactivate_plugins ( $this -> plugin_slug , true );
$information = array ();
if ( is_plugin_active ( $this -> plugin_slug ) ) {
MainWP_Helper :: error ( 'Plugin still active' );
}
$information [ 'deactivated' ] = true ;
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function activation () {
2020-04-07 16:53:05 +02:00
$mu_plugin_enabled = apply_filters ( 'mainwp_child_mu_plugin_enabled' , false );
2020-03-27 15:13:11 +00:00
if ( $mu_plugin_enabled ) {
return ;
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
$to_delete = array (
'mainwp_child_pubkey' ,
'mainwp_child_nonce' ,
'mainwp_child_nossl' ,
'mainwp_child_nossl_key' ,
);
foreach ( $to_delete as $delete ) {
if ( get_option ( $delete ) ) {
delete_option ( $delete );
}
}
MainWP_Helper :: update_option ( 'mainwp_child_activated_once' , true );
2020-04-07 17:12:41 +02:00
// delete bad data if existed.
2015-10-15 22:52:37 +10:00
$to_delete = array ( 'mainwp_ext_snippets_enabled' , 'mainwp_ext_code_snippets' );
foreach ( $to_delete as $delete ) {
delete_option ( $delete );
}
}
2020-04-07 19:04:20 +02:00
public function deactivation ( $deact = true ) {
2018-09-27 19:52:32 +02:00
2020-04-07 16:53:05 +02:00
$mu_plugin_enabled = apply_filters ( 'mainwp_child_mu_plugin_enabled' , false );
2020-03-27 15:13:11 +00:00
if ( $mu_plugin_enabled ) {
return ;
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
$to_delete = array (
'mainwp_child_pubkey' ,
'mainwp_child_nonce' ,
'mainwp_child_nossl' ,
'mainwp_child_nossl_key' ,
'mainwp_security' ,
'mainwp_child_server' ,
);
$to_delete [] = 'mainwp_ext_snippets_enabled' ;
$to_delete [] = 'mainwp_ext_code_snippets' ;
foreach ( $to_delete as $delete ) {
if ( get_option ( $delete ) ) {
delete_option ( $delete );
2017-07-11 14:10:22 +02:00
wp_cache_delete ( $delete , 'options' );
2015-10-15 22:52:37 +10:00
}
}
2018-09-27 19:52:32 +02:00
2020-03-27 13:05:05 +00:00
if ( $deact ) {
2018-06-26 19:52:53 +02:00
do_action ( 'mainwp_child_deactivation' );
2020-03-27 15:13:11 +00:00
}
2015-10-15 22:52:37 +10:00
}
2020-05-06 00:47:59 +07:00
public function get_wp_filesystem () {
2015-10-15 22:52:37 +10:00
global $wp_filesystem ;
if ( empty ( $wp_filesystem ) ) {
ob_start ();
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2015-10-15 22:52:37 +10:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/template.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/template.php' ;
2015-10-15 22:52:37 +10:00
}
$creds = request_filesystem_credentials ( 'test' , '' , false , false , $extra_fields = null );
ob_end_clean ();
if ( empty ( $creds ) ) {
define ( 'FS_METHOD' , 'direct' );
}
WP_Filesystem ( $creds );
}
if ( empty ( $wp_filesystem ) ) {
MainWP_Helper :: error ( $this -> FTP_ERROR );
2020-03-26 14:11:33 +00:00
} elseif ( is_wp_error ( $wp_filesystem -> errors ) ) {
2015-10-15 22:52:37 +10:00
$errorCodes = $wp_filesystem -> errors -> get_error_codes ();
if ( ! empty ( $errorCodes ) ) {
2016-10-24 20:33:37 +02:00
MainWP_Helper :: error ( __ ( 'WordPress Filesystem error: ' , 'mainwp-child' ) . $wp_filesystem -> errors -> get_error_message () );
2015-10-15 22:52:37 +10:00
}
}
return $wp_filesystem ;
}
2020-05-06 00:47:59 +07:00
public function get_total_file_size ( $directory = WP_CONTENT_DIR ) {
2015-10-15 22:52:37 +10:00
try {
if ( MainWP_Helper :: function_exists ( 'popen' ) ) {
2020-05-06 00:47:59 +07:00
$uploadDir = MainWP_Helper :: get_mainwp_dir ();
2015-10-15 22:52:37 +10:00
$uploadDir = $uploadDir [ 0 ];
2020-04-23 19:16:35 +02:00
$popenHandle = popen ( 'du -s ' . $directory . ' --exclude "' . str_replace ( ABSPATH , '' , $uploadDir ) . '"' , 'r' );
2015-10-15 22:52:37 +10:00
if ( 'resource' === gettype ( $popenHandle ) ) {
2020-04-23 19:16:35 +02:00
$size = fread ( $popenHandle , 1024 );
pclose ( $popenHandle );
2015-10-15 22:52:37 +10:00
$size = substr ( $size , 0 , strpos ( $size , " \t " ) );
2017-12-04 21:55:05 +01:00
if ( $size && MainWP_Helper :: ctype_digit ( $size ) ) {
2015-10-15 22:52:37 +10:00
return $size / 1024 ;
}
}
}
2016-02-15 22:08:39 +01:00
2015-10-15 22:52:37 +10:00
if ( MainWP_Helper :: function_exists ( 'shell_exec' ) ) {
2020-05-06 00:47:59 +07:00
$uploadDir = MainWP_Helper :: get_mainwp_dir ();
2015-10-15 22:52:37 +10:00
$uploadDir = $uploadDir [ 0 ];
2020-04-23 19:16:35 +02:00
$size = shell_exec ( 'du -s ' . $directory . ' --exclude "' . str_replace ( ABSPATH , '' , $uploadDir ) . '"' );
2015-10-15 22:52:37 +10:00
if ( null !== $size ) {
$size = substr ( $size , 0 , strpos ( $size , " \t " ) );
2017-12-04 21:55:05 +01:00
if ( $size && MainWP_Helper :: ctype_digit ( $size ) ) {
2015-10-15 22:52:37 +10:00
return $size / 1024 ;
}
}
}
if ( class_exists ( 'COM' ) ) {
$obj = new COM ( 'scripting.filesystemobject' );
if ( is_object ( $obj ) ) {
$ref = $obj -> getfolder ( $directory );
$size = $ref -> size ;
$obj = null ;
2016-02-15 22:08:39 +01:00
if ( MainWP_Helper :: ctype_digit ( $size ) ) {
2015-10-15 22:52:37 +10:00
return $size / 1024 ;
}
}
}
2020-03-27 15:13:11 +00:00
// to fix for window host, performance not good?
if ( class_exists ( 'RecursiveIteratorIterator' ) ) {
$size = 0 ;
2020-04-07 16:53:05 +02:00
foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $directory ) ) as $file ) {
2020-03-27 15:13:11 +00:00
$size += $file -> getSize ();
}
if ( $size && MainWP_Helper :: ctype_digit ( $size ) ) {
return $size / 1024 / 1024 ;
}
2017-12-04 21:55:05 +01:00
}
2016-04-27 19:25:53 +02:00
return 0 ;
2015-10-15 22:52:37 +10:00
} catch ( Exception $e ) {
return 0 ;
}
}
2020-05-06 00:47:59 +07:00
public function server_information () {
2020-04-23 19:16:35 +02:00
ob_start ();
2015-10-15 22:52:37 +10:00
MainWP_Child_Server_Information :: render ();
2020-04-23 19:16:35 +02:00
$output [ 'information' ] = ob_get_contents ();
ob_end_clean ();
ob_start ();
2020-05-06 20:22:11 +07:00
MainWP_Child_Server_Information :: render_cron ();
2020-04-23 19:16:35 +02:00
$output [ 'cron' ] = ob_get_contents ();
ob_end_clean ();
ob_start ();
2020-05-06 20:22:11 +07:00
MainWP_Child_Server_Information :: render_error_log_page ();
2020-04-23 19:16:35 +02:00
$output [ 'error' ] = ob_get_contents ();
ob_end_clean ();
ob_start ();
2020-05-06 20:22:11 +07:00
MainWP_Child_Server_Information :: render_wp_config ();
2020-04-23 19:16:35 +02:00
$output [ 'wpconfig' ] = ob_get_contents ();
ob_end_clean ();
ob_start ();
2015-10-15 22:52:37 +10:00
MainWP_Child_Server_Information :: renderhtaccess ();
2020-04-23 19:16:35 +02:00
$output [ 'htaccess' ] = ob_get_contents ();
ob_end_clean ();
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $output );
}
2020-04-07 19:04:20 +02:00
public function maintenance_site () {
2015-10-15 22:52:37 +10:00
global $wpdb ;
$information = array ();
if ( isset ( $_POST [ 'action' ] ) ) {
if ( 'save_settings' === $_POST [ 'action' ] ) {
2015-12-06 19:05:27 +01:00
if ( isset ( $_POST [ 'enable_alert' ] ) && '1' === $_POST [ 'enable_alert' ] ) {
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_maintenance_opt_alert_404' , 1 , 'yes' );
} else {
delete_option ( 'mainwp_maintenance_opt_alert_404' );
}
if ( isset ( $_POST [ 'email' ] ) && ! empty ( $_POST [ 'email' ] ) ) {
MainWP_Helper :: update_option ( 'mainwp_maintenance_opt_alert_404_email' , $_POST [ 'email' ], 'yes' );
} else {
delete_option ( 'mainwp_maintenance_opt_alert_404_email' );
}
$information [ 'result' ] = 'SUCCESS' ;
MainWP_Helper :: write ( $information );
return ;
2020-03-26 14:11:33 +00:00
} elseif ( 'clear_settings' === $_POST [ 'action' ] ) {
2015-10-15 22:52:37 +10:00
delete_option ( 'mainwp_maintenance_opt_alert_404' );
delete_option ( 'mainwp_maintenance_opt_alert_404_email' );
$information [ 'result' ] = 'SUCCESS' ;
MainWP_Helper :: write ( $information );
}
MainWP_Helper :: write ( $information );
}
$maint_options = $_POST [ 'options' ];
$max_revisions = isset ( $_POST [ 'revisions' ] ) ? intval ( $_POST [ 'revisions' ] ) : 0 ;
if ( ! is_array ( $maint_options ) ) {
$information [ 'status' ] = 'FAIL' ;
$maint_options = array ();
}
2020-03-27 15:13:11 +00:00
$performed_what = array ();
2015-10-15 22:52:37 +10:00
if ( empty ( $max_revisions ) ) {
$sql_clean = " DELETE FROM $wpdb->posts WHERE post_type = 'revision' " ;
$wpdb -> query ( $sql_clean );
2020-04-07 17:12:41 +02:00
// to fix issue of meta_value short length.
$performed_what [] = 'revisions' ; // 'Posts revisions deleted'.
2015-10-15 22:52:37 +10:00
} else {
2020-05-06 00:47:59 +07:00
$results = MainWP_Helper :: get_revisions ( $max_revisions );
$count_deleted = MainWP_Helper :: delete_revisions ( $results , $max_revisions );
2020-04-07 17:12:41 +02:00
$performed_what [] = 'revisions' ; // 'Posts revisions deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'autodraft' , $maint_options ) ) {
$sql_clean = " DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft' " ;
$wpdb -> query ( $sql_clean );
2020-04-07 17:12:41 +02:00
$performed_what [] = 'autodraft' ; // 'Auto draft posts deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'trashpost' , $maint_options ) ) {
$sql_clean = " DELETE FROM $wpdb->posts WHERE post_status = 'trash' " ;
$wpdb -> query ( $sql_clean );
2020-04-07 17:12:41 +02:00
$performed_what [] = 'trashpost' ; // 'Trash posts deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'spam' , $maint_options ) ) {
$sql_clean = " DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' " ;
$wpdb -> query ( $sql_clean );
2020-04-07 17:12:41 +02:00
$performed_what [] = 'spam' ; // 'Spam comments deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'pending' , $maint_options ) ) {
$sql_clean = " DELETE FROM $wpdb->comments WHERE comment_approved = '0' " ;
$wpdb -> query ( $sql_clean );
2020-04-07 17:12:41 +02:00
$performed_what [] = 'pending' ; // 'Pending comments deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'trashcomment' , $maint_options ) ) {
$sql_clean = " DELETE FROM $wpdb->comments WHERE comment_approved = 'trash' " ;
$wpdb -> query ( $sql_clean );
2020-04-07 17:12:41 +02:00
$performed_what [] = 'trashcomment' ; // 'Trash comments deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'tags' , $maint_options ) ) {
$post_tags = get_terms ( 'post_tag' , array ( 'hide_empty' => false ) );
if ( is_array ( $post_tags ) ) {
foreach ( $post_tags as $tag ) {
if ( 0 === $tag -> count ) {
wp_delete_term ( $tag -> term_id , 'post_tag' );
}
}
}
2020-04-07 17:12:41 +02:00
$performed_what [] = 'tags' ; // 'Tags with 0 posts associated deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'categories' , $maint_options ) ) {
$post_cats = get_terms ( 'category' , array ( 'hide_empty' => false ) );
if ( is_array ( $post_cats ) ) {
foreach ( $post_cats as $cat ) {
if ( 0 === $cat -> count ) {
wp_delete_term ( $cat -> term_id , 'category' );
}
}
}
2020-04-07 17:12:41 +02:00
$performed_what [] = 'categories' ; // 'Categories with 0 posts associated deleted'.
2015-10-15 22:52:37 +10:00
}
if ( in_array ( 'optimize' , $maint_options ) ) {
$this -> maintenance_optimize ();
2020-04-07 17:12:41 +02:00
$performed_what [] = 'optimize' ; // 'Database optimized'.
2015-10-15 22:52:37 +10:00
}
if ( ! isset ( $information [ 'status' ] ) ) {
$information [ 'status' ] = 'SUCCESS' ;
}
2017-01-14 13:16:52 +01:00
2020-03-27 15:13:11 +00:00
if ( ! empty ( $performed_what ) && has_action ( 'mainwp_reports_maintenance' ) ) {
$details = implode ( ',' , $performed_what );
$log_time = time ();
2020-04-07 19:32:01 +02:00
$message = 'Maintenance Performed' ;
$result = 'Maintenance Performed' ;
2020-04-07 17:12:41 +02:00
do_action ( 'mainwp_reports_maintenance' , $message , $log_time , $details , $result );
2020-03-27 15:13:11 +00:00
}
2017-01-14 13:16:52 +01:00
2015-10-15 22:52:37 +10:00
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function maintenance_optimize () {
2015-10-15 22:52:37 +10:00
global $wpdb , $table_prefix ;
$sql = 'SHOW TABLE STATUS FROM `' . DB_NAME . '`' ;
2020-04-23 19:16:35 +02:00
$result = MainWP_Child_DB :: _query ( $sql , $wpdb -> dbh );
if ( MainWP_Child_DB :: num_rows ( $result ) && MainWP_Child_DB :: is_result ( $result ) ) {
2015-10-15 22:52:37 +10:00
while ( $row = MainWP_Child_DB :: fetch_array ( $result ) ) {
if ( strpos ( $row [ 'Name' ], $table_prefix ) !== false ) {
$sql = 'OPTIMIZE TABLE ' . $row [ 'Name' ];
MainWP_Child_DB :: _query ( $sql , $wpdb -> dbh );
}
}
}
}
2020-04-07 19:04:20 +02:00
public function maintenance_alert_404 () {
2015-10-15 22:52:37 +10:00
if ( ! is_404 () ) {
return ;
}
2016-02-17 20:38:44 +01:00
if ( 1 !== ( int ) get_option ( 'mainwp_maintenance_opt_alert_404' ) ) {
return ;
}
2015-10-15 22:52:37 +10:00
$email = get_option ( 'mainwp_maintenance_opt_alert_404_email' );
if ( empty ( $email ) || ! preg_match ( '/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/is' , $email ) ) {
return ;
}
2020-04-07 18:33:47 +02:00
// set status.
2015-10-15 22:52:37 +10:00
header ( 'HTTP/1.1 404 Not Found' );
header ( 'Status: 404 Not Found' );
2020-04-07 18:33:47 +02:00
// site info.
2015-10-15 22:52:37 +10:00
$blog = get_bloginfo ( 'name' );
$site = get_bloginfo ( 'url' ) . '/' ;
$from_email = get_bloginfo ( 'admin_email' );
2020-04-07 18:33:47 +02:00
// referrer.
2015-10-15 22:52:37 +10:00
if ( isset ( $_SERVER [ 'HTTP_REFERER' ] ) ) {
$referer = MainWP_Helper :: clean ( $_SERVER [ 'HTTP_REFERER' ] );
} else {
$referer = 'undefined' ;
}
$protocol = isset ( $_SERVER [ 'HTTPS' ] ) && strcasecmp ( $_SERVER [ 'HTTPS' ], 'off' ) ? 'https://' : 'http://' ;
2020-04-07 18:33:47 +02:00
// request URI.
2015-10-15 22:52:37 +10:00
if ( isset ( $_SERVER [ 'REQUEST_URI' ] ) && isset ( $_SERVER [ 'HTTP_HOST' ] ) ) {
$request = MainWP_Helper :: clean ( $protocol . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'REQUEST_URI' ] );
} else {
$request = 'undefined' ;
}
2020-04-07 18:33:47 +02:00
// query string.
2015-10-15 22:52:37 +10:00
if ( isset ( $_SERVER [ 'QUERY_STRING' ] ) ) {
$string = MainWP_Helper :: clean ( $_SERVER [ 'QUERY_STRING' ] );
} else {
$string = 'undefined' ;
}
2020-04-07 18:33:47 +02:00
// IP address.
2015-10-15 22:52:37 +10:00
if ( isset ( $_SERVER [ 'REMOTE_ADDR' ] ) ) {
$address = MainWP_Helper :: clean ( $_SERVER [ 'REMOTE_ADDR' ] );
} else {
$address = 'undefined' ;
}
2020-04-07 18:33:47 +02:00
// user agent.
2015-10-15 22:52:37 +10:00
if ( isset ( $_SERVER [ 'HTTP_USER_AGENT' ] ) ) {
$agent = MainWP_Helper :: clean ( $_SERVER [ 'HTTP_USER_AGENT' ] );
} else {
$agent = 'undefined' ;
}
2020-04-07 17:12:41 +02:00
// identity.
2015-10-15 22:52:37 +10:00
if ( isset ( $_SERVER [ 'REMOTE_IDENT' ] ) ) {
$remote = MainWP_Helper :: clean ( $_SERVER [ 'REMOTE_IDENT' ] );
} else {
$remote = 'undefined' ;
}
2020-04-07 17:12:41 +02:00
// log time.
2015-10-15 22:52:37 +10:00
$time = MainWP_Helper :: clean ( date ( 'F jS Y, h:ia' , time () ) );
2020-05-05 20:13:38 +07:00
$mail = '<div>404 alert</div><div></div>' .
'<div>TIME: ' . $time . '</div>' .
'<div>*404: ' . $request . '</div>' .
'<div>SITE: ' . $site . '</div>' .
'<div>REFERRER: ' . $referer . '</div>' .
'<div>QUERY STRING: ' . $string . '</div>' .
'<div>REMOTE ADDRESS: ' . $address . '</div>' .
'<div>REMOTE IDENTITY: ' . $remote . '</div>' .
2020-05-05 13:19:34 +00:00
'<div>USER AGENT: ' . $agent . '</div>' ;
2020-04-23 19:16:35 +02:00
wp_mail (
2020-04-07 17:12:41 +02:00
$email ,
'MainWP - 404 Alert: ' . $blog ,
2020-05-06 00:47:59 +07:00
MainWP_Helper :: format_email ( $email , $mail ),
2020-04-07 17:12:41 +02:00
array (
2020-04-07 19:32:01 +02:00
'content-type: text/html' ,
2020-04-07 17:12:41 +02:00
)
);
2015-10-15 22:52:37 +10:00
}
public function keyword_links_action () {
2020-05-06 20:22:11 +07:00
MainWP_Keyword_Links :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
public function branding_child_plugin () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Branding :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
public function code_snippet () {
$action = $_POST [ 'action' ];
$information = array ( 'status' => 'FAIL' );
if ( 'run_snippet' === $action || 'save_snippet' === $action ) {
if ( ! isset ( $_POST [ 'code' ] ) ) {
MainWP_Helper :: write ( $information );
}
}
$code = stripslashes ( $_POST [ 'code' ] );
if ( 'run_snippet' === $action ) {
2020-05-05 20:13:38 +07:00
$information = MainWP_Helper :: execute_snippet ( $code );
2020-03-26 14:11:33 +00:00
} elseif ( 'save_snippet' === $action ) {
2015-10-15 22:52:37 +10:00
$type = $_POST [ 'type' ];
$slug = $_POST [ 'slug' ];
$snippets = get_option ( 'mainwp_ext_code_snippets' );
if ( ! is_array ( $snippets ) ) {
$snippets = array ();
}
2020-04-07 17:12:41 +02:00
if ( 'C' === $type ) { // save into wp-config file.
2020-05-06 00:47:59 +07:00
if ( false !== $this -> snippet_update_wp_config ( 'save' , $slug , $code ) ) {
2015-10-15 22:52:37 +10:00
$information [ 'status' ] = 'SUCCESS' ;
}
} else {
$snippets [ $slug ] = $code ;
if ( MainWP_Helper :: update_option ( 'mainwp_ext_code_snippets' , $snippets ) ) {
$information [ 'status' ] = 'SUCCESS' ;
}
}
MainWP_Helper :: update_option ( 'mainwp_ext_snippets_enabled' , true , 'yes' );
2020-03-26 14:11:33 +00:00
} elseif ( 'delete_snippet' === $action ) {
2015-10-15 22:52:37 +10:00
$type = $_POST [ 'type' ];
$slug = $_POST [ 'slug' ];
$snippets = get_option ( 'mainwp_ext_code_snippets' );
if ( ! is_array ( $snippets ) ) {
$snippets = array ();
}
2020-04-07 17:12:41 +02:00
if ( 'C' === $type ) { // delete in wp-config file.
2020-05-06 00:47:59 +07:00
if ( false !== $this -> snippet_update_wp_config ( 'delete' , $slug ) ) {
2015-10-15 22:52:37 +10:00
$information [ 'status' ] = 'SUCCESS' ;
}
} else {
if ( isset ( $snippets [ $slug ] ) ) {
unset ( $snippets [ $slug ] );
if ( MainWP_Helper :: update_option ( 'mainwp_ext_code_snippets' , $snippets ) ) {
$information [ 'status' ] = 'SUCCESS' ;
}
} else {
$information [ 'status' ] = 'SUCCESS' ;
}
}
}
MainWP_Helper :: write ( $information );
}
2020-05-06 00:47:59 +07:00
public function snippet_update_wp_config ( $action , $slug , $code = '' ) {
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$config_file = '' ;
2020-04-07 16:53:05 +02:00
if ( file_exists ( ABSPATH . 'wp-config.php' ) ) {
// The config file resides in ABSPATH.
2020-03-27 15:13:11 +00:00
$config_file = ABSPATH . 'wp-config.php' ;
2020-04-23 19:16:35 +02:00
} elseif ( file_exists ( dirname ( ABSPATH ) . '/wp-config.php' ) && ! file_exists ( dirname ( ABSPATH ) . '/wp-settings.php' ) ) {
2020-04-07 16:53:05 +02:00
// The config file resides one level above ABSPATH but is not part of another install.
2020-03-27 15:13:11 +00:00
$config_file = dirname ( ABSPATH ) . '/wp-config.php' ;
}
2019-02-14 22:38:14 +07:00
2020-04-07 16:53:05 +02:00
if ( ! empty ( $config_file ) ) {
2020-03-27 15:13:11 +00:00
$wpConfig = file_get_contents ( $config_file );
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( 'delete' === $action ) {
$wpConfig = preg_replace ( '/' . PHP_EOL . '{1,2}\/\*\*\*snippet_' . $slug . '\*\*\*\/(.*)\/\*\*\*end_' . $slug . '\*\*\*\/' . PHP_EOL . '/is' , '' , $wpConfig );
} elseif ( 'save' === $action ) {
$wpConfig = preg_replace ( '/(\$table_prefix *= *[\'"][^\'|^"]*[\'"] *;)/is' , '${1}' . PHP_EOL . PHP_EOL . '/***snippet_' . $slug . '***/' . PHP_EOL . $code . PHP_EOL . '/***end_' . $slug . '***/' . PHP_EOL , $wpConfig );
}
file_put_contents ( $config_file , $wpConfig );
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
return true ;
}
return false ;
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function run_saved_snippets () {
2015-10-15 22:52:37 +10:00
$action = null ;
if ( isset ( $_POST [ 'action' ] ) ) {
$action = $_POST [ 'action' ];
}
if ( 'run_snippet' === $action || 'save_snippet' === $action || 'delete_snippet' === $action ) {
return ;
} // do not run saved snippets if in do action snippet
if ( get_option ( 'mainwp_ext_snippets_enabled' ) ) {
$snippets = get_option ( 'mainwp_ext_code_snippets' );
if ( is_array ( $snippets ) && count ( $snippets ) > 0 ) {
foreach ( $snippets as $code ) {
2020-05-05 20:13:38 +07:00
MainWP_Helper :: execute_snippet ( $code );
2015-10-15 22:52:37 +10:00
}
}
}
}
2020-04-07 19:04:20 +02:00
public function uploader_action () {
2020-04-07 19:32:01 +02:00
$file_url = base64_decode ( $_POST [ 'url' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
$path = $_POST [ 'path' ];
$filename = $_POST [ 'filename' ];
$information = array ();
if ( empty ( $file_url ) || empty ( $path ) ) {
MainWP_Helper :: write ( $information );
return ;
}
if ( strpos ( $path , 'wp-content' ) === 0 ) {
$path = basename ( WP_CONTENT_DIR ) . substr ( $path , 10 );
2020-03-26 14:11:33 +00:00
} elseif ( strpos ( $path , 'wp-includes' ) === 0 ) {
2015-10-15 22:52:37 +10:00
$path = WPINC . substr ( $path , 11 );
}
if ( '/' === $path ) {
$dir = ABSPATH ;
} else {
$path = str_replace ( ' ' , '-' , $path );
$path = str_replace ( '.' , '-' , $path );
$dir = ABSPATH . $path ;
}
if ( ! file_exists ( $dir ) ) {
2020-04-23 19:16:35 +02:00
if ( false === mkdir ( $dir , 0777 , true ) ) {
2015-10-15 22:52:37 +10:00
$information [ 'error' ] = 'ERRORCREATEDIR' ;
MainWP_Helper :: write ( $information );
return ;
}
}
try {
2020-05-06 00:47:59 +07:00
$upload = MainWP_Helper :: upload_file ( $file_url , $dir , $filename );
2015-10-15 22:52:37 +10:00
if ( null !== $upload ) {
$information [ 'success' ] = true ;
}
} catch ( Exception $e ) {
$information [ 'error' ] = $e -> getMessage ();
}
MainWP_Helper :: write ( $information );
}
2020-04-07 19:04:20 +02:00
public function wordpress_seo () {
2020-05-06 20:22:11 +07:00
MainWP_Wordpress_SEO :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function client_report () {
2020-05-06 20:22:11 +07:00
MainWP_Client_Report :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function page_speed () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Pagespeed :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function woo_com_status () {
2020-05-06 20:22:11 +07:00
MainWP_Child_WooCommerce_Status :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function links_checker () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Links_Checker :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function wordfence () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Wordfence :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function ithemes () {
2020-05-06 20:22:11 +07:00
MainWP_Child_IThemes_Security :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function updraftplus () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Updraft_Plus_Backups :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function wpvivid_backuprestore () {
2020-05-06 20:22:11 +07:00
MainWP_Child_WPvivid_BackupRestore :: instance () -> action ();
2020-03-27 15:13:11 +00:00
}
2019-08-26 23:29:16 +07:00
2020-04-07 19:04:20 +02:00
public function backup_wp () {
2015-10-15 22:52:37 +10:00
if ( ! version_compare ( phpversion (), '5.3' , '>=' ) ) {
$error = sprintf ( __ ( 'PHP Version %s is unsupported.' , 'mainwp-child' ), phpversion () );
MainWP_Helper :: write ( array ( 'error' => $error ) );
}
2020-05-06 20:22:11 +07:00
MainWP_Child_Back_Up_Wordpress :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function wp_rocket () {
2020-05-06 20:22:11 +07:00
MainWP_Child_WP_Rocket :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function backwpup () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Back_WP_Up :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function delete_backup () {
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
$file = $_REQUEST [ 'del' ];
2020-04-23 19:16:35 +02:00
if ( file_exists ( $backupdir . $file ) ) {
unlink ( $backupdir . $file );
2015-10-15 22:52:37 +10:00
}
MainWP_Helper :: write ( array ( 'result' => 'ok' ) );
}
2020-04-07 19:04:20 +02:00
public function update_values () {
2015-10-15 22:52:37 +10:00
$uniId = isset ( $_POST [ 'uniqueId' ] ) ? $_POST [ 'uniqueId' ] : '' ;
MainWP_Helper :: update_option ( 'mainwp_child_uniqueId' , $uniId );
MainWP_Helper :: write ( array ( 'result' => 'ok' ) );
}
2020-05-06 00:47:59 +07:00
public function upload_file ( $file , $offset = 0 ) {
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
header ( 'Content-Description: File Transfer' );
header ( 'Content-Description: File Transfer' );
2020-05-06 00:47:59 +07:00
if ( MainWP_Helper :: ends_with ( $file , '.tar.gz' ) ) {
2015-10-15 22:52:37 +10:00
header ( 'Content-Type: application/x-gzip' );
2020-03-26 14:05:04 +00:00
header ( 'Content-Encoding: gzip' );
2015-10-15 22:52:37 +10:00
} else {
header ( 'Content-Type: application/octet-stream' );
}
header ( 'Content-Disposition: attachment; filename="' . basename ( $file ) . '"' );
header ( 'Expires: 0' );
header ( 'Cache-Control: must-revalidate' );
header ( 'Pragma: public' );
header ( 'Content-Length: ' . filesize ( $backupdir . $file ) );
2020-04-23 19:16:35 +02:00
while ( ob_end_flush () ) {; // phpcs:ignore
2015-10-15 22:52:37 +10:00
}
$this -> readfile_chunked ( $backupdir . $file , $offset );
}
2020-04-07 19:04:20 +02:00
public function readfile_chunked ( $filename , $offset ) {
2020-04-07 17:12:41 +02:00
$chunksize = 1024 ; // how many bytes per chunk?
2020-04-23 19:16:35 +02:00
$handle = fopen ( $filename , 'rb' );
2015-10-15 22:52:37 +10:00
if ( false === $handle ) {
return false ;
}
2020-04-23 19:16:35 +02:00
fseek ( $handle , $offset );
2015-10-15 22:52:37 +10:00
2020-04-23 19:16:35 +02:00
while ( ! feof ( $handle ) ) {
$buffer = fread ( $handle , $chunksize );
2015-10-15 22:52:37 +10:00
echo $buffer ;
2020-04-23 19:16:35 +02:00
ob_flush ();
flush ();
2015-10-15 22:52:37 +10:00
$buffer = null ;
}
2020-04-23 19:16:35 +02:00
return fclose ( $handle );
2015-10-15 22:52:37 +10:00
}
2020-04-07 19:04:20 +02:00
public function settings_tools () {
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'action' ] ) ) {
switch ( $_POST [ 'action' ] ) {
case 'force_destroy_sessions' ;
if ( 0 === get_current_user_id () ) {
MainWP_Helper :: write ( array ( 'error' => __ ( 'Cannot get user_id' , 'mainwp-child' ) ) );
}
wp_destroy_all_sessions ();
$sessions = wp_get_all_sessions ();
if ( empty ( $sessions ) ) {
MainWP_Helper :: write ( array ( 'success' => 1 ) );
} else {
MainWP_Helper :: write ( array ( 'error' => __ ( 'Cannot destroy sessions' , 'mainwp-child' ) ) );
}
break ;
default :
MainWP_Helper :: write ( array ( 'error' => __ ( 'Invalid action' , 'mainwp-child' ) ) );
}
} else {
MainWP_Helper :: write ( array ( 'error' => __ ( 'Missing action' , 'mainwp-child' ) ) );
}
}
2020-04-07 19:04:20 +02:00
public function skeleton_key () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Skeleton_Key :: instance () -> action ();
2015-10-15 22:52:37 +10:00
}
2016-03-03 19:49:09 +01:00
2020-04-07 19:04:20 +02:00
public function custom_post_type () {
2020-05-06 20:22:11 +07:00
MainWP_Custom_Post_Type :: instance () -> action ();
2020-03-27 15:13:11 +00:00
}
2016-05-22 17:16:34 +02:00
2020-04-07 19:04:20 +02:00
public function backup_buddy () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Back_Up_Buddy :: instance () -> action ();
2020-03-27 15:13:11 +00:00
}
2017-02-22 21:39:22 +01:00
2020-04-07 19:04:20 +02:00
public function vulner_checker () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Vulnerability_Checker :: instance () -> action ();
2020-03-27 15:13:11 +00:00
}
2018-09-27 19:52:32 +02:00
2020-04-07 19:04:20 +02:00
public function time_capsule () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Timecapsule :: instance () -> action ();
2020-03-27 15:13:11 +00:00
}
2018-09-27 19:52:32 +02:00
2020-04-07 19:04:20 +02:00
public function wp_staging () {
2020-05-06 20:22:11 +07:00
MainWP_Child_Staging :: instance () -> action ();
2020-03-27 15:13:11 +00:00
}
2018-09-27 19:52:32 +02:00
2020-04-07 19:04:20 +02:00
public function extra_execution () {
2020-03-27 15:13:11 +00:00
$post = $_POST ;
$information = array ();
2020-04-07 16:53:05 +02:00
$information = apply_filters ( 'mainwp_child_extra_execution' , $information , $post );
2020-03-27 15:13:11 +00:00
MainWP_Helper :: write ( $information );
}
2018-09-27 19:52:32 +02:00
2020-04-07 19:04:20 +02:00
public function disconnect () {
2020-04-07 17:12:41 +02:00
$this -> deactivation ( false );
2018-09-27 19:52:32 +02:00
MainWP_Helper :: write ( array ( 'result' => 'success' ) );
2020-03-27 15:13:11 +00:00
}
2016-08-18 20:51:19 +02:00
2020-04-23 17:05:27 +02:00
public static function fix_for_custom_themes () {
2016-03-03 19:49:09 +01:00
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2016-03-03 19:49:09 +01:00
}
2017-01-04 21:03:57 +01:00
if ( function_exists ( 'et_register_updates_component' ) ) {
et_register_updates_component ();
}
2016-03-03 19:49:09 +01:00
}
2015-10-15 22:52:37 +10:00
}