';
protected function __construct() {
add_filter( 'brandy_extra_localize', array( $this, 'add_localize_data' ) );
$this->title = __( 'Account', 'brandy' );
parent::__construct();
}
/**
* Register settings components
*/
protected function register_components() {
return array(
'logged_in_title' => array(
'type' => 'AccountLoggedInTitle',
),
'logged_in_profile_type' => array(
'title' => array(
'text' => __( 'Profile type', 'brandy' ),
'type' => 'bold',
),
'value_path' => array( self::LOGGED_IN_STATE, 'profile_type' ),
'type' => 'ButtonGroup',
'options' => array(
array(
'label' => 'Avatar',
'value' => 'avatar',
),
array(
'label' => 'Icon',
'value' => 'icon',
),
array(
'label' => 'Text',
'value' => 'text',
),
),
'default_value' => 'icon',
'render_options' => array(
'type' => 'force_refresh',
),
),
'logged_in_icon_type' => array(
'title' => array(
'text' => __( 'Select icon', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( self::LOGGED_IN_STATE, 'icon', 'type' ),
'type' => 'AccountIconSelection',
'default_value' => 'icon_1',
'visible_conditions' => array(
array(
'value_path' => array( self::LOGGED_IN_STATE, 'profile_type' ),
'value' => 'icon',
),
),
'render_options' => array(
'type' => 'force_refresh',
),
),
'logged_in_icon_style' => array(
'title' => array(
'text' => __( 'Icon style', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( self::LOGGED_IN_STATE, 'icon', 'style' ),
'type' => 'ButtonGroup',
'options' => array(
array(
'label' => 'Bold',
'value' => 'bold',
),
array(
'label' => 'Outline',
'value' => 'outline',
),
),
'default_value' => 'outline',
'render_options' => array(
'type' => 'force_refresh',
),
'visible_conditions' => array(
array(
'value_path' => array( self::LOGGED_IN_STATE, 'profile_type' ),
'value' => 'icon',
),
),
),
'logged_in_click_action' => array(
'title' => array(
'text' => __( 'Click action', 'brandy' ),
'type' => 'bold',
),
// Translators: %s Link to menu.
'description' => sprintf( __( 'If you want to choose menu, configure menu from here', 'brandy' ), esc_url( admin_url( 'nav-menus.php' ) ) ),
'value_path' => array( self::LOGGED_IN_STATE, 'click_action' ),
'type' => 'AccountClickAction',
'options' => array(
array(
'label' => 'Profile',
'value' => 'profile',
),
array(
'label' => 'Woocommerce',
'value' => 'woocommerce',
),
array(
'label' => 'Logout',
'value' => 'logout',
),
array(
'label' => 'Menu',
'value' => 'menu',
),
array(
'label' => 'Custom link',
'value' => 'custom',
),
),
'default_value' => 'profile',
),
'logged_in_custom_link' => array(
'title' => array(
'text' => __( 'Custom link', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( self::LOGGED_IN_STATE, 'custom_link' ),
'type' => 'TextInput',
'default_value' => '#',
'visible_conditions' => array(
array(
'value_path' => array( self::LOGGED_IN_STATE, 'click_action' ),
'value' => 'custom',
),
),
'render_options' => array(
'type' => 'data_attribute',
'data' => array(
array(
'selector' => '.brandy-account[state="logged_in"]',
'name' => 'href',
'value_path' => array( self::LOGGED_IN_STATE, 'custom_link' ),
),
),
),
),
'logged_in_label_enabled' => array(
'title' => array(
'text' => __( 'Label', 'brandy' ),
'type' => 'bold',
'show_devices' => true,
),
'description' => __( 'Toggle to show as label or tooltip', 'brandy' ),
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'enabled' ),
'type' => 'Switcher',
'default_value' => array(
'desktop' => false,
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'force_refresh',
),
),
'logged_in_label_type' => array(
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'type' ),
'type' => 'ButtonGroup',
'default_value' => array(
'desktop' => 'name',
'tablet' => null,
'mobile' => null,
),
'options' => array(
array(
'label' => __( 'Name', 'brandy' ),
'value' => 'name',
),
array(
'label' => __( 'Text', 'brandy' ),
'value' => 'text',
),
),
'render_options' => array(
'type' => 'force_refresh',
),
),
'logged_in_label_text' => array(
'title' => array(
'text' => __( 'Add label', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'text' ),
'type' => 'TextInput',
'default_value' => array(
'desktop' => 'Account',
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'content',
'data' => array(
array(
'selector' => '.brandy-account[state="logged_in"] .brandy-account__label[device="desktop"]',
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'text', 'desktop' ),
),
array(
'selector' => '.brandy-account[state="logged_in"] .brandy-account__label[device="tablet"]',
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'text', 'tablet' ),
),
array(
'selector' => '.brandy-account[state="logged_in"] .brandy-account__label[device="mobile"]',
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'text', 'mobile' ),
),
),
),
'visible_conditions' => array(
'relation' => 'AND',
array(
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'type' ),
'value' => 'text',
),
array(
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'enabled' ),
'value' => true,
),
),
),
'logged_in_label_position' => array(
'title' => array(
'text' => __( 'Label position', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'position' ),
'type' => 'Position',
'default_value' => array(
'desktop' => 'right',
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'data_attribute',
'data' => array(
array(
'selector' => '.brandy-account[device="desktop"]',
'name' => 'label-position',
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'position', 'desktop' ),
),
array(
'selector' => '.brandy-account[device="tablet"]',
'name' => 'label-position',
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'position', 'tablet' ),
),
array(
'selector' => '.brandy-account[device="mobile"]',
'name' => 'label-position',
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'position', 'mobile' ),
),
),
),
'visible_conditions' => array(
array(
'value_path' => array( self::LOGGED_IN_STATE, 'label', 'enabled' ),
'value' => true,
),
),
),
'logged_in_target' => array(
'title' => array(
'text' => __( 'Open in a new tab', 'brandy' ),
'type' => 'bold',
),
'value_path' => array( self::LOGGED_IN_STATE, 'target' ),
'type' => 'Switcher',
'default_value' => true,
'render_options' => array(
'type' => 'data_attribute',
'data' => array(
array(
'type' => 'switcher',
'selector' => 'a.brandy-account[device="desktop"]',
'name' => 'target',
'value_path' => array( self::LOGGED_IN_STATE, 'target' ),
'enabled_value' => '_blank',
'disabled_value' => '_self',
),
array(
'type' => 'switcher',
'selector' => 'a.brandy-account[device="tablet"]',
'name' => 'target',
'value_path' => array( self::LOGGED_IN_STATE, 'target' ),
'enabled_value' => '_blank',
'disabled_value' => '_self',
),
array(
'type' => 'switcher',
'selector' => 'a.brandy-account[device="mobile"]',
'name' => 'target',
'value_path' => array( self::LOGGED_IN_STATE, 'target' ),
'enabled_value' => '_blank',
'disabled_value' => '_self',
),
),
),
),
'logged_out_title' => array(
'type' => 'AccountLoggedOutTitle',
),
'logged_out_click_action' => array(
'title' => array(
'text' => __( 'Click action', 'brandy' ),
'type' => 'bold',
),
// Translators: %s Link to menu.
'description' => sprintf( __( 'If you want to choose menu, configure menu from here', 'brandy' ), esc_url( admin_url( 'nav-menus.php' ) ) ),
'value_path' => array( 'logged_out', 'click_action' ),
'type' => 'AccountClickAction',
'options' => array(
array(
'label' => 'Login',
'value' => 'login',
),
array(
'label' => 'Custom link',
'value' => 'custom',
),
),
'default_value' => 'login',
),
'logged_out_custom_link' => array(
'title' => array(
'text' => __( 'Custom link', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'logged_out', 'custom_link' ),
'type' => 'TextInput',
'default_value' => '#',
'visible_conditions' => array(
array(
'value_path' => array( 'logged_out', 'click_action' ),
'value' => 'custom',
),
),
'render_options' => array(
'type' => 'data_attribute',
'data' => array(
array(
'selector' => '.brandy-account[state="logged_out"]',
'name' => 'href',
'value_path' => array( 'logged_out', 'custom_link' ),
),
),
),
),
'logged_out_target' => array(
'title' => array(
'text' => __( 'Open in a new tab', 'brandy' ),
'type' => 'bold',
),
'value_path' => array( self::LOGGED_OUT_STATE, 'target' ),
'type' => 'Switcher',
'default_value' => true,
'render_options' => array(
'type' => 'data_attribute',
'data' => array(
array(
'type' => 'switcher',
'selector' => 'a.brandy-account[state="' . self::LOGGED_OUT_STATE . '"]',
'name' => 'target',
'value_path' => array( self::LOGGED_OUT_STATE, 'target' ),
'enabled_value' => '_blank',
'disabled_value' => '_self',
),
),
),
),
'logged_out_profile_type' => array(
'title' => array(
'text' => __( 'Profile type', 'brandy' ),
'type' => 'bold',
),
'value_path' => array( 'logged_out', 'profile_type' ),
'type' => 'ButtonGroup',
'options' => array(
array(
'label' => 'Icon',
'value' => 'icon',
),
array(
'label' => 'Text',
'value' => 'text',
),
),
'default_value' => 'icon',
'render_options' => array(
'type' => 'force_refresh',
),
),
'logged_out_icon_type' => array(
'title' => array(
'text' => __( 'Select icon', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'logged_out', 'icon', 'type' ),
'type' => 'AccountIconSelection',
'default_value' => 'icon_1',
'visible_conditions' => array(
array(
'value_path' => array( 'logged_out', 'profile_type' ),
'value' => 'icon',
),
),
'render_options' => array(
'type' => 'force_refresh',
),
),
'logged_out_icon_style' => array(
'title' => array(
'text' => __( 'Icon style', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'logged_out', 'icon', 'style' ),
'type' => 'ButtonGroup',
'options' => array(
array(
'label' => 'Bold',
'value' => 'bold',
),
array(
'label' => 'Outline',
'value' => 'outline',
),
),
'default_value' => 'outline',
'render_options' => array(
'type' => 'force_refresh',
),
'visible_conditions' => array(
array(
'value_path' => array( 'logged_out', 'profile_type' ),
'value' => 'icon',
),
),
),
'logged_out_label_text' => array(
'title' => array(
'text' => __( 'Add label', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'logged_out', 'label', 'text' ),
'type' => 'TextInput',
'default_value' => 'Login',
'render_options' => array(
'type' => 'content',
'data' => array(
array(
'name' => '',
'value_path' => array( 'logged_out', 'label', 'text' ),
),
),
),
),
'logged_out_label_enabled' => array(
'title' => array(
'text' => __( 'Label', 'brandy' ),
'type' => 'bold',
'show_devices' => true,
),
'description' => __( 'Toggle to show as label or tooltip', 'brandy' ),
'value_path' => array( self::LOGGED_OUT_STATE, 'label', 'enabled' ),
'type' => 'Switcher',
'default_value' => array(
'desktop' => false,
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'force_refresh',
),
),
'icon_reset' => array(
'title' => array(
'text' => __( 'Icon account', 'brandy' ),
'type' => 'bold',
'show_devices' => true,
),
'reset_paths' => array( array( 'icon' ) ),
'type' => 'Reset',
),
'icon_color' => array(
'title' => array(
'text' => __( 'Icon color', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'icon', 'color' ),
'type' => 'ColorGroup',
'default_value' => array(
'normal' => array(
'desktop' => 'var(--wp--preset--color--brandy-secondary-text)',
'tablet' => null,
'mobile' => null,
),
'hover' => array(
'desktop' => 'var(--wp--preset--color--brandy-secondary-text)',
'tablet' => null,
'mobile' => null,
),
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'color',
'name' => '--element-account-icon-color',
'value_path' => array( 'icon', 'color' ),
),
),
),
),
'icon_background' => array(
'title' => array(
'text' => __( 'Background color', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'icon', 'background' ),
'type' => 'ColorGroup',
'default_value' => array(
'normal' => array(
'desktop' => '#ffffff00',
'tablet' => null,
'mobile' => null,
),
'hover' => array(
'desktop' => '#ffffff00',
'tablet' => null,
'mobile' => null,
),
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'color',
'name' => '--element-account-icon-background',
'value_path' => array( 'icon', 'background' ),
),
),
),
),
'icon_border_color' => array(
'title' => array(
'text' => __( 'Border color', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'icon', 'border', 'color' ),
'type' => 'ColorGroup',
'default_value' => array(
'normal' => array(
'desktop' => 'var(--wp--preset--color--brandy-border)',
'tablet' => null,
'mobile' => null,
),
'hover' => array(
'desktop' => 'var(--wp--preset--color--brandy-border)',
'tablet' => null,
'mobile' => null,
),
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'color',
'name' => '--element-account-icon-border-color',
'value_path' => array( 'icon', 'border', 'color' ),
),
),
),
),
'icon_border_width' => array(
'title' => array(
'text' => __( 'Border width', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'icon', 'border', 'width' ),
'type' => 'Dimension',
'units' => array( 'px' ),
'default_value' => array(
'desktop' => array(
'unit' => 'px',
'min' => 0,
'max' => 30,
'value' => 0,
),
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'dimension',
'name' => '--element-account-icon-border-width',
'value_path' => array( 'icon', 'border', 'width' ),
),
),
),
),
'icon_border_radius' => array(
'title' => array(
'text' => __( 'Border radius', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'icon', 'border_radius' ),
'type' => 'Dimension',
'units' => array( 'px', '%' ),
'default_value' => array(
'desktop' => array(
'unit' => 'px',
'min' => 0,
'max' => 100,
'value' => 100,
),
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'dimension',
'name' => '--element-account-icon-border-radius',
'value_path' => array( 'icon', 'border_radius' ),
),
),
),
),
'icon_size' => array(
'title' => array(
'text' => __( 'Size icon', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'icon', 'size' ),
'type' => 'Dimension',
'units' => array( 'px' ),
'default_value' => array(
'desktop' => ElementsLoader::get_default_icon_size(),
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'dimension',
'name' => '--element-account-icon-size',
'value_path' => array( 'icon', 'size' ),
),
),
),
),
'label_reset' => array(
'type' => 'Reset',
'title' => array(
'text' => __( 'Label', 'brandy' ),
'type' => 'bold',
'show_devices' => true,
),
'reset_paths' => array(
array( 'label' ),
),
),
'label_typography' => array(
'title' => array(
'text' => __( 'Typography', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'label', 'typography' ),
'type' => 'Typography',
'default_value' => TypographyService::get_default_typography_value(),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'typography',
'name' => '--element-account-label-typography',
'value_path' => array( 'label', 'typography' ),
),
),
),
),
'label_color' => array(
'title' => array(
'text' => __( 'Color', 'brandy' ),
'type' => 'normal',
),
'value_path' => array( 'label', 'color' ),
'type' => 'ColorGroup',
'default_value' => array(
'normal' => array(
'desktop' => 'var(--wp--preset--color--brandy-primary-text)',
'tablet' => null,
'mobile' => null,
),
'hover' => array(
'desktop' => 'var(--wp--preset--color--brandy-primary-text)',
'tablet' => null,
'mobile' => null,
),
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'color',
'name' => '--element-account-label-color',
'value_path' => array( 'label', 'color' ),
),
),
),
),
'item_spacing' => array(
'title' => array(
'text' => __( 'Item spacing', 'brandy' ),
'type' => 'bold',
'show_devices' => true,
),
'value_path' => array( 'item_spacing' ),
'type' => 'Dimension',
'units' => array( 'px' ),
'default_value' => array(
'desktop' => array(
'unit' => 'px',
'min' => 0,
'max' => 50,
'value' => 10,
),
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'dimension',
'name' => '--element-account-item-spacing',
'value_path' => array( 'item_spacing' ),
),
),
),
),
'padding' => array(
'title' => array(
'text' => __( 'Padding', 'brandy' ),
'type' => 'bold',
'show_devices' => true,
),
'value_path' => array( 'padding' ),
'type' => 'Spacing',
'units' => array( 'px', '%' ),
'default_value' => array(
'desktop' => array(
'unit' => 'px',
'top' => 0,
'right' => 0,
'bottom' => 0,
'left' => 0,
'is_constraints' => false,
),
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'spacing',
'name' => '--element-account-padding',
'value_path' => array( 'padding' ),
),
),
),
),
'margin' => array(
'title' => array(
'text' => __( 'Margin', 'brandy' ),
'type' => 'bold',
'show_devices' => true,
),
'value_path' => array( 'margin' ),
'type' => 'Spacing',
'units' => array( 'px', '%' ),
'default_value' => array(
'desktop' => array(
'unit' => 'px',
'top' => 0,
'right' => 0,
'bottom' => 0,
'left' => 0,
'is_constraints' => false,
),
'tablet' => null,
'mobile' => null,
),
'render_options' => array(
'type' => 'variable',
'data' => array(
array(
'type' => 'spacing',
'name' => '--element-account-margin',
'value_path' => array( 'margin' ),
),
),
),
),
);
}
/**
* Register settings layout
*/
protected function register_layout() {
return array(
'general' => array(
'sections' => array(
array(
'components' => array( 'logged_in_title' ),
),
array(
'components' => array(
'logged_in_profile_type',
'logged_in_icon_type',
'logged_in_icon_style',
),
),
array(
'components' => array(
'logged_in_click_action',
'logged_in_custom_link',
),
),
array(
'components' => array(
'logged_in_label_enabled',
'logged_in_label_type',
'logged_in_label_text',
'logged_in_label_position',
),
),
array(
'components' => array(
'logged_in_target',
),
),
array(
'components' => array( 'logged_out_title' ),
),
array(
'components' => array(
'logged_out_click_action',
'logged_out_custom_link',
),
),
array(
'components' => array( 'logged_out_target' ),
),
array(
'components' => array(
'logged_out_profile_type',
'logged_out_icon_type',
'logged_out_icon_style',
'logged_out_label_enabled',
'logged_out_label_text',
),
),
),
),
'designs' => array(
'sections' => array(
array(
'visible_conditions' => array(
'relation' => 'OR',
array(
'value_path' => array( self::LOGGED_IN_STATE, 'profile_type' ),
'operator' => 'NOT',
'value' => 'text',
),
array(
'value_path' => array( self::LOGGED_OUT_STATE, 'profile_type' ),
'operator' => 'NOT',
'value' => 'text',
),
),
'components' => array(
'icon_reset',
'icon_color',
'icon_background',
'icon_border_color',
'icon_border_width',
'icon_border_radius',
'icon_size',
),
),
array(
'components' => array(
'label_reset',
'label_typography',
'label_color',
),
),
array(
'components' => array(
'item_spacing',
),
),
array(
'components' => array(
'padding',
),
),
array(
'components' => array(
'margin',
),
),
),
),
);
}
/**
* Add element localize data to the general
*
* @param array $localize_data General data
*
* @return array Data after adding
*/
public function add_localize_data( $localize_data ) {
$icons = array();
$icon_styles = array( 'bold', 'outline' );
foreach ( $icon_styles as $style ) {
$dir = new \DirectoryIterator( self::$path_to_icons . $style );
$icon_files = array();
foreach ( $dir as $fileinfo ) {
if ( ! $fileinfo->isDot() ) {
$icon_files[] = $fileinfo->getFilename();
}
}
usort(
$icon_files,
function( $a, $b ) {
return strcmp( $a, $b );
}
);
$icons[ $style ] = array();
foreach ( $icon_files as $file_name ) {
$icon_path = self::$path_to_icons . "$style/$file_name";
ob_start();
require $icon_path;
$icon_data = ob_get_contents();
ob_end_clean();
$icon_name = basename( $file_name, '.php' );
$icons[ $style ][ $icon_name ] = $icon_data;
}
$localize_data['icons']['account'] = $icons;
}
return $localize_data;
}
/**
* Get account icon based on icon type and style
*
* @param string $icon_type
* @param string $icon style
*
* @return string
*/
public static function get_icon( $icon_type, $icon_style ) {
$icon_path = self::$path_to_icons . "$icon_style/$icon_type.php";
if ( file_exists( $icon_path ) ) {
ob_start();
require $icon_path;
$icon_data = ob_get_contents();
ob_end_clean();
return $icon_data;
}
return '';
}
/**
* Get account link
*
* @param string $action_type
* @param string $custom_link Link returns when action type is custom
*
* @return string
*/
public static function get_link_base_on_action( $action_type = 'profile', $custom_link = '' ) {
// TODO: turn this to global function
switch ( $action_type ) {
case 'profile':
return is_wc_installed() ? wc_get_account_endpoint_url( 'dashboard' ) : get_edit_user_link( get_current_user_id() );
case 'woocommerce':
return home_url( 'woocommerce' );
case 'logout':
return brandy_get_logout_url();
case 'menu':
return home_url( 'menu' );
case 'login':
return brandy_get_login_url();
case 'custom':
return $custom_link;
default:
return '';
}
}
/**
* Get account icon based on state
*
* @param array $settings Account settings
*
* @return string
*/
public static function get_account_icon( $settings ) {
$icon = '';
$state = self::get_state();
$profile_type = isset( $settings[ $state ]['profile_type'] ) ? $settings[ $state ]['profile_type'] : 'avatar';
if ( is_user_logged_in() ) {
$current_user_id = get_current_user_id();
if ( 'avatar' === $profile_type ) {
$icon = get_avatar( $current_user_id );
}
}
if ( 'icon' === $profile_type ) {
$icon_type = isset( $settings[ $state ]['icon']['type'] ) ? $settings[ $state ]['icon']['type'] : 'icon_1';
$icon_style = isset( $settings[ $state ]['icon']['style'] ) ? $settings[ $state ]['icon']['style'] : 'outline';
$icon = self::get_icon( $icon_type, $icon_style );
}
return $icon;
}
/**
* Get account link based on state
*
* @return string
*/
public static function get_account_link( $settings ) {
$state = self::get_state();
if ( ! isset( $settings[ $state ]['click_action'] ) ) {
return '';
}
$action_type = $settings[ $state ]['click_action'];
$custom_link = isset( $settings[ $state ]['custom_link'] ) ? $settings[ $state ]['custom_link'] : '';
$link = self::get_link_base_on_action( $action_type, $custom_link );
return $link;
}
/**
* Get account label based on state
*
* @return string
*/
public static function get_account_label( $settings ) {
$state = self::get_state();
$label_settings = $settings[ $state ]['label'];
if ( is_user_logged_in() ) {
$label = array();
foreach ( brandy_get_devices() as $device ) {
$label_type = Helpers::get_device_value( $label_settings['type'], $device );
if ( 'name' === $label_type ) {
$label[ $device ] = self::get_account_display_name();
} else {
$label[ $device ] = $label_settings['text'][ $device ];
}
}
} else {
$label = $label_settings['text'];
}
return $label;
}
/**
* Get user display name
*
* @return string
*/
private static function get_account_display_name() {
$user_info = wp_get_current_user();
$name_list = array(
! empty( $user_info->first_name ) ? $user_info->first_name : '',
! empty( $user_info->last_name ) ? $user_info->last_name : '',
);
$name = implode( ' ', $name_list );
if ( empty( trim( $name ) ) ) {
$name = $user_info->display_name;
}
return $name;
}
/**
* Returns current logged state
*
* @return string
*/
public static function get_state() {
return is_user_logged_in() ? self::LOGGED_IN_STATE : self::LOGGED_OUT_STATE;
}
}