Skip to content
Snippets Groups Projects
Verified Commit b7ed8b86 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

fix: defer hook execution to `plugins_loaded` event

parent 9533440f
No related branches found
No related tags found
2 merge requests!5feat: remove compilation command,!4feat: remove compilation command
...@@ -20,17 +20,23 @@ class GenericDriver implements HookDriver { ...@@ -20,17 +20,23 @@ class GenericDriver implements HookDriver {
} }
public function register_hooks(): void { public function register_hooks(): void {
foreach ( $this->definitions->load() as $definition ) { // Load has to be deffered until plugins_loaded because classes may implement or extend interfaces/classes which doesn't exist yet.
if ( $definition->hook() ) {
add_action( add_action(
$definition->hook(), 'plugins_loaded',
function () use ( $definition ) { function () {
foreach ( $this->definitions->load() as $definition ) {
if ( $definition->hook() === null ) {
$this->binder->bind( $definition ); $this->binder->bind( $definition );
continue;
} }
add_action(
$definition->hook(),
fn () => $this->binder->bind( $definition )
); );
} else {
$this->binder->bind( $definition );
}
} }
},
-50
);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment