| 1 |
<?php |
| 2 |
|
| 3 |
namespace FlyWP\Admin; |
| 4 |
|
| 5 |
use FlyWP\Admin; |
| 6 |
|
| 7 |
class Opcache { |
| 8 |
|
| 9 |
/** |
| 10 |
* Class constructor. |
| 11 |
*/ |
| 12 |
public function __construct() { |
| 13 |
add_action( 'load-' . Admin::SCREEN_NAME, [ $this, 'handle_cleanup' ] ); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Handle cache cleanup. |
| 18 |
* |
| 19 |
* @return void |
| 20 |
*/ |
| 21 |
public function handle_cleanup() { |
| 22 |
if ( ! isset( $_GET['flywp-action'] ) || 'purge-opcache' !== $_GET['flywp-action'] ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'fly-opcache-purge' ) ) { |
| 27 |
wp_die( __( 'Nonce verification failed.', 'flywp' ) ); |
| 28 |
} |
| 29 |
|
| 30 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 31 |
wp_die( __( 'You do not have permission to purge the opcache.', 'flywp' ) ); |
| 32 |
} |
| 33 |
|
| 34 |
flywp()->opcache->clear(); |
| 35 |
|
| 36 |
wp_safe_redirect( admin_url( 'index.php?page=flywp&fly-notice=opcache-purged' ) ); |
| 37 |
exit; |
| 38 |
} |
| 39 |
} |
| 40 |
|