1. Get Firebase ID Token

mo_firebase_get_firebase_idtoken()- function for returning Firebase ID token for a WordPress user.
  • To get a Firebase ID token for a user who logs in with Firebase credentials, call the mo_firebase_get_firebase_idtoken() function and pass it the user's WordPress ID:

Parameters $wp_user_id ( int ) – The ID of the WordPress user.

Return id_token|null|boolean - The Firebase ID token for the user, or false if there was an error

Usage:


$wp_user_id = 123;

$id_token = mo_firebase_get_firebase_idtoken( $wp_user_id );

// This will return the Firebase ID token for the user with ID 123.

  
 

2. LOGIN FLOW

Fetch the entered email/username and password, sanitize and escape them and then pass them as arguments to our mo_firebase_login_user_custom_form()

Function Definition:-

function mo_firebase_login_user_custom_form($username, $password, $return_user=false)
{
return $result;
}

$username:- Email of the user which exists in Firebase authentication.

$password:- Plain text password entered by the user.

$return_user:- If true, then the function would return the user object, and you would need to explicitly set the login cookie for the user.
If false, then the Firebase authentication plugin itself would login the user and create a user session.

$result:- WP_User Object or Error string.

Code Snippet:-


<? php

<- - - -  Your Code- - - - >

- Fetch the input values after the form is submitted 
<- Code to sanitize the input values->

$return_user = false; // you want the user login session created by the miniOrange plugin and further handling 

$result = mo_firebase_login_user_custom_form( $username, $password, $return_user);

if(!empty($result)){
 <- You custom code for displaying the error messages->
}

?>

  
 

3. REGISTRATION FLOW

Fetch the information entered in the login form. Sanitize and escape the information.Now store the sanitized and escaped information in the form of an array in the following format.

$user_data= array(
“user_pass” => $password_entered,
“user_login” => $username_entered,
“user_email“ => $email,
“Confirm_password” => $confirm_password,
“display_name“ => $display_name, // you can pass username or email as well
“nickname“ => $nickname, //you can pass username or email as well
“first_name“ => $firstname,
“last_name”=> $lastname,
“user_registered“ =>$registered_date,
“role”=> $wp_role,
“meta_input”=> $meta_data,
)

Any other extra information other than the basic WP user profile attributes would be inside $meta_data.
It would be an associative array with the array key as the WordPress meta key and value as the entered value.
Below is the format for $meta_data

$meta_data= array(
“<- your-wp_meta_key_for_city_name ->” => $city_name,
“<- your-wp_meta_key_for_acc_no ->”=>$account_number,
);

Now pass the complete $user_data as argument to the mo_firebase_register_user_custom_form()

Function Definition:-

function mo_firebase_register_user_custom_form($user_data, $return_user=false)
{
return $result;
}

$user_data:- The array containing the entered information in the above-specified format.

$return_user:- If true, then the function would return the user id, and you would need to explicitly set the login cookie for the user.
If false, then the Firebase authentication plugin itself would login the user and create a user session.

$result:- WP_User User ID or Error string.

CODE SNIPPET:-

<? php

<- - - -  Your Code- - - - >

- Fetch the input values after the form is submitted 
<- Code to sanitize the input values->

$return_user = false; // you want the user login session created by the miniOrange plugin and further handling 

$result = mo_firebase_register_user_custom_form ( $user_data, $return_user);

if(!empty($result)){
 <- You custom code for displaying the error messages->
}

?>