WordPress.org

Support

Support » Plugins and Hacks » Hacks » Automatically Change Roles after (x) Posts

Automatically Change Roles after (x) Posts

  • 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:
    $user->set_role
    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…

    gcleve

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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;
      get_currentuserinfo();
      $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.
      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…
    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Automatically Change Roles after (x) Posts’ is closed to new replies.
Skip to toolbar