Update user role for expired membership

If you need to get the value of a field in a custom database table you can try using an SQL query. You’ll have to check the column or table name to construct final version of the query.

add_action( 'profile_update', 'my_profile_update', 10, 2 );
function my_profile_update( $user_id, $old_user_data ) {

    global $wpdb;
    $status = $wpdb->get_var( $wpdb->prepare(
        " SELECT rcp_status FROM rcp_membership WHERE ID = %d ",
        $user_id
    ) );

    if( $status == "expired") {
        $new_role = array( 'bbp_blocked' => 1 );
        $data = serialize( $new_role ); 
        $updated = update_user_meta( $user_id, 'wp_capabilities', $data );

        // check and make sure the stored value matches $new_role.
        if ( $data != get_user_meta( $user_id, 'wp_capabilities', true ) ) {
            wp_die( __( 'user role not updated', 'textdomain' ) );
        }
    }

}