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' );