PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Wordpress / HookServiceProvider.php
kirki / libraries / framework / Wordpress Last commit date
Constants 3 weeks ago Contracts 3 weeks ago Hooks 3 weeks ago Models 3 weeks ago BaseHook.php 3 weeks ago HookServiceProvider.php 3 weeks ago Menu.php 3 weeks ago User.php 3 weeks ago UserMeta.php 3 weeks ago
HookServiceProvider.php
81 lines
1 <?php
2
3 /**
4 * Loads action and filter hook classes from config/hooks.php and tags them for container discovery.
5 * Ensures RegisterRestApi is always registered even when config is empty.
6 * Boots hook instances onto WordPress during application boot.
7 *
8 * @package Framework
9 * @subpackage Wordpress
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Wordpress;
13
14 \defined('ABSPATH') || exit;
15 use Kirki\Framework\ServiceProvider;
16 use Kirki\Framework\Wordpress\Hooks\Actions\RegisterRestApi;
17 class HookServiceProvider extends ServiceProvider
18 {
19 /**
20 * The defaults.
21 *
22 * @var string
23 *
24 * @since 1.0.0
25 */
26 protected static $defaults = ['actions' => [RegisterRestApi::class], 'filters' => []];
27 /**
28 * Register the hooks to the application.
29 *
30 * @return void
31 *
32 * @since 1.0.0
33 */
34 public function register()
35 {
36 $hooks = $this->hooks();
37 $this->app->tag($hooks['actions'], 'hook.actions');
38 $this->app->tag($hooks['filters'], 'hook.filters');
39 }
40 /**
41 * Get the hooks from the configuration file.
42 *
43 * @return array
44 *
45 * @since 1.0.0
46 */
47 protected function hooks()
48 {
49 $hooks_path = $this->app->config_path('hooks.php');
50 if (!\file_exists($hooks_path)) {
51 return static::$defaults;
52 }
53 $hooks = (include $hooks_path);
54 if (empty($hooks)) {
55 return static::$defaults;
56 }
57 if (!\in_array(RegisterRestApi::class, $hooks['actions'], \true)) {
58 \array_unshift($hooks['actions'], RegisterRestApi::class);
59 }
60 return ['actions' => $hooks['actions'] ?? [], 'filters' => $hooks['filters'] ?? []];
61 }
62 /**
63 * Add the action hooks on after the application booted.
64 *
65 * @return void
66 *
67 * @since 1.0.0
68 */
69 public function boot()
70 {
71 $actions = $this->app->tagged('hook.actions');
72 foreach ($actions as $action) {
73 add_action($action->get_name(), [$action, 'handle'], $action->get_priority(), $action->get_args_count());
74 }
75 $filters = $this->app->tagged('hook.filters');
76 foreach ($filters as $filter) {
77 add_filter($filter->get_name(), [$filter, 'handle'], $filter->get_priority(), $filter->get_args_count());
78 }
79 }
80 }
81