• Resolved rjaehnrich

    (@rjaehnrich)


    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

    (@riddler84)

    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

    (@riddler84)

    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

    (@riddler84)

    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.

    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

    (@rjaehnrich)

    Hey,

    thats great News. tyvm for your fast bugfix!! i will check it out ??

    Plugin Author Hendrik Lersch

    (@riddler84)

    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.

    Hendrik, thank you much!

    Plugin Author Hendrik Lersch

    (@riddler84)

    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

    (@rjaehnrich)

    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

    (@riddler84)

    Yes, it is planned for 0.5.0, which i’ve mentioned above. Besides the minification and concatenation of scripts or styles ??

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.