[wp-hackers] ajax to call function in theme
Otto
otto at ottodestruct.com
Fri Dec 11 17:27:05 UTC 2009
On Fri, Dec 11, 2009 at 10:46 AM, Davit Barbakadze <jayarjo at gmail.com> wrote:
> There's still some inconsistency. Tutorial says: "Note: In WP 2.8, if
> a user is not logged in ('wp_ajax_nopriv_my_action'), then GET
> requests are ignored (and return -1). This bug was fixed in WP 2.9."
>
> It probably means that for every wordpress with version less then 2.9
> wp_ajax_nopriv_my_action hook doesn't work, right for not logged in
> users?
No. It means that you can't use GET. So you have to use POST.
In 2.9, both GET and POST work.
> And then it goes again - next section: "Ajax on the
> Viewer-Facing Side ( WordPress 2.6 , 2.7, 2.8 )" and:
> "add_action('wp_ajax_nopriv_my_special_action',
> 'my_action_callback');". At the same time Codex says that: "We need to
> send our request to a plugin PHP file. This should be the main plugin
> PHP file. In case you want it to be a separate PHP file, bare in mind
> that you won't be able to access the Wordpress global variables, e.g.
> $wpdb, since separate files have absolutely no visibility to any part
> of WordPress at all."
That is for WP versions prior to the nopriv actions being added. Which
happened back in March:
http://core.trac.wordpress.org/changeset/10720/trunk/wp-admin/admin-ajax.php
> I think having all that together, no new comer will be able to figure
> out howto write an ajax call for not logged-in users for WP version
> less then 2.9 (current stable release that is).
The nopriv actions are there in in 2.8 and up. So probably the codex
needs editing.
On Fri, Dec 11, 2009 at 10:57 AM, Michael Pretty
<mpretty at voceconnect.com> wrote:
> I had a similar discussion on trac
> (http://core.trac.wordpress.org/ticket/11062). I think before we work on
> updating the codex, we should come up with a recommended solution for
> handling ajax requests from the front end. The problem with always using
> admin-ajax is that some sites have the admin in a different domain and or
> have the admin htaccess protected. Not all users know how to make
> exceptions in the htaccess file to allow the ajax to work.
> Davit Barbakadze wrote:
Using an SSL admin won't make any difference.
Using an admin on a different domain might be a problem, but that's a
pretty custom setup to begin with. I don't think we need explicit
support for that type of configuration.
That said, you can always use the init or the template_redirect action
to do AJAX requests to the main blog URL instead of going through the
explicit admin-ajax code.
-Otto
Sent from Memphis, TN, United States
More information about the wp-hackers
mailing list