Skip to content

Commit 609a423

Browse files
danslebobygfazioli
authored andcommitted
Allow controls of priority/timing of add_actions in init
This was needed for me beacause I have other plugin with init action with a priority 5, so the hooks can not be register before the other plugin.
1 parent b4911f9 commit 609a423

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/Foundation/Plugin.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,20 @@ public function boot(): Plugin
131131
// init api
132132
$this->initApi();
133133

134+
// Fetch the priorities from the config file
135+
$priorities = $this->config('plugin.priorities', []);
136+
134137
// Fires after WordPress has finished loading but before any headers are sent.
135-
add_action('init', [$this, '_init']);
138+
add_action('init', [$this, '_init'], $priorities['init'] ?? 10);
136139

137140
// Fires before the administration menu loads in the admin.
138-
add_action('admin_menu', [$this, '_admin_menu']);
141+
add_action('admin_menu', [$this, '_admin_menu'], $priorities['admin_init'] ?? 10);
139142

140143
// Fires after all default WordPress widgets have been registered.
141-
add_action('widgets_init', [$this, '_widgets_init']);
144+
add_action('widgets_init', [$this, '_widgets_init'], $priorities['widget_init'] ?? 10);
142145

143146
// Filter a screen option value before it is set.
144-
add_filter('set-screen-option', [$this, '_set_screen_option'], 10, 3);
147+
add_filter('set-screen-option', [$this, '_set_screen_option'], $priorities['set_screen_option'] ?? 10, 3);
145148

146149
static::$instance = $this;
147150

0 commit comments

Comments
 (0)