Skip to content

Instantly share code, notes, and snippets.

@ibndawood
Last active April 27, 2020 23:16
Show Gist options
  • Select an option

  • Save ibndawood/2d60435d5c68f7de45e4449582a12c79 to your computer and use it in GitHub Desktop.

Select an option

Save ibndawood/2d60435d5c68f7de45e4449582a12c79 to your computer and use it in GitHub Desktop.
Front - is_account_page bug fix
function front_header_user_account() {
if ( ! is_user_logged_in() && ( function_exists( 'is_account_page' ) && is_account_page() ) ) {
return;
}
$woocommerce = function_exists( 'front_is_woocommerce_activated' ) && front_is_woocommerce_activated();
$job_manager = function_exists( 'front_is_wp_job_manager_activated' ) && front_is_wp_job_manager_activated();
$job_resume_manager = function_exists( 'front_is_wp_resume_manager_activated' ) && front_is_wp_resume_manager_activated();
$job_company_manager = function_exists( 'front_is_mas_wp_company_manager_activated' ) && front_is_mas_wp_company_manager_activated();
$header_user_account_enable = apply_filters( 'front_header_header_user_account_enable', true );
$user = wp_get_current_user();
if ( ( $woocommerce || $job_manager || $job_resume_manager || $job_company_manager ) && $header_user_account_enable == true ) {
$header_account_view = apply_filters( 'front_header_topbar_user_account_view', 'dropdown' );
$enable_user_name = apply_filters( 'front_header_topbar_user_account_enable_user_name', true );
if ( $woocommerce && get_option('woocommerce_myaccount_page_id') ) {
$modal_link = get_permalink( get_option('woocommerce_myaccount_page_id') );
}
else if ( $job_manager && get_option( 'job_manager_job_dashboard_page_id' ) && ( in_array( 'employer', (array) $user->roles ) || in_array( 'administrator', (array) $user->roles ) ) ) {
$modal_link = get_permalink( get_option( 'job_manager_job_dashboard_page_id' ) );
}
else if ( $job_resume_manager && get_option( 'resume_manager_candidate_dashboard_page_id' ) && ! ( in_array( 'employer', (array) $user->roles ) ) ) {
$modal_link = get_permalink( get_option( 'resume_manager_candidate_dashboard_page_id' ) );
}
else {
$modal_link = '#';
}
if ( $header_account_view == 'sidebar-right' || $header_account_view == 'sidebar-left' ) {
$user_account_link = 'javascript:;';
} else if ( $header_account_view == 'modal' ) {
$user_account_link = is_user_logged_in() ? $modal_link : '#loginModal';
} else if ( $woocommerce && is_user_logged_in() ) {
$user_account_link = get_permalink( get_option('woocommerce_myaccount_page_id') );
} else {
$user_account_link = '#';
}
if ( $header_account_view == 'dropdown' ) {
$header_account_id = 'account-dropdown-invoker';
}
else if ( $header_account_view == 'sidebar-right' || $header_account_view == 'sidebar-left' ) {
$header_account_id = 'sidebarMyAccountNavToggler';
}
else {
$header_account_id = NULL;
}
$atts = apply_filters( 'front_user_account_link_atts', array(
'id' => $header_account_id,
'class' => 'btn btn-xs btn-text-secondary ' . ( is_user_logged_in() ? 'u-sidebar--account__toggle-bg' : 'btn-icon' ) . ( ( $header_account_view == 'sidebar-right' || $header_account_view == 'sidebar-left' ) ? ' ml-1' : '' ) . ( $enable_user_name == false ? ' pl-1' : '' ),
'href' => $user_account_link,
'role' => 'button',
) );
if ( $header_account_view == 'dropdown' || $header_account_view == 'sidebar-right' || $header_account_view == 'sidebar-left' ) {
if ( $header_account_view == 'sidebar-left' ) {
$animation_in = 'fadeInLeft';
$animation_out = 'fadeOutLeft';
}
else if ( $header_account_view == 'sidebar-right' ) {
$animation_in = 'fadeInRight';
$animation_out = 'fadeOutRight';
}
else {
$animation_in = 'slideInUp';
$animation_out = 'fadeOut';
}
$atts['aria-controls'] = $header_account_view == 'dropdown' ? 'account-dropdown' : 'sidebarMyAccountContent';
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
$atts['data-unfold-event'] = ( $header_account_view == 'dropdown' && is_user_logged_in() ) ? 'hover' : 'click';
$atts['data-unfold-target'] = $header_account_view == 'dropdown' ? '#account-dropdown' : '#sidebarMyAccountContent';
$atts['data-unfold-type'] = 'css-animation';
$atts['data-unfold-duration'] = $header_account_view == 'dropdown' ? '300' : '500';
$atts['data-unfold-delay'] = $header_account_view == 'dropdown' ? '300' : NULL;
$atts['data-unfold-hide-on-scroll'] = $header_account_view == 'dropdown' ? 'true' : 'false';
$atts['data-unfold-animation-in'] = $animation_in;
$atts['data-unfold-animation-out'] = $animation_out;
}
if ( $header_account_view == 'modal' ) {
$atts['data-modal-target'] = '#loginModal';
$atts['data-overlay-color'] = '#111722';
}
?>
<li class="list-inline-item position-relative">
<?php
global $current_user; ?>
<a <?php printf( front_get_attributes( $atts ) ); ?>>
<?php if ( is_user_logged_in() && ( $header_account_view == 'dropdown' || $header_account_view == 'modal' || $header_account_view == 'sidebar-right' || $header_account_view == 'sidebar-left' ) ) : ?>
<?php if ( $header_account_view == 'sidebar-right' || $header_account_view == 'sidebar-left' ): ?>
<span class="position-relative">
<?php endif ?>
<?php if ( $enable_user_name == true ): ?>
<span class="u-sidebar--account__toggle-text"><?php echo apply_filters( 'front_user_account_login_text', get_the_author_meta( 'display_name', $current_user->ID ) ); ?></span>
<?php endif ?>
<img class="u-sidebar--account__toggle-img" src="<?php echo get_avatar_url( $current_user->ID ); ?>" alt="<?php echo esc_attr__( 'User', 'front' ); ?>">
<?php else: ?>
<span class="<?php echo esc_attr( apply_filters( 'front_user_account_menu_item_icon', 'fas fa-user-circle ' ) ); ?> btn-icon__inner font-size-1">
</span>
<?php if ( $header_account_view == 'sidebar-right' || $header_account_view == 'sidebar-left' ): ?>
</span>
<?php endif ?>
<?php endif ?>
</a>
<?php
if ( $header_account_view == 'dropdown' ) {
front_header_user_account_submenu();
}
?>
</li>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment