Skip Navigation

[Resolved] Allow administrator to assign the author for subscriber

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.79 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 replies, has 2 voices.

Last updated by kelvinL-2 3 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1980405
Screenshot 2021-03-10 at 10.09.28 AM.png
Screenshot 2021-03-10 at 9.55.07 AM.png

Dear Sir/Madam,

All users register into my site will be assigned as subscribers, I have CRED form to let subscriber to apply an tour application and add the applicants.

From the backend, when the administrator edit the CPT application or applicant, there is no choice from the Author to select the subscriber. I understand subscriber has no post edit ability, how can I associate the CPT created by the record via the CRED?

Is it must to create custom role to all new register user. It doesn't help even we change the access to allow Subscriber to edit/delete the CPT application and applicant. Please help.

Best regards,

Kelvin.

#1980487

Hi Kelvin,

Thank you for contacting us and I'd be happy to assist.

To include the "subscriber" role users in the list of author selector in the admin area, you can use the "wp_dropdown_users_args" filter:
https://developer.wordpress.org/reference/hooks/wp_dropdown_users_args/#user-contributed-notes

For example, to limit the author selection to "subscriber" and "administrator" roles:


function wpdocs_add_subscribers_to_dropdown( $query_args ) {
 
    // Use this array to specify multiple roles to show in dropdown
    $query_args['role__in'] = array( 'subscriber', 'administrator' );
 
    // Unset the 'who' as this defaults to the 'author' role
    unset( $query_args['who'] );
  
    return $query_args;
}
add_filter( 'wp_dropdown_users_args', 'wpdocs_add_subscribers_to_dropdown' );

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

regards,
Waqar

#1985817

Dear Waqar,

I added below code in functions.php but doesn't work. Will it be only applied to WP default page and post, my post is the Toolset Custom Post.

add_filter( 'wp_dropdown_users_args', 'add_subscribers_to_dropdown', 10, 2 );
function add_subscribers_to_dropdown( $query_args, $r ) {
 
    $query_args['who'] = '';
    return $query_args;
 
}
#1986433

Thanks for writing back and the code that I shared, will work for Toolset custom post types too.

I don't see where you've added the name of roles that should be included in the author list, in your code snippet.
( specifically check the line# 5 from my code snippet: $query_args['role__in'] = array( 'subscriber', 'administrator' ); )

Can you please check the code snippet that I shared earlier and use it as it is?

#1991431
Screenshot 2021-03-18 at 7.19.46 AM.png
Screenshot 2021-03-18 at 7.17.38 AM.png
Screenshot 2021-03-18 at 7.17.23 AM.png

Dear Waqar,

Yes, I add your script to functions.php but not work, so I research the code I got from somewhere.

#1991985

It is strange that the code is working on my test website, but not on yours.

Can you please share temporary admin login details along with the link to the page where this author drop-down can be seen?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

#1993403

Thank you for sharing the access details.

I see multiple (3) functions added for the filter "wp_dropdown_users_args" in the theme's "functions.php" file.
( screenshot: hidden link )

Can you please remove the 2nd and 3rd code blocks shown in the screenshot and then check the author dropdown again?

#1993539

Dear Waqar,

Oh, sorry for my mistake. Yes, you helped to solve the issue.

#1993543

My issue is resolved now. Thank you!