定制 arraypress/wp-mdash 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

arraypress/wp-mdash

Composer 安装命令:

composer require arraypress/wp-mdash

包简介

A collection of WordPress functions for handling empty values consistently using mdash and other semantic formatting patterns

README 文档

README

A minimal WordPress polyfill providing mdash functions for consistent empty value handling.

Description

This package provides two simple utility functions for WordPress development that handle empty values using the HTML em dash entity (—). Since WordPress doesn't include built-in mdash functions, this fills that gap with a minimal, focused implementation.

Installation

Install via Composer:

composer require arraypress/wp-mdash

Usage

Basic Functions

Return em dash for empty values
echo mdash( $value );        Returns '—' if empty, otherwise the value
echo mdash( '' );            Returns '—'
echo mdash( null );          Returns '—'
echo mdash( false );         Returns '—'
echo mdash( 0 );             Returns '—'
echo mdash( 'Hello' );       Returns 'Hello'

Direct output
mdash_e( $value );           Echoes '—' if empty, otherwise echoes the value

Common Use Cases

In admin tables
echo '<td>' . mdash( $user->last_login ) . '</td>';

In reports
echo 'Total Sales: ' . mdash( $sales_count );

In user profiles  
echo 'Bio: ' . mdash( $user_bio );

Direct output in templates
<div class="price"><?php mdash_e( $product->sale_price ); ?></div>

Why This Exists

WordPress has many display functions but lacks a simple way to handle empty values with em dashes—a common pattern in professional interfaces. This polyfill provides that missing functionality with just two functions, following WordPress coding standards and conventions.

Requirements

  • PHP 7.4 or higher
  • WordPress 5.0 or higher

License

GPL-2.0-or-later

Support

For support, please use the GitHub issue tracker

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

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