-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypemanager.php
103 lines (90 loc) · 2.61 KB
/
typemanager.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @package wp-content-aware-engine
* @author Joachim Jensen <[email protected]>
* @license GPLv3
* @copyright 2023 by Joachim Jensen
*/
defined('ABSPATH') || exit;
if (!class_exists('WPCATypeManager')) {
/**
* Manage module objects
*/
final class WPCATypeManager extends WPCACollection
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
add_action(
'init',
[$this,'set_modules'],
999
);
}
/**
* @param string $name
* @return $this
*/
public function add($name)
{
return parent::put($name, new WPCACollection());
}
/**
* Set initial modules
*
* @since 4.0
* @return void
*/
public function set_modules()
{
do_action('wpca/types/init', $this);
$modules = [
'static',
'post_type',
'author',
'page_template',
'taxonomy',
'date',
'bbpress',
'bp_member',
'pods',
'polylang',
'qtranslate',
'translatepress',
'transposh',
'weglot',
'wpml'
];
foreach ($modules as $name) {
$class_name = WPCACore::CLASS_PREFIX . 'Module_' . $name;
if (!class_exists($class_name)) {
continue;
}
$class = new $class_name();
if (!($class instanceof WPCAModule_Base) || !$class->can_enable()) {
continue;
}
foreach ($this->all() as $post_type) {
$post_type->put($name, $class);
}
}
do_action('wpca/modules/init', $this);
//initiate all modules once with backwards compatibility on can_enable()
$initiated = [];
foreach ($this->all() as $post_type_name => $post_type) {
if (!WPCACore::get_option($post_type_name, 'legacy.date_module', false)) {
$post_type->remove('date');
}
foreach ($post_type->all() as $key => $module) {
if (!isset($initiated[$key])) {
$initiated[$key] = 1;
$module->initiate();
}
}
}
}
}
}