mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
Add user approval action upon email confirmation. Reviewed PR #1776
Introduced a new action `um_approve_user_on_email_confirmation` to enable user approval after verifying the email activation link. Refactored related logic to enhance extensibility and allow developers to hook custom behavior post-approval.
This commit is contained in:
@@ -33,6 +33,8 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
|
||||
// don't use lower than 2 priority because there is sending email inside, but Action Scheduler is init on 1st priority.
|
||||
add_action( 'init', array( &$this, 'activate_account_via_email_link' ), 2 );
|
||||
// Approve the user after the activate account link is verified.
|
||||
add_action( 'um_approve_user_on_email_confirmation', array( &$this, 'approve_user_on_email_confirmation' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,9 +137,25 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
}
|
||||
|
||||
// Activate account link is valid. Can be approved below.
|
||||
|
||||
um_fetch_user( $user_id ); // @todo maybe don't need to fetch.
|
||||
UM()->common()->users()->approve( $user_id, true );
|
||||
/**
|
||||
* Fires for user activation after validation the link for email confirmation.
|
||||
*
|
||||
* Internal Ultimate Member callbacks (Priority -> Callback name -> Excerpt):
|
||||
* 10 - `UM()->permalinks()->approve_user_on_email_confirmation()` Approve the user after the activate account link is verified.
|
||||
*
|
||||
* @hook um_approve_user_on_email_confirmation
|
||||
*
|
||||
* @param {int} $user_id The user ID.
|
||||
*
|
||||
* @since 2.11.2
|
||||
*
|
||||
* @example <caption>Doing some code just after native approve the $user_id on email confirmation.</caption>
|
||||
* function my_approve_user_on_email_confirmation( $user_id ) {
|
||||
* // your code here
|
||||
* }
|
||||
* add_action( 'um_approve_user_on_email_confirmation', 'my_approve_user_on_email_confirmation', 11 );
|
||||
*/
|
||||
do_action( 'um_approve_user_on_email_confirmation', $user_id );
|
||||
|
||||
$user_role = UM()->roles()->get_priority_user_role( $user_id );
|
||||
$user_role_data = UM()->roles()->role_data( $user_role );
|
||||
@@ -161,7 +179,7 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
* function my_after_email_confirmation( $user_id ) {
|
||||
* // your code here
|
||||
* }
|
||||
* add_filter( 'um_after_email_confirmation', 'my_after_email_confirmation' );
|
||||
* add_action( 'um_after_email_confirmation', 'my_after_email_confirmation' );
|
||||
*/
|
||||
do_action( 'um_after_email_confirmation', $user_id );
|
||||
|
||||
@@ -200,6 +218,18 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Natively approve the user after validation of the email activation link.
|
||||
*
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function approve_user_on_email_confirmation( $user_id ) {
|
||||
um_fetch_user( $user_id ); // @todo maybe don't need to fetch.
|
||||
UM()->common()->users()->approve( $user_id, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an activate link for any user
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user