[WordPress] 外掛分享: Mm Ajax Login

首頁外掛目錄 › Mm Ajax Login
WordPress 外掛 Mm Ajax Login 的封面圖片
10+
安裝啟用
尚無評分
3754 天前
最後更新
問題解決
WordPress 3.8+ v1.0.0 上架:2015-08-22

內容簡介

這個外掛可以讓你建立特殊的連結,在檢查使用者是否已登入之後,如果已登入就直接轉頁到該連結所指的網頁;如果未登入,則會在簡單的燈箱中顯示 AJAX 驅動的登入表單。當使用者填寫有效的憑證,他們就會登入並被重新導向到該連結所指的頁面。

情境

假設你的網站上有一個只有已登入使用者才能存取的頁面。這可能是一個私人頁面,或者最好是一個能向未登入使用者顯示標準登入表單的頁面。你可以在指向該頁面的所有連結中加入「ajax-login-trigger」類別。當使用者點擊其中一個連結時,將向伺服器發送 AJAX 請求,檢查使用者是否已登入。如果使用者已登入,將直接重新導向到頁面,使用者甚至不會察覺到登入檢查已完成;如果使用者未登入,將顯示簡單的燈箱中的登入表單。當使用者填寫表單後,將發送第二個 AJAX 請求來嘗試登入,如果成功,使用者將被重新導向回原本的頁面。

自訂:

此外掛包含許多鉤子和過濾器,允許進行各種自訂和獨特用途。以下是一個快速列表:

動作:

mm_ajax_login_before_form_outside
mm_ajax_login_before_form_inside
mm_ajax_login_extra_buttons
mm_ajax_login_after_form_inside
mm_ajax_login_after_form_outside

過濾器:

mm_ajax_login_trigger_selector
mm_ajax_login_form_title
mm_ajax_login_status_message
mm_ajax_login_username_label
mm_ajax_login_password_label
mm_ajax_login_rememberme_text
mm_ajax_login_lost_password_text
mm_ajax_login_button_text
mm_ajax_login_custom_login_action
mm_ajax_login_email_login_fail_message
mm_ajax_login_success_message
mm_ajax_login_fail_message
mm_ajax_login_allow_email_login

使用這些鉤子可以完成許多事情。鉤子「mm_ajax_login_before_form_inside」和「mm_ajax_login_after_form_inside」允許在表單中添加任何自訂輸入元素。當提交登入表單時,包含在表單中的輸入元素的所有值都會傳遞給處理 AJAX 請求的 PHP 函數,然後該資料會傳遞給「mm_ajax_login_custom_login_action」過濾器。你可以使用此過濾器攔截傳入的資料,並進行任何自訂操作,例如在同一行動中註冊新使用者和登入他們。

過濾器示例

使用自訂選取器作為觸發連結:

add_filter( 'mm_ajax_login_trigger_selector', 'prefix_custom_login_trigger' );
function prefix_custom_login_trigger( $selector ) {

// 自訂選取器在這裡
$selector = '.my-custom-selector';

return $selector;
}

使用自訂狀態訊息:

add_filter( 'mm_ajax_login_status_message', 'prefix_custom_status_message' );
function prefix_custom_status_message( $status_message ) {

// 自訂狀態訊息在這裡
$status_message = 'Magic happening...';

return $status_message;
}

此外掛在Github上,歡迎提交拉取請求。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Mm Ajax Login」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin allows you to create special links that check whether a user is logged in and then follow the link if they are or show an ajax-powered login form in a simple lightbox if they are not. Once the user fills out the login form with valid credentials they will be logged in and redirected to the page the link points to.
Scenario
Let’s say you’ve got a page on your site that only logged in users are able to access. It could be a private page or ideally it is a page that is set up to show a standard login form to users who are not logged in. With this plugin you could add the class ‘ajax-login-trigger’ to all the links that point to that page, then when a user clicks one of these links an ajax request is sent to the server to check whether the user is already logged in, and if they are the user is redirected to the page without ever noticing that the login check was done, or if they aren’t logged in they’ll see a login form appear in a simple lightbox. When the user fills out the form, a second ajax request is sent to the server to attempt to log them in, and if successful the user is redirected to the page.
Customize It!
This plugin includes lots of hooks and filters that allow for all sorts of customizations and unique use cases. Here’s a quick list:
Actions:
mm_ajax_login_before_form_outside
mm_ajax_login_before_form_inside
mm_ajax_login_extra_buttons
mm_ajax_login_after_form_inside
mm_ajax_login_after_form_outside

Filters:
mm_ajax_login_trigger_selector
mm_ajax_login_form_title
mm_ajax_login_status_message
mm_ajax_login_username_label
mm_ajax_login_password_label
mm_ajax_login_rememberme_text
mm_ajax_login_lost_password_text
mm_ajax_login_button_text
mm_ajax_login_custom_login_action
mm_ajax_login_email_login_fail_message
mm_ajax_login_success_message
mm_ajax_login_fail_message
mm_ajax_login_allow_email_login

Many things are possible with these hooks. The hooks mm_ajax_login_before_form_inside and mm_ajax_login_after_form_inside allow you to add any custom input elements to the form. When the login form is submitted all of the values from the input elements included in the form will get passed to the PHP function that processes the ajax request, which will then pass the data to the mm_ajax_login_custom_login_action filter. You can intercept the incoming data using this filter and proceed with any custom action you want, like registering new users and logging them in during the same action.
Filter Examples
Use a custom selector for the trigger link:
add_filter( 'mm_ajax_login_trigger_selector', 'prefix_custom_login_trigger' );
function prefix_custom_login_trigger( $selector ) {

// Custom selector goes here.
$selector = '.my-custom-selector';

return $selector;
}

Use a custom status message:
add_filter( 'mm_ajax_login_status_message', 'prefix_custom_status_message' );
function prefix_custom_status_message( $status_message ) {

// Custom status message goes here.
$status_message = 'Magic happening...';

return $status_message;
}

This plugin is on Github and pull requests are always welcome.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon