$item Nav row. */ public static function get_item_icon_class( array $item ): string { $type = (string) ( $item['type'] ?? '' ); $id = (string) ( $item['id'] ?? '' ); if ( 'link' === $type ) { return 'dashicons-admin-links'; } $map = array( 'dashboard' => 'dashicons-dashboard', 'favorites' => 'dashicons-heart', 'notifications' => 'dashicons-bell', 'woocommerce' => 'dashicons-cart', 'lms4wp' => 'dashicons-welcome-learn-more', 'other' => 'dashicons-admin-generic', ); $class = isset( $map[ $id ] ) ? $map[ $id ] : 'dashicons-admin-users'; return (string) apply_filters( 'forwp_account_menu_item_icon_class', $class, $item ); } /** * Render account menu widget HTML. * * @param array $args accountUrl. * @return string */ public static function render( array $args = array() ): string { $args = wp_parse_args( $args, array( 'account_url' => '', ) ); if ( ! is_user_logged_in() ) { return self::render_guest(); } self::enqueue_assets(); $user = wp_get_current_user(); $account_url = self::resolve_account_url( (string) $args['account_url'] ); $items = AccountMenu::get_nav_items( AccountMenu::CONTEXT_HEADER ); $current = AccountMenu::is_account_page() ? AccountMenu::get_current_section() : ''; $logout_url = wp_logout_url( $account_url ); $login_url = AccountMenu::get_login_url( is_singular() ? (string) get_permalink() : '' ); $i18n = array( 'myAccount' => __( 'My account', '4wp-account' ), 'logOut' => __( 'Log out', '4wp-account' ), 'signIn' => __( 'Sign in', '4wp-account' ), ); wp_localize_script( 'forwp-account-menu-widget', 'forwpAccountMenuI18n', $i18n ); ob_start(); ?>
$item Nav row. * @param string $current Active section slug. */ public static function render_item( array $item, string $current = '' ): void { $id = (string) ( $item['id'] ?? '' ); $label = (string) ( $item['label'] ?? '' ); $url = (string) ( $item['url'] ?? '#' ); $target = (string) ( $item['target'] ?? '' ); $icon = self::get_item_icon_class( $item ); $active = ( 'section' === ( $item['type'] ?? '' ) && $id !== '' && $id === $current ); $class = 'forwp-account-menu__item' . ( $active ? ' forwp-account-menu__item--active' : '' ); $attrs = ''; if ( '_blank' === $target ) { $attrs = ' target="_blank" rel="noopener noreferrer"'; } ?> >