How to know what page is calling admin-ajax.php?
The original goal is this:
all users can add and remove images from the page on front end, but, they can only see their own images.
When in the admin part of the website, administrators should see all images, from every user. (only administrators have access to the admin part of the website).
So far, I have the following code:
add_action( 'pre_get_posts','users_own_attachments' );
function users_own_attachments( $wp_query_obj ) {
global $current_user, $pagenow;
$is_attachment_request = ($wp_query_obj-get('post_type')=='attachment');
if( !$is_attachment_request )
return;
if( !is_a( $current_user, 'WP_User') )
return;
if( !in_array( $pagenow, array( 'upload.php', 'admin-ajax.php' ) ) )
return;
if(basename(get_page_template()) === 'upload.php')
return;
if ( ! is_admin() $query-is_main_query() )
return;
$wp_query_obj-set('author', $current_user-ID );
return;
}
However, $pagenow
always returns admin-ajax.php
, no matter on what page it's beeing called, and basename(get_page_template())
always returns only home URL. $wp_query_obj
doesn't have any usefull information in it.
How can I check if the user is on upload.php, or on another page on the site?
Thanks.
Topic file-manager ajax uploads Wordpress
Category Web