Skip to content

Commit

Permalink
Notification count added on vendor dashboard menu render (#2195)
Browse files Browse the repository at this point in the history
* fix: notification count added on vendor dashboard menu render

* fix: Translation added, docblock updated

* fix: Logical issue fixed

* refactor: Notification count segregated
  • Loading branch information
aihimel authored Apr 4, 2024
1 parent d255885 commit 4ba9597
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
40 changes: 39 additions & 1 deletion includes/Dashboard/Templates/Main.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

namespace WeDevs\Dokan\Dashboard\Templates;

defined( 'ABSPATH' ) || exit;

class Main {

public function __construct() {
add_action( 'dokan_dashboard_content_before', [ self::class, 'dashboard_side_navigation' ] );
add_filter( 'dokan_vendor_dashboard_menu_title', [ $this, 'add_notification_count' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -39,4 +41,40 @@ public static function dashboard_side_navigation() {

dokan_get_template_part( 'global/dashboard-nav', '', [ 'active_menu' => apply_filters( 'dokan_dashboard_nav_active', $active_menu, $request, $active ) ] );
}

/**
* Adds notification count to menu and submenu of vendor dashboard
*
* @since DOKAN_SINCE
*
* @param string $menu_title Menu title
* @param array $menu_details Menu details array
*
* @return string
*/
public function add_notification_count( string $menu_title, array $menu_details ): string {
if ( ! empty( $menu_details['counts'] ) ) {
$notification_counts = (int) $menu_details['counts'];
/**
* Notification count filter
*
* @since DOKAN_SINCE
*
* @param int $notification_counts Number of notifications for menu & submenu
* @param array $menu_details Details for menu and submenu
*/
$notification_counts = apply_filters(
'dokan_vendor_dashboard_menu_notification_count',
$notification_counts, $menu_details
);
$menu_title = sprintf(
// translators: 1) Title 2) Notification Count
__( '%1$s (%2$s)', 'dokan-lite' ),
$menu_title,
number_format_i18n( $notification_counts )
);
}

return $menu_title;
}
}
11 changes: 7 additions & 4 deletions includes/functions-dashboard-navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ function dokan_dashboard_nav( $active_menu = '' ) {

$class = $active_menu === $filtered_key || 0 === stripos( $active_menu, $filtered_key ) ? 'active ' . $key : $key; // checking starts with the key
$title = __( 'No Title', 'dokan-lite' );

if ( ! empty( $item['menu_manager_title'] ) ) {
$title = $item['menu_manager_title'];
} elseif ( ! empty( $item['title'] ) ) {
$title = $item['title'];
}

$menu_slug = $filtered_key;
$submenu = '';

Expand All @@ -240,27 +242,28 @@ function dokan_dashboard_nav( $active_menu = '' ) {
/**
* Filters a menu key according to slug if needed.
*
* @since DOKAN_PRO_SINCE
* @since DOKAN_SINCE
*
* @param string $submenu_key
* @param string $menu_key
*/
$filtered_subkey = apply_filters( 'dokan_dashboard_nav_submenu_key', $sub_key, $key );

$submenu_class = $active_submenu === $filtered_subkey || 0 === stripos( $active_submenu, $filtered_subkey ) ? "current $sub_key" : $sub_key;

$submenu_title = __( 'No Title', 'dokan-lite' );

if ( ! empty( $sub['menu_manager_title'] ) ) {
$submenu_title = $sub['menu_manager_title'];
} elseif ( ! empty( $sub['title'] ) ) {
$submenu_title = $sub['title'];
}

$submenu .= sprintf(
'<li class="submenu-item %s"><a href="%s" class="submenu-link">%s %s</a></li>',
$submenu_class,
isset( $sub['url'] ) ? $sub['url'] : dokan_get_navigation_url( "{$key}/{$sub_key}" ),
isset( $sub['icon'] ) ? $sub['icon'] : '<i class="fab fa-staylinked"></i>',
$submenu_title
apply_filters( 'dokan_vendor_dashboard_menu_title', $submenu_title, $sub )
);

$subkey_slugs[] = $filtered_subkey;
Expand All @@ -279,7 +282,7 @@ function dokan_dashboard_nav( $active_menu = '' ) {
$class,
isset( $item['url'] ) ? $item['url'] : dokan_get_navigation_url( $menu_slug ),
isset( $item['icon'] ) ? $item['icon'] : '<i class="fab fa-staylinked"></i>',
$title,
apply_filters( 'dokan_vendor_dashboard_menu_title', $title, $item ),
$submenu
);
}
Expand Down

0 comments on commit 4ba9597

Please sign in to comment.