hooks - `rest_user_query` can't access post author in post edit screen

I'm trying to modify the user dropdown in the post edit screen to show only (a) the current user and (b) the curren

I'm trying to modify the user dropdown in the post edit screen to show only (a) the current user and (b) the current author of the post. I can't do this using wp_dropdown_users_args because the meta box in the block editor gets the list of users via a REST query. (wp_dropdown_users_args works fine for the user dropdown in the "Quick Edit" form, however.)

rest_user_query can modify this dropdown for me, but I can't seem to get any info about the post I'm editing, so I'm unable to determine who the current author is. I can add the current user to the include value, but then the dropdown doesn't appear at all (I assume because it has only returned a single user).

What I want to do is something like this, but I don't know how to define the $POST_AUTHOR variable here:

function rest_user_filter( $prepared_args, $request = NULL ) {
  $args['include'] = [ get_current_user_id() ];
  array_push( $args['include'], $POST_AUTHOR;
  return $args;
}
add_filter( 'rest_user_query', 'rest_user_filter' );

I'd also only like to do this on the post edit screen, of course, too.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744780648a4593317.html

相关推荐

  • hooks - `rest_user_query` can't access post author in post edit screen

    I'm trying to modify the user dropdown in the post edit screen to show only (a) the current user and (b) the curren

    13小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信