Support » Plugin: Q2W3 Fixed Widget for WordPress » Use wp_localize_script to pass Widgets options to JS

  • Hi.

    I’ve been looking for a repository to make a Pull Request but I haven’t found anything.

    The function q2w3_fixed_widget::js_settings() enqueues a JS object that stores the widget/sidebars options but it’s enqueued by using wp_head action and wp_add_inline_scripts but WP provides a much better funciton for that: wp_localize_script().

    The problems is that by using some kind of minification plugin (that minifies scripts, etc) you lost the reference to that script in some cases by using wp_head + wp_add_inline_script so the options are never set as a JS global.

    wp_localize_script works better. As an example, I created a patch file that you can apply and see by yourself: https://www.dropbox.com/s/6ur2gmu32c9wiqq/q2w3-fixed-widget.patch?dl=0

    The code is clear.

    Thanks!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Use wp_localize_script to pass Widgets options to JS’ is closed to new replies.