Localizes a script, but only if script has already been added. Can also be used to include arbitrary Javascript data in a page.
0
votes
1answer
77 views
Can't seem to get wp_localize_script to work
This is my code:
wp_enqueue_script('ms_ajax_localized');
wp_localize_script( 'ms_ajax_localized', 'MS_Ajax', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nextNonce' => ...
0
votes
1answer
89 views
Using template tags in external JS file
I’d like to know how to use the get_bloginfo( 'template_directory' ) tag in an external JS file.
I just found out that it’s possible using the wp_localize_script function but I didn’t manage to get ...
0
votes
1answer
46 views
Passing widget options to external script
I am trying to pass some widget options to an external script using wp_localize_script. I know how to pass the variables and how to use them within the script, but how do I extract the widget options ...
5
votes
2answers
209 views
What is the correct way to build a widget using OOP
I am working on a simple search form widget, with a built in autocomplete capability (You can download the current version here). The plugin is working, but I am currently rewriting all the code using ...
1
vote
1answer
293 views
How to localize inline script called with ajax
I have a loop of posts and I allow a user to edit each post using ajax. When the edit button is clicked for the post I use ajax to retrieve the template part containing the edit form for the post. ...
1
vote
1answer
122 views
How to get the post ID when creating JS variables with localize_script
how do you set the current post ID as a JS variable with localize_script? It seems like the $post variable isn't availible in the functions.php file. When is it created? Do i have to add localize ...
2
votes
2answers
152 views
Nonce best practices: hidden input vs. wp_localize_script?
I noticed while looking at the HTML of an edit page that WordPress uses a lot of hidden input elements for storing nonces. Is there a significant advantage to using either this style of storing ...
0
votes
1answer
93 views
jQuery dialog prints HTML-Tags under Wordpress
i need some help. I am using wp_localize_script in my Wordpres_Plugin. Inthe documentready-function i use this Code to bring the Message up:
$('#button-setup-league').click(function()
{
$( "#dialog ...
2
votes
2answers
135 views
Use wp_localize_script for non existing script
Task: What I'm trying to do
I'm fetching data via the WP Http API from a remote server. The data I'm getting back is JSON encoded. In one of my methods, I'm converting them back and then push it into ...
0
votes
0answers
232 views
Localization variable not visible in minified script [closed]
I'm using W3 Total Cache and WP-PostRatings. JavaScript is minimized. The minimized file contains the WP-PostRatings' js file which is enqueued & localized as:
wp_enqueue_script('wp-postratings', ...
4
votes
1answer
230 views
w3 total cache minification breaks wp_localize_script()
I am trying to configure W3 total cache plugin to speed up my site. The minify option is great but I am running into the following issue:
Let's say I have a JavaScript file I am attached wp_localize ...
0
votes
1answer
130 views
Parsing post->ID in included plugin file
running into something that has got me completely puzzled.
I have a plugin with a main file that looks like this:
// Global Variables
$mouldings_prefix = 'mouldings_';
$mouldings_name = 'Mouldings';
...
1
vote
2answers
73 views
esc_html__ security : what for in this example?
how does esc_html__ (the 2nd one) protect the $message variable from being hacked ? what's the point to use this protection here (the second one with a plain text)?
<?php
function unknown(){
...
2
votes
1answer
390 views
enqueue and localize script in footer
I have a script which must run in my footer, after some variables are declared. It works if I just put the code directly in my footer file, but I think best practices dictate I should do this via ...
-1
votes
1answer
773 views
Using WP Ajax and jQuery to process multiple forms on the same page?
I'm using the following to make ajax calls:
wp_enqueue_script( 'my-ajax-request', TAF_PLUGIN_URL . 'js/ajaxcf.js', array( 'jquery' ) );
wp_localize_script( 'my-ajax-request', 'MyAjax', array( ...
0
votes
2answers
147 views
adding custom script to functions file
I have a problem adding a custom script to my functions.php file:
add_action('wp_print_scripts', 'load_AJAX_URL__');
function load_AJAX_URL__() {
wp_localize_script( 'ajax_URL', 'MyAjax', array( ...
1
vote
1answer
158 views
How to localize admin.php only once
I am creating a set of plugins that all use AJAX. Now localizing the admin.php in all the plugins seems to be a bit of an overkill. Is there a way to localize the script only once.\
Now I do not know ...
3
votes
1answer
397 views
Multiple wp_localize_script
Is it possible to localize a script more than once? I want to send two separate arrays of params.
Or is it only possible to localize a script once, in which case, I'll have to combine the arrays?
...
0
votes
1answer
414 views
Does wp_localize_script Call a Javascript Function or Simply Pass PHP Parameters to It
Easy question: I'm trying to understand wp_localize_script.
Does wp_localize_script call a javascript function or does it simply pass PHP parameters to javascript?
I want to pass php parameters to ...
0
votes
2answers
384 views
wp_enqueue_script calling jQuery at different times for different browsers?
This makes no sense, but in looking at my view source across browsers, wp_localize_script() is inserting tags as expected for all browsers other than IE7,8,9. The script tag is simply not there in ...
1
vote
1answer
96 views
Find out if enqueued script uses wp_localize_script?
Is there a function that can check if an enqueued script has a call to wp_localize_script attached to it?