PHP Toolkit

Polyfill

PHP 8 string functions on PHP 7.2+, WordPress hook stubs, and translation/escaping passthroughs so toolkit code runs without booting WordPress.

composer require wp-php-toolkit/polyfill

A lot of WordPress-adjacent code wants to call esc_html(), __(), or apply_filters() without booting WordPress. The polyfill component provides minimal implementations for the subset used by the toolkit, and stays out of the way when WordPress is loaded (every function uses function_exists() guards).

PHP 8 string functions on PHP 7.2

The polyfills define str_contains, str_starts_with, str_ends_with, and array_key_first only when missing.

Escaping and translation stubs

Pass-through implementations let you write code that looks WordPressy and runs anywhere.

A simple filter chain

The hook system implements the common filter path: registered callbacks get applied in priority order, and each one transforms the running value.

Priority ordering and multi-arg passing

Lower priority numbers run first. The fourth argument to add_filter controls how many context values get passed to the callback.

Hook-based extension points in standalone libraries

Use do_action and apply_filters as cheap extension points in your own code, without depending on WordPress.

See also