first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Delete_Cache extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Get a collection of items
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
$params = $request->get_json_params();
|
||||
|
||||
if ( isset( $params['id'] ) && is_numeric( $params['id'] ) ) {
|
||||
wpsc_delete_post_cache( $params['id'] );
|
||||
|
||||
} elseif ( !empty( $params['expired'] ) ) {
|
||||
global $file_prefix;
|
||||
wp_cache_clean_expired( $file_prefix );
|
||||
|
||||
} elseif ( isset( $params['url'] ) ) {
|
||||
global $cache_path;
|
||||
|
||||
$directory = $cache_path . 'supercache/' . $params[ 'url' ];
|
||||
wpsc_delete_files( $directory );
|
||||
prune_super_cache( $directory . '/page', true );
|
||||
|
||||
} else {
|
||||
global $file_prefix;
|
||||
wp_cache_clean_cache( $file_prefix, !empty( $params['all'] ) );
|
||||
}
|
||||
|
||||
return rest_ensure_response( array( 'Cache Cleared' => true ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Get_Cache extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Get a collection of items
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
global $valid_nonce;
|
||||
|
||||
$valid_nonce = true;
|
||||
$_GET[ 'listfiles' ] = 1;
|
||||
$sizes = wpsc_generate_sizes_array();
|
||||
$supercachedir = get_supercache_dir();
|
||||
$list = wpsc_dirsize( $supercachedir, $sizes );
|
||||
$return_list = array();
|
||||
|
||||
foreach( $list as $type => $file_list ) {
|
||||
foreach ( $file_list as $state => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
foreach( $value as $filenames ) {
|
||||
foreach( $filenames as $filename => $t ) {
|
||||
if ( $type == 'wpcache' ) {
|
||||
$filename = dirname( $filename );
|
||||
}
|
||||
if ( false == isset( $return_list[ $type ][ $state ] ) || false == in_array( $filename, $return_list[ $type ][ $state ] ) )
|
||||
$return_list[ $type ][ $state ][] = $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset ( $return_list[ $type ] ) ) {
|
||||
$list[ $type ] = $return_list[ $type ];
|
||||
}
|
||||
|
||||
unset( $return_list[ $type ] );
|
||||
}
|
||||
|
||||
return rest_ensure_response( $list );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Get_Plugins extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* GET a list of plugins through the /plugins/ endpoint
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
|
||||
$list = wpsc_get_plugin_list();
|
||||
return rest_ensure_response( $list );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-settings-map.php' );
|
||||
|
||||
class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Get the settings.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
$settings = array();
|
||||
|
||||
global $wp_cache_config_file;
|
||||
|
||||
if ( defined( 'WPLOCKDOWN' ) ) {
|
||||
$config_file = file_get_contents( $wp_cache_config_file );
|
||||
if ( false === strpos( $config_file, "defined( 'WPLOCKDOWN' )" ) ) {
|
||||
wp_cache_replace_line( '^.*WPLOCKDOWN', "if ( ! defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', " . $this->get_is_lock_down_enabled() . " );", $wp_cache_config_file );
|
||||
}
|
||||
}
|
||||
|
||||
if ( function_exists( "opcache_invalidate" ) ) {
|
||||
@opcache_invalidate( $wp_cache_config_file );
|
||||
}
|
||||
include( $wp_cache_config_file );
|
||||
|
||||
foreach ( WP_Super_Cache_Settings_Map::$map as $name => $map ) {
|
||||
if ( isset ( $map['get'] ) ) {
|
||||
$get_method = $map['get'];
|
||||
|
||||
if ( method_exists( $this, $get_method ) ) {
|
||||
$settings[ $name ] = $this->$get_method();
|
||||
|
||||
} elseif ( function_exists( $get_method ) ) {
|
||||
$settings[ $name ] = $get_method();
|
||||
}
|
||||
|
||||
} else if ( isset ( $map['option'] ) ) {
|
||||
$settings[ $name ] = get_option( $map['option'] );
|
||||
|
||||
} elseif ( isset( $map['global'] ) ) {
|
||||
if ( false == isset( $GLOBALS[ $map[ 'global' ] ] ) ) {
|
||||
$settings[ $name ] = false;
|
||||
} else {
|
||||
$settings[ $name ] = $GLOBALS[ $map[ 'global' ] ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->prepare_item_for_response( $settings, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_ossdl_off_blog_url() {
|
||||
$url = get_option( 'ossdl_off_blog_url' );
|
||||
if ( ! $url )
|
||||
$url = apply_filters( 'ossdl_off_blog_url', untrailingslashit( get_option( 'siteurl' ) ) );
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_cache_path_url() {
|
||||
global $cache_path;
|
||||
|
||||
return site_url( str_replace( ABSPATH, '', "{$cache_path}" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_cache_type() {
|
||||
global $wp_cache_config_file;
|
||||
if ( function_exists( "opcache_invalidate" ) ) {
|
||||
@opcache_invalidate( $wp_cache_config_file );
|
||||
}
|
||||
include( $wp_cache_config_file );
|
||||
|
||||
if ( $wp_cache_mod_rewrite == 1 ) {
|
||||
return 'mod_rewrite';
|
||||
} else {
|
||||
return 'PHP';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the item for the REST response
|
||||
*
|
||||
* @param mixed $item WordPress representation of the item.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return mixed
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
$settings = array();
|
||||
|
||||
$integers = array( 'cache_max_time', 'preload_interval' );
|
||||
$string_arrays = array( 'cache_stats', 'cache_acceptable_files', 'cache_rejected_uri', 'cache_rejected_user_agent',
|
||||
'cache_direct_pages' );
|
||||
foreach( $item as $key => $value ) {
|
||||
if ( is_array( $value ) && false == in_array( $key, $string_arrays ) ) {
|
||||
array_walk( $value, array( $this, 'make_array_bool' ) );
|
||||
|
||||
} elseif ( ( $value === 0 || $value === 1 ) && false == in_array( $key, $integers ) ) {
|
||||
$value = (bool)$value;
|
||||
}
|
||||
|
||||
$settings[ $key ] = $value;
|
||||
}
|
||||
|
||||
$strings_to_bool = array( 'ossdl_https', 'refresh_current_only_on_comments' );
|
||||
foreach( $strings_to_bool as $key ) {
|
||||
if ( isset( $settings[ $key ] ) ) {
|
||||
$settings[ $key ] = (bool)$settings[ $key ];
|
||||
}
|
||||
}
|
||||
|
||||
return rest_ensure_response( $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param string $key
|
||||
*/
|
||||
public function make_array_bool( &$value, $key ) {
|
||||
if ( $value == 0 || $value == 1 ) {
|
||||
$value = (bool) $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function get_is_submit_enabled() {
|
||||
global $wp_cache_config_file;
|
||||
return is_writeable_ACLSafe( $wp_cache_config_file );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function get_is_preload_enabled() {
|
||||
return false === defined( 'DISABLESUPERCACHEPRELOADING' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|int
|
||||
*/
|
||||
protected function get_next_gc() {
|
||||
return wp_next_scheduled( 'wp_cache_gc' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function get_is_preload_active() {
|
||||
if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function get_minimum_preload_interval() {
|
||||
global $wpdb;
|
||||
$count = $this->get_post_count();
|
||||
if ( $count > 1000 ) {
|
||||
$min_refresh_interval = 720;
|
||||
} else {
|
||||
$min_refresh_interval = 30;
|
||||
}
|
||||
|
||||
return $min_refresh_interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function get_is_lock_down_enabled() {
|
||||
if ( defined( 'WPLOCKDOWN' ) ) {
|
||||
return constant( 'WPLOCKDOWN' ) ? 1 : 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function get_post_count() {
|
||||
return wpsc_post_count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function get_default_cache_path() {
|
||||
return WP_CONTENT_DIR . '/wp-cache/';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Get_Stats extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Get the cache stats for the site.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
global $valid_nonce;
|
||||
$_GET[ 'listfiles' ] = 1;
|
||||
$valid_nonce = true;
|
||||
|
||||
return rest_ensure_response( wp_cache_regenerate_cache_file_stats() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Get_Status extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Get any status that might be visible.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
$status = array();
|
||||
|
||||
include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path()
|
||||
include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers()
|
||||
$this->add_rewrite_status( $status );
|
||||
$this->add_cache_disabled_status( $status );
|
||||
$this->add_compression_status( $status );
|
||||
$this->add_php_mod_rewrite_status( $status );
|
||||
$this->add_preload_status( $status );
|
||||
|
||||
if ( empty( $status ) ) {
|
||||
return rest_ensure_response( new stdclass() );
|
||||
} else {
|
||||
return rest_ensure_response( $status );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $status
|
||||
*/
|
||||
protected function add_preload_status( & $status ) {
|
||||
global $wp_cache_config_file;
|
||||
|
||||
include( $wp_cache_config_file );
|
||||
|
||||
if ( false == $cache_enabled ) {
|
||||
$status[ 'preload_disabled_cache_off' ] = true;
|
||||
}
|
||||
if ( false == $super_cache_enabled ) {
|
||||
$status[ 'preload_disabled_supercache_off' ] = true;
|
||||
}
|
||||
if ( true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
|
||||
$status[ 'preload_disabled_by_admin' ] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $status
|
||||
*/
|
||||
protected function add_php_mod_rewrite_status( & $status ) {
|
||||
global $wp_cache_config_file;
|
||||
|
||||
include( $wp_cache_config_file );
|
||||
|
||||
if ( $cache_enabled && !$wp_cache_mod_rewrite ) {
|
||||
$scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
|
||||
if ( $scrules != '' ) {
|
||||
$status[ 'php_mod_rewrite' ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $status
|
||||
*/
|
||||
protected function add_cache_disabled_status( & $status ) {
|
||||
global $wp_cache_config_file;
|
||||
|
||||
if ( ! is_writeable_ACLSafe( $wp_cache_config_file ) ) {
|
||||
$status['cache_disabled'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $status
|
||||
*/
|
||||
protected function add_compression_status( & $status ) {
|
||||
if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
|
||||
$status['compression_disabled_by_admin'] = true;
|
||||
} elseif ( false == function_exists( 'gzencode' ) ) {
|
||||
$status['compression_disabled_no_gzencode'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $status
|
||||
*/
|
||||
protected function add_rewrite_status( & $status ) {
|
||||
global $home_path, $wp_cache_config_file;
|
||||
|
||||
include( $wp_cache_config_file );
|
||||
|
||||
// Return if the rewrite caching is disabled.
|
||||
if ( ! $cache_enabled || ! $super_cache_enabled || ! $wp_cache_mod_rewrite ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
|
||||
extract( wpsc_get_htaccess_info() );
|
||||
|
||||
if ( $scrules != $rules ) {
|
||||
$status[ 'mod_rewrite_rules' ] = true;
|
||||
}
|
||||
$got_rewrite = apache_mod_loaded( 'mod_rewrite', true );
|
||||
if ( $wp_cache_mod_rewrite && false == apply_filters( 'got_rewrite', $got_rewrite ) ) {
|
||||
$status[ 'mod_rewrite_missing' ] = true;
|
||||
}
|
||||
|
||||
if ( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
|
||||
$status[ 'htaccess_ro' ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Preload extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Update the cache settings.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
$parameters = $request->get_json_params();
|
||||
|
||||
if ( defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
|
||||
wp_cache_debug( 'WP_Super_Cache_Rest_Preload: preload disabled by admin' );
|
||||
return rest_ensure_response( array( 'error' => 'preload disabled by admin' ) );
|
||||
}
|
||||
|
||||
if ( isset( $parameters[ 'enable' ] ) ) {
|
||||
if ( $parameters[ 'enable' ] == true ) {
|
||||
wp_cache_debug( 'WP_Super_Cache_Rest_Preload: enable' );
|
||||
wpsc_enable_preload();
|
||||
return( rest_ensure_response( array( 'enabled' => true ) ) );
|
||||
} else {
|
||||
wp_cache_debug( 'WP_Super_Cache_Rest_Preload: cancel' );
|
||||
wpsc_cancel_preload();
|
||||
return( rest_ensure_response( array( 'enabled' => false ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Test_Cache extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Get a collection of items
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
global $cache_path;
|
||||
|
||||
$url = trailingslashit( get_bloginfo( 'url' ) );
|
||||
|
||||
$response = array( 'status' => 'UNKNOWN' );
|
||||
$has_errors = false;
|
||||
|
||||
$attempts = array( 'prime', 'first', 'second' );
|
||||
|
||||
$c = 0;
|
||||
foreach ( $attempts as $attempt_name ) {
|
||||
$attempt = array();
|
||||
$page[ $c ] = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
|
||||
|
||||
if ( ! is_wp_error( $page[ $c ] ) ) {
|
||||
$fp = fopen( $cache_path . $c . ".html", "w" );
|
||||
fwrite( $fp, $page[ $c ][ 'body' ] );
|
||||
fclose( $fp );
|
||||
}
|
||||
|
||||
if ( is_wp_error( $page[ $c ] ) ) {
|
||||
$has_errors = true;
|
||||
$attempt['status'] = false;
|
||||
$attempt['errors'] = $this->format_error( $page[ $c ] );
|
||||
|
||||
} elseif ( $page[ $c ]['response']['code'] != 200 ) {
|
||||
$has_errors = true;
|
||||
$attempt['status'] = false;
|
||||
$attempt['errors'] = array( $page[ $c ]['response']['message'] );
|
||||
|
||||
// Don't run this step on prime cache.
|
||||
} elseif ( 0 !== $c && 0 === preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ $c ]['body'], $matches2 ) ) {
|
||||
$has_errors = true;
|
||||
$attempt['status'] = false;
|
||||
$attempt['errors'] = array( __( 'Timestamps not found', 'wp-super-cache' ) );
|
||||
|
||||
} else {
|
||||
$attempt['status'] = true;
|
||||
}
|
||||
|
||||
|
||||
$response[ 'attempts' ][ $attempt_name ] = $attempt;
|
||||
$c++;
|
||||
}
|
||||
|
||||
if (
|
||||
false == $has_errors &&
|
||||
preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 1 ][ 'body' ], $matches1 ) &&
|
||||
preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 2 ][ 'body' ], $matches2 ) &&
|
||||
$matches1[2] == $matches2[2]
|
||||
) {
|
||||
$response[ 'status' ] = true;
|
||||
} else {
|
||||
$response[ 'status' ] = false;
|
||||
$response[ 'error' ] = array( __( 'Timestamps do not match', 'wp-super-cache' ) );
|
||||
}
|
||||
|
||||
$error = '';
|
||||
if ( $response[ 'status' ] == false ) {
|
||||
if ( isset( $response[ 'error' ] ) ) {
|
||||
$error = $response[ 'error' ];
|
||||
} else {
|
||||
foreach( $response[ 'attempts' ] as $attempt ) {
|
||||
$error .= $attempt[ 'errors' ] . "\n";
|
||||
}
|
||||
}
|
||||
return new WP_Error( 'test_error', $error, array( 'status' => 500 ) );
|
||||
}
|
||||
return rest_ensure_response( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_Error $error
|
||||
* @return array
|
||||
*/
|
||||
protected function format_error( WP_Error $error ) {
|
||||
$messages = array();
|
||||
foreach ( $error->get_error_codes() as $code ) {
|
||||
foreach ( $error->get_error_messages( $code ) as $err ) {
|
||||
$messages[] = $err;
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Rest_Update_Plugins extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Toggle plugins on/off through the /plugins/ endpoint
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
$parameters = $request->get_json_params();
|
||||
|
||||
global $valid_nonce;
|
||||
$valid_nonce = true;
|
||||
|
||||
wpsc_update_plugin_list( $parameters );
|
||||
$list = wpsc_get_plugin_list();
|
||||
|
||||
return rest_ensure_response( $list );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,655 @@
|
||||
<?php
|
||||
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-settings-map.php' );
|
||||
|
||||
class WP_Super_Cache_Rest_Update_Settings extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Update the cache settings.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function callback( $request ) {
|
||||
$parameters = $request->get_json_params();
|
||||
|
||||
// Override to force locking.
|
||||
if ( defined( 'WPSC_DISABLE_LOCKING' ) ) {
|
||||
$parameters['cache_disable_locking'] = 1;
|
||||
}
|
||||
|
||||
// Set the nonce to valid, so that form sets will work later.
|
||||
global $valid_nonce;
|
||||
$valid_nonce = true;
|
||||
|
||||
$errors = array();
|
||||
|
||||
if ( isset( $parameters['easy'] ) ) {
|
||||
$errors = $this->toggle_easy_caching( $parameters['easy'] );
|
||||
|
||||
} elseif ( isset( $parameters[ 'reset' ] ) ) {
|
||||
$errors = $this->restore_default_settings( $parameters );
|
||||
|
||||
} else {
|
||||
|
||||
foreach ( $parameters as $name => $value ) {
|
||||
$has_error = $this->set_value_by_key( $value, $name );
|
||||
|
||||
if ( false == is_numeric( $has_error ) && false == is_bool( $has_error ) ) {
|
||||
$errors[] = $has_error;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save_time_settings( $parameters );
|
||||
$this->save_preload_settings();
|
||||
$this->set_debug_settings( $parameters );
|
||||
}
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
return rest_ensure_response( $errors );
|
||||
|
||||
} else {
|
||||
$get_settings = new WP_Super_Cache_Rest_Get_Settings();
|
||||
return $get_settings->callback( $request );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a key and a value, set the value for that key, based on
|
||||
* the configuration in the settings map.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $key
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function set_value_by_key( $value, $key ) {
|
||||
|
||||
$settings_map = WP_Super_Cache_Settings_Map::$map;
|
||||
|
||||
// If this parameter isn't in the map, then let's ignore it.
|
||||
if ( ! isset( $settings_map[ $key ] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$map = $settings_map[ $key ];
|
||||
|
||||
if ( isset( $map['set'] ) ) {
|
||||
if ( method_exists( $this, $map['set'] ) ) {
|
||||
$has_error = call_user_func( array( $this, $map['set'] ), $value, $key );
|
||||
|
||||
} elseif ( function_exists( $map['set'] ) ) {
|
||||
$has_error = call_user_func( $map['set'], $value );
|
||||
|
||||
}
|
||||
} elseif ( isset( $map['global'] ) ) {
|
||||
|
||||
$set_method = method_exists( $this, 'set_' . $map['global'] ) ?
|
||||
'set_' . $map['global'] : 'set_global';
|
||||
if ( $set_method == 'set_global' ) {
|
||||
$has_error = call_user_func( array( $this, $set_method ), $key, $value );
|
||||
} else {
|
||||
$has_error = call_user_func( array( $this, $set_method ), $value );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $has_error ) ) {
|
||||
return $has_error;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic method for setting globals.
|
||||
*
|
||||
* The setting must be added to the whitelist in order to be set this way.
|
||||
*
|
||||
* @param string $global_name
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_global( $global_name, $value ) {
|
||||
$whitelist = array(
|
||||
'wp_super_cache_late_init',
|
||||
'wp_cache_disable_utf8',
|
||||
'wp_cache_no_cache_for_get',
|
||||
'wp_supercache_304',
|
||||
'wp_cache_mfunc_enabled',
|
||||
'wp_cache_mobile_enabled',
|
||||
'wp_cache_front_page_checks',
|
||||
'wp_supercache_cache_list',
|
||||
'wp_cache_hello_world',
|
||||
'wp_cache_clear_on_post_edit',
|
||||
'cache_rebuild_files',
|
||||
'wp_cache_refresh_single_only',
|
||||
'wp_cache_mutex_disabled',
|
||||
'wpsc_save_headers',
|
||||
);
|
||||
|
||||
if ( ! in_array( $global_name, $whitelist ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wp_cache_setting( $global_name, (int)$value );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_wp_cache_location( $value ) {
|
||||
global $cache_path;
|
||||
|
||||
if ( $value != '' && ( ! isset( $cache_path ) || $value != $cache_path ) ) {
|
||||
$dir = realpath( trailingslashit( dirname( $value ) ) );
|
||||
if ( $dir == false ) {
|
||||
$dir = WP_CONTENT_DIR . '/cache/';
|
||||
|
||||
} else {
|
||||
$dir = trailingslashit( $dir ) . trailingslashit( wpsc_deep_replace( array(
|
||||
'..',
|
||||
'\\'
|
||||
), basename( $value ) ) );
|
||||
}
|
||||
|
||||
$new_cache_path = $dir;
|
||||
|
||||
} else {
|
||||
$new_cache_path = WP_CONTENT_DIR . '/cache/';
|
||||
}
|
||||
|
||||
if ( $new_cache_path != $cache_path ) {
|
||||
if ( file_exists( $new_cache_path ) == false ) {
|
||||
rename( $cache_path, $new_cache_path );
|
||||
}
|
||||
|
||||
$cache_path = $new_cache_path;
|
||||
wp_cache_setting( 'cache_path', $cache_path );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_cache_enabled( $value ) {
|
||||
if ( $value != 1 ) {
|
||||
wp_cache_disable();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
wp_cache_enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_lock_down( $value ) {
|
||||
$_POST[ 'wp_lock_down' ] = (int)$value;
|
||||
wp_update_lock_down();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_super_cache_enabled( $value ) {
|
||||
global $wp_cache_mod_rewrite;
|
||||
|
||||
if ( is_numeric( $value ) == false ) {
|
||||
$types = array( 'wpcache' => 0, 'mod_rewrite' => 1, 'PHP' => 2 );
|
||||
if ( isset( $types[ $value ] ) ) {
|
||||
$value = $types[ $value ];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $value === 0 ) { // WPCache
|
||||
wp_super_cache_disable();
|
||||
|
||||
} else {
|
||||
wp_super_cache_enable();
|
||||
$wp_cache_mod_rewrite = 0; // PHP recommended
|
||||
|
||||
if ( $value == 1 ) { // mod_rewrite
|
||||
$wp_cache_mod_rewrite = 1;
|
||||
add_mod_rewrite_rules();
|
||||
|
||||
} elseif( $value == 2 ) { // PHP
|
||||
$wp_cache_mod_rewrite = 0;
|
||||
remove_mod_rewrite_rules();
|
||||
|
||||
}
|
||||
|
||||
wp_cache_setting( 'wp_cache_mod_rewrite', $wp_cache_mod_rewrite );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_wp_cache_not_logged_in( $value ) {
|
||||
global $wp_cache_not_logged_in, $cache_path;
|
||||
|
||||
if ( 0 != $value ) {
|
||||
if ( 0 == $wp_cache_not_logged_in && function_exists( 'prune_super_cache' ) ) {
|
||||
prune_super_cache( $cache_path, true );
|
||||
}
|
||||
|
||||
$wp_cache_not_logged_in = (int) $value;
|
||||
|
||||
} else {
|
||||
$wp_cache_not_logged_in = 0;
|
||||
}
|
||||
|
||||
wp_cache_setting( 'wp_cache_not_logged_in', $wp_cache_not_logged_in );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_wp_cache_make_known_anon( $value ) {
|
||||
global $wp_cache_make_known_anon, $cache_path;
|
||||
|
||||
if ( 1 == $value ) {
|
||||
if ( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) ) {
|
||||
prune_super_cache( $cache_path, true );
|
||||
}
|
||||
|
||||
$wp_cache_make_known_anon = 1;
|
||||
|
||||
} else {
|
||||
$wp_cache_make_known_anon = 0;
|
||||
}
|
||||
|
||||
wp_cache_setting( 'wp_cache_make_known_anon', $wp_cache_make_known_anon );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_wp_cache_object_cache( $value ) {
|
||||
global $_wp_using_ext_object_cache, $wp_cache_object_cache, $cache_path;
|
||||
|
||||
if ( ! $_wp_using_ext_object_cache ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $value == 0 ) {
|
||||
if ( function_exists( 'prune_super_cache' ) ) {
|
||||
prune_super_cache( $cache_path, true );
|
||||
}
|
||||
|
||||
$wp_cache_object_cache = 1;
|
||||
|
||||
} else {
|
||||
$wp_cache_object_cache = 0;
|
||||
}
|
||||
|
||||
wp_cache_setting( 'wp_cache_object_cache', $wp_cache_object_cache );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
protected function set_cache_compression( $value ) {
|
||||
global $cache_compression, $cache_path;
|
||||
|
||||
$new_cache_compression = 0;
|
||||
if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
|
||||
$cache_compression = 0;
|
||||
wp_cache_setting( 'cache_compression', $cache_compression );
|
||||
|
||||
} else {
|
||||
if ( 1 == $value ) {
|
||||
$new_cache_compression = 1;
|
||||
}
|
||||
|
||||
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
|
||||
return __( "You attempted to enable compression but `zlib.output_compression` is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' );
|
||||
}
|
||||
|
||||
if ( $new_cache_compression != $cache_compression ) {
|
||||
$cache_compression = $new_cache_compression;
|
||||
wp_cache_setting( 'cache_compression', $cache_compression );
|
||||
if ( function_exists( 'prune_super_cache' ) ) {
|
||||
prune_super_cache( $cache_path, true );
|
||||
}
|
||||
|
||||
delete_option( 'super_cache_meta' );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cache_pages
|
||||
*/
|
||||
protected function set_wp_cache_pages( $cache_pages ) {
|
||||
if ( ! is_array( $cache_pages ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$_POST['wp_edit_rejected_pages'] = 1;
|
||||
|
||||
foreach ( $cache_pages as $page => $value ) {
|
||||
if ( $value ) {
|
||||
$_POST['wp_cache_pages'][ $page ] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
wp_cache_update_rejected_pages();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_cache_rejected_uri( $value ) {
|
||||
$_REQUEST['wp_rejected_uri'] = implode( "\n", $value );
|
||||
wp_cache_update_rejected_strings();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_cache_acceptable_files( $value ) {
|
||||
$_REQUEST['wp_accepted_files'] = implode( "\n", $value );
|
||||
wp_cache_update_accepted_strings();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_cache_rejected_user_agent( $value ) {
|
||||
$_POST['wp_rejected_user_agent'] = implode( "\n", $value );
|
||||
wp_cache_update_rejected_ua();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_ossdl_cname( $value ) {
|
||||
update_option( 'ossdl_cname', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_ossdl_off_blog_url( $value ) {
|
||||
update_option( 'ossdl_off_blog_url', untrailingslashit( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_ossdl_off_cdn_url( $value ) {
|
||||
update_option( 'ossdl_off_cdn_url', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_ossdl_off_include_dirs( $value ) {
|
||||
update_option( 'ossdl_off_include_dirs', $value == '' ? 'wp-content,wp-includes' : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_ossdl_off_exclude( $value ) {
|
||||
update_option( 'ossdl_off_exclude', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_ossdl_https( $value ) {
|
||||
update_option( 'ossdl_https', $value ? 1 : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function set_ossdlcdn( $value ) {
|
||||
global $wp_cache_config_file;
|
||||
|
||||
$ossdlcdn = $value ? 1 : 0;
|
||||
wp_cache_replace_line( '^ *\$ossdlcdn', "\$ossdlcdn = $ossdlcdn;", $wp_cache_config_file );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param string $name
|
||||
*/
|
||||
protected function set_time_setting( $value, $name ) {
|
||||
$_POST[ $name ] = $value;
|
||||
$_POST['_time_setting'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param string $name
|
||||
*/
|
||||
protected function set_preload_setting( $value, $name ) {
|
||||
$_POST[ $name ] = $value;
|
||||
$_POST['_preload_setting'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Easy caching is a mode that allows the user to press one button and
|
||||
* enable a sensible default of settings.
|
||||
*
|
||||
* @param bool $enabled
|
||||
*/
|
||||
protected function toggle_easy_caching( $enabled = true ) {
|
||||
global $cache_path, $wp_cache_shutdown_gc, $cache_schedule_type;
|
||||
if ( $enabled ) {
|
||||
$settings = array(
|
||||
'wp_cache_mobile_enabled' => 1,
|
||||
'is_cache_enabled' => 1,
|
||||
'cache_rebuild_files' => 1,
|
||||
'cache_compression' => 0,
|
||||
'wp_cache_not_logged_in' => 2,
|
||||
);
|
||||
wp_cache_enable();
|
||||
if ( ! defined( 'DISABLE_SUPERCACHE' ) ) {
|
||||
wp_cache_debug( 'DISABLE_SUPERCACHE is not set, super_cache enabled.' );
|
||||
wp_super_cache_enable();
|
||||
}
|
||||
wpsc_set_default_gc();
|
||||
|
||||
} else {
|
||||
wp_cache_disable();
|
||||
$settings = array( 'is_cache_enabled' => 0 );
|
||||
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
|
||||
wp_clear_scheduled_hook( 'wp_cache_gc' );
|
||||
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
|
||||
}
|
||||
|
||||
foreach ( $settings as $key => $value ) {
|
||||
$this->set_value_by_key( $value, $key );
|
||||
}
|
||||
|
||||
if ( $cache_path != WP_CONTENT_DIR . '/cache/' ) {
|
||||
$this->set_value_by_key( $cache_path, 'wp_cache_location' );
|
||||
}
|
||||
|
||||
$advanced_settings = array(
|
||||
'wp_super_cache_late_init',
|
||||
'wp_cache_disable_utf8',
|
||||
'wp_cache_no_cache_for_get',
|
||||
'wp_supercache_304',
|
||||
'wp_cache_mfunc_enabled',
|
||||
'wp_cache_mobile_enabled',
|
||||
'wp_cache_front_page_checks',
|
||||
'wp_supercache_cache_list',
|
||||
'wp_cache_hello_world',
|
||||
'wp_cache_clear_on_post_edit',
|
||||
'wp_cache_make_known_anon',
|
||||
'wp_cache_object_cache',
|
||||
'wp_cache_refresh_single_only',
|
||||
'cache_compression',
|
||||
'wp_cache_mutex_disabled'
|
||||
);
|
||||
|
||||
foreach ( $advanced_settings as $setting ) {
|
||||
$value = ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) ? 1 : 0;
|
||||
$this->set_value_by_key( $value, $setting );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs at the end and saves the time settings.
|
||||
*/
|
||||
protected function save_time_settings( $parameters ) {
|
||||
if ( ! isset( $_POST['_time_setting'] ) || true !== $_POST['_time_setting'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$_POST['action'] = 'expirytime';
|
||||
|
||||
$all_time_settings = array(
|
||||
'cache_max_time',
|
||||
'cache_schedule_type',
|
||||
'cache_scheduled_time',
|
||||
'cache_schedule_interval',
|
||||
'cache_time_interval',
|
||||
'cache_gc_email_me'
|
||||
);
|
||||
|
||||
foreach ( $all_time_settings as $time_setting ) {
|
||||
if ( false == isset( $_POST[ $time_setting ] ) || $GLOBALS[ $time_setting ] == $_POST[ $time_setting ] ) {
|
||||
$_POST[ $time_setting ] = $GLOBALS[ $time_setting ]; // fill in the potentially missing fields before updating GC settings.
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $parameters['cache_gc_email_me'] ) && $parameters['cache_gc_email_me'] == 0 ) {
|
||||
unset( $_POST['cache_gc_email_me'] );
|
||||
}
|
||||
$_POST[ 'wp_max_time' ] = $_POST[ 'cache_max_time' ];
|
||||
|
||||
wp_cache_time_update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set the cached direct pages list.
|
||||
*/
|
||||
protected function set_cache_direct_pages( $list ) {
|
||||
if ( is_array( $list ) == false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$_POST[ 'direct_pages' ] = $list;
|
||||
wpsc_update_direct_pages();
|
||||
}
|
||||
|
||||
/**
|
||||
* add an entry to the cached direct pages list.
|
||||
*/
|
||||
protected function new_direct_page( $value ) {
|
||||
global $cached_direct_pages;
|
||||
|
||||
if ( isset( $_POST[ 'direct_pages' ] ) == false ) {
|
||||
$_POST[ 'direct_pages' ] = $cached_direct_pages;
|
||||
}
|
||||
|
||||
$_POST[ 'new_direct_page' ] = $value;
|
||||
wpsc_update_direct_pages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs at the end and saves the preload settings.
|
||||
*/
|
||||
protected function save_preload_settings() {
|
||||
if ( ! isset( $_POST['_preload_setting'] ) || true !== $_POST['_preload_setting'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$_POST['action'] = 'preload';
|
||||
|
||||
$all_preload_settings = array(
|
||||
'preload_interval' => 'wp_cache_preload_interval',
|
||||
'preload_on' => 'wp_cache_preload_on',
|
||||
'preload_taxonomies' => 'wp_cache_preload_taxonomies',
|
||||
'preload_email_volume' => 'wp_cache_preload_email_volume',
|
||||
'preload_posts' => 'wp_cache_preload_posts',
|
||||
);
|
||||
|
||||
foreach ( $all_preload_settings as $key => $original ) {
|
||||
if ( ! isset( $_POST[ $key ] ) ) {
|
||||
$_POST[ $original ] = $GLOBALS[ $original ];
|
||||
} else {
|
||||
$_POST[ $original ] = $_POST[ $key ];
|
||||
if ( $key !== 'preload_interval' && ( $_POST[ $key ] === 0 || $_POST[ $key ] === false ) ) {
|
||||
unset( $_POST[ $original ] );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
wpsc_preload_settings();
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete the plugin configuration file and restore the sample one.
|
||||
*/
|
||||
protected function restore_default_settings( $parameters ) {
|
||||
global $wp_cache_config_file, $wp_cache_config_file_sample;
|
||||
|
||||
if ( file_exists( $wp_cache_config_file_sample ) ) {
|
||||
copy( $wp_cache_config_file_sample, $wp_cache_config_file );
|
||||
$cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() );
|
||||
wp_cache_setting( 'cache_page_secret', $cache_page_secret );
|
||||
|
||||
if ( function_exists( "opcache_invalidate" ) ) {
|
||||
@opcache_invalidate( $wp_cache_config_file );
|
||||
}
|
||||
}
|
||||
wpsc_set_default_gc( true );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the debug settings.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function set_debug_settings( $parameters ) {
|
||||
|
||||
$settings = array (
|
||||
'wp_super_cache_debug',
|
||||
'wp_cache_debug_ip',
|
||||
'wp_super_cache_comments',
|
||||
'wp_super_cache_front_page_check',
|
||||
'wp_super_cache_front_page_clear',
|
||||
'wp_super_cache_front_page_text',
|
||||
'wp_super_cache_front_page_notification',
|
||||
'wpsc_delete_log',
|
||||
);
|
||||
|
||||
foreach( $settings as $setting ) {
|
||||
if ( isset( $parameters[ $setting ] ) ) {
|
||||
if ( $parameters[ $setting ] != false ) {
|
||||
$_POST[ $setting ] = $parameters[ $setting ];
|
||||
}
|
||||
$_POST[ 'wp_cache_debug' ] = 1;
|
||||
} else {
|
||||
if ( ! isset( $GLOBALS[ $setting ] ) ) {
|
||||
$GLOBALS[ $setting ] = 0;
|
||||
}
|
||||
$_POST[ $setting ] = $GLOBALS[ $setting ];
|
||||
}
|
||||
}
|
||||
global $valid_nonce;
|
||||
$valid_nonce = true;
|
||||
|
||||
$settings = wpsc_update_debug_settings();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
class WP_Super_Cache_Settings_Map {
|
||||
/**
|
||||
* A map describing how settings transform from their external names
|
||||
* into internal methods and globals.
|
||||
*
|
||||
* Key definitions:
|
||||
*
|
||||
* - get: A getter method or function that will be called to return the var
|
||||
* - set: A setter method or function that will be called to set the var
|
||||
* - option: An option name that will be used to get or set the var
|
||||
* - global: A name of a global that can GET
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $map = array(
|
||||
'is_submit_enabled' => array(
|
||||
'get' => 'get_is_submit_enabled',
|
||||
'set' => '',
|
||||
),
|
||||
'is_preload_enabled' => array(
|
||||
'get' => 'get_is_preload_enabled',
|
||||
'set' => '',
|
||||
),
|
||||
'cache_lock_down' => array(
|
||||
'get' => 'get_is_lock_down_enabled',
|
||||
'set' => 'set_lock_down',
|
||||
),
|
||||
'cache_next_gc' => array(
|
||||
'get' => 'get_next_gc',
|
||||
'set' => '',
|
||||
),
|
||||
'cache_gc_email_me' => array(
|
||||
'global' => 'cache_gc_email_me',
|
||||
'set' => 'set_time_setting',
|
||||
),
|
||||
'cache_path_url' => array(
|
||||
'get' => 'get_cache_path_url',
|
||||
),
|
||||
'cache_type' => array(
|
||||
'get' => 'get_cache_type',
|
||||
'set' => 'set_super_cache_enabled',
|
||||
),
|
||||
'is_preloading' => array(
|
||||
'get' => 'wpsc_is_preloading',
|
||||
'set' => '',
|
||||
),
|
||||
'post_count' => array(
|
||||
'get' => 'get_post_count',
|
||||
'set' => '',
|
||||
),
|
||||
'is_cache_enabled' => array(
|
||||
'global' => 'cache_enabled',
|
||||
'set' => 'set_cache_enabled',
|
||||
),
|
||||
'is_super_cache_enabled' => array(
|
||||
'global' => 'super_cache_enabled',
|
||||
'set' => 'set_super_cache_enabled',
|
||||
),
|
||||
'is_mobile_enabled' => array(
|
||||
'global' => 'wp_cache_mobile_enabled',
|
||||
),
|
||||
'is_mfunc_enabled' => array(
|
||||
'global' => 'wp_cache_mfunc_enabled',
|
||||
),
|
||||
'cache_list' => array(
|
||||
'global' => 'wp_supercache_cache_list',
|
||||
),
|
||||
'clear_cache_on_post_edit' => array(
|
||||
'global' => 'wp_cache_clear_on_post_edit',
|
||||
),
|
||||
'wpsc_save_headers' => array(
|
||||
'global' => 'wpsc_save_headers',
|
||||
),
|
||||
'cache_rebuild' => array(
|
||||
'global' => 'cache_rebuild_files',
|
||||
),
|
||||
'dont_cache_logged_in' => array(
|
||||
'global' => 'wp_cache_not_logged_in',
|
||||
),
|
||||
'make_known_anon' => array(
|
||||
'global' => 'wp_cache_make_known_anon',
|
||||
),
|
||||
'cache_path' => array(
|
||||
'global' => 'cache_path',
|
||||
'set' => 'set_wp_cache_location',
|
||||
),
|
||||
'default_cache_path' => array(
|
||||
'get' => 'get_default_cache_path',
|
||||
),
|
||||
'use_object_cache' => array(
|
||||
'global' => 'wp_cache_object_cache',
|
||||
),
|
||||
'refresh_current_only_on_comments' => array(
|
||||
'global' => 'wp_cache_refresh_single_only',
|
||||
),
|
||||
'cache_compression' => array(
|
||||
'global' => 'cache_compression',
|
||||
'set' => 'set_cache_compression',
|
||||
),
|
||||
'cache_mod_rewrite' => array(
|
||||
'global' => 'wp_cache_mod_rewrite',
|
||||
),
|
||||
'use_304_headers' => array(
|
||||
'global' => 'wp_supercache_304',
|
||||
),
|
||||
'cache_late_init' => array(
|
||||
'global' => 'wp_super_cache_late_init',
|
||||
),
|
||||
'front_page_checks' => array(
|
||||
'global' => 'wp_cache_front_page_checks',
|
||||
),
|
||||
'cache_page_secret' => array(
|
||||
'global' => 'cache_page_secret',
|
||||
),
|
||||
'disable_utf8' => array(
|
||||
'global' => 'wp_cache_disable_utf8',
|
||||
),
|
||||
'no_cache_for_get' => array(
|
||||
'global' => 'wp_cache_no_cache_for_get',
|
||||
),
|
||||
'cache_schedule_type' => array(
|
||||
'global' => 'cache_schedule_type',
|
||||
'set' => 'set_time_setting',
|
||||
),
|
||||
'cache_scheduled_time' => array(
|
||||
'global' => 'cache_scheduled_time',
|
||||
'set' => 'set_time_setting',
|
||||
),
|
||||
'cache_max_time' => array(
|
||||
'global' => 'cache_max_time',
|
||||
'set' => 'set_time_setting',
|
||||
),
|
||||
'cache_time_interval' => array(
|
||||
'global' => 'cache_time_interval',
|
||||
'set' => 'set_time_setting',
|
||||
),
|
||||
'shutdown_garbage_collector' => array(
|
||||
'global' => 'wp_cache_shutdown_gc',
|
||||
),
|
||||
'pages' => array(
|
||||
'global' => 'wp_cache_pages',
|
||||
),
|
||||
'minimum_preload_interval' => array(
|
||||
'get' => 'get_minimum_preload_interval',
|
||||
),
|
||||
'preload_interval' => array(
|
||||
'global' => 'wp_cache_preload_interval',
|
||||
'set' => 'set_preload_setting',
|
||||
),
|
||||
'preload_posts' => array(
|
||||
'global' => 'wp_cache_preload_posts',
|
||||
'set' => 'set_preload_setting',
|
||||
),
|
||||
'preload_on' => array(
|
||||
'global' => 'wp_cache_preload_on',
|
||||
'set' => 'set_preload_setting',
|
||||
),
|
||||
'preload_active' => array(
|
||||
'get' => 'get_is_preload_active',
|
||||
),
|
||||
'preload_taxonomies' => array(
|
||||
'global' => 'wp_cache_preload_taxonomies',
|
||||
'set' => 'set_preload_setting',
|
||||
),
|
||||
'preload_email_me' => array(
|
||||
'global' => 'wp_cache_preload_email_me',
|
||||
'set' => 'set_preload_setting',
|
||||
),
|
||||
'preload_email_volume' => array(
|
||||
'global' => 'wp_cache_preload_email_volume',
|
||||
'set' => 'set_preload_setting',
|
||||
),
|
||||
'cache_mobile_browsers' => array(
|
||||
'global' => 'wp_cache_mobile_browsers',
|
||||
),
|
||||
'cache_mobile_prefixes' => array(
|
||||
'global' => 'wp_cache_mobile_prefixes',
|
||||
),
|
||||
'cache_disable_locking' => array(
|
||||
'global' => 'wp_cache_mutex_disabled',
|
||||
),
|
||||
'cache_hello_world' => array(
|
||||
'global' => 'wp_cache_hello_world',
|
||||
),
|
||||
'cache_schedule_interval' => array(
|
||||
'global' => 'cache_schedule_interval',
|
||||
'set' => 'set_time_setting',
|
||||
),
|
||||
'cache_acceptable_files' => array(
|
||||
'global' => 'cache_acceptable_files',
|
||||
),
|
||||
'cache_rejected_uri' => array(
|
||||
'global' => 'cache_rejected_uri',
|
||||
),
|
||||
'cache_rejected_user_agent' => array(
|
||||
'global' => 'cache_rejected_user_agent',
|
||||
),
|
||||
'cache_direct_pages' => array(
|
||||
'global' => 'cached_direct_pages',
|
||||
'set' => 'set_cache_direct_pages',
|
||||
),
|
||||
'new_direct_page' => array(
|
||||
'set' => 'new_direct_page',
|
||||
),
|
||||
'ossdl_cname' => array(
|
||||
'option' => 'ossdl_cname',
|
||||
'set' => 'set_ossdl_cname',
|
||||
),
|
||||
'ossdl_https' => array(
|
||||
'option' => 'ossdl_https',
|
||||
'set' => 'set_ossdl_https',
|
||||
),
|
||||
'ossdl_off_cdn_url' => array(
|
||||
'option' => 'ossdl_off_cdn_url',
|
||||
'set' => 'set_ossdl_off_cdn_url',
|
||||
),
|
||||
'ossdl_off_blog_url' => array(
|
||||
'option' => 'ossdl_off_blog_url',
|
||||
'set' => 'set_ossdl_off_blog_url',
|
||||
),
|
||||
'ossdl_off_exclude' => array(
|
||||
'option' => 'ossdl_off_exclude',
|
||||
'set' => 'set_ossdl_off_exclude',
|
||||
),
|
||||
'ossdl_off_include_dirs' => array(
|
||||
'option' => 'ossdl_off_include_dirs',
|
||||
'set' => 'set_ossdl_off_include_dirs',
|
||||
),
|
||||
'ossdlcdn' => array(
|
||||
'global' => 'ossdlcdn',
|
||||
'set' => 'set_ossdlcdn',
|
||||
),
|
||||
'wp_super_cache_debug' => array(
|
||||
'global' => 'wp_super_cache_debug',
|
||||
),
|
||||
'wp_cache_debug_username' => array(
|
||||
'get' => 'wpsc_debug_username',
|
||||
),
|
||||
'wp_cache_debug_log' => array(
|
||||
'global' => 'wp_cache_debug_log',
|
||||
),
|
||||
'wp_cache_debug_ip' => array(
|
||||
'global' => 'wp_cache_debug_ip',
|
||||
),
|
||||
'wp_super_cache_comments' => array(
|
||||
'global' => 'wp_super_cache_comments',
|
||||
),
|
||||
'wp_super_cache_front_page_check' => array(
|
||||
'global' => 'wp_super_cache_front_page_check',
|
||||
),
|
||||
'wp_super_cache_front_page_clear' => array(
|
||||
'global' => 'wp_super_cache_front_page_clear',
|
||||
),
|
||||
'wp_super_cache_front_page_text' => array(
|
||||
'global' => 'wp_super_cache_front_page_text',
|
||||
),
|
||||
'wp_super_cache_front_page_notification' => array(
|
||||
'global' => 'wp_super_cache_front_page_notification',
|
||||
),
|
||||
);
|
||||
}
|
||||
168
wp-content/plugins/wp-super-cache/rest/load.php
Normal file
168
wp-content/plugins/wp-super-cache/rest/load.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-settings.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-update-settings.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-stats.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-cache.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-status.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-test-cache.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-delete-cache.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-preload.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-get-plugins.php' );
|
||||
require_once( dirname( __FILE__ ) . '/class.wp-super-cache-rest-update-plugins.php' );
|
||||
|
||||
class WP_Super_Cache_Router {
|
||||
|
||||
/**
|
||||
* Register the routes for the objects of the controller.
|
||||
*
|
||||
* GET /wp-super-cache/v1/settings
|
||||
* POST /wp-super-cache/v1/settings
|
||||
* GET /wp-super-cache/v1/stats
|
||||
* GET /wp-super-cache/v1/cache
|
||||
* POST /wp-super-cache/v1/cache
|
||||
*/
|
||||
public static function register_routes() {
|
||||
$version = '1';
|
||||
$namespace = 'wp-super-cache/v' . $version;
|
||||
|
||||
$get_settings = new WP_Super_Cache_Rest_Get_Settings();
|
||||
$update_settings = new WP_Super_Cache_Rest_Update_Settings();
|
||||
$get_stats = new WP_Super_Cache_Rest_Get_Stats();
|
||||
$get_cache = new WP_Super_Cache_Rest_Get_Cache();
|
||||
$test_cache = new WP_Super_Cache_Rest_Test_Cache();
|
||||
$delete_cache = new WP_Super_Cache_Rest_Delete_Cache();
|
||||
$preload_cache = new WP_Super_Cache_Rest_Preload();
|
||||
$get_status = new WP_Super_Cache_Rest_Get_Status();
|
||||
$get_plugins = new WP_Super_Cache_Rest_Get_Plugins();
|
||||
$update_plugins = new WP_Super_Cache_Rest_Update_Plugins();
|
||||
|
||||
register_rest_route( $namespace, '/settings', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $get_settings, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::get_item_permissions_check',
|
||||
'args' => array(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $update_settings, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::update_item_permissions_check',
|
||||
'args' => array(),
|
||||
),
|
||||
) );
|
||||
|
||||
register_rest_route( $namespace, '/status', array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $get_status, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::get_item_permissions_check',
|
||||
) );
|
||||
|
||||
register_rest_route( $namespace, '/stats', array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $get_stats, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::get_item_permissions_check',
|
||||
) );
|
||||
|
||||
register_rest_route( $namespace, '/cache', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $get_cache, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::get_item_permissions_check',
|
||||
'args' => array(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $delete_cache, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::delete_item_permissions_check',
|
||||
'args' => array(),
|
||||
),
|
||||
) );
|
||||
|
||||
register_rest_route( $namespace, '/preload', array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $preload_cache, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::update_item_permissions_check',
|
||||
) );
|
||||
|
||||
register_rest_route( $namespace, '/cache/test', array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $test_cache, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::create_item_permissions_check',
|
||||
) );
|
||||
|
||||
register_rest_route( $namespace, '/plugins', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $get_plugins, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::get_item_permissions_check',
|
||||
'args' => array(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $update_plugins, 'callback' ),
|
||||
'permission_callback' => __CLASS__ . '::update_item_permissions_check',
|
||||
'args' => array(),
|
||||
),
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to get items
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
public static function get_items_permissions_check( $request ) {
|
||||
return wpsupercache_site_admin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to get a specific item
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
public static function get_item_permissions_check( $request ) {
|
||||
return self::get_items_permissions_check( $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to create items
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
public static function create_item_permissions_check( $request ) {
|
||||
return self::get_items_permissions_check( $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to update a specific item
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
public static function update_item_permissions_check( $request ) {
|
||||
return self::create_item_permissions_check( $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to update a specific item
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
public static function delete_item_permissions_check( $request ) {
|
||||
return self::update_item_permissions_check( $request );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function wpsc_load_rest_api() {
|
||||
$wpsupercache_route = new WP_Super_Cache_Router;
|
||||
$wpsupercache_route->register_routes();
|
||||
};
|
||||
|
||||
add_action( 'rest_api_init', 'wpsc_load_rest_api' );
|
||||
Reference in New Issue
Block a user