admin管理员组文章数量:1404924
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.
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.
Share Improve this question asked Dec 26, 2019 at 10:28 BojanBojan 315 bronze badges 2 |1 Answer
Reset to default 1I was searching the internet, and I found out about this
strtolower( wp_get_referer() );
So I was able to place simple if statement and test what page called the admin-ajax.
if (strpos($referrer, 'upload.php') === false) { ... }
本文标签: uploadsHow to know what page is calling adminajaxphp
版权声明:本文标题:uploads - How to know what page is calling admin-ajax.php? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744874660a2629844.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
upload.php
? Or is that in reference to a WordPress core file? If your user is on the front end, the page they will be making the request from is unlikely to be the aforementioned unless you have created anupload.php
file yourself that is requested directly. Can you elaborate... – Adam Commented Dec 26, 2019 at 12:04