- review ultimatemember_password();

- made UM()->password()->change_password variable as private and avoid dynamic for PHP8 compatibility;
- marked `um_before_{$mode}_form_is_loaded` hook as has to be deprecated since 2.7.0 because it duplicates previous 2 hooks with similar;
- updated hookdocs for `um_before_{$mode}_form_is_loaded`;
- updated hookdocs for `um_before_form_is_loaded`;
- updated hookdocs for `um_pre_{$mode}_shortcode`;
This commit is contained in:
Mykyta Synelnikov
2023-06-26 16:54:43 +03:00
parent bf5c6a6d04
commit f8da8f0433
3 changed files with 75 additions and 163 deletions
+3 -58
View File
@@ -245,69 +245,14 @@ if ( ! class_exists( 'um\core\Account' ) ) {
$this->current_tab = apply_filters( 'um_change_default_tab', $this->current_tab, $args );
/**
* UM hook
*
* @type action
* @title um_pre_{$mode}_shortcode
* @description Make some action before account tabs loading
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Page Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_pre_{$mode}_shortcode', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_pre_{$mode}_shortcode', 'my_pre_account_shortcode', 10, 1 );
* function my_pre_account_shortcode( $args ) {
* // your code here
* }
* ?>
*/
/** This filter is documented in includes/core/class-shortcodes.php */
do_action( "um_pre_{$args['mode']}_shortcode", $args );
/**
* UM hook
*
* @type action
* @title um_before_form_is_loaded
* @description Make some action before account tabs loading
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Page Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_form_is_loaded', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_before_form_is_loaded', 'my_before_form_is_loaded', 10, 1 );
* function my_before_form_is_loaded( $args ) {
* // your code here
* }
* ?>
*/
/** This filter is documented in includes/core/class-shortcodes.php */
do_action( 'um_before_form_is_loaded', $args );
/**
* UM hook
*
* @type action
* @title um_before_{$mode}_form_is_loaded
* @description Make some action before account tabs loading
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Page Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_{$mode}_form_is_loaded', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_before_{$mode}_form_is_loaded', 'my_before_account_form_is_loaded', 10, 1 );
* function my_before_account_form_is_loaded( $args ) {
* // your code here
* }
* ?>
*/
/** This filter is documented in includes/core/class-shortcodes.php */
do_action( "um_before_{$args['mode']}_form_is_loaded", $args );
UM()->shortcodes()->template_load( $args['template'], $args );
}
if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
+34 -80
View File
@@ -1,37 +1,35 @@
<?php
namespace um\core;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\core\Password' ) ) {
/**
* Class Password
* @package um\core
*/
class Password {
private $change_password = false;
/**
* Password constructor.
*/
function __construct() {
public function __construct() {
add_shortcode( 'ultimatemember_password', array( &$this, 'ultimatemember_password' ) );
add_action( 'template_redirect', array( &$this, 'form_init' ), 10001 );
add_action( 'um_reset_password_errors_hook', array( &$this, 'um_reset_password_errors_hook' ) );
add_action( 'um_reset_password_process_hook', array( &$this,'um_reset_password_process_hook' ) );
add_action( 'um_reset_password_process_hook', array( &$this, 'um_reset_password_process_hook' ) );
add_action( 'um_change_password_errors_hook', array( &$this, 'um_change_password_errors_hook' ) );
add_action( 'um_change_password_process_hook', array( &$this,'um_change_password_process_hook' ) );
add_action( 'um_change_password_process_hook', array( &$this, 'um_change_password_process_hook' ) );
}
/**
* Get Reset URL
*
@@ -107,7 +105,6 @@ if ( ! class_exists( 'um\core\Password' ) ) {
return $classes;
}
/**
* Shortcode
*
@@ -116,32 +113,33 @@ if ( ! class_exists( 'um\core\Password' ) ) {
* @return string
*/
public function ultimatemember_password( $args = array() ) {
ob_start();
$defaults = array(
'template' => 'password-reset',
'mode' => 'password',
'form_id' => 'um_password_id',
'max_width' => '450px',
'align' => 'center',
/** There is possible to use 'shortcode_atts_ultimatemember_password' filter for getting customized $atts. This filter is documented in wp-includes/shortcodes.php "shortcode_atts_{$shortcode}" */
$args = shortcode_atts(
array(
'template' => 'password-reset',
'mode' => 'password',
'form_id' => 'um_password_id',
'max_width' => '450px',
'align' => 'center',
),
$args,
'ultimatemember_password'
);
$args = wp_parse_args( $args, $defaults );
if ( empty( $args['use_custom_settings'] ) ) {
$args = array_merge( $args, UM()->shortcodes()->get_css_args( $args ) );
} else {
$args = array_merge( UM()->shortcodes()->get_css_args( $args ), $args );
}
/**
* Filters extend Reset Password Arguments
*
* @since 2.0
* @since 1.3.x
* @hook um_reset_password_shortcode_args_filter
*
* @param {array} $args Shortcode arguments.
* @param {array} $args Shortcode arguments.
*
* @return {array} $args Shortcode arguments.
* @return {array} Shortcode arguments.
*
* @example <caption>Extend Reset Password Arguments.</caption>
* function my_reset_password_shortcode_args( $args ) {
@@ -152,7 +150,7 @@ if ( ! class_exists( 'um\core\Password' ) ) {
*/
$args = apply_filters( 'um_reset_password_shortcode_args_filter', $args );
if ( isset( $this->change_password ) ) {
if ( false !== $this->change_password ) {
// then COOKIE are valid then get data from them and populate hidden fields for the password reset form
$args['template'] = 'password-change';
$args['rp_key'] = '';
@@ -165,74 +163,30 @@ if ( ! class_exists( 'um\core\Password' ) ) {
}
}
UM()->fields()->set_id = 'um_password_id';
if ( ! isset( $mode ) && isset( $args['mode'] ) ) {
$mode = $args['mode'];
}
if ( ! isset( $template ) && isset( $args['template'] ) ) {
$template = $args['template'];
if ( empty( $args['mode'] ) || empty( $args['template'] ) ) {
return '';
}
/**
* Fires pre-load password form shortcode.
*
* @since 2.0
* @hook um_pre_{$mode}_shortcode
*
* @param {array} $args Form shortcode pre-loading.
*
* @example <caption>Make any custom action pre-load password form shortcode.</caption>
* function my_pre_password_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_{$mode}_shortcode', 'my_pre_password_shortcode', 10, 1 );
*/
do_action( "um_pre_{$mode}_shortcode", $args );
UM()->fields()->set_id = $args['form_id'];
/**
* Fires pre-load password form shortcode.
*
* @since 2.0
* @hook um_before_form_is_loaded
*
* @param {array} $args Form shortcode pre-loading.
*
* @example <caption>Make any custom action pre-load password form shortcode.</caption>
* function my_before_form_is_loaded( $args ) {
* // your code here
* }
* add_action( 'um_before_form_is_loaded', 'my_before_form_is_loaded', 10, 1 );
*/
ob_start();
/** This filter is documented in includes/core/class-shortcodes.php */
do_action( "um_pre_{$args['mode']}_shortcode", $args );
/** This filter is documented in includes/core/class-shortcodes.php */
do_action( 'um_before_form_is_loaded', $args );
/** This filter is documented in includes/core/class-shortcodes.php */
do_action( "um_before_{$args['mode']}_form_is_loaded", $args );
/**
* Fires pre-load password form shortcode.
*
* @since 2.0
* @hook um_before_{$mode}_form_is_loaded
*
* @param {array} $args Form shortcode pre-loading.
*
* @example <caption>Make any custom action pre-load password form shortcode.</caption>
* function my_before_form_is_loaded( $args ) {
* // your code here
* }
* add_action( 'um_before_{$mode}_form_is_loaded', 'my_before_form_is_loaded', 10, 1 );
*/
do_action( "um_before_{$mode}_form_is_loaded", $args );
UM()->shortcodes()->template_load( $template, $args );
UM()->shortcodes()->template_load( $args['template'], $args );
if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
UM()->shortcodes()->dynamic_css( $args );
}
$output = ob_get_clean();
return $output;
return ob_get_clean();
}
/**
* Check if a legitimate password reset request is in action
*
+38 -25
View File
@@ -757,50 +757,65 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
}
/**
* Fires pre-load form shortcode.
* Fires before loading form shortcode.
*
* @since 2.0
* Note: $mode can be 'profile', 'login', 'register', 'account'.
*
* @since 1.3.x
* @hook um_pre_{$mode}_shortcode
*
* @param {array} $args Form shortcode pre-loading.
* @param {array} $args Form shortcode arguments.
*
* @example <caption>Make any custom action on pre-load form shortcode.</caption>
* function my_pre_shortcode( $args ) {
* @example <caption>Make any custom action before loading a registration form shortcode.</caption>
* function my_pre_register_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_{$mode}_shortcode', 'my_pre_shortcode', 10, 1 );
* add_action( 'um_pre_register_shortcode', 'my_pre_register_shortcode' );
* @example <caption>Make any custom action before loading a login form shortcode.</caption>
* function my_pre_login_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_login_shortcode', 'my_pre_login_shortcode' );
* @example <caption>Make any custom action before loading a password reset form shortcode.</caption>
* function my_pre_password_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_password_shortcode', 'my_pre_password_shortcode' );
* @example <caption>Make any custom action before loading a profile form shortcode.</caption>
* function my_pre_profile_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_profile_shortcode', 'my_pre_profile_shortcode' );
* @example <caption>Make any custom action before loading an account form shortcode.</caption>
* function my_pre_account_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_pre_account_shortcode', 'my_pre_account_shortcode' );
*/
do_action( "um_pre_{$mode}_shortcode", $args );
/**
* Fires pre-load form shortcode.
* Fires before loading form shortcode.
*
* @since 2.0
* @since 1.3.x
* @hook um_before_form_is_loaded
*
* @param {array} $args Form shortcode pre-loading.
* @param {array} $args Form shortcode arguments.
*
* @example <caption>Make any custom action on pre-load form shortcode.</caption>
* @example <caption>Make any custom action before loading UM form shortcode.</caption>
* function my_pre_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_before_form_is_loaded', 'my_pre_shortcode', 10, 1 );
*/
do_action( 'um_before_form_is_loaded', $args );
/**
* Fires pre-load form shortcode.
* Fires before loading a form shortcode.
*
* @since 2.0
* @since 1.3.x
* @todo Deprecate since 2.7.0. Use `um_pre_{$mode}_shortcode` or `um_before_form_is_loaded` instead.
* @hook um_before_{$mode}_form_is_loaded
*
* @param {array} $args Form shortcode pre-loading.
*
* @example <caption>Make any custom action on pre-load form shortcode.</caption>
* function my_pre_shortcode( $args ) {
* // your code here
* }
* add_action( 'um_before_{$mode}_form_is_loaded', 'my_pre_shortcode', 10, 1 );
* @param {array} $args Form shortcode arguments.
*/
do_action( "um_before_{$mode}_form_is_loaded", $args );
@@ -808,7 +823,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
$this->dynamic_css( $args );
if ( um_get_requested_user() || 'logout' === $mode ) {
if ( 'logout' === $mode || um_get_requested_user() ) {
um_reset_user();
}
@@ -828,11 +843,9 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
*/
do_action( 'um_after_everything_output' );
$output = ob_get_clean();
return $output;
return ob_get_clean();
}
/**
* Get dynamic CSS args
*