@@ -7,151 +7,151 @@ |
||
7 | 7 | abstract class EE_Table_Base |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * This holds the table_name without the table prefix. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - public $_table_name; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * This holds what is used as the alias for the table in queries. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $_table_alias; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * Table's private key column |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_pk_column; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Whether this table is a global table (in multisite) or specific to site. |
|
36 | - * |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - protected $_global; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $table_name with or without wpdb prefix |
|
44 | - * @param string $pk_column |
|
45 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
46 | - * install, or whether each site on a multisite install has a copy of this table |
|
47 | - * @global wpdb $wpdb |
|
48 | - */ |
|
49 | - public function __construct($table_name, $pk_column, $global = false) |
|
50 | - { |
|
51 | - $this->_global = $global; |
|
52 | - $prefix = $this->get_table_prefix(); |
|
53 | - // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
54 | - if (strpos($table_name, $prefix) === 0) { |
|
55 | - $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
56 | - } |
|
57 | - $this->_table_name = $table_name; |
|
58 | - $this->_pk_column = $pk_column; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * This returns the table prefix for the current model state. |
|
64 | - * |
|
65 | - * @return string |
|
66 | - * @global wpdb $wpdb |
|
67 | - */ |
|
68 | - public function get_table_prefix() |
|
69 | - { |
|
70 | - global $wpdb; |
|
71 | - if ($this->_global) { |
|
72 | - return $wpdb->base_prefix; |
|
73 | - } |
|
74 | - return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Used to set the table_alias property |
|
80 | - * |
|
81 | - * @param string $table_alias |
|
82 | - */ |
|
83 | - public function _construct_finalize_with_alias($table_alias) |
|
84 | - { |
|
85 | - $this->_table_alias = $table_alias; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
91 | - * |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function get_table_name() |
|
95 | - { |
|
96 | - return $this->get_table_prefix() . $this->_table_name; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Provides what is currently set as the alias for the table to be used in queries. |
|
102 | - * |
|
103 | - * @return string |
|
104 | - * @throws EE_Error |
|
105 | - */ |
|
106 | - public function get_table_alias() |
|
107 | - { |
|
108 | - if (! $this->_table_alias) { |
|
109 | - throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
110 | - } |
|
111 | - return $this->_table_alias; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return string name of column of PK |
|
117 | - */ |
|
118 | - public function get_pk_column() |
|
119 | - { |
|
120 | - return $this->_pk_column; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * returns a string with the table alias, a period, and the private key's column. |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function get_fully_qualified_pk_column() |
|
130 | - { |
|
131 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * returns the special sql for a inner select with a limit. |
|
137 | - * |
|
138 | - * @return string SQL select |
|
139 | - */ |
|
140 | - public function get_select_join_limit($limit) |
|
141 | - { |
|
142 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
143 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * Returns whether or not htis is a global table (ie, on multisite there's |
|
149 | - * only one of these tables, on the main blog) |
|
150 | - * |
|
151 | - * @return boolean |
|
152 | - */ |
|
153 | - public function is_global() |
|
154 | - { |
|
155 | - return $this->_global; |
|
156 | - } |
|
10 | + /** |
|
11 | + * This holds the table_name without the table prefix. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + public $_table_name; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * This holds what is used as the alias for the table in queries. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $_table_alias; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * Table's private key column |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_pk_column; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Whether this table is a global table (in multisite) or specific to site. |
|
36 | + * |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + protected $_global; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $table_name with or without wpdb prefix |
|
44 | + * @param string $pk_column |
|
45 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
46 | + * install, or whether each site on a multisite install has a copy of this table |
|
47 | + * @global wpdb $wpdb |
|
48 | + */ |
|
49 | + public function __construct($table_name, $pk_column, $global = false) |
|
50 | + { |
|
51 | + $this->_global = $global; |
|
52 | + $prefix = $this->get_table_prefix(); |
|
53 | + // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
54 | + if (strpos($table_name, $prefix) === 0) { |
|
55 | + $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
56 | + } |
|
57 | + $this->_table_name = $table_name; |
|
58 | + $this->_pk_column = $pk_column; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * This returns the table prefix for the current model state. |
|
64 | + * |
|
65 | + * @return string |
|
66 | + * @global wpdb $wpdb |
|
67 | + */ |
|
68 | + public function get_table_prefix() |
|
69 | + { |
|
70 | + global $wpdb; |
|
71 | + if ($this->_global) { |
|
72 | + return $wpdb->base_prefix; |
|
73 | + } |
|
74 | + return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Used to set the table_alias property |
|
80 | + * |
|
81 | + * @param string $table_alias |
|
82 | + */ |
|
83 | + public function _construct_finalize_with_alias($table_alias) |
|
84 | + { |
|
85 | + $this->_table_alias = $table_alias; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
91 | + * |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function get_table_name() |
|
95 | + { |
|
96 | + return $this->get_table_prefix() . $this->_table_name; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Provides what is currently set as the alias for the table to be used in queries. |
|
102 | + * |
|
103 | + * @return string |
|
104 | + * @throws EE_Error |
|
105 | + */ |
|
106 | + public function get_table_alias() |
|
107 | + { |
|
108 | + if (! $this->_table_alias) { |
|
109 | + throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
110 | + } |
|
111 | + return $this->_table_alias; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return string name of column of PK |
|
117 | + */ |
|
118 | + public function get_pk_column() |
|
119 | + { |
|
120 | + return $this->_pk_column; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * returns a string with the table alias, a period, and the private key's column. |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function get_fully_qualified_pk_column() |
|
130 | + { |
|
131 | + return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * returns the special sql for a inner select with a limit. |
|
137 | + * |
|
138 | + * @return string SQL select |
|
139 | + */ |
|
140 | + public function get_select_join_limit($limit) |
|
141 | + { |
|
142 | + $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
143 | + return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * Returns whether or not htis is a global table (ie, on multisite there's |
|
149 | + * only one of these tables, on the main blog) |
|
150 | + * |
|
151 | + * @return boolean |
|
152 | + */ |
|
153 | + public function is_global() |
|
154 | + { |
|
155 | + return $this->_global; |
|
156 | + } |
|
157 | 157 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function get_table_name() |
95 | 95 | { |
96 | - return $this->get_table_prefix() . $this->_table_name; |
|
96 | + return $this->get_table_prefix().$this->_table_name; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function get_table_alias() |
107 | 107 | { |
108 | - if (! $this->_table_alias) { |
|
108 | + if ( ! $this->_table_alias) { |
|
109 | 109 | throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
110 | 110 | } |
111 | 111 | return $this->_table_alias; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function get_fully_qualified_pk_column() |
130 | 130 | { |
131 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
131 | + return $this->get_table_alias().".".$this->get_pk_column(); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function get_select_join_limit($limit) |
141 | 141 | { |
142 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
143 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
142 | + $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit; |
|
143 | + return SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 |
@@ -13,51 +13,51 @@ |
||
13 | 13 | class EE_Register_Personal_Data_Exporter implements EEI_Plugin_API |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * FQCN for all privacy policy generators |
|
18 | - * |
|
19 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
20 | - */ |
|
21 | - protected static $exporters = []; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param string $addon_name |
|
26 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
27 | - * OR fully qualified class names of privacy policies |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
31 | - { |
|
32 | - self::$exporters[ $addon_name ] = $setup_args; |
|
33 | - // add to list of modules to be registered |
|
34 | - add_filter( |
|
35 | - 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
36 | - ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
37 | - ); |
|
38 | - return true; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $addon_name |
|
44 | - */ |
|
45 | - public static function deregister(string $addon_name = '') |
|
46 | - { |
|
47 | - unset(self::$exporters[ $addon_name ]); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Adds our personal data exporters registered by add-ons |
|
53 | - * |
|
54 | - * @param string[] $exporters |
|
55 | - * @return string[] |
|
56 | - */ |
|
57 | - public static function addExporters(array $exporters): array |
|
58 | - { |
|
59 | - return array_merge($exporters, ...self::$exporters); |
|
60 | - } |
|
16 | + /** |
|
17 | + * FQCN for all privacy policy generators |
|
18 | + * |
|
19 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
20 | + */ |
|
21 | + protected static $exporters = []; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param string $addon_name |
|
26 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
27 | + * OR fully qualified class names of privacy policies |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
31 | + { |
|
32 | + self::$exporters[ $addon_name ] = $setup_args; |
|
33 | + // add to list of modules to be registered |
|
34 | + add_filter( |
|
35 | + 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
36 | + ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
37 | + ); |
|
38 | + return true; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $addon_name |
|
44 | + */ |
|
45 | + public static function deregister(string $addon_name = '') |
|
46 | + { |
|
47 | + unset(self::$exporters[ $addon_name ]); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Adds our personal data exporters registered by add-ons |
|
53 | + * |
|
54 | + * @param string[] $exporters |
|
55 | + * @return string[] |
|
56 | + */ |
|
57 | + public static function addExporters(array $exporters): array |
|
58 | + { |
|
59 | + return array_merge($exporters, ...self::$exporters); |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | // End of file EE_Register_Personal_Data_Exporter.lib.php |
63 | 63 | // Location: ${NAMESPACE}/EE_Register_Personal_Data_Exporter.lib.php |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register(string $addon_name = '', array $setup_args = []): bool |
31 | 31 | { |
32 | - self::$exporters[ $addon_name ] = $setup_args; |
|
32 | + self::$exporters[$addon_name] = $setup_args; |
|
33 | 33 | // add to list of modules to be registered |
34 | 34 | add_filter( |
35 | 35 | 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public static function deregister(string $addon_name = '') |
46 | 46 | { |
47 | - unset(self::$exporters[ $addon_name ]); |
|
47 | + unset(self::$exporters[$addon_name]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 |
@@ -13,51 +13,51 @@ |
||
13 | 13 | class EE_Register_Personal_Data_Eraser implements EEI_Plugin_API |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * FQCN for all privacy policy generators |
|
18 | - * |
|
19 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
20 | - */ |
|
21 | - protected static $erasers = []; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param string $addon_name |
|
26 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
27 | - * OR fully qualified class names of privacy policies |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
31 | - { |
|
32 | - self::$erasers[ $addon_name ] = $setup_args; |
|
33 | - // add to list of modules to be registered |
|
34 | - add_filter( |
|
35 | - 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
|
36 | - ['EE_Register_Personal_Data_Eraser', 'addErasers'] |
|
37 | - ); |
|
38 | - return true; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $addon_name |
|
44 | - */ |
|
45 | - public static function deregister(string $addon_name = '') |
|
46 | - { |
|
47 | - unset(self::$erasers[ $addon_name ]); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Adds our personal data erasers registered by add-ons |
|
53 | - * |
|
54 | - * @param string[] $erasers |
|
55 | - * @return string[] |
|
56 | - */ |
|
57 | - public static function addErasers(array $erasers): array |
|
58 | - { |
|
59 | - return array_merge($erasers, ...self::$erasers); |
|
60 | - } |
|
16 | + /** |
|
17 | + * FQCN for all privacy policy generators |
|
18 | + * |
|
19 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
20 | + */ |
|
21 | + protected static $erasers = []; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param string $addon_name |
|
26 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
27 | + * OR fully qualified class names of privacy policies |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
31 | + { |
|
32 | + self::$erasers[ $addon_name ] = $setup_args; |
|
33 | + // add to list of modules to be registered |
|
34 | + add_filter( |
|
35 | + 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
|
36 | + ['EE_Register_Personal_Data_Eraser', 'addErasers'] |
|
37 | + ); |
|
38 | + return true; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $addon_name |
|
44 | + */ |
|
45 | + public static function deregister(string $addon_name = '') |
|
46 | + { |
|
47 | + unset(self::$erasers[ $addon_name ]); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Adds our personal data erasers registered by add-ons |
|
53 | + * |
|
54 | + * @param string[] $erasers |
|
55 | + * @return string[] |
|
56 | + */ |
|
57 | + public static function addErasers(array $erasers): array |
|
58 | + { |
|
59 | + return array_merge($erasers, ...self::$erasers); |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | // End of file EE_Register_Personal_Data_Eraser.lib.php |
63 | 63 | // Location: ${NAMESPACE}/EE_Register_Personal_Data_Eraser.lib.php |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register(string $addon_name = '', array $setup_args = []): bool |
31 | 31 | { |
32 | - self::$erasers[ $addon_name ] = $setup_args; |
|
32 | + self::$erasers[$addon_name] = $setup_args; |
|
33 | 33 | // add to list of modules to be registered |
34 | 34 | add_filter( |
35 | 35 | 'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers', |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public static function deregister(string $addon_name = '') |
46 | 46 | { |
47 | - unset(self::$erasers[ $addon_name ]); |
|
47 | + unset(self::$erasers[$addon_name]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 |
@@ -15,100 +15,100 @@ |
||
15 | 15 | class EE_Register_Widget implements EEI_Plugin_API |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Holds values for registered widgets |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected static $_settings = []; |
|
18 | + /** |
|
19 | + * Holds values for registered widgets |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected static $_settings = []; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Method for registering new EED_Widgets |
|
28 | - * |
|
29 | - * @param string $addon_name a unique identifier for this set of widgets |
|
30 | - * @param array $setup_args an array of arguments provided for registering widgets |
|
31 | - * @type array widget_paths an array of full server paths to folders containing any EED_Widgets, or to the |
|
32 | - * EED_Widget files themselves |
|
33 | - * @return bool |
|
34 | - * @throws EE_Error |
|
35 | - * @since 4.3.0 |
|
36 | - */ |
|
37 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
38 | - { |
|
26 | + /** |
|
27 | + * Method for registering new EED_Widgets |
|
28 | + * |
|
29 | + * @param string $addon_name a unique identifier for this set of widgets |
|
30 | + * @param array $setup_args an array of arguments provided for registering widgets |
|
31 | + * @type array widget_paths an array of full server paths to folders containing any EED_Widgets, or to the |
|
32 | + * EED_Widget files themselves |
|
33 | + * @return bool |
|
34 | + * @throws EE_Error |
|
35 | + * @since 4.3.0 |
|
36 | + */ |
|
37 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
38 | + { |
|
39 | 39 | |
40 | - // required fields MUST be present, so let's make sure they are. |
|
41 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) { |
|
42 | - throw new EE_Error( |
|
43 | - __( |
|
44 | - 'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)', |
|
45 | - 'event_espresso' |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
40 | + // required fields MUST be present, so let's make sure they are. |
|
41 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) { |
|
42 | + throw new EE_Error( |
|
43 | + __( |
|
44 | + 'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)', |
|
45 | + 'event_espresso' |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - // make sure we don't register twice |
|
51 | - if (isset(self::$_settings[ $addon_name ])) { |
|
52 | - return true; |
|
53 | - } |
|
50 | + // make sure we don't register twice |
|
51 | + if (isset(self::$_settings[ $addon_name ])) { |
|
52 | + return true; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - // make sure this was called in the right place! |
|
57 | - if ( |
|
58 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
59 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
60 | - ) { |
|
61 | - EE_Error::doing_it_wrong( |
|
62 | - __METHOD__, |
|
63 | - __( |
|
64 | - 'An attempt to register widgets has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - '4.3.0' |
|
68 | - ); |
|
69 | - } |
|
70 | - // setup $_settings array from incoming values. |
|
71 | - self::$_settings[ $addon_name ] = [ |
|
72 | - // array of full server paths to any EED_Widgets used by the widget |
|
73 | - 'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [], |
|
74 | - ]; |
|
75 | - // add to list of widgets to be registered |
|
76 | - add_filter( |
|
77 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
78 | - ['EE_Register_Widget', 'add_widgets'] |
|
79 | - ); |
|
80 | - return true; |
|
81 | - } |
|
56 | + // make sure this was called in the right place! |
|
57 | + if ( |
|
58 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
59 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
60 | + ) { |
|
61 | + EE_Error::doing_it_wrong( |
|
62 | + __METHOD__, |
|
63 | + __( |
|
64 | + 'An attempt to register widgets has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + '4.3.0' |
|
68 | + ); |
|
69 | + } |
|
70 | + // setup $_settings array from incoming values. |
|
71 | + self::$_settings[ $addon_name ] = [ |
|
72 | + // array of full server paths to any EED_Widgets used by the widget |
|
73 | + 'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [], |
|
74 | + ]; |
|
75 | + // add to list of widgets to be registered |
|
76 | + add_filter( |
|
77 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
78 | + ['EE_Register_Widget', 'add_widgets'] |
|
79 | + ); |
|
80 | + return true; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * Filters the list of widgets to add ours. |
|
86 | - * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
87 | - * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...) |
|
88 | - * |
|
89 | - * @param array $widgets_to_register array of paths to all widgets that require registering |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public static function add_widgets(array $widgets_to_register = []): array |
|
93 | - { |
|
94 | - $widget_paths = []; |
|
95 | - foreach (self::$_settings as $settings) { |
|
96 | - $widget_paths[] = $settings['widget_paths']; |
|
97 | - } |
|
98 | - return array_merge($widgets_to_register, ...$widget_paths); |
|
99 | - } |
|
84 | + /** |
|
85 | + * Filters the list of widgets to add ours. |
|
86 | + * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
87 | + * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...) |
|
88 | + * |
|
89 | + * @param array $widgets_to_register array of paths to all widgets that require registering |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public static function add_widgets(array $widgets_to_register = []): array |
|
93 | + { |
|
94 | + $widget_paths = []; |
|
95 | + foreach (self::$_settings as $settings) { |
|
96 | + $widget_paths[] = $settings['widget_paths']; |
|
97 | + } |
|
98 | + return array_merge($widgets_to_register, ...$widget_paths); |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * This deregisters a widget that was previously registered with a specific $addon_name. |
|
104 | - * |
|
105 | - * @param string $addon_name the name for the widget that was previously registered |
|
106 | - * @return void |
|
107 | - * @since 4.3.0 |
|
108 | - * |
|
109 | - */ |
|
110 | - public static function deregister(string $addon_name = '') |
|
111 | - { |
|
112 | - unset(self::$_settings[ $addon_name ]); |
|
113 | - } |
|
102 | + /** |
|
103 | + * This deregisters a widget that was previously registered with a specific $addon_name. |
|
104 | + * |
|
105 | + * @param string $addon_name the name for the widget that was previously registered |
|
106 | + * @return void |
|
107 | + * @since 4.3.0 |
|
108 | + * |
|
109 | + */ |
|
110 | + public static function deregister(string $addon_name = '') |
|
111 | + { |
|
112 | + unset(self::$_settings[ $addon_name ]); |
|
113 | + } |
|
114 | 114 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | // make sure we don't register twice |
51 | - if (isset(self::$_settings[ $addon_name ])) { |
|
51 | + if (isset(self::$_settings[$addon_name])) { |
|
52 | 52 | return true; |
53 | 53 | } |
54 | 54 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | ); |
69 | 69 | } |
70 | 70 | // setup $_settings array from incoming values. |
71 | - self::$_settings[ $addon_name ] = [ |
|
71 | + self::$_settings[$addon_name] = [ |
|
72 | 72 | // array of full server paths to any EED_Widgets used by the widget |
73 | 73 | 'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [], |
74 | 74 | ]; |
@@ -109,6 +109,6 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public static function deregister(string $addon_name = '') |
111 | 111 | { |
112 | - unset(self::$_settings[ $addon_name ]); |
|
112 | + unset(self::$_settings[$addon_name]); |
|
113 | 113 | } |
114 | 114 | } |
@@ -12,174 +12,174 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * holds values for registered messages shortcode libraries |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected static $_ee_messages_shortcode_registry = []; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Helper method for registering a new shortcodes library class for the messages system. |
|
25 | - * |
|
26 | - * Note this is not used for adding shortcodes to existing libraries. It's for registering anything |
|
27 | - * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class. |
|
28 | - * |
|
29 | - * @param string $addon_name What is the name of this shortcode library (e.g. 'question_list'); |
|
30 | - * @param array $setup_args An array of arguments provided for registering the new messages shortcode library. |
|
31 | - * { |
|
32 | - * |
|
33 | - * @type array $autoloadpaths An array of paths to add to the messages autoloader |
|
34 | - * for the new shortcode library class file. |
|
35 | - * @type string $msgr_validator_callback Callback for a method that will register the library with the |
|
36 | - * messenger _validator_config. Optional. |
|
37 | - * @type string $msgr_template_fields_callback Callback for changing adding the _template_fields property for |
|
38 | - * messenger. For example, the shortcode library may add a new |
|
39 | - * field to the message templates. Optional. |
|
40 | - * @type string $valid_shortcodes_callback Callback for message types _valid_shortcodes array setup. |
|
41 | - * Optional. |
|
42 | - * @type array $list_type_shortcodes If there are any specific shortcodes with this message |
|
43 | - * shortcode library that should be considered "list type" |
|
44 | - * then include them in an array. |
|
45 | - * List Type shortcodes are shortcodes that have a corresponding |
|
46 | - * field that indicates how they are parsed. Optional. |
|
47 | - * } |
|
48 | - * @return bool |
|
49 | - * @throws EE_Error |
|
50 | - * @throws EE_Error |
|
51 | - * @since 4.3.0 |
|
52 | - * |
|
53 | - */ |
|
54 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
55 | - { |
|
56 | - |
|
57 | - // required fields MUST be present, so let's make sure they are. |
|
58 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) { |
|
59 | - throw new EE_Error( |
|
60 | - __( |
|
61 | - 'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"', |
|
62 | - 'event_espresso' |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - // make sure we don't register twice |
|
68 | - if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
69 | - return true; |
|
70 | - } |
|
71 | - |
|
72 | - // make sure this was called in the right place! |
|
73 | - if ( |
|
74 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
75 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
76 | - ) { |
|
77 | - EE_Error::doing_it_wrong( |
|
78 | - __METHOD__, |
|
79 | - sprintf( |
|
80 | - __( |
|
81 | - 'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).', |
|
82 | - 'event_espresso' |
|
83 | - ), |
|
84 | - $addon_name |
|
85 | - ), |
|
86 | - '4.3.0' |
|
87 | - ); |
|
88 | - } |
|
89 | - |
|
90 | - self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
91 | - 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
92 | - 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
|
93 | - ? (array) $setup_args['list_type_shortcodes'] : [], |
|
94 | - ]; |
|
95 | - |
|
96 | - // add filters |
|
97 | - add_filter( |
|
98 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
99 | - ['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'], |
|
100 | - 10 |
|
101 | - ); |
|
102 | - |
|
103 | - // add below filters if the required callback is provided. |
|
104 | - if (! empty($setup_args['msgr_validator_callback'])) { |
|
105 | - add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
|
106 | - } |
|
107 | - |
|
108 | - if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
109 | - add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
|
110 | - } |
|
111 | - |
|
112 | - if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
113 | - add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
|
114 | - } |
|
115 | - |
|
116 | - if (! empty($setup_args['list_type_shortcodes'])) { |
|
117 | - add_filter( |
|
118 | - 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
119 | - ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
|
120 | - 10 |
|
121 | - ); |
|
122 | - } |
|
123 | - return true; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * This deregisters any messages shortcode library previously registered with the given name. |
|
129 | - * |
|
130 | - * @param string $addon_name name used to register the shortcode library. |
|
131 | - * @return void |
|
132 | - * @since 4.3.0 |
|
133 | - */ |
|
134 | - public static function deregister(string $addon_name = '') |
|
135 | - { |
|
136 | - unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
142 | - * |
|
143 | - * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
144 | - * @return array |
|
145 | - * @since 4.3.0 |
|
146 | - * |
|
147 | - */ |
|
148 | - public static function register_msgs_autoload_paths(array $paths): array |
|
149 | - { |
|
150 | - $autoload_paths = []; |
|
151 | - if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
152 | - foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
|
153 | - if (empty($st_reg['autoloadpaths'])) { |
|
154 | - continue; |
|
155 | - } |
|
156 | - $autoload_paths[] = $st_reg['autoloadpaths']; |
|
157 | - } |
|
158 | - } |
|
159 | - return array_merge($paths, ...$autoload_paths); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes |
|
165 | - * filter which is used to add additional list type shortcodes. |
|
166 | - * |
|
167 | - * @param array $original_shortcodes |
|
168 | - * @return array Modifications to original shortcodes. |
|
169 | - * @since 4.3.0 |
|
170 | - * |
|
171 | - */ |
|
172 | - public static function register_list_type_shortcodes(array $original_shortcodes): array |
|
173 | - { |
|
174 | - if (empty(self::$_ee_messages_shortcode_registry)) { |
|
175 | - return $original_shortcodes; |
|
176 | - } |
|
177 | - $shortcodes = []; |
|
178 | - foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
|
179 | - if (! empty($sc_reg['list_type_shortcodes'])) { |
|
180 | - $shortcodes[] = $sc_reg['list_type_shortcodes']; |
|
181 | - } |
|
182 | - } |
|
183 | - return array_merge($original_shortcodes, ...$shortcodes); |
|
184 | - } |
|
15 | + /** |
|
16 | + * holds values for registered messages shortcode libraries |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected static $_ee_messages_shortcode_registry = []; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Helper method for registering a new shortcodes library class for the messages system. |
|
25 | + * |
|
26 | + * Note this is not used for adding shortcodes to existing libraries. It's for registering anything |
|
27 | + * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class. |
|
28 | + * |
|
29 | + * @param string $addon_name What is the name of this shortcode library (e.g. 'question_list'); |
|
30 | + * @param array $setup_args An array of arguments provided for registering the new messages shortcode library. |
|
31 | + * { |
|
32 | + * |
|
33 | + * @type array $autoloadpaths An array of paths to add to the messages autoloader |
|
34 | + * for the new shortcode library class file. |
|
35 | + * @type string $msgr_validator_callback Callback for a method that will register the library with the |
|
36 | + * messenger _validator_config. Optional. |
|
37 | + * @type string $msgr_template_fields_callback Callback for changing adding the _template_fields property for |
|
38 | + * messenger. For example, the shortcode library may add a new |
|
39 | + * field to the message templates. Optional. |
|
40 | + * @type string $valid_shortcodes_callback Callback for message types _valid_shortcodes array setup. |
|
41 | + * Optional. |
|
42 | + * @type array $list_type_shortcodes If there are any specific shortcodes with this message |
|
43 | + * shortcode library that should be considered "list type" |
|
44 | + * then include them in an array. |
|
45 | + * List Type shortcodes are shortcodes that have a corresponding |
|
46 | + * field that indicates how they are parsed. Optional. |
|
47 | + * } |
|
48 | + * @return bool |
|
49 | + * @throws EE_Error |
|
50 | + * @throws EE_Error |
|
51 | + * @since 4.3.0 |
|
52 | + * |
|
53 | + */ |
|
54 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
55 | + { |
|
56 | + |
|
57 | + // required fields MUST be present, so let's make sure they are. |
|
58 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) { |
|
59 | + throw new EE_Error( |
|
60 | + __( |
|
61 | + 'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"', |
|
62 | + 'event_espresso' |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + // make sure we don't register twice |
|
68 | + if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
69 | + return true; |
|
70 | + } |
|
71 | + |
|
72 | + // make sure this was called in the right place! |
|
73 | + if ( |
|
74 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
75 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
76 | + ) { |
|
77 | + EE_Error::doing_it_wrong( |
|
78 | + __METHOD__, |
|
79 | + sprintf( |
|
80 | + __( |
|
81 | + 'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).', |
|
82 | + 'event_espresso' |
|
83 | + ), |
|
84 | + $addon_name |
|
85 | + ), |
|
86 | + '4.3.0' |
|
87 | + ); |
|
88 | + } |
|
89 | + |
|
90 | + self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
91 | + 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
92 | + 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
|
93 | + ? (array) $setup_args['list_type_shortcodes'] : [], |
|
94 | + ]; |
|
95 | + |
|
96 | + // add filters |
|
97 | + add_filter( |
|
98 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
99 | + ['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'], |
|
100 | + 10 |
|
101 | + ); |
|
102 | + |
|
103 | + // add below filters if the required callback is provided. |
|
104 | + if (! empty($setup_args['msgr_validator_callback'])) { |
|
105 | + add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
|
106 | + } |
|
107 | + |
|
108 | + if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
109 | + add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
|
110 | + } |
|
111 | + |
|
112 | + if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
113 | + add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
|
114 | + } |
|
115 | + |
|
116 | + if (! empty($setup_args['list_type_shortcodes'])) { |
|
117 | + add_filter( |
|
118 | + 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
119 | + ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
|
120 | + 10 |
|
121 | + ); |
|
122 | + } |
|
123 | + return true; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * This deregisters any messages shortcode library previously registered with the given name. |
|
129 | + * |
|
130 | + * @param string $addon_name name used to register the shortcode library. |
|
131 | + * @return void |
|
132 | + * @since 4.3.0 |
|
133 | + */ |
|
134 | + public static function deregister(string $addon_name = '') |
|
135 | + { |
|
136 | + unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
142 | + * |
|
143 | + * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
144 | + * @return array |
|
145 | + * @since 4.3.0 |
|
146 | + * |
|
147 | + */ |
|
148 | + public static function register_msgs_autoload_paths(array $paths): array |
|
149 | + { |
|
150 | + $autoload_paths = []; |
|
151 | + if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
152 | + foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
|
153 | + if (empty($st_reg['autoloadpaths'])) { |
|
154 | + continue; |
|
155 | + } |
|
156 | + $autoload_paths[] = $st_reg['autoloadpaths']; |
|
157 | + } |
|
158 | + } |
|
159 | + return array_merge($paths, ...$autoload_paths); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes |
|
165 | + * filter which is used to add additional list type shortcodes. |
|
166 | + * |
|
167 | + * @param array $original_shortcodes |
|
168 | + * @return array Modifications to original shortcodes. |
|
169 | + * @since 4.3.0 |
|
170 | + * |
|
171 | + */ |
|
172 | + public static function register_list_type_shortcodes(array $original_shortcodes): array |
|
173 | + { |
|
174 | + if (empty(self::$_ee_messages_shortcode_registry)) { |
|
175 | + return $original_shortcodes; |
|
176 | + } |
|
177 | + $shortcodes = []; |
|
178 | + foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
|
179 | + if (! empty($sc_reg['list_type_shortcodes'])) { |
|
180 | + $shortcodes[] = $sc_reg['list_type_shortcodes']; |
|
181 | + } |
|
182 | + } |
|
183 | + return array_merge($original_shortcodes, ...$shortcodes); |
|
184 | + } |
|
185 | 185 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | // make sure we don't register twice |
68 | - if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
68 | + if (isset(self::$_ee_messages_shortcode_registry[$addon_name])) { |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
90 | - self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
90 | + self::$_ee_messages_shortcode_registry[$addon_name] = [ |
|
91 | 91 | 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
92 | 92 | 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
93 | 93 | ? (array) $setup_args['list_type_shortcodes'] : [], |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | ); |
102 | 102 | |
103 | 103 | // add below filters if the required callback is provided. |
104 | - if (! empty($setup_args['msgr_validator_callback'])) { |
|
104 | + if ( ! empty($setup_args['msgr_validator_callback'])) { |
|
105 | 105 | add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
106 | 106 | } |
107 | 107 | |
108 | - if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
108 | + if ( ! empty($setup_args['msgr_template_fields_callback'])) { |
|
109 | 109 | add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
110 | 110 | } |
111 | 111 | |
112 | - if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
112 | + if ( ! empty($setup_args['valid_shortcodes_callback'])) { |
|
113 | 113 | add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
114 | 114 | } |
115 | 115 | |
116 | - if (! empty($setup_args['list_type_shortcodes'])) { |
|
116 | + if ( ! empty($setup_args['list_type_shortcodes'])) { |
|
117 | 117 | add_filter( |
118 | 118 | 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
119 | 119 | ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public static function deregister(string $addon_name = '') |
135 | 135 | { |
136 | - unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
136 | + unset(self::$_ee_messages_shortcode_registry[$addon_name]); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public static function register_msgs_autoload_paths(array $paths): array |
149 | 149 | { |
150 | 150 | $autoload_paths = []; |
151 | - if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
151 | + if ( ! empty(self::$_ee_messages_shortcode_registry)) { |
|
152 | 152 | foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
153 | 153 | if (empty($st_reg['autoloadpaths'])) { |
154 | 154 | continue; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | $shortcodes = []; |
178 | 178 | foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
179 | - if (! empty($sc_reg['list_type_shortcodes'])) { |
|
179 | + if ( ! empty($sc_reg['list_type_shortcodes'])) { |
|
180 | 180 | $shortcodes[] = $sc_reg['list_type_shortcodes']; |
181 | 181 | } |
182 | 182 | } |
@@ -12,140 +12,140 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Holds registered EE_Admin_Pages |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected static $_ee_admin_page_registry = []; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * The purpose of this method is to provide an easy way for addons to register their admin pages (using the EE |
|
25 | - * Admin Page loader system). |
|
26 | - * |
|
27 | - * @param string $addon_name This string represents the basename of the Admin |
|
28 | - * Page init. The init file must use this basename |
|
29 | - * in its name and class (i.e. |
|
30 | - * {page_basename}_Admin_Page_Init.core.php). |
|
31 | - * @param array $setup_args { An array of configuration options |
|
32 | - * that will be used in different circumstances |
|
33 | - * |
|
34 | - * @type string $page_path This is the path where the registered admin pages |
|
35 | - * reside ( used to setup autoloaders). |
|
36 | - * |
|
37 | - * } |
|
38 | - * @return bool |
|
39 | - * @throws EE_Error |
|
40 | - * @since 4.3.0 |
|
41 | - * |
|
42 | - */ |
|
43 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
44 | - { |
|
45 | - |
|
46 | - // check that an admin_page has not already been registered with that name |
|
47 | - if (isset(self::$_ee_admin_page_registry[ $addon_name ])) { |
|
48 | - throw new EE_Error( |
|
49 | - sprintf( |
|
50 | - __( |
|
51 | - 'An Admin Page with the name "%s" has already been registered and each Admin Page requires a unique name.', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - $addon_name |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - // required fields MUST be present, so let's make sure they are. |
|
60 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['page_path'])) { |
|
61 | - throw new EE_Error( |
|
62 | - __( |
|
63 | - 'In order to register an Admin Page with EE_Register_Admin_Page::register(), you must include the "page_basename" (the class name of the page), and an array containing the following keys: "page_path" (the path where the registered admin pages reside)', |
|
64 | - 'event_espresso' |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - // make sure we don't register twice |
|
70 | - if (isset(self::$_ee_admin_page_registry[ $addon_name ])) { |
|
71 | - return true; |
|
72 | - } |
|
73 | - |
|
74 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
75 | - EE_Error::doing_it_wrong( |
|
76 | - __METHOD__, |
|
77 | - sprintf( |
|
78 | - __( |
|
79 | - 'An attempt was made to register "%s" as an EE Admin page has failed because it was not registered at the correct time. Please use the "AHEE__EE_Admin__loaded" hook to register Admin pages.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - $addon_name |
|
83 | - ), |
|
84 | - '4.3' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - // add incoming stuff to our registry property |
|
89 | - self::$_ee_admin_page_registry[ $addon_name ] = [ |
|
90 | - 'page_path' => $setup_args['page_path'], |
|
91 | - 'config' => $setup_args, |
|
92 | - ]; |
|
93 | - |
|
94 | - // add filters |
|
95 | - |
|
96 | - add_filter( |
|
97 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
98 | - ['EE_Register_Admin_Page', 'set_page_basename'], |
|
99 | - 10 |
|
100 | - ); |
|
101 | - add_filter('FHEE__EEH_Autoloader__load_admin_core', ['EE_Register_Admin_Page', 'set_page_path'], 10); |
|
102 | - return true; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * This deregisters a EE_Admin page that is already registered. Note, this MUST be loaded after the |
|
108 | - * page being deregistered is loaded. |
|
109 | - * |
|
110 | - * @param string $addon_name Use whatever string was used to register the admin page. |
|
111 | - * @return void |
|
112 | - * @since 4.3.0 |
|
113 | - * |
|
114 | - */ |
|
115 | - public static function deregister(string $addon_name = '') |
|
116 | - { |
|
117 | - unset(self::$_ee_admin_page_registry[ $addon_name ]); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * set_page_basename |
|
123 | - * |
|
124 | - * @param array $installed_refs |
|
125 | - * @return mixed |
|
126 | - */ |
|
127 | - public static function set_page_basename(array $installed_refs): array |
|
128 | - { |
|
129 | - if (! empty(self::$_ee_admin_page_registry)) { |
|
130 | - foreach (self::$_ee_admin_page_registry as $basename => $args) { |
|
131 | - $installed_refs[ $basename ] = $args['page_path']; |
|
132 | - } |
|
133 | - } |
|
134 | - return $installed_refs; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * set_page_path |
|
140 | - * |
|
141 | - * @param array $paths |
|
142 | - * @return mixed |
|
143 | - */ |
|
144 | - public static function set_page_path(array $paths): array |
|
145 | - { |
|
146 | - foreach (self::$_ee_admin_page_registry as $basename => $args) { |
|
147 | - $paths[ $basename ] = $args['page_path']; |
|
148 | - } |
|
149 | - return $paths; |
|
150 | - } |
|
15 | + /** |
|
16 | + * Holds registered EE_Admin_Pages |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected static $_ee_admin_page_registry = []; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * The purpose of this method is to provide an easy way for addons to register their admin pages (using the EE |
|
25 | + * Admin Page loader system). |
|
26 | + * |
|
27 | + * @param string $addon_name This string represents the basename of the Admin |
|
28 | + * Page init. The init file must use this basename |
|
29 | + * in its name and class (i.e. |
|
30 | + * {page_basename}_Admin_Page_Init.core.php). |
|
31 | + * @param array $setup_args { An array of configuration options |
|
32 | + * that will be used in different circumstances |
|
33 | + * |
|
34 | + * @type string $page_path This is the path where the registered admin pages |
|
35 | + * reside ( used to setup autoloaders). |
|
36 | + * |
|
37 | + * } |
|
38 | + * @return bool |
|
39 | + * @throws EE_Error |
|
40 | + * @since 4.3.0 |
|
41 | + * |
|
42 | + */ |
|
43 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
44 | + { |
|
45 | + |
|
46 | + // check that an admin_page has not already been registered with that name |
|
47 | + if (isset(self::$_ee_admin_page_registry[ $addon_name ])) { |
|
48 | + throw new EE_Error( |
|
49 | + sprintf( |
|
50 | + __( |
|
51 | + 'An Admin Page with the name "%s" has already been registered and each Admin Page requires a unique name.', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + $addon_name |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + // required fields MUST be present, so let's make sure they are. |
|
60 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['page_path'])) { |
|
61 | + throw new EE_Error( |
|
62 | + __( |
|
63 | + 'In order to register an Admin Page with EE_Register_Admin_Page::register(), you must include the "page_basename" (the class name of the page), and an array containing the following keys: "page_path" (the path where the registered admin pages reside)', |
|
64 | + 'event_espresso' |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + // make sure we don't register twice |
|
70 | + if (isset(self::$_ee_admin_page_registry[ $addon_name ])) { |
|
71 | + return true; |
|
72 | + } |
|
73 | + |
|
74 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
75 | + EE_Error::doing_it_wrong( |
|
76 | + __METHOD__, |
|
77 | + sprintf( |
|
78 | + __( |
|
79 | + 'An attempt was made to register "%s" as an EE Admin page has failed because it was not registered at the correct time. Please use the "AHEE__EE_Admin__loaded" hook to register Admin pages.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + $addon_name |
|
83 | + ), |
|
84 | + '4.3' |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + // add incoming stuff to our registry property |
|
89 | + self::$_ee_admin_page_registry[ $addon_name ] = [ |
|
90 | + 'page_path' => $setup_args['page_path'], |
|
91 | + 'config' => $setup_args, |
|
92 | + ]; |
|
93 | + |
|
94 | + // add filters |
|
95 | + |
|
96 | + add_filter( |
|
97 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
98 | + ['EE_Register_Admin_Page', 'set_page_basename'], |
|
99 | + 10 |
|
100 | + ); |
|
101 | + add_filter('FHEE__EEH_Autoloader__load_admin_core', ['EE_Register_Admin_Page', 'set_page_path'], 10); |
|
102 | + return true; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * This deregisters a EE_Admin page that is already registered. Note, this MUST be loaded after the |
|
108 | + * page being deregistered is loaded. |
|
109 | + * |
|
110 | + * @param string $addon_name Use whatever string was used to register the admin page. |
|
111 | + * @return void |
|
112 | + * @since 4.3.0 |
|
113 | + * |
|
114 | + */ |
|
115 | + public static function deregister(string $addon_name = '') |
|
116 | + { |
|
117 | + unset(self::$_ee_admin_page_registry[ $addon_name ]); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * set_page_basename |
|
123 | + * |
|
124 | + * @param array $installed_refs |
|
125 | + * @return mixed |
|
126 | + */ |
|
127 | + public static function set_page_basename(array $installed_refs): array |
|
128 | + { |
|
129 | + if (! empty(self::$_ee_admin_page_registry)) { |
|
130 | + foreach (self::$_ee_admin_page_registry as $basename => $args) { |
|
131 | + $installed_refs[ $basename ] = $args['page_path']; |
|
132 | + } |
|
133 | + } |
|
134 | + return $installed_refs; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * set_page_path |
|
140 | + * |
|
141 | + * @param array $paths |
|
142 | + * @return mixed |
|
143 | + */ |
|
144 | + public static function set_page_path(array $paths): array |
|
145 | + { |
|
146 | + foreach (self::$_ee_admin_page_registry as $basename => $args) { |
|
147 | + $paths[ $basename ] = $args['page_path']; |
|
148 | + } |
|
149 | + return $paths; |
|
150 | + } |
|
151 | 151 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | |
46 | 46 | // check that an admin_page has not already been registered with that name |
47 | - if (isset(self::$_ee_admin_page_registry[ $addon_name ])) { |
|
47 | + if (isset(self::$_ee_admin_page_registry[$addon_name])) { |
|
48 | 48 | throw new EE_Error( |
49 | 49 | sprintf( |
50 | 50 | __( |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | // make sure we don't register twice |
70 | - if (isset(self::$_ee_admin_page_registry[ $addon_name ])) { |
|
70 | + if (isset(self::$_ee_admin_page_registry[$addon_name])) { |
|
71 | 71 | return true; |
72 | 72 | } |
73 | 73 | |
74 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
74 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
75 | 75 | EE_Error::doing_it_wrong( |
76 | 76 | __METHOD__, |
77 | 77 | sprintf( |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | // add incoming stuff to our registry property |
89 | - self::$_ee_admin_page_registry[ $addon_name ] = [ |
|
89 | + self::$_ee_admin_page_registry[$addon_name] = [ |
|
90 | 90 | 'page_path' => $setup_args['page_path'], |
91 | 91 | 'config' => $setup_args, |
92 | 92 | ]; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public static function deregister(string $addon_name = '') |
116 | 116 | { |
117 | - unset(self::$_ee_admin_page_registry[ $addon_name ]); |
|
117 | + unset(self::$_ee_admin_page_registry[$addon_name]); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function set_page_basename(array $installed_refs): array |
128 | 128 | { |
129 | - if (! empty(self::$_ee_admin_page_registry)) { |
|
129 | + if ( ! empty(self::$_ee_admin_page_registry)) { |
|
130 | 130 | foreach (self::$_ee_admin_page_registry as $basename => $args) { |
131 | - $installed_refs[ $basename ] = $args['page_path']; |
|
131 | + $installed_refs[$basename] = $args['page_path']; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | return $installed_refs; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | public static function set_page_path(array $paths): array |
145 | 145 | { |
146 | 146 | foreach (self::$_ee_admin_page_registry as $basename => $args) { |
147 | - $paths[ $basename ] = $args['page_path']; |
|
147 | + $paths[$basename] = $args['page_path']; |
|
148 | 148 | } |
149 | 149 | return $paths; |
150 | 150 | } |
@@ -15,105 +15,105 @@ |
||
15 | 15 | class EE_Register_Data_Migration_Scripts implements EEI_Plugin_API |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Holds values for registered DMSs |
|
20 | - * |
|
21 | - * @var array[][] |
|
22 | - */ |
|
23 | - protected static $_settings = []; |
|
18 | + /** |
|
19 | + * Holds values for registered DMSs |
|
20 | + * |
|
21 | + * @var array[][] |
|
22 | + */ |
|
23 | + protected static $_settings = []; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Method for registering new Data Migration Scripts |
|
28 | - * |
|
29 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
30 | - * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
31 | - * @param array $setup_args { |
|
32 | - * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
33 | - * } |
|
34 | - * @return bool |
|
35 | - * @throws EE_Error |
|
36 | - * @since 4.3.0 |
|
37 | - * @since 4.3.0 |
|
38 | - */ |
|
39 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
40 | - { |
|
41 | - // required fields MUST be present, so let's make sure they are. |
|
42 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
43 | - throw new EE_Error( |
|
44 | - esc_html__( |
|
45 | - 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
46 | - 'event_espresso' |
|
47 | - ) |
|
48 | - ); |
|
49 | - } |
|
50 | - // make sure we don't register twice |
|
51 | - if (isset(self::$_settings[ $addon_name ])) { |
|
52 | - return true; |
|
53 | - } |
|
54 | - // make sure this was called in the right place! |
|
55 | - if ( |
|
56 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
57 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
58 | - ) { |
|
59 | - EE_Error::doing_it_wrong( |
|
60 | - __METHOD__, |
|
61 | - esc_html__( |
|
62 | - 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - '4.3.0' |
|
66 | - ); |
|
67 | - } |
|
68 | - // setup $_settings array from incoming values. |
|
69 | - self::$_settings[ $addon_name ] = ['dms_paths' => (array) $setup_args['dms_paths']]; |
|
70 | - // setup DMS |
|
71 | - $filters_set = has_filter( |
|
72 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
73 | - ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
74 | - ); |
|
75 | - if (! $filters_set) { |
|
76 | - add_filter( |
|
77 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
78 | - ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
79 | - ); |
|
80 | - } |
|
81 | - return true; |
|
82 | - } |
|
26 | + /** |
|
27 | + * Method for registering new Data Migration Scripts |
|
28 | + * |
|
29 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
30 | + * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
31 | + * @param array $setup_args { |
|
32 | + * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
33 | + * } |
|
34 | + * @return bool |
|
35 | + * @throws EE_Error |
|
36 | + * @since 4.3.0 |
|
37 | + * @since 4.3.0 |
|
38 | + */ |
|
39 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
40 | + { |
|
41 | + // required fields MUST be present, so let's make sure they are. |
|
42 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
43 | + throw new EE_Error( |
|
44 | + esc_html__( |
|
45 | + 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
46 | + 'event_espresso' |
|
47 | + ) |
|
48 | + ); |
|
49 | + } |
|
50 | + // make sure we don't register twice |
|
51 | + if (isset(self::$_settings[ $addon_name ])) { |
|
52 | + return true; |
|
53 | + } |
|
54 | + // make sure this was called in the right place! |
|
55 | + if ( |
|
56 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
57 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
58 | + ) { |
|
59 | + EE_Error::doing_it_wrong( |
|
60 | + __METHOD__, |
|
61 | + esc_html__( |
|
62 | + 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + '4.3.0' |
|
66 | + ); |
|
67 | + } |
|
68 | + // setup $_settings array from incoming values. |
|
69 | + self::$_settings[ $addon_name ] = ['dms_paths' => (array) $setup_args['dms_paths']]; |
|
70 | + // setup DMS |
|
71 | + $filters_set = has_filter( |
|
72 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
73 | + ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
74 | + ); |
|
75 | + if (! $filters_set) { |
|
76 | + add_filter( |
|
77 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
78 | + ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
79 | + ); |
|
80 | + } |
|
81 | + return true; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * @param array $dms_paths |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public static function add_data_migration_script_folders(array $dms_paths = []): array |
|
90 | - { |
|
91 | - foreach (self::$_settings as $addon_name => $settings) { |
|
92 | - $wildcards = 0; |
|
93 | - foreach ($settings['dms_paths'] as $dms_path) { |
|
94 | - // since we are using the addon name for the array key |
|
95 | - // we need to ensure that the key is unique, |
|
96 | - // so if for some reason an addon has multiple dms paths, |
|
97 | - // we append one or more * to the classname |
|
98 | - // which will get stripped out later on |
|
99 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
100 | - $wildcards++; |
|
101 | - } |
|
102 | - } |
|
103 | - return $dms_paths; |
|
104 | - } |
|
85 | + /** |
|
86 | + * @param array $dms_paths |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public static function add_data_migration_script_folders(array $dms_paths = []): array |
|
90 | + { |
|
91 | + foreach (self::$_settings as $addon_name => $settings) { |
|
92 | + $wildcards = 0; |
|
93 | + foreach ($settings['dms_paths'] as $dms_path) { |
|
94 | + // since we are using the addon name for the array key |
|
95 | + // we need to ensure that the key is unique, |
|
96 | + // so if for some reason an addon has multiple dms paths, |
|
97 | + // we append one or more * to the classname |
|
98 | + // which will get stripped out later on |
|
99 | + $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
100 | + $wildcards++; |
|
101 | + } |
|
102 | + } |
|
103 | + return $dms_paths; |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
109 | - * |
|
110 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
111 | - * @return void |
|
112 | - * @since 4.3.0 |
|
113 | - * @since 4.3.0 |
|
114 | - */ |
|
115 | - public static function deregister(string $addon_name = '') |
|
116 | - { |
|
117 | - unset(self::$_settings[ $addon_name ]); |
|
118 | - } |
|
107 | + /** |
|
108 | + * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
109 | + * |
|
110 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
111 | + * @return void |
|
112 | + * @since 4.3.0 |
|
113 | + * @since 4.3.0 |
|
114 | + */ |
|
115 | + public static function deregister(string $addon_name = '') |
|
116 | + { |
|
117 | + unset(self::$_settings[ $addon_name ]); |
|
118 | + } |
|
119 | 119 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | ); |
49 | 49 | } |
50 | 50 | // make sure we don't register twice |
51 | - if (isset(self::$_settings[ $addon_name ])) { |
|
51 | + if (isset(self::$_settings[$addon_name])) { |
|
52 | 52 | return true; |
53 | 53 | } |
54 | 54 | // make sure this was called in the right place! |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | ); |
67 | 67 | } |
68 | 68 | // setup $_settings array from incoming values. |
69 | - self::$_settings[ $addon_name ] = ['dms_paths' => (array) $setup_args['dms_paths']]; |
|
69 | + self::$_settings[$addon_name] = ['dms_paths' => (array) $setup_args['dms_paths']]; |
|
70 | 70 | // setup DMS |
71 | 71 | $filters_set = has_filter( |
72 | 72 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
73 | 73 | ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
74 | 74 | ); |
75 | - if (! $filters_set) { |
|
75 | + if ( ! $filters_set) { |
|
76 | 76 | add_filter( |
77 | 77 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
78 | 78 | ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | // so if for some reason an addon has multiple dms paths, |
97 | 97 | // we append one or more * to the classname |
98 | 98 | // which will get stripped out later on |
99 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
99 | + $dms_paths[$addon_name.str_repeat('*', $wildcards)] = $dms_path; |
|
100 | 100 | $wildcards++; |
101 | 101 | } |
102 | 102 | } |
@@ -114,6 +114,6 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public static function deregister(string $addon_name = '') |
116 | 116 | { |
117 | - unset(self::$_settings[ $addon_name ]); |
|
117 | + unset(self::$_settings[$addon_name]); |
|
118 | 118 | } |
119 | 119 | } |
@@ -15,217 +15,217 @@ |
||
15 | 15 | class EE_Register_Capabilities implements EEI_Plugin_API |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Holds the settings for a specific registration. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected static $_registry = []; |
|
18 | + /** |
|
19 | + * Holds the settings for a specific registration. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected static $_registry = []; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Used to register capability items with EE core. |
|
28 | - * |
|
29 | - * @param string $addon_name usually will be a class name |
|
30 | - * that references capability |
|
31 | - * related items setup for |
|
32 | - * something. |
|
33 | - * @param array $setup_args { |
|
34 | - * An array of items related to |
|
35 | - * registering capabilities. |
|
36 | - * @type array $capabilities An array mapping capability |
|
37 | - * strings to core WP Role. |
|
38 | - * Something like: array( |
|
39 | - * 'administrator' => array( |
|
40 | - * 'read_cap', 'edit_cap', |
|
41 | - * 'delete_cap'), |
|
42 | - * 'author' => |
|
43 | - * array( 'read_cap' ) |
|
44 | - * ). |
|
45 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
46 | - * @return bool |
|
47 | - * @throws EE_Error |
|
48 | - * @since 4.5.0 |
|
49 | - * @see EE_Capabilities.php for php docs on these objects. |
|
50 | - * Should be indexed by the |
|
51 | - * classname for the capability |
|
52 | - * map and values representing |
|
53 | - * the arguments for the map. |
|
54 | - * } |
|
55 | - */ |
|
56 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
57 | - { |
|
58 | - // required fields MUST be present, so let's make sure they are. |
|
59 | - if ($addon_name === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
60 | - throw new EE_Error( |
|
61 | - __( |
|
62 | - 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
63 | - 'event_espresso' |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
67 | - // make sure we don't register twice |
|
68 | - if (isset(self::$_registry[ $addon_name ])) { |
|
69 | - return true; |
|
70 | - } |
|
71 | - // make sure this is not registered too late or too early. |
|
72 | - if ( |
|
73 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
74 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
75 | - ) { |
|
76 | - EE_Error::doing_it_wrong( |
|
77 | - __METHOD__, |
|
78 | - sprintf( |
|
79 | - __( |
|
80 | - '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - $addon_name |
|
84 | - ), |
|
85 | - '4.5.0' |
|
86 | - ); |
|
87 | - return false; |
|
88 | - } |
|
89 | - // some preliminary sanitization and setting to the $_registry property |
|
90 | - self::$_registry[ $addon_name ] = [ |
|
91 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
92 | - ? $setup_args['capabilities'] |
|
93 | - : [], |
|
94 | - 'cap_maps' => $setup_args['capability_maps'] ?? [], |
|
95 | - ]; |
|
96 | - // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
97 | - add_filter( |
|
98 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
99 | - ['EE_Register_Capabilities', 'register_capabilities'] |
|
100 | - ); |
|
101 | - // add filter for cap maps |
|
102 | - add_filter( |
|
103 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
104 | - ['EE_Register_Capabilities', 'register_cap_maps'] |
|
105 | - ); |
|
106 | - return true; |
|
107 | - } |
|
26 | + /** |
|
27 | + * Used to register capability items with EE core. |
|
28 | + * |
|
29 | + * @param string $addon_name usually will be a class name |
|
30 | + * that references capability |
|
31 | + * related items setup for |
|
32 | + * something. |
|
33 | + * @param array $setup_args { |
|
34 | + * An array of items related to |
|
35 | + * registering capabilities. |
|
36 | + * @type array $capabilities An array mapping capability |
|
37 | + * strings to core WP Role. |
|
38 | + * Something like: array( |
|
39 | + * 'administrator' => array( |
|
40 | + * 'read_cap', 'edit_cap', |
|
41 | + * 'delete_cap'), |
|
42 | + * 'author' => |
|
43 | + * array( 'read_cap' ) |
|
44 | + * ). |
|
45 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
46 | + * @return bool |
|
47 | + * @throws EE_Error |
|
48 | + * @since 4.5.0 |
|
49 | + * @see EE_Capabilities.php for php docs on these objects. |
|
50 | + * Should be indexed by the |
|
51 | + * classname for the capability |
|
52 | + * map and values representing |
|
53 | + * the arguments for the map. |
|
54 | + * } |
|
55 | + */ |
|
56 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
57 | + { |
|
58 | + // required fields MUST be present, so let's make sure they are. |
|
59 | + if ($addon_name === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
60 | + throw new EE_Error( |
|
61 | + __( |
|
62 | + 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
63 | + 'event_espresso' |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | + // make sure we don't register twice |
|
68 | + if (isset(self::$_registry[ $addon_name ])) { |
|
69 | + return true; |
|
70 | + } |
|
71 | + // make sure this is not registered too late or too early. |
|
72 | + if ( |
|
73 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
74 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
75 | + ) { |
|
76 | + EE_Error::doing_it_wrong( |
|
77 | + __METHOD__, |
|
78 | + sprintf( |
|
79 | + __( |
|
80 | + '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + $addon_name |
|
84 | + ), |
|
85 | + '4.5.0' |
|
86 | + ); |
|
87 | + return false; |
|
88 | + } |
|
89 | + // some preliminary sanitization and setting to the $_registry property |
|
90 | + self::$_registry[ $addon_name ] = [ |
|
91 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
92 | + ? $setup_args['capabilities'] |
|
93 | + : [], |
|
94 | + 'cap_maps' => $setup_args['capability_maps'] ?? [], |
|
95 | + ]; |
|
96 | + // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
97 | + add_filter( |
|
98 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
99 | + ['EE_Register_Capabilities', 'register_capabilities'] |
|
100 | + ); |
|
101 | + // add filter for cap maps |
|
102 | + add_filter( |
|
103 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
104 | + ['EE_Register_Capabilities', 'register_cap_maps'] |
|
105 | + ); |
|
106 | + return true; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
112 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
113 | - * registration ensures that new capabilities are added to existing roles. |
|
114 | - * |
|
115 | - * @param array $incoming_caps The original caps map. |
|
116 | - * @return array merged in new caps. |
|
117 | - */ |
|
118 | - public static function register_capabilities(array $incoming_caps): array |
|
119 | - { |
|
120 | - $caps = []; |
|
121 | - foreach (self::$_registry as $caps_and_cap_map) { |
|
122 | - $caps[] = $caps_and_cap_map['caps']; |
|
123 | - } |
|
124 | - return array_merge_recursive($incoming_caps, ...$caps); |
|
125 | - } |
|
110 | + /** |
|
111 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
112 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
113 | + * registration ensures that new capabilities are added to existing roles. |
|
114 | + * |
|
115 | + * @param array $incoming_caps The original caps map. |
|
116 | + * @return array merged in new caps. |
|
117 | + */ |
|
118 | + public static function register_capabilities(array $incoming_caps): array |
|
119 | + { |
|
120 | + $caps = []; |
|
121 | + foreach (self::$_registry as $caps_and_cap_map) { |
|
122 | + $caps[] = $caps_and_cap_map['caps']; |
|
123 | + } |
|
124 | + return array_merge_recursive($incoming_caps, ...$caps); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
130 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
131 | - * |
|
132 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
133 | - * @return EE_Meta_Capability_Map[] |
|
134 | - * @throws EE_Error |
|
135 | - * @since 4.5.0 |
|
136 | - */ |
|
137 | - public static function register_cap_maps(array $cap_maps): array |
|
138 | - { |
|
139 | - // loop through and instantiate cap maps. |
|
140 | - foreach (self::$_registry as $addon_name => $setup) { |
|
141 | - if (! isset($setup['cap_maps'])) { |
|
142 | - continue; |
|
143 | - } |
|
144 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
128 | + /** |
|
129 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
130 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
131 | + * |
|
132 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
133 | + * @return EE_Meta_Capability_Map[] |
|
134 | + * @throws EE_Error |
|
135 | + * @since 4.5.0 |
|
136 | + */ |
|
137 | + public static function register_cap_maps(array $cap_maps): array |
|
138 | + { |
|
139 | + // loop through and instantiate cap maps. |
|
140 | + foreach (self::$_registry as $addon_name => $setup) { |
|
141 | + if (! isset($setup['cap_maps'])) { |
|
142 | + continue; |
|
143 | + } |
|
144 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
145 | 145 | |
146 | - /** |
|
147 | - * account for cases where capability maps may be indexed |
|
148 | - * numerically to allow for the same map class to be utilized |
|
149 | - * In those cases, maps will be setup in an array like: |
|
150 | - * array( |
|
151 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
152 | - * 'ee_edit_cap', array( 'Object_Name', |
|
153 | - * 'ee_edit_published_cap', |
|
154 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
155 | - * ) ) |
|
156 | - * 1 => ... |
|
157 | - * ) |
|
158 | - * instead of: |
|
159 | - * array( |
|
160 | - * 'EE_Meta_Capability' => array( |
|
161 | - * 'ee_edit_cap', array( 'Object_Name', |
|
162 | - * 'ee_edit_published_cap', |
|
163 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
164 | - * ), |
|
165 | - * ... |
|
166 | - * ) |
|
167 | - */ |
|
168 | - if (is_numeric($cap_class)) { |
|
169 | - $cap_class = key($args); |
|
170 | - $args = $args[ $cap_class ]; |
|
171 | - } |
|
146 | + /** |
|
147 | + * account for cases where capability maps may be indexed |
|
148 | + * numerically to allow for the same map class to be utilized |
|
149 | + * In those cases, maps will be setup in an array like: |
|
150 | + * array( |
|
151 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
152 | + * 'ee_edit_cap', array( 'Object_Name', |
|
153 | + * 'ee_edit_published_cap', |
|
154 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
155 | + * ) ) |
|
156 | + * 1 => ... |
|
157 | + * ) |
|
158 | + * instead of: |
|
159 | + * array( |
|
160 | + * 'EE_Meta_Capability' => array( |
|
161 | + * 'ee_edit_cap', array( 'Object_Name', |
|
162 | + * 'ee_edit_published_cap', |
|
163 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
164 | + * ), |
|
165 | + * ... |
|
166 | + * ) |
|
167 | + */ |
|
168 | + if (is_numeric($cap_class)) { |
|
169 | + $cap_class = key($args); |
|
170 | + $args = $args[ $cap_class ]; |
|
171 | + } |
|
172 | 172 | |
173 | - if (! class_exists($cap_class)) { |
|
174 | - throw new EE_Error( |
|
175 | - sprintf( |
|
176 | - __( |
|
177 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
178 | - 'event_espresso' |
|
179 | - ), |
|
180 | - $addon_name |
|
181 | - ) |
|
182 | - ); |
|
183 | - } |
|
173 | + if (! class_exists($cap_class)) { |
|
174 | + throw new EE_Error( |
|
175 | + sprintf( |
|
176 | + __( |
|
177 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
178 | + 'event_espresso' |
|
179 | + ), |
|
180 | + $addon_name |
|
181 | + ) |
|
182 | + ); |
|
183 | + } |
|
184 | 184 | |
185 | - if (count($args) !== 2) { |
|
186 | - throw new EE_Error( |
|
187 | - sprintf( |
|
188 | - __( |
|
189 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
190 | - 'event_espresso' |
|
191 | - ), |
|
192 | - $addon_name |
|
193 | - ) |
|
194 | - ); |
|
195 | - } |
|
196 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
197 | - } |
|
198 | - } |
|
199 | - return $cap_maps; |
|
200 | - } |
|
185 | + if (count($args) !== 2) { |
|
186 | + throw new EE_Error( |
|
187 | + sprintf( |
|
188 | + __( |
|
189 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
190 | + 'event_espresso' |
|
191 | + ), |
|
192 | + $addon_name |
|
193 | + ) |
|
194 | + ); |
|
195 | + } |
|
196 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
197 | + } |
|
198 | + } |
|
199 | + return $cap_maps; |
|
200 | + } |
|
201 | 201 | |
202 | 202 | |
203 | - /** |
|
204 | - * @param string $addon_name |
|
205 | - * @throws InvalidArgumentException |
|
206 | - * @throws InvalidDataTypeException |
|
207 | - * @throws InvalidInterfaceException |
|
208 | - */ |
|
209 | - public static function deregister(string $addon_name = '') |
|
210 | - { |
|
211 | - if (! empty(self::$_registry[ $addon_name ])) { |
|
212 | - if (! empty(self::$_registry[ $addon_name ]['caps'])) { |
|
213 | - // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
214 | - $caps_to_remove = self::$_registry[ $addon_name ]['caps']; |
|
215 | - if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
216 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
217 | - $capabilities->removeCaps($caps_to_remove); |
|
218 | - } else { |
|
219 | - add_action( |
|
220 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
221 | - function () use ($caps_to_remove) { |
|
222 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
223 | - $capabilities->removeCaps($caps_to_remove); |
|
224 | - } |
|
225 | - ); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - unset(self::$_registry[ $addon_name ]); |
|
230 | - } |
|
203 | + /** |
|
204 | + * @param string $addon_name |
|
205 | + * @throws InvalidArgumentException |
|
206 | + * @throws InvalidDataTypeException |
|
207 | + * @throws InvalidInterfaceException |
|
208 | + */ |
|
209 | + public static function deregister(string $addon_name = '') |
|
210 | + { |
|
211 | + if (! empty(self::$_registry[ $addon_name ])) { |
|
212 | + if (! empty(self::$_registry[ $addon_name ]['caps'])) { |
|
213 | + // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
214 | + $caps_to_remove = self::$_registry[ $addon_name ]['caps']; |
|
215 | + if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
216 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
217 | + $capabilities->removeCaps($caps_to_remove); |
|
218 | + } else { |
|
219 | + add_action( |
|
220 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
221 | + function () use ($caps_to_remove) { |
|
222 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
223 | + $capabilities->removeCaps($caps_to_remove); |
|
224 | + } |
|
225 | + ); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + unset(self::$_registry[ $addon_name ]); |
|
230 | + } |
|
231 | 231 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ); |
66 | 66 | } |
67 | 67 | // make sure we don't register twice |
68 | - if (isset(self::$_registry[ $addon_name ])) { |
|
68 | + if (isset(self::$_registry[$addon_name])) { |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | // make sure this is not registered too late or too early. |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | // some preliminary sanitization and setting to the $_registry property |
90 | - self::$_registry[ $addon_name ] = [ |
|
90 | + self::$_registry[$addon_name] = [ |
|
91 | 91 | 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
92 | 92 | ? $setup_args['capabilities'] |
93 | 93 | : [], |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | { |
139 | 139 | // loop through and instantiate cap maps. |
140 | 140 | foreach (self::$_registry as $addon_name => $setup) { |
141 | - if (! isset($setup['cap_maps'])) { |
|
141 | + if ( ! isset($setup['cap_maps'])) { |
|
142 | 142 | continue; |
143 | 143 | } |
144 | 144 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | */ |
168 | 168 | if (is_numeric($cap_class)) { |
169 | 169 | $cap_class = key($args); |
170 | - $args = $args[ $cap_class ]; |
|
170 | + $args = $args[$cap_class]; |
|
171 | 171 | } |
172 | 172 | |
173 | - if (! class_exists($cap_class)) { |
|
173 | + if ( ! class_exists($cap_class)) { |
|
174 | 174 | throw new EE_Error( |
175 | 175 | sprintf( |
176 | 176 | __( |
@@ -208,17 +208,17 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public static function deregister(string $addon_name = '') |
210 | 210 | { |
211 | - if (! empty(self::$_registry[ $addon_name ])) { |
|
212 | - if (! empty(self::$_registry[ $addon_name ]['caps'])) { |
|
211 | + if ( ! empty(self::$_registry[$addon_name])) { |
|
212 | + if ( ! empty(self::$_registry[$addon_name]['caps'])) { |
|
213 | 213 | // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
214 | - $caps_to_remove = self::$_registry[ $addon_name ]['caps']; |
|
214 | + $caps_to_remove = self::$_registry[$addon_name]['caps']; |
|
215 | 215 | if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
216 | 216 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
217 | 217 | $capabilities->removeCaps($caps_to_remove); |
218 | 218 | } else { |
219 | 219 | add_action( |
220 | 220 | 'AHEE__EE_System__core_loaded_and_ready', |
221 | - function () use ($caps_to_remove) { |
|
221 | + function() use ($caps_to_remove) { |
|
222 | 222 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
223 | 223 | $capabilities->removeCaps($caps_to_remove); |
224 | 224 | } |
@@ -226,6 +226,6 @@ discard block |
||
226 | 226 | } |
227 | 227 | } |
228 | 228 | } |
229 | - unset(self::$_registry[ $addon_name ]); |
|
229 | + unset(self::$_registry[$addon_name]); |
|
230 | 230 | } |
231 | 231 | } |
@@ -11,333 +11,333 @@ |
||
11 | 11 | class EE_Register_Messages_Template_Variations implements EEI_Plugin_API |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds values for registered variations |
|
16 | - * |
|
17 | - * @since 4.5.0 |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected static $_registry = []; |
|
14 | + /** |
|
15 | + * Holds values for registered variations |
|
16 | + * |
|
17 | + * @since 4.5.0 |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected static $_registry = []; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * Used to register new variations |
|
26 | - * |
|
27 | - * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | - * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | - * style of existing structure. |
|
30 | - * |
|
31 | - * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | - * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | - * |
|
34 | - * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | - * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | - * you can have the correct variation loaded. |
|
37 | - * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | - * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | - * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | - * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | - * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | - * you want it to be accurately represented in various template contexts you need to have that relevant |
|
43 | - * variation file available. |
|
44 | - * - $variation_slug is simply the variation slug for that variation. |
|
45 | - * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | - * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | - * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | - * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | - * variation (so the template pack would be unstyled) |
|
50 | - * |
|
51 | - * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | - * messengers. |
|
53 | - * |
|
54 | - * @param string $addon_name unique reference used to describe this variation registry. If |
|
55 | - * this ISN'T unique then this method will make it unique (and it |
|
56 | - * becomes harder to deregister). |
|
57 | - * @param array $setup_args { |
|
58 | - * an array of required values for registering the variations. |
|
59 | - * @type array $variations { |
|
60 | - * An array indexed by template_pack->dbref. and values are an array |
|
61 | - * indexed by messenger name and values are an array indexed by |
|
62 | - * message_type and values are an array indexed by variation_slug |
|
63 | - * and value is the localized label for the variation. Note this |
|
64 | - * api reserves the "default" variation name for the default |
|
65 | - * template pack so you can't register a default variation. Also, |
|
66 | - * try to use unique variation slugs to reference your variations |
|
67 | - * because this api checks if any existing variations are in place |
|
68 | - * with that name. If there are then subsequent variations for that |
|
69 | - * template pack with that same name will fail to register with a |
|
70 | - * persistent notice put up for the user. Required. |
|
71 | - * 'default' => array( |
|
72 | - * 'email' => array( |
|
73 | - * 'registration_approved' => array( |
|
74 | - * my_ee_addon_blue_lagoon' => __('Blue Lagoon', |
|
75 | - * 'text_domain'), |
|
76 | - * 'my_ee_addon_red_sunset' => __('Red Sunset', |
|
77 | - * 'text_domain') |
|
78 | - * ) |
|
79 | - * ) |
|
80 | - * ) |
|
81 | - * } |
|
82 | - * @type string $base_path The base path for where all your variations are found. Although |
|
83 | - * the full path to your variation files should include |
|
84 | - * '/variations/' in it, do not include the |
|
85 | - * 'variations/' in this. Required. |
|
86 | - * @type string $base_url The base url for where all your variations are found. See note |
|
87 | - * above about the 'variations/' string. Required. |
|
88 | - * } |
|
89 | - * } |
|
90 | - * |
|
91 | - * @throws EE_Error |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
95 | - { |
|
24 | + /** |
|
25 | + * Used to register new variations |
|
26 | + * |
|
27 | + * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
28 | + * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
29 | + * style of existing structure. |
|
30 | + * |
|
31 | + * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
32 | + * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
33 | + * |
|
34 | + * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
35 | + * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
36 | + * you can have the correct variation loaded. |
|
37 | + * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
38 | + * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
39 | + * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
40 | + * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
41 | + * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
42 | + * you want it to be accurately represented in various template contexts you need to have that relevant |
|
43 | + * variation file available. |
|
44 | + * - $variation_slug is simply the variation slug for that variation. |
|
45 | + * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
46 | + * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
47 | + * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
48 | + * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
49 | + * variation (so the template pack would be unstyled) |
|
50 | + * |
|
51 | + * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
52 | + * messengers. |
|
53 | + * |
|
54 | + * @param string $addon_name unique reference used to describe this variation registry. If |
|
55 | + * this ISN'T unique then this method will make it unique (and it |
|
56 | + * becomes harder to deregister). |
|
57 | + * @param array $setup_args { |
|
58 | + * an array of required values for registering the variations. |
|
59 | + * @type array $variations { |
|
60 | + * An array indexed by template_pack->dbref. and values are an array |
|
61 | + * indexed by messenger name and values are an array indexed by |
|
62 | + * message_type and values are an array indexed by variation_slug |
|
63 | + * and value is the localized label for the variation. Note this |
|
64 | + * api reserves the "default" variation name for the default |
|
65 | + * template pack so you can't register a default variation. Also, |
|
66 | + * try to use unique variation slugs to reference your variations |
|
67 | + * because this api checks if any existing variations are in place |
|
68 | + * with that name. If there are then subsequent variations for that |
|
69 | + * template pack with that same name will fail to register with a |
|
70 | + * persistent notice put up for the user. Required. |
|
71 | + * 'default' => array( |
|
72 | + * 'email' => array( |
|
73 | + * 'registration_approved' => array( |
|
74 | + * my_ee_addon_blue_lagoon' => __('Blue Lagoon', |
|
75 | + * 'text_domain'), |
|
76 | + * 'my_ee_addon_red_sunset' => __('Red Sunset', |
|
77 | + * 'text_domain') |
|
78 | + * ) |
|
79 | + * ) |
|
80 | + * ) |
|
81 | + * } |
|
82 | + * @type string $base_path The base path for where all your variations are found. Although |
|
83 | + * the full path to your variation files should include |
|
84 | + * '/variations/' in it, do not include the |
|
85 | + * 'variations/' in this. Required. |
|
86 | + * @type string $base_url The base url for where all your variations are found. See note |
|
87 | + * above about the 'variations/' string. Required. |
|
88 | + * } |
|
89 | + * } |
|
90 | + * |
|
91 | + * @throws EE_Error |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
95 | + { |
|
96 | 96 | |
97 | - // check for required params |
|
98 | - if (empty($addon_name)) { |
|
99 | - throw new EE_Error( |
|
100 | - __( |
|
101 | - 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
102 | - 'event_espresso' |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
97 | + // check for required params |
|
98 | + if (empty($addon_name)) { |
|
99 | + throw new EE_Error( |
|
100 | + __( |
|
101 | + 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
102 | + 'event_espresso' |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | |
107 | - if ( |
|
108 | - ! is_array($setup_args) |
|
109 | - || empty($setup_args['variations']) |
|
110 | - || empty($setup_args['base_path']) |
|
111 | - || empty($setup_args['base_url']) |
|
112 | - ) { |
|
113 | - throw new EE_Error( |
|
114 | - __( |
|
115 | - 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
116 | - 'event_espresso' |
|
117 | - ) |
|
118 | - ); |
|
119 | - } |
|
107 | + if ( |
|
108 | + ! is_array($setup_args) |
|
109 | + || empty($setup_args['variations']) |
|
110 | + || empty($setup_args['base_path']) |
|
111 | + || empty($setup_args['base_url']) |
|
112 | + ) { |
|
113 | + throw new EE_Error( |
|
114 | + __( |
|
115 | + 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
116 | + 'event_espresso' |
|
117 | + ) |
|
118 | + ); |
|
119 | + } |
|
120 | 120 | |
121 | - // make sure we don't register twice |
|
122 | - if (isset(self::$_registry[ $addon_name ])) { |
|
123 | - return true; |
|
124 | - } |
|
121 | + // make sure we don't register twice |
|
122 | + if (isset(self::$_registry[ $addon_name ])) { |
|
123 | + return true; |
|
124 | + } |
|
125 | 125 | |
126 | - // make sure variation ref is unique. |
|
127 | - if (isset(self::$_registry[ $addon_name ])) { |
|
128 | - $addon_name = uniqid() . '_' . $addon_name; |
|
129 | - } |
|
126 | + // make sure variation ref is unique. |
|
127 | + if (isset(self::$_registry[ $addon_name ])) { |
|
128 | + $addon_name = uniqid() . '_' . $addon_name; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - // make sure this was called in the right place! |
|
133 | - if ( |
|
134 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
135 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
136 | - ) { |
|
137 | - EE_Error::doing_it_wrong( |
|
138 | - __METHOD__, |
|
139 | - sprintf( |
|
140 | - __( |
|
141 | - 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
142 | - 'event_espresso' |
|
143 | - ), |
|
144 | - $addon_name |
|
145 | - ), |
|
146 | - '4.5.0' |
|
147 | - ); |
|
148 | - } |
|
132 | + // make sure this was called in the right place! |
|
133 | + if ( |
|
134 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
135 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
136 | + ) { |
|
137 | + EE_Error::doing_it_wrong( |
|
138 | + __METHOD__, |
|
139 | + sprintf( |
|
140 | + __( |
|
141 | + 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
142 | + 'event_espresso' |
|
143 | + ), |
|
144 | + $addon_name |
|
145 | + ), |
|
146 | + '4.5.0' |
|
147 | + ); |
|
148 | + } |
|
149 | 149 | |
150 | - // validate/sanitize incoming args. |
|
151 | - $validated = [ |
|
152 | - 'variations' => (array) $setup_args['variations'], |
|
153 | - 'base_path' => (string) $setup_args['base_path'], |
|
154 | - 'base_url' => (string) $setup_args['base_url'], |
|
155 | - ]; |
|
150 | + // validate/sanitize incoming args. |
|
151 | + $validated = [ |
|
152 | + 'variations' => (array) $setup_args['variations'], |
|
153 | + 'base_path' => (string) $setup_args['base_path'], |
|
154 | + 'base_url' => (string) $setup_args['base_url'], |
|
155 | + ]; |
|
156 | 156 | |
157 | 157 | |
158 | - // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
159 | - $validated = self::_verify_variations($addon_name, $validated); |
|
160 | - self::$_registry[ $addon_name ] = $validated; |
|
158 | + // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
159 | + $validated = self::_verify_variations($addon_name, $validated); |
|
160 | + self::$_registry[ $addon_name ] = $validated; |
|
161 | 161 | |
162 | - add_filter( |
|
163 | - 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
164 | - ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
165 | - 10, |
|
166 | - 4 |
|
167 | - ); |
|
168 | - add_filter( |
|
169 | - 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
170 | - ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
171 | - 10, |
|
172 | - 8 |
|
173 | - ); |
|
174 | - return true; |
|
175 | - } |
|
162 | + add_filter( |
|
163 | + 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
164 | + ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
165 | + 10, |
|
166 | + 4 |
|
167 | + ); |
|
168 | + add_filter( |
|
169 | + 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
170 | + ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
171 | + 10, |
|
172 | + 8 |
|
173 | + ); |
|
174 | + return true; |
|
175 | + } |
|
176 | 176 | |
177 | 177 | |
178 | - /** |
|
179 | - * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
180 | - * throws an error. Also checks if there is already a |
|
181 | - * |
|
182 | - * @param string $addon_name the reference for the variations being registered |
|
183 | - * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
184 | - * @return array |
|
185 | - * @throws EE_Error |
|
186 | - * @since 4.5.0 |
|
187 | - * |
|
188 | - */ |
|
189 | - private static function _verify_variations(string $addon_name, array $validated_variations): array |
|
190 | - { |
|
191 | - foreach (self::$_registry as $settings) { |
|
192 | - foreach ($settings['variations'] as $messenger) { |
|
193 | - foreach ($messenger as $all_variations) { |
|
194 | - if (isset($all_variations['default'])) { |
|
195 | - throw new EE_Error( |
|
196 | - sprintf( |
|
197 | - __( |
|
198 | - 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - $addon_name |
|
202 | - ) |
|
203 | - ); |
|
204 | - } |
|
205 | - } |
|
206 | - } |
|
207 | - } |
|
178 | + /** |
|
179 | + * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
180 | + * throws an error. Also checks if there is already a |
|
181 | + * |
|
182 | + * @param string $addon_name the reference for the variations being registered |
|
183 | + * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
184 | + * @return array |
|
185 | + * @throws EE_Error |
|
186 | + * @since 4.5.0 |
|
187 | + * |
|
188 | + */ |
|
189 | + private static function _verify_variations(string $addon_name, array $validated_variations): array |
|
190 | + { |
|
191 | + foreach (self::$_registry as $settings) { |
|
192 | + foreach ($settings['variations'] as $messenger) { |
|
193 | + foreach ($messenger as $all_variations) { |
|
194 | + if (isset($all_variations['default'])) { |
|
195 | + throw new EE_Error( |
|
196 | + sprintf( |
|
197 | + __( |
|
198 | + 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + $addon_name |
|
202 | + ) |
|
203 | + ); |
|
204 | + } |
|
205 | + } |
|
206 | + } |
|
207 | + } |
|
208 | 208 | |
209 | - // is there already a variation registered with a given variation slug? |
|
210 | - foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
211 | - foreach ($messenger as $message_type => $variations) { |
|
212 | - foreach ($variations as $slug => $label) { |
|
213 | - foreach (self::$_registry as $registered_var => $reg_settings) { |
|
214 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
215 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
216 | - EE_Error::add_error( |
|
217 | - sprintf( |
|
218 | - __( |
|
219 | - 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
220 | - 'event_espresso' |
|
221 | - ), |
|
222 | - $label, |
|
223 | - $template_pack, |
|
224 | - $messenger, |
|
225 | - $message_type, |
|
226 | - $registered_var |
|
227 | - ) |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - return $validated_variations; |
|
235 | - } |
|
209 | + // is there already a variation registered with a given variation slug? |
|
210 | + foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
211 | + foreach ($messenger as $message_type => $variations) { |
|
212 | + foreach ($variations as $slug => $label) { |
|
213 | + foreach (self::$_registry as $registered_var => $reg_settings) { |
|
214 | + if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
215 | + unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
216 | + EE_Error::add_error( |
|
217 | + sprintf( |
|
218 | + __( |
|
219 | + 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
220 | + 'event_espresso' |
|
221 | + ), |
|
222 | + $label, |
|
223 | + $template_pack, |
|
224 | + $messenger, |
|
225 | + $message_type, |
|
226 | + $registered_var |
|
227 | + ) |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + return $validated_variations; |
|
235 | + } |
|
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
240 | - * |
|
241 | - * @param string $variation_path The path generated for the current variation |
|
242 | - * @param string $messenger The messenger the variation is for |
|
243 | - * @param string $message_type EE_message_type->name |
|
244 | - * @param string $type The type of variation being requested |
|
245 | - * @param string $variation The slug for the variation being requested |
|
246 | - * @param string $file_extension What the file extension is for the variation |
|
247 | - * @param bool $url Whether url or path is being returned. |
|
248 | - * @param EE_Messages_Template_Pack $template_pack |
|
249 | - * |
|
250 | - * @return string The path to the requested variation. |
|
251 | - * @since 4.5.0 |
|
252 | - * |
|
253 | - */ |
|
254 | - public static function get_variation( |
|
255 | - string $variation_path, |
|
256 | - string $messenger, |
|
257 | - string $message_type, |
|
258 | - string $type, |
|
259 | - string $variation, |
|
260 | - string $file_extension, |
|
261 | - bool $url, |
|
262 | - EE_Messages_Template_Pack $template_pack |
|
263 | - ): string { |
|
264 | - // so let's loop through our registered variations and then pull any details matching the request. |
|
265 | - foreach (self::$_registry as $registry_settings) { |
|
266 | - $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
267 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
268 | - // see if this file exists |
|
269 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
270 | - return $base . $file_string; |
|
271 | - } |
|
272 | - } |
|
238 | + /** |
|
239 | + * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
240 | + * |
|
241 | + * @param string $variation_path The path generated for the current variation |
|
242 | + * @param string $messenger The messenger the variation is for |
|
243 | + * @param string $message_type EE_message_type->name |
|
244 | + * @param string $type The type of variation being requested |
|
245 | + * @param string $variation The slug for the variation being requested |
|
246 | + * @param string $file_extension What the file extension is for the variation |
|
247 | + * @param bool $url Whether url or path is being returned. |
|
248 | + * @param EE_Messages_Template_Pack $template_pack |
|
249 | + * |
|
250 | + * @return string The path to the requested variation. |
|
251 | + * @since 4.5.0 |
|
252 | + * |
|
253 | + */ |
|
254 | + public static function get_variation( |
|
255 | + string $variation_path, |
|
256 | + string $messenger, |
|
257 | + string $message_type, |
|
258 | + string $type, |
|
259 | + string $variation, |
|
260 | + string $file_extension, |
|
261 | + bool $url, |
|
262 | + EE_Messages_Template_Pack $template_pack |
|
263 | + ): string { |
|
264 | + // so let's loop through our registered variations and then pull any details matching the request. |
|
265 | + foreach (self::$_registry as $registry_settings) { |
|
266 | + $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
267 | + $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
268 | + // see if this file exists |
|
269 | + if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
270 | + return $base . $file_string; |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | - // no match |
|
275 | - return $variation_path; |
|
276 | - } |
|
274 | + // no match |
|
275 | + return $variation_path; |
|
276 | + } |
|
277 | 277 | |
278 | 278 | |
279 | - /** |
|
280 | - * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
281 | - * |
|
282 | - * |
|
283 | - * @param array $variations The original contents for the template pack variations property. |
|
284 | - * @param string $messenger The messenger requesting the variations. |
|
285 | - * @param string $message_type |
|
286 | - * @param EE_Messages_Template_Pack $template_pack |
|
287 | - * |
|
288 | - * @return array new variations array (or existing one if nothing registered) |
|
289 | - * @since 4.5.0 |
|
290 | - * |
|
291 | - * @see $_variation property definition in EE_Messages_Template_Pack |
|
292 | - */ |
|
293 | - public static function get_variations( |
|
294 | - array $variations, |
|
295 | - string $messenger, |
|
296 | - string $message_type, |
|
297 | - EE_Messages_Template_Pack $template_pack |
|
298 | - ): array { |
|
299 | - // first let's check if we even have registered variations and get out early. |
|
300 | - if (empty(self::$_registry)) { |
|
301 | - return $variations; |
|
302 | - } |
|
303 | - $template_variations = []; |
|
304 | - // do we have any new variations for the given messenger, $message_type, and template packs |
|
305 | - foreach (self::$_registry as $registry_settings) { |
|
306 | - // allow for different conditions. |
|
307 | - if (empty($messenger)) { |
|
308 | - return array_merge($registry_settings['variations'], $variations); |
|
309 | - } |
|
310 | - if (empty($message_type)) { |
|
311 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
312 | - return array_merge( |
|
313 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
314 | - $variations |
|
315 | - ); |
|
316 | - } |
|
317 | - } else { |
|
318 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
319 | - return array_merge( |
|
320 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
321 | - $variations |
|
322 | - ); |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - return array_merge($variations, ...$template_variations); |
|
327 | - } |
|
279 | + /** |
|
280 | + * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
281 | + * |
|
282 | + * |
|
283 | + * @param array $variations The original contents for the template pack variations property. |
|
284 | + * @param string $messenger The messenger requesting the variations. |
|
285 | + * @param string $message_type |
|
286 | + * @param EE_Messages_Template_Pack $template_pack |
|
287 | + * |
|
288 | + * @return array new variations array (or existing one if nothing registered) |
|
289 | + * @since 4.5.0 |
|
290 | + * |
|
291 | + * @see $_variation property definition in EE_Messages_Template_Pack |
|
292 | + */ |
|
293 | + public static function get_variations( |
|
294 | + array $variations, |
|
295 | + string $messenger, |
|
296 | + string $message_type, |
|
297 | + EE_Messages_Template_Pack $template_pack |
|
298 | + ): array { |
|
299 | + // first let's check if we even have registered variations and get out early. |
|
300 | + if (empty(self::$_registry)) { |
|
301 | + return $variations; |
|
302 | + } |
|
303 | + $template_variations = []; |
|
304 | + // do we have any new variations for the given messenger, $message_type, and template packs |
|
305 | + foreach (self::$_registry as $registry_settings) { |
|
306 | + // allow for different conditions. |
|
307 | + if (empty($messenger)) { |
|
308 | + return array_merge($registry_settings['variations'], $variations); |
|
309 | + } |
|
310 | + if (empty($message_type)) { |
|
311 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
312 | + return array_merge( |
|
313 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
314 | + $variations |
|
315 | + ); |
|
316 | + } |
|
317 | + } else { |
|
318 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
319 | + return array_merge( |
|
320 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
321 | + $variations |
|
322 | + ); |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + return array_merge($variations, ...$template_variations); |
|
327 | + } |
|
328 | 328 | |
329 | 329 | |
330 | - /** |
|
331 | - * This deregisters a variation set that was previously registered with the given slug. |
|
332 | - * |
|
333 | - * @param string $addon_name The name for the variation set that was previously registered. |
|
334 | - * |
|
335 | - * @return void |
|
336 | - * @since 4.5.0 |
|
337 | - * |
|
338 | - */ |
|
339 | - public static function deregister(string $addon_name = '') |
|
340 | - { |
|
341 | - unset(self::$_registry[ $addon_name ]); |
|
342 | - } |
|
330 | + /** |
|
331 | + * This deregisters a variation set that was previously registered with the given slug. |
|
332 | + * |
|
333 | + * @param string $addon_name The name for the variation set that was previously registered. |
|
334 | + * |
|
335 | + * @return void |
|
336 | + * @since 4.5.0 |
|
337 | + * |
|
338 | + */ |
|
339 | + public static function deregister(string $addon_name = '') |
|
340 | + { |
|
341 | + unset(self::$_registry[ $addon_name ]); |
|
342 | + } |
|
343 | 343 | } |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | // make sure we don't register twice |
122 | - if (isset(self::$_registry[ $addon_name ])) { |
|
122 | + if (isset(self::$_registry[$addon_name])) { |
|
123 | 123 | return true; |
124 | 124 | } |
125 | 125 | |
126 | 126 | // make sure variation ref is unique. |
127 | - if (isset(self::$_registry[ $addon_name ])) { |
|
128 | - $addon_name = uniqid() . '_' . $addon_name; |
|
127 | + if (isset(self::$_registry[$addon_name])) { |
|
128 | + $addon_name = uniqid().'_'.$addon_name; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
159 | 159 | $validated = self::_verify_variations($addon_name, $validated); |
160 | - self::$_registry[ $addon_name ] = $validated; |
|
160 | + self::$_registry[$addon_name] = $validated; |
|
161 | 161 | |
162 | 162 | add_filter( |
163 | 163 | 'FHEE__EE_Messages_Template_Pack__get_variations', |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | foreach ($messenger as $message_type => $variations) { |
212 | 212 | foreach ($variations as $slug => $label) { |
213 | 213 | foreach (self::$_registry as $registered_var => $reg_settings) { |
214 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
215 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
214 | + if (isset($reg_settings['variations'][$template_pack][$messenger][$message_type][$slug])) { |
|
215 | + unset($validated_variations['variations'][$template_pack][$messenger][$message_type][$slug]); |
|
216 | 216 | EE_Error::add_error( |
217 | 217 | sprintf( |
218 | 218 | __( |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | // so let's loop through our registered variations and then pull any details matching the request. |
265 | 265 | foreach (self::$_registry as $registry_settings) { |
266 | 266 | $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
267 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
267 | + $file_string = $messenger.'_'.$type.'_'.$variation.$file_extension; |
|
268 | 268 | // see if this file exists |
269 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
270 | - return $base . $file_string; |
|
269 | + if (is_readable($registry_settings['base_path'].$file_string)) { |
|
270 | + return $base.$file_string; |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
@@ -308,16 +308,16 @@ discard block |
||
308 | 308 | return array_merge($registry_settings['variations'], $variations); |
309 | 309 | } |
310 | 310 | if (empty($message_type)) { |
311 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
311 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger])) { |
|
312 | 312 | return array_merge( |
313 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
313 | + $registry_settings['variations'][$template_pack->dbref][$messenger], |
|
314 | 314 | $variations |
315 | 315 | ); |
316 | 316 | } |
317 | 317 | } else { |
318 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
318 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger][$message_type])) { |
|
319 | 319 | return array_merge( |
320 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
320 | + $registry_settings['variations'][$template_pack->dbref][$messenger][$message_type], |
|
321 | 321 | $variations |
322 | 322 | ); |
323 | 323 | } |
@@ -338,6 +338,6 @@ discard block |
||
338 | 338 | */ |
339 | 339 | public static function deregister(string $addon_name = '') |
340 | 340 | { |
341 | - unset(self::$_registry[ $addon_name ]); |
|
341 | + unset(self::$_registry[$addon_name]); |
|
342 | 342 | } |
343 | 343 | } |