WordPress.org

Ready to get started?Download WordPress

Forums

Edit Flow
Assign an Editor using Editorial Metadata (6 posts)

  1. jasonfretwell
    Member
    Posted 11 months ago #

    Hi! Although this issue has already been addressed and, apparently resolved here:

    http://wordpress.org/support/topic/editorial-metadata-limit-user-field-to-specific-role?replies=4

    But I do not understand the resolution and no one has addressed my query so I thought I would post a new topic.

    Basically, I need Contributors to be able to select an Editor from a Editorial Metadata dropdown menu within the Post they are writing. Obviously, this can be done for all users but how do I filter the dropdown menu to only allow users from a specific User Group ie. Editors? The link above refers to adding a filter to the development version but doesn't say where to get the development version or how to add the filter.

    Can anyone out there help? Thanks

    http://wordpress.org/plugins/edit-flow/

  2. cojennin
    Member
    Plugin Author

    Posted 11 months ago #

    Sorry about that, looks like there's a syntax error in the code that was in that last post.

    add_filter( 'ef_editorial_metadata_user_dropdown_args', 'efx_editorial_metadata_user_dropdown_args' );
    function efx_editorial_metadata_user_dropdown_args( $args ) {
       $args['include'] = array( 1, 2, 3 );
        return $args;
    }

    Could you try this and see what you get? From what it looks like this would limit certain users (users with user id's 1, 2, 3). It should be fairly easy to rewrite this to just get all users ID's from user's within a certain usergroup and place them in that array. But first try pasting this back in and seeing if it works on your site. If it does, we can walk through extending it a bit to get it working like how you've specified.

  3. jasonfretwell
    Member
    Posted 10 months ago #

    Hi! Thanks for getting back to me about this - it's such a small issue but it's the difference between us being able to use EditFlow within our organisation or not.

    OK, so I've pasted your code into the functions.php file (via 'Snippets' plugin) and it doesn't change anything within the metadata drop down - it still shows ALL users regardless of role or user group. I have no idea whether I am using the version of WordPress or EditFlow that supports this (WordPress 3.6.1, EditFlow 0.7.6) but it would be a really great feature if I could get it to work! Any ideas what I'm doing wrong?

  4. cojennin
    Member
    Plugin Author

    Posted 10 months ago #

    Jeez, my bad. Didn't see this reply (email going a little wonky). Let me work on it a bit and see if I can whip something up. Could be useful to put on editflow.org, as it seems like something other folks might want to utilize.

  5. jasonfretwell
    Member
    Posted 10 months ago #

    No problem Cojennin! Thanks for getting back to me nevertheless. I still haven't fixed this issue through EditFlow but have used a couple of other plugins to replicate the behaviour I need.

    I do think that it would be a great feature for EditFlow though. If you do manage to integrate this then please let me know. Thanks for your work on the plugin, it's proving really useful!

  6. cojennin
    Member
    Plugin Author

    Posted 10 months ago #

    Hey,
    So I was messing around and something like the following should work:

    add_filter( 'ef_editorial_metadata_user_dropdown_args', 'efx_editorial_metadata_user_dropdown_args' );
    
    function efx_editorial_metadata_user_dropdown_args( $args ) {
    	if( $args['name'] == '_ef_editorial_meta_user_user-assigned' ) {
    		global $current_user;
    		get_currentuserinfo();
    		if( !in_array( 'contributor', $current_user->wp_capabilities ) )
    			return $args;
    
    		$contributors = get_users( array( 'role' => 'editor' ) );
    		$contributor_ids = '';
    
    		if( empty( $contributors ) )
    			return $args;
    
    		foreach( $contributors as $user ) {
    			$contributor_ids .= $user->data->ID . ',';
    		}
    
    		$args['include'] = $contributor_ids;
    	}
    
    	return $args;
    }

    I'll walk through it real quick.

    Here we're registering the filter for all editorial metadata that is the type user.

    add_filter( 'ef_editorial_metadata_user_dropdown_args', 'efx_editorial_metadata_user_dropdown_args' );

    The next part is the only part you will probably have to modify before placing in functions.php:
    if( $args['name'] == '_ef_editorial_meta_user_user-assigned' )

    In this snippet we're checking which editorial metadata it is (in the event we have multiple editorial metadata's that are of the type "user"). I gave my editorial metadata the slug user-assigned. If you gave your editorial metadata the slug users-are-cool, then yours would probably look like:

    if( $args['name'] == '_ef_editorial_meta_user_users-are-cool' ).

    Here we're checking if the user is a contributor:

    if( !in_array( 'contributor', $current_user->wp_capabilities ) )
        return $args;

    *This doesn't check capabilities, it checks the user role. This shouldn't cause any bugs, but keep an eyeball on it.

    Lastly, we're getting all the users that are editors, and we're going to have our dropdown just show those:

    foreach( $contributors as $user ) {
        $contributor_ids .= $user->data->ID . ',';
    }
    $args['include'] = $contributor_ids;

    Hopefully this works! Definitely reply back here if you need any help!

Reply

You must log in to post.

About this Plugin

About this Topic