WordPress Hooks

  • This feature allows you to extend the plugin to your needs.
  • We provide multiple hooks to extend the plugin functionality
  • You can get the access token and perform your own API calls with your OAuth Provider.
    This will allow you to perform multiple tasks such as getting or updating extra user information to and from your OAuth Provider.

List of Hooks

Read Access Token

  • This Hook is called after logging in the user.
  • Calling this hook will give you access to all the parameters returned from the Token Endpoint by the OAuth/OpenID provider.

HOOK: mo_oauth_logged_in_user_token

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_action('mo_oauth_logged_in_user_token', array( $this,'your_function_name'), 10, 2);                

// If your function 'your_function_name' exists outside of PHP class
add_action('mo_oauth_logged_in_user_token', 'your_function_name' , 10, 2);                

// Function Definition
function your_function_name( $user, $token ){                
  // $token : contains all information related to access_token and refresh_token                
  // $user : WP user belonging to above access_token                
}

Get Refresh Token

  • This filter is used to get a new access token using the refresh token.

FILTER: mo_oauth_refresh_token

SAMPLE CODE:

$access_token = apply_filters( 'mo_oauth_refresh_token', $refresh_token, $app_name);

Here, $app_name can be any of the two:

Post Login Redirection

  • This hook is used to redirect the user to the particular url after they are logged in.

HOOK: mo_oauth_redirect_oauth_users

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_action('mo_oauth_redirect_oauth_users', array( $this,'your_function_name'), 10, 1);                

// If your function 'your_function_name' exists outside of PHP class
add_action('mo_oauth_redirect_oauth_users', 'your_function_name' , 10, 1);                

// Function Definition
function your_function_name( $after_login_url ) {                
  // $after_login_url : contains url to be redirected to after login              
}
  • This hook is used to set a login cookie for a user.

HOOK: mo_oauth_set_login_cookie

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_action('mo_oauth_set_login_cookie', array( $this,'your_function_name'), 10, 0);                

// If your function 'your_function_name' exists outside of PHP class
add_action('mo_oauth_set_login_cookie', 'your_function_name' , 10, 0);                

// Function Definition
function your_function_name() {                
   // your code to setcookie             
}

Get Logged in user attrs

  • This hook is used to get all the user attributes returned by the resource owner.

HOOK: mo_oauth_get_user_attrs

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_action('mo_oauth_get_user_attrs', array( $this,'your_function_name'), 10, 2);                

// If your function 'your_function_name' exists outside of PHP class
add_action('mo_oauth_get_user_attrs', 'your_function_name' , 10, 2);                

// Function Definition
function your_function_name( $user, $resource_owner ) {    
   // $user : WP user 
   // $resource_owner : contains response received from resource owner (user attrs)            
}

Post User Registration

  • This hook is fired immediately after a new user is registered.

HOOK: user_register

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_action('user_register', array( $this,'your_function_name'), 10, 1);                

// If your function 'your_function_name' exists outside of PHP class
add_action('user_register', 'your_function_name' , 10, 1);                

// Function Definition
function your_function_name( $user_id ) {                
   // $user_id : WP user id           
}

Get Form Data

  • This hook is fired while saving settings in the plugin.

NOTE - When using this hook, please make sure you verify the wp_nonce before performing any action.

HOOK: do_main_settings_internal

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_action('do_main_settings_internal', array( $this,'your_function_name'), 10, 1);                

// If your function 'your_function_name' exists outside of PHP class
add_action('do_main_settings_internal', 'your_function_name' , 10, 1);                

// Function Definition
function your_function_name( $post ) {                
  // $post : contains filtered data from the superglobal $_POST.              
}

Change Authorization Request

  • This filter is used to parse and change the Authorization Request (on Authorization Endpoint).

FILTER: mo_auth_url_internal

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_filter('mo_auth_url_internal', array( $this,'your_function_name'), 10, 2);                

// If your function 'your_function_name' exists outside of PHP class
add_filter('mo_auth_url_internal', 'your_function_name' , 10, 2);                

// Function Definition
function your_function_name( $authorization_url, $appname ) {                
   // $authorization_url : Initial authorization URL on which the user will be redirected to (has default parameters attached).               
   // $appname : Name of the application being used.
    return $authorization_url;          
}

Clear Plugin Cache

  • This hook can be used mainly to clear all the configuration/database when the plugin is being uninstalled.

HOOK: mo_clear_plug_cache

SAMPLE CODE:

// If your function 'your_function_name' belongs to PHP class                
add_action('mo_clear_plug_cache', array( $this,'your_function_name'), 10, 0);                

// If your function 'your_function_name' exists outside of PHP class
add_action('mo_clear_plug_cache', 'your_function_name' , 10, 0);                

// Function Definition
function your_function_name() {                
  //your code to perform uninstall action              
}

Customize Error Message

  • This hook can be used to customize your error messages during the SSO flow.

HOOK: mo_tr_login_errors

SAMPLE CODE:

// // If your function 'your_function_name' belongs to PHP class                
add_action('mo_tr_login_errors', array( $this,'your_function_name'), 10, 1);

// If your function 'your_function_name' exists outside of PHP class
add_action('mo_tr_login_errors', 'your_function_name' , 10, 1);

// Function Definition
function your_function_name( $error ){
  // $error : default error msg
    wp_die($error);
    exit;      
}