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

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