PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
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 4 days ago Contracts 1 month ago Hooks 4 days ago Models 1 month ago BaseHook.php 1 month ago HookServiceProvider.php 4 days ago Menu.php 1 month ago User.php 1 month ago UserMeta.php 1 month ago
HookServiceProvider.php
85 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 use Kirki\Framework\Wordpress\Hooks\Actions\RegisterSiteRoutes;
18 class HookServiceProvider extends ServiceProvider
19 {
20 /**
21 * The defaults.
22 *
23 * @var string
24 *
25 * @since 1.0.0
26 */
27 protected static $defaults = ['actions' => [RegisterRestApi::class, RegisterSiteRoutes::class], 'filters' => []];
28 /**
29 * Register the hooks to the application.
30 *
31 * @return void
32 *
33 * @since 1.0.0
34 */
35 public function register()
36 {
37 $hooks = $this->hooks();
38 $this->app->tag($hooks['actions'], 'hook.actions');
39 $this->app->tag($hooks['filters'], 'hook.filters');
40 }
41 /**
42 * Get the hooks from the configuration file.
43 *
44 * @return array
45 *
46 * @since 1.0.0
47 */
48 protected function hooks()
49 {
50 $hooks_path = $this->app->config_path('hooks.php');
51 if (!\file_exists($hooks_path)) {
52 return static::$defaults;
53 }
54 $hooks = (include $hooks_path);
55 if (empty($hooks)) {
56 return static::$defaults;
57 }
58 if (!\in_array(RegisterRestApi::class, $hooks['actions'], \true)) {
59 \array_unshift($hooks['actions'], RegisterRestApi::class);
60 }
61 if (!\in_array(RegisterSiteRoutes::class, $hooks['actions'], \true)) {
62 $hooks['actions'][] = RegisterSiteRoutes::class;
63 }
64 return ['actions' => $hooks['actions'] ?? [], 'filters' => $hooks['filters'] ?? []];
65 }
66 /**
67 * Add the action hooks on after the application booted.
68 *
69 * @return void
70 *
71 * @since 1.0.0
72 */
73 public function boot()
74 {
75 $actions = $this->app->tagged('hook.actions');
76 foreach ($actions as $action) {
77 add_action($action->get_name(), [$action, 'handle'], $action->get_priority(), $action->get_args_count());
78 }
79 $filters = $this->app->tagged('hook.filters');
80 foreach ($filters as $filter) {
81 add_filter($filter->get_name(), [$filter, 'handle'], $filter->get_priority(), $filter->get_args_count());
82 }
83 }
84 }
85