@@ -10,29 +10,29 @@ |
||
10 | 10 | class EE_Email_Confirm_Input extends EE_Form_Input_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $input_settings |
|
15 | - */ |
|
16 | - public function __construct($input_settings = array()) |
|
17 | - { |
|
18 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | - $this->_add_validation_strategy( |
|
21 | - new EE_Email_Validation_Strategy( |
|
22 | - isset($input_settings['validation_error_message']) |
|
23 | - ? $input_settings['validation_error_message'] |
|
24 | - : null |
|
25 | - ) |
|
26 | - ); |
|
27 | - $this->_add_validation_strategy( |
|
28 | - new EE_Equal_To_Validation_Strategy( |
|
29 | - isset($input_settings['validation_error_message']) |
|
30 | - ? $input_settings['validation_error_message'] |
|
31 | - : null, |
|
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | - ) |
|
34 | - ); |
|
35 | - parent::__construct($input_settings); |
|
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
37 | - } |
|
13 | + /** |
|
14 | + * @param array $input_settings |
|
15 | + */ |
|
16 | + public function __construct($input_settings = array()) |
|
17 | + { |
|
18 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | + $this->_add_validation_strategy( |
|
21 | + new EE_Email_Validation_Strategy( |
|
22 | + isset($input_settings['validation_error_message']) |
|
23 | + ? $input_settings['validation_error_message'] |
|
24 | + : null |
|
25 | + ) |
|
26 | + ); |
|
27 | + $this->_add_validation_strategy( |
|
28 | + new EE_Equal_To_Validation_Strategy( |
|
29 | + isset($input_settings['validation_error_message']) |
|
30 | + ? $input_settings['validation_error_message'] |
|
31 | + : null, |
|
32 | + '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | + ) |
|
34 | + ); |
|
35 | + parent::__construct($input_settings); |
|
36 | + $this->set_html_class($this->html_class() . ' email'); |
|
37 | + } |
|
38 | 38 | } |
@@ -29,10 +29,10 @@ |
||
29 | 29 | isset($input_settings['validation_error_message']) |
30 | 30 | ? $input_settings['validation_error_message'] |
31 | 31 | : null, |
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
32 | + '#'.str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | 33 | ) |
34 | 34 | ); |
35 | 35 | parent::__construct($input_settings); |
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
36 | + $this->set_html_class($this->html_class().' email'); |
|
37 | 37 | } |
38 | 38 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | */ |
24 | 24 | public function __construct($validation_error_message = '', $compare_to) |
25 | 25 | { |
26 | - if (! $validation_error_message) { |
|
26 | + if ( ! $validation_error_message) { |
|
27 | 27 | $validation_error_message = apply_filters( |
28 | 28 | 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
29 | 29 | esc_html__('Fields do not match.', 'event_espresso') |
@@ -16,49 +16,49 @@ |
||
16 | 16 | class EE_Equal_To_Validation_Strategy extends EE_Text_Validation_Strategy |
17 | 17 | { |
18 | 18 | |
19 | - protected $_compare_to = null; |
|
19 | + protected $_compare_to = null; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $validation_error_message |
|
24 | - */ |
|
25 | - public function __construct($validation_error_message = '', $compare_to) |
|
26 | - { |
|
27 | - if (! $validation_error_message) { |
|
28 | - $validation_error_message = apply_filters( |
|
29 | - 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
30 | - esc_html__('Fields do not match.', 'event_espresso') |
|
31 | - ); |
|
32 | - } |
|
33 | - parent::__construct($validation_error_message); |
|
34 | - $this->_compare_to = $compare_to; |
|
35 | - } |
|
22 | + /** |
|
23 | + * @param string $validation_error_message |
|
24 | + */ |
|
25 | + public function __construct($validation_error_message = '', $compare_to) |
|
26 | + { |
|
27 | + if (! $validation_error_message) { |
|
28 | + $validation_error_message = apply_filters( |
|
29 | + 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
30 | + esc_html__('Fields do not match.', 'event_espresso') |
|
31 | + ); |
|
32 | + } |
|
33 | + parent::__construct($validation_error_message); |
|
34 | + $this->_compare_to = $compare_to; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * just checks the field isn't blank |
|
41 | - * |
|
42 | - * @param $normalized_value |
|
43 | - * @return bool |
|
44 | - * @throws InvalidArgumentException |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - * @throws InvalidDataTypeException |
|
47 | - * @throws EE_Validation_Error |
|
48 | - */ |
|
49 | - public function validate($normalized_value) |
|
50 | - { |
|
51 | - // No need to be validated |
|
52 | - return true; |
|
53 | - } |
|
39 | + /** |
|
40 | + * just checks the field isn't blank |
|
41 | + * |
|
42 | + * @param $normalized_value |
|
43 | + * @return bool |
|
44 | + * @throws InvalidArgumentException |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + * @throws InvalidDataTypeException |
|
47 | + * @throws EE_Validation_Error |
|
48 | + */ |
|
49 | + public function validate($normalized_value) |
|
50 | + { |
|
51 | + // No need to be validated |
|
52 | + return true; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function get_jquery_validation_rule_array() |
|
61 | - { |
|
62 | - return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function get_jquery_validation_rule_array() |
|
61 | + { |
|
62 | + return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
63 | + } |
|
64 | 64 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation(); |
203 | 203 | $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation(); |
204 | 204 | $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback( |
205 | - static function () { |
|
205 | + static function() { |
|
206 | 206 | wp_add_inline_script( |
207 | 207 | CoreAssetManager::JS_HANDLE_DATA_STORES, |
208 | 208 | is_admin() |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | |
262 | 262 | $this->addJavascript( |
263 | 263 | CoreAssetManager::JS_HANDLE_CORE, |
264 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
264 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
265 | 265 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
266 | 266 | ) |
267 | 267 | ->setInlineDataCallback( |
268 | - static function () { |
|
268 | + static function() { |
|
269 | 269 | wp_localize_script( |
270 | 270 | CoreAssetManager::JS_HANDLE_CORE, |
271 | 271 | CoreAssetManager::JS_HANDLE_I18N, |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | if ($this->template_config->enable_default_style && ! is_admin()) { |
371 | 371 | $this->addStylesheet( |
372 | 372 | CoreAssetManager::CSS_HANDLE_DEFAULT, |
373 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
373 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css') |
|
374 | 374 | ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
375 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
375 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
376 | 376 | array('dashicons') |
377 | 377 | ); |
378 | 378 | //Load custom style sheet if available |
379 | 379 | if ($this->template_config->custom_style_sheet !== null) { |
380 | 380 | $this->addStylesheet( |
381 | 381 | CoreAssetManager::CSS_HANDLE_CUSTOM, |
382 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
382 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
383 | 383 | array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
384 | 384 | ); |
385 | 385 | } |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | { |
403 | 403 | $this->addJavascript( |
404 | 404 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
405 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
405 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
406 | 406 | array(CoreAssetManager::JS_HANDLE_JQUERY), |
407 | 407 | true, |
408 | 408 | '1.15.0' |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | |
411 | 411 | $this->addJavascript( |
412 | 412 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
413 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
413 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
414 | 414 | array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
415 | 415 | true, |
416 | 416 | '1.15.0' |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | // @link http://josscrowcroft.github.io/accounting.js/ |
434 | 434 | $this->addJavascript( |
435 | 435 | CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
436 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
436 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
437 | 437 | array(CoreAssetManager::JS_HANDLE_UNDERSCORE), |
438 | 438 | true, |
439 | 439 | '0.3.2' |
@@ -441,11 +441,11 @@ discard block |
||
441 | 441 | |
442 | 442 | $this->addJavascript( |
443 | 443 | CoreAssetManager::JS_HANDLE_ACCOUNTING, |
444 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
444 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
445 | 445 | array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
446 | 446 | ) |
447 | 447 | ->setInlineDataCallback( |
448 | - function () { |
|
448 | + function() { |
|
449 | 449 | wp_localize_script( |
450 | 450 | CoreAssetManager::JS_HANDLE_ACCOUNTING, |
451 | 451 | 'EE_ACCOUNTING_CFG', |
@@ -32,461 +32,461 @@ |
||
32 | 32 | class CoreAssetManager extends AssetManager |
33 | 33 | { |
34 | 34 | |
35 | - // WordPress core / Third party JS asset handles |
|
36 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
35 | + // WordPress core / Third party JS asset handles |
|
36 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
37 | 37 | |
38 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
38 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
39 | 39 | |
40 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
40 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
41 | 41 | |
42 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
42 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
43 | 43 | |
44 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
44 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 4.9.71.p |
|
48 | - */ |
|
49 | - const JS_HANDLE_REACT = 'react'; |
|
46 | + /** |
|
47 | + * @since 4.9.71.p |
|
48 | + */ |
|
49 | + const JS_HANDLE_REACT = 'react'; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @since 4.9.71.p |
|
53 | - */ |
|
54 | - const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
51 | + /** |
|
52 | + * @since 4.9.71.p |
|
53 | + */ |
|
54 | + const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @since 4.9.71.p |
|
58 | - */ |
|
59 | - const JS_HANDLE_LODASH = 'lodash'; |
|
56 | + /** |
|
57 | + * @since 4.9.71.p |
|
58 | + */ |
|
59 | + const JS_HANDLE_LODASH = 'lodash'; |
|
60 | 60 | |
61 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
61 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
62 | 62 | |
63 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
63 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
64 | 64 | |
65 | - const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
65 | + const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
66 | 66 | |
67 | - const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
67 | + const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
68 | 68 | |
69 | - const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
69 | + const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
70 | 70 | |
71 | - const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
71 | + const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
72 | 72 | |
73 | - const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
73 | + const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
74 | 74 | |
75 | - const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
75 | + const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
76 | 76 | |
77 | - const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
78 | - |
|
79 | - const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
77 | + const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
78 | + |
|
79 | + const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
80 | 80 | |
81 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
81 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
82 | 82 | |
83 | - const JS_HANDLE_I18N = 'eei18n'; |
|
83 | + const JS_HANDLE_I18N = 'eei18n'; |
|
84 | 84 | |
85 | - const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
86 | - |
|
87 | - const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
88 | - |
|
89 | - // EE CSS assets handles |
|
90 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
91 | - |
|
92 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
93 | - |
|
94 | - const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
95 | - |
|
96 | - const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default'; |
|
97 | - |
|
98 | - /** |
|
99 | - * @var EE_Currency_Config $currency_config |
|
100 | - */ |
|
101 | - protected $currency_config; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var EE_Template_Config $template_config |
|
105 | - */ |
|
106 | - protected $template_config; |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * CoreAssetRegister constructor. |
|
111 | - * |
|
112 | - * @param AssetCollection $assets |
|
113 | - * @param EE_Currency_Config $currency_config |
|
114 | - * @param EE_Template_Config $template_config |
|
115 | - * @param DomainInterface $domain |
|
116 | - * @param Registry $registry |
|
117 | - */ |
|
118 | - public function __construct( |
|
119 | - AssetCollection $assets, |
|
120 | - EE_Currency_Config $currency_config, |
|
121 | - EE_Template_Config $template_config, |
|
122 | - DomainInterface $domain, |
|
123 | - Registry $registry |
|
124 | - ) { |
|
125 | - $this->currency_config = $currency_config; |
|
126 | - $this->template_config = $template_config; |
|
127 | - parent::__construct($domain, $assets, $registry); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @since 4.9.62.p |
|
133 | - * @throws DomainException |
|
134 | - * @throws DuplicateCollectionIdentifierException |
|
135 | - * @throws InvalidArgumentException |
|
136 | - * @throws InvalidDataTypeException |
|
137 | - * @throws InvalidEntityException |
|
138 | - * @throws InvalidInterfaceException |
|
139 | - */ |
|
140 | - public function addAssets() |
|
141 | - { |
|
142 | - $this->addJavascriptFiles(); |
|
143 | - $this->addStylesheetFiles(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @since 4.9.62.p |
|
149 | - * @throws DomainException |
|
150 | - * @throws DuplicateCollectionIdentifierException |
|
151 | - * @throws InvalidArgumentException |
|
152 | - * @throws InvalidDataTypeException |
|
153 | - * @throws InvalidEntityException |
|
154 | - * @throws InvalidInterfaceException |
|
155 | - */ |
|
156 | - public function addJavascriptFiles() |
|
157 | - { |
|
158 | - $this->loadCoreJs(); |
|
159 | - $this->loadJqueryValidate(); |
|
160 | - $this->loadAccountingJs(); |
|
161 | - add_action( |
|
162 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
163 | - array($this, 'loadQtipJs') |
|
164 | - ); |
|
165 | - $this->registerAdminAssets(); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @throws DuplicateCollectionIdentifierException |
|
171 | - * @throws InvalidDataTypeException |
|
172 | - * @throws InvalidEntityException |
|
173 | - * @throws DomainException |
|
174 | - * @since 4.9.62.p |
|
175 | - */ |
|
176 | - public function addStylesheetFiles() |
|
177 | - { |
|
178 | - $this->loadCoreCss(); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * core default javascript |
|
184 | - * |
|
185 | - * @since 4.9.62.p |
|
186 | - * @throws DomainException |
|
187 | - * @throws DuplicateCollectionIdentifierException |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws InvalidDataTypeException |
|
190 | - * @throws InvalidEntityException |
|
191 | - * @throws InvalidInterfaceException |
|
192 | - */ |
|
193 | - private function loadCoreJs() |
|
194 | - { |
|
195 | - // conditionally load third-party libraries that WP core MIGHT have. |
|
196 | - $this->registerWpAssets(); |
|
197 | - |
|
198 | - $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
199 | - $this->addJs(self::JS_HANDLE_VENDOR); |
|
200 | - $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation(); |
|
201 | - $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation(); |
|
202 | - $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation(); |
|
203 | - $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation(); |
|
204 | - $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback( |
|
205 | - static function () { |
|
206 | - wp_add_inline_script( |
|
207 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
208 | - is_admin() |
|
209 | - ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )' |
|
210 | - : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )' |
|
211 | - ); |
|
212 | - } |
|
213 | - ); |
|
214 | - $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
215 | - $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
216 | - $this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation(); |
|
217 | - |
|
218 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
219 | - $this->registry->addData( |
|
220 | - 'paths', |
|
221 | - array( |
|
222 | - 'base_rest_route' => rest_url(), |
|
223 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
224 | - 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
225 | - 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
226 | - 'site_url' => site_url('/'), |
|
227 | - 'admin_url' => admin_url('/'), |
|
228 | - ) |
|
229 | - ); |
|
230 | - // Event Espresso brand name |
|
231 | - $this->registry->addData('brandName', Domain::brandName()); |
|
232 | - /** site formatting values **/ |
|
233 | - $this->registry->addData( |
|
234 | - 'site_formats', |
|
235 | - array( |
|
236 | - 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
237 | - ) |
|
238 | - ); |
|
239 | - /** currency data **/ |
|
240 | - $this->registry->addData( |
|
241 | - 'currency_config', |
|
242 | - $this->getCurrencySettings() |
|
243 | - ); |
|
244 | - /** site timezone */ |
|
245 | - $this->registry->addData( |
|
246 | - 'default_timezone', |
|
247 | - array( |
|
248 | - 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
249 | - 'string' => get_option('timezone_string'), |
|
250 | - 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
251 | - ) |
|
252 | - ); |
|
253 | - /** site locale (user locale if user logged in) */ |
|
254 | - $this->registry->addData( |
|
255 | - 'locale', |
|
256 | - array( |
|
257 | - 'user' => get_user_locale(), |
|
258 | - 'site' => get_locale() |
|
259 | - ) |
|
260 | - ); |
|
261 | - |
|
262 | - $this->addJavascript( |
|
263 | - CoreAssetManager::JS_HANDLE_CORE, |
|
264 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
265 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
266 | - ) |
|
267 | - ->setInlineDataCallback( |
|
268 | - static function () { |
|
269 | - wp_localize_script( |
|
270 | - CoreAssetManager::JS_HANDLE_CORE, |
|
271 | - CoreAssetManager::JS_HANDLE_I18N, |
|
272 | - EE_Registry::sanitize_i18n_js_strings() |
|
273 | - ); |
|
274 | - } |
|
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
281 | - * WordPress in the running environment. |
|
282 | - * |
|
283 | - * @throws DuplicateCollectionIdentifierException |
|
284 | - * @throws InvalidDataTypeException |
|
285 | - * @throws InvalidEntityException |
|
286 | - * @throws DomainException |
|
287 | - * @since 4.9.71.p |
|
288 | - */ |
|
289 | - private function registerWpAssets() |
|
290 | - { |
|
291 | - global $wp_version; |
|
292 | - if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
293 | - return; |
|
294 | - } |
|
295 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0'); |
|
296 | - $this->addVendorJavascript( |
|
297 | - CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
298 | - array(CoreAssetManager::JS_HANDLE_REACT), |
|
299 | - true, |
|
300 | - '16.6.0' |
|
301 | - ); |
|
302 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11') |
|
303 | - ->setInlineDataCallback( |
|
304 | - static function() { |
|
305 | - wp_add_inline_script( |
|
306 | - CoreAssetManager::JS_HANDLE_LODASH, |
|
307 | - 'window.lodash = _.noConflict();' |
|
308 | - ); |
|
309 | - } |
|
310 | - ); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Returns configuration data for the accounting-js library. |
|
316 | - * @since 4.9.71.p |
|
317 | - * @return array |
|
318 | - */ |
|
319 | - private function getAccountingSettings() { |
|
320 | - return array( |
|
321 | - 'currency' => array( |
|
322 | - 'symbol' => $this->currency_config->sign, |
|
323 | - 'format' => array( |
|
324 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
325 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
326 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
327 | - ), |
|
328 | - 'decimal' => $this->currency_config->dec_mrk, |
|
329 | - 'thousand' => $this->currency_config->thsnds, |
|
330 | - 'precision' => $this->currency_config->dec_plc, |
|
331 | - ), |
|
332 | - 'number' => array( |
|
333 | - 'precision' => $this->currency_config->dec_plc, |
|
334 | - 'thousand' => $this->currency_config->thsnds, |
|
335 | - 'decimal' => $this->currency_config->dec_mrk, |
|
336 | - ), |
|
337 | - ); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * Returns configuration data for the js Currency VO. |
|
343 | - * @since 4.9.71.p |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - private function getCurrencySettings() |
|
347 | - { |
|
348 | - return array( |
|
349 | - 'code' => $this->currency_config->code, |
|
350 | - 'singularLabel' => $this->currency_config->name, |
|
351 | - 'pluralLabel' => $this->currency_config->plural, |
|
352 | - 'sign' => $this->currency_config->sign, |
|
353 | - 'signB4' => $this->currency_config->sign_b4, |
|
354 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
355 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
356 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * @throws DuplicateCollectionIdentifierException |
|
363 | - * @throws InvalidDataTypeException |
|
364 | - * @throws InvalidEntityException |
|
365 | - * @throws DomainException |
|
366 | - * @since 4.9.62.p |
|
367 | - */ |
|
368 | - private function loadCoreCss() |
|
369 | - { |
|
370 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
371 | - $this->addStylesheet( |
|
372 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
373 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
374 | - ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
375 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
376 | - array('dashicons') |
|
377 | - ); |
|
378 | - //Load custom style sheet if available |
|
379 | - if ($this->template_config->custom_style_sheet !== null) { |
|
380 | - $this->addStylesheet( |
|
381 | - CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
382 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
383 | - array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
384 | - ); |
|
385 | - } |
|
386 | - } |
|
387 | - $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']); |
|
388 | - $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * jQuery Validate for form validation |
|
394 | - * |
|
395 | - * @since 4.9.62.p |
|
396 | - * @throws DomainException |
|
397 | - * @throws DuplicateCollectionIdentifierException |
|
398 | - * @throws InvalidDataTypeException |
|
399 | - * @throws InvalidEntityException |
|
400 | - */ |
|
401 | - private function loadJqueryValidate() |
|
402 | - { |
|
403 | - $this->addJavascript( |
|
404 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
405 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
406 | - array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
407 | - true, |
|
408 | - '1.15.0' |
|
409 | - ); |
|
410 | - |
|
411 | - $this->addJavascript( |
|
412 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
413 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
414 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
415 | - true, |
|
416 | - '1.15.0' |
|
417 | - ); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * accounting.js for performing client-side calculations |
|
423 | - * |
|
424 | - * @since 4.9.62.p |
|
425 | - * @throws DomainException |
|
426 | - * @throws DuplicateCollectionIdentifierException |
|
427 | - * @throws InvalidDataTypeException |
|
428 | - * @throws InvalidEntityException |
|
429 | - */ |
|
430 | - private function loadAccountingJs() |
|
431 | - { |
|
432 | - //accounting.js library |
|
433 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
434 | - $this->addJavascript( |
|
435 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
436 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
437 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE), |
|
438 | - true, |
|
439 | - '0.3.2' |
|
440 | - ); |
|
441 | - |
|
442 | - $this->addJavascript( |
|
443 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
444 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
445 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
446 | - ) |
|
447 | - ->setInlineDataCallback( |
|
448 | - function () { |
|
449 | - wp_localize_script( |
|
450 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
451 | - 'EE_ACCOUNTING_CFG', |
|
452 | - $this->getAccountingSettings() |
|
453 | - ); |
|
454 | - } |
|
455 | - ); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * registers assets for cleaning your ears |
|
461 | - * |
|
462 | - * @param JavascriptAsset $script |
|
463 | - */ |
|
464 | - public function loadQtipJs(JavascriptAsset $script) |
|
465 | - { |
|
466 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
467 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
468 | - if ( |
|
469 | - $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
470 | - && apply_filters('FHEE_load_qtip', false) |
|
471 | - ) { |
|
472 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * assets that are used in the WordPress admin |
|
479 | - * |
|
480 | - * @throws DuplicateCollectionIdentifierException |
|
481 | - * @throws InvalidDataTypeException |
|
482 | - * @throws InvalidEntityException |
|
483 | - * @throws DomainException |
|
484 | - * @since 4.9.62.p |
|
485 | - */ |
|
486 | - private function registerAdminAssets() |
|
487 | - { |
|
488 | - $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation(); |
|
489 | - // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle. |
|
490 | - $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE); |
|
491 | - } |
|
85 | + const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
86 | + |
|
87 | + const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
88 | + |
|
89 | + // EE CSS assets handles |
|
90 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
91 | + |
|
92 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
93 | + |
|
94 | + const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
95 | + |
|
96 | + const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default'; |
|
97 | + |
|
98 | + /** |
|
99 | + * @var EE_Currency_Config $currency_config |
|
100 | + */ |
|
101 | + protected $currency_config; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var EE_Template_Config $template_config |
|
105 | + */ |
|
106 | + protected $template_config; |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * CoreAssetRegister constructor. |
|
111 | + * |
|
112 | + * @param AssetCollection $assets |
|
113 | + * @param EE_Currency_Config $currency_config |
|
114 | + * @param EE_Template_Config $template_config |
|
115 | + * @param DomainInterface $domain |
|
116 | + * @param Registry $registry |
|
117 | + */ |
|
118 | + public function __construct( |
|
119 | + AssetCollection $assets, |
|
120 | + EE_Currency_Config $currency_config, |
|
121 | + EE_Template_Config $template_config, |
|
122 | + DomainInterface $domain, |
|
123 | + Registry $registry |
|
124 | + ) { |
|
125 | + $this->currency_config = $currency_config; |
|
126 | + $this->template_config = $template_config; |
|
127 | + parent::__construct($domain, $assets, $registry); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @since 4.9.62.p |
|
133 | + * @throws DomainException |
|
134 | + * @throws DuplicateCollectionIdentifierException |
|
135 | + * @throws InvalidArgumentException |
|
136 | + * @throws InvalidDataTypeException |
|
137 | + * @throws InvalidEntityException |
|
138 | + * @throws InvalidInterfaceException |
|
139 | + */ |
|
140 | + public function addAssets() |
|
141 | + { |
|
142 | + $this->addJavascriptFiles(); |
|
143 | + $this->addStylesheetFiles(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @since 4.9.62.p |
|
149 | + * @throws DomainException |
|
150 | + * @throws DuplicateCollectionIdentifierException |
|
151 | + * @throws InvalidArgumentException |
|
152 | + * @throws InvalidDataTypeException |
|
153 | + * @throws InvalidEntityException |
|
154 | + * @throws InvalidInterfaceException |
|
155 | + */ |
|
156 | + public function addJavascriptFiles() |
|
157 | + { |
|
158 | + $this->loadCoreJs(); |
|
159 | + $this->loadJqueryValidate(); |
|
160 | + $this->loadAccountingJs(); |
|
161 | + add_action( |
|
162 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
163 | + array($this, 'loadQtipJs') |
|
164 | + ); |
|
165 | + $this->registerAdminAssets(); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @throws DuplicateCollectionIdentifierException |
|
171 | + * @throws InvalidDataTypeException |
|
172 | + * @throws InvalidEntityException |
|
173 | + * @throws DomainException |
|
174 | + * @since 4.9.62.p |
|
175 | + */ |
|
176 | + public function addStylesheetFiles() |
|
177 | + { |
|
178 | + $this->loadCoreCss(); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * core default javascript |
|
184 | + * |
|
185 | + * @since 4.9.62.p |
|
186 | + * @throws DomainException |
|
187 | + * @throws DuplicateCollectionIdentifierException |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws InvalidDataTypeException |
|
190 | + * @throws InvalidEntityException |
|
191 | + * @throws InvalidInterfaceException |
|
192 | + */ |
|
193 | + private function loadCoreJs() |
|
194 | + { |
|
195 | + // conditionally load third-party libraries that WP core MIGHT have. |
|
196 | + $this->registerWpAssets(); |
|
197 | + |
|
198 | + $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
199 | + $this->addJs(self::JS_HANDLE_VENDOR); |
|
200 | + $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation(); |
|
201 | + $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation(); |
|
202 | + $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation(); |
|
203 | + $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation(); |
|
204 | + $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback( |
|
205 | + static function () { |
|
206 | + wp_add_inline_script( |
|
207 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
208 | + is_admin() |
|
209 | + ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )' |
|
210 | + : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )' |
|
211 | + ); |
|
212 | + } |
|
213 | + ); |
|
214 | + $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
215 | + $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
216 | + $this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation(); |
|
217 | + |
|
218 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
219 | + $this->registry->addData( |
|
220 | + 'paths', |
|
221 | + array( |
|
222 | + 'base_rest_route' => rest_url(), |
|
223 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
224 | + 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
225 | + 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
226 | + 'site_url' => site_url('/'), |
|
227 | + 'admin_url' => admin_url('/'), |
|
228 | + ) |
|
229 | + ); |
|
230 | + // Event Espresso brand name |
|
231 | + $this->registry->addData('brandName', Domain::brandName()); |
|
232 | + /** site formatting values **/ |
|
233 | + $this->registry->addData( |
|
234 | + 'site_formats', |
|
235 | + array( |
|
236 | + 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
237 | + ) |
|
238 | + ); |
|
239 | + /** currency data **/ |
|
240 | + $this->registry->addData( |
|
241 | + 'currency_config', |
|
242 | + $this->getCurrencySettings() |
|
243 | + ); |
|
244 | + /** site timezone */ |
|
245 | + $this->registry->addData( |
|
246 | + 'default_timezone', |
|
247 | + array( |
|
248 | + 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
249 | + 'string' => get_option('timezone_string'), |
|
250 | + 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
251 | + ) |
|
252 | + ); |
|
253 | + /** site locale (user locale if user logged in) */ |
|
254 | + $this->registry->addData( |
|
255 | + 'locale', |
|
256 | + array( |
|
257 | + 'user' => get_user_locale(), |
|
258 | + 'site' => get_locale() |
|
259 | + ) |
|
260 | + ); |
|
261 | + |
|
262 | + $this->addJavascript( |
|
263 | + CoreAssetManager::JS_HANDLE_CORE, |
|
264 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
265 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
266 | + ) |
|
267 | + ->setInlineDataCallback( |
|
268 | + static function () { |
|
269 | + wp_localize_script( |
|
270 | + CoreAssetManager::JS_HANDLE_CORE, |
|
271 | + CoreAssetManager::JS_HANDLE_I18N, |
|
272 | + EE_Registry::sanitize_i18n_js_strings() |
|
273 | + ); |
|
274 | + } |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
281 | + * WordPress in the running environment. |
|
282 | + * |
|
283 | + * @throws DuplicateCollectionIdentifierException |
|
284 | + * @throws InvalidDataTypeException |
|
285 | + * @throws InvalidEntityException |
|
286 | + * @throws DomainException |
|
287 | + * @since 4.9.71.p |
|
288 | + */ |
|
289 | + private function registerWpAssets() |
|
290 | + { |
|
291 | + global $wp_version; |
|
292 | + if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
293 | + return; |
|
294 | + } |
|
295 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0'); |
|
296 | + $this->addVendorJavascript( |
|
297 | + CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
298 | + array(CoreAssetManager::JS_HANDLE_REACT), |
|
299 | + true, |
|
300 | + '16.6.0' |
|
301 | + ); |
|
302 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11') |
|
303 | + ->setInlineDataCallback( |
|
304 | + static function() { |
|
305 | + wp_add_inline_script( |
|
306 | + CoreAssetManager::JS_HANDLE_LODASH, |
|
307 | + 'window.lodash = _.noConflict();' |
|
308 | + ); |
|
309 | + } |
|
310 | + ); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Returns configuration data for the accounting-js library. |
|
316 | + * @since 4.9.71.p |
|
317 | + * @return array |
|
318 | + */ |
|
319 | + private function getAccountingSettings() { |
|
320 | + return array( |
|
321 | + 'currency' => array( |
|
322 | + 'symbol' => $this->currency_config->sign, |
|
323 | + 'format' => array( |
|
324 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
325 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
326 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
327 | + ), |
|
328 | + 'decimal' => $this->currency_config->dec_mrk, |
|
329 | + 'thousand' => $this->currency_config->thsnds, |
|
330 | + 'precision' => $this->currency_config->dec_plc, |
|
331 | + ), |
|
332 | + 'number' => array( |
|
333 | + 'precision' => $this->currency_config->dec_plc, |
|
334 | + 'thousand' => $this->currency_config->thsnds, |
|
335 | + 'decimal' => $this->currency_config->dec_mrk, |
|
336 | + ), |
|
337 | + ); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * Returns configuration data for the js Currency VO. |
|
343 | + * @since 4.9.71.p |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + private function getCurrencySettings() |
|
347 | + { |
|
348 | + return array( |
|
349 | + 'code' => $this->currency_config->code, |
|
350 | + 'singularLabel' => $this->currency_config->name, |
|
351 | + 'pluralLabel' => $this->currency_config->plural, |
|
352 | + 'sign' => $this->currency_config->sign, |
|
353 | + 'signB4' => $this->currency_config->sign_b4, |
|
354 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
355 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
356 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * @throws DuplicateCollectionIdentifierException |
|
363 | + * @throws InvalidDataTypeException |
|
364 | + * @throws InvalidEntityException |
|
365 | + * @throws DomainException |
|
366 | + * @since 4.9.62.p |
|
367 | + */ |
|
368 | + private function loadCoreCss() |
|
369 | + { |
|
370 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
371 | + $this->addStylesheet( |
|
372 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
373 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
374 | + ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
375 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
376 | + array('dashicons') |
|
377 | + ); |
|
378 | + //Load custom style sheet if available |
|
379 | + if ($this->template_config->custom_style_sheet !== null) { |
|
380 | + $this->addStylesheet( |
|
381 | + CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
382 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
383 | + array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
384 | + ); |
|
385 | + } |
|
386 | + } |
|
387 | + $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']); |
|
388 | + $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * jQuery Validate for form validation |
|
394 | + * |
|
395 | + * @since 4.9.62.p |
|
396 | + * @throws DomainException |
|
397 | + * @throws DuplicateCollectionIdentifierException |
|
398 | + * @throws InvalidDataTypeException |
|
399 | + * @throws InvalidEntityException |
|
400 | + */ |
|
401 | + private function loadJqueryValidate() |
|
402 | + { |
|
403 | + $this->addJavascript( |
|
404 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
405 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
406 | + array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
407 | + true, |
|
408 | + '1.15.0' |
|
409 | + ); |
|
410 | + |
|
411 | + $this->addJavascript( |
|
412 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
413 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
414 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
415 | + true, |
|
416 | + '1.15.0' |
|
417 | + ); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * accounting.js for performing client-side calculations |
|
423 | + * |
|
424 | + * @since 4.9.62.p |
|
425 | + * @throws DomainException |
|
426 | + * @throws DuplicateCollectionIdentifierException |
|
427 | + * @throws InvalidDataTypeException |
|
428 | + * @throws InvalidEntityException |
|
429 | + */ |
|
430 | + private function loadAccountingJs() |
|
431 | + { |
|
432 | + //accounting.js library |
|
433 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
434 | + $this->addJavascript( |
|
435 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
436 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
437 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE), |
|
438 | + true, |
|
439 | + '0.3.2' |
|
440 | + ); |
|
441 | + |
|
442 | + $this->addJavascript( |
|
443 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
444 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
445 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
446 | + ) |
|
447 | + ->setInlineDataCallback( |
|
448 | + function () { |
|
449 | + wp_localize_script( |
|
450 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
451 | + 'EE_ACCOUNTING_CFG', |
|
452 | + $this->getAccountingSettings() |
|
453 | + ); |
|
454 | + } |
|
455 | + ); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * registers assets for cleaning your ears |
|
461 | + * |
|
462 | + * @param JavascriptAsset $script |
|
463 | + */ |
|
464 | + public function loadQtipJs(JavascriptAsset $script) |
|
465 | + { |
|
466 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
467 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
468 | + if ( |
|
469 | + $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
470 | + && apply_filters('FHEE_load_qtip', false) |
|
471 | + ) { |
|
472 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * assets that are used in the WordPress admin |
|
479 | + * |
|
480 | + * @throws DuplicateCollectionIdentifierException |
|
481 | + * @throws InvalidDataTypeException |
|
482 | + * @throws InvalidEntityException |
|
483 | + * @throws DomainException |
|
484 | + * @since 4.9.62.p |
|
485 | + */ |
|
486 | + private function registerAdminAssets() |
|
487 | + { |
|
488 | + $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation(); |
|
489 | + // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle. |
|
490 | + $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE); |
|
491 | + } |
|
492 | 492 | } |
@@ -15,38 +15,38 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $table_column |
|
20 | - * @param string $nice_name |
|
21 | - * @param bool $nullable |
|
22 | - * @param null $default_value |
|
23 | - * @throws InvalidArgumentException |
|
24 | - */ |
|
25 | - public function __construct($table_column, $nice_name, $nullable, $default_value = null) |
|
26 | - { |
|
27 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
28 | - $this->setSchemaFormat('email'); |
|
29 | - } |
|
18 | + /** |
|
19 | + * @param string $table_column |
|
20 | + * @param string $nice_name |
|
21 | + * @param bool $nullable |
|
22 | + * @param null $default_value |
|
23 | + * @throws InvalidArgumentException |
|
24 | + */ |
|
25 | + public function __construct($table_column, $nice_name, $nullable, $default_value = null) |
|
26 | + { |
|
27 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
28 | + $this->setSchemaFormat('email'); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * In form inputs, we should have called htmlentities and addslashes() on form inputs, |
|
35 | - * so we need to undo that on setting of these fields |
|
36 | - * |
|
37 | - * @param string $email_address |
|
38 | - * @return string |
|
39 | - * @throws InvalidArgumentException |
|
40 | - * @throws InvalidInterfaceException |
|
41 | - * @throws InvalidDataTypeException |
|
42 | - */ |
|
43 | - public function prepare_for_set($email_address) |
|
44 | - { |
|
45 | - try { |
|
46 | - $email_address_obj = EmailAddressFactory::create($email_address); |
|
47 | - return $email_address_obj instanceof EmailAddress ? $email_address_obj->get() : ''; |
|
48 | - } catch (EmailValidationException $e) { |
|
49 | - return ''; |
|
50 | - } |
|
51 | - } |
|
33 | + /** |
|
34 | + * In form inputs, we should have called htmlentities and addslashes() on form inputs, |
|
35 | + * so we need to undo that on setting of these fields |
|
36 | + * |
|
37 | + * @param string $email_address |
|
38 | + * @return string |
|
39 | + * @throws InvalidArgumentException |
|
40 | + * @throws InvalidInterfaceException |
|
41 | + * @throws InvalidDataTypeException |
|
42 | + */ |
|
43 | + public function prepare_for_set($email_address) |
|
44 | + { |
|
45 | + try { |
|
46 | + $email_address_obj = EmailAddressFactory::create($email_address); |
|
47 | + return $email_address_obj instanceof EmailAddress ? $email_address_obj->get() : ''; |
|
48 | + } catch (EmailValidationException $e) { |
|
49 | + return ''; |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -112,10 +112,10 @@ |
||
112 | 112 | ]; |
113 | 113 | $this->_wp_core_model = true; |
114 | 114 | $this->_caps_slug = 'users'; |
115 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
116 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
115 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
116 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
117 | 117 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
118 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
118 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
119 | 119 | } |
120 | 120 | // @todo: account for create_users controls whether they can create users at all |
121 | 121 | parent::__construct($timezone); |
@@ -13,133 +13,133 @@ |
||
13 | 13 | class EEM_WP_User extends EEM_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * private instance of the EEM_WP_User object |
|
18 | - * |
|
19 | - * @type EEM_WP_User |
|
20 | - */ |
|
21 | - protected static $_instance; |
|
16 | + /** |
|
17 | + * private instance of the EEM_WP_User object |
|
18 | + * |
|
19 | + * @type EEM_WP_User |
|
20 | + */ |
|
21 | + protected static $_instance; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * constructor |
|
26 | - * |
|
27 | - * @param null $timezone |
|
28 | - * @param ModelFieldFactory $model_field_factory |
|
29 | - * @throws EE_Error |
|
30 | - * @throws InvalidArgumentException |
|
31 | - */ |
|
32 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
33 | - { |
|
34 | - $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
35 | - $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
36 | - global $wpdb; |
|
37 | - $this->_tables = array( |
|
38 | - 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
39 | - ); |
|
40 | - $this->_fields = array( |
|
41 | - 'WP_User' => array( |
|
42 | - 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
43 | - 'ID', |
|
44 | - esc_html__('WP_User ID', 'event_espresso') |
|
45 | - ), |
|
46 | - 'user_login' => $model_field_factory->createPlainTextField( |
|
47 | - 'user_login', |
|
48 | - esc_html__('User Login', 'event_espresso'), |
|
49 | - false |
|
50 | - ), |
|
51 | - 'user_pass' => $model_field_factory->createPlainTextField( |
|
52 | - 'user_pass', |
|
53 | - esc_html__('User Password', 'event_espresso'), |
|
54 | - false |
|
55 | - ), |
|
56 | - 'user_nicename' => $model_field_factory->createPlainTextField( |
|
57 | - 'user_nicename', |
|
58 | - esc_html__(' User Nice Name', 'event_espresso'), |
|
59 | - false |
|
60 | - ), |
|
61 | - 'user_email' => $model_field_factory->createEmailField( |
|
62 | - 'user_email', |
|
63 | - esc_html__('User Email', 'event_espresso'), |
|
64 | - false, |
|
65 | - null |
|
66 | - ), |
|
67 | - 'user_registered' => $model_field_factory->createDatetimeField( |
|
68 | - 'user_registered', |
|
69 | - esc_html__('Date User Registered', 'event_espresso'), |
|
70 | - $timezone |
|
71 | - ), |
|
72 | - 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
73 | - 'user_activation_key', |
|
74 | - esc_html__('User Activation Key', 'event_espresso'), |
|
75 | - false |
|
76 | - ), |
|
77 | - 'user_status' => $model_field_factory->createIntegerField( |
|
78 | - 'user_status', |
|
79 | - esc_html__('User Status', 'event_espresso') |
|
80 | - ), |
|
81 | - 'display_name' => $model_field_factory->createPlainTextField( |
|
82 | - 'display_name', |
|
83 | - esc_html__('Display Name', 'event_espresso'), |
|
84 | - false |
|
85 | - ), |
|
86 | - ), |
|
87 | - ); |
|
88 | - $this->_model_relations = array( |
|
89 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
90 | - // all models are related to the change log |
|
91 | - // 'Change_Log' => new EE_Has_Many_Relation(), |
|
92 | - 'Event' => new EE_Has_Many_Relation(), |
|
93 | - 'Message' => new EE_Has_Many_Relation(), |
|
94 | - 'Payment_Method' => new EE_Has_Many_Relation(), |
|
95 | - 'Price' => new EE_Has_Many_Relation(), |
|
96 | - 'Price_Type' => new EE_Has_Many_Relation(), |
|
97 | - 'Question' => new EE_Has_Many_Relation(), |
|
98 | - 'Question_Group' => new EE_Has_Many_Relation(), |
|
99 | - 'Ticket' => new EE_Has_Many_Relation(), |
|
100 | - 'Venue' => new EE_Has_Many_Relation(), |
|
101 | - ); |
|
102 | - $this->foreign_key_aliases = [ |
|
103 | - 'Event.EVT_wp_user' => 'WP_User.ID', |
|
104 | - 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
105 | - 'Price.PRC_wp_user' => 'WP_User.ID', |
|
106 | - 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
107 | - 'Question.QST_wp_user' => 'WP_User.ID', |
|
108 | - 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
109 | - 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
110 | - 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
111 | - ]; |
|
112 | - $this->_wp_core_model = true; |
|
113 | - $this->_caps_slug = 'users'; |
|
114 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
115 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
116 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
117 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
118 | - } |
|
119 | - // @todo: account for create_users controls whether they can create users at all |
|
120 | - parent::__construct($timezone); |
|
121 | - } |
|
24 | + /** |
|
25 | + * constructor |
|
26 | + * |
|
27 | + * @param null $timezone |
|
28 | + * @param ModelFieldFactory $model_field_factory |
|
29 | + * @throws EE_Error |
|
30 | + * @throws InvalidArgumentException |
|
31 | + */ |
|
32 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
33 | + { |
|
34 | + $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
35 | + $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
36 | + global $wpdb; |
|
37 | + $this->_tables = array( |
|
38 | + 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
39 | + ); |
|
40 | + $this->_fields = array( |
|
41 | + 'WP_User' => array( |
|
42 | + 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
43 | + 'ID', |
|
44 | + esc_html__('WP_User ID', 'event_espresso') |
|
45 | + ), |
|
46 | + 'user_login' => $model_field_factory->createPlainTextField( |
|
47 | + 'user_login', |
|
48 | + esc_html__('User Login', 'event_espresso'), |
|
49 | + false |
|
50 | + ), |
|
51 | + 'user_pass' => $model_field_factory->createPlainTextField( |
|
52 | + 'user_pass', |
|
53 | + esc_html__('User Password', 'event_espresso'), |
|
54 | + false |
|
55 | + ), |
|
56 | + 'user_nicename' => $model_field_factory->createPlainTextField( |
|
57 | + 'user_nicename', |
|
58 | + esc_html__(' User Nice Name', 'event_espresso'), |
|
59 | + false |
|
60 | + ), |
|
61 | + 'user_email' => $model_field_factory->createEmailField( |
|
62 | + 'user_email', |
|
63 | + esc_html__('User Email', 'event_espresso'), |
|
64 | + false, |
|
65 | + null |
|
66 | + ), |
|
67 | + 'user_registered' => $model_field_factory->createDatetimeField( |
|
68 | + 'user_registered', |
|
69 | + esc_html__('Date User Registered', 'event_espresso'), |
|
70 | + $timezone |
|
71 | + ), |
|
72 | + 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
73 | + 'user_activation_key', |
|
74 | + esc_html__('User Activation Key', 'event_espresso'), |
|
75 | + false |
|
76 | + ), |
|
77 | + 'user_status' => $model_field_factory->createIntegerField( |
|
78 | + 'user_status', |
|
79 | + esc_html__('User Status', 'event_espresso') |
|
80 | + ), |
|
81 | + 'display_name' => $model_field_factory->createPlainTextField( |
|
82 | + 'display_name', |
|
83 | + esc_html__('Display Name', 'event_espresso'), |
|
84 | + false |
|
85 | + ), |
|
86 | + ), |
|
87 | + ); |
|
88 | + $this->_model_relations = array( |
|
89 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
90 | + // all models are related to the change log |
|
91 | + // 'Change_Log' => new EE_Has_Many_Relation(), |
|
92 | + 'Event' => new EE_Has_Many_Relation(), |
|
93 | + 'Message' => new EE_Has_Many_Relation(), |
|
94 | + 'Payment_Method' => new EE_Has_Many_Relation(), |
|
95 | + 'Price' => new EE_Has_Many_Relation(), |
|
96 | + 'Price_Type' => new EE_Has_Many_Relation(), |
|
97 | + 'Question' => new EE_Has_Many_Relation(), |
|
98 | + 'Question_Group' => new EE_Has_Many_Relation(), |
|
99 | + 'Ticket' => new EE_Has_Many_Relation(), |
|
100 | + 'Venue' => new EE_Has_Many_Relation(), |
|
101 | + ); |
|
102 | + $this->foreign_key_aliases = [ |
|
103 | + 'Event.EVT_wp_user' => 'WP_User.ID', |
|
104 | + 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
105 | + 'Price.PRC_wp_user' => 'WP_User.ID', |
|
106 | + 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
107 | + 'Question.QST_wp_user' => 'WP_User.ID', |
|
108 | + 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
109 | + 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
110 | + 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
111 | + ]; |
|
112 | + $this->_wp_core_model = true; |
|
113 | + $this->_caps_slug = 'users'; |
|
114 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
115 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
116 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
117 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
118 | + } |
|
119 | + // @todo: account for create_users controls whether they can create users at all |
|
120 | + parent::__construct($timezone); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * We don't need a foreign key to the WP_User model, we just need its primary key |
|
126 | - * |
|
127 | - * @return string |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function wp_user_field_name() |
|
131 | - { |
|
132 | - return $this->primary_key_name(); |
|
133 | - } |
|
124 | + /** |
|
125 | + * We don't need a foreign key to the WP_User model, we just need its primary key |
|
126 | + * |
|
127 | + * @return string |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function wp_user_field_name() |
|
131 | + { |
|
132 | + return $this->primary_key_name(); |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
138 | - * |
|
139 | - * @return boolean |
|
140 | - */ |
|
141 | - public function is_owned() |
|
142 | - { |
|
143 | - return true; |
|
144 | - } |
|
136 | + /** |
|
137 | + * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
138 | + * |
|
139 | + * @return boolean |
|
140 | + */ |
|
141 | + public function is_owned() |
|
142 | + { |
|
143 | + return true; |
|
144 | + } |
|
145 | 145 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public function is_valid_scope($scope) |
171 | 171 | { |
172 | 172 | $scopes = $this->scopes(); |
173 | - if (isset($scopes[ $scope ])) { |
|
173 | + if (isset($scopes[$scope])) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | return false; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function get_all_active($scope = null, $query_params = []) |
189 | 189 | { |
190 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
191 | 191 | $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
192 | 192 | } |
193 | 193 | return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $count = 0; |
236 | 236 | foreach ($this->scopes() as $scope_name => $desc) { |
237 | 237 | $count++; |
238 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | + $acceptable_scopes['PMD_scope*'.$count] = ['LIKE', '%'.$scope_name.'%']; |
|
239 | 239 | } |
240 | 240 | return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
241 | 241 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $usable_payment_methods = []; |
392 | 392 | foreach ($payment_methods as $key => $payment_method) { |
393 | 393 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
394 | - $usable_payment_methods[ $key ] = $payment_method; |
|
394 | + $usable_payment_methods[$key] = $payment_method; |
|
395 | 395 | // some payment methods enqueue their scripts in EE_PMT_*::__construct |
396 | 396 | // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
397 | 397 | // its scripts). but for backwards-compat we should continue to do that |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $payment_method |
406 | 406 | ); |
407 | 407 | new PersistentAdminNotice( |
408 | - 'auto-deactivated-' . $payment_method->type(), |
|
408 | + 'auto-deactivated-'.$payment_method->type(), |
|
409 | 409 | sprintf( |
410 | 410 | esc_html__( |
411 | 411 | 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | ), |
414 | 414 | $payment_method->admin_name(), |
415 | 415 | '<br />', |
416 | - '<a href="' . admin_url('plugins.php') . '">', |
|
416 | + '<a href="'.admin_url('plugins.php').'">', |
|
417 | 417 | '</a>' |
418 | 418 | ), |
419 | 419 | true |
@@ -17,456 +17,456 @@ |
||
17 | 17 | class EEM_Payment_Method extends EEM_Base |
18 | 18 | { |
19 | 19 | |
20 | - const scope_cart = 'CART'; |
|
21 | - |
|
22 | - const scope_admin = 'ADMIN'; |
|
23 | - |
|
24 | - const scope_api = 'API'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type EEM_Payment_Method |
|
28 | - */ |
|
29 | - protected static $_instance = null; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * private constructor to prevent direct creation |
|
34 | - * |
|
35 | - * @param null $timezone |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
38 | - protected function __construct($timezone = null) |
|
39 | - { |
|
40 | - $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
41 | - $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
42 | - $this->_tables = [ |
|
43 | - 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
44 | - ]; |
|
45 | - $this->_fields = [ |
|
46 | - 'Payment_Method' => [ |
|
47 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
48 | - 'PMD_ID', |
|
49 | - esc_html__('ID', 'event_espresso') |
|
50 | - ), |
|
51 | - 'PMD_type' => new EE_Plain_Text_Field( |
|
52 | - 'PMD_type', |
|
53 | - esc_html__('Payment Method Type', 'event_espresso'), |
|
54 | - false, |
|
55 | - 'Admin_Only' |
|
56 | - ), |
|
57 | - 'PMD_name' => new EE_Plain_Text_Field( |
|
58 | - 'PMD_name', |
|
59 | - esc_html__('Name', 'event_espresso'), |
|
60 | - false |
|
61 | - ), |
|
62 | - 'PMD_desc' => new EE_Post_Content_Field( |
|
63 | - 'PMD_desc', |
|
64 | - esc_html__('Description', 'event_espresso'), |
|
65 | - false, |
|
66 | - '' |
|
67 | - ), |
|
68 | - 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
69 | - 'PMD_admin_name', |
|
70 | - esc_html__('Admin-Only Name', 'event_espresso'), |
|
71 | - true |
|
72 | - ), |
|
73 | - 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
74 | - 'PMD_admin_desc', |
|
75 | - esc_html__('Admin-Only Description', 'event_espresso'), |
|
76 | - true |
|
77 | - ), |
|
78 | - 'PMD_slug' => new EE_Slug_Field( |
|
79 | - 'PMD_slug', |
|
80 | - esc_html__('Slug', 'event_espresso'), |
|
81 | - false |
|
82 | - ), |
|
83 | - 'PMD_order' => new EE_Integer_Field( |
|
84 | - 'PMD_order', |
|
85 | - esc_html__('Order', 'event_espresso'), |
|
86 | - false, |
|
87 | - 0 |
|
88 | - ), |
|
89 | - 'PMD_debug_mode' => new EE_Boolean_Field( |
|
90 | - 'PMD_debug_mode', |
|
91 | - esc_html__('Debug Mode On?', 'event_espresso'), |
|
92 | - false, |
|
93 | - false |
|
94 | - ), |
|
95 | - 'PMD_wp_user' => new EE_WP_User_Field( |
|
96 | - 'PMD_wp_user', |
|
97 | - esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
98 | - false |
|
99 | - ), |
|
100 | - 'PMD_open_by_default' => new EE_Boolean_Field( |
|
101 | - 'PMD_open_by_default', |
|
102 | - esc_html__('Open by Default?', 'event_espresso'), |
|
103 | - false, |
|
104 | - false |
|
105 | - ), |
|
106 | - 'PMD_button_url' => new EE_Plain_Text_Field( |
|
107 | - 'PMD_button_url', |
|
108 | - esc_html__('Button URL', 'event_espresso'), |
|
109 | - true, |
|
110 | - '' |
|
111 | - ), |
|
112 | - 'PMD_scope' => new EE_Serialized_Text_Field( |
|
113 | - 'PMD_scope', |
|
114 | - esc_html__('Usable From?', 'event_espresso'), |
|
115 | - false, |
|
116 | - []// possible values currently are 'CART','ADMIN','API' |
|
117 | - ), |
|
118 | - ], |
|
119 | - ]; |
|
120 | - $this->_model_relations = [ |
|
121 | - 'Payment' => new EE_Has_Many_Relation(), |
|
122 | - 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
123 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
124 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
125 | - ]; |
|
126 | - parent::__construct($timezone); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Gets one by the slug provided |
|
132 | - * |
|
133 | - * @param string $slug |
|
134 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
135 | - * @throws EE_Error |
|
136 | - */ |
|
137 | - public function get_one_by_slug($slug) |
|
138 | - { |
|
139 | - return $this->get_one([['PMD_slug' => $slug]]); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Gets all the acceptable scopes for payment methods. |
|
145 | - * Keys are their names as store din the DB, and values are nice names for displaying them |
|
146 | - * |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public function scopes() |
|
150 | - { |
|
151 | - return apply_filters( |
|
152 | - 'FHEE__EEM_Payment_Method__scopes', |
|
153 | - [ |
|
154 | - EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
155 | - EEM_Payment_Method::scope_admin => esc_html__( |
|
156 | - 'Admin Registration Page (no online processing)', |
|
157 | - 'event_espresso' |
|
158 | - ), |
|
159 | - ] |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Determines if this is an valid scope |
|
166 | - * |
|
167 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
168 | - * @return boolean |
|
169 | - */ |
|
170 | - public function is_valid_scope($scope) |
|
171 | - { |
|
172 | - $scopes = $this->scopes(); |
|
173 | - if (isset($scopes[ $scope ])) { |
|
174 | - return true; |
|
175 | - } |
|
176 | - return false; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Gets all active payment methods |
|
182 | - * |
|
183 | - * @param string $scope one of |
|
184 | - * @param array $query_params |
|
185 | - * @return EE_Base_Class[]|EE_Payment_Method[] |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - public function get_all_active($scope = null, $query_params = []) |
|
189 | - { |
|
190 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
191 | - $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
192 | - } |
|
193 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * Counts all active gateways in the specified scope |
|
199 | - * |
|
200 | - * @param string $scope one of EEM_Payment_Method::scope_* |
|
201 | - * @param array $query_params |
|
202 | - * @return int |
|
203 | - * @throws EE_Error |
|
204 | - */ |
|
205 | - public function count_active($scope = null, $query_params = []) |
|
206 | - { |
|
207 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
213 | - * argument to get all active for a given scope |
|
214 | - * |
|
215 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
216 | - * @param array $query_params |
|
217 | - * @return array |
|
218 | - * @throws EE_Error |
|
219 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
220 | - */ |
|
221 | - protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
222 | - { |
|
223 | - if ($scope) { |
|
224 | - if ($this->is_valid_scope($scope)) { |
|
225 | - return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
226 | - } |
|
227 | - throw new EE_Error( |
|
228 | - sprintf( |
|
229 | - esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
230 | - $scope |
|
231 | - ) |
|
232 | - ); |
|
233 | - } |
|
234 | - $acceptable_scopes = []; |
|
235 | - $count = 0; |
|
236 | - foreach ($this->scopes() as $scope_name => $desc) { |
|
237 | - $count++; |
|
238 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
239 | - } |
|
240 | - return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
246 | - * argument to get all active for a given scope |
|
247 | - * |
|
248 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
249 | - * @param array $query_params |
|
250 | - * @return array |
|
251 | - * @throws EE_Error |
|
252 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
253 | - */ |
|
254 | - public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
255 | - { |
|
256 | - return $this->_get_query_params_for_all_active($scope, $query_params); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Gets one active payment method. see @get_all_active for documentation |
|
262 | - * |
|
263 | - * @param string $scope |
|
264 | - * @param array $query_params |
|
265 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
266 | - * @throws EE_Error |
|
267 | - */ |
|
268 | - public function get_one_active($scope = null, $query_params = []) |
|
269 | - { |
|
270 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * Gets one payment method of that type, regardless of whether its active or not |
|
276 | - * |
|
277 | - * @param string $type |
|
278 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - public function get_one_of_type($type) |
|
282 | - { |
|
283 | - return $this->get_one([['PMD_type' => $type]]); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * Overrides parent ot also check by the slug |
|
289 | - * |
|
290 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
291 | - * @param boolean $ensure_is_in_db |
|
292 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
293 | - * @throws EE_Error |
|
294 | - * @see EEM_Base::ensure_is_obj() |
|
295 | - */ |
|
296 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
297 | - { |
|
298 | - // first: check if it's a slug |
|
299 | - if (is_string($base_class_obj_or_id)) { |
|
300 | - $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
301 | - if ($obj) { |
|
302 | - return $obj; |
|
303 | - } |
|
304 | - } |
|
305 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
306 | - try { |
|
307 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
308 | - } catch (EE_Error $e) { |
|
309 | - // handle it outside the catch |
|
310 | - } |
|
311 | - throw new EE_Error( |
|
312 | - sprintf( |
|
313 | - esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
314 | - $base_class_obj_or_id |
|
315 | - ) |
|
316 | - ); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * Gets the ID of this object, or if its a string finds the object's id |
|
322 | - * associated with that slug |
|
323 | - * |
|
324 | - * @param mixed $base_obj_or_id_or_slug |
|
325 | - * @return int |
|
326 | - * @throws EE_Error |
|
327 | - */ |
|
328 | - public function ensure_is_ID($base_obj_or_id_or_slug) |
|
329 | - { |
|
330 | - if (is_string($base_obj_or_id_or_slug)) { |
|
331 | - // assume it's a slug |
|
332 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
333 | - } |
|
334 | - return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Verifies the button urls on all the passed payment methods have a valid button url. |
|
340 | - * If not, resets them to their default. |
|
341 | - * |
|
342 | - * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
343 | - * @throws EE_Error |
|
344 | - * @throws ReflectionException |
|
345 | - */ |
|
346 | - public function verify_button_urls($payment_methods = null) |
|
347 | - { |
|
348 | - $payment_methods = is_array($payment_methods) |
|
349 | - ? $payment_methods |
|
350 | - : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
351 | - foreach ($payment_methods as $payment_method) { |
|
352 | - try { |
|
353 | - // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
354 | - // though this is a caffeinated install, reset it to the default. |
|
355 | - $current_button_url = $payment_method->button_url(); |
|
356 | - if ( |
|
357 | - empty($current_button_url) |
|
358 | - || ( |
|
359 | - strpos($current_button_url, 'decaf') !== false |
|
360 | - && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
361 | - ) |
|
362 | - ) { |
|
363 | - $payment_method->save( |
|
364 | - [ |
|
365 | - 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
366 | - ] |
|
367 | - ); |
|
368 | - } |
|
369 | - } catch (EE_Error $e) { |
|
370 | - $payment_method->deactivate(); |
|
371 | - } |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
378 | - * but also verifies the payment method type of each is a usable object. If not, |
|
379 | - * deactivate it, sets a notification, and deactivates it |
|
380 | - * |
|
381 | - * @param array $rows |
|
382 | - * @return EE_Payment_Method[] |
|
383 | - * @throws EE_Error |
|
384 | - * @throws InvalidDataTypeException |
|
385 | - * @throws ReflectionException |
|
386 | - */ |
|
387 | - protected function _create_objects($rows = []) |
|
388 | - { |
|
389 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
390 | - $payment_methods = parent::_create_objects($rows); |
|
391 | - /* @var $payment_methods EE_Payment_Method[] */ |
|
392 | - $usable_payment_methods = []; |
|
393 | - foreach ($payment_methods as $key => $payment_method) { |
|
394 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
395 | - $usable_payment_methods[ $key ] = $payment_method; |
|
396 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
397 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
398 | - // its scripts). but for backwards-compat we should continue to do that |
|
399 | - $payment_method->type_obj(); |
|
400 | - } elseif ($payment_method->active()) { |
|
401 | - // only deactivate and notify the admin if the payment is active somewhere |
|
402 | - $payment_method->deactivate(); |
|
403 | - $payment_method->save(); |
|
404 | - do_action( |
|
405 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
406 | - $payment_method |
|
407 | - ); |
|
408 | - new PersistentAdminNotice( |
|
409 | - 'auto-deactivated-' . $payment_method->type(), |
|
410 | - sprintf( |
|
411 | - esc_html__( |
|
412 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
413 | - 'event_espresso' |
|
414 | - ), |
|
415 | - $payment_method->admin_name(), |
|
416 | - '<br />', |
|
417 | - '<a href="' . admin_url('plugins.php') . '">', |
|
418 | - '</a>' |
|
419 | - ), |
|
420 | - true |
|
421 | - ); |
|
422 | - } |
|
423 | - } |
|
424 | - return $usable_payment_methods; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * Gets all the payment methods which can be used for transaction |
|
430 | - * (according to the relations between payment methods and events, and |
|
431 | - * the currencies used for the transaction and their relation to payment methods) |
|
432 | - * |
|
433 | - * @param EE_Transaction $transaction |
|
434 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
435 | - * @return EE_Payment_Method[] |
|
436 | - * @throws EE_Error |
|
437 | - */ |
|
438 | - public function get_all_for_transaction($transaction, $scope) |
|
439 | - { |
|
440 | - // give addons a chance to override what payment methods are chosen based on the transaction |
|
441 | - return apply_filters( |
|
442 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
443 | - $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
444 | - $transaction, |
|
445 | - $scope |
|
446 | - ); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * Returns the payment method used for the last payment made for a registration. |
|
452 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
453 | - * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
454 | - * |
|
455 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
456 | - * registration. |
|
457 | - * @return EE_Payment|null |
|
458 | - * @throws EE_Error |
|
459 | - */ |
|
460 | - public function get_last_used_for_registration($registration_or_reg_id) |
|
461 | - { |
|
462 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
463 | - |
|
464 | - $query_params = [ |
|
465 | - 0 => [ |
|
466 | - 'Payment.Registration.REG_ID' => $registration_id, |
|
467 | - ], |
|
468 | - 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
469 | - ]; |
|
470 | - return $this->get_one($query_params); |
|
471 | - } |
|
20 | + const scope_cart = 'CART'; |
|
21 | + |
|
22 | + const scope_admin = 'ADMIN'; |
|
23 | + |
|
24 | + const scope_api = 'API'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type EEM_Payment_Method |
|
28 | + */ |
|
29 | + protected static $_instance = null; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * private constructor to prevent direct creation |
|
34 | + * |
|
35 | + * @param null $timezone |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | + protected function __construct($timezone = null) |
|
39 | + { |
|
40 | + $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
41 | + $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
42 | + $this->_tables = [ |
|
43 | + 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
44 | + ]; |
|
45 | + $this->_fields = [ |
|
46 | + 'Payment_Method' => [ |
|
47 | + 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
48 | + 'PMD_ID', |
|
49 | + esc_html__('ID', 'event_espresso') |
|
50 | + ), |
|
51 | + 'PMD_type' => new EE_Plain_Text_Field( |
|
52 | + 'PMD_type', |
|
53 | + esc_html__('Payment Method Type', 'event_espresso'), |
|
54 | + false, |
|
55 | + 'Admin_Only' |
|
56 | + ), |
|
57 | + 'PMD_name' => new EE_Plain_Text_Field( |
|
58 | + 'PMD_name', |
|
59 | + esc_html__('Name', 'event_espresso'), |
|
60 | + false |
|
61 | + ), |
|
62 | + 'PMD_desc' => new EE_Post_Content_Field( |
|
63 | + 'PMD_desc', |
|
64 | + esc_html__('Description', 'event_espresso'), |
|
65 | + false, |
|
66 | + '' |
|
67 | + ), |
|
68 | + 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
69 | + 'PMD_admin_name', |
|
70 | + esc_html__('Admin-Only Name', 'event_espresso'), |
|
71 | + true |
|
72 | + ), |
|
73 | + 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
74 | + 'PMD_admin_desc', |
|
75 | + esc_html__('Admin-Only Description', 'event_espresso'), |
|
76 | + true |
|
77 | + ), |
|
78 | + 'PMD_slug' => new EE_Slug_Field( |
|
79 | + 'PMD_slug', |
|
80 | + esc_html__('Slug', 'event_espresso'), |
|
81 | + false |
|
82 | + ), |
|
83 | + 'PMD_order' => new EE_Integer_Field( |
|
84 | + 'PMD_order', |
|
85 | + esc_html__('Order', 'event_espresso'), |
|
86 | + false, |
|
87 | + 0 |
|
88 | + ), |
|
89 | + 'PMD_debug_mode' => new EE_Boolean_Field( |
|
90 | + 'PMD_debug_mode', |
|
91 | + esc_html__('Debug Mode On?', 'event_espresso'), |
|
92 | + false, |
|
93 | + false |
|
94 | + ), |
|
95 | + 'PMD_wp_user' => new EE_WP_User_Field( |
|
96 | + 'PMD_wp_user', |
|
97 | + esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
98 | + false |
|
99 | + ), |
|
100 | + 'PMD_open_by_default' => new EE_Boolean_Field( |
|
101 | + 'PMD_open_by_default', |
|
102 | + esc_html__('Open by Default?', 'event_espresso'), |
|
103 | + false, |
|
104 | + false |
|
105 | + ), |
|
106 | + 'PMD_button_url' => new EE_Plain_Text_Field( |
|
107 | + 'PMD_button_url', |
|
108 | + esc_html__('Button URL', 'event_espresso'), |
|
109 | + true, |
|
110 | + '' |
|
111 | + ), |
|
112 | + 'PMD_scope' => new EE_Serialized_Text_Field( |
|
113 | + 'PMD_scope', |
|
114 | + esc_html__('Usable From?', 'event_espresso'), |
|
115 | + false, |
|
116 | + []// possible values currently are 'CART','ADMIN','API' |
|
117 | + ), |
|
118 | + ], |
|
119 | + ]; |
|
120 | + $this->_model_relations = [ |
|
121 | + 'Payment' => new EE_Has_Many_Relation(), |
|
122 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
123 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
124 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
125 | + ]; |
|
126 | + parent::__construct($timezone); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Gets one by the slug provided |
|
132 | + * |
|
133 | + * @param string $slug |
|
134 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
135 | + * @throws EE_Error |
|
136 | + */ |
|
137 | + public function get_one_by_slug($slug) |
|
138 | + { |
|
139 | + return $this->get_one([['PMD_slug' => $slug]]); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Gets all the acceptable scopes for payment methods. |
|
145 | + * Keys are their names as store din the DB, and values are nice names for displaying them |
|
146 | + * |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public function scopes() |
|
150 | + { |
|
151 | + return apply_filters( |
|
152 | + 'FHEE__EEM_Payment_Method__scopes', |
|
153 | + [ |
|
154 | + EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
155 | + EEM_Payment_Method::scope_admin => esc_html__( |
|
156 | + 'Admin Registration Page (no online processing)', |
|
157 | + 'event_espresso' |
|
158 | + ), |
|
159 | + ] |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Determines if this is an valid scope |
|
166 | + * |
|
167 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
168 | + * @return boolean |
|
169 | + */ |
|
170 | + public function is_valid_scope($scope) |
|
171 | + { |
|
172 | + $scopes = $this->scopes(); |
|
173 | + if (isset($scopes[ $scope ])) { |
|
174 | + return true; |
|
175 | + } |
|
176 | + return false; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Gets all active payment methods |
|
182 | + * |
|
183 | + * @param string $scope one of |
|
184 | + * @param array $query_params |
|
185 | + * @return EE_Base_Class[]|EE_Payment_Method[] |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + public function get_all_active($scope = null, $query_params = []) |
|
189 | + { |
|
190 | + if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
191 | + $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
192 | + } |
|
193 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * Counts all active gateways in the specified scope |
|
199 | + * |
|
200 | + * @param string $scope one of EEM_Payment_Method::scope_* |
|
201 | + * @param array $query_params |
|
202 | + * @return int |
|
203 | + * @throws EE_Error |
|
204 | + */ |
|
205 | + public function count_active($scope = null, $query_params = []) |
|
206 | + { |
|
207 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
213 | + * argument to get all active for a given scope |
|
214 | + * |
|
215 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
216 | + * @param array $query_params |
|
217 | + * @return array |
|
218 | + * @throws EE_Error |
|
219 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
220 | + */ |
|
221 | + protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
222 | + { |
|
223 | + if ($scope) { |
|
224 | + if ($this->is_valid_scope($scope)) { |
|
225 | + return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
226 | + } |
|
227 | + throw new EE_Error( |
|
228 | + sprintf( |
|
229 | + esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
230 | + $scope |
|
231 | + ) |
|
232 | + ); |
|
233 | + } |
|
234 | + $acceptable_scopes = []; |
|
235 | + $count = 0; |
|
236 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
237 | + $count++; |
|
238 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
239 | + } |
|
240 | + return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
246 | + * argument to get all active for a given scope |
|
247 | + * |
|
248 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
249 | + * @param array $query_params |
|
250 | + * @return array |
|
251 | + * @throws EE_Error |
|
252 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
253 | + */ |
|
254 | + public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
255 | + { |
|
256 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Gets one active payment method. see @get_all_active for documentation |
|
262 | + * |
|
263 | + * @param string $scope |
|
264 | + * @param array $query_params |
|
265 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
266 | + * @throws EE_Error |
|
267 | + */ |
|
268 | + public function get_one_active($scope = null, $query_params = []) |
|
269 | + { |
|
270 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * Gets one payment method of that type, regardless of whether its active or not |
|
276 | + * |
|
277 | + * @param string $type |
|
278 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + public function get_one_of_type($type) |
|
282 | + { |
|
283 | + return $this->get_one([['PMD_type' => $type]]); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * Overrides parent ot also check by the slug |
|
289 | + * |
|
290 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
291 | + * @param boolean $ensure_is_in_db |
|
292 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
293 | + * @throws EE_Error |
|
294 | + * @see EEM_Base::ensure_is_obj() |
|
295 | + */ |
|
296 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
297 | + { |
|
298 | + // first: check if it's a slug |
|
299 | + if (is_string($base_class_obj_or_id)) { |
|
300 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
301 | + if ($obj) { |
|
302 | + return $obj; |
|
303 | + } |
|
304 | + } |
|
305 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
306 | + try { |
|
307 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
308 | + } catch (EE_Error $e) { |
|
309 | + // handle it outside the catch |
|
310 | + } |
|
311 | + throw new EE_Error( |
|
312 | + sprintf( |
|
313 | + esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
314 | + $base_class_obj_or_id |
|
315 | + ) |
|
316 | + ); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * Gets the ID of this object, or if its a string finds the object's id |
|
322 | + * associated with that slug |
|
323 | + * |
|
324 | + * @param mixed $base_obj_or_id_or_slug |
|
325 | + * @return int |
|
326 | + * @throws EE_Error |
|
327 | + */ |
|
328 | + public function ensure_is_ID($base_obj_or_id_or_slug) |
|
329 | + { |
|
330 | + if (is_string($base_obj_or_id_or_slug)) { |
|
331 | + // assume it's a slug |
|
332 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
333 | + } |
|
334 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Verifies the button urls on all the passed payment methods have a valid button url. |
|
340 | + * If not, resets them to their default. |
|
341 | + * |
|
342 | + * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
343 | + * @throws EE_Error |
|
344 | + * @throws ReflectionException |
|
345 | + */ |
|
346 | + public function verify_button_urls($payment_methods = null) |
|
347 | + { |
|
348 | + $payment_methods = is_array($payment_methods) |
|
349 | + ? $payment_methods |
|
350 | + : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
351 | + foreach ($payment_methods as $payment_method) { |
|
352 | + try { |
|
353 | + // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
354 | + // though this is a caffeinated install, reset it to the default. |
|
355 | + $current_button_url = $payment_method->button_url(); |
|
356 | + if ( |
|
357 | + empty($current_button_url) |
|
358 | + || ( |
|
359 | + strpos($current_button_url, 'decaf') !== false |
|
360 | + && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
361 | + ) |
|
362 | + ) { |
|
363 | + $payment_method->save( |
|
364 | + [ |
|
365 | + 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
366 | + ] |
|
367 | + ); |
|
368 | + } |
|
369 | + } catch (EE_Error $e) { |
|
370 | + $payment_method->deactivate(); |
|
371 | + } |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
378 | + * but also verifies the payment method type of each is a usable object. If not, |
|
379 | + * deactivate it, sets a notification, and deactivates it |
|
380 | + * |
|
381 | + * @param array $rows |
|
382 | + * @return EE_Payment_Method[] |
|
383 | + * @throws EE_Error |
|
384 | + * @throws InvalidDataTypeException |
|
385 | + * @throws ReflectionException |
|
386 | + */ |
|
387 | + protected function _create_objects($rows = []) |
|
388 | + { |
|
389 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
390 | + $payment_methods = parent::_create_objects($rows); |
|
391 | + /* @var $payment_methods EE_Payment_Method[] */ |
|
392 | + $usable_payment_methods = []; |
|
393 | + foreach ($payment_methods as $key => $payment_method) { |
|
394 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
395 | + $usable_payment_methods[ $key ] = $payment_method; |
|
396 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
397 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
398 | + // its scripts). but for backwards-compat we should continue to do that |
|
399 | + $payment_method->type_obj(); |
|
400 | + } elseif ($payment_method->active()) { |
|
401 | + // only deactivate and notify the admin if the payment is active somewhere |
|
402 | + $payment_method->deactivate(); |
|
403 | + $payment_method->save(); |
|
404 | + do_action( |
|
405 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
406 | + $payment_method |
|
407 | + ); |
|
408 | + new PersistentAdminNotice( |
|
409 | + 'auto-deactivated-' . $payment_method->type(), |
|
410 | + sprintf( |
|
411 | + esc_html__( |
|
412 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
413 | + 'event_espresso' |
|
414 | + ), |
|
415 | + $payment_method->admin_name(), |
|
416 | + '<br />', |
|
417 | + '<a href="' . admin_url('plugins.php') . '">', |
|
418 | + '</a>' |
|
419 | + ), |
|
420 | + true |
|
421 | + ); |
|
422 | + } |
|
423 | + } |
|
424 | + return $usable_payment_methods; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * Gets all the payment methods which can be used for transaction |
|
430 | + * (according to the relations between payment methods and events, and |
|
431 | + * the currencies used for the transaction and their relation to payment methods) |
|
432 | + * |
|
433 | + * @param EE_Transaction $transaction |
|
434 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
435 | + * @return EE_Payment_Method[] |
|
436 | + * @throws EE_Error |
|
437 | + */ |
|
438 | + public function get_all_for_transaction($transaction, $scope) |
|
439 | + { |
|
440 | + // give addons a chance to override what payment methods are chosen based on the transaction |
|
441 | + return apply_filters( |
|
442 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
443 | + $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
444 | + $transaction, |
|
445 | + $scope |
|
446 | + ); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * Returns the payment method used for the last payment made for a registration. |
|
452 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
453 | + * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
454 | + * |
|
455 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
456 | + * registration. |
|
457 | + * @return EE_Payment|null |
|
458 | + * @throws EE_Error |
|
459 | + */ |
|
460 | + public function get_last_used_for_registration($registration_or_reg_id) |
|
461 | + { |
|
462 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
463 | + |
|
464 | + $query_params = [ |
|
465 | + 0 => [ |
|
466 | + 'Payment.Registration.REG_ID' => $registration_id, |
|
467 | + ], |
|
468 | + 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
469 | + ]; |
|
470 | + return $this->get_one($query_params); |
|
471 | + } |
|
472 | 472 | } |
@@ -12,116 +12,116 @@ |
||
12 | 12 | class EEM_Event_Message_Template extends EEM_Base |
13 | 13 | { |
14 | 14 | |
15 | - // private instance of the EEM_Event_Message_Template object |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance of the EEM_Event_Message_Template object |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * protected constructor to prevent direct creation |
|
21 | - * |
|
22 | - * @param null $timezone |
|
23 | - * @throws EE_Error |
|
24 | - */ |
|
25 | - protected function __construct($timezone = null) |
|
26 | - { |
|
27 | - $this->singular_item = esc_html__('Event Message Template', 'event_espresso'); |
|
28 | - $this->plural_item = esc_html__('Event Message Templates', 'event_espresso'); |
|
19 | + /** |
|
20 | + * protected constructor to prevent direct creation |
|
21 | + * |
|
22 | + * @param null $timezone |
|
23 | + * @throws EE_Error |
|
24 | + */ |
|
25 | + protected function __construct($timezone = null) |
|
26 | + { |
|
27 | + $this->singular_item = esc_html__('Event Message Template', 'event_espresso'); |
|
28 | + $this->plural_item = esc_html__('Event Message Templates', 'event_espresso'); |
|
29 | 29 | |
30 | - $this->_tables = [ |
|
31 | - 'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'), |
|
32 | - ]; |
|
33 | - $this->_fields = [ |
|
34 | - 'Event_Message_Template' => [ |
|
35 | - 'EMT_ID' => new EE_Primary_Key_Int_Field( |
|
36 | - 'EMT_ID', |
|
37 | - esc_html__('Event Message Template ID', 'event_espresso') |
|
38 | - ), |
|
39 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
40 | - 'EVT_ID', |
|
41 | - esc_html__('The ID to the Event', 'event_espresso'), |
|
42 | - false, |
|
43 | - 0, |
|
44 | - 'Event' |
|
45 | - ), |
|
46 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
47 | - 'GRP_ID', |
|
48 | - esc_html__('The ID to the Message Template Group', 'event_espresso'), |
|
49 | - false, |
|
50 | - 0, |
|
51 | - 'Message_Template_Group' |
|
52 | - ), |
|
53 | - ], |
|
54 | - ]; |
|
55 | - $this->_model_relations = [ |
|
56 | - 'Event' => new EE_Belongs_To_Relation(), |
|
57 | - 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
58 | - ]; |
|
59 | - $path_to_event = 'Event'; |
|
60 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
61 | - $path_to_event |
|
62 | - ); |
|
63 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
64 | - $path_to_event |
|
65 | - ); |
|
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
67 | - $path_to_event |
|
68 | - ); |
|
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
70 | - $path_to_event, |
|
71 | - EEM_Base::caps_edit |
|
72 | - ); |
|
73 | - parent::__construct($timezone); |
|
74 | - } |
|
30 | + $this->_tables = [ |
|
31 | + 'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'), |
|
32 | + ]; |
|
33 | + $this->_fields = [ |
|
34 | + 'Event_Message_Template' => [ |
|
35 | + 'EMT_ID' => new EE_Primary_Key_Int_Field( |
|
36 | + 'EMT_ID', |
|
37 | + esc_html__('Event Message Template ID', 'event_espresso') |
|
38 | + ), |
|
39 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
40 | + 'EVT_ID', |
|
41 | + esc_html__('The ID to the Event', 'event_espresso'), |
|
42 | + false, |
|
43 | + 0, |
|
44 | + 'Event' |
|
45 | + ), |
|
46 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
47 | + 'GRP_ID', |
|
48 | + esc_html__('The ID to the Message Template Group', 'event_espresso'), |
|
49 | + false, |
|
50 | + 0, |
|
51 | + 'Message_Template_Group' |
|
52 | + ), |
|
53 | + ], |
|
54 | + ]; |
|
55 | + $this->_model_relations = [ |
|
56 | + 'Event' => new EE_Belongs_To_Relation(), |
|
57 | + 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
58 | + ]; |
|
59 | + $path_to_event = 'Event'; |
|
60 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
61 | + $path_to_event |
|
62 | + ); |
|
63 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
64 | + $path_to_event |
|
65 | + ); |
|
66 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
67 | + $path_to_event |
|
68 | + ); |
|
69 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
70 | + $path_to_event, |
|
71 | + EEM_Base::caps_edit |
|
72 | + ); |
|
73 | + parent::__construct($timezone); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * helper method to simply return an array of event ids for events attached to the given |
|
79 | - * message template group. |
|
80 | - * |
|
81 | - * @param int $GRP_ID The MTP group we want attached events for. |
|
82 | - * @return array An array of event ids. |
|
83 | - * @throws EE_Error |
|
84 | - * @since 4.3.0 |
|
85 | - */ |
|
86 | - public function get_attached_event_ids($GRP_ID) |
|
87 | - { |
|
88 | - $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID'); |
|
89 | - $event_ids = call_user_func_array('array_merge', $event_ids); |
|
90 | - return $event_ids; |
|
91 | - } |
|
77 | + /** |
|
78 | + * helper method to simply return an array of event ids for events attached to the given |
|
79 | + * message template group. |
|
80 | + * |
|
81 | + * @param int $GRP_ID The MTP group we want attached events for. |
|
82 | + * @return array An array of event ids. |
|
83 | + * @throws EE_Error |
|
84 | + * @since 4.3.0 |
|
85 | + */ |
|
86 | + public function get_attached_event_ids($GRP_ID) |
|
87 | + { |
|
88 | + $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID'); |
|
89 | + $event_ids = call_user_func_array('array_merge', $event_ids); |
|
90 | + return $event_ids; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * helper method for clearing event/group relations for the given event ids and grp ids. |
|
96 | - * |
|
97 | - * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs. |
|
98 | - * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be GRP IDs. |
|
99 | - * @return int How many rows were deleted. |
|
100 | - * @throws EE_Error |
|
101 | - * @throws EE_Error |
|
102 | - */ |
|
103 | - public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = []) |
|
104 | - { |
|
105 | - if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
106 | - throw new EE_Error( |
|
107 | - sprintf( |
|
108 | - esc_html__( |
|
109 | - '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', |
|
110 | - 'event_espresso' |
|
111 | - ), |
|
112 | - __METHOD__ |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
94 | + /** |
|
95 | + * helper method for clearing event/group relations for the given event ids and grp ids. |
|
96 | + * |
|
97 | + * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs. |
|
98 | + * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be GRP IDs. |
|
99 | + * @return int How many rows were deleted. |
|
100 | + * @throws EE_Error |
|
101 | + * @throws EE_Error |
|
102 | + */ |
|
103 | + public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = []) |
|
104 | + { |
|
105 | + if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
106 | + throw new EE_Error( |
|
107 | + sprintf( |
|
108 | + esc_html__( |
|
109 | + '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', |
|
110 | + 'event_espresso' |
|
111 | + ), |
|
112 | + __METHOD__ |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | 116 | |
117 | - $where = []; |
|
118 | - if (! empty($GRP_IDs)) { |
|
119 | - $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
|
120 | - } |
|
121 | - if (! empty($EVT_IDs)) { |
|
122 | - $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
|
123 | - } |
|
117 | + $where = []; |
|
118 | + if (! empty($GRP_IDs)) { |
|
119 | + $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
|
120 | + } |
|
121 | + if (! empty($EVT_IDs)) { |
|
122 | + $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
|
123 | + } |
|
124 | 124 | |
125 | - return $this->delete([$where], false); |
|
126 | - } |
|
125 | + return $this->delete([$where], false); |
|
126 | + } |
|
127 | 127 | } |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
58 | 58 | ]; |
59 | 59 | $path_to_event = 'Event'; |
60 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
60 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
61 | 61 | $path_to_event |
62 | 62 | ); |
63 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
63 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
64 | 64 | $path_to_event |
65 | 65 | ); |
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
66 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
67 | 67 | $path_to_event |
68 | 68 | ); |
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
69 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
70 | 70 | $path_to_event, |
71 | 71 | EEM_Base::caps_edit |
72 | 72 | ); |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | $where = []; |
118 | - if (! empty($GRP_IDs)) { |
|
118 | + if ( ! empty($GRP_IDs)) { |
|
119 | 119 | $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
120 | 120 | } |
121 | - if (! empty($EVT_IDs)) { |
|
121 | + if ( ! empty($EVT_IDs)) { |
|
122 | 122 | $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
123 | 123 | } |
124 | 124 |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + if ( ! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | 42 | /** |
43 | 43 | * espresso_duplicate_plugin_error |
44 | 44 | * displays if more than one version of EE is activated at the same time |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
63 | 63 | } else { |
64 | 64 | define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | 66 | /** |
67 | 67 | * espresso_minimum_php_version_error |
68 | 68 | * |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | |
117 | 117 | register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
119 | + require_once __DIR__.'/core/bootstrap_espresso.php'; |
|
120 | 120 | bootstrap_espresso(); |
121 | 121 | } |
122 | 122 | } |
123 | -if (! function_exists('espresso_deactivate_plugin')) { |
|
123 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
124 | 124 | /** |
125 | 125 | * deactivate_plugin |
126 | 126 | * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | */ |
132 | 132 | function espresso_deactivate_plugin($plugin_basename = '') |
133 | 133 | { |
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
134 | + if ( ! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
136 | 136 | } |
137 | 137 | unset($_GET['activate'], $_REQUEST['activate']); |
138 | 138 | deactivate_plugins($plugin_basename); |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.000'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.000'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |
@@ -4,45 +4,45 @@ |
||
4 | 4 | interface EnqueueAssetsInterface |
5 | 5 | { |
6 | 6 | |
7 | - /** |
|
8 | - * a place to register scripts and stylesheets with WordPress core |
|
9 | - * IMPORTANT !!! |
|
10 | - * ALL JavaScript files need to be registered for loading in the footer |
|
11 | - * by setting the 5th parameter of wp_register_script() to ` true ` |
|
12 | - * |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function registerScriptsAndStylesheets(); |
|
7 | + /** |
|
8 | + * a place to register scripts and stylesheets with WordPress core |
|
9 | + * IMPORTANT !!! |
|
10 | + * ALL JavaScript files need to be registered for loading in the footer |
|
11 | + * by setting the 5th parameter of wp_register_script() to ` true ` |
|
12 | + * |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function registerScriptsAndStylesheets(); |
|
16 | 16 | |
17 | - /** |
|
18 | - * a place to enqueue previously registered stylesheets |
|
19 | - * this will be called during the wp_enqueue_scripts hook for frontend requests |
|
20 | - * |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function enqueueStylesheets(); |
|
17 | + /** |
|
18 | + * a place to enqueue previously registered stylesheets |
|
19 | + * this will be called during the wp_enqueue_scripts hook for frontend requests |
|
20 | + * |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function enqueueStylesheets(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * a place to enqueue previously registered stylesheets |
|
27 | - * this will be called during the admin_enqueue_scripts hook for admin requests |
|
28 | - * |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function enqueueAdminStylesheets(); |
|
25 | + /** |
|
26 | + * a place to enqueue previously registered stylesheets |
|
27 | + * this will be called during the admin_enqueue_scripts hook for admin requests |
|
28 | + * |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function enqueueAdminStylesheets(); |
|
32 | 32 | |
33 | - /** |
|
34 | - * a place to enqueue previously registered scripts for frontend requests |
|
35 | - * |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function enqueueScripts(); |
|
33 | + /** |
|
34 | + * a place to enqueue previously registered scripts for frontend requests |
|
35 | + * |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function enqueueScripts(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * a place to enqueue previously registered scripts for admin requests |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function enqueueAdminScripts(); |
|
40 | + /** |
|
41 | + * a place to enqueue previously registered scripts for admin requests |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function enqueueAdminScripts(); |
|
46 | 46 | } |
47 | 47 | // End of file EnqueueAssetsInterface.php |
48 | 48 | // Location: EventEspresso\core\domain/EnqueueAssetsInterface.php |