PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.7
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.7
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Tweaks.php

Tweaks.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.1.7, at Inc/Classes/Tweaks.php

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