• Resolved luminsol

    (@luminsol)


    Hi,

    In the change log for v3, there is a mention that the code needs to be adjusted if using LiteSpeed_Cache_API.

    Is there any documentation regarding what exactly has been changed? I can’t seem to find it, so if someone could point me in the right direction I would be most grateful.

    API API refactored. * NOTE: All 3rd party plugins that are using previous APIs, especially LiteSpeed_Cache_API, need to be adjusted to the latest one. Same for ESI blocks.* ESI shortcode doesn’t change.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Support Hai Zheng?

    (@hailite)

    Hi,

    Sorry for that, our docs are heavily delayed behind. Please check this ref https://github.com/litespeedtech/lscache_wp/blob/master/src/api.cls.php#L58

    NOTE: Only recommend the ones in init() func. All other functions in that API class may be deprecated in future.

    Hi @hailite

    I don’t suppose if you know if Closte (web hosting/CDN, who have a plugin) use the API?

    I’m having issues between Closte and Litespeed.

    Thanks!

    Plugin Support Hai Zheng?

    (@hailite)

    @andyuk2005 Would you mind to tell a bit more on that plugin? Seems its not on WP. I am not aware that we have other 3rd party plugins. I have made 3rd party compatibility in v3 for all current known 3rd party plugins.

    Closte plug in appears to be part of the WP hosting by the hosting provider.

    I wasn’t sure if you knew about it as they seem to be a popular host.

    I was hoping you may know and may have been able to give some insight, as I’m still experiencing issues with multiple resources being downloaded from both native address and CDN address.

    Is someone able to help me convert this API hook that I was given by Litespeed support to fix an issue we were having with Stripe ApplePay buttons on the WooCommerce product pages not working when the page is cached? Due to the API changes this code now just generates a fatal error on our site:

    /*
    * Replace Stripe payment nonce to ESI
    */

    if ( ! isset( $_GET[ ‘lsesi’ ] ) ) {
    add_action( ‘wp_footer’, ‘override_stripe_js_var’, 99999 ) ;
    }

    function override_stripe_js_var() {
    echo LiteSpeed_Cache_API::esi_url( ‘stripe_data_esi’, ‘Hook Stripe Data Esi’, [], ‘private,no-vary’, true ) ;
    }

    LiteSpeed_Cache_API::hook_tpl_esi(‘stripe_data_esi’, ‘hook_stripe_data_esi’ );

    // I guess this line would have to change to something like:

    add_action( ‘litespeed_esi_load-‘ . ‘stripe_data_esi’, ‘hook_stripe_data_esi’ );

    I’m not sure about the code within the override_stripe_js_var function though?

    Many thanks,
    Gordon

    Plugin Support Hai Zheng?

    (@hailite)

    Hi @gferguson78,

    Here is the changes:

    
    function override_stripe_js_var() {
        echo apply_filters( 'litespeed_esi_url', ‘stripe_data_esi’, ‘Hook Stripe Data Esi’, [], ‘private,no-vary’, true ) ;
    }
    
    add_action( ‘litespeed_esi_load-stripe_data_esi’, ‘hook_stripe_data_esi’ );
    
    

    The fatal error is caused by the direct usage of LiteSpeed_Cache_API but didn’t check if it exists or not first.

    Thanks for your help Hai.

    I’ve updated this now. This seems to have partially sorted the issue but I still seem to be having trouble with ApplePay buy now buttons on WooCommerce product pages. When the page is cached there is an issue with the nonce also being cached and this is preventing the ApplePay process from working correctly – the ApplePay box just hangs indefinitely.

    This is the full (now updated) code I was sent from Litespeed support some time ago. It did work but I guess it must be out of date with the plugin now. I’ve checked this again on our live site and sure enough it no longer works.

    /*
     * Replace Stripe payment nonce to ESI
     */
    
    if ( ! isset( $_GET[ 'lsesi' ] ) ) {
        add_action( 'wp_footer', 'override_stripe_js_var', 99999 ) ; 
        
    }
    
    function override_stripe_js_var() {
        echo apply_filters( 'litespeed_esi_url', ‘stripe_data_esi’, ‘Hook Stripe Data Esi’, [], ‘private,no-vary’, true ) ;
    }
    
    add_action( 'litespeed_esi_load-stripe_data_esi', 'hook_stripe_data_esi' );
    
    function hook_stripe_data_esi() {
        echo "<script>";
        echo "wc_stripe_payment_request_params.nonce.payment = '" . wp_create_nonce( 'wc-stripe-payment-request' ) . "';";
        echo "wc_stripe_payment_request_params.nonce.shipping = '" . wp_create_nonce( 'wc-stripe-payment-request-shipping' ) . "';";
        echo "wc_stripe_payment_request_params.nonce.update_shipping = '" . wp_create_nonce( 'wc-stripe-update-shipping-method' ) . "';";
        echo "wc_stripe_payment_request_params.nonce.checkout = '" . wp_create_nonce( 'woocommerce-process_checkout' ) . "';";
        echo "wc_stripe_payment_request_params.nonce.add_to_cart = '" . wp_create_nonce( 'wc-stripe-add-to-cart' ) . "';";
        echo "wc_stripe_payment_request_params.nonce.get_selected_product_data = '" . wp_create_nonce( 'wc-stripe-get-selected-product-data' ) . "';";
        echo "wc_stripe_payment_request_params.nonce.log_errors = '" . wp_create_nonce( 'wc-stripe-log-errors' ) . "';";
        echo "wc_stripe_payment_request_params.nonce.clear_cart = '" . wp_create_nonce( 'wc-stripe-clear-cart' ) . "';";
        echo "</script>";
    }

    Hopefully you can help with this issue. I see a fix has now been added in the most recent version for a identical issue I had with PayPal Smart Buttons on product pages. Hopefully this can be sorted for these ApplePay buttons as well.

    Gordon

    Plugin Support Hai Zheng?

    (@hailite)

    Well it seems you are having nonce. You need to specify those nonces in ESI nonce setting of v3. That is especially to fix the nonce issue.

    Go to Cache -> ESI -> ESI Nonce, append these

    
    wc-stripe-payment-request
    wc-stripe-payment-request-shipping
    wc-stripe-update-shipping-method
    and all left
    

    If you still have issues for quick fix, come to slack and PM me(hai).

    Thanks Hai,

    I have now tried this and it did initially seem to work – in basic testing the Apple Pay smart button on WooCommerce product pages did work correctly when pages were cached. It did however massively slow down page load times and seems to have put a lot of extra load on the server for some reason. I’m not sure if by uncaching these then it uncached the whole page?

    The fix you have added in V3 for PayPal Smart Buttons is working well though and doesn’t seem to be causing any speed issues.

    I’ll maybe drop you a message through Slack to see if it’s possible to find another way to fix this nonce issue as it would be good to be able to use the Apple Pay smart button on product pages. I’ve had to disable it for now though.

    Thanks for your help!
    Gordon

    Plugin Support Hai Zheng?

    (@hailite)

    Sure, welcome to pm me anytime.

    To track the reason for server log, better turn on log, see when you visit that page, which page requests are logged. ESI will give additional visit to your WP, but as long as it cached, shouldn’t have more load.

    Hi Hai

    Hope you’re well

    We’re having the same issue trying to refactor this code

    LiteSpeed_Cache_API::hook_tpl_esi(‘tsmc_phone_no_identify’, ‘hook_esi’ );
    function hook_esi( $param ) {

    //From original call
    if ($_GET[‘gclid’] || isset($_COOKIE[‘google_ppc’])){
    echo get_field(‘ppc_phone_number’, ‘options’);
    } else {
    echo get_field(‘phone_number’, ‘options’);
    }

    }

    Could you help please? I can’t see any new filter to achieve this

    Thank you

    Plugin Support Hai Zheng?

    (@hailite)

    Hi @identifydigital

    Change

    
    LiteSpeed_Cache_API::hook_tpl_esi(‘tsmc_phone_no_identify’, ‘hook_esi’ );
    

    to

    
    add_action( 'litespeed_esi_load-tsmc_phone_no_identify', 'hook_esi' );
    

    Just be aware that you need to type that single quote manually. WP converted it to a different char.

    Thanks Hai – really appreciated!

    Plugin Support Hai Zheng?

    (@hailite)

    You are most welcome. If you have any API questions, don’t hesitate to create a new topic.

    Good day!

    Can I just quickly check something Hai – previously our code to purge a WooCommerce product by its ID was as follows:

    LiteSpeed_Cache_API::purge_post($product_id);

    Should this new code do the same thing?

    add_action( ‘litespeed_purge_post’, $product_id );

    I’ve changed it but it doesn’t seem to be uncaching the product page for some reason?

    Many thanks,
    Gordon

    • This reply was modified 4 years, 10 months ago by gferguson78.
Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘What has changed with LiteSpeed_Cache_API ?’ is closed to new replies.