I'm working on a plugin that captures some data from a non-logged-in user (such as a Like Button) and enters it into the database based on post_id.

My plugin works fine for logged-in users but non-logged-in users produces a "-1" response in AJAX.

I'm guessing this has to do with an authentication barrier for writing to the database but I'm looking for a way to work around that.

Any ideas?

EDIT: Here is the code: http://pastebin.com/ghtvJNiW I'm basing this off the Love-It AJAX plugin by Pippin. He says in the tutorial that this only works for logged-in users but I need to get this to work for non-logged-in users as well.

  • 1
    Please share the relevant code. With the information given, there's no way your problem can be diagnosed at all. Jun 17 '12 at 16:42
  • @Johannes Please see edit.
    – AlxVallejo
    Jun 17 '12 at 16:59

The wp_ajax_{action} hook only fires for logged in users. For logged-out users the action wp_ajax_nopriv_{action} is triggered on an ajax request - so you need to hook into that as well.

  • Wow thank you so much - completely forgot about that.
    – AlxVallejo
    Jun 17 '12 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.