WordPress.org

Ideas

allow filter localized variables

  1. Tigran Nazaryan
    Member

    12345

    It is possible to call wp_localize_script with the same variable and script slug only once.
    However sometimes there is a need to filter the data passing to JavaScript.
    See details here.

    http://wordpress.stackexchange.com/questions/108362/how-to-intercept-already-localized-scripts/108364#108364
    and here
    http://wordpress.stackexchange.com/questions/191840/how-to-overwrite-js-variable-with-wp-localize-script

    Posted: 3 years ago #
  2. Drew Jaynes
    Inactive

    12345

    In a way, this suggestion only further amplifies the problem of plugin authors misusing wp_localize_script() to pass miscellaneous data to a script when the function is meant to serve as a way to pass localized strings to a script.

    It seems like the better suggestion would be to provide a more modular method for passing general data to scripts in a hookable, priority-driven way. Sort of a wp_prepare_script() idea (think wp_localize_script() + wp_prepare_attachment_for_js()).

    Does that sound about right?

    Posted: 3 years ago #
  3. Tigran Nazaryan
    Member

    12345

    Yes, exactly.
    There should be a standard way of passing any kind of PHP variables to javascript.
    I don't know whether wp_localize_script was intended to be used only for string localization, but actually this is the only way WP core provides. So developers have no other option.

    Posted: 3 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    2 Votes
  • Status

    This idea is under consideration