BP_Members_Admin::process_member_type_update()
Process changes from the profile type metabox.
Description
Source
File: bp-members/classes/class-bp-members-admin.php
public function process_member_type_update() { if ( ! isset( $_POST['bp-member-type-nonce'] ) || ! isset( $_POST['bp-members-profile-member-type'] ) ) { return; } $user_id = $this->get_user_id(); check_admin_referer( 'bp-member-type-change-' . $user_id, 'bp-member-type-nonce' ); // Permission check. if ( ! bp_current_user_can( 'bp_moderate' ) && $user_id != bp_loggedin_user_id() ) { return; } // profile type string must either reference a valid profile type, or be empty. $member_type = stripslashes( $_POST['bp-members-profile-member-type'] ); if ( ! empty( $member_type ) && ! bp_get_member_type_object( $member_type ) ) { return; } if ( '' !== $member_type ) { // Get post id of selected profile type. $post_id = bp_member_type_post_by_type( $member_type ); // Get selected profile type role. $selected_member_type_wp_roles = get_post_meta( $post_id, '_bp_member_type_wp_roles', true ); if ( $user_id === get_current_user_id() ) { if ( 'administrator' !== $selected_member_type_wp_roles[0] ) { if ( empty( $selected_member_type_wp_roles ) ) { /* * If an invalid profile type is passed, someone's doing something * fishy with the POST request, so we can fail silently. */ if ( bp_set_member_type( $user_id, $member_type ) ) { // @todo Success messages can't be posted because other stuff happens on the page load. } } else { $bp_error_message_string = __( 'You cannot assign yourself to this profile type as doing so would remove your Administrator role and lock you out of the WordPress admin. You first need to associate this profile type to the Administrator role, and then you can assign it to yourself.', 'buddyboss' ); $error_message = apply_filters( 'bp_invalid_role_selection_extended_profile', $bp_error_message_string ); // Define the settings error to display add_settings_error( 'bp-invalid-role-selection-extended-profile', 'bp-invalid-role-selection-extended-profile', $error_message, 'error' ); set_transient( 'bp_invalid_role_selection_extended_profile', get_settings_errors(), 30 ); return; } } else { $bp_current_user = new WP_User( get_current_user_id() ); // Remove role $bp_current_user->remove_role( $bp_current_user->roles[0] ); // Add role $bp_current_user->add_role( $selected_member_type_wp_roles[0] ); } } else { $bp_user = new WP_User( $user_id ); // Remove role $bp_user->remove_role( $bp_user->roles[0] ); // Add role $bp_user->add_role( $selected_member_type_wp_roles[0] ); } } /* * If an invalid profile type is passed, someone's doing something * fishy with the POST request, so we can fail silently. */ if ( bp_set_member_type( $user_id, $member_type ) ) { // @todo Success messages can't be posted because other stuff happens on the page load. } }
Changelog
Version | Description |
---|---|
BuddyPress 2.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.