[wp-trac] [WordPress Trac] #54921: wp_dropdown_users_args Filter not working in WordPress 5.9
WordPress Trac
noreply at wordpress.org
Sun Jan 30 23:15:22 UTC 2022
#54921: wp_dropdown_users_args Filter not working in WordPress 5.9
-------------------------------+------------------------------
Reporter: martin7ba | Owner: audrasjb
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: Awaiting Review
Component: Users | Version: 5.9
Severity: major | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Comment (by martin7ba):
@audrasjb
I did few more tests and if I set it like below it works.
{{{#!php
<?php
add_filter( 'wp_dropdown_users_args', array( $this,
'display_additional_author_roles' ), 99, 2 );
public function display_additional_author_roles( $query_args, $parsed_args
) {
if ( 'company' !== get_post_type() ) {
return $query_args;
}
$query_args['capability__in'] = array( 'administrator',
'company_owner' );
unset( $query_args['capability'] );
return $query_args;
}
}}}
Works with `role__in` too as long as I unset the `capability` key.
The capability is set to `edit_posts` by default for CPT.
When registering the CPT, the Authors support (metabox) in the CPT add /
edit screen is not showing when I try to add:
{{{#!php
<?php
'capability_type' => array( 'company', 'companies' ),
'map_meta_cap' => true,
}}}
The other way I can set it as follows:
{{{#!php
<?php
public function display_additional_author_roles( $query_args, $parsed_args
) {
if ( 'company' !== get_post_type() ) {
return $query_args;
}
$query_args['capability'] = 'publish_companies';
return $query_args;
}
}}}
So every role that has the publish_companies capability will be listed as
author.
I am pretty sure this is the right way to go for it, but kinda confusing
if we use the `capability__in` key.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54921#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list