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

951 lines 28.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')) {
11 exit;
12 }
13
14 /**
15 * @package WP Adminify
16 * @author: Jewel Theme<support@jeweltheme.com>
17 */
18
19 class Tweaks extends AdminSettingsModel
20 {
21
22 public $redirect_status = 301;
23 private $performance;
24 private $security_head;
25 private $security_feed;
26 private $security_rest_api;
27 private $security_posts;
28 private $security_media;
29 private $custom_gravatar;
30
31 public function __construct()
32 {
33 $this->options = (array) AdminSettings::get_instance()->get();
34 $this->performance = $this->options['performance'];
35 $this->security_head = $this->options['security_head'];
36 $this->security_feed = $this->options['security_feed'];
37 $this->security_rest_api = $this->options['security_rest_api'];
38 $this->security_posts = $this->options['post_archives'];
39 $this->security_media = $this->options['media_attachments'];
40 $this->custom_gravatar = $this->options['custom_gravatar'];
41
42
43
44 if (!empty($this->security_head['enable_security_head'])) {
45 $this->security_head();
46 }
47
48 $this->security_feed();
49
50 if (!empty($this->security_rest_api['security_rest_api_enable'])) {
51 $this->security_rest_api();
52 }
53
54 if (!empty($this->security_posts['post_archives_enable'])) {
55 $this->security_post_archives();
56 }
57
58 $this->security_attachments();
59
60 if(!empty($this->performance['performance_enable'])){
61 $this->adminify_performances();
62 }
63
64 // Add Custom Default Gravatar Image
65 if (!empty($this->custom_gravatar) && array_key_exists('enable', $this->custom_gravatar)) {
66 // Add Custom Default Gravatar Image
67 add_filter('avatar_defaults', [$this, 'add_custom_gravatar_image'], 99);
68 }
69
70 // If Admin bar Editor Plugin not Installed
71 if (! class_exists('\JewelTheme\AdminBarEditor\AdminBarEditor')) {
72 if (!empty($this->options['white_label']['wordpress']['remove_howdy_msg']) || !empty($this->options['white_label']['wordpress']['change_howdy_text'])) {
73 // Change Howdy Text
74 // add_action('admin_bar_menu', [$this, 'remove_from_admin_bar'], 999);
75 // add_action('admin_bar_menu', [$this, 'clear_node_title'], 999);
76 add_filter('admin_bar_menu', [$this, 'adminify_change_howdy_text'], 9999);
77 }
78 }
79
80
81 // Remove Admin Bar Logo
82 if(!empty($this->options['white_label']['wordpress']['admin_bar_cleanup'])){
83 add_action("wp_before_admin_bar_render", [$this, "admin_bar_cleanup"], 0);
84 }
85
86 }
87
88
89 /**
90 * Security: Post & Archives
91 *
92 * @return void
93 */
94 public function security_post_archives(){
95 $post_archives_data = $this->security_posts['post_archives_data'];
96
97 // tag and category hooks
98 if (!empty($post_archives_data) && in_array('last_modified_date', $post_archives_data)) {
99 add_filter('the_content', [$this, 'last_updated_date'], 10, 1);
100 add_filter('wp_head', [$this, 'last_updated_date_style']);
101 }
102
103 /** Remove Capital P Dangit */
104 if (!empty($post_archives_data) && in_array('capital_p_dangit', $post_archives_data)) {
105 remove_filter('the_title', 'capital_P_dangit', 11);
106 remove_filter('the_content', 'capital_P_dangit', 11);
107 remove_filter('comment_text', 'capital_P_dangit', 31);
108 }
109
110 // Remove date archives
111 if (!empty($post_archives_data) && (
112 in_array('archives_date', $post_archives_data) ||
113 in_array('archives_author', $post_archives_data) ||
114 in_array('archives_tag', $post_archives_data) ||
115 in_array('archives_category', $post_archives_data) ||
116 in_array('archives_postformat', $post_archives_data) ||
117 in_array('archives_search', $post_archives_data)
118 )) {
119 add_action('template_redirect', [$this, 'redirect_to_home']);
120 }
121
122 // // Remove Author archives
123 // if (!empty($post_archives_data) && in_array('archives_author', $post_archives_data)) {
124 // if (is_author()) {
125 // add_action('template_redirect', [$this, 'redirect']);
126 // }
127 // }
128
129
130 // // Remove tag archives
131 // if (!empty($post_archives_data) && in_array('archives_tag', $post_archives_data)) {
132 // if (is_tag()) {
133 // add_action('template_redirect', [$this, 'redirect']);
134 // }
135 // }
136
137 // // Remove category archives
138 // if (!empty($post_archives_data) && in_array('archives_category', $post_archives_data)) {
139 // if (is_category()) {
140 // add_action('template_redirect', [$this, 'redirect']);
141 // }
142 // }
143
144 // // Remove archives post formats
145 // if (!empty($post_archives_data) && in_array('archives_postformat', $post_archives_data)) {
146 // if (is_tax('post_format')) {
147 // add_action('template_redirect', [$this, 'redirect']);
148 // }
149 // }
150
151 // // Remove search page
152 // if (!empty($post_archives_data) && in_array('archives_search', $post_archives_data)) {
153 // if (is_search()) {
154 // add_action('template_redirect', [$this, 'redirect']);
155 // }
156 // }
157
158 }
159
160 public function url_redirection(){
161 global $wp_query;
162 $wp_query->set_404();
163 wp_redirect(esc_url(home_url()), 301);
164 }
165
166 public function redirect_to_home(){
167 $post_archives_data = $this->security_posts['post_archives_data'];
168
169 // Remove Author archives
170 if (!empty($post_archives_data) && in_array('archives_author', $post_archives_data)) {
171 if (is_author()) {
172 $this->url_redirection();
173 }
174 }
175
176
177 // Remove tag archives
178 if (!empty($post_archives_data) && in_array('archives_tag', $post_archives_data)) {
179 if (is_tag()) {
180 $this->url_redirection();
181 }
182 }
183
184 // Remove category archives
185 if (!empty($post_archives_data) && in_array('archives_category', $post_archives_data)) {
186 if (is_category()) {
187 $this->url_redirection();
188 }
189 }
190
191 // Remove archives post formats
192 if (!empty($post_archives_data) && in_array('archives_postformat', $post_archives_data)) {
193 if (is_tax('post_format')) {
194 $this->url_redirection();
195 }
196 }
197
198 // Remove search page
199 if (!empty($post_archives_data) && in_array('archives_search', $post_archives_data)) {
200 if (is_search()) {
201 $this->url_redirection();
202 }
203 }
204 }
205
206
207 /**
208 * Security: Attachments
209 *
210 * @return void
211 */
212 public function security_attachments(){
213
214 // Add Featured Image or Post Thumbnail to RSS Feed
215 if (!empty($this->security_media['thumbnails_rss_feed'])) {
216 add_filter('the_excerpt_rss', [$this, 'jltwp_adminify_rss_post_thumbnail']);
217 add_filter('the_content_feed', [$this, 'jltwp_adminify_rss_post_thumbnail']);
218 }
219
220 }
221
222 /**
223 * Disable REST API
224 *
225 * @return void
226 */
227 public function security_rest_api(){
228 $this->security_rest_api = $this->security_rest_api['security_rest_api_data'];
229
230 /** Disable REST API */
231 if (!empty($this->security_rest_api) && in_array('rest_api', $this->security_rest_api)) {
232
233 // All REST API Hooks
234 if (version_compare(get_bloginfo('version'), '4.7', '>=')) {
235 add_filter('rest_authentication_errors', [$this, 'disable_rest_api']);
236 } else {
237 // Filters for WP-API version 1.x
238 add_filter('json_enabled', '__return_false');
239 add_filter('json_jsonp_enabled', '__return_false');
240
241 // Filters for WP-API version 2.x
242 add_filter('rest_enabled', '__return_false');
243 add_filter('rest_jsonp_enabled', '__return_false');
244 }
245
246 remove_action('wp_head', 'rest_output_link_wp_head', 10); // Disable REST API links in the HTML <head> tag
247 remove_action('wp_head', 'wp_oembed_add_discovery_links'); // Remove oEmbed discovery links.
248 remove_action('template_redirect', 'rest_output_link_header', 11, 0); // Disable the REST API link in HTTP headers.
249 remove_action('xmlrpc_rsd_apis', 'rest_output_rsd'); // Remove the REST API URL from the WordPress RSD endpoint.
250 }
251
252
253 // Remove X-Powered-By
254 if (!empty($this->security_rest_api) && in_array('powered', $this->security_rest_api)) {
255 // add_action('wp', [$this, 'remove_powered']); // OLD way
256
257 // Hook into 'send_headers' to remove the "X-Powered-By" header
258 add_action('send_headers', [$this, 'remove_powered']);
259 }
260 }
261
262
263 public function disable_rest_api(){
264 if (!is_user_logged_in()) {
265 return new \WP_Error(
266 'rest_api_authentication_required',
267 __('The REST API has been restricted to authenticated users.', 'adminify'),
268 [
269 'status' => rest_authorization_required_code()
270 ]
271 );
272 }
273 }
274
275
276 /**
277 * Security Head
278 *
279 * @return void
280 */
281 public function security_head(){
282
283 $this->security_head = $this->security_head['security_head_data'];
284
285 // Disable XML-RPC
286 if (!empty($this->security_head) && in_array('xmlrpc', $this->security_head)) {
287 // add_filter('xmlrpc_enabled', '__return_false');
288 add_filter('wp_xmlrpc_server_class', [$this, 'adminify_disable_wp_xmlrpc']);
289 }
290
291 // Remove WordPress Version Number
292 if (!empty($this->security_head) && in_array('generator_wp_version', $this->security_head)) {
293 remove_action('wp_head', 'wp_generator'); // Remove WordPress Generator Version
294 add_filter('the_generator', '__return_false'); // Remove Generator Name From Rss Feeds.
295 }
296
297 // Remove Revolution Slider generator version
298 if (!empty($this->security_head) && in_array('revslider_generator', $this->security_head)) {
299 add_filter('revslider_meta_generator', '__return_empty_string');
300 }
301
302 // Remove woocommerce generator version
303 if (!empty($this->security_head) && in_array('wc_generator', $this->security_head)) {
304 remove_action('wp_head', 'wc_generator_tag');
305 }
306
307 // Remove wpml meta generator tag
308 if (!empty($this->security_head) && in_array('wpml_generator', $this->security_head)) {
309 add_action('wp_head', [$this, 'remove_wpml_generator'], 0);
310 }
311
312 // Remove wpbakery visual_composer meta generator tag
313 if (!empty($this->security_head) && in_array('js_composer_generator', $this->security_head)) {
314 if (class_exists('Vc_Manager')) {
315 remove_action('wp_head', [visual_composer(), 'addMetaData'], 1);
316 }
317 }
318
319 // Remove Yoast SEO meta generator tag
320 if (!empty($this->security_head) && in_array('yoast_generator', $this->security_head)) {
321 add_filter('wpseo_debug_markers', '__return_false');
322 }
323
324 // REMOVE wlwmanifest.xml.
325 if (!empty($this->security_head) && in_array('wlwmanifest', $this->security_head)) {
326 remove_action('wp_head', 'wlwmanifest_link');
327 }
328
329 // Remove Really Simple Discovery Link.
330 if (!empty($this->security_head) && in_array('rsd', $this->security_head)) {
331 remove_action('wp_head', 'rsd_link');
332 }
333
334 // Remove Shortlink Url
335 if (!empty($this->security_head) && in_array('shortlink', $this->security_head)) {
336 remove_action('wp_head', 'wp_shortlink_wp_head');
337 remove_action('template_redirect', 'wp_shortlink_header', 100, 0);
338 }
339
340 /** Remove Version Query Strings from Scripts/Styles */
341 if (!empty($this->security_head) && in_array('canonical', $this->security_head)) {
342 remove_action('embed_head', 'rel_canonical');
343
344 // Function to remove the canonical URL
345 //
346
347 // Hook the function to wp_head
348 add_action('wp_head', [$this, 'remove_wp_canonical_url'] , 1);
349 // Yoast SEO Canonical URL
350 if (Utils::is_plugin_active('wordpress-seo/wp-seo.php')) {
351 add_filter('wpseo_canonical', '__return_false');
352 }
353 }
354
355
356 /* Disable Self Pings */
357 if (!empty($this->security_head) && in_array('self_ping', $this->security_head)) {
358 add_action('pre_ping', [$this, 'disable_self_ping']);
359 }
360
361 }
362
363 /**
364 * Disable XMLRPC file
365 *
366 * @return void
367 */
368 public function adminify_disable_wp_xmlrpc($data)
369 {
370 http_response_code(403);
371 }
372
373 /**
374 * Security Feed Links
375 *
376 * @return void
377 */
378 public function security_feed(){
379
380 // Remove Feed Links
381 if (!empty($this->security_feed)) {
382 remove_action('wp_head', 'feed_links_extra', 3); // Remove Every Extra Links to Rss Feeds.
383 remove_action('wp_head', 'feed_links', 2); // Remove Head link <head/>
384 remove_action('do_feed_rdf', 'do_feed_rdf', 10, 0);
385 remove_action('do_feed_rss', 'do_feed_rss', 10, 0);
386 remove_action('do_feed_rss2', 'do_feed_rss2', 10, 1);
387 remove_action('do_feed_atom', 'do_feed_atom', 10, 1);
388
389 // Redirect to Home
390 add_action('do_feed', [$this, 'redirect'], 1);
391 add_action('do_feed_rdf', [$this, 'redirect'], 1);
392 add_action('do_feed_rss', [$this, 'redirect'], 1);
393 add_action('do_feed_rss2', [$this, 'redirect'], 1);
394 add_action('do_feed_atom', [$this, 'redirect'], 1);
395
396 }
397 }
398
399
400
401 /*
402 * Change Howdy Text
403 */
404 public function adminify_change_howdy_text($wp_admin_bar)
405 {
406 // Remove Howdy Message entirely
407 if (!empty($this->options['white_label']['wordpress']['remove_howdy_msg'])) {
408
409 // Remove the entire "My Account" section and rebuild it later.
410 remove_action('admin_bar_menu', 'wp_admin_bar_my_account_item', 7);
411
412 $current_user = wp_get_current_user();
413 $user_id = get_current_user_id();
414 $profile_url = get_edit_profile_url($user_id);
415
416 $avatar = get_avatar($user_id, 26); // size 26x26 pixels
417 $display_name = $current_user->display_name;
418 $class = $avatar ? 'with-avatar' : 'no-avatar';
419 $wp_admin_bar->add_menu(array(
420 'id' => 'my-account',
421 'parent' => 'top-secondary',
422 'title' => $display_name . $avatar,
423 'href' => $profile_url,
424 'meta' => array(
425 'class' => $class,
426 ),
427 ));
428 }
429
430 // Change Howdy Text
431 if (!empty($this->options['white_label']['wordpress']['change_howdy_text'])) {
432
433 // Get the current user information
434 $my_account = $wp_admin_bar->get_node('my-account');
435
436 if (isset($my_account->title)) {
437
438 // Replace the "Howdy" text with "Welcome"
439 $changed_howdy_text = str_replace('Howdy', Utils::wp_kses_custom($this->options['white_label']['wordpress']['change_howdy_text']), $my_account->title);
440
441 // Update the node with the new title
442 $wp_admin_bar->add_node([
443 'id' => 'my-account',
444 'parent' => 'top-secondary',
445 'title' => $changed_howdy_text,
446 ]);
447 }
448
449 }
450 }
451
452 /**
453 * Remove Canonical URL
454 *
455 * @return void
456 */
457 public function remove_wp_canonical_url()
458 {
459 remove_action('wp_head', 'rel_canonical');
460 }
461
462 /**
463 * Removes admin bar logo from Admin Toolbar
464 */
465 public function admin_bar_cleanup()
466 {
467 global $wp_admin_bar;
468 //TODO: Check for Network wide site "my-sites"
469
470 if (in_array('wp_logo', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) {
471 $wp_admin_bar->remove_menu('wp-logo');
472 }
473 if (in_array('site_name', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) {
474 $wp_admin_bar->remove_menu('site-name');
475 }
476 if (in_array('comments', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) {
477 $wp_admin_bar->remove_menu('comments');
478 }
479 // if (in_array('menu_toggle', $this->options['white_label']['wordpress']['admin_bar_cleanup'])) {
480 // $wp_admin_bar->remove_menu('menu-toggle');
481 // }
482 }
483
484
485
486 // Clear the node titles
487 // This will only work if the node is using a :before element for the icon
488 public function clear_node_title($wp_admin_bar)
489 {
490 $all_toolbar_nodes = $wp_admin_bar->get_nodes();
491 // Create an array of node ID's we'd like to remove
492 $clear_titles = [
493 'site-name',
494 'customize',
495 ];
496
497 foreach ($all_toolbar_nodes as $node) {
498
499 // Run an if check to see if a node is in the array to clear_titles
500 if (in_array($node->id, $clear_titles)) {
501 // use the same node's properties
502 $args = $node;
503
504 // make the node title a blank string
505 $args->title = '';
506
507 // update the Toolbar node
508 $wp_admin_bar->add_node($args);
509 }
510 }
511 }
512
513 // Remove items from the admin bar
514 public function remove_from_admin_bar($wp_admin_bar)
515 {
516 /*
517 * Placing items in here will only remove them from admin bar
518 * when viewing the fronte end of the site
519 */
520 if (!is_admin()) {
521 // Example of removing item generated by plugin. Full ID is #wp-admin-bar-si_menu
522 $wp_admin_bar->remove_node('si_menu');
523
524 // WordPress Core Items (uncomment to remove)
525 $wp_admin_bar->remove_node('updates');
526 $wp_admin_bar->remove_node('comments');
527 $wp_admin_bar->remove_node('new-content');
528 // $wp_admin_bar->remove_node('wp-logo');
529 // $wp_admin_bar->remove_node('site-name');
530 $wp_admin_bar->remove_node('my-account');
531 // $wp_admin_bar->remove_node('search');
532 // $wp_admin_bar->remove_node('customize');
533 }
534
535 /*
536 * Items placed outside the if statement will remove it from both the frontend
537 * and backend of the site
538 */
539 $wp_admin_bar->remove_node('wp-logo');
540 }
541
542 // Custom Avatars
543 public function add_custom_gravatar_image($avatar_defaults)
544 {
545 // if (!empty($this->custom_gravatar) && array_key_exists('image', $this->custom_gravatar)) {
546 // foreach ($this->custom_gravatar['image'] as $key => $value) {
547 // $avatar_url = esc_url_raw($value['avatar_image']['url']);
548 // $avatar_defaults[$avatar_url] = $value['avatar_name'];
549 // }
550 // }
551 $custom_avatar_url = 'https://scontent.fzyl2-2.fna.fbcdn.net/v/t39.30808-6/348970682_781621106945149_5992028158112526767_n.jpg?_nc_cat=100&ccb=1-7&_nc_sid=cc71e4&_nc_ohc=gUNSZF2ODw8Q7kNvgG5T48V&_nc_ht=scontent.fzyl2-2.fna&oh=00_AYDLLCAW7eyeRQakH_Fy9R57hYPAekMNIcEHLGi12watcA&oe=66906465'; // Replace with your custom avatar URL
552 $avatar_defaults[$custom_avatar_url] = 'Custom Gravatar'; // Text to display in the avatar dropdown
553
554 return $avatar_defaults;
555 }
556
557 // Check Last Login Column
558 public function last_login_column_info( $user_login )
559 {
560 $user = get_user_by( 'login', $user_login );
561 // by username
562 update_user_meta( $user->ID, 'adminify_last_login_on', time() );
563 }
564
565
566 // Remove WPML Generator
567 public function remove_wpml_generator()
568 {
569 if (!empty($GLOBALS['sitepress'])) {
570 remove_action(current_filter(), [$GLOBALS['sitepress'], 'meta_generator_tag']);
571 }
572 }
573
574
575 /**
576 * Disable WP emojicons from TinyMCE
577 *
578 * @access public
579 * @since 1.0.0
580 * @return void
581 */
582 public function disable_emojicons_tinymce($plugins)
583 {
584 if (is_array($plugins)) {
585 return array_diff($plugins, ['wpemoji']);
586 } else {
587 return [];
588 }
589 }
590
591 /**
592 * Disable WP emojicons from TinyMCE
593 *
594 * @access public
595 * @since 1.0.0
596 * @return void
597 */
598 public function remove_dns_prefetch( $urls, $relation_type ) {
599 if ('dns-prefetch' == $relation_type) {
600 // Strip out any URLs referencing the WordPress.org emoji location
601 $emoji_svg_url_base = 'https://s.w.org/images/core/emoji/';
602 foreach ($urls as $key => $url) {
603 if (is_string($url) && false !== strpos($url, $emoji_svg_url_base)) {
604 unset($urls[$key]);
605 }
606 }
607 }
608 return $urls;
609 }
610
611 public function remove_powered()
612 {
613 if (function_exists('header_remove')) {
614 header_remove('X-Powered-By');
615 }
616 }
617
618
619
620 /**
621 * Remove all rewrite rules related to embeds.
622 *
623 * @param array $rules WordPress rewrite rules.
624 * @return array Rewrite rules without embeds rules.
625 */
626 public function adminify_disable_embeds_rewrites($rules)
627 {
628 foreach ($rules as $rule => $rewrite) {
629 if (false !== strpos($rewrite, 'embed=true')) {
630 unset($rules[$rule]);
631 }
632 }
633
634 return $rules;
635 }
636
637 // Redirect 403
638 public function redirect_to_403($url = false)
639 {
640 status_header(403); // Send an HTTP 403 Forbidden status header
641 die('403 Forbidden'); // End execution and display a 403 Forbidden message
642 }
643
644 // Redirect function
645 public function redirect($url = false)
646 {
647 if ($url) {
648 $target = $url;
649 } else {
650 $target = esc_url(home_url());
651 }
652
653 $target = apply_filters('wp_adminify_redirect_target', $target);
654 $status = apply_filters('wp_adminify_redirect_status', $this->redirect_status);
655
656 wp_redirect($target, $status);
657 die();
658 }
659
660
661 /* Add Featured Image or Post Thumbnail to RSS Feed */
662 public function jltwp_adminify_rss_post_thumbnail($content)
663 {
664 global $post;
665 if (has_post_thumbnail($post->ID)) {
666 $content = '<p>' . get_the_post_thumbnail($post->ID) .
667 '</p>' . get_the_content();
668 }
669 return $content;
670 }
671
672 // Display Last Updated Date of Your Posts
673 public function last_updated_date($content)
674 {
675 if (!is_single()) {
676 return $content;
677 }
678
679 $u_time = get_the_time('U');
680 $u_modified_time = get_the_modified_time('U');
681
682 if ($u_modified_time >= $u_time + 86400) {
683 $custom_content = sprintf(
684 __('<div class="wp-adminify-last-updated"><strong><span>%1$s</span></strong><span>%2$s %3$s</span></div>', 'adminify'),
685 esc_html__('Last Updated on ', 'adminify'),
686 get_the_modified_time('F jS, Y'),
687 get_the_modified_time('h:i a')
688 );
689 return $custom_content . $content;
690 }
691
692 return $content;
693 }
694
695 public function last_updated_date_style()
696 {
697 echo '<style>.wp-adminify-last-updated{ border: 1px dashed red; padding: 5px 10px;}</style>';
698 }
699
700
701 // Remove Default Image Links typeremove_image_link
702 public function security_attachment_imagelink()
703 {
704 $image_set = get_option('image_default_link_type');
705
706 if ($image_set !== 'none') {
707 update_option('image_default_link_type', 'none');
708 }
709 }
710
711
712 /* Disable Self Pings */
713 public function disable_self_ping(&$links)
714 {
715 $home = esc_url( home_url() );
716
717 // Additional URLs and explode into an array.
718 $extra_urls = (!empty($this->options['self_ping_sites'])) ? $this->options['self_ping_sites'] : '';
719 $extra_urls = explode(PHP_EOL, $extra_urls);
720
721 if ( is_array( $extra_urls ) ) {
722 $url_array = $extra_urls;
723 } else {
724 $url_array = array();
725 }
726
727 foreach ( $links as $l => $link ) {
728 if ( 0 === strpos( $link, $home ) ) {
729 unset( $links[ $l ] );
730 }
731 foreach ( $url_array as $url ) {
732 $url = trim( $url );
733 if ( 0 === strpos( $link, $url ) && '' !== $url ) {
734 unset( $links[ $l ] );
735 }
736 }
737 }
738
739 }
740
741
742 /** Remove Dashicons from Admin Bar for non logged in users **/
743 public function jltwp_adminify_remove_dashicons()
744 {
745 global $pagenow;
746
747 if (!is_user_logged_in()) {
748
749 // This retrieves the /path/file.php?param=val part of the URL
750 $current_request_uri = sanitize_text_field($_SERVER['REQUEST_URI']);
751
752 // for homepage
753 if (empty($current_request_uri)) {
754 wp_dequeue_style('dashicons');
755 wp_deregister_style('dashicons');
756 } else {
757 // Exclude the login page, where Dashicons assets are required for proper styling.
758 if (false !== strpos($current_request_uri, 'wp-login.php') || 'wp-login.php' === $pagenow) {
759 // Do nothing on wp-login.php
760 } elseif (false !== strpos($current_request_uri, 'protected-page=view')) {
761 // Exclude the password protection form.
762 // Do nothing on protected-page=view.
763 } else {
764 // Dequeue Dashicons from contents e.g., yoursite.com/content-url/. Not for wp-login.php,
765 wp_dequeue_style('dashicons');
766 wp_deregister_style('dashicons');
767 }
768 }
769 }
770 }
771
772
773 /** Control Interval Heartbeat API **/
774 public function control_heartbeat_api($settings)
775 {
776 $settings['interval'] = 60;
777 return $settings;
778 }
779
780 /** Remove Query Strings from Scripts/Styles **/
781 public function remove_script_versions($src)
782 {
783 if( !empty($src) ) {
784 $parts = explode('?ver', $src);
785 return $parts[0];
786 }
787 }
788
789 /** Browser Cache Expires & GZIP Compression **/
790 public function jltwp_adminify_htaccess()
791 {
792 // We get the main WordPress .htaccess filepath.
793 $ruta_htaccess = get_home_path() . '.htaccess'; // https://codex.wordpress.org/Function_Reference/get_home_path !
794
795 $lineas = [];
796 $lineas[] = '<IfModule mod_expires.c>';
797 $lineas[] = '# Activar caducidad de contenido';
798 $lineas[] = 'ExpiresActive On';
799 $lineas[] = '# Directiva de caducidad por defecto';
800 $lineas[] = 'ExpiresDefault "access plus 1 month"';
801 $lineas[] = '# Para el favicon';
802 $lineas[] = 'ExpiresByType image/x-icon "access plus 1 year"';
803 $lineas[] = '# Imagenes';
804 $lineas[] = 'ExpiresByType image/gif "access plus 1 month"';
805 $lineas[] = 'ExpiresByType image/png "access plus 1 month"';
806 $lineas[] = 'ExpiresByType image/jpg "access plus 1 month"';
807 $lineas[] = 'ExpiresByType image/jpeg "access plus 1 month"';
808 $lineas[] = '# CSS';
809 $lineas[] = 'ExpiresByType text/css "access 1 month"';
810 $lineas[] = '# Javascript';
811 $lineas[] = 'ExpiresByType application/javascript "access plus 1 year"';
812 $lineas[] = '</IfModule>';
813 $lineas[] = '<IfModule mod_deflate.c>';
814 $lineas[] = '# Activar compresión de contenidos estáticos';
815 $lineas[] = 'AddOutputFilterByType DEFLATE text/plain text/html';
816 $lineas[] = 'AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd';
817 $lineas[] = 'AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml';
818 $lineas[] = 'AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript';
819 $lineas[] = 'AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf';
820 $lineas[] = 'AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf';
821 $lineas[] = '</IfModule>';
822
823 insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ !
824 }
825
826
827 /**
828 * Performance Cleanup
829 *
830 * @access public
831 * @since 1.0.0
832 * @return void
833 */
834 public function adminify_performances()
835 {
836 $performance_data = $this->performance['performance_data'];
837
838 // Remove jQuery Migrate
839
840 // Remove Dashicons from Frontend
841 if (!empty($performance_data) && in_array('dashicons', $performance_data)) {
842 add_action('wp_print_styles', [$this, 'jltwp_adminify_remove_dashicons'], 100);
843 }
844
845 /** Remove Version Query Strings from Scripts/Styles */
846 if (!empty($performance_data) && in_array('version_strings', $performance_data)) {
847 if(!is_admin()){
848 add_filter('script_loader_src', [$this, 'remove_script_versions'], 15, 1);
849 add_filter('style_loader_src', [$this, 'remove_script_versions'], 15, 1);
850 }
851 }
852
853
854 // Remove Emoji Styles and Scripts
855 if (!empty($performance_data) && in_array('emoji', $performance_data)) {
856 remove_action('wp_head', 'print_emoji_detection_script', 7); // Remove Emoji's Styles and Scripts.
857 remove_action('embed_head', 'print_emoji_detection_script');
858 remove_action('embeded_head', 'print_emoji_detection_script');
859 remove_action('admin_print_scripts', 'print_emoji_detection_script'); // Remove Emoji's Styles and Scripts.
860 remove_action('wp_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts.
861 remove_action('admin_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts.
862 remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
863 remove_filter('the_content_feed', 'wp_staticize_emoji');
864 remove_filter('comment_text_rss', 'wp_staticize_emoji');
865 add_filter('option_use_smilies', '__return_false');
866 add_filter('emoji_svg_url', '__return_false');
867 add_action('admin_init', [$this, 'remove_admin_emojis']);
868 add_filter('tiny_mce_plugins', [$this, 'disable_emojicons_tinymce']);
869 add_filter('wp_resource_hints', [$this, 'remove_dns_prefetch'], 10, 2);
870 }
871
872
873
874 add_action('wp_default_scripts', [$this, 'remove_wp_default_scripts'], 9999);
875
876 /** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer */
877 if (in_array('defer_parsing_js_footer', $performance_data)) {
878 add_filter('script_loader_tag', [$this, 'defer_parsing_of_js'], 10, 2);
879 }
880
881 /** Browser Cache Expires & GZIP Compression */
882 if (in_array('cache_gzip_compression', $performance_data)) {
883 register_activation_hook(__FILE__, [$this, 'jltwp_adminify_htaccess']);
884 }
885
886
887 // Remove Gravatar Query Strings
888 if (!empty($performance_data) && in_array('gravatar_query_strings', $performance_data)) {
889 add_filter('get_avatar_url', [$this, 'remove_avatar_query_string']);
890 }
891 }
892
893 /* Remove Gravatar Query Strings */
894 public function remove_avatar_query_string($url)
895 {
896 $url_parts = explode('?', $url);
897 return $url_parts[0];
898 }
899
900
901 public function remove_admin_emojis()
902 {
903 remove_action('admin_print_scripts', 'print_emoji_detection_script');
904 remove_action('admin_print_styles', 'print_emoji_styles');
905 }
906
907
908 /** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer **/
909 public function defer_parsing_of_js($tag, $handle)
910 {
911 $skip = apply_filters('wp_adminify_defer_skip', false, $tag, $handle);
912
913 if ($skip) {
914 return $tag;
915 }
916
917 if (is_admin()) {
918 return $tag;
919 }
920 if (strpos($tag, '/wp-includes/js/jquery/jquery')) {
921 return $tag;
922 }
923 if (isset($_SERVER['HTTP_USER_AGENT']) && strpos(sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])), 'MSIE 9.') !== false) {
924 return $tag;
925 } else {
926 return str_replace(' src', ' defer src', $tag);
927 }
928 }
929
930 /**
931 * Remove jQuery Migrate Script
932 *
933 * @param [type] $scripts
934 *
935 * @return void
936 */
937 public function remove_wp_default_scripts($scripts)
938 {
939 // Frontend
940 if (!is_admin() && in_array('jquery_migrate_front', $this->performance['performance_data'])) {
941 $scripts->registered["jquery"]->deps = array_diff($scripts->registered["jquery"]->deps, ["jquery-migrate"]);
942 }
943
944 // Backend
945 if (is_admin() && in_array('jquery_migrate_back', $this->performance['performance_data'])) {
946 $scripts->registered["jquery"]->deps = array_diff($scripts->registered["jquery"]->deps, ["jquery-migrate"]);
947 }
948
949 }
950 }
951