Code Sample: Changing the number of posts on the Story Budget

We received a question from Quint Randle about how to customize the number of posts displayed in the Story Budget view of Edit Flow (which is 10 by default), so I thought I’d write up a quick tutorial here. It’s simple, and enabled in Edit Flow by this bit of code.

To increase (or decrease) the number of posts from the default of 10, just add a small code snippet to the functions.php file in your theme. For instance, the following would increase the number of stories shown per category to 20:
[code lang=”php” title=”Change the number of posts displayed on the Story Budget” light=”true”]
add_filter( ‘ef_story_budget_query_limit’, create_function( ”, ‘return 20;’ ) );
[/code]
Just modify the ’20’ above to whatever number of posts you’d like to see in the Story Budget view. And voilà!

Of course you could split out the create_function call above to actually use a function that you’ve defined elsewhere in your functions.php file, but unless you’re going to have complicated logic to decide how many posts to display, I don’t see the need for anything beyond that one-liner.

Any further tutorials you would like to see on our blog here? There are lots and lots of filters baked into Edit Flow that are just dying to be unlocked by you, our users—let us know in the comments below what you’d like to customize or see in action and we’ll do our best to explain how to use it! And as always, for support questions, please post your question here.

Code Sample: Filtering Custom Statuses by Role

We’ve received a number of requests from Edit Flow users asking for the ability to limit statuses to specific roles. While this isn’t possible via the WordPress admin, you can write a bit of code to implement this. Just add the following snippet to the functions.php file of your active theme and modify as necessary.

The code sample limits authors to only set ‘Draft’ and ‘Pitch’ statuses, whereas editors (and administrators, by omission) have access to all statuses.

 -1,
	'author' => array( 'draft', 'pitch' )
);

add_filter( 'ef_custom_status_list', 'ef_x_filter_statuses_by_role', 10, 2 );

function ef_x_filter_statuses_by_role( $statuses, $post ) {
	global $role_status_map;
	
	$role = ef_x_get_user_role();
	if( isset( $role_status_map[$role] ) && $role_status_map[$role] != -1 ) {
		$statuses = ef_x_filter_by_value( $statuses, 'slug', $role_status_map[$role] );
	}
	
	return $statuses;
}

function ef_x_get_user_role() {
	$user = wp_get_current_user();
	return array_shift( $user->roles );
}

function ef_x_filter_by_value( $array, $property, $value ) { 
	$filtered_array = array();
	foreach( (array) $array as $index => $item ) { 
		if( isset( $item->$property ) ) {
			if ( ( is_array( $value ) && in_array( $item->$property, $value ) ) || $item->$property == $value ) {
				$filtered_array[$index] = $item;
			}
		}
	} 
	return $filtered_array; 
}