PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.2
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.2
1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 1.5.1 All 26 releases
flywp / includes / Optimizations / General.php

General.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 1.2, at includes/Optimizations/General.php

156 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP\Optimizations;
4
5 class General extends Base {
6
7 /**
8 * Group name
9 *
10 * @var string
11 */
12 protected $group = 'general';
13
14 /**
15 * Features to remove.
16 *
17 * @var array
18 */
19 protected $features = [
20 'emoji' => 'remove_emoji',
21 'oembed' => 'remove_embed',
22 'self_ping' => 'disable_self_ping',
23 'comments' => 'disable_comments',
24 'jquery_migrate' => 'remove_jquery_migrate',
25 'clean_nav_menu' => 'clean_nav_menu',
26 'rss_feed' => 'remove_rss_feed',
27 'xmlrpc' => 'remove_xmlrpc',
28 ];
29
30 /**
31 * Remove emoji scripts.
32 *
33 * @return void
34 */
35 public function remove_emoji() {
36 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
37 remove_action( 'wp_print_styles', 'print_emoji_styles' );
38 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
39 remove_action( 'admin_print_styles', 'print_emoji_styles' );
40 remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
41 remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
42 remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
43
44 add_filter( 'emoji_svg_url', '__return_false' );
45
46 // Remove from TinyMCE
47 add_filter( 'tiny_mce_plugins', function ( $plugins ) {
48 return is_array( $plugins ) ? array_diff( $plugins, [ 'wpemoji' ] ) : [];
49 } );
50 }
51
52 /**
53 * Remove embed scripts.
54 *
55 * @return void
56 */
57 public function remove_embed() {
58 remove_action( 'wp_head', 'wp_oembed_add_host_js' );
59 remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
60 remove_action( 'rest_api_init', 'wp_oembed_register_route' );
61
62 add_filter( 'embed_oembed_discover', '__return_false' );
63 remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result' );
64 }
65
66 /**
67 * Disable self ping.
68 *
69 * @return void
70 */
71 public function disable_self_ping() {
72 add_action( 'pre_ping', function ( &$links ) {
73 $home = get_option( 'home' );
74
75 foreach ( $links as $l => $link ) {
76 if ( 0 === strpos( $link, $home ) ) {
77 unset( $links[ $l ] );
78 }
79 }
80 } );
81 }
82
83 /**
84 * Disable comments.
85 *
86 * @return void
87 */
88 public function disable_comments() {
89 add_filter( 'comments_open', '__return_false', 20, 2 );
90 add_filter( 'pings_open', '__return_false', 20, 2 );
91
92 // Remove comments feed
93 add_filter( 'feed_links_show_comments_feed', '__return_false' );
94 add_filter( 'post_comments_feed_link', '__return_false' );
95 add_filter( 'comments_link_feed', '__return_false' );
96 }
97
98 /**
99 * Remove jQuery Migrate.
100 *
101 * @return void
102 */
103 public function remove_jquery_migrate() {
104 add_action( 'wp_default_scripts', function ( $scripts ) {
105 if ( isset( $scripts->registered['jquery'] ) ) {
106 $script = $scripts->registered['jquery'];
107
108 if ( $script->deps ) {
109 $script->deps = array_diff( $script->deps, [ 'jquery-migrate' ] );
110 }
111 }
112 } );
113 }
114
115 /**
116 * Clean navigation menu.
117 *
118 * @return void
119 */
120 public function clean_nav_menu() {
121 add_filter( 'nav_menu_css_class', function ( $classes ) {
122 return array_intersect( $classes, [
123 'current-menu-item',
124 'menu-item-has-children',
125 'menu-item',
126 'current-menu-ancestor',
127 ] );
128 } );
129
130 add_filter( 'nav_menu_item_id', '__return_null' );
131 }
132
133 /**
134 * Remove RSS feed links.
135 *
136 * @return void
137 */
138 public function remove_rss_feed() {
139 add_action( 'template_redirect', function () {
140 if ( is_feed() ) {
141 wp_redirect( home_url(), 301 );
142 exit;
143 }
144 }, 1 );
145 }
146
147 /**
148 * Remove XML-RPC.
149 *
150 * @return void
151 */
152 public function remove_xmlrpc() {
153 add_filter( 'xmlrpc_enabled', '__return_false' );
154 }
155 }
156