PHPackages                             arraypress/wp-conversion-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-conversion-utils

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

arraypress/wp-conversion-utils
==============================

A comprehensive WordPress library for converting units, sizes, formats, and measurements

00PHP

Since Jul 5Pushed 10mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Conversion Utils
==========================

[](#wordpress-conversion-utils)

A comprehensive WordPress library for converting units, measurements, sizes, and formats. Provides utility functions for length, weight, volume, temperature, clothing sizes, data formats, and more.

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

[](#installation)

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

Quick Start
-----------

[](#quick-start)

```
// Global functions (recommended)
$meters   = wp_convert_units( 10, 'ft', 'm', 'length' );
$celsius  = wp_convert_temperature( 77, 'F', 'C' );
$filesize = wp_format_filesize( 1048576 ); // "1.00 MB"

// Or use classes directly
use ArrayPress\ConversionUtils\Unit;
use ArrayPress\ConversionUtils\Format;

$pounds   = Unit::weight( 50, 'kg', 'lb' );
$duration = Format::seconds_to_duration( 3661 ); // "1 hour 1 minute 1 second"
```

Features
--------

[](#features)

### Unit Conversions

[](#unit-conversions)

- **Length**: m, km, ft, in, mi, yd, cm, mm
- **Weight**: kg, g, mg, lb, oz, t
- **Volume**: l, ml, gal, qt, pt, cup, fl oz, tbsp, tsp
- **Temperature**: Celsius, Fahrenheit
- **Speed**: km/h, m/s, mph, knot
- **Data Storage**: B, KB, MB, GB, TB, PB
- **Area**: sq m, sq km, sq ft, acre, hectare
- **Time**: s, min, h, day, week, month, year
- **Energy**: J, kJ, cal, kcal, Wh, kWh, BTU
- **Pressure**: Pa, kPa, bar, psi, atm
- **Cooking**: tsp, tbsp, cup, ml, l, pint, quart, gallon

### Size Conversions

[](#size-conversions)

- **Clothing Sizes**: US, UK, EU, IT, FR, JP (men/women)
- **Shoe Sizes**: US, UK, EU (men/women)
- **Ring Sizes**: US, UK, EU, JP
- **Bra Sizes**: US, UK, EU, FR, AU
- **Hat Sizes**: US, UK, EU, CM
- **Glove Sizes**: US, EU, CM
- **Watch Band Sizes**: MM, Inches
- **Belt Sizes**: US, UK, EU, CM, Inches (men/women)
- **Sock Sizes**: US, UK, EU (men/women)

### Format Conversions

[](#format-conversions)

- **Boolean formats**: yes/no, on/off, true/false, 1/0
- **File sizes**: bytes to human-readable
- **Duration**: seconds to human-readable
- **Percentages**: decimal to percentage

Examples
--------

[](#examples)

### Unit Conversions

[](#unit-conversions-1)

```
// Length conversions
$meters = wp_convert_units( 5, 'ft', 'm', 'length' ); // 1.524
$inches = Unit::length( 100, 'cm', 'in' ); // 39.37

// Weight conversions
$pounds = wp_convert_units( 70, 'kg', 'lb', 'weight' ); // 154.32
$grams  = Unit::weight( 1, 'lb', 'g' ); // 453.59

// Temperature conversions
$fahrenheit = wp_convert_temperature( 25, 'C', 'F' ); // 77
$celsius    = Unit::temperature( 100, 'F', 'C' ); // 37.78

// Volume conversions
$liters = Unit::volume( 1, 'gal', 'l' ); // 3.79
$cups   = Unit::cooking( 250, 'ml', 'cup' ); // 1.04

// Data storage conversions
$megabytes = Unit::data_storage( 1, 'gb', 'mb' ); // 1024
$gigabytes = wp_convert_units( 2048, 'mb', 'gb', 'data' ); // 2

// Speed conversions
$kmh = Unit::speed( 60, 'mph', 'km/h' ); // 96.56
$ms  = wp_convert_units( 100, 'km/h', 'm/s', 'speed' ); // 27.78

// Area conversions
$hectares = Unit::area( 1, 'acre', 'hectare' ); // 0.405
$sqft     = wp_convert_units( 100, 'sq m', 'sq ft', 'area' ); // 1076.39

// Time conversions
$hours = Unit::time( 3600, 's', 'h' ); // 1
$days  = wp_convert_units( 168, 'h', 'day', 'time' ); // 7

// Energy conversions
$calories = Unit::energy( 1000, 'j', 'cal' ); // 239.01
$kwh      = wp_convert_units( 3600000, 'j', 'kwh', 'energy' ); // 1

// Pressure conversions
$psi = Unit::pressure( 1, 'bar', 'psi' ); // 14.5
$atm = wp_convert_units( 101325, 'pa', 'atm', 'pressure' ); // 1
```

### Size Conversions

[](#size-conversions-1)

```
// Clothing sizes
$eu_dress = Size::clothing( '8', 'us', 'eu', 'women' ); // "36"
$uk_shirt = Size::clothing( 'L', 'us', 'uk', 'men' ); // "40"

// Shoe sizes
$eu_shoe = Size::shoe( 9.5, 'us', 'eu', 'men' ); // 43
$uk_shoe = wp_convert_size( 8, 'us', 'uk', 'shoe', 'women' ); // 5.5

// Ring sizes
$uk_ring = Size::ring( '7', 'us', 'uk' ); // "N"
$eu_ring = wp_convert_size( 'M', 'uk', 'eu', 'ring' ); // "52"

// Bra sizes
$eu_bra = Size::bra( '34B', 'us', 'eu' ); // "75B"
$uk_bra = wp_convert_size( '32C', 'us', 'uk', 'bra' ); // "32C"

// Hat sizes
$eu_hat = Size::hat( '7 1/4', 'us', 'eu' ); // "58"
$cm_hat = wp_convert_size( '58', 'eu', 'cm', 'hat' ); // "58"

// Glove sizes
$eu_glove = Size::glove( 'M', 'us', 'eu' ); // "8"
$cm_glove = wp_convert_size( '19', 'cm', 'us', 'glove' ); // "M"

// Watch band sizes
$inches_band = Size::watch_band( '20', 'mm', 'inches' ); // "25/32"
$mm_band     = wp_convert_size( '7/8', 'inches', 'mm', 'watch' ); // "22"

// Belt sizes
$eu_belt    = Size::belt( '34', 'us', 'eu', 'men' ); // "85"
$women_belt = wp_convert_size( 'M', 'us', 'cm', 'belt', 'women' ); // "80"

// Sock sizes
$uk_sock = Size::sock( '9', 'us', 'uk', 'men' ); // "8.5"
$eu_sock = wp_convert_size( '7', 'us', 'eu', 'sock', 'women' ); // "37.5"
```

### Format Conversions

[](#format-conversions-1)

```
// Boolean formats
$yes_no      = Format::to_yes_no( true ); // "yes"
$binary      = Format::to_binary( false ); // "0"
$string_bool = Format::to_string_boolean( 1, true ); // "True"
$on_off      = Format::to_on_off( true, true ); // "On"

// File sizes
$size1 = wp_format_filesize( 1024 ); // "1.00 KB"
$size2 = Format::bytes_to_size( 1048576, 1 ); // "1.0 MB"
$size3 = wp_format_filesize( 1073741824 ); // "1.00 GB"

// Duration formatting
$duration1 = wp_format_duration( 3661 ); // "1 hour 1 minute 1 second"
$duration2 = Format::seconds_to_duration( 7200, true ); // "2h"
$duration3 = wp_format_duration( 90, true ); // "1m 30s"

// Percentage formatting
$percent = Format::to_percentage( 0.75, 1 ); // "75.0%"
$decimal = Format::to_percentage( 0.3333, 2, false ); // "33.33"

// Date formatting
$formatted = Format::to_date( '2024-01-15', 'M j, Y' ); // "Jan 15, 2024"
$timestamp = Format::to_date( 1705276800, 'Y-m-d H:i:s' ); // "2024-01-15 00:00:00"
```

Global Functions
----------------

[](#global-functions)

The library provides convenient WordPress-style functions:

FunctionDescription`wp_convert_units($value, $from, $to, $type)`Convert between measurement units`wp_convert_temperature( $value, $from, $to )`Convert temperature (C ↔ F)`wp_format_filesize($bytes, $precision)`Format bytes to human readable`wp_format_duration($seconds, $short)`Format seconds to duration`wp_convert_size( $size, $from, $to, $type, $gender)`Convert clothing/shoe/ring sizes### Global Function Examples

[](#global-function-examples)

```
// Unit conversions
$meters  = wp_convert_units( 100, 'ft', 'm', 'length' ); // 30.48
$pounds  = wp_convert_units( 50, 'kg', 'lb', 'weight' ); // 110.23
$liters  = wp_convert_units( 1, 'gal', 'l', 'volume' ); // 3.79
$celsius = wp_convert_temperature( 212, 'F', 'C' ); // 100

// File and duration formatting
$readable   = wp_format_filesize( 2048576 ); // "2.00 MB"
$time       = wp_format_duration( 3725 ); // "1 hour 2 minutes 5 seconds"
$short_time = wp_format_duration( 3725, true ); // "1h 2m 5s"

// Size conversions
$eu_clothing = wp_convert_size( 'M', 'us', 'eu', 'clothing', 'men' ); // "48"
$uk_shoe     = wp_convert_size( 9, 'us', 'uk', 'shoe', 'women' ); // "6.5"
$eu_ring     = wp_convert_size( '7', 'us', 'eu', 'ring' ); // "54"
$mm_watch    = wp_convert_size( '3/4', 'inches', 'mm', 'watch' ); // "19"
```

Class Methods
-------------

[](#class-methods)

### Unit Class

[](#unit-class)

- `Unit::length( $value, $from, $to )` - Length conversions
- `Unit::weight( $value, $from, $to )` - Weight conversions
- `Unit::volume( $value, $from, $to )` - Volume conversions
- `Unit::temperature( $value, $from, $to )` - Temperature conversions
- `Unit::speed( $value, $from, $to )` - Speed conversions
- `Unit::data_storage( $value, $from, $to )` - Data size conversions
- `Unit::area( $value, $from, $to )` - Area conversions
- `Unit::time( $value, $from, $to )` - Time conversions
- `Unit::energy( $value, $from, $to )` - Energy conversions
- `Unit::pressure( $value, $from, $to )` - Pressure conversions
- `Unit::cooking( $value, $from, $to )` - Cooking measurements

### Size Class

[](#size-class)

- `Size::clothing( $size, $from, $to, $gender )` - Clothing size conversions
- `Size::shoe( $size, $from, $to, $gender )` - Shoe size conversions
- `Size::ring( $size, $from, $to )` - Ring size conversions
- `Size::bra( $size, $from, $to )` - Bra size conversions
- `Size::hat( $size, $from, $to )` - Hat size conversions
- `Size::glove( $size, $from, $to )` - Glove size conversions
- `Size::watch_band( $size, $from, $to )` - Watch band size conversions
- `Size::belt( $size, $from, $to, $gender )` - Belt size conversions
- `Size::sock( $size, $from, $to, $gender )` - Sock size conversions

### Format Class

[](#format-class)

- `Format::to_yes_no( $value, $title_case )` - Convert to yes/no
- `Format::to_on_off( $value, $title_case )` - Convert to on/off
- `Format::to_binary( $value )` - Convert to 1/0
- `Format::to_string_boolean( $value, $title_case )` - Convert to true/false
- `Format::bytes_to_size( $bytes, $precision )` - Format file sizes
- `Format::seconds_to_duration( $seconds, $short )` - Format duration
- `Format::rgb_to_hex( $red, $green, $blue )` - RGB to hex color
- `Format::hex_to_rgb( $hex )` - Hex to RGB color
- `Format::to_percentage( $number, $decimals, $add_symbol )` - Format percentage
- `Format::to_date( $value, $format )` - Format dates

Use Cases
---------

[](#use-cases)

### E-commerce

[](#e-commerce)

```
// Product dimensions
$length_cm = wp_convert_units( 12, 'in', 'cm', 'length' ); // 30.48
$weight_kg = wp_convert_units( 5, 'lb', 'kg', 'weight' ); // 2.27

// International sizing
$eu_size = wp_convert_size( 'M', 'us', 'eu', 'clothing', 'men' ); // "48"
$uk_shoe = wp_convert_size( 9, 'us', 'uk', 'shoe', 'women' ); // 6.5
$eu_bra  = wp_convert_size( '34B', 'us', 'eu', 'bra' ); // "75B"
```

### File Management

[](#file-management)

```
// Display file sizes
$readable_size = wp_format_filesize( $file_size_bytes );
echo "File size: " . $readable_size; // "File size: 2.5 MB"

// Convert storage units
$gb_available = Unit::data_storage( $mb_available, 'mb', 'gb' );
$tb_total     = wp_convert_units( $gb_total, 'gb', 'tb', 'data' );
```

### Recipe Sites

[](#recipe-sites)

```
// Convert cooking measurements
$metric_cups = Unit::cooking( 250, 'ml', 'cup' ); // 1.04
$tablespoons = Unit::cooking( 0.5, 'cup', 'tbsp' ); // 8
$liters      = wp_convert_units( 4, 'qt', 'l', 'volume' ); // 3.79
```

### International Retail

[](#international-retail)

```
// Clothing conversions for global customers
$sizes = [
	'us' => '8',
	'uk' => Size::clothing( '8', 'us', 'uk', 'women' ), // "12"
	'eu' => Size::clothing( '8', 'us', 'eu', 'women' ), // "36"
	'fr' => Size::clothing( '8', 'us', 'fr', 'women' )  // "36"
];

// Shoe size chart
$shoe_sizes = [
	'us_women' => '8',
	'uk_women' => Size::shoe( 8, 'us', 'uk', 'women' ), // 5.5
	'eu_women' => Size::shoe( 8, 'us', 'eu', 'women' )  // 38.5
];
```

### Technical Applications

[](#technical-applications)

```
// Network monitoring
$bandwidth_mbps = Unit::data_storage( $bytes_per_second * 8, 'b', 'mb' );
$storage_tb     = wp_convert_units( $total_bytes, 'b', 'tb', 'data' );

// Performance metrics
$load_time = wp_format_duration( $milliseconds / 1000 );
$file_size = wp_format_filesize( $asset_bytes );
```

### Weather &amp; Environmental

[](#weather--environmental)

```
// Temperature display
$celsius      = wp_convert_temperature( $fahrenheit, 'F', 'C' );
$display_temp = round( $celsius, 1 ) . '°C';

// Wind speed
$kmh = wp_convert_units( $mph_wind, 'mph', 'km/h', 'speed' );
$ms  = Unit::speed( $kmh, 'km/h', 'm/s' );

// Pressure readings
$mb = Unit::pressure( $inches_hg, 'psi', 'kpa' ) * 10; // Convert to millibars
```

Advanced Usage
--------------

[](#advanced-usage)

### Chaining Conversions

[](#chaining-conversions)

```
// Convert through multiple units
$temp_f = 68; // Fahrenheit
$temp_c = wp_convert_temperature( $temp_f, 'F', 'C' ); // 20°C
$temp_k = $temp_c + 273.15; // Kelvin conversion

// Multistep size conversion
$us_shoe = 9.5;
$uk_shoe = Size::shoe( $us_shoe, 'us', 'uk', 'men' ); // 9.0
$eu_shoe = Size::shoe( $uk_shoe, 'uk', 'eu', 'men' );  // 43
```

### Batch Processing

[](#batch-processing)

```
// Convert multiple measurements
$measurements = [
	[ 'value' => 10, 'from' => 'in', 'to' => 'cm' ],
	[ 'value' => 5, 'from' => 'lb', 'to' => 'kg' ],
	[ 'value' => 2, 'from' => 'gal', 'to' => 'l' ]
];

$converted = array_map( function ( $m ) {
	return wp_convert_units( $m['value'], $m['from'], $m['to'], 'length' );
}, $measurements );
```

### Error Handling

[](#error-handling)

```
// Check for successful conversions
$result = wp_convert_units( 100, 'invalid_unit', 'm', 'length' );
if ( $result === null ) {
	echo "Conversion failed - invalid units";
} else {
	echo "Result: " . $result . " meters";
}

// Size conversion validation
$bra_size = Size::bra( '34B', 'us', 'invalid_system' );
if ( $bra_size === null ) {
	echo "Invalid size system";
}
```

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

[](#requirements)

- 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-conversion-utils)
- [Issue Tracker](https://github.com/arraypress/wp-conversion-utils/issues)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

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 (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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