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

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