If you want the default post status to be in-progress
when contributors click on “New Post”, then you can try the following:
/**
* Set default post status as 'in-progress' for contributors
*
* @link https://wordpress.stackexchange.com/a/143128/26350
*
* @param array $data
* @return array $data
*/
function wpse_143100_wp_insert_post_data( $data )
{
$current_user = wp_get_current_user();
if( 'auto-draft' === $data['post_status']
&& 'post' === $data['post_type']
&& '0000-00-00 00:00:00' === $data['post_date_gmt']
&& in_array( 'contributor', $current_user->roles, TRUE )
)
$data['post_status'] = 'in-progress';
return $data;
}
add_filter( 'wp_insert_post_data', 'wpse_143100_wp_insert_post_data' );
It’s informative to investigate the default post status transitions:
-
Click on “New Post”:
new -> auto-draft
-
Auto-Save:
auto-draft -> draft
-
Change post status manually to “In Progress” and then press the “Update” button:
draft -> in-progress new -> inherit (revision created)
-
Press again the “Update” post:
in-progress -> in-progress
You can hook into these transitions with the transition_post_status
hook.
Update:
Here’s a modification of your example:
function educadme_assigned_to_inprogress()
{
global $post;
if ( get_current_user_id() == $post->post_author // current user is the post author
&& 'post' === get_post_type() // current post type is 'post'
&& 'assigned' === get_post_status() // current post status is 'assigned'
&& ! current_user_can( 'publish_post' ) // current user is 'contributor'
&& function_exists( 'EditFlow' ) // Edit flow plugin is installed
):
if ( $post->ID > 0 ):
$post->post_status="in-progress"; // use any post status
$pid = wp_update_post( $post ); // update post
if ( is_wp_error( $pid ) ): // debug
// error_log( $pid->get_error_message(), 1 );
endif;
endif;
endif;
}
add_action( 'admin_head-post.php', 'educadme_assigned_to_inprogress');
where I use the admin_head-post.php
hook to narrow it down to the post screen only.
The post status will only change to in-progress
if
- the current user is the post author
- the current user is a contributor
- the Edit Flow plugin is installed
- the current post type is
post
. - the current post status is
assigned
.
Notice that you will need to refresh to see the updated status.