1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Addons; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\PluginContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Hooks\AbstractHooks; |
7
|
|
|
|
8
|
|
|
abstract class Hooks extends AbstractHooks |
9
|
|
|
{ |
10
|
|
|
abstract public function app(): PluginContract; |
11
|
|
|
|
12
|
|
|
public function runIntegrations(): void |
13
|
|
|
{ |
14
|
|
|
$dir = $this->app()->path('plugin/Integrations'); |
15
|
|
|
if (!is_dir($dir)) { |
16
|
|
|
return; |
17
|
|
|
} |
18
|
|
|
$iterator = new \DirectoryIterator($dir); |
19
|
|
|
$namespace = (new \ReflectionClass($this->app()))->getNamespaceName(); |
20
|
|
|
foreach ($iterator as $fileinfo) { |
21
|
|
|
if (!$fileinfo->isDir() || $fileinfo->isDot()) { |
22
|
|
|
continue; |
23
|
|
|
} |
24
|
|
|
try { |
25
|
|
|
$hooks = "{$namespace}\Integrations\\{$fileinfo->getBasename()}\Hooks"; |
26
|
|
|
$reflect = new \ReflectionClass($hooks); |
27
|
|
|
if ($reflect->isInstantiable()) { |
28
|
|
|
glsr()->singleton($hooks); |
29
|
|
|
add_action('plugins_loaded', fn () => glsr($hooks)->run(), 100); // run integrations late |
30
|
|
|
glsr($hooks)->runDeferred(); |
31
|
|
|
} |
32
|
|
|
} catch (\ReflectionException $e) { |
33
|
|
|
glsr_log()->error($e->getMessage()); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function baseHooks(array $hooks = []): array |
39
|
|
|
{ |
40
|
|
|
$defaults = [ |
41
|
|
|
['enqueueAdminAssets', 'admin_enqueue_scripts'], |
42
|
|
|
['enqueuePublicAssets', 'wp_enqueue_scripts'], |
43
|
|
|
['filterActionLinks', "plugin_action_links_{$this->basename()}"], |
44
|
|
|
['filterCapabilities', 'site-reviews/capabilities'], |
45
|
|
|
['filterConfigPath', 'site-reviews/config'], |
46
|
|
|
['filterDocumentation', 'site-reviews/addon/documentation'], |
47
|
|
|
['filterFilePaths', 'site-reviews/path', 10, 2], |
48
|
|
|
['filterGettext', "gettext_{$this->id()}", 10, 2], |
49
|
|
|
['filterGettextWithContext', "gettext_with_context_{$this->id()}", 10, 3], |
50
|
|
|
['filterLocalizedPublicVariables', 'site-reviews/enqueue/public/localize'], |
51
|
|
|
['filterNgettext', "ngettext_{$this->id()}", 10, 4], |
52
|
|
|
['filterNgettextWithContext', "ngettext_with_context_{$this->id()}", 10, 5], |
53
|
|
|
['filterRenderView', "{$this->id()}/render/view"], |
54
|
|
|
['filterRoles', 'site-reviews/roles'], |
55
|
|
|
['filterSettings', 'site-reviews/settings'], |
56
|
|
|
['filterSubsubsub', 'site-reviews/addon/subsubsub'], |
57
|
|
|
['filterTranslationEntries', 'site-reviews/translation/entries'], |
58
|
|
|
['filterTranslatorDomains', 'site-reviews/translator/domains'], |
59
|
|
|
['install', "{$this->id()}/activated"], |
60
|
|
|
['onActivation', 'admin_init'], |
61
|
|
|
['onDeactivation', "deactivate_{$this->basename()}"], |
62
|
|
|
['registerLanguages', 'after_setup_theme'], |
63
|
|
|
['registerShortcodes', 'init'], |
64
|
|
|
['registerTinymcePopups', 'admin_init'], |
65
|
|
|
['registerWidgets', 'widgets_init'], |
66
|
|
|
['renderSettings', "site-reviews/settings/{$this->slug()}"], |
67
|
|
|
]; |
68
|
|
|
return array_merge($defaults, $hooks); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function basename(): string |
72
|
|
|
{ |
73
|
|
|
return $this->app()->basename; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function id(): string |
77
|
|
|
{ |
78
|
|
|
return $this->app()->id; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function slug(): string |
82
|
|
|
{ |
83
|
|
|
return $this->app()->slug; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function type(): string |
87
|
|
|
{ |
88
|
|
|
return $this->app()->post_type; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|