mirror of
https://ghproxy.net/https://github.com/wearerequired/wp-cli-clear-opcache.git
synced 2026-02-23 22:14:01 +08:00
30 lines
663 B
PHP
30 lines
663 B
PHP
<?php
|
|
|
|
namespace Required\ClearOpcache;
|
|
|
|
function maybe_clear_cache() {
|
|
if ( isset( $_GET['opcache_action'], $_GET['opcache_nonce'] ) && 'clear-opcache' === $_GET['opcache_action'] ) {
|
|
$nonce = wp_verify_nonce( $_GET['opcache_nonce'], 'clear-opcache' );
|
|
|
|
if ( ! $nonce ) {
|
|
status_header( 400 );
|
|
die();
|
|
}
|
|
|
|
if ( isset( $_GET['opcache_script'] ) ) {
|
|
if ( opcache_invalidate( wp_unslash( $_GET['opcache_script'] ), isset( $_GET['opcache_force'] ) ) ) {
|
|
status_header( 202 );
|
|
} else {
|
|
status_header( 400 );
|
|
}
|
|
} else {
|
|
if ( opcache_reset() ) {
|
|
status_header( 202 );
|
|
} else {
|
|
status_header( 400 );
|
|
}
|
|
}
|
|
|
|
die();
|
|
}
|
|
}
|