-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFaqExtension.php
More file actions
75 lines (64 loc) · 2.22 KB
/
Copy pathFaqExtension.php
File metadata and controls
75 lines (64 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Jankx\Extensions\Faq;
use Jankx\Extensions\AbstractExtension;
/**
* FAQ extension for the nibitour site.
*
* Manages frequently asked questions through the `jankx_faq` post type grouped
* by the `jankx_faq_category` taxonomy, and optionally injects FAQs into the
* My Account overview page when the my-account extension is installed.
*/
class FaqExtension extends AbstractExtension
{
protected static $instance;
public function __construct()
{
$this->register_autoloader();
parent::__construct();
}
protected function register_autoloader()
{
spl_autoload_register(function ($class) {
$prefix = 'Jankx\\Extensions\\Faq\\';
$base_dir = __DIR__ . '/src/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
}
public function init(): void
{
self::$instance = $this;
}
public static function get_instance(): ?self
{
return self::$instance;
}
public function register_hooks(): void
{
$postType = new \Jankx\Extensions\Faq\PostTypes\FaqPostType();
$postType->register();
$metaBoxes = new \Jankx\Extensions\Faq\Meta\FaqMetaBoxes();
$metaBoxes->register();
if (is_admin()) {
$settingsPage = new \Jankx\Extensions\Faq\Admin\SettingsPage();
$settingsPage->register();
}
// Inject FAQs into the My Account overview when that extension exists.
// Deferred: my-account loads after this extension (alphabetical order),
// so class_exists() is still false while register_hooks() runs.
add_action('after_setup_theme', [$this, 'registerMyAccountIntegration'], 20);
}
public function registerMyAccountIntegration(): void
{
if (class_exists('\Jankx\Extensions\MyAccount\MyAccountExtension')) {
(new \Jankx\Extensions\Faq\Integration\MyAccountIntegration())->register();
}
}
}