An open API service indexing awesome lists of open source software.

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

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