Registry

The Registry package provides a flexible, namespaced key-value store for sharing data across your WordPress application. It supports multiple named registries (using the Multiton pattern) and is useful for managing configuration, caching, or any shared state.

Last modified: June 2, 2025

link Features

link Usage

link Default Registry

use T2\Registry\Registry;

// Get the default registry instance
$default = Registry::get_instance();
$default->set('key', 'value');
print_r( $default->get_all() );
// Output: [ 'key' => 'value' ]

link Named Registries

// Get a named registry instance (e.g., "config")
$config = Registry::get_instance('config');
$config->set('setting', 'on');
print_r( $config->get_all() );
// Output: [ 'setting' => 'on' ]

// Each registry is isolated:
print_r( $default->get_all() );
// Output: [ 'key' => 'value' ]

link API

link Registry::get_instance( $name = 'default' )

Returns a singleton instance of the registry for the given name.

link set( $key, $value )

Stores a value by key.

link get( $key, $default = null )

Retrieves a value by key, or returns the default if not set.

link get_all()

Returns all key-value pairs in the registry.

link has( $key )

Checks if a key exists in the registry.

link remove( $key )

Removes a key from the registry.