Added dashboard menu item and created function to get menu item classes

This commit is contained in:
Claudio Sanches 2016-01-20 14:11:07 -02:00
parent 0c27f9bf1e
commit 57c7b3c6c3
2 changed files with 48 additions and 1 deletions

View File

@ -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' ),
@ -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.
*

View File

@ -24,7 +24,9 @@ if ( ! defined( 'ABSPATH' ) ) {
<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>