diff --git a/includes/core/class-account.php b/includes/core/class-account.php index ac2ceda9..ce4b5a15 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -5,10 +5,8 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } - if ( ! class_exists( 'um\core\Account' ) ) { - /** * Class Account * @package um\core @@ -16,34 +14,30 @@ if ( ! class_exists( 'um\core\Account' ) ) { class Account { /** - * @var boolean + * @var array */ - public $account_exist = false; + private $account_exist = array(); /** * @var */ public $tabs; - /** * @var string */ public $current_tab = 'general'; - /** * @var array */ public $displayed_fields = array(); - /** * @var array */ public $tab_output = array(); - /** * Account constructor. */ @@ -54,7 +48,6 @@ if ( ! class_exists( 'um\core\Account' ) ) { add_filter( 'um_predefined_fields_hook', array( &$this, 'predefined_fields_hook' ), 1 ); } - /** * Init AllTabs for user account * @@ -155,7 +148,6 @@ if ( ! class_exists( 'um\core\Account' ) ) { return apply_filters( 'um_account_page_default_tabs_hook', $tabs ); } - /** * Account Shortcode * @@ -168,43 +160,47 @@ if ( ! class_exists( 'um\core\Account' ) ) { if ( ! is_user_logged_in() ) { return ''; } - if ( true === $this->account_exist ) { - return ''; - } um_fetch_user( get_current_user_id() ); - ob_start(); - - $defaults = array( - 'template' => 'account', - 'mode' => 'account', - 'form_id' => 'um_account_id', + /** There is possible to use 'shortcode_atts_ultimatemember_account' filter for getting customized $args. This filter is documented in wp-includes/shortcodes.php "shortcode_atts_{$shortcode}" */ + $args = shortcode_atts( + array( + 'template' => 'account', + 'mode' => 'account', + 'form_id' => 'um_account_id', + 'tab' => '', + ), + $args, + 'ultimatemember_account' ); - $args = wp_parse_args( $args, $defaults ); /** - * UM hook + * Filters Account shortcode arguments. * - * @type filter - * @title um_account_shortcode_args_filter - * @description Account Shortcode Arguments - * @input_vars - * [{"var":"$args","type":"array","desc":"Shortcode Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_shortcode_args_filter', 'function_name', 10, 1 ); - * @example - * Change Account arguments. * function my_account_shortcode_args( $args ) { - * // your code here + * $args['tab'] = 'password'; * return $args; * } - * ?> + * add_filter( 'um_account_shortcode_args_filter', 'my_account_shortcode_args' ); */ $args = apply_filters( 'um_account_shortcode_args_filter', $args ); + $account_hash = md5( wp_json_encode( $args ) ); + if ( in_array( $account_hash, $this->account_exist, true ) ) { + return ''; + } + if ( ! empty( $args['tab'] ) ) { if ( 'account' === $args['tab'] ) { @@ -221,23 +217,18 @@ if ( ! class_exists( 'um\core\Account' ) ) {
Make some action before account tab loading. * function my_account_page_hidden_fields( $args ) { * // your code here * } - * ?> + * add_action( 'um_account_page_hidden_fields', 'my_account_page_hidden_fields' ); */ do_action( 'um_account_page_hidden_fields', $args ); @@ -252,6 +243,24 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_tabs( $args ); + /** + * Filters Account shortcode default tab. + * + * @since 2.0 + * @hook um_change_default_tab + * + * @param {string} $tab Current account tab. + * @param {array} $args Shortcode arguments. + * + * @return {string} Current account tab. + * + * @example Change Account default tab to Password. + * function my_um_change_default_tab( $tab, $args ) { + * $tab = 'password'; + * return $tab; + * } + * add_filter( 'um_change_default_tab', 'my_um_change_default_tab, 10, 2 ); + */ $this->current_tab = apply_filters( 'um_change_default_tab', $this->current_tab, $args ); /** This filter is documented in includes/core/class-shortcodes.php */ @@ -272,7 +281,7 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->account_fields_hash(); - $this->account_exist = true; + $this->account_exist[] = $account_hash; return $output; }