keycdn / cache-enabler

A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
https://wordpress.org/plugins/cache-enabler/
123 stars 46 forks source link

Cache Enabler addons #229

Open byteperfect opened 3 years ago

byteperfect commented 3 years ago

First of all, I would like to express my gratitude for the good work you are doing!

Could you please consider the possibility of adding add-ons functionality to the plugin? This will allow sites developers to use your plugin as a basis and gives the ability to flexibly configure the caching system for each specific site.

As one of the implementation options, I suggest you the scheme that I use on my sites.

  1. In the wp-config.php file, add an array with absolute paths to add-ons bootstrap files as a constant or a global variable, for example:
    define(
    'CACHE_ENABLER_ADD_ONS',
    array(
        '/absolute/path/to/add-on1.php',
        '/absolute/path/to/add-on2.php',
    )
    );
  2. In the advanced-cache.php file, before other require_once add the following code:
    if ( defined( 'CACHE_ENABLER_ADD_ONS' ) && is_array( CACHE_ENABLER_ADD_ONS ) ) {
    foreach ( CACHE_ENABLER_ADD_ONS as $add_on ) {
        if ( is_readable( $add_on ) ) {
            require_once $add_on;
        }
    }
    }
  3. Return values ​​from all functions must be passed through filters, for example:

    public static function get_cache_file() {
    
    $cache_file = sprintf(
        '%s/%s',
        self::get_cache_file_dir(),
        self::get_cache_file_name()
    );
    
    return apply_filters( 'cache_enabler_get_cache_file', $cache_file );
    }
  4. Maybe, add additional actions and filters inside functions.
coreykn commented 3 years ago

You're welcome! Happy to hear that you're enjoying Cache Enabler. Anything is always up for consideration. To better understand this request, can you please let me know what type of add ons you'd like to implement if this were to be introduced? Like the functionality that you're trying to add with the add ons.

byteperfect commented 3 years ago

For example, I need to have my own files naming based on certain conditions and be able to alter should_start, deliver_cache and start_buffering behavior. I am sure that similar functionality will be in demand by other developers as well. For example: https://github.com/keycdn/cache-enabler/issues/226.

coreykn commented 3 years ago

Thanks for explaining a little more about why you would like this to be added. Like with our other requests, let's leave this open as that allows others to comment and/or upvote your request.

davelit commented 3 years ago

In case you are loooking for inspiration, WP Super Cache has support for cache plugins (docs) that go into ./wp-content/plugins/wp-super-cache-plugins/ (in wp-cache-phase1.php): Plugins can manipulate the results by hooking into "cache actions" (add_cacheaction() and do_cacheaction()).

In my humble opinion, I think the cache plugins should be normal plugins that can be installed/uninstalled via the normal WordPress plugin repository and they should make themselves "available" to advanced-cache.php through the creation and removal of symlinks in a conf.d like directory, which could default to ./wp-content/plugins/cache-enabler-plugins/ (but should be overridable via a constant like CACHE_ENABLER_PLUGINS_DIR).