Below, you’ll find a detailed guide on how to add the Miniorange 2 Factor Authentication Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Miniorange 2 Factor Authentication Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Miniorange 2 Factor Authentication Plugin and the shortcodes it provides:
"MiniOrange's Google Authenticator is a WordPress plugin providing two-factor authentication (2FA), OTP SMS/Email, and passwordless login, enhancing your site's security."
- [mo2f_enable_register]
Miniorange 2 Factor Authentication [mo2f_enable_register] Shortcode
The miniorange-2-factor-authentication plugin shortcode enables user registration. It retrieves site options, checks if the user is registered, and enqueues necessary scripts and styles. This shortcode also localizes scripts, providing translation for various strings, enhancing the user experience. It’s crucial for enabling 2FA on forms.
Shortcode: [mo2f_enable_register]
Examples and Usage
Basic example – Enable registration using the shortcode with the default settings.
[mo2f_enable_register /]
Advanced examples
Using the shortcode to enable registration with a custom form name and submit selector. This will allow you to customize the form that the user sees when they register.
[mo2f_enable_register form_name="custom_form" submit_selector=".custom_submit" /]
Using the shortcode to enable registration with a custom email field and phone selector. This will allow you to customize the fields that the user needs to fill out when they register.
[mo2f_enable_register email_field="custom_email" phone_selector=".custom_phone" /]
Using the shortcode to enable registration with a custom notification selector and success class. This will allow you to customize the notification message that the user sees after they register and the styling of the success message.
[mo2f_enable_register notification_selector="#custom_notification" success_class="custom_success" /]
Using the shortcode to enable registration with a custom error class. This will allow you to customize the styling of the error message that the user sees if there is an issue with their registration.
[mo2f_enable_register error_class="custom_error" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [mo2f_enable_register]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'mo2f_enable_register', array( $this, 'mo2f_enable_register_shortcode' ) );
Shortcode PHP function:
function mo2f_enable_register_shortcode() {
$submit_selector = get_site_option( 'mo2f_custom_submit_selector' );
$form_submit = get_site_option( 'mo2f_form_submit_after_validation' );
$form_name = get_site_option( 'mo2f_custom_form_name' );
$email_field = get_site_option( 'mo2f_custom_email_selector' );
$auth_type = get_site_option( 'mo2f_custom_auth_type' );
$phone_selector = get_site_option( 'mo2f_custom_phone_selector' );
$notification_selector = get_site_option( 'mo2f_custom_notification_selector', '#otpmessage' );
$success_class = get_site_option( 'mo2f_custom_success_selector', 'mo2f_green' );
$error_class = get_site_option( 'mo2f_custom_error_selector', 'mo2f_red' );
if ( get_site_option( 'mo2f_customerkey' ) > 0 ) {
$is_registered = get_site_option( 'mo2f_customerkey' );
} else {
$is_registered = 'false';
}
$form_ajax = array( '.um-form', '.wpcf7-form', '#um-submit-btn' );
$form_r_c_p = array( '#rcp_registration_form', '.rcp_form', '#rc_registration_form', '.rc_form' );
$form_mepr = array( '.mepr-signup-form' );
if ( in_array( $form_name, $form_ajax, true ) ) {
$java_script = 'includes/js/custom-form-ajax.min.js';
} elseif ( in_array( $form_name, $form_r_c_p, true ) ) {
$java_script = 'includes/js/custom-ajax-rcp.min.js';
} elseif ( in_array( $form_name, $form_mepr, true ) ) {
$java_script = 'includes/js/custom-ajax-mepr.min.js';
} else {
$java_script = 'includes/js/custom-form.min.js';
}
wp_enqueue_style( 'mo2f_intl_tel_style', plugin_dir_url( __FILE__ ) . 'includes/css/phone.min.css', array(), MO2F_VERSION );
$country_details = is_array( get_site_option( 'mo2f_country_code' ) ) ? wp_unslash( get_site_option( 'mo2f_country_code' ) ) : array();
wp_enqueue_script( 'mo2f_intl_tel_script', plugin_dir_url( __FILE__ ) . 'includes/js/phone.min.js', array( 'jquery' ), MO2F_VERSION, false );
wp_localize_script( 'mo2f_intl_tel_script', 'countryDetails', $country_details );
wp_register_script( 'mo2f_otpVerification', plugin_dir_url( __FILE__ ) . $java_script, array( 'jquery' ), MO2F_VERSION, false );
wp_localize_script(
'mo2f_otpVerification',
'otpverificationObj',
array(
'siteURL' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'ajax-nonce' ),
'authType' => $auth_type,
'submitSelector' => $submit_selector,
'formSubmit' => $form_submit,
'formname' => $form_name,
'emailselector' => $email_field,
'isRegistered' => $is_registered,
'phoneSelector' => $phone_selector,
'errorClass' => $error_class,
'successClass' => $success_class,
'notificationSelector' => $notification_selector,
'loaderUrl' => plugin_dir_url( __FILE__ ) . 'includes/images/loader.gif',
'isEnabledShortcode' => get_site_option( 'enable_form_shortcode' ),
)
);
wp_localize_script(
'mo2f_otpVerification',
'otpverificationStringsObj',
array(
'contact_admin' => __( 'Contact Site Administrator', 'miniorange-2-factor-authentication' ),
'sending_otp' => __( 'Sending OTP ', 'miniorange-2-factor-authentication' ),
'invalid_phone' => __( 'Invalid Phone Number', 'miniorange-2-factor-authentication' ),
'phone_num' => __( 'Phone Number', 'miniorange-2-factor-authentication' ),
'invalid_email' => __( 'Invalid Email Address', 'miniorange-2-factor-authentication' ),
'send_otp' => __( 'Send OTP ', 'miniorange-2-factor-authentication' ),
'enter_otp' => __( 'Enter OTP ', 'miniorange-2-factor-authentication' ),
'resend_otp' => __( 'Resend OTP ', 'miniorange-2-factor-authentication' ),
'validate_otp' => __( 'Validate OTP ', 'miniorange-2-factor-authentication' ),
'otp_sent_phone' => __( 'An OTP will be sent to your Mobile Number', 'miniorange-2-factor-authentication' ),
'otp_sent_both' => __( 'An OTP will be sent to your Mobile Number and Email', 'miniorange-2-factor-authentication' ),
'otp_sent_email' => __( 'An OTP will be sent to your Email ID', 'miniorange-2-factor-authentication' ),
'already_validated' => __( 'Already Validated', 'miniorange-2-factor-authentication' ),
'validate_phone' => __( 'Please Validate Phone first', 'miniorange-2-factor-authentication' ),
'validate_email' => __( 'Please Validate Email first', 'miniorange-2-factor-authentication' ),
'phone_field_not_found' => __( 'miniOrange : Phone Field not Found.', 'miniorange-2-factor-authentication' ),
'email_field' => __( 'miniOrange : Email Field', 'miniorange-2-factor-authentication' ),
'not_found' => __( ' not Found. Please check Selector', 'miniorange-2-factor-authentication' ),
'validate_both' => __( 'Please Validate Email and Phone first', 'miniorange-2-factor-authentication' ),
'account_register' => __( 'miniOrange : Register/Login with miniOrange to Enable 2FA for this Form', 'miniorange-2-factor-authentication' ),
'register' => __( 'Register', 'miniorange-2-factor-authentication' ),
'validation_error' => __( 'Error Validating OTP', 'miniorange-2-factor-authentication' ),
'phone_validated' => __( 'Phone Number Validated', 'miniorange-2-factor-authentication' ),
)
);
wp_enqueue_script( 'mo2f_otpVerification' );
// Register Shortcode JavaScript And Pass Parameters To JS.
}
Code file location:
miniorange-2-factor-authentication/miniorange-2-factor-authentication/miniorange_2_factor_settings.php
Conclusion
Now that you’ve learned how to embed the Miniorange 2 Factor Authentication Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply