Skip to content

Commit d7b59c6

Browse files
authored
Updates
1 parent fdc4061 commit d7b59c6

File tree

2 files changed

+95
-26
lines changed

2 files changed

+95
-26
lines changed

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Requires at least: 6.5
55
Tested up to: 6.8
66
Stable tag: 1.6.0
77
Requires PHP: 7.4
8-
License: GPLv2 or later
8+
License: GPLv3 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

1111
Optimizes WordPress by removing unnecessary features and scripts to improve performance.

simple-wp-optimizer.php

Lines changed: 94 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Optimizes WordPress by removing unnecessary features and scripts to improve performance
66
* Version: 1.6.0
77
* Author: EngineScript
8-
* License: GPL v2 or later
8+
* License: GPL-3.0-or-later
99
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
* Text Domain: simple-wp-optimizer
1111
* Requires at least: 6.5
@@ -56,6 +56,98 @@
5656
define( 'ES_WP_OPTIMIZER_VERSION', '1.6.0' );
5757
}
5858

59+
/**
60+
* Initialize the Simple WP Optimizer plugin
61+
*
62+
* This function is hooked to 'plugins_loaded' to ensure all other plugins
63+
* have been loaded first, preventing potential conflicts and ensuring
64+
* WordPress core functions and other plugin APIs are available.
65+
*
66+
* @since 1.6.0
67+
*/
68+
function es_optimizer_init_plugin() {
69+
// Clear options cache to ensure fresh data after all plugins are loaded
70+
es_optimizer_clear_options_cache();
71+
72+
// Initialize admin functionality
73+
es_optimizer_init_admin();
74+
75+
// Initialize frontend optimizations
76+
es_optimizer_init_frontend_optimizations();
77+
78+
// Initialize plugin settings link
79+
es_optimizer_init_plugin_links();
80+
}
81+
add_action( 'plugins_loaded', 'es_optimizer_init_plugin' );
82+
83+
/**
84+
* Plugin activation hook
85+
*
86+
* @since 1.6.0
87+
*/
88+
function es_optimizer_activate_plugin() {
89+
// Ensure default options are set on activation
90+
if ( false === get_option( 'es_optimizer_options' ) ) {
91+
add_option( 'es_optimizer_options', es_optimizer_get_default_options() );
92+
}
93+
94+
// Clear any cached data
95+
es_optimizer_clear_options_cache();
96+
}
97+
register_activation_hook( __FILE__, 'es_optimizer_activate_plugin' );
98+
99+
/**
100+
* Plugin deactivation hook
101+
*
102+
* @since 1.6.0
103+
*/
104+
function es_optimizer_deactivate_plugin() {
105+
// Clear any cached data on deactivation
106+
es_optimizer_clear_options_cache();
107+
108+
// Note: We don't delete options on deactivation to preserve user settings
109+
// Options are only deleted on plugin uninstall
110+
}
111+
register_deactivation_hook( __FILE__, 'es_optimizer_deactivate_plugin' );
112+
113+
/**
114+
* Initialize admin-related functionality
115+
*
116+
* @since 1.6.0
117+
*/
118+
function es_optimizer_init_admin() {
119+
if ( is_admin() ) {
120+
add_action( 'admin_init', 'es_optimizer_init_settings' );
121+
add_action( 'admin_menu', 'es_optimizer_add_settings_page' );
122+
}
123+
}
124+
125+
/**
126+
* Initialize frontend optimization functionality
127+
*
128+
* @since 1.6.0
129+
*/
130+
function es_optimizer_init_frontend_optimizations() {
131+
add_action( 'init', 'disable_emojis' );
132+
add_action( 'wp_default_scripts', 'remove_jquery_migrate' );
133+
add_action( 'wp_enqueue_scripts', 'disable_classic_theme_styles', 100 );
134+
add_action( 'init', 'remove_header_items' );
135+
add_action( 'init', 'remove_recent_comments_style' );
136+
add_action( 'wp_head', 'add_dns_prefetch', 0 );
137+
add_action( 'init', 'disable_jetpack_ads' );
138+
add_action( 'init', 'disable_post_via_email' );
139+
}
140+
141+
/**
142+
* Initialize plugin action links
143+
*
144+
* @since 1.6.0
145+
*/
146+
function es_optimizer_init_plugin_links() {
147+
$plugin_basename = plugin_basename( __FILE__ );
148+
add_filter( "plugin_action_links_{$plugin_basename}", 'es_optimizer_add_settings_link' );
149+
}
150+
59151
/**
60152
* Initialize the plugin settings
61153
*
@@ -77,7 +169,6 @@ function es_optimizer_init_settings() {
77169
add_option( 'es_optimizer_options', es_optimizer_get_default_options() );
78170
}
79171
}
80-
add_action( 'admin_init', 'es_optimizer_init_settings' );
81172

82173
/**
83174
* Get default plugin options
@@ -160,17 +251,6 @@ function es_optimizer_add_settings_page() {
160251
}
161252
// Only enqueue scripts/styles if we're on the plugin settings page.
162253
}
163-
add_action( 'admin_menu', 'es_optimizer_add_settings_page' );
164-
165-
/**
166-
* Load admin assets only on plugin settings page
167-
*
168-
* @since 1.5.13
169-
*/
170-
function es_optimizer_load_admin_assets() {
171-
// Only enqueue scripts/styles if we're on the plugin settings page.
172-
add_action( 'admin_enqueue_scripts', 'es_optimizer_enqueue_admin_scripts' );
173-
}
174254

175255
/**
176256
* Enqueue admin scripts and styles for plugin settings page
@@ -697,7 +777,6 @@ function disable_emojis() {
697777
// Remove emoji DNS prefetch.
698778
add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
699779
}
700-
add_action( 'init', 'disable_emojis' );
701780

702781
/**
703782
* Add settings link to plugins page
@@ -713,8 +792,6 @@ function es_optimizer_add_settings_link( $links ) {
713792
array_unshift( $links, $settings_link );
714793
return $links;
715794
}
716-
$plugin_basename = plugin_basename( __FILE__ );
717-
add_filter( "plugin_action_links_{$plugin_basename}", 'es_optimizer_add_settings_link' );
718795

719796
/**
720797
* Filter function used to remove the tinymce emoji plugin.
@@ -770,7 +847,6 @@ function remove_jquery_migrate( $scripts ) {
770847
}
771848
}
772849
}
773-
add_action( 'wp_default_scripts', 'remove_jquery_migrate' );
774850

775851
/**
776852
* Disable classic-themes css added in WP 6.1
@@ -788,7 +864,6 @@ function disable_classic_theme_styles() {
788864
wp_deregister_style( 'classic-theme-styles' );
789865
wp_dequeue_style( 'classic-theme-styles' );
790866
}
791-
add_action( 'wp_enqueue_scripts', 'disable_classic_theme_styles', 100 );
792867

793868
/**
794869
* Remove WordPress version, WLW manifest, and shortlink.
@@ -813,7 +888,6 @@ function remove_header_items() {
813888
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 );
814889
}
815890
}
816-
add_action( 'init', 'remove_header_items' );
817891

818892
/**
819893
* Remove Recent Comments Widget CSS Styles.
@@ -826,7 +900,6 @@ function remove_recent_comments_style() {
826900
add_filter( 'show_recent_comments_widget_style', '__return_false', PHP_INT_MAX );
827901
}
828902
}
829-
add_action( 'init', 'remove_recent_comments_style' );
830903

831904
/**
832905
* Add DNS prefetching for common external domains.
@@ -890,8 +963,6 @@ function add_dns_prefetch() {
890963
}
891964
}
892965
}
893-
// Hook after wp_head and before other elements are added.
894-
add_action( 'wp_head', 'add_dns_prefetch', 0 );
895966

896967
/**
897968
* Disable Jetpack advertisements.
@@ -906,7 +977,6 @@ function disable_jetpack_ads() {
906977
add_filter( 'jetpack_blaze_enabled', '__return_false', PHP_INT_MAX );
907978
}
908979
}
909-
add_action( 'init', 'disable_jetpack_ads' );
910980

911981
/**
912982
* Disable WordPress post via email functionality.
@@ -918,5 +988,4 @@ function disable_post_via_email() {
918988
if ( isset( $options['disable_post_via_email'] ) && $options['disable_post_via_email'] ) {
919989
add_filter( 'enable_post_by_email_configuration', '__return_false', PHP_INT_MAX );
920990
}
921-
}
922-
add_action( 'init', 'disable_post_via_email' );
991+
}

0 commit comments

Comments
 (0)