Search Results :
×Handle WordPress Login and User registration in WordPress Cognito User Pool through your custom code.
There may be situations where the custom forms plugin has limitations and you need your own code to design the login and registration forms, handle the form submit event, and manage the backend flow to authenticate users via Cognito credentials. In these cases, having the ability to write custom code can be useful. By creating your own code, you have full control over the form design and authentication functionality.
When faced with such situations, the WordPress Cognito Integration becomes a valuable solution for incorporating WordPress login with Cognito Credentials and user registration into a Cognito Pool within your backend code. To use the WordPress Cognito Integrator, make sure to first install the WordPress OAuth Client plugin on your website. Know more about WordPress OAuth Client plugin.
To achieve this, simply invoke the appropriate login and registration functions provided by our plugin within your code, passing the necessary parameters. The WordPress Cognito Integration will take care of the remaining tasks.
Here are the provided code snippets that will guide you in implementing the code on your side, effectively handing over control to the WordPress Cognito Integration and providing the essential information.
Fetch the entered email/username and password, sanitize and escape them, and then pass them as arguments to our function. mo_ci_custom_login_form()
Function Definition:
$username |
Username or Email of the user depending upon whether your Cognito pool is configured to username & password login OR email & password Login. |
---|---|
$password |
Plain text password entered by the user. |
$return_user |
If true, the function would return the user ID, and you would need to explicitly set the login cookie for the user. If false, the Cognito Integrator itself would log in the user. |
$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_ci_custom_login_form($username, $password, $return_user);
if(!empty($result)){
// Your custom code for displaying the error messages
}
?>
Fetch the information entered in the registration form, sanitize and escape the information, and store the sanitized and escaped information in an array following the specified format:
$user_data = array(
"user_pass" => $password_entered,
"user_login" => $username_entered,
"user_email" => $email,
"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,
// ...
);
Pass the complete $user_data array as an argument to the function mo_ci_custom_registeration_form()
Function Definition:
function mo_ci_custom_registeration_form ($user_data, $return_user=false){
return $result;
}
$username |
Username or Email of the user depending upon whether your Cognito pool is configured to username & password login OR email & password Login. |
---|---|
$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 Cognito Integrator itself would login the user. |
$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_ci_custom_registeration_form($user_data, $return_user);
if(!empty($result)){
// Your custom code for displaying the error messages
}
?>
Thank you for your response. We will get back to you soon.
Something went wrong. Please submit your query again
Discover how miniOrange can help you
Sign up for a Demo to receive
Overview of Plugin's Premium features
Test Add-ons & 3rd-party integrations
24*7 support with mail and Zoom call
Get a guided demo from a Developer
Mail us on oauthsupport@xecurify.com for quick guidance(via email/meeting) on your requirement and our team will help you to select the best suitable solution/plan as per your requirement.
Need Help? We are right here!
Thanks for your inquiry.
If you dont hear from us within 24 hours, please feel free to send a follow up email to info@xecurify.com
This privacy statement applies to miniorange websites describing how we handle the personal information. When you visit any website, it may store or retrieve the information on your browser, mostly in the form of the cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not directly identify you, but it can give you a more personalized web experience. Click on the category headings to check how we handle the cookies. For the privacy statement of our solutions you can refer to the privacy policy.
Necessary cookies help make a website fully usable by enabling the basic functions like site navigation, logging in, filling forms, etc. The cookies used for the functionality do not store any personal identifiable information. However, some parts of the website will not work properly without the cookies.
These cookies only collect aggregated information about the traffic of the website including - visitors, sources, page clicks and views, etc. This allows us to know more about our most and least popular pages along with users' interaction on the actionable elements and hence letting us improve the performance of our website as well as our services.