S
S
Sergey Krivosheev2018-03-16 11:50:27
WordPress
Sergey Krivosheev, 2018-03-16 11:50:27

Wordpress client side ajax requests?

Good afternoon.
Ajax requests are implemented for the admin panel. But it was not possible to find how to send an ajax request on the site for clients.
The maximum that could be done was to send it to the same admin-ajax.php, but I had to specify add_action('wp_ajax_nopriv_****', '****');
One more question. is it possible to implement such a mechanism for regular requests (not Ajax)?
Those. add_action('wp_info', myinfo'); to work and intercept the request to the page site.ru/info (or another URL) but not wp-admin/admin-ajax.php?action=info

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-03-16
@HeadOnFire

The maximum that could be done was to send to the same admin-ajax.php

That's the way it should be. The admin-ajax.php file is a handler for ajax requests. You send to it, you hang up your code on the corresponding hook. The hook itself comes in 2 versions - wp_ajax_* (for authorized users) wp_ajax_nopriv_* (for unauthorized users). This allows you to share functionality.
The second is not entirely clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question