Support » Plugin: Edit Flow » Assign an Editor using Editorial Metadata

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author cojennin

    (@comradefuzz)

    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.

    Thread Starter jasonfretwell

    (@jasonfretwell)

    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?

    Plugin Author cojennin

    (@comradefuzz)

    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.

    Thread Starter jasonfretwell

    (@jasonfretwell)

    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!

    Plugin Author cojennin

    (@comradefuzz)

    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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Assign an Editor using Editorial Metadata’ is closed to new replies.