On my websites the contributors (user role contributor) are allowed to post posts. All their posts are not published automatically (these posts are with pending status). After approving their first post, i modify their user role to author. This is a manual process and i want to make it automatically. So when their first post gets approved their user role gets changed automatically from contributor to author.
I use a custom post type for this posts. It is called 'portfolio'. I was trying to modify this code snippet, but i can't make it working. What I am doing wrong?
add_action( 'pending_to_publish'. 'my_function', 10, 1 );
function my_function( $post )
{
$wp_user_object = new WP_User( $post->post_author );
if ( in_array('contributor', $wp_user_object->roles ) ) {
$wp_user_object->remove_role( 'contributor' );
$wp_user_object->add_role( 'author' );
}
}