Assigning a Role when Patreon User Connects

I’ve created some basic logic for assigning a role to a User based on their Patreon pledge amount when joining the site. I was wondering if I could test this in some way, without having to subscribe to my own Patreon.

function custom_patreon_role_manager() {
    $user = wp_get_current_user();

    $pledge_amount = Patreon_Wordpress::getUserPatronage( $user->ID );

    if ( $pledge_amount >= 14.99 ) {
        $user->set_role( 'Game-Developer-Test' );
    } elseif ( $pledge_amount >= 4.99 ) {
        $user->set_role( 'Scripter Test' );
    } else {
        $user->remove_role( 'Game-Developer-Test' );
        $user->remove_role( 'Scripter Test' );
add_action( 'patreon_action_after_wp_logged_user_is_updated', 'custom_patreon_role_manager' );
add_action( 'patreon_do_action_after_user_logged_in_via_patreon', 'custom_patreon_role_manager' );
add_action( 'patreon_do_action_after_new_user_created_from_patreon_logged_in', 'custom_patreon_role_manager' );
add_action( 'patreon_do_action_after_existing_user_from_patreon_logged_in', 'custom_patreon_role_manager' );

That looks good. Currently there isnt a way to test things without pledging to your campaign from a separate Patreon account. (a different email but the same payment info is ok). You could pledge from a low tier to test.

1 Like