This is an old revision of the document!


Assume the following code in one WordPress plugin is some private info in one page.

<syntaxhighlight lang='php'> function show( $id ) {

  return "ID: $id <a href='test?nonce=$nonce'>Click Me</a>";

}

echo show(35); </syntaxhighlight>

With LSCWP ESI API, it can be changed to this: <syntaxhighlight lang='php'> function show( $id, $from_esi = false ) {

  // To make sure it is the original call
  if ( ! $from_esi ) {
      // To make sure LSCWP ESI is on
      if( method_exists( 'LiteSpeed_Cache_API', 'esi_enabled' ) && LiteSpeed_Cache_API::esi_enabled() ) {
          // To make sure is using the compatible API version
          if ( method_exists( 'LiteSpeed_Cache_API', 'v' ) && LiteSpeed_Cache_API::v( '1.2.4' ) ) {
        $params = array( 'id' => $id ) ;// If you have any parameters want to pass
              // Let's turn this block to ESI by returning directly
        return LiteSpeed_Cache_API::esi_url( 'my_plugin_esi', 'My Plugin Name', $params ) ;
          }
}
  }
  return "ID: $id <a href='test?nonce=$nonce'>Click Me</a>";

}

echo show(35); </syntaxhighlight>

And then, in your main process, hook the ESI call to the real content: <syntaxhighlight lang='php'> if ( method_exists( 'LiteSpeed_Cache_API', 'esi_enabled' ) && LiteSpeed_Cache_API::esi_enabled() ) {

  LiteSpeed_Cache_API::hook_tpl_esi('my_plugin_esi', 'hook_esi' );

}

function hook_esi( $params ) {

  $id = $params[ 'id' ] ;
  echo show( $id, true ) ;

} </syntaxhighlight>

  • Admin
  • Last modified: 2017/09/24 15:12
  • by Hai Zheng