Advertisement
borlabs

Popular Posts

Jul 27th, 2018
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. // Your current code - class-wordpress-popular-posts-public.php, Method enqueue_scripts()
  2. $params = array(
  3.     'rest_api' => (int) $wp_rest_api,
  4.     'sampling_active' => (int) $this->admin_options['tools']['sampling']['active'],
  5.     'sampling_rate' => $this->admin_options['tools']['sampling']['rate'],
  6.     'ajax_url' => esc_url_raw( rest_url( 'wordpress-popular-posts/v1/popular-posts/' ) ),
  7.     'action' => 'update_views_ajax',
  8.     'ID' => $is_single,
  9.     'token' => ( $wp_rest_api ) ? wp_create_nonce( 'wp_rest' ) : wp_create_nonce( 'wpp-token' ),
  10.     'debug' => WP_DEBUG
  11. );
  12.  
  13. wp_localize_script( 'wpp-js', 'wpp_params', $params );
  14.  
  15. // WITH BORLABS CACHE SUPPORT
  16. $params = array(
  17.     'rest_api' => (int) $wp_rest_api,
  18.     'sampling_active' => (int) $this->admin_options['tools']['sampling']['active'],
  19.     'sampling_rate' => $this->admin_options['tools']['sampling']['rate'],
  20.     'ajax_url' => esc_url_raw( rest_url( 'wordpress-popular-posts/v1/popular-posts/' ) ),
  21.     'action' => 'update_views_ajax',
  22.     'ID' => $is_single,
  23.     'token' => ( $wp_rest_api ) ? wp_create_nonce( 'wp_rest' ) : wp_create_nonce( 'wpp-token' ),
  24.     'debug' => WP_DEBUG
  25. );
  26.  
  27. if (function_exists('BorlabsCacheHelper') && method_exists(BorlabsCacheHelper(), 'localizeScript')) {
  28.    
  29.     $params['token'] = ($wp_rest_api) ? 'wp_create_nonce__wp_rest' : 'wp_create_nonce__wpp-token',
  30.    
  31.     // Same setup, just different function
  32.     BorlabsCacheHelper()->localizeScript('wpp-js', 'wpp_params', $params);
  33.    
  34. } else {
  35.     wp_localize_script( 'wpp-js', 'wpp_params', $params );    
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement