承接 humanmade/hm-url-tabs 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

humanmade/hm-url-tabs

Composer 安装命令:

composer require humanmade/hm-url-tabs

包简介

Tab-based navigation with rewrite endpoints for conditional block visibility

README 文档

README

A WordPress plugin that allows editors to use the core navigation block to create tab-based navigation with rewrite endpoints for conditional block visibility.

Features

  • Tab Navigation Variations: Extends the core navigation-link block with three variations:

    • Home Tab: Links to the current page without any endpoint
    • Base Tab: Links to just the endpoint without a value (e.g., /tab/)
    • Tab: Links with a rewrite endpoint and value (e.g., /tab/settings/)
  • Rewrite Endpoints: Registers filterable rewrite endpoints (default: tab) with EP_ALL mask

  • URL Rewriting: Automatically rewrites navigation link URLs to use the current page with the appropriate endpoint

  • Dynamic Tab Visibility Controls: Adds a "Tab Visibility" panel to all blocks (except navigation-link) that automatically appears when the page contains tab navigation (no refresh needed), with options to:

    • Always show the block
    • Show only when no endpoint is active
    • Show only when the endpoint is in use but has no value (e.g., /tab)
    • Show only for a specific tab value (e.g., /tab/settings)
  • Active State: Automatically adds hm-url-tab-active class to the current tab link

Installation

  1. Clone this repository into your wp-content/plugins directory
  2. Run npm install to install dependencies
  3. Run npm run build to build the assets
  4. Activate the plugin through the WordPress admin

Usage

Creating Tab Navigation

  1. Add a Navigation block to your page
  2. Insert a navigation link and select one of the tab variations:
    • Home Tab: Links to the page without any endpoint
    • Base Tab: Links to just the endpoint (e.g., /tab/) - useful for "All" or default views
    • Tab: Links to a specific tab value (e.g., /tab/settings/)
  3. For regular tabs:
    • Set the label (e.g., "Settings")
    • Enter the tab slug in the URL field (e.g., "settings")
  4. The final URL will be automatically built from the current page URL with the endpoint and slug on the frontend

Controlling Block Visibility

When your page contains tab navigation links:

  1. Select any block on the page (except navigation links)
  2. Open the "Tab Visibility" panel in the block sidebar
  3. Choose the display condition:
    • Always show: Block is always visible
    • Show when no endpoint is active: Block is only visible on the base page (Home Tab)
    • Show when endpoint has no value: Block is visible when accessing /tab/ (Base Tab)
    • Show for specific tab: Block is only visible for the selected tab value

Example

Create a settings page with tabbed sections:

Page URL: /settings

Navigation:
- Home Tab → /settings
- All Settings Tab (Base Tab) → /settings/tab/
- General Tab → /settings/tab/general/
- Privacy Tab → /settings/tab/privacy/

Blocks:
- Welcome message (Visibility: Show when no endpoint is active)
- All settings list (Visibility: Show when endpoint has no value)
- General settings (Visibility: Show for specific tab → general)
- Privacy settings (Visibility: Show for specific tab → privacy)

Customization

Adding Custom Endpoints

You can register additional endpoints using the hm_url_tabs_endpoints filter:

add_filter( 'hm_url_tabs_endpoints', function( $endpoints ) {
	$endpoints[] = [
		'name' => 'section',
		'mask' => EP_ALL,
	];
	return $endpoints;
} );

When multiple endpoints are registered, a selector will appear in the navigation link settings to choose which endpoint to use.

Development

Build Scripts

  • npm start: Start development build with watch mode
  • npm run build: Build production assets
  • npm run format: Format code
  • npm run lint:js: Lint JavaScript
  • npm run lint:js:fix: Lint and fix JavaScript
  • npm run lint:css: Lint CSS
  • npm run lint:css:fix: Lint and fix CSS

Local Development

Use WordPress Playground for local development:

npm run playground:start

This will start a WordPress instance at http://localhost:9400 with the plugin activated.

Testing

Run Playwright tests:

npm run test:e2e           # Run tests
npm run test:e2e:debug     # Run tests in debug mode
npm run test:e2e:watch     # Run tests in watch mode

Filters

hm_url_tabs_endpoints

Filters the registered tab endpoints.

Parameters:

  • $endpoints (array): Array of endpoints with 'name' and 'mask' keys.

Example:

add_filter( 'hm_url_tabs_endpoints', function( $endpoints ) {
	$endpoints[] = [
		'name' => 'custom',
		'mask' => EP_PAGES,
	];
	return $endpoints;
} );

Technical Details

Block Attributes

Navigation Link (core/navigation-link):

  • kind (string): Set to "tab-home" for home tab, "tab-base" for base tab, or "tab" for regular tab
  • tabEndpoint (string): The endpoint name to use (default: "tab")
  • url (string): The URL slug for the tab (uses the standard navigation-link URL field, empty for Base Tab)

All Other Blocks:

  • hmUrlTabVisibility (object):
    • condition (string): "always", "no-endpoint", "endpoint-empty", or "specific-tab"
    • endpoint (string): The endpoint name
    • tabUrl (string): The tab URL slug to match (for "specific-tab" condition)

URL Structure

  • Base page: /settings
  • Home tab: /settings
  • Base tab (endpoint without value): /settings/tab/
  • Tab with value: /settings/tab/general/

Note: Tab URL slugs are automatically lowercased for consistency (e.g., "Settings" becomes /tab/settings/). All generated URLs include a trailing slash.

License

GPL-2.0-or-later

Author

Human Made Limited - https://humanmade.com

humanmade/hm-url-tabs 适用场景与选型建议

humanmade/hm-url-tabs 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 3.96k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 humanmade/hm-url-tabs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 humanmade/hm-url-tabs 我们能提供哪些服务?
定制开发 / 二次开发

基于 humanmade/hm-url-tabs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2025-11-26