PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / trunk
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score vtrunk
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
← All changes | includes/core.php +47 -8 2.0trunk View file →
@@ -7,8 +7,9 @@
7 7
8 8 namespace PoweredCache\Core;
9 9
10 10 use PoweredCache\Async\CachePreloader;
11 +use PoweredCache\Async\CachePurger;
11 12 use PoweredCache\Async\DatabaseOptimizer;
12 13 use PoweredCache\Config;
13 14 use const PoweredCache\Constants\DB_CLEANUP_COUNT_CACHE_KEY;
14 15 use const PoweredCache\Constants\MENU_SLUG;
@@ -110,9 +111,9 @@
110 111 *
111 112 * @return array
112 113 */
113 114 function get_enqueue_contexts() {
114 - return [ 'admin', 'frontend', 'shared' ];
115 + return [ 'admin', 'frontend', 'shared', 'classic-editor' ];
115 116 }
116 117
117 118 /**
118 119 * Generate an URL to a script, taking into account whether SCRIPT_DEBUG is enabled.
@@ -127,9 +128,9 @@
127 128 if ( ! in_array( $context, get_enqueue_contexts(), true ) ) {
128 129 return new WP_Error( 'invalid_enqueue_context', 'Invalid $context specified in PoweredCache script loader.' );
129 130 }
130 131
131 - return POWERED_CACHE_URL . "dist/js/${script}.js";
132 + return POWERED_CACHE_URL . "dist/js/{$script}.js";
132 133
133 134 }
134 135
135 136 /**
@@ -145,9 +146,9 @@
145 146 if ( ! in_array( $context, get_enqueue_contexts(), true ) ) {
146 147 return new WP_Error( 'invalid_enqueue_context', 'Invalid $context specified in PoweredCache stylesheet loader.' );
147 148 }
148 149
149 - return POWERED_CACHE_URL . "dist/css/${stylesheet}.css";
150 + return POWERED_CACHE_URL . "dist/css/{$stylesheet}.css";
150 151
151 152 }
152 153
153 154 /**
@@ -152,17 +153,34 @@
152 153
153 154 /**
154 155 * Enqueue scripts for admin.
155 156 *
157 + * @param string $hook Current hook.
158 + *
156 159 * @return void
157 160 */
158 -function admin_scripts() {
161 +function admin_scripts( $hook ) {
162 +
163 + $classic_editor_hooks = [ 'post-new.php', 'post.php' ];
164 +
165 + if ( in_array( $hook, $classic_editor_hooks, true ) ) {
166 + wp_enqueue_script(
167 + 'powered-cache-classic-editor',
168 + script_url( 'classic-editor', 'classic-editor' ),
169 + [
170 + 'jquery',
171 + ],
172 + POWERED_CACHE_VERSION,
173 + true
174 + );
175 + }
176 +
159 177 if ( empty( $_GET['page'] ) || MENU_SLUG !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
160 178 return;
161 179 }
162 180
163 181 wp_enqueue_script(
164 - 'powered_cache_admin',
182 + 'powered-cache-admin',
165 183 script_url( 'admin', 'admin' ),
166 184 [
167 185 'jquery',
168 186 'lodash',
@@ -170,8 +188,15 @@
170 188 ],
171 189 POWERED_CACHE_VERSION,
172 190 true
173 191 );
192 +
193 + wp_set_script_translations(
194 + 'powered-cache-admin',
195 + 'powered-cache',
196 + plugin_dir_path( POWERED_CACHE_PLUGIN_FILE ) . 'languages'
197 + );
198 +
174 199 }
175 200
176 201 /**
177 202 * Enqueue Block Editor assets
@@ -179,8 +204,12 @@
179 204 * @since 2.0
180 205 */
181 206 function block_editor_assets() {
182 207
208 + if ( ! current_user_can( 'edit_others_posts' ) ) {
209 + return;
210 + }
211 +
183 212 /**
184 213 * Min. WP 5.3 required for block editor plugin due to useSelect
185 214 * Likely the older version of react didn't support hooks.
186 215 * The post meta-box works with compat mode vice-versa...
@@ -185,10 +214,10 @@
185 214 * Likely the older version of react didn't support hooks.
186 215 * The post meta-box works with compat mode vice-versa...
187 216 */
188 217 if ( version_compare( get_bloginfo( 'version' ), '5.3', '>=' ) ) {
189 - wp_enqueue_script(
190 - 'powered_cache_admin',
218 + wp_register_script(
219 + 'powered-cache-editor',
191 220 script_url( 'editor', 'admin' ),
192 221 [
193 222 'jquery',
194 223 'lodash',
@@ -203,8 +232,17 @@
203 232 ],
204 233 POWERED_CACHE_VERSION,
205 234 true
206 235 );
236 +
237 + wp_enqueue_script( 'powered-cache-editor' );
238 +
239 + wp_set_script_translations(
240 + 'powered-cache-editor',
241 + 'powered-cache',
242 + plugin_dir_path( POWERED_CACHE_PLUGIN_FILE ) . 'languages'
243 + );
244 +
207 245 }
208 246 }
209 247
210 248 /**
@@ -218,9 +256,9 @@
218 256 return;
219 257 }
220 258
221 259 wp_enqueue_style(
222 - 'powered_cache_admin',
260 + 'powered-cache-admin',
223 261 style_url( 'admin-style', 'admin' ),
224 262 [],
225 263 POWERED_CACHE_VERSION
226 264 );
@@ -267,5 +305,6 @@
267 305 * Invoke async classes
268 306 */
269 307 function register_async_process() {
270 308 DatabaseOptimizer::factory();
309 + CachePurger::factory();
271 310 }