From 772beb26c57dac40f2755fdddc6df77f0f23f529 Mon Sep 17 00:00:00 2001 From: ashfame Date: Thu, 2 Jan 2025 21:55:20 +0400 Subject: [PATCH] Handle mimicry of WordPress-y API for developers --- src/plugin/class-engine.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/plugin/class-engine.php b/src/plugin/class-engine.php index a88e6840..985de716 100644 --- a/src/plugin/class-engine.php +++ b/src/plugin/class-engine.php @@ -34,6 +34,37 @@ public function __construct() { new Storage( self::STORAGE_POST_TYPE ); Ops::init( self::STORAGE_POST_TYPE ); + + /** + * Handle mimicry of WordPress-y API for developers + * + * There are no `do_action( 'data_liberated_' . %subjectype% )` calls anywhere + * We loop over any registered callbacks and invoke Ops::handle on their behalf + */ + add_action( + 'init', + function () { + global $wp_filter; + foreach ( SubjectType::cases() as $type ) { + $hook_name = 'data_liberated_' . $type->value; + if ( isset( $wp_filter[ $hook_name ] ) ) { + foreach ( $wp_filter[ $hook_name ]->callbacks as $callbacks ) { + foreach ( $callbacks as $callback ) { + Ops::handle( + $type, + array( + 'slug' => 'wp_action_' . wp_generate_uuid4(), + 'description' => 'Handler registered via WordPress action', + ), + $callback['function'] + ); + } + } + } + } + }, + PHP_INT_MAX + ); } )(); } }