2015-10-15 22:52:37 +10:00
< ? php
2020-05-05 20:13:38 +07:00
namespace MainWP\Child ;
2015-10-15 22:52:37 +10:00
class MainWP_Child_Branding {
public static $instance = null ;
2019-02-14 22:38:14 +07:00
public $child_plugin_dir ;
public $child_branding_options = null ;
2015-10-15 22:52:37 +10:00
2020-05-06 20:22:11 +07:00
public static function instance () {
2020-03-26 14:05:04 +00:00
if ( null === self :: $instance ) {
2020-05-07 01:03:56 +07:00
self :: $instance = new self ();
2015-10-15 22:52:37 +10:00
}
2020-03-26 14:05:04 +00:00
return self :: $instance ;
2015-10-15 22:52:37 +10:00
}
public function __construct () {
$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 );
2020-03-27 15:13:11 +00:00
$this -> child_branding_options = $this -> init_options ();
2019-02-14 22:38:14 +07:00
}
2015-10-15 22:52:37 +10:00
2020-04-16 19:59:35 +02:00
public function init_options () {
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$opts = get_option ( 'mainwp_child_branding_settings' );
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( ! is_array ( $opts ) ) {
$opts = array ();
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$label = get_option ( 'mainwp_branding_button_contact_label' );
if ( ! empty ( $label ) ) {
$label = stripslashes ( $label );
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$opts [ 'contact_label' ] = $label ;
$opts [ 'extra_settings' ] = get_option ( 'mainwp_branding_extra_settings' );
2020-04-16 20:10:19 +02:00
MainWP_Helper :: update_option ( 'mainwp_child_branding_settings' , $opts );
2020-03-27 15:13:11 +00:00
}
2019-02-14 22:38:14 +07:00
2020-04-16 19:59:35 +02:00
if ( ! isset ( $opts [ 'contact_label' ] ) || empty ( $opts [ 'contact_label' ] ) ) {
$opts [ 'contact_label' ] = __ ( 'Contact Support' , 'mainwp-child' );
2020-03-27 15:13:11 +00:00
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$disconnected = isset ( $opts [ 'branding_disconnected' ] ) ? $opts [ 'branding_disconnected' ] : '' ;
$preserve_branding = isset ( $opts [ 'preserve_branding' ] ) ? $opts [ 'preserve_branding' ] : '' ;
2020-04-16 19:59:35 +02:00
$cancelled_branding = ( 'yes' === $disconnected ) && ! $preserve_branding ;
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$opts [ 'cancelled_branding' ] = $cancelled_branding ;
$opts [ 'branding_preserve_title' ] = '' ;
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
if ( ! $cancelled_branding ) {
2020-04-16 19:59:35 +02:00
if ( isset ( $opts [ 'branding_header' ] ) ) {
2020-03-27 15:13:11 +00:00
$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' ] );
}
}
2020-03-26 14:05:04 +00:00
}
$opts = apply_filters ( 'mainwp_child_branding_init_options' , $opts );
2020-03-27 15:13:11 +00:00
return $opts ;
}
2015-10-15 22:52:37 +10:00
2020-04-16 20:10:19 +02:00
public function get_extra_options () {
2020-03-27 15:13:11 +00:00
$extra = array ();
2020-04-16 19:59:35 +02:00
if ( is_array ( $this -> child_branding_options ) && isset ( $this -> child_branding_options [ 'extra_settings' ] ) ) {
2020-03-27 15:13:11 +00:00
$extra = $this -> child_branding_options [ 'extra_settings' ];
2020-04-16 20:10:19 +02:00
if ( ! is_array ( $extra ) ) {
2020-03-27 15:13:11 +00:00
$extra = array ();
}
}
2015-10-15 22:52:37 +10:00
2020-03-27 15:13:11 +00:00
return $extra ;
}
2015-10-15 22:52:37 +10:00
public function plugin_row_meta ( $plugin_meta , $plugin_file , $child_plugin_slug ) {
if ( $child_plugin_slug !== $plugin_file ) {
return $plugin_meta ;
}
2019-02-14 22:38:14 +07:00
if ( ! $this -> is_branding () ) {
2015-10-15 22:52:37 +10:00
return $plugin_meta ;
}
2020-04-16 19:59:35 +02:00
// hide View details links!
2015-10-15 22:52:37 +10:00
$meta_total = count ( $plugin_meta );
for ( $i = 0 ; $i < $meta_total ; $i ++ ) {
$str_meta = $plugin_meta [ $i ];
if ( strpos ( $str_meta , 'plugin-install.php?tab=plugin-information' ) ) {
unset ( $plugin_meta [ $i ] );
break ;
}
}
return $plugin_meta ;
}
public function child_deactivation () {
$dell_all = array (
'mainwp_branding_disable_change' ,
2016-02-15 22:08:39 +01:00
'mainwp_branding_disable_switching_theme' ,
2015-10-15 22:52:37 +10:00
'mainwp_branding_child_hide' ,
'mainwp_branding_show_support' ,
'mainwp_branding_support_email' ,
'mainwp_branding_support_message' ,
'mainwp_branding_remove_restore' ,
'mainwp_branding_remove_setting' ,
'mainwp_branding_remove_server_info' ,
'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_extra_settings' ,
'mainwp_branding_ext_enabled' ,
);
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
foreach ( $dell_all as $opt ) {
delete_option ( $opt );
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$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' ,
'contact_label' ,
'email_message' ,
'message_return_sender' ,
'submit_button_title' ,
'extra_settings' ,
'branding_ext_enabled' ,
);
foreach ( $brandingOptions_empty as $opt ) {
2020-04-16 20:10:19 +02:00
if ( isset ( $this -> child_branding_options [ $opt ] ) ) {
2020-03-27 15:13:11 +00:00
$this -> child_branding_options [ $opt ] = '' ;
}
}
MainWP_Helper :: update_option ( 'mainwp_child_branding_settings' , $this -> child_branding_options );
2015-10-15 22:52:37 +10:00
}
public function action () {
$information = array ();
switch ( $_POST [ 'action' ] ) {
case 'update_branding' :
$information = $this -> update_branding ();
break ;
}
2020-05-07 19:34:36 +07:00
mainwp_child_helper () -> write ( $information );
2015-10-15 22:52:37 +10:00
}
public function update_branding () {
$information = array ();
2020-04-16 19:59:35 +02:00
$settings = maybe_unserialize ( base64_decode ( $_POST [ 'settings' ] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
2015-10-15 22:52:37 +10:00
if ( ! is_array ( $settings ) ) {
return $information ;
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$current_settings = $this -> child_branding_options ;
$current_extra_setting = $this -> child_branding_options [ 'extra_settings' ];
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$current_settings [ 'branding_ext_enabled' ] = 'Y' ;
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
$header = array (
'name' => $settings [ 'child_plugin_name' ],
'description' => $settings [ 'child_plugin_desc' ],
'author' => $settings [ 'child_plugin_author' ],
'authoruri' => $settings [ 'child_plugin_author_uri' ],
2020-04-16 19:59:35 +02:00
'pluginuri' => isset ( $settings [ 'child_plugin_uri' ] ) ? $settings [ 'child_plugin_uri' ] : '' ,
2015-10-15 22:52:37 +10:00
);
2019-02-14 22:38:14 +07:00
2020-04-16 19:59:35 +02:00
MainWP_Helper :: update_option ( 'mainwp_branding_preserve_branding' , $settings [ 'child_preserve_branding' ], 'yes' );
MainWP_Helper :: update_option ( 'mainwp_branding_plugin_header' , $header , 'yes' );
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$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' ];
2020-04-16 19:59:35 +02:00
$current_settings [ 'remove_connection_detail' ] = isset ( $settings [ 'child_remove_connection_detail' ] ) ? $settings [ 'child_remove_connection_detail' ] : 0 ;
2020-03-27 15:13:11 +00:00
$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' ] ) ) {
2020-03-26 17:03:00 +00:00
$current_settings [ 'disable_wp_branding' ] = $settings [ 'child_disable_wp_branding' ];
2015-10-15 22:52:37 +10:00
}
$extra_setting = array (
'show_button_in' => $settings [ 'child_show_support_button_in' ],
'global_footer' => $settings [ 'child_global_footer' ],
'dashboard_footer' => $settings [ 'child_dashboard_footer' ],
'remove_widget_welcome' => $settings [ 'child_remove_widget_welcome' ],
'remove_widget_glance' => $settings [ 'child_remove_widget_glance' ],
'remove_widget_activity' => $settings [ 'child_remove_widget_activity' ],
'remove_widget_quick' => $settings [ 'child_remove_widget_quick' ],
'remove_widget_news' => $settings [ 'child_remove_widget_news' ],
2020-03-26 15:29:54 +00:00
'login_image_link' => $settings [ 'child_login_image_link' ],
'login_image_title' => $settings [ 'child_login_image_title' ],
2015-10-15 22:52:37 +10:00
'site_generator' => $settings [ 'child_site_generator' ],
'generator_link' => $settings [ 'child_generator_link' ],
'admin_css' => $settings [ 'child_admin_css' ],
'login_css' => $settings [ 'child_login_css' ],
'texts_replace' => $settings [ 'child_texts_replace' ],
'hide_nag' => $settings [ 'child_hide_nag' ],
'hide_screen_opts' => $settings [ 'child_hide_screen_opts' ],
'hide_help_box' => $settings [ 'child_hide_help_box' ],
'hide_metabox_post_excerpt' => $settings [ 'child_hide_metabox_post_excerpt' ],
'hide_metabox_post_slug' => $settings [ 'child_hide_metabox_post_slug' ],
'hide_metabox_post_tags' => $settings [ 'child_hide_metabox_post_tags' ],
'hide_metabox_post_author' => $settings [ 'child_hide_metabox_post_author' ],
'hide_metabox_post_comments' => $settings [ 'child_hide_metabox_post_comments' ],
'hide_metabox_post_revisions' => $settings [ 'child_hide_metabox_post_revisions' ],
'hide_metabox_post_discussion' => $settings [ 'child_hide_metabox_post_discussion' ],
'hide_metabox_post_categories' => $settings [ 'child_hide_metabox_post_categories' ],
'hide_metabox_post_custom_fields' => $settings [ 'child_hide_metabox_post_custom_fields' ],
'hide_metabox_post_trackbacks' => $settings [ 'child_hide_metabox_post_trackbacks' ],
'hide_metabox_page_custom_fields' => $settings [ 'child_hide_metabox_page_custom_fields' ],
'hide_metabox_page_author' => $settings [ 'child_hide_metabox_page_author' ],
'hide_metabox_page_discussion' => $settings [ 'child_hide_metabox_page_discussion' ],
'hide_metabox_page_revisions' => $settings [ 'child_hide_metabox_page_revisions' ],
'hide_metabox_page_attributes' => $settings [ 'child_hide_metabox_page_attributes' ],
'hide_metabox_page_slug' => $settings [ 'child_hide_metabox_page_slug' ],
);
if ( isset ( $settings [ 'child_login_image_url' ] ) ) {
if ( empty ( $settings [ 'child_login_image_url' ] ) ) {
$extra_setting [ 'login_image' ] = array ();
} else {
try {
2020-05-06 00:47:59 +07:00
$upload = $this -> upload_image ( $settings [ 'child_login_image_url' ] );
2015-10-15 22:52:37 +10:00
if ( null !== $upload ) {
2020-03-26 15:29:54 +00:00
$extra_setting [ 'login_image' ] = array (
'path' => $upload [ 'path' ],
'url' => $upload [ 'url' ],
);
2015-10-15 22:52:37 +10:00
if ( isset ( $current_extra_setting [ 'login_image' ][ 'path' ] ) ) {
$old_file = $current_extra_setting [ 'login_image' ][ 'path' ];
if ( ! empty ( $old_file ) && file_exists ( $old_file ) ) {
2020-04-23 19:53:22 +02:00
unlink ( $old_file );
2015-10-15 22:52:37 +10:00
}
}
}
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-10-15 22:52:37 +10:00
$information [ 'error' ][ 'login_image' ] = $e -> getMessage ();
}
}
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $current_extra_setting [ 'login_image' ] ) ) {
2015-10-15 22:52:37 +10:00
$extra_setting [ 'login_image' ] = $current_extra_setting [ 'login_image' ];
}
if ( isset ( $settings [ 'child_favico_image_url' ] ) ) {
if ( empty ( $settings [ 'child_favico_image_url' ] ) ) {
$extra_setting [ 'favico_image' ] = array ();
} else {
try {
2020-05-06 00:47:59 +07:00
$upload = $this -> upload_image ( $settings [ 'child_favico_image_url' ] );
2015-10-15 22:52:37 +10:00
if ( null !== $upload ) {
2020-03-26 15:29:54 +00:00
$extra_setting [ 'favico_image' ] = array (
'path' => $upload [ 'path' ],
'url' => $upload [ 'url' ],
);
2015-10-15 22:52:37 +10:00
if ( isset ( $current_extra_setting [ 'favico_image' ][ 'path' ] ) ) {
$old_file = $current_extra_setting [ 'favico_image' ][ 'path' ];
if ( ! empty ( $old_file ) && file_exists ( $old_file ) ) {
2020-04-23 19:53:22 +02:00
unlink ( $old_file );
2015-10-15 22:52:37 +10:00
}
}
}
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-10-15 22:52:37 +10:00
$information [ 'error' ][ 'favico_image' ] = $e -> getMessage ();
}
}
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $current_extra_setting [ 'favico_image' ] ) ) {
2015-10-15 22:52:37 +10:00
$extra_setting [ 'favico_image' ] = $current_extra_setting [ 'favico_image' ];
}
2020-03-27 15:13:11 +00:00
$current_settings [ 'extra_settings' ] = $extra_setting ;
2015-10-15 22:52:37 +10:00
if ( $settings [ 'child_plugin_hide' ] ) {
2017-07-11 14:10:22 +02:00
MainWP_Helper :: update_option ( 'mainwp_branding_child_hide' , 'T' , 'yes' );
2015-10-15 22:52:37 +10:00
} else {
MainWP_Helper :: update_option ( 'mainwp_branding_child_hide' , '' );
}
2016-02-15 22:08:39 +01:00
2020-03-27 15:13:11 +00:00
$current_settings [ 'hide' ] = $settings [ 'child_plugin_hide' ] ? 'T' : '' ;
2020-04-16 19:59:35 +02:00
$current_settings [ 'show_support' ] = ( $settings [ 'child_show_support_button' ] && ! empty ( $settings [ 'child_support_email' ] ) ) ? 'T' : '' ;
2020-03-27 15:13:11 +00:00
$current_settings [ 'disable_change' ] = $settings [ 'child_disable_change' ] ? 'T' : '' ;
$current_settings [ 'disable_switching_theme' ] = $settings [ 'child_disable_switching_theme' ] ? 'T' : '' ;
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
MainWP_Helper :: update_option ( 'mainwp_child_branding_settings' , $current_settings );
2016-02-15 22:08:39 +01:00
2015-10-15 22:52:37 +10:00
$information [ 'result' ] = 'SUCCESS' ;
return $information ;
}
2020-05-06 00:47:59 +07:00
public static function upload_image ( $img_url ) {
2020-04-16 19:59:35 +02:00
include_once ABSPATH . 'wp-admin/includes/file.php' ;
global $mainWPChild ;
2020-03-27 15:13:11 +00:00
add_filter ( 'http_request_args' , array ( $mainWPChild , 'http_request_reject_unsafe_urls' ), 99 , 2 );
2018-09-27 19:52:32 +02:00
$temporary_file = download_url ( $img_url );
2020-03-27 15:13:11 +00:00
remove_filter ( 'http_request_args' , array ( $mainWPChild , 'http_request_reject_unsafe_urls' ), 99 , 2 );
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
if ( is_wp_error ( $temporary_file ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( $temporary_file -> get_error_message () );
2015-10-15 22:52:37 +10:00
} else {
$upload_dir = wp_upload_dir ();
2020-04-16 19:59:35 +02:00
$local_img_path = $upload_dir [ 'path' ] . DIRECTORY_SEPARATOR . basename ( $img_url );
2015-10-15 22:52:37 +10:00
$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 );
2020-04-23 19:53:22 +02:00
$moved = rename ( $temporary_file , $local_img_path );
2015-10-15 22:52:37 +10:00
if ( $moved ) {
2020-03-26 15:29:54 +00:00
return array (
'path' => $local_img_path ,
'url' => $local_img_url ,
);
2015-10-15 22:52:37 +10:00
}
}
if ( file_exists ( $temporary_file ) ) {
unlink ( $temporary_file );
}
return null ;
}
public function branding_init () {
2020-05-07 23:22:05 +07:00
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2018-12-19 17:01:08 +07:00
2020-03-27 15:13:11 +00:00
if ( is_admin () ) {
add_action ( 'in_admin_footer' , array ( $this , 'in_admin_footer' ) );
} elseif ( is_user_logged_in () ) {
2020-04-16 19:59:35 +02:00
add_action ( 'wp_after_admin_bar_render' , array ( $this , 'after_admin_bar_render' ) );
2020-03-27 15:13:11 +00:00
}
2020-04-16 19:59:35 +02:00
2020-03-27 15:13:11 +00:00
$opts = $this -> child_branding_options ;
2018-12-19 17:01:08 +07:00
2019-02-14 22:38:14 +07:00
$cancelled_branding = $opts [ 'cancelled_branding' ];
2015-10-15 22:52:37 +10:00
if ( $cancelled_branding ) {
return ;
}
2020-04-16 19:59:35 +02:00
// enable branding in case child plugin deactive and re-activated.
2019-02-14 22:38:14 +07:00
add_filter ( 'all_plugins' , array ( $this , 'modify_plugin_header' ) );
if ( $this -> is_branding () ) {
2018-12-19 17:01:08 +07:00
add_filter ( 'site_transient_update_plugins' , array ( & $this , 'remove_update_nag' ) );
2020-03-27 15:13:11 +00:00
add_filter ( 'mainwp_child_hide_update_notice' , array ( & $this , 'hide_update_notice' ) );
2018-12-19 17:01:08 +07:00
}
2017-01-18 22:33:53 +01:00
2020-04-16 19:59:35 +02:00
if ( ! isset ( $opts [ 'branding_ext_enabled' ] ) || 'Y' !== $opts [ 'branding_ext_enabled' ] ) {
2015-10-15 22:52:37 +10:00
return ;
}
add_filter ( 'map_meta_cap' , array ( $this , 'branding_map_meta_cap' ), 10 , 5 );
2018-09-27 19:52:32 +02:00
2020-03-27 14:11:21 +00:00
if ( 'T' === $opts [ 'disable_change' ] ) {
2020-05-07 23:22:05 +07:00
2020-04-16 19:59:35 +02:00
// Disable the WordPress plugin update notifications.
remove_action ( 'load-update-core.php' , 'wp_update_plugins' );
add_filter ( 'pre_site_transient_update_plugins' , '__return_null' );
// Disable the WordPress theme update notifications.
remove_action ( 'load-update-core.php' , 'wp_update_themes' );
add_filter (
'pre_site_transient_update_themes' ,
2020-05-07 23:22:05 +07:00
function ( $a ) {
return null ;
}
2020-04-16 19:59:35 +02:00
);
2018-04-17 20:33:10 +02:00
2020-04-16 19:59:35 +02:00
// Disable the WordPress core update notifications.
add_action ( 'after_setup_theme' , 'remove_core_updates' );
2018-09-27 19:52:32 +02:00
function remove_core_updates () {
2020-04-16 19:59:35 +02:00
add_action (
'init' ,
2020-05-07 23:22:05 +07:00
function ( $a ) {
2020-04-16 19:59:35 +02:00
remove_action ( 'wp_version_check' , 'wp_version_check' );
2020-05-07 23:22:05 +07:00
},
2020-04-16 19:59:35 +02:00
2
);
add_filter ( 'pre_option_update_core' , '__return_null' );
add_filter ( 'pre_site_transient_update_core' , '__return_null' );
2018-04-17 20:33:10 +02:00
}
2018-09-27 19:52:32 +02:00
add_action ( 'admin_head' , array ( & $this , 'admin_head_hide_elements' ), 15 );
2020-04-16 19:59:35 +02:00
add_action ( 'admin_menu' , array ( $this , 'branding_redirect' ), 9 );
2018-04-17 20:33:10 +02:00
}
2015-10-15 22:52:37 +10:00
2020-04-16 19:59:35 +02:00
add_action ( 'admin_menu' , array ( & $this , 'admin_menu' ) );
if ( ! isset ( $opts [ 'disable_wp_branding' ] ) || 'Y' !== $opts [ 'disable_wp_branding' ] ) {
2015-10-15 22:52:37 +10:00
add_filter ( 'wp_footer' , array ( & $this , 'branding_global_footer' ), 15 );
add_action ( 'wp_dashboard_setup' , array ( & $this , 'custom_dashboard_widgets' ), 999 );
2020-04-16 19:59:35 +02:00
// branding site generator.
2015-10-15 22:52:37 +10:00
$types = array ( 'html' , 'xhtml' , 'atom' , 'rss2' , 'rdf' , 'comment' , 'export' );
foreach ( $types as $type ) {
2016-02-15 22:08:39 +01:00
add_filter ( 'get_the_generator_' . $type , array ( & $this , 'custom_the_generator' ), 999 , 2 );
2015-10-15 22:52:37 +10:00
}
add_action ( 'admin_head' , array ( & $this , 'custom_admin_css' ) );
add_action ( 'login_enqueue_scripts' , array ( & $this , 'custom_login_css' ) );
add_filter ( 'gettext' , array ( & $this , 'custom_gettext' ), 99 , 3 );
add_action ( 'login_head' , array ( & $this , 'custom_login_logo' ) );
2018-09-27 19:52:32 +02:00
add_filter ( 'login_headerurl' , array ( & $this , 'custom_login_headerurl' ) );
2019-08-26 23:29:16 +07:00
add_filter ( 'login_headertext' , array ( & $this , 'custom_login_headertitle' ) );
2015-10-15 22:52:37 +10:00
add_action ( 'wp_head' , array ( & $this , 'custom_favicon_frontend' ) );
if ( isset ( $extra_setting [ 'dashboard_footer' ] ) && ! empty ( $extra_setting [ 'dashboard_footer' ] ) ) {
2018-04-17 20:33:10 +02:00
add_filter ( 'update_footer' , array ( & $this , 'core_update_footer' ), 14 );
2020-03-27 15:13:11 +00:00
add_filter ( 'admin_footer_text' , array ( & $this , 'admin_footer_text' ), 14 );
2015-10-15 22:52:37 +10:00
}
2018-09-27 19:52:32 +02:00
if ( isset ( $extra_setting [ 'hide_nag' ] ) && ! empty ( $extra_setting [ 'hide_nag' ] ) ) {
2020-04-16 19:59:35 +02:00
add_action ( 'admin_init' , array ( $this , 'admin_init' ) );
2015-10-15 22:52:37 +10:00
}
add_action ( 'admin_menu' , array ( & $this , 'remove_default_post_metaboxes' ) );
add_action ( 'admin_menu' , array ( & $this , 'remove_default_page_metaboxes' ) );
}
}
2018-04-17 20:33:10 +02:00
public function admin_init () {
2018-09-27 19:52:32 +02:00
remove_action ( 'admin_notices' , 'update_nag' , 3 );
2018-04-17 20:33:10 +02:00
}
2018-09-27 19:52:32 +02:00
2020-04-16 19:59:35 +02:00
// prevent conflicts with other plugins.
2020-04-16 20:10:19 +02:00
public function admin_menu () {
2020-05-05 20:13:38 +07:00
$enable_contact = apply_filters ( 'mainwp_branding_role_cap_enable_contact_form' , false );
2020-05-05 13:19:34 +00:00
2020-05-05 20:13:38 +07:00
if ( ! $enable_contact && ! current_user_can ( 'administrator' ) ) {
2017-07-11 19:36:28 +02:00
return false ;
}
2019-02-14 22:38:14 +07:00
2020-03-27 15:13:11 +00:00
$extra_setting = $this -> get_extra_options ();
2020-04-16 20:10:19 +02:00
if ( empty ( $extra_setting ) ) {
2019-02-14 22:38:14 +07:00
return false ;
2017-07-11 14:10:22 +02:00
}
2020-03-27 15:13:11 +00:00
$opts = $this -> child_branding_options ;
2019-02-14 22:38:14 +07:00
if ( 'T' === $opts [ 'show_support' ] ) {
$title = $opts [ 'contact_label' ];
2017-07-11 14:10:22 +02:00
if ( isset ( $extra_setting [ 'show_button_in' ] ) && ( 2 === ( int ) $extra_setting [ 'show_button_in' ] || 3 === ( int ) $extra_setting [ 'show_button_in' ] ) ) {
2019-02-14 22:38:14 +07:00
$title = $opts [ 'contact_label' ];
2020-04-16 19:59:35 +02:00
add_menu_page (
$title ,
$title ,
'read' ,
'ContactSupport2' ,
array (
$this ,
'contact_support' ,
),
'' ,
'2.0001'
);
2017-07-11 14:10:22 +02:00
}
if ( isset ( $extra_setting [ 'show_button_in' ] ) && ( 1 === $extra_setting [ 'show_button_in' ] || 3 === $extra_setting [ 'show_button_in' ] ) ) {
2020-04-16 19:59:35 +02:00
add_submenu_page (
null ,
$title ,
$opts [ 'contact_label' ],
'read' ,
'ContactSupport' ,
array (
$this ,
'contact_support' ,
)
);
2017-07-11 14:10:22 +02:00
add_action ( 'admin_bar_menu' , array ( $this , 'add_support_button_in_top_admin_bar' ), 100 );
}
}
}
2020-04-16 19:59:35 +02:00
public function remove_default_post_metaboxes () {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
add_filter ( 'manage_posts_columns' , array ( & $this , 'custom_post_columns' ) );
add_filter ( 'manage_edit-post_tag_columns' , array ( & $this , 'manage_my_category_columns' ) );
add_filter ( 'manage_edit-category_columns' , array ( & $this , 'manage_my_category_columns' ) );
if ( isset ( $extra_setting [ 'hide_metabox_post_custom_fields' ] ) && $extra_setting [ 'hide_metabox_post_custom_fields' ] ) {
remove_meta_box ( 'postcustom' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_excerpt' ] ) && $extra_setting [ 'hide_metabox_post_excerpt' ] ) {
remove_meta_box ( 'postexcerpt' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_discussion' ] ) && $extra_setting [ 'hide_metabox_post_discussion' ] ) {
remove_meta_box ( 'commentstatusdiv' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_trackbacks' ] ) && $extra_setting [ 'hide_metabox_post_trackbacks' ] ) {
remove_meta_box ( 'trackbacksdiv' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_slug' ] ) && $extra_setting [ 'hide_metabox_post_slug' ] ) {
remove_meta_box ( 'slugdiv' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_author' ] ) && $extra_setting [ 'hide_metabox_post_author' ] ) {
remove_meta_box ( 'authordiv' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_revisions' ] ) && $extra_setting [ 'hide_metabox_post_revisions' ] ) {
remove_meta_box ( 'revisionsdiv' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_tags' ] ) && $extra_setting [ 'hide_metabox_post_tags' ] ) {
remove_meta_box ( 'tagsdiv-post_tag' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_categories' ] ) && $extra_setting [ 'hide_metabox_post_categories' ] ) {
remove_meta_box ( 'categorydiv' , 'post' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_comments' ] ) && $extra_setting [ 'hide_metabox_post_comments' ] ) {
remove_meta_box ( 'commentsdiv' , 'post' , 'normal' );
}
}
2020-04-16 19:59:35 +02:00
public function custom_post_columns ( $defaults ) {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
if ( isset ( $extra_setting [ 'hide_metabox_post_comments' ] ) && $extra_setting [ 'hide_metabox_post_comments' ] ) {
unset ( $defaults [ 'comments' ] );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_author' ] ) && $extra_setting [ 'hide_metabox_post_author' ] ) {
unset ( $defaults [ 'author' ] );
}
if ( isset ( $extra_setting [ 'hide_metabox_post_categories' ] ) && $extra_setting [ 'hide_metabox_post_categories' ] ) {
unset ( $defaults [ 'categories' ] );
}
return $defaults ;
}
2020-04-16 19:59:35 +02:00
public function manage_my_category_columns ( $defaults ) {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
if ( isset ( $extra_setting [ 'hide_metabox_post_slug' ] ) && $extra_setting [ 'hide_metabox_post_slug' ] ) {
unset ( $defaults [ 'slug' ] );
}
return $defaults ;
}
2020-04-16 19:59:35 +02:00
public function remove_default_page_metaboxes () {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
add_filter ( 'manage_pages_columns' , array ( & $this , 'custom_pages_columns' ) );
2020-04-16 19:59:35 +02:00
if ( isset ( $extra_setting [ 'hide_metabox_page_custom_fields' ] ) && $extra_setting [ 'hide_metabox_page_custom_fields' ] ) {
2015-10-15 22:52:37 +10:00
remove_meta_box ( 'postcustom' , 'page' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_page_author' ] ) && $extra_setting [ 'hide_metabox_page_author' ] ) {
remove_meta_box ( 'authordiv' , 'page' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_page_discussion' ] ) && $extra_setting [ 'hide_metabox_page_discussion' ] ) {
remove_meta_box ( 'commentstatusdiv' , 'page' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_page_slug' ] ) && $extra_setting [ 'hide_metabox_page_slug' ] ) {
remove_meta_box ( 'slugdiv' , 'page' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_page_revisions' ] ) && $extra_setting [ 'hide_metabox_page_revisions' ] ) {
remove_meta_box ( 'revisionsdiv' , 'page' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_page_attributes' ] ) && $extra_setting [ 'hide_metabox_page_attributes' ] ) {
remove_meta_box ( 'pageparentdiv' , 'page' , 'normal' );
}
if ( isset ( $extra_setting [ 'hide_metabox_page_comments' ] ) && $extra_setting [ 'hide_metabox_page_comments' ] ) {
remove_meta_box ( 'commentsdiv' , 'page' , 'normal' );
}
}
2020-04-16 20:10:19 +02:00
public function custom_pages_columns ( $defaults ) {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
if ( isset ( $extra_setting [ 'hide_metabox_page_comments' ] ) && $extra_setting [ 'hide_metabox_page_comments' ] ) {
unset ( $defaults [ 'comments' ] );
}
if ( isset ( $extra_setting [ 'hide_metabox_page_author' ] ) && $extra_setting [ 'hide_metabox_page_author' ] ) {
unset ( $defaults [ 'author' ] );
}
return $defaults ;
}
2018-04-17 20:33:10 +02:00
public function branding_redirect () {
$pos1 = stripos ( $_SERVER [ 'REQUEST_URI' ], 'update-core.php' );
$pos2 = stripos ( $_SERVER [ 'REQUEST_URI' ], 'plugins.php' );
if ( false !== $pos1 || false !== $pos2 ) {
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( get_option ( 'siteurl' ) . '/wp-admin/index.php' );
2018-04-17 20:33:10 +02:00
exit ();
2018-09-27 19:52:32 +02:00
}
2018-04-17 20:33:10 +02:00
}
2018-09-27 19:52:32 +02:00
2020-04-16 19:59:35 +02:00
public function admin_head_hide_elements () {
?>
< script type = " text/javascript " >
document . addEventListener ( " DOMContentLoaded " , function ( event ) {
document . getElementById ( " wp-admin-bar-updates " ) . outerHTML = '' ;
document . getElementById ( " menu-plugins " ) . outerHTML = '' ;
var els_core = document . querySelectorAll ( " a[href='update-core.php'] " );
for ( var i = 0 , l = els_core . length ; i < l ; i ++ ) {
2018-09-27 19:52:32 +02:00
var el = els_core [ i ];
2018-04-17 20:33:10 +02:00
el . parentElement . innerHTML = '' ;
}
2020-04-16 19:59:35 +02:00
} );
2020-03-26 14:05:04 +00:00
</ script >
2020-03-27 15:13:11 +00:00
< ? php
2018-04-17 20:33:10 +02:00
}
2018-09-27 19:52:32 +02:00
2020-04-16 19:59:35 +02:00
public function core_update_footer () {
echo '' ;
2018-04-17 20:33:10 +02:00
}
2018-09-27 19:52:32 +02:00
2020-04-16 19:59:35 +02:00
public function admin_footer_text () {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
if ( isset ( $extra_setting [ 'dashboard_footer' ] ) && ! empty ( $extra_setting [ 'dashboard_footer' ] ) ) {
echo wp_kses_post ( nl2br ( stripslashes ( $extra_setting [ 'dashboard_footer' ] ) ) );
}
}
2020-04-16 19:59:35 +02:00
public function custom_favicon_frontend () {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
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 " ;
}
}
2020-04-16 19:59:35 +02:00
public function custom_login_logo () {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
if ( isset ( $extra_setting [ 'login_image' ][ 'url' ] ) && ! empty ( $extra_setting [ 'login_image' ][ 'url' ] ) ) {
$login_logo = $extra_setting [ 'login_image' ][ 'url' ];
2020-04-16 19:59:35 +02:00
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>' ;
2015-10-15 22:52:37 +10:00
}
}
2020-04-16 19:59:35 +02:00
public function custom_login_headerurl ( $value ) {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2018-06-26 19:52:53 +02:00
if ( isset ( $extra_setting [ 'login_image_link' ] ) && ! empty ( $extra_setting [ 'login_image_link' ] ) ) {
return $extra_setting [ 'login_image_link' ];
}
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
return $value ;
}
2018-09-27 19:52:32 +02:00
2020-04-16 19:59:35 +02:00
public function custom_login_headertitle ( $value ) {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2018-06-26 19:52:53 +02:00
if ( isset ( $extra_setting [ 'login_image_title' ] ) && ! empty ( $extra_setting [ 'login_image_title' ] ) ) {
return $extra_setting [ 'login_image_title' ];
}
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
return $value ;
2018-09-27 19:52:32 +02:00
}
2020-04-16 19:59:35 +02:00
public function custom_gettext ( $translations , $text , $domain = 'default' ) {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
$texts_replace = $extra_setting [ 'texts_replace' ];
if ( is_array ( $texts_replace ) && count ( $texts_replace ) > 0 ) {
foreach ( $texts_replace as $text => $replace ) {
if ( ! empty ( $text ) ) {
$translations = str_replace ( $text , $replace , $translations );
}
}
}
return $translations ;
}
2020-04-16 19:59:35 +02:00
public function custom_admin_css () {
2015-10-15 22:52:37 +10:00
$header_css = '' ;
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
2019-02-14 22:38:14 +07:00
if ( isset ( $extra_setting [ 'admin_css' ] ) && ! empty ( $extra_setting [ 'admin_css' ] ) ) {
2015-10-15 22:52:37 +10:00
$header_css .= $extra_setting [ 'admin_css' ];
}
if ( isset ( $extra_setting [ 'hide_screen_opts' ] ) && ! empty ( $extra_setting [ 'hide_screen_opts' ] ) ) {
$header_css .= ' #screen-options-link-wrap { display: none; }' ;
}
if ( isset ( $extra_setting [ 'hide_help_box' ] ) && ! empty ( $extra_setting [ 'hide_help_box' ] ) ) {
$header_css .= ' #contextual-help-link-wrap { display: none; }' ;
$header_css .= ' #contextual-help-link { display: none; }' ;
}
if ( ! empty ( $header_css ) ) {
2016-01-18 19:40:51 +01:00
echo '<style>' . MainWP_Helper :: parse_css ( $header_css ) . '</style>' ;
2015-10-15 22:52:37 +10:00
}
}
2020-04-16 19:59:35 +02:00
public function custom_login_css () {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
if ( isset ( $extra_setting [ 'login_css' ] ) && ! empty ( $extra_setting [ 'login_css' ] ) ) {
2016-01-18 19:40:51 +01:00
echo '<style>' . MainWP_Helper :: parse_css ( $extra_setting [ 'login_css' ] ) . '</style>' ;
2015-10-15 22:52:37 +10:00
}
}
2020-04-16 19:59:35 +02:00
public function custom_the_generator ( $generator , $type = '' ) {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
if ( isset ( $extra_setting [ 'site_generator' ] ) ) {
if ( ! empty ( $extra_setting [ 'site_generator' ] ) ) {
switch ( $type ) :
case 'html' :
$generator = '<meta name="generator" content="' . $extra_setting [ 'site_generator' ] . '">' ;
break ;
case 'xhtml' :
$generator = '<meta name="generator" content="' . $extra_setting [ 'site_generator' ] . '" />' ;
break ;
case 'atom' :
if ( ! empty ( $extra_setting [ 'generator_link' ] ) ) {
$generator = '<generator uri="' . $extra_setting [ 'generator_link' ] . '" >' . $extra_setting [ 'site_generator' ] . '</generator>' ;
}
break ;
case 'rss2' :
if ( ! empty ( $extra_setting [ 'generator_link' ] ) ) {
$generator = '<generator>' . $extra_setting [ 'generator_link' ] . '</generator>' ;
}
break ;
case 'rdf' :
if ( ! empty ( $extra_setting [ 'generator_link' ] ) ) {
$generator = '<admin:generatorAgent rdf:resource="' . $extra_setting [ 'generator_link' ] . '" />' ;
}
break ;
case 'comment' :
$generator = '<!-- generator="' . $extra_setting [ 'site_generator' ] . '" -->' ;
break ;
case 'export' :
2020-05-07 19:34:36 +07:00
$generator = '<!-- generator="' . $extra_setting [ 'site_generator' ] . '" created="' . date ( 'Y-m-d H:i' ) . '" -->' ; //phpcs:ignore -- current local time.
2015-10-15 22:52:37 +10:00
break ;
endswitch ;
return $generator ;
}
}
return $generator ;
}
2020-04-16 19:59:35 +02:00
public function custom_dashboard_widgets () {
2015-10-15 22:52:37 +10:00
global $wp_meta_boxes ;
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
if ( isset ( $extra_setting [ 'remove_widget_welcome' ] ) && $extra_setting [ 'remove_widget_welcome' ] ) {
remove_action ( 'welcome_panel' , 'wp_welcome_panel' );
}
if ( isset ( $extra_setting [ 'remove_widget_glance' ] ) && $extra_setting [ 'remove_widget_glance' ] ) {
unset ( $wp_meta_boxes [ 'dashboard' ][ 'normal' ][ 'core' ][ 'dashboard_right_now' ] );
}
if ( isset ( $extra_setting [ 'remove_widget_activity' ] ) && $extra_setting [ 'remove_widget_activity' ] ) {
unset ( $wp_meta_boxes [ 'dashboard' ][ 'normal' ][ 'core' ][ 'dashboard_activity' ] );
}
if ( isset ( $extra_setting [ 'remove_widget_quick' ] ) && $extra_setting [ 'remove_widget_quick' ] ) {
unset ( $wp_meta_boxes [ 'dashboard' ][ 'side' ][ 'core' ][ 'dashboard_quick_press' ] );
}
if ( isset ( $extra_setting [ 'remove_widget_news' ] ) && $extra_setting [ 'remove_widget_news' ] ) {
unset ( $wp_meta_boxes [ 'dashboard' ][ 'side' ][ 'core' ][ 'dashboard_primary' ] );
}
}
public function branding_global_footer () {
2019-02-14 22:38:14 +07:00
$extra_setting = $this -> get_extra_options ();
2015-10-15 22:52:37 +10:00
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 () {
2019-02-14 22:38:14 +07:00
$email = $this -> child_branding_options [ 'support_email' ];
2020-03-26 19:45:07 +00:00
$sub = wp_kses_post ( nl2br ( stripslashes ( $_POST [ 'mainwp_branding_contact_message_subject' ] ) ) );
2020-04-16 19:59:35 +02:00
$from = trim ( $_POST [ 'mainwp_branding_contact_send_from' ] );
2020-03-26 17:03:00 +00:00
$subject = ! empty ( $sub ) ? $sub : 'MainWP - Support Contact' ;
2015-10-15 22:52:37 +10:00
$content = wp_kses_post ( nl2br ( stripslashes ( $_POST [ 'mainwp_branding_contact_message_content' ] ) ) );
2020-04-16 19:59:35 +02:00
$mail = '' ;
$headers = '' ;
2015-10-15 22:52:37 +10:00
if ( ! empty ( $_POST [ 'mainwp_branding_contact_message_content' ] ) && ! empty ( $email ) ) {
global $current_user ;
2016-03-03 20:28:07 +01:00
$headers .= " Content-Type: text/html;charset=utf-8 \r \n " ;
2020-04-16 19:59:35 +02:00
if ( ! empty ( $from ) ) {
2020-03-27 15:13:11 +00:00
$headers .= 'From: "' . $from . '" <' . $from . " > \r \n " ;
}
2016-03-03 20:28:07 +01:00
$mail .= " <p>Support Email from: <a href=' " . site_url () . " '> " . site_url () . " </a></p> \r \n \r \n " ;
2020-03-26 14:05:04 +00:00
$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 " ;
2016-03-03 20:28:07 +01:00
$mail .= " <p>Support Text:</p> \r \n \r \n " ;
2020-03-26 14:05:04 +00:00
$mail .= '<p>' . $content . " </p> \r \n \r \n " ;
2016-03-03 20:28:07 +01:00
2020-04-22 19:00:01 +02:00
wp_mail ( $email , $subject , $mail , $headers );
2015-10-15 22:52:37 +10:00
return true ;
}
return false ;
}
2020-04-16 19:59:35 +02:00
public function contact_support () {
2020-03-27 15:13:11 +00:00
global $current_user ;
2015-10-15 22:52:37 +10:00
?>
< style >
. mainwp_info - box - yellow {
margin : 5 px 0 15 px ;
padding : . 6 em ;
background : #ffffe0;
border : 1 px solid #e6db55;
border - radius : 3 px ;
- moz - border - radius : 3 px ;
- webkit - border - radius : 3 px ;
clear : both ;
}
</ style >
< ? php
2020-03-27 15:13:11 +00:00
$opts = $this -> child_branding_options ;
2019-02-14 22:38:14 +07:00
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'submit' ] ) ) {
if ( ! isset ( $_POST [ '_wpnonce' ] ) || ! wp_verify_nonce ( $_POST [ '_wpnonce' ], '_contactNonce' ) ) {
return false ;
}
$from_page = $_POST [ 'mainwp_branding_send_from_page' ];
2019-02-14 22:38:14 +07:00
$back_link = $opts [ 'message_return_sender' ];
2015-10-15 22:52:37 +10:00
$back_link = ! empty ( $back_link ) ? $back_link : 'Go Back' ;
2015-12-05 17:38:52 +01:00
$back_link = ! empty ( $from_page ) ? '<a href="' . esc_url ( $from_page ) . '" title="' . esc_attr ( $back_link ) . '">' . esc_html ( $back_link ) . '</a>' : '' ;
2015-10-15 22:52:37 +10:00
if ( $this -> send_support_mail () ) {
2019-03-06 22:45:51 +07:00
$send_email_message = isset ( $opts [ 'send_email_message' ] ) ? $opts [ 'send_email_message' ] : '' ;
2015-10-15 22:52:37 +10:00
if ( ! empty ( $send_email_message ) ) {
$send_email_message = stripslashes ( $send_email_message );
} else {
2018-09-27 19:52:32 +02:00
$send_email_message = __ ( 'Message has been submitted successfully.' , 'mainwp-child' );
2015-10-15 22:52:37 +10:00
}
} else {
2018-09-27 19:52:32 +02:00
$send_email_message = __ ( 'Sending email failed!' , 'mainwp-child' );
2015-10-15 22:52:37 +10:00
}
?>
2020-04-16 19:59:35 +02:00
< div class = " mainwp_info-box-yellow " >< ? php echo esc_html ( $send_email_message ) . '  ' . $back_link ; ?> </div>
< ? php
2015-10-15 22:52:37 +10:00
} else {
$from_page = '' ;
if ( isset ( $_GET [ 'from_page' ] ) ) {
2020-04-16 19:59:35 +02:00
$from_page = rawurldecode ( $_GET [ 'from_page' ] );
2015-10-15 22:52:37 +10:00
} else {
$protocol = isset ( $_SERVER [ 'HTTPS' ] ) && strcasecmp ( $_SERVER [ 'HTTPS' ], 'off' ) ? 'https://' : 'http://' ;
$fullurl = $protocol . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'REQUEST_URI' ];
2020-04-16 19:59:35 +02:00
$from_page = rawurldecode ( $fullurl );
2015-10-15 22:52:37 +10:00
}
2019-02-14 22:38:14 +07:00
$support_message = $opts [ 'support_message' ];
2015-10-15 22:52:37 +10:00
$support_message = nl2br ( stripslashes ( $support_message ) );
2020-03-27 15:13:11 +00:00
$from_email = $current_user ? $current_user -> user_email : '' ;
2015-10-15 22:52:37 +10:00
?>
< form action = " " method = " post " >
< div style = " width: 99%; " >
2019-02-14 22:38:14 +07:00
< h2 >< ? php echo esc_html ( $opts [ 'contact_label' ] ); ?> </h2>
2015-10-15 22:52:37 +10:00
< div style = " height: auto; margin-bottom: 10px; text-align: left " >
2016-01-18 19:40:51 +01:00
< p >< ? php echo wp_kses_post ( $support_message ); ?> </p>
2020-04-16 19:59:35 +02:00
< p >
< label for = " mainwp_branding_contact_message_subject " >< ? php esc_html_e ( 'Subject:' , 'mainwp-child' ); ?> </label>
< br >
< 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 >
2015-10-15 22:52:37 +10:00
< div style = " max-width: 650px; " >
2020-04-16 19:59:35 +02:00
< label for = " mainwp_branding_contact_message_content " >< ? php esc_html_e ( 'Your message:' , 'mainwp-child' ); ?> </label>
< br >
2015-10-15 22:52:37 +10:00
< ? php
2020-04-16 19:59:35 +02:00
remove_editor_styles (); // stop custom theme styling interfering with the editor.
wp_editor (
'' ,
'mainwp_branding_contact_message_content' ,
array (
'textarea_name' => 'mainwp_branding_contact_message_content' ,
'textarea_rows' => 10 ,
'teeny' => true ,
'wpautop' => true ,
'media_buttons' => false ,
)
2015-10-15 22:52:37 +10:00
);
?>
</ div >
</ div >
< br />
< ? php
2019-02-14 22:38:14 +07:00
$button_title = $opts [ 'submit_button_title' ];
2020-04-16 19:59:35 +02:00
$button_title = ! empty ( $button_title ) ? $button_title : __ ( 'Submit' , 'mainwp-child' );
2015-10-15 22:52:37 +10:00
?>
2020-04-16 19:59:35 +02:00
< 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 " />
2015-10-15 22:52:37 +10:00
</ div >
2020-04-16 19:59:35 +02:00
< input type = " hidden " name = " mainwp_branding_send_from_page " value = " <?php echo esc_url( $from_page ); ?> " />
2015-10-15 22:52:37 +10:00
< input type = " hidden " name = " _wpnonce " value = " <?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?> " />
</ form >
2020-03-26 19:51:58 +00:00
< ? php
2020-03-27 15:13:11 +00:00
}
2015-10-15 22:52:37 +10:00
}
/**
* @ param WP_Admin_Bar $wp_admin_bar
*/
public function add_support_button_in_top_admin_bar ( $wp_admin_bar ) {
2020-05-05 20:13:38 +07:00
$enable_contact = apply_filters ( 'mainwp_branding_role_cap_enable_contact_form' , false );
if ( ! $enable_contact && ! current_user_can ( 'administrator' ) ) {
2015-10-15 22:52:37 +10:00
return false ;
}
if ( isset ( $_GET [ 'from_page' ] ) ) {
2020-04-16 19:59:35 +02:00
$href = admin_url ( 'admin.php?page=ContactSupport&from_page=' . rawurlencode ( esc_url ( $_GET [ 'from_page' ] ) ) );
2015-10-15 22:52:37 +10:00
} else {
$protocol = isset ( $_SERVER [ 'HTTPS' ] ) && strcasecmp ( $_SERVER [ 'HTTPS' ], 'off' ) ? 'https://' : 'http://' ;
$fullurl = $protocol . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'REQUEST_URI' ];
2020-04-16 19:59:35 +02:00
$href = admin_url ( 'admin.php?page=ContactSupport&from_page=' . rawurlencode ( esc_url ( $fullurl ) ) );
2015-10-15 22:52:37 +10:00
}
$args = array (
'id' => 999 ,
2019-02-14 22:38:14 +07:00
'title' => $this -> child_branding_options [ 'contact_label' ],
2015-10-15 22:52:37 +10:00
'parent' => 'top-secondary' ,
'href' => $href ,
'meta' => array (
'class' => 'mainwp_branding_support_top_bar_button' ,
2019-02-14 22:38:14 +07:00
'title' => $this -> child_branding_options [ 'contact_label' ],
2015-10-15 22:52:37 +10:00
),
);
$wp_admin_bar -> add_node ( $args );
}
2019-02-14 22:38:14 +07:00
public function is_branding () {
2020-03-27 15:13:11 +00:00
$opts = $this -> child_branding_options ;
2020-04-16 19:59:35 +02:00
if ( ! isset ( $opts [ 'branding_ext_enabled' ] ) || 'Y' !== $opts [ 'branding_ext_enabled' ] ) {
2020-03-27 15:13:11 +00:00
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 ;
}
2020-04-16 19:59:35 +02:00
2020-03-27 15:13:11 +00:00
if ( 'T' === $is_hide ) {
return true ;
}
2020-04-16 19:59:35 +02:00
2020-05-04 23:02:02 +07:00
if ( is_array ( $branding_header ) && ! empty ( $branding_header [ 'name' ] ) && is_array ( $plugins ) ) {
2020-03-27 15:13:11 +00:00
return true ;
}
2020-04-16 19:59:35 +02:00
2020-03-27 15:13:11 +00:00
return false ;
2019-02-14 22:38:14 +07:00
}
2015-10-15 22:52:37 +10:00
2020-03-27 15:13:11 +00:00
public function get_branding_title () {
2019-02-14 22:38:14 +07:00
if ( $this -> is_branding () ) {
2020-03-27 15:13:11 +00:00
$branding_header = $this -> child_branding_options [ 'branding_header' ];
2019-02-14 22:38:14 +07:00
return $branding_header [ 'name' ];
2015-10-15 22:52:37 +10:00
}
2019-02-14 22:38:14 +07:00
return '' ;
2015-10-15 22:52:37 +10:00
}
2020-03-27 15:13:11 +00:00
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 after_admin_bar_render () {
2020-04-16 19:59:35 +02:00
$hide_slugs = apply_filters ( 'mainwp_child_hide_update_notice' , array () );
2020-03-27 15:13:11 +00:00
2020-04-16 19:59:35 +02:00
if ( ! is_array ( $hide_slugs ) ) {
2020-03-27 15:13:11 +00:00
$hide_slugs = array ();
}
2020-04-16 19:59:35 +02:00
if ( 0 == count ( $hide_slugs ) ) {
2020-03-27 15:13:11 +00:00
return ;
}
2020-04-16 19:59:35 +02:00
if ( ! function_exists ( 'get_plugin_updates' ) ) {
2020-03-27 15:13:11 +00:00
include_once ABSPATH . '/wp-admin/includes/update.php' ;
}
$count_hide = 0 ;
$updates = get_plugin_updates ();
2020-04-16 19:59:35 +02:00
if ( is_array ( $updates ) ) {
2020-03-27 15:13:11 +00:00
foreach ( $updates as $slug => $data ) {
2020-04-16 19:59:35 +02:00
if ( in_array ( $slug , $hide_slugs ) ) {
2020-03-27 15:13:11 +00:00
$count_hide ++ ;
}
}
}
2020-04-16 19:59:35 +02:00
if ( 0 == $count_hide ) {
2020-03-27 15:13:11 +00:00
return ;
}
?>
< script type = " text/javascript " >
2020-04-16 19:59:35 +02:00
var mainwpCountHide = < ? php echo esc_attr ( $count_hide ); ?> ;
document . addEventListener ( " DOMContentLoaded " , function ( event ) {
var $adminBarUpdates = document . querySelector ( '#wp-admin-bar-updates .ab-label' ),
2020-03-27 15:13:11 +00:00
itemCount ;
2018-12-19 17:01:08 +07:00
2020-04-16 19:59:35 +02:00
if ( typeof ( $adminBarUpdates ) !== 'undefined' && $adminBarUpdates !== null ) {
2020-03-27 15:13:11 +00:00
itemCount = $adminBarUpdates . textContent ;
2020-04-16 19:59:35 +02:00
itemCount = parseInt ( itemCount );
2018-12-19 17:01:08 +07:00
2020-03-27 15:13:11 +00:00
itemCount -= mainwpCountHide ;
2020-04-16 19:59:35 +02:00
if ( itemCount < 0 )
2020-03-27 15:13:11 +00:00
itemCount = 0 ;
2018-12-19 17:01:08 +07:00
2020-03-27 15:13:11 +00:00
$adminBarUpdates . textContent = itemCount ;
}
2020-04-16 19:59:35 +02:00
} );
2020-03-26 14:05:04 +00:00
</ script >
2020-03-27 15:13:11 +00:00
< ? php
}
2018-12-19 17:01:08 +07:00
2020-03-27 15:13:11 +00:00
public function in_admin_footer () {
2020-04-16 19:59:35 +02:00
$hide_slugs = apply_filters ( 'mainwp_child_hide_update_notice' , array () );
2018-12-19 17:01:08 +07:00
2020-04-16 19:59:35 +02:00
if ( ! is_array ( $hide_slugs ) ) {
2020-03-27 15:13:11 +00:00
$hide_slugs = array ();
}
2018-12-19 17:01:08 +07:00
2020-03-27 15:13:11 +00:00
$count_hide = 0 ;
2018-12-19 17:01:08 +07:00
2020-03-27 15:13:11 +00:00
$updates = get_plugin_updates ();
2020-04-16 20:10:19 +02:00
if ( is_array ( $updates ) ) {
2020-03-27 15:13:11 +00:00
foreach ( $updates as $slug => $data ) {
2020-04-16 19:59:35 +02:00
if ( in_array ( $slug , $hide_slugs ) ) {
2020-03-27 15:13:11 +00:00
$count_hide ++ ;
}
}
}
2018-12-19 17:01:08 +07:00
2020-04-16 19:59:35 +02:00
if ( 0 == $count_hide ) {
2020-03-27 15:13:11 +00:00
return ;
}
2018-12-19 17:01:08 +07:00
2020-03-27 15:13:11 +00:00
?>
< script type = " text/javascript " >
2020-04-16 19:59:35 +02:00
var mainwpCountHide = < ? php echo esc_attr ( $count_hide ); ?> ;
document . addEventListener ( " DOMContentLoaded " , function ( event ) {
if ( typeof ( pagenow ) !== 'undefined' && pagenow == 'plugins' ) {
2020-03-27 15:13:11 +00:00
< ? php
2020-04-16 19:59:35 +02:00
// hide update notice row.
if ( in_array ( 'mainwp-child/mainwp-child.php' , $hide_slugs ) ) {
2020-03-27 15:13:11 +00:00
?>
2020-04-16 19:59:35 +02:00
var el = document . querySelector ( 'tr#mainwp-child-update' );
if ( typeof ( el ) !== 'undefined' && el !== null ) {
2020-03-27 15:13:11 +00:00
el . style . display = 'none' ;
}
< ? php
}
2020-04-16 19:59:35 +02:00
// hide update notice row.
if ( in_array ( 'mainwp-child-reports/mainwp-child-reports.php' , $hide_slugs ) ) {
2020-03-27 15:13:11 +00:00
?>
2020-04-16 19:59:35 +02:00
var el = document . querySelector ( 'tr#mainwp-child-reports-update' );
if ( typeof ( el ) !== 'undefined' && el !== null ) {
2020-03-27 15:13:11 +00:00
el . style . display = 'none' ;
}
< ? php
}
?>
}
2020-04-16 19:59:35 +02:00
if ( mainwpCountHide > 0 ) {
2020-03-27 15:13:11 +00:00
jQuery ( document ) . ready ( function () {
2020-04-16 19:59:35 +02:00
var $adminBarUpdates = jQuery ( '#wp-admin-bar-updates' ),
$pluginsNavMenuUpdateCount = jQuery ( 'a[href="plugins.php"] .update-plugins' ),
itemCount ;
2020-03-27 15:13:11 +00:00
itemCount = $adminBarUpdates . find ( '.ab-label' ) . text ();
itemCount -= mainwpCountHide ;
2020-04-16 19:59:35 +02:00
if ( itemCount < 0 )
2020-03-27 15:13:11 +00:00
itemCount = 0 ;
itemPCount = $pluginsNavMenuUpdateCount . find ( '.plugin-count' ) . text ();
itemPCount -= mainwpCountHide ;
2020-04-16 19:59:35 +02:00
if ( itemPCount < 0 )
2020-03-27 15:13:11 +00:00
itemPCount = 0 ;
2020-04-16 19:59:35 +02:00
$adminBarUpdates . find ( '.ab-label' ) . text ( itemCount );
2020-03-27 15:13:11 +00:00
$pluginsNavMenuUpdateCount . find ( '.plugin-count' ) . text ( itemPCount );
2020-04-16 19:59:35 +02:00
} );
2020-03-27 15:13:11 +00:00
}
2020-04-16 19:59:35 +02:00
} );
2020-03-26 14:05:04 +00:00
</ script >
2020-03-27 15:13:11 +00:00
< ? php
}
2018-12-19 17:01:08 +07:00
2015-10-15 22:52:37 +10:00
public function branding_map_meta_cap ( $caps , $cap , $user_id , $args ) {
2020-04-16 19:59:35 +02:00
if ( isset ( $this -> child_branding_options [ 'disable_switching_theme' ] ) && 'T' === $this -> child_branding_options [ 'disable_switching_theme' ] ) {
2016-02-15 22:08:39 +01:00
if ( 'switch_themes' === $cap ) {
$caps [ 0 ] = 'do_not_allow' ;
}
}
2015-10-15 22:52:37 +10:00
return $caps ;
}
2019-02-14 22:38:14 +07:00
public function modify_plugin_header ( $plugins ) {
2020-03-27 15:13:11 +00:00
$opts = $this -> child_branding_options ;
2020-04-16 19:59:35 +02:00
if ( is_array ( $opts ) ) {
2020-03-27 15:13:11 +00:00
$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 $plugins ;
}
2020-04-16 19:59:35 +02:00
if ( 'T' === $is_hide ) {
2020-03-27 15:13:11 +00:00
foreach ( $plugins as $key => $value ) {
$plugin_slug = basename ( $key , '.php' );
if ( 'mainwp-child' === $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 ;
2015-10-15 22:52:37 +10:00
}
2020-04-16 19:59:35 +02:00
public function hide_update_notice ( $slugs ) {
2020-03-27 15:13:11 +00:00
$slugs [] = 'mainwp-child/mainwp-child.php' ;
return $slugs ;
}
2018-12-19 17:01:08 +07:00
2020-04-16 19:59:35 +02:00
public function remove_update_nag ( $value ) {
2020-03-27 15:13:11 +00:00
if ( isset ( $_POST [ 'mainwpsignature' ] ) ) {
2018-12-19 17:01:08 +07:00
return $value ;
}
2020-03-27 15:13:11 +00:00
if ( ! MainWP_Helper :: is_screen_with_update () ) {
return $value ;
}
2018-12-19 17:01:08 +07:00
if ( isset ( $value -> response [ 'mainwp-child/mainwp-child.php' ] ) ) {
unset ( $value -> response [ 'mainwp-child/mainwp-child.php' ] );
}
return $value ;
}
2017-01-18 22:33:53 +01:00
2019-02-14 22:38:14 +07:00
public function update_plugin_header ( $plugins , $header ) {
2015-10-15 22:52:37 +10:00
$plugin_key = '' ;
foreach ( $plugins as $key => $value ) {
$plugin_slug = basename ( $key , '.php' );
if ( 'mainwp-child' === $plugin_slug ) {
$plugin_key = $key ;
$plugin_data = $value ;
}
}
if ( ! empty ( $plugin_key ) ) {
$plugin_data [ 'Name' ] = stripslashes ( $header [ 'name' ] );
$plugin_data [ 'Description' ] = stripslashes ( $header [ 'description' ] );
$plugin_data [ 'Author' ] = stripslashes ( $header [ 'author' ] );
$plugin_data [ 'AuthorURI' ] = stripslashes ( $header [ 'authoruri' ] );
if ( ! empty ( $header [ 'pluginuri' ] ) ) {
$plugin_data [ 'PluginURI' ] = stripslashes ( $header [ 'pluginuri' ] );
}
$plugins [ $plugin_key ] = $plugin_data ;
}
return $plugins ;
}
}