Advertisement
borlabs

Borlabs Cache - Nonce Support

Jul 17th, 2018
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. // The regular way
  2. wp_localize_script(
  3.     'myJSHandle',
  4.     'myJSVariable',
  5.     [
  6.         'demo'=>'demoValue',
  7.         '_ajax_nonce'=>wp_create_nonce('myAjaxNonce'),
  8.     ]
  9. );
  10.  
  11. // Borlabs Cache support + fallback
  12. if (function_exists('BorlabsCacheHelper') && method_exists(BorlabsCacheHelper(), 'localizeScript')) {
  13.    
  14.     // Same setup, just different function
  15.     BorlabsCacheHelper()->localizeScript(
  16.         'myJSHandle',
  17.         'myJSVariable',
  18.         [
  19.             'demo'=>'demoValue',
  20.             '_ajax_nonce'=>'wp_create_nonce__myAjaxNonce', // This is the difference, wp_create_nonce__ will be detected and myAjaxNonce will be used for wp_create_nonce()
  21.         ]
  22.     );
  23.    
  24. } else {
  25.     // The regular way
  26.     wp_localize_script(
  27.         'myJSHandle',
  28.         'myJSVariable',
  29.         [
  30.             'demo'=>'demoValue',
  31.             '_ajax_nonce'=>wp_create_nonce('myAjaxNonce'),
  32.         ]
  33.     );
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement