Created
November 2, 2013 16:08
-
-
Save strangerstudios/7280490 to your computer and use it in GitHub Desktop.
Add author role to members at checkout. Add this to your active theme's functions.php or a custom plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This code will make members signing up for membership level #1 authors and make them subscribers when they cancel. | |
*/ | |
function my_pmpro_after_change_membership_level($level_id, $user_id) | |
{ | |
if($level_id == 1) | |
{ | |
//New member of level #1. If they are a subscriber, make them an author. | |
$wp_user_object = new WP_User($user_id); | |
if(in_array("subscriber", $wp_user_object->roles)) | |
$wp_user_object->set_role('author'); | |
} | |
else | |
{ | |
//Not a member of level #1. If they are an author, make them a subscriber. | |
$wp_user_object = new WP_User($user_id); | |
if(in_array("author", $wp_user_object->roles)) | |
$wp_user_object->set_role('subscriber'); | |
} | |
} | |
add_action("pmpro_after_change_membership_level", "my_pmpro_after_change_membership_level", 10, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Give New Members Author Role" at Paid Memberships Pro here: https://www.paidmembershipspro.com/give-new-members-author-role/