arraypress / wp-mdash
Minimal WordPress polyfill for handling empty values with mdash
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/arraypress/wp-mdash
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2026-01-31 15:35:21 UTC
README
Minimal WordPress polyfill for handling empty values with em dashes.
Installation
composer require arraypress/wp-mdash
Functions
mdash( $value ): string
Return an em dash if value is empty, otherwise return the value.
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.
mdash_esc( '' ); // '—' mdash_esc( 'Hello' ); // 'Hello' mdash_esc( '<script>alert()</script>' ); // '<script>alert()</script>'
Usage
Admin Tables
<table class="wp-list-table">
<tr>
<td><?php echo mdash_esc( $user->display_name ); ?></td>
<td><?php echo mdash_esc( $user->last_login ); ?></td>
<td><?php echo mdash( $user->post_count ); ?></td>
</tr>
</table>
Settings Pages
<tr>
<th>API Key</th>
<td><?php echo mdash_esc( get_option( 'api_key' ) ); ?></td>
</tr>
<tr>
<th>Last Sync</th>
<td><?php echo mdash( $last_sync_date ); ?></td>
</tr>
Reports
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