https://github.com/arraypress/wp-mdash
A collection of WordPress functions for handling empty values consistently using mdash and other semantic formatting patterns
https://github.com/arraypress/wp-mdash
Last synced: about 2 months ago
JSON representation
A collection of WordPress functions for handling empty values consistently using mdash and other semantic formatting patterns
- Host: GitHub
- URL: https://github.com/arraypress/wp-mdash
- Owner: arraypress
- Created: 2024-12-15T22:33:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-06T17:40:54.000Z (over 1 year ago)
- Last Synced: 2025-09-07T15:44:54.705Z (7 months ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WordPress MDash Polyfill
Minimal WordPress polyfill for handling empty values with em dashes.
## Installation
```bash
composer require arraypress/wp-mdash
```
## Functions
### `mdash( $value ): string`
Return an em dash if value is empty, otherwise return the value.
```php
mdash( '' ); // '—'
mdash( null ); // '—'
mdash( false ); // '—'
mdash( 0 ); // '—'
mdash( 'Hello' ); // 'Hello'
mdash( 42 ); // '42'
```
### `mdash_esc( $value ): string`
Return an em dash if value is empty, otherwise return the escaped value.
```php
mdash_esc( '' ); // '—'
mdash_esc( 'Hello' ); // 'Hello'
mdash_esc( 'alert()' ); // '<script>alert()</script>'
```
## Usage
### Admin Tables
```php
display_name ); ?>
last_login ); ?>
post_count ); ?>
```
### Settings Pages
```php
API Key
Last Sync
```
### Reports
```php
echo 'Total Sales: ' . mdash( $sales_count );
echo 'Average Rating: ' . mdash( $avg_rating );
echo 'Customer Notes: ' . mdash_esc( $customer_notes );
```
## When to Use Each
| Function | Use When |
|---------------|-----------------------------------------------------|
| `mdash()` | Value is already safe (numbers, dates, pre-escaped) |
| `mdash_esc()` | Value contains user input or untrusted data |
## Requirements
- PHP 7.4+
- WordPress 5.0+
## License
GPL-2.0-or-later