[wp-trac] [WordPress Trac] #35154: The admin_url filter might break ajaxurl usage
WordPress Trac
noreply at wordpress.org
Fri Dec 18 13:14:04 UTC 2015
#35154: The admin_url filter might break ajaxurl usage
--------------------------+------------------------------
Reporter: jadpm | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by stephenharris):
As an aside, shouldn't they be using `wp.ajax.settings.url` rather than
defining it themselves? (wp-util.js is a small dependency to add if it
needs to be).
As for a js version of `add_query_arg()`, I'm not able to create a patch
just now, but I use the following in a few plug-ins (it's not a strict
port of `add_query_arg()`):
{{{#!js
eo.add_query_arg = function( key, value, uri ){
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}else {
return uri + separator + key + "=" + value;
}
};
}}}
that could be modified to accept an object and URL so that you can more
concisely add multiple key-value pairs.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35154#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list