Automatically Change Roles after (x) Posts (3 posts)

  1. gcleve
    Posted 4 years ago #

    Hi There

    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!

    Thanks in advance...


  2. Jerry
    Posted 4 years ago #

    Here's how I would do it, though somewhat vague, i hope it helps.

    1. Hook onto user logins.
      add_action('wp_login', 'yourloginfunction')
    2. Firstly get your current user's role.
    3. If the users role isn't Author or higher, then you can continue.
    4. Now check the users current number of posts.
      global current_user;
      $currentPosts = count_user_posts($current_user->user_ID);
    5. 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.
      Just use the correct array key/value of the user's data you want to update.
  3. gcleve
    Posted 4 years ago #

    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...
    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic