mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-17 13:43:38 +09:00
Refactor email placeholders and deprecate obsolete methods
Streamline placeholder handling for emails by introducing universal patterns and replacements, and update email dispatch functions for efficiency. Deprecated various redundant user and password-related methods, consolidating logic into common utility classes for better maintainability.
This commit is contained in:
@@ -348,9 +348,6 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
||||
*/
|
||||
$message = apply_filters( 'um_email_send_message_content', $message, $slug, $args );
|
||||
|
||||
// add_filter( 'um_template_tags_patterns_hook', array( &$this, 'add_placeholder' ) );
|
||||
// add_filter( 'um_template_tags_replaces_hook', array( &$this, 'add_replace_placeholder' ) );
|
||||
|
||||
// Convert tags in email template.
|
||||
return um_convert_tags( $message, $args );
|
||||
}
|
||||
@@ -616,12 +613,8 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
||||
$placeholders[] = '{user_profile_link}';
|
||||
$placeholders[] = '{site_url}';
|
||||
$placeholders[] = '{admin_email}';
|
||||
$placeholders[] = '{submitted_registration}';
|
||||
$placeholders[] = '{login_url}';
|
||||
$placeholders[] = '{password}';
|
||||
$placeholders[] = '{account_activation_link}';
|
||||
$placeholders[] = '{action_url}';
|
||||
$placeholders[] = '{action_title}';
|
||||
return $placeholders;
|
||||
}
|
||||
|
||||
@@ -636,20 +629,8 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
||||
$replace_placeholders[] = um_user_profile_url();
|
||||
$replace_placeholders[] = get_bloginfo( 'url' );
|
||||
$replace_placeholders[] = um_admin_email();
|
||||
$replace_placeholders[] = um_user_submitted_registration_formatted();
|
||||
$replace_placeholders[] = um_get_core_page( 'login' );
|
||||
$replace_placeholders[] = esc_html__( 'Your set password', 'ultimate-member' );
|
||||
$replace_placeholders[] = um_user( 'account_activation_link' );
|
||||
|
||||
$set_password_required = get_user_meta( um_user( 'ID' ), 'um_set_password_required', true );
|
||||
if ( empty( $set_password_required ) || 'pending' === um_user( 'status' ) ) {
|
||||
$replace_placeholders[] = um_get_core_page( 'login' );
|
||||
$replace_placeholders[] = esc_html__( 'Login to our site', 'ultimate-member' );
|
||||
} else {
|
||||
$replace_placeholders[] = um_user( 'password_reset_link' );
|
||||
$replace_placeholders[] = esc_html__( 'Set your password', 'ultimate-member' );
|
||||
}
|
||||
|
||||
return $replace_placeholders;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ if ( ! class_exists( 'um\core\Password' ) ) {
|
||||
}
|
||||
|
||||
if ( empty( $reset_key ) ) {
|
||||
$reset_key = UM()->user()->maybe_generate_password_reset_key( $user_data );
|
||||
$reset_key = UM()->common()->users()->maybe_generate_password_reset_key( $user_data );
|
||||
}
|
||||
|
||||
// this link looks like WordPress native link e.g. wp-login.php?action=rp&key={hash}&login={user_login}
|
||||
$url = add_query_arg(
|
||||
// This link looks like WordPress native link e.g. wp-login.php?action=rp&key={hash}&login={user_login}
|
||||
return add_query_arg(
|
||||
array(
|
||||
'act' => 'reset_password',
|
||||
'hash' => $reset_key,
|
||||
@@ -69,7 +69,6 @@ if ( ! class_exists( 'um\core\Password' ) ) {
|
||||
),
|
||||
um_get_core_page( 'password-reset' )
|
||||
);
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
@@ -695,31 +694,27 @@ if ( ! class_exists( 'um\core\Password' ) ) {
|
||||
setcookie( $name, $value, $expire, $path, COOKIE_DOMAIN, is_ssl(), true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* UM Placeholders for reset password
|
||||
*
|
||||
* @depreated 2.10.5
|
||||
* @param $placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function add_placeholder( $placeholders ) {
|
||||
$placeholders[] = '{password_reset_link}';
|
||||
$placeholders[] = '{password}';
|
||||
public function add_placeholder( $placeholders ) {
|
||||
_deprecated_function( __METHOD__, '2.10.5' );
|
||||
return $placeholders;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* UM Replace Placeholders for reset password
|
||||
*
|
||||
* @depreated 2.10.5
|
||||
* @param $replace_placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function add_replace_placeholder( $replace_placeholders ) {
|
||||
$replace_placeholders[] = um_user( 'password_reset_link' );
|
||||
$replace_placeholders[] = esc_html__( 'Your set password', 'ultimate-member' );
|
||||
public function add_replace_placeholder( $replace_placeholders ) {
|
||||
_deprecated_function( __METHOD__, '2.10.5' );
|
||||
return $replace_placeholders;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,8 +172,7 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
$redirect = empty( $user_role_data['url_email_activate'] ) ? um_get_core_page( 'login', 'account_active' ) : trim( $user_role_data['url_email_activate'] );
|
||||
} else {
|
||||
// Redirect to the change password page if there is no password for this user.
|
||||
um_fetch_user( $user_id );
|
||||
$redirect = um_user( 'password_reset_link' );
|
||||
$redirect = UM()->password()->reset_url( $user_id );
|
||||
}
|
||||
/**
|
||||
* Filter to change the redirect URL after email confirmation.
|
||||
@@ -204,40 +203,44 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
/**
|
||||
* Makes an activate link for any user
|
||||
*
|
||||
* @return bool|string
|
||||
* @return string
|
||||
*/
|
||||
public function activate_url() {
|
||||
if ( ! um_user( 'account_secret_hash' ) ) {
|
||||
return false;
|
||||
public function activate_url( $user_id = null ) {
|
||||
if ( is_null( $user_id ) ) {
|
||||
$user_id = um_user( 'ID' );
|
||||
}
|
||||
|
||||
$account_secret_hash = get_user_meta( $user_id, 'account_secret_hash', true );
|
||||
if ( empty( $account_secret_hash ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
* Filter to change the base URL for the user activation link.
|
||||
*
|
||||
* @type filter
|
||||
* @title um_activate_url
|
||||
* @description Change activate user URL
|
||||
* @input_vars
|
||||
* [{"var":"$url","type":"string","desc":"Activate URL"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_activate_url', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_activate_url', 'my_activate_url', 10, 1 );
|
||||
* function my_activate_url( $url ) {
|
||||
* @hook um_activate_url
|
||||
*
|
||||
* @param {string} $url The base URL. `home_url()` by default
|
||||
*
|
||||
* @since 1.3.x
|
||||
*
|
||||
* @example <caption>Change activate user base URL.</caption>
|
||||
* function my_after_email_confirmation_redirect( $url ) {
|
||||
* // your code here
|
||||
* return $url;
|
||||
* }
|
||||
* ?>
|
||||
* add_filter( 'um_activate_url', 'my_um_activate_url' );
|
||||
*/
|
||||
$url = apply_filters( 'um_activate_url', home_url() );
|
||||
$url = add_query_arg( 'act', 'activate_via_email', $url );
|
||||
$url = add_query_arg( 'hash', um_user( 'account_secret_hash' ), $url );
|
||||
$url = add_query_arg( 'user_id', um_user( 'ID' ), $url );
|
||||
$base_url = apply_filters( 'um_activate_url', home_url() );
|
||||
|
||||
return $url;
|
||||
return add_query_arg(
|
||||
array(
|
||||
'act' => 'activate_via_email',
|
||||
'hash' => $account_secret_hash,
|
||||
'user_id' => $user_id,
|
||||
),
|
||||
$base_url
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -513,35 +513,28 @@ if ( ! class_exists( 'um\core\Profile' ) ) {
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* UM Placeholders for user link, avatar link
|
||||
*
|
||||
* @depreacated 2.10.5
|
||||
* @param $placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function add_placeholder( $placeholders ) {
|
||||
$placeholders[] = '{user_profile_link}';
|
||||
$placeholders[] = '{user_avatar_url}';
|
||||
$placeholders[] = '{password}';
|
||||
public function add_placeholder( $placeholders ) {
|
||||
_deprecated_function( __METHOD__, '2.10.5' );
|
||||
return $placeholders;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* UM Replace Placeholders for user link, avatar link
|
||||
*
|
||||
* @deprecated 2.10.5
|
||||
* @param $replace_placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function add_replace_placeholder( $replace_placeholders ) {
|
||||
$replace_placeholders[] = um_get_user_avatar_url();
|
||||
$replace_placeholders[] = um_user_profile_url();
|
||||
$replace_placeholders[] = esc_html__( 'Your set password', 'ultimate-member' );
|
||||
public function add_replace_placeholder( $replace_placeholders ) {
|
||||
_deprecated_function( __METHOD__, '2.10.5' );
|
||||
return $replace_placeholders;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
namespace um\core;
|
||||
|
||||
use WP_Error;
|
||||
use WP_User;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
@@ -965,7 +968,7 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
* On wp_update_user function complete
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param \WP_User $old_data
|
||||
* @param WP_User $old_data
|
||||
*/
|
||||
function profile_update( $user_id, $old_data ) {
|
||||
// Bail if no user ID was passed
|
||||
@@ -1018,7 +1021,7 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
/**
|
||||
* Additional section for WP Profile page with UM data fields
|
||||
*
|
||||
* @param \WP_User $userdata User data
|
||||
* @param WP_User $userdata User data
|
||||
* @return void
|
||||
*/
|
||||
function profile_form_additional_section( $userdata ) {
|
||||
@@ -1063,7 +1066,7 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
* Default interface for setting a ultimatemember role
|
||||
*
|
||||
* @param string $content Section HTML
|
||||
* @param \WP_User $userdata User data
|
||||
* @param WP_User $userdata User data
|
||||
* @return string
|
||||
*/
|
||||
public function secondary_role_field( $content, $userdata ) {
|
||||
@@ -1103,7 +1106,7 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
$class = ( $userdata == 'add-existing-user' ) ? 'um_role_existing_selector_wrapper' : 'um_role_selector_wrapper';
|
||||
$class = 'add-existing-user' === $userdata ? 'um_role_existing_selector_wrapper' : 'um_role_selector_wrapper';
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
@@ -1468,22 +1471,6 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
do_action( 'um_after_save_registration_details', $this->id, $submitted, $form_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set last login for new registered users
|
||||
*/
|
||||
public function set_last_login() {
|
||||
update_user_meta( $this->id, '_um_last_login', current_time( 'mysql', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_User $userdata
|
||||
*
|
||||
* @return string|\WP_Error
|
||||
*/
|
||||
function maybe_generate_password_reset_key( $userdata ) {
|
||||
return get_password_reset_key( $userdata );
|
||||
}
|
||||
|
||||
/**
|
||||
* Password reset email
|
||||
*
|
||||
@@ -1497,19 +1484,22 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
}
|
||||
$userdata = get_userdata( $user_id );
|
||||
|
||||
$this->maybe_generate_password_reset_key( $userdata );
|
||||
|
||||
$mail_args = array(
|
||||
'fetch_user_id' => $user_id,
|
||||
'tags' => array(
|
||||
'{password_reset_link}',
|
||||
),
|
||||
'tags_replace' => array(
|
||||
UM()->password()->reset_url( $user_id ),
|
||||
),
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action(
|
||||
'um_dispatch_email',
|
||||
array(
|
||||
$userdata->user_email,
|
||||
'resetpw_email',
|
||||
array(
|
||||
'fetch_user_id' => $user_id,
|
||||
'tags' => array(
|
||||
'{password_reset_link}',
|
||||
),
|
||||
'tags_replace' => array(
|
||||
UM()->password()->reset_url( $user_id ),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, 'resetpw_email', $mail_args ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2121,30 +2111,6 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
return $hash_email_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* UM Placeholders for activation link in email
|
||||
*
|
||||
* @param $placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_activation_placeholder( $placeholders ) {
|
||||
$placeholders[] = '{account_activation_link}';
|
||||
return $placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
* UM Replace Placeholders for activation link in email
|
||||
*
|
||||
* @param $replace_placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_activation_replace_placeholder( $replace_placeholders ) {
|
||||
$replace_placeholders[] = um_user( 'account_activation_link' );
|
||||
return $replace_placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user's account status
|
||||
*
|
||||
@@ -2240,5 +2206,53 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->deactivate()' );
|
||||
UM()->common()->users()->deactivate( um_user( 'ID' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 2.10.5
|
||||
*
|
||||
* @param WP_User $userdata
|
||||
*
|
||||
* @return string|WP_Error
|
||||
*/
|
||||
public function maybe_generate_password_reset_key( $userdata ) {
|
||||
_deprecated_function( __METHOD__, '2.10.5', 'UM()->common()->users()->maybe_generate_password_reset_key()' );
|
||||
return UM()->common()->users()->maybe_generate_password_reset_key( $userdata );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set last login for new registered users
|
||||
*
|
||||
* @deprecated 2.10.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_last_login() {
|
||||
_deprecated_function( __METHOD__, '2.10.5', 'UM()->common()->users()->set_last_login()' );
|
||||
UM()->common()->users()->set_last_login( $this->id );
|
||||
}
|
||||
|
||||
/**
|
||||
* UM Placeholders for activation link in email
|
||||
* @deprecated 2.10.5
|
||||
* @param $placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_activation_placeholder( $placeholders ) {
|
||||
_deprecated_function( __METHOD__, '2.10.5' );
|
||||
return $placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
* UM Replace Placeholders for activation link in email
|
||||
* @deprecated 2.10.5
|
||||
* @param $replace_placeholders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_activation_replace_placeholder( $replace_placeholders ) {
|
||||
_deprecated_function( __METHOD__, '2.10.5' );
|
||||
return $replace_placeholders;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,11 +157,9 @@ add_action( 'um_submit_form_errors_hook_logincheck', 'um_submit_form_errors_hook
|
||||
* @param $user_id
|
||||
*/
|
||||
function um_store_lastlogin_timestamp( $user_id ) {
|
||||
update_user_meta( $user_id, '_um_last_login', current_time( 'mysql', true ) );
|
||||
// Flush user cache after updating last_login timestamp.
|
||||
UM()->user()->remove_cache( $user_id );
|
||||
UM()->common()->users()->set_last_login( $user_id );
|
||||
}
|
||||
add_action( 'um_on_login_before_redirect', 'um_store_lastlogin_timestamp', 10, 1 );
|
||||
add_action( 'um_on_login_before_redirect', 'um_store_lastlogin_timestamp' );
|
||||
|
||||
|
||||
/**
|
||||
@@ -171,7 +169,7 @@ function um_store_lastlogin_timestamp_( $login ) {
|
||||
$user = get_user_by( 'login', $login );
|
||||
|
||||
if ( false !== $user ) {
|
||||
um_store_lastlogin_timestamp( $user->ID );
|
||||
UM()->common()->users()->set_last_login( $user->ID );
|
||||
|
||||
$attempts = (int) get_user_meta( $user->ID, 'password_rst_attempts', true );
|
||||
if ( $attempts ) {
|
||||
|
||||
@@ -120,15 +120,27 @@ function um_send_registration_notification( $user_id ) {
|
||||
|
||||
um_fetch_user( $user_id );
|
||||
$registration_status = um_user( 'status' );
|
||||
$email_template = 'pending' !== $registration_status ? 'notification_new_user' : 'notification_review';
|
||||
$sending_args = array(
|
||||
'admin' => true,
|
||||
'fetch_user_id' => $user_id,
|
||||
'tags' => array(
|
||||
'{submitted_registration}',
|
||||
),
|
||||
'tags_replace' => um_user_submitted_registration_formatted(),
|
||||
);
|
||||
|
||||
$emails = um_multi_admin_email();
|
||||
if ( ! empty( $emails ) ) {
|
||||
foreach ( $emails as $email ) {
|
||||
if ( 'pending' !== $registration_status ) {
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $email, 'notification_new_user', array( 'admin' => true, 'fetch_user_id' => $user_id ) ) );
|
||||
} else {
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $email, 'notification_review', array( 'admin' => true, 'fetch_user_id' => $user_id ) ) );
|
||||
}
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action(
|
||||
'um_dispatch_email',
|
||||
array(
|
||||
$email,
|
||||
$email_template,
|
||||
$sending_args,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user