Auto update user role if user have post in Wordpress -


i need this. when user registers on site, assigned role "subscriber". need is, when user publish new custom post type ($listing), role automatically updated "contributor". posts have expiry date, when listing expires , goes draft mode, user role goes subscriber.

i tried work out, role doesn't updated..

add_action('publish_post', 'update_roles'); function update_roles() {  global $wpdb;   $author = wp_get_current_user();   $posts = $wpdb->get_results("select * $wpdb->posts post_author = " . $author->id );  $numpost = count($listing);   if($numpost > 0 && $numposts <= 100 && current_user_can('subscriber'))   {    $author->remove_role( 'subscriber' );    $author->add_role( 'contributor' );   }  } 

what missing?


Comments