22/*
33Plugin Name: WP Optimization (EngineScript)
44Description: Optimizes WordPress by removing unnecessary features and scripts
5- Version: 1.1 .0
5+ Version: 1.2 .0
66Author: EngineScript
77License: GPL v2 or later
88*/
99
10- // Define plugin constants
11- define ('WP_OPTIMIZATION_VERSION ' , '1.1.0 ' );
12- define ('WP_OPTIMIZATION_FILE ' , __FILE__ );
13- define ('WP_OPTIMIZATION_PATH ' , plugin_dir_path (__FILE__ ));
14-
1510// Prevent direct access
1611if (!defined ('ABSPATH ' )) {
1712 exit ('No direct script access allowed ' );
1813}
1914
20- class WP_Optimization {
21- private static $ instance = null ;
22-
23- /**
24- * Get plugin instance
25- */
26- public static function get_instance () {
27- if (null === self ::$ instance ) {
28- self ::$ instance = new self ();
29- }
30- return self ::$ instance ;
31- }
15+ /**
16+ * Disable the emoji's
17+ */
18+ function disable_emojis () {
19+ remove_action ('wp_head ' , 'print_emoji_detection_script ' , 7 );
20+ remove_action ('admin_print_scripts ' , 'print_emoji_detection_script ' );
21+ remove_action ('wp_print_styles ' , 'print_emoji_styles ' );
22+ remove_action ('admin_print_styles ' , 'print_emoji_styles ' );
23+ remove_filter ('the_content_feed ' , 'wp_staticize_emoji ' );
24+ remove_filter ('comment_text_rss ' , 'wp_staticize_emoji ' );
25+ remove_filter ('wp_mail ' , 'wp_staticize_emoji_for_email ' );
26+ add_filter ('tiny_mce_plugins ' , 'disable_emojis_tinymce ' );
27+ add_filter ('wp_resource_hints ' , 'disable_emojis_remove_dns_prefetch ' , 10 , 2 );
28+ }
29+ add_action ('init ' , 'disable_emojis ' );
3230
33- /**
34- * Private constructor to prevent direct creation
35- */
36- private function __construct () {
37- // Initialize plugin
38- add_action ('init ' , [$ this , 'disable_emojis ' ]);
39- add_action ('wp_default_scripts ' , [$ this , 'remove_jquery_migrate ' ]);
40- add_filter ('wp_enqueue_scripts ' , [$ this , 'disable_classic_theme_styles ' ], 100 );
41-
42- // Remove header items
43- remove_action ('wp_head ' , 'wp_generator ' );
44- remove_action ('wp_head ' , 'wlwmanifest_link ' );
45- remove_action ('wp_head ' , 'wp_shortlink_wp_head ' , 10 , 0 );
46- remove_action ('wp_head ' , 'rest_output_link_wp_head ' );
47- remove_action ('wp_head ' , 'wp_oembed_add_discovery_links ' );
48- remove_action ('wp_head ' , 'rsd_link ' );
49-
50- // Disable widget styles and Jetpack ads
51- add_filter ('show_recent_comments_widget_style ' , '__return_false ' , 99 );
52-
53- // Only add Jetpack filters if active
54- if ($ this ->is_jetpack_active ()) {
55- add_filter ('jetpack_just_in_time_msgs ' , '__return_false ' , 20 );
56- add_filter ('jetpack_show_promotions ' , '__return_false ' , 20 );
57- add_filter ('jetpack_blaze_enabled ' , '__return_false ' );
58- }
31+ /**
32+ * Filter function used to remove the tinymce emoji plugin.
33+ *
34+ * @param array $plugins
35+ * @return array Difference betwen the two arrays
36+ */
37+ function disable_emojis_tinymce ($ plugins ) {
38+ if (is_array ($ plugins )) {
39+ return array_diff ($ plugins , array ('wpemoji ' ));
5940 }
41+ return array ();
42+ }
6043
61- /**
62- * Check if Jetpack is active
63- */
64- private function is_jetpack_active () {
65- return class_exists ('Jetpack ' );
44+ /**
45+ * Remove emoji CDN hostname from DNS prefetching hints.
46+ *
47+ * @param array $urls URLs to print for resource hints.
48+ * @param string $relation_type The relation type the URLs are printed for.
49+ * @return array Difference betwen the two arrays.
50+ */
51+ function disable_emojis_remove_dns_prefetch ($ urls , $ relation_type ) {
52+ if ('dns-prefetch ' == $ relation_type ) {
53+ $ emoji_svg_url = apply_filters ('emoji_svg_url ' , 'https://s.w.org/images/core/emoji/2/svg/ ' );
54+ $ urls = array_diff ($ urls , array ($ emoji_svg_url ));
6655 }
56+ return $ urls ;
57+ }
6758
68- /**
69- * Disable the emoji's
70- */
71- public function disable_emojis () {
72- remove_action ('wp_head ' , 'print_emoji_detection_script ' , 7 );
73- remove_action ('admin_print_scripts ' , 'print_emoji_detection_script ' );
74- remove_action ('wp_print_styles ' , 'print_emoji_styles ' );
75- remove_action ('admin_print_styles ' , 'print_emoji_styles ' );
76- remove_filter ('the_content_feed ' , 'wp_staticize_emoji ' );
77- remove_filter ('comment_text_rss ' , 'wp_staticize_emoji ' );
78- remove_filter ('wp_mail ' , 'wp_staticize_emoji_for_email ' );
79- add_filter ('tiny_mce_plugins ' , [$ this , 'disable_emojis_tinymce ' ]);
80- add_filter ('wp_resource_hints ' , [$ this , 'disable_emojis_remove_dns_prefetch ' ], 10 , 2 );
59+ /**
60+ * Remove JQuery Migrate
61+ */
62+ function remove_jquery_migrate ($ scripts ) {
63+ if (!is_admin () && isset ($ scripts ->registered ['jquery ' ])) {
64+ $ script = $ scripts ->registered ['jquery ' ];
65+ if ($ script ->deps ) {
66+ $ script ->deps = array_diff ($ script ->deps , array ('jquery-migrate ' ));
67+ }
8168 }
69+ }
70+ add_action ('wp_default_scripts ' , 'remove_jquery_migrate ' );
8271
83- /**
84- * Filter function used to remove the tinymce emoji plugin.
85- *
86- * @param array $plugins
87- * @return array Difference between the two arrays
88- */
89- public function disable_emojis_tinymce ($ plugins ) {
90- return is_array ($ plugins ) ? array_diff ($ plugins , ['wpemoji ' ]) : [];
91- }
72+ /**
73+ * Disable classic-themes css added in WP 6.1
74+ */
75+ function disable_classic_theme_styles () {
76+ wp_deregister_style ('classic-theme-styles ' );
77+ wp_dequeue_style ('classic-theme-styles ' );
78+ }
79+ add_filter ('wp_enqueue_scripts ' , 'disable_classic_theme_styles ' , 100 );
9280
93- /**
94- * Remove emoji CDN hostname from DNS prefetching hints.
95- *
96- * @param array $urls URLs to print for resource hints.
97- * @param string $relation_type The relation type the URLs are printed for.
98- * @return array Difference between the two arrays.
99- */
100- public function disable_emojis_remove_dns_prefetch ($ urls , $ relation_type ) {
101- if ('dns-prefetch ' == $ relation_type ) {
102- $ emoji_svg_url = apply_filters ('emoji_svg_url ' , 'https://s.w.org/images/core/emoji/2/svg/ ' );
103- $ urls = array_diff ($ urls , [$ emoji_svg_url ]);
104- }
105- return $ urls ;
106- }
81+ // Remove WordPress Version from Header
82+ remove_action ('wp_head ' , 'wp_generator ' );
10783
108- /**
109- * Remove JQuery Migrate
110- */
111- public function remove_jquery_migrate ($ scripts ) {
112- if (!is_admin () && isset ($ scripts ->registered ['jquery ' ])) {
113- $ script = $ scripts ->registered ['jquery ' ];
114- if ($ script ->deps ) {
115- $ script ->deps = array_diff ($ script ->deps , ['jquery-migrate ' ]);
116- }
117- }
118- }
84+ // Remove Windows Live Writer Manifest
85+ remove_action ('wp_head ' , 'wlwmanifest_link ' );
11986
120- /**
121- * Disable classic-themes css added in WP 6.1
122- */
123- public function disable_classic_theme_styles () {
124- wp_deregister_style ('classic-theme-styles ' );
125- wp_dequeue_style ('classic-theme-styles ' );
126- }
87+ // Remove WP Shortlink URLs
88+ remove_action ('wp_head ' , 'wp_shortlink_wp_head ' , 10 , 0 );
12789
128- // Prevent cloning
129- private function __clone () {}
130-
131- // Prevent unserialize
132- private function __wakeup () {}
133- }
90+ // Remove Recent Comments Widget CSS Styles
91+ add_filter ('show_recent_comments_widget_style ' , '__return_false ' , 99 );
13492
135- // Initialize using singleton
136- WP_Optimization::get_instance ();
93+ // Remove Jetpack Advertisements
94+ add_filter ('jetpack_just_in_time_msgs ' , '__return_false ' , 20 );
95+ add_filter ('jetpack_show_promotions ' , '__return_false ' , 20 );
96+ add_filter ('jetpack_blaze_enabled ' , '__return_false ' );
0 commit comments