Merge with brand01

* Fixed: issues with displaying broken links data for specific setups
* Fixed: compatibility issues with the latest PageSpeed Insights plugin version
* Fixed: an issue with publishing "future" posts
* Fixed: an issue with sending email alerts in specific setups
* Fixed: an issue with saving code snippets in wp-config.php when the file is in a custom location
* Fixed: an issue with clearing unused scheduled cron jobs
* Added: support for the new PageSpeed Insights plugin options
* Updated: disabled the "Remove readme.html" security check feature for WPEngine hosted child sites 
* Updated: support for detecting premium themes updates
This commit is contained in:
Thang Hoang Van 2019-02-14 22:38:14 +07:00
parent 1e11c93c4a
commit bd4d9d2432
14 changed files with 851 additions and 481 deletions

View file

@ -2,14 +2,14 @@
class MainWP_Child_Branding {
public static $instance = null;
protected $child_plugin_dir;
protected $settings = null;
public $child_plugin_dir;
public $child_branding_options = null;
static function Instance() {
if ( null === MainWP_Child_Branding::$instance ) {
MainWP_Child_Branding::$instance = new MainWP_Child_Branding();
}
return MainWP_Child_Branding::$instance;
}
@ -17,25 +17,65 @@ class MainWP_Child_Branding {
$this->child_plugin_dir = dirname( dirname( __FILE__ ) );
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
add_filter( 'mainwp_child_plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
$label = get_option( 'mainwp_branding_button_contact_label' );
if ( ! empty( $label ) ) {
$label = stripslashes( $label );
} else {
$label = 'Contact Support';
}
$this->settings['contact_support_label'] = $label;
$this->settings['extra_settings'] = get_option( 'mainwp_branding_extra_settings' );
$this->child_branding_options = $this->init_options();
}
function init_options(){
$opts = get_option( 'mainwp_child_branding_settings' );
if ( !is_array( $opts ) ) {
// compatible with old code
$opts = array();
$label = get_option( 'mainwp_branding_button_contact_label' );
if ( ! empty( $label ) ) {
$label = stripslashes( $label );
}
$opts['contact_label'] = $label;
$opts['extra_settings'] = get_option( 'mainwp_branding_extra_settings' );
}
if ( !isset($opts['contact_label']) || empty($opts['contact_label']) ) {
$opts['contact_label'] = 'Contact Support';
}
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
$cancelled_branding = ( $disconnected === 'yes' ) && ! $preserve_branding;
$opts['cancelled_branding'] = $cancelled_branding;
$opts['branding_preserve_title'] = '';
if ( ! $cancelled_branding ) {
if (isset($opts['branding_header'])) {
$branding_header = $opts['branding_header'];
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
}
}
}
return $opts;
}
function get_extra_options() {
$extra = array();
if (is_array($this->child_branding_options) && isset($this->child_branding_options['extra_settings'])) {
$extra = $this->child_branding_options['extra_settings'];
if (!is_array($extra))
$extra = array();
}
return $extra;
}
public function plugin_row_meta( $plugin_meta, $plugin_file, $child_plugin_slug ) {
if ( $child_plugin_slug !== $plugin_file ) {
return $plugin_meta;
}
if ( ! self::is_branding() ) {
if ( ! $this->is_branding() ) {
return $plugin_meta;
}
// hide View details links
@ -52,6 +92,7 @@ class MainWP_Child_Branding {
}
public function child_deactivation() {
// will remove later
$dell_all = array(
'mainwp_branding_disable_change',
'mainwp_branding_disable_switching_theme',
@ -73,9 +114,40 @@ class MainWP_Child_Branding {
'mainwp_branding_extra_settings',
'mainwp_branding_ext_enabled',
);
foreach ( $dell_all as $opt ) {
delete_option( $opt );
}
$brandingOptions_empty = array(
'hide',
'disable_change',
'disable_switching_theme',
'show_support',
'support_email',
'support_message',
'remove_restore',
'remove_setting',
'remove_server_info',
'remove_wp_tools',
'remove_wp_setting',
'remove_permalink',
//'branding_header', // don't remove header
'contact_label',
'email_message',
'message_return_sender',
'submit_button_title',
'extra_settings',
'branding_ext_enabled',
);
foreach($brandingOptions_empty as $opt) {
if (isset($this->child_branding_options[$opt])) {
$this->child_branding_options[$opt] = '';
}
}
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
}
@ -95,8 +167,13 @@ class MainWP_Child_Branding {
if ( ! is_array( $settings ) ) {
return $information;
}
$current_extra_setting = $this->settings['extra_settings'];
MainWP_Helper::update_option( 'mainwp_branding_ext_enabled', 'Y', 'yes' );
$current_settings = $this->child_branding_options;
$current_extra_setting = $this->child_branding_options['extra_settings'];
//MainWP_Helper::update_option( 'mainwp_branding_ext_enabled', 'Y' );
$current_settings['branding_ext_enabled'] = 'Y';
$header = array(
'name' => $settings['child_plugin_name'],
'description' => $settings['child_plugin_desc'],
@ -104,23 +181,44 @@ class MainWP_Child_Branding {
'authoruri' => $settings['child_plugin_author_uri'],
'pluginuri' => isset($settings['child_plugin_uri']) ? $settings['child_plugin_uri'] : '',
);
MainWP_Helper::update_option( 'mainwp_branding_preserve_branding', $settings['child_preserve_branding'], 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_plugin_header', $header, 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_support_email', $settings['child_support_email'] );
MainWP_Helper::update_option( 'mainwp_branding_support_message', $settings['child_support_message'] );
MainWP_Helper::update_option( 'mainwp_branding_remove_restore', $settings['child_remove_restore'] );
MainWP_Helper::update_option( 'mainwp_branding_remove_setting', $settings['child_remove_setting'], 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_remove_server_info', $settings['child_remove_server_info'] );
MainWP_Helper::update_option( 'mainwp_branding_remove_connection_detail', (isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0) );
MainWP_Helper::update_option( 'mainwp_branding_remove_wp_tools', $settings['child_remove_wp_tools'], 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_remove_wp_setting', $settings['child_remove_wp_setting'], 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_remove_permalink', $settings['child_remove_permalink'], 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_button_contact_label', $settings['child_button_contact_label'], 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_send_email_message', $settings['child_send_email_message'] );
MainWP_Helper::update_option( 'mainwp_branding_message_return_sender', $settings['child_message_return_sender'] );
MainWP_Helper::update_option( 'mainwp_branding_submit_button_title', $settings['child_submit_button_title'] );
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
MainWP_Helper::update_option( 'mainwp_branding_disable_wp_branding', $settings['child_disable_wp_branding'] );
MainWP_Helper::update_option( 'mainwp_branding_preserve_branding', $settings['child_preserve_branding'], 'yes' ); // to compatible with old version of child report plugin
MainWP_Helper::update_option( 'mainwp_branding_plugin_header', $header, 'yes' ); // to compatible
// MainWP_Helper::update_option( 'mainwp_branding_support_email', $settings['child_support_email'] );
// MainWP_Helper::update_option( 'mainwp_branding_support_message', $settings['child_support_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_restore', $settings['child_remove_restore'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_setting', $settings['child_remove_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_server_info', $settings['child_remove_server_info'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_connection_detail', (isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0) );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_tools', $settings['child_remove_wp_tools'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_setting', $settings['child_remove_wp_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_permalink', $settings['child_remove_permalink'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_button_contact_label', $settings['child_button_contact_label'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_send_email_message', $settings['child_send_email_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_message_return_sender', $settings['child_message_return_sender'] );
// MainWP_Helper::update_option( 'mainwp_branding_submit_button_title', $settings['child_submit_button_title'] );
// if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_wp_branding', $settings['child_disable_wp_branding'] );
// }
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
$current_settings['branding_header'] = $header;
$current_settings['support_email'] = $settings['child_support_email'];
$current_settings['support_message'] = $settings['child_support_message'];
$current_settings['remove_restore'] = $settings['child_remove_restore'];
$current_settings['remove_setting'] = $settings['child_remove_setting'];
$current_settings['remove_server_info'] = $settings['child_remove_server_info'];
$current_settings['remove_connection_detail'] = isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0 ;
$current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools'];
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
$current_settings['remove_permalink'] = $settings['child_remove_permalink'];
$current_settings['contact_label'] = $settings['child_button_contact_label'];
$current_settings['email_message'] = $settings['child_send_email_message'];
$current_settings['return_sender'] = $settings['child_message_return_sender'];
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
}
$extra_setting = array(
@ -206,31 +304,40 @@ class MainWP_Child_Branding {
$extra_setting['favico_image'] = $current_extra_setting['favico_image'];
}
MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' );
//MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' );
$current_settings['extra_settings'] = $extra_setting;
// keep it to compatible with old version of child reports plugin
if ( $settings['child_plugin_hide'] ) {
MainWP_Helper::update_option( 'mainwp_branding_child_hide', 'T', 'yes' );
} else {
MainWP_Helper::update_option( 'mainwp_branding_child_hide', '' );
}
//
// if ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', '' );
// }
if ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) {
MainWP_Helper::update_option( 'mainwp_branding_show_support', 'T' );
} else {
MainWP_Helper::update_option( 'mainwp_branding_show_support', '' );
}
// if ( $settings['child_disable_change'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', '' );
// }
if ( $settings['child_disable_change'] ) {
MainWP_Helper::update_option( 'mainwp_branding_disable_change', 'T' );
} else {
MainWP_Helper::update_option( 'mainwp_branding_disable_change', '' );
}
// if ( $settings['child_disable_switching_theme'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', '' );
// }
if ( $settings['child_disable_switching_theme'] ) {
MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', 'T' );
} else {
MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', '' );
}
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
$current_settings['show_support'] = ( $settings['child_show_support_button'] && !empty($settings['child_support_email']) ) ? 'T' : '';
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
$information['result'] = 'SUCCESS';
@ -266,10 +373,8 @@ class MainWP_Child_Branding {
public function branding_init() {
$extra_setting = $this->settings['extra_settings'];
if ( ! is_array( $extra_setting ) ) {
$extra_setting = array();
}
$extra_setting = $this->get_extra_options();
// to hide updates notice
if (is_admin()) {
@ -279,27 +384,28 @@ class MainWP_Child_Branding {
// front end
add_action( 'add_admin_bar_menus', array( $this, 'add_admin_bar_menus' ));
}
$opts = $this->child_branding_options;
$cancelled_branding = ( get_option( 'mainwp_child_branding_disconnected' ) === 'yes' ) && ! get_option( 'mainwp_branding_preserve_branding' );
$cancelled_branding = $opts['cancelled_branding'];
if ( $cancelled_branding ) {
return;
}
// enable branding in case child plugin is deactive
add_filter( 'all_plugins', array( $this, 'branding_child_plugin' ) );
if ( self::is_branding() ) {
// enable branding in case child plugin deactive and re-activated
add_filter( 'all_plugins', array( $this, 'modify_plugin_header' ) );
if ( $this->is_branding() ) {
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
}
if ( get_option( 'mainwp_branding_ext_enabled' ) !== 'Y' ) {
if ( !isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) {
return;
}
add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 );
if ( 'T' === get_option( 'mainwp_branding_disable_change' ) ) {
if ( 'T' === $opts['disable_change']) {
// Disable the wordpress plugin update notifications
remove_action('load-update-core.php', 'wp_update_plugins');
@ -323,7 +429,7 @@ class MainWP_Child_Branding {
// to fix
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );//
if ( get_option( 'mainwp_branding_disable_wp_branding' ) !== 'Y' ) {
if ( $opts['disable_wp_branding'] !== 'Y' ) {
add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 );
add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 );
// branding site generator
@ -366,14 +472,17 @@ class MainWP_Child_Branding {
} else if ( !current_user_can( 'administrator' ) ) {
return false;
}
$extra_setting = $this->settings['extra_settings'];
if ( ! is_array( $extra_setting ) ) {
$extra_setting = array();
$extra_setting = $this->get_extra_options();
if ( empty ( $extra_setting ) ) {
return false;
}
if ( 'T' === get_option( 'mainwp_branding_show_support' ) ) {
$title = $this->settings['contact_support_label'];
$opts = $this->child_branding_options;
if ( 'T' === $opts['show_support'] ) {
$title = $opts['contact_label'];
if ( isset( $extra_setting['show_button_in'] ) && ( 2 === (int) $extra_setting['show_button_in'] || 3 === (int) $extra_setting['show_button_in'] ) ) {
$title = $this->settings['contact_support_label'];
$title = $opts['contact_label'];
add_menu_page( $title, $title, 'read', 'ContactSupport2', array(
$this,
'contact_support',
@ -381,7 +490,7 @@ class MainWP_Child_Branding {
}
if ( isset( $extra_setting['show_button_in'] ) && ( 1 === $extra_setting['show_button_in'] || 3 === $extra_setting['show_button_in'] ) ) {
add_submenu_page( null, $title, $this->settings['contact_support_label'], 'read', 'ContactSupport', array(
add_submenu_page( null, $title, $opts['contact_label'], 'read', 'ContactSupport', array(
$this,
'contact_support',
) );
@ -392,10 +501,7 @@ class MainWP_Child_Branding {
}
function remove_default_post_metaboxes() {
$extra_setting = $this->settings['extra_settings'];
if ( ! is_array( $extra_setting ) ) {
$extra_setting = array();
}
$extra_setting = $this->get_extra_options();
add_filter( 'manage_posts_columns', array( &$this, 'custom_post_columns' ) );
add_filter( 'manage_edit-post_tag_columns', array( &$this, 'manage_my_category_columns' ) );
@ -435,10 +541,7 @@ class MainWP_Child_Branding {
function custom_post_columns( $defaults ) {
$extra_setting = $this->settings['extra_settings'];
if ( ! is_array( $extra_setting ) ) {
$extra_setting = array();
}
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['hide_metabox_post_comments'] ) && $extra_setting['hide_metabox_post_comments'] ) {
unset( $defaults['comments'] );
@ -454,10 +557,7 @@ class MainWP_Child_Branding {
}
function manage_my_category_columns( $defaults ) {
$extra_setting = $this->settings['extra_settings'];
if ( ! is_array( $extra_setting ) ) {
$extra_setting = array();
}
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['hide_metabox_post_slug'] ) && $extra_setting['hide_metabox_post_slug'] ) {
unset( $defaults['slug'] );
@ -467,10 +567,7 @@ class MainWP_Child_Branding {
}
function remove_default_page_metaboxes() {
$extra_setting = $this->settings['extra_settings'];
if ( ! is_array( $extra_setting ) ) {
$extra_setting = array();
}
$extra_setting = $this->get_extra_options();
add_filter( 'manage_pages_columns', array( &$this, 'custom_pages_columns' ) );
@ -498,10 +595,7 @@ class MainWP_Child_Branding {
}
function custom_pages_columns( $defaults ) {
$extra_setting = $this->settings['extra_settings'];
if ( ! is_array( $extra_setting ) ) {
$extra_setting = array();
}
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['hide_metabox_page_comments'] ) && $extra_setting['hide_metabox_page_comments'] ) {
unset( $defaults['comments'] );
@ -541,14 +635,14 @@ class MainWP_Child_Branding {
}
function admin_footer_text() {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
echo wp_kses_post( nl2br( stripslashes( $extra_setting['dashboard_footer'] ) ) );
}
}
function custom_favicon_frontend() {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['favico_image']['url'] ) && ! empty( $extra_setting['favico_image']['url'] ) ) {
$favico = $extra_setting['favico_image']['url'];
echo '<link rel="shortcut icon" href="' . esc_url( $favico ) . '"/>' . "\n";
@ -556,7 +650,7 @@ class MainWP_Child_Branding {
}
function custom_login_logo() {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_image']['url'] ) && ! empty( $extra_setting['login_image']['url'] ) ) {
$login_logo = $extra_setting['login_image']['url'];
echo '<style type="text/css">
@ -567,7 +661,7 @@ class MainWP_Child_Branding {
function custom_login_headerurl( $value ) {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_image_link'] ) && ! empty( $extra_setting['login_image_link'] ) ) {
return $extra_setting['login_image_link'];
}
@ -577,7 +671,7 @@ class MainWP_Child_Branding {
function custom_login_headertitle( $value ) {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_image_title'] ) && ! empty( $extra_setting['login_image_title'] ) ) {
return $extra_setting['login_image_title'];
}
@ -586,7 +680,7 @@ class MainWP_Child_Branding {
}
function custom_gettext( $translations, $text, $domain = 'default' ) {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
$texts_replace = $extra_setting['texts_replace'];
if ( is_array( $texts_replace ) && count( $texts_replace ) > 0 ) {
foreach ( $texts_replace as $text => $replace ) {
@ -601,9 +695,9 @@ class MainWP_Child_Branding {
function custom_admin_css() {
$header_css = '';
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( is_array( $extra_setting ) && isset( $extra_setting['admin_css'] ) && ! empty( $extra_setting['admin_css'] ) ) {
if ( isset( $extra_setting['admin_css'] ) && ! empty( $extra_setting['admin_css'] ) ) {
$header_css .= $extra_setting['admin_css'];
}
@ -622,14 +716,14 @@ class MainWP_Child_Branding {
}
function custom_login_css() {
$extra_setting = $this->settings['extra_settings'];
if ( is_array( $extra_setting ) && isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) {
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) {
echo '<style>' . MainWP_Helper::parse_css( $extra_setting['login_css'] ) . '</style>';
}
}
function custom_the_generator( $generator, $type = '' ) {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['site_generator'] ) ) {
if ( ! empty( $extra_setting['site_generator'] ) ) {
switch ( $type ) :
@ -671,7 +765,7 @@ class MainWP_Child_Branding {
function custom_dashboard_widgets() {
global $wp_meta_boxes;
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['remove_widget_welcome'] ) && $extra_setting['remove_widget_welcome'] ) {
remove_action( 'welcome_panel', 'wp_welcome_panel' );
}
@ -690,28 +784,28 @@ class MainWP_Child_Branding {
}
public function branding_global_footer() {
$extra_setting = $this->settings['extra_settings'];
$extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['global_footer'] ) && ! empty( $extra_setting['global_footer'] ) ) {
echo wp_kses_post( nl2br( stripslashes( $extra_setting['global_footer'] ) ) );
}
}
public function send_support_mail() {
$email = get_option( 'mainwp_branding_support_email' );
$email = $this->child_branding_options['support_email'];
$sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
$subject = !empty( $sub ) ? $sub : "MainWP - Support Contact";
$content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
global $current_user;
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
$headers .= "From: \"" . $current_user->user_email . "\" <" . $current_user->user_email . ">\r\n";
//$headers .= "From: \"" . $current_user->user_email . "\" <" . $current_user->user_email . ">\r\n";
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
$mail .= "<p>Sent from WordPress page: " . ( ! empty( $_POST["mainwp_branding_send_from_page"] ) ? "<a href='" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "'>" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "</a></p>\r\n\r\n" : "" );
$mail .= "<p>Client Email: " . $current_user->user_email . " </p>\r\n\r\n";
$mail .= "<p>Support Text:</p>\r\n\r\n";
$mail .= "<p>" . $content . "</p>\r\n\r\n";
if ( wp_mail( $email, $subject, $mail, $headers ) ) {
if ( @wp_mail( $email, $subject, $mail, $headers ) ) {
;
}
@ -736,17 +830,19 @@ class MainWP_Child_Branding {
}
</style>
<?php
$opts = $this->child_branding_options;
if ( isset( $_POST['submit'] ) ) {
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], '_contactNonce' ) ) {
return false;
}
$from_page = $_POST['mainwp_branding_send_from_page'];
$back_link = get_option( 'mainwp_branding_message_return_sender' );
$back_link = $opts['message_return_sender'];
$back_link = ! empty( $back_link ) ? $back_link : 'Go Back';
$back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
if ( $this->send_support_mail() ) {
$send_email_message = get_option( 'mainwp_branding_send_email_message' );
$send_email_message = $opts['send_email_message'];
if ( ! empty( $send_email_message ) ) {
$send_email_message = stripslashes( $send_email_message );
} else {
@ -768,12 +864,12 @@ class MainWP_Child_Branding {
$from_page = urldecode( $fullurl );
}
$support_message = get_option( 'mainwp_branding_support_message' );
$support_message = $opts['support_message'];
$support_message = nl2br( stripslashes( $support_message ) );
?>
<form action="" method="post">
<div style="width: 99%;">
<h2><?php echo esc_html( $this->settings['contact_support_label'] ); ?></h2>
<h2><?php echo esc_html( $opts['contact_label'] ); ?></h2>
<div style="height: auto; margin-bottom: 10px; text-align: left">
<p><?php echo wp_kses_post( $support_message ); ?></p>
@ -796,7 +892,7 @@ class MainWP_Child_Branding {
</div>
<br/>
<?php
$button_title = get_option( 'mainwp_branding_submit_button_title' );
$button_title = $opts['submit_button_title'];
$button_title = ! empty( $button_title ) ? $button_title : __( 'Submit' );
?>
<input id="mainwp-branding-contact-support-submit" type="submit" name="submit"
@ -827,47 +923,59 @@ class MainWP_Child_Branding {
}
$args = array(
'id' => 999,
'title' => $this->settings['contact_support_label'],
'title' => $this->child_branding_options['contact_label'],
'parent' => 'top-secondary',
'href' => $href,
'meta' => array(
'class' => 'mainwp_branding_support_top_bar_button',
'title' => $this->settings['contact_support_label'],
'title' => $this->child_branding_options['contact_label'],
),
);
$wp_admin_bar->add_node( $args );
}
public static function is_branding() {
$cancelled_branding = ( get_option( 'mainwp_child_branding_disconnected' ) === 'yes' ) && ! get_option( 'mainwp_branding_preserve_branding' );
if ( $cancelled_branding ) {
return false;
}
public function is_branding() {
$opts = $this->child_branding_options;
// hide
if ( 'T' === get_option( 'mainwp_branding_child_hide' ) ) {
return true;
}
// branding
$header = get_option( 'mainwp_branding_plugin_header' );
if ( is_array( $header ) && ! empty( $header['name'] ) ) {
return true;
}
if (!isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y') {
return false;
}
return false;
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$cancelled_branding = $opts['cancelled_branding'];
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
if ( $cancelled_branding ) {
return false;
}
// hide
if ( 'T' === $is_hide ) {
return true;
}
if ( is_array( $branding_header ) && !empty( $branding_header['name'] ) ) {
return true;
}
return false;
}
public static function get_branding() {
if ( self::is_branding() ) {
$header = get_option( 'mainwp_branding_plugin_header' );
return $header['name'];
public function get_branding_title() {
if ( $this->is_branding() ) {
$branding_header = $this->child_branding_options['branding_header'];
return $branding_header['name'];
}
return 'MainWP';
return '';
}
public function get_branding_options() {
return $this->child_branding_options;
}
public function save_branding_options( $name, $val ) {
$this->child_branding_options[$name] = $val;
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
}
public function add_admin_bar_menus() {
$hide_slugs = apply_filters('mainwp_child_hide_update_notice' , array());
@ -998,15 +1106,7 @@ class MainWP_Child_Branding {
}
public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) {
// this is causing of some plugin's menu not added
// if ( 'T' === get_option( 'mainwp_branding_disable_change' ) ) {
// // disable: edit, update, install, active themes and plugins
// if ( false !== strpos( $cap, 'plugins' ) || false !== strpos( $cap, 'themes' ) || 'edit_theme_options' === $cap ) {
// $caps[0] = 'do_not_allow';
// }
// }
if ( 'T' === get_option( 'mainwp_branding_disable_switching_theme' ) ) {
if ( isset($this->child_branding_options['disable_switching_theme']) && 'T' === $this->child_branding_options['disable_switching_theme'] ) {
// disable: theme switching
if ( 'switch_themes' === $cap ) {
$caps[0] = 'do_not_allow';
@ -1015,24 +1115,35 @@ class MainWP_Child_Branding {
return $caps;
}
public function branding_child_plugin( $plugins ) {
if ( 'T' === get_option( 'mainwp_branding_child_hide' ) ) {
foreach ( $plugins as $key => $value ) {
$plugin_slug = basename( $key, '.php' );
if ( 'mainwp-child' === $plugin_slug ) {
unset( $plugins[ $key ] );
}
}
public function modify_plugin_header( $plugins ) {
$opts = $this->child_branding_options;
if ( is_array($opts) ) {
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$cancelled_branding = $opts['cancelled_branding'];
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
return $plugins;
}
if ( $cancelled_branding ) {
return $plugins;
}
$header = get_option( 'mainwp_branding_plugin_header' );
if ( is_array( $header ) && ! empty( $header['name'] ) ) {
return $this->update_child_header( $plugins, $header );
} else {
return $plugins;
}
if ( $is_hide === 'T' ) {
foreach ( $plugins as $key => $value ) {
$plugin_slug = basename( $key, '.php' );
if ( 'mainwp-child-reports' === $plugin_slug ) {
unset( $plugins[ $key ] );
}
}
return $plugins;
}
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) {
return $this->update_plugin_header( $plugins, $branding_header );
} else {
return $plugins;
}
}
return $plugins;
}
function hide_update_notice( $slugs ) {
@ -1056,7 +1167,7 @@ class MainWP_Child_Branding {
return $value;
}
public function update_child_header( $plugins, $header ) {
public function update_plugin_header( $plugins, $header ) {
$plugin_key = '';
foreach ( $plugins as $key => $value ) {
$plugin_slug = basename( $key, '.php' );

View file

@ -34,6 +34,7 @@ class MainWP_Child_Links_Checker {
}
blc_init();
MainWP_Helper::update_option( 'mainwp_linkschecker_ext_enabled', 'Y', 'yes' );
// need this try()
try {
if ( isset( $_POST['mwp_action'] ) ) {
@ -186,7 +187,6 @@ class MainWP_Child_Links_Checker {
function set_showhide() {
MainWP_Helper::update_option( 'mainwp_linkschecker_ext_enabled', 'Y', 'yes' );
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
MainWP_Helper::update_option( 'mainwp_linkschecker_hide_plugin', $hide );
$information['result'] = 'SUCCESS';

View file

@ -164,6 +164,13 @@ class MainWP_Child_Pagespeed {
$current_values['strategy'] = $_POST['strategy'];
}
if ( isset( $settings['store_screenshots'] ) ) {
$current_values['store_screenshots'] = $settings['store_screenshots'];
}
if ( isset( $settings['use_schedule'] ) ) {
$current_values['use_schedule'] = $settings['use_schedule'];
}
if ( isset( $settings['max_execution_time'] ) ) {
$current_values['max_execution_time'] = $settings['max_execution_time'];
}
@ -184,10 +191,6 @@ class MainWP_Child_Pagespeed {
$current_values['log_api_errors'] = ( $settings['log_exception'] ) ? true : false;
}
if ( isset( $settings['scan_technical'] ) ) {
$current_values['scan_method'] = $settings['scan_technical'];
}
if ( isset( $settings['report_expiration'] ) ) {
$current_values['recheck_interval'] = $settings['report_expiration'];
}
@ -197,8 +200,9 @@ class MainWP_Child_Pagespeed {
$current_values['check_pages'] = in_array( 'page', $settings['check_report'] ) ? true : false;
$current_values['check_posts'] = in_array( 'post', $settings['check_report'] ) ? true : false;
$current_values['check_categories'] = in_array( 'category', $settings['check_report'] ) ? true : false;
$current_values['check_custom_urls'] = in_array( 'custom_urls', $settings['check_report'] ) ? true : false;
} else {
$current_values['check_pages'] = $current_values['check_posts'] = $current_values['check_categories'] = false;
$current_values['check_pages'] = $current_values['check_posts'] = $current_values['check_categories'] = $current_values['check_custom_urls'] = false;
}
}
@ -253,7 +257,7 @@ class MainWP_Child_Pagespeed {
if ( $checkstatus ) {
$information['error'] = __( 'The API is busy checking other pages, please try again later.', 'gpagespeedi' );
} else {
do_action( 'googlepagespeedinsightsworker', array(), true );
do_action( 'googlepagespeedinsightsworker', array(), $forceRecheck );
$information['checked_pages'] = 1;
}
}
@ -288,15 +292,19 @@ class MainWP_Child_Pagespeed {
if ( 'both' === $strategy || 'desktop' === $strategy ) {
$result = self::cal_pagespeed_data( 'desktop' );
$data['desktop_score'] = $result['average_score'];
$data['desktop_total_pages'] = $result['total_pages'];
$data['desktop_last_modified'] = $result['last_modified'];
if ( !empty($result) && is_array($result) ) {
$data['desktop_score'] = $result['average_score'];
$data['desktop_total_pages'] = $result['total_pages'];
$data['desktop_last_modified'] = $result['last_modified'];
}
}
if ( 'both' === $strategy || 'mobile' === $strategy ) {
$result = self::cal_pagespeed_data( 'mobile' );
$data['mobile_score'] = $result['average_score'];
$data['mobile_total_pages'] = $result['total_pages'];
$data['mobile_last_modified'] = $result['last_modified'];
if ( !empty($result) && is_array($result) ) {
$data['mobile_score'] = $result['average_score'];
$data['mobile_total_pages'] = $result['total_pages'];
$data['mobile_last_modified'] = $result['last_modified'];
}
}
$information['data'] = $data;
@ -307,15 +315,15 @@ class MainWP_Child_Pagespeed {
static function cal_pagespeed_data( $strategy ) {
global $wpdb;
if ( ! defined( 'GPI_DIRECTORY' ) ) {
return 0;
return false;
}
if ( 'desktop' !== $strategy && 'mobile' !== $strategy ) {
return 0;
return false;
}
$score_column = $strategy . '_score';
$page_stats_column = $strategy . '_page_stats';
//$page_stats_column = $strategy . '_page_stats';
$data_typestocheck = self::getTypesToCheck( 'all' );
@ -325,7 +333,7 @@ class MainWP_Child_Pagespeed {
$allpagedata = $wpdb->get_results(
$wpdb->prepare(
"SELECT ID, URL, $score_column, $page_stats_column
"SELECT ID, URL, $score_column
FROM $gpi_page_stats
WHERE ($data_typestocheck[0])",
$data_typestocheck[1]
@ -343,11 +351,10 @@ class MainWP_Child_Pagespeed {
$allpagereports = $wpdb->get_results(
$wpdb->prepare(
"SELECT r.rule_key, r.rule_name, r.rule_impact
"SELECT r.rule_key, r.rule_name
FROM $gpi_page_stats d
INNER JOIN $gpi_page_reports r
ON r.page_id = d.ID
AND r.rule_impact > 0
AND r.strategy = '$strategy'
WHERE ($reports_typestocheck[0])",
$reports_typestocheck[1]

View file

@ -33,19 +33,20 @@ class MainWP_Child_Plugins_Check {
}
public function __construct() {
$this->schedule_watchdog();
if ( get_option('mainwp_child_plugintheme_days_outdate') ) {
$this->schedule_watchdog();
add_action( $this->cron_name_batching, array( $this, 'run_check' ) );
add_action( $this->cron_name_daily, array( $this, 'run_check' ) );
add_action( $this->cron_name_batching, array( $this, 'run_check' ) );
add_action( $this->cron_name_daily, array( $this, 'run_check' ) );
add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) );
add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) );
//add_filter( 'plugin_row_meta', array( $this, 'change_plugin_row_meta' ), 10, 4 );
//add_filter( 'plugin_row_meta', array( $this, 'change_plugin_row_meta' ), 10, 4 );
add_filter( 'plugins_api_args', array( $this, 'modify_plugin_api_search_query' ), 10, 2 );
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
add_filter( 'plugins_api_args', array( $this, 'modify_plugin_api_search_query' ), 10, 2 );
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
}
}
private function cleanup_basic() {

View file

@ -66,7 +66,7 @@ class MainWP_Child_Server_Information {
var data = {
action: 'mainwp-child_dismiss_warnings',
what: pAction,
warnings: <?php echo intval($warnings); ?>
warnings: <?php echo intval($warnings); ?>
};
jQuery.ajax( {
@ -537,11 +537,11 @@ class MainWP_Child_Server_Information {
}
public static function render() {
$branding_title = 'MainWP Child';
$isBranding = false;
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
$isBranding = true;
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
$isBranding = true;
if ( $branding_title == '' ) {
$branding_title = 'MainWP Child';
$isBranding = false;
}
?>
@ -956,10 +956,10 @@ class MainWP_Child_Server_Information {
}
protected static function checkDirectoryMainWPDirectory( $write = true ) {
$branding_title = 'MainWP';
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
}
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ($branding_title == '')
$branding_title = 'MainWP';
$branding_title .= ' Upload Directory';
try {
@ -1009,7 +1009,7 @@ class MainWP_Child_Server_Information {
?>
<tr class="mwp-not-generate-row">
<td></td>
<td><?php echo esc_html( stripslashes( $pName ) ); ?><br/><?php echo esc_html( ( MainWP_Child_Branding::is_branding() ) ? '' : $pDirectory ); ?>
<td><?php echo esc_html( stripslashes( $pName ) ); ?><br/><?php echo esc_html( ( MainWP_Child_Branding::Instance()->is_branding() ) ? '' : $pDirectory ); ?>
</td>
<td><?php echo esc_html( $pCheck ); ?></td>
<td><?php echo esc_html( $pResult ); ?></td>
@ -1467,14 +1467,12 @@ class MainWP_Child_Server_Information {
$lines = array_filter( $lines );
if ( empty( $lines ) ) {
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
} else {
$msg = esc_html__( 'MainWP is unable to find your error logs, please contact your host for server error logs.', 'mainwp-child' );
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ($branding_title == '') {
$branding_title = 'MainWP';
}
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
echo '<tr><td colspan="2">' . $msg . '</td></tr>';
return;
}
@ -1621,10 +1619,9 @@ class MainWP_Child_Server_Information {
}
public static function renderConnectionDetails() {
$branding_title = 'MainWP';
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
}
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ($branding_title == '')
$branding_title = 'MainWP';
global $current_user;
$uniqueId = get_option('mainwp_child_uniqueId');

View file

@ -33,15 +33,19 @@ class MainWP_Child_Themes_Check {
}
public function __construct() {
$this->schedule_watchdog();
add_action( $this->cron_name_batching, array( $this, 'run_check' ) );
add_action( $this->cron_name_daily, array( $this, 'run_check' ) );
add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) );
if ( get_option('mainwp_child_plugintheme_days_outdate') ) {
$this->schedule_watchdog();
add_action( $this->cron_name_batching, array( $this, 'run_check' ) );
add_action( $this->cron_name_daily, array( $this, 'run_check' ) );
add_filter( 'themes_api_args', array( $this, 'modify_theme_api_search_query' ), 10, 2 );
add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) );
add_filter( 'themes_api_args', array( $this, 'modify_theme_api_search_query' ), 10, 2 );
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
}
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
}
private function cleanup_basic() {

View file

@ -115,8 +115,8 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
}
class MainWP_Child {
public static $version = '3.5.3';
private $update_version = '1.3';
public static $version = '3.5.4';
private $update_version = '1.5';
private $callableFunctions = array(
'stats' => 'getSiteStats',
@ -185,7 +185,7 @@ class MainWP_Child {
'disconnect' => 'disconnect',
'time_capsule' => 'time_capsule',
'extra_excution' => 'extra_execution', // deprecated
'extra_execution' => 'extra_execution',
'extra_execution' => 'extra_execution'
);
private $FTP_ERROR = 'Failed! Please, add FTP details for automatic updates.';
@ -203,7 +203,6 @@ class MainWP_Child {
private $filterFunction = null;
public static $brandingTitle = null;
private $branding_robust = 'MainWP';
public static $subPages;
public static $subPagesLoaded = false;
@ -231,7 +230,9 @@ class MainWP_Child {
add_action( 'admin_init', array( &$this, 'admin_init' ) );
add_action( 'admin_head', array( &$this, 'admin_head' ) );
add_action( 'init', array( &$this, 'localization' ), 33 );
add_action( 'pre_current_active_plugins', array( &$this, 'pre_current_active_plugins' ) );
add_action( 'pre_current_active_plugins', array( &$this, 'detect_premium_themesplugins_updates' ) ); // to support detect premium themes/plugins update
add_action( 'core_upgrade_preamble', array( &$this, 'detect_premium_themesplugins_updates' ) );
if ( is_admin() ) {
MainWP_Helper::update_option( 'mainwp_child_plugin_version', self::$version, 'yes' );
@ -242,22 +243,16 @@ class MainWP_Child {
MainWP_Clone::get()->init();
MainWP_Child_Server_Information::init();
MainWP_Client_Report::Instance()->init();
MainWP_Child_Plugins_Check::Instance();
MainWP_Child_Themes_Check::Instance();
MainWP_Child_Plugins_Check::Instance();
MainWP_Child_Themes_Check::Instance();
$this->run_saved_snippets();
if ( ! get_option( 'mainwp_child_pubkey' ) ) {
MainWP_Helper::update_option( 'mainwp_child_branding_disconnected', 'yes', 'yes' );
MainWP_Child_Branding::Instance()->save_branding_options('branding_disconnected', 'yes');
MainWP_Helper::update_option( 'mainwp_child_branding_disconnected', 'yes', 'yes' ); // to compatible
}
$cancelled_branding = ( get_option( 'mainwp_child_branding_disconnected' ) === 'yes' ) && ! get_option( 'mainwp_branding_preserve_branding' );
if ( ! $cancelled_branding ) {
$branding_header = get_option( 'mainwp_branding_plugin_header' );
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
$this->branding_robust = stripslashes( $branding_header['name'] );
}
}
add_action( 'admin_notices', array( &$this, 'admin_notice' ) );
add_filter( 'plugin_row_meta', array( &$this, 'plugin_row_meta' ), 10, 2 );
@ -310,15 +305,17 @@ class MainWP_Child {
'mainwp_security',
'mainwp_backupwordpress_ext_enabled',
'mainwp_wprocket_ext_enabled',
'mainwp_wordfence_ext_enabled',
//'mainwp_wordfence_ext_enabled',
'mainwp_branding_button_contact_label',
'mainwp_branding_extra_settings',
'mainwp_branding_child_hide',
'mainwp_branding_ext_enabled',
'mainwp_creport_ext_branding_enabled',
//'mainwp_creport_ext_branding_enabled',
'mainwp_pagespeed_ext_enabled',
'mainwp_linkschecker_ext_enabled',
'mainwp_ithemes_ext_enabled',
//'mainwp_ithemes_ext_enabled',
'mainwp_child_branding_settings',
'mainwp_child_plugintheme_days_outdate'
);
$query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
foreach ($options as $option) {
@ -360,7 +357,6 @@ class MainWP_Child {
$options = array(
'mainwp_child_legacy',
'mainwp_child_auth',
'mainwp_branding_ext_enabled',
'mainwp_child_uniqueId',
'mainwp_child_htaccess_set',
'mainwp_child_fix_htaccess',
@ -401,33 +397,33 @@ class MainWP_Child {
'mainwp_kwl_statistic_data_',
'mainwp_kwl_enable_statistic',
'mainwpKeywordLinks',
'mainwp_branding_ext_enabled',
'mainwp_branding_plugin_header',
'mainwp_branding_support_email',
'mainwp_branding_support_message',
'mainwp_branding_remove_restore',
'mainwp_branding_remove_setting',
'mainwp_branding_remove_wp_tools',
'mainwp_branding_remove_wp_setting',
'mainwp_branding_remove_permalink',
'mainwp_branding_button_contact_label',
'mainwp_branding_send_email_message',
'mainwp_branding_message_return_sender',
'mainwp_branding_submit_button_title',
'mainwp_branding_disable_wp_branding',
'mainwp_branding_extra_settings',
'mainwp_branding_child_hide',
'mainwp_branding_show_support',
'mainwp_branding_disable_change',
// 'mainwp_branding_ext_enabled',
// 'mainwp_branding_plugin_header',
// 'mainwp_branding_support_email',
// 'mainwp_branding_support_message',
// 'mainwp_branding_remove_restore',
// 'mainwp_branding_remove_setting',
// 'mainwp_branding_remove_wp_tools',
// 'mainwp_branding_remove_wp_setting',
// 'mainwp_branding_remove_permalink',
// 'mainwp_branding_button_contact_label',
// 'mainwp_branding_send_email_message',
// 'mainwp_branding_message_return_sender',
// 'mainwp_branding_submit_button_title',
// 'mainwp_branding_disable_wp_branding',
// 'mainwp_branding_extra_settings',
// 'mainwp_branding_child_hide',
// 'mainwp_branding_show_support',
// 'mainwp_branding_disable_change',
);
foreach ( $options as $option ) {
MainWP_Helper::fix_option( $option );
}
} else if ( ( false === $update_version ) || ( '1.0' === $update_version ) || ( '1.1' === $update_version ) ) {
} else if ( ( '1.0' === $update_version ) || ( '1.1' === $update_version ) ) {
$options = array(
'mainwp_child_pubkey',
'mainwp_child_branding_disconnected',
'mainwp_branding_plugin_header',
//'mainwp_child_branding_disconnected',
//'mainwp_branding_plugin_header',
'mainwp_child_update_version',
'mainwp_child_auth',
'mainwp_child_clone_permalink',
@ -444,14 +440,14 @@ class MainWP_Child {
'mainwp_updraftplus_ext_enabled',
'mainwpKeywordLinks',
'mainwp_keyword_links_htaccess_set',
'mainwp_branding_button_contact_label',
'mainwp_branding_extra_settings',
'mainwp_branding_ext_enabled',
'mainwp_creport_ext_branding_enabled',
//'mainwp_branding_button_contact_label',
//'mainwp_branding_extra_settings',
//'mainwp_branding_ext_enabled',
//'mainwp_creport_ext_branding_enabled',
'mainwp_pagespeed_ext_enabled',
'mainwp_linkschecker_ext_enabled',
'mainwp_wordfence_ext_enabled',
'mainwp_ithemes_ext_enabled',
//'mainwp_wordfence_ext_enabled',
//'mainwp_ithemes_ext_enabled',
'mainwp_maintenance_opt_alert_404',
);
foreach ( $options as $option ) {
@ -479,9 +475,46 @@ class MainWP_Child {
}
MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' );
}
} else if ($update_version == '1.2') {
MainWP_Child_Plugins_Check::Instance()->cleanup_deactivation(false);
MainWP_Child_Themes_Check::Instance()->cleanup_deactivation(false);
}
if ( !empty($update_version) && version_compare($update_version, '1.4', '<=' ) ) { // 3.5.4
if ( ! is_array( get_option( 'mainwp_child_branding_settings' ) ) ) {
// to fix: reduce number of options
$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',
'hide_child_reports' => 'mainwp_creport_branding_stream_hide',
'branding_ext_enabled' => 'mainwp_branding_ext_enabled'
);
$convertBranding = array();
foreach ( $brandingOptions as $option => $old ) {
$value = get_option( $old );
$convertBranding[ $option ] = $value;
}
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $convertBranding );
}
}
MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' );
@ -507,27 +540,27 @@ class MainWP_Child {
public function admin_notice() {
//Admin Notice...
if ( is_plugin_active( 'mainwp-child/mainwp-child.php' ) ) {
if ( ! get_option( 'mainwp_child_pubkey' ) && MainWP_Helper::isAdmin() && is_admin() ) {
$child_name = ( $this->branding_robust === 'MainWP' ) ? 'MainWP Child' : $this->branding_robust;
$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' ) . $this->branding_robust . __( ' Dashboard <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>';
if ( ! MainWP_Child_Branding::is_branding() ) {
$msg .= '<p>';
$msg .= __( 'You can also turn on the unique security ID option in <a href="admin.php?page=mainwp_child_tab">', 'mainwp-child' ) . $this->branding_robust . __( ' 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 );
}
}
if ( ! get_option( 'mainwp_child_pubkey' ) && MainWP_Helper::isAdmin() && is_admin() ) {
$branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
$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';
$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>';
if ( ! MainWP_Child_Branding::Instance()->is_branding() ) {
$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 );
}
MainWP_Child_Server_Information::showWarnings();
}
@ -535,14 +568,28 @@ class MainWP_Child {
load_plugin_textdomain( 'mainwp-child', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
}
public function pre_current_active_plugins() {
public function detect_premium_themesplugins_updates() {
if (isset($_GET['_detect_plugins_updates']) && $_GET['_detect_plugins_updates'] == 'yes') {
// to fix some premium plugins update notification
$current = get_site_transient( 'update_plugins' );
set_site_transient( 'update_plugins', $current );
$plugin_updates = get_plugin_updates();
set_site_transient( 'mainwp_update_plugins_cached', $plugin_updates, DAY_IN_SECONDS);
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
$plugins = get_plugin_updates();
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
set_site_transient( 'mainwp_update_plugins_cached', $plugins, DAY_IN_SECONDS);
wp_destroy_current_session(); // to fix issue multi user session
}
if (isset($_GET['_detect_themes_updates']) && $_GET['_detect_themes_updates'] == 'yes') {
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
$themes = get_theme_updates();
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
set_site_transient( 'mainwp_update_themes_cached', $themes, DAY_IN_SECONDS);
wp_destroy_current_session(); // to fix issue multi user session
}
}
@ -600,9 +647,11 @@ class MainWP_Child {
}
function admin_menu() {
$cancelled_branding = ( get_option( 'mainwp_child_branding_disconnected' ) === 'yes' ) && ! get_option( 'mainwp_branding_preserve_branding' );
$branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
$is_hide = isset( $branding_opts['hide'] ) ? $branding_opts['hide'] : '';
$cancelled_branding = $branding_opts['cancelled_branding'];
if ( get_option( 'mainwp_branding_remove_wp_tools' ) && ! $cancelled_branding ) {
if ( isset($branding_opts['remove_wp_tools']) && $branding_opts['remove_wp_tools'] && ! $cancelled_branding ) {
remove_menu_page( 'tools.php' );
$pos = stripos( $_SERVER['REQUEST_URI'], 'tools.php' ) ||
stripos( $_SERVER['REQUEST_URI'], 'import.php' ) ||
@ -612,7 +661,7 @@ class MainWP_Child {
}
}
// if preserve branding do not remove menus
if ( get_option( 'mainwp_branding_remove_wp_setting' ) && ! $cancelled_branding ) {
if ( isset($branding_opts['remove_wp_setting']) && $branding_opts['remove_wp_setting'] && ! $cancelled_branding ) {
remove_menu_page( 'options-general.php' );
$pos = stripos( $_SERVER['REQUEST_URI'], 'options-general.php' ) ||
stripos( $_SERVER['REQUEST_URI'], 'options-writing.php' ) ||
@ -626,7 +675,7 @@ class MainWP_Child {
}
}
if ( get_option( 'mainwp_branding_remove_permalink' ) && ! $cancelled_branding ) {
if ( isset($branding_opts['remove_permalink']) && $branding_opts['remove_permalink'] && ! $cancelled_branding ) {
remove_submenu_page( 'options-general.php', 'options-permalink.php' );
$pos = stripos( $_SERVER['REQUEST_URI'], 'options-permalink.php' );
if ( false !== $pos ) {
@ -636,13 +685,13 @@ class MainWP_Child {
}
$remove_all_child_menu = false;
if ( get_option( 'mainwp_branding_remove_setting' ) && get_option( 'mainwp_branding_remove_restore' ) && get_option( 'mainwp_branding_remove_server_info' ) ) {
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'] ) {
$remove_all_child_menu = true;
}
// if preserve branding do not hide menus
if ( ( ! $remove_all_child_menu && get_option( 'mainwp_branding_child_hide' ) !== 'T' ) || $cancelled_branding ) {
$branding_header = get_option( 'mainwp_branding_plugin_header' );
if ( ( ! $remove_all_child_menu && $is_hide !== 'T' ) || $cancelled_branding ) {
$branding_header = isset( $branding_opts['branding_header'] ) ? $branding_opts['branding_header'] : array();
if ( ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) && ! $cancelled_branding ) {
self::$brandingTitle = $child_menu_title = stripslashes( $branding_header['name'] );
$child_page_title = $child_menu_title . ' Settings';
@ -662,6 +711,7 @@ class MainWP_Child {
do_action( 'mainwp-child-subpages', $subpageargs ); // to compatible
$sub_pages = array();
$all_subpages = apply_filters( 'mainwp-child-init-subpages', array() );
if ( !is_array( $all_subpages ) )
@ -709,11 +759,13 @@ class MainWP_Child {
if ( isset($_GET['tab']) ) {
$shownPage = $_GET['tab'];
}
$branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
$hide_settings = $branding_opts['remove_setting'] ? true : false;
$hide_restore = $branding_opts['remove_restore'] ? true : false;
$hide_server_info = $branding_opts['remove_server_info'] ? true : false;
$hide_connection_detail = $branding_opts['remove_connection_detail'] ? true : false;
$hide_settings = get_option( 'mainwp_branding_remove_setting' ) ? true : false;
$hide_restore = get_option( 'mainwp_branding_remove_restore' ) ? true : false;
$hide_server_info = get_option( 'mainwp_branding_remove_server_info' ) ? true : false;
$hide_connection_detail = get_option( 'mainwp_branding_remove_connection_detail' ) ? true : false;
$hide_style = 'style="display:none"';
if ($shownPage == '') {
@ -783,10 +835,13 @@ class MainWP_Child {
if (empty($shownPage))
$shownPage = 'settings';
$hide_settings = get_option( 'mainwp_branding_remove_setting' ) ? true : false;
$hide_restore = get_option( 'mainwp_branding_remove_restore' ) ? true : false;
$hide_server_info = get_option( 'mainwp_branding_remove_server_info' ) ? true : false;
$hide_connection_detail = get_option( 'mainwp_branding_remove_connection_detail' ) ? true : false;
$branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
$hide_settings = $branding_opts['remove_setting'] ? true : false;
$hide_restore = $branding_opts['remove_restore'] ? true : false;
$hide_server_info = $branding_opts['remove_server_info'] ? true : false;
$hide_connection_detail = $branding_opts['remove_connection_detail'] ? true : false;
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
?>
@ -1064,7 +1119,7 @@ class MainWP_Child {
}
}
function check_login() {
function check_login() {
$file = '';
if ( isset( $_REQUEST['f'] ) ) {
$file = $_REQUEST['f'];
@ -1084,13 +1139,30 @@ class MainWP_Child {
MainWP_Helper::error( __( 'Authentication failed! Please deactivate and re-activate the MainWP Child plugin on this site.', 'mainwp-child' ) );
}
$auth_user = false;
if ( $auth ) {
//disable duo auth for mainwp
remove_action('init', 'duo_verify_auth', 10);
//Check if the user exists & is an administrator
if ( isset( $_POST['function'] ) && isset( $_POST['user'] ) ) {
$user = get_user_by( 'login', $_POST['user'] );
$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 );
}
}
// if not valid alternative admin
if ( ! $user ) {
// check connected admin existed
$user = get_user_by( 'login', $_POST['user'] );
$auth_user = $_POST['user'];
}
if ( ! $user ) {
MainWP_Helper::error( __( 'That administrator username was not found on this child site. Please verify that it is an existing administrator.', 'mainwp-child' ) );
}
@ -1099,11 +1171,16 @@ class MainWP_Child {
MainWP_Helper::error( __( 'That user is not an administrator. Please use an administrator user to establish the connection.', 'mainwp-child' ) );
}
$this->login( $_REQUEST['user'] );
$this->login( $auth_user );
}
if ( isset( $_POST['function'] ) && 'visitPermalink' === $_POST['function'] ) {
if ( $this->login( $_POST['user'], true ) ) {
if (empty($auth_user)) {
$auth_user = $_POST['user'];
}
if ( $this->login( $auth_user, true ) ) {
return;
} else {
exit();
@ -1261,7 +1338,17 @@ class MainWP_Child {
global $current_user; //wp variable
//Login the user
if ( isset( $_REQUEST['login_required'] ) && ( '1' === $_REQUEST['login_required'] ) && isset( $_REQUEST['user'] ) ) {
$username = rawurldecode( $_REQUEST['user'] );
$alter_login_required = false;
$username = rawurldecode( $_REQUEST['user'] );
if ( isset( $_REQUEST['alt_user'] ) && !empty( $_REQUEST['alt_user'] ) ) {
$alter_login_required = $this->check_login_as( $_REQUEST['alt_user'] );
if ( $alter_login_required ) {
$username = rawurldecode( $_REQUEST['alt_user'] );
}
}
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' ) ) {
@ -1291,9 +1378,14 @@ class MainWP_Child {
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' );
// if is not alternative admin login
// it is connected admin login
if ( ! $alter_login_required ) {
// log out if connected admin is not admin level 10
do_action( 'wp_logout' );
return;
return;
}
}
}
@ -1323,6 +1415,7 @@ class MainWP_Child {
$_SESSION['size'] = $_POST['size'];
}
// to support open not wp-admin url
$open_location = isset( $_REQUEST['open_location'] ) ? $_REQUEST['open_location'] : '';
if ( ! empty( $open_location ) ) {
$open_location = base64_decode( $open_location );
@ -1347,7 +1440,6 @@ class MainWP_Child {
exit();
}
add_filter( 'the_content', array( MainWP_Keyword_Links::Instance(), 'filter_content' ), 100, 2 );
wp_redirect( admin_url( $where ) );
exit();
}
@ -1387,10 +1479,26 @@ class MainWP_Child {
MainWP_Helper::error( __( 'Authentication failed! Please deactivate and re-activate the MainWP Child plugin on this site.', 'mainwp-child' ) );
}
$auth_user = false;
if ( $auth ) {
//Check if the user exists & is an administrator
if ( isset( $_POST['function'] ) && isset( $_POST['user'] ) ) {
$user = get_user_by( 'login', $_POST['user'] );
$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 );
}
}
// if alternative admin not existed
if ( ! $user ) {
// check connected admin existed
$user = get_user_by( 'login', $_POST['user'] );
$auth_user = $_POST['user'];
}
if ( ! $user ) {
MainWP_Helper::error( __( 'That administrator username was not found on this child site. Please verify that it is an existing administrator.', 'mainwp-child' ) );
}
@ -1399,11 +1507,16 @@ class MainWP_Child {
MainWP_Helper::error( __( 'That user is not an administrator. Please use an administrator user to establish the connection.', 'mainwp-child' ) );
}
$this->login( $_REQUEST['user'] );
$this->login( $auth_user );
}
if ( isset( $_POST['function'] ) && 'visitPermalink' === $_POST['function'] ) {
if ( $this->login( $_POST['user'], true ) ) {
if (empty($auth_user)) {
$auth_user = $_POST['user'];
}
if ( $this->login( $auth_user, true ) ) {
return;
} else {
exit();
@ -1470,6 +1583,31 @@ class MainWP_Child {
}
// Check to support login by alternative admin
// return false will login by connected admin user
// return true will try to login as alternative user
function check_login_as( $alter_login ) {
if ( !empty( $alter_login ) ) {
// check alternative admin existed
$user = get_user_by( 'login', $alter_login );
if ( ! $user ) {
//That administrator username was not found on this child site
return false;
}
if ( 10 != $user->wp_user_level && ( ! isset( $user->user_level ) || 10 != $user->user_level ) && ! $user->has_cap( 'level_10' ) ) {
// That user is not an administrator
return false;
}
return true; // ok, will try to login by alternative user
}
return false;
}
function default_option_active_plugins( $default ) {
if ( ! is_array( $default ) ) {
$default = array();
@ -1508,10 +1646,16 @@ class MainWP_Child {
//Logout if required
if ( isset( $current_user->user_login ) ) {
if ( $current_user->user_login === $username ) {
// to fix issue multi user session
$user_id = wp_validate_auth_cookie();
if ( $user_id && $user_id === $current_user->ID ) {
return true;
}
wp_set_auth_cookie( $current_user->ID );
return true;
}
do_action( 'wp_logout' );
}
@ -1521,7 +1665,7 @@ class MainWP_Child {
// wp_set_auth_cookie($user->ID);
wp_set_current_user( $user->ID );
wp_set_auth_cookie( $user->ID );
wp_set_auth_cookie( $user->ID );
if ( $doAction ) {
do_action( 'wp_login', $user->user_login );
}
@ -1899,11 +2043,11 @@ class MainWP_Child {
// trick to prevent some premium plugins re-create update info
remove_all_filters('pre_set_site_transient_update_plugins');
$information['plugin_updates'] = get_plugin_updates();
// to support cached premium plugins update info, hooking in the bulk_upgrade()
// to support cached premium plugins update info, hooking in the bulk_upgrade()
add_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ) );
$information['plugin_updates'] = get_plugin_updates();
$plugins = explode( ',', urldecode( $_POST['list'] ) );
$premiumPlugins = array();
$premiumUpdates = get_option( 'mainwp_premium_updates' );
@ -2011,6 +2155,10 @@ class MainWP_Child {
@wp_update_themes();
include_once( ABSPATH . '/wp-admin/includes/theme.php' );
// to support cached premium themes update info, hooking in the bulk_upgrade()
add_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ) );
$information['theme_updates'] = $this->upgrade_get_theme_updates();
$themes = explode( ',', $_POST['list'] );
$premiumThemes = array();
@ -2094,6 +2242,10 @@ class MainWP_Child {
}
remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 );
delete_site_transient( 'mainwp_update_themes_cached' ); // to fix cached update info
// $last_update = get_site_transient( 'update_themes' );
// if ( !empty( $last_update ) && property_exists( $last_update, 'last_checked' ) ) {
// $last_update->last_checked = $originalLastChecked;
@ -2197,9 +2349,32 @@ class MainWP_Child {
$pre = false;
$cached_update_info = get_site_transient( 'mainwp_update_plugins_cached' );
if ( is_array($cached_update_info) && count($cached_update_info) > 0 ) {
foreach( $cached_update_info as $slug => $plugin_update ) {
if ( !isset( $_transient_data->response[ $slug ] ) && isset($plugin_update->update) ) {
$_transient_data->response[ $slug ] = $plugin_update->update;
foreach( $cached_update_info as $slug => $info ) {
if ( !isset( $_transient_data->response[ $slug ] ) && isset($info->update) ) {
$_transient_data->response[ $slug ] = $info->update;
$pre = true;
}
}
}
if ($pre == false)
return $false;
return $_transient_data;
}
public function set_cached_update_themes( $false = false, $_transient_data = null ) {
if ( ! is_object( $_transient_data ) ) {
$_transient_data = new stdClass;
}
$pre = false;
$cached_update_info = get_site_transient( 'mainwp_update_themes_cached' );
if ( is_array($cached_update_info) && count($cached_update_info) > 0 ) {
foreach( $cached_update_info as $slug => $info ) {
if ( !isset( $_transient_data->response[ $slug ] ) && isset($info->update) ) {
$_transient_data->response[ $slug ] = $info->update;
$pre = true;
}
}
@ -2253,11 +2428,13 @@ class MainWP_Child {
MainWP_Helper::error( __( 'Invalid request!', 'mainwp-child' ) );
}
MainWP_Helper::update_option( 'mainwp_child_branding_disconnected', 'yes', 'yes' );
//Already added - can't readd. Deactivate plugin..
if ( get_option( 'mainwp_child_pubkey' ) ) {
// set disconnect status to yes here, it will empty after reconnected
MainWP_Child_Branding::Instance()->save_branding_options('branding_disconnected', 'yes');
MainWP_Helper::update_option( 'mainwp_child_branding_disconnected', 'yes', 'yes' ); // to compatible with old client reports
MainWP_Helper::error( __( 'Public key already set. Please reset the MainWP Child plugin on the child site and try again.', 'mainwp-child' ) );
}
if ( '' != get_option( 'mainwp_child_uniqueId' ) ) {
@ -2294,7 +2471,6 @@ class MainWP_Child {
$nossl_key = uniqid( '', true );
MainWP_Helper::update_option( 'mainwp_child_nossl_key', $nossl_key, 'yes' );
$information['nosslkey'] = $nossl_key;
MainWP_Helper::update_option( 'mainwp_child_branding_disconnected', '', 'yes' );
$information['register'] = 'OK';
$information['uniqueId'] = get_option( 'mainwp_child_uniqueId', '' );
@ -2348,9 +2524,21 @@ class MainWP_Child {
$my_post = array();
if ( 'publish' === $action ) {
// to fix error post slug
//wp_publish_post( $postId );
wp_update_post(array('ID' => $postId, 'post_status' => 'publish' ));
$post_current = get_post( $postId );
if ( empty($post_current) ) {
$information['status'] = 'FAIL';
} else {
if ( 'future' == $post_current->post_status ) {
wp_publish_post( $postId ); // to fix: fail when publish future page
wp_update_post(array('ID' => $postId,
'post_date' => current_time( 'mysql', false ),
'post_date_gmt' => current_time( 'mysql', true )
));
} else {
// to fix error post slug
wp_update_post(array('ID' => $postId,'post_status' => 'publish' ));
}
}
} else if ( 'update' === $action ) {
$postData = $_POST['post_data'];
$my_post = is_array( $postData ) ? $postData : array();
@ -2897,7 +3085,7 @@ class MainWP_Child {
$message .= sprintf( __( 'Password: %s' ), $new_user['user_pass'] ) . "\r\n";
$message .= wp_login_url() . "\r\n";
wp_mail( $user_email, sprintf( __( '[%s] Your username and password' ), $blogname ), $message );
@wp_mail( $user_email, sprintf( __( '[%s] Your username and password' ), $blogname ), $message, '' );
}
$information['added'] = true;
MainWP_Helper::write( $information );
@ -3461,15 +3649,16 @@ class MainWP_Child {
$this->updateExternalSettings();
}
MainWP_Child_Branding::Instance()->save_branding_options('branding_disconnected', '');
MainWP_Helper::update_option( 'mainwp_child_branding_disconnected', '', 'yes' );
if ( isset( $_POST['server'] ) ) {
MainWP_Helper::update_option( 'mainwp_child_server', $_POST['server'] );
}
if ( isset( $_POST['numberdaysOutdatePluginTheme'] ) && ! empty( $_POST['numberdaysOutdatePluginTheme'] ) ) {
if ( isset( $_POST['numberdaysOutdatePluginTheme'] ) ) {
$days_outdate = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
if ( $days_outdate !== $_POST['numberdaysOutdatePluginTheme'] ) {
$days_outdate = $_POST['numberdaysOutdatePluginTheme'];
if ( $days_outdate != $_POST['numberdaysOutdatePluginTheme'] ) {
$days_outdate = intval($_POST['numberdaysOutdatePluginTheme']);
MainWP_Helper::update_option( 'mainwp_child_plugintheme_days_outdate', $days_outdate );
MainWP_Child_Plugins_Check::Instance()->cleanup_deactivation( false );
MainWP_Child_Themes_Check::Instance()->cleanup_deactivation( false );
@ -3479,7 +3668,7 @@ class MainWP_Child {
$information['version'] = self::$version;
$information['wpversion'] = $wp_version;
$information['siteurl'] = get_option( 'siteurl' );
$information['wpe'] = function_exists( 'is_wpe' ) ? 1 : 0;
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
$information['site_info'] = array(
'wpversion' => $wp_version,
@ -3614,23 +3803,23 @@ class MainWP_Child {
}
}
// to fix bug
$info_update_plugins_cached = get_site_transient( 'mainwp_update_plugins_cached' );
if ( is_array( $info_update_plugins_cached ) && ( count( $info_update_plugins_cached ) > 0 ) ) {
if ( null !== $this->filterFunction ) {
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
}
// to fix premium plugs update
$cached_plugins_update = get_site_transient( 'mainwp_update_plugins_cached' );
if ( is_array( $cached_plugins_update ) && ( count( $cached_plugins_update ) > 0 ) ) {
if (!isset($information['plugin_updates'])) {
$information['plugin_updates'] = array();
}
foreach( $info_update_plugins_cached as $slug => $plugin_update ) {
foreach( $cached_plugins_update as $slug => $plugin_update ) {
if ( !isset( $information['plugin_updates'][ $slug ] ) ) {
$information['plugin_updates'][ $slug ] = $plugin_update;
}
}
}
// end fix
if ( null !== $this->filterFunction ) {
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
}
if ( null !== $this->filterFunction ) {
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
}
@ -3653,6 +3842,26 @@ class MainWP_Child {
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
}
// to fix premium themes update
$cached_themes_update = get_site_transient( 'mainwp_update_themes_cached' );
if ( is_array( $cached_themes_update ) && ( count( $cached_themes_update ) > 0 ) ) {
if (!isset($information['theme_updates'])) {
$information['theme_updates'] = array();
}
foreach ( $cached_themes_update as $slug => $theme_update ) {
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
if ( in_array( $name, $premiumThemes ) ) {
continue;
}
if ( isset( $information['theme_updates'][ $slug ] ) ) {
continue;
}
$information['theme_updates'][ $slug ] = $theme_update;
}
}
$translation_updates = wp_get_translation_updates();
if ( !empty( $translation_updates ) ) {
$information['translation_updates'] = array();
@ -4773,7 +4982,7 @@ class MainWP_Child {
global $wp_version;
$information['version'] = self::$version;
$information['wpversion'] = $wp_version;
$information['wpe'] = function_exists( 'is_wpe' ) ? 1 : 0;
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
MainWP_Helper::write( $information );
}
@ -5226,8 +5435,8 @@ class MainWP_Child {
'<div>' . 'USER AGENT: ' . $agent . '</div>';
$mail = '<div>404 alert</div>
<div></div>' . $mail;
wp_mail( $email, 'MainWP - 404 Alert: ' . $blog, MainWP_Helper::formatEmail( $email, $mail ), array(
'From: "' . $from_email . '" <' . $from_email . '>',
@wp_mail( $email, 'MainWP - 404 Alert: ' . $blog, MainWP_Helper::formatEmail( $email, $mail ), array(
//'From: "' . $from_email . '" <' . $from_email . '>',
'content-type: text/html',
) );
@ -5299,13 +5508,33 @@ class MainWP_Child {
}
public function snippetUpdateWPConfig( $action, $slug, $code = '' ) {
$wpConfig = file_get_contents( ABSPATH . 'wp-config.php' );
if ( 'delete' === $action ) {
$wpConfig = preg_replace( '/' . PHP_EOL . '{1,2}\/\*\*\*snippet_' . $slug . '\*\*\*\/(.*)\/\*\*\*end_' . $slug . '\*\*\*\/' . PHP_EOL . '/is', '', $wpConfig );
} else if ( '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( ABSPATH . 'wp-config.php', $wpConfig );
$config_file = '';
if ( file_exists( ABSPATH . 'wp-config.php') ) {
/** The config file resides in ABSPATH */
$config_file = ABSPATH . 'wp-config.php';
} elseif ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
/** The config file resides one level above ABSPATH but is not part of another install */
$config_file = dirname( ABSPATH ) . '/wp-config.php';
}
if ( !empty($config_file) ) {
$wpConfig = file_get_contents( $config_file );
if ( 'delete' === $action ) {
$wpConfig = preg_replace( '/' . PHP_EOL . '{1,2}\/\*\*\*snippet_' . $slug . '\*\*\*\/(.*)\/\*\*\*end_' . $slug . '\*\*\*\/' . PHP_EOL . '/is', '', $wpConfig );
} else if ( '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 );
return true;
}
return false;
}
function run_saved_snippets() {
@ -5564,7 +5793,7 @@ class MainWP_Child {
MainWP_Helper::write( $information );
}
function disconnect() {
function disconnect() {
$this->deactivation(false);
MainWP_Helper::write( array( 'result' => 'success' ) );
}

View file

@ -256,7 +256,7 @@ class MainWP_Client_Report {
$args['date_to'] = date( 'Y-m-d H:i:s', $args['date_to'] );
}
if ( MainWP_Child_Branding::is_branding() ) {
if ( MainWP_Child_Branding::Instance()->is_branding() ) {
$args['hide_child_reports'] = 1;
}
@ -316,6 +316,8 @@ class MainWP_Client_Report {
function get_other_tokens_data( $records, $tokens, &$skip_records ) {
// convert context name of tokens to context name saved in child report
// some context are not difference
$convert_context_name = array(
'comment' => 'comments',
'plugin' => 'plugins',
@ -489,19 +491,19 @@ class MainWP_Client_Report {
'backup' => 'mainwp_backup',
);
$some_allowed_data = array(
'ID',
'name',
'title',
'oldversion',
'currentversion',
'date',
'time',
'count',
'author',
'old.version',
'current.version',
);
// $some_allowed_data = array(
// 'ID',
// 'name',
// 'title',
// 'oldversion',
// 'currentversion',
// 'date',
// 'time',
// 'count',
// 'author',
// 'old.version',
// 'current.version',
// );
$context = $action = '';
$str_tmp = str_replace( array( '[', ']' ), '', $section );
@ -807,30 +809,33 @@ class MainWP_Client_Report {
}
function set_showhide() {
// MainWP_Helper::update_option( 'mainwp_creport_ext_branding_enabled', 'Y', 'yes' );
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
MainWP_Helper::update_option( 'mainwp_creport_branding_stream_hide', $hide, 'yes' );
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
MainWP_Child_Branding::Instance()->save_branding_options('hide_child_reports', $hide);
MainWP_Helper::update_option( 'mainwp_creport_branding_stream_hide', $hide, 'yes' ); // to compatible with old child reports
$information['result'] = 'SUCCESS';
return $information;
return $information;
}
public function creport_init() {
// if ( get_option( 'mainwp_creport_ext_branding_enabled' ) !== 'Y' ) {
// return;
// }
$branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
$hide_nag = false;
if ( get_option( 'mainwp_creport_branding_stream_hide' ) === 'hide' ) {
add_filter( 'all_plugins', array( $this, 'creport_branding_plugin' ) );
add_action( 'admin_menu', array( $this, 'creport_remove_menu' ) );
$hide_nag = true;
}
if ( MainWP_Child_Branding::is_branding() ) {
// check setting of 'hide_child_reports'
if ( isset($branding_opts['hide_child_reports']) && $branding_opts['hide_child_reports'] == 'hide' ) {
add_filter( 'all_plugins', array( $this, 'creport_branding_plugin' ) );
add_action( 'admin_menu', array( $this, 'creport_remove_menu' ) );
$hide_nag = true;
}
if ( ! $hide_nag ) {
// check child branding settings
if ( MainWP_Child_Branding::Instance()->is_branding() ) {
$hide_nag = true;
}
}
if ($hide_nag) {
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );

View file

@ -300,21 +300,14 @@ class MainWP_Clone {
?>
<p><?php esc_html_e( 'Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child' ); ?><?php echo esc_html( $uploadSize ); ?>)</p>
<?php
$branding_msg = '';
if ( MainWP_Child_Branding::is_branding() ) {
$branding_title = MainWP_Child_Branding::get_branding();
$branding_msg = 'If you have a FULL backup created by basic ' . esc_html( stripslashes( $branding_title ) ) . ' Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.';
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ( $branding_title != '' ) {
$branding_msg = 'If you have a FULL backup created by basic ' . esc_html( stripslashes( $branding_title ) ) . ' Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.';
} else {
$branding_msg = esc_html__( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.', 'mainwp-child' );
}
?>
<em>
<?php
if ($branding_msg != '') {
echo $branding_msg ;
} else {
esc_html_e( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.', 'mainwp-child' );
}
?>
<br/>
<em> <?php echo $branding_msg ; ?> <br/>
<?php esc_html_e( 'A database only backup will not work.', 'mainwp-child' ); ?></em><br/><br/>
<form action="<?php echo esc_attr( admin_url( 'options-general.php?page=mainwp_child_tab&tab=restore-clone&upload=yes' ) ); ?>"
method="post"

View file

@ -263,18 +263,21 @@ class MainWP_Helper {
}
}
// current user may be connected admin or alternative admin
$current_uid = $current_user->ID;
//Set up a new post (adding addition information)
$usr = get_user_by( 'login', $_POST['user'] );
//$usr = get_user_by( 'login', $_POST['user'] );
//$new_post['post_author'] = $current_user->ID;
$is_robot_post = false;
$is_robot_post = false; // retirement soon
if ( isset( $_POST['isMainWPRobot'] ) && ! empty( $_POST['isMainWPRobot'] ) ) {
$is_robot_post = true;
}
$post_author = isset( $new_post['post_author'] ) ? $new_post['post_author'] : $usr->ID;
if ( $is_robot_post ) {
$post_author = isset( $new_post['post_author'] ) ? $new_post['post_author'] : $current_uid;
if ( $is_robot_post ) { // retirement soon
if ( 1 === $post_author ) {
$new_post['post_author'] = $usr->ID;
$new_post['post_author'] = $current_uid;
} else if ( ! is_numeric( $post_author ) ) {
$user_author = get_user_by( 'login', $post_author );
if ( $user_author ) {
@ -289,12 +292,12 @@ class MainWP_Helper {
if ( ! empty( $_author ) ) {
$new_post['post_author'] = $_author->ID;
} else {
$new_post['post_author'] = $usr->ID;
$new_post['post_author'] = $current_uid;
}
unset( $new_post['custom_post_author'] );
}
$post_author = ! empty( $post_author ) ? $post_author : $usr->ID;
$post_author = ! empty( $post_author ) ? $post_author : $current_uid;
$new_post['post_author'] = $post_author;
$is_ezine_post = ! empty( $post_custom['_ezine_post_article_source'] ) ? true : false;
@ -1433,6 +1436,10 @@ static function remove_filters_with_method_name( $hook_name = '', $method_name =
return false;
}
public static function is_wp_engine() {
return function_exists( 'is_wpe' ) && is_wpe();
}
public static function check_files_exists( $files = array(), $return = false ) {
$missing = array();
if (is_array($files)) {

View file

@ -318,6 +318,11 @@ class MainWP_Security {
}
public static function remove_readme( $force = false ) {
// to prevent remove readme.html file on WPE hosts
if ( MainWP_Helper::is_wp_engine() )
return true;
if ( $force || self::get_security_option( 'readme' ) ) {
if ( @file_exists( ABSPATH . 'readme.html' ) ) {
if ( ! @unlink( ABSPATH . 'readme.html' ) ) {

View file

@ -50,7 +50,7 @@ class MainWP_Wordpress_SEO {
if ( $this->import_seo_settings( $temporary_file ) ) {
$information['success'] = true;
} else {
throw new Exception( __( 'Settings could not be imported:', 'wordpress-seo' ) );
throw new Exception( __( 'Settings could not be imported.', 'wordpress-seo' ) );
}
}
} catch ( Exception $e ) {

View file

@ -6,7 +6,7 @@
Author: MainWP
Author URI: https://mainwp.com
Text Domain: mainwp-child
Version: 3.5.3
Version: 3.5.4
*/
//if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) {
// header( 'X-Frame-Options: ALLOWALL' );

View file

@ -6,8 +6,8 @@ Author: mainwp
Author URI: https://mainwp.com
Plugin URI: https://mainwp.com
Requires at least: 3.6
Tested up to: 5.0.1
Stable tag: 3.5.3
Tested up to: 5.0.3
Stable tag: 3.5.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -71,6 +71,17 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
== Changelog ==
= 3.5.4 - 2-14-19 =
* Fixed: issues with displaying broken links data for specific setups
* Fixed: compatibility issues with the latest PageSpeed Insights plugin version
* Fixed: an issue with publishing "future" posts
* Fixed: an issue with sending email alerts in specific setups
* Fixed: an issue with saving code snippets in wp-config.php when the file is in a custom location
* Fixed: an issue with clearing unused scheduled cron jobs
* Added: support for the new PageSpeed Insights plugin options
* Updated: disabled the "Remove readme.html" security check feature for WPEngine hosted child sites
* Updated: support for detecting premium themes updates
= 3.5.3 - 12-19-18 =
* Fixed: an issue with the X-Frame-Options configuration
* Fixed: an issue with clearing WP Rocket cache