• Resolved atoomic

    (@atoomic)


    Hi I’m using the RestAPI to enable SuperCache.

    I m submitting a POST request to /wp-json/wp-super-cache/v1/settings URL with the data “{ easy => true }”

    POST /wp-json/wp-super-cache/v1/settings 
    { "easy": true }

    After adding some debug to the /class.wp-super-cache-rest-update-settings.php file I can confirm that the toggle_easy_caching function is called and that “wp_super_cache_enable();” is also called

           protected function toggle_easy_caching( $enabled = true ) {
                    global $cache_path, $wp_cache_shutdown_gc, $cache_schedule_type;
                    if ( $enabled ) {
                            // return rest_ensure_response( array( "easy" => "enabling it...." ) );
                            $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();
                            //return rest_ensure_response( array( "easy" => "463" ) );
                            if ( ! defined( 'DISABLE_SUPERCACHE' ) ) {
                                    return rest_ensure_response( array( "easy" => "465" ) );
                                    wp_cache_debug( 'DISABLE_SUPERCACHE is not set, super_cache enabled.' );
                                    wp_super_cache_enable();
                            }
                            wpsc_set_default_gc();
    
                    }

    But when going back to the wp-admin UI the radio is still set to “Caching Off”. What am I missing? What additional steps need to be performed to enable the plugin using the API?

    The API reply contains the following fields:

    ...
    # is_cache_enabled => 1
    # is_super_cache_enabled => 1
    ...

    Note: I double checked that DISABLE_SUPERCACHE was not set.

    • This topic was modified 2 years ago by atoomic.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Bruce (a11n)

    (@bruceallen)

    Happiness Engineer

    Hi @atoomic

    Based on the code snippet you provided, it looks like you are correctly calling the wp_super_cache_enable() function to enable the plugin via the REST API.

    However, it’s possible that the plugin settings are not being updated correctly due to a caching issue or a conflict with other plugins or custom code on your site. Here are a few things you can try to resolve the issue:

    1. Clear cache: Clear the cache on your site and try submitting the POST request again to see if the changes are reflected in the UI.
    2. Disable other caching plugins: If you have other caching plugins installed on your site, they may be conflicting with WP Super Cache. Disable any other caching plugins and try enabling WP Super Cache again via the REST API.
    3. Check for conflicts: If disabling other plugins does not resolve the issue, check for conflicts with your theme or custom code on your site. Try disabling your theme and any custom code and see if the plugin settings are updated correctly.
    4. Check error logs: Review the error logs on your site to see if there are any error messages related to WP Super Cache or the REST API. This can help you identify the source of the issue and troubleshoot it more effectively.
    Thread Starter atoomic

    (@atoomic)

    Thanks for your reply, I tested on a fresh installation of WordPress and the API call is working fine.

    POST /wp-json/wp-super-cache/v1/settings 
    { "easy": true } # or { "easy": false }

    What I can notice is the first time I run the API to enable the plugin it flips the cache_enabled boolean and add a wp_cache_debug_username

    --- a/wp-content/wp-cache-config.php
    +++ b/wp-content/wp-cache-config.php
    @@ -5,12 +5,13 @@ WP-Cache Config Sample File
     See wp-cache.php for author details.
     */
    
    +$wp_cache_debug_username = 'deadbeefdeadbeefdeadbeefdeadbeef';
     $cache_time_interval = 600;
     if ( ! defined('WPCACHEHOME') )
            define( 'WPCACHEHOME', WP_CONTENT_DIR . "/plugins/wp-super-cache/" );
    
     $cache_compression = 0; // Super cache compression
    -$cache_enabled = false;
    +$cache_enabled = true;
     $super_cache_enabled = true;
     $cache_max_time = 1800;
     //$use_flock = true; // Set it true or false if you know what to use
    

    Later when accessing the ‘/wp-admin/options-general.php?page=wpsupercache‘ page from a browser some additional values are added to the configuration file. I’m not sure if the plugin works fine without these variable being set?

    $wp_cache_home_path = '/';
    $wp_cache_slash_check = 1;
    $cache_page_secret = 'deadbeefdeadbeefdeadbeefdeadbeef';
    

    Note/ProTip: in order to get the WebAPI working correctly you need to setup redirection in your .htaccess

    +++ b/.htaccess
    @@ -0,0 +1,15 @@
    +# BEGIN WordPress
    +# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    +# dynamically generated, and should only be modified via WordPress filters.
    +# Any changes to the directives between these markers will be overwritten.
    +<IfModule mod_rewrite.c>
    +RewriteEngine On
    +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    +RewriteBase /
    +RewriteRule ^index\.php$ - [L]
    +RewriteCond %{REQUEST_FILENAME} !-f
    +RewriteCond %{REQUEST_FILENAME} !-d
    +RewriteRule . /index.php [L]
    +</IfModule>
    +
    +# END WordPress#

    Thanks with or without these answers, we can close this case.

    Plugin Support Bruce (a11n)

    (@bruceallen)

    Happiness Engineer

    Later when accessing the ‘/wp-admin/options-general.php?page=wpsupercache‘ page from a browser some additional values are added to the configuration file. I’m not sure if the plugin works fine without these variable being set?

    The “wp_cache_debug_username” value added to the configuration file is used for debugging purposes and is not required for the plugin to function properly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Enabling SuperCache using RestAPI’ is closed to new replies.