| @@ -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,11 +153,28 @@ | ||
| 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 | |
| @@ -186,8 +204,12 @@ | ||
| 186 | 204 | * @since 2.0 |
| 187 | 205 | */ |
| 188 | 206 | function block_editor_assets() { |
| 189 | 207 | |
| 208 | + if ( ! current_user_can( 'edit_others_posts' ) ) { | |
| 209 | + return; | |
| 210 | + } | |
| 211 | + | |
| 190 | 212 | /** |
| 191 | 213 | * Min. WP 5.3 required for block editor plugin due to useSelect |
| 192 | 214 | * Likely the older version of react didn't support hooks. |
| 193 | 215 | * The post meta-box works with compat mode vice-versa... |
| @@ -283,5 +305,6 @@ | ||
| 283 | 305 | * Invoke async classes |
| 284 | 306 | */ |
| 285 | 307 | function register_async_process() { |
| 286 | 308 | DatabaseOptimizer::factory(); |
| 309 | + CachePurger::factory(); | |
| 287 | 310 | } |