PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.0.4
Adminify – White Label, Admin Menu Editor, Login Customizer v3.0.4
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.0.4, at Inc/Classes/Tweaks.php

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