1

It's not uncommon for WordPress sites to have 10+ instances of the admin-ajax.php path outputted to the front-end for use by plugins and themes. Does anyone know if there is a reason WordPress core hasn't added this as a default? It seems like it would save a ton of duplication.

4
  • 1
    kinda pointless question. yes it should be, but asking here is pointless as we can only guess why. To know why, you should open ticket and request this feature Commented Mar 6, 2016 at 3:21
  • If someone actually knows the answer to this then it isn't pointless, correct? But, to your point, I'll look at opening a ticket. I just thought there may be a reason for it that is known to someone. Commented Mar 6, 2016 at 6:06
  • It is just that why feature X is not in core can have many explanations, including,"no one asked for it". Even why feature Y is in core will not be a great question. a better question can probably be "how do I avoid ajax url duplication" Commented Mar 6, 2016 at 7:30
  • If you already know the path, why do you need it to be stored in an object? Do you store the paths to other resources such as images in JS objects as well? Commented Mar 6, 2016 at 8:13

1 Answer 1

1

As you are probably aware admin-ajax.php has been around for a very long and it provides a unified file for making AJAX requests, whether they are from the back end or front end, however its responsbility is not to provide a unified way to access it's URL as a JavaScript variable in the front end.

WordPress provides you the destination file, it's up to you how you access it.

Most people who are localizing variables in the front end do so along with other data they need for the application, not just the AJAX URL.

I suspect this, along with the fact that WordPress provides no other standard information in the way of JavaScript variables (excluding the emoji rubbish); as to being the reason why it hasn't been standardized in the front end.

I've wondered the same thing before, in the spirit of keeping it DRY, but this is WordPress afterall where there is a great deal of carry-over in old architecture and design decisions that are still yet to be improved and this could very well be one of those things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.