Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter EasyEl

    (@easyel)

    Aelia provides a plugin for Wp SuperCache. I followed their instructions and it almost works. I also added this to functions:

    function myplugin_add_wpsc_plugin_filter( $plugin ) {
    $plugin->wpsc_add_plugin(‘Aelia_Internationalisation_WPSuperCache’);
    return $plugin;
    }
    add_filter( ‘wpsc_plugin’, ‘myplugin_add_wpsc_plugin_filter’ );

    What does not work is to use an external plugin folder that is defined in wp-config.

    I defined folder and path:

    $wp_cache_plugins_dir = ‘/var/www/clients/client1/web/wp-content/wpsc-plugins’;

    But it won’t budge until I put the plugin into the Wp SuperCache own plugin folder. The path is the full path and correct.

    Any support would be appreciated!

    Saša

    (@stodorovic)

    I’m not sure that I could understand your code. You should provide filename as argument for wpsc_add_plugin. WPSC plugins are loading before regular plugins.

    You could use following code:
    do_action( 'wpsc_add_plugin', 'wp-content/wpsc-plugins/my_aelia_plugin.php' );

    More details – https://odd.blog/2017/10/25/writing-wp-super-cache-plugins/

    Thread Starter EasyEl

    (@easyel)

    Sasa,

    thank you. Is there a programmatic way to check wether the plugin was loaded?

    Best,
    Elmar

    Saša

    (@stodorovic)

    WPSC only includes PHP files before loading of plugins (from dropin advanced-cache.php > wp-cache-phase1.php). There isn’t general solution. You could try to use function_exists or class_exists to check existence of a function or a class.

    Example for WPSC multisite plugin:

    if ( function_exists( 'wp_super_cache_multisite_init' ) ) {
        // WPSC multisite plugin is loaded.
    }
    
    Thread Starter EasyEl

    (@easyel)

    Sasa,

    it does not seem to fire. Do you have demo code where to place the plugin call in the functions.php? Just paste the do_action without hook or filter like this?

    do_action( ‘wpsc_add_plugin’, ABSPATH . ‘wp-content/wpsc-plugins/aelia-wpsupercache-ac-plugin.php’ );

    Best,
    Elmar

    Saša

    (@stodorovic)

    Recommended way is adding the code in init action:

    add_action( 'init', function() {
            do_action( 'wpsc_add_plugin', 'wp-content/wpsc-plugins/aelia-wpsupercache-ac-plugin.php' );
    } );
    

    You should delete line $wp_cache_plugins_dir = ... in wp-config.php. Also ABSHPATH isn’t needed. Previous code only adds $wpsc_plugins = ... in wp-content/wp-cache-config.php. You should see this line in config file and wp-cache-phase1.php should load this file. Check permissions for directory wpsc-plugins and PHP error logs if it doesn’t work.

    Thread Starter EasyEl

    (@easyel)

    Sasa, very helpful. I initialized with the init code in functions and can confirm that the plugin does not load. File and directory permissions are 755. Below is the plugin code. I checked for the Global in the last line – it is not set. No errors in log.

    Plugin Code:

    <?php
    /**
     * Extends WP Super Cache to allow it to work correctly with Aelia Internationalisation
     * solutions.
     *
     * @author Aelia <support@aelia.co>
     */
    class Aelia_Internationalisation_WPSuperCache {
    	const VERSION = '1.0.1.160401';
    
    	// @var Aelia_Internationalisation_SuperCache The class instance
    	protected static $instance;
    
    	// @var string The cache key that Super Cache should use to retrieve the cached content
    	protected $cache_key;
    
    	// @var array A list of the cookies that should be processed to build the cache key
    	protected function expected_cookies() {
    		return array(
    			'aelia_cs_selected_currency',
    			'aelia_customer_country',
    			'aelia_customer_state',
    			'aelia_billing_country',
    			'aelia_tax_exempt',
    		);
    	}
    
    	/**
    	 * Returns the cache key to be used by WP Super Cache. The key takes into account
    	 * elements such as the selected currency, customer's country, customer's
    	 * State/county, and so on.
    	 *
    	 * @return string
    	 */
    	protected function get_cache_key() {
    		$cache_key = '';
    		foreach($this->expected_cookies() as $cookie_name) {
    			if(!empty($_COOKIE[$cookie_name])) {
    				$cache_key .= $_COOKIE[$cookie_name];
    			}
    		}
    		return $cache_key;
    	}
    
    	/**
    	 * Class constructor.
    	 */
    	public function __construct() {
    		$this->cache_key = $this->get_cache_key();
    
    		// If one or more cookies are set by the Aelia internationalisation plugins,
    		// enable the callback that will set the cache key
    		if(!empty($this->cache_key)) {
    			add_cacheaction('wp_cache_key', array($this, 'wp_cache_key'), 10, 1);
    		}
    		else {
    			// Debug
    			//var_dump("NO COOKIES FOUND. ASSUMING FIRST TIME VISITOR AND DISABLING CACHE");
    			if(!defined('DONOTCACHEPAGE')) {
    				define('DONOTCACHEPAGE', true);
    			}
    		}
    	}
    
    	/**
    	 * Initialises the plugin.
    	 */
    	public static function init() {
    		self::$instance = new self();
    	}
    
    	/**
    	 * Extends the standard cache key with one that includes additional arguments,
    	 * such as customer's currency, country, state, etc.
    	 *
    	 * @param string $cache_key The original cache key passed by WP Super Cache.
    	 * @return string The updated cache key.
    	 */
    	public function wp_cache_key($cache_key) {
    		$cache_key .= (string)$this->cache_key;
    		// Debug
    		//var_dump("CACHE KEY FOR PAGE: {$cache_key}");
    		return $cache_key;
    	}
    }
    
    $GLOBALS['aelia-internationalisation-wpsupercache']

    = Aelia_Internationalisation_WPSuperCache::init();

    Thread Starter EasyEl

    (@easyel)

    And yes, there is an entry for it in wp-cache-config.php:

    $wpsc_plugins = array ( 0 => 'wp-content/wpsc-plugins/aelia-wpsupercache-ac-plugin.php', );
    $wp_cache_mobile_groups = '';
    $wp_cache_debug_username = 'XXX';
    $wp_cache_home_path = '/';
    $wp_cache_slash_check = 1;
    $cache_page_secret = 'XXX';
    $cache_time_interval = '600';
    if ( ! defined('WPCACHEHOME') )
    	define( 'WPCACHEHOME', WP_CONTENT_DIR . "/plugins/wp-super-cache/" );
    Saša

    (@stodorovic)

    The code in Aelia_Internationalisation_WPSuperCache doesn’t follow all standards related to code style, … Global variable aelia-internationalisation-wpsupercache doesn’t contain instance of the object (method init returns null). Anyway, it should work. Is it official plugin?

    I’ve added at the end of plugin:

    error_log( 'Aelia_Internationalisation_WPSuperCache is instantiated' );
    

    I see this message in wp-content/debug.log (I’ve enabled debugging in WP).

    Thread Starter EasyEl

    (@easyel)

    Sasa,

    yes it is an official plugin from Aelia. I added the code and it does appear in the error log. So it seems to load but not work properly.

    Best,
    Elmar

    Diego

    (@daigo75)

    @stodorovic Thanks for the tests. As explained to @easyel, we wrote that module over two years ago, it could need some update. We don’t normally use Super Cache, something might have changed in the past years.

    As for the coding style not matching the one used by WordPress, that’s a deliberate choice. We have been using current coding style for 20 years, both on WordPress and non-WordPress projects. Since it’s almost identical to the WordPress style one, and it doesn’t cause any issue, we decided to keep it, for consistency across our own projects.

    Saša

    (@stodorovic)

    @daigo75 I agree. It should work, but it isn’t perfect.

    I’ll try to test more details in next days. Anyway, loading of plugin is solved.

    Diego

    (@daigo75)

    @stodorovic based on some tests, the module still works as intended. It’s purpose is to alter the cache key, so that it takes into account the value of some cookies, as well as the page URL, and store a separate copy of content for each combination of URL + cookies.

    We tested this behaviour with the latest Super Cache, and it works. When the cookies change, so does the cache key, for the same URL. This should make Super Cache serve the correct content.

    Saša

    (@stodorovic)

    You should try to enable logging on WPSC dashboard (Debug tab). Also, you need to disable “Expert” delivery method because rewrite rules will serve HTML files without checking cookies. You need to set “Simple” delivery method if you are using this WPSC plugin.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Aelia Tax Display and Currency Converter Widget’ is closed to new replies.