| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace PXLBSAdminify\Inc\Classes; | |
| 3 | +namespace WPAdminify\Inc\Classes; | |
| 4 | 4 | |
| 5 | -use PXLBSAdminify\Inc\Utils; | |
| 6 | -use PXLBSAdminify\Inc\Admin\AdminSettings; | |
| 7 | -use PXLBSAdminify\Inc\Admin\AdminSettingsModel; | |
| 5 | +use WPAdminify\Inc\Utils; | |
| 6 | +use WPAdminify\Inc\Admin\AdminSettings; | |
| 7 | +use WPAdminify\Inc\Admin\AdminSettingsModel; | |
| 8 | 8 | |
| 9 | 9 | // no direct access allowed |
| 10 | 10 | if (!defined('ABSPATH')) { |
| 11 | 11 | exit; |
| @@ -19,631 +19,657 @@ | ||
| 19 | 19 | class Tweaks extends AdminSettingsModel |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | 22 | public $redirect_status = 301; |
| 23 | - private $performance; | |
| 24 | - private $security_head; | |
| 25 | - private $security_feed; | |
| 26 | - private $security_rest_api; | |
| 27 | - private $security_posts; | |
| 28 | - private $security_media; | |
| 29 | - private $custom_gravatar; | |
| 30 | 23 | |
| 31 | 24 | public function __construct() |
| 32 | 25 | { |
| 33 | - $this->options = (array) AdminSettings::get_instance()->get(); | |
| 34 | - $this->performance = $this->options['performance']; | |
| 35 | - $this->security_head = $this->options['security_head']; | |
| 36 | - $this->security_feed = $this->options['security_feed']; | |
| 37 | - $this->security_rest_api = $this->options['security_rest_api']; | |
| 38 | - $this->security_posts = $this->options['post_archives']; | |
| 39 | - $this->security_media = $this->options['media_attachments']; | |
| 40 | - $this->custom_gravatar = $this->options['custom_gravatar']; | |
| 26 | + $this->options = (array) AdminSettings::get_instance()->get(); | |
| 27 | + $this->tweaks_init(); | |
| 28 | + $this->jltwp_adminify_cleanup(); | |
| 29 | + $this->http_response_cleanup(); | |
| 30 | + $this->wp_json_api_cleanup(); | |
| 31 | + $this->comments_cleanup(); | |
| 32 | + $this->archives_cleanup(); | |
| 33 | + $this->attachments_cleanup(); | |
| 34 | + $this->performance_cleanup(); | |
| 35 | + $this->remove_try_gutenberg_panel(); | |
| 36 | + $this->jltwp_adminify_customize_admin_bar(); | |
| 41 | 37 | |
| 38 | + add_action('wp_dashboard_setup', [$this, 'remove_welcome_panel'], 999); | |
| 39 | + } | |
| 42 | 40 | |
| 43 | - | |
| 44 | - if (!empty($this->security_head['enable_security_head'])) { | |
| 45 | - $this->security_head(); | |
| 41 | + public function tweaks_init() | |
| 42 | + { | |
| 43 | + /* Disable Self Pings */ | |
| 44 | + if (!empty($this->options['self_ping'])) { | |
| 45 | + add_action('pre_ping', [$this, 'jltwp_adminify_no_self_ping']); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - $this->security_feed(); | |
| 49 | - | |
| 50 | - if (!empty($this->security_rest_api['security_rest_api_enable'])) { | |
| 51 | - $this->security_rest_api(); | |
| 48 | + /** Remove Dashicons from Admin Bar for non logged in users */ | |
| 49 | + if (!empty($this->options['remove_dashicons'])) { | |
| 50 | + add_action('wp_print_styles', [$this, 'jltwp_adminify_remove_dashicons'], 100); | |
| 52 | 51 | } |
| 53 | 52 | |
| 54 | - if (!empty($this->security_posts['post_archives_enable'])) { | |
| 55 | - $this->security_post_archives(); | |
| 56 | - } | |
| 53 | + /** Disable REST API */ | |
| 54 | + if (!empty($this->options['disable_rest_api'])) { | |
| 57 | 55 | |
| 58 | - $this->security_attachments(); | |
| 56 | + $this->disable_all_api(); | |
| 59 | 57 | |
| 60 | - if(!empty($this->performance['performance_enable'])){ | |
| 61 | - $this->performances(); | |
| 62 | - } | |
| 58 | + // Filters for WP-API version 1.x | |
| 59 | + add_filter('json_enabled', '__return_false'); | |
| 60 | + add_filter('json_jsonp_enabled', '__return_false'); | |
| 63 | 61 | |
| 64 | - // Add Custom Default Gravatar Image | |
| 65 | - if (!empty($this->custom_gravatar) && array_key_exists('enable', $this->custom_gravatar)) { | |
| 66 | - // Add Custom Default Gravatar Image | |
| 67 | - add_filter('avatar_defaults', [$this, 'add_custom_gravatar_image'], 99); | |
| 62 | + // Filters for WP-API version 2.x | |
| 63 | + // add_filter('rest_enabled', '__return_false'); | |
| 64 | + add_filter('rest_jsonp_enabled', '__return_false'); | |
| 68 | 65 | } |
| 69 | 66 | |
| 70 | - // If Admin bar Editor Plugin not Installed | |
| 71 | - if (! class_exists('\JewelTheme\AdminBarEditor\AdminBarEditor')) { | |
| 72 | - if (!empty($this->options['white_label']['wordpress']['remove_howdy_msg']) || !empty($this->options['white_label']['wordpress']['change_howdy_text'])) { | |
| 73 | - // Change Howdy Text | |
| 74 | - // add_action('admin_bar_menu', [$this, 'remove_from_admin_bar'], 999); | |
| 75 | - // add_action('admin_bar_menu', [$this, 'clear_node_title'], 999); | |
| 76 | - add_filter('admin_bar_menu', [$this, 'change_howdy_text'], 9999); | |
| 77 | - } | |
| 67 | + /** Control Interval Heartbeat API */ | |
| 68 | + if (!empty($this->options['control_heartbeat_api'])) { | |
| 69 | + add_filter('heartbeat_settings', [$this, 'jltwp_adminify_control_heartbeat']); | |
| 78 | 70 | } |
| 79 | 71 | |
| 80 | - | |
| 81 | - // Remove Admin Bar Logo | |
| 82 | - if(!empty($this->options['white_label']['wordpress']['admin_bar_cleanup'])){ | |
| 83 | - add_action("wp_before_admin_bar_render", [$this, "admin_bar_cleanup"], 0); | |
| 72 | + /** Remove Version Query Strings from Scripts/Styles */ | |
| 73 | + if (!empty($this->options['remove_version_strings'])) { | |
| 74 | + add_filter('script_loader_src', [$this, 'jltwp_adminify_remove_script_version'], 15, 1); | |
| 75 | + add_filter('style_loader_src', [$this, 'jltwp_adminify_remove_script_version'], 15, 1); | |
| 84 | 76 | } |
| 85 | 77 | |
| 86 | - } | |
| 87 | - | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * Security: Post & Archives | |
| 91 | - * | |
| 92 | - * @return void | |
| 93 | - */ | |
| 94 | - public function security_post_archives(){ | |
| 95 | - $post_archives_data = $this->security_posts['post_archives_data']; | |
| 96 | - | |
| 97 | - // tag and category hooks | |
| 98 | - if (!empty($post_archives_data) && in_array('last_modified_date', $post_archives_data)) { | |
| 99 | - add_filter('the_content', [$this, 'last_updated_date'], 10, 1); | |
| 100 | - add_filter('wp_head', [$this, 'last_updated_date_style']); | |
| 78 | + /** Remove Version Query Strings from Scripts/Styles */ | |
| 79 | + if (!empty($this->options['remove_canonical'])) { | |
| 80 | + remove_action('embed_head', 'rel_canonical'); | |
| 81 | + add_filter('wpseo_canonical', '__return_false'); | |
| 101 | 82 | } |
| 102 | 83 | |
| 103 | 84 | /** Remove Capital P Dangit */ |
| 104 | - if (!empty($post_archives_data) && in_array('capital_p_dangit', $post_archives_data)) { | |
| 85 | + if (!empty($this->options['remove_capital_p_dangit'])) { | |
| 105 | 86 | remove_filter('the_title', 'capital_P_dangit', 11); |
| 106 | 87 | remove_filter('the_content', 'capital_P_dangit', 11); |
| 107 | 88 | remove_filter('comment_text', 'capital_P_dangit', 31); |
| 108 | 89 | } |
| 109 | 90 | |
| 110 | - // Remove date archives | |
| 111 | - if (!empty($post_archives_data) && ( | |
| 112 | - in_array('archives_date', $post_archives_data) || | |
| 113 | - in_array('archives_author', $post_archives_data) || | |
| 114 | - in_array('archives_tag', $post_archives_data) || | |
| 115 | - in_array('archives_category', $post_archives_data) || | |
| 116 | - in_array('archives_postformat', $post_archives_data) || | |
| 117 | - in_array('archives_search', $post_archives_data) | |
| 118 | - )) { | |
| 119 | - add_action('template_redirect', [$this, 'redirect_to_home']); | |
| 91 | + /** Disable PDF Thumbnails Preview */ | |
| 92 | + if (!empty($this->options['disable_pdf_thumbnail'])) { | |
| 93 | + add_filter('fallback_intermediate_image_sizes', [$this, 'jltwp_adminify_disable_pdf_previews']); | |
| 120 | 94 | } |
| 121 | 95 | |
| 122 | - // // Remove Author archives | |
| 123 | - // if (!empty($post_archives_data) && in_array('archives_author', $post_archives_data)) { | |
| 124 | - // if (is_author()) { | |
| 125 | - // add_action('template_redirect', [$this, 'redirect']); | |
| 126 | - // } | |
| 127 | - // } | |
| 96 | + /** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer */ | |
| 97 | + if (!empty($this->options['defer_parsing_js_footer'])) { | |
| 98 | + add_filter('script_loader_tag', [$this, 'jltwp_adminify_defer_parsing_of_js'], 10, 2); | |
| 99 | + } | |
| 128 | 100 | |
| 101 | + /* Remove Gravatar Query Strings */ | |
| 102 | + if (!empty($this->options['gravatar_query_strings'])) { | |
| 103 | + add_filter('get_avatar_url', [$this, 'jltwp_adminify_avatar_remove_querystring']); | |
| 104 | + } | |
| 129 | 105 | |
| 130 | - // // Remove tag archives | |
| 131 | - // if (!empty($post_archives_data) && in_array('archives_tag', $post_archives_data)) { | |
| 132 | - // if (is_tag()) { | |
| 133 | - // add_action('template_redirect', [$this, 'redirect']); | |
| 134 | - // } | |
| 135 | - // } | |
| 106 | + // Add Custom Default Gravatar Image | |
| 107 | + if (!empty($this->options['enable_custom_gravatar'])) { | |
| 108 | + add_filter('avatar_defaults', [$this, 'jltwp_adminify_add_custom_gravatar']); | |
| 109 | + } | |
| 136 | 110 | |
| 137 | - // // Remove category archives | |
| 138 | - // if (!empty($post_archives_data) && in_array('archives_category', $post_archives_data)) { | |
| 139 | - // if (is_category()) { | |
| 140 | - // add_action('template_redirect', [$this, 'redirect']); | |
| 141 | - // } | |
| 142 | - // } | |
| 111 | + /* Add Featured Image or Post Thumbnail to RSS Feed */ | |
| 112 | + if (!empty($this->options['thumbnails_rss_feed'])) { | |
| 113 | + add_filter('the_excerpt_rss', [$this, 'jltwp_adminify_rss_post_thumbnail']); | |
| 114 | + add_filter('the_content_feed', [$this, 'jltwp_adminify_rss_post_thumbnail']); | |
| 115 | + } | |
| 143 | 116 | |
| 144 | - // // Remove archives post formats | |
| 145 | - // if (!empty($post_archives_data) && in_array('archives_postformat', $post_archives_data)) { | |
| 146 | - // if (is_tax('post_format')) { | |
| 147 | - // add_action('template_redirect', [$this, 'redirect']); | |
| 148 | - // } | |
| 149 | - // } | |
| 117 | + // tag and category hooks | |
| 118 | + if (!empty($this->options['display_last_modified_date'])) { | |
| 119 | + add_filter('the_content', [$this, 'jltwp_adminify_last_updated_date'], 10, 1); | |
| 120 | + add_filter('wp_head', [$this, 'jltwp_adminify_last_updated_date_style']); | |
| 121 | + } | |
| 150 | 122 | |
| 151 | - // // Remove search page | |
| 152 | - // if (!empty($post_archives_data) && in_array('archives_search', $post_archives_data)) { | |
| 153 | - // if (is_search()) { | |
| 154 | - // add_action('template_redirect', [$this, 'redirect']); | |
| 155 | - // } | |
| 156 | - // } | |
| 123 | + if (!empty($this->options['remove_image_link'])) { | |
| 124 | + add_action('admin_init', [$this, 'jltwp_adminify_imagelink'], 10); | |
| 125 | + } | |
| 157 | 126 | |
| 127 | + /** Browser Cache Expires & GZIP Compression */ | |
| 128 | + if (!empty($this->options['cache_gzip_compression'])) { | |
| 129 | + register_activation_hook(__FILE__, [$this, 'jltwp_adminify_htaccess']); | |
| 130 | + } | |
| 131 | + /** | |
| 132 | + * We run the function that ckecks here | |
| 133 | + * if there are $lineas content between: | |
| 134 | + * # BEGIN WP Adminify by Jewel Theme | |
| 135 | + * and... | |
| 136 | + * # END WP Adminify by Jewel Theme | |
| 137 | + * If exist and it's the same we don't do anything, | |
| 138 | + * if has changed, we update it to the new one | |
| 139 | + * if it doesn't exist we write it. | |
| 140 | + */ | |
| 141 | + register_deactivation_hook(__FILE__, [$this, 'jltwp_adminify_delete_tweaks_htaccess']); | |
| 158 | 142 | } |
| 159 | 143 | |
| 160 | - public function url_redirection(){ | |
| 161 | - global $wp_query; | |
| 162 | - $wp_query->set_404(); | |
| 163 | - wp_safe_redirect(esc_url(home_url()), 301); | |
| 164 | - exit; | |
| 144 | + | |
| 145 | + // Remove Items from Admin bar | |
| 146 | + public function jltwp_adminify_customize_admin_bar() | |
| 147 | + { | |
| 148 | + // add_action('admin_bar_menu', [$this, 'remove_from_admin_bar'], 999); | |
| 149 | + // add_action('admin_bar_menu', [$this, 'clear_node_title'], 999); | |
| 150 | + add_filter('admin_bar_menu', [$this, 'jltma_adminify_change_howdy_text'], 25); | |
| 165 | 151 | } |
| 166 | 152 | |
| 167 | - public function redirect_to_home(){ | |
| 168 | - $post_archives_data = $this->security_posts['post_archives_data']; | |
| 153 | + /* | |
| 154 | + * Change Howdy Text | |
| 155 | + */ | |
| 156 | + public function jltma_adminify_change_howdy_text($wp_admin_bar) | |
| 157 | + { | |
| 158 | + $admin_bar_howdy_text = !empty($this->options['admin_bar_settings']['admin_bar_howdy_text']) ? $this->options['admin_bar_settings']['admin_bar_howdy_text'] : ''; | |
| 159 | + if (!empty($admin_bar_howdy_text)) { | |
| 160 | + $my_account = $wp_admin_bar->get_node('my-account'); | |
| 161 | + $changed_howdy_text = str_replace('Howdy,', wp_kses_post($admin_bar_howdy_text), $my_account->title); | |
| 162 | + $wp_admin_bar->add_node( | |
| 163 | + [ | |
| 164 | + 'id' => 'my-account', | |
| 165 | + 'title' => wp_kses_post($changed_howdy_text), | |
| 166 | + ] | |
| 167 | + ); | |
| 168 | + } | |
| 169 | + } | |
| 169 | 170 | |
| 170 | - // Remove Author archives | |
| 171 | - if (!empty($post_archives_data) && in_array('archives_author', $post_archives_data)) { | |
| 172 | - if (is_author()) { | |
| 173 | - $this->url_redirection(); | |
| 174 | - } | |
| 175 | - } | |
| 176 | 171 | |
| 177 | 172 | |
| 178 | - // Remove tag archives | |
| 179 | - if (!empty($post_archives_data) && in_array('archives_tag', $post_archives_data)) { | |
| 180 | - if (is_tag()) { | |
| 181 | - $this->url_redirection(); | |
| 182 | - } | |
| 183 | - } | |
| 173 | + // Clear the node titles | |
| 174 | + // This will only work if the node is using a :before element for the icon | |
| 175 | + public function clear_node_title($wp_admin_bar) | |
| 176 | + { | |
| 177 | + $all_toolbar_nodes = $wp_admin_bar->get_nodes(); | |
| 178 | + // Create an array of node ID's we'd like to remove | |
| 179 | + $clear_titles = [ | |
| 180 | + 'site-name', | |
| 181 | + 'customize', | |
| 182 | + ]; | |
| 184 | 183 | |
| 185 | - // Remove category archives | |
| 186 | - if (!empty($post_archives_data) && in_array('archives_category', $post_archives_data)) { | |
| 187 | - if (is_category()) { | |
| 188 | - $this->url_redirection(); | |
| 189 | - } | |
| 190 | - } | |
| 184 | + foreach ($all_toolbar_nodes as $node) { | |
| 191 | 185 | |
| 192 | - // Remove archives post formats | |
| 193 | - if (!empty($post_archives_data) && in_array('archives_postformat', $post_archives_data)) { | |
| 194 | - if (is_tax('post_format')) { | |
| 195 | - $this->url_redirection(); | |
| 196 | - } | |
| 197 | - } | |
| 186 | + // Run an if check to see if a node is in the array to clear_titles | |
| 187 | + if (in_array($node->id, $clear_titles)) { | |
| 188 | + // use the same node's properties | |
| 189 | + $args = $node; | |
| 198 | 190 | |
| 199 | - // Remove search page | |
| 200 | - if (!empty($post_archives_data) && in_array('archives_search', $post_archives_data)) { | |
| 201 | - if (is_search()) { | |
| 202 | - $this->url_redirection(); | |
| 191 | + // make the node title a blank string | |
| 192 | + $args->title = ''; | |
| 193 | + | |
| 194 | + // update the Toolbar node | |
| 195 | + $wp_admin_bar->add_node($args); | |
| 203 | 196 | } |
| 204 | 197 | } |
| 205 | 198 | } |
| 206 | 199 | |
| 200 | + // Remove items from the admin bar | |
| 201 | + public function remove_from_admin_bar($wp_admin_bar) | |
| 202 | + { | |
| 203 | + /* | |
| 204 | + * Placing items in here will only remove them from admin bar | |
| 205 | + * when viewing the fronte end of the site | |
| 206 | + */ | |
| 207 | + if (!is_admin()) { | |
| 208 | + // Example of removing item generated by plugin. Full ID is #wp-admin-bar-si_menu | |
| 209 | + $wp_admin_bar->remove_node('si_menu'); | |
| 207 | 210 | |
| 208 | - /** | |
| 209 | - * Security: Attachments | |
| 210 | - * | |
| 211 | - * @return void | |
| 212 | - */ | |
| 213 | - public function security_attachments(){ | |
| 214 | - | |
| 215 | - // Add Featured Image or Post Thumbnail to RSS Feed | |
| 216 | - if (!empty($this->security_media['thumbnails_rss_feed'])) { | |
| 217 | - add_filter('the_excerpt_rss', [$this, 'rss_post_thumbnail']); | |
| 218 | - add_filter('the_content_feed', [$this, 'rss_post_thumbnail']); | |
| 211 | + // WordPress Core Items (uncomment to remove) | |
| 212 | + $wp_admin_bar->remove_node('updates'); | |
| 213 | + $wp_admin_bar->remove_node('comments'); | |
| 214 | + $wp_admin_bar->remove_node('new-content'); | |
| 215 | + // $wp_admin_bar->remove_node('wp-logo'); | |
| 216 | + // $wp_admin_bar->remove_node('site-name'); | |
| 217 | + // $wp_admin_bar->remove_node('my-account'); | |
| 218 | + // $wp_admin_bar->remove_node('search'); | |
| 219 | + // $wp_admin_bar->remove_node('customize'); | |
| 219 | 220 | } |
| 220 | 221 | |
| 222 | + /* | |
| 223 | + * Items placed outside the if statement will remove it from both the frontend | |
| 224 | + * and backend of the site | |
| 225 | + */ | |
| 226 | + $wp_admin_bar->remove_node('wp-logo'); | |
| 221 | 227 | } |
| 222 | 228 | |
| 229 | + | |
| 223 | 230 | /** |
| 224 | - * Disable REST API | |
| 225 | - * | |
| 226 | - * @return void | |
| 231 | + * Remove Welcome Panel | |
| 227 | 232 | */ |
| 228 | - public function security_rest_api(){ | |
| 229 | - $this->security_rest_api = $this->security_rest_api['security_rest_api_data']; | |
| 230 | - | |
| 231 | - /** Disable REST API */ | |
| 232 | - if (!empty($this->security_rest_api) && in_array('rest_api', $this->security_rest_api)) { | |
| 233 | - | |
| 234 | - // All REST API Hooks | |
| 235 | - if (version_compare(get_bloginfo('version'), '4.7', '>=')) { | |
| 236 | - add_filter('rest_authentication_errors', [$this, 'disable_rest_api']); | |
| 237 | - } else { | |
| 238 | - // Filters for WP-API version 1.x | |
| 239 | - add_filter('json_enabled', '__return_false'); | |
| 240 | - add_filter('json_jsonp_enabled', '__return_false'); | |
| 241 | - | |
| 242 | - // Filters for WP-API version 2.x | |
| 243 | - add_filter('rest_enabled', '__return_false'); | |
| 244 | - add_filter('rest_jsonp_enabled', '__return_false'); | |
| 245 | - } | |
| 246 | - | |
| 247 | - remove_action('wp_head', 'rest_output_link_wp_head', 10); // Disable REST API links in the HTML <head> tag | |
| 248 | - remove_action('wp_head', 'wp_oembed_add_discovery_links'); // Remove oEmbed discovery links. | |
| 249 | - remove_action('template_redirect', 'rest_output_link_header', 11, 0); // Disable the REST API link in HTTP headers. | |
| 250 | - remove_action('xmlrpc_rsd_apis', 'rest_output_rsd'); // Remove the REST API URL from the WordPress RSD endpoint. | |
| 233 | + public function remove_welcome_panel() | |
| 234 | + { | |
| 235 | + if (!empty($this->options['remove_welcome_panel'])) { | |
| 236 | + remove_action('welcome_panel', 'wp_welcome_panel'); | |
| 251 | 237 | } |
| 238 | + } | |
| 252 | 239 | |
| 253 | 240 | |
| 254 | - // Remove X-Powered-By | |
| 255 | - if (!empty($this->security_rest_api) && in_array('powered', $this->security_rest_api)) { | |
| 256 | - // add_action('wp', [$this, 'remove_powered']); // OLD way | |
| 257 | - | |
| 258 | - // Hook into 'send_headers' to remove the "X-Powered-By" header | |
| 259 | - add_action('send_headers', [$this, 'remove_powered']); | |
| 241 | + /** | |
| 242 | + * Remove "Try Gutenberg Panel" | |
| 243 | + */ | |
| 244 | + public function remove_try_gutenberg_panel() | |
| 245 | + { | |
| 246 | + if (!empty($this->options['remove_try_gutenberg_panel'])) { | |
| 247 | + remove_action('try_gutenberg_panel', 'wp_try_gutenberg_panel'); | |
| 260 | 248 | } |
| 261 | 249 | } |
| 262 | 250 | |
| 263 | 251 | |
| 264 | - public function disable_rest_api(){ | |
| 265 | - if (!is_user_logged_in()) { | |
| 266 | - return new \WP_Error( | |
| 267 | - 'rest_api_authentication_required', | |
| 268 | - __('The REST API has been restricted to authenticated users.', 'adminify'), | |
| 269 | - [ | |
| 270 | - 'status' => rest_authorization_required_code() | |
| 271 | - ] | |
| 272 | - ); | |
| 252 | + // Custom Avatars | |
| 253 | + public function jltwp_adminify_add_custom_gravatar($avatar_defaults) | |
| 254 | + { | |
| 255 | + if (!empty($this->options['custom_gravatar_image'])) { | |
| 256 | + foreach ($this->options['custom_gravatar_image'] as $key => $value) { | |
| 257 | + $avatar_url = esc_url_raw($value['avatar_image']['url']); | |
| 258 | + $avatar_defaults[$avatar_url] = $value['avatar_name']; | |
| 259 | + } | |
| 273 | 260 | } |
| 261 | + return $avatar_defaults; | |
| 274 | 262 | } |
| 275 | 263 | |
| 276 | 264 | |
| 277 | - /** | |
| 278 | - * Security Head | |
| 279 | - * | |
| 280 | - * @return void | |
| 281 | - */ | |
| 282 | - public function security_head(){ | |
| 265 | + // Cleanup Hooks | |
| 266 | + public function jltwp_adminify_cleanup() | |
| 267 | + { | |
| 283 | 268 | |
| 284 | - $this->security_head = $this->security_head['security_head_data']; | |
| 269 | + // Hide Admin bar | |
| 270 | + if (!empty($this->options['show_admin_bar'])) { | |
| 271 | + add_filter('show_admin_bar', '__return_false'); | |
| 272 | + } | |
| 285 | 273 | |
| 286 | - // Disable XML-RPC | |
| 287 | - if (!empty($this->security_head) && in_array('xmlrpc', $this->security_head)) { | |
| 288 | - // add_filter('xmlrpc_enabled', '__return_false'); | |
| 289 | - add_filter('wp_xmlrpc_server_class', [$this, 'adminify_disable_wp_xmlrpc']); | |
| 274 | + // Remove Admin Footer Version Number | |
| 275 | + if (!empty($this->options['admin_footer_default_wp_version'])) { | |
| 276 | + add_action('admin_menu', [$this, 'remove_admin_footer_version']); | |
| 290 | 277 | } |
| 291 | 278 | |
| 292 | 279 | // Remove WordPress Version Number |
| 293 | - if (!empty($this->security_head) && in_array('generator_wp_version', $this->security_head)) { | |
| 280 | + if (!empty($this->options['generator_wp_version'])) { | |
| 294 | 281 | remove_action('wp_head', 'wp_generator'); // Remove WordPress Generator Version |
| 295 | 282 | add_filter('the_generator', '__return_false'); // Remove Generator Name From Rss Feeds. |
| 296 | 283 | } |
| 297 | 284 | |
| 298 | 285 | // Remove Revolution Slider generator version |
| 299 | - if (!empty($this->security_head) && in_array('revslider_generator', $this->security_head)) { | |
| 286 | + if (!empty($this->options['remove_revslider_generator'])) { | |
| 300 | 287 | add_filter('revslider_meta_generator', '__return_empty_string'); |
| 301 | 288 | } |
| 302 | 289 | |
| 303 | 290 | // Remove woocommerce generator version |
| 304 | - if (!empty($this->security_head) && in_array('wc_generator', $this->security_head)) { | |
| 291 | + if (!empty($this->options['remove_wc_generator'])) { | |
| 305 | 292 | remove_action('wp_head', 'wc_generator_tag'); |
| 306 | 293 | } |
| 307 | 294 | |
| 308 | 295 | // Remove wpml meta generator tag |
| 309 | - if (!empty($this->security_head) && in_array('wpml_generator', $this->security_head)) { | |
| 310 | - add_action('wp_head', [$this, 'remove_wpml_generator'], 0); | |
| 296 | + if (!empty($this->options['remove_wpml_generator'])) { | |
| 297 | + add_action('wp_head', [$this, '_remove_wpml_generator'], 0); | |
| 311 | 298 | } |
| 312 | 299 | |
| 313 | 300 | // Remove wpbakery visual_composer meta generator tag |
| 314 | - if (!empty($this->security_head) && in_array('js_composer_generator', $this->security_head)) { | |
| 315 | - if (class_exists('Vc_Manager')) { | |
| 316 | - remove_action('wp_head', [visual_composer(), 'addMetaData'], 1); | |
| 317 | - } | |
| 301 | + if (!empty($this->options['remove_visual_composer_generator'])) { | |
| 302 | + add_action('wp_head', [$this, 'jltwp_adminify_remove_visual_composer_generator'], 1); | |
| 318 | 303 | } |
| 319 | 304 | |
| 320 | 305 | // Remove Yoast SEO meta generator tag |
| 321 | - if (!empty($this->security_head) && in_array('yoast_generator', $this->security_head)) { | |
| 306 | + if (!empty($this->options['remove_yoast_generator'])) { | |
| 322 | 307 | add_filter('wpseo_debug_markers', '__return_false'); |
| 323 | 308 | } |
| 324 | 309 | |
| 310 | + // Remove WordPress.org Dns-prefetch. | |
| 311 | + if (!empty($this->options['remove_dns_prefetch'])) { | |
| 312 | + remove_action('wp_head', 'wp_resource_hints', 2); | |
| 313 | + } | |
| 314 | + | |
| 325 | 315 | // REMOVE wlwmanifest.xml. |
| 326 | - if (!empty($this->security_head) && in_array('wlwmanifest', $this->security_head)) { | |
| 316 | + if (!empty($this->options['remove_wlwmanifest'])) { | |
| 327 | 317 | remove_action('wp_head', 'wlwmanifest_link'); |
| 328 | 318 | } |
| 329 | 319 | |
| 330 | 320 | // Remove Really Simple Discovery Link. |
| 331 | - if (!empty($this->security_head) && in_array('rsd', $this->security_head)) { | |
| 321 | + if (!empty($this->options['remove_rsd'])) { | |
| 332 | 322 | remove_action('wp_head', 'rsd_link'); |
| 333 | 323 | } |
| 334 | 324 | |
| 335 | 325 | // Remove Shortlink Url |
| 336 | - if (!empty($this->security_head) && in_array('shortlink', $this->security_head)) { | |
| 337 | - remove_action('wp_head', 'wp_shortlink_wp_head'); | |
| 338 | - remove_action('template_redirect', 'wp_shortlink_header', 100, 0); | |
| 326 | + if (!empty($this->options['remove_shortlink'])) { | |
| 327 | + remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); | |
| 328 | + remove_action('template_redirect', 'wp_shortlink_header', 11); | |
| 339 | 329 | } |
| 340 | 330 | |
| 341 | - /** Remove Version Query Strings from Scripts/Styles */ | |
| 342 | - if (!empty($this->security_head) && in_array('canonical', $this->security_head)) { | |
| 343 | - remove_action('embed_head', 'rel_canonical'); | |
| 331 | + // Remove Emoji Styles and Scripts | |
| 332 | + if (!empty($this->options['remove_emoji'])) { | |
| 333 | + remove_action('wp_head', 'print_emoji_detection_script', 7); // Remove Emoji's Styles and Scripts. | |
| 334 | + remove_action('embeded_head', 'print_emoji_detection_script'); | |
| 335 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); // Remove Emoji's Styles and Scripts. | |
| 336 | + remove_action('wp_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts. | |
| 337 | + remove_action('admin_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts. | |
| 338 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); | |
| 339 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); | |
| 340 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); | |
| 341 | + add_filter('tiny_mce_plugins', [$this, 'disable_emojicons_tinymce']); | |
| 342 | + add_filter('emoji_svg_url', '__return_false'); | |
| 343 | + } | |
| 344 | 344 | |
| 345 | - // Function to remove the canonical URL | |
| 346 | - // | |
| 345 | + $this->remove_feed(); | |
| 346 | + $this->redirect_feed(); | |
| 347 | 347 | |
| 348 | - // Hook the function to wp_head | |
| 349 | - add_action('wp_head', [$this, 'remove_wp_canonical_url'] , 1); | |
| 350 | - // Yoast SEO Canonical URL | |
| 351 | - if (Utils::is_plugin_active('wordpress-seo/wp-seo.php')) { | |
| 352 | - add_filter('wpseo_canonical', '__return_false'); | |
| 353 | - } | |
| 348 | + // Remove Link to Home Page. | |
| 349 | + if (!empty($this->options['remove_link_url'])) { | |
| 350 | + remove_action('wp_head', 'index_rel_link'); | |
| 354 | 351 | } |
| 355 | 352 | |
| 353 | + // Remove Prev/Next Link from Head | |
| 354 | + if (!empty($this->options['remove_prev_next'])) { | |
| 355 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10); // Remove Prev-next Links From Header -not From Post-. | |
| 356 | + remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Remove Prev-next Links. | |
| 357 | + remove_action('wp_head', 'start_post_rel_link', 10, 0); // Remove Random Link Post. | |
| 358 | + remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Remove Parent Post Link. | |
| 359 | + } | |
| 356 | 360 | |
| 357 | - /* Disable Self Pings */ | |
| 358 | - if (!empty($this->security_head) && in_array('self_ping', $this->security_head)) { | |
| 359 | - add_action('pre_ping', [$this, 'disable_self_ping']); | |
| 361 | + // Remove styles for .recentcomments | |
| 362 | + if (!empty($this->options['remove_recentcomments'])) { | |
| 363 | + add_action('widgets_init', [$this, 'jltwp_adminify_remove_recent_comments_style']); | |
| 360 | 364 | } |
| 361 | 365 | |
| 366 | + // Remove styles for .recentcomments | |
| 367 | + if (!empty($this->options['disable_xmlrpc'])) { | |
| 368 | + add_action('wp_default_scripts', [$this, 'jltwp_adminify_disable_xmlrpc'], 9999); | |
| 369 | + } | |
| 362 | 370 | } |
| 363 | 371 | |
| 372 | + // Remove styles for .recentcomments | |
| 373 | + public function jltwp_adminify_remove_recent_comments_style() | |
| 374 | + { | |
| 375 | + global $wp_widget_factory; | |
| 376 | + remove_action('wp_head', [$wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style']); | |
| 377 | + } | |
| 378 | + | |
| 379 | + // Remove Visual Composer Generator | |
| 380 | + public function jltwp_adminify_remove_visual_composer_generator() | |
| 381 | + { | |
| 382 | + if (class_exists('Vc_Manager')) { | |
| 383 | + remove_action('wp_head', [visual_composer(), 'addMetaData']); | |
| 384 | + } | |
| 385 | + } | |
| 386 | + | |
| 387 | + // Remove WPML Generator | |
| 388 | + public function _remove_wpml_generator() | |
| 389 | + { | |
| 390 | + if (!empty($GLOBALS['sitepress'])) { | |
| 391 | + remove_action(current_filter(), [$GLOBALS['sitepress'], 'meta_generator_tag']); | |
| 392 | + } | |
| 393 | + } | |
| 394 | + | |
| 364 | 395 | /** |
| 365 | - * Disable XMLRPC file | |
| 396 | + * Disable XML-RPC | |
| 366 | 397 | * |
| 398 | + * @access public | |
| 399 | + * @since 1.0.0 | |
| 367 | 400 | * @return void |
| 368 | 401 | */ |
| 369 | - public function adminify_disable_wp_xmlrpc($data) | |
| 402 | + public function jltwp_adminify_disable_xmlrpc() | |
| 370 | 403 | { |
| 371 | - http_response_code(403); | |
| 404 | + add_filter('xmlrpc_enabled', '__return_false'); | |
| 372 | 405 | } |
| 373 | 406 | |
| 374 | 407 | /** |
| 375 | - * Security Feed Links | |
| 408 | + * Disable WP emojicons from TinyMCE | |
| 376 | 409 | * |
| 410 | + * @access public | |
| 411 | + * @since 1.0.0 | |
| 377 | 412 | * @return void |
| 378 | 413 | */ |
| 379 | - public function security_feed(){ | |
| 414 | + public function disable_emojicons_tinymce($plugins) | |
| 415 | + { | |
| 416 | + if (is_array($plugins)) { | |
| 417 | + return array_diff($plugins, ['wpemoji']); | |
| 418 | + } else { | |
| 419 | + return []; | |
| 420 | + } | |
| 421 | + } | |
| 380 | 422 | |
| 381 | - // Remove Feed Links | |
| 382 | - if (!empty($this->security_feed)) { | |
| 383 | - remove_action('wp_head', 'feed_links_extra', 3); // Remove Every Extra Links to Rss Feeds. | |
| 384 | - remove_action('wp_head', 'feed_links', 2); // Remove Head link <head/> | |
| 385 | - remove_action('do_feed_rdf', 'do_feed_rdf', 10, 0); | |
| 386 | - remove_action('do_feed_rss', 'do_feed_rss', 10, 0); | |
| 387 | - remove_action('do_feed_rss2', 'do_feed_rss2', 10, 1); | |
| 388 | - remove_action('do_feed_atom', 'do_feed_atom', 10, 1); | |
| 389 | 423 | |
| 390 | - // Redirect to Home | |
| 391 | - add_action('do_feed', [$this, 'redirect'], 1); | |
| 392 | - add_action('do_feed_rdf', [$this, 'redirect'], 1); | |
| 393 | - add_action('do_feed_rss', [$this, 'redirect'], 1); | |
| 394 | - add_action('do_feed_rss2', [$this, 'redirect'], 1); | |
| 395 | - add_action('do_feed_atom', [$this, 'redirect'], 1); | |
| 424 | + // HTTP Response Cleanup | |
| 425 | + public function http_response_cleanup() | |
| 426 | + { | |
| 427 | + // Remove Link rel=shortlink from http | |
| 428 | + if (!empty($this->options['remove_http_shortlink'])) { | |
| 429 | + remove_action('template_redirect', 'wp_shortlink_header', 11); | |
| 430 | + } | |
| 396 | 431 | |
| 432 | + // Remove X-Pingback | |
| 433 | + if (!empty($this->options['remove_pingback'])) { | |
| 434 | + add_filter('wp_headers', [$this, 'jltwp_adminify_remove_pingback_head']); | |
| 435 | + add_action('wp', [$this, 'jltwp_adminify_remove_pingback']); | |
| 397 | 436 | } |
| 437 | + | |
| 438 | + // Remove X-Powered-By | |
| 439 | + if (!empty($this->options['remove_powered'])) { | |
| 440 | + add_action('wp', [$this, 'jltwp_adminify_remove_powered']); | |
| 441 | + } | |
| 398 | 442 | } |
| 399 | 443 | |
| 444 | + public function jltwp_adminify_remove_powered() | |
| 445 | + { | |
| 446 | + if (function_exists('header_remove')) { | |
| 447 | + header_remove('x-powered-by'); | |
| 448 | + } | |
| 449 | + } | |
| 400 | 450 | |
| 401 | - | |
| 402 | - /* | |
| 403 | - * Change Howdy Text | |
| 404 | - */ | |
| 405 | - public function change_howdy_text($wp_admin_bar) | |
| 451 | + public function jltwp_adminify_remove_pingback_head($headers) | |
| 406 | 452 | { |
| 407 | - // Remove Howdy Message entirely | |
| 408 | - if (!empty($this->options['white_label']['wordpress']['remove_howdy_msg'])) { | |
| 453 | + if (isset($headers['X-Pingback'])) { | |
| 454 | + unset($headers['X-Pingback']); | |
| 455 | + } | |
| 409 | 456 | |
| 410 | - // Remove the entire "My Account" section and rebuild it later. | |
| 411 | - remove_action('admin_bar_menu', 'wp_admin_bar_my_account_item', 7); | |
| 457 | + return $headers; | |
| 458 | + } | |
| 412 | 459 | |
| 413 | - $current_user = wp_get_current_user(); | |
| 414 | - $user_id = get_current_user_id(); | |
| 415 | - $profile_url = get_edit_profile_url($user_id); | |
| 460 | + public function jltwp_adminify_remove_pingback() | |
| 461 | + { | |
| 462 | + if (function_exists('header_remove')) { | |
| 463 | + header_remove('X-Pingback'); | |
| 464 | + } | |
| 465 | + } | |
| 416 | 466 | |
| 417 | - $avatar = get_avatar($user_id, 26); // size 26x26 pixels | |
| 418 | - $display_name = $current_user->display_name; | |
| 419 | - $class = $avatar ? 'with-avatar' : 'no-avatar'; | |
| 420 | - $wp_admin_bar->add_menu(array( | |
| 421 | - 'id' => 'my-account', | |
| 422 | - 'parent' => 'top-secondary', | |
| 423 | - 'title' => $display_name . $avatar, | |
| 424 | - 'href' => $profile_url, | |
| 425 | - 'meta' => array( | |
| 426 | - 'class' => $class, | |
| 427 | - ), | |
| 428 | - )); | |
| 467 | + // WP JSON API Cleanup | |
| 468 | + public function wp_json_api_cleanup() | |
| 469 | + { | |
| 470 | + if (!empty($this->options['remove_api_head'])) { | |
| 471 | + $this->remove_api_head(); | |
| 429 | 472 | } |
| 430 | 473 | |
| 431 | - // Change Howdy Text | |
| 432 | - if (!empty($this->options['white_label']['wordpress']['change_howdy_text'])) { | |
| 474 | + if (!empty($this->options['remove_api_server'])) { | |
| 475 | + $this->remove_api_server(); | |
| 476 | + } | |
| 477 | + } | |
| 478 | + public function remove_api_server() | |
| 479 | + { | |
| 480 | + remove_action('template_redirect', 'rest_output_link_header', 11); | |
| 481 | + } | |
| 433 | 482 | |
| 434 | - // Get the current user information | |
| 435 | - $my_account = $wp_admin_bar->get_node('my-account'); | |
| 483 | + public function disable_json_api() | |
| 484 | + { | |
| 485 | + // Filters for WP-API version 1.x | |
| 486 | + add_filter('json_enabled', '__return_false'); | |
| 487 | + add_filter('json_jsonp_enabled', '__return_false'); | |
| 436 | 488 | |
| 437 | - if (isset($my_account->title)) { | |
| 489 | + // Filters for WP-API version 2.x | |
| 490 | + // add_filter('rest_enabled', '__return_false'); | |
| 491 | + add_filter('rest_jsonp_enabled', '__return_false'); | |
| 492 | + } | |
| 438 | 493 | |
| 439 | - // Replace the "Howdy" text with "Welcome" | |
| 440 | - $changed_howdy_text = str_replace('Howdy', Utils::kses_custom($this->options['white_label']['wordpress']['change_howdy_text']), $my_account->title); | |
| 494 | + public function disable_all_api() | |
| 495 | + { | |
| 496 | + $this->remove_api_head(); | |
| 497 | + $this->remove_api_server(); | |
| 498 | + $this->disable_json_api(); | |
| 441 | 499 | |
| 442 | - // Update the node with the new title | |
| 443 | - $wp_admin_bar->add_node([ | |
| 444 | - 'id' => 'my-account', | |
| 445 | - 'parent' => 'top-secondary', | |
| 446 | - 'title' => $changed_howdy_text, | |
| 447 | - ]); | |
| 448 | - } | |
| 500 | + // More REST API Hooks | |
| 501 | + remove_action('rest_api_init', 'wp_oembed_register_route'); // Remove the REST API endpoint. | |
| 502 | + remove_action('wp_head', 'wp_oembed_add_host_js'); // Remove oEmbed-specific JavaScript from the front-end and back-end. | |
| 503 | + add_filter('embed_oembed_discover', '__return_false'); // Turn off oEmbed auto discovery. | |
| 504 | + remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); // Remove filter oEmbed results. | |
| 505 | + add_filter('rewrite_rules_array', [$this, 'adminify_disable_embeds_rewrites']); // Remove all embeds rewrite rules. | |
| 506 | + } | |
| 449 | 507 | |
| 450 | - } | |
| 451 | - } | |
| 452 | 508 | |
| 453 | 509 | /** |
| 454 | - * Remove Canonical URL | |
| 510 | + * Remove all rewrite rules related to embeds. | |
| 455 | 511 | * |
| 456 | - * @return void | |
| 512 | + * @param array $rules WordPress rewrite rules. | |
| 513 | + * @return array Rewrite rules without embeds rules. | |
| 457 | 514 | */ |
| 458 | - public function remove_wp_canonical_url() | |
| 515 | + public function adminify_disable_embeds_rewrites($rules) | |
| 459 | 516 | { |
| 460 | - remove_action('wp_head', 'rel_canonical'); | |
| 517 | + foreach ($rules as $rule => $rewrite) { | |
| 518 | + if (false !== strpos($rewrite, 'embed=true')) { | |
| 519 | + unset($rules[$rule]); | |
| 520 | + } | |
| 521 | + } | |
| 522 | + | |
| 523 | + return $rules; | |
| 461 | 524 | } |
| 462 | 525 | |
| 463 | - /** | |
| 464 | - * Removes admin bar logo from Admin Toolbar | |
| 465 | - */ | |
| 466 | - public function admin_bar_cleanup() | |
| 526 | + public function remove_api_head() | |
| 467 | 527 | { |
| 468 | - global $wp_admin_bar; | |
| 469 | - //TODO: Check for Network wide site "my-sites" | |
| 528 | + remove_action('wp_head', 'rest_output_link_wp_head'); | |
| 529 | + remove_action('wp_head', 'wp_oembed_add_discovery_links'); | |
| 530 | + } | |
| 470 | 531 | |
| 471 | - if (in_array('wp_logo', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) { | |
| 472 | - $wp_admin_bar->remove_menu('wp-logo'); | |
| 532 | + | |
| 533 | + // Comments Cleanup | |
| 534 | + public function comments_cleanup() | |
| 535 | + { | |
| 536 | + // Remove Comments Website/URL field | |
| 537 | + if (!empty($this->options['remove_comments_url'])) { | |
| 538 | + add_filter('comment_form_default_fields', [$this, 'jltwp_adminify_remove_comments_url']); | |
| 473 | 539 | } |
| 474 | - if (in_array('site_name', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) { | |
| 475 | - $wp_admin_bar->remove_menu('site-name'); | |
| 540 | + | |
| 541 | + // Remove comment notes | |
| 542 | + if (!empty($this->options['remove_comments_notes'])) { | |
| 543 | + add_filter('comment_form_defaults', [$this, 'jltwp_adminify_remove_comments_notes']); | |
| 476 | 544 | } |
| 477 | - if (in_array('comments', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) { | |
| 478 | - $wp_admin_bar->remove_menu('comments'); | |
| 545 | + | |
| 546 | + // Remove comment author link | |
| 547 | + if (!empty($this->options['remove_comments_author_link'])) { | |
| 548 | + add_filter('get_comment_author_link', [$this, 'jltwp_adminify_remove_comments_author_link']); | |
| 479 | 549 | } |
| 480 | - // if (in_array('menu_toggle', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) { | |
| 481 | - // $wp_admin_bar->remove_menu('menu-toggle'); | |
| 482 | - // } | |
| 550 | + | |
| 551 | + // Remove comments autolinking | |
| 552 | + if (!empty($this->options['remove_comments_autolinking'])) { | |
| 553 | + remove_filter('comment_text', 'make_clickable', 9); | |
| 554 | + } | |
| 483 | 555 | } |
| 484 | 556 | |
| 557 | + public function jltwp_adminify_remove_comments_author_link($author_link) | |
| 558 | + { | |
| 559 | + return strip_tags($author_link); | |
| 560 | + } | |
| 485 | 561 | |
| 562 | + public function jltwp_adminify_remove_comments_notes($defaults) | |
| 563 | + { | |
| 564 | + $defaults['comment_notes_before'] = ''; | |
| 486 | 565 | |
| 487 | - // Clear the node titles | |
| 488 | - // This will only work if the node is using a :before element for the icon | |
| 489 | - public function clear_node_title($wp_admin_bar) | |
| 566 | + return $defaults; | |
| 567 | + } | |
| 568 | + | |
| 569 | + public function jltwp_adminify_remove_comments_url($fields) | |
| 490 | 570 | { |
| 491 | - $all_toolbar_nodes = $wp_admin_bar->get_nodes(); | |
| 492 | - // Create an array of node ID's we'd like to remove | |
| 493 | - $clear_titles = [ | |
| 494 | - 'site-name', | |
| 495 | - 'customize', | |
| 496 | - ]; | |
| 571 | + if (isset($fields['url'])) { | |
| 572 | + unset($fields['url']); | |
| 573 | + } | |
| 497 | 574 | |
| 498 | - foreach ($all_toolbar_nodes as $node) { | |
| 575 | + return $fields; | |
| 576 | + } | |
| 499 | 577 | |
| 500 | - // Run an if check to see if a node is in the array to clear_titles | |
| 501 | - if (in_array($node->id, $clear_titles)) { | |
| 502 | - // use the same node's properties | |
| 503 | - $args = $node; | |
| 504 | 578 | |
| 505 | - // make the node title a blank string | |
| 506 | - $args->title = ''; | |
| 579 | + // Archives Cleanup | |
| 580 | + public function archives_cleanup() | |
| 581 | + { | |
| 582 | + // Remove date archives | |
| 583 | + if (!empty($this->options['remove_archives_date'])) { | |
| 584 | + add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_date']); | |
| 585 | + } | |
| 507 | 586 | |
| 508 | - // update the Toolbar node | |
| 509 | - $wp_admin_bar->add_node($args); | |
| 510 | - } | |
| 587 | + // Remove Author archives | |
| 588 | + if (!empty($this->options['remove_archives_author'])) { | |
| 589 | + add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_author']); | |
| 511 | 590 | } |
| 512 | - } | |
| 513 | 591 | |
| 514 | - // Remove items from the admin bar | |
| 515 | - public function remove_from_admin_bar($wp_admin_bar) | |
| 516 | - { | |
| 517 | - /* | |
| 518 | - * Placing items in here will only remove them from admin bar | |
| 519 | - * when viewing the fronte end of the site | |
| 520 | - */ | |
| 521 | - if (!is_admin()) { | |
| 522 | - // Example of removing item generated by plugin. Full ID is #wp-admin-bar-si_menu | |
| 523 | - $wp_admin_bar->remove_node('si_menu'); | |
| 592 | + // Remove tag archives | |
| 593 | + if (!empty($this->options['remove_archives_tag'])) { | |
| 594 | + add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_tag']); | |
| 595 | + } | |
| 524 | 596 | |
| 525 | - // WordPress Core Items (uncomment to remove) | |
| 526 | - $wp_admin_bar->remove_node('updates'); | |
| 527 | - $wp_admin_bar->remove_node('comments'); | |
| 528 | - $wp_admin_bar->remove_node('new-content'); | |
| 529 | - // $wp_admin_bar->remove_node('wp-logo'); | |
| 530 | - // $wp_admin_bar->remove_node('site-name'); | |
| 531 | - $wp_admin_bar->remove_node('my-account'); | |
| 532 | - // $wp_admin_bar->remove_node('search'); | |
| 533 | - // $wp_admin_bar->remove_node('customize'); | |
| 597 | + // Remove category archives | |
| 598 | + if (!empty($this->options['remove_archives_category'])) { | |
| 599 | + add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_category']); | |
| 534 | 600 | } |
| 535 | 601 | |
| 536 | - /* | |
| 537 | - * Items placed outside the if statement will remove it from both the frontend | |
| 538 | - * and backend of the site | |
| 539 | - */ | |
| 540 | - $wp_admin_bar->remove_node('wp-logo'); | |
| 602 | + // Remove archives post formats | |
| 603 | + if (!empty($this->options['remove_archives_postformat'])) { | |
| 604 | + add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_postformat']); | |
| 605 | + } | |
| 606 | + | |
| 607 | + // Remove search page | |
| 608 | + if (!empty($this->options['remove_archives_search'])) { | |
| 609 | + add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_search']); | |
| 610 | + } | |
| 541 | 611 | } |
| 542 | 612 | |
| 543 | - // Custom Avatars | |
| 544 | - public function add_custom_gravatar_image($avatar_defaults) | |
| 613 | + public function jltwp_adminify_remove_archives_date() | |
| 545 | 614 | { |
| 546 | - // Register the avatar images configured by the administrator in the plugin settings. | |
| 547 | - if ( ! empty( $this->custom_gravatar['image'] ) && is_array( $this->custom_gravatar['image'] ) ) { | |
| 548 | - foreach ( $this->custom_gravatar['image'] as $value ) { | |
| 549 | - if ( empty( $value['avatar_image']['url'] ) ) { | |
| 550 | - continue; | |
| 551 | - } | |
| 552 | - $avatar_url = esc_url_raw( $value['avatar_image']['url'] ); | |
| 553 | - $avatar_name = ! empty( $value['avatar_name'] ) ? sanitize_text_field( $value['avatar_name'] ) : __( 'Custom Gravatar', 'adminify' ); | |
| 554 | - $avatar_defaults[ $avatar_url ] = $avatar_name; | |
| 555 | - } | |
| 615 | + if (is_date()) { | |
| 616 | + $this->redirect(); | |
| 556 | 617 | } |
| 618 | + } | |
| 557 | 619 | |
| 558 | - return $avatar_defaults; | |
| 620 | + public function jltwp_adminify_remove_archives_author() | |
| 621 | + { | |
| 622 | + if (is_author()) { | |
| 623 | + $this->redirect(); | |
| 624 | + } | |
| 559 | 625 | } |
| 560 | 626 | |
| 561 | - // Check Last Login Column | |
| 562 | - public function last_login_column_info( $user_login ) | |
| 563 | - { | |
| 564 | - $user = get_user_by( 'login', $user_login ); | |
| 565 | - // by username | |
| 566 | - update_user_meta( $user->ID, 'adminify_last_login_on', time() ); | |
| 567 | - } | |
| 568 | - | |
| 569 | - | |
| 570 | - // Remove WPML Generator | |
| 571 | - public function remove_wpml_generator() | |
| 627 | + public function jltwp_adminify_remove_archives_tag() | |
| 572 | 628 | { |
| 573 | - if (!empty($GLOBALS['sitepress'])) { | |
| 574 | - remove_action(current_filter(), [$GLOBALS['sitepress'], 'meta_generator_tag']); | |
| 629 | + if (is_tag()) { | |
| 630 | + $this->redirect(); | |
| 575 | 631 | } |
| 576 | 632 | } |
| 577 | 633 | |
| 578 | - | |
| 579 | - /** | |
| 580 | - * Disable WP emojicons from TinyMCE | |
| 581 | - * | |
| 582 | - * @access public | |
| 583 | - * @since 1.0.0 | |
| 584 | - * @return void | |
| 585 | - */ | |
| 586 | - public function disable_emojicons_tinymce($plugins) | |
| 634 | + public function jltwp_adminify_remove_archives_category() | |
| 587 | 635 | { |
| 588 | - if (is_array($plugins)) { | |
| 589 | - return array_diff($plugins, ['wpemoji']); | |
| 590 | - } else { | |
| 591 | - return []; | |
| 636 | + if (is_category()) { | |
| 637 | + $this->redirect(); | |
| 592 | 638 | } |
| 593 | 639 | } |
| 594 | 640 | |
| 595 | - /** | |
| 596 | - * Disable WP emojicons from TinyMCE | |
| 597 | - * | |
| 598 | - * @access public | |
| 599 | - * @since 1.0.0 | |
| 600 | - * @return void | |
| 601 | - */ | |
| 602 | - public function remove_dns_prefetch( $urls, $relation_type ) { | |
| 603 | - if ('dns-prefetch' == $relation_type) { | |
| 604 | - // Strip out any URLs referencing the WordPress.org emoji location | |
| 605 | - $emoji_svg_url_base = 'https://s.w.org/images/core/emoji/'; | |
| 606 | - foreach ($urls as $key => $url) { | |
| 607 | - if (is_string($url) && false !== strpos($url, $emoji_svg_url_base)) { | |
| 608 | - unset($urls[$key]); | |
| 609 | - } | |
| 610 | - } | |
| 641 | + public function jltwp_adminify_remove_archives_postformat() | |
| 642 | + { | |
| 643 | + if (is_tax('post_format')) { | |
| 644 | + $this->redirect(); | |
| 611 | 645 | } |
| 612 | - return $urls; | |
| 613 | 646 | } |
| 614 | 647 | |
| 615 | - public function remove_powered() | |
| 648 | + public function jltwp_adminify_remove_archives_search() | |
| 616 | 649 | { |
| 617 | - if (function_exists('header_remove')) { | |
| 618 | - header_remove('X-Powered-By'); | |
| 650 | + if (is_search()) { | |
| 651 | + $this->redirect(); | |
| 619 | 652 | } |
| 620 | 653 | } |
| 621 | 654 | |
| 622 | - | |
| 623 | - | |
| 624 | - /** | |
| 625 | - * Remove all rewrite rules related to embeds. | |
| 626 | - * | |
| 627 | - * @param array $rules WordPress rewrite rules. | |
| 628 | - * @return array Rewrite rules without embeds rules. | |
| 629 | - */ | |
| 630 | - public function disable_embeds_rewrites($rules) | |
| 655 | + public function attachments_cleanup() | |
| 631 | 656 | { |
| 632 | - foreach ($rules as $rule => $rewrite) { | |
| 633 | - if (false !== strpos($rewrite, 'embed=true')) { | |
| 634 | - unset($rules[$rule]); | |
| 635 | - } | |
| 657 | + // Remove attachments | |
| 658 | + if (!empty($this->options['remove_attachment'])) { | |
| 659 | + add_action('template_redirect', [$this, 'jltwp_adminify_remove_attachment']); | |
| 636 | 660 | } |
| 637 | - | |
| 638 | - return $rules; | |
| 639 | 661 | } |
| 640 | 662 | |
| 641 | - // Redirect 403 | |
| 642 | - public function redirect_to_403($url = false) | |
| 663 | + public function jltwp_adminify_remove_attachment() | |
| 643 | 664 | { |
| 644 | - status_header(403); // Send an HTTP 403 Forbidden status header | |
| 645 | - die('403 Forbidden'); // End execution and display a 403 Forbidden message | |
| 665 | + if (is_attachment()) { | |
| 666 | + global $post; | |
| 667 | + | |
| 668 | + $url = get_the_permalink($post->post_parent); | |
| 669 | + | |
| 670 | + $this->redirect($url); | |
| 671 | + } | |
| 646 | 672 | } |
| 647 | 673 | |
| 648 | 674 | // Redirect function |
| 649 | 675 | public function redirect($url = false) |
| @@ -650,21 +676,55 @@ | ||
| 650 | 676 | { |
| 651 | 677 | if ($url) { |
| 652 | 678 | $target = $url; |
| 653 | 679 | } else { |
| 654 | - $target = esc_url(home_url()); | |
| 680 | + $target = get_option('siteurl'); | |
| 655 | 681 | } |
| 656 | 682 | |
| 657 | - $target = apply_filters('pxlbsadminify_redirect_target', $target); | |
| 658 | - $status = apply_filters('pxlbsadminify_redirect_status', $this->redirect_status); | |
| 683 | + $target = apply_filters('wp_adminify_redirect_target', $target); | |
| 684 | + $status = apply_filters('wp_adminify_redirect_status', $this->redirect_status); | |
| 659 | 685 | |
| 660 | - wp_safe_redirect($target, $status); | |
| 661 | - exit; | |
| 686 | + wp_redirect($target, $status); | |
| 687 | + die(); | |
| 662 | 688 | } |
| 663 | 689 | |
| 690 | + // Disable Feeds | |
| 691 | + public function redirect_feed() | |
| 692 | + { | |
| 693 | + $this->remove_feed(); | |
| 694 | + } | |
| 664 | 695 | |
| 696 | + public function _redirect_feed() | |
| 697 | + { | |
| 698 | + $this->redirect(); | |
| 699 | + } | |
| 700 | + | |
| 701 | + // Remove Feed Links | |
| 702 | + public function remove_feed() | |
| 703 | + { | |
| 704 | + if (!empty($this->options['remove_feed'])) { | |
| 705 | + add_action('do_feed', [$this, '_redirect_feed'], 1); | |
| 706 | + add_action('do_feed_rdf', [$this, '_redirect_feed'], 1); | |
| 707 | + add_action('do_feed_rss', [$this, '_redirect_feed'], 1); | |
| 708 | + add_action('do_feed_rss2', [$this, '_redirect_feed'], 1); | |
| 709 | + add_action('do_feed_atom', [$this, '_redirect_feed'], 1); | |
| 710 | + remove_action('wp_head', 'feed_links_extra', 3); // Remove Every Extra Links to Rss Feeds. | |
| 711 | + remove_action('wp_head', 'feed_links', 2); | |
| 712 | + remove_action('wp_head', 'wc_products_rss_feed'); | |
| 713 | + } | |
| 714 | + } | |
| 715 | + | |
| 716 | + public function remove_admin_footer_version() | |
| 717 | + { | |
| 718 | + // Remove WordPress Version except Admin | |
| 719 | + if (!current_user_can('manage_options')) { | |
| 720 | + remove_filter('update_footer', 'core_update_footer'); | |
| 721 | + } | |
| 722 | + } | |
| 723 | + | |
| 724 | + | |
| 665 | 725 | /* Add Featured Image or Post Thumbnail to RSS Feed */ |
| 666 | - public function rss_post_thumbnail($content) | |
| 726 | + public function jltwp_adminify_rss_post_thumbnail($content) | |
| 667 | 727 | { |
| 668 | 728 | global $post; |
| 669 | 729 | if (has_post_thumbnail($post->ID)) { |
| 670 | 730 | $content = '<p>' . get_the_post_thumbnail($post->ID) . |
| @@ -673,9 +733,9 @@ | ||
| 673 | 733 | return $content; |
| 674 | 734 | } |
| 675 | 735 | |
| 676 | 736 | // Display Last Updated Date of Your Posts |
| 677 | - public function last_updated_date($content) | |
| 737 | + public function jltwp_adminify_last_updated_date($content) | |
| 678 | 738 | { |
| 679 | 739 | if (!is_single()) { |
| 680 | 740 | return $content; |
| 681 | 741 | } |
| @@ -684,12 +744,12 @@ | ||
| 684 | 744 | $u_modified_time = get_the_modified_time('U'); |
| 685 | 745 | |
| 686 | 746 | if ($u_modified_time >= $u_time + 86400) { |
| 687 | 747 | $custom_content = sprintf( |
| 688 | - '<div class="wp-adminify-last-updated"><strong><span>%1$s</span></strong><span>%2$s %3$s</span></div>', | |
| 748 | + __('<div class="wp-adminify-last-updated"><p>%1$s</p><p>%2$s %3$s</p></div>', 'adminify'), | |
| 689 | 749 | esc_html__('Last Updated on', 'adminify'), |
| 690 | - esc_html(get_the_modified_time('F jS, Y')), | |
| 691 | - esc_html(get_the_modified_time('h:i a')) | |
| 750 | + get_the_modified_time('F jS, Y'), | |
| 751 | + get_the_modified_time('h:i a') | |
| 692 | 752 | ); |
| 693 | 753 | return $custom_content . $content; |
| 694 | 754 | } |
| 695 | 755 | |
| @@ -695,16 +755,16 @@ | ||
| 695 | 755 | |
| 696 | 756 | return $content; |
| 697 | 757 | } |
| 698 | 758 | |
| 699 | - public function last_updated_date_style() | |
| 759 | + public function jltwp_adminify_last_updated_date_style() | |
| 700 | 760 | { |
| 701 | - echo '<style>.wp-adminify-last-updated{ border: 1px dashed red; padding: 5px 10px;}</style>'; | |
| 761 | + echo '<style>.last-updated{ border: 1px dashed red; padding: 5px 10px;}</style>'; | |
| 702 | 762 | } |
| 703 | 763 | |
| 704 | 764 | |
| 705 | 765 | // Remove Default Image Links typeremove_image_link |
| 706 | - public function security_attachment_imagelink() | |
| 766 | + public function jltwp_adminify_imagelink() | |
| 707 | 767 | { |
| 708 | 768 | $image_set = get_option('image_default_link_type'); |
| 709 | 769 | |
| 710 | 770 | if ($image_set !== 'none') { |
| @@ -713,70 +773,38 @@ | ||
| 713 | 773 | } |
| 714 | 774 | |
| 715 | 775 | |
| 716 | 776 | /* Disable Self Pings */ |
| 717 | - public function disable_self_ping(&$links) | |
| 777 | + public function jltwp_adminify_no_self_ping(&$links) | |
| 718 | 778 | { |
| 719 | - $home = esc_url( home_url() ); | |
| 779 | + $home = get_option('home'); | |
| 720 | 780 | |
| 721 | - // Additional URLs and explode into an array. | |
| 722 | - $extra_urls = (!empty($this->options['self_ping_sites'])) ? $this->options['self_ping_sites'] : ''; | |
| 723 | - $extra_urls = explode(PHP_EOL, $extra_urls); | |
| 724 | - | |
| 725 | - if ( is_array( $extra_urls ) ) { | |
| 726 | - $url_array = $extra_urls; | |
| 727 | - } else { | |
| 728 | - $url_array = array(); | |
| 729 | - } | |
| 730 | - | |
| 731 | - foreach ( $links as $l => $link ) { | |
| 732 | - if ( 0 === strpos( $link, $home ) ) { | |
| 733 | - unset( $links[ $l ] ); | |
| 781 | + foreach ($links as $l => $link) { | |
| 782 | + if (0 === strpos($link, $home)) { | |
| 783 | + unset($links[$l]); | |
| 734 | 784 | } |
| 735 | - foreach ( $url_array as $url ) { | |
| 736 | - $url = trim( $url ); | |
| 737 | - if ( 0 === strpos( $link, $url ) && '' !== $url ) { | |
| 738 | - unset( $links[ $l ] ); | |
| 739 | - } | |
| 740 | - } | |
| 741 | 785 | } |
| 742 | - | |
| 743 | 786 | } |
| 744 | 787 | |
| 745 | 788 | |
| 746 | 789 | /** Remove Dashicons from Admin Bar for non logged in users **/ |
| 747 | - public function remove_dashicons() | |
| 790 | + public function jltwp_adminify_remove_dashicons() | |
| 748 | 791 | { |
| 749 | - global $pagenow; | |
| 792 | + $dequeue = !(bool) apply_filters('wp_adminify_skip_removing_dashicons', false); | |
| 750 | 793 | |
| 751 | - if (!is_user_logged_in()) { | |
| 794 | + if (is_admin_bar_showing() || is_customize_preview()) { | |
| 795 | + $dequeue = false; | |
| 796 | + } | |
| 752 | 797 | |
| 753 | - // This retrieves the /path/file.php?param=val part of the URL | |
| 754 | - $current_request_uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : ''; | |
| 755 | - | |
| 756 | - // for homepage | |
| 757 | - if (empty($current_request_uri)) { | |
| 758 | - wp_dequeue_style('dashicons'); | |
| 759 | - wp_deregister_style('dashicons'); | |
| 760 | - } else { | |
| 761 | - // Exclude the login page, where Dashicons assets are required for proper styling. | |
| 762 | - if (false !== strpos($current_request_uri, 'wp-login.php') || 'wp-login.php' === $pagenow) { | |
| 763 | - // Do nothing on wp-login.php | |
| 764 | - } elseif (false !== strpos($current_request_uri, 'protected-page=view')) { | |
| 765 | - // Exclude the password protection form. | |
| 766 | - // Do nothing on protected-page=view. | |
| 767 | - } else { | |
| 768 | - // Dequeue Dashicons from contents e.g., yoursite.com/content-url/. Not for wp-login.php, | |
| 769 | - wp_dequeue_style('dashicons'); | |
| 770 | - wp_deregister_style('dashicons'); | |
| 771 | - } | |
| 772 | - } | |
| 798 | + if ($dequeue) { | |
| 799 | + wp_dequeue_style('dashicons'); | |
| 800 | + wp_deregister_style('dashicons'); | |
| 773 | 801 | } |
| 774 | 802 | } |
| 775 | 803 | |
| 776 | 804 | |
| 777 | 805 | /** Control Interval Heartbeat API **/ |
| 778 | - public function control_heartbeat_api($settings) | |
| 806 | + public function jltwp_adminify_control_heartbeat($settings) | |
| 779 | 807 | { |
| 780 | 808 | $settings['interval'] = 60; |
| 781 | 809 | return $settings; |
| 782 | 810 | } |
| @@ -781,18 +809,53 @@ | ||
| 781 | 809 | return $settings; |
| 782 | 810 | } |
| 783 | 811 | |
| 784 | 812 | /** Remove Query Strings from Scripts/Styles **/ |
| 785 | - public function remove_script_versions($src) | |
| 813 | + public function jltwp_adminify_remove_script_version($src) | |
| 786 | 814 | { |
| 787 | - if( !empty($src) ) { | |
| 788 | - $parts = explode('?ver', $src); | |
| 789 | - return $parts[0]; | |
| 815 | + $parts = explode('?ver', $src); | |
| 816 | + | |
| 817 | + return $parts[0]; | |
| 818 | + } | |
| 819 | + | |
| 820 | + /* Remove Gravatar Query Strings */ | |
| 821 | + public function jltwp_adminify_avatar_remove_querystring($url) | |
| 822 | + { | |
| 823 | + $url_parts = explode('?', $url); | |
| 824 | + return $url_parts[0]; | |
| 825 | + } | |
| 826 | + | |
| 827 | + /** Disable PDF Thumbnails Preview **/ | |
| 828 | + public function jltwp_adminify_disable_pdf_previews() | |
| 829 | + { | |
| 830 | + $fallbacksizes = []; | |
| 831 | + return $fallbacksizes; | |
| 832 | + } | |
| 833 | + | |
| 834 | + /** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer **/ | |
| 835 | + public function jltwp_adminify_defer_parsing_of_js($tag, $handle) | |
| 836 | + { | |
| 837 | + $skip = apply_filters('wp_adminify_defer_skip', false, $tag, $handle); | |
| 838 | + | |
| 839 | + if ($skip) { | |
| 840 | + return $tag; | |
| 790 | 841 | } |
| 842 | + | |
| 843 | + if (is_admin()) { | |
| 844 | + return $tag; | |
| 845 | + } | |
| 846 | + if (strpos($tag, '/wp-includes/js/jquery/jquery')) { | |
| 847 | + return $tag; | |
| 848 | + } | |
| 849 | + if (isset($_SERVER['HTTP_USER_AGENT']) && strpos(sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])), 'MSIE 9.') !== false) { | |
| 850 | + return $tag; | |
| 851 | + } else { | |
| 852 | + return str_replace(' src', ' defer src', $tag); | |
| 853 | + } | |
| 791 | 854 | } |
| 792 | 855 | |
| 793 | 856 | /** Browser Cache Expires & GZIP Compression **/ |
| 794 | - public function htaccess() | |
| 857 | + public function jltwp_adminify_htaccess() | |
| 795 | 858 | { |
| 796 | 859 | // We get the main WordPress .htaccess filepath. |
| 797 | 860 | $ruta_htaccess = get_home_path() . '.htaccess'; // https://codex.wordpress.org/Function_Reference/get_home_path ! |
| 798 | 861 | |
| @@ -823,12 +886,23 @@ | ||
| 823 | 886 | $lineas[] = 'AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf'; |
| 824 | 887 | $lineas[] = 'AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf'; |
| 825 | 888 | $lineas[] = '</IfModule>'; |
| 826 | 889 | |
| 827 | - insert_with_markers($ruta_htaccess, 'Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ ! | |
| 890 | + insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ ! | |
| 828 | 891 | } |
| 829 | 892 | |
| 893 | + public function jltwp_adminify_delete_tweaks_htaccess() | |
| 894 | + { | |
| 895 | + // We get the mail WordPress .htaccess filepath. | |
| 896 | + $ruta_htaccess = get_home_path() . '.htaccess'; // https://codex.wordpress.org/Function_Reference/get_home_path ! | |
| 830 | 897 | |
| 898 | + $lineas = []; | |
| 899 | + | |
| 900 | + $lineas[] = '# Optimizaciones eliminadas al desactivar el plugin'; | |
| 901 | + | |
| 902 | + insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ ! | |
| 903 | + } | |
| 904 | + | |
| 831 | 905 | /** |
| 832 | 906 | * Performance Cleanup |
| 833 | 907 | * |
| 834 | 908 | * @access public |
| @@ -834,121 +908,46 @@ | ||
| 834 | 908 | * @access public |
| 835 | 909 | * @since 1.0.0 |
| 836 | 910 | * @return void |
| 837 | 911 | */ |
| 838 | - public function performances() | |
| 912 | + public function performance_cleanup() | |
| 839 | 913 | { |
| 840 | - $performance_data = $this->performance['performance_data']; | |
| 841 | - | |
| 842 | 914 | // Remove jQuery Migrate |
| 843 | - | |
| 844 | - // Remove Dashicons from Frontend | |
| 845 | - if (!empty($performance_data) && in_array('dashicons', $performance_data)) { | |
| 846 | - add_action('wp_print_styles', [$this, 'remove_dashicons'], 100); | |
| 915 | + if (!empty($this->options['remove_jquery_migrate'])) { | |
| 916 | + add_action('wp_default_scripts', [$this, 'jltwp_adminify_remove_jquery_migrate'], 9999); | |
| 847 | 917 | } |
| 848 | 918 | |
| 849 | - /** Remove Version Query Strings from Scripts/Styles */ | |
| 850 | - if (!empty($performance_data) && in_array('version_strings', $performance_data)) { | |
| 851 | - if(!is_admin()){ | |
| 852 | - add_filter('script_loader_src', [$this, 'remove_script_versions'], 15, 1); | |
| 853 | - add_filter('style_loader_src', [$this, 'remove_script_versions'], 15, 1); | |
| 854 | - } | |
| 919 | + // Remove Gutenberg scrips | |
| 920 | + if (!empty($this->options['remove_gutenberg_scripts'])) { | |
| 921 | + add_action('wp_default_scripts', [$this, 'jltwp_adminify_remove_gutenberg_scripts'], 9999); | |
| 855 | 922 | } |
| 856 | - | |
| 857 | - | |
| 858 | - // Remove Emoji Styles and Scripts | |
| 859 | - if (!empty($performance_data) && in_array('emoji', $performance_data)) { | |
| 860 | - remove_action('wp_head', 'print_emoji_detection_script', 7); // Remove Emoji's Styles and Scripts. | |
| 861 | - remove_action('embed_head', 'print_emoji_detection_script'); | |
| 862 | - remove_action('embeded_head', 'print_emoji_detection_script'); | |
| 863 | - remove_action('admin_print_scripts', 'print_emoji_detection_script'); // Remove Emoji's Styles and Scripts. | |
| 864 | - remove_action('wp_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts. | |
| 865 | - remove_action('admin_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts. | |
| 866 | - remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); | |
| 867 | - remove_filter('the_content_feed', 'wp_staticize_emoji'); | |
| 868 | - remove_filter('comment_text_rss', 'wp_staticize_emoji'); | |
| 869 | - add_filter('option_use_smilies', '__return_false'); | |
| 870 | - add_filter('emoji_svg_url', '__return_false'); | |
| 871 | - add_action('admin_init', [$this, 'remove_admin_emojis']); | |
| 872 | - add_filter('tiny_mce_plugins', [$this, 'disable_emojicons_tinymce']); | |
| 873 | - add_filter('wp_resource_hints', [$this, 'remove_dns_prefetch'], 10, 2); | |
| 874 | - } | |
| 875 | - | |
| 876 | - | |
| 877 | - | |
| 878 | - add_action('wp_default_scripts', [$this, 'remove_wp_default_scripts'], 9999); | |
| 879 | - | |
| 880 | - /** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer */ | |
| 881 | - if (in_array('defer_parsing_js_footer', $performance_data)) { | |
| 882 | - add_filter('script_loader_tag', [$this, 'defer_parsing_of_js'], 10, 2); | |
| 883 | - } | |
| 884 | - | |
| 885 | - /** Browser Cache Expires & GZIP Compression */ | |
| 886 | - if (in_array('cache_gzip_compression', $performance_data)) { | |
| 887 | - register_activation_hook(__FILE__, [$this, 'htaccess']); | |
| 888 | - } | |
| 889 | - | |
| 890 | - | |
| 891 | - // Remove Gravatar Query Strings | |
| 892 | - if (!empty($performance_data) && in_array('gravatar_query_strings', $performance_data)) { | |
| 893 | - add_filter('get_avatar_url', [$this, 'remove_avatar_query_string']); | |
| 894 | - } | |
| 895 | 923 | } |
| 896 | 924 | |
| 897 | - /* Remove Gravatar Query Strings */ | |
| 898 | - public function remove_avatar_query_string($url) | |
| 925 | + public function jltwp_adminify_remove_jquery_migrate($scripts) | |
| 899 | 926 | { |
| 900 | - $url_parts = explode('?', $url); | |
| 901 | - return $url_parts[0]; | |
| 927 | + if (!is_admin() && isset($scripts->registered['jquery'])) { | |
| 928 | + $script = $scripts->registered['jquery']; | |
| 929 | + if ($script->deps) { // Check whether the script has any dependencies | |
| 930 | + $script->deps = array_diff( | |
| 931 | + $script->deps, | |
| 932 | + [ | |
| 933 | + 'jquery-migrate', | |
| 934 | + ] | |
| 935 | + ); | |
| 936 | + } | |
| 937 | + } | |
| 902 | 938 | } |
| 903 | 939 | |
| 904 | - | |
| 905 | - public function remove_admin_emojis() | |
| 940 | + // Remove all scripts and styles added by Gutenberg | |
| 941 | + public function jltwp_adminify_remove_gutenberg_scripts($scripts) | |
| 906 | 942 | { |
| 907 | - remove_action('admin_print_scripts', 'print_emoji_detection_script'); | |
| 908 | - remove_action('admin_print_styles', 'print_emoji_styles'); | |
| 943 | + add_action('wp_enqueue_scripts', [$this, 'jltwp_adminify_remove_block_scripts_action']); | |
| 944 | + remove_action('enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles'); | |
| 909 | 945 | } |
| 910 | 946 | |
| 911 | - | |
| 912 | - /** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer **/ | |
| 913 | - public function defer_parsing_of_js($tag, $handle) | |
| 947 | + // Dequeue all scripts and styles added by Gutenberg | |
| 948 | + public function jltwp_adminify_remove_block_scripts_action() | |
| 914 | 949 | { |
| 915 | - $skip = apply_filters('pxlbsadminify_defer_skip', false, $tag, $handle); | |
| 916 | - | |
| 917 | - if ($skip) { | |
| 918 | - return $tag; | |
| 919 | - } | |
| 920 | - | |
| 921 | - if (is_admin()) { | |
| 922 | - return $tag; | |
| 923 | - } | |
| 924 | - if (strpos($tag, '/wp-includes/js/jquery/jquery')) { | |
| 925 | - return $tag; | |
| 926 | - } | |
| 927 | - if (isset($_SERVER['HTTP_USER_AGENT']) && strpos(sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])), 'MSIE 9.') !== false) { | |
| 928 | - return $tag; | |
| 929 | - } else { | |
| 930 | - return str_replace(' src', ' defer src', $tag); | |
| 931 | - } | |
| 932 | - } | |
| 933 | - | |
| 934 | - /** | |
| 935 | - * Remove jQuery Migrate Script | |
| 936 | - * | |
| 937 | - * @param [type] $scripts | |
| 938 | - * | |
| 939 | - * @return void | |
| 940 | - */ | |
| 941 | - public function remove_wp_default_scripts($scripts) | |
| 942 | - { | |
| 943 | - // Frontend | |
| 944 | - if (!is_admin() && in_array('jquery_migrate_front', $this->performance['performance_data'])) { | |
| 945 | - $scripts->registered["jquery"]->deps = array_diff($scripts->registered["jquery"]->deps, ["jquery-migrate"]); | |
| 946 | - } | |
| 947 | - | |
| 948 | - // Backend | |
| 949 | - if (is_admin() && in_array('jquery_migrate_back', $this->performance['performance_data'])) { | |
| 950 | - $scripts->registered["jquery"]->deps = array_diff($scripts->registered["jquery"]->deps, ["jquery-migrate"]); | |
| 951 | - } | |
| 952 | - | |
| 950 | + wp_dequeue_style('wp-block-library'); | |
| 951 | + wp_dequeue_style('wc-block-style'); | |
| 953 | 952 | } |
| 954 | 953 | } |