2017-07-26 14:57:52 +03:00
< ? php
namespace um\core ;
2023-07-12 09:41:25 +03:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
2017-07-26 14:57:52 +03:00
2018-03-26 01:27:46 +03:00
if ( ! class_exists ( 'um\core\Account' ) ) {
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* Class Account
* @package um\core
*/
class Account {
2017-07-26 14:57:52 +03:00
2023-07-12 11:46:03 +03:00
/**
2023-07-13 15:50:56 +03:00
* @var array
2023-07-12 11:46:03 +03:00
*/
2023-07-13 15:50:56 +03:00
private $account_exist = array ();
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* @var
*/
2023-07-12 09:41:25 +03:00
public $tabs ;
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* @var string
*/
2023-07-12 09:41:25 +03:00
public $current_tab = 'general' ;
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* @var array
*/
2023-07-12 09:41:25 +03:00
public $displayed_fields = array ();
2017-07-26 14:57:52 +03:00
2018-03-20 13:24:38 +02:00
/**
* @var array
*/
2023-07-12 09:41:25 +03:00
public $tab_output = array ();
2018-03-20 13:24:38 +02:00
/**
* Account constructor.
*/
2023-07-12 09:41:25 +03:00
public function __construct () {
2018-03-20 13:24:38 +02:00
add_shortcode ( 'ultimatemember_account' , array ( & $this , 'ultimatemember_account' ) );
add_action ( 'template_redirect' , array ( & $this , 'account_page_restrict' ), 10001 );
add_action ( 'template_redirect' , array ( & $this , 'account_submit' ), 10002 );
add_filter ( 'um_predefined_fields_hook' , array ( & $this , 'predefined_fields_hook' ), 1 );
}
/**
2023-10-03 13:30:02 +03:00
* Init AllTabs for user account.
2018-03-20 13:24:38 +02:00
*
2023-10-03 13:30:02 +03:00
* @param array $args
2019-09-27 12:38:14 +03:00
*
* @throws \Exception
2018-03-20 13:24:38 +02:00
*/
2023-10-03 13:30:02 +03:00
public function init_tabs ( $args ) {
2018-03-20 13:24:38 +02:00
$this -> tabs = $this -> get_tabs ();
ksort ( $this -> tabs );
2023-10-03 13:30:02 +03:00
$tabs_structured = array ();
2018-03-20 13:24:38 +02:00
foreach ( $this -> tabs as $k => $arr ) {
foreach ( $arr as $id => $info ) {
2023-10-03 13:30:02 +03:00
if ( ! empty ( $args [ 'tab' ] ) && $id !== $args [ 'tab' ] ) {
2018-03-20 13:24:38 +02:00
continue ;
2019-03-12 09:13:40 +02:00
}
2018-03-20 13:24:38 +02:00
$output = $this -> get_tab_fields ( $id , $args );
2019-03-12 09:13:40 +02:00
if ( ! empty ( $output ) ) {
2023-10-03 13:30:02 +03:00
$tabs_structured [ $id ] = $info ;
2019-03-12 09:13:40 +02:00
}
2018-03-20 13:24:38 +02:00
}
}
2023-10-03 13:30:02 +03:00
$this -> tabs = $tabs_structured ;
2018-03-20 13:24:38 +02:00
}
/**
2023-10-03 13:30:02 +03:00
* Get all Account tabs.
2019-09-27 12:38:14 +03:00
*
* @return array
2018-03-20 13:24:38 +02:00
*/
2023-10-03 13:30:02 +03:00
public function get_tabs () {
$tabs = array ();
2018-03-20 13:24:38 +02:00
$tabs [ 100 ][ 'general' ] = array (
2023-10-03 13:30:02 +03:00
'icon' => 'um-faicon-user' ,
'title' => __ ( 'Account' , 'ultimate-member' ),
'submit_title' => __ ( 'Update Account' , 'ultimate-member' ),
2018-03-20 13:24:38 +02:00
);
$tabs [ 200 ][ 'password' ] = array (
2023-10-03 13:30:02 +03:00
'icon' => 'um-faicon-asterisk' ,
'title' => __ ( 'Change Password' , 'ultimate-member' ),
'submit_title' => __ ( 'Update Password' , 'ultimate-member' ),
2018-03-20 13:24:38 +02:00
);
$tabs [ 300 ][ 'privacy' ] = array (
2023-10-03 13:30:02 +03:00
'icon' => 'um-faicon-lock' ,
'title' => __ ( 'Privacy' , 'ultimate-member' ),
'submit_title' => __ ( 'Update Privacy' , 'ultimate-member' ),
2018-03-20 13:24:38 +02:00
);
2023-10-03 13:30:02 +03:00
// Init here, but default account tab content is empty, so it's hidden.
// Init required here for the using inside the extensions where is possible to disable email notification.
// Default Ultimate Member core notifications cannot be disabled on the user's side.
2018-03-20 13:24:38 +02:00
$tabs [ 400 ][ 'notifications' ] = array (
2023-10-03 13:30:02 +03:00
'icon' => 'um-faicon-envelope' ,
'title' => __ ( 'Notifications' , 'ultimate-member' ),
'submit_title' => __ ( 'Update Notifications' , 'ultimate-member' ),
2018-03-20 13:24:38 +02:00
);
2023-10-03 13:30:02 +03:00
// If user cannot delete profile hide delete tab.
2018-03-20 13:24:38 +02:00
if ( um_user ( 'can_delete_profile' ) || um_user ( 'can_delete_everyone' ) ) {
$tabs [ 99999 ][ 'delete' ] = array (
2023-10-03 13:30:02 +03:00
'icon' => 'um-faicon-trash-o' ,
'title' => __ ( 'Delete Account' , 'ultimate-member' ),
'submit_title' => __ ( 'Delete Account' , 'ultimate-member' ),
2018-03-20 13:24:38 +02:00
);
}
/**
* UM hook
*
* @type filter
* @title um_account_page_default_tabs_hook
* @description Account Page Tabs
* @input_vars
* [{"var":"$tabs","type":"array","desc":"Account Page Tabs"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_account_page_default_tabs_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_account_page_default_tabs_hook', 'my_account_page_default_tabs', 10, 1 );
* function my_account_page_default_tabs( $tabs ) {
* // your code here
* return $tabs;
* }
* ?>
*/
return apply_filters ( 'um_account_page_default_tabs_hook' , $tabs );
}
/**
* Account Shortcode
*
* @param array $args
2019-09-26 16:52:11 +03:00
*
* @return false|string
* @throws \Exception
2018-03-20 13:24:38 +02:00
*/
2023-07-12 09:41:25 +03:00
public function ultimatemember_account ( $args = array () ) {
2020-08-03 18:06:26 +03:00
if ( ! is_user_logged_in () ) {
return '' ;
}
2018-03-20 13:24:38 +02:00
um_fetch_user ( get_current_user_id () );
2023-07-13 15:50:56 +03:00
/** 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'
2018-03-20 13:24:38 +02:00
);
/**
2023-07-13 15:50:56 +03:00
* Filters Account shortcode arguments.
2018-03-20 13:24:38 +02:00
*
2023-07-13 15:50:56 +03:00
* @since 1.3.x
* @hook um_account_shortcode_args_filter
2023-07-22 00:51:26 +03:00
* @deprecated 2.6.9
2023-07-13 15:50:56 +03:00
*
* @param {array} $args Shortcode arguments.
*
* @return {array} Shortcode arguments.
*
* @example <caption>Change Account arguments.</caption>
2018-03-20 13:24:38 +02:00
* function my_account_shortcode_args( $args ) {
2023-07-13 15:50:56 +03:00
* $args['tab'] = 'password';
2018-03-20 13:24:38 +02:00
* return $args;
* }
2023-07-13 15:50:56 +03:00
* add_filter( 'um_account_shortcode_args_filter', 'my_account_shortcode_args' );
2018-03-20 13:24:38 +02:00
*/
2023-07-22 00:51:26 +03:00
$args = apply_filters_deprecated ( 'um_account_shortcode_args_filter' , array ( $args ), '2.6.9' , 'shortcode_atts_ultimatemember_account' );
2018-03-20 13:24:38 +02:00
2023-07-13 15:50:56 +03:00
$account_hash = md5 ( wp_json_encode ( $args ) );
2023-07-22 00:51:26 +03:00
/**
* Filters variable for enable singleton shortcode loading on the same page.
* Note: Set it to `false` if you don't need to render the same form twice or more on the same page.
*
* @since 2.6.9
*
* @hook um_ultimatemember_account_shortcode_disable_singleton
*
* @param {bool} $disable Disabled singleton. By default, it's `true`.
* @param {array} $args Shortcode arguments.
*
* @return {bool} Disabled singleton or not.
*
* @example <caption>Turn off ability to use ultimatemember_account shortcode twice.</caption>
* add_filter( 'um_ultimatemember_account_shortcode_disable_singleton', '__return_false' );
*/
$disable_singleton_shortcode = apply_filters ( 'um_ultimatemember_account_shortcode_disable_singleton' , true , $args );
if ( false === $disable_singleton_shortcode && in_array ( $account_hash , $this -> account_exist , true ) ) {
2023-07-13 15:50:56 +03:00
return '' ;
}
2023-07-22 00:51:26 +03:00
ob_start ();
2018-03-20 13:24:38 +02:00
if ( ! empty ( $args [ 'tab' ] ) ) {
2023-07-12 09:41:25 +03:00
if ( 'account' === $args [ 'tab' ] ) {
2018-03-20 13:24:38 +02:00
$args [ 'tab' ] = 'general' ;
2019-08-08 00:36:33 +03:00
}
2018-03-20 13:24:38 +02:00
$this -> init_tabs ( $args );
$this -> current_tab = $args [ 'tab' ];
if ( ! empty ( $this -> tabs [ $args [ 'tab' ] ] ) ) { ?>
2019-10-21 13:31:59 +03:00
<div class="um um-custom-shortcode-tab">
<div class="um-form">
<form method="post" action="">
<?php
/**
2023-07-13 15:50:56 +03:00
* Fires for render account form hidden fields.
*
* @since 1.3.x
* @hook um_account_page_hidden_fields
*
* @param {array} $args Account shortcode arguments.
2019-10-21 13:31:59 +03:00
*
2023-07-13 15:50:56 +03:00
* @example <caption>Make some action before account tab loading.</caption>
2019-10-21 13:31:59 +03:00
* function my_account_page_hidden_fields( $args ) {
* // your code here
* }
2023-07-13 15:50:56 +03:00
* add_action( 'um_account_page_hidden_fields', 'my_account_page_hidden_fields' );
2019-10-21 13:31:59 +03:00
*/
do_action( 'um_account_page_hidden_fields', $args );
2023-07-12 09:41:25 +03:00
$this->render_account_tab( $args['tab'], $this->tabs[ $args['tab'] ], $args );
?>
2019-10-21 13:31:59 +03:00
</form>
</div>
2018-03-20 13:24:38 +02:00
</div>
2023-07-12 09:41:25 +03:00
<?php
}
2018-03-20 13:24:38 +02:00
} else {
$this->init_tabs( $args );
2023-07-13 15:50:56 +03:00
/**
* 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 <caption>Change Account default tab to Password.</caption>
* 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 );
*/
2019-03-01 17:08:28 +02:00
$this->current_tab = apply_filters( 'um_change_default_tab', $this->current_tab, $args );
2019-02-22 12:39:14 +02:00
2023-06-26 16:54:43 +03:00
/** This filter is documented in includes/core/class-shortcodes.php */
2018-03-20 13:24:38 +02:00
do_action( "um_pre_{$args['mode']}_shortcode", $args );
2023-06-26 16:54:43 +03:00
/** This filter is documented in includes/core/class-shortcodes.php */
2019-08-08 00:36:33 +03:00
do_action( 'um_before_form_is_loaded', $args );
2023-06-26 16:54:43 +03:00
/** This filter is documented in includes/core/class-shortcodes.php */
2018-03-20 13:24:38 +02:00
do_action( "um_before_{$args['mode']}_form_is_loaded", $args );
UM()->shortcodes()->template_load( $args['template'], $args );
}
if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
UM()->shortcodes()->dynamic_css( $args );
}
$output = ob_get_clean();
2019-09-26 16:52:11 +03:00
$this->account_fields_hash();
2023-07-13 15:50:56 +03:00
$this->account_exist[] = $account_hash;
2023-07-12 09:41:25 +03:00
2018-03-20 13:24:38 +02:00
return $output;
}
2019-09-26 16:52:11 +03:00
/**
* Update account fields to secure the account submission
*/
function account_fields_hash() {
update_user_meta( um_user( 'ID' ), 'um_account_secure_fields', UM()->account()->displayed_fields );
}
2018-03-20 13:24:38 +02:00
/**
* Restrict access to Account page
*/
2023-10-03 15:40:10 +03:00
public function account_page_restrict() {
2018-03-20 13:24:38 +02:00
if ( um_is_core_page( 'account' ) ) {
2023-10-03 15:40:10 +03:00
// Redirect to the login page for not logged-in users.
2018-03-20 13:24:38 +02:00
if ( ! is_user_logged_in() ) {
$redirect_to = add_query_arg(
'redirect_to',
2023-10-03 15:40:10 +03:00
urlencode_deep( um_get_core_page( 'account' ) ),
2018-03-20 13:24:38 +02:00
um_get_core_page( 'login' )
);
2023-10-03 15:40:10 +03:00
wp_safe_redirect( $redirect_to );
exit;
2018-03-20 13:24:38 +02:00
}
2023-10-03 15:40:10 +03:00
// Set data for fields.
UM()->fields()->set_mode = 'account';
UM()->fields()->editing = true;
UM()->fields()->global_args = array(
'mode' => 'account',
);
2018-03-20 13:24:38 +02:00
2019-08-08 00:36:33 +03:00
if ( get_query_var( 'um_tab' ) ) {
$this->current_tab = get_query_var( 'um_tab' );
2018-09-17 16:53:40 +03:00
}
2018-03-20 13:24:38 +02:00
}
}
/**
* Submit Account handler
*/
function account_submit() {
if ( um_submitting_account_page() ) {
2023-03-01 14:54:30 +02:00
UM()->form()->post_form = wp_unslash( $_POST );
2018-03-20 13:24:38 +02:00
/**
* UM hook
*
* @type action
* @title um_submit_account_errors_hook
* @description Validate process on account submit
* @input_vars
* [{"var":"$submitted","type":"array","desc":"Account Page Submitted data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_submit_account_errors_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_submit_account_errors_hook', 'my_submit_account_errors', 10, 1 );
* function my_submit_account_errors( $submitted ) {
* // your code here
* }
* ?>
*/
do_action( 'um_submit_account_errors_hook', UM()->form()->post_form );
2019-03-11 16:01:11 +02:00
if ( um_is_core_page( 'account' ) && get_query_var( 'um_tab' ) ) {
$this->current_tab = get_query_var( 'um_tab' );
} else {
$this->current_tab = UM()->form()->post_form['_um_account_tab'];
}
2018-03-20 13:24:38 +02:00
2021-06-29 02:51:54 +03:00
$this->current_tab = sanitize_key( $this->current_tab );
2019-03-11 16:01:11 +02:00
if ( ! isset( UM()->form()->errors ) ) {
2018-03-20 13:24:38 +02:00
/**
* UM hook
*
* @type action
* @title um_submit_account_details
* @description On success account submit
* @input_vars
* [{"var":"$submitted","type":"array","desc":"Account Page Submitted data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_submit_account_details', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_submit_account_details', 'my_submit_account_details', 10, 1 );
* function my_submit_account_details( $submitted ) {
* // your code here
* }
* ?>
*/
do_action( 'um_submit_account_details', UM()->form()->post_form );
2019-03-11 16:01:11 +02:00
} elseif ( UM()->form()->has_error( 'um_account_security' ) ) {
$url = '';
if ( um_is_core_page( 'account' ) ) {
$url = UM()->account()->tab_link( $this->current_tab );
$url = add_query_arg( 'err', 'account', $url );
if ( function_exists( 'icl_get_current_language' ) ) {
if ( icl_get_current_language() != icl_get_default_language() ) {
$url = UM()->permalinks()->get_current_url( true );
$url = add_query_arg( 'err', 'account', $url );
exit( wp_redirect( $url ) );
}
}
}
exit( wp_redirect( $url ) );
2018-03-20 13:24:38 +02:00
}
}
}
/**
* Filter account fields
* @param array $predefined_fields
* @return array
*/
function predefined_fields_hook( $predefined_fields ) {
$account_hide_in_directory = UM()->options()->get( 'account_hide_in_directory' );
2020-01-24 14:59:47 +02:00
$account_hide_in_directory = apply_filters( 'um_account_hide_in_members_visibility', $account_hide_in_directory );
2019-08-08 00:36:33 +03:00
if ( ! $account_hide_in_directory ) {
2018-03-20 13:24:38 +02:00
unset( $predefined_fields['hide_in_members'] );
2019-08-08 00:36:33 +03:00
}
2018-03-20 13:24:38 +02:00
return $predefined_fields;
}
/**
* Get Tab Link
* @param integer $id
* @return string
*/
function tab_link( $id ) {
2023-06-09 12:28:15 +03:00
if ( UM()->is_permalinks ) {
2018-03-20 13:24:38 +02:00
2019-08-08 00:36:33 +03:00
$url = trailingslashit( untrailingslashit( um_get_core_page( 'account' ) ) );
2018-03-20 13:24:38 +02:00
$url = $url . $id . '/';
} else {
2019-08-08 00:36:33 +03:00
$url = add_query_arg( 'um_tab', $id, um_get_core_page( 'account' ) );
2018-03-20 13:24:38 +02:00
}
return $url;
}
/**
* @param $fields
* @param $shortcode_args
* @return mixed
*/
function filter_fields_by_attrs( $fields, $shortcode_args ) {
foreach ( $fields as $k => $field ) {
2019-08-08 00:36:33 +03:00
if ( isset( $shortcode_args[ $field['metakey'] ] ) && 0 == $shortcode_args[ $field['metakey'] ] ) {
2018-03-20 13:24:38 +02:00
unset( $fields[ $k ] );
2019-08-08 00:36:33 +03:00
}
2018-03-20 13:24:38 +02:00
}
return $fields;
}
/**
2019-09-26 16:52:11 +03:00
* Init displayed fields for security check
2018-03-20 13:24:38 +02:00
*
2019-09-26 16:52:11 +03:00
* @param $fields
* @param $tab_key
2018-03-20 13:24:38 +02:00
*/
2019-09-26 16:52:11 +03:00
function init_displayed_fields( $fields, $tab_key ) {
if ( ! $this->is_secure_enabled() ) {
return;
}
if ( ! isset( $this->displayed_fields[ $tab_key ] ) ) {
$this->displayed_fields[ $tab_key ] = array_keys( $fields );
2019-10-21 13:31:59 +03:00
} else {
$this->displayed_fields[ $tab_key ] = array_merge( $this->displayed_fields[ $tab_key ], array_keys( $fields ) );
$this->displayed_fields[ $tab_key ] = array_unique( $this->displayed_fields[ $tab_key ] );
2019-09-26 16:52:11 +03:00
}
}
/**
* @param $field_key
* @param $tab_key
*/
function add_displayed_field( $field_key, $tab_key ) {
if ( ! $this->is_secure_enabled() ) {
return;
}
if ( ! isset( $this->displayed_fields[ $tab_key ] ) ) {
$this->displayed_fields[ $tab_key ] = array( $field_key );
} else {
$this->displayed_fields[ $tab_key ][] = $field_key;
}
}
/**
* @return bool
*/
function is_secure_enabled() {
2018-03-20 13:24:38 +02:00
/**
* UM hook
*
* @type filter
2019-09-26 16:52:11 +03:00
* @title um_account_secure_fields__enabled
* @description Active account secure fields
2018-03-20 13:24:38 +02:00
* @input_vars
2019-09-26 16:52:11 +03:00
* [{"var":"$enabled","type":"string","desc":"Enable secure account fields"}]
2018-03-20 13:24:38 +02:00
* @change_log
* ["Since: 2.0"]
2019-09-26 16:52:11 +03:00
* @usage
* <?php add_filter( 'um_account_secure_fields__enabled', 'function_name', 10, 1 ); ?>
2018-03-20 13:24:38 +02:00
* @example
* <?php
2019-09-26 16:52:11 +03:00
* add_filter( 'um_account_secure_fields__enabled', 'my_account_secure_fields', 10, 1 );
* function my_account_secure_fields( $enabled ) {
2018-03-20 13:24:38 +02:00
* // your code here
2019-09-26 16:52:11 +03:00
* return $enabled;
2018-03-20 13:24:38 +02:00
* }
* ?>
*/
2019-09-26 16:52:11 +03:00
$secure = apply_filters( 'um_account_secure_fields__enabled', true );
return $secure;
2018-03-20 13:24:38 +02:00
}
/**
2019-08-08 00:36:33 +03:00
* Get Tab Output
2018-03-20 13:24:38 +02:00
*
2019-08-08 00:36:33 +03:00
* @param $id
* @param $shortcode_args
*
* @return mixed|string|null
* @throws \Exception
2018-03-20 13:24:38 +02:00
*/
function get_tab_fields( $id, $shortcode_args ) {
$output = null;
2023-10-03 13:30:02 +03:00
UM()->fields()->set_id = absint( $id );
2018-03-20 13:24:38 +02:00
UM()->fields()->set_mode = 'account';
2023-10-03 13:30:02 +03:00
UM()->fields()->editing = true;
2018-03-20 13:24:38 +02:00
2019-09-26 16:52:11 +03:00
if ( ! empty( $this->tab_output[ $id ]['content'] ) && ! empty( $this->tab_output[ $id ]['hash'] ) &&
$this->tab_output[ $id ]['hash'] == md5( json_encode( $shortcode_args ) ) ) {
2019-08-08 00:36:33 +03:00
return $this->tab_output[ $id ]['content'];
2019-03-12 09:13:40 +02:00
}
2018-03-20 13:24:38 +02:00
switch ( $id ) {
case 'privacy':
2024-04-02 17:28:54 +03:00
$args = 'profile_privacy,profile_noindex,hide_in_members,um_show_last_login';
2018-03-20 13:24:38 +02:00
/**
* UM hook
*
* @type filter
* @title um_account_tab_privacy_fields
* @description Extend Account Tab Privacy
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Arguments"},
* {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_account_tab_privacy_fields', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_account_tab_privacy_fields', 'my_account_tab_privacy_fields', 10, 2 );
* function my_account_tab_privacy_fields( $args, $shortcode_args ) {
* // your code here
* return $args;
* }
* ?>
*/
$args = apply_filters( 'um_account_tab_privacy_fields', $args, $shortcode_args );
2019-02-22 12:39:14 +02:00
2018-03-20 13:24:38 +02:00
$fields = UM()->builtin()->get_specific_fields( $args );
$fields = $this->filter_fields_by_attrs( $fields, $shortcode_args );
2019-09-26 16:52:11 +03:00
$this->init_displayed_fields( $fields, $id );
2018-09-24 09:15:18 +03:00
foreach ( $fields as $key => $data ) {
2023-09-02 00:53:51 +03:00
if ( ! empty( $shortcode_args['is_block'] ) ) {
$data['is_block'] = true;
2023-04-27 12:51:57 +03:00
}
2018-03-20 13:24:38 +02:00
$output .= UM()->fields()->edit_field( $key, $data );
}
break;
case 'delete':
2020-08-03 18:06:26 +03:00
$args = '';
if ( $this->current_password_is_required( $id ) ) {
$args = 'single_user_password';
}
2018-03-20 13:24:38 +02:00
/**
* UM hook
*
* @type filter
* @title um_account_tab_delete_fields
* @description Extend Account Tab Delete
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Arguments"},
* {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_account_tab_delete_fields', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_account_tab_delete_fields', 'my_account_tab_delete_fields', 10, 2 );
* function my_account_tab_delete_fields( $args, $shortcode_args ) {
* // your code here
* return $args;
* }
* ?>
*/
$args = apply_filters( 'um_account_tab_delete_fields', $args, $shortcode_args );
$fields = UM()->builtin()->get_specific_fields( $args );
$fields = $this->filter_fields_by_attrs( $fields, $shortcode_args );
2019-09-26 16:52:11 +03:00
$this->init_displayed_fields( $fields, $id );
2018-03-20 13:24:38 +02:00
foreach ( $fields as $key => $data ) {
2023-09-02 00:53:51 +03:00
if ( ! empty( $shortcode_args['is_block'] ) ) {
$data['is_block'] = true;
2023-04-27 12:51:57 +03:00
}
2018-03-20 13:24:38 +02:00
$output .= UM()->fields()->edit_field( $key, $data );
}
2020-08-03 18:06:26 +03:00
if ( ! $output && ! $this->current_password_is_required( $id ) ) {
$output = '<div></div>';
}
2018-03-20 13:24:38 +02:00
break;
case 'general':
$args = 'user_login,first_name,last_name,user_email';
if ( ! UM()->options()->get( 'account_name' ) ) {
$args = 'user_login,user_email';
}
if ( ! UM()->options()->get( 'account_email' ) && ! um_user( 'can_edit_everyone' ) ) {
$args = str_replace(',user_email','', $args );
}
2020-08-03 18:06:26 +03:00
if ( $this->current_password_is_required( $id ) ) {
2019-03-12 09:13:40 +02:00
$args .= ',single_user_password';
}
2018-03-20 13:24:38 +02:00
/**
* UM hook
*
* @type filter
* @title um_account_tab_general_fields
* @description Extend Account Tab General
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Arguments"},
* {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_account_tab_general_fields', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_account_tab_general_fields', 'my_account_tab_general_fields', 10, 2 );
* function my_account_tab_general_fields( $args, $shortcode_args ) {
* // your code here
* return $args;
* }
* ?>
*/
$args = apply_filters( 'um_account_tab_general_fields', $args, $shortcode_args );
$fields = UM()->builtin()->get_specific_fields( $args );
$fields = $this->filter_fields_by_attrs( $fields, $shortcode_args );
2019-09-26 16:52:11 +03:00
$this->init_displayed_fields( $fields, $id );
2018-03-20 13:24:38 +02:00
foreach ( $fields as $key => $data ) {
2023-09-02 00:53:51 +03:00
if ( ! empty( $shortcode_args['is_block'] ) ) {
$data['is_block'] = true;
2023-04-27 12:51:57 +03:00
}
2018-03-20 13:24:38 +02:00
$output .= UM()->fields()->edit_field( $key, $data );
}
break;
case 'password':
$args = 'user_password';
/**
* UM hook
*
* @type filter
* @title um_account_tab_password_fields
* @description Extend Account Tab Password
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Arguments"},
* {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_account_tab_password_fields', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_account_tab_password_fields', 'my_account_tab_password_fields', 10, 2 );
* function my_account_tab_password_fields( $args, $shortcode_args ) {
* // your code here
* return $args;
* }
* ?>
*/
$args = apply_filters( 'um_account_tab_password_fields', $args, $shortcode_args );
$fields = UM()->builtin()->get_specific_fields( $args );
$fields = $this->filter_fields_by_attrs( $fields, $shortcode_args );
2019-09-26 16:52:11 +03:00
$this->init_displayed_fields( $fields, $id );
2018-03-20 13:24:38 +02:00
foreach ( $fields as $key => $data ) {
2023-09-02 00:53:51 +03:00
if ( ! empty( $shortcode_args['is_block'] ) ) {
$data['is_block'] = true;
2023-04-27 12:51:57 +03:00
}
2018-03-20 13:24:38 +02:00
$output .= UM()->fields()->edit_field( $key, $data );
}
break;
default :
/**
* UM hook
*
* @type filter
* @title um_account_content_hook_{$id}
* @description Change not default Account tabs content
* @input_vars
* [{"var":"$output","type":"string","desc":"Account Tab Output"},
* {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_account_content_hook_{$id}', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_account_content_hook_{$id}', 'my_account_content', 10, 2 );
* function my_account_tab_password_fields( $args, $shortcode_args ) {
* // your code here
* return $args;
* }
* ?>
*/
$output = apply_filters( "um_account_content_hook_{$id}", $output, $shortcode_args );
break;
}
2019-08-08 00:36:33 +03:00
$this->tab_output[ $id ] = array( 'content' => $output, 'hash' => md5( json_encode( $shortcode_args ) ) );
2018-03-20 13:24:38 +02:00
return $output;
}
/**
* Render Account Tab HTML
*
* @param $tab_id
* @param $tab_data
* @param $args
2019-08-08 00:36:33 +03:00
*
* @throws \Exception
2018-03-20 13:24:38 +02:00
*/
function render_account_tab( $tab_id, $tab_data, $args ) {
$output = $this->get_tab_fields( $tab_id, $args );
if ( $output ) {
if ( ! empty ( $tab_data['with_header'] ) ) { ?>
2019-08-08 00:36:33 +03:00
<div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo esc_attr( $tab_data['icon'] ) ?>"></i><?php echo esc_html( $tab_data['title'] ); ?></div>
2018-03-20 13:24:38 +02:00
<?php }
/**
* UM hook
*
* @type action
* @title um_before_account_{$tab_id}
* @description Make some action before show account tab
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Page Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_account_{$tab_id}', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_before_account_{$tab_id}', 'my_before_account_tab', 10, 1 );
* function my_before_account_tab( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_before_account_{$tab_id}", $args );
echo $output;
/**
* UM hook
*
* @type action
* @title um_after_account_{$tab_id}
* @description Make some action after show account tab
* @input_vars
* [{"var":"$args","type":"array","desc":"Account Page Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_account_{$tab_id}', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_account_{$tab_id}', 'my_after_account_tab', 10, 1 );
* function my_after_account_tab( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_after_account_{$tab_id}", $args );
if ( ! isset( $tab_data['show_button'] ) || false !== $tab_data['show_button'] ) { ?>
<div class="um-col-alt um-col-alt-b">
<div class="um-left">
2019-03-11 16:01:11 +02:00
<?php $submit_title = ! empty( $tab_data['submit_title'] ) ? $tab_data['submit_title'] : $tab_data['title']; ?>
<input type="hidden" name="um_account_nonce_<?php echo esc_attr( $tab_id ) ?>" value="<?php echo esc_attr( wp_create_nonce( 'um_update_account_' . $tab_id ) ) ?>" />
2019-08-08 00:36:33 +03:00
<input type="submit" name="um_account_submit" id="um_account_submit_<?php echo esc_attr( $tab_id ) ?>" class="um-button" value="<?php echo esc_attr( $submit_title ) ?>" />
2018-03-20 13:24:38 +02:00
</div>
<?php
/**
* UM hook
*
* @type action
* @title um_after_account_{$tab_id}_button
* @description Make some action after show account tab button
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_account_{$tab_id}_button', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_after_account_{$tab_id}_button', 'my_after_account_tab_button', 10 );
* function my_after_account_tab_button() {
* // your code here
* }
* ?>
*/
do_action( "um_after_account_{$tab_id}_button" ); ?>
<div class="um-clear"></div>
</div>
<?php }
}
}
/**
* Add class based on shortcode
*
* @param string $mode
* @return string
*/
function get_class( $mode ) {
$classes = 'um-'.$mode;
if ( is_admin() ) {
$classes .= ' um-in-admin';
}
2023-08-15 03:49:13 +03:00
if ( true === UM()->fields()->editing ) {
2018-03-20 13:24:38 +02:00
$classes .= ' um-editing';
}
2023-08-15 03:49:13 +03:00
if ( true === UM()->fields()->viewing ) {
2018-03-20 13:24:38 +02:00
$classes .= ' um-viewing';
}
/**
* UM hook
*
* @type filter
* @title um_form_official_classes__hook
* @description Change not default Account tabs content
* @input_vars
* [{"var":"$classes","type":"string","desc":"Form Classes"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_form_official_classes__hook', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_form_official_classes__hook', 'my_form_official_classes', 10, 1 );
* function my_form_official_classes( $classes ) {
* // your code here
* return $classes;
* }
* ?>
*/
$classes = apply_filters( 'um_form_official_classes__hook', $classes );
return $classes;
}
2020-08-03 18:06:26 +03:00
/**
2023-10-03 13:30:02 +03:00
* Checks account actions require current password.
2020-08-03 18:06:26 +03:00
*
2023-10-03 13:30:02 +03:00
* @param string $tab_key
2020-08-03 18:06:26 +03:00
*
* @return bool
*/
2023-10-03 13:30:02 +03:00
public function current_password_is_required( $tab_key ) {
2020-08-03 18:06:26 +03:00
$is_required = true;
switch ( $tab_key ) {
case 'general':
$is_required = UM()->options()->get( 'account_general_password' );
break;
case 'delete':
case 'password':
case 'privacy_erase_data':
case 'privacy_download_data':
break;
}
2023-10-03 13:30:02 +03:00
return apply_filters( "um_account_{$tab_key}_require_current", $is_required );
}
2020-08-03 18:06:26 +03:00
2023-10-03 13:30:02 +03:00
/**
* Check the conditional hook for getting notifications tab data.
*
* @return bool
*/
public function is_notifications_tab_visible() {
return apply_filters( 'um_account_notifications_tab_enabled', false );
2020-08-03 18:06:26 +03:00
}
2018-03-20 13:24:38 +02:00
}
2021-06-29 02:51:54 +03:00
}