Skip to content

Commit

Permalink
Added dashboard menu item and created function to get menu item classes
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Jan 20, 2016
1 parent 0c27f9b commit 57c7b3c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 45 additions & 0 deletions includes/wc-account-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function wc_edit_address_i18n( $id, $flip = false ) {
*/
function wc_get_account_menu_items() {
return apply_filters( 'woocommerce_account_menu_items', array(
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'edit-address' => __( 'Addresses', 'woocommerce' ),
Expand All @@ -85,6 +86,50 @@ function wc_get_account_menu_items() {
) );
}

/**
* Get account menu item classes.
*
* @since 2.6.0
* @param string $endpoint
* @return string
*/
function wc_get_account_menu_item_classes( $endpoint ) {
global $wp;

$classes = array(
'my-account-menu-item-' . $endpoint,
);

// Set current item class.
$current = isset( $wp->query_vars[ $endpoint ] );
if ( 'dashboard' === $endpoint && ( isset( $wp->query_vars['page'] ) || empty( $wp->query_vars ) ) ) {
$current = true; // Dashboard is not an endpoint, so needs a custom check.
}

if ( $current ) {
$classes[] = 'current-item';
}

$classes = apply_filters( 'woocommerce_account_menu_item_classes', $classes, $endpoint );

return implode( ' ', array_map( 'sanitize_html_class', $classes ) );
}

/**
* Get account endpoint URL.
*
* @since 2.6.0
* @param string $endpoint
* @return string
*/
function wc_get_account_endpoint_url( $endpoint ) {
if ( 'dashboard' === $endpoint ) {
return wc_get_page_permalink( 'myaccount' );
}

return wc_get_endpoint_url( $endpoint );
}

/**
* Get My Account > Orders columns.
*
Expand Down
4 changes: 3 additions & 1 deletion templates/myaccount/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<nav class="my-account-navigation">
<ul>
<?php foreach ( wc_get_account_menu_items() as $endpoint => $label ) : ?>
<li class="my-account-menu-item-<?php echo sanitize_html_class( $endpoint ); ?>"><a href="<?php echo esc_url( wc_get_endpoint_url( $endpoint ) ); ?>"><?php echo esc_html( $label ); ?></a></li>
<li class="<?php echo wc_get_account_menu_item_classes( $endpoint ); ?>">
<a href="<?php echo esc_url( wc_get_account_endpoint_url( $endpoint ) ); ?>"><?php echo esc_html( $label ); ?></a>
</li>
<?php endforeach; ?>
</ul>
</nav>

0 comments on commit 57c7b3c

Please sign in to comment.