• Resolved [email protected]

    (@web1naturopathy-ukcom)


    Hi,

    I want to create a Gravity Form page that a member can use to change their UM Role.

    I was trying to do this with the following code in functions.php:

    As per these pages:
    https://docs.ultimatemember.com/article/32-change-user-community-role
    https://docs.ultimatemember.com/article/171-setrole

    add_action( 'gform_after_submission_2', 'after_submission_change_role', 10, 2 );
    function after_submission_change_role($entry, $form) {
    	global $ultimatemember;
    	$user_id = get_current_user_id();
    	um_fetch_user( $user_id );
    	// Change user role
    	$ultimatemember->user->set_role('um_full-member');
    }

    This gives me an error 500 in the log looks like this:

    
    [04-Aug-2020 10:46:55 UTC] PHP Notice:  Undefined property: UM::$user in /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-content/themes/wp_theme_anp/functions.php on line 506
    [04-Aug-2020 10:46:55 UTC] PHP Fatal error:  Uncaught Error: Call to a member function set_role() on null in /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-content/themes/wp_theme_anp/functions.php:506
    Stack trace:
    #0 /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-includes/class-wp-hook.php(289): after_submission_change_role(Array, Array)
    #1 /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
    #2 /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #3 /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-content/plugins/gravityforms/gravityforms.php(5957): do_action('gform_after_sub...', Array, Array, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
    #4 /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-content/plugins/gravityforms/form_display.php(167): gf_do_action('gform_after_sub...', Array, Array)
    #5 /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-content/plugins/gravityforms/gravityforms.php(629): GFFormDisplay::process_form(2)
    #6 /var/www/vh in /var/www/vhosts/staging.theanp.co.uk/httpdocs/wp-content/themes/wp_theme_anp/functions.php on line 506
    
    

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cannot use set_role’ is closed to new replies.