最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - add_filter( 'user_has_cap','my_function', 10, 3 ); and call to get_users in my functio

programmeradmin6浏览0评论

I use:

add_filter( 'user_has_cap','my_function', 10, 3 ); 

In user list to allow users to edit only a specific list of users with a meta user identical to a current user connected.

To get the list of users I use get_users($args); but this triggers an infinite loop.

I guess somewhere get_users calls user_has_cap again.

I try to remove_filter before get_users($args);, this works but the filter only works the first time in my user list.

I try to add add_filter( 'user_has_cap','my_function', 10, 3 ); after get_users($args); but again this triggers an infinite loop.

remove_filter( 'user_has_cap', __FUNCTION__ );
$user_ids = get_users($args);
add_filter( 'user_has_cap', 'author_cap_filter', 10, 3 );

My other solution is to write a SQL query with $wpdb->get_results.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论