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