Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
litespeed_wiki:cache:lscwp:esi_replace [2017/09/24 15:43]
Hai Zheng
litespeed_wiki:cache:lscwp:esi_replace [2017/10/01 17:57]
Hai Zheng
Line 1: Line 1:
-Note: LiteSpeed WordPress Cache plugin needs to be v1.2.4+.+Note: LiteSpeed WordPress Cache plugin needs to be v1.3+.
  
 Let's take **Caldera Forms Version 1.5.6.1** as the example. ​ Let's take **Caldera Forms Version 1.5.6.1** as the example. ​
  
 In <​code>​caldera-forms/​classes/​render/​nonce.php</​code>​ line 86 <​code>​public static function nonce_field( $form_id )</​code>​ is where the form nonce is generated. So to convert it to ESI, change In <​code>​caldera-forms/​classes/​render/​nonce.php</​code>​ line 86 <​code>​public static function nonce_field( $form_id )</​code>​ is where the form nonce is generated. So to convert it to ESI, change
-<syntaxhighlight lang='​php'​>+<code>
  public static function nonce_field( $form_id ){  public static function nonce_field( $form_id ){
  $nonce_field = '<​input type="​hidden"​ id="'​ . esc_attr( self::​nonce_field_name( $form_id ) ) . '"​ name="'​ . esc_attr( self::​nonce_field_name() ) . '"​ value="'​ . esc_attr( self::​create_verify_nonce( $form_id ) ) . '" ​ data-nonce-time="'​ . esc_attr( time() ) . '"​ />';​  $nonce_field = '<​input type="​hidden"​ id="'​ . esc_attr( self::​nonce_field_name( $form_id ) ) . '"​ name="'​ . esc_attr( self::​nonce_field_name() ) . '"​ value="'​ . esc_attr( self::​create_verify_nonce( $form_id ) ) . '" ​ data-nonce-time="'​ . esc_attr( time() ) . '"​ />';​
Line 10: Line 10:
  return $nonce_field;​  return $nonce_field;​
  }  }
-</syntaxhighlight>+</code>
  
 to to
  
-<syntaxhighlight lang='​php'​>+<code>
  public static function nonce_field( $form_id, $from_esi = false ){  public static function nonce_field( $form_id, $from_esi = false ){
  
  if ( ! $from_esi ) {  if ( ! $from_esi ) {
  if ( method_exists( '​LiteSpeed_Cache_API',​ '​esi_enabled'​ ) && LiteSpeed_Cache_API::​esi_enabled() ) {  if ( method_exists( '​LiteSpeed_Cache_API',​ '​esi_enabled'​ ) && LiteSpeed_Cache_API::​esi_enabled() ) {
- if ( method_exists( '​LiteSpeed_Cache_API',​ '​v'​ ) && LiteSpeed_Cache_API::​v( '1.2.4' ) ) {+ if ( method_exists( '​LiteSpeed_Cache_API',​ '​v'​ ) && LiteSpeed_Cache_API::​v( '1.3' ) ) {
  $params = array( '​form_id'​ => $form_id ) ;  $params = array( '​form_id'​ => $form_id ) ;
  return LiteSpeed_Cache_API::​esi_url( '​caldera_forms',​ '​Caldera Forms',​ $params ) ;  return LiteSpeed_Cache_API::​esi_url( '​caldera_forms',​ '​Caldera Forms',​ $params ) ;
Line 40: Line 40:
  exit ;  exit ;
  }  }
-</syntaxhighlight>+</code>
  
 Then go to <​code>​caldera-forms/​classes/​core.php</​code>,​ in <​code>​function __construct()</​code>​ line 146 or other preferred position, add this: Then go to <​code>​caldera-forms/​classes/​core.php</​code>,​ in <​code>​function __construct()</​code>​ line 146 or other preferred position, add this:
-<syntaxhighlight lang='​php'​>+<code>
  if ( method_exists( '​LiteSpeed_Cache_API',​ '​esi_enabled'​ ) && LiteSpeed_Cache_API::​esi_enabled() ) {  if ( method_exists( '​LiteSpeed_Cache_API',​ '​esi_enabled'​ ) && LiteSpeed_Cache_API::​esi_enabled() ) {
  LiteSpeed_Cache_API::​hook_tpl_esi( '​caldera_forms',​ '​Caldera_Forms_Render_Nonce::​hook_esi'​ );  LiteSpeed_Cache_API::​hook_tpl_esi( '​caldera_forms',​ '​Caldera_Forms_Render_Nonce::​hook_esi'​ );
  }  }
  
-</syntaxhighlight>+</code>
  
 Now **Caldera Forms** can be perfectly cached with ESI on. Now **Caldera Forms** can be perfectly cached with ESI on.
  • Admin
  • Last modified: 2017/10/02 14:33
  • by Hai Zheng