I’m 90% of the way through building a private members site using WordPress and would greatly appreciate any help that could be given on my final hurdle.
I need to create a simple plugin of some sort that will check the number of posts a user has. If posts= > 1, then change the users role from ‘contributor’ to ‘author’.
However, this should not affect the roles above this, i.e. editor, Admins etc.
The function to change the roles is:
but the rest of it is going over my head…
Any help towards getting this up and running would be hugely appreciated!
Here’s how I would do it, though somewhat vague, i hope it helps.
Hook onto user logins. add_action('wp_login', 'yourloginfunction')
Firstly get your current user’s role.
If the users role isn’t Author or higher, then you can continue.
Now check the users current number of posts.
$currentPosts = count_user_posts($current_user->user_ID);
If the user has reached a certain number of posts, being that he/she has already logged in, we can simply change his/her role in the site. wp_update_user($userData)
Just use the correct array key/value of the user’s data you want to update.
Phyrax, thanks for your input, this is good direction. I’ll have a go over then next couple of evenings and see if I can get that working. I’m attempting this as my first plugin, so may well be back for some novice level advice…
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Automatically Change Roles after (x) Posts’ is closed to new replies.