user3782619
user3782619

Reputation: 9

Wordpress Ajax for logged in user fails

I am using wordpress 4.1.1. wp-admin and other several pages (like login, register...) use https connection. My goal is create ajax request for adding tickets to system.

So I can not call function for logged in user it calls function for not-logged in user. But when I add https for this page it`s work fine for me.

Question:

How I can keep user logged in on https and http, so is_user_logged_in() in amin-ajax.php works fine?

Upvotes: 0

Views: 1540

Answers (2)

user3782619
user3782619

Reputation: 9

I found solution, but it1s not pretty good, we should use http://example.com/wp-admin/admn-ajax.php url not https://example.com/wp-admin/admn-ajax.php, that I have used.

Upvotes: -1

WpTricks24
WpTricks24

Reputation: 825

Just need to add one more line with your code :

for logged in users : 

add_action( 'wp_ajax_my_request', 'my_request' ); //calling function "my_request" for logged in users only

for non-logged in users : 

add_action( 'wp_ajax_nopriv_my_request', 'my_request' ); //calling function "my_request" for non-logged in users

for more information about addition of ajax in wordpress, just check here : http://www.wptricks24.com/how-to-use-ajax-wordpress/

Upvotes: 3

Related Questions