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.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 2.0.9, at Inc/Classes/Tweaks.php

940 lines 31.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')) 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_welcome_panel();
33 $this->remove_try_gutenberg_panel();
34 $this->jltwp_adminify_customize_admin_bar();
35 }
36
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 }
43
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 }
49
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');
55
56 // Filters for WP-API version 2.x
57 // add_filter('rest_enabled', '__return_false');
58 add_filter('rest_jsonp_enabled', '__return_false');
59 }
60
61
62 /** Control Interval Heartbeat API **/
63 if (!empty($this->options['control_heartbeat_api'])) {
64 add_filter('heartbeat_settings', [$this, 'jltwp_adminify_control_heartbeat']);
65 }
66
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 }
72
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 }
78
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 }
85
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 }
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 }
95
96
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 }
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 }
106
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 }
112
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 }
118
119 if (!empty($this->options['remove_image_link'])) {
120 add_action('admin_init', [$this, 'jltwp_adminify_imagelink'], 10);
121 }
122
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 }
139
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 }
148
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 }
164
165
166
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 {
171
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 );
178
179 foreach ($all_toolbar_nodes as $node) {
180
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;
185
186 // make the node title a blank string
187 $args->title = '';
188
189 // update the Toolbar node
190 $wp_admin_bar->add_node($args);
191 }
192 }
193 }
194
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');
205
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 }
216
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 }
223
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 }
234
235
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 }
245
246
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 }
258
259
260 // Cleanup Hooks
261 public function jltwp_adminify_cleanup()
262 {
263
264 // Hide Admin bar
265 if (!empty($this->options['show_admin_bar'])) {
266 add_filter('show_admin_bar', '__return_false');
267 }
268
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 }
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 }
279
280 // Remove Revolution Slider generator version
281 if (!empty($this->options['remove_revslider_generator'])) {
282 add_filter('revslider_meta_generator', '__return_empty_string');
283 }
284
285 // Remove woocommerce generator version
286 if (!empty($this->options['remove_wc_generator'])) {
287 remove_action('wp_head', 'wc_generator_tag');
288 }
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 }
294
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 }
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 }
304
305 //Remove WordPress.org Dns-prefetch.
306 if (!empty($this->options['remove_dns_prefetch'])) {
307 remove_action('wp_head', 'wp_resource_hints', 2);
308 }
309
310 // REMOVE wlwmanifest.xml.
311 if (!empty($this->options['remove_wlwmanifest'])) {
312 remove_action('wp_head', 'wlwmanifest_link');
313 }
314
315 // Remove Really Simple Discovery Link.
316 if (!empty($this->options['remove_rsd'])) {
317 remove_action('wp_head', 'rsd_link');
318 }
319
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 }
325
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 }
339
340
341 $this->remove_feed();
342 $this->redirect_feed();
343
344 // Remove Link to Home Page.
345 if (!empty($this->options['remove_link_url'])) {
346 remove_action('wp_head', 'index_rel_link');
347 }
348
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 }
356
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 }
361
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 }
367
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 }
374
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 }
382
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 }
390
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 }
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 }
416
417
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 }
425
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 }
431
432 // Remove X-Powered-By
433 if (!empty($this->options['remove_powered'])) {
434 add_action('wp', [$this, 'jltwp_adminify_remove_powered']);
435 }
436 }
437
438 public function jltwp_adminify_remove_powered()
439 {
440 if (function_exists('header_remove')) {
441 header_remove('x-powered-by');
442 }
443 }
444
445 public function jltwp_adminify_remove_pingback_head($headers)
446 {
447 if (isset($headers['X-Pingback'])) {
448 unset($headers['X-Pingback']);
449 }
450
451 return $headers;
452 }
453
454 public function jltwp_adminify_remove_pingback()
455 {
456 if (function_exists('header_remove')) {
457 header_remove('X-Pingback');
458 }
459 }
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();
468
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 }
477
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');
483
484 // Filters for WP-API version 2.x
485 // add_filter('rest_enabled', '__return_false');
486 add_filter('rest_jsonp_enabled', '__return_false');
487 }
488
489 public function disable_all_api()
490 {
491 $this->remove_api_head();
492 $this->remove_api_server();
493 $this->disable_json_api();
494
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 }
502
503
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 }
516
517 return $rules;
518 }
519
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 }
525
526
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 }
534
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 }
539
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 }
544
545 // Remove comments autolinking
546 if (!empty($this->options['remove_comments_autolinking'])) {
547 remove_filter('comment_text', 'make_clickable', 9);
548 }
549 }
550
551 public function jltwp_adminify_remove_comments_author_link($author_link)
552 {
553 return strip_tags($author_link);
554 }
555
556 public function jltwp_adminify_remove_comments_notes($defaults)
557 {
558 $defaults['comment_notes_before'] = '';
559
560 return $defaults;
561 }
562
563 public function jltwp_adminify_remove_comments_url($fields)
564 {
565 if (isset($fields['url']))
566 unset($fields['url']);
567
568 return $fields;
569 }
570
571
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 }
579
580 // Remove Author archives
581 if (!empty($this->options['remove_archives_author'])) {
582 add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_author']);
583 }
584
585 // Remove tag archives
586 if (!empty($this->options['remove_archives_tag'])) {
587 add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_tag']);
588 }
589
590 // Remove category archives
591 if (!empty($this->options['remove_archives_category'])) {
592 add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_category']);
593 }
594
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 }
599
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()
607 {
608 if (is_date())
609 $this->redirect();
610 }
611
612 public function jltwp_adminify_remove_archives_author()
613 {
614 if (is_author())
615 $this->redirect();
616 }
617
618 public function jltwp_adminify_remove_archives_tag()
619 {
620 if (is_tag())
621 $this->redirect();
622 }
623
624 public function jltwp_adminify_remove_archives_category()
625 {
626 if (is_category())
627 $this->redirect();
628 }
629
630 public function jltwp_adminify_remove_archives_postformat()
631 {
632 if (is_tax('post_format'))
633 $this->redirect();
634 }
635
636 public function jltwp_adminify_remove_archives_search()
637 {
638 if (is_search())
639 $this->redirect();
640 }
641
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 }
649
650 public function jltwp_adminify_remove_attachment()
651 {
652 if (is_attachment()) {
653
654 global $post;
655
656 $url = get_the_permalink($post->post_parent);
657
658 $this->redirect($url);
659 }
660 }
661
662 // Redirect function
663 public function redirect($url = false)
664 {
665 if ($url) {
666 $target = $url;
667 } else {
668 $target = get_option('siteurl');
669 }
670
671 $target = apply_filters('wp_adminify_redirect_target', $target);
672 $status = apply_filters('wp_adminify_redirect_status', $this->redirect_status);
673
674 wp_redirect($target, $status);
675 die();
676 }
677
678 // Disable Feeds
679 public function redirect_feed()
680 {
681 $this->remove_feed();
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 }
689
690 public function _redirect_feed()
691 {
692 $this->redirect();
693 }
694
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 }
704
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 }
712
713
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 }
724
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 }
731
732 $u_time = get_the_time('U');
733 $u_modified_time = get_the_modified_time('U');
734
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 }
744
745 return $content;
746 }
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 }
752
753
754 //Remove Default Image Links typeremove_image_link
755 public function jltwp_adminify_imagelink()
756 {
757 $image_set = get_option('image_default_link_type');
758
759 if ($image_set !== 'none') {
760 update_option('image_default_link_type', 'none');
761 }
762 }
763
764
765 /* Disable Self Pings */
766 public function jltwp_adminify_no_self_ping(&$links)
767 {
768 $home = get_option('home');
769
770 foreach ($links as $l => $link)
771
772 if (0 === strpos($link, $home))
773
774 unset($links[$l]);
775 }
776
777
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);
782
783 if (is_admin_bar_showing() || is_customize_preview()) {
784 $dequeue = false;
785 }
786
787 if ($dequeue) {
788 wp_dequeue_style('dashicons');
789 wp_deregister_style('dashicons');
790 }
791 }
792
793
794 /** Control Interval Heartbeat API **/
795 public function jltwp_adminify_control_heartbeat($settings)
796 {
797 $settings['interval'] = 60;
798 return $settings;
799 }
800
801 /** Remove Query Strings from Scripts/Styles **/
802 public function jltwp_adminify_remove_script_version($src)
803 {
804 $parts = explode('?ver', $src);
805
806 return $parts[0];
807 }
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 }
815
816 /** Disable PDF Thumbnails Preview **/
817 public function jltwp_adminify_disable_pdf_previews()
818 {
819 $fallbacksizes = array();
820 return $fallbacksizes;
821 }
822
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 {
826
827 $skip = apply_filters('wp_adminify_defer_skip', false, $tag, $handle);
828
829 if ($skip) {
830 return $tag;
831 }
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 }
845
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 !
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>';
879
880 insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ !
881 }
882
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 !
887
888 $lineas = array();
889
890 $lineas[] = '# Optimizaciones eliminadas al desactivar el plugin';
891
892 insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ !
893 }
894
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 }
907
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 }
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 }
925
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 }
932
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 }
939 }
940