offsetwp / hook-wordpress
Typed, secure, and maintainable WordPress Core action and filter hooks
Fund package maintenance!
Buy Me A Coffee
Ko Fi
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/offsetwp/hook-wordpress
Requires
- php: >=8.1
Requires (Dev)
- nette/php-generator: ^4.2
- wp-coding-standards/wpcs: ^3.3
- wp-hooks/wordpress-core: ^1.11
This package is not auto-updated.
Last update: 2025-12-19 14:17:51 UTC
README
OffsetWP Hook
Typed, secure, and maintainable WordPress Core action and filter hooks
About OffsetWP WordPress
WordPress makes extensive use of hooks for its internal functioning. Unfortunately, the way it was developed makes it difficult to work with hook data:
- the callback is public and accessible by any other function
- to find out the returned parameters, you have to consult the documentation
- no auto-completion
OffsetWP Hook provides ready-to-use wrappers for native WordPress hooks. The wrappers already include the exact callback signatures, allowing for optimal autocompletion in your IDE.
Installation
composer require offsetwp/hook
Basic usage
use OffsetWP\Hook\WordPress\Filter\WPAdminFooterTextFilter; new class extends WPAdminFooterTextFilter { protected function handle( $text ) { return 'Made with love by OffsetWP | ' . $text; } };
Hook with a dynamique name
use OffsetWP\Hook\WordPress\Filter\WPGetMetaTypeMetadataFilter; new class extends WPGetMetaTypeMetadataFilter { public string $hook_name = 'get_post_metadata'; // 'get_{$meta_type}_metadata' protected function handle( $value, $object_id, $meta_key, $single, $meta_type ) { return $value; } };
Advanced usage
With more substantial development, it may be necessary for your hooks to use dependencies. All of this is possible, depending on your needs:
use OffsetWP\Hook\WordPress\Filter\WPAdminFooterTextFilter; new class extends WPAdminFooterTextFilter { public function __construct( private $myServiceName = 'CustomService' ) { return parent::__construct(); } protected function handle( $text ) { return $this->myServiceName . ' | ' . $text; } }

