• Resolved akawins

    (@akawins)


    Hi, this question was never answered https://wordpress.org/support/topic/ask-about-the-select-role/.
    The question is the same, I need 2 roles when registering with telegram, for example, on page “1” – one role, on page “2” – another.
    I found in the LoginHandler.php file if I change:
    $role = ‘author’;
    $userdata = compact( ‘user_pass’, ‘user_login’, ‘first_name’, ‘last_name’, ‘author’ );
    Then when registering, the role is set as I indicated, and not as in the admin panel, it remains to set the condition “if (is_page (25)) { }”, but this does not work, maybe I need to change the login-view.php file?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Irshad Ahmad

    (@irshadahmad21)

    Hi,
    It’s a complicated requirement. Here is what you can do if you want to write custom code:

    You can use wptelegram_login_telegram_callback_url filter to set the callback URL and add some query param like current page slug to the URL and then read that param inside the callback for wptelegram_login_insert_user_data filter to return the appropriate role you want.

    add_filter( 'wptelegram_login_telegram_callback_url', function ( $callback_url ) {
    	// Add 'page_id' to query params
    	return add_query_arg( [ 'page_id' => get_the_ID() ], $callback_url );
    }, 10, 1 );
    
    add_filter( 'wptelegram_login_insert_user_data', function ( $userdata ) {
    	if ( empty( $_GET['page_id'] ) ) {
    		return $userdata;
    	}
    
    	// Read 'page_id' added above
    	$page_id = (int) $_GET['page_id'];
    
    	// If page ID is 25
    	if ( 25 === $page_id ) {
    		// set the role to 'author'
    		$userdata['role'] = 'author';
    	}
    
    	return $userdata;
    }, 10, 1 );
    Thread Starter akawins

    (@akawins)

    Amazing! Thanks for the quick and accurate answer!

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