Skip to content

Commit

Permalink
Merge pull request #195 from WordPress/devex_api_wp
Browse files Browse the repository at this point in the history
DevEx API - WordPress-y version
  • Loading branch information
ashfame authored Jan 7, 2025
2 parents 04d147a + 772beb2 commit d92e085
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/plugin/class-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
} )();
}
}

0 comments on commit d92e085

Please sign in to comment.