Title: Problem with wp_localize_script and wp_create_nonce
Last modified: July 3, 2017

---

# Problem with wp_localize_script and wp_create_nonce

 *  Resolved [rjaehnrich](https://wordpress.org/support/users/rjaehnrich/)
 * (@rjaehnrich)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/)
 * Hi,
 * when using your plugin i got a problem with the js of my plugin. My Plugin have
   to handle ajax_calls and so i send the wp-nonce per wp_localize_script among 
   some other things to the js.
 *     ```
        wp_localize_script( 'mypluginajax', 'myplugin_ajax',
               array(
                   'ajaxurl'   => admin_url( 'admin-ajax.php' ),
                   'nonce'     => wp_create_nonce('myplugin')
               )
           );
       ```
   
 * i figured out, that your plugin stores those infos in the database in the field‘
   extra’ and deliver this out, when the webpage request the script.
 * this results in the behavior that the ajax calls to my plugin got an 403-error
   because the nonce isnt valid.
 * i set up a filter with your plugin that the script and style of my plugin loaded
   only at the specific page (not home)
 * is there a setting or a trick, where the ‘extra’ field will be updated or the
   wp_localize_script-output be used instead ?
 * im happy to hear from you, also you can email me for further info.
 * Greetings
    Ralf Jähnrich

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [Hendrik Lersch](https://wordpress.org/support/users/riddler84/)
 * (@riddler84)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9286915)
 * Hi Ralf,
    thanks for your question. This is indeed a problem, which i haven’t
   thought about before.
 * I will try to find a solution for this. Maybe it’s not even necessary to store
   localized data into the database, because if the associated script will not be
   enqueued, the localized data will also not appear.
 * I’ve had my reasons to store it in the DB in the first place, because i deregister
   all scripts and styles before i register them again. This was the only way to
   make it possible to move stylesheets into the footer. Maybe i could scripts exclude
   from this.
 * I will check this later today and answer you soon.
 *  Plugin Author [Hendrik Lersch](https://wordpress.org/support/users/riddler84/)
 * (@riddler84)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9288713)
 * Ok, i have looked into it and it unfortunately requires a bigger rewrite than
   i thought. I will publish an updated version as soon as possible.
 *  Plugin Author [Hendrik Lersch](https://wordpress.org/support/users/riddler84/)
 * (@riddler84)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9292102)
 * I have just released an update. Localized data will now be used dynamically and
   not from the database. Please let me know, if anything doesn’t work as expected.
    -  This reply was modified 8 years, 11 months ago by [Hendrik Lersch](https://wordpress.org/support/users/riddler84/).
    -  This reply was modified 8 years, 11 months ago by [Hendrik Lersch](https://wordpress.org/support/users/riddler84/).
    -  This reply was modified 8 years, 11 months ago by [Hendrik Lersch](https://wordpress.org/support/users/riddler84/).
 *  [dhesse90](https://wordpress.org/support/users/dhesse90/)
 * (@dhesse90)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9293937)
 * Hi Hendrik,
 * I love your plugin. When I updated to the new version, however, the images and
   variation description on my Woocommerce product pages won’t load. They will work
   when I add the individual page synced with global without changing any scripts
   which I find to be strange. Please let me know if you’d like more info.
 * Thanks Dan
 *  Thread Starter [rjaehnrich](https://wordpress.org/support/users/rjaehnrich/)
 * (@rjaehnrich)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9294563)
 * Hey,
 * thats great News. tyvm for your fast bugfix!! i will check it out 🙂
 *  Plugin Author [Hendrik Lersch](https://wordpress.org/support/users/riddler84/)
 * (@riddler84)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9296175)
 * Hey Dan,
    no bugfix, which not produce new bugs 😉 I have installed woocommerce
   in my test environment and could reproduce the error you describe. I’ll try to
   fix it soon.
 *  [dhesse90](https://wordpress.org/support/users/dhesse90/)
 * (@dhesse90)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9296428)
 * Hendrik, thank you much!
 *  Plugin Author [Hendrik Lersch](https://wordpress.org/support/users/riddler84/)
 * (@riddler84)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9299776)
 * So.. found the reason and published an update. It should now work properly 🙂
   
   Good that these problems have now occured, so i can implement the fixes into 
   the next milestone version 0.5.0, which is an almost complete rewrite of the 
   plugin, with a new ajax driven UI and more features. It will be released within
   the next two months. Hope you will like it 🙂
 *  Thread Starter [rjaehnrich](https://wordpress.org/support/users/rjaehnrich/)
 * (@rjaehnrich)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9311898)
 * Hey,
 * i tested your update a while with the ‘nonce’-problematic. it works now wonderful
   🙂
    thank you for that 🙂
 * I#ve still got another question. is it planned, that i can decide (with your 
   plugin) to toggle a kind of switch for loading scripts async and/or deferred?(
   simly by adding async or defer attribute into script-tag).
 * Greetings
    Ralf 🙂
 *  Plugin Author [Hendrik Lersch](https://wordpress.org/support/users/riddler84/)
 * (@riddler84)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9321918)
 * Yes, it is planned for 0.5.0, which i’ve mentioned above. Besides the minification
   and concatenation of scripts or styles 🙂
    -  This reply was modified 8 years, 11 months ago by [Hendrik Lersch](https://wordpress.org/support/users/riddler84/).

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Problem with wp_localize_script and wp_create_nonce’ is closed to new
replies.

 * ![](https://ps.w.org/wp-script-optimizer/assets/icon-128x128.png?rev=1450859)
 * [WP Scripts & Styles Optimizer](https://wordpress.org/plugins/wp-script-optimizer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-script-optimizer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-script-optimizer/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-script-optimizer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-script-optimizer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-script-optimizer/reviews/)

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [nonce](https://wordpress.org/support/topic-tag/nonce/)
 * [product pages](https://wordpress.org/support/topic-tag/product-pages/)

 * 10 replies
 * 3 participants
 * Last reply from: [Hendrik Lersch](https://wordpress.org/support/users/riddler84/)
 * Last activity: [8 years, 11 months ago](https://wordpress.org/support/topic/problem-with-wp_localize_script-and-wp_create_nonce/#post-9321918)
 * Status: resolved