Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2585824
Initial import of framework for rewrite.
donnchawp Oct 29, 2020
1a0fd95
Use the right text domain
donnchawp Oct 29, 2020
3f8d06f
Add $filename to replace_line_in_file() so it's more useful.
donnchawp Oct 29, 2020
c431619
Add functions to check setup.
donnchawp Oct 29, 2020
751a975
In admin page check the setup before showing settings.
donnchawp Oct 29, 2020
6281ca6
Remove ", so the path to the plugin is correct
donnchawp Oct 29, 2020
5c04bef
Check for WPCACHEHOME and improve advanced-cache.php creation
donnchawp Oct 29, 2020
7abf728
Add wp_super_cache_create_cache() to process output buffer.
donnchawp Oct 29, 2020
b2d1890
Fill in more code from the plugin.
donnchawp Oct 31, 2020
7d39905
Add code to create a blank configuration file.
donnchawp Oct 31, 2020
4da0bbb
Add a "$caching = 0" to the config file.
donnchawp Oct 31, 2020
ac27bed
Change caching to cache_enabled
donnchawp Nov 1, 2020
4ce2ef0
Add a User class and move code in there.
donnchawp Nov 1, 2020
36d522f
$config is an object, not an array.
donnchawp Nov 1, 2020
11fb125
Ignore this, the plugin does lots of filesystem actions.
donnchawp Nov 1, 2020
f7f7b51
Add sample config file
donnchawp Nov 1, 2020
2da92a1
Fix case of config class and add wp_cache_home_path setting function.
donnchawp Nov 1, 2020
c63bc59
Change how the $config is used.
donnchawp Nov 1, 2020
bece452
Lots of changes:
donnchawp Dec 28, 2020
4e1067b
Use the gzip_encoding() function
donnchawp Dec 28, 2020
a43f521
Check "cache_compression" setting in the gzip_encoding function
donnchawp Dec 28, 2020
bb19090
Rename function ok_to_cache to is_cacheable
donnchawp Dec 28, 2020
aa3d0a7
Check if this exists before setting it.
donnchawp Dec 28, 2020
95c63fc
Add make_anonymous()
donnchawp Dec 28, 2020
1137f37
Fixed up is_caching_disabled and debugging logs
donnchawp Dec 28, 2020
27be12b
Move cache_init into Page class contructor
donnchawp Dec 28, 2020
c0cd065
Minor changes, for phpcs
donnchawp Dec 28, 2020
a232038
Fix "cache_enabled" check and add customizer check
donnchawp Dec 28, 2020
da5ea78
Fix call to gzip_encoding()
donnchawp Dec 28, 2020
0933a61
Cache query_vars to speed it up.
donnchawp Dec 28, 2020
59cb369
Split cache checks into pre and post.
donnchawp Dec 28, 2020
3264987
Remove wp_super_cache_config and clean up debug code.
donnchawp Dec 28, 2020
7bac899
Forgot a description for this function
donnchawp Dec 28, 2020
7305508
phpcs fix and move post checks into output buffer handler
donnchawp Dec 28, 2020
0b97192
Oops, this is an array, not a function.
donnchawp Dec 28, 2020
97d0d23
Move post check into this output buffer function
donnchawp Dec 28, 2020
2c3733b
Multiple fixes.
donnchawp Dec 28, 2020
2788c4f
Move $wp_query check to get_query_vars()
donnchawp Dec 28, 2020
284570e
Tiny typo in 404 query var.
donnchawp Dec 28, 2020
8a2efe9
Added set_env function.
donnchawp Jan 1, 2021
09e917e
Multiple changes.
donnchawp Jan 1, 2021
11fc209
Multiple changes:
donnchawp Jan 1, 2021
e720672
Add functions to create cache folders and call from setup.
donnchawp Jan 2, 2021
fa73330
Add page to the admin so environment is setup.
donnchawp Jan 2, 2021
a02bc95
Move cache directory creation to file cache and call via filter.
donnchawp Jan 2, 2021
151fdbc
This config variable isn't used any more.
donnchawp Jan 3, 2021
f8360b2
Multiple changes:
donnchawp Jan 3, 2021
efe0f9f
Remove broken "cache_enabled" check and move debugging around.
donnchawp Jan 3, 2021
8673d76
Remove this, not needed now.
donnchawp Jan 3, 2021
652888c
Tiny whitespace diff
donnchawp Jan 3, 2021
41ea736
Get debugging working.
donnchawp Jan 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
321 changes: 321 additions & 0 deletions admin/class-wp-super-cache-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://automattic.com/
* @since 2.0.0
*
* @package Wp_Super_Cache
* @subpackage Wp_Super_Cache/admin
*/

/**
* The class responsible for setting up required files for caching.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-super-cache-setup.php';


/**
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package Wp_Super_Cache
* @subpackage Wp_Super_Cache/admin
* @author Automattic <doc.wp-super-cache@ocaoimh.ie>
*/
class Wp_Super_Cache_Admin {

/**
* The ID of this plugin.
*
* @since 2.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;

/**
* The version of this plugin.
*
* @since 2.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;

/**
* Configuration object
*
* @since 2.0.0
* @var object $config
*/
private $config;

/**
* Setup object
*
* @since 2.0.0
* @access private
* @var object $config.
*/
private $setup;

/**
* Initialize the class and set its properties.
*
* @since 2.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {

$this->plugin_name = $plugin_name;
$this->version = $version;
$this->config = Wp_Super_Cache_Config::instance();
$this->setup = Wp_Super_cache_Setup::instance();

// Create page environment for cache info like blog_cache_dir.
$page = Wp_Super_Cache_Page::instance();
}

/**
* Register the stylesheets for the admin area.
*
* @since 2.0.0
*/
public function enqueue_styles() {

/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Wp_Super_Cache_Loader as all of the hooks are defined
* in that particular class.
*
* The Wp_Super_Cache_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/

wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-super-cache-admin.css', array(), $this->version, 'all' );

}

/**
* Register the JavaScript for the admin area.
*
* @since 2.0.0
*/
public function enqueue_scripts() {

/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Wp_Super_Cache_Loader as all of the hooks are defined
* in that particular class.
*
* The Wp_Super_Cache_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/

wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wp-super-cache-admin.js', array( 'jquery' ), $this->version, false );

}

/**
* Output network setting menu option
*
* @since 1.7
*/
public function network_admin_menu() {
add_submenu_page( 'settings.php', esc_html__( 'WP Super Cache', 'wp-super-cache' ), esc_html__( 'WP Super Cache', 'wp-super-cache' ), 'manage_options', 'wp-super-cache', array( $this, 'screen_options' ) );
}

/**
* Add options page
*
* @since 1.0
*/
public function action_admin_menu() {
add_submenu_page( 'options-general.php', esc_html__( 'WP Super Cache', 'wp-super-cache' ), esc_html__( 'WP Super Cache', 'wp-super-cache' ), 'manage_options', 'wp-super-cache', array( $this, 'screen_options' ) );
}

/**
* Add purge cache button to admin bar
*
* @since 1,3
*/
public function admin_bar_menu() {
global $wp_admin_bar;

if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can( 'delete_others_posts' ) ) {
$site_regex = preg_quote( rtrim( (string) wp_parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' ), '`' );
$req_uri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] ); // phpcs:ignore
$path = preg_replace( '`^' . $site_regex . '`', '', $req_uri );

$wp_admin_bar->add_menu(
array(
'parent' => '',
'id' => 'delete-cache',
'title' => __( 'Delete Cache', 'wp-super-cache' ),
'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache' ),
)
);
}
}

/**
* Output settings
*
* @since 1.0
*/
public function screen_options() {
// TODO - setup screen to create cache dir.
$setup_done = true;
if ( ! $this->setup->is_wp_cache_constant_defined() ) {
$setup_done = $this->setup->add_wp_cache_constant();
}

if ( ! $this->setup->is_wpcachehome_constant_defined() ) {
$setup_done = $this->setup->add_wpcachehome_constant();
}

if ( $setup_done && ! $this->setup->advanced_cache_exists() ) {
$setup_done = $this->setup->create_advanced_cache();
}

if ( $setup_done && ! $this->setup->plugin_config_exists() ) {
$setup_done = $this->setup->create_config_file();
}

if ( $setup_done && ! $this->config->config['wp_cache_home_path'] ) {
$setup_done = $this->setup->set_home_path();
}

if ( $setup_done ) {
$setup_done = $this->setup->create_cache_storage();
}

if ( ! $setup_done ) {
include_once 'partials/wp-super-cache-admin-setup.php';
} else {
include_once 'partials/wp-super-cache-admin-screen.php';
}
}

/**
* Update settings
*
* @since 2.0
*/
public function update() {
if ( ! isset( $_GET['page'] ) || 'wp-super-cache' !== $_GET['page'] ) {
return false;
}

if ( ! isset( $_POST['wp-super-cache_settings_nonce'] ) ) {
return false;
}

if (
! wp_verify_nonce(
sanitize_key( $_POST['wp-super-cache_settings_nonce'] ),
'wp-super-cache_update_settings'
)
) {
return false;
}

// TODO - switch to update settings for various pages.

$this->config->update_setting(
'cache_enabled',
isset( $_POST['cache_enabled'] ) ? 1 : 0
);

$this->config->update_setting(
'wp_super_cache_debug',
isset( $_POST['wp_super_cache_debug'] ) ? 1 : 0
);

if ( $this->config->config['wp_super_cache_debug'] ) {
$debug = Wp_Super_Cache_Debug::instance();
if (
isset( $this->config->config['wp_super_cache_debug_log'] ) && $this->config->config['wp_super_cache_debug_log'] &&
isset( $this->config->config['wp_super_cache_debug_username'] ) && $this->config->config['wp_super_cache_debug_username']
) {
$debug->create_debug_log( $this->config->config['wp_super_cache_debug_log'], $this->config->config['wp_super_cache_debug_username'] );
} else {
$debug->create_debug_log();
}
}

if ( false === isset( $this->config->config['cache_page_secret'] ) ) {
$cache_page_secret = md5( gmdate( 'H:i:s' ) . wp_rand() );
$this->config->update_setting( 'cache_page_secret', $cache_page_secret );
}

if ( isset( $_POST['action'] ) && 'easysetup' === $_POST['action'] ) {
$_POST['action'] = 'scupdates';
if ( isset( $_POST['wp_cache_easy_on'] ) && 1 === $_POST['wp_cache_easy_on'] ) {
$_POST['wp_cache_enabled'] = 1;
$_POST['super_cache_enabled'] = 1;
$_POST['cache_rebuild_files'] = 1;
unset( $_POST['cache_compression'] );
if ( WP_CONTENT_DIR . '/cache/' !== $cache_path ) {
$_POST['wp_cache_location'] = $cache_path;
}

// set up garbage collection with some default settings.
if ( ( ! isset( $wp_cache_shutdown_gc ) || 0 === $wp_cache_shutdown_gc ) && false === wp_next_scheduled( 'wp_cache_gc' ) ) {
if ( false === isset( $cache_schedule_type ) ) {
$cache_schedule_type = 'interval';
$cache_time_interval = 600;
$cache_max_time = 1800;
$this->config->update_setting( 'cache_schedule_type', $cache_schedule_type );
$this->config->update_setting( 'cache_time_interval', $cache_time_interval );
$this->config->update_setting( 'cache_max_time', $cache_max_time );
}
wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
}
} else {
unset( $_POST['wp_cache_enabled'] );
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
}
$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_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_clear_on_post_edit', 'wp_cache_make_known_anon', 'wp_cache_refresh_single_only', 'cache_compression' );
foreach ( $advanced_settings as $setting ) {
if ( isset( $GLOBALS[ $setting ] ) && 1 === $GLOBALS[ $setting ] ) {
$_POST[ $setting ] = 1;
}
}
$_POST['wp_cache_not_logged_in'] = 2;
}

}

/**
* Check if user can use admin page.
*
* @since 1.0
*/
private function is_super_admin() {
global $wp_version;

if ( version_compare( $wp_version, '4.8', '>=' ) ) {
return current_user_can( 'setup_network' );
}

return is_super_admin();
}

}
4 changes: 4 additions & 0 deletions admin/css/wp-super-cache-admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/
2 changes: 2 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// phpcs:ignoreFile -- Silence is golden.
32 changes: 32 additions & 0 deletions admin/js/wp-super-cache-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(function( $ ) {
'use strict';

/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/

})( jQuery );
28 changes: 28 additions & 0 deletions admin/partials/wp-super-cache-admin-screen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Provide a admin area view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://automattic.com/
* @since 2.0.0
*
* @package Wp_Super_Cache
* @subpackage Wp_Super_Cache/admin/partials
*/

?>

<!-- This file should primarily consist of HTML with a little bit of PHP. -->
<div class="wrap">
<h1><?php esc_html_e( 'WP Super Cache Settings', 'wp-super-cache' ); ?></h1>
<form action="" method="post">
<?php wp_nonce_field( 'wp-super-cache_update_settings', 'wp-super-cache_settings_nonce' ); ?>
<input type='checkbox' name='cache_enabled' value='1' <?php echo checked( $this->config->config['cache_enabled'] ); ?> /> <?php esc_html_e( 'Enable Caching', 'wp-super-cache' ); ?><br />
<input type='checkbox' name='wp_super_cache_debug' value='1' <?php echo checked( $this->config->config['wp_super_cache_debug'] ); ?> /> <?php esc_html_e( 'Enable Debugging', 'wp-super-cache' ); ?>
<input type="hidden" name="action" value="wp-super-cache_update" />
<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e( 'Save Changes', 'wp-super-cache' ); ?>">
</p>
</form>
</div>
Loading