PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.2.1
Adminify – White Label, Admin Menu Editor, Login Customizer v3.2.1
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 4.1.17 All 164 releases
adminify / Inc / Classes / Tweaks.php

Tweaks.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.2.1, at Inc/Classes/Tweaks.php

954 lines 27.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Classes;
4
5 use WPAdminify\Inc\Utils;
6 use WPAdminify\Inc\Admin\AdminSettings;
7 use WPAdminify\Inc\Admin\AdminSettingsModel;
8
9 // no direct access allowed
10 if (!defined('ABSPATH')) {
11 exit;
12 }
13
14 /**
15 * @package WP Adminify
16 * @author: Jewel Theme<support@jeweltheme.com>
17 */
18
19 class Tweaks extends AdminSettingsModel
20 {
21
22 public $redirect_status = 301;
23
24 public function __construct()
25 {
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();
37
38 add_action('wp_dashboard_setup', [$this, 'remove_welcome_panel'], 999);
39 }
40
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 }
47
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);
51 }
52
53 /** Disable REST API */
54 if (!empty($this->options['disable_rest_api'])) {
55
56 $this->disable_all_api();
57
58 // Filters for WP-API version 1.x
59 add_filter('json_enabled', '__return_false');
60 add_filter('json_jsonp_enabled', '__return_false');
61
62 // Filters for WP-API version 2.x
63 // add_filter('rest_enabled', '__return_false');
64 add_filter('rest_jsonp_enabled', '__return_false');
65 }
66
67 /** Control Interval Heartbeat API */
68 if (!empty($this->options['control_heartbeat_api'])) {
69 add_filter('heartbeat_settings', [$this, 'jltwp_adminify_control_heartbeat']);
70 }
71
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);
76 }
77
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');
82 }
83
84 /** Remove Capital P Dangit */
85 if (!empty($this->options['remove_capital_p_dangit'])) {
86 remove_filter('the_title', 'capital_P_dangit', 11);
87 remove_filter('the_content', 'capital_P_dangit', 11);
88 remove_filter('comment_text', 'capital_P_dangit', 31);
89 }
90
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']);
94 }
95
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 }
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 }
105
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 }
110
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 }
116
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 }
122
123 if (!empty($this->options['remove_image_link'])) {
124 add_action('admin_init', [$this, 'jltwp_adminify_imagelink'], 10);
125 }
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']);
142 }
143
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);
151 }
152
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 }
170
171
172
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 ];
183
184 foreach ($all_toolbar_nodes as $node) {
185
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;
190
191 // make the node title a blank string
192 $args->title = '';
193
194 // update the Toolbar node
195 $wp_admin_bar->add_node($args);
196 }
197 }
198 }
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');
210
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');
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');
227 }
228
229
230 /**
231 * Remove Welcome Panel
232 */
233 public function remove_welcome_panel()
234 {
235 if (!empty($this->options['remove_welcome_panel'])) {
236 remove_action('welcome_panel', 'wp_welcome_panel');
237 }
238 }
239
240
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');
248 }
249 }
250
251
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 }
260 }
261 return $avatar_defaults;
262 }
263
264
265 // Cleanup Hooks
266 public function jltwp_adminify_cleanup()
267 {
268
269 // Hide Admin bar
270 if (!empty($this->options['show_admin_bar'])) {
271 add_filter('show_admin_bar', '__return_false');
272 }
273
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']);
277 }
278
279 // Remove WordPress Version Number
280 if (!empty($this->options['generator_wp_version'])) {
281 remove_action('wp_head', 'wp_generator'); // Remove WordPress Generator Version
282 add_filter('the_generator', '__return_false'); // Remove Generator Name From Rss Feeds.
283 }
284
285 // Remove Revolution Slider generator version
286 if (!empty($this->options['remove_revslider_generator'])) {
287 add_filter('revslider_meta_generator', '__return_empty_string');
288 }
289
290 // Remove woocommerce generator version
291 if (!empty($this->options['remove_wc_generator'])) {
292 remove_action('wp_head', 'wc_generator_tag');
293 }
294
295 // Remove wpml meta generator tag
296 if (!empty($this->options['remove_wpml_generator'])) {
297 add_action('wp_head', [$this, '_remove_wpml_generator'], 0);
298 }
299
300 // Remove wpbakery visual_composer meta generator tag
301 if (!empty($this->options['remove_visual_composer_generator'])) {
302 add_action('wp_head', [$this, 'jltwp_adminify_remove_visual_composer_generator'], 1);
303 }
304
305 // Remove Yoast SEO meta generator tag
306 if (!empty($this->options['remove_yoast_generator'])) {
307 add_filter('wpseo_debug_markers', '__return_false');
308 }
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
315 // REMOVE wlwmanifest.xml.
316 if (!empty($this->options['remove_wlwmanifest'])) {
317 remove_action('wp_head', 'wlwmanifest_link');
318 }
319
320 // Remove Really Simple Discovery Link.
321 if (!empty($this->options['remove_rsd'])) {
322 remove_action('wp_head', 'rsd_link');
323 }
324
325 // Remove Shortlink Url
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);
329 }
330
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
345 $this->remove_feed();
346 $this->redirect_feed();
347
348 // Remove Link to Home Page.
349 if (!empty($this->options['remove_link_url'])) {
350 remove_action('wp_head', 'index_rel_link');
351 }
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 }
360
361 // Remove styles for .recentcomments
362 if (!empty($this->options['remove_recentcomments'])) {
363 add_action('widgets_init', [$this, 'jltwp_adminify_remove_recent_comments_style']);
364 }
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 }
370 }
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
395 /**
396 * Disable XML-RPC
397 *
398 * @access public
399 * @since 1.0.0
400 * @return void
401 */
402 public function jltwp_adminify_disable_xmlrpc()
403 {
404 add_filter('xmlrpc_enabled', '__return_false');
405 }
406
407 /**
408 * Disable WP emojicons from TinyMCE
409 *
410 * @access public
411 * @since 1.0.0
412 * @return void
413 */
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 }
422
423
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 }
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']);
436 }
437
438 // Remove X-Powered-By
439 if (!empty($this->options['remove_powered'])) {
440 add_action('wp', [$this, 'jltwp_adminify_remove_powered']);
441 }
442 }
443
444 public function jltwp_adminify_remove_powered()
445 {
446 if (function_exists('header_remove')) {
447 header_remove('x-powered-by');
448 }
449 }
450
451 public function jltwp_adminify_remove_pingback_head($headers)
452 {
453 if (isset($headers['X-Pingback'])) {
454 unset($headers['X-Pingback']);
455 }
456
457 return $headers;
458 }
459
460 public function jltwp_adminify_remove_pingback()
461 {
462 if (function_exists('header_remove')) {
463 header_remove('X-Pingback');
464 }
465 }
466
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();
472 }
473
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 }
482
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');
488
489 // Filters for WP-API version 2.x
490 // add_filter('rest_enabled', '__return_false');
491 add_filter('rest_jsonp_enabled', '__return_false');
492 }
493
494 public function disable_all_api()
495 {
496 $this->remove_api_head();
497 $this->remove_api_server();
498 $this->disable_json_api();
499
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 }
507
508
509 /**
510 * Remove all rewrite rules related to embeds.
511 *
512 * @param array $rules WordPress rewrite rules.
513 * @return array Rewrite rules without embeds rules.
514 */
515 public function adminify_disable_embeds_rewrites($rules)
516 {
517 foreach ($rules as $rule => $rewrite) {
518 if (false !== strpos($rewrite, 'embed=true')) {
519 unset($rules[$rule]);
520 }
521 }
522
523 return $rules;
524 }
525
526 public function remove_api_head()
527 {
528 remove_action('wp_head', 'rest_output_link_wp_head');
529 remove_action('wp_head', 'wp_oembed_add_discovery_links');
530 }
531
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']);
539 }
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']);
544 }
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']);
549 }
550
551 // Remove comments autolinking
552 if (!empty($this->options['remove_comments_autolinking'])) {
553 remove_filter('comment_text', 'make_clickable', 9);
554 }
555 }
556
557 public function jltwp_adminify_remove_comments_author_link($author_link)
558 {
559 return strip_tags($author_link);
560 }
561
562 public function jltwp_adminify_remove_comments_notes($defaults)
563 {
564 $defaults['comment_notes_before'] = '';
565
566 return $defaults;
567 }
568
569 public function jltwp_adminify_remove_comments_url($fields)
570 {
571 if (isset($fields['url'])) {
572 unset($fields['url']);
573 }
574
575 return $fields;
576 }
577
578
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 }
586
587 // Remove Author archives
588 if (!empty($this->options['remove_archives_author'])) {
589 add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_author']);
590 }
591
592 // Remove tag archives
593 if (!empty($this->options['remove_archives_tag'])) {
594 add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_tag']);
595 }
596
597 // Remove category archives
598 if (!empty($this->options['remove_archives_category'])) {
599 add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_category']);
600 }
601
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 }
611 }
612
613 public function jltwp_adminify_remove_archives_date()
614 {
615 if (is_date()) {
616 $this->redirect();
617 }
618 }
619
620 public function jltwp_adminify_remove_archives_author()
621 {
622 if (is_author()) {
623 $this->redirect();
624 }
625 }
626
627 public function jltwp_adminify_remove_archives_tag()
628 {
629 if (is_tag()) {
630 $this->redirect();
631 }
632 }
633
634 public function jltwp_adminify_remove_archives_category()
635 {
636 if (is_category()) {
637 $this->redirect();
638 }
639 }
640
641 public function jltwp_adminify_remove_archives_postformat()
642 {
643 if (is_tax('post_format')) {
644 $this->redirect();
645 }
646 }
647
648 public function jltwp_adminify_remove_archives_search()
649 {
650 if (is_search()) {
651 $this->redirect();
652 }
653 }
654
655 public function attachments_cleanup()
656 {
657 // Remove attachments
658 if (!empty($this->options['remove_attachment'])) {
659 add_action('template_redirect', [$this, 'jltwp_adminify_remove_attachment']);
660 }
661 }
662
663 public function jltwp_adminify_remove_attachment()
664 {
665 if (is_attachment()) {
666 global $post;
667
668 $url = get_the_permalink($post->post_parent);
669
670 $this->redirect($url);
671 }
672 }
673
674 // Redirect function
675 public function redirect($url = false)
676 {
677 if ($url) {
678 $target = $url;
679 } else {
680 $target = get_option('siteurl');
681 }
682
683 $target = apply_filters('wp_adminify_redirect_target', $target);
684 $status = apply_filters('wp_adminify_redirect_status', $this->redirect_status);
685
686 wp_redirect($target, $status);
687 die();
688 }
689
690 // Disable Feeds
691 public function redirect_feed()
692 {
693 $this->remove_feed();
694 }
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
725 /* Add Featured Image or Post Thumbnail to RSS Feed */
726 public function jltwp_adminify_rss_post_thumbnail($content)
727 {
728 global $post;
729 if (has_post_thumbnail($post->ID)) {
730 $content = '<p>' . get_the_post_thumbnail($post->ID) .
731 '</p>' . get_the_content();
732 }
733 return $content;
734 }
735
736 // Display Last Updated Date of Your Posts
737 public function jltwp_adminify_last_updated_date($content)
738 {
739 if (!is_single()) {
740 return $content;
741 }
742
743 $u_time = get_the_time('U');
744 $u_modified_time = get_the_modified_time('U');
745
746 if ($u_modified_time >= $u_time + 86400) {
747 $custom_content = sprintf(
748 __('<div class="wp-adminify-last-updated"><p>%1$s</p><p>%2$s %3$s</p></div>', 'adminify'),
749 esc_html__('Last Updated on', 'adminify'),
750 get_the_modified_time('F jS, Y'),
751 get_the_modified_time('h:i a')
752 );
753 return $custom_content . $content;
754 }
755
756 return $content;
757 }
758
759 public function jltwp_adminify_last_updated_date_style()
760 {
761 echo '<style>.last-updated{ border: 1px dashed red; padding: 5px 10px;}</style>';
762 }
763
764
765 // Remove Default Image Links typeremove_image_link
766 public function jltwp_adminify_imagelink()
767 {
768 $image_set = get_option('image_default_link_type');
769
770 if ($image_set !== 'none') {
771 update_option('image_default_link_type', 'none');
772 }
773 }
774
775
776 /* Disable Self Pings */
777 public function jltwp_adminify_no_self_ping(&$links)
778 {
779 $home = get_option('home');
780
781 foreach ($links as $l => $link) {
782 if (0 === strpos($link, $home)) {
783 unset($links[$l]);
784 }
785 }
786 }
787
788
789 /** Remove Dashicons from Admin Bar for non logged in users **/
790 public function jltwp_adminify_remove_dashicons()
791 {
792 $dequeue = !(bool) apply_filters('wp_adminify_skip_removing_dashicons', false);
793
794 if (is_admin_bar_showing() || is_customize_preview()) {
795 $dequeue = false;
796 }
797
798 if ($dequeue) {
799 wp_dequeue_style('dashicons');
800 wp_deregister_style('dashicons');
801 }
802 }
803
804
805 /** Control Interval Heartbeat API **/
806 public function jltwp_adminify_control_heartbeat($settings)
807 {
808 $settings['interval'] = 60;
809 return $settings;
810 }
811
812 /** Remove Query Strings from Scripts/Styles **/
813 public function jltwp_adminify_remove_script_version($src)
814 {
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;
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 }
854 }
855
856 /** Browser Cache Expires & GZIP Compression **/
857 public function jltwp_adminify_htaccess()
858 {
859 // We get the main WordPress .htaccess filepath.
860 $ruta_htaccess = get_home_path() . '.htaccess'; // https://codex.wordpress.org/Function_Reference/get_home_path !
861
862 $lineas = [];
863 $lineas[] = '<IfModule mod_expires.c>';
864 $lineas[] = '# Activar caducidad de contenido';
865 $lineas[] = 'ExpiresActive On';
866 $lineas[] = '# Directiva de caducidad por defecto';
867 $lineas[] = 'ExpiresDefault "access plus 1 month"';
868 $lineas[] = '# Para el favicon';
869 $lineas[] = 'ExpiresByType image/x-icon "access plus 1 year"';
870 $lineas[] = '# Imagenes';
871 $lineas[] = 'ExpiresByType image/gif "access plus 1 month"';
872 $lineas[] = 'ExpiresByType image/png "access plus 1 month"';
873 $lineas[] = 'ExpiresByType image/jpg "access plus 1 month"';
874 $lineas[] = 'ExpiresByType image/jpeg "access plus 1 month"';
875 $lineas[] = '# CSS';
876 $lineas[] = 'ExpiresByType text/css "access 1 month"';
877 $lineas[] = '# Javascript';
878 $lineas[] = 'ExpiresByType application/javascript "access plus 1 year"';
879 $lineas[] = '</IfModule>';
880 $lineas[] = '<IfModule mod_deflate.c>';
881 $lineas[] = '# Activar compresión de contenidos estáticos';
882 $lineas[] = 'AddOutputFilterByType DEFLATE text/plain text/html';
883 $lineas[] = 'AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd';
884 $lineas[] = 'AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml';
885 $lineas[] = 'AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript';
886 $lineas[] = 'AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf';
887 $lineas[] = 'AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf';
888 $lineas[] = '</IfModule>';
889
890 insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ !
891 }
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 !
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
905 /**
906 * Performance Cleanup
907 *
908 * @access public
909 * @since 1.0.0
910 * @return void
911 */
912 public function performance_cleanup()
913 {
914 // Remove jQuery Migrate
915 if (!empty($this->options['remove_jquery_migrate'])) {
916 add_action('wp_default_scripts', [$this, 'jltwp_adminify_remove_jquery_migrate'], 9999);
917 }
918
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);
922 }
923 }
924
925 public function jltwp_adminify_remove_jquery_migrate($scripts)
926 {
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 }
938 }
939
940 // Remove all scripts and styles added by Gutenberg
941 public function jltwp_adminify_remove_gutenberg_scripts($scripts)
942 {
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');
945 }
946
947 // Dequeue all scripts and styles added by Gutenberg
948 public function jltwp_adminify_remove_block_scripts_action()
949 {
950 wp_dequeue_style('wp-block-library');
951 wp_dequeue_style('wc-block-style');
952 }
953 }
954