WordPress Firebase Authentication Developer Hooks

  • This feature allows you to extend the plugin to your needs.
  • We provide multiple hooks to extend the plugin functionality

List of Hooks

Redirect User to specific URL

  • This hook can be used to redirect users to a specific URL after login.

HOOK: mo_firebase_auth_login_redirect

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class 

add_filter('mo_firebase_auth_login_redirect',array($this,'your_function_name'), 10, 2); 

// If your function 'your_function_name' exists outside of PHP class

add_filter('mo_firebase_auth_login_redirect','your_function_name' , 10, 2);                

// Function Definition

function your_function_name($redirect, $user ) {
       // $redirect =site_url();
         return $redirect;

}

Integrate Custom Login Form

  • This hook can be used to integrate your custom login form with Firebase Authentication.

Hook: mo_custom_login_form_end

  • Add the below code after your form ends.

    $username_id is the HTML id of your username field in your custom form.

    $pass_id is the HTML id of your password field in your custom form.

    $submit_id is the HTML id of your submit button of the custom form.

    do_action ('mo_custom_login_form_end', $username_id, $pass_id, $submit_id);

Integrate Custom Registration Form

  • This hook can be used to integrate your custom registration form with Firebase Authentication.

HOOK: mo_custom_registration_form_end

  • Add the below code after your form ends.

    $username_id is the HTML id of your username field in your custom form.

    $pass_id is the HTML id of your password field in your custom form.

    $submit_id is the HTML id of your submit button of the custom form.

    do_action('mo_custom_registration_form_end', $username_id, $pass_id, $submit_id);

Hooks available in Firebase Authentication enterprise plugin

Get Firebase jwt token

  • This Hook is used to get a jwt token provided by Firebase.

HOOK: mo_firebase_get_idtoken

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class 

add_action('mo_firebase_get_idtoken',array($this,'your_function_name'), 10, 2);           

// If your function 'your_function_name' exists outside of PHP class

add_action('mo_firebase_get_idtoken', 'your_function_name' , 10, 2);                

// Function Definition

function your_function_name( $wp_user, $firebase_idToken ){   
      // your custom code
     // $wp_user: object of WP_User class for the firebase logged in user
    // $firebase_idToken: JWT provided by Firebase

}

Get decoded jwt token

  • This Hook is used to get a decoded payload of the jwt token provided by Firebase.

HOOK: mo_firebase_get_jwt_token

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class 

add_action('mo_firebase_get_jwt_token',array($this,'your_function_name'), 10, 2); 

// If your function 'your_function_name' exists outside of PHP class

add_action('mo_firebase_get_jwt_token', 'your_function_name' , 10, 2);                

// Function Definition

function your_function_name($wp_user, $jwt_payload ){  

        // your custom code

       // $wp_user: object of WP_User class for the firebase logged in user

      // $jwt_payload: Decodded payload of JWT provided by Firebase

       $user_id = $wp_user->ID;

    // Code to store user attributes goes here

    add_user_meta( $user_id, 'user_jwt_token', $jwt_token ); 

  }

Get attributes for social login users

  • This hook can be used to get all the social login user attributes returned by the Firebase social provider.

HOOK: mo_firebase_auth_get_social_user

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class  

add_action('mo_firebase_auth_get_social_user',array($this,'your_function_name'), 10, 1);       

// If your function 'your_function_name' exists outside of PHP class

add_action('mo_firebase_auth_get_social_user', 'your_function_name' , 10, 1);               

// Function Definition

function your_function_name( $content){         

         // $content : social login attributes of a user

  }

To change register shortcode texts:

  • This hook is used Change display texts in the register shortcode.

HOOK: mo_firebase_reg_shortcode_texts

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class 

add_action('mo_firebase_reg_shortcode_texts',array($this,'your_function_name'), 10, 1);                

// If your function 'your_function_name' exists outside of PHP class

add_action('mo_firebase_reg_shortcode_texts','your_function_name' , 10, 1);                

// Function Definition

function your_function_name( $reg_form_texts ){ 

   // By default $reg_form_texts will have the following data

('label_text'=>"REGISTER",'email_text'=>"Email",'password_text'=>"Password",'btn_text'=>"Register",'err_msg_weak_password'=>"Password Must contain minimum 6 digit",'err_msg_user_exists_fb'=>"this user is already exist in firebase please login with firebase credentials");

  // you can update fields in the registration as below

      $reg_form_texts['label_text'] =  " custom value";
      $reg_form_texts['email_text'] =  " custom value";
      $reg_form_texts['password_text'] =  " custom value";
      $reg_form_texts['btn_text'] =  " custom value";
      $reg_form_texts['err_msg_weak_password_text'] =  " custom value";
      $reg_form_texts['err_msg_user_exists_fb_text'] =  " custom value";

//Where custom 'label_text' is your register form header key and 'custom value' is your register form header value

   return $reg_form_texts;              


   }

To change login shortcode texts:

  • This hook is used Change display texts in the login shortcode.

HOOK: mo_firebase_login_shortcode_texts

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class 

add_action('mo_firebase_login_shortcode_texts',array($this,'your_function_name'), 10, 1);                

// If your function 'your_function_name' exists outside of PHP class

add_action('mo_firebase_login_shortcode_texts','your_function_name' , 10, 1);                

// Function Definition

function your_function_name($login_form_texts )
{ 

// By default $login_form_texts will have the following data 

$login=array('label_text'=>"LOGIN",'email_text'=>"Email/Username", 'password_text'=>"Password",'btn_text'=>"Login"); 

 // you can update fields in the login as below

       $login_form_texts['label_text'] =  " custom value";
       $login_form_texts['email_text'] =  "custom value";
       $login_form_texts['password_text'] =  " custom value";
       $login_form_texts['btn_text'] =  " custom value";

//Where custom 'label_text' is your login form header key and 'custom value' is your login form header value

     return   $login_form_texts;              

  }