Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple wp_localize_script #850

Closed
ma3ie4 opened this issue Apr 30, 2016 · 3 comments
Closed

Multiple wp_localize_script #850

ma3ie4 opened this issue Apr 30, 2016 · 3 comments
Assignees

Comments

@ma3ie4
Copy link

ma3ie4 commented Apr 30, 2016

Hi,
great plugin! I use it in all of my projects.
I've noticed that wp_localize_script is adding multiple i18nRwmbMedia arrays to HTML.
Line 18 - \meta-box\inc\fields\media.php
It looks like for every: field 'type' => 'image_advanced' - there is separate array.

screenshot_17

As I understand it's wordpress default implementation of 'wp_localize_script'.
Maybe it will be possible to call it like 'Woocommerce plugin' did in function 'private static function localize_script' (only once):
https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-frontend-scripts.php

@rilwis
Copy link
Member

rilwis commented May 10, 2016

@funkedgeek Please fix this.

@rilwis rilwis assigned rilwis and unassigned funkatron82 May 10, 2016
@rilwis
Copy link
Member

rilwis commented May 10, 2016

Just looked at this and I think it might be the same as @ma3ie4 said about the default implementation of wp_localize_script. I'm looking for WC for a solution.

rilwis pushed a commit that referenced this issue May 10, 2016
…or all cases because we can use wp_localize_script() multiple times to add more than one localized strings with 1 handle. But in Meta Box, each fields requires only 1 localized string, so we can check if that exists and enqueue only once.
@rilwis
Copy link
Member

rilwis commented May 10, 2016

Added a fix for this. Better than the way WC does :).

The logic is checking if the script already has localized string: if no -> add localized string, if yes -> ignore. Because each field requires only 1 localized string, this works nicely :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants