-
Notifications
You must be signed in to change notification settings - Fork 214
Dokan Login Form Popup
Dokan Login Form Popup is an Ajax login form that you can find anywhere in WordPress frontend when Dokan Lite plugin is active. This form works based on some custom JavaScript events. The custom events and their possible use cases are listed below.
This event will start fetching the form by ajax. When ever you need to show the form in your custom code you can trigger this event by using,
$( 'body' ).trigger( 'dokan:login_form_popup:show' );This event will fire right before start fetching the form. You can use this event to show any ajax loading animation by using code like this,
$( 'body' ).on( 'dokan:login_form_popup:fetching_form', function () {
// show ajax loading animation
} );This event will fire after completed fetching login form. So, at this point you can stop showing your ajax loading animation.
$( 'body' ).on( 'dokan:login_form_popup:fetched_form', function () {
// stop ajax loading animation
} );After this event Dokan login form popup will be visible.
This event will fire after a successful login.
$( 'body' ).on( 'dokan:login_form_popup:logged_in', function () {
// do whatever you want to do after a user successfully logged in.
} );After this event the popup will be closed automatically.
If you need any data in ajax response right after the user is logged in, then you can use dokan_ajax_login_user_response filter and get the response in dokan:login_form_popup:logged_in event. For example, you may need to create a nonce for a custom action using wp_create_nonce right after user is logged in. In that case you can use snippet like this,
add_filter( 'dokan_ajax_login_user_response', 'mycustom_plugin_add_nonce_to_ajax_reponse' );
function mycustom_plugin_add_nonce_to_ajax_reponse( $response ) {
$response['mycustom_nonce'] = wp_create_nonce( 'custom_action' );
return $response;
}Then get this data in JS like this,
$( 'body' ).on( 'dokan:login_form_popup:logged_in', function ( response ) {
var nonce = response.data.mycustom_nonce
// you can now use this nonce and send it to another ajax request
} );