• Resolved ybabel

    (@ybabel)


    Hello,
    great plugin, works well. To use it with another plugin I would like to be able to get the wordpress user id from the telegram chat id.
    Is there a helper function that do that ?
    I searched in the code of the plugin but did not found it.
    regards,
    Yoann

Viewing 3 replies - 1 through 3 (of 3 total)
  • This function should do the job:

    /**
     * Get WP User ID from Telegram User ID.
     *
     * @param  integer $tg_user_id Telegram User ID
     * @return integer             WP user ID
     */
    function get_wp_user_id_by_tg_id( $tg_user_id ) {
    	$wp_user_id = 0;
    
    	$args  = array(
    		'meta_key'   => 'wptelegram_login_user_id',
    		'meta_value' => $tg_user_id,
    		'number'     => 1,
    	);
    	// get user list
    	$users = get_users( $args );
    	if ( ! empty( $users ) ) {
    		// get the first user
    		$user = reset( $users );
    		// get the user's ID
    		$wp_user_id = $user->ID;
    	}
    	return $wp_user_id;
    }
    Thread Starter ybabel

    (@ybabel)

    found it :
    $user = get_users(array('meta_key' => 'wptelegram_login_user_id', 'meta_value' => $tid));

    return an array, it’s in the first one.

    Thread Starter ybabel

    (@ybabel)

    thanks, your function is better

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Function to search WP user by TG id ?’ is closed to new replies.