PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.4
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.4
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 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 1 week ago Contracts 1 month ago Hooks 1 week ago Models 1 month ago BaseHook.php 1 month ago HookServiceProvider.php 1 week ago Menu.php 1 month ago User.php 1 month ago UserMeta.php 1 month ago
HookServiceProvider.php
108 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\FlushQueuedCookies;
17 use Kirki\Framework\Wordpress\Hooks\Actions\VersionUpdate;
18 use Kirki\Framework\Wordpress\Hooks\Actions\RegisterRestApi;
19 use Kirki\Framework\Wordpress\Hooks\Actions\RegisterSiteRoutes;
20 use Kirki\Framework\Wordpress\Hooks\Filters\FlushRestCookies;
21 class HookServiceProvider extends ServiceProvider
22 {
23 /**
24 * The defaults.
25 *
26 * @var array<string, array<string>>
27 *
28 * @since 1.0.0
29 */
30 protected static $defaults = ['actions' => [RegisterRestApi::class, RegisterSiteRoutes::class, VersionUpdate::class, FlushQueuedCookies::class], 'filters' => [FlushRestCookies::class]];
31 /**
32 * Register the hooks to the application.
33 *
34 * @return void
35 *
36 * @since 1.0.0
37 */
38 public function register()
39 {
40 $hooks = $this->hooks();
41 $this->app->tag($hooks['actions'], 'hook.actions');
42 $this->app->tag($hooks['filters'], 'hook.filters');
43 }
44 /**
45 * Get the hooks from the configuration file.
46 *
47 * @return array
48 *
49 * @since 1.0.0
50 */
51 protected function hooks()
52 {
53 $hooks_path = $this->app->config_path('hooks.php');
54 if (!\file_exists($hooks_path)) {
55 return static::$defaults;
56 }
57 $hooks = (include $hooks_path);
58 if (empty($hooks)) {
59 return static::$defaults;
60 }
61 return ['actions' => $this->merge_defaults($hooks['actions'] ?? [], 'actions'), 'filters' => $this->merge_defaults($hooks['filters'] ?? [], 'filters')];
62 }
63 /**
64 * Merge the framework default hooks into the configured ones.
65 *
66 * Defaults are prepended so the framework hooks register before application hooks,
67 * and are skipped when the application already lists them.
68 *
69 * @param array $configured The hooks defined by the application.
70 * @param string $type The hook group, either actions or filters.
71 *
72 * @return array
73 *
74 * @since 1.0.0
75 */
76 protected function merge_defaults(array $configured, string $type)
77 {
78 $missing = [];
79 foreach (static::$defaults[$type] as $hook) {
80 if (!\in_array($hook, $configured, \true)) {
81 $missing[] = $hook;
82 }
83 }
84 if (empty($missing)) {
85 return $configured;
86 }
87 return \array_merge($missing, $configured);
88 }
89 /**
90 * Add the action hooks on after the application booted.
91 *
92 * @return void
93 *
94 * @since 1.0.0
95 */
96 public function boot()
97 {
98 $actions = $this->app->tagged('hook.actions');
99 foreach ($actions as $action) {
100 add_action($action->get_name(), [$action, 'handle'], $action->get_priority(), $action->get_args_count());
101 }
102 $filters = $this->app->tagged('hook.filters');
103 foreach ($filters as $filter) {
104 add_filter($filter->get_name(), [$filter, 'handle'], $filter->get_priority(), $filter->get_args_count());
105 }
106 }
107 }
108