Created
September 3, 2018 20:31
-
-
Save pbrocks/36b3d84c075ec6d8a0a6b6f6edd15c00 to your computer and use it in GitHub Desktop.
Check the default bbPress role associated with a level and then assign it to a new member during PMPro checkout.
This file contains hidden or 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 // Do not include in your Customizations Plugin | |
/** | |
* Check the default bbPress role associated with a level and then assign it to a new member during PMPro checkout. | |
*/ | |
add_action( 'pmpro_after_checkout', 'pmpro_add_forum_role', 11 ); | |
function pmpro_add_forum_role( $user_id ) { | |
// $member_data = get_userdata( $user_object->ID ); | |
$member_object = pmpro_getMembershipLevelForUser( $user_id ); | |
$level_id = $member_object->id; | |
$user_role = 'subscriber'; | |
$bbp_role = pmprobb_check_membership_level_bbpress_role( $level_id ); | |
if ( is_wp_error( $user_id ) ) { | |
echo $return->get_error_message(); | |
} | |
if ( ! empty( $_POST['role'] ) ) { | |
$user_role = $_POST['role']; | |
} | |
$capabilities_array = array( | |
$user_role => true, | |
$bbp_role => true, | |
); | |
$updated_roles = update_user_meta( $user_id, 'wp_capabilities', $capabilities_array ); | |
} | |
function pmprobb_check_membership_level_bbpress_role( $level_id ) { | |
if ( class_exists( 'bbPress' ) ) { | |
// get values | |
$options = get_option( 'pmprobb_options_levels' ); | |
} | |
return $options[ $level_id ]['role']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment