PHPackages                             arraypress/wp-format-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/wp-format-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/wp-format-utils
==========================

Display formatting utilities for WordPress with internationalization support

014PHP

Since Jan 31Pushed 3mo agoCompare

[ Source](https://github.com/arraypress/wp-format-utils)[ Packagist](https://packagist.org/packages/arraypress/wp-format-utils)[ RSS](/packages/arraypress-wp-format-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Format Utilities
==========================

[](#wordpress-format-utilities)

Display formatting utilities for WordPress with full internationalization support. Provides clean, consistent formatting for numbers, dates, text, and data presentation across WordPress themes and plugins.

Features
--------

[](#features)

- 🌍 **Internationalization Ready**: Full i18n support using WordPress translation functions
- 📊 **Number Formatting**: Percentages and numeric values with WordPress standards
- 📅 **Date/Time Formatting**: WordPress-compatible date formatting with timezone support
- 📝 **Text Formatting**: HTML processing, truncation, and label generation
- ✅ **Boolean Formatting**: Translatable yes/no, on/off, true/false strings
- 📋 **List Formatting**: Smart lists with overflow handling and natural language conjunctions
- 🛡️ **WordPress-Native**: Leverages WordPress core functions for consistency

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- WordPress 5.0 or later

Installation
------------

[](#installation)

```
composer require arraypress/wp-format-utils
```

Basic Usage
-----------

[](#basic-usage)

### Boolean Formatting

[](#boolean-formatting)

```
use ArrayPress\FormatUtils\Format;

// Translatable boolean strings
Format::yes_no( true );              // 'yes' (translatable)
Format::yes_no( true, true );        // 'Yes' (translatable, title case)
Format::on_off( false );             // 'off' (translatable)
Format::true_false( true );          // 'true' (translatable)

// Perfect for admin interfaces and form display
$enabled = get_option( 'feature_enabled' );
echo Format::yes_no( $enabled, true ); // Shows 'Yes' or 'No' in user's language
```

### Number Formatting

[](#number-formatting)

```
// WordPress i18n number formatting (returns em dash for non-numeric)
Format::numeric( 1234.56 );         // '1,234.56' (respects locale)
Format::numeric( 1234.56, 0 );      // '1,235' (no decimals)
Format::numeric( 'invalid' );       // '—' (em dash)

// Percentage formatting
Format::percentage( 0.75 );         // '75%'
Format::percentage( 0.756, 1 );     // '75.6%'
```

### Date and Time Formatting

[](#date-and-time-formatting)

```
// WordPress i18n date formatting (accepts timestamp, string, or DateTime)
Format::date( '2024-01-15' );                    // 'January 15, 2024' (translated)
Format::date( '2024-01-15', 'Y-m-d' );          // '2024-01-15'
Format::date( time(), 'F j, Y', false );        // English only

// Duration formatting
Format::duration( 90 );                         // '1 minutes'
Format::duration( 3661 );                       // '1 hours 1 minutes'
Format::duration( 3661, true );                 // '1h 1m' (abbreviated)
Format::duration( 90061 );                      // '1 days 1 hours'

// Relative time
Format::time_ago( strtotime( '-2 hours' ) );    // '2 hours ago'
```

### Text Formatting

[](#text-formatting)

```
// WordPress text processing
Format::html( "Hello\n\nWorld" );               // 'HelloWorld'

// Key to label conversion
Format::label( 'first_name' );                  // 'First Name'
Format::label( 'user-profile-id' );             // 'User Profile Id'

// Multibyte-safe truncation
Format::excerpt( $long_text, 100 );             // 'First 97 chars...'
Format::excerpt( $text, 50, '…' );              // 'First 49 chars…'

// Email link generation
Format::email_link( 'user@example.com' );
// 'user@example.com'

Format::email_link( 'user@example.com', 'Contact Us' );
// 'Contact Us'

// Rating with proper pluralization
Format::rating( 1 );                            // '1 Star'
Format::rating( 4 );                            // '4 Stars'
Format::rating( 0 );                            // 'No Rating'
```

### Utility Methods

[](#utility-methods)

```
// Em dash fallback for empty values
Format::maybe_dash( 'value' );                  // 'value'
Format::maybe_dash( '' );                       // '—'
Format::maybe_dash( null );                     // '—'

// Natural language lists
Format::list( ['Apple'] );                      // 'Apple'
Format::list( ['Apple', 'Banana'] );            // 'Apple and Banana'
Format::list( ['A', 'B', 'C'] );               // 'A, B and C'
Format::list( ['A', 'B', 'C'], ', ', ' or ' ); // 'A, B or C'

// Lists with overflow handling
$items = ['Theme A', 'Plugin B', 'Template C', 'Widget D', 'Block E'];

Format::list_with_overflow( $items, 3 );        // 'Theme A, Plugin B and 3 more'
Format::list_with_overflow( $items, 2 );        // 'Theme A and 4 more'

// Custom overflow text
Format::list_with_overflow(
    $items,
    3,
    ' | ',           // separator
    ' & ',           // last separator
    '%d others'      // overflow text
); // 'Theme A | Plugin B & 3 others'
```

API Reference
-------------

[](#api-reference)

### Boolean Formatting Methods

[](#boolean-formatting-methods)

MethodDescriptionReturns`yes_no($value, $title_case = false)`Convert to translatable yes/no`string``on_off($value, $title_case = false)`Convert to translatable on/off`string``true_false($value, $title_case = false)`Convert to translatable true/false`string`### Number Formatting Methods

[](#number-formatting-methods)

MethodDescriptionReturns`numeric($value, $decimals = 0)`WordPress i18n number formatting with em dash fallback`string``percentage($value, $decimals = 0)`Format as percentage`string`### Date/Time Formatting Methods

[](#datetime-formatting-methods)

MethodDescriptionReturns`date($date, $format = 'F j, Y', $translate = true)`WordPress i18n date formatting`string``duration($seconds, $abbreviated = false)`Human readable duration`string``time_ago($date)`Relative time formatting`string`### Text Formatting Methods

[](#text-formatting-methods)

MethodDescriptionReturns`html($text)`WordPress text processing (wpautop + wptexturize)`string``label($key)`Convert key to human-readable label`string``excerpt($text, $length = 150, $suffix = '...')`Multibyte-safe text truncation`string``email_link($email, $text = '')`Generate mailto link`string``rating($rating)`Translatable star rating with pluralization`string`### Utility Methods

[](#utility-methods-1)

MethodDescriptionReturns`maybe_dash($value)`Return value or em dash if empty`string``list($items, $separator = ', ', $last_sep = ' and ')`Natural language list formatting`string``list_with_overflow($items, $limit = 3, ...)`List with overflow handling`string`### Constants

[](#constants)

ConstantValueDescription`Format::MDASH``'&mdash;'`HTML em dash entityCommon Use Cases
----------------

[](#common-use-cases)

### Admin Table Display

[](#admin-table-display)

```
// Settings page display
function display_settings_table( $options ) {
    foreach ( $options as $key => $value ) {
        echo '';
        echo '' . esc_html( Format::label( $key ) ) . '';

        if ( is_bool( $value ) ) {
            echo '' . esc_html( Format::yes_no( $value, true ) ) . '';
        } elseif ( is_numeric( $value ) ) {
            echo '' . esc_html( Format::numeric( $value ) ) . '';
        } else {
            echo '' . esc_html( Format::maybe_dash( $value ) ) . '';
        }

        echo '';
    }
}
```

### Content Lists

[](#content-lists)

```
// Category display with overflow
$categories = wp_get_post_categories( $post_id, ['fields' => 'names'] );
echo 'Categories: ' . esc_html( Format::list_with_overflow( $categories, 3 ) );
// Output: "Categories: WordPress, PHP and 2 more"

// Tag cloud with natural language
$tags = get_the_tags( $post_id );
$tag_names = wp_list_pluck( $tags, 'name' );
echo 'Tagged: ' . esc_html( Format::list( $tag_names ) );
// Output: "Tagged: Development, Tutorial and Advanced"
```

### Dashboard Statistics

[](#dashboard-statistics)

```
$stats = get_site_statistics();

echo 'Total Users: ' . esc_html( Format::numeric( $stats['users'] ) );
echo 'Uptime: ' . esc_html( Format::duration( $stats['uptime_seconds'] ) );
echo 'Success Rate: ' . esc_html( Format::percentage( $stats['success_rate'] ) );
echo 'Last Updated: ' . esc_html( Format::time_ago( $stats['last_update'] ) );
```

Internationalization
--------------------

[](#internationalization)

All user-facing strings are translatable using WordPress i18n functions:

- **Text Domain**: `arraypress`
- **Translation Functions**: `__()`, `_n()` for plurals
- **Translator Comments**: Included for context

### Translatable Strings

[](#translatable-strings)

- Yes/No, On/Off, True/False formatting
- "X more" overflow text
- Star rating text
- "No Rating" text
- "ago" text

Requirements
------------

[](#requirements-1)

- PHP 7.4+
- WordPress 5.0+

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the GPL-2.0-or-later License.

Support
-------

[](#support)

- [Documentation](https://github.com/arraypress/wp-format-utils)
- [Issue Tracker](https://github.com/arraypress/wp-format-utils/issues)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance54

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (2 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-format-utils/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-format-utils/health.svg)](https://phpackages.com/packages/arraypress-wp-format-utils)
```

###  Alternatives

[rakutentech/laravel-request-docs

Automatically generate Laravel docs from request rules, controllers and routes

7861.2M2](/packages/rakutentech-laravel-request-docs)[datlechin/flarum-link-preview

Automatically display a rich preview of the link contents.

1715.9k](/packages/datlechin-flarum-link-preview)[schmeits/filament-pan-analytics-widget

A widget for pan (lightweight and privacy-focused PHP product analytics library)

221.9k](/packages/schmeits-filament-pan-analytics-widget)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
