@@ -12,75 +12,75 @@ |
||
12 | 12 | */ |
13 | 13 | class OptionEngine |
14 | 14 | { |
15 | - /** |
|
16 | - * @var bool |
|
17 | - */ |
|
18 | - private $is_network_option; |
|
15 | + /** |
|
16 | + * @var bool |
|
17 | + */ |
|
18 | + private $is_network_option; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var int |
|
22 | - */ |
|
23 | - private $network_ID; |
|
20 | + /** |
|
21 | + * @var int |
|
22 | + */ |
|
23 | + private $network_ID; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @param bool $is_network_option |
|
28 | - */ |
|
29 | - public function __construct(bool $is_network_option = false) |
|
30 | - { |
|
31 | - $this->is_network_option = $is_network_option; |
|
32 | - $this->network_ID = get_current_network_id(); |
|
33 | - } |
|
26 | + /** |
|
27 | + * @param bool $is_network_option |
|
28 | + */ |
|
29 | + public function __construct(bool $is_network_option = false) |
|
30 | + { |
|
31 | + $this->is_network_option = $is_network_option; |
|
32 | + $this->network_ID = get_current_network_id(); |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @param string $option_name |
|
38 | - * @param mixed $default_value |
|
39 | - * @return false|mixed|void |
|
40 | - */ |
|
41 | - public function getOption(string $option_name, $default_value) |
|
42 | - { |
|
43 | - return $this->is_network_option |
|
44 | - ? get_network_option($this->network_ID, $option_name, $default_value) |
|
45 | - : get_option($option_name, $default_value); |
|
46 | - } |
|
36 | + /** |
|
37 | + * @param string $option_name |
|
38 | + * @param mixed $default_value |
|
39 | + * @return false|mixed|void |
|
40 | + */ |
|
41 | + public function getOption(string $option_name, $default_value) |
|
42 | + { |
|
43 | + return $this->is_network_option |
|
44 | + ? get_network_option($this->network_ID, $option_name, $default_value) |
|
45 | + : get_option($option_name, $default_value); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @param string $option_name |
|
51 | - * @param mixed $value |
|
52 | - * @param string $autoload |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function addOption(string $option_name, $value, string $autoload): bool |
|
56 | - { |
|
57 | - return $this->is_network_option |
|
58 | - ? add_network_option($this->network_ID, $option_name, $value) |
|
59 | - : add_option($option_name, $value, '', $autoload); |
|
60 | - } |
|
49 | + /** |
|
50 | + * @param string $option_name |
|
51 | + * @param mixed $value |
|
52 | + * @param string $autoload |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function addOption(string $option_name, $value, string $autoload): bool |
|
56 | + { |
|
57 | + return $this->is_network_option |
|
58 | + ? add_network_option($this->network_ID, $option_name, $value) |
|
59 | + : add_option($option_name, $value, '', $autoload); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @param string $option_name |
|
65 | - * @param mixed $value |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function updateOption(string $option_name, $value): bool |
|
69 | - { |
|
70 | - return $this->is_network_option |
|
71 | - ? update_network_option($this->network_ID, $option_name, $value) |
|
72 | - : update_option($option_name, $value); |
|
73 | - } |
|
63 | + /** |
|
64 | + * @param string $option_name |
|
65 | + * @param mixed $value |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function updateOption(string $option_name, $value): bool |
|
69 | + { |
|
70 | + return $this->is_network_option |
|
71 | + ? update_network_option($this->network_ID, $option_name, $value) |
|
72 | + : update_option($option_name, $value); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * @param string $option_name |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function deleteOption(string $option_name): bool |
|
81 | - { |
|
82 | - return $this->is_network_option |
|
83 | - ? delete_network_option($this->network_ID, $option_name) |
|
84 | - : delete_option($option_name); |
|
85 | - } |
|
76 | + /** |
|
77 | + * @param string $option_name |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function deleteOption(string $option_name): bool |
|
81 | + { |
|
82 | + return $this->is_network_option |
|
83 | + ? delete_network_option($this->network_ID, $option_name) |
|
84 | + : delete_option($option_name); |
|
85 | + } |
|
86 | 86 | } |
@@ -17,181 +17,181 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class WordPressOption |
19 | 19 | { |
20 | - const NOT_SET_YET = 'wordpress-option-value-not-yet-set'; |
|
21 | - |
|
22 | - /** |
|
23 | - * WordPress makes it difficult to determine if an option successfully saved or not, |
|
24 | - * which is sometimes really important to know, especially if the information you are saving is critical. |
|
25 | - * The following options allow us to have a better chance of knowing when an update actually failed |
|
26 | - * or when everything is OK but it just didn't update because the value hasn't changed. |
|
27 | - */ |
|
28 | - const UPDATE_SUCCESS = 1; |
|
29 | - |
|
30 | - const UPDATE_NONE = 0; |
|
31 | - |
|
32 | - const UPDATE_ERROR = -1; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var boolean |
|
36 | - */ |
|
37 | - private $autoload = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var mixed |
|
41 | - */ |
|
42 | - private $default_value = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $option_name = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var mixed |
|
51 | - */ |
|
52 | - private $value = WordPressOption::NOT_SET_YET; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var OptionEngine |
|
56 | - */ |
|
57 | - private $option_engine; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * WordPressOption constructor. |
|
62 | - * |
|
63 | - * @param string $option_name |
|
64 | - * @param mixed $default_value |
|
65 | - * @param bool $autoload if true, will load the option on EVERY request |
|
66 | - * @param bool $is_network_option if true, will save the option to the network as opposed to the current blog |
|
67 | - */ |
|
68 | - public function __construct( |
|
69 | - string $option_name, |
|
70 | - $default_value, |
|
71 | - bool $autoload = false, |
|
72 | - bool $is_network_option = false |
|
73 | - ) { |
|
74 | - $this->setAutoload($autoload); |
|
75 | - $this->setDefaultValue($default_value); |
|
76 | - $this->setOptionName($option_name); |
|
77 | - $this->option_engine = new OptionEngine($is_network_option); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param bool|string $autoload |
|
83 | - */ |
|
84 | - public function setAutoload($autoload): void |
|
85 | - { |
|
86 | - $this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @param mixed $default_value |
|
92 | - */ |
|
93 | - public function setDefaultValue($default_value): void |
|
94 | - { |
|
95 | - $this->default_value = $default_value; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $option_name |
|
101 | - */ |
|
102 | - public function setOptionName(string $option_name): void |
|
103 | - { |
|
104 | - $this->option_name = sanitize_key($option_name); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function optionExists(): string |
|
112 | - { |
|
113 | - return $this->option_engine->getOption( |
|
114 | - $this->option_name, |
|
115 | - WordPressOption::NOT_SET_YET |
|
116 | - ) !== WordPressOption::NOT_SET_YET; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getOptionName(): string |
|
124 | - { |
|
125 | - return $this->option_name; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @return false|mixed|void |
|
131 | - */ |
|
132 | - public function loadOption() |
|
133 | - { |
|
134 | - if ($this->value === WordPressOption::NOT_SET_YET) { |
|
135 | - $this->value = $this->option_engine->getOption($this->option_name, $this->default_value); |
|
136 | - } |
|
137 | - return $this->value; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param $value |
|
143 | - * @return int |
|
144 | - */ |
|
145 | - public function updateOption($value): int |
|
146 | - { |
|
147 | - // don't update if value has not changed since last update |
|
148 | - if ($this->valueIsUnchanged($value)) { |
|
149 | - return WordPressOption::UPDATE_NONE; |
|
150 | - } |
|
151 | - $this->value = $value; |
|
152 | - // because the options for updating differ when adding an option for the first time |
|
153 | - // we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db |
|
154 | - $updated = $this->optionExists() |
|
155 | - ? $this->option_engine->updateOption($this->option_name, $this->value) |
|
156 | - : $this->option_engine->addOption($this->option_name, $this->value, $this->autoload()); |
|
157 | - |
|
158 | - if ($updated) { |
|
159 | - return WordPressOption::UPDATE_SUCCESS; |
|
160 | - } |
|
161 | - return WordPressOption::UPDATE_ERROR; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - private function valueIsUnchanged($value): bool |
|
166 | - { |
|
167 | - if (is_array($value) && is_array($this->value)) { |
|
168 | - $diff = EEH_Array::array_diff_recursive($value, $this->value); |
|
169 | - // $diff = array_diff($value, $this->value); |
|
170 | - return empty($diff); |
|
171 | - } |
|
172 | - // emulate WP's method for checking equality |
|
173 | - return $value === $this->value && maybe_serialize($value) === maybe_serialize($this->value); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - private function autoload(): string |
|
181 | - { |
|
182 | - return $this->autoload ? 'yes' : 'no'; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Deletes the option from the database |
|
188 | - * for the rest of the request |
|
189 | - * |
|
190 | - * @return bool |
|
191 | - * @since $VID:$ |
|
192 | - */ |
|
193 | - public function deleteOption(): bool |
|
194 | - { |
|
195 | - return $this->option_engine->deleteOption($this->option_name); |
|
196 | - } |
|
20 | + const NOT_SET_YET = 'wordpress-option-value-not-yet-set'; |
|
21 | + |
|
22 | + /** |
|
23 | + * WordPress makes it difficult to determine if an option successfully saved or not, |
|
24 | + * which is sometimes really important to know, especially if the information you are saving is critical. |
|
25 | + * The following options allow us to have a better chance of knowing when an update actually failed |
|
26 | + * or when everything is OK but it just didn't update because the value hasn't changed. |
|
27 | + */ |
|
28 | + const UPDATE_SUCCESS = 1; |
|
29 | + |
|
30 | + const UPDATE_NONE = 0; |
|
31 | + |
|
32 | + const UPDATE_ERROR = -1; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var boolean |
|
36 | + */ |
|
37 | + private $autoload = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var mixed |
|
41 | + */ |
|
42 | + private $default_value = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $option_name = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var mixed |
|
51 | + */ |
|
52 | + private $value = WordPressOption::NOT_SET_YET; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var OptionEngine |
|
56 | + */ |
|
57 | + private $option_engine; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * WordPressOption constructor. |
|
62 | + * |
|
63 | + * @param string $option_name |
|
64 | + * @param mixed $default_value |
|
65 | + * @param bool $autoload if true, will load the option on EVERY request |
|
66 | + * @param bool $is_network_option if true, will save the option to the network as opposed to the current blog |
|
67 | + */ |
|
68 | + public function __construct( |
|
69 | + string $option_name, |
|
70 | + $default_value, |
|
71 | + bool $autoload = false, |
|
72 | + bool $is_network_option = false |
|
73 | + ) { |
|
74 | + $this->setAutoload($autoload); |
|
75 | + $this->setDefaultValue($default_value); |
|
76 | + $this->setOptionName($option_name); |
|
77 | + $this->option_engine = new OptionEngine($is_network_option); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param bool|string $autoload |
|
83 | + */ |
|
84 | + public function setAutoload($autoload): void |
|
85 | + { |
|
86 | + $this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @param mixed $default_value |
|
92 | + */ |
|
93 | + public function setDefaultValue($default_value): void |
|
94 | + { |
|
95 | + $this->default_value = $default_value; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $option_name |
|
101 | + */ |
|
102 | + public function setOptionName(string $option_name): void |
|
103 | + { |
|
104 | + $this->option_name = sanitize_key($option_name); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function optionExists(): string |
|
112 | + { |
|
113 | + return $this->option_engine->getOption( |
|
114 | + $this->option_name, |
|
115 | + WordPressOption::NOT_SET_YET |
|
116 | + ) !== WordPressOption::NOT_SET_YET; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getOptionName(): string |
|
124 | + { |
|
125 | + return $this->option_name; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @return false|mixed|void |
|
131 | + */ |
|
132 | + public function loadOption() |
|
133 | + { |
|
134 | + if ($this->value === WordPressOption::NOT_SET_YET) { |
|
135 | + $this->value = $this->option_engine->getOption($this->option_name, $this->default_value); |
|
136 | + } |
|
137 | + return $this->value; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param $value |
|
143 | + * @return int |
|
144 | + */ |
|
145 | + public function updateOption($value): int |
|
146 | + { |
|
147 | + // don't update if value has not changed since last update |
|
148 | + if ($this->valueIsUnchanged($value)) { |
|
149 | + return WordPressOption::UPDATE_NONE; |
|
150 | + } |
|
151 | + $this->value = $value; |
|
152 | + // because the options for updating differ when adding an option for the first time |
|
153 | + // we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db |
|
154 | + $updated = $this->optionExists() |
|
155 | + ? $this->option_engine->updateOption($this->option_name, $this->value) |
|
156 | + : $this->option_engine->addOption($this->option_name, $this->value, $this->autoload()); |
|
157 | + |
|
158 | + if ($updated) { |
|
159 | + return WordPressOption::UPDATE_SUCCESS; |
|
160 | + } |
|
161 | + return WordPressOption::UPDATE_ERROR; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + private function valueIsUnchanged($value): bool |
|
166 | + { |
|
167 | + if (is_array($value) && is_array($this->value)) { |
|
168 | + $diff = EEH_Array::array_diff_recursive($value, $this->value); |
|
169 | + // $diff = array_diff($value, $this->value); |
|
170 | + return empty($diff); |
|
171 | + } |
|
172 | + // emulate WP's method for checking equality |
|
173 | + return $value === $this->value && maybe_serialize($value) === maybe_serialize($this->value); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + private function autoload(): string |
|
181 | + { |
|
182 | + return $this->autoload ? 'yes' : 'no'; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Deletes the option from the database |
|
188 | + * for the rest of the request |
|
189 | + * |
|
190 | + * @return bool |
|
191 | + * @since $VID:$ |
|
192 | + */ |
|
193 | + public function deleteOption(): bool |
|
194 | + { |
|
195 | + return $this->option_engine->deleteOption($this->option_name); |
|
196 | + } |
|
197 | 197 | } |
@@ -14,709 +14,709 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class EEH_Debug_Tools |
16 | 16 | { |
17 | - /** |
|
18 | - * instance of the EEH_Autoloader object |
|
19 | - * |
|
20 | - * @var $_instance |
|
21 | - * @access private |
|
22 | - */ |
|
23 | - private static $_instance; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $_memory_usage_points = array(); |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @singleton method used to instantiate class object |
|
34 | - * @access public |
|
35 | - * @return EEH_Debug_Tools |
|
36 | - */ |
|
37 | - public static function instance() |
|
38 | - { |
|
39 | - // check if class object is instantiated, and instantiated properly |
|
40 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
41 | - self::$_instance = new self(); |
|
42 | - } |
|
43 | - return self::$_instance; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * private class constructor |
|
50 | - */ |
|
51 | - private function __construct() |
|
52 | - { |
|
53 | - // load Kint PHP debugging library |
|
54 | - if ( |
|
55 | - defined('EE_LOAD_KINT') |
|
56 | - && ! class_exists('Kint') |
|
57 | - && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
58 | - ) { |
|
59 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
60 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
61 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
62 | - // so we've moved it to our test folder so that it is not included with production releases |
|
63 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
64 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
65 | - } |
|
66 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
67 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
68 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
69 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * show_db_name |
|
76 | - * |
|
77 | - * @return void |
|
78 | - */ |
|
79 | - public static function show_db_name() |
|
80 | - { |
|
81 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
82 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
83 | - . DB_NAME |
|
84 | - . '</p>'; |
|
85 | - } |
|
86 | - if (EE_DEBUG) { |
|
87 | - Benchmark::displayResults(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * dump EE_Session object at bottom of page after everything else has happened |
|
95 | - * |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public function espresso_session_footer_dump() |
|
99 | - { |
|
100 | - if ( |
|
101 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
102 | - && ! defined('DOING_AJAX') |
|
103 | - && class_exists('Kint') |
|
104 | - && function_exists('wp_get_current_user') |
|
105 | - && current_user_can('update_core') |
|
106 | - && class_exists('EE_Registry') |
|
107 | - ) { |
|
108 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
109 | - Kint::dump(EE_Registry::instance()->SSN); |
|
110 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
111 | - $this->espresso_list_hooked_functions(); |
|
112 | - Benchmark::displayResults(); |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * List All Hooked Functions |
|
120 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
121 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
122 | - * |
|
123 | - * @param string $tag |
|
124 | - * @return void |
|
125 | - */ |
|
126 | - public function espresso_list_hooked_functions($tag = '') |
|
127 | - { |
|
128 | - global $wp_filter; |
|
129 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
130 | - if ($tag) { |
|
131 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
132 | - if (! is_array($hook[ $tag ])) { |
|
133 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
134 | - return; |
|
135 | - } |
|
136 | - echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
137 | - } else { |
|
138 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
139 | - ksort($hook); |
|
140 | - } |
|
141 | - foreach ($hook as $tag_name => $priorities) { |
|
142 | - echo "<br />>>>>>\t<strong>esc_html($tag_name)</strong><br />"; |
|
143 | - ksort($priorities); |
|
144 | - foreach ($priorities as $priority => $function) { |
|
145 | - echo esc_html($priority); |
|
146 | - foreach ($function as $name => $properties) { |
|
147 | - $name = esc_html($name); |
|
148 | - echo "\t$name<br />"; |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * registered_filter_callbacks |
|
158 | - * |
|
159 | - * @param string $hook_name |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - public static function registered_filter_callbacks($hook_name = '') |
|
163 | - { |
|
164 | - $filters = array(); |
|
165 | - global $wp_filter; |
|
166 | - if (isset($wp_filter[ $hook_name ])) { |
|
167 | - $filters[ $hook_name ] = array(); |
|
168 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
169 | - $filters[ $hook_name ][ $priority ] = array(); |
|
170 | - foreach ($callbacks as $callback) { |
|
171 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
175 | - return $filters; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * captures plugin activation errors for debugging |
|
182 | - * |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - */ |
|
186 | - public static function ee_plugin_activation_errors() |
|
187 | - { |
|
188 | - if (WP_DEBUG) { |
|
189 | - $activation_errors = ob_get_contents(); |
|
190 | - if (empty($activation_errors)) { |
|
191 | - return; |
|
192 | - } |
|
193 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | - if (class_exists('EEH_File')) { |
|
196 | - try { |
|
197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
199 | - ); |
|
200 | - EEH_File::write_to_file( |
|
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
202 | - $activation_errors |
|
203 | - ); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf( |
|
207 | - esc_html__( |
|
208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - $e->getMessage() |
|
212 | - ), |
|
213 | - __FILE__, |
|
214 | - __FUNCTION__, |
|
215 | - __LINE__ |
|
216 | - ); |
|
217 | - } |
|
218 | - } else { |
|
219 | - // old school attempt |
|
220 | - file_put_contents( |
|
221 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
222 | - $activation_errors |
|
223 | - ); |
|
224 | - } |
|
225 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
226 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
234 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
235 | - * or we want to make sure they use something the right way. |
|
236 | - * |
|
237 | - * @access public |
|
238 | - * @param string $function The function that was called |
|
239 | - * @param string $message A message explaining what has been done incorrectly |
|
240 | - * @param string $version The version of Event Espresso where the error was added |
|
241 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
242 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
243 | - * but not have any notices appear until a later version. This allows developers |
|
244 | - * extra time to update their code before notices appear. |
|
245 | - * @param int $error_type |
|
246 | - * @uses trigger_error() |
|
247 | - */ |
|
248 | - public function doing_it_wrong( |
|
249 | - $function, |
|
250 | - $message, |
|
251 | - $version, |
|
252 | - $applies_when = '', |
|
253 | - $error_type = null |
|
254 | - ) { |
|
255 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
256 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
257 | - // because we swapped the parameter order around for the last two params, |
|
258 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
259 | - if (is_int($applies_when)) { |
|
260 | - $error_type = $applies_when; |
|
261 | - $applies_when = espresso_version(); |
|
262 | - } |
|
263 | - // if not displaying notices yet, then just leave |
|
264 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
265 | - return; |
|
266 | - } |
|
267 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
268 | - $version = $version === null |
|
269 | - ? '' |
|
270 | - : sprintf( |
|
271 | - esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
272 | - $version |
|
273 | - ); |
|
274 | - $error_message = sprintf( |
|
275 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
276 | - $function, |
|
277 | - '<strong>', |
|
278 | - '</strong>', |
|
279 | - $message, |
|
280 | - $version |
|
281 | - ); |
|
282 | - // don't trigger error if doing ajax, |
|
283 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
284 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
285 | - $error_message .= ' ' . esc_html__( |
|
286 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
287 | - 'event_espresso' |
|
288 | - ); |
|
289 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
290 | - $error_message .= '<ul><li>'; |
|
291 | - $error_message .= implode('</li><li>', $request->requestParams()); |
|
292 | - $error_message .= '</ul>'; |
|
293 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
294 | - // now we set this on the transient so it shows up on the next request. |
|
295 | - EE_Error::get_notices(false, true); |
|
296 | - } else { |
|
297 | - trigger_error($error_message, $error_type); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Logger helpers |
|
306 | - */ |
|
307 | - /** |
|
308 | - * debug |
|
309 | - * |
|
310 | - * @param string $class |
|
311 | - * @param string $func |
|
312 | - * @param string $line |
|
313 | - * @param array $info |
|
314 | - * @param bool $display_request |
|
315 | - * @param string $debug_index |
|
316 | - * @param string $debug_key |
|
317 | - */ |
|
318 | - public static function log( |
|
319 | - $class = '', |
|
320 | - $func = '', |
|
321 | - $line = '', |
|
322 | - $info = array(), |
|
323 | - $display_request = false, |
|
324 | - $debug_index = '', |
|
325 | - $debug_key = 'EE_DEBUG_SPCO' |
|
326 | - ) { |
|
327 | - if (WP_DEBUG) { |
|
328 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
329 | - $debug_data = get_option($debug_key, array()); |
|
330 | - $default_data = array( |
|
331 | - $class => $func . '() : ' . $line, |
|
332 | - ); |
|
333 | - // don't serialize objects |
|
334 | - $info = self::strip_objects($info); |
|
335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | - if (! isset($debug_data[ $index ])) { |
|
337 | - $debug_data[ $index ] = array(); |
|
338 | - } |
|
339 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
340 | - update_option($debug_key, $debug_data); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * strip_objects |
|
348 | - * |
|
349 | - * @param array $info |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function strip_objects($info = array()) |
|
353 | - { |
|
354 | - foreach ($info as $key => $value) { |
|
355 | - if (is_array($value)) { |
|
356 | - $info[ $key ] = self::strip_objects($value); |
|
357 | - } elseif (is_object($value)) { |
|
358 | - $object_class = get_class($value); |
|
359 | - $info[ $object_class ] = array(); |
|
360 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | - if (method_exists($value, 'ID')) { |
|
362 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
363 | - } |
|
364 | - if (method_exists($value, 'status')) { |
|
365 | - $info[ $object_class ]['status'] = $value->status(); |
|
366 | - } elseif (method_exists($value, 'status_ID')) { |
|
367 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
368 | - } |
|
369 | - unset($info[ $key ]); |
|
370 | - } |
|
371 | - } |
|
372 | - return (array) $info; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $var |
|
379 | - * @param string $var_name |
|
380 | - * @param string $file |
|
381 | - * @param int|string $line |
|
382 | - * @param int|string $heading_tag |
|
383 | - * @param bool $die |
|
384 | - * @param string $margin |
|
385 | - */ |
|
386 | - public static function printv( |
|
387 | - $var, |
|
388 | - $var_name = '', |
|
389 | - $file = '', |
|
390 | - $line = '', |
|
391 | - $heading_tag = 5, |
|
392 | - $die = false, |
|
393 | - $margin = '' |
|
394 | - ) { |
|
395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | - $is_method = method_exists($var_name, $var); |
|
398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | - // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | - $result .= $is_method |
|
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | - if ($die) { |
|
408 | - die($result); |
|
409 | - } |
|
410 | - echo $result; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - protected static function headingTag($heading_tag) |
|
415 | - { |
|
416 | - $heading_tag = absint($heading_tag); |
|
417 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | - } |
|
419 | - |
|
420 | - protected static function headingSpacer($heading_tag) |
|
421 | - { |
|
422 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
423 | - ? self::lineBreak() |
|
424 | - : ''; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - protected static function plainOutput() |
|
429 | - { |
|
430 | - return defined('EE_TESTS_DIR') |
|
431 | - || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output'])) |
|
432 | - || ( |
|
433 | - isset($_SERVER['REQUEST_URI']) |
|
434 | - && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
435 | - ); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * @param string $var_name |
|
441 | - * @param string $heading_tag |
|
442 | - * @param string $margin |
|
443 | - * @param int $line |
|
444 | - * @return string |
|
445 | - */ |
|
446 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
447 | - { |
|
448 | - if (EEH_Debug_Tools::plainOutput()) { |
|
449 | - switch ($heading_tag) { |
|
450 | - case 'h1': |
|
451 | - $line_breaks = EEH_Debug_Tools::lineBreak(3); |
|
452 | - break; |
|
453 | - case 'h2': |
|
454 | - $line_breaks = EEH_Debug_Tools::lineBreak(2); |
|
455 | - break; |
|
456 | - default: |
|
457 | - $line_breaks = EEH_Debug_Tools::lineBreak(); |
|
458 | - break; |
|
459 | - } |
|
460 | - return "{$line_breaks}{$line}) {$var_name}"; |
|
461 | - } |
|
462 | - $margin = "25px 0 0 {$margin}"; |
|
463 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @param string $heading_tag |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - protected static function headingX($heading_tag = 'h5') |
|
473 | - { |
|
474 | - if (EEH_Debug_Tools::plainOutput()) { |
|
475 | - return ''; |
|
476 | - } |
|
477 | - return '</' . $heading_tag . '>'; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param string $content |
|
484 | - * @return string |
|
485 | - */ |
|
486 | - protected static function grey_span($content = '') |
|
487 | - { |
|
488 | - if (EEH_Debug_Tools::plainOutput()) { |
|
489 | - return $content; |
|
490 | - } |
|
491 | - return '<span style="color:#999">' . $content . '</span>'; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * @param string $file |
|
498 | - * @param int $line |
|
499 | - * @return string |
|
500 | - */ |
|
501 | - protected static function file_and_line($file, $line, $heading_tag) |
|
502 | - { |
|
503 | - if ($file === '' || $line === '') { |
|
504 | - return ''; |
|
505 | - } |
|
506 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
507 | - if (EEH_Debug_Tools::plainOutput()) { |
|
508 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
509 | - return " ({$file})" . EEH_Debug_Tools::lineBreak(); |
|
510 | - } |
|
511 | - return ''; |
|
512 | - } |
|
513 | - return EEH_Debug_Tools::lineBreak() |
|
514 | - . '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
515 | - . $file |
|
516 | - . EEH_Debug_Tools::lineBreak() |
|
517 | - . 'line no: ' |
|
518 | - . $line |
|
519 | - . '</span>'; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * @param string $content |
|
526 | - * @return string |
|
527 | - */ |
|
528 | - protected static function orange_span($content = '') |
|
529 | - { |
|
530 | - if (EEH_Debug_Tools::plainOutput()) { |
|
531 | - return $content; |
|
532 | - } |
|
533 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * @param mixed $var |
|
540 | - * @return string |
|
541 | - */ |
|
542 | - protected static function pre_span($var) |
|
543 | - { |
|
544 | - ob_start(); |
|
545 | - var_dump($var); |
|
546 | - $var = ob_get_clean(); |
|
547 | - if (EEH_Debug_Tools::plainOutput()) { |
|
548 | - return str_replace("\n", '', $var); |
|
549 | - } |
|
550 | - return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">' . $var . '</pre>'; |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @param mixed $var |
|
557 | - * @param string $var_name |
|
558 | - * @param string $file |
|
559 | - * @param int|string $line |
|
560 | - * @param int|string $heading_tag |
|
561 | - * @param bool $die |
|
562 | - */ |
|
563 | - public static function printr( |
|
564 | - $var, |
|
565 | - $var_name = '', |
|
566 | - $file = '', |
|
567 | - $line = '', |
|
568 | - $heading_tag = 5, |
|
569 | - $die = false |
|
570 | - ) { |
|
571 | - // return; |
|
572 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
573 | - if (empty($var) && empty($var_name)) { |
|
574 | - $var = $file; |
|
575 | - $var_name = "line $line"; |
|
576 | - $file = ''; |
|
577 | - $line = ''; |
|
578 | - } |
|
579 | - $margin = is_admin() ? ' 180px' : '0'; |
|
580 | - if (is_string($var)) { |
|
581 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
582 | - return; |
|
583 | - } |
|
584 | - if (is_object($var)) { |
|
585 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
586 | - } elseif (is_array($var)) { |
|
587 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
588 | - } elseif (is_numeric($var)) { |
|
589 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
590 | - } elseif ($var === null) { |
|
591 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
592 | - } |
|
593 | - $var_name = EEH_Debug_Tools::trimVarName($var_name); |
|
594 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
595 | - // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
596 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
597 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
598 | - EEH_Debug_Tools::pre_span($var) |
|
599 | - ); |
|
600 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
601 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
602 | - if ($die) { |
|
603 | - die($result); |
|
604 | - } |
|
605 | - echo $result; |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - private static function trimVarName($var_name): string |
|
610 | - { |
|
611 | - $converted = str_replace(['$', '_', 'this->'], ['', ' ', ''], $var_name); |
|
612 | - $words = explode(' ', $converted); |
|
613 | - $words = array_map( |
|
614 | - function ($word) { |
|
615 | - return $word === 'id' || $word === 'Id' ? 'ID' : $word; |
|
616 | - }, |
|
617 | - $words |
|
618 | - ); |
|
619 | - return ucwords(implode(' ', $words)); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - private static function lineBreak($lines = 1): string |
|
624 | - { |
|
625 | - $linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL; |
|
626 | - return str_repeat($linebreak, $lines); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - public static function shortClassName(string $fqcn): string |
|
631 | - { |
|
632 | - return substr(strrchr($fqcn, '\\'), 1); |
|
633 | - } |
|
634 | - |
|
635 | - |
|
636 | - |
|
637 | - /******************** deprecated ********************/ |
|
638 | - |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * @deprecated 4.9.39.rc.034 |
|
643 | - */ |
|
644 | - public function reset_times() |
|
645 | - { |
|
646 | - Benchmark::resetTimes(); |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * @deprecated 4.9.39.rc.034 |
|
653 | - * @param null $timer_name |
|
654 | - */ |
|
655 | - public function start_timer($timer_name = null) |
|
656 | - { |
|
657 | - Benchmark::startTimer($timer_name); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * @deprecated 4.9.39.rc.034 |
|
664 | - * @param string $timer_name |
|
665 | - */ |
|
666 | - public function stop_timer($timer_name = '') |
|
667 | - { |
|
668 | - Benchmark::stopTimer($timer_name); |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * @deprecated 4.9.39.rc.034 |
|
675 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
676 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
677 | - * @return void |
|
678 | - */ |
|
679 | - public function measure_memory($label, $output_now = false) |
|
680 | - { |
|
681 | - Benchmark::measureMemory($label, $output_now); |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - |
|
686 | - /** |
|
687 | - * @deprecated 4.9.39.rc.034 |
|
688 | - * @param int $size |
|
689 | - * @return string |
|
690 | - */ |
|
691 | - public function convert($size) |
|
692 | - { |
|
693 | - return Benchmark::convert($size); |
|
694 | - } |
|
695 | - |
|
696 | - |
|
17 | + /** |
|
18 | + * instance of the EEH_Autoloader object |
|
19 | + * |
|
20 | + * @var $_instance |
|
21 | + * @access private |
|
22 | + */ |
|
23 | + private static $_instance; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $_memory_usage_points = array(); |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @singleton method used to instantiate class object |
|
34 | + * @access public |
|
35 | + * @return EEH_Debug_Tools |
|
36 | + */ |
|
37 | + public static function instance() |
|
38 | + { |
|
39 | + // check if class object is instantiated, and instantiated properly |
|
40 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
41 | + self::$_instance = new self(); |
|
42 | + } |
|
43 | + return self::$_instance; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * private class constructor |
|
50 | + */ |
|
51 | + private function __construct() |
|
52 | + { |
|
53 | + // load Kint PHP debugging library |
|
54 | + if ( |
|
55 | + defined('EE_LOAD_KINT') |
|
56 | + && ! class_exists('Kint') |
|
57 | + && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
58 | + ) { |
|
59 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
60 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
61 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
62 | + // so we've moved it to our test folder so that it is not included with production releases |
|
63 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
64 | + require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
65 | + } |
|
66 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
67 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
68 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
69 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * show_db_name |
|
76 | + * |
|
77 | + * @return void |
|
78 | + */ |
|
79 | + public static function show_db_name() |
|
80 | + { |
|
81 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
82 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
83 | + . DB_NAME |
|
84 | + . '</p>'; |
|
85 | + } |
|
86 | + if (EE_DEBUG) { |
|
87 | + Benchmark::displayResults(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * dump EE_Session object at bottom of page after everything else has happened |
|
95 | + * |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public function espresso_session_footer_dump() |
|
99 | + { |
|
100 | + if ( |
|
101 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
102 | + && ! defined('DOING_AJAX') |
|
103 | + && class_exists('Kint') |
|
104 | + && function_exists('wp_get_current_user') |
|
105 | + && current_user_can('update_core') |
|
106 | + && class_exists('EE_Registry') |
|
107 | + ) { |
|
108 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
109 | + Kint::dump(EE_Registry::instance()->SSN); |
|
110 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
111 | + $this->espresso_list_hooked_functions(); |
|
112 | + Benchmark::displayResults(); |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * List All Hooked Functions |
|
120 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
121 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
122 | + * |
|
123 | + * @param string $tag |
|
124 | + * @return void |
|
125 | + */ |
|
126 | + public function espresso_list_hooked_functions($tag = '') |
|
127 | + { |
|
128 | + global $wp_filter; |
|
129 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
130 | + if ($tag) { |
|
131 | + $hook[ $tag ] = $wp_filter[ $tag ]; |
|
132 | + if (! is_array($hook[ $tag ])) { |
|
133 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
134 | + return; |
|
135 | + } |
|
136 | + echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
137 | + } else { |
|
138 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
139 | + ksort($hook); |
|
140 | + } |
|
141 | + foreach ($hook as $tag_name => $priorities) { |
|
142 | + echo "<br />>>>>>\t<strong>esc_html($tag_name)</strong><br />"; |
|
143 | + ksort($priorities); |
|
144 | + foreach ($priorities as $priority => $function) { |
|
145 | + echo esc_html($priority); |
|
146 | + foreach ($function as $name => $properties) { |
|
147 | + $name = esc_html($name); |
|
148 | + echo "\t$name<br />"; |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * registered_filter_callbacks |
|
158 | + * |
|
159 | + * @param string $hook_name |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + public static function registered_filter_callbacks($hook_name = '') |
|
163 | + { |
|
164 | + $filters = array(); |
|
165 | + global $wp_filter; |
|
166 | + if (isset($wp_filter[ $hook_name ])) { |
|
167 | + $filters[ $hook_name ] = array(); |
|
168 | + foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
169 | + $filters[ $hook_name ][ $priority ] = array(); |
|
170 | + foreach ($callbacks as $callback) { |
|
171 | + $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | + return $filters; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * captures plugin activation errors for debugging |
|
182 | + * |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + */ |
|
186 | + public static function ee_plugin_activation_errors() |
|
187 | + { |
|
188 | + if (WP_DEBUG) { |
|
189 | + $activation_errors = ob_get_contents(); |
|
190 | + if (empty($activation_errors)) { |
|
191 | + return; |
|
192 | + } |
|
193 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | + if (class_exists('EEH_File')) { |
|
196 | + try { |
|
197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
199 | + ); |
|
200 | + EEH_File::write_to_file( |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
202 | + $activation_errors |
|
203 | + ); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf( |
|
207 | + esc_html__( |
|
208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + $e->getMessage() |
|
212 | + ), |
|
213 | + __FILE__, |
|
214 | + __FUNCTION__, |
|
215 | + __LINE__ |
|
216 | + ); |
|
217 | + } |
|
218 | + } else { |
|
219 | + // old school attempt |
|
220 | + file_put_contents( |
|
221 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
222 | + $activation_errors |
|
223 | + ); |
|
224 | + } |
|
225 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
226 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
234 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
235 | + * or we want to make sure they use something the right way. |
|
236 | + * |
|
237 | + * @access public |
|
238 | + * @param string $function The function that was called |
|
239 | + * @param string $message A message explaining what has been done incorrectly |
|
240 | + * @param string $version The version of Event Espresso where the error was added |
|
241 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
242 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
243 | + * but not have any notices appear until a later version. This allows developers |
|
244 | + * extra time to update their code before notices appear. |
|
245 | + * @param int $error_type |
|
246 | + * @uses trigger_error() |
|
247 | + */ |
|
248 | + public function doing_it_wrong( |
|
249 | + $function, |
|
250 | + $message, |
|
251 | + $version, |
|
252 | + $applies_when = '', |
|
253 | + $error_type = null |
|
254 | + ) { |
|
255 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
256 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
257 | + // because we swapped the parameter order around for the last two params, |
|
258 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
259 | + if (is_int($applies_when)) { |
|
260 | + $error_type = $applies_when; |
|
261 | + $applies_when = espresso_version(); |
|
262 | + } |
|
263 | + // if not displaying notices yet, then just leave |
|
264 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
265 | + return; |
|
266 | + } |
|
267 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
268 | + $version = $version === null |
|
269 | + ? '' |
|
270 | + : sprintf( |
|
271 | + esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
272 | + $version |
|
273 | + ); |
|
274 | + $error_message = sprintf( |
|
275 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
276 | + $function, |
|
277 | + '<strong>', |
|
278 | + '</strong>', |
|
279 | + $message, |
|
280 | + $version |
|
281 | + ); |
|
282 | + // don't trigger error if doing ajax, |
|
283 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
284 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
285 | + $error_message .= ' ' . esc_html__( |
|
286 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
287 | + 'event_espresso' |
|
288 | + ); |
|
289 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
290 | + $error_message .= '<ul><li>'; |
|
291 | + $error_message .= implode('</li><li>', $request->requestParams()); |
|
292 | + $error_message .= '</ul>'; |
|
293 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
294 | + // now we set this on the transient so it shows up on the next request. |
|
295 | + EE_Error::get_notices(false, true); |
|
296 | + } else { |
|
297 | + trigger_error($error_message, $error_type); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Logger helpers |
|
306 | + */ |
|
307 | + /** |
|
308 | + * debug |
|
309 | + * |
|
310 | + * @param string $class |
|
311 | + * @param string $func |
|
312 | + * @param string $line |
|
313 | + * @param array $info |
|
314 | + * @param bool $display_request |
|
315 | + * @param string $debug_index |
|
316 | + * @param string $debug_key |
|
317 | + */ |
|
318 | + public static function log( |
|
319 | + $class = '', |
|
320 | + $func = '', |
|
321 | + $line = '', |
|
322 | + $info = array(), |
|
323 | + $display_request = false, |
|
324 | + $debug_index = '', |
|
325 | + $debug_key = 'EE_DEBUG_SPCO' |
|
326 | + ) { |
|
327 | + if (WP_DEBUG) { |
|
328 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
329 | + $debug_data = get_option($debug_key, array()); |
|
330 | + $default_data = array( |
|
331 | + $class => $func . '() : ' . $line, |
|
332 | + ); |
|
333 | + // don't serialize objects |
|
334 | + $info = self::strip_objects($info); |
|
335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | + if (! isset($debug_data[ $index ])) { |
|
337 | + $debug_data[ $index ] = array(); |
|
338 | + } |
|
339 | + $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
340 | + update_option($debug_key, $debug_data); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * strip_objects |
|
348 | + * |
|
349 | + * @param array $info |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function strip_objects($info = array()) |
|
353 | + { |
|
354 | + foreach ($info as $key => $value) { |
|
355 | + if (is_array($value)) { |
|
356 | + $info[ $key ] = self::strip_objects($value); |
|
357 | + } elseif (is_object($value)) { |
|
358 | + $object_class = get_class($value); |
|
359 | + $info[ $object_class ] = array(); |
|
360 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | + if (method_exists($value, 'ID')) { |
|
362 | + $info[ $object_class ]['ID'] = $value->ID(); |
|
363 | + } |
|
364 | + if (method_exists($value, 'status')) { |
|
365 | + $info[ $object_class ]['status'] = $value->status(); |
|
366 | + } elseif (method_exists($value, 'status_ID')) { |
|
367 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
368 | + } |
|
369 | + unset($info[ $key ]); |
|
370 | + } |
|
371 | + } |
|
372 | + return (array) $info; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $var |
|
379 | + * @param string $var_name |
|
380 | + * @param string $file |
|
381 | + * @param int|string $line |
|
382 | + * @param int|string $heading_tag |
|
383 | + * @param bool $die |
|
384 | + * @param string $margin |
|
385 | + */ |
|
386 | + public static function printv( |
|
387 | + $var, |
|
388 | + $var_name = '', |
|
389 | + $file = '', |
|
390 | + $line = '', |
|
391 | + $heading_tag = 5, |
|
392 | + $die = false, |
|
393 | + $margin = '' |
|
394 | + ) { |
|
395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | + $is_method = method_exists($var_name, $var); |
|
398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | + // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | + $result .= $is_method |
|
403 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | + if ($die) { |
|
408 | + die($result); |
|
409 | + } |
|
410 | + echo $result; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + protected static function headingTag($heading_tag) |
|
415 | + { |
|
416 | + $heading_tag = absint($heading_tag); |
|
417 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | + } |
|
419 | + |
|
420 | + protected static function headingSpacer($heading_tag) |
|
421 | + { |
|
422 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
423 | + ? self::lineBreak() |
|
424 | + : ''; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + protected static function plainOutput() |
|
429 | + { |
|
430 | + return defined('EE_TESTS_DIR') |
|
431 | + || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output'])) |
|
432 | + || ( |
|
433 | + isset($_SERVER['REQUEST_URI']) |
|
434 | + && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
435 | + ); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * @param string $var_name |
|
441 | + * @param string $heading_tag |
|
442 | + * @param string $margin |
|
443 | + * @param int $line |
|
444 | + * @return string |
|
445 | + */ |
|
446 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
447 | + { |
|
448 | + if (EEH_Debug_Tools::plainOutput()) { |
|
449 | + switch ($heading_tag) { |
|
450 | + case 'h1': |
|
451 | + $line_breaks = EEH_Debug_Tools::lineBreak(3); |
|
452 | + break; |
|
453 | + case 'h2': |
|
454 | + $line_breaks = EEH_Debug_Tools::lineBreak(2); |
|
455 | + break; |
|
456 | + default: |
|
457 | + $line_breaks = EEH_Debug_Tools::lineBreak(); |
|
458 | + break; |
|
459 | + } |
|
460 | + return "{$line_breaks}{$line}) {$var_name}"; |
|
461 | + } |
|
462 | + $margin = "25px 0 0 {$margin}"; |
|
463 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @param string $heading_tag |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + protected static function headingX($heading_tag = 'h5') |
|
473 | + { |
|
474 | + if (EEH_Debug_Tools::plainOutput()) { |
|
475 | + return ''; |
|
476 | + } |
|
477 | + return '</' . $heading_tag . '>'; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param string $content |
|
484 | + * @return string |
|
485 | + */ |
|
486 | + protected static function grey_span($content = '') |
|
487 | + { |
|
488 | + if (EEH_Debug_Tools::plainOutput()) { |
|
489 | + return $content; |
|
490 | + } |
|
491 | + return '<span style="color:#999">' . $content . '</span>'; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * @param string $file |
|
498 | + * @param int $line |
|
499 | + * @return string |
|
500 | + */ |
|
501 | + protected static function file_and_line($file, $line, $heading_tag) |
|
502 | + { |
|
503 | + if ($file === '' || $line === '') { |
|
504 | + return ''; |
|
505 | + } |
|
506 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
507 | + if (EEH_Debug_Tools::plainOutput()) { |
|
508 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
509 | + return " ({$file})" . EEH_Debug_Tools::lineBreak(); |
|
510 | + } |
|
511 | + return ''; |
|
512 | + } |
|
513 | + return EEH_Debug_Tools::lineBreak() |
|
514 | + . '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
515 | + . $file |
|
516 | + . EEH_Debug_Tools::lineBreak() |
|
517 | + . 'line no: ' |
|
518 | + . $line |
|
519 | + . '</span>'; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * @param string $content |
|
526 | + * @return string |
|
527 | + */ |
|
528 | + protected static function orange_span($content = '') |
|
529 | + { |
|
530 | + if (EEH_Debug_Tools::plainOutput()) { |
|
531 | + return $content; |
|
532 | + } |
|
533 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * @param mixed $var |
|
540 | + * @return string |
|
541 | + */ |
|
542 | + protected static function pre_span($var) |
|
543 | + { |
|
544 | + ob_start(); |
|
545 | + var_dump($var); |
|
546 | + $var = ob_get_clean(); |
|
547 | + if (EEH_Debug_Tools::plainOutput()) { |
|
548 | + return str_replace("\n", '', $var); |
|
549 | + } |
|
550 | + return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">' . $var . '</pre>'; |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @param mixed $var |
|
557 | + * @param string $var_name |
|
558 | + * @param string $file |
|
559 | + * @param int|string $line |
|
560 | + * @param int|string $heading_tag |
|
561 | + * @param bool $die |
|
562 | + */ |
|
563 | + public static function printr( |
|
564 | + $var, |
|
565 | + $var_name = '', |
|
566 | + $file = '', |
|
567 | + $line = '', |
|
568 | + $heading_tag = 5, |
|
569 | + $die = false |
|
570 | + ) { |
|
571 | + // return; |
|
572 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
573 | + if (empty($var) && empty($var_name)) { |
|
574 | + $var = $file; |
|
575 | + $var_name = "line $line"; |
|
576 | + $file = ''; |
|
577 | + $line = ''; |
|
578 | + } |
|
579 | + $margin = is_admin() ? ' 180px' : '0'; |
|
580 | + if (is_string($var)) { |
|
581 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
582 | + return; |
|
583 | + } |
|
584 | + if (is_object($var)) { |
|
585 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
586 | + } elseif (is_array($var)) { |
|
587 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
588 | + } elseif (is_numeric($var)) { |
|
589 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
590 | + } elseif ($var === null) { |
|
591 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
592 | + } |
|
593 | + $var_name = EEH_Debug_Tools::trimVarName($var_name); |
|
594 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
595 | + // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
596 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
597 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
598 | + EEH_Debug_Tools::pre_span($var) |
|
599 | + ); |
|
600 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
601 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
602 | + if ($die) { |
|
603 | + die($result); |
|
604 | + } |
|
605 | + echo $result; |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + private static function trimVarName($var_name): string |
|
610 | + { |
|
611 | + $converted = str_replace(['$', '_', 'this->'], ['', ' ', ''], $var_name); |
|
612 | + $words = explode(' ', $converted); |
|
613 | + $words = array_map( |
|
614 | + function ($word) { |
|
615 | + return $word === 'id' || $word === 'Id' ? 'ID' : $word; |
|
616 | + }, |
|
617 | + $words |
|
618 | + ); |
|
619 | + return ucwords(implode(' ', $words)); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + private static function lineBreak($lines = 1): string |
|
624 | + { |
|
625 | + $linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL; |
|
626 | + return str_repeat($linebreak, $lines); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + public static function shortClassName(string $fqcn): string |
|
631 | + { |
|
632 | + return substr(strrchr($fqcn, '\\'), 1); |
|
633 | + } |
|
634 | + |
|
635 | + |
|
636 | + |
|
637 | + /******************** deprecated ********************/ |
|
638 | + |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * @deprecated 4.9.39.rc.034 |
|
643 | + */ |
|
644 | + public function reset_times() |
|
645 | + { |
|
646 | + Benchmark::resetTimes(); |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * @deprecated 4.9.39.rc.034 |
|
653 | + * @param null $timer_name |
|
654 | + */ |
|
655 | + public function start_timer($timer_name = null) |
|
656 | + { |
|
657 | + Benchmark::startTimer($timer_name); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * @deprecated 4.9.39.rc.034 |
|
664 | + * @param string $timer_name |
|
665 | + */ |
|
666 | + public function stop_timer($timer_name = '') |
|
667 | + { |
|
668 | + Benchmark::stopTimer($timer_name); |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * @deprecated 4.9.39.rc.034 |
|
675 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
676 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
677 | + * @return void |
|
678 | + */ |
|
679 | + public function measure_memory($label, $output_now = false) |
|
680 | + { |
|
681 | + Benchmark::measureMemory($label, $output_now); |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + |
|
686 | + /** |
|
687 | + * @deprecated 4.9.39.rc.034 |
|
688 | + * @param int $size |
|
689 | + * @return string |
|
690 | + */ |
|
691 | + public function convert($size) |
|
692 | + { |
|
693 | + return Benchmark::convert($size); |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | 697 | |
698 | - /** |
|
699 | - * @deprecated 4.9.39.rc.034 |
|
700 | - * @param bool $output_now |
|
701 | - * @return string |
|
702 | - */ |
|
703 | - public function show_times($output_now = true) |
|
704 | - { |
|
705 | - return Benchmark::displayResults($output_now); |
|
706 | - } |
|
698 | + /** |
|
699 | + * @deprecated 4.9.39.rc.034 |
|
700 | + * @param bool $output_now |
|
701 | + * @return string |
|
702 | + */ |
|
703 | + public function show_times($output_now = true) |
|
704 | + { |
|
705 | + return Benchmark::displayResults($output_now); |
|
706 | + } |
|
707 | 707 | |
708 | 708 | |
709 | 709 | |
710 | - /** |
|
711 | - * @deprecated 4.9.39.rc.034 |
|
712 | - * @param string $timer_name |
|
713 | - * @param float $total_time |
|
714 | - * @return string |
|
715 | - */ |
|
716 | - public function format_time($timer_name, $total_time) |
|
717 | - { |
|
718 | - return Benchmark::formatTime($timer_name, $total_time); |
|
719 | - } |
|
710 | + /** |
|
711 | + * @deprecated 4.9.39.rc.034 |
|
712 | + * @param string $timer_name |
|
713 | + * @param float $total_time |
|
714 | + * @return string |
|
715 | + */ |
|
716 | + public function format_time($timer_name, $total_time) |
|
717 | + { |
|
718 | + return Benchmark::formatTime($timer_name, $total_time); |
|
719 | + } |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | |
@@ -726,31 +726,31 @@ discard block |
||
726 | 726 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
727 | 727 | */ |
728 | 728 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
729 | - function dump_wp_query() |
|
730 | - { |
|
731 | - global $wp_query; |
|
732 | - d($wp_query); |
|
733 | - } |
|
729 | + function dump_wp_query() |
|
730 | + { |
|
731 | + global $wp_query; |
|
732 | + d($wp_query); |
|
733 | + } |
|
734 | 734 | } |
735 | 735 | /** |
736 | 736 | * borrowed from Kint Debugger |
737 | 737 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
738 | 738 | */ |
739 | 739 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
740 | - function dump_wp() |
|
741 | - { |
|
742 | - global $wp; |
|
743 | - d($wp); |
|
744 | - } |
|
740 | + function dump_wp() |
|
741 | + { |
|
742 | + global $wp; |
|
743 | + d($wp); |
|
744 | + } |
|
745 | 745 | } |
746 | 746 | /** |
747 | 747 | * borrowed from Kint Debugger |
748 | 748 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
749 | 749 | */ |
750 | 750 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
751 | - function dump_post() |
|
752 | - { |
|
753 | - global $post; |
|
754 | - d($post); |
|
755 | - } |
|
751 | + function dump_post() |
|
752 | + { |
|
753 | + global $post; |
|
754 | + d($post); |
|
755 | + } |
|
756 | 756 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public static function instance() |
38 | 38 | { |
39 | 39 | // check if class object is instantiated, and instantiated properly |
40 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
40 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
41 | 41 | self::$_instance = new self(); |
42 | 42 | } |
43 | 43 | return self::$_instance; |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | if ( |
55 | 55 | defined('EE_LOAD_KINT') |
56 | 56 | && ! class_exists('Kint') |
57 | - && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
57 | + && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php') |
|
58 | 58 | ) { |
59 | 59 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
60 | 60 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
61 | 61 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
62 | 62 | // so we've moved it to our test folder so that it is not included with production releases |
63 | 63 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
64 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
64 | + require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php'); |
|
65 | 65 | } |
66 | 66 | $plugin = basename(EE_PLUGIN_DIR_PATH); |
67 | 67 | add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public static function show_db_name() |
80 | 80 | { |
81 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
81 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
82 | 82 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
83 | 83 | . DB_NAME |
84 | 84 | . '</p>'; |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | global $wp_filter; |
129 | 129 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
130 | 130 | if ($tag) { |
131 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
132 | - if (! is_array($hook[ $tag ])) { |
|
131 | + $hook[$tag] = $wp_filter[$tag]; |
|
132 | + if ( ! is_array($hook[$tag])) { |
|
133 | 133 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
134 | 134 | return; |
135 | 135 | } |
136 | - echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
136 | + echo '<h5>For Tag: '.esc_html($tag).'</h5>'; |
|
137 | 137 | } else { |
138 | 138 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
139 | 139 | ksort($hook); |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | { |
164 | 164 | $filters = array(); |
165 | 165 | global $wp_filter; |
166 | - if (isset($wp_filter[ $hook_name ])) { |
|
167 | - $filters[ $hook_name ] = array(); |
|
168 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
169 | - $filters[ $hook_name ][ $priority ] = array(); |
|
166 | + if (isset($wp_filter[$hook_name])) { |
|
167 | + $filters[$hook_name] = array(); |
|
168 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
169 | + $filters[$hook_name][$priority] = array(); |
|
170 | 170 | foreach ($callbacks as $callback) { |
171 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
171 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | } |
@@ -190,15 +190,15 @@ discard block |
||
190 | 190 | if (empty($activation_errors)) { |
191 | 191 | return; |
192 | 192 | } |
193 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
193 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
195 | 195 | if (class_exists('EEH_File')) { |
196 | 196 | try { |
197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html' |
|
199 | 199 | ); |
200 | 200 | EEH_File::write_to_file( |
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
202 | 202 | $activation_errors |
203 | 203 | ); |
204 | 204 | } catch (EE_Error $e) { |
@@ -218,11 +218,11 @@ discard block |
||
218 | 218 | } else { |
219 | 219 | // old school attempt |
220 | 220 | file_put_contents( |
221 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
221 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
222 | 222 | $activation_errors |
223 | 223 | ); |
224 | 224 | } |
225 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
225 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
226 | 226 | update_option('ee_plugin_activation_errors', $activation_errors); |
227 | 227 | } |
228 | 228 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | // don't trigger error if doing ajax, |
283 | 283 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
284 | 284 | if (defined('DOING_AJAX') && DOING_AJAX) { |
285 | - $error_message .= ' ' . esc_html__( |
|
285 | + $error_message .= ' '.esc_html__( |
|
286 | 286 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
287 | 287 | 'event_espresso' |
288 | 288 | ); |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | $debug_key = 'EE_DEBUG_SPCO' |
326 | 326 | ) { |
327 | 327 | if (WP_DEBUG) { |
328 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
329 | 329 | $debug_data = get_option($debug_key, array()); |
330 | 330 | $default_data = array( |
331 | - $class => $func . '() : ' . $line, |
|
331 | + $class => $func.'() : '.$line, |
|
332 | 332 | ); |
333 | 333 | // don't serialize objects |
334 | 334 | $info = self::strip_objects($info); |
335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
336 | - if (! isset($debug_data[ $index ])) { |
|
337 | - $debug_data[ $index ] = array(); |
|
336 | + if ( ! isset($debug_data[$index])) { |
|
337 | + $debug_data[$index] = array(); |
|
338 | 338 | } |
339 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | 340 | update_option($debug_key, $debug_data); |
341 | 341 | } |
342 | 342 | } |
@@ -353,20 +353,20 @@ discard block |
||
353 | 353 | { |
354 | 354 | foreach ($info as $key => $value) { |
355 | 355 | if (is_array($value)) { |
356 | - $info[ $key ] = self::strip_objects($value); |
|
356 | + $info[$key] = self::strip_objects($value); |
|
357 | 357 | } elseif (is_object($value)) { |
358 | 358 | $object_class = get_class($value); |
359 | - $info[ $object_class ] = array(); |
|
360 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
359 | + $info[$object_class] = array(); |
|
360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | 361 | if (method_exists($value, 'ID')) { |
362 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
362 | + $info[$object_class]['ID'] = $value->ID(); |
|
363 | 363 | } |
364 | 364 | if (method_exists($value, 'status')) { |
365 | - $info[ $object_class ]['status'] = $value->status(); |
|
365 | + $info[$object_class]['status'] = $value->status(); |
|
366 | 366 | } elseif (method_exists($value, 'status_ID')) { |
367 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
368 | 368 | } |
369 | - unset($info[ $key ]); |
|
369 | + unset($info[$key]); |
|
370 | 370 | } |
371 | 371 | } |
372 | 372 | return (array) $info; |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
401 | 401 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
402 | 402 | $result .= $is_method |
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
403 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
405 | 405 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
406 | 406 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
407 | 407 | if ($die) { |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | return "{$line_breaks}{$line}) {$var_name}"; |
461 | 461 | } |
462 | 462 | $margin = "25px 0 0 {$margin}"; |
463 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
463 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | if (EEH_Debug_Tools::plainOutput()) { |
475 | 475 | return ''; |
476 | 476 | } |
477 | - return '</' . $heading_tag . '>'; |
|
477 | + return '</'.$heading_tag.'>'; |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | if (EEH_Debug_Tools::plainOutput()) { |
489 | 489 | return $content; |
490 | 490 | } |
491 | - return '<span style="color:#999">' . $content . '</span>'; |
|
491 | + return '<span style="color:#999">'.$content.'</span>'; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
507 | 507 | if (EEH_Debug_Tools::plainOutput()) { |
508 | 508 | if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
509 | - return " ({$file})" . EEH_Debug_Tools::lineBreak(); |
|
509 | + return " ({$file})".EEH_Debug_Tools::lineBreak(); |
|
510 | 510 | } |
511 | 511 | return ''; |
512 | 512 | } |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | if (EEH_Debug_Tools::plainOutput()) { |
531 | 531 | return $content; |
532 | 532 | } |
533 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
533 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | if (EEH_Debug_Tools::plainOutput()) { |
548 | 548 | return str_replace("\n", '', $var); |
549 | 549 | } |
550 | - return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">' . $var . '</pre>'; |
|
550 | + return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">'.$var.'</pre>'; |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
595 | 595 | // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
596 | 596 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
597 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
597 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
598 | 598 | EEH_Debug_Tools::pre_span($var) |
599 | 599 | ); |
600 | 600 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | $converted = str_replace(['$', '_', 'this->'], ['', ' ', ''], $var_name); |
612 | 612 | $words = explode(' ', $converted); |
613 | 613 | $words = array_map( |
614 | - function ($word) { |
|
614 | + function($word) { |
|
615 | 615 | return $word === 'id' || $word === 'Id' ? 'ID' : $word; |
616 | 616 | }, |
617 | 617 | $words |
@@ -11,313 +11,313 @@ |
||
11 | 11 | */ |
12 | 12 | class EEH_Array extends EEH_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
16 | - * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
17 | - * |
|
18 | - * @uses array_udiff core php function for setting up our own array comparison |
|
19 | - * @uses self::_compare_objects as the custom method for array_udiff |
|
20 | - * @param array $array1 an array of objects |
|
21 | - * @param array $array2 an array of objects |
|
22 | - * @return array an array of objects found in array 1 that aren't found in array 2. |
|
23 | - */ |
|
24 | - public static function object_array_diff($array1, $array2) |
|
25 | - { |
|
26 | - return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
27 | - } |
|
14 | + /** |
|
15 | + * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
16 | + * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
17 | + * |
|
18 | + * @uses array_udiff core php function for setting up our own array comparison |
|
19 | + * @uses self::_compare_objects as the custom method for array_udiff |
|
20 | + * @param array $array1 an array of objects |
|
21 | + * @param array $array2 an array of objects |
|
22 | + * @return array an array of objects found in array 1 that aren't found in array 2. |
|
23 | + */ |
|
24 | + public static function object_array_diff($array1, $array2) |
|
25 | + { |
|
26 | + return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
31 | - * |
|
32 | - * @param array $array |
|
33 | - * @return boolean |
|
34 | - */ |
|
35 | - public static function is_associative_array(array $array): bool |
|
36 | - { |
|
37 | - return ! empty($array) && array_keys($array) !== range(0, count($array) - 1); |
|
38 | - } |
|
29 | + /** |
|
30 | + * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
31 | + * |
|
32 | + * @param array $array |
|
33 | + * @return boolean |
|
34 | + */ |
|
35 | + public static function is_associative_array(array $array): bool |
|
36 | + { |
|
37 | + return ! empty($array) && array_keys($array) !== range(0, count($array) - 1); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Gets an item from the array and leave the array intact. Use in place of end() |
|
42 | - * when you don't want to change the array |
|
43 | - * |
|
44 | - * @param array $arr |
|
45 | - * @return mixed what ever is in the array |
|
46 | - */ |
|
47 | - public static function get_one_item_from_array($arr) |
|
48 | - { |
|
49 | - $item = end($arr); |
|
50 | - reset($arr); |
|
51 | - return $item; |
|
52 | - } |
|
40 | + /** |
|
41 | + * Gets an item from the array and leave the array intact. Use in place of end() |
|
42 | + * when you don't want to change the array |
|
43 | + * |
|
44 | + * @param array $arr |
|
45 | + * @return mixed what ever is in the array |
|
46 | + */ |
|
47 | + public static function get_one_item_from_array($arr) |
|
48 | + { |
|
49 | + $item = end($arr); |
|
50 | + reset($arr); |
|
51 | + return $item; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Detects if this is a multi-dimensional array |
|
56 | - * meaning that at least one top-level value is an array. Eg [ [], ...] |
|
57 | - * |
|
58 | - * @param mixed $arr |
|
59 | - * @return boolean |
|
60 | - */ |
|
61 | - public static function is_multi_dimensional_array($arr) |
|
62 | - { |
|
63 | - if (is_array($arr)) { |
|
64 | - foreach ($arr as $item) { |
|
65 | - if (is_array($item)) { |
|
66 | - return true; // yep, there's at least 2 levels to this array |
|
67 | - } |
|
68 | - } |
|
69 | - } |
|
70 | - return false; // there's only 1 level, or it's not an array at all! |
|
71 | - } |
|
54 | + /** |
|
55 | + * Detects if this is a multi-dimensional array |
|
56 | + * meaning that at least one top-level value is an array. Eg [ [], ...] |
|
57 | + * |
|
58 | + * @param mixed $arr |
|
59 | + * @return boolean |
|
60 | + */ |
|
61 | + public static function is_multi_dimensional_array($arr) |
|
62 | + { |
|
63 | + if (is_array($arr)) { |
|
64 | + foreach ($arr as $item) { |
|
65 | + if (is_array($item)) { |
|
66 | + return true; // yep, there's at least 2 levels to this array |
|
67 | + } |
|
68 | + } |
|
69 | + } |
|
70 | + return false; // there's only 1 level, or it's not an array at all! |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
75 | - * |
|
76 | - * @param array $arr |
|
77 | - * @param mixed $index |
|
78 | - * @param mixed $default |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - public static function is_set($arr, $index, $default) |
|
82 | - { |
|
83 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
84 | - } |
|
73 | + /** |
|
74 | + * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
75 | + * |
|
76 | + * @param array $arr |
|
77 | + * @param mixed $index |
|
78 | + * @param mixed $default |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + public static function is_set($arr, $index, $default) |
|
82 | + { |
|
83 | + return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
88 | - * |
|
89 | - * @param mixed $value usually a string, but could be an array or object |
|
90 | - * @return mixed the UN-serialized data |
|
91 | - */ |
|
92 | - public static function maybe_unserialize($value) |
|
93 | - { |
|
94 | - $data = maybe_unserialize($value); |
|
95 | - // it's possible that this still has serialized data if it's the session. |
|
96 | - // WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically. |
|
97 | - $token = 'C'; |
|
98 | - $data = is_string($data) ? trim($data) : $data; |
|
99 | - if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
100 | - return unserialize($data); |
|
101 | - } else { |
|
102 | - return $data; |
|
103 | - } |
|
104 | - } |
|
86 | + /** |
|
87 | + * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
88 | + * |
|
89 | + * @param mixed $value usually a string, but could be an array or object |
|
90 | + * @return mixed the UN-serialized data |
|
91 | + */ |
|
92 | + public static function maybe_unserialize($value) |
|
93 | + { |
|
94 | + $data = maybe_unserialize($value); |
|
95 | + // it's possible that this still has serialized data if it's the session. |
|
96 | + // WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically. |
|
97 | + $token = 'C'; |
|
98 | + $data = is_string($data) ? trim($data) : $data; |
|
99 | + if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
100 | + return unserialize($data); |
|
101 | + } else { |
|
102 | + return $data; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * insert_into_array |
|
109 | - * |
|
110 | - * @param array $target_array the array to insert new data into |
|
111 | - * @param array $array_to_insert the new data to be inserted |
|
112 | - * @param int|string|null $offset a known key within $target_array where new data will be inserted |
|
113 | - * @param bool $add_before whether to add new data before or after the offset key |
|
114 | - * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public static function insert_into_array( |
|
118 | - array $target_array = array(), |
|
119 | - array $array_to_insert = array(), |
|
120 | - $offset = null, |
|
121 | - bool $add_before = true, |
|
122 | - bool $preserve_keys = true |
|
123 | - ) { |
|
124 | - $target_array_keys = array_keys($target_array); |
|
125 | - // if no offset key was supplied |
|
126 | - if (empty($offset)) { |
|
127 | - // use start or end of $target_array based on whether we are adding before or not |
|
128 | - $offset = $add_before ? 0 : count($target_array); |
|
129 | - } |
|
130 | - // if offset key is a string, then find the corresponding numeric location for that element |
|
131 | - $offset = is_int($offset) ? $offset : array_search($offset, $target_array_keys, true); |
|
132 | - // add one to the offset if adding after |
|
133 | - $offset = $add_before ? $offset : $offset + 1; |
|
134 | - // but ensure offset does not exceed the length of the array |
|
135 | - $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
136 | - // reindex array ??? |
|
137 | - if ($preserve_keys) { |
|
138 | - // take a slice of the target array from the beginning till the offset, |
|
139 | - // then add the new data |
|
140 | - // then add another slice that starts at the offset and goes till the end |
|
141 | - return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
142 | - $target_array, |
|
143 | - $offset, |
|
144 | - null, |
|
145 | - true |
|
146 | - ); |
|
147 | - } else { |
|
148 | - // since we don't want to preserve keys, we can use array_splice |
|
149 | - array_splice($target_array, $offset, 0, $array_to_insert); |
|
150 | - return $target_array; |
|
151 | - } |
|
152 | - } |
|
107 | + /** |
|
108 | + * insert_into_array |
|
109 | + * |
|
110 | + * @param array $target_array the array to insert new data into |
|
111 | + * @param array $array_to_insert the new data to be inserted |
|
112 | + * @param int|string|null $offset a known key within $target_array where new data will be inserted |
|
113 | + * @param bool $add_before whether to add new data before or after the offset key |
|
114 | + * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public static function insert_into_array( |
|
118 | + array $target_array = array(), |
|
119 | + array $array_to_insert = array(), |
|
120 | + $offset = null, |
|
121 | + bool $add_before = true, |
|
122 | + bool $preserve_keys = true |
|
123 | + ) { |
|
124 | + $target_array_keys = array_keys($target_array); |
|
125 | + // if no offset key was supplied |
|
126 | + if (empty($offset)) { |
|
127 | + // use start or end of $target_array based on whether we are adding before or not |
|
128 | + $offset = $add_before ? 0 : count($target_array); |
|
129 | + } |
|
130 | + // if offset key is a string, then find the corresponding numeric location for that element |
|
131 | + $offset = is_int($offset) ? $offset : array_search($offset, $target_array_keys, true); |
|
132 | + // add one to the offset if adding after |
|
133 | + $offset = $add_before ? $offset : $offset + 1; |
|
134 | + // but ensure offset does not exceed the length of the array |
|
135 | + $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
136 | + // reindex array ??? |
|
137 | + if ($preserve_keys) { |
|
138 | + // take a slice of the target array from the beginning till the offset, |
|
139 | + // then add the new data |
|
140 | + // then add another slice that starts at the offset and goes till the end |
|
141 | + return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
142 | + $target_array, |
|
143 | + $offset, |
|
144 | + null, |
|
145 | + true |
|
146 | + ); |
|
147 | + } else { |
|
148 | + // since we don't want to preserve keys, we can use array_splice |
|
149 | + array_splice($target_array, $offset, 0, $array_to_insert); |
|
150 | + return $target_array; |
|
151 | + } |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * array_merge() is slow and should never be used while looping over data |
|
157 | - * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
158 | - * so really this acts more like array_replace( $array1, $array2 ) |
|
159 | - * or a union with the arrays flipped ( $array2 + $array1 ) |
|
160 | - * this saves a few lines of code and improves readability |
|
161 | - * |
|
162 | - * @param array $array1 |
|
163 | - * @param array $array2 |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
167 | - { |
|
168 | - foreach ($array2 as $key => $value) { |
|
169 | - $array1[ $key ] = $value; |
|
170 | - } |
|
171 | - return $array1; |
|
172 | - } |
|
155 | + /** |
|
156 | + * array_merge() is slow and should never be used while looping over data |
|
157 | + * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
158 | + * so really this acts more like array_replace( $array1, $array2 ) |
|
159 | + * or a union with the arrays flipped ( $array2 + $array1 ) |
|
160 | + * this saves a few lines of code and improves readability |
|
161 | + * |
|
162 | + * @param array $array1 |
|
163 | + * @param array $array2 |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
167 | + { |
|
168 | + foreach ($array2 as $key => $value) { |
|
169 | + $array1[ $key ] = $value; |
|
170 | + } |
|
171 | + return $array1; |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * given a flat array like $array = array('A', 'B', 'C') |
|
177 | - * will convert into a multidimensional array like $array[A][B][C] |
|
178 | - * if $final_value is provided and is anything other than null, |
|
179 | - * then that will be set as the value for the innermost array key |
|
180 | - * like so: $array[A][B][C] = $final_value |
|
181 | - * |
|
182 | - * @param array $flat_array |
|
183 | - * @param mixed $final_value |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
187 | - { |
|
188 | - $multidimensional = array(); |
|
189 | - $reference = &$multidimensional; |
|
190 | - foreach ($flat_array as $key) { |
|
191 | - $reference[ $key ] = array(); |
|
192 | - $reference = &$reference[ $key ]; |
|
193 | - } |
|
194 | - if ($final_value !== null) { |
|
195 | - $reference = $final_value; |
|
196 | - } |
|
197 | - return $multidimensional; |
|
198 | - } |
|
175 | + /** |
|
176 | + * given a flat array like $array = array('A', 'B', 'C') |
|
177 | + * will convert into a multidimensional array like $array[A][B][C] |
|
178 | + * if $final_value is provided and is anything other than null, |
|
179 | + * then that will be set as the value for the innermost array key |
|
180 | + * like so: $array[A][B][C] = $final_value |
|
181 | + * |
|
182 | + * @param array $flat_array |
|
183 | + * @param mixed $final_value |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
187 | + { |
|
188 | + $multidimensional = array(); |
|
189 | + $reference = &$multidimensional; |
|
190 | + foreach ($flat_array as $key) { |
|
191 | + $reference[ $key ] = array(); |
|
192 | + $reference = &$reference[ $key ]; |
|
193 | + } |
|
194 | + if ($final_value !== null) { |
|
195 | + $reference = $final_value; |
|
196 | + } |
|
197 | + return $multidimensional; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | |
201 | - /** |
|
202 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
203 | - * @param array $array |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
207 | - { |
|
208 | - return empty($array) || array_keys($array) === range(0, count($array) - 1); |
|
209 | - } |
|
201 | + /** |
|
202 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
203 | + * @param array $array |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
207 | + { |
|
208 | + return empty($array) || array_keys($array) === range(0, count($array) - 1); |
|
209 | + } |
|
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * recursively walks through an array and adds slashes to all no array elements |
|
214 | - * |
|
215 | - * @param mixed $element |
|
216 | - * @return array|string |
|
217 | - * @since 4.10.29.p |
|
218 | - */ |
|
219 | - public static function addSlashesRecursively($element) |
|
220 | - { |
|
221 | - if (is_array($element)) { |
|
222 | - foreach ($element as $key => $value) { |
|
223 | - $element[ $key ] = EEH_Array::addSlashesRecursively($value); |
|
224 | - } |
|
225 | - return $element; |
|
226 | - } |
|
227 | - return is_string($element) ? addslashes($element) : $element; |
|
228 | - } |
|
212 | + /** |
|
213 | + * recursively walks through an array and adds slashes to all no array elements |
|
214 | + * |
|
215 | + * @param mixed $element |
|
216 | + * @return array|string |
|
217 | + * @since 4.10.29.p |
|
218 | + */ |
|
219 | + public static function addSlashesRecursively($element) |
|
220 | + { |
|
221 | + if (is_array($element)) { |
|
222 | + foreach ($element as $key => $value) { |
|
223 | + $element[ $key ] = EEH_Array::addSlashesRecursively($value); |
|
224 | + } |
|
225 | + return $element; |
|
226 | + } |
|
227 | + return is_string($element) ? addslashes($element) : $element; |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | - /** |
|
232 | - * link https://stackoverflow.com/a/3877494 |
|
233 | - * |
|
234 | - * @param array $array_1 |
|
235 | - * @param array $array_2 |
|
236 | - * @return array |
|
237 | - * @since $VID:$ |
|
238 | - */ |
|
239 | - public static function array_diff_recursive(array $array_1, array $array_2): array |
|
240 | - { |
|
241 | - $diff = []; |
|
242 | - foreach ($array_1 as $key => $value) { |
|
243 | - if (array_key_exists($key, $array_2)) { |
|
244 | - if (is_array($value)) { |
|
245 | - $inner_diff = EEH_Array::array_diff_recursive($value, $array_2[ $key ]); |
|
246 | - if (count($inner_diff)) { |
|
247 | - $diff[ $key ] = $inner_diff; |
|
248 | - } |
|
249 | - } else { |
|
250 | - if ($value != $array_2[ $key ]) { |
|
251 | - $diff[ $key ] = $value; |
|
252 | - } |
|
253 | - } |
|
254 | - } else { |
|
255 | - $diff[ $key ] = $value; |
|
256 | - } |
|
257 | - } |
|
258 | - return $diff; |
|
259 | - } |
|
231 | + /** |
|
232 | + * link https://stackoverflow.com/a/3877494 |
|
233 | + * |
|
234 | + * @param array $array_1 |
|
235 | + * @param array $array_2 |
|
236 | + * @return array |
|
237 | + * @since $VID:$ |
|
238 | + */ |
|
239 | + public static function array_diff_recursive(array $array_1, array $array_2): array |
|
240 | + { |
|
241 | + $diff = []; |
|
242 | + foreach ($array_1 as $key => $value) { |
|
243 | + if (array_key_exists($key, $array_2)) { |
|
244 | + if (is_array($value)) { |
|
245 | + $inner_diff = EEH_Array::array_diff_recursive($value, $array_2[ $key ]); |
|
246 | + if (count($inner_diff)) { |
|
247 | + $diff[ $key ] = $inner_diff; |
|
248 | + } |
|
249 | + } else { |
|
250 | + if ($value != $array_2[ $key ]) { |
|
251 | + $diff[ $key ] = $value; |
|
252 | + } |
|
253 | + } |
|
254 | + } else { |
|
255 | + $diff[ $key ] = $value; |
|
256 | + } |
|
257 | + } |
|
258 | + return $diff; |
|
259 | + } |
|
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * converts multidimensional arrays into a single depth associative array |
|
264 | - * or converts arrays of any depth into a readable string representation |
|
265 | - * |
|
266 | - * $example = [ |
|
267 | - * 'a' => 'A', |
|
268 | - * 'b' => 'B', |
|
269 | - * 'c' => [ |
|
270 | - * 'd' => 'D', |
|
271 | - * 'e' => 'E', |
|
272 | - * 'f' => [ 'G', 'H', 'I' ], |
|
273 | - * ], |
|
274 | - * [ 'J', 'K' ], |
|
275 | - * 'L', |
|
276 | - * 'M', |
|
277 | - * 'n' => [ |
|
278 | - * 'o' => 'P' |
|
279 | - * ], |
|
280 | - * ]; |
|
281 | - * |
|
282 | - * print_r( EEH_Array::flattenArray($example) ); |
|
283 | - * |
|
284 | - * Array ( |
|
285 | - * [a] => A |
|
286 | - * [b] => B |
|
287 | - * [c] => [ d:D, e:E, f:[ G, H, I ] ] |
|
288 | - * [0] => [ J, K ] |
|
289 | - * [1] => L |
|
290 | - * [2] => M |
|
291 | - * [n] => [ o:P ] |
|
292 | - * ) |
|
293 | - * |
|
294 | - * print_r( EEH_Array::flattenArray($example, true) ); |
|
295 | - * |
|
296 | - * "a:A, b:B, c:[ d:D, e:E, f:[ G, H, I ] ], [ J, K ], L, M, n:[ o:P ]" |
|
297 | - * |
|
298 | - * @param array $array the array to be flattened |
|
299 | - * @param bool $to_string [true] will flatten the entire array down into a string |
|
300 | - * [false] will only flatten sub-arrays down into strings and return a array |
|
301 | - * @param bool $top_level used for formatting purposes only, best to leave this alone as it's set internally |
|
302 | - * @return array|false|string |
|
303 | - * @since $VID:$ |
|
304 | - */ |
|
305 | - public static function flattenArray(array $array, bool $to_string = false, bool $top_level = true) |
|
306 | - { |
|
307 | - $flat_array = []; |
|
308 | - foreach ($array as $key => $value) { |
|
309 | - $flat_array[ $key ] = is_array($value) |
|
310 | - ? EEH_Array::flattenArray($value, true, false) |
|
311 | - : $value; |
|
312 | - } |
|
313 | - if (! $to_string) { |
|
314 | - return $flat_array; |
|
315 | - } |
|
316 | - $flat = ''; |
|
317 | - foreach ($flat_array as $key => $value) { |
|
318 | - $flat .= is_int($key) ? "$value, " : "$key:$value, "; |
|
319 | - } |
|
320 | - $flat = substr($flat, 0, -2); |
|
321 | - return $top_level ? $flat : "[ $flat ]"; |
|
322 | - } |
|
262 | + /** |
|
263 | + * converts multidimensional arrays into a single depth associative array |
|
264 | + * or converts arrays of any depth into a readable string representation |
|
265 | + * |
|
266 | + * $example = [ |
|
267 | + * 'a' => 'A', |
|
268 | + * 'b' => 'B', |
|
269 | + * 'c' => [ |
|
270 | + * 'd' => 'D', |
|
271 | + * 'e' => 'E', |
|
272 | + * 'f' => [ 'G', 'H', 'I' ], |
|
273 | + * ], |
|
274 | + * [ 'J', 'K' ], |
|
275 | + * 'L', |
|
276 | + * 'M', |
|
277 | + * 'n' => [ |
|
278 | + * 'o' => 'P' |
|
279 | + * ], |
|
280 | + * ]; |
|
281 | + * |
|
282 | + * print_r( EEH_Array::flattenArray($example) ); |
|
283 | + * |
|
284 | + * Array ( |
|
285 | + * [a] => A |
|
286 | + * [b] => B |
|
287 | + * [c] => [ d:D, e:E, f:[ G, H, I ] ] |
|
288 | + * [0] => [ J, K ] |
|
289 | + * [1] => L |
|
290 | + * [2] => M |
|
291 | + * [n] => [ o:P ] |
|
292 | + * ) |
|
293 | + * |
|
294 | + * print_r( EEH_Array::flattenArray($example, true) ); |
|
295 | + * |
|
296 | + * "a:A, b:B, c:[ d:D, e:E, f:[ G, H, I ] ], [ J, K ], L, M, n:[ o:P ]" |
|
297 | + * |
|
298 | + * @param array $array the array to be flattened |
|
299 | + * @param bool $to_string [true] will flatten the entire array down into a string |
|
300 | + * [false] will only flatten sub-arrays down into strings and return a array |
|
301 | + * @param bool $top_level used for formatting purposes only, best to leave this alone as it's set internally |
|
302 | + * @return array|false|string |
|
303 | + * @since $VID:$ |
|
304 | + */ |
|
305 | + public static function flattenArray(array $array, bool $to_string = false, bool $top_level = true) |
|
306 | + { |
|
307 | + $flat_array = []; |
|
308 | + foreach ($array as $key => $value) { |
|
309 | + $flat_array[ $key ] = is_array($value) |
|
310 | + ? EEH_Array::flattenArray($value, true, false) |
|
311 | + : $value; |
|
312 | + } |
|
313 | + if (! $to_string) { |
|
314 | + return $flat_array; |
|
315 | + } |
|
316 | + $flat = ''; |
|
317 | + foreach ($flat_array as $key => $value) { |
|
318 | + $flat .= is_int($key) ? "$value, " : "$key:$value, "; |
|
319 | + } |
|
320 | + $flat = substr($flat, 0, -2); |
|
321 | + return $top_level ? $flat : "[ $flat ]"; |
|
322 | + } |
|
323 | 323 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function is_set($arr, $index, $default) |
82 | 82 | { |
83 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
83 | + return isset($arr[$index]) ? $arr[$index] : $default; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
167 | 167 | { |
168 | 168 | foreach ($array2 as $key => $value) { |
169 | - $array1[ $key ] = $value; |
|
169 | + $array1[$key] = $value; |
|
170 | 170 | } |
171 | 171 | return $array1; |
172 | 172 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | $multidimensional = array(); |
189 | 189 | $reference = &$multidimensional; |
190 | 190 | foreach ($flat_array as $key) { |
191 | - $reference[ $key ] = array(); |
|
192 | - $reference = &$reference[ $key ]; |
|
191 | + $reference[$key] = array(); |
|
192 | + $reference = &$reference[$key]; |
|
193 | 193 | } |
194 | 194 | if ($final_value !== null) { |
195 | 195 | $reference = $final_value; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | { |
221 | 221 | if (is_array($element)) { |
222 | 222 | foreach ($element as $key => $value) { |
223 | - $element[ $key ] = EEH_Array::addSlashesRecursively($value); |
|
223 | + $element[$key] = EEH_Array::addSlashesRecursively($value); |
|
224 | 224 | } |
225 | 225 | return $element; |
226 | 226 | } |
@@ -242,17 +242,17 @@ discard block |
||
242 | 242 | foreach ($array_1 as $key => $value) { |
243 | 243 | if (array_key_exists($key, $array_2)) { |
244 | 244 | if (is_array($value)) { |
245 | - $inner_diff = EEH_Array::array_diff_recursive($value, $array_2[ $key ]); |
|
245 | + $inner_diff = EEH_Array::array_diff_recursive($value, $array_2[$key]); |
|
246 | 246 | if (count($inner_diff)) { |
247 | - $diff[ $key ] = $inner_diff; |
|
247 | + $diff[$key] = $inner_diff; |
|
248 | 248 | } |
249 | 249 | } else { |
250 | - if ($value != $array_2[ $key ]) { |
|
251 | - $diff[ $key ] = $value; |
|
250 | + if ($value != $array_2[$key]) { |
|
251 | + $diff[$key] = $value; |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | } else { |
255 | - $diff[ $key ] = $value; |
|
255 | + $diff[$key] = $value; |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | return $diff; |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | { |
307 | 307 | $flat_array = []; |
308 | 308 | foreach ($array as $key => $value) { |
309 | - $flat_array[ $key ] = is_array($value) |
|
309 | + $flat_array[$key] = is_array($value) |
|
310 | 310 | ? EEH_Array::flattenArray($value, true, false) |
311 | 311 | : $value; |
312 | 312 | } |
313 | - if (! $to_string) { |
|
313 | + if ( ! $to_string) { |
|
314 | 314 | return $flat_array; |
315 | 315 | } |
316 | 316 | $flat = ''; |
@@ -19,1425 +19,1425 @@ |
||
19 | 19 | */ |
20 | 20 | class General_Settings_Admin_Page extends EE_Admin_Page |
21 | 21 | { |
22 | - /** |
|
23 | - * @var EE_Core_Config |
|
24 | - */ |
|
25 | - public $core_config; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Initialize basic properties. |
|
30 | - */ |
|
31 | - protected function _init_page_props() |
|
32 | - { |
|
33 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
34 | - $this->page_label = GEN_SET_LABEL; |
|
35 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
36 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Set ajax hooks |
|
42 | - */ |
|
43 | - protected function _ajax_hooks() |
|
44 | - { |
|
45 | - add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']); |
|
46 | - add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']); |
|
47 | - add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3); |
|
48 | - add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * More page properties initialization. |
|
54 | - */ |
|
55 | - protected function _define_page_props() |
|
56 | - { |
|
57 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
58 | - $this->_labels = ['publishbox' => esc_html__('Update Settings', 'event_espresso')]; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Set page routes property. |
|
64 | - */ |
|
65 | - protected function _set_page_routes() |
|
66 | - { |
|
67 | - $this->_page_routes = [ |
|
68 | - 'critical_pages' => [ |
|
69 | - 'func' => '_espresso_page_settings', |
|
70 | - 'capability' => 'manage_options', |
|
71 | - ], |
|
72 | - 'update_espresso_page_settings' => [ |
|
73 | - 'func' => '_update_espresso_page_settings', |
|
74 | - 'capability' => 'manage_options', |
|
75 | - 'noheader' => true, |
|
76 | - ], |
|
77 | - 'default' => [ |
|
78 | - 'func' => '_your_organization_settings', |
|
79 | - 'capability' => 'manage_options', |
|
80 | - ], |
|
81 | - |
|
82 | - 'update_your_organization_settings' => [ |
|
83 | - 'func' => '_update_your_organization_settings', |
|
84 | - 'capability' => 'manage_options', |
|
85 | - 'noheader' => true, |
|
86 | - ], |
|
87 | - |
|
88 | - 'admin_option_settings' => [ |
|
89 | - 'func' => '_admin_option_settings', |
|
90 | - 'capability' => 'manage_options', |
|
91 | - ], |
|
92 | - |
|
93 | - 'update_admin_option_settings' => [ |
|
94 | - 'func' => '_update_admin_option_settings', |
|
95 | - 'capability' => 'manage_options', |
|
96 | - 'noheader' => true, |
|
97 | - ], |
|
98 | - |
|
99 | - 'country_settings' => [ |
|
100 | - 'func' => '_country_settings', |
|
101 | - 'capability' => 'manage_options', |
|
102 | - ], |
|
103 | - |
|
104 | - 'update_country_settings' => [ |
|
105 | - 'func' => '_update_country_settings', |
|
106 | - 'capability' => 'manage_options', |
|
107 | - 'noheader' => true, |
|
108 | - ], |
|
109 | - |
|
110 | - 'display_country_settings' => [ |
|
111 | - 'func' => 'display_country_settings', |
|
112 | - 'capability' => 'manage_options', |
|
113 | - 'noheader' => true, |
|
114 | - ], |
|
115 | - |
|
116 | - 'add_new_state' => [ |
|
117 | - 'func' => 'add_new_state', |
|
118 | - 'capability' => 'manage_options', |
|
119 | - 'noheader' => true, |
|
120 | - ], |
|
121 | - |
|
122 | - 'delete_state' => [ |
|
123 | - 'func' => 'delete_state', |
|
124 | - 'capability' => 'manage_options', |
|
125 | - 'noheader' => true, |
|
126 | - ], |
|
127 | - 'privacy_settings' => [ |
|
128 | - 'func' => 'privacySettings', |
|
129 | - 'capability' => 'manage_options', |
|
130 | - ], |
|
131 | - 'update_privacy_settings' => [ |
|
132 | - 'func' => 'updatePrivacySettings', |
|
133 | - 'capability' => 'manage_options', |
|
134 | - 'noheader' => true, |
|
135 | - 'headers_sent_route' => 'privacy_settings', |
|
136 | - ], |
|
137 | - ]; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Set page configuration property |
|
143 | - */ |
|
144 | - protected function _set_page_config() |
|
145 | - { |
|
146 | - $this->_page_config = [ |
|
147 | - 'critical_pages' => [ |
|
148 | - 'nav' => [ |
|
149 | - 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
150 | - 'order' => 50, |
|
151 | - ], |
|
152 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
153 | - 'help_tabs' => [ |
|
154 | - 'general_settings_critical_pages_help_tab' => [ |
|
155 | - 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
156 | - 'filename' => 'general_settings_critical_pages', |
|
157 | - ], |
|
158 | - ], |
|
159 | - 'require_nonce' => false, |
|
160 | - ], |
|
161 | - 'default' => [ |
|
162 | - 'nav' => [ |
|
163 | - 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
164 | - 'order' => 20, |
|
165 | - ], |
|
166 | - 'help_tabs' => [ |
|
167 | - 'general_settings_your_organization_help_tab' => [ |
|
168 | - 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
169 | - 'filename' => 'general_settings_your_organization', |
|
170 | - ], |
|
171 | - ], |
|
172 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
173 | - 'require_nonce' => false, |
|
174 | - ], |
|
175 | - 'admin_option_settings' => [ |
|
176 | - 'nav' => [ |
|
177 | - 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
178 | - 'order' => 60, |
|
179 | - ], |
|
180 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
181 | - 'help_tabs' => [ |
|
182 | - 'general_settings_admin_options_help_tab' => [ |
|
183 | - 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
184 | - 'filename' => 'general_settings_admin_options', |
|
185 | - ], |
|
186 | - ], |
|
187 | - 'require_nonce' => false, |
|
188 | - ], |
|
189 | - 'country_settings' => [ |
|
190 | - 'nav' => [ |
|
191 | - 'label' => esc_html__('Countries', 'event_espresso'), |
|
192 | - 'order' => 70, |
|
193 | - ], |
|
194 | - 'help_tabs' => [ |
|
195 | - 'general_settings_countries_help_tab' => [ |
|
196 | - 'title' => esc_html__('Countries', 'event_espresso'), |
|
197 | - 'filename' => 'general_settings_countries', |
|
198 | - ], |
|
199 | - ], |
|
200 | - 'require_nonce' => false, |
|
201 | - ], |
|
202 | - 'privacy_settings' => [ |
|
203 | - 'nav' => [ |
|
204 | - 'label' => esc_html__('Privacy', 'event_espresso'), |
|
205 | - 'order' => 80, |
|
206 | - ], |
|
207 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
208 | - 'require_nonce' => false, |
|
209 | - ], |
|
210 | - ]; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - protected function _add_screen_options() |
|
215 | - { |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - protected function _add_feature_pointers() |
|
220 | - { |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
226 | - */ |
|
227 | - public function load_scripts_styles() |
|
228 | - { |
|
229 | - // styles |
|
230 | - wp_enqueue_style('espresso-ui-theme'); |
|
231 | - // scripts |
|
232 | - wp_enqueue_script('ee_admin_js'); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Execute logic running on `admin_init` |
|
238 | - */ |
|
239 | - public function admin_init() |
|
240 | - { |
|
241 | - $this->core_config = EE_Registry::instance()->CFG->core; |
|
242 | - |
|
243 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags( |
|
244 | - esc_html__( |
|
245 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
246 | - 'event_espresso' |
|
247 | - ) |
|
248 | - ); |
|
249 | - EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
250 | - esc_html__( |
|
251 | - 'An error occurred! Please refresh the page and try again.', |
|
252 | - 'event_espresso' |
|
253 | - ) |
|
254 | - ); |
|
255 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
256 | - esc_html__( |
|
257 | - 'Are you sure you want to delete this State / Province?', |
|
258 | - 'event_espresso' |
|
259 | - ) |
|
260 | - ); |
|
261 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
262 | - 'admin-ajax.php?page=espresso_general_settings', |
|
263 | - is_ssl() ? 'https://' : 'http://' |
|
264 | - ); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - public function admin_notices() |
|
269 | - { |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - public function admin_footer_scripts() |
|
274 | - { |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * Enqueue scripts and styles for the default route. |
|
280 | - */ |
|
281 | - public function load_scripts_styles_default() |
|
282 | - { |
|
283 | - // styles |
|
284 | - wp_enqueue_style('thickbox'); |
|
285 | - // scripts |
|
286 | - wp_enqueue_script('media-upload'); |
|
287 | - wp_enqueue_script('thickbox'); |
|
288 | - wp_register_script( |
|
289 | - 'organization_settings', |
|
290 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
291 | - ['jquery', 'media-upload', 'thickbox'], |
|
292 | - EVENT_ESPRESSO_VERSION, |
|
293 | - true |
|
294 | - ); |
|
295 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
296 | - wp_enqueue_script('organization_settings'); |
|
297 | - wp_enqueue_style('organization-css'); |
|
298 | - $confirm_image_delete = [ |
|
299 | - 'text' => wp_strip_all_tags( |
|
300 | - esc_html__( |
|
301 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
302 | - 'event_espresso' |
|
303 | - ) |
|
304 | - ), |
|
305 | - ]; |
|
306 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Enqueue scripts and styles for the country settings route. |
|
312 | - */ |
|
313 | - public function load_scripts_styles_country_settings() |
|
314 | - { |
|
315 | - // scripts |
|
316 | - wp_register_script( |
|
317 | - 'gen_settings_countries', |
|
318 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
319 | - ['ee_admin_js'], |
|
320 | - EVENT_ESPRESSO_VERSION, |
|
321 | - true |
|
322 | - ); |
|
323 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
324 | - wp_enqueue_script('gen_settings_countries'); |
|
325 | - wp_enqueue_style('organization-css'); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /************* Espresso Pages *************/ |
|
330 | - /** |
|
331 | - * _espresso_page_settings |
|
332 | - * |
|
333 | - * @throws EE_Error |
|
334 | - * @throws DomainException |
|
335 | - * @throws DomainException |
|
336 | - * @throws InvalidDataTypeException |
|
337 | - * @throws InvalidArgumentException |
|
338 | - */ |
|
339 | - protected function _espresso_page_settings() |
|
340 | - { |
|
341 | - // Check to make sure all of the main pages are set up properly, |
|
342 | - // if not create the default pages and display an admin notice |
|
343 | - EEH_Activation::verify_default_pages_exist(); |
|
344 | - $this->_transient_garbage_collection(); |
|
345 | - |
|
346 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
347 | - |
|
348 | - $this->_template_args['reg_page_id'] = $this->core_config->reg_page_id ?? null; |
|
349 | - $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id) |
|
350 | - ? get_post($this->core_config->reg_page_id) |
|
351 | - : false; |
|
352 | - |
|
353 | - $this->_template_args['txn_page_id'] = $this->core_config->txn_page_id ?? null; |
|
354 | - $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id) |
|
355 | - ? get_post($this->core_config->txn_page_id) |
|
356 | - : false; |
|
357 | - |
|
358 | - $this->_template_args['thank_you_page_id'] = $this->core_config->thank_you_page_id ?? null; |
|
359 | - $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id) |
|
360 | - ? get_post($this->core_config->thank_you_page_id) |
|
361 | - : false; |
|
362 | - |
|
363 | - $this->_template_args['cancel_page_id'] = $this->core_config->cancel_page_id ?? null; |
|
364 | - $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id) |
|
365 | - ? get_post($this->core_config->cancel_page_id) |
|
366 | - : false; |
|
367 | - |
|
368 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
369 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
370 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
371 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
372 | - $this->_template_args, |
|
373 | - true |
|
374 | - ); |
|
375 | - $this->display_admin_page_with_sidebar(); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * Handler for updating espresso page settings. |
|
381 | - * |
|
382 | - * @throws EE_Error |
|
383 | - */ |
|
384 | - protected function _update_espresso_page_settings() |
|
385 | - { |
|
386 | - $this->core_config = EE_Registry::instance()->CFG->core; |
|
387 | - // capture incoming request data && set page IDs |
|
388 | - $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
389 | - 'reg_page_id', |
|
390 | - $this->core_config->reg_page_id, |
|
391 | - DataType::INT |
|
392 | - ); |
|
393 | - $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
394 | - 'txn_page_id', |
|
395 | - $this->core_config->txn_page_id, |
|
396 | - DataType::INT |
|
397 | - ); |
|
398 | - $this->core_config->thank_you_page_id = $this->request->getRequestParam( |
|
399 | - 'thank_you_page_id', |
|
400 | - $this->core_config->thank_you_page_id, |
|
401 | - DataType::INT |
|
402 | - ); |
|
403 | - $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
404 | - 'cancel_page_id', |
|
405 | - $this->core_config->cancel_page_id, |
|
406 | - DataType::INT |
|
407 | - ); |
|
408 | - |
|
409 | - $this->core_config = apply_filters( |
|
410 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
411 | - $this->core_config, |
|
412 | - $this->request->requestParams() |
|
413 | - ); |
|
414 | - |
|
415 | - $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
416 | - $this->_redirect_after_action( |
|
417 | - $this->_update_espresso_configuration( |
|
418 | - $what, |
|
419 | - $this->core_config, |
|
420 | - __FILE__, |
|
421 | - __FUNCTION__, |
|
422 | - __LINE__ |
|
423 | - ), |
|
424 | - $what, |
|
425 | - '', |
|
426 | - [ |
|
427 | - 'action' => 'critical_pages', |
|
428 | - ], |
|
429 | - true |
|
430 | - ); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /************* Your Organization *************/ |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @throws DomainException |
|
439 | - * @throws EE_Error |
|
440 | - * @throws InvalidArgumentException |
|
441 | - * @throws InvalidDataTypeException |
|
442 | - * @throws InvalidInterfaceException |
|
443 | - */ |
|
444 | - protected function _your_organization_settings() |
|
445 | - { |
|
446 | - $this->_template_args['admin_page_content'] = ''; |
|
447 | - try { |
|
448 | - /** @var OrganizationSettings $organization_settings_form */ |
|
449 | - $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
450 | - |
|
451 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
452 | - $organization_settings_form->display(), |
|
453 | - '', |
|
454 | - 'padding' |
|
455 | - ); |
|
456 | - } catch (Exception $e) { |
|
457 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
458 | - } |
|
459 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
460 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
461 | - $this->display_admin_page_with_sidebar(); |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * Handler for updating organization settings. |
|
467 | - * |
|
468 | - * @throws EE_Error |
|
469 | - */ |
|
470 | - protected function _update_your_organization_settings() |
|
471 | - { |
|
472 | - try { |
|
473 | - /** @var OrganizationSettings $organization_settings_form */ |
|
474 | - $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
475 | - |
|
476 | - $success = $organization_settings_form->process($this->request->requestParams()); |
|
477 | - |
|
478 | - EE_Registry::instance()->CFG = apply_filters( |
|
479 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
480 | - EE_Registry::instance()->CFG |
|
481 | - ); |
|
482 | - } catch (Exception $e) { |
|
483 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
484 | - $success = false; |
|
485 | - } |
|
486 | - |
|
487 | - if ($success) { |
|
488 | - $success = $this->_update_espresso_configuration( |
|
489 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
490 | - EE_Registry::instance()->CFG, |
|
491 | - __FILE__, |
|
492 | - __FUNCTION__, |
|
493 | - __LINE__ |
|
494 | - ); |
|
495 | - } |
|
496 | - |
|
497 | - $this->_redirect_after_action($success, '', '', ['action' => 'default'], true); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /************* Admin Options *************/ |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * _admin_option_settings |
|
507 | - * |
|
508 | - * @throws EE_Error |
|
509 | - * @throws LogicException |
|
510 | - */ |
|
511 | - protected function _admin_option_settings() |
|
512 | - { |
|
513 | - $this->_template_args['admin_page_content'] = ''; |
|
514 | - try { |
|
515 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
516 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
517 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
518 | - // also need to account for the do_action that was in the old template |
|
519 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
520 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
521 | - $admin_options_settings_form->display(), |
|
522 | - '', |
|
523 | - 'padding' |
|
524 | - ); |
|
525 | - } catch (Exception $e) { |
|
526 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
527 | - } |
|
528 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
529 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
530 | - $this->display_admin_page_with_sidebar(); |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * _update_admin_option_settings |
|
536 | - * |
|
537 | - * @throws EE_Error |
|
538 | - * @throws InvalidDataTypeException |
|
539 | - * @throws InvalidFormSubmissionException |
|
540 | - * @throws InvalidArgumentException |
|
541 | - * @throws LogicException |
|
542 | - */ |
|
543 | - protected function _update_admin_option_settings() |
|
544 | - { |
|
545 | - try { |
|
546 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
547 | - $admin_options_settings_form->process( |
|
548 | - $this->request->getRequestParam( |
|
549 | - $admin_options_settings_form->slug(), |
|
550 | - [], |
|
551 | - DataType::STRING, |
|
552 | - true |
|
553 | - ) |
|
554 | - ); |
|
555 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
556 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
557 | - EE_Registry::instance()->CFG->admin |
|
558 | - ); |
|
559 | - } catch (Exception $e) { |
|
560 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
561 | - } |
|
562 | - $this->_redirect_after_action( |
|
563 | - apply_filters( |
|
564 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
565 | - $this->_update_espresso_configuration( |
|
566 | - esc_html__('Admin Options', 'event_espresso'), |
|
567 | - EE_Registry::instance()->CFG->admin, |
|
568 | - __FILE__, |
|
569 | - __FUNCTION__, |
|
570 | - __LINE__ |
|
571 | - ) |
|
572 | - ), |
|
573 | - esc_html__('Admin Options', 'event_espresso'), |
|
574 | - 'updated', |
|
575 | - ['action' => 'admin_option_settings'] |
|
576 | - ); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /************* Countries *************/ |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * @param string|null $default |
|
585 | - * @return string |
|
586 | - */ |
|
587 | - protected function getCountryISO(?string $default = null): string |
|
588 | - { |
|
589 | - $default = $default ?? $this->getCountryIsoForSite(); |
|
590 | - $CNT_ISO = $this->request->getRequestParam('country', $default); |
|
591 | - return strtoupper($CNT_ISO); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * @return string |
|
597 | - */ |
|
598 | - protected function getCountryIsoForSite(): string |
|
599 | - { |
|
600 | - return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
601 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
602 | - : 'US'; |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * @param string $CNT_ISO |
|
608 | - * @param EE_Country|null $country |
|
609 | - * @return EE_Base_Class|EE_Country |
|
610 | - * @throws EE_Error |
|
611 | - * @throws InvalidArgumentException |
|
612 | - * @throws InvalidDataTypeException |
|
613 | - * @throws InvalidInterfaceException |
|
614 | - * @throws ReflectionException |
|
615 | - */ |
|
616 | - protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null) |
|
617 | - { |
|
618 | - /** @var EE_Country $country */ |
|
619 | - return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
620 | - ? $country |
|
621 | - : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - /** |
|
626 | - * Output Country Settings view. |
|
627 | - * |
|
628 | - * @throws DomainException |
|
629 | - * @throws EE_Error |
|
630 | - * @throws InvalidArgumentException |
|
631 | - * @throws InvalidDataTypeException |
|
632 | - * @throws InvalidInterfaceException |
|
633 | - * @throws ReflectionException |
|
634 | - */ |
|
635 | - protected function _country_settings() |
|
636 | - { |
|
637 | - $CNT_ISO = $this->getCountryISO(); |
|
638 | - |
|
639 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
640 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
641 | - EE_Question::new_instance( |
|
642 | - [ |
|
643 | - 'QST_ID' => 0, |
|
644 | - 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
645 | - 'QST_system' => 'admin-country', |
|
646 | - ] |
|
647 | - ), |
|
648 | - EE_Answer::new_instance( |
|
649 | - [ |
|
650 | - 'ANS_ID' => 0, |
|
651 | - 'ANS_value' => $CNT_ISO, |
|
652 | - ] |
|
653 | - ), |
|
654 | - [ |
|
655 | - 'input_id' => 'country', |
|
656 | - 'input_name' => 'country', |
|
657 | - 'input_prefix' => '', |
|
658 | - 'append_qstn_id' => false, |
|
659 | - ] |
|
660 | - ); |
|
661 | - |
|
662 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
663 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10); |
|
664 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10); |
|
665 | - $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
666 | - $country->ID(), |
|
667 | - $country |
|
668 | - ); |
|
669 | - $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
670 | - $country->ID(), |
|
671 | - $country |
|
672 | - ); |
|
673 | - $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
674 | - |
|
675 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
676 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
677 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
678 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
679 | - $this->_template_args, |
|
680 | - true |
|
681 | - ); |
|
682 | - $this->display_admin_page_with_no_sidebar(); |
|
683 | - } |
|
684 | - |
|
685 | - |
|
686 | - /** |
|
687 | - * @param string $CNT_ISO |
|
688 | - * @param EE_Country|null $country |
|
689 | - * @return string |
|
690 | - * @throws DomainException |
|
691 | - * @throws EE_Error |
|
692 | - * @throws InvalidArgumentException |
|
693 | - * @throws InvalidDataTypeException |
|
694 | - * @throws InvalidInterfaceException |
|
695 | - * @throws ReflectionException |
|
696 | - */ |
|
697 | - public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
698 | - { |
|
699 | - $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
700 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
701 | - |
|
702 | - if (! $CNT_ISO) { |
|
703 | - return ''; |
|
704 | - } |
|
705 | - |
|
706 | - // for ajax |
|
707 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
708 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
709 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2); |
|
710 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2); |
|
711 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
712 | - $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
713 | - $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
714 | - |
|
715 | - $country_input_types = [ |
|
716 | - 'CNT_active' => [ |
|
717 | - 'type' => 'RADIO_BTN', |
|
718 | - 'input_name' => "cntry[$CNT_ISO]", |
|
719 | - 'class' => '', |
|
720 | - 'options' => $this->_yes_no_values, |
|
721 | - 'use_desc_4_label' => true, |
|
722 | - ], |
|
723 | - 'CNT_ISO' => [ |
|
724 | - 'type' => 'TEXT', |
|
725 | - 'input_name' => "cntry[$CNT_ISO]", |
|
726 | - 'class' => 'ee-input-width--small', |
|
727 | - ], |
|
728 | - 'CNT_ISO3' => [ |
|
729 | - 'type' => 'TEXT', |
|
730 | - 'input_name' => "cntry[$CNT_ISO]", |
|
731 | - 'class' => 'ee-input-width--small', |
|
732 | - ], |
|
733 | - // 'RGN_ID' => [ |
|
734 | - // 'type' => 'TEXT', |
|
735 | - // 'input_name' => "cntry[$CNT_ISO]", |
|
736 | - // 'class' => 'ee-input-width--small', |
|
737 | - // ], |
|
738 | - 'CNT_name' => [ |
|
739 | - 'type' => 'TEXT', |
|
740 | - 'input_name' => "cntry[$CNT_ISO]", |
|
741 | - 'class' => 'ee-input-width--big', |
|
742 | - ], |
|
743 | - 'CNT_cur_code' => [ |
|
744 | - 'type' => 'TEXT', |
|
745 | - 'input_name' => "cntry[$CNT_ISO]", |
|
746 | - 'class' => 'ee-input-width--small', |
|
747 | - 'disabled' => $CNT_cur_disabled, |
|
748 | - ], |
|
749 | - 'CNT_cur_single' => [ |
|
750 | - 'type' => 'TEXT', |
|
751 | - 'input_name' => "cntry[$CNT_ISO]", |
|
752 | - 'class' => 'ee-input-width--reg', |
|
753 | - 'disabled' => $CNT_cur_disabled, |
|
754 | - ], |
|
755 | - 'CNT_cur_plural' => [ |
|
756 | - 'type' => 'TEXT', |
|
757 | - 'input_name' => "cntry[$CNT_ISO]", |
|
758 | - 'class' => 'ee-input-width--reg', |
|
759 | - 'disabled' => $CNT_cur_disabled, |
|
760 | - ], |
|
761 | - 'CNT_cur_sign' => [ |
|
762 | - 'type' => 'TEXT', |
|
763 | - 'input_name' => "cntry[$CNT_ISO]", |
|
764 | - 'class' => 'ee-input-width--small', |
|
765 | - 'htmlentities' => false, |
|
766 | - 'disabled' => $CNT_cur_disabled, |
|
767 | - ], |
|
768 | - 'CNT_cur_sign_b4' => [ |
|
769 | - 'type' => 'RADIO_BTN', |
|
770 | - 'input_name' => "cntry[$CNT_ISO]", |
|
771 | - 'class' => '', |
|
772 | - 'options' => $this->_yes_no_values, |
|
773 | - 'use_desc_4_label' => true, |
|
774 | - 'disabled' => $CNT_cur_disabled, |
|
775 | - ], |
|
776 | - 'CNT_cur_dec_plc' => [ |
|
777 | - 'type' => 'RADIO_BTN', |
|
778 | - 'input_name' => "cntry[$CNT_ISO]", |
|
779 | - 'class' => '', |
|
780 | - 'options' => [ |
|
781 | - ['id' => 0, 'text' => ''], |
|
782 | - ['id' => 1, 'text' => ''], |
|
783 | - ['id' => 2, 'text' => ''], |
|
784 | - ['id' => 3, 'text' => ''], |
|
785 | - ], |
|
786 | - 'disabled' => $CNT_cur_disabled, |
|
787 | - ], |
|
788 | - 'CNT_cur_dec_mrk' => [ |
|
789 | - 'type' => 'RADIO_BTN', |
|
790 | - 'input_name' => "cntry[$CNT_ISO]", |
|
791 | - 'class' => '', |
|
792 | - 'options' => [ |
|
793 | - [ |
|
794 | - 'id' => ',', |
|
795 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
796 | - ], |
|
797 | - ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')], |
|
798 | - ], |
|
799 | - 'use_desc_4_label' => true, |
|
800 | - 'disabled' => $CNT_cur_disabled, |
|
801 | - ], |
|
802 | - 'CNT_cur_thsnds' => [ |
|
803 | - 'type' => 'RADIO_BTN', |
|
804 | - 'input_name' => "cntry[$CNT_ISO]", |
|
805 | - 'class' => '', |
|
806 | - 'options' => [ |
|
807 | - [ |
|
808 | - 'id' => ',', |
|
809 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
810 | - ], |
|
811 | - [ |
|
812 | - 'id' => '.', |
|
813 | - 'text' => esc_html__('. (decimal)', 'event_espresso'), |
|
814 | - ], |
|
815 | - [ |
|
816 | - 'id' => ' ', |
|
817 | - 'text' => esc_html__('(space)', 'event_espresso'), |
|
818 | - ], |
|
819 | - ], |
|
820 | - 'use_desc_4_label' => true, |
|
821 | - 'disabled' => $CNT_cur_disabled, |
|
822 | - ], |
|
823 | - 'CNT_tel_code' => [ |
|
824 | - 'type' => 'TEXT', |
|
825 | - 'input_name' => "cntry[$CNT_ISO]", |
|
826 | - 'class' => 'ee-input-width--small', |
|
827 | - ], |
|
828 | - 'CNT_is_EU' => [ |
|
829 | - 'type' => 'RADIO_BTN', |
|
830 | - 'input_name' => "cntry[$CNT_ISO]", |
|
831 | - 'class' => '', |
|
832 | - 'options' => $this->_yes_no_values, |
|
833 | - 'use_desc_4_label' => true, |
|
834 | - ], |
|
835 | - ]; |
|
836 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
837 | - $country, |
|
838 | - $country_input_types |
|
839 | - ); |
|
840 | - $country_details_settings = EEH_Template::display_template( |
|
841 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
842 | - $this->_template_args, |
|
843 | - true |
|
844 | - ); |
|
845 | - |
|
846 | - if (defined('DOING_AJAX')) { |
|
847 | - $notices = EE_Error::get_notices(false, false, false); |
|
848 | - echo wp_json_encode( |
|
849 | - [ |
|
850 | - 'return_data' => $country_details_settings, |
|
851 | - 'success' => $notices['success'], |
|
852 | - 'errors' => $notices['errors'], |
|
853 | - ] |
|
854 | - ); |
|
855 | - die(); |
|
856 | - } |
|
857 | - return $country_details_settings; |
|
858 | - } |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * @param string $CNT_ISO |
|
863 | - * @param EE_Country|null $country |
|
864 | - * @return string |
|
865 | - * @throws DomainException |
|
866 | - * @throws EE_Error |
|
867 | - * @throws InvalidArgumentException |
|
868 | - * @throws InvalidDataTypeException |
|
869 | - * @throws InvalidInterfaceException |
|
870 | - * @throws ReflectionException |
|
871 | - */ |
|
872 | - public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
873 | - { |
|
874 | - $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
875 | - if (! $CNT_ISO) { |
|
876 | - return ''; |
|
877 | - } |
|
878 | - // for ajax |
|
879 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
880 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
881 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2); |
|
882 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10); |
|
883 | - $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
884 | - if (empty($states)) { |
|
885 | - /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
886 | - $countrySubRegionDao = $this->loader->getShared( |
|
887 | - 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
888 | - ); |
|
889 | - if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
890 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
891 | - if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
892 | - $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
893 | - } |
|
894 | - } |
|
895 | - } |
|
896 | - if (is_array($states)) { |
|
897 | - foreach ($states as $STA_ID => $state) { |
|
898 | - if ($state instanceof EE_State) { |
|
899 | - $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
900 | - $state, |
|
901 | - [ |
|
902 | - 'STA_abbrev' => [ |
|
903 | - 'type' => 'TEXT', |
|
904 | - 'label' => esc_html__('Code', 'event_espresso'), |
|
905 | - 'input_name' => "states[$STA_ID]", |
|
906 | - 'class' => 'ee-input-width--tiny', |
|
907 | - 'add_mobile_label' => true, |
|
908 | - ], |
|
909 | - 'STA_name' => [ |
|
910 | - 'type' => 'TEXT', |
|
911 | - 'label' => esc_html__('Name', 'event_espresso'), |
|
912 | - 'input_name' => "states[$STA_ID]", |
|
913 | - 'class' => 'ee-input-width--big', |
|
914 | - 'add_mobile_label' => true, |
|
915 | - ], |
|
916 | - 'STA_active' => [ |
|
917 | - 'type' => 'RADIO_BTN', |
|
918 | - 'label' => esc_html__('State Appears in Dropdown Select Lists', 'event_espresso'), |
|
919 | - 'input_name' => "states[$STA_ID]", |
|
920 | - 'options' => $this->_yes_no_values, |
|
921 | - 'use_desc_4_label' => true, |
|
922 | - 'add_mobile_label' => true, |
|
923 | - ], |
|
924 | - ] |
|
925 | - ); |
|
926 | - |
|
927 | - $delete_state_url = EE_Admin_Page::add_query_args_and_nonce( |
|
928 | - [ |
|
929 | - 'action' => 'delete_state', |
|
930 | - 'STA_ID' => $STA_ID, |
|
931 | - 'CNT_ISO' => $CNT_ISO, |
|
932 | - 'STA_abbrev' => $state->abbrev(), |
|
933 | - ], |
|
934 | - GEN_SET_ADMIN_URL |
|
935 | - ); |
|
936 | - |
|
937 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = $inputs; |
|
938 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url; |
|
939 | - } |
|
940 | - } |
|
941 | - } else { |
|
942 | - $this->_template_args['states'] = false; |
|
943 | - } |
|
944 | - |
|
945 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
946 | - ['action' => 'add_new_state'], |
|
947 | - GEN_SET_ADMIN_URL |
|
948 | - ); |
|
949 | - |
|
950 | - $state_details_settings = EEH_Template::display_template( |
|
951 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
952 | - $this->_template_args, |
|
953 | - true |
|
954 | - ); |
|
955 | - |
|
956 | - if (defined('DOING_AJAX')) { |
|
957 | - $notices = EE_Error::get_notices(false, false, false); |
|
958 | - echo wp_json_encode( |
|
959 | - [ |
|
960 | - 'return_data' => $state_details_settings, |
|
961 | - 'success' => $notices['success'], |
|
962 | - 'errors' => $notices['errors'], |
|
963 | - ] |
|
964 | - ); |
|
965 | - die(); |
|
966 | - } |
|
967 | - return $state_details_settings; |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - /** |
|
972 | - * @return void |
|
973 | - * @throws EE_Error |
|
974 | - * @throws InvalidArgumentException |
|
975 | - * @throws InvalidDataTypeException |
|
976 | - * @throws InvalidInterfaceException |
|
977 | - * @throws ReflectionException |
|
978 | - */ |
|
979 | - public function add_new_state() |
|
980 | - { |
|
981 | - $success = true; |
|
982 | - $CNT_ISO = $this->getCountryISO(''); |
|
983 | - if (! $CNT_ISO) { |
|
984 | - EE_Error::add_error( |
|
985 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
986 | - __FILE__, |
|
987 | - __FUNCTION__, |
|
988 | - __LINE__ |
|
989 | - ); |
|
990 | - $success = false; |
|
991 | - } |
|
992 | - $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
993 | - if (! $STA_abbrev) { |
|
994 | - EE_Error::add_error( |
|
995 | - esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
996 | - __FILE__, |
|
997 | - __FUNCTION__, |
|
998 | - __LINE__ |
|
999 | - ); |
|
1000 | - $success = false; |
|
1001 | - } |
|
1002 | - $STA_name = $this->request->getRequestParam('STA_name'); |
|
1003 | - if (! $STA_name) { |
|
1004 | - EE_Error::add_error( |
|
1005 | - esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
1006 | - __FILE__, |
|
1007 | - __FUNCTION__, |
|
1008 | - __LINE__ |
|
1009 | - ); |
|
1010 | - $success = false; |
|
1011 | - } |
|
1012 | - |
|
1013 | - if ($success) { |
|
1014 | - $cols_n_values = [ |
|
1015 | - 'CNT_ISO' => $CNT_ISO, |
|
1016 | - 'STA_abbrev' => $STA_abbrev, |
|
1017 | - 'STA_name' => $STA_name, |
|
1018 | - 'STA_active' => true, |
|
1019 | - ]; |
|
1020 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
1021 | - EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
1022 | - } |
|
1023 | - |
|
1024 | - if (defined('DOING_AJAX')) { |
|
1025 | - $notices = EE_Error::get_notices(false, false, false); |
|
1026 | - echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO])); |
|
1027 | - die(); |
|
1028 | - } |
|
1029 | - $this->_redirect_after_action( |
|
1030 | - $success, |
|
1031 | - esc_html__('State', 'event_espresso'), |
|
1032 | - 'added', |
|
1033 | - ['action' => 'country_settings'] |
|
1034 | - ); |
|
1035 | - } |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * @return void |
|
1040 | - * @throws EE_Error |
|
1041 | - * @throws InvalidArgumentException |
|
1042 | - * @throws InvalidDataTypeException |
|
1043 | - * @throws InvalidInterfaceException |
|
1044 | - * @throws ReflectionException |
|
1045 | - */ |
|
1046 | - public function delete_state() |
|
1047 | - { |
|
1048 | - $CNT_ISO = $this->getCountryISO(); |
|
1049 | - $STA_ID = $this->request->getRequestParam('STA_ID'); |
|
1050 | - $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
1051 | - |
|
1052 | - if (! $STA_ID) { |
|
1053 | - EE_Error::add_error( |
|
1054 | - esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
1055 | - __FILE__, |
|
1056 | - __FUNCTION__, |
|
1057 | - __LINE__ |
|
1058 | - ); |
|
1059 | - return; |
|
1060 | - } |
|
1061 | - |
|
1062 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
1063 | - if ($success !== false) { |
|
1064 | - do_action( |
|
1065 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1066 | - $CNT_ISO, |
|
1067 | - $STA_ID, |
|
1068 | - ['STA_abbrev' => $STA_abbrev] |
|
1069 | - ); |
|
1070 | - EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
1071 | - } |
|
1072 | - if (defined('DOING_AJAX')) { |
|
1073 | - $notices = EE_Error::get_notices(false); |
|
1074 | - $notices['return_data'] = true; |
|
1075 | - echo wp_json_encode($notices); |
|
1076 | - die(); |
|
1077 | - } |
|
1078 | - $this->_redirect_after_action( |
|
1079 | - $success, |
|
1080 | - esc_html__('State', 'event_espresso'), |
|
1081 | - 'deleted', |
|
1082 | - ['action' => 'country_settings'] |
|
1083 | - ); |
|
1084 | - } |
|
1085 | - |
|
1086 | - |
|
1087 | - /** |
|
1088 | - * @return void |
|
1089 | - * @throws EE_Error |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - * @throws InvalidDataTypeException |
|
1092 | - * @throws InvalidInterfaceException |
|
1093 | - * @throws ReflectionException |
|
1094 | - */ |
|
1095 | - protected function _update_country_settings() |
|
1096 | - { |
|
1097 | - $CNT_ISO = $this->getCountryISO(); |
|
1098 | - if (! $CNT_ISO) { |
|
1099 | - EE_Error::add_error( |
|
1100 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1101 | - __FILE__, |
|
1102 | - __FUNCTION__, |
|
1103 | - __LINE__ |
|
1104 | - ); |
|
1105 | - return; |
|
1106 | - } |
|
1107 | - |
|
1108 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
1109 | - |
|
1110 | - $cols_n_values = []; |
|
1111 | - $cols_n_values['CNT_ISO3'] = strtoupper( |
|
1112 | - $this->request->getRequestParam('cntry', '', $country->ISO3()) |
|
1113 | - ); |
|
1114 | - $cols_n_values['CNT_name'] = |
|
1115 | - $this->request->getRequestParam("cntry[$CNT_ISO][CNT_name]", $country->name()); |
|
1116 | - $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1117 | - $this->request->getRequestParam( |
|
1118 | - "cntry[$CNT_ISO][CNT_cur_code]", |
|
1119 | - $country->currency_code() |
|
1120 | - ) |
|
1121 | - ); |
|
1122 | - $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
1123 | - "cntry[$CNT_ISO][CNT_cur_single]", |
|
1124 | - $country->currency_name_single() |
|
1125 | - ); |
|
1126 | - $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
1127 | - "cntry[$CNT_ISO][CNT_cur_plural]", |
|
1128 | - $country->currency_name_plural() |
|
1129 | - ); |
|
1130 | - $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
1131 | - "cntry[$CNT_ISO][CNT_cur_sign]", |
|
1132 | - $country->currency_sign() |
|
1133 | - ); |
|
1134 | - $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam( |
|
1135 | - "cntry[$CNT_ISO][CNT_cur_sign_b4]", |
|
1136 | - $country->currency_sign_before(), |
|
1137 | - DataType::BOOL |
|
1138 | - ); |
|
1139 | - $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam( |
|
1140 | - "cntry[$CNT_ISO][CNT_cur_dec_plc]", |
|
1141 | - $country->currency_decimal_places() |
|
1142 | - ); |
|
1143 | - $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam( |
|
1144 | - "cntry[$CNT_ISO][CNT_cur_dec_mrk]", |
|
1145 | - $country->currency_decimal_mark() |
|
1146 | - ); |
|
1147 | - $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
1148 | - "cntry[$CNT_ISO][CNT_cur_thsnds]", |
|
1149 | - $country->currency_thousands_separator() |
|
1150 | - ); |
|
1151 | - $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
1152 | - "cntry[$CNT_ISO][CNT_tel_code]", |
|
1153 | - $country->telephoneCode() |
|
1154 | - ); |
|
1155 | - $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
1156 | - "cntry[$CNT_ISO][CNT_active]", |
|
1157 | - $country->isActive(), |
|
1158 | - DataType::BOOL |
|
1159 | - ); |
|
1160 | - |
|
1161 | - // allow filtering of country data |
|
1162 | - $cols_n_values = apply_filters( |
|
1163 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1164 | - $cols_n_values |
|
1165 | - ); |
|
1166 | - |
|
1167 | - // where values |
|
1168 | - $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]]; |
|
1169 | - // run the update |
|
1170 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1171 | - |
|
1172 | - // allow filtering of states data |
|
1173 | - $states = apply_filters( |
|
1174 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1175 | - $this->request->getRequestParam('states', [], DataType::STRING, true) |
|
1176 | - ); |
|
1177 | - |
|
1178 | - if (! empty($states) && $success !== false) { |
|
1179 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
1180 | - foreach ($states as $STA_ID => $state) { |
|
1181 | - $cols_n_values = [ |
|
1182 | - 'CNT_ISO' => $CNT_ISO, |
|
1183 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1184 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1185 | - 'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN), |
|
1186 | - ]; |
|
1187 | - // where values |
|
1188 | - $where_cols_n_values = [['STA_ID' => $STA_ID]]; |
|
1189 | - // run the update |
|
1190 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1191 | - if ($success !== false) { |
|
1192 | - do_action( |
|
1193 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1194 | - $CNT_ISO, |
|
1195 | - $STA_ID, |
|
1196 | - $cols_n_values |
|
1197 | - ); |
|
1198 | - } |
|
1199 | - } |
|
1200 | - } |
|
1201 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1202 | - if ( |
|
1203 | - isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1204 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1205 | - ) { |
|
1206 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1207 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
1208 | - } |
|
1209 | - |
|
1210 | - if ($success !== false) { |
|
1211 | - EE_Error::add_success( |
|
1212 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1213 | - ); |
|
1214 | - } |
|
1215 | - $this->_redirect_after_action( |
|
1216 | - $success, |
|
1217 | - '', |
|
1218 | - '', |
|
1219 | - ['action' => 'country_settings', 'country' => $CNT_ISO], |
|
1220 | - true |
|
1221 | - ); |
|
1222 | - } |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * form_form_field_label_wrap |
|
1227 | - * |
|
1228 | - * @param string $label |
|
1229 | - * @return string |
|
1230 | - */ |
|
1231 | - public function country_form_field_label_wrap(string $label): string |
|
1232 | - { |
|
1233 | - return ' |
|
22 | + /** |
|
23 | + * @var EE_Core_Config |
|
24 | + */ |
|
25 | + public $core_config; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Initialize basic properties. |
|
30 | + */ |
|
31 | + protected function _init_page_props() |
|
32 | + { |
|
33 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
34 | + $this->page_label = GEN_SET_LABEL; |
|
35 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
36 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Set ajax hooks |
|
42 | + */ |
|
43 | + protected function _ajax_hooks() |
|
44 | + { |
|
45 | + add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']); |
|
46 | + add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']); |
|
47 | + add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3); |
|
48 | + add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * More page properties initialization. |
|
54 | + */ |
|
55 | + protected function _define_page_props() |
|
56 | + { |
|
57 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
58 | + $this->_labels = ['publishbox' => esc_html__('Update Settings', 'event_espresso')]; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Set page routes property. |
|
64 | + */ |
|
65 | + protected function _set_page_routes() |
|
66 | + { |
|
67 | + $this->_page_routes = [ |
|
68 | + 'critical_pages' => [ |
|
69 | + 'func' => '_espresso_page_settings', |
|
70 | + 'capability' => 'manage_options', |
|
71 | + ], |
|
72 | + 'update_espresso_page_settings' => [ |
|
73 | + 'func' => '_update_espresso_page_settings', |
|
74 | + 'capability' => 'manage_options', |
|
75 | + 'noheader' => true, |
|
76 | + ], |
|
77 | + 'default' => [ |
|
78 | + 'func' => '_your_organization_settings', |
|
79 | + 'capability' => 'manage_options', |
|
80 | + ], |
|
81 | + |
|
82 | + 'update_your_organization_settings' => [ |
|
83 | + 'func' => '_update_your_organization_settings', |
|
84 | + 'capability' => 'manage_options', |
|
85 | + 'noheader' => true, |
|
86 | + ], |
|
87 | + |
|
88 | + 'admin_option_settings' => [ |
|
89 | + 'func' => '_admin_option_settings', |
|
90 | + 'capability' => 'manage_options', |
|
91 | + ], |
|
92 | + |
|
93 | + 'update_admin_option_settings' => [ |
|
94 | + 'func' => '_update_admin_option_settings', |
|
95 | + 'capability' => 'manage_options', |
|
96 | + 'noheader' => true, |
|
97 | + ], |
|
98 | + |
|
99 | + 'country_settings' => [ |
|
100 | + 'func' => '_country_settings', |
|
101 | + 'capability' => 'manage_options', |
|
102 | + ], |
|
103 | + |
|
104 | + 'update_country_settings' => [ |
|
105 | + 'func' => '_update_country_settings', |
|
106 | + 'capability' => 'manage_options', |
|
107 | + 'noheader' => true, |
|
108 | + ], |
|
109 | + |
|
110 | + 'display_country_settings' => [ |
|
111 | + 'func' => 'display_country_settings', |
|
112 | + 'capability' => 'manage_options', |
|
113 | + 'noheader' => true, |
|
114 | + ], |
|
115 | + |
|
116 | + 'add_new_state' => [ |
|
117 | + 'func' => 'add_new_state', |
|
118 | + 'capability' => 'manage_options', |
|
119 | + 'noheader' => true, |
|
120 | + ], |
|
121 | + |
|
122 | + 'delete_state' => [ |
|
123 | + 'func' => 'delete_state', |
|
124 | + 'capability' => 'manage_options', |
|
125 | + 'noheader' => true, |
|
126 | + ], |
|
127 | + 'privacy_settings' => [ |
|
128 | + 'func' => 'privacySettings', |
|
129 | + 'capability' => 'manage_options', |
|
130 | + ], |
|
131 | + 'update_privacy_settings' => [ |
|
132 | + 'func' => 'updatePrivacySettings', |
|
133 | + 'capability' => 'manage_options', |
|
134 | + 'noheader' => true, |
|
135 | + 'headers_sent_route' => 'privacy_settings', |
|
136 | + ], |
|
137 | + ]; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Set page configuration property |
|
143 | + */ |
|
144 | + protected function _set_page_config() |
|
145 | + { |
|
146 | + $this->_page_config = [ |
|
147 | + 'critical_pages' => [ |
|
148 | + 'nav' => [ |
|
149 | + 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
150 | + 'order' => 50, |
|
151 | + ], |
|
152 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
153 | + 'help_tabs' => [ |
|
154 | + 'general_settings_critical_pages_help_tab' => [ |
|
155 | + 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
156 | + 'filename' => 'general_settings_critical_pages', |
|
157 | + ], |
|
158 | + ], |
|
159 | + 'require_nonce' => false, |
|
160 | + ], |
|
161 | + 'default' => [ |
|
162 | + 'nav' => [ |
|
163 | + 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
164 | + 'order' => 20, |
|
165 | + ], |
|
166 | + 'help_tabs' => [ |
|
167 | + 'general_settings_your_organization_help_tab' => [ |
|
168 | + 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
169 | + 'filename' => 'general_settings_your_organization', |
|
170 | + ], |
|
171 | + ], |
|
172 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
173 | + 'require_nonce' => false, |
|
174 | + ], |
|
175 | + 'admin_option_settings' => [ |
|
176 | + 'nav' => [ |
|
177 | + 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
178 | + 'order' => 60, |
|
179 | + ], |
|
180 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
181 | + 'help_tabs' => [ |
|
182 | + 'general_settings_admin_options_help_tab' => [ |
|
183 | + 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
184 | + 'filename' => 'general_settings_admin_options', |
|
185 | + ], |
|
186 | + ], |
|
187 | + 'require_nonce' => false, |
|
188 | + ], |
|
189 | + 'country_settings' => [ |
|
190 | + 'nav' => [ |
|
191 | + 'label' => esc_html__('Countries', 'event_espresso'), |
|
192 | + 'order' => 70, |
|
193 | + ], |
|
194 | + 'help_tabs' => [ |
|
195 | + 'general_settings_countries_help_tab' => [ |
|
196 | + 'title' => esc_html__('Countries', 'event_espresso'), |
|
197 | + 'filename' => 'general_settings_countries', |
|
198 | + ], |
|
199 | + ], |
|
200 | + 'require_nonce' => false, |
|
201 | + ], |
|
202 | + 'privacy_settings' => [ |
|
203 | + 'nav' => [ |
|
204 | + 'label' => esc_html__('Privacy', 'event_espresso'), |
|
205 | + 'order' => 80, |
|
206 | + ], |
|
207 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
208 | + 'require_nonce' => false, |
|
209 | + ], |
|
210 | + ]; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + protected function _add_screen_options() |
|
215 | + { |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + protected function _add_feature_pointers() |
|
220 | + { |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
226 | + */ |
|
227 | + public function load_scripts_styles() |
|
228 | + { |
|
229 | + // styles |
|
230 | + wp_enqueue_style('espresso-ui-theme'); |
|
231 | + // scripts |
|
232 | + wp_enqueue_script('ee_admin_js'); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Execute logic running on `admin_init` |
|
238 | + */ |
|
239 | + public function admin_init() |
|
240 | + { |
|
241 | + $this->core_config = EE_Registry::instance()->CFG->core; |
|
242 | + |
|
243 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags( |
|
244 | + esc_html__( |
|
245 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
246 | + 'event_espresso' |
|
247 | + ) |
|
248 | + ); |
|
249 | + EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
250 | + esc_html__( |
|
251 | + 'An error occurred! Please refresh the page and try again.', |
|
252 | + 'event_espresso' |
|
253 | + ) |
|
254 | + ); |
|
255 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
256 | + esc_html__( |
|
257 | + 'Are you sure you want to delete this State / Province?', |
|
258 | + 'event_espresso' |
|
259 | + ) |
|
260 | + ); |
|
261 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
262 | + 'admin-ajax.php?page=espresso_general_settings', |
|
263 | + is_ssl() ? 'https://' : 'http://' |
|
264 | + ); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + public function admin_notices() |
|
269 | + { |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + public function admin_footer_scripts() |
|
274 | + { |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * Enqueue scripts and styles for the default route. |
|
280 | + */ |
|
281 | + public function load_scripts_styles_default() |
|
282 | + { |
|
283 | + // styles |
|
284 | + wp_enqueue_style('thickbox'); |
|
285 | + // scripts |
|
286 | + wp_enqueue_script('media-upload'); |
|
287 | + wp_enqueue_script('thickbox'); |
|
288 | + wp_register_script( |
|
289 | + 'organization_settings', |
|
290 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
291 | + ['jquery', 'media-upload', 'thickbox'], |
|
292 | + EVENT_ESPRESSO_VERSION, |
|
293 | + true |
|
294 | + ); |
|
295 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
296 | + wp_enqueue_script('organization_settings'); |
|
297 | + wp_enqueue_style('organization-css'); |
|
298 | + $confirm_image_delete = [ |
|
299 | + 'text' => wp_strip_all_tags( |
|
300 | + esc_html__( |
|
301 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
302 | + 'event_espresso' |
|
303 | + ) |
|
304 | + ), |
|
305 | + ]; |
|
306 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Enqueue scripts and styles for the country settings route. |
|
312 | + */ |
|
313 | + public function load_scripts_styles_country_settings() |
|
314 | + { |
|
315 | + // scripts |
|
316 | + wp_register_script( |
|
317 | + 'gen_settings_countries', |
|
318 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
319 | + ['ee_admin_js'], |
|
320 | + EVENT_ESPRESSO_VERSION, |
|
321 | + true |
|
322 | + ); |
|
323 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
324 | + wp_enqueue_script('gen_settings_countries'); |
|
325 | + wp_enqueue_style('organization-css'); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /************* Espresso Pages *************/ |
|
330 | + /** |
|
331 | + * _espresso_page_settings |
|
332 | + * |
|
333 | + * @throws EE_Error |
|
334 | + * @throws DomainException |
|
335 | + * @throws DomainException |
|
336 | + * @throws InvalidDataTypeException |
|
337 | + * @throws InvalidArgumentException |
|
338 | + */ |
|
339 | + protected function _espresso_page_settings() |
|
340 | + { |
|
341 | + // Check to make sure all of the main pages are set up properly, |
|
342 | + // if not create the default pages and display an admin notice |
|
343 | + EEH_Activation::verify_default_pages_exist(); |
|
344 | + $this->_transient_garbage_collection(); |
|
345 | + |
|
346 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
347 | + |
|
348 | + $this->_template_args['reg_page_id'] = $this->core_config->reg_page_id ?? null; |
|
349 | + $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id) |
|
350 | + ? get_post($this->core_config->reg_page_id) |
|
351 | + : false; |
|
352 | + |
|
353 | + $this->_template_args['txn_page_id'] = $this->core_config->txn_page_id ?? null; |
|
354 | + $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id) |
|
355 | + ? get_post($this->core_config->txn_page_id) |
|
356 | + : false; |
|
357 | + |
|
358 | + $this->_template_args['thank_you_page_id'] = $this->core_config->thank_you_page_id ?? null; |
|
359 | + $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id) |
|
360 | + ? get_post($this->core_config->thank_you_page_id) |
|
361 | + : false; |
|
362 | + |
|
363 | + $this->_template_args['cancel_page_id'] = $this->core_config->cancel_page_id ?? null; |
|
364 | + $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id) |
|
365 | + ? get_post($this->core_config->cancel_page_id) |
|
366 | + : false; |
|
367 | + |
|
368 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
369 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
370 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
371 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
372 | + $this->_template_args, |
|
373 | + true |
|
374 | + ); |
|
375 | + $this->display_admin_page_with_sidebar(); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * Handler for updating espresso page settings. |
|
381 | + * |
|
382 | + * @throws EE_Error |
|
383 | + */ |
|
384 | + protected function _update_espresso_page_settings() |
|
385 | + { |
|
386 | + $this->core_config = EE_Registry::instance()->CFG->core; |
|
387 | + // capture incoming request data && set page IDs |
|
388 | + $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
389 | + 'reg_page_id', |
|
390 | + $this->core_config->reg_page_id, |
|
391 | + DataType::INT |
|
392 | + ); |
|
393 | + $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
394 | + 'txn_page_id', |
|
395 | + $this->core_config->txn_page_id, |
|
396 | + DataType::INT |
|
397 | + ); |
|
398 | + $this->core_config->thank_you_page_id = $this->request->getRequestParam( |
|
399 | + 'thank_you_page_id', |
|
400 | + $this->core_config->thank_you_page_id, |
|
401 | + DataType::INT |
|
402 | + ); |
|
403 | + $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
404 | + 'cancel_page_id', |
|
405 | + $this->core_config->cancel_page_id, |
|
406 | + DataType::INT |
|
407 | + ); |
|
408 | + |
|
409 | + $this->core_config = apply_filters( |
|
410 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
411 | + $this->core_config, |
|
412 | + $this->request->requestParams() |
|
413 | + ); |
|
414 | + |
|
415 | + $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
416 | + $this->_redirect_after_action( |
|
417 | + $this->_update_espresso_configuration( |
|
418 | + $what, |
|
419 | + $this->core_config, |
|
420 | + __FILE__, |
|
421 | + __FUNCTION__, |
|
422 | + __LINE__ |
|
423 | + ), |
|
424 | + $what, |
|
425 | + '', |
|
426 | + [ |
|
427 | + 'action' => 'critical_pages', |
|
428 | + ], |
|
429 | + true |
|
430 | + ); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /************* Your Organization *************/ |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @throws DomainException |
|
439 | + * @throws EE_Error |
|
440 | + * @throws InvalidArgumentException |
|
441 | + * @throws InvalidDataTypeException |
|
442 | + * @throws InvalidInterfaceException |
|
443 | + */ |
|
444 | + protected function _your_organization_settings() |
|
445 | + { |
|
446 | + $this->_template_args['admin_page_content'] = ''; |
|
447 | + try { |
|
448 | + /** @var OrganizationSettings $organization_settings_form */ |
|
449 | + $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
450 | + |
|
451 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
452 | + $organization_settings_form->display(), |
|
453 | + '', |
|
454 | + 'padding' |
|
455 | + ); |
|
456 | + } catch (Exception $e) { |
|
457 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
458 | + } |
|
459 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
460 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
461 | + $this->display_admin_page_with_sidebar(); |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * Handler for updating organization settings. |
|
467 | + * |
|
468 | + * @throws EE_Error |
|
469 | + */ |
|
470 | + protected function _update_your_organization_settings() |
|
471 | + { |
|
472 | + try { |
|
473 | + /** @var OrganizationSettings $organization_settings_form */ |
|
474 | + $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
475 | + |
|
476 | + $success = $organization_settings_form->process($this->request->requestParams()); |
|
477 | + |
|
478 | + EE_Registry::instance()->CFG = apply_filters( |
|
479 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
480 | + EE_Registry::instance()->CFG |
|
481 | + ); |
|
482 | + } catch (Exception $e) { |
|
483 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
484 | + $success = false; |
|
485 | + } |
|
486 | + |
|
487 | + if ($success) { |
|
488 | + $success = $this->_update_espresso_configuration( |
|
489 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
490 | + EE_Registry::instance()->CFG, |
|
491 | + __FILE__, |
|
492 | + __FUNCTION__, |
|
493 | + __LINE__ |
|
494 | + ); |
|
495 | + } |
|
496 | + |
|
497 | + $this->_redirect_after_action($success, '', '', ['action' => 'default'], true); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /************* Admin Options *************/ |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * _admin_option_settings |
|
507 | + * |
|
508 | + * @throws EE_Error |
|
509 | + * @throws LogicException |
|
510 | + */ |
|
511 | + protected function _admin_option_settings() |
|
512 | + { |
|
513 | + $this->_template_args['admin_page_content'] = ''; |
|
514 | + try { |
|
515 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
516 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
517 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
518 | + // also need to account for the do_action that was in the old template |
|
519 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
520 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
521 | + $admin_options_settings_form->display(), |
|
522 | + '', |
|
523 | + 'padding' |
|
524 | + ); |
|
525 | + } catch (Exception $e) { |
|
526 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
527 | + } |
|
528 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
529 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
530 | + $this->display_admin_page_with_sidebar(); |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * _update_admin_option_settings |
|
536 | + * |
|
537 | + * @throws EE_Error |
|
538 | + * @throws InvalidDataTypeException |
|
539 | + * @throws InvalidFormSubmissionException |
|
540 | + * @throws InvalidArgumentException |
|
541 | + * @throws LogicException |
|
542 | + */ |
|
543 | + protected function _update_admin_option_settings() |
|
544 | + { |
|
545 | + try { |
|
546 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
547 | + $admin_options_settings_form->process( |
|
548 | + $this->request->getRequestParam( |
|
549 | + $admin_options_settings_form->slug(), |
|
550 | + [], |
|
551 | + DataType::STRING, |
|
552 | + true |
|
553 | + ) |
|
554 | + ); |
|
555 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
556 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
557 | + EE_Registry::instance()->CFG->admin |
|
558 | + ); |
|
559 | + } catch (Exception $e) { |
|
560 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
561 | + } |
|
562 | + $this->_redirect_after_action( |
|
563 | + apply_filters( |
|
564 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
565 | + $this->_update_espresso_configuration( |
|
566 | + esc_html__('Admin Options', 'event_espresso'), |
|
567 | + EE_Registry::instance()->CFG->admin, |
|
568 | + __FILE__, |
|
569 | + __FUNCTION__, |
|
570 | + __LINE__ |
|
571 | + ) |
|
572 | + ), |
|
573 | + esc_html__('Admin Options', 'event_espresso'), |
|
574 | + 'updated', |
|
575 | + ['action' => 'admin_option_settings'] |
|
576 | + ); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /************* Countries *************/ |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * @param string|null $default |
|
585 | + * @return string |
|
586 | + */ |
|
587 | + protected function getCountryISO(?string $default = null): string |
|
588 | + { |
|
589 | + $default = $default ?? $this->getCountryIsoForSite(); |
|
590 | + $CNT_ISO = $this->request->getRequestParam('country', $default); |
|
591 | + return strtoupper($CNT_ISO); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * @return string |
|
597 | + */ |
|
598 | + protected function getCountryIsoForSite(): string |
|
599 | + { |
|
600 | + return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
601 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
602 | + : 'US'; |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * @param string $CNT_ISO |
|
608 | + * @param EE_Country|null $country |
|
609 | + * @return EE_Base_Class|EE_Country |
|
610 | + * @throws EE_Error |
|
611 | + * @throws InvalidArgumentException |
|
612 | + * @throws InvalidDataTypeException |
|
613 | + * @throws InvalidInterfaceException |
|
614 | + * @throws ReflectionException |
|
615 | + */ |
|
616 | + protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null) |
|
617 | + { |
|
618 | + /** @var EE_Country $country */ |
|
619 | + return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
620 | + ? $country |
|
621 | + : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + /** |
|
626 | + * Output Country Settings view. |
|
627 | + * |
|
628 | + * @throws DomainException |
|
629 | + * @throws EE_Error |
|
630 | + * @throws InvalidArgumentException |
|
631 | + * @throws InvalidDataTypeException |
|
632 | + * @throws InvalidInterfaceException |
|
633 | + * @throws ReflectionException |
|
634 | + */ |
|
635 | + protected function _country_settings() |
|
636 | + { |
|
637 | + $CNT_ISO = $this->getCountryISO(); |
|
638 | + |
|
639 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
640 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
641 | + EE_Question::new_instance( |
|
642 | + [ |
|
643 | + 'QST_ID' => 0, |
|
644 | + 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
645 | + 'QST_system' => 'admin-country', |
|
646 | + ] |
|
647 | + ), |
|
648 | + EE_Answer::new_instance( |
|
649 | + [ |
|
650 | + 'ANS_ID' => 0, |
|
651 | + 'ANS_value' => $CNT_ISO, |
|
652 | + ] |
|
653 | + ), |
|
654 | + [ |
|
655 | + 'input_id' => 'country', |
|
656 | + 'input_name' => 'country', |
|
657 | + 'input_prefix' => '', |
|
658 | + 'append_qstn_id' => false, |
|
659 | + ] |
|
660 | + ); |
|
661 | + |
|
662 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
663 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10); |
|
664 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10); |
|
665 | + $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
666 | + $country->ID(), |
|
667 | + $country |
|
668 | + ); |
|
669 | + $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
670 | + $country->ID(), |
|
671 | + $country |
|
672 | + ); |
|
673 | + $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
674 | + |
|
675 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
676 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
677 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
678 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
679 | + $this->_template_args, |
|
680 | + true |
|
681 | + ); |
|
682 | + $this->display_admin_page_with_no_sidebar(); |
|
683 | + } |
|
684 | + |
|
685 | + |
|
686 | + /** |
|
687 | + * @param string $CNT_ISO |
|
688 | + * @param EE_Country|null $country |
|
689 | + * @return string |
|
690 | + * @throws DomainException |
|
691 | + * @throws EE_Error |
|
692 | + * @throws InvalidArgumentException |
|
693 | + * @throws InvalidDataTypeException |
|
694 | + * @throws InvalidInterfaceException |
|
695 | + * @throws ReflectionException |
|
696 | + */ |
|
697 | + public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
698 | + { |
|
699 | + $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
700 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
701 | + |
|
702 | + if (! $CNT_ISO) { |
|
703 | + return ''; |
|
704 | + } |
|
705 | + |
|
706 | + // for ajax |
|
707 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
708 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
709 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2); |
|
710 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2); |
|
711 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
712 | + $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
713 | + $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
714 | + |
|
715 | + $country_input_types = [ |
|
716 | + 'CNT_active' => [ |
|
717 | + 'type' => 'RADIO_BTN', |
|
718 | + 'input_name' => "cntry[$CNT_ISO]", |
|
719 | + 'class' => '', |
|
720 | + 'options' => $this->_yes_no_values, |
|
721 | + 'use_desc_4_label' => true, |
|
722 | + ], |
|
723 | + 'CNT_ISO' => [ |
|
724 | + 'type' => 'TEXT', |
|
725 | + 'input_name' => "cntry[$CNT_ISO]", |
|
726 | + 'class' => 'ee-input-width--small', |
|
727 | + ], |
|
728 | + 'CNT_ISO3' => [ |
|
729 | + 'type' => 'TEXT', |
|
730 | + 'input_name' => "cntry[$CNT_ISO]", |
|
731 | + 'class' => 'ee-input-width--small', |
|
732 | + ], |
|
733 | + // 'RGN_ID' => [ |
|
734 | + // 'type' => 'TEXT', |
|
735 | + // 'input_name' => "cntry[$CNT_ISO]", |
|
736 | + // 'class' => 'ee-input-width--small', |
|
737 | + // ], |
|
738 | + 'CNT_name' => [ |
|
739 | + 'type' => 'TEXT', |
|
740 | + 'input_name' => "cntry[$CNT_ISO]", |
|
741 | + 'class' => 'ee-input-width--big', |
|
742 | + ], |
|
743 | + 'CNT_cur_code' => [ |
|
744 | + 'type' => 'TEXT', |
|
745 | + 'input_name' => "cntry[$CNT_ISO]", |
|
746 | + 'class' => 'ee-input-width--small', |
|
747 | + 'disabled' => $CNT_cur_disabled, |
|
748 | + ], |
|
749 | + 'CNT_cur_single' => [ |
|
750 | + 'type' => 'TEXT', |
|
751 | + 'input_name' => "cntry[$CNT_ISO]", |
|
752 | + 'class' => 'ee-input-width--reg', |
|
753 | + 'disabled' => $CNT_cur_disabled, |
|
754 | + ], |
|
755 | + 'CNT_cur_plural' => [ |
|
756 | + 'type' => 'TEXT', |
|
757 | + 'input_name' => "cntry[$CNT_ISO]", |
|
758 | + 'class' => 'ee-input-width--reg', |
|
759 | + 'disabled' => $CNT_cur_disabled, |
|
760 | + ], |
|
761 | + 'CNT_cur_sign' => [ |
|
762 | + 'type' => 'TEXT', |
|
763 | + 'input_name' => "cntry[$CNT_ISO]", |
|
764 | + 'class' => 'ee-input-width--small', |
|
765 | + 'htmlentities' => false, |
|
766 | + 'disabled' => $CNT_cur_disabled, |
|
767 | + ], |
|
768 | + 'CNT_cur_sign_b4' => [ |
|
769 | + 'type' => 'RADIO_BTN', |
|
770 | + 'input_name' => "cntry[$CNT_ISO]", |
|
771 | + 'class' => '', |
|
772 | + 'options' => $this->_yes_no_values, |
|
773 | + 'use_desc_4_label' => true, |
|
774 | + 'disabled' => $CNT_cur_disabled, |
|
775 | + ], |
|
776 | + 'CNT_cur_dec_plc' => [ |
|
777 | + 'type' => 'RADIO_BTN', |
|
778 | + 'input_name' => "cntry[$CNT_ISO]", |
|
779 | + 'class' => '', |
|
780 | + 'options' => [ |
|
781 | + ['id' => 0, 'text' => ''], |
|
782 | + ['id' => 1, 'text' => ''], |
|
783 | + ['id' => 2, 'text' => ''], |
|
784 | + ['id' => 3, 'text' => ''], |
|
785 | + ], |
|
786 | + 'disabled' => $CNT_cur_disabled, |
|
787 | + ], |
|
788 | + 'CNT_cur_dec_mrk' => [ |
|
789 | + 'type' => 'RADIO_BTN', |
|
790 | + 'input_name' => "cntry[$CNT_ISO]", |
|
791 | + 'class' => '', |
|
792 | + 'options' => [ |
|
793 | + [ |
|
794 | + 'id' => ',', |
|
795 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
796 | + ], |
|
797 | + ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')], |
|
798 | + ], |
|
799 | + 'use_desc_4_label' => true, |
|
800 | + 'disabled' => $CNT_cur_disabled, |
|
801 | + ], |
|
802 | + 'CNT_cur_thsnds' => [ |
|
803 | + 'type' => 'RADIO_BTN', |
|
804 | + 'input_name' => "cntry[$CNT_ISO]", |
|
805 | + 'class' => '', |
|
806 | + 'options' => [ |
|
807 | + [ |
|
808 | + 'id' => ',', |
|
809 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
810 | + ], |
|
811 | + [ |
|
812 | + 'id' => '.', |
|
813 | + 'text' => esc_html__('. (decimal)', 'event_espresso'), |
|
814 | + ], |
|
815 | + [ |
|
816 | + 'id' => ' ', |
|
817 | + 'text' => esc_html__('(space)', 'event_espresso'), |
|
818 | + ], |
|
819 | + ], |
|
820 | + 'use_desc_4_label' => true, |
|
821 | + 'disabled' => $CNT_cur_disabled, |
|
822 | + ], |
|
823 | + 'CNT_tel_code' => [ |
|
824 | + 'type' => 'TEXT', |
|
825 | + 'input_name' => "cntry[$CNT_ISO]", |
|
826 | + 'class' => 'ee-input-width--small', |
|
827 | + ], |
|
828 | + 'CNT_is_EU' => [ |
|
829 | + 'type' => 'RADIO_BTN', |
|
830 | + 'input_name' => "cntry[$CNT_ISO]", |
|
831 | + 'class' => '', |
|
832 | + 'options' => $this->_yes_no_values, |
|
833 | + 'use_desc_4_label' => true, |
|
834 | + ], |
|
835 | + ]; |
|
836 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
837 | + $country, |
|
838 | + $country_input_types |
|
839 | + ); |
|
840 | + $country_details_settings = EEH_Template::display_template( |
|
841 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
842 | + $this->_template_args, |
|
843 | + true |
|
844 | + ); |
|
845 | + |
|
846 | + if (defined('DOING_AJAX')) { |
|
847 | + $notices = EE_Error::get_notices(false, false, false); |
|
848 | + echo wp_json_encode( |
|
849 | + [ |
|
850 | + 'return_data' => $country_details_settings, |
|
851 | + 'success' => $notices['success'], |
|
852 | + 'errors' => $notices['errors'], |
|
853 | + ] |
|
854 | + ); |
|
855 | + die(); |
|
856 | + } |
|
857 | + return $country_details_settings; |
|
858 | + } |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * @param string $CNT_ISO |
|
863 | + * @param EE_Country|null $country |
|
864 | + * @return string |
|
865 | + * @throws DomainException |
|
866 | + * @throws EE_Error |
|
867 | + * @throws InvalidArgumentException |
|
868 | + * @throws InvalidDataTypeException |
|
869 | + * @throws InvalidInterfaceException |
|
870 | + * @throws ReflectionException |
|
871 | + */ |
|
872 | + public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
873 | + { |
|
874 | + $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
875 | + if (! $CNT_ISO) { |
|
876 | + return ''; |
|
877 | + } |
|
878 | + // for ajax |
|
879 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
880 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
881 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2); |
|
882 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10); |
|
883 | + $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
884 | + if (empty($states)) { |
|
885 | + /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
886 | + $countrySubRegionDao = $this->loader->getShared( |
|
887 | + 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
888 | + ); |
|
889 | + if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
890 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
891 | + if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
892 | + $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
893 | + } |
|
894 | + } |
|
895 | + } |
|
896 | + if (is_array($states)) { |
|
897 | + foreach ($states as $STA_ID => $state) { |
|
898 | + if ($state instanceof EE_State) { |
|
899 | + $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
900 | + $state, |
|
901 | + [ |
|
902 | + 'STA_abbrev' => [ |
|
903 | + 'type' => 'TEXT', |
|
904 | + 'label' => esc_html__('Code', 'event_espresso'), |
|
905 | + 'input_name' => "states[$STA_ID]", |
|
906 | + 'class' => 'ee-input-width--tiny', |
|
907 | + 'add_mobile_label' => true, |
|
908 | + ], |
|
909 | + 'STA_name' => [ |
|
910 | + 'type' => 'TEXT', |
|
911 | + 'label' => esc_html__('Name', 'event_espresso'), |
|
912 | + 'input_name' => "states[$STA_ID]", |
|
913 | + 'class' => 'ee-input-width--big', |
|
914 | + 'add_mobile_label' => true, |
|
915 | + ], |
|
916 | + 'STA_active' => [ |
|
917 | + 'type' => 'RADIO_BTN', |
|
918 | + 'label' => esc_html__('State Appears in Dropdown Select Lists', 'event_espresso'), |
|
919 | + 'input_name' => "states[$STA_ID]", |
|
920 | + 'options' => $this->_yes_no_values, |
|
921 | + 'use_desc_4_label' => true, |
|
922 | + 'add_mobile_label' => true, |
|
923 | + ], |
|
924 | + ] |
|
925 | + ); |
|
926 | + |
|
927 | + $delete_state_url = EE_Admin_Page::add_query_args_and_nonce( |
|
928 | + [ |
|
929 | + 'action' => 'delete_state', |
|
930 | + 'STA_ID' => $STA_ID, |
|
931 | + 'CNT_ISO' => $CNT_ISO, |
|
932 | + 'STA_abbrev' => $state->abbrev(), |
|
933 | + ], |
|
934 | + GEN_SET_ADMIN_URL |
|
935 | + ); |
|
936 | + |
|
937 | + $this->_template_args['states'][ $STA_ID ]['inputs'] = $inputs; |
|
938 | + $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url; |
|
939 | + } |
|
940 | + } |
|
941 | + } else { |
|
942 | + $this->_template_args['states'] = false; |
|
943 | + } |
|
944 | + |
|
945 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
946 | + ['action' => 'add_new_state'], |
|
947 | + GEN_SET_ADMIN_URL |
|
948 | + ); |
|
949 | + |
|
950 | + $state_details_settings = EEH_Template::display_template( |
|
951 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
952 | + $this->_template_args, |
|
953 | + true |
|
954 | + ); |
|
955 | + |
|
956 | + if (defined('DOING_AJAX')) { |
|
957 | + $notices = EE_Error::get_notices(false, false, false); |
|
958 | + echo wp_json_encode( |
|
959 | + [ |
|
960 | + 'return_data' => $state_details_settings, |
|
961 | + 'success' => $notices['success'], |
|
962 | + 'errors' => $notices['errors'], |
|
963 | + ] |
|
964 | + ); |
|
965 | + die(); |
|
966 | + } |
|
967 | + return $state_details_settings; |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + /** |
|
972 | + * @return void |
|
973 | + * @throws EE_Error |
|
974 | + * @throws InvalidArgumentException |
|
975 | + * @throws InvalidDataTypeException |
|
976 | + * @throws InvalidInterfaceException |
|
977 | + * @throws ReflectionException |
|
978 | + */ |
|
979 | + public function add_new_state() |
|
980 | + { |
|
981 | + $success = true; |
|
982 | + $CNT_ISO = $this->getCountryISO(''); |
|
983 | + if (! $CNT_ISO) { |
|
984 | + EE_Error::add_error( |
|
985 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
986 | + __FILE__, |
|
987 | + __FUNCTION__, |
|
988 | + __LINE__ |
|
989 | + ); |
|
990 | + $success = false; |
|
991 | + } |
|
992 | + $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
993 | + if (! $STA_abbrev) { |
|
994 | + EE_Error::add_error( |
|
995 | + esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
996 | + __FILE__, |
|
997 | + __FUNCTION__, |
|
998 | + __LINE__ |
|
999 | + ); |
|
1000 | + $success = false; |
|
1001 | + } |
|
1002 | + $STA_name = $this->request->getRequestParam('STA_name'); |
|
1003 | + if (! $STA_name) { |
|
1004 | + EE_Error::add_error( |
|
1005 | + esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
1006 | + __FILE__, |
|
1007 | + __FUNCTION__, |
|
1008 | + __LINE__ |
|
1009 | + ); |
|
1010 | + $success = false; |
|
1011 | + } |
|
1012 | + |
|
1013 | + if ($success) { |
|
1014 | + $cols_n_values = [ |
|
1015 | + 'CNT_ISO' => $CNT_ISO, |
|
1016 | + 'STA_abbrev' => $STA_abbrev, |
|
1017 | + 'STA_name' => $STA_name, |
|
1018 | + 'STA_active' => true, |
|
1019 | + ]; |
|
1020 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
1021 | + EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
1022 | + } |
|
1023 | + |
|
1024 | + if (defined('DOING_AJAX')) { |
|
1025 | + $notices = EE_Error::get_notices(false, false, false); |
|
1026 | + echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO])); |
|
1027 | + die(); |
|
1028 | + } |
|
1029 | + $this->_redirect_after_action( |
|
1030 | + $success, |
|
1031 | + esc_html__('State', 'event_espresso'), |
|
1032 | + 'added', |
|
1033 | + ['action' => 'country_settings'] |
|
1034 | + ); |
|
1035 | + } |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * @return void |
|
1040 | + * @throws EE_Error |
|
1041 | + * @throws InvalidArgumentException |
|
1042 | + * @throws InvalidDataTypeException |
|
1043 | + * @throws InvalidInterfaceException |
|
1044 | + * @throws ReflectionException |
|
1045 | + */ |
|
1046 | + public function delete_state() |
|
1047 | + { |
|
1048 | + $CNT_ISO = $this->getCountryISO(); |
|
1049 | + $STA_ID = $this->request->getRequestParam('STA_ID'); |
|
1050 | + $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
1051 | + |
|
1052 | + if (! $STA_ID) { |
|
1053 | + EE_Error::add_error( |
|
1054 | + esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
1055 | + __FILE__, |
|
1056 | + __FUNCTION__, |
|
1057 | + __LINE__ |
|
1058 | + ); |
|
1059 | + return; |
|
1060 | + } |
|
1061 | + |
|
1062 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
1063 | + if ($success !== false) { |
|
1064 | + do_action( |
|
1065 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1066 | + $CNT_ISO, |
|
1067 | + $STA_ID, |
|
1068 | + ['STA_abbrev' => $STA_abbrev] |
|
1069 | + ); |
|
1070 | + EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
1071 | + } |
|
1072 | + if (defined('DOING_AJAX')) { |
|
1073 | + $notices = EE_Error::get_notices(false); |
|
1074 | + $notices['return_data'] = true; |
|
1075 | + echo wp_json_encode($notices); |
|
1076 | + die(); |
|
1077 | + } |
|
1078 | + $this->_redirect_after_action( |
|
1079 | + $success, |
|
1080 | + esc_html__('State', 'event_espresso'), |
|
1081 | + 'deleted', |
|
1082 | + ['action' => 'country_settings'] |
|
1083 | + ); |
|
1084 | + } |
|
1085 | + |
|
1086 | + |
|
1087 | + /** |
|
1088 | + * @return void |
|
1089 | + * @throws EE_Error |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + * @throws InvalidDataTypeException |
|
1092 | + * @throws InvalidInterfaceException |
|
1093 | + * @throws ReflectionException |
|
1094 | + */ |
|
1095 | + protected function _update_country_settings() |
|
1096 | + { |
|
1097 | + $CNT_ISO = $this->getCountryISO(); |
|
1098 | + if (! $CNT_ISO) { |
|
1099 | + EE_Error::add_error( |
|
1100 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1101 | + __FILE__, |
|
1102 | + __FUNCTION__, |
|
1103 | + __LINE__ |
|
1104 | + ); |
|
1105 | + return; |
|
1106 | + } |
|
1107 | + |
|
1108 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
1109 | + |
|
1110 | + $cols_n_values = []; |
|
1111 | + $cols_n_values['CNT_ISO3'] = strtoupper( |
|
1112 | + $this->request->getRequestParam('cntry', '', $country->ISO3()) |
|
1113 | + ); |
|
1114 | + $cols_n_values['CNT_name'] = |
|
1115 | + $this->request->getRequestParam("cntry[$CNT_ISO][CNT_name]", $country->name()); |
|
1116 | + $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1117 | + $this->request->getRequestParam( |
|
1118 | + "cntry[$CNT_ISO][CNT_cur_code]", |
|
1119 | + $country->currency_code() |
|
1120 | + ) |
|
1121 | + ); |
|
1122 | + $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
1123 | + "cntry[$CNT_ISO][CNT_cur_single]", |
|
1124 | + $country->currency_name_single() |
|
1125 | + ); |
|
1126 | + $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
1127 | + "cntry[$CNT_ISO][CNT_cur_plural]", |
|
1128 | + $country->currency_name_plural() |
|
1129 | + ); |
|
1130 | + $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
1131 | + "cntry[$CNT_ISO][CNT_cur_sign]", |
|
1132 | + $country->currency_sign() |
|
1133 | + ); |
|
1134 | + $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam( |
|
1135 | + "cntry[$CNT_ISO][CNT_cur_sign_b4]", |
|
1136 | + $country->currency_sign_before(), |
|
1137 | + DataType::BOOL |
|
1138 | + ); |
|
1139 | + $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam( |
|
1140 | + "cntry[$CNT_ISO][CNT_cur_dec_plc]", |
|
1141 | + $country->currency_decimal_places() |
|
1142 | + ); |
|
1143 | + $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam( |
|
1144 | + "cntry[$CNT_ISO][CNT_cur_dec_mrk]", |
|
1145 | + $country->currency_decimal_mark() |
|
1146 | + ); |
|
1147 | + $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
1148 | + "cntry[$CNT_ISO][CNT_cur_thsnds]", |
|
1149 | + $country->currency_thousands_separator() |
|
1150 | + ); |
|
1151 | + $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
1152 | + "cntry[$CNT_ISO][CNT_tel_code]", |
|
1153 | + $country->telephoneCode() |
|
1154 | + ); |
|
1155 | + $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
1156 | + "cntry[$CNT_ISO][CNT_active]", |
|
1157 | + $country->isActive(), |
|
1158 | + DataType::BOOL |
|
1159 | + ); |
|
1160 | + |
|
1161 | + // allow filtering of country data |
|
1162 | + $cols_n_values = apply_filters( |
|
1163 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1164 | + $cols_n_values |
|
1165 | + ); |
|
1166 | + |
|
1167 | + // where values |
|
1168 | + $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]]; |
|
1169 | + // run the update |
|
1170 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1171 | + |
|
1172 | + // allow filtering of states data |
|
1173 | + $states = apply_filters( |
|
1174 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1175 | + $this->request->getRequestParam('states', [], DataType::STRING, true) |
|
1176 | + ); |
|
1177 | + |
|
1178 | + if (! empty($states) && $success !== false) { |
|
1179 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
1180 | + foreach ($states as $STA_ID => $state) { |
|
1181 | + $cols_n_values = [ |
|
1182 | + 'CNT_ISO' => $CNT_ISO, |
|
1183 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1184 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1185 | + 'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN), |
|
1186 | + ]; |
|
1187 | + // where values |
|
1188 | + $where_cols_n_values = [['STA_ID' => $STA_ID]]; |
|
1189 | + // run the update |
|
1190 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1191 | + if ($success !== false) { |
|
1192 | + do_action( |
|
1193 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1194 | + $CNT_ISO, |
|
1195 | + $STA_ID, |
|
1196 | + $cols_n_values |
|
1197 | + ); |
|
1198 | + } |
|
1199 | + } |
|
1200 | + } |
|
1201 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1202 | + if ( |
|
1203 | + isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1204 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1205 | + ) { |
|
1206 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1207 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
1208 | + } |
|
1209 | + |
|
1210 | + if ($success !== false) { |
|
1211 | + EE_Error::add_success( |
|
1212 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1213 | + ); |
|
1214 | + } |
|
1215 | + $this->_redirect_after_action( |
|
1216 | + $success, |
|
1217 | + '', |
|
1218 | + '', |
|
1219 | + ['action' => 'country_settings', 'country' => $CNT_ISO], |
|
1220 | + true |
|
1221 | + ); |
|
1222 | + } |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * form_form_field_label_wrap |
|
1227 | + * |
|
1228 | + * @param string $label |
|
1229 | + * @return string |
|
1230 | + */ |
|
1231 | + public function country_form_field_label_wrap(string $label): string |
|
1232 | + { |
|
1233 | + return ' |
|
1234 | 1234 | <tr> |
1235 | 1235 | <th> |
1236 | 1236 | ' . $label . ' |
1237 | 1237 | </th>'; |
1238 | - } |
|
1239 | - |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * form_form_field_input__wrap |
|
1243 | - * |
|
1244 | - * @param string $input |
|
1245 | - * @return string |
|
1246 | - */ |
|
1247 | - public function country_form_field_input__wrap(string $input): string |
|
1248 | - { |
|
1249 | - return ' |
|
1238 | + } |
|
1239 | + |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * form_form_field_input__wrap |
|
1243 | + * |
|
1244 | + * @param string $input |
|
1245 | + * @return string |
|
1246 | + */ |
|
1247 | + public function country_form_field_input__wrap(string $input): string |
|
1248 | + { |
|
1249 | + return ' |
|
1250 | 1250 | <td class="general-settings-country-input-td"> |
1251 | 1251 | ' . $input . ' |
1252 | 1252 | </td> |
1253 | 1253 | </tr>'; |
1254 | - } |
|
1255 | - |
|
1256 | - |
|
1257 | - /** |
|
1258 | - * form_form_field_label_wrap |
|
1259 | - * |
|
1260 | - * @param string $label |
|
1261 | - * @param string $required_text |
|
1262 | - * @return string |
|
1263 | - */ |
|
1264 | - public function state_form_field_label_wrap(string $label, string $required_text): string |
|
1265 | - { |
|
1266 | - return $required_text; |
|
1267 | - } |
|
1268 | - |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * form_form_field_input__wrap |
|
1272 | - * |
|
1273 | - * @param string $input |
|
1274 | - * @return string |
|
1275 | - */ |
|
1276 | - public function state_form_field_input__wrap(string $input): string |
|
1277 | - { |
|
1278 | - return ' |
|
1254 | + } |
|
1255 | + |
|
1256 | + |
|
1257 | + /** |
|
1258 | + * form_form_field_label_wrap |
|
1259 | + * |
|
1260 | + * @param string $label |
|
1261 | + * @param string $required_text |
|
1262 | + * @return string |
|
1263 | + */ |
|
1264 | + public function state_form_field_label_wrap(string $label, string $required_text): string |
|
1265 | + { |
|
1266 | + return $required_text; |
|
1267 | + } |
|
1268 | + |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * form_form_field_input__wrap |
|
1272 | + * |
|
1273 | + * @param string $input |
|
1274 | + * @return string |
|
1275 | + */ |
|
1276 | + public function state_form_field_input__wrap(string $input): string |
|
1277 | + { |
|
1278 | + return ' |
|
1279 | 1279 | <td class="general-settings-country-state-input-td"> |
1280 | 1280 | ' . $input . ' |
1281 | 1281 | </td>'; |
1282 | - } |
|
1283 | - |
|
1284 | - |
|
1285 | - /***********/ |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * displays edit and view links for critical EE pages |
|
1290 | - * |
|
1291 | - * @param int $ee_page_id |
|
1292 | - * @return string |
|
1293 | - */ |
|
1294 | - public static function edit_view_links(int $ee_page_id): string |
|
1295 | - { |
|
1296 | - $edit_url = add_query_arg( |
|
1297 | - ['post' => $ee_page_id, 'action' => 'edit'], |
|
1298 | - admin_url('post.php') |
|
1299 | - ); |
|
1300 | - $links = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
1301 | - $links .= ' | '; |
|
1302 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1303 | - |
|
1304 | - return $links; |
|
1305 | - } |
|
1306 | - |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * displays page and shortcode status for critical EE pages |
|
1310 | - * |
|
1311 | - * @param WP_Post $ee_page |
|
1312 | - * @param string $shortcode |
|
1313 | - * @return string |
|
1314 | - */ |
|
1315 | - public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string |
|
1316 | - { |
|
1317 | - // page status |
|
1318 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1319 | - $pg_class = 'ee-status-bg--success'; |
|
1320 | - $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1321 | - } else { |
|
1322 | - $pg_class = 'ee-status-bg--error'; |
|
1323 | - $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1324 | - } |
|
1325 | - |
|
1326 | - // shortcode status |
|
1327 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1328 | - $sc_class = 'ee-status-bg--success'; |
|
1329 | - $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1330 | - } else { |
|
1331 | - $sc_class = 'ee-status-bg--error'; |
|
1332 | - $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1333 | - } |
|
1334 | - |
|
1335 | - return ' |
|
1282 | + } |
|
1283 | + |
|
1284 | + |
|
1285 | + /***********/ |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * displays edit and view links for critical EE pages |
|
1290 | + * |
|
1291 | + * @param int $ee_page_id |
|
1292 | + * @return string |
|
1293 | + */ |
|
1294 | + public static function edit_view_links(int $ee_page_id): string |
|
1295 | + { |
|
1296 | + $edit_url = add_query_arg( |
|
1297 | + ['post' => $ee_page_id, 'action' => 'edit'], |
|
1298 | + admin_url('post.php') |
|
1299 | + ); |
|
1300 | + $links = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
1301 | + $links .= ' | '; |
|
1302 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1303 | + |
|
1304 | + return $links; |
|
1305 | + } |
|
1306 | + |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * displays page and shortcode status for critical EE pages |
|
1310 | + * |
|
1311 | + * @param WP_Post $ee_page |
|
1312 | + * @param string $shortcode |
|
1313 | + * @return string |
|
1314 | + */ |
|
1315 | + public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string |
|
1316 | + { |
|
1317 | + // page status |
|
1318 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1319 | + $pg_class = 'ee-status-bg--success'; |
|
1320 | + $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1321 | + } else { |
|
1322 | + $pg_class = 'ee-status-bg--error'; |
|
1323 | + $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1324 | + } |
|
1325 | + |
|
1326 | + // shortcode status |
|
1327 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1328 | + $sc_class = 'ee-status-bg--success'; |
|
1329 | + $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1330 | + } else { |
|
1331 | + $sc_class = 'ee-status-bg--error'; |
|
1332 | + $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1333 | + } |
|
1334 | + |
|
1335 | + return ' |
|
1336 | 1336 | <span class="ee-page-status ' . $pg_class . '"><strong>' . $pg_status . '</strong></span> |
1337 | 1337 | <span class="ee-page-status ' . $sc_class . '"><strong>' . $sc_status . '</strong></span>'; |
1338 | - } |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * generates a dropdown of all parent pages - copied from WP core |
|
1343 | - * |
|
1344 | - * @param int $default |
|
1345 | - * @param int $parent |
|
1346 | - * @param int $level |
|
1347 | - * @param bool $echo |
|
1348 | - * @return string; |
|
1349 | - */ |
|
1350 | - public static function page_settings_dropdown( |
|
1351 | - int $default = 0, |
|
1352 | - int $parent = 0, |
|
1353 | - int $level = 0, |
|
1354 | - bool $echo = true |
|
1355 | - ): string { |
|
1356 | - global $wpdb; |
|
1357 | - $items = $wpdb->get_results( |
|
1358 | - $wpdb->prepare( |
|
1359 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1360 | - $parent |
|
1361 | - ) |
|
1362 | - ); |
|
1363 | - $output = ''; |
|
1364 | - |
|
1365 | - if ($items) { |
|
1366 | - $level = absint($level); |
|
1367 | - foreach ($items as $item) { |
|
1368 | - $ID = absint($item->ID); |
|
1369 | - $post_title = wp_strip_all_tags($item->post_title); |
|
1370 | - $pad = str_repeat(' ', $level * 3); |
|
1371 | - $option = "\n\t"; |
|
1372 | - $option .= '<option class="level-' . $level . '" '; |
|
1373 | - $option .= 'value="' . $ID . '" '; |
|
1374 | - $option .= $ID === absint($default) ? ' selected' : ''; |
|
1375 | - $option .= '>'; |
|
1376 | - $option .= "$pad {$post_title}"; |
|
1377 | - $option .= '</option>'; |
|
1378 | - $output .= $option; |
|
1379 | - ob_start(); |
|
1380 | - parent_dropdown($default, $item->ID, $level + 1); |
|
1381 | - $output .= ob_get_clean(); |
|
1382 | - } |
|
1383 | - } |
|
1384 | - if ($echo) { |
|
1385 | - echo wp_kses($output, AllowedTags::getWithFormTags()); |
|
1386 | - return ''; |
|
1387 | - } |
|
1388 | - return $output; |
|
1389 | - } |
|
1390 | - |
|
1391 | - |
|
1392 | - /** |
|
1393 | - * Loads the scripts for the privacy settings form |
|
1394 | - */ |
|
1395 | - public function load_scripts_styles_privacy_settings() |
|
1396 | - { |
|
1397 | - $form_handler = $this->loader->getShared( |
|
1398 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1399 | - ); |
|
1400 | - $form_handler->enqueueStylesAndScripts(); |
|
1401 | - } |
|
1402 | - |
|
1403 | - |
|
1404 | - /** |
|
1405 | - * display the privacy settings form |
|
1406 | - * |
|
1407 | - * @throws EE_Error |
|
1408 | - */ |
|
1409 | - public function privacySettings() |
|
1410 | - { |
|
1411 | - $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1412 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1413 | - $form_handler = $this->loader->getShared( |
|
1414 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1415 | - ); |
|
1416 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
1417 | - $form_handler->display(), |
|
1418 | - '', |
|
1419 | - 'padding' |
|
1420 | - ); |
|
1421 | - $this->display_admin_page_with_sidebar(); |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - /** |
|
1426 | - * Update the privacy settings from form data |
|
1427 | - * |
|
1428 | - * @throws EE_Error |
|
1429 | - */ |
|
1430 | - public function updatePrivacySettings() |
|
1431 | - { |
|
1432 | - $form_handler = $this->loader->getShared( |
|
1433 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1434 | - ); |
|
1435 | - $success = $form_handler->process($this->get_request_data()); |
|
1436 | - $this->_redirect_after_action( |
|
1437 | - $success, |
|
1438 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1439 | - 'updated', |
|
1440 | - ['action' => 'privacy_settings'] |
|
1441 | - ); |
|
1442 | - } |
|
1338 | + } |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * generates a dropdown of all parent pages - copied from WP core |
|
1343 | + * |
|
1344 | + * @param int $default |
|
1345 | + * @param int $parent |
|
1346 | + * @param int $level |
|
1347 | + * @param bool $echo |
|
1348 | + * @return string; |
|
1349 | + */ |
|
1350 | + public static function page_settings_dropdown( |
|
1351 | + int $default = 0, |
|
1352 | + int $parent = 0, |
|
1353 | + int $level = 0, |
|
1354 | + bool $echo = true |
|
1355 | + ): string { |
|
1356 | + global $wpdb; |
|
1357 | + $items = $wpdb->get_results( |
|
1358 | + $wpdb->prepare( |
|
1359 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1360 | + $parent |
|
1361 | + ) |
|
1362 | + ); |
|
1363 | + $output = ''; |
|
1364 | + |
|
1365 | + if ($items) { |
|
1366 | + $level = absint($level); |
|
1367 | + foreach ($items as $item) { |
|
1368 | + $ID = absint($item->ID); |
|
1369 | + $post_title = wp_strip_all_tags($item->post_title); |
|
1370 | + $pad = str_repeat(' ', $level * 3); |
|
1371 | + $option = "\n\t"; |
|
1372 | + $option .= '<option class="level-' . $level . '" '; |
|
1373 | + $option .= 'value="' . $ID . '" '; |
|
1374 | + $option .= $ID === absint($default) ? ' selected' : ''; |
|
1375 | + $option .= '>'; |
|
1376 | + $option .= "$pad {$post_title}"; |
|
1377 | + $option .= '</option>'; |
|
1378 | + $output .= $option; |
|
1379 | + ob_start(); |
|
1380 | + parent_dropdown($default, $item->ID, $level + 1); |
|
1381 | + $output .= ob_get_clean(); |
|
1382 | + } |
|
1383 | + } |
|
1384 | + if ($echo) { |
|
1385 | + echo wp_kses($output, AllowedTags::getWithFormTags()); |
|
1386 | + return ''; |
|
1387 | + } |
|
1388 | + return $output; |
|
1389 | + } |
|
1390 | + |
|
1391 | + |
|
1392 | + /** |
|
1393 | + * Loads the scripts for the privacy settings form |
|
1394 | + */ |
|
1395 | + public function load_scripts_styles_privacy_settings() |
|
1396 | + { |
|
1397 | + $form_handler = $this->loader->getShared( |
|
1398 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1399 | + ); |
|
1400 | + $form_handler->enqueueStylesAndScripts(); |
|
1401 | + } |
|
1402 | + |
|
1403 | + |
|
1404 | + /** |
|
1405 | + * display the privacy settings form |
|
1406 | + * |
|
1407 | + * @throws EE_Error |
|
1408 | + */ |
|
1409 | + public function privacySettings() |
|
1410 | + { |
|
1411 | + $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1412 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1413 | + $form_handler = $this->loader->getShared( |
|
1414 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1415 | + ); |
|
1416 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
1417 | + $form_handler->display(), |
|
1418 | + '', |
|
1419 | + 'padding' |
|
1420 | + ); |
|
1421 | + $this->display_admin_page_with_sidebar(); |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + /** |
|
1426 | + * Update the privacy settings from form data |
|
1427 | + * |
|
1428 | + * @throws EE_Error |
|
1429 | + */ |
|
1430 | + public function updatePrivacySettings() |
|
1431 | + { |
|
1432 | + $form_handler = $this->loader->getShared( |
|
1433 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
1434 | + ); |
|
1435 | + $success = $form_handler->process($this->get_request_data()); |
|
1436 | + $this->_redirect_after_action( |
|
1437 | + $success, |
|
1438 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1439 | + 'updated', |
|
1440 | + ['action' => 'privacy_settings'] |
|
1441 | + ); |
|
1442 | + } |
|
1443 | 1443 | } |
@@ -246,19 +246,19 @@ discard block |
||
246 | 246 | 'event_espresso' |
247 | 247 | ) |
248 | 248 | ); |
249 | - EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
249 | + EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
250 | 250 | esc_html__( |
251 | 251 | 'An error occurred! Please refresh the page and try again.', |
252 | 252 | 'event_espresso' |
253 | 253 | ) |
254 | 254 | ); |
255 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
255 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
256 | 256 | esc_html__( |
257 | 257 | 'Are you sure you want to delete this State / Province?', |
258 | 258 | 'event_espresso' |
259 | 259 | ) |
260 | 260 | ); |
261 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
261 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
262 | 262 | 'admin-ajax.php?page=espresso_general_settings', |
263 | 263 | is_ssl() ? 'https://' : 'http://' |
264 | 264 | ); |
@@ -287,12 +287,12 @@ discard block |
||
287 | 287 | wp_enqueue_script('thickbox'); |
288 | 288 | wp_register_script( |
289 | 289 | 'organization_settings', |
290 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
290 | + GEN_SET_ASSETS_URL.'your_organization_settings.js', |
|
291 | 291 | ['jquery', 'media-upload', 'thickbox'], |
292 | 292 | EVENT_ESPRESSO_VERSION, |
293 | 293 | true |
294 | 294 | ); |
295 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
295 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
296 | 296 | wp_enqueue_script('organization_settings'); |
297 | 297 | wp_enqueue_style('organization-css'); |
298 | 298 | $confirm_image_delete = [ |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | // scripts |
316 | 316 | wp_register_script( |
317 | 317 | 'gen_settings_countries', |
318 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
318 | + GEN_SET_ASSETS_URL.'gen_settings_countries.js', |
|
319 | 319 | ['ee_admin_js'], |
320 | 320 | EVENT_ESPRESSO_VERSION, |
321 | 321 | true |
322 | 322 | ); |
323 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
323 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
324 | 324 | wp_enqueue_script('gen_settings_countries'); |
325 | 325 | wp_enqueue_style('organization-css'); |
326 | 326 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
369 | 369 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
370 | 370 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
371 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
371 | + GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php', |
|
372 | 372 | $this->_template_args, |
373 | 373 | true |
374 | 374 | ); |
@@ -385,12 +385,12 @@ discard block |
||
385 | 385 | { |
386 | 386 | $this->core_config = EE_Registry::instance()->CFG->core; |
387 | 387 | // capture incoming request data && set page IDs |
388 | - $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
388 | + $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
389 | 389 | 'reg_page_id', |
390 | 390 | $this->core_config->reg_page_id, |
391 | 391 | DataType::INT |
392 | 392 | ); |
393 | - $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
393 | + $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
394 | 394 | 'txn_page_id', |
395 | 395 | $this->core_config->txn_page_id, |
396 | 396 | DataType::INT |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | $this->core_config->thank_you_page_id, |
401 | 401 | DataType::INT |
402 | 402 | ); |
403 | - $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
403 | + $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
404 | 404 | 'cancel_page_id', |
405 | 405 | $this->core_config->cancel_page_id, |
406 | 406 | DataType::INT |
@@ -666,16 +666,16 @@ discard block |
||
666 | 666 | $country->ID(), |
667 | 667 | $country |
668 | 668 | ); |
669 | - $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
669 | + $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
670 | 670 | $country->ID(), |
671 | 671 | $country |
672 | 672 | ); |
673 | - $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
673 | + $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
674 | 674 | |
675 | 675 | $this->_set_add_edit_form_tags('update_country_settings'); |
676 | 676 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
677 | 677 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
678 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
678 | + GEN_SET_TEMPLATE_PATH.'countries_settings.template.php', |
|
679 | 679 | $this->_template_args, |
680 | 680 | true |
681 | 681 | ); |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | $CNT_ISO = $this->getCountryISO($CNT_ISO); |
700 | 700 | $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
701 | 701 | |
702 | - if (! $CNT_ISO) { |
|
702 | + if ( ! $CNT_ISO) { |
|
703 | 703 | return ''; |
704 | 704 | } |
705 | 705 | |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
713 | 713 | $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
714 | 714 | |
715 | - $country_input_types = [ |
|
715 | + $country_input_types = [ |
|
716 | 716 | 'CNT_active' => [ |
717 | 717 | 'type' => 'RADIO_BTN', |
718 | 718 | 'input_name' => "cntry[$CNT_ISO]", |
@@ -837,8 +837,8 @@ discard block |
||
837 | 837 | $country, |
838 | 838 | $country_input_types |
839 | 839 | ); |
840 | - $country_details_settings = EEH_Template::display_template( |
|
841 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
840 | + $country_details_settings = EEH_Template::display_template( |
|
841 | + GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php', |
|
842 | 842 | $this->_template_args, |
843 | 843 | true |
844 | 844 | ); |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string |
873 | 873 | { |
874 | 874 | $CNT_ISO = $this->getCountryISO($CNT_ISO); |
875 | - if (! $CNT_ISO) { |
|
875 | + if ( ! $CNT_ISO) { |
|
876 | 876 | return ''; |
877 | 877 | } |
878 | 878 | // for ajax |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | GEN_SET_ADMIN_URL |
935 | 935 | ); |
936 | 936 | |
937 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = $inputs; |
|
938 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url; |
|
937 | + $this->_template_args['states'][$STA_ID]['inputs'] = $inputs; |
|
938 | + $this->_template_args['states'][$STA_ID]['delete_state_url'] = $delete_state_url; |
|
939 | 939 | } |
940 | 940 | } |
941 | 941 | } else { |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | ); |
949 | 949 | |
950 | 950 | $state_details_settings = EEH_Template::display_template( |
951 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
951 | + GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php', |
|
952 | 952 | $this->_template_args, |
953 | 953 | true |
954 | 954 | ); |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | { |
981 | 981 | $success = true; |
982 | 982 | $CNT_ISO = $this->getCountryISO(''); |
983 | - if (! $CNT_ISO) { |
|
983 | + if ( ! $CNT_ISO) { |
|
984 | 984 | EE_Error::add_error( |
985 | 985 | esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
986 | 986 | __FILE__, |
@@ -990,7 +990,7 @@ discard block |
||
990 | 990 | $success = false; |
991 | 991 | } |
992 | 992 | $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
993 | - if (! $STA_abbrev) { |
|
993 | + if ( ! $STA_abbrev) { |
|
994 | 994 | EE_Error::add_error( |
995 | 995 | esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
996 | 996 | __FILE__, |
@@ -1000,7 +1000,7 @@ discard block |
||
1000 | 1000 | $success = false; |
1001 | 1001 | } |
1002 | 1002 | $STA_name = $this->request->getRequestParam('STA_name'); |
1003 | - if (! $STA_name) { |
|
1003 | + if ( ! $STA_name) { |
|
1004 | 1004 | EE_Error::add_error( |
1005 | 1005 | esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
1006 | 1006 | __FILE__, |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | 'STA_name' => $STA_name, |
1018 | 1018 | 'STA_active' => true, |
1019 | 1019 | ]; |
1020 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
1020 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
1021 | 1021 | EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
1022 | 1022 | } |
1023 | 1023 | |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | $STA_ID = $this->request->getRequestParam('STA_ID'); |
1050 | 1050 | $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
1051 | 1051 | |
1052 | - if (! $STA_ID) { |
|
1052 | + if ( ! $STA_ID) { |
|
1053 | 1053 | EE_Error::add_error( |
1054 | 1054 | esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
1055 | 1055 | __FILE__, |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | protected function _update_country_settings() |
1096 | 1096 | { |
1097 | 1097 | $CNT_ISO = $this->getCountryISO(); |
1098 | - if (! $CNT_ISO) { |
|
1098 | + if ( ! $CNT_ISO) { |
|
1099 | 1099 | EE_Error::add_error( |
1100 | 1100 | esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
1101 | 1101 | __FILE__, |
@@ -1119,15 +1119,15 @@ discard block |
||
1119 | 1119 | $country->currency_code() |
1120 | 1120 | ) |
1121 | 1121 | ); |
1122 | - $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
1122 | + $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
1123 | 1123 | "cntry[$CNT_ISO][CNT_cur_single]", |
1124 | 1124 | $country->currency_name_single() |
1125 | 1125 | ); |
1126 | - $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
1126 | + $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
1127 | 1127 | "cntry[$CNT_ISO][CNT_cur_plural]", |
1128 | 1128 | $country->currency_name_plural() |
1129 | 1129 | ); |
1130 | - $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
1130 | + $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
1131 | 1131 | "cntry[$CNT_ISO][CNT_cur_sign]", |
1132 | 1132 | $country->currency_sign() |
1133 | 1133 | ); |
@@ -1144,15 +1144,15 @@ discard block |
||
1144 | 1144 | "cntry[$CNT_ISO][CNT_cur_dec_mrk]", |
1145 | 1145 | $country->currency_decimal_mark() |
1146 | 1146 | ); |
1147 | - $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
1147 | + $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
1148 | 1148 | "cntry[$CNT_ISO][CNT_cur_thsnds]", |
1149 | 1149 | $country->currency_thousands_separator() |
1150 | 1150 | ); |
1151 | - $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
1151 | + $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
1152 | 1152 | "cntry[$CNT_ISO][CNT_tel_code]", |
1153 | 1153 | $country->telephoneCode() |
1154 | 1154 | ); |
1155 | - $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
1155 | + $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
1156 | 1156 | "cntry[$CNT_ISO][CNT_active]", |
1157 | 1157 | $country->isActive(), |
1158 | 1158 | DataType::BOOL |
@@ -1175,7 +1175,7 @@ discard block |
||
1175 | 1175 | $this->request->getRequestParam('states', [], DataType::STRING, true) |
1176 | 1176 | ); |
1177 | 1177 | |
1178 | - if (! empty($states) && $success !== false) { |
|
1178 | + if ( ! empty($states) && $success !== false) { |
|
1179 | 1179 | // loop thru state data ( looks like : states[75][STA_name] ) |
1180 | 1180 | foreach ($states as $STA_ID => $state) { |
1181 | 1181 | $cols_n_values = [ |
@@ -1233,7 +1233,7 @@ discard block |
||
1233 | 1233 | return ' |
1234 | 1234 | <tr> |
1235 | 1235 | <th> |
1236 | - ' . $label . ' |
|
1236 | + ' . $label.' |
|
1237 | 1237 | </th>'; |
1238 | 1238 | } |
1239 | 1239 | |
@@ -1248,7 +1248,7 @@ discard block |
||
1248 | 1248 | { |
1249 | 1249 | return ' |
1250 | 1250 | <td class="general-settings-country-input-td"> |
1251 | - ' . $input . ' |
|
1251 | + ' . $input.' |
|
1252 | 1252 | </td> |
1253 | 1253 | </tr>'; |
1254 | 1254 | } |
@@ -1277,7 +1277,7 @@ discard block |
||
1277 | 1277 | { |
1278 | 1278 | return ' |
1279 | 1279 | <td class="general-settings-country-state-input-td"> |
1280 | - ' . $input . ' |
|
1280 | + ' . $input.' |
|
1281 | 1281 | </td>'; |
1282 | 1282 | } |
1283 | 1283 | |
@@ -1297,9 +1297,9 @@ discard block |
||
1297 | 1297 | ['post' => $ee_page_id, 'action' => 'edit'], |
1298 | 1298 | admin_url('post.php') |
1299 | 1299 | ); |
1300 | - $links = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
1300 | + $links = '<a href="'.esc_url_raw($edit_url).'" >'.esc_html__('Edit', 'event_espresso').'</a>'; |
|
1301 | 1301 | $links .= ' | '; |
1302 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
1302 | + $links .= '<a href="'.get_permalink($ee_page_id).'" >'.esc_html__('View', 'event_espresso').'</a>'; |
|
1303 | 1303 | |
1304 | 1304 | return $links; |
1305 | 1305 | } |
@@ -1333,8 +1333,8 @@ discard block |
||
1333 | 1333 | } |
1334 | 1334 | |
1335 | 1335 | return ' |
1336 | - <span class="ee-page-status ' . $pg_class . '"><strong>' . $pg_status . '</strong></span> |
|
1337 | - <span class="ee-page-status ' . $sc_class . '"><strong>' . $sc_status . '</strong></span>'; |
|
1336 | + <span class="ee-page-status ' . $pg_class.'"><strong>'.$pg_status.'</strong></span> |
|
1337 | + <span class="ee-page-status ' . $sc_class.'"><strong>'.$sc_status.'</strong></span>'; |
|
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | bool $echo = true |
1355 | 1355 | ): string { |
1356 | 1356 | global $wpdb; |
1357 | - $items = $wpdb->get_results( |
|
1357 | + $items = $wpdb->get_results( |
|
1358 | 1358 | $wpdb->prepare( |
1359 | 1359 | "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
1360 | 1360 | $parent |
@@ -1369,8 +1369,8 @@ discard block |
||
1369 | 1369 | $post_title = wp_strip_all_tags($item->post_title); |
1370 | 1370 | $pad = str_repeat(' ', $level * 3); |
1371 | 1371 | $option = "\n\t"; |
1372 | - $option .= '<option class="level-' . $level . '" '; |
|
1373 | - $option .= 'value="' . $ID . '" '; |
|
1372 | + $option .= '<option class="level-'.$level.'" '; |
|
1373 | + $option .= 'value="'.$ID.'" '; |
|
1374 | 1374 | $option .= $ID === absint($default) ? ' selected' : ''; |
1375 | 1375 | $option .= '>'; |
1376 | 1376 | $option .= "$pad {$post_title}"; |