Fixed: CodeFactor issues

This commit is contained in:
Bogdan Rapaić 2020-04-16 19:59:35 +02:00 committed by GitHub
parent 2df8ed7210
commit d7220088da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@ class MainWP_Child_Branding {
public $child_plugin_dir; public $child_plugin_dir;
public $child_branding_options = null; public $child_branding_options = null;
static function Instance() { public static function Instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Branding(); self::$instance = new MainWP_Child_Branding();
} }
@ -20,12 +20,11 @@ class MainWP_Child_Branding {
$this->child_branding_options = $this->init_options(); $this->child_branding_options = $this->init_options();
} }
function init_options() { public function init_options() {
$opts = get_option( 'mainwp_child_branding_settings' ); $opts = get_option( 'mainwp_child_branding_settings' );
if ( ! is_array( $opts ) ) { if ( ! is_array( $opts ) ) {
// compatible with old code
$opts = array(); $opts = array();
$label = get_option( 'mainwp_branding_button_contact_label' ); $label = get_option( 'mainwp_branding_button_contact_label' );
@ -38,19 +37,19 @@ class MainWP_Child_Branding {
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $opts ); MainWP_Helper::update_option( 'mainwp_child_branding_settings', $opts );
} }
if ( ! isset($opts['contact_label']) || empty($opts['contact_label']) ) { if ( ! isset( $opts['contact_label'] ) || empty( $opts['contact_label'] ) ) {
$opts['contact_label'] = 'Contact Support'; $opts['contact_label'] = __( 'Contact Support', 'mainwp-child' );
} }
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : ''; $disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : ''; $preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
$cancelled_branding = ( $disconnected === 'yes' ) && ! $preserve_branding; $cancelled_branding = ( 'yes' === $disconnected ) && ! $preserve_branding;
$opts['cancelled_branding'] = $cancelled_branding; $opts['cancelled_branding'] = $cancelled_branding;
$opts['branding_preserve_title'] = ''; $opts['branding_preserve_title'] = '';
if ( ! $cancelled_branding ) { if ( ! $cancelled_branding ) {
if ( isset($opts['branding_header']) ) { if ( isset( $opts['branding_header'] ) ) {
$branding_header = $opts['branding_header']; $branding_header = $opts['branding_header'];
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) { if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] ); $opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
@ -64,7 +63,7 @@ class MainWP_Child_Branding {
function get_extra_options() { function get_extra_options() {
$extra = array(); $extra = array();
if ( is_array($this->child_branding_options) && isset($this->child_branding_options['extra_settings']) ) { if ( is_array( $this->child_branding_options ) && isset( $this->child_branding_options['extra_settings'] ) ) {
$extra = $this->child_branding_options['extra_settings']; $extra = $this->child_branding_options['extra_settings'];
if ( ! is_array($extra) ) { if ( ! is_array($extra) ) {
$extra = array(); $extra = array();
@ -82,7 +81,7 @@ class MainWP_Child_Branding {
if ( ! $this->is_branding() ) { if ( ! $this->is_branding() ) {
return $plugin_meta; return $plugin_meta;
} }
// hide View details links // hide View details links!
$meta_total = count( $plugin_meta ); $meta_total = count( $plugin_meta );
for ( $i = 0; $i < $meta_total; $i++ ) { for ( $i = 0; $i < $meta_total; $i++ ) {
$str_meta = $plugin_meta[ $i ]; $str_meta = $plugin_meta[ $i ];
@ -96,7 +95,6 @@ class MainWP_Child_Branding {
} }
public function child_deactivation() { public function child_deactivation() {
// will remove later
$dell_all = array( $dell_all = array(
'mainwp_branding_disable_change', 'mainwp_branding_disable_change',
'mainwp_branding_disable_switching_theme', 'mainwp_branding_disable_switching_theme',
@ -110,7 +108,6 @@ class MainWP_Child_Branding {
'mainwp_branding_remove_wp_tools', 'mainwp_branding_remove_wp_tools',
'mainwp_branding_remove_wp_setting', 'mainwp_branding_remove_wp_setting',
'mainwp_branding_remove_permalink', 'mainwp_branding_remove_permalink',
// 'mainwp_branding_plugin_header', // don't remove header
'mainwp_branding_button_contact_label', 'mainwp_branding_button_contact_label',
'mainwp_branding_send_email_message', 'mainwp_branding_send_email_message',
'mainwp_branding_message_return_sender', 'mainwp_branding_message_return_sender',
@ -136,7 +133,6 @@ class MainWP_Child_Branding {
'remove_wp_tools', 'remove_wp_tools',
'remove_wp_setting', 'remove_wp_setting',
'remove_permalink', 'remove_permalink',
// 'branding_header', // don't remove header
'contact_label', 'contact_label',
'email_message', 'email_message',
'message_return_sender', 'message_return_sender',
@ -153,7 +149,6 @@ class MainWP_Child_Branding {
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options ); MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
} }
public function action() { public function action() {
$information = array(); $information = array();
switch ( $_POST['action'] ) { switch ( $_POST['action'] ) {
@ -166,7 +161,7 @@ class MainWP_Child_Branding {
public function update_branding() { public function update_branding() {
$information = array(); $information = array();
$settings = maybe_unserialize( base64_decode( $_POST['settings'] ) ); $settings = maybe_unserialize( base64_decode( $_POST['settings'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
if ( ! is_array( $settings ) ) { if ( ! is_array( $settings ) ) {
return $information; return $information;
} }
@ -174,7 +169,6 @@ class MainWP_Child_Branding {
$current_settings = $this->child_branding_options; $current_settings = $this->child_branding_options;
$current_extra_setting = $this->child_branding_options['extra_settings']; $current_extra_setting = $this->child_branding_options['extra_settings'];
// MainWP_Helper::update_option( 'mainwp_branding_ext_enabled', 'Y' );
$current_settings['branding_ext_enabled'] = 'Y'; $current_settings['branding_ext_enabled'] = 'Y';
$header = array( $header = array(
@ -182,27 +176,11 @@ class MainWP_Child_Branding {
'description' => $settings['child_plugin_desc'], 'description' => $settings['child_plugin_desc'],
'author' => $settings['child_plugin_author'], 'author' => $settings['child_plugin_author'],
'authoruri' => $settings['child_plugin_author_uri'], 'authoruri' => $settings['child_plugin_author_uri'],
'pluginuri' => isset($settings['child_plugin_uri']) ? $settings['child_plugin_uri'] : '', 'pluginuri' => isset( $settings['child_plugin_uri'] ) ? $settings['child_plugin_uri'] : '',
); );
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_preserve_branding', $settings['child_preserve_branding'], 'yes' );
MainWP_Helper::update_option( 'mainwp_branding_plugin_header', $header, 'yes' ); // to compatible 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'] );
// }
$current_settings['preserve_branding'] = $settings['child_preserve_branding']; $current_settings['preserve_branding'] = $settings['child_preserve_branding'];
$current_settings['branding_header'] = $header; $current_settings['branding_header'] = $header;
@ -211,7 +189,7 @@ class MainWP_Child_Branding {
$current_settings['remove_restore'] = $settings['child_remove_restore']; $current_settings['remove_restore'] = $settings['child_remove_restore'];
$current_settings['remove_setting'] = $settings['child_remove_setting']; $current_settings['remove_setting'] = $settings['child_remove_setting'];
$current_settings['remove_server_info'] = $settings['child_remove_server_info']; $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_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_tools'] = $settings['child_remove_wp_tools'];
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting']; $current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
$current_settings['remove_permalink'] = $settings['child_remove_permalink']; $current_settings['remove_permalink'] = $settings['child_remove_permalink'];
@ -266,7 +244,7 @@ class MainWP_Child_Branding {
$extra_setting['login_image'] = array(); $extra_setting['login_image'] = array();
} else { } else {
try { try {
$upload = $this->uploadImage( $settings['child_login_image_url'] ); // Upload image to WP $upload = $this->uploadImage( $settings['child_login_image_url'] );
if ( null !== $upload ) { if ( null !== $upload ) {
$extra_setting['login_image'] = array( $extra_setting['login_image'] = array(
'path' => $upload['path'], 'path' => $upload['path'],
@ -292,7 +270,7 @@ class MainWP_Child_Branding {
$extra_setting['favico_image'] = array(); $extra_setting['favico_image'] = array();
} else { } else {
try { try {
$upload = $this->uploadImage( $settings['child_favico_image_url'] ); // Upload image to WP $upload = $this->uploadImage( $settings['child_favico_image_url'] );
if ( null !== $upload ) { if ( null !== $upload ) {
$extra_setting['favico_image'] = array( $extra_setting['favico_image'] = array(
'path' => $upload['path'], 'path' => $upload['path'],
@ -313,36 +291,16 @@ class MainWP_Child_Branding {
$extra_setting['favico_image'] = $current_extra_setting['favico_image']; $extra_setting['favico_image'] = $current_extra_setting['favico_image'];
} }
// MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' );
$current_settings['extra_settings'] = $extra_setting; $current_settings['extra_settings'] = $extra_setting;
// keep it to compatible with old version of child reports plugin
if ( $settings['child_plugin_hide'] ) { if ( $settings['child_plugin_hide'] ) {
MainWP_Helper::update_option( 'mainwp_branding_child_hide', 'T', 'yes' ); MainWP_Helper::update_option( 'mainwp_branding_child_hide', 'T', 'yes' );
} else { } else {
MainWP_Helper::update_option( 'mainwp_branding_child_hide', '' ); 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_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', '' );
// }
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : ''; $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['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_change'] = $settings['child_disable_change'] ? 'T' : '';
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : ''; $current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
@ -353,19 +311,18 @@ class MainWP_Child_Branding {
return $information; return $information;
} }
static function uploadImage( $img_url ) { public static function uploadImage( $img_url ) {
include_once ABSPATH . 'wp-admin/includes/file.php'; // Contains download_url include_once ABSPATH . 'wp-admin/includes/file.php';
global $mainWPChild; global $mainWPChild;
add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
// Download $img_url
$temporary_file = download_url( $img_url ); $temporary_file = download_url( $img_url );
remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
if ( is_wp_error( $temporary_file ) ) { if ( is_wp_error( $temporary_file ) ) {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() ); throw new Exception( $temporary_file->get_error_message() );
} else { } else {
$upload_dir = wp_upload_dir(); $upload_dir = wp_upload_dir();
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); // Local name $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url );
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) ); $local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path ); $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
$moved = @rename( $temporary_file, $local_img_path ); $moved = @rename( $temporary_file, $local_img_path );
@ -385,17 +342,14 @@ class MainWP_Child_Branding {
public function branding_init() { public function branding_init() {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
// to hide updates notice
if ( is_admin() ) { if ( is_admin() ) {
// back end
add_action( 'in_admin_footer', array( $this, 'in_admin_footer' ) ); add_action( 'in_admin_footer', array( $this, 'in_admin_footer' ) );
} elseif ( is_user_logged_in() ) { } elseif ( is_user_logged_in() ) {
// front end add_action( 'wp_after_admin_bar_render', array( $this, 'after_admin_bar_render' ) );
add_action( 'wp_after_admin_bar_render', array( $this, 'after_admin_bar_render' ));
} }
$opts = $this->child_branding_options; $opts = $this->child_branding_options;
$cancelled_branding = $opts['cancelled_branding']; $cancelled_branding = $opts['cancelled_branding'];
@ -403,7 +357,7 @@ class MainWP_Child_Branding {
return; return;
} }
// enable branding in case child plugin deactive and re-activated // enable branding in case child plugin deactive and re-activated.
add_filter( 'all_plugins', array( $this, 'modify_plugin_header' ) ); add_filter( 'all_plugins', array( $this, 'modify_plugin_header' ) );
if ( $this->is_branding() ) { if ( $this->is_branding() ) {
@ -411,7 +365,7 @@ class MainWP_Child_Branding {
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
} }
if ( ! isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) { if ( ! isset( $opts['branding_ext_enabled'] ) || 'Y' !== $opts['branding_ext_enabled'] ) {
return; return;
} }
@ -419,35 +373,47 @@ class MainWP_Child_Branding {
if ( 'T' === $opts['disable_change'] ) { if ( 'T' === $opts['disable_change'] ) {
// Disable the WordPress plugin update notifications // Disable the WordPress plugin update notifications.
remove_action('load-update-core.php', 'wp_update_plugins'); remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter('pre_site_transient_update_plugins', '__return_null'); add_filter( 'pre_site_transient_update_plugins', '__return_null' );
// Disable the WordPress theme update notifications // Disable the WordPress theme update notifications.
remove_action('load-update-core.php', 'wp_update_themes'); remove_action( 'load-update-core.php', 'wp_update_themes' );
add_filter('pre_site_transient_update_themes', ( $func = function( $a ) { add_filter(
return null; 'pre_site_transient_update_themes',
} )); (
$func = function( $a ) {
return null;
}
)
);
// Disable the WordPress core update notifications // Disable the WordPress core update notifications.
add_action('after_setup_theme', 'remove_core_updates'); add_action( 'after_setup_theme', 'remove_core_updates' );
function remove_core_updates() { function remove_core_updates() {
add_action('init', ( $func = function( $a ) { add_action(
remove_action( 'wp_version_check', 'wp_version_check' ); 'init',
} ), 2); (
add_filter('pre_option_update_core', '__return_null'); $func = function( $a ) {
add_filter('pre_site_transient_update_core', '__return_null'); remove_action( 'wp_version_check', 'wp_version_check' );
}
),
2
);
add_filter( 'pre_option_update_core', '__return_null' );
add_filter( 'pre_site_transient_update_core', '__return_null' );
} }
add_action( 'admin_head', array( &$this, 'admin_head_hide_elements' ), 15 ); add_action( 'admin_head', array( &$this, 'admin_head_hide_elements' ), 15 );
add_action( 'admin_menu', array( $this, 'branding_redirect' ), 9); add_action( 'admin_menu', array( $this, 'branding_redirect' ), 9 );
} }
// to fix add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); if ( ! isset($opts['disable_wp_branding']) || $opts['disable_wp_branding'] !== 'Y' ) {
if ( ! isset( $opts['disable_wp_branding'] ) || 'Y' !== $opts['disable_wp_branding'] ) {
add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 ); add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 );
add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 ); add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 );
// branding site generator // branding site generator.
$types = array( 'html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export' ); $types = array( 'html', 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export' );
foreach ( $types as $type ) { foreach ( $types as $type ) {
add_filter( 'get_the_generator_' . $type, array( &$this, 'custom_the_generator' ), 999, 2 ); add_filter( 'get_the_generator_' . $type, array( &$this, 'custom_the_generator' ), 999, 2 );
@ -460,13 +426,12 @@ class MainWP_Child_Branding {
add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) ); add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) );
add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) ); add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) );
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) { if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
// remove_filter( 'update_footer', 'core_update_footer' );
add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 ); add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 );
add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text' ), 14 ); add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text' ), 14 );
} }
if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) { if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) {
add_action( 'admin_init', array( $this, 'admin_init' )); add_action( 'admin_init', array( $this, 'admin_init' ) );
} }
add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) ); add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) );
@ -474,15 +439,15 @@ class MainWP_Child_Branding {
} }
} }
public function admin_init() { public function admin_init() {
remove_action( 'admin_notices', 'update_nag', 3 ); remove_action( 'admin_notices', 'update_nag', 3 );
} }
// to fix conflict with other plugin // prevent conflicts with other plugins.
function admin_menu() { function admin_menu() {
$allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false); $allow_contact = apply_filters( 'mainwp_branding_role_cap_enable_contact_form', false );
if ( $allow_contact ) {; // ok if ( $allow_contact ) {
// skip!
} elseif ( ! current_user_can( 'administrator' ) ) { } elseif ( ! current_user_can( 'administrator' ) ) {
return false; return false;
} }
@ -497,23 +462,38 @@ class MainWP_Child_Branding {
$title = $opts['contact_label']; $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'] ) ) { if ( isset( $extra_setting['show_button_in'] ) && ( 2 === (int) $extra_setting['show_button_in'] || 3 === (int) $extra_setting['show_button_in'] ) ) {
$title = $opts['contact_label']; $title = $opts['contact_label'];
add_menu_page( $title, $title, 'read', 'ContactSupport2', array( add_menu_page(
$this, $title,
'contact_support', $title,
), '', '2.0001' ); 'read',
'ContactSupport2',
array(
$this,
'contact_support',
),
'',
'2.0001'
);
} }
if ( isset( $extra_setting['show_button_in'] ) && ( 1 === $extra_setting['show_button_in'] || 3 === $extra_setting['show_button_in'] ) ) { if ( isset( $extra_setting['show_button_in'] ) && ( 1 === $extra_setting['show_button_in'] || 3 === $extra_setting['show_button_in'] ) ) {
add_submenu_page( null, $title, $opts['contact_label'], 'read', 'ContactSupport', array( add_submenu_page(
$this, null,
'contact_support', $title,
) ); $opts['contact_label'],
'read',
'ContactSupport',
array(
$this,
'contact_support',
)
);
add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 ); add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 );
} }
} }
} }
function remove_default_post_metaboxes() { public function remove_default_post_metaboxes() {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
add_filter( 'manage_posts_columns', array( &$this, 'custom_post_columns' ) ); add_filter( 'manage_posts_columns', array( &$this, 'custom_post_columns' ) );
@ -552,8 +532,7 @@ class MainWP_Child_Branding {
} }
} }
public function custom_post_columns( $defaults ) {
function custom_post_columns( $defaults ) {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['hide_metabox_post_comments'] ) && $extra_setting['hide_metabox_post_comments'] ) { if ( isset( $extra_setting['hide_metabox_post_comments'] ) && $extra_setting['hide_metabox_post_comments'] ) {
@ -569,7 +548,7 @@ class MainWP_Child_Branding {
return $defaults; return $defaults;
} }
function manage_my_category_columns( $defaults ) { public function manage_my_category_columns( $defaults ) {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['hide_metabox_post_slug'] ) && $extra_setting['hide_metabox_post_slug'] ) { if ( isset( $extra_setting['hide_metabox_post_slug'] ) && $extra_setting['hide_metabox_post_slug'] ) {
@ -579,12 +558,12 @@ class MainWP_Child_Branding {
return $defaults; return $defaults;
} }
function remove_default_page_metaboxes() { public function remove_default_page_metaboxes() {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
add_filter( 'manage_pages_columns', array( &$this, 'custom_pages_columns' ) ); add_filter( 'manage_pages_columns', array( &$this, 'custom_pages_columns' ) );
if ( isset( $extra_setting['hide_metabox_page_custom_fields'] ) && $extra_setting['hide_metabox_page_custom_fields'] ) { // if (get_option('wlcms_o_page_meta_box_custom')) if ( isset( $extra_setting['hide_metabox_page_custom_fields'] ) && $extra_setting['hide_metabox_page_custom_fields'] ) {
remove_meta_box( 'postcustom', 'page', 'normal' ); remove_meta_box( 'postcustom', 'page', 'normal' );
} }
if ( isset( $extra_setting['hide_metabox_page_author'] ) && $extra_setting['hide_metabox_page_author'] ) { if ( isset( $extra_setting['hide_metabox_page_author'] ) && $extra_setting['hide_metabox_page_author'] ) {
@ -629,33 +608,34 @@ class MainWP_Child_Branding {
} }
} }
function admin_head_hide_elements() { public function admin_head_hide_elements() {
?><script type="text/javascript"> ?>
document.addEventListener("DOMContentLoaded", function(event) { <script type="text/javascript">
document.getElementById("wp-admin-bar-updates").outerHTML = ''; document.addEventListener( "DOMContentLoaded", function( event ) {
document.getElementById("menu-plugins").outerHTML = ''; document.getElementById( "wp-admin-bar-updates" ).outerHTML = '';
var els_core = document.querySelectorAll("a[href='update-core.php']"); document.getElementById( "menu-plugins" ).outerHTML = '';
for (var i = 0, l = els_core.length; i < l; i++) { var els_core = document.querySelectorAll( "a[href='update-core.php']" );
for ( var i = 0, l = els_core.length; i < l; i++ ) {
var el = els_core[i]; var el = els_core[i];
el.parentElement.innerHTML = ''; el.parentElement.innerHTML = '';
} }
}); } );
</script> </script>
<?php <?php
} }
function core_update_footer() { public function core_update_footer() {
echo ''; // it clear version text echo '';
} }
function admin_footer_text() { public function admin_footer_text() {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) { if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
echo wp_kses_post( nl2br( stripslashes( $extra_setting['dashboard_footer'] ) ) ); echo wp_kses_post( nl2br( stripslashes( $extra_setting['dashboard_footer'] ) ) );
} }
} }
function custom_favicon_frontend() { public function custom_favicon_frontend() {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['favico_image']['url'] ) && ! empty( $extra_setting['favico_image']['url'] ) ) { if ( isset( $extra_setting['favico_image']['url'] ) && ! empty( $extra_setting['favico_image']['url'] ) ) {
$favico = $extra_setting['favico_image']['url']; $favico = $extra_setting['favico_image']['url'];
@ -663,18 +643,15 @@ class MainWP_Child_Branding {
} }
} }
function custom_login_logo() { public function custom_login_logo() {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_image']['url'] ) && ! empty( $extra_setting['login_image']['url'] ) ) { if ( isset( $extra_setting['login_image']['url'] ) && ! empty( $extra_setting['login_image']['url'] ) ) {
$login_logo = $extra_setting['login_image']['url']; $login_logo = $extra_setting['login_image']['url'];
echo '<style type="text/css"> echo '<style type="text/css">#login h1 a { background-image: url(\'' . esc_url( $login_logo ) . '\') !important; height:70px !important; width:310px !important; background-size: auto auto !important; }</style>';
#login h1 a { background-image: url(\'' . esc_url( $login_logo ) . '\') !important; height:70px !important; width:310px !important; background-size: auto auto !important; }
</style>';
} }
} }
function custom_login_headerurl( $value ) { public function custom_login_headerurl( $value ) {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_image_link'] ) && ! empty( $extra_setting['login_image_link'] ) ) { if ( isset( $extra_setting['login_image_link'] ) && ! empty( $extra_setting['login_image_link'] ) ) {
return $extra_setting['login_image_link']; return $extra_setting['login_image_link'];
@ -683,8 +660,7 @@ class MainWP_Child_Branding {
return $value; return $value;
} }
function custom_login_headertitle( $value ) { public function custom_login_headertitle( $value ) {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_image_title'] ) && ! empty( $extra_setting['login_image_title'] ) ) { if ( isset( $extra_setting['login_image_title'] ) && ! empty( $extra_setting['login_image_title'] ) ) {
return $extra_setting['login_image_title']; return $extra_setting['login_image_title'];
@ -693,7 +669,7 @@ class MainWP_Child_Branding {
return $value; return $value;
} }
function custom_gettext( $translations, $text, $domain = 'default' ) { public function custom_gettext( $translations, $text, $domain = 'default' ) {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
$texts_replace = $extra_setting['texts_replace']; $texts_replace = $extra_setting['texts_replace'];
if ( is_array( $texts_replace ) && count( $texts_replace ) > 0 ) { if ( is_array( $texts_replace ) && count( $texts_replace ) > 0 ) {
@ -707,7 +683,7 @@ class MainWP_Child_Branding {
return $translations; return $translations;
} }
function custom_admin_css() { public function custom_admin_css() {
$header_css = ''; $header_css = '';
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
@ -729,14 +705,14 @@ class MainWP_Child_Branding {
} }
} }
function custom_login_css() { public function custom_login_css() {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) { if ( isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) {
echo '<style>' . MainWP_Helper::parse_css( $extra_setting['login_css'] ) . '</style>'; echo '<style>' . MainWP_Helper::parse_css( $extra_setting['login_css'] ) . '</style>';
} }
} }
function custom_the_generator( $generator, $type = '' ) { public function custom_the_generator( $generator, $type = '' ) {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['site_generator'] ) ) { if ( isset( $extra_setting['site_generator'] ) ) {
if ( ! empty( $extra_setting['site_generator'] ) ) { if ( ! empty( $extra_setting['site_generator'] ) ) {
@ -777,7 +753,7 @@ class MainWP_Child_Branding {
return $generator; return $generator;
} }
function custom_dashboard_widgets() { public function custom_dashboard_widgets() {
global $wp_meta_boxes; global $wp_meta_boxes;
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
if ( isset( $extra_setting['remove_widget_welcome'] ) && $extra_setting['remove_widget_welcome'] ) { if ( isset( $extra_setting['remove_widget_welcome'] ) && $extra_setting['remove_widget_welcome'] ) {
@ -807,14 +783,15 @@ class MainWP_Child_Branding {
public function send_support_mail() { public function send_support_mail() {
$email = $this->child_branding_options['support_email']; $email = $this->child_branding_options['support_email'];
$sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) ); $sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
$from = trim($_POST['mainwp_branding_contact_send_from']); $from = trim( $_POST['mainwp_branding_contact_send_from'] );
$subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact'; $subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact';
$content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) ); $content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
$mail = $headers = ''; $mail = '';
$headers = '';
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) { if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
global $current_user; global $current_user;
$headers .= "Content-Type: text/html;charset=utf-8\r\n"; $headers .= "Content-Type: text/html;charset=utf-8\r\n";
if ( ! empty($from) ) { if ( ! empty( $from ) ) {
$headers .= 'From: "' . $from . '" <' . $from . ">\r\n"; $headers .= 'From: "' . $from . '" <' . $from . ">\r\n";
} }
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n"; $mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
@ -832,7 +809,7 @@ class MainWP_Child_Branding {
return false; return false;
} }
function contact_support() { public function contact_support() {
global $current_user; global $current_user;
?> ?>
<style> <style>
@ -870,17 +847,16 @@ class MainWP_Child_Branding {
$send_email_message = __( 'Sending email failed!', 'mainwp-child' ); $send_email_message = __( 'Sending email failed!', 'mainwp-child' );
} }
?> ?>
<div <div class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '&nbsp;&nbsp' . $back_link; ?></div>
class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '&nbsp;&nbsp' . $back_link; ?></div> <?php
<?php
} else { } else {
$from_page = ''; $from_page = '';
if ( isset( $_GET['from_page'] ) ) { if ( isset( $_GET['from_page'] ) ) {
$from_page = urldecode( $_GET['from_page'] ); $from_page = rawurldecode( $_GET['from_page'] );
} else { } else {
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( $_SERVER['HTTPS'], 'off' ) ? 'https://' : 'http://'; $protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( $_SERVER['HTTPS'], 'off' ) ? 'https://' : 'http://';
$fullurl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $fullurl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$from_page = urldecode( $fullurl ); $from_page = rawurldecode( $fullurl );
} }
$support_message = $opts['support_message']; $support_message = $opts['support_message'];
@ -890,24 +866,33 @@ class MainWP_Child_Branding {
<form action="" method="post"> <form action="" method="post">
<div style="width: 99%;"> <div style="width: 99%;">
<h2><?php echo esc_html( $opts['contact_label'] ); ?></h2> <h2><?php echo esc_html( $opts['contact_label'] ); ?></h2>
<div style="height: auto; margin-bottom: 10px; text-align: left"> <div style="height: auto; margin-bottom: 10px; text-align: left">
<p><?php echo wp_kses_post( $support_message ); ?></p> <p><?php echo wp_kses_post( $support_message ); ?></p>
<p><label for="mainwp_branding_contact_message_subject"><?php _e('Subject:', 'mainwp-child'); ?></label><br> <p>
<input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;"></p> <label for="mainwp_branding_contact_message_subject"><?php esc_html_e( 'Subject:', 'mainwp-child' ); ?></label>
<p><label for="mainwp_branding_contact_send_from"><?php _e('From:', 'mainwp-child'); ?></label><br> <br>
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_html( $from_email ); ?>"></p> <input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;">
</p>
<p>
<label for="mainwp_branding_contact_send_from"><?php esc_html_e( 'From:', 'mainwp-child' ); ?></label>
<br>
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_attr( $from_email ); ?>">
</p>
<div style="max-width: 650px;"> <div style="max-width: 650px;">
<label for="mainwp_branding_contact_message_content"><?php _e('Your message:', 'mainwp-child'); ?></label><br> <label for="mainwp_branding_contact_message_content"><?php esc_html_e( 'Your message:', 'mainwp-child' ); ?></label>
<br>
<?php <?php
remove_editor_styles(); // stop custom theme styling interfering with the editor remove_editor_styles(); // stop custom theme styling interfering with the editor.
wp_editor( '', 'mainwp_branding_contact_message_content', array( wp_editor(
'textarea_name' => 'mainwp_branding_contact_message_content', '',
'textarea_rows' => 10, 'mainwp_branding_contact_message_content',
'teeny' => true, array(
'wpautop' => true, 'textarea_name' => 'mainwp_branding_contact_message_content',
'media_buttons' => false, 'textarea_rows' => 10,
) 'teeny' => true,
'wpautop' => true,
'media_buttons' => false,
)
); );
?> ?>
</div> </div>
@ -915,14 +900,11 @@ class MainWP_Child_Branding {
<br/> <br/>
<?php <?php
$button_title = $opts['submit_button_title']; $button_title = $opts['submit_button_title'];
$button_title = ! empty( $button_title ) ? $button_title : __( 'Submit' ); $button_title = ! empty( $button_title ) ? $button_title : __( 'Submit', 'mainwp-child' );
?> ?>
<input id="mainwp-branding-contact-support-submit" type="submit" name="submit" <input id="mainwp-branding-contact-support-submit" type="submit" name="submit" value="<?php echo esc_attr( $button_title ); ?>" class="button-primary button" style="float: left"/>
value="<?php echo esc_attr( $button_title ); ?>"
class="button-primary button" style="float: left"/>
</div> </div>
<input type="hidden" name="mainwp_branding_send_from_page" <input type="hidden" name="mainwp_branding_send_from_page" value="<?php echo esc_url( $from_page ); ?>"/>
value="<?php echo esc_url( $from_page ); ?>"/>
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/> <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
</form> </form>
<?php <?php
@ -933,18 +915,19 @@ class MainWP_Child_Branding {
* @param WP_Admin_Bar $wp_admin_bar * @param WP_Admin_Bar $wp_admin_bar
*/ */
public function add_support_button_in_top_admin_bar( $wp_admin_bar ) { public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
$allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false); $allow_contact = apply_filters( 'mainwp_branding_role_cap_enable_contact_form', false );
if ( $allow_contact ) {; // ok if ( $allow_contact ) {
// skip!
} elseif ( ! current_user_can( 'administrator' ) ) { } elseif ( ! current_user_can( 'administrator' ) ) {
return false; return false;
} }
if ( isset( $_GET['from_page'] ) ) { if ( isset( $_GET['from_page'] ) ) {
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . urlencode( esc_url( $_GET['from_page'] ) ) ); $href = admin_url( 'admin.php?page=ContactSupport&from_page=' . rawurlencode( esc_url( $_GET['from_page'] ) ) );
} else { } else {
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( $_SERVER['HTTPS'], 'off' ) ? 'https://' : 'http://'; $protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( $_SERVER['HTTPS'], 'off' ) ? 'https://' : 'http://';
$fullurl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $fullurl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$href = admin_url( 'admin.php?page=ContactSupport&from_page=' . urlencode( esc_url( $fullurl ) ) ); $href = admin_url( 'admin.php?page=ContactSupport&from_page=' . rawurlencode( esc_url( $fullurl ) ) );
} }
$args = array( $args = array(
'id' => 999, 'id' => 999,
@ -963,7 +946,7 @@ class MainWP_Child_Branding {
public function is_branding() { public function is_branding() {
$opts = $this->child_branding_options; $opts = $this->child_branding_options;
if ( ! isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) { if ( ! isset( $opts['branding_ext_enabled'] ) || 'Y' !== $opts['branding_ext_enabled'] ) {
return false; return false;
} }
@ -974,13 +957,15 @@ class MainWP_Child_Branding {
if ( $cancelled_branding ) { if ( $cancelled_branding ) {
return false; return false;
} }
// hide
if ( 'T' === $is_hide ) { if ( 'T' === $is_hide ) {
return true; return true;
} }
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) { if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) {
return true; return true;
} }
return false; return false;
} }
@ -1002,63 +987,60 @@ class MainWP_Child_Branding {
} }
public function after_admin_bar_render() { public function after_admin_bar_render() {
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
$hide_slugs = apply_filters('mainwp_child_hide_update_notice', array()); if ( ! is_array( $hide_slugs ) ) {
if ( ! is_array($hide_slugs) ) {
$hide_slugs = array(); $hide_slugs = array();
} }
if ( count($hide_slugs) == 0 ) { if ( 0 == count( $hide_slugs ) ) {
return; return;
} }
if ( ! function_exists('get_plugin_updates') ) { if ( ! function_exists( 'get_plugin_updates' ) ) {
include_once ABSPATH . '/wp-admin/includes/update.php'; include_once ABSPATH . '/wp-admin/includes/update.php';
} }
$count_hide = 0; $count_hide = 0;
$updates = get_plugin_updates(); $updates = get_plugin_updates();
if ( is_array($updates) ) { if ( is_array( $updates ) ) {
foreach ( $updates as $slug => $data ) { foreach ( $updates as $slug => $data ) {
if ( in_array($slug, $hide_slugs) ) { if ( in_array( $slug, $hide_slugs ) ) {
$count_hide++; $count_hide++;
} }
} }
} }
if ( $count_hide == 0 ) { if ( 0 == $count_hide ) {
return; return;
} }
// js for front end
?> ?>
<script type="text/javascript"> <script type="text/javascript">
var mainwpCountHide = <?php echo esc_attr($count_hide); ?>; var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
document.addEventListener("DOMContentLoaded", function(event) { document.addEventListener( "DOMContentLoaded", function( event ) {
var $adminBarUpdates = document.querySelector( '#wp-admin-bar-updates .ab-label' ), var $adminBarUpdates = document.querySelector( '#wp-admin-bar-updates .ab-label' ),
itemCount; itemCount;
if (typeof($adminBarUpdates) !== 'undefined' && $adminBarUpdates !== null) { if ( typeof( $adminBarUpdates ) !== 'undefined' && $adminBarUpdates !== null ) {
itemCount = $adminBarUpdates.textContent; itemCount = $adminBarUpdates.textContent;
itemCount = parseInt(itemCount); itemCount = parseInt( itemCount );
itemCount -= mainwpCountHide; itemCount -= mainwpCountHide;
if (itemCount < 0) if ( itemCount < 0 )
itemCount = 0; itemCount = 0;
$adminBarUpdates.textContent = itemCount; $adminBarUpdates.textContent = itemCount;
} }
}); } );
</script> </script>
<?php <?php
} }
public function in_admin_footer() { public function in_admin_footer() {
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
$hide_slugs = apply_filters('mainwp_child_hide_update_notice', array()); if ( ! is_array( $hide_slugs ) ) {
if ( ! is_array($hide_slugs) ) {
$hide_slugs = array(); $hide_slugs = array();
} }
@ -1067,38 +1049,36 @@ class MainWP_Child_Branding {
$updates = get_plugin_updates(); $updates = get_plugin_updates();
if ( is_array($updates) ) { if ( is_array($updates) ) {
foreach ( $updates as $slug => $data ) { foreach ( $updates as $slug => $data ) {
if ( in_array($slug, $hide_slugs) ) { if ( in_array( $slug, $hide_slugs ) ) {
$count_hide++; $count_hide++;
} }
} }
} }
if ( $count_hide == 0 ) { if ( 0 == $count_hide ) {
return; return;
} }
// to tweaks counting of update notification display
// js for admin end
?> ?>
<script type="text/javascript"> <script type="text/javascript">
var mainwpCountHide = <?php echo esc_attr($count_hide); ?>; var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
document.addEventListener("DOMContentLoaded", function(event) { document.addEventListener( "DOMContentLoaded", function( event ) {
if (typeof(pagenow) !== 'undefined' && pagenow == 'plugins') { if ( typeof( pagenow ) !== 'undefined' && pagenow == 'plugins' ) {
<?php <?php
// hide update notice row // hide update notice row.
if ( in_array('mainwp-child/mainwp-child.php', $hide_slugs) ) { if ( in_array( 'mainwp-child/mainwp-child.php', $hide_slugs ) ) {
?> ?>
var el = document.querySelector('tr#mainwp-child-update'); var el = document.querySelector( 'tr#mainwp-child-update' );
if (typeof(el) !== 'undefined' && el !== null) { if ( typeof( el ) !== 'undefined' && el !== null ) {
el.style.display = 'none'; el.style.display = 'none';
} }
<?php <?php
} }
// hide update notice row // hide update notice row.
if ( in_array('mainwp-child-reports/mainwp-child-reports.php', $hide_slugs) ) { if ( in_array( 'mainwp-child-reports/mainwp-child-reports.php', $hide_slugs ) ) {
?> ?>
var el = document.querySelector('tr#mainwp-child-reports-update'); var el = document.querySelector( 'tr#mainwp-child-reports-update' );
if (typeof(el) !== 'undefined' && el !== null) { if ( typeof( el ) !== 'undefined' && el !== null ) {
el.style.display = 'none'; el.style.display = 'none';
} }
<?php <?php
@ -1106,36 +1086,35 @@ class MainWP_Child_Branding {
?> ?>
} }
if (mainwpCountHide > 0) { if ( mainwpCountHide > 0 ) {
jQuery( document ).ready( function () { jQuery( document ).ready( function () {
var $adminBarUpdates = jQuery( '#wp-admin-bar-updates' ), var $adminBarUpdates = jQuery( '#wp-admin-bar-updates' ),
$pluginsNavMenuUpdateCount = jQuery( 'a[href="plugins.php"] .update-plugins' ), $pluginsNavMenuUpdateCount = jQuery( 'a[href="plugins.php"] .update-plugins' ),
itemCount; itemCount;
itemCount = $adminBarUpdates.find( '.ab-label' ).text(); itemCount = $adminBarUpdates.find( '.ab-label' ).text();
itemCount -= mainwpCountHide; itemCount -= mainwpCountHide;
if (itemCount < 0) if ( itemCount < 0 )
itemCount = 0; itemCount = 0;
itemPCount = $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text(); itemPCount = $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text();
itemPCount -= mainwpCountHide; itemPCount -= mainwpCountHide;
if (itemPCount < 0) if ( itemPCount < 0 )
itemPCount = 0; itemPCount = 0;
$adminBarUpdates.find( '.ab-label' ).text(itemCount); $adminBarUpdates.find( '.ab-label' ).text( itemCount );
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( itemPCount ); $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( itemPCount );
}); } );
} }
}); } );
</script> </script>
<?php <?php
} }
public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) { public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) {
if ( isset($this->child_branding_options['disable_switching_theme']) && 'T' === $this->child_branding_options['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 ) { if ( 'switch_themes' === $cap ) {
$caps[0] = 'do_not_allow'; $caps[0] = 'do_not_allow';
} }
@ -1145,7 +1124,7 @@ class MainWP_Child_Branding {
public function modify_plugin_header( $plugins ) { public function modify_plugin_header( $plugins ) {
$opts = $this->child_branding_options; $opts = $this->child_branding_options;
if ( is_array($opts) ) { if ( is_array( $opts ) ) {
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : ''; $is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$cancelled_branding = $opts['cancelled_branding']; $cancelled_branding = $opts['cancelled_branding'];
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : ''; $branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
@ -1154,7 +1133,7 @@ class MainWP_Child_Branding {
return $plugins; return $plugins;
} }
if ( $is_hide === 'T' ) { if ( 'T' === $is_hide ) {
foreach ( $plugins as $key => $value ) { foreach ( $plugins as $key => $value ) {
$plugin_slug = basename( $key, '.php' ); $plugin_slug = basename( $key, '.php' );
if ( 'mainwp-child' === $plugin_slug ) { if ( 'mainwp-child' === $plugin_slug ) {
@ -1174,13 +1153,12 @@ class MainWP_Child_Branding {
return $plugins; return $plugins;
} }
function hide_update_notice( $slugs ) { public function hide_update_notice( $slugs ) {
$slugs[] = 'mainwp-child/mainwp-child.php'; $slugs[] = 'mainwp-child/mainwp-child.php';
return $slugs; return $slugs;
} }
public function remove_update_nag( $value ) {
function remove_update_nag( $value ) {
if ( isset( $_POST['mainwpsignature'] ) ) { if ( isset( $_POST['mainwpsignature'] ) ) {
return $value; return $value;
} }
@ -1219,4 +1197,3 @@ class MainWP_Child_Branding {
return $plugins; return $plugins;
} }
} }