I have two roles.
A: The user sends a post for moderation
B: The user publishes posts without moderation
For new users the role of A. How do I do if I approve of his first post, the role is changed to B?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityYou can attach code to change role when post status is changing from "pending" to "published" see documentation: http://codex.wordpress.org/Post_Status_Transitions Then, if user has role "contributor" you can change this to "author":
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' );
}
}
From the Codex Post_Status_Transitions you have hooks on the post status change:
function on_publish_pending_post( $post ) {
// A function to perform when a pending post is published.
}
add_action( 'pending_to_publish', 'on_publish_pending_post', 10, 1 );
You have access to the $post variable. So you have to pull the author id, and change his role...
Cheers