@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function form($for_display = false) |
| 173 | 173 | { |
| 174 | - if (! $this->formIsValid()) { |
|
| 174 | + if ( ! $this->formIsValid()) { |
|
| 175 | 175 | return null; |
| 176 | 176 | } |
| 177 | 177 | if ($for_display) { |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | public function setFormName($form_name) |
| 276 | 276 | { |
| 277 | - if (! is_string($form_name)) { |
|
| 277 | + if ( ! is_string($form_name)) { |
|
| 278 | 278 | throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
| 279 | 279 | } |
| 280 | 280 | $this->form_name = $form_name; |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function setAdminName($admin_name) |
| 300 | 300 | { |
| 301 | - if (! is_string($admin_name)) { |
|
| 301 | + if ( ! is_string($admin_name)) { |
|
| 302 | 302 | throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
| 303 | 303 | } |
| 304 | 304 | $this->admin_name = $admin_name; |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | public function setSlug($slug) |
| 324 | 324 | { |
| 325 | - if (! is_string($slug)) { |
|
| 325 | + if ( ! is_string($slug)) { |
|
| 326 | 326 | throw new InvalidDataTypeException('$slug', $slug, 'string'); |
| 327 | 327 | } |
| 328 | 328 | $this->slug = $slug; |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | public function setSubmitBtnText($submit_btn_text) |
| 347 | 347 | { |
| 348 | - if (! is_string($submit_btn_text)) { |
|
| 348 | + if ( ! is_string($submit_btn_text)) { |
|
| 349 | 349 | throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
| 350 | 350 | } |
| 351 | 351 | if (empty($submit_btn_text)) { |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | */ |
| 375 | 375 | public function setFormAction($form_action) |
| 376 | 376 | { |
| 377 | - if (! is_string($form_action)) { |
|
| 377 | + if ( ! is_string($form_action)) { |
|
| 378 | 378 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
| 379 | 379 | } |
| 380 | 380 | $this->form_action = $form_action; |
@@ -493,11 +493,11 @@ discard block |
||
| 493 | 493 | $text = ! empty($text) ? $text : $this->submitBtnText(); |
| 494 | 494 | return new EE_Submit_Input( |
| 495 | 495 | array( |
| 496 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 497 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 496 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
| 497 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
| 498 | 498 | 'html_class' => 'ee-form-submit', |
| 499 | 499 | 'html_label' => ' ', |
| 500 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 500 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
| 501 | 501 | 'default' => $text, |
| 502 | 502 | ) |
| 503 | 503 | ); |
@@ -513,11 +513,11 @@ discard block |
||
| 513 | 513 | */ |
| 514 | 514 | public function appendSubmitButton($text = '') |
| 515 | 515 | { |
| 516 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 516 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
| 517 | 517 | return; |
| 518 | 518 | } |
| 519 | 519 | $this->form->add_subsections( |
| 520 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 520 | + array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)), |
|
| 521 | 521 | null, |
| 522 | 522 | false |
| 523 | 523 | ); |
@@ -534,11 +534,11 @@ discard block |
||
| 534 | 534 | { |
| 535 | 535 | $cancel_button = new EE_Submit_Input( |
| 536 | 536 | array( |
| 537 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 538 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 537 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
| 538 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
| 539 | 539 | 'html_class' => 'ee-cancel-form', |
| 540 | 540 | 'html_label' => ' ', |
| 541 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 541 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
| 542 | 542 | 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
| 543 | 543 | ) |
| 544 | 544 | ); |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | $this->form->add_subsections( |
| 559 | 559 | array( |
| 560 | 560 | 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
| 561 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 561 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
| 562 | 562 | ), |
| 563 | 563 | ), |
| 564 | 564 | null, |
@@ -644,11 +644,11 @@ discard block |
||
| 644 | 644 | */ |
| 645 | 645 | public function process($submitted_form_data = array()) |
| 646 | 646 | { |
| 647 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 647 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
| 648 | 648 | throw new InvalidFormSubmissionException($this->form_name); |
| 649 | 649 | } |
| 650 | 650 | $this->form(true)->receive_form_submission($submitted_form_data); |
| 651 | - if (! $this->form()->is_valid()) { |
|
| 651 | + if ( ! $this->form()->is_valid()) { |
|
| 652 | 652 | throw new InvalidFormSubmissionException( |
| 653 | 653 | $this->form_name, |
| 654 | 654 | sprintf( |
@@ -29,643 +29,643 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | abstract class FormHandler implements FormHandlerInterface |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * will add opening and closing HTML form tags as well as a submit button |
|
| 34 | - */ |
|
| 35 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * will add opening and closing HTML form tags but NOT a submit button |
|
| 39 | - */ |
|
| 40 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 44 | - */ |
|
| 45 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 49 | - */ |
|
| 50 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * if set to false, then this form has no displayable content, |
|
| 54 | - * and will only be used for processing data sent passed via GET or POST |
|
| 55 | - * defaults to true ( ie: form has displayable content ) |
|
| 56 | - * |
|
| 57 | - * @var boolean $displayable |
|
| 58 | - */ |
|
| 59 | - private $displayable = true; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string $form_name |
|
| 63 | - */ |
|
| 64 | - private $form_name; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var string $admin_name |
|
| 68 | - */ |
|
| 69 | - private $admin_name; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string $slug |
|
| 73 | - */ |
|
| 74 | - private $slug; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var string $submit_btn_text |
|
| 78 | - */ |
|
| 79 | - private $submit_btn_text; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var string $form_action |
|
| 83 | - */ |
|
| 84 | - private $form_action; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * form params in key value pairs |
|
| 88 | - * can be added to form action URL or as hidden inputs |
|
| 89 | - * |
|
| 90 | - * @var array $form_args |
|
| 91 | - */ |
|
| 92 | - private $form_args = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * value of one of the string constant above |
|
| 96 | - * |
|
| 97 | - * @var string $form_config |
|
| 98 | - */ |
|
| 99 | - private $form_config; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * whether or not the form was determined to be invalid |
|
| 103 | - * |
|
| 104 | - * @var boolean $form_has_errors |
|
| 105 | - */ |
|
| 106 | - private $form_has_errors; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * the absolute top level form section being used on the page |
|
| 110 | - * |
|
| 111 | - * @var EE_Form_Section_Proper $form |
|
| 112 | - */ |
|
| 113 | - private $form; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var EE_Registry $registry |
|
| 117 | - */ |
|
| 118 | - protected $registry; |
|
| 119 | - |
|
| 120 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 121 | - /** |
|
| 122 | - * Form constructor. |
|
| 123 | - * |
|
| 124 | - * @param string $form_name |
|
| 125 | - * @param string $admin_name |
|
| 126 | - * @param string $slug |
|
| 127 | - * @param string $form_action |
|
| 128 | - * @param string $form_config |
|
| 129 | - * @param EE_Registry $registry |
|
| 130 | - * @throws InvalidDataTypeException |
|
| 131 | - * @throws DomainException |
|
| 132 | - * @throws InvalidArgumentException |
|
| 133 | - */ |
|
| 134 | - public function __construct( |
|
| 135 | - $form_name, |
|
| 136 | - $admin_name, |
|
| 137 | - $slug, |
|
| 138 | - $form_action = '', |
|
| 139 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 140 | - EE_Registry $registry |
|
| 141 | - ) { |
|
| 142 | - $this->setFormName($form_name); |
|
| 143 | - $this->setAdminName($admin_name); |
|
| 144 | - $this->setSlug($slug); |
|
| 145 | - $this->setFormAction($form_action); |
|
| 146 | - $this->setFormConfig($form_config); |
|
| 147 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 148 | - $this->registry = $registry; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public static function getFormConfigConstants() |
|
| 156 | - { |
|
| 157 | - return array( |
|
| 158 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 159 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 160 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 161 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param bool $for_display |
|
| 168 | - * @return EE_Form_Section_Proper |
|
| 169 | - * @throws EE_Error |
|
| 170 | - * @throws LogicException |
|
| 171 | - */ |
|
| 172 | - public function form($for_display = false) |
|
| 173 | - { |
|
| 174 | - if (! $this->formIsValid()) { |
|
| 175 | - return null; |
|
| 176 | - } |
|
| 177 | - if ($for_display) { |
|
| 178 | - $form_config = $this->formConfig(); |
|
| 179 | - if ( |
|
| 180 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 181 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 182 | - ) { |
|
| 183 | - $this->appendSubmitButton(); |
|
| 184 | - $this->clearFormButtonFloats(); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - return $this->form; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @return boolean |
|
| 193 | - * @throws LogicException |
|
| 194 | - */ |
|
| 195 | - public function formIsValid() |
|
| 196 | - { |
|
| 197 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 198 | - return true; |
|
| 199 | - } |
|
| 200 | - $form = apply_filters( |
|
| 201 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 202 | - $this->generate(), |
|
| 203 | - $this |
|
| 204 | - ); |
|
| 205 | - if ($this->verifyForm($form)) { |
|
| 206 | - $this->setForm($form); |
|
| 207 | - } |
|
| 208 | - return true; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @param EE_Form_Section_Proper|null $form |
|
| 214 | - * @return bool |
|
| 215 | - * @throws LogicException |
|
| 216 | - */ |
|
| 217 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 218 | - { |
|
| 219 | - $form = $form !== null ? $form : $this->form; |
|
| 220 | - if ($form instanceof EE_Form_Section_Proper) { |
|
| 221 | - return true; |
|
| 222 | - } |
|
| 223 | - throw new LogicException( |
|
| 224 | - sprintf( |
|
| 225 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 226 | - $this->form_name, |
|
| 227 | - var_export($form, true) |
|
| 228 | - ) |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @param EE_Form_Section_Proper $form |
|
| 235 | - */ |
|
| 236 | - public function setForm(EE_Form_Section_Proper $form) |
|
| 237 | - { |
|
| 238 | - $this->form = $form; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return boolean |
|
| 244 | - */ |
|
| 245 | - public function displayable() |
|
| 246 | - { |
|
| 247 | - return $this->displayable; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @param boolean $displayable |
|
| 253 | - */ |
|
| 254 | - public function setDisplayable($displayable = false) |
|
| 255 | - { |
|
| 256 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * a public name for the form that can be displayed on the frontend of a site |
|
| 262 | - * |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public function formName() |
|
| 266 | - { |
|
| 267 | - return $this->form_name; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param string $form_name |
|
| 273 | - * @throws InvalidDataTypeException |
|
| 274 | - */ |
|
| 275 | - public function setFormName($form_name) |
|
| 276 | - { |
|
| 277 | - if (! is_string($form_name)) { |
|
| 278 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 279 | - } |
|
| 280 | - $this->form_name = $form_name; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * a public name for the form that can be displayed, but only in the admin |
|
| 286 | - * |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - public function adminName() |
|
| 290 | - { |
|
| 291 | - return $this->admin_name; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @param string $admin_name |
|
| 297 | - * @throws InvalidDataTypeException |
|
| 298 | - */ |
|
| 299 | - public function setAdminName($admin_name) |
|
| 300 | - { |
|
| 301 | - if (! is_string($admin_name)) { |
|
| 302 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 303 | - } |
|
| 304 | - $this->admin_name = $admin_name; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * a URL friendly string that can be used for identifying the form |
|
| 310 | - * |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 313 | - public function slug() |
|
| 314 | - { |
|
| 315 | - return $this->slug; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @param string $slug |
|
| 321 | - * @throws InvalidDataTypeException |
|
| 322 | - */ |
|
| 323 | - public function setSlug($slug) |
|
| 324 | - { |
|
| 325 | - if (! is_string($slug)) { |
|
| 326 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 327 | - } |
|
| 328 | - $this->slug = $slug; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * @return string |
|
| 334 | - */ |
|
| 335 | - public function submitBtnText() |
|
| 336 | - { |
|
| 337 | - return $this->submit_btn_text; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @param string $submit_btn_text |
|
| 343 | - * @throws InvalidDataTypeException |
|
| 344 | - * @throws InvalidArgumentException |
|
| 345 | - */ |
|
| 346 | - public function setSubmitBtnText($submit_btn_text) |
|
| 347 | - { |
|
| 348 | - if (! is_string($submit_btn_text)) { |
|
| 349 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 350 | - } |
|
| 351 | - if (empty($submit_btn_text)) { |
|
| 352 | - throw new InvalidArgumentException( |
|
| 353 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 354 | - ); |
|
| 355 | - } |
|
| 356 | - $this->submit_btn_text = $submit_btn_text; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @return string |
|
| 362 | - */ |
|
| 363 | - public function formAction() |
|
| 364 | - { |
|
| 365 | - return ! empty($this->form_args) |
|
| 366 | - ? add_query_arg($this->form_args, $this->form_action) |
|
| 367 | - : $this->form_action; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @param string $form_action |
|
| 373 | - * @throws InvalidDataTypeException |
|
| 374 | - */ |
|
| 375 | - public function setFormAction($form_action) |
|
| 376 | - { |
|
| 377 | - if (! is_string($form_action)) { |
|
| 378 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 379 | - } |
|
| 380 | - $this->form_action = $form_action; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @param array $form_args |
|
| 386 | - * @throws InvalidDataTypeException |
|
| 387 | - * @throws InvalidArgumentException |
|
| 388 | - */ |
|
| 389 | - public function addFormActionArgs($form_args = array()) |
|
| 390 | - { |
|
| 391 | - if (is_object($form_args)) { |
|
| 392 | - throw new InvalidDataTypeException( |
|
| 393 | - '$form_args', |
|
| 394 | - $form_args, |
|
| 395 | - 'anything other than an object was expected.' |
|
| 396 | - ); |
|
| 397 | - } |
|
| 398 | - if (empty($form_args)) { |
|
| 399 | - throw new InvalidArgumentException( |
|
| 400 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 401 | - ); |
|
| 402 | - } |
|
| 403 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public function formConfig() |
|
| 411 | - { |
|
| 412 | - return $this->form_config; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * @param string $form_config |
|
| 418 | - * @throws DomainException |
|
| 419 | - */ |
|
| 420 | - public function setFormConfig($form_config) |
|
| 421 | - { |
|
| 422 | - if ( |
|
| 423 | - ! in_array( |
|
| 424 | - $form_config, |
|
| 425 | - array( |
|
| 426 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 427 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 428 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 429 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 430 | - ), |
|
| 431 | - true |
|
| 432 | - ) |
|
| 433 | - ) { |
|
| 434 | - throw new DomainException( |
|
| 435 | - sprintf( |
|
| 436 | - esc_html__( |
|
| 437 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
| 438 | - 'event_espresso' |
|
| 439 | - ), |
|
| 440 | - $form_config |
|
| 441 | - ) |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - $this->form_config = $form_config; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * called after the form is instantiated |
|
| 450 | - * and used for performing any logic that needs to occur early |
|
| 451 | - * before any of the other methods are called. |
|
| 452 | - * returns true if everything is ok to proceed, |
|
| 453 | - * and false if no further form logic should be implemented |
|
| 454 | - * |
|
| 455 | - * @return boolean |
|
| 456 | - */ |
|
| 457 | - public function initialize() |
|
| 458 | - { |
|
| 459 | - $this->form_has_errors = EE_Error::has_error(true); |
|
| 460 | - return true; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * used for setting up css and js |
|
| 466 | - * |
|
| 467 | - * @return void |
|
| 468 | - * @throws LogicException |
|
| 469 | - * @throws EE_Error |
|
| 470 | - */ |
|
| 471 | - public function enqueueStylesAndScripts() |
|
| 472 | - { |
|
| 473 | - $this->form()->enqueue_js(); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * creates and returns the actual form |
|
| 479 | - * |
|
| 480 | - * @return EE_Form_Section_Proper |
|
| 481 | - */ |
|
| 482 | - abstract public function generate(); |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 487 | - * |
|
| 488 | - * @param string $text |
|
| 489 | - * @return EE_Submit_Input |
|
| 490 | - */ |
|
| 491 | - public function generateSubmitButton($text = '') |
|
| 492 | - { |
|
| 493 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 494 | - return new EE_Submit_Input( |
|
| 495 | - array( |
|
| 496 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 497 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 498 | - 'html_class' => 'ee-form-submit', |
|
| 499 | - 'html_label' => ' ', |
|
| 500 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 501 | - 'default' => $text, |
|
| 502 | - ) |
|
| 503 | - ); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 509 | - * |
|
| 510 | - * @param string $text |
|
| 511 | - * @return void |
|
| 512 | - * @throws EE_Error |
|
| 513 | - */ |
|
| 514 | - public function appendSubmitButton($text = '') |
|
| 515 | - { |
|
| 516 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 517 | - return; |
|
| 518 | - } |
|
| 519 | - $this->form->add_subsections( |
|
| 520 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 521 | - null, |
|
| 522 | - false |
|
| 523 | - ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 529 | - * |
|
| 530 | - * @param string $text |
|
| 531 | - * @return EE_Submit_Input |
|
| 532 | - */ |
|
| 533 | - public function generateCancelButton($text = '') |
|
| 534 | - { |
|
| 535 | - $cancel_button = new EE_Submit_Input( |
|
| 536 | - array( |
|
| 537 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 538 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 539 | - 'html_class' => 'ee-cancel-form', |
|
| 540 | - 'html_label' => ' ', |
|
| 541 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 542 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 543 | - ) |
|
| 544 | - ); |
|
| 545 | - $cancel_button->set_button_css_attributes(false); |
|
| 546 | - return $cancel_button; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * appends a float clearing div onto end of form |
|
| 552 | - * |
|
| 553 | - * @return void |
|
| 554 | - * @throws EE_Error |
|
| 555 | - */ |
|
| 556 | - public function clearFormButtonFloats() |
|
| 557 | - { |
|
| 558 | - $this->form->add_subsections( |
|
| 559 | - array( |
|
| 560 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 561 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 562 | - ), |
|
| 563 | - ), |
|
| 564 | - null, |
|
| 565 | - false |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 572 | - * returns a string of HTML that can be directly echoed in a template |
|
| 573 | - * |
|
| 574 | - * @return string |
|
| 575 | - * @throws InvalidArgumentException |
|
| 576 | - * @throws InvalidInterfaceException |
|
| 577 | - * @throws InvalidDataTypeException |
|
| 578 | - * @throws LogicException |
|
| 579 | - * @throws EE_Error |
|
| 580 | - */ |
|
| 581 | - public function display() |
|
| 582 | - { |
|
| 583 | - $form_html = apply_filters( |
|
| 584 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 585 | - '' |
|
| 586 | - ); |
|
| 587 | - $form_config = $this->formConfig(); |
|
| 588 | - if ( |
|
| 589 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 590 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 591 | - ) { |
|
| 592 | - $additional_props = $this->requiresMultipartEnctype() |
|
| 593 | - ? 'enctype="multipart/form-data"' |
|
| 594 | - : ''; |
|
| 595 | - $form_html .= $this->form()->form_open( |
|
| 596 | - $this->formAction(), |
|
| 597 | - 'POST', |
|
| 598 | - $additional_props |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - $form_html .= $this->form(true)->get_html(); |
|
| 602 | - if ( |
|
| 603 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 604 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 605 | - ) { |
|
| 606 | - $form_html .= $this->form()->form_close(); |
|
| 607 | - } |
|
| 608 | - $form_html .= apply_filters( |
|
| 609 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 610 | - '' |
|
| 611 | - ); |
|
| 612 | - return $form_html; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
| 617 | - * @since 4.9.80.p |
|
| 618 | - * @return bool |
|
| 619 | - * @throws EE_Error |
|
| 620 | - */ |
|
| 621 | - public function requiresMultipartEnctype() |
|
| 622 | - { |
|
| 623 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
| 624 | - if ($input instanceof EE_File_Input) { |
|
| 625 | - return true; |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - return false; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * handles processing the form submission |
|
| 634 | - * returns true or false depending on whether the form was processed successfully or not |
|
| 635 | - * |
|
| 636 | - * @param array $submitted_form_data |
|
| 637 | - * @return array |
|
| 638 | - * @throws InvalidArgumentException |
|
| 639 | - * @throws InvalidInterfaceException |
|
| 640 | - * @throws InvalidDataTypeException |
|
| 641 | - * @throws EE_Error |
|
| 642 | - * @throws LogicException |
|
| 643 | - * @throws InvalidFormSubmissionException |
|
| 644 | - */ |
|
| 645 | - public function process($submitted_form_data = array()) |
|
| 646 | - { |
|
| 647 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 648 | - throw new InvalidFormSubmissionException($this->form_name); |
|
| 649 | - } |
|
| 650 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 651 | - if (! $this->form()->is_valid()) { |
|
| 652 | - throw new InvalidFormSubmissionException( |
|
| 653 | - $this->form_name, |
|
| 654 | - sprintf( |
|
| 655 | - esc_html__( |
|
| 656 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 657 | - 'event_espresso' |
|
| 658 | - ), |
|
| 659 | - $this->form_name, |
|
| 660 | - '<br />', |
|
| 661 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 662 | - ) |
|
| 663 | - ); |
|
| 664 | - } |
|
| 665 | - return apply_filters( |
|
| 666 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 667 | - $this->form()->valid_data(), |
|
| 668 | - $this |
|
| 669 | - ); |
|
| 670 | - } |
|
| 32 | + /** |
|
| 33 | + * will add opening and closing HTML form tags as well as a submit button |
|
| 34 | + */ |
|
| 35 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * will add opening and closing HTML form tags but NOT a submit button |
|
| 39 | + */ |
|
| 40 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 44 | + */ |
|
| 45 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 49 | + */ |
|
| 50 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * if set to false, then this form has no displayable content, |
|
| 54 | + * and will only be used for processing data sent passed via GET or POST |
|
| 55 | + * defaults to true ( ie: form has displayable content ) |
|
| 56 | + * |
|
| 57 | + * @var boolean $displayable |
|
| 58 | + */ |
|
| 59 | + private $displayable = true; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string $form_name |
|
| 63 | + */ |
|
| 64 | + private $form_name; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var string $admin_name |
|
| 68 | + */ |
|
| 69 | + private $admin_name; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string $slug |
|
| 73 | + */ |
|
| 74 | + private $slug; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var string $submit_btn_text |
|
| 78 | + */ |
|
| 79 | + private $submit_btn_text; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var string $form_action |
|
| 83 | + */ |
|
| 84 | + private $form_action; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * form params in key value pairs |
|
| 88 | + * can be added to form action URL or as hidden inputs |
|
| 89 | + * |
|
| 90 | + * @var array $form_args |
|
| 91 | + */ |
|
| 92 | + private $form_args = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * value of one of the string constant above |
|
| 96 | + * |
|
| 97 | + * @var string $form_config |
|
| 98 | + */ |
|
| 99 | + private $form_config; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * whether or not the form was determined to be invalid |
|
| 103 | + * |
|
| 104 | + * @var boolean $form_has_errors |
|
| 105 | + */ |
|
| 106 | + private $form_has_errors; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * the absolute top level form section being used on the page |
|
| 110 | + * |
|
| 111 | + * @var EE_Form_Section_Proper $form |
|
| 112 | + */ |
|
| 113 | + private $form; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var EE_Registry $registry |
|
| 117 | + */ |
|
| 118 | + protected $registry; |
|
| 119 | + |
|
| 120 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 121 | + /** |
|
| 122 | + * Form constructor. |
|
| 123 | + * |
|
| 124 | + * @param string $form_name |
|
| 125 | + * @param string $admin_name |
|
| 126 | + * @param string $slug |
|
| 127 | + * @param string $form_action |
|
| 128 | + * @param string $form_config |
|
| 129 | + * @param EE_Registry $registry |
|
| 130 | + * @throws InvalidDataTypeException |
|
| 131 | + * @throws DomainException |
|
| 132 | + * @throws InvalidArgumentException |
|
| 133 | + */ |
|
| 134 | + public function __construct( |
|
| 135 | + $form_name, |
|
| 136 | + $admin_name, |
|
| 137 | + $slug, |
|
| 138 | + $form_action = '', |
|
| 139 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 140 | + EE_Registry $registry |
|
| 141 | + ) { |
|
| 142 | + $this->setFormName($form_name); |
|
| 143 | + $this->setAdminName($admin_name); |
|
| 144 | + $this->setSlug($slug); |
|
| 145 | + $this->setFormAction($form_action); |
|
| 146 | + $this->setFormConfig($form_config); |
|
| 147 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 148 | + $this->registry = $registry; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public static function getFormConfigConstants() |
|
| 156 | + { |
|
| 157 | + return array( |
|
| 158 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 159 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 160 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 161 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param bool $for_display |
|
| 168 | + * @return EE_Form_Section_Proper |
|
| 169 | + * @throws EE_Error |
|
| 170 | + * @throws LogicException |
|
| 171 | + */ |
|
| 172 | + public function form($for_display = false) |
|
| 173 | + { |
|
| 174 | + if (! $this->formIsValid()) { |
|
| 175 | + return null; |
|
| 176 | + } |
|
| 177 | + if ($for_display) { |
|
| 178 | + $form_config = $this->formConfig(); |
|
| 179 | + if ( |
|
| 180 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 181 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 182 | + ) { |
|
| 183 | + $this->appendSubmitButton(); |
|
| 184 | + $this->clearFormButtonFloats(); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + return $this->form; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @return boolean |
|
| 193 | + * @throws LogicException |
|
| 194 | + */ |
|
| 195 | + public function formIsValid() |
|
| 196 | + { |
|
| 197 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 198 | + return true; |
|
| 199 | + } |
|
| 200 | + $form = apply_filters( |
|
| 201 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 202 | + $this->generate(), |
|
| 203 | + $this |
|
| 204 | + ); |
|
| 205 | + if ($this->verifyForm($form)) { |
|
| 206 | + $this->setForm($form); |
|
| 207 | + } |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @param EE_Form_Section_Proper|null $form |
|
| 214 | + * @return bool |
|
| 215 | + * @throws LogicException |
|
| 216 | + */ |
|
| 217 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 218 | + { |
|
| 219 | + $form = $form !== null ? $form : $this->form; |
|
| 220 | + if ($form instanceof EE_Form_Section_Proper) { |
|
| 221 | + return true; |
|
| 222 | + } |
|
| 223 | + throw new LogicException( |
|
| 224 | + sprintf( |
|
| 225 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 226 | + $this->form_name, |
|
| 227 | + var_export($form, true) |
|
| 228 | + ) |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @param EE_Form_Section_Proper $form |
|
| 235 | + */ |
|
| 236 | + public function setForm(EE_Form_Section_Proper $form) |
|
| 237 | + { |
|
| 238 | + $this->form = $form; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return boolean |
|
| 244 | + */ |
|
| 245 | + public function displayable() |
|
| 246 | + { |
|
| 247 | + return $this->displayable; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @param boolean $displayable |
|
| 253 | + */ |
|
| 254 | + public function setDisplayable($displayable = false) |
|
| 255 | + { |
|
| 256 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * a public name for the form that can be displayed on the frontend of a site |
|
| 262 | + * |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public function formName() |
|
| 266 | + { |
|
| 267 | + return $this->form_name; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param string $form_name |
|
| 273 | + * @throws InvalidDataTypeException |
|
| 274 | + */ |
|
| 275 | + public function setFormName($form_name) |
|
| 276 | + { |
|
| 277 | + if (! is_string($form_name)) { |
|
| 278 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 279 | + } |
|
| 280 | + $this->form_name = $form_name; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * a public name for the form that can be displayed, but only in the admin |
|
| 286 | + * |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + public function adminName() |
|
| 290 | + { |
|
| 291 | + return $this->admin_name; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @param string $admin_name |
|
| 297 | + * @throws InvalidDataTypeException |
|
| 298 | + */ |
|
| 299 | + public function setAdminName($admin_name) |
|
| 300 | + { |
|
| 301 | + if (! is_string($admin_name)) { |
|
| 302 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 303 | + } |
|
| 304 | + $this->admin_name = $admin_name; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * a URL friendly string that can be used for identifying the form |
|
| 310 | + * |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | + public function slug() |
|
| 314 | + { |
|
| 315 | + return $this->slug; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @param string $slug |
|
| 321 | + * @throws InvalidDataTypeException |
|
| 322 | + */ |
|
| 323 | + public function setSlug($slug) |
|
| 324 | + { |
|
| 325 | + if (! is_string($slug)) { |
|
| 326 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 327 | + } |
|
| 328 | + $this->slug = $slug; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @return string |
|
| 334 | + */ |
|
| 335 | + public function submitBtnText() |
|
| 336 | + { |
|
| 337 | + return $this->submit_btn_text; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @param string $submit_btn_text |
|
| 343 | + * @throws InvalidDataTypeException |
|
| 344 | + * @throws InvalidArgumentException |
|
| 345 | + */ |
|
| 346 | + public function setSubmitBtnText($submit_btn_text) |
|
| 347 | + { |
|
| 348 | + if (! is_string($submit_btn_text)) { |
|
| 349 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 350 | + } |
|
| 351 | + if (empty($submit_btn_text)) { |
|
| 352 | + throw new InvalidArgumentException( |
|
| 353 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 354 | + ); |
|
| 355 | + } |
|
| 356 | + $this->submit_btn_text = $submit_btn_text; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @return string |
|
| 362 | + */ |
|
| 363 | + public function formAction() |
|
| 364 | + { |
|
| 365 | + return ! empty($this->form_args) |
|
| 366 | + ? add_query_arg($this->form_args, $this->form_action) |
|
| 367 | + : $this->form_action; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @param string $form_action |
|
| 373 | + * @throws InvalidDataTypeException |
|
| 374 | + */ |
|
| 375 | + public function setFormAction($form_action) |
|
| 376 | + { |
|
| 377 | + if (! is_string($form_action)) { |
|
| 378 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 379 | + } |
|
| 380 | + $this->form_action = $form_action; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @param array $form_args |
|
| 386 | + * @throws InvalidDataTypeException |
|
| 387 | + * @throws InvalidArgumentException |
|
| 388 | + */ |
|
| 389 | + public function addFormActionArgs($form_args = array()) |
|
| 390 | + { |
|
| 391 | + if (is_object($form_args)) { |
|
| 392 | + throw new InvalidDataTypeException( |
|
| 393 | + '$form_args', |
|
| 394 | + $form_args, |
|
| 395 | + 'anything other than an object was expected.' |
|
| 396 | + ); |
|
| 397 | + } |
|
| 398 | + if (empty($form_args)) { |
|
| 399 | + throw new InvalidArgumentException( |
|
| 400 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 401 | + ); |
|
| 402 | + } |
|
| 403 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public function formConfig() |
|
| 411 | + { |
|
| 412 | + return $this->form_config; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @param string $form_config |
|
| 418 | + * @throws DomainException |
|
| 419 | + */ |
|
| 420 | + public function setFormConfig($form_config) |
|
| 421 | + { |
|
| 422 | + if ( |
|
| 423 | + ! in_array( |
|
| 424 | + $form_config, |
|
| 425 | + array( |
|
| 426 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 427 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 428 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 429 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 430 | + ), |
|
| 431 | + true |
|
| 432 | + ) |
|
| 433 | + ) { |
|
| 434 | + throw new DomainException( |
|
| 435 | + sprintf( |
|
| 436 | + esc_html__( |
|
| 437 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
| 438 | + 'event_espresso' |
|
| 439 | + ), |
|
| 440 | + $form_config |
|
| 441 | + ) |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + $this->form_config = $form_config; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * called after the form is instantiated |
|
| 450 | + * and used for performing any logic that needs to occur early |
|
| 451 | + * before any of the other methods are called. |
|
| 452 | + * returns true if everything is ok to proceed, |
|
| 453 | + * and false if no further form logic should be implemented |
|
| 454 | + * |
|
| 455 | + * @return boolean |
|
| 456 | + */ |
|
| 457 | + public function initialize() |
|
| 458 | + { |
|
| 459 | + $this->form_has_errors = EE_Error::has_error(true); |
|
| 460 | + return true; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * used for setting up css and js |
|
| 466 | + * |
|
| 467 | + * @return void |
|
| 468 | + * @throws LogicException |
|
| 469 | + * @throws EE_Error |
|
| 470 | + */ |
|
| 471 | + public function enqueueStylesAndScripts() |
|
| 472 | + { |
|
| 473 | + $this->form()->enqueue_js(); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * creates and returns the actual form |
|
| 479 | + * |
|
| 480 | + * @return EE_Form_Section_Proper |
|
| 481 | + */ |
|
| 482 | + abstract public function generate(); |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 487 | + * |
|
| 488 | + * @param string $text |
|
| 489 | + * @return EE_Submit_Input |
|
| 490 | + */ |
|
| 491 | + public function generateSubmitButton($text = '') |
|
| 492 | + { |
|
| 493 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 494 | + return new EE_Submit_Input( |
|
| 495 | + array( |
|
| 496 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 497 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 498 | + 'html_class' => 'ee-form-submit', |
|
| 499 | + 'html_label' => ' ', |
|
| 500 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 501 | + 'default' => $text, |
|
| 502 | + ) |
|
| 503 | + ); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 509 | + * |
|
| 510 | + * @param string $text |
|
| 511 | + * @return void |
|
| 512 | + * @throws EE_Error |
|
| 513 | + */ |
|
| 514 | + public function appendSubmitButton($text = '') |
|
| 515 | + { |
|
| 516 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 517 | + return; |
|
| 518 | + } |
|
| 519 | + $this->form->add_subsections( |
|
| 520 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 521 | + null, |
|
| 522 | + false |
|
| 523 | + ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 529 | + * |
|
| 530 | + * @param string $text |
|
| 531 | + * @return EE_Submit_Input |
|
| 532 | + */ |
|
| 533 | + public function generateCancelButton($text = '') |
|
| 534 | + { |
|
| 535 | + $cancel_button = new EE_Submit_Input( |
|
| 536 | + array( |
|
| 537 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 538 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 539 | + 'html_class' => 'ee-cancel-form', |
|
| 540 | + 'html_label' => ' ', |
|
| 541 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 542 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 543 | + ) |
|
| 544 | + ); |
|
| 545 | + $cancel_button->set_button_css_attributes(false); |
|
| 546 | + return $cancel_button; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * appends a float clearing div onto end of form |
|
| 552 | + * |
|
| 553 | + * @return void |
|
| 554 | + * @throws EE_Error |
|
| 555 | + */ |
|
| 556 | + public function clearFormButtonFloats() |
|
| 557 | + { |
|
| 558 | + $this->form->add_subsections( |
|
| 559 | + array( |
|
| 560 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 561 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 562 | + ), |
|
| 563 | + ), |
|
| 564 | + null, |
|
| 565 | + false |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 572 | + * returns a string of HTML that can be directly echoed in a template |
|
| 573 | + * |
|
| 574 | + * @return string |
|
| 575 | + * @throws InvalidArgumentException |
|
| 576 | + * @throws InvalidInterfaceException |
|
| 577 | + * @throws InvalidDataTypeException |
|
| 578 | + * @throws LogicException |
|
| 579 | + * @throws EE_Error |
|
| 580 | + */ |
|
| 581 | + public function display() |
|
| 582 | + { |
|
| 583 | + $form_html = apply_filters( |
|
| 584 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 585 | + '' |
|
| 586 | + ); |
|
| 587 | + $form_config = $this->formConfig(); |
|
| 588 | + if ( |
|
| 589 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 590 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 591 | + ) { |
|
| 592 | + $additional_props = $this->requiresMultipartEnctype() |
|
| 593 | + ? 'enctype="multipart/form-data"' |
|
| 594 | + : ''; |
|
| 595 | + $form_html .= $this->form()->form_open( |
|
| 596 | + $this->formAction(), |
|
| 597 | + 'POST', |
|
| 598 | + $additional_props |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + $form_html .= $this->form(true)->get_html(); |
|
| 602 | + if ( |
|
| 603 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 604 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 605 | + ) { |
|
| 606 | + $form_html .= $this->form()->form_close(); |
|
| 607 | + } |
|
| 608 | + $form_html .= apply_filters( |
|
| 609 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 610 | + '' |
|
| 611 | + ); |
|
| 612 | + return $form_html; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
| 617 | + * @since 4.9.80.p |
|
| 618 | + * @return bool |
|
| 619 | + * @throws EE_Error |
|
| 620 | + */ |
|
| 621 | + public function requiresMultipartEnctype() |
|
| 622 | + { |
|
| 623 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
| 624 | + if ($input instanceof EE_File_Input) { |
|
| 625 | + return true; |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * handles processing the form submission |
|
| 634 | + * returns true or false depending on whether the form was processed successfully or not |
|
| 635 | + * |
|
| 636 | + * @param array $submitted_form_data |
|
| 637 | + * @return array |
|
| 638 | + * @throws InvalidArgumentException |
|
| 639 | + * @throws InvalidInterfaceException |
|
| 640 | + * @throws InvalidDataTypeException |
|
| 641 | + * @throws EE_Error |
|
| 642 | + * @throws LogicException |
|
| 643 | + * @throws InvalidFormSubmissionException |
|
| 644 | + */ |
|
| 645 | + public function process($submitted_form_data = array()) |
|
| 646 | + { |
|
| 647 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 648 | + throw new InvalidFormSubmissionException($this->form_name); |
|
| 649 | + } |
|
| 650 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 651 | + if (! $this->form()->is_valid()) { |
|
| 652 | + throw new InvalidFormSubmissionException( |
|
| 653 | + $this->form_name, |
|
| 654 | + sprintf( |
|
| 655 | + esc_html__( |
|
| 656 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 657 | + 'event_espresso' |
|
| 658 | + ), |
|
| 659 | + $this->form_name, |
|
| 660 | + '<br />', |
|
| 661 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 662 | + ) |
|
| 663 | + ); |
|
| 664 | + } |
|
| 665 | + return apply_filters( |
|
| 666 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 667 | + $this->form()->valid_data(), |
|
| 668 | + $this |
|
| 669 | + ); |
|
| 670 | + } |
|
| 671 | 671 | } |
@@ -20,1132 +20,1132 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class EE_Dependency_Map |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * This means that the requested class dependency is not present in the dependency map |
|
| 25 | - */ |
|
| 26 | - const not_registered = 0; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 30 | - */ |
|
| 31 | - const load_new_object = 1; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 36 | - */ |
|
| 37 | - const load_from_cache = 2; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * When registering a dependency, |
|
| 41 | - * this indicates to keep any existing dependencies that already exist, |
|
| 42 | - * and simply discard any new dependencies declared in the incoming data |
|
| 43 | - */ |
|
| 44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * When registering a dependency, |
|
| 48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 49 | - */ |
|
| 50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @type EE_Dependency_Map $_instance |
|
| 54 | - */ |
|
| 55 | - protected static $_instance; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var ClassInterfaceCache $class_cache |
|
| 59 | - */ |
|
| 60 | - private $class_cache; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @type RequestInterface $request |
|
| 64 | - */ |
|
| 65 | - protected $request; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @type LegacyRequestInterface $legacy_request |
|
| 69 | - */ |
|
| 70 | - protected $legacy_request; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @type ResponseInterface $response |
|
| 74 | - */ |
|
| 75 | - protected $response; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @type LoaderInterface $loader |
|
| 79 | - */ |
|
| 80 | - protected $loader; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @type array $_dependency_map |
|
| 84 | - */ |
|
| 85 | - protected $_dependency_map = []; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @type array $_class_loaders |
|
| 89 | - */ |
|
| 90 | - protected $_class_loaders = []; |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * EE_Dependency_Map constructor. |
|
| 95 | - * |
|
| 96 | - * @param ClassInterfaceCache $class_cache |
|
| 97 | - */ |
|
| 98 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
| 99 | - { |
|
| 100 | - $this->class_cache = $class_cache; |
|
| 101 | - do_action('EE_Dependency_Map____construct', $this); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return void |
|
| 107 | - * @throws InvalidAliasException |
|
| 108 | - */ |
|
| 109 | - public function initialize() |
|
| 110 | - { |
|
| 111 | - $this->_register_core_dependencies(); |
|
| 112 | - $this->_register_core_class_loaders(); |
|
| 113 | - $this->_register_core_aliases(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @singleton method used to instantiate class object |
|
| 119 | - * @param ClassInterfaceCache|null $class_cache |
|
| 120 | - * @return EE_Dependency_Map |
|
| 121 | - */ |
|
| 122 | - public static function instance(ClassInterfaceCache $class_cache = null): EE_Dependency_Map |
|
| 123 | - { |
|
| 124 | - // check if class object is instantiated, and instantiated properly |
|
| 125 | - if ( |
|
| 126 | - ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
| 127 | - && $class_cache instanceof ClassInterfaceCache |
|
| 128 | - ) { |
|
| 129 | - EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
| 130 | - } |
|
| 131 | - return EE_Dependency_Map::$_instance; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @param RequestInterface $request |
|
| 137 | - */ |
|
| 138 | - public function setRequest(RequestInterface $request) |
|
| 139 | - { |
|
| 140 | - $this->request = $request; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param LegacyRequestInterface $legacy_request |
|
| 146 | - */ |
|
| 147 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 148 | - { |
|
| 149 | - $this->legacy_request = $legacy_request; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param ResponseInterface $response |
|
| 155 | - */ |
|
| 156 | - public function setResponse(ResponseInterface $response) |
|
| 157 | - { |
|
| 158 | - $this->response = $response; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param LoaderInterface $loader |
|
| 164 | - */ |
|
| 165 | - public function setLoader(LoaderInterface $loader) |
|
| 166 | - { |
|
| 167 | - $this->loader = $loader; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param string $class |
|
| 173 | - * @param array $dependencies |
|
| 174 | - * @param int $overwrite |
|
| 175 | - * @return bool |
|
| 176 | - */ |
|
| 177 | - public static function register_dependencies( |
|
| 178 | - string $class, |
|
| 179 | - array $dependencies, |
|
| 180 | - int $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 181 | - ): bool { |
|
| 182 | - return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 188 | - * to the class specified by the first parameter. |
|
| 189 | - * IMPORTANT !!! |
|
| 190 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 191 | - * the order of the constructor parameters for the class in question. |
|
| 192 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 193 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 194 | - * |
|
| 195 | - * @param string $class |
|
| 196 | - * @param array $dependencies |
|
| 197 | - * @param int $overwrite |
|
| 198 | - * @return bool |
|
| 199 | - */ |
|
| 200 | - public function registerDependencies( |
|
| 201 | - string $class, |
|
| 202 | - array $dependencies, |
|
| 203 | - int $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 204 | - ): bool { |
|
| 205 | - $class = trim($class, '\\'); |
|
| 206 | - $registered = false; |
|
| 207 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
| 208 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
| 209 | - } |
|
| 210 | - // we need to make sure that any aliases used when registering a dependency |
|
| 211 | - // get resolved to the correct class name |
|
| 212 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 213 | - $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
| 214 | - if ( |
|
| 215 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 216 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 217 | - ) { |
|
| 218 | - unset($dependencies[ $dependency ]); |
|
| 219 | - $dependencies[ $alias ] = $load_source; |
|
| 220 | - $registered = true; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - // now add our two lists of dependencies together. |
|
| 224 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 225 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 226 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 227 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 228 | - // especially with numerically indexed arrays |
|
| 229 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
| 230 | - // now we need to ensure that the resulting dependencies |
|
| 231 | - // array only has the entries that are required for the class |
|
| 232 | - // so first count how many dependencies were originally registered for the class |
|
| 233 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
| 234 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 235 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 236 | - // then truncate the final array to match that count |
|
| 237 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 238 | - // otherwise just take the incoming array because nothing previously existed |
|
| 239 | - : $dependencies; |
|
| 240 | - return $registered; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @param string $class_name |
|
| 246 | - * @param callable|string $loader |
|
| 247 | - * @param bool $overwrite |
|
| 248 | - * @return bool |
|
| 249 | - * @throws DomainException |
|
| 250 | - */ |
|
| 251 | - public static function register_class_loader( |
|
| 252 | - string $class_name, |
|
| 253 | - $loader = 'load_core', |
|
| 254 | - bool $overwrite = false |
|
| 255 | - ): bool { |
|
| 256 | - return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader, $overwrite); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @param string $class_name |
|
| 262 | - * @param Closure|string $loader |
|
| 263 | - * @param bool $overwrite |
|
| 264 | - * @return bool |
|
| 265 | - * @throws DomainException |
|
| 266 | - */ |
|
| 267 | - public function registerClassLoader(string $class_name, $loader = 'load_core', bool $overwrite = false): bool |
|
| 268 | - { |
|
| 269 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 270 | - throw new DomainException( |
|
| 271 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 275 | - if ( |
|
| 276 | - ! is_callable($loader) |
|
| 277 | - && ( |
|
| 278 | - strpos($loader, 'load_') !== 0 |
|
| 279 | - || ! method_exists('EE_Registry', $loader) |
|
| 280 | - ) |
|
| 281 | - ) { |
|
| 282 | - throw new DomainException( |
|
| 283 | - sprintf( |
|
| 284 | - esc_html__( |
|
| 285 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 286 | - 'event_espresso' |
|
| 287 | - ), |
|
| 288 | - $loader |
|
| 289 | - ) |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
| 293 | - if ($overwrite || ! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
| 294 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 295 | - return true; |
|
| 296 | - } |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * @return array |
|
| 303 | - */ |
|
| 304 | - public function dependency_map(): array |
|
| 305 | - { |
|
| 306 | - return $this->_dependency_map; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 312 | - * |
|
| 313 | - * @param string $class_name |
|
| 314 | - * @return boolean |
|
| 315 | - */ |
|
| 316 | - public function has(string $class_name = ''): bool |
|
| 317 | - { |
|
| 318 | - // all legacy models have the same dependencies |
|
| 319 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 320 | - $class_name = 'LEGACY_MODELS'; |
|
| 321 | - } |
|
| 322 | - return isset($this->_dependency_map[ $class_name ]); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 328 | - * |
|
| 329 | - * @param string $class_name |
|
| 330 | - * @param string $dependency |
|
| 331 | - * @return bool |
|
| 332 | - */ |
|
| 333 | - public function has_dependency_for_class(string $class_name = '', string $dependency = ''): bool |
|
| 334 | - { |
|
| 335 | - // all legacy models have the same dependencies |
|
| 336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 337 | - $class_name = 'LEGACY_MODELS'; |
|
| 338 | - } |
|
| 339 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 340 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 346 | - * |
|
| 347 | - * @param string $class_name |
|
| 348 | - * @param string $dependency |
|
| 349 | - * @return int |
|
| 350 | - */ |
|
| 351 | - public function loading_strategy_for_class_dependency(string $class_name = '', string $dependency = ''): int |
|
| 352 | - { |
|
| 353 | - // all legacy models have the same dependencies |
|
| 354 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 355 | - $class_name = 'LEGACY_MODELS'; |
|
| 356 | - } |
|
| 357 | - $dependency = $this->getFqnForAlias($dependency); |
|
| 358 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 359 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 360 | - : EE_Dependency_Map::not_registered; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * @param string $class_name |
|
| 366 | - * @return string | Closure |
|
| 367 | - */ |
|
| 368 | - public function class_loader(string $class_name) |
|
| 369 | - { |
|
| 370 | - // all legacy models use load_model() |
|
| 371 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 372 | - return 'load_model'; |
|
| 373 | - } |
|
| 374 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 375 | - // perform strpos() first to avoid loading regex every time we load a class |
|
| 376 | - if ( |
|
| 377 | - strpos($class_name, 'EE_CPT_') === 0 |
|
| 378 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 379 | - ) { |
|
| 380 | - return 'load_core'; |
|
| 381 | - } |
|
| 382 | - $class_name = $this->getFqnForAlias($class_name); |
|
| 383 | - return $this->_class_loaders[ $class_name ] ?? ''; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @return array |
|
| 389 | - */ |
|
| 390 | - public function class_loaders(): array |
|
| 391 | - { |
|
| 392 | - return $this->_class_loaders; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * adds an alias for a classname |
|
| 398 | - * |
|
| 399 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 400 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 401 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 402 | - * @throws InvalidAliasException |
|
| 403 | - */ |
|
| 404 | - public function add_alias(string $fqcn, string $alias, string $for_class = '') |
|
| 405 | - { |
|
| 406 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
| 412 | - * WHY? |
|
| 413 | - * Because if a class is type hinting for a concretion, |
|
| 414 | - * then why would we need to find another class to supply it? |
|
| 415 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 416 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 417 | - * Don't go looking for some substitute. |
|
| 418 | - * Whereas if a class is type hinting for an interface... |
|
| 419 | - * then we need to find an actual class to use. |
|
| 420 | - * So the interface IS the alias for some other FQN, |
|
| 421 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 422 | - * represents some other class. |
|
| 423 | - * |
|
| 424 | - * @param string $fqn |
|
| 425 | - * @param string $for_class |
|
| 426 | - * @return bool |
|
| 427 | - */ |
|
| 428 | - public function isAlias(string $fqn = '', string $for_class = ''): bool |
|
| 429 | - { |
|
| 430 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 436 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 437 | - * for example: |
|
| 438 | - * if the following two entries were added to the _aliases array: |
|
| 439 | - * array( |
|
| 440 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 441 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 442 | - * ) |
|
| 443 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 444 | - * to load an instance of 'some\namespace\classname' |
|
| 445 | - * |
|
| 446 | - * @param string $alias |
|
| 447 | - * @param string $for_class |
|
| 448 | - * @return string |
|
| 449 | - */ |
|
| 450 | - public function getFqnForAlias(string $alias = '', string $for_class = ''): string |
|
| 451 | - { |
|
| 452 | - return $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 458 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 459 | - * This is done by using the following class constants: |
|
| 460 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 461 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 462 | - */ |
|
| 463 | - protected function _register_core_dependencies() |
|
| 464 | - { |
|
| 465 | - $this->_dependency_map = [ |
|
| 466 | - 'EE_Admin' => [ |
|
| 467 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 469 | - ], |
|
| 470 | - 'EE_Request_Handler' => [ |
|
| 471 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - 'EventEspresso\core\services\request\Response' => EE_Dependency_Map::load_from_cache, |
|
| 473 | - ], |
|
| 474 | - 'EE_System' => [ |
|
| 475 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 477 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
| 480 | - ], |
|
| 481 | - 'EE_Session' => [ |
|
| 482 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 484 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 485 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 487 | - ], |
|
| 488 | - 'EE_Cart' => [ |
|
| 489 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 490 | - ], |
|
| 491 | - 'EE_Messenger_Collection_Loader' => [ |
|
| 492 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 493 | - ], |
|
| 494 | - 'EE_Message_Type_Collection_Loader' => [ |
|
| 495 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 496 | - ], |
|
| 497 | - 'EE_Message_Resource_Manager' => [ |
|
| 498 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 499 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 500 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 501 | - ], |
|
| 502 | - 'EE_Message_Factory' => [ |
|
| 503 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - ], |
|
| 505 | - 'EE_messages' => [ |
|
| 506 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 507 | - ], |
|
| 508 | - 'EE_Messages_Generator' => [ |
|
| 509 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 510 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 511 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 512 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 513 | - ], |
|
| 514 | - 'EE_Messages_Processor' => [ |
|
| 515 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 516 | - ], |
|
| 517 | - 'EE_Messages_Queue' => [ |
|
| 518 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 519 | - ], |
|
| 520 | - 'EE_Messages_Template_Defaults' => [ |
|
| 521 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 522 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ], |
|
| 524 | - 'EE_Message_To_Generate_From_Request' => [ |
|
| 525 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 527 | - ], |
|
| 528 | - 'EventEspresso\core\services\commands\CommandBus' => [ |
|
| 529 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 530 | - ], |
|
| 531 | - 'EventEspresso\services\commands\CommandHandler' => [ |
|
| 532 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 533 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 534 | - ], |
|
| 535 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
| 536 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 537 | - ], |
|
| 538 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
| 539 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 540 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ], |
|
| 542 | - 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
| 543 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ], |
|
| 545 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
| 546 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ], |
|
| 548 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
| 549 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ], |
|
| 551 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
| 552 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ], |
|
| 554 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
| 555 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - ], |
|
| 557 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
| 558 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | - ], |
|
| 560 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
| 561 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | - ], |
|
| 563 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
| 564 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - ], |
|
| 566 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
| 567 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - ], |
|
| 569 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
| 570 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 571 | - ], |
|
| 572 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
| 573 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 574 | - ], |
|
| 575 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
| 576 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - ], |
|
| 578 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
| 579 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 580 | - ], |
|
| 581 | - 'EventEspresso\core\services\database\TableManager' => [ |
|
| 582 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | - ], |
|
| 584 | - 'EE_Data_Migration_Class_Base' => [ |
|
| 585 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 586 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 587 | - ], |
|
| 588 | - 'EE_DMS_Core_4_1_0' => [ |
|
| 589 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 590 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - ], |
|
| 592 | - 'EE_DMS_Core_4_2_0' => [ |
|
| 593 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 594 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 595 | - ], |
|
| 596 | - 'EE_DMS_Core_4_3_0' => [ |
|
| 597 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 598 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 599 | - ], |
|
| 600 | - 'EE_DMS_Core_4_4_0' => [ |
|
| 601 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 602 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - ], |
|
| 604 | - 'EE_DMS_Core_4_5_0' => [ |
|
| 605 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 606 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - ], |
|
| 608 | - 'EE_DMS_Core_4_6_0' => [ |
|
| 609 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 610 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - ], |
|
| 612 | - 'EE_DMS_Core_4_7_0' => [ |
|
| 613 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 614 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - ], |
|
| 616 | - 'EE_DMS_Core_4_8_0' => [ |
|
| 617 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 618 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 619 | - ], |
|
| 620 | - 'EE_DMS_Core_4_9_0' => [ |
|
| 621 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 622 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 623 | - ], |
|
| 624 | - 'EE_DMS_Core_4_10_0' => [ |
|
| 625 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 626 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 627 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 628 | - ], |
|
| 629 | - 'EE_DMS_Core_4_11_0' => [ |
|
| 630 | - 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
| 631 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 632 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 633 | - ], |
|
| 634 | - 'EE_DMS_Core_4_12_0' => [ |
|
| 635 | - 'EE_DMS_Core_4_11_0' => EE_Dependency_Map::load_from_cache, |
|
| 636 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 637 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 638 | - ], |
|
| 639 | - 'EventEspresso\core\services\assets\I18nRegistry' => [ |
|
| 640 | - [], |
|
| 641 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 642 | - ], |
|
| 643 | - 'EventEspresso\core\services\assets\Registry' => [ |
|
| 644 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 645 | - 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
| 646 | - ], |
|
| 647 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => [ |
|
| 648 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 649 | - ], |
|
| 650 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => [ |
|
| 651 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 652 | - ], |
|
| 653 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => [ |
|
| 654 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 655 | - ], |
|
| 656 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => [ |
|
| 657 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 658 | - ], |
|
| 659 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => [ |
|
| 660 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 661 | - ], |
|
| 662 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => [ |
|
| 663 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 664 | - ], |
|
| 665 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => [ |
|
| 666 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 667 | - ], |
|
| 668 | - 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
| 669 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 670 | - ], |
|
| 671 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
| 672 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 673 | - ], |
|
| 674 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
| 675 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 676 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 677 | - ], |
|
| 678 | - 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
| 679 | - null, |
|
| 680 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 681 | - ], |
|
| 682 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
| 683 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 684 | - ], |
|
| 685 | - 'LEGACY_MODELS' => [ |
|
| 686 | - null, |
|
| 687 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 688 | - ], |
|
| 689 | - 'EE_Module_Request_Router' => [ |
|
| 690 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 691 | - ], |
|
| 692 | - 'EE_Registration_Processor' => [ |
|
| 693 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 694 | - ], |
|
| 695 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
| 696 | - null, |
|
| 697 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 698 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 699 | - ], |
|
| 700 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
| 701 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 702 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 703 | - ], |
|
| 704 | - 'EventEspresso\modules\ticket_selector\DisplayTicketSelector' => [ |
|
| 705 | - 'EventEspresso\core\domain\entities\users\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
| 706 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 707 | - 'EE_Ticket_Selector_Config' => EE_Dependency_Map::load_from_cache, |
|
| 708 | - ], |
|
| 709 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
| 710 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 711 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 712 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 713 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 714 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 715 | - ], |
|
| 716 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
| 717 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 718 | - ], |
|
| 719 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
| 720 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 721 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 722 | - ], |
|
| 723 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
| 724 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 725 | - ], |
|
| 726 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
| 727 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 728 | - ], |
|
| 729 | - 'EE_CPT_Strategy' => [ |
|
| 730 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 731 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 732 | - ], |
|
| 733 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
| 734 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 735 | - ], |
|
| 736 | - 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
| 737 | - null, |
|
| 738 | - null, |
|
| 739 | - null, |
|
| 740 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 741 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 742 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 743 | - ], |
|
| 744 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
| 745 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 746 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 747 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 748 | - ], |
|
| 749 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
| 750 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 751 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 752 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 753 | - ], |
|
| 754 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
| 755 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 756 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 757 | - ], |
|
| 758 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
| 759 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 760 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 761 | - ], |
|
| 762 | - 'EE_URL_Validation_Strategy' => [ |
|
| 763 | - null, |
|
| 764 | - null, |
|
| 765 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
| 766 | - ], |
|
| 767 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
| 768 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 769 | - ], |
|
| 770 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 771 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 772 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 773 | - ], |
|
| 774 | - 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
| 775 | - 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
| 776 | - 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
| 777 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
| 778 | - null, |
|
| 779 | - ], |
|
| 780 | - 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
| 781 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
| 782 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 783 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 784 | - 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
| 785 | - ], |
|
| 786 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
| 787 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
| 788 | - ], |
|
| 789 | - 'EventEspresso\core\services\routing\Router' => [ |
|
| 790 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 791 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 792 | - 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
| 793 | - ], |
|
| 794 | - 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
| 795 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 796 | - ], |
|
| 797 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
| 798 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 799 | - ], |
|
| 800 | - 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
| 801 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
| 802 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 803 | - ], |
|
| 804 | - 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
| 805 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 806 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 807 | - ], |
|
| 808 | - 'EventEspresso\core\services\addon\AddonManager' => [ |
|
| 809 | - 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
| 810 | - 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
| 811 | - 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
| 812 | - 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
| 813 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
| 814 | - ], |
|
| 815 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
| 816 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 817 | - ], |
|
| 818 | - 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
| 819 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 820 | - ], |
|
| 821 | - 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
| 822 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 823 | - ], |
|
| 824 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
| 825 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 826 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 827 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 828 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 829 | - ], |
|
| 830 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
| 831 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 832 | - ], |
|
| 833 | - 'EventEspresso\core\services\request\CurrentPage' => [ |
|
| 834 | - 'EE_CPT_Strategy' => EE_Dependency_Map::load_from_cache, |
|
| 835 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 836 | - ], |
|
| 837 | - 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => [ |
|
| 838 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 839 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 840 | - ], |
|
| 841 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager' => [ |
|
| 842 | - 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => EE_Dependency_Map::load_from_cache, |
|
| 843 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 844 | - ], |
|
| 845 | - 'EventEspresso\core\domain\entities\users\CurrentUser' => [ |
|
| 846 | - 'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache, |
|
| 847 | - ], |
|
| 848 | - 'EventEspresso\core\services\form\meta\InputTypes' => [ |
|
| 849 | - 'EventEspresso\core\services\form\meta\inputs\Block' => EE_Dependency_Map::load_from_cache, |
|
| 850 | - 'EventEspresso\core\services\form\meta\inputs\Button' => EE_Dependency_Map::load_from_cache, |
|
| 851 | - 'EventEspresso\core\services\form\meta\inputs\DateTime' => EE_Dependency_Map::load_from_cache, |
|
| 852 | - 'EventEspresso\core\services\form\meta\inputs\Input' => EE_Dependency_Map::load_from_cache, |
|
| 853 | - 'EventEspresso\core\services\form\meta\inputs\Number' => EE_Dependency_Map::load_from_cache, |
|
| 854 | - 'EventEspresso\core\services\form\meta\inputs\Phone' => EE_Dependency_Map::load_from_cache, |
|
| 855 | - 'EventEspresso\core\services\form\meta\inputs\Select' => EE_Dependency_Map::load_from_cache, |
|
| 856 | - 'EventEspresso\core\services\form\meta\inputs\Text' => EE_Dependency_Map::load_from_cache, |
|
| 857 | - ], |
|
| 858 | - 'EventEspresso\core\domain\services\registration\form\v1\RegFormDependencyHandler' => [ |
|
| 859 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 860 | - ], |
|
| 861 | - 'EventEspresso\core\services\calculators\LineItemCalculator' => [ |
|
| 862 | - 'EventEspresso\core\services\helpers\DecimalValues' => EE_Dependency_Map::load_from_cache, |
|
| 863 | - ], |
|
| 864 | - 'EventEspresso\core\services\helpers\DecimalValues' => [ |
|
| 865 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 866 | - ], |
|
| 867 | - ]; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * Registers how core classes are loaded. |
|
| 873 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 874 | - * 'EE_Request_Handler' => 'load_core' |
|
| 875 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 876 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 877 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 878 | - * 'Some_Class' => function () { |
|
| 879 | - * return new Some_Class(); |
|
| 880 | - * }, |
|
| 881 | - * This is required for instantiating dependencies |
|
| 882 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 883 | - * 'Required_Interface' => function () { |
|
| 884 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 885 | - * }, |
|
| 886 | - */ |
|
| 887 | - protected function _register_core_class_loaders() |
|
| 888 | - { |
|
| 889 | - $this->_class_loaders = [ |
|
| 890 | - // load_core |
|
| 891 | - 'EE_Dependency_Map' => function () { |
|
| 892 | - return $this; |
|
| 893 | - }, |
|
| 894 | - 'EE_Capabilities' => 'load_core', |
|
| 895 | - 'EE_Encryption' => 'load_core', |
|
| 896 | - 'EE_Front_Controller' => 'load_core', |
|
| 897 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 898 | - 'EE_Registry' => 'load_core', |
|
| 899 | - 'EE_Request' => function () { |
|
| 900 | - return $this->legacy_request; |
|
| 901 | - }, |
|
| 902 | - 'EventEspresso\core\services\request\Request' => function () { |
|
| 903 | - return $this->request; |
|
| 904 | - }, |
|
| 905 | - 'EventEspresso\core\services\request\Response' => function () { |
|
| 906 | - return $this->response; |
|
| 907 | - }, |
|
| 908 | - 'EE_Base' => 'load_core', |
|
| 909 | - 'EE_Request_Handler' => 'load_core', |
|
| 910 | - 'EE_Session' => 'load_core', |
|
| 911 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 912 | - 'EE_System' => 'load_core', |
|
| 913 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 914 | - 'EE_Register_CPTs' => 'load_core', |
|
| 915 | - 'EE_Admin' => 'load_core', |
|
| 916 | - 'EE_CPT_Strategy' => 'load_core', |
|
| 917 | - // load_class |
|
| 918 | - 'EE_Registration_Processor' => 'load_class', |
|
| 919 | - // load_lib |
|
| 920 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 921 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 922 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 923 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 924 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 925 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 926 | - 'EE_Message_Repository' => 'load_lib', |
|
| 927 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 928 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 929 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 930 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 931 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 932 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 933 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 934 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 935 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 936 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 937 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 938 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 939 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 940 | - 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
| 941 | - 'EE_DMS_Core_4_12_0' => 'load_dms', |
|
| 942 | - 'EE_Messages_Generator' => static function () { |
|
| 943 | - return EE_Registry::instance()->load_lib( |
|
| 944 | - 'Messages_Generator', |
|
| 945 | - [], |
|
| 946 | - false, |
|
| 947 | - false |
|
| 948 | - ); |
|
| 949 | - }, |
|
| 950 | - 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
| 951 | - return EE_Registry::instance()->load_lib( |
|
| 952 | - 'Messages_Template_Defaults', |
|
| 953 | - $arguments, |
|
| 954 | - false, |
|
| 955 | - false |
|
| 956 | - ); |
|
| 957 | - }, |
|
| 958 | - // load_helper |
|
| 959 | - 'EEH_Parse_Shortcodes' => static function () { |
|
| 960 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 961 | - return new EEH_Parse_Shortcodes(); |
|
| 962 | - } |
|
| 963 | - return null; |
|
| 964 | - }, |
|
| 965 | - 'EE_Template_Config' => static function () { |
|
| 966 | - return EE_Config::instance()->template_settings; |
|
| 967 | - }, |
|
| 968 | - 'EE_Currency_Config' => static function () { |
|
| 969 | - return EE_Currency_Config::getCurrencyConfig(); |
|
| 970 | - }, |
|
| 971 | - 'EE_Registration_Config' => static function () { |
|
| 972 | - return EE_Config::instance()->registration; |
|
| 973 | - }, |
|
| 974 | - 'EE_Core_Config' => static function () { |
|
| 975 | - return EE_Config::instance()->core; |
|
| 976 | - }, |
|
| 977 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
| 978 | - return LoaderFactory::getLoader(); |
|
| 979 | - }, |
|
| 980 | - 'EE_Network_Config' => static function () { |
|
| 981 | - return EE_Network_Config::instance(); |
|
| 982 | - }, |
|
| 983 | - 'EE_Config' => static function () { |
|
| 984 | - return EE_Config::instance(); |
|
| 985 | - }, |
|
| 986 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
| 987 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
| 988 | - }, |
|
| 989 | - 'EE_Admin_Config' => static function () { |
|
| 990 | - return EE_Config::instance()->admin; |
|
| 991 | - }, |
|
| 992 | - 'EE_Organization_Config' => static function () { |
|
| 993 | - return EE_Config::instance()->organization; |
|
| 994 | - }, |
|
| 995 | - 'EE_Network_Core_Config' => static function () { |
|
| 996 | - return EE_Network_Config::instance()->core; |
|
| 997 | - }, |
|
| 998 | - 'EE_Environment_Config' => static function () { |
|
| 999 | - return EE_Config::instance()->environment; |
|
| 1000 | - }, |
|
| 1001 | - 'EED_Core_Rest_Api' => static function () { |
|
| 1002 | - return EED_Core_Rest_Api::instance(); |
|
| 1003 | - }, |
|
| 1004 | - 'WP_REST_Server' => static function () { |
|
| 1005 | - return rest_get_server(); |
|
| 1006 | - }, |
|
| 1007 | - 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
| 1008 | - return EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 1009 | - }, |
|
| 1010 | - 'EE_Ticket_Selector_Config' => function () { |
|
| 1011 | - return EE_Config::instance()->template_settings->EED_Ticket_Selector; |
|
| 1012 | - }, |
|
| 1013 | - ]; |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - /** |
|
| 1018 | - * can be used for supplying alternate names for classes, |
|
| 1019 | - * or for connecting interface names to instantiable classes |
|
| 1020 | - * |
|
| 1021 | - * @throws InvalidAliasException |
|
| 1022 | - */ |
|
| 1023 | - protected function _register_core_aliases() |
|
| 1024 | - { |
|
| 1025 | - $aliases = [ |
|
| 1026 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 1027 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 1028 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 1029 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 1030 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 1031 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 1032 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1033 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 1034 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1035 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 1036 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1037 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 1038 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 1039 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 1040 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 1041 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 1042 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 1043 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 1044 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 1045 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 1046 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1047 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 1048 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1049 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 1050 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 1051 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 1052 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 1053 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 1054 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 1055 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 1056 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 1057 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 1058 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 1059 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 1060 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 1061 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 1062 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 1063 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 1064 | - 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
| 1065 | - ]; |
|
| 1066 | - foreach ($aliases as $alias => $fqn) { |
|
| 1067 | - if (is_array($fqn)) { |
|
| 1068 | - foreach ($fqn as $class => $for_class) { |
|
| 1069 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 1070 | - } |
|
| 1071 | - continue; |
|
| 1072 | - } |
|
| 1073 | - $this->class_cache->addAlias($fqn, $alias); |
|
| 1074 | - } |
|
| 1075 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1076 | - $this->class_cache->addAlias( |
|
| 1077 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 1078 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 1079 | - ); |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - public function debug($for_class = '') |
|
| 1085 | - { |
|
| 1086 | - if (method_exists($this->class_cache, 'debug')) { |
|
| 1087 | - $this->class_cache->debug($for_class); |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - |
|
| 1092 | - /** |
|
| 1093 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 1094 | - * request Primarily used by unit tests. |
|
| 1095 | - */ |
|
| 1096 | - public function reset() |
|
| 1097 | - { |
|
| 1098 | - $this->_register_core_class_loaders(); |
|
| 1099 | - $this->_register_core_dependencies(); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - /** |
|
| 1104 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
| 1105 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 1106 | - * WHY? |
|
| 1107 | - * Because if a class is type hinting for a concretion, |
|
| 1108 | - * then why would we need to find another class to supply it? |
|
| 1109 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1110 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1111 | - * Don't go looking for some substitute. |
|
| 1112 | - * Whereas if a class is type hinting for an interface... |
|
| 1113 | - * then we need to find an actual class to use. |
|
| 1114 | - * So the interface IS the alias for some other FQN, |
|
| 1115 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1116 | - * represents some other class. |
|
| 1117 | - * |
|
| 1118 | - * @param string $fqn |
|
| 1119 | - * @param string $for_class |
|
| 1120 | - * @return bool |
|
| 1121 | - * @deprecated 4.9.62.p |
|
| 1122 | - */ |
|
| 1123 | - public function has_alias(string $fqn = '', string $for_class = ''): bool |
|
| 1124 | - { |
|
| 1125 | - return $this->isAlias($fqn, $for_class); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1131 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1132 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1133 | - * for example: |
|
| 1134 | - * if the following two entries were added to the _aliases array: |
|
| 1135 | - * array( |
|
| 1136 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 1137 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1138 | - * ) |
|
| 1139 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1140 | - * to load an instance of 'some\namespace\classname' |
|
| 1141 | - * |
|
| 1142 | - * @param string $alias |
|
| 1143 | - * @param string $for_class |
|
| 1144 | - * @return string |
|
| 1145 | - * @deprecated 4.9.62.p |
|
| 1146 | - */ |
|
| 1147 | - public function get_alias(string $alias = '', string $for_class = ''): string |
|
| 1148 | - { |
|
| 1149 | - return $this->getFqnForAlias($alias, $for_class); |
|
| 1150 | - } |
|
| 23 | + /** |
|
| 24 | + * This means that the requested class dependency is not present in the dependency map |
|
| 25 | + */ |
|
| 26 | + const not_registered = 0; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 30 | + */ |
|
| 31 | + const load_new_object = 1; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 36 | + */ |
|
| 37 | + const load_from_cache = 2; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * When registering a dependency, |
|
| 41 | + * this indicates to keep any existing dependencies that already exist, |
|
| 42 | + * and simply discard any new dependencies declared in the incoming data |
|
| 43 | + */ |
|
| 44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * When registering a dependency, |
|
| 48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 49 | + */ |
|
| 50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @type EE_Dependency_Map $_instance |
|
| 54 | + */ |
|
| 55 | + protected static $_instance; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var ClassInterfaceCache $class_cache |
|
| 59 | + */ |
|
| 60 | + private $class_cache; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @type RequestInterface $request |
|
| 64 | + */ |
|
| 65 | + protected $request; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @type LegacyRequestInterface $legacy_request |
|
| 69 | + */ |
|
| 70 | + protected $legacy_request; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @type ResponseInterface $response |
|
| 74 | + */ |
|
| 75 | + protected $response; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @type LoaderInterface $loader |
|
| 79 | + */ |
|
| 80 | + protected $loader; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @type array $_dependency_map |
|
| 84 | + */ |
|
| 85 | + protected $_dependency_map = []; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @type array $_class_loaders |
|
| 89 | + */ |
|
| 90 | + protected $_class_loaders = []; |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * EE_Dependency_Map constructor. |
|
| 95 | + * |
|
| 96 | + * @param ClassInterfaceCache $class_cache |
|
| 97 | + */ |
|
| 98 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
| 99 | + { |
|
| 100 | + $this->class_cache = $class_cache; |
|
| 101 | + do_action('EE_Dependency_Map____construct', $this); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return void |
|
| 107 | + * @throws InvalidAliasException |
|
| 108 | + */ |
|
| 109 | + public function initialize() |
|
| 110 | + { |
|
| 111 | + $this->_register_core_dependencies(); |
|
| 112 | + $this->_register_core_class_loaders(); |
|
| 113 | + $this->_register_core_aliases(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @singleton method used to instantiate class object |
|
| 119 | + * @param ClassInterfaceCache|null $class_cache |
|
| 120 | + * @return EE_Dependency_Map |
|
| 121 | + */ |
|
| 122 | + public static function instance(ClassInterfaceCache $class_cache = null): EE_Dependency_Map |
|
| 123 | + { |
|
| 124 | + // check if class object is instantiated, and instantiated properly |
|
| 125 | + if ( |
|
| 126 | + ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
| 127 | + && $class_cache instanceof ClassInterfaceCache |
|
| 128 | + ) { |
|
| 129 | + EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
| 130 | + } |
|
| 131 | + return EE_Dependency_Map::$_instance; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @param RequestInterface $request |
|
| 137 | + */ |
|
| 138 | + public function setRequest(RequestInterface $request) |
|
| 139 | + { |
|
| 140 | + $this->request = $request; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param LegacyRequestInterface $legacy_request |
|
| 146 | + */ |
|
| 147 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 148 | + { |
|
| 149 | + $this->legacy_request = $legacy_request; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param ResponseInterface $response |
|
| 155 | + */ |
|
| 156 | + public function setResponse(ResponseInterface $response) |
|
| 157 | + { |
|
| 158 | + $this->response = $response; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param LoaderInterface $loader |
|
| 164 | + */ |
|
| 165 | + public function setLoader(LoaderInterface $loader) |
|
| 166 | + { |
|
| 167 | + $this->loader = $loader; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param string $class |
|
| 173 | + * @param array $dependencies |
|
| 174 | + * @param int $overwrite |
|
| 175 | + * @return bool |
|
| 176 | + */ |
|
| 177 | + public static function register_dependencies( |
|
| 178 | + string $class, |
|
| 179 | + array $dependencies, |
|
| 180 | + int $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 181 | + ): bool { |
|
| 182 | + return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 188 | + * to the class specified by the first parameter. |
|
| 189 | + * IMPORTANT !!! |
|
| 190 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 191 | + * the order of the constructor parameters for the class in question. |
|
| 192 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 193 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 194 | + * |
|
| 195 | + * @param string $class |
|
| 196 | + * @param array $dependencies |
|
| 197 | + * @param int $overwrite |
|
| 198 | + * @return bool |
|
| 199 | + */ |
|
| 200 | + public function registerDependencies( |
|
| 201 | + string $class, |
|
| 202 | + array $dependencies, |
|
| 203 | + int $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 204 | + ): bool { |
|
| 205 | + $class = trim($class, '\\'); |
|
| 206 | + $registered = false; |
|
| 207 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
| 208 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
| 209 | + } |
|
| 210 | + // we need to make sure that any aliases used when registering a dependency |
|
| 211 | + // get resolved to the correct class name |
|
| 212 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 213 | + $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
| 214 | + if ( |
|
| 215 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 216 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 217 | + ) { |
|
| 218 | + unset($dependencies[ $dependency ]); |
|
| 219 | + $dependencies[ $alias ] = $load_source; |
|
| 220 | + $registered = true; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + // now add our two lists of dependencies together. |
|
| 224 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 225 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 226 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 227 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 228 | + // especially with numerically indexed arrays |
|
| 229 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
| 230 | + // now we need to ensure that the resulting dependencies |
|
| 231 | + // array only has the entries that are required for the class |
|
| 232 | + // so first count how many dependencies were originally registered for the class |
|
| 233 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
| 234 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 235 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 236 | + // then truncate the final array to match that count |
|
| 237 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 238 | + // otherwise just take the incoming array because nothing previously existed |
|
| 239 | + : $dependencies; |
|
| 240 | + return $registered; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param string $class_name |
|
| 246 | + * @param callable|string $loader |
|
| 247 | + * @param bool $overwrite |
|
| 248 | + * @return bool |
|
| 249 | + * @throws DomainException |
|
| 250 | + */ |
|
| 251 | + public static function register_class_loader( |
|
| 252 | + string $class_name, |
|
| 253 | + $loader = 'load_core', |
|
| 254 | + bool $overwrite = false |
|
| 255 | + ): bool { |
|
| 256 | + return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader, $overwrite); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @param string $class_name |
|
| 262 | + * @param Closure|string $loader |
|
| 263 | + * @param bool $overwrite |
|
| 264 | + * @return bool |
|
| 265 | + * @throws DomainException |
|
| 266 | + */ |
|
| 267 | + public function registerClassLoader(string $class_name, $loader = 'load_core', bool $overwrite = false): bool |
|
| 268 | + { |
|
| 269 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 270 | + throw new DomainException( |
|
| 271 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 275 | + if ( |
|
| 276 | + ! is_callable($loader) |
|
| 277 | + && ( |
|
| 278 | + strpos($loader, 'load_') !== 0 |
|
| 279 | + || ! method_exists('EE_Registry', $loader) |
|
| 280 | + ) |
|
| 281 | + ) { |
|
| 282 | + throw new DomainException( |
|
| 283 | + sprintf( |
|
| 284 | + esc_html__( |
|
| 285 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 286 | + 'event_espresso' |
|
| 287 | + ), |
|
| 288 | + $loader |
|
| 289 | + ) |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
| 293 | + if ($overwrite || ! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
| 294 | + EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 295 | + return true; |
|
| 296 | + } |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * @return array |
|
| 303 | + */ |
|
| 304 | + public function dependency_map(): array |
|
| 305 | + { |
|
| 306 | + return $this->_dependency_map; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 312 | + * |
|
| 313 | + * @param string $class_name |
|
| 314 | + * @return boolean |
|
| 315 | + */ |
|
| 316 | + public function has(string $class_name = ''): bool |
|
| 317 | + { |
|
| 318 | + // all legacy models have the same dependencies |
|
| 319 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 320 | + $class_name = 'LEGACY_MODELS'; |
|
| 321 | + } |
|
| 322 | + return isset($this->_dependency_map[ $class_name ]); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 328 | + * |
|
| 329 | + * @param string $class_name |
|
| 330 | + * @param string $dependency |
|
| 331 | + * @return bool |
|
| 332 | + */ |
|
| 333 | + public function has_dependency_for_class(string $class_name = '', string $dependency = ''): bool |
|
| 334 | + { |
|
| 335 | + // all legacy models have the same dependencies |
|
| 336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 337 | + $class_name = 'LEGACY_MODELS'; |
|
| 338 | + } |
|
| 339 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 340 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 346 | + * |
|
| 347 | + * @param string $class_name |
|
| 348 | + * @param string $dependency |
|
| 349 | + * @return int |
|
| 350 | + */ |
|
| 351 | + public function loading_strategy_for_class_dependency(string $class_name = '', string $dependency = ''): int |
|
| 352 | + { |
|
| 353 | + // all legacy models have the same dependencies |
|
| 354 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 355 | + $class_name = 'LEGACY_MODELS'; |
|
| 356 | + } |
|
| 357 | + $dependency = $this->getFqnForAlias($dependency); |
|
| 358 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 359 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 360 | + : EE_Dependency_Map::not_registered; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * @param string $class_name |
|
| 366 | + * @return string | Closure |
|
| 367 | + */ |
|
| 368 | + public function class_loader(string $class_name) |
|
| 369 | + { |
|
| 370 | + // all legacy models use load_model() |
|
| 371 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 372 | + return 'load_model'; |
|
| 373 | + } |
|
| 374 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 375 | + // perform strpos() first to avoid loading regex every time we load a class |
|
| 376 | + if ( |
|
| 377 | + strpos($class_name, 'EE_CPT_') === 0 |
|
| 378 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 379 | + ) { |
|
| 380 | + return 'load_core'; |
|
| 381 | + } |
|
| 382 | + $class_name = $this->getFqnForAlias($class_name); |
|
| 383 | + return $this->_class_loaders[ $class_name ] ?? ''; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @return array |
|
| 389 | + */ |
|
| 390 | + public function class_loaders(): array |
|
| 391 | + { |
|
| 392 | + return $this->_class_loaders; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * adds an alias for a classname |
|
| 398 | + * |
|
| 399 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 400 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 401 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 402 | + * @throws InvalidAliasException |
|
| 403 | + */ |
|
| 404 | + public function add_alias(string $fqcn, string $alias, string $for_class = '') |
|
| 405 | + { |
|
| 406 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
| 412 | + * WHY? |
|
| 413 | + * Because if a class is type hinting for a concretion, |
|
| 414 | + * then why would we need to find another class to supply it? |
|
| 415 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 416 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 417 | + * Don't go looking for some substitute. |
|
| 418 | + * Whereas if a class is type hinting for an interface... |
|
| 419 | + * then we need to find an actual class to use. |
|
| 420 | + * So the interface IS the alias for some other FQN, |
|
| 421 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 422 | + * represents some other class. |
|
| 423 | + * |
|
| 424 | + * @param string $fqn |
|
| 425 | + * @param string $for_class |
|
| 426 | + * @return bool |
|
| 427 | + */ |
|
| 428 | + public function isAlias(string $fqn = '', string $for_class = ''): bool |
|
| 429 | + { |
|
| 430 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 436 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 437 | + * for example: |
|
| 438 | + * if the following two entries were added to the _aliases array: |
|
| 439 | + * array( |
|
| 440 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 441 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 442 | + * ) |
|
| 443 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 444 | + * to load an instance of 'some\namespace\classname' |
|
| 445 | + * |
|
| 446 | + * @param string $alias |
|
| 447 | + * @param string $for_class |
|
| 448 | + * @return string |
|
| 449 | + */ |
|
| 450 | + public function getFqnForAlias(string $alias = '', string $for_class = ''): string |
|
| 451 | + { |
|
| 452 | + return $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 458 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 459 | + * This is done by using the following class constants: |
|
| 460 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 461 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 462 | + */ |
|
| 463 | + protected function _register_core_dependencies() |
|
| 464 | + { |
|
| 465 | + $this->_dependency_map = [ |
|
| 466 | + 'EE_Admin' => [ |
|
| 467 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 469 | + ], |
|
| 470 | + 'EE_Request_Handler' => [ |
|
| 471 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + 'EventEspresso\core\services\request\Response' => EE_Dependency_Map::load_from_cache, |
|
| 473 | + ], |
|
| 474 | + 'EE_System' => [ |
|
| 475 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 477 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
| 480 | + ], |
|
| 481 | + 'EE_Session' => [ |
|
| 482 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 484 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 485 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 487 | + ], |
|
| 488 | + 'EE_Cart' => [ |
|
| 489 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 490 | + ], |
|
| 491 | + 'EE_Messenger_Collection_Loader' => [ |
|
| 492 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 493 | + ], |
|
| 494 | + 'EE_Message_Type_Collection_Loader' => [ |
|
| 495 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 496 | + ], |
|
| 497 | + 'EE_Message_Resource_Manager' => [ |
|
| 498 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 499 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 500 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 501 | + ], |
|
| 502 | + 'EE_Message_Factory' => [ |
|
| 503 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + ], |
|
| 505 | + 'EE_messages' => [ |
|
| 506 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 507 | + ], |
|
| 508 | + 'EE_Messages_Generator' => [ |
|
| 509 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 510 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 511 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 512 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 513 | + ], |
|
| 514 | + 'EE_Messages_Processor' => [ |
|
| 515 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 516 | + ], |
|
| 517 | + 'EE_Messages_Queue' => [ |
|
| 518 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 519 | + ], |
|
| 520 | + 'EE_Messages_Template_Defaults' => [ |
|
| 521 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 522 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ], |
|
| 524 | + 'EE_Message_To_Generate_From_Request' => [ |
|
| 525 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 527 | + ], |
|
| 528 | + 'EventEspresso\core\services\commands\CommandBus' => [ |
|
| 529 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 530 | + ], |
|
| 531 | + 'EventEspresso\services\commands\CommandHandler' => [ |
|
| 532 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 533 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 534 | + ], |
|
| 535 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
| 536 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 537 | + ], |
|
| 538 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
| 539 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 540 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ], |
|
| 542 | + 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
| 543 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ], |
|
| 545 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
| 546 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ], |
|
| 548 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
| 549 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ], |
|
| 551 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
| 552 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ], |
|
| 554 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
| 555 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + ], |
|
| 557 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
| 558 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | + ], |
|
| 560 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
| 561 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | + ], |
|
| 563 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
| 564 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + ], |
|
| 566 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
| 567 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + ], |
|
| 569 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
| 570 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 571 | + ], |
|
| 572 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
| 573 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 574 | + ], |
|
| 575 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
| 576 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + ], |
|
| 578 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
| 579 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 580 | + ], |
|
| 581 | + 'EventEspresso\core\services\database\TableManager' => [ |
|
| 582 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 583 | + ], |
|
| 584 | + 'EE_Data_Migration_Class_Base' => [ |
|
| 585 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 586 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 587 | + ], |
|
| 588 | + 'EE_DMS_Core_4_1_0' => [ |
|
| 589 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 590 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + ], |
|
| 592 | + 'EE_DMS_Core_4_2_0' => [ |
|
| 593 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 594 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 595 | + ], |
|
| 596 | + 'EE_DMS_Core_4_3_0' => [ |
|
| 597 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 598 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 599 | + ], |
|
| 600 | + 'EE_DMS_Core_4_4_0' => [ |
|
| 601 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 602 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + ], |
|
| 604 | + 'EE_DMS_Core_4_5_0' => [ |
|
| 605 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 606 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + ], |
|
| 608 | + 'EE_DMS_Core_4_6_0' => [ |
|
| 609 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 610 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + ], |
|
| 612 | + 'EE_DMS_Core_4_7_0' => [ |
|
| 613 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 614 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + ], |
|
| 616 | + 'EE_DMS_Core_4_8_0' => [ |
|
| 617 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 618 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 619 | + ], |
|
| 620 | + 'EE_DMS_Core_4_9_0' => [ |
|
| 621 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 622 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 623 | + ], |
|
| 624 | + 'EE_DMS_Core_4_10_0' => [ |
|
| 625 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 626 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 627 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 628 | + ], |
|
| 629 | + 'EE_DMS_Core_4_11_0' => [ |
|
| 630 | + 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
| 631 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 632 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 633 | + ], |
|
| 634 | + 'EE_DMS_Core_4_12_0' => [ |
|
| 635 | + 'EE_DMS_Core_4_11_0' => EE_Dependency_Map::load_from_cache, |
|
| 636 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 637 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 638 | + ], |
|
| 639 | + 'EventEspresso\core\services\assets\I18nRegistry' => [ |
|
| 640 | + [], |
|
| 641 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 642 | + ], |
|
| 643 | + 'EventEspresso\core\services\assets\Registry' => [ |
|
| 644 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 645 | + 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
| 646 | + ], |
|
| 647 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => [ |
|
| 648 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 649 | + ], |
|
| 650 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => [ |
|
| 651 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 652 | + ], |
|
| 653 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => [ |
|
| 654 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 655 | + ], |
|
| 656 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => [ |
|
| 657 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 658 | + ], |
|
| 659 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => [ |
|
| 660 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 661 | + ], |
|
| 662 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => [ |
|
| 663 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 664 | + ], |
|
| 665 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => [ |
|
| 666 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 667 | + ], |
|
| 668 | + 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
| 669 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 670 | + ], |
|
| 671 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
| 672 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 673 | + ], |
|
| 674 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
| 675 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 676 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 677 | + ], |
|
| 678 | + 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
| 679 | + null, |
|
| 680 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 681 | + ], |
|
| 682 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
| 683 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 684 | + ], |
|
| 685 | + 'LEGACY_MODELS' => [ |
|
| 686 | + null, |
|
| 687 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 688 | + ], |
|
| 689 | + 'EE_Module_Request_Router' => [ |
|
| 690 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 691 | + ], |
|
| 692 | + 'EE_Registration_Processor' => [ |
|
| 693 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 694 | + ], |
|
| 695 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
| 696 | + null, |
|
| 697 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 698 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 699 | + ], |
|
| 700 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
| 701 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 702 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 703 | + ], |
|
| 704 | + 'EventEspresso\modules\ticket_selector\DisplayTicketSelector' => [ |
|
| 705 | + 'EventEspresso\core\domain\entities\users\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
| 706 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 707 | + 'EE_Ticket_Selector_Config' => EE_Dependency_Map::load_from_cache, |
|
| 708 | + ], |
|
| 709 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
| 710 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 711 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 712 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 713 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 714 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 715 | + ], |
|
| 716 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
| 717 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 718 | + ], |
|
| 719 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
| 720 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 721 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 722 | + ], |
|
| 723 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
| 724 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 725 | + ], |
|
| 726 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
| 727 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 728 | + ], |
|
| 729 | + 'EE_CPT_Strategy' => [ |
|
| 730 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 731 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 732 | + ], |
|
| 733 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
| 734 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 735 | + ], |
|
| 736 | + 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
| 737 | + null, |
|
| 738 | + null, |
|
| 739 | + null, |
|
| 740 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 741 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 742 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 743 | + ], |
|
| 744 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
| 745 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 746 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 747 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 748 | + ], |
|
| 749 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
| 750 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 751 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 752 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 753 | + ], |
|
| 754 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
| 755 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 756 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 757 | + ], |
|
| 758 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
| 759 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 760 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 761 | + ], |
|
| 762 | + 'EE_URL_Validation_Strategy' => [ |
|
| 763 | + null, |
|
| 764 | + null, |
|
| 765 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
| 766 | + ], |
|
| 767 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
| 768 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 769 | + ], |
|
| 770 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 771 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 772 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 773 | + ], |
|
| 774 | + 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
| 775 | + 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
| 776 | + 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
| 777 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
| 778 | + null, |
|
| 779 | + ], |
|
| 780 | + 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
| 781 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
| 782 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 783 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 784 | + 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
| 785 | + ], |
|
| 786 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
| 787 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
| 788 | + ], |
|
| 789 | + 'EventEspresso\core\services\routing\Router' => [ |
|
| 790 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 791 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 792 | + 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
| 793 | + ], |
|
| 794 | + 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
| 795 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 796 | + ], |
|
| 797 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
| 798 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 799 | + ], |
|
| 800 | + 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
| 801 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
| 802 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 803 | + ], |
|
| 804 | + 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
| 805 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 806 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 807 | + ], |
|
| 808 | + 'EventEspresso\core\services\addon\AddonManager' => [ |
|
| 809 | + 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
| 810 | + 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
| 811 | + 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
| 812 | + 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
| 813 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
| 814 | + ], |
|
| 815 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
| 816 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 817 | + ], |
|
| 818 | + 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
| 819 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 820 | + ], |
|
| 821 | + 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
| 822 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 823 | + ], |
|
| 824 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
| 825 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 826 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 827 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 828 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 829 | + ], |
|
| 830 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
| 831 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 832 | + ], |
|
| 833 | + 'EventEspresso\core\services\request\CurrentPage' => [ |
|
| 834 | + 'EE_CPT_Strategy' => EE_Dependency_Map::load_from_cache, |
|
| 835 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 836 | + ], |
|
| 837 | + 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => [ |
|
| 838 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 839 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 840 | + ], |
|
| 841 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager' => [ |
|
| 842 | + 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => EE_Dependency_Map::load_from_cache, |
|
| 843 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 844 | + ], |
|
| 845 | + 'EventEspresso\core\domain\entities\users\CurrentUser' => [ |
|
| 846 | + 'EventEspresso\core\domain\entities\users\EventManagers' => EE_Dependency_Map::load_from_cache, |
|
| 847 | + ], |
|
| 848 | + 'EventEspresso\core\services\form\meta\InputTypes' => [ |
|
| 849 | + 'EventEspresso\core\services\form\meta\inputs\Block' => EE_Dependency_Map::load_from_cache, |
|
| 850 | + 'EventEspresso\core\services\form\meta\inputs\Button' => EE_Dependency_Map::load_from_cache, |
|
| 851 | + 'EventEspresso\core\services\form\meta\inputs\DateTime' => EE_Dependency_Map::load_from_cache, |
|
| 852 | + 'EventEspresso\core\services\form\meta\inputs\Input' => EE_Dependency_Map::load_from_cache, |
|
| 853 | + 'EventEspresso\core\services\form\meta\inputs\Number' => EE_Dependency_Map::load_from_cache, |
|
| 854 | + 'EventEspresso\core\services\form\meta\inputs\Phone' => EE_Dependency_Map::load_from_cache, |
|
| 855 | + 'EventEspresso\core\services\form\meta\inputs\Select' => EE_Dependency_Map::load_from_cache, |
|
| 856 | + 'EventEspresso\core\services\form\meta\inputs\Text' => EE_Dependency_Map::load_from_cache, |
|
| 857 | + ], |
|
| 858 | + 'EventEspresso\core\domain\services\registration\form\v1\RegFormDependencyHandler' => [ |
|
| 859 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 860 | + ], |
|
| 861 | + 'EventEspresso\core\services\calculators\LineItemCalculator' => [ |
|
| 862 | + 'EventEspresso\core\services\helpers\DecimalValues' => EE_Dependency_Map::load_from_cache, |
|
| 863 | + ], |
|
| 864 | + 'EventEspresso\core\services\helpers\DecimalValues' => [ |
|
| 865 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 866 | + ], |
|
| 867 | + ]; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * Registers how core classes are loaded. |
|
| 873 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 874 | + * 'EE_Request_Handler' => 'load_core' |
|
| 875 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 876 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 877 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 878 | + * 'Some_Class' => function () { |
|
| 879 | + * return new Some_Class(); |
|
| 880 | + * }, |
|
| 881 | + * This is required for instantiating dependencies |
|
| 882 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 883 | + * 'Required_Interface' => function () { |
|
| 884 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 885 | + * }, |
|
| 886 | + */ |
|
| 887 | + protected function _register_core_class_loaders() |
|
| 888 | + { |
|
| 889 | + $this->_class_loaders = [ |
|
| 890 | + // load_core |
|
| 891 | + 'EE_Dependency_Map' => function () { |
|
| 892 | + return $this; |
|
| 893 | + }, |
|
| 894 | + 'EE_Capabilities' => 'load_core', |
|
| 895 | + 'EE_Encryption' => 'load_core', |
|
| 896 | + 'EE_Front_Controller' => 'load_core', |
|
| 897 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 898 | + 'EE_Registry' => 'load_core', |
|
| 899 | + 'EE_Request' => function () { |
|
| 900 | + return $this->legacy_request; |
|
| 901 | + }, |
|
| 902 | + 'EventEspresso\core\services\request\Request' => function () { |
|
| 903 | + return $this->request; |
|
| 904 | + }, |
|
| 905 | + 'EventEspresso\core\services\request\Response' => function () { |
|
| 906 | + return $this->response; |
|
| 907 | + }, |
|
| 908 | + 'EE_Base' => 'load_core', |
|
| 909 | + 'EE_Request_Handler' => 'load_core', |
|
| 910 | + 'EE_Session' => 'load_core', |
|
| 911 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 912 | + 'EE_System' => 'load_core', |
|
| 913 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 914 | + 'EE_Register_CPTs' => 'load_core', |
|
| 915 | + 'EE_Admin' => 'load_core', |
|
| 916 | + 'EE_CPT_Strategy' => 'load_core', |
|
| 917 | + // load_class |
|
| 918 | + 'EE_Registration_Processor' => 'load_class', |
|
| 919 | + // load_lib |
|
| 920 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 921 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 922 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 923 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 924 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 925 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 926 | + 'EE_Message_Repository' => 'load_lib', |
|
| 927 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 928 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 929 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 930 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 931 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 932 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 933 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 934 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 935 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 936 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 937 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 938 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 939 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 940 | + 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
| 941 | + 'EE_DMS_Core_4_12_0' => 'load_dms', |
|
| 942 | + 'EE_Messages_Generator' => static function () { |
|
| 943 | + return EE_Registry::instance()->load_lib( |
|
| 944 | + 'Messages_Generator', |
|
| 945 | + [], |
|
| 946 | + false, |
|
| 947 | + false |
|
| 948 | + ); |
|
| 949 | + }, |
|
| 950 | + 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
| 951 | + return EE_Registry::instance()->load_lib( |
|
| 952 | + 'Messages_Template_Defaults', |
|
| 953 | + $arguments, |
|
| 954 | + false, |
|
| 955 | + false |
|
| 956 | + ); |
|
| 957 | + }, |
|
| 958 | + // load_helper |
|
| 959 | + 'EEH_Parse_Shortcodes' => static function () { |
|
| 960 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 961 | + return new EEH_Parse_Shortcodes(); |
|
| 962 | + } |
|
| 963 | + return null; |
|
| 964 | + }, |
|
| 965 | + 'EE_Template_Config' => static function () { |
|
| 966 | + return EE_Config::instance()->template_settings; |
|
| 967 | + }, |
|
| 968 | + 'EE_Currency_Config' => static function () { |
|
| 969 | + return EE_Currency_Config::getCurrencyConfig(); |
|
| 970 | + }, |
|
| 971 | + 'EE_Registration_Config' => static function () { |
|
| 972 | + return EE_Config::instance()->registration; |
|
| 973 | + }, |
|
| 974 | + 'EE_Core_Config' => static function () { |
|
| 975 | + return EE_Config::instance()->core; |
|
| 976 | + }, |
|
| 977 | + 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
| 978 | + return LoaderFactory::getLoader(); |
|
| 979 | + }, |
|
| 980 | + 'EE_Network_Config' => static function () { |
|
| 981 | + return EE_Network_Config::instance(); |
|
| 982 | + }, |
|
| 983 | + 'EE_Config' => static function () { |
|
| 984 | + return EE_Config::instance(); |
|
| 985 | + }, |
|
| 986 | + 'EventEspresso\core\domain\Domain' => static function () { |
|
| 987 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
| 988 | + }, |
|
| 989 | + 'EE_Admin_Config' => static function () { |
|
| 990 | + return EE_Config::instance()->admin; |
|
| 991 | + }, |
|
| 992 | + 'EE_Organization_Config' => static function () { |
|
| 993 | + return EE_Config::instance()->organization; |
|
| 994 | + }, |
|
| 995 | + 'EE_Network_Core_Config' => static function () { |
|
| 996 | + return EE_Network_Config::instance()->core; |
|
| 997 | + }, |
|
| 998 | + 'EE_Environment_Config' => static function () { |
|
| 999 | + return EE_Config::instance()->environment; |
|
| 1000 | + }, |
|
| 1001 | + 'EED_Core_Rest_Api' => static function () { |
|
| 1002 | + return EED_Core_Rest_Api::instance(); |
|
| 1003 | + }, |
|
| 1004 | + 'WP_REST_Server' => static function () { |
|
| 1005 | + return rest_get_server(); |
|
| 1006 | + }, |
|
| 1007 | + 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
| 1008 | + return EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 1009 | + }, |
|
| 1010 | + 'EE_Ticket_Selector_Config' => function () { |
|
| 1011 | + return EE_Config::instance()->template_settings->EED_Ticket_Selector; |
|
| 1012 | + }, |
|
| 1013 | + ]; |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + /** |
|
| 1018 | + * can be used for supplying alternate names for classes, |
|
| 1019 | + * or for connecting interface names to instantiable classes |
|
| 1020 | + * |
|
| 1021 | + * @throws InvalidAliasException |
|
| 1022 | + */ |
|
| 1023 | + protected function _register_core_aliases() |
|
| 1024 | + { |
|
| 1025 | + $aliases = [ |
|
| 1026 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 1027 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 1028 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 1029 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 1030 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 1031 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 1032 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1033 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 1034 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1035 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 1036 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1037 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 1038 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 1039 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 1040 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 1041 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 1042 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 1043 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 1044 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 1045 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 1046 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1047 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 1048 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1049 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 1050 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 1051 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 1052 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 1053 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 1054 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 1055 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 1056 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 1057 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 1058 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 1059 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 1060 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 1061 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 1062 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 1063 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 1064 | + 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
| 1065 | + ]; |
|
| 1066 | + foreach ($aliases as $alias => $fqn) { |
|
| 1067 | + if (is_array($fqn)) { |
|
| 1068 | + foreach ($fqn as $class => $for_class) { |
|
| 1069 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 1070 | + } |
|
| 1071 | + continue; |
|
| 1072 | + } |
|
| 1073 | + $this->class_cache->addAlias($fqn, $alias); |
|
| 1074 | + } |
|
| 1075 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1076 | + $this->class_cache->addAlias( |
|
| 1077 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 1078 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 1079 | + ); |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + public function debug($for_class = '') |
|
| 1085 | + { |
|
| 1086 | + if (method_exists($this->class_cache, 'debug')) { |
|
| 1087 | + $this->class_cache->debug($for_class); |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + |
|
| 1092 | + /** |
|
| 1093 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 1094 | + * request Primarily used by unit tests. |
|
| 1095 | + */ |
|
| 1096 | + public function reset() |
|
| 1097 | + { |
|
| 1098 | + $this->_register_core_class_loaders(); |
|
| 1099 | + $this->_register_core_dependencies(); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + /** |
|
| 1104 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
| 1105 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 1106 | + * WHY? |
|
| 1107 | + * Because if a class is type hinting for a concretion, |
|
| 1108 | + * then why would we need to find another class to supply it? |
|
| 1109 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1110 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1111 | + * Don't go looking for some substitute. |
|
| 1112 | + * Whereas if a class is type hinting for an interface... |
|
| 1113 | + * then we need to find an actual class to use. |
|
| 1114 | + * So the interface IS the alias for some other FQN, |
|
| 1115 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1116 | + * represents some other class. |
|
| 1117 | + * |
|
| 1118 | + * @param string $fqn |
|
| 1119 | + * @param string $for_class |
|
| 1120 | + * @return bool |
|
| 1121 | + * @deprecated 4.9.62.p |
|
| 1122 | + */ |
|
| 1123 | + public function has_alias(string $fqn = '', string $for_class = ''): bool |
|
| 1124 | + { |
|
| 1125 | + return $this->isAlias($fqn, $for_class); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1131 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1132 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1133 | + * for example: |
|
| 1134 | + * if the following two entries were added to the _aliases array: |
|
| 1135 | + * array( |
|
| 1136 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 1137 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1138 | + * ) |
|
| 1139 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1140 | + * to load an instance of 'some\namespace\classname' |
|
| 1141 | + * |
|
| 1142 | + * @param string $alias |
|
| 1143 | + * @param string $for_class |
|
| 1144 | + * @return string |
|
| 1145 | + * @deprecated 4.9.62.p |
|
| 1146 | + */ |
|
| 1147 | + public function get_alias(string $alias = '', string $for_class = ''): string |
|
| 1148 | + { |
|
| 1149 | + return $this->getFqnForAlias($alias, $for_class); |
|
| 1150 | + } |
|
| 1151 | 1151 | } |
@@ -6,80 +6,80 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class EE_Float_Field extends EE_Model_Field_Base |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var EE_Currency_Config |
|
| 11 | - */ |
|
| 12 | - protected $currency; |
|
| 9 | + /** |
|
| 10 | + * @var EE_Currency_Config |
|
| 11 | + */ |
|
| 12 | + protected $currency; |
|
| 13 | 13 | |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param string $table_column |
|
| 17 | - * @param string $nicename |
|
| 18 | - * @param bool $nullable |
|
| 19 | - * @param null $default_value |
|
| 20 | - */ |
|
| 21 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 22 | - { |
|
| 23 | - $this->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
| 24 | - ? EE_Config::instance()->currency |
|
| 25 | - : new EE_Currency_Config(); |
|
| 26 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 27 | - $this->setSchemaType('number'); |
|
| 28 | - } |
|
| 15 | + /** |
|
| 16 | + * @param string $table_column |
|
| 17 | + * @param string $nicename |
|
| 18 | + * @param bool $nullable |
|
| 19 | + * @param null $default_value |
|
| 20 | + */ |
|
| 21 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 22 | + { |
|
| 23 | + $this->currency = EE_Config::instance()->currency instanceof EE_Currency_Config |
|
| 24 | + ? EE_Config::instance()->currency |
|
| 25 | + : new EE_Currency_Config(); |
|
| 26 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 27 | + $this->setSchemaType('number'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
| 33 | - * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
| 34 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 35 | - * Returns a float |
|
| 36 | - * |
|
| 37 | - * @param float|string $value_inputted_for_field_on_model_object |
|
| 38 | - * @return float |
|
| 39 | - */ |
|
| 40 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 41 | - { |
|
| 42 | - // remove whitespaces and thousands separators |
|
| 43 | - if (is_string($value_inputted_for_field_on_model_object)) { |
|
| 44 | - $value_inputted_for_field_on_model_object = str_replace( |
|
| 45 | - array(" ", $this->currency->thsnds), |
|
| 46 | - "", |
|
| 47 | - $value_inputted_for_field_on_model_object |
|
| 48 | - ); |
|
| 49 | - // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
|
| 50 | - $value_inputted_for_field_on_model_object = str_replace( |
|
| 51 | - $this->currency->dec_mrk, |
|
| 52 | - ".", |
|
| 53 | - $value_inputted_for_field_on_model_object |
|
| 54 | - ); |
|
| 55 | - // double-check there's absolutely nothing left on this string besides numbers |
|
| 56 | - $value_inputted_for_field_on_model_object = preg_replace( |
|
| 57 | - "/[^0-9,.]/", |
|
| 58 | - "", |
|
| 59 | - $value_inputted_for_field_on_model_object |
|
| 60 | - ); |
|
| 61 | - } |
|
| 62 | - return floatval($value_inputted_for_field_on_model_object); |
|
| 63 | - } |
|
| 31 | + /** |
|
| 32 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
| 33 | + * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
| 34 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 35 | + * Returns a float |
|
| 36 | + * |
|
| 37 | + * @param float|string $value_inputted_for_field_on_model_object |
|
| 38 | + * @return float |
|
| 39 | + */ |
|
| 40 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 41 | + { |
|
| 42 | + // remove whitespaces and thousands separators |
|
| 43 | + if (is_string($value_inputted_for_field_on_model_object)) { |
|
| 44 | + $value_inputted_for_field_on_model_object = str_replace( |
|
| 45 | + array(" ", $this->currency->thsnds), |
|
| 46 | + "", |
|
| 47 | + $value_inputted_for_field_on_model_object |
|
| 48 | + ); |
|
| 49 | + // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
|
| 50 | + $value_inputted_for_field_on_model_object = str_replace( |
|
| 51 | + $this->currency->dec_mrk, |
|
| 52 | + ".", |
|
| 53 | + $value_inputted_for_field_on_model_object |
|
| 54 | + ); |
|
| 55 | + // double-check there's absolutely nothing left on this string besides numbers |
|
| 56 | + $value_inputted_for_field_on_model_object = preg_replace( |
|
| 57 | + "/[^0-9,.]/", |
|
| 58 | + "", |
|
| 59 | + $value_inputted_for_field_on_model_object |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | + return floatval($value_inputted_for_field_on_model_object); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
| 67 | - * |
|
| 68 | - * @param float $value_on_field_to_be_outputted |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 72 | - { |
|
| 73 | - return number_format( |
|
| 74 | - $value_on_field_to_be_outputted, |
|
| 75 | - $this->currency->dec_plc, |
|
| 76 | - $this->currency->dec_mrk, |
|
| 77 | - $this->currency->thsnds |
|
| 78 | - ); |
|
| 79 | - } |
|
| 65 | + /** |
|
| 66 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
| 67 | + * |
|
| 68 | + * @param float $value_on_field_to_be_outputted |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 72 | + { |
|
| 73 | + return number_format( |
|
| 74 | + $value_on_field_to_be_outputted, |
|
| 75 | + $this->currency->dec_plc, |
|
| 76 | + $this->currency->dec_mrk, |
|
| 77 | + $this->currency->thsnds |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 82 | - { |
|
| 83 | - return floatval($value_found_in_db_for_model_object); |
|
| 84 | - } |
|
| 81 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 82 | + { |
|
| 83 | + return floatval($value_found_in_db_for_model_object); |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -21,4264 +21,4264 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var EE_Admin_Config |
|
| 26 | - */ |
|
| 27 | - protected $admin_config; |
|
| 24 | + /** |
|
| 25 | + * @var EE_Admin_Config |
|
| 26 | + */ |
|
| 27 | + protected $admin_config; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var LoaderInterface |
|
| 31 | - */ |
|
| 32 | - protected $loader; |
|
| 29 | + /** |
|
| 30 | + * @var LoaderInterface |
|
| 31 | + */ |
|
| 32 | + protected $loader; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var RequestInterface |
|
| 36 | - */ |
|
| 37 | - protected $request; |
|
| 34 | + /** |
|
| 35 | + * @var RequestInterface |
|
| 36 | + */ |
|
| 37 | + protected $request; |
|
| 38 | 38 | |
| 39 | - // set in _init_page_props() |
|
| 40 | - public $page_slug; |
|
| 39 | + // set in _init_page_props() |
|
| 40 | + public $page_slug; |
|
| 41 | 41 | |
| 42 | - public $page_label; |
|
| 42 | + public $page_label; |
|
| 43 | 43 | |
| 44 | - public $page_folder; |
|
| 44 | + public $page_folder; |
|
| 45 | 45 | |
| 46 | - // set in define_page_props() |
|
| 47 | - protected $_admin_base_url; |
|
| 46 | + // set in define_page_props() |
|
| 47 | + protected $_admin_base_url; |
|
| 48 | 48 | |
| 49 | - protected $_admin_base_path; |
|
| 49 | + protected $_admin_base_path; |
|
| 50 | 50 | |
| 51 | - protected $_admin_page_title; |
|
| 51 | + protected $_admin_page_title; |
|
| 52 | 52 | |
| 53 | - protected $_labels; |
|
| 53 | + protected $_labels; |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - // set early within EE_Admin_Init |
|
| 57 | - protected $_wp_page_slug; |
|
| 56 | + // set early within EE_Admin_Init |
|
| 57 | + protected $_wp_page_slug; |
|
| 58 | 58 | |
| 59 | - // nav tabs |
|
| 60 | - protected $_nav_tabs; |
|
| 59 | + // nav tabs |
|
| 60 | + protected $_nav_tabs; |
|
| 61 | 61 | |
| 62 | - protected $_default_nav_tab_name; |
|
| 62 | + protected $_default_nav_tab_name; |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - // template variables (used by templates) |
|
| 66 | - protected $_template_path; |
|
| 65 | + // template variables (used by templates) |
|
| 66 | + protected $_template_path; |
|
| 67 | 67 | |
| 68 | - protected $_column_template_path; |
|
| 68 | + protected $_column_template_path; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @var array $_template_args |
|
| 72 | - */ |
|
| 73 | - protected $_template_args = []; |
|
| 70 | + /** |
|
| 71 | + * @var array $_template_args |
|
| 72 | + */ |
|
| 73 | + protected $_template_args = []; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * this will hold the list table object for a given view. |
|
| 77 | - * |
|
| 78 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 79 | - */ |
|
| 80 | - protected $_list_table_object; |
|
| 75 | + /** |
|
| 76 | + * this will hold the list table object for a given view. |
|
| 77 | + * |
|
| 78 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 79 | + */ |
|
| 80 | + protected $_list_table_object; |
|
| 81 | 81 | |
| 82 | - // boolean |
|
| 83 | - protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states. |
|
| 82 | + // boolean |
|
| 83 | + protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states. |
|
| 84 | 84 | |
| 85 | - protected $_routing; |
|
| 85 | + protected $_routing; |
|
| 86 | 86 | |
| 87 | - // list table args |
|
| 88 | - protected $_view; |
|
| 87 | + // list table args |
|
| 88 | + protected $_view; |
|
| 89 | 89 | |
| 90 | - protected $_views; |
|
| 90 | + protected $_views; |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - // action => method pairs used for routing incoming requests |
|
| 94 | - protected $_page_routes; |
|
| 93 | + // action => method pairs used for routing incoming requests |
|
| 94 | + protected $_page_routes; |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @var array $_page_config |
|
| 98 | - */ |
|
| 99 | - protected $_page_config; |
|
| 96 | + /** |
|
| 97 | + * @var array $_page_config |
|
| 98 | + */ |
|
| 99 | + protected $_page_config; |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * the current page route and route config |
|
| 103 | - * |
|
| 104 | - * @var string $_route |
|
| 105 | - */ |
|
| 106 | - protected $_route; |
|
| 101 | + /** |
|
| 102 | + * the current page route and route config |
|
| 103 | + * |
|
| 104 | + * @var string $_route |
|
| 105 | + */ |
|
| 106 | + protected $_route; |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @var string $_cpt_route |
|
| 110 | - */ |
|
| 111 | - protected $_cpt_route; |
|
| 108 | + /** |
|
| 109 | + * @var string $_cpt_route |
|
| 110 | + */ |
|
| 111 | + protected $_cpt_route; |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * @var array $_route_config |
|
| 115 | - */ |
|
| 116 | - protected $_route_config; |
|
| 113 | + /** |
|
| 114 | + * @var array $_route_config |
|
| 115 | + */ |
|
| 116 | + protected $_route_config; |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 120 | - * actions. |
|
| 121 | - * |
|
| 122 | - * @since 4.6.x |
|
| 123 | - * @var array. |
|
| 124 | - */ |
|
| 125 | - protected $_default_route_query_args; |
|
| 118 | + /** |
|
| 119 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 120 | + * actions. |
|
| 121 | + * |
|
| 122 | + * @since 4.6.x |
|
| 123 | + * @var array. |
|
| 124 | + */ |
|
| 125 | + protected $_default_route_query_args; |
|
| 126 | 126 | |
| 127 | - // set via request page and action args. |
|
| 128 | - protected $_current_page; |
|
| 127 | + // set via request page and action args. |
|
| 128 | + protected $_current_page; |
|
| 129 | 129 | |
| 130 | - protected $_current_view; |
|
| 130 | + protected $_current_view; |
|
| 131 | 131 | |
| 132 | - protected $_current_page_view_url; |
|
| 132 | + protected $_current_page_view_url; |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * unprocessed value for the 'action' request param (default '') |
|
| 136 | - * |
|
| 137 | - * @var string |
|
| 138 | - */ |
|
| 139 | - protected $raw_req_action = ''; |
|
| 134 | + /** |
|
| 135 | + * unprocessed value for the 'action' request param (default '') |
|
| 136 | + * |
|
| 137 | + * @var string |
|
| 138 | + */ |
|
| 139 | + protected $raw_req_action = ''; |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * unprocessed value for the 'page' request param (default '') |
|
| 143 | - * |
|
| 144 | - * @var string |
|
| 145 | - */ |
|
| 146 | - protected $raw_req_page = ''; |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * sanitized request action (and nonce) |
|
| 150 | - * |
|
| 151 | - * @var string |
|
| 152 | - */ |
|
| 153 | - protected $_req_action = ''; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * sanitized request action nonce |
|
| 157 | - * |
|
| 158 | - * @var string |
|
| 159 | - */ |
|
| 160 | - protected $_req_nonce = ''; |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @var string |
|
| 164 | - */ |
|
| 165 | - protected $_search_btn_label = ''; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @var string |
|
| 169 | - */ |
|
| 170 | - protected $_search_box_callback = ''; |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @var WP_Screen |
|
| 174 | - */ |
|
| 175 | - protected $_current_screen; |
|
| 176 | - |
|
| 177 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 178 | - protected $_hook_obj; |
|
| 179 | - |
|
| 180 | - // for holding incoming request data |
|
| 181 | - protected $_req_data = []; |
|
| 182 | - |
|
| 183 | - // yes / no array for admin form fields |
|
| 184 | - protected $_yes_no_values = []; |
|
| 185 | - |
|
| 186 | - // some default things shared by all child classes |
|
| 187 | - protected $_default_espresso_metaboxes = [ |
|
| 188 | - '_espresso_news_post_box', |
|
| 189 | - '_espresso_links_post_box', |
|
| 190 | - '_espresso_ratings_request', |
|
| 191 | - '_espresso_sponsors_post_box', |
|
| 192 | - ]; |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @var EE_Registry |
|
| 196 | - */ |
|
| 197 | - protected $EE; |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 202 | - * |
|
| 203 | - * @var boolean |
|
| 204 | - */ |
|
| 205 | - protected $_is_caf = false; |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * whether or not initializePage() has run |
|
| 209 | - * |
|
| 210 | - * @var boolean |
|
| 211 | - */ |
|
| 212 | - protected $initialized = false; |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @var FeatureFlags |
|
| 216 | - */ |
|
| 217 | - protected $feature; |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @var string |
|
| 222 | - */ |
|
| 223 | - protected $class_name; |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * if the current class is an admin page extension, like: Extend_Events_Admin_Page, |
|
| 227 | - * then this would be the parent classname: Events_Admin_Page |
|
| 228 | - * |
|
| 229 | - * @var string |
|
| 230 | - */ |
|
| 231 | - protected $base_class_name; |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @Constructor |
|
| 236 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 237 | - * @throws InvalidArgumentException |
|
| 238 | - * @throws InvalidDataTypeException |
|
| 239 | - * @throws InvalidInterfaceException |
|
| 240 | - * @throws ReflectionException |
|
| 241 | - */ |
|
| 242 | - public function __construct($routing = true) |
|
| 243 | - { |
|
| 244 | - $this->loader = LoaderFactory::getLoader(); |
|
| 245 | - $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 246 | - $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 247 | - $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 248 | - // routing enabled? |
|
| 249 | - $this->_routing = $routing; |
|
| 250 | - |
|
| 251 | - $this->class_name = get_class($this); |
|
| 252 | - $this->base_class_name = strpos($this->class_name, 'Extend_') === 0 |
|
| 253 | - ? str_replace('Extend_', '', $this->class_name) |
|
| 254 | - : ''; |
|
| 255 | - |
|
| 256 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 257 | - $this->_is_caf = true; |
|
| 258 | - } |
|
| 259 | - $this->_yes_no_values = [ |
|
| 260 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 261 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 262 | - ]; |
|
| 263 | - // set the _req_data property. |
|
| 264 | - $this->_req_data = $this->request->requestParams(); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @return EE_Admin_Config |
|
| 270 | - */ |
|
| 271 | - public function adminConfig(): EE_Admin_Config |
|
| 272 | - { |
|
| 273 | - return $this->admin_config; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @return FeatureFlags |
|
| 279 | - */ |
|
| 280 | - public function feature(): FeatureFlags |
|
| 281 | - { |
|
| 282 | - return $this->feature; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 288 | - * for child classes that needed to set properties prior to these methods getting called, |
|
| 289 | - * but also needed the parent class to have its construction completed as well. |
|
| 290 | - * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 291 | - * and any complex initialization logic should only run after instantiation is complete. |
|
| 292 | - * |
|
| 293 | - * This method gets called immediately after construction from within |
|
| 294 | - * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 295 | - * |
|
| 296 | - * @throws EE_Error |
|
| 297 | - * @throws InvalidArgumentException |
|
| 298 | - * @throws InvalidDataTypeException |
|
| 299 | - * @throws InvalidInterfaceException |
|
| 300 | - * @throws ReflectionException |
|
| 301 | - * @since $VID:$ |
|
| 302 | - */ |
|
| 303 | - public function initializePage() |
|
| 304 | - { |
|
| 305 | - if ($this->initialized) { |
|
| 306 | - return; |
|
| 307 | - } |
|
| 308 | - // set initial page props (child method) |
|
| 309 | - $this->_init_page_props(); |
|
| 310 | - // set global defaults |
|
| 311 | - $this->_set_defaults(); |
|
| 312 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 313 | - $this->_global_ajax_hooks(); |
|
| 314 | - $this->_ajax_hooks(); |
|
| 315 | - // other_page_hooks have to be early too. |
|
| 316 | - $this->_do_other_page_hooks(); |
|
| 317 | - // set up page dependencies |
|
| 318 | - $this->_before_page_setup(); |
|
| 319 | - $this->_page_setup(); |
|
| 320 | - $this->initialized = true; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * _init_page_props |
|
| 326 | - * Child classes use to set at least the following properties: |
|
| 327 | - * $page_slug. |
|
| 328 | - * $page_label. |
|
| 329 | - * |
|
| 330 | - * @abstract |
|
| 331 | - * @return void |
|
| 332 | - */ |
|
| 333 | - abstract protected function _init_page_props(); |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * _ajax_hooks |
|
| 338 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 339 | - * Note: within the ajax callback methods. |
|
| 340 | - * |
|
| 341 | - * @abstract |
|
| 342 | - * @return void |
|
| 343 | - */ |
|
| 344 | - abstract protected function _ajax_hooks(); |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * _define_page_props |
|
| 349 | - * child classes define page properties in here. Must include at least: |
|
| 350 | - * $_admin_base_url = base_url for all admin pages |
|
| 351 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 352 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 353 | - * array( |
|
| 354 | - * 'buttons' => array( |
|
| 355 | - * 'add' => esc_html__('label for add new button'), |
|
| 356 | - * 'edit' => esc_html__('label for edit button'), |
|
| 357 | - * 'delete' => esc_html__('label for delete button') |
|
| 358 | - * ) |
|
| 359 | - * ) |
|
| 360 | - * |
|
| 361 | - * @abstract |
|
| 362 | - * @return void |
|
| 363 | - */ |
|
| 364 | - abstract protected function _define_page_props(); |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * _set_page_routes |
|
| 369 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 370 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 371 | - * have a 'default' route. Here's the format |
|
| 372 | - * $this->_page_routes = array( |
|
| 373 | - * 'default' => array( |
|
| 374 | - * 'func' => '_default_method_handling_route', |
|
| 375 | - * 'args' => array('array','of','args'), |
|
| 376 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 377 | - * ajax request, backend processing) |
|
| 378 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 379 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 380 | - * headers sent route. |
|
| 381 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 382 | - * this route. |
|
| 383 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 384 | - * checks). |
|
| 385 | - * ), |
|
| 386 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 387 | - * handling method. |
|
| 388 | - * ) |
|
| 389 | - * ) |
|
| 390 | - * |
|
| 391 | - * @abstract |
|
| 392 | - * @return void |
|
| 393 | - */ |
|
| 394 | - abstract protected function _set_page_routes(); |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * _set_page_config |
|
| 399 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 400 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 401 | - * $this->_page_config = array( |
|
| 402 | - * 'default' => array( |
|
| 403 | - * 'labels' => array( |
|
| 404 | - * 'buttons' => array( |
|
| 405 | - * 'add' => esc_html__('label for adding item'), |
|
| 406 | - * 'edit' => esc_html__('label for editing item'), |
|
| 407 | - * 'delete' => esc_html__('label for deleting item') |
|
| 408 | - * ), |
|
| 409 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 410 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 411 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 412 | - * _define_page_props() method |
|
| 413 | - * 'nav' => array( |
|
| 414 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 415 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 416 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 417 | - * 'order' => 10, //required to indicate tab position. |
|
| 418 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 419 | - * displayed then add this parameter. |
|
| 420 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 421 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 422 | - * metaboxes set for eventespresso admin pages. |
|
| 423 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 424 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 425 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 426 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 427 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 428 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 429 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 430 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 431 | - * want to display. |
|
| 432 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 433 | - * 'tab_id' => array( |
|
| 434 | - * 'title' => 'tab_title', |
|
| 435 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 436 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 437 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 438 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 439 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 440 | - * attempt to use the callback which should match the name of a method in the class |
|
| 441 | - * ), |
|
| 442 | - * 'tab2_id' => array( |
|
| 443 | - * 'title' => 'tab2 title', |
|
| 444 | - * 'filename' => 'file_name_2' |
|
| 445 | - * 'callback' => 'callback_method_for_content', |
|
| 446 | - * ), |
|
| 447 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 448 | - * help tab area on an admin page. @return void |
|
| 449 | - * |
|
| 450 | - * @abstract |
|
| 451 | - */ |
|
| 452 | - abstract protected function _set_page_config(); |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * _add_screen_options |
|
| 457 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 458 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 459 | - * to a particular view. |
|
| 460 | - * |
|
| 461 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 462 | - * see also WP_Screen object documents... |
|
| 463 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 464 | - * @abstract |
|
| 465 | - * @return void |
|
| 466 | - */ |
|
| 467 | - abstract protected function _add_screen_options(); |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * _add_feature_pointers |
|
| 472 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 473 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 474 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 475 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 476 | - * extended) also see: |
|
| 477 | - * |
|
| 478 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 479 | - * @abstract |
|
| 480 | - * @return void |
|
| 481 | - */ |
|
| 482 | - abstract protected function _add_feature_pointers(); |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * load_scripts_styles |
|
| 487 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 488 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 489 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 490 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 491 | - * |
|
| 492 | - * @abstract |
|
| 493 | - * @return void |
|
| 494 | - */ |
|
| 495 | - abstract public function load_scripts_styles(); |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * admin_init |
|
| 500 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 501 | - * all pages/views loaded by child class. |
|
| 502 | - * |
|
| 503 | - * @abstract |
|
| 504 | - * @return void |
|
| 505 | - */ |
|
| 506 | - abstract public function admin_init(); |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * admin_notices |
|
| 511 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 512 | - * all pages/views loaded by child class. |
|
| 513 | - * |
|
| 514 | - * @abstract |
|
| 515 | - * @return void |
|
| 516 | - */ |
|
| 517 | - abstract public function admin_notices(); |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * admin_footer_scripts |
|
| 522 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 523 | - * will apply to all pages/views loaded by child class. |
|
| 524 | - * |
|
| 525 | - * @return void |
|
| 526 | - */ |
|
| 527 | - abstract public function admin_footer_scripts(); |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * admin_footer |
|
| 532 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 533 | - * apply to all pages/views loaded by child class. |
|
| 534 | - * |
|
| 535 | - * @return void |
|
| 536 | - */ |
|
| 537 | - public function admin_footer() |
|
| 538 | - { |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * _global_ajax_hooks |
|
| 544 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 545 | - * Note: within the ajax callback methods. |
|
| 546 | - * |
|
| 547 | - * @abstract |
|
| 548 | - * @return void |
|
| 549 | - */ |
|
| 550 | - protected function _global_ajax_hooks() |
|
| 551 | - { |
|
| 552 | - // for lazy loading of metabox content |
|
| 553 | - add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 554 | - |
|
| 555 | - add_action( |
|
| 556 | - 'wp_ajax_espresso_hide_status_change_notice', |
|
| 557 | - [$this, 'hideStatusChangeNotice'] |
|
| 558 | - ); |
|
| 559 | - add_action( |
|
| 560 | - 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 561 | - [$this, 'hideStatusChangeNotice'] |
|
| 562 | - ); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - public function ajax_metabox_content() |
|
| 567 | - { |
|
| 568 | - $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 569 | - $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 570 | - EE_Admin_Page::cached_rss_display($content_id, $content_url); |
|
| 571 | - wp_die(); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - public function hideStatusChangeNotice() |
|
| 576 | - { |
|
| 577 | - $response = []; |
|
| 578 | - try { |
|
| 579 | - /** @var StatusChangeNotice $status_change_notice */ |
|
| 580 | - $status_change_notice = $this->loader->getShared( |
|
| 581 | - 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 582 | - ); |
|
| 583 | - $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 584 | - } catch (Exception $exception) { |
|
| 585 | - $response['errors'] = $exception->getMessage(); |
|
| 586 | - } |
|
| 587 | - echo wp_json_encode($response); |
|
| 588 | - exit(); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 594 | - * |
|
| 595 | - * @return void |
|
| 596 | - */ |
|
| 597 | - protected function _before_page_setup() |
|
| 598 | - { |
|
| 599 | - // default is to do nothing |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Makes sure any things that need to be loaded early get handled. |
|
| 605 | - * We also escape early here if the page requested doesn't match the object. |
|
| 606 | - * |
|
| 607 | - * @final |
|
| 608 | - * @return void |
|
| 609 | - * @throws EE_Error |
|
| 610 | - * @throws InvalidArgumentException |
|
| 611 | - * @throws ReflectionException |
|
| 612 | - * @throws InvalidDataTypeException |
|
| 613 | - * @throws InvalidInterfaceException |
|
| 614 | - */ |
|
| 615 | - final protected function _page_setup() |
|
| 616 | - { |
|
| 617 | - // requires? |
|
| 618 | - // admin_init stuff - global - we're setting this REALLY early |
|
| 619 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 620 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 621 | - add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 622 | - // next verify if we need to load anything... |
|
| 623 | - $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 624 | - $this->page_folder = strtolower( |
|
| 625 | - str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name) |
|
| 626 | - ); |
|
| 627 | - global $ee_menu_slugs; |
|
| 628 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 629 | - if ( |
|
| 630 | - ! $this->request->isAjax() |
|
| 631 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 632 | - ) { |
|
| 633 | - return; |
|
| 634 | - } |
|
| 635 | - // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 636 | - // we need to copy the action from the second to the first |
|
| 637 | - $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 638 | - $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 639 | - $action = $action !== '-1' ? $action : $action2; |
|
| 640 | - $req_action = $action !== '-1' ? $action : 'default'; |
|
| 641 | - |
|
| 642 | - // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 643 | - // then let's use the route as the action. |
|
| 644 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 645 | - $route = $this->request->getRequestParam('route'); |
|
| 646 | - $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 647 | - ? $route |
|
| 648 | - : $req_action; |
|
| 649 | - |
|
| 650 | - $this->_current_view = $this->_req_action; |
|
| 651 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 652 | - $this->_define_page_props(); |
|
| 653 | - $this->_current_page_view_url = add_query_arg( |
|
| 654 | - ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 655 | - $this->_admin_base_url |
|
| 656 | - ); |
|
| 657 | - // set page configs |
|
| 658 | - $this->_set_page_routes(); |
|
| 659 | - $this->_set_page_config(); |
|
| 660 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 661 | - if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 662 | - $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 663 | - if ($wp_referer) { |
|
| 664 | - $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - // for caffeinated and other extended functionality. |
|
| 668 | - // If there is a _extend_page_config method |
|
| 669 | - // then let's run that to modify the all the various page configuration arrays |
|
| 670 | - if (method_exists($this, '_extend_page_config')) { |
|
| 671 | - $this->_extend_page_config(); |
|
| 672 | - } |
|
| 673 | - // for CPT and other extended functionality. |
|
| 674 | - // If there is an _extend_page_config_for_cpt |
|
| 675 | - // then let's run that to modify all the various page configuration arrays. |
|
| 676 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 677 | - $this->_extend_page_config_for_cpt(); |
|
| 678 | - } |
|
| 679 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 680 | - $this->_page_routes = apply_filters( |
|
| 681 | - 'FHEE__' . $this->class_name . '__page_setup__page_routes', |
|
| 682 | - $this->_page_routes, |
|
| 683 | - $this |
|
| 684 | - ); |
|
| 685 | - $this->_page_config = apply_filters( |
|
| 686 | - 'FHEE__' . $this->class_name . '__page_setup__page_config', |
|
| 687 | - $this->_page_config, |
|
| 688 | - $this |
|
| 689 | - ); |
|
| 690 | - if ($this->base_class_name !== '') { |
|
| 691 | - $this->_page_routes = apply_filters( |
|
| 692 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_routes', |
|
| 693 | - $this->_page_routes, |
|
| 694 | - $this |
|
| 695 | - ); |
|
| 696 | - $this->_page_config = apply_filters( |
|
| 697 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_config', |
|
| 698 | - $this->_page_config, |
|
| 699 | - $this |
|
| 700 | - ); |
|
| 701 | - } |
|
| 702 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 703 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 704 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 705 | - add_action( |
|
| 706 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 707 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 708 | - 10, |
|
| 709 | - 2 |
|
| 710 | - ); |
|
| 711 | - } |
|
| 712 | - // next route only if routing enabled |
|
| 713 | - if ($this->_routing && ! $this->request->isAjax()) { |
|
| 714 | - $this->_verify_routes(); |
|
| 715 | - // next let's just check user_access and kill if no access |
|
| 716 | - $this->check_user_access(); |
|
| 717 | - if ($this->_is_UI_request) { |
|
| 718 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 719 | - add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 720 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 721 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 722 | - } |
|
| 723 | - } else { |
|
| 724 | - // hijack regular WP loading and route admin request immediately |
|
| 725 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 726 | - $this->route_admin_request(); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 734 | - * |
|
| 735 | - * @return void |
|
| 736 | - * @throws EE_Error |
|
| 737 | - */ |
|
| 738 | - private function _do_other_page_hooks() |
|
| 739 | - { |
|
| 740 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 741 | - foreach ($registered_pages as $page) { |
|
| 742 | - // now let's setup the file name and class that should be present |
|
| 743 | - $classname = str_replace('.class.php', '', $page); |
|
| 744 | - // autoloaders should take care of loading file |
|
| 745 | - if (! class_exists($classname)) { |
|
| 746 | - $error_msg[] = sprintf( |
|
| 747 | - esc_html__( |
|
| 748 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 749 | - 'event_espresso' |
|
| 750 | - ), |
|
| 751 | - $page |
|
| 752 | - ); |
|
| 753 | - $error_msg[] = $error_msg[0] |
|
| 754 | - . "\r\n" |
|
| 755 | - . sprintf( |
|
| 756 | - esc_html__( |
|
| 757 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 758 | - 'event_espresso' |
|
| 759 | - ), |
|
| 760 | - $page, |
|
| 761 | - '<br />', |
|
| 762 | - '<strong>' . $classname . '</strong>' |
|
| 763 | - ); |
|
| 764 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 765 | - } |
|
| 766 | - // notice we are passing the instance of this class to the hook object. |
|
| 767 | - $this->loader->getShared($classname, [$this]); |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * @throws ReflectionException |
|
| 774 | - * @throws EE_Error |
|
| 775 | - */ |
|
| 776 | - public function load_page_dependencies() |
|
| 777 | - { |
|
| 778 | - try { |
|
| 779 | - $this->_load_page_dependencies(); |
|
| 780 | - } catch (EE_Error $e) { |
|
| 781 | - $e->get_error(); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - /** |
|
| 787 | - * load_page_dependencies |
|
| 788 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 789 | - * |
|
| 790 | - * @return void |
|
| 791 | - * @throws DomainException |
|
| 792 | - * @throws EE_Error |
|
| 793 | - * @throws InvalidArgumentException |
|
| 794 | - * @throws InvalidDataTypeException |
|
| 795 | - * @throws InvalidInterfaceException |
|
| 796 | - */ |
|
| 797 | - protected function _load_page_dependencies() |
|
| 798 | - { |
|
| 799 | - // let's set the current_screen and screen options to override what WP set |
|
| 800 | - $this->_current_screen = get_current_screen(); |
|
| 801 | - // load admin_notices - global, page class, and view specific |
|
| 802 | - add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 803 | - add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 804 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 805 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 806 | - } |
|
| 807 | - // load network admin_notices - global, page class, and view specific |
|
| 808 | - add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 809 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 810 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 811 | - } |
|
| 812 | - // this will save any per_page screen options if they are present |
|
| 813 | - $this->_set_per_page_screen_options(); |
|
| 814 | - // setup list table properties |
|
| 815 | - $this->_set_list_table(); |
|
| 816 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 817 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 818 | - $this->_add_registered_meta_boxes(); |
|
| 819 | - $this->_add_screen_columns(); |
|
| 820 | - // add screen options - global, page child class, and view specific |
|
| 821 | - $this->_add_global_screen_options(); |
|
| 822 | - $this->_add_screen_options(); |
|
| 823 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 824 | - if (method_exists($this, $add_screen_options)) { |
|
| 825 | - $this->{$add_screen_options}(); |
|
| 826 | - } |
|
| 827 | - // add help tab(s) - set via page_config and qtips. |
|
| 828 | - $this->_add_help_tabs(); |
|
| 829 | - $this->_add_qtips(); |
|
| 830 | - // add feature_pointers - global, page child class, and view specific |
|
| 831 | - $this->_add_feature_pointers(); |
|
| 832 | - $this->_add_global_feature_pointers(); |
|
| 833 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 834 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 835 | - $this->{$add_feature_pointer}(); |
|
| 836 | - } |
|
| 837 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 838 | - add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 839 | - add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 840 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 841 | - add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 842 | - } |
|
| 843 | - add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 844 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 845 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 846 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 847 | - // is a good use case. Notice the late priority we're giving these |
|
| 848 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 849 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 850 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 851 | - add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 852 | - } |
|
| 853 | - // admin footer scripts |
|
| 854 | - add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 855 | - add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 856 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 857 | - add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 858 | - } |
|
| 859 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 860 | - // targeted hook |
|
| 861 | - do_action( |
|
| 862 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 863 | - ); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * _set_defaults |
|
| 869 | - * This sets some global defaults for class properties. |
|
| 870 | - */ |
|
| 871 | - private function _set_defaults() |
|
| 872 | - { |
|
| 873 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 874 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 875 | - $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 876 | - $this->_page_config = $this->_default_route_query_args = []; |
|
| 877 | - $this->_default_nav_tab_name = 'overview'; |
|
| 878 | - // init template args |
|
| 879 | - $this->_template_args = [ |
|
| 880 | - 'admin_page_header' => '', |
|
| 881 | - 'admin_page_content' => '', |
|
| 882 | - 'post_body_content' => '', |
|
| 883 | - 'before_list_table' => '', |
|
| 884 | - 'after_list_table' => '', |
|
| 885 | - ]; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * route_admin_request |
|
| 891 | - * |
|
| 892 | - * @return void |
|
| 893 | - * @throws InvalidArgumentException |
|
| 894 | - * @throws InvalidInterfaceException |
|
| 895 | - * @throws InvalidDataTypeException |
|
| 896 | - * @throws EE_Error |
|
| 897 | - * @throws ReflectionException |
|
| 898 | - * @see _route_admin_request() |
|
| 899 | - */ |
|
| 900 | - public function route_admin_request() |
|
| 901 | - { |
|
| 902 | - try { |
|
| 903 | - $this->_route_admin_request(); |
|
| 904 | - } catch (EE_Error $e) { |
|
| 905 | - $e->get_error(); |
|
| 906 | - } |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - public function set_wp_page_slug($wp_page_slug) |
|
| 911 | - { |
|
| 912 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 913 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 914 | - if (is_network_admin()) { |
|
| 915 | - $this->_wp_page_slug .= '-network'; |
|
| 916 | - } |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * _verify_routes |
|
| 922 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 923 | - * we know if we need to drop out. |
|
| 924 | - * |
|
| 925 | - * @return bool |
|
| 926 | - * @throws EE_Error |
|
| 927 | - */ |
|
| 928 | - protected function _verify_routes() |
|
| 929 | - { |
|
| 930 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 931 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 932 | - return false; |
|
| 933 | - } |
|
| 934 | - $this->_route = false; |
|
| 935 | - // check that the page_routes array is not empty |
|
| 936 | - if (empty($this->_page_routes)) { |
|
| 937 | - // user error msg |
|
| 938 | - $error_msg = sprintf( |
|
| 939 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 940 | - $this->_admin_page_title |
|
| 941 | - ); |
|
| 942 | - // developer error msg |
|
| 943 | - $error_msg .= '||' . $error_msg |
|
| 944 | - . esc_html__( |
|
| 945 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 946 | - 'event_espresso' |
|
| 947 | - ); |
|
| 948 | - throw new EE_Error($error_msg); |
|
| 949 | - } |
|
| 950 | - // and that the requested page route exists |
|
| 951 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 952 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 953 | - $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 954 | - } else { |
|
| 955 | - // user error msg |
|
| 956 | - $error_msg = sprintf( |
|
| 957 | - esc_html__( |
|
| 958 | - 'The requested page route does not exist for the %s admin page.', |
|
| 959 | - 'event_espresso' |
|
| 960 | - ), |
|
| 961 | - $this->_admin_page_title |
|
| 962 | - ); |
|
| 963 | - // developer error msg |
|
| 964 | - $error_msg .= '||' . $error_msg |
|
| 965 | - . sprintf( |
|
| 966 | - esc_html__( |
|
| 967 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 968 | - 'event_espresso' |
|
| 969 | - ), |
|
| 970 | - $this->_req_action |
|
| 971 | - ); |
|
| 972 | - throw new EE_Error($error_msg); |
|
| 973 | - } |
|
| 974 | - // and that a default route exists |
|
| 975 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 976 | - // user error msg |
|
| 977 | - $error_msg = sprintf( |
|
| 978 | - esc_html__( |
|
| 979 | - 'A default page route has not been set for the % admin page.', |
|
| 980 | - 'event_espresso' |
|
| 981 | - ), |
|
| 982 | - $this->_admin_page_title |
|
| 983 | - ); |
|
| 984 | - // developer error msg |
|
| 985 | - $error_msg .= '||' . $error_msg |
|
| 986 | - . esc_html__( |
|
| 987 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 988 | - 'event_espresso' |
|
| 989 | - ); |
|
| 990 | - throw new EE_Error($error_msg); |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - // first lets' catch if the UI request has EVER been set. |
|
| 994 | - if ($this->_is_UI_request === null) { |
|
| 995 | - // lets set if this is a UI request or not. |
|
| 996 | - $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 997 | - // wait a minute... we might have a noheader in the route array |
|
| 998 | - $this->_is_UI_request = ! ( |
|
| 999 | - is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 1000 | - ) |
|
| 1001 | - ? $this->_is_UI_request |
|
| 1002 | - : false; |
|
| 1003 | - } |
|
| 1004 | - $this->_set_current_labels(); |
|
| 1005 | - return true; |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - |
|
| 1009 | - /** |
|
| 1010 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 1011 | - * |
|
| 1012 | - * @param string $route the route name we're verifying |
|
| 1013 | - * @return bool we'll throw an exception if this isn't a valid route. |
|
| 1014 | - * @throws EE_Error |
|
| 1015 | - */ |
|
| 1016 | - protected function _verify_route($route) |
|
| 1017 | - { |
|
| 1018 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 1019 | - return true; |
|
| 1020 | - } |
|
| 1021 | - // user error msg |
|
| 1022 | - $error_msg = sprintf( |
|
| 1023 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 1024 | - $this->_admin_page_title |
|
| 1025 | - ); |
|
| 1026 | - // developer error msg |
|
| 1027 | - $error_msg .= '||' . $error_msg |
|
| 1028 | - . sprintf( |
|
| 1029 | - esc_html__( |
|
| 1030 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 1031 | - 'event_espresso' |
|
| 1032 | - ), |
|
| 1033 | - $route |
|
| 1034 | - ); |
|
| 1035 | - throw new EE_Error($error_msg); |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - |
|
| 1039 | - /** |
|
| 1040 | - * perform nonce verification |
|
| 1041 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 1042 | - * using this method (and save retyping!) |
|
| 1043 | - * |
|
| 1044 | - * @param string $nonce The nonce sent |
|
| 1045 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 1046 | - * @return void |
|
| 1047 | - * @throws EE_Error |
|
| 1048 | - * @throws InvalidArgumentException |
|
| 1049 | - * @throws InvalidDataTypeException |
|
| 1050 | - * @throws InvalidInterfaceException |
|
| 1051 | - */ |
|
| 1052 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 1053 | - { |
|
| 1054 | - // verify nonce against expected value |
|
| 1055 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1056 | - // these are not the droids you are looking for !!! |
|
| 1057 | - $msg = sprintf( |
|
| 1058 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1059 | - '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1060 | - '</a>' |
|
| 1061 | - ); |
|
| 1062 | - if (WP_DEBUG) { |
|
| 1063 | - $msg .= "\n "; |
|
| 1064 | - $msg .= sprintf( |
|
| 1065 | - esc_html__( |
|
| 1066 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1067 | - 'event_espresso' |
|
| 1068 | - ), |
|
| 1069 | - __CLASS__ |
|
| 1070 | - ); |
|
| 1071 | - } |
|
| 1072 | - if (! $this->request->isAjax()) { |
|
| 1073 | - wp_die($msg); |
|
| 1074 | - } |
|
| 1075 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1076 | - $this->_return_json(); |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * _route_admin_request() |
|
| 1083 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1084 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1085 | - * in the page routes and then will try to load the corresponding method. |
|
| 1086 | - * |
|
| 1087 | - * @return void |
|
| 1088 | - * @throws EE_Error |
|
| 1089 | - * @throws InvalidArgumentException |
|
| 1090 | - * @throws InvalidDataTypeException |
|
| 1091 | - * @throws InvalidInterfaceException |
|
| 1092 | - * @throws ReflectionException |
|
| 1093 | - */ |
|
| 1094 | - protected function _route_admin_request() |
|
| 1095 | - { |
|
| 1096 | - if (! $this->_is_UI_request) { |
|
| 1097 | - $this->_verify_routes(); |
|
| 1098 | - } |
|
| 1099 | - $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1100 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1101 | - // set nonce from post data |
|
| 1102 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1103 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1104 | - } |
|
| 1105 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 1106 | - if ($this->_is_UI_request) { |
|
| 1107 | - $this->_set_nav_tabs(); |
|
| 1108 | - } |
|
| 1109 | - // grab callback function |
|
| 1110 | - $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route; |
|
| 1111 | - // check if callback has args |
|
| 1112 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 1113 | - $error_msg = ''; |
|
| 1114 | - // action right before calling route |
|
| 1115 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1116 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1117 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1118 | - } |
|
| 1119 | - // strip _wp_http_referer from the server REQUEST_URI |
|
| 1120 | - // else it grows in length on every submission due to recursion, |
|
| 1121 | - // ultimately causing a "Request-URI Too Large" error |
|
| 1122 | - $request_uri = remove_query_arg( |
|
| 1123 | - '_wp_http_referer', |
|
| 1124 | - wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1125 | - ); |
|
| 1126 | - // set new value in both our Request object and the super global |
|
| 1127 | - $this->request->setServerParam('REQUEST_URI', $request_uri, true); |
|
| 1128 | - if (! empty($func)) { |
|
| 1129 | - if (is_array($func)) { |
|
| 1130 | - [$class, $method] = $func; |
|
| 1131 | - } elseif (strpos($func, '::') !== false) { |
|
| 1132 | - [$class, $method] = explode('::', $func); |
|
| 1133 | - } else { |
|
| 1134 | - $class = $this; |
|
| 1135 | - $method = $func; |
|
| 1136 | - } |
|
| 1137 | - if (! (is_object($class) && $class === $this)) { |
|
| 1138 | - // send along this admin page object for access by addons. |
|
| 1139 | - $args['admin_page_object'] = $this; |
|
| 1140 | - } |
|
| 1141 | - if ( |
|
| 1142 | - // is it a method on a class that doesn't work? |
|
| 1143 | - ( |
|
| 1144 | - ( |
|
| 1145 | - method_exists($class, $method) |
|
| 1146 | - && call_user_func_array([$class, $method], $args) === false |
|
| 1147 | - ) |
|
| 1148 | - && ( |
|
| 1149 | - // is it a standalone function that doesn't work? |
|
| 1150 | - function_exists($method) |
|
| 1151 | - && call_user_func_array( |
|
| 1152 | - $func, |
|
| 1153 | - array_merge(['admin_page_object' => $this], $args) |
|
| 1154 | - ) === false |
|
| 1155 | - ) |
|
| 1156 | - ) |
|
| 1157 | - || ( |
|
| 1158 | - // is it neither a class method NOR a standalone function? |
|
| 1159 | - ! method_exists($class, $method) |
|
| 1160 | - && ! function_exists($method) |
|
| 1161 | - ) |
|
| 1162 | - ) { |
|
| 1163 | - // user error msg |
|
| 1164 | - $error_msg = esc_html__( |
|
| 1165 | - 'An error occurred. The requested page route could not be found.', |
|
| 1166 | - 'event_espresso' |
|
| 1167 | - ); |
|
| 1168 | - // developer error msg |
|
| 1169 | - $error_msg .= '||'; |
|
| 1170 | - $error_msg .= sprintf( |
|
| 1171 | - esc_html__( |
|
| 1172 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1173 | - 'event_espresso' |
|
| 1174 | - ), |
|
| 1175 | - $method |
|
| 1176 | - ); |
|
| 1177 | - } |
|
| 1178 | - if (! empty($error_msg)) { |
|
| 1179 | - throw new EE_Error($error_msg); |
|
| 1180 | - } |
|
| 1181 | - } |
|
| 1182 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1183 | - // then we need to reset the routing properties to the new route. |
|
| 1184 | - // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1185 | - if ( |
|
| 1186 | - $this->_is_UI_request === false |
|
| 1187 | - && is_array($this->_route) |
|
| 1188 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1189 | - ) { |
|
| 1190 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1191 | - } |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - /** |
|
| 1196 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1197 | - * route redirects to a headers route in its route config. |
|
| 1198 | - * |
|
| 1199 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1200 | - * @return void |
|
| 1201 | - * @throws ReflectionException |
|
| 1202 | - * @throws InvalidArgumentException |
|
| 1203 | - * @throws InvalidInterfaceException |
|
| 1204 | - * @throws InvalidDataTypeException |
|
| 1205 | - * @throws EE_Error |
|
| 1206 | - * @since 4.3.0 |
|
| 1207 | - */ |
|
| 1208 | - protected function _reset_routing_properties($new_route) |
|
| 1209 | - { |
|
| 1210 | - $this->_is_UI_request = true; |
|
| 1211 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1212 | - $this->request->setRequestParam('action', $new_route); |
|
| 1213 | - // rerun page setup |
|
| 1214 | - $this->_page_setup(); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * _add_query_arg |
|
| 1220 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1221 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1222 | - * |
|
| 1223 | - * @param array $args |
|
| 1224 | - * @param string $url |
|
| 1225 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1226 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1227 | - * Example usage: If the current page is: |
|
| 1228 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1229 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1230 | - * &_wpnonce=5467821 |
|
| 1231 | - * and you call: |
|
| 1232 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1233 | - * array( |
|
| 1234 | - * 'action' => 'resend_something', |
|
| 1235 | - * 'page=>espresso_registrations' |
|
| 1236 | - * ), |
|
| 1237 | - * $some_url, |
|
| 1238 | - * true |
|
| 1239 | - * ); |
|
| 1240 | - * It will produce a url in this structure: |
|
| 1241 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1242 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1243 | - * month_range]=March%202015 |
|
| 1244 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1245 | - * @return string |
|
| 1246 | - */ |
|
| 1247 | - public static function add_query_args_and_nonce( |
|
| 1248 | - $args = [], |
|
| 1249 | - $url = '', |
|
| 1250 | - $sticky = false, |
|
| 1251 | - $exclude_nonce = false |
|
| 1252 | - ) { |
|
| 1253 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1254 | - if ($sticky) { |
|
| 1255 | - /** @var RequestInterface $request */ |
|
| 1256 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1257 | - $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true); |
|
| 1258 | - $request->unSetServerParam('_wp_http_referer', true); |
|
| 1259 | - foreach ($request->requestParams() as $key => $value) { |
|
| 1260 | - // do not add nonces |
|
| 1261 | - if (strpos($key, 'nonce') !== false) { |
|
| 1262 | - continue; |
|
| 1263 | - } |
|
| 1264 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1267 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * This returns a generated link that will load the related help tab. |
|
| 1273 | - * |
|
| 1274 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1275 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1276 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1277 | - * @return string generated link |
|
| 1278 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1279 | - */ |
|
| 1280 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1281 | - { |
|
| 1282 | - return EEH_Template::get_help_tab_link( |
|
| 1283 | - $help_tab_id, |
|
| 1284 | - $this->page_slug, |
|
| 1285 | - $this->_req_action, |
|
| 1286 | - $icon_style, |
|
| 1287 | - $help_text |
|
| 1288 | - ); |
|
| 1289 | - } |
|
| 1290 | - |
|
| 1291 | - |
|
| 1292 | - /** |
|
| 1293 | - * _add_help_tabs |
|
| 1294 | - * Note child classes define their help tabs within the page_config array. |
|
| 1295 | - * |
|
| 1296 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1297 | - * @return void |
|
| 1298 | - * @throws DomainException |
|
| 1299 | - * @throws EE_Error |
|
| 1300 | - * @throws ReflectionException |
|
| 1301 | - */ |
|
| 1302 | - protected function _add_help_tabs() |
|
| 1303 | - { |
|
| 1304 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1305 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1306 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1307 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1308 | - // check that the callback given is valid |
|
| 1309 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1310 | - throw new EE_Error( |
|
| 1311 | - sprintf( |
|
| 1312 | - esc_html__( |
|
| 1313 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1314 | - 'event_espresso' |
|
| 1315 | - ), |
|
| 1316 | - $config['help_sidebar'], |
|
| 1317 | - $this->class_name |
|
| 1318 | - ) |
|
| 1319 | - ); |
|
| 1320 | - } |
|
| 1321 | - $content = apply_filters( |
|
| 1322 | - 'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar', |
|
| 1323 | - $this->{$config['help_sidebar']}() |
|
| 1324 | - ); |
|
| 1325 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1326 | - } |
|
| 1327 | - if (! isset($config['help_tabs'])) { |
|
| 1328 | - return; |
|
| 1329 | - } //no help tabs for this route |
|
| 1330 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1331 | - // we're here so there ARE help tabs! |
|
| 1332 | - // make sure we've got what we need |
|
| 1333 | - if (! isset($cfg['title'])) { |
|
| 1334 | - throw new EE_Error( |
|
| 1335 | - esc_html__( |
|
| 1336 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1337 | - 'event_espresso' |
|
| 1338 | - ) |
|
| 1339 | - ); |
|
| 1340 | - } |
|
| 1341 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1342 | - throw new EE_Error( |
|
| 1343 | - esc_html__( |
|
| 1344 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1345 | - 'event_espresso' |
|
| 1346 | - ) |
|
| 1347 | - ); |
|
| 1348 | - } |
|
| 1349 | - // first priority goes to content. |
|
| 1350 | - if (! empty($cfg['content'])) { |
|
| 1351 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1352 | - // second priority goes to filename |
|
| 1353 | - } elseif (! empty($cfg['filename'])) { |
|
| 1354 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1355 | - // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1356 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1357 | - . basename($this->_get_dir()) |
|
| 1358 | - . '/help_tabs/' |
|
| 1359 | - . $cfg['filename'] |
|
| 1360 | - . '.help_tab.php' : $file_path; |
|
| 1361 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1362 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1363 | - EE_Error::add_error( |
|
| 1364 | - sprintf( |
|
| 1365 | - esc_html__( |
|
| 1366 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1367 | - 'event_espresso' |
|
| 1368 | - ), |
|
| 1369 | - $tab_id, |
|
| 1370 | - key($config), |
|
| 1371 | - $file_path |
|
| 1372 | - ), |
|
| 1373 | - __FILE__, |
|
| 1374 | - __FUNCTION__, |
|
| 1375 | - __LINE__ |
|
| 1376 | - ); |
|
| 1377 | - return; |
|
| 1378 | - } |
|
| 1379 | - $template_args['admin_page_obj'] = $this; |
|
| 1380 | - $content = EEH_Template::display_template( |
|
| 1381 | - $file_path, |
|
| 1382 | - $template_args, |
|
| 1383 | - true |
|
| 1384 | - ); |
|
| 1385 | - } else { |
|
| 1386 | - $content = ''; |
|
| 1387 | - } |
|
| 1388 | - // check if callback is valid |
|
| 1389 | - if ( |
|
| 1390 | - empty($content) |
|
| 1391 | - && ( |
|
| 1392 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1393 | - ) |
|
| 1394 | - ) { |
|
| 1395 | - EE_Error::add_error( |
|
| 1396 | - sprintf( |
|
| 1397 | - esc_html__( |
|
| 1398 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1399 | - 'event_espresso' |
|
| 1400 | - ), |
|
| 1401 | - $cfg['title'] |
|
| 1402 | - ), |
|
| 1403 | - __FILE__, |
|
| 1404 | - __FUNCTION__, |
|
| 1405 | - __LINE__ |
|
| 1406 | - ); |
|
| 1407 | - return; |
|
| 1408 | - } |
|
| 1409 | - // setup config array for help tab method |
|
| 1410 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1411 | - $_ht = [ |
|
| 1412 | - 'id' => $id, |
|
| 1413 | - 'title' => $cfg['title'], |
|
| 1414 | - 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1415 | - 'content' => $content, |
|
| 1416 | - ]; |
|
| 1417 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - |
|
| 1423 | - /** |
|
| 1424 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1425 | - * |
|
| 1426 | - * @return void |
|
| 1427 | - * @throws ReflectionException |
|
| 1428 | - * @throws EE_Error |
|
| 1429 | - */ |
|
| 1430 | - protected function _add_qtips() |
|
| 1431 | - { |
|
| 1432 | - if (isset($this->_route_config['qtips'])) { |
|
| 1433 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1434 | - // load qtip loader |
|
| 1435 | - $path = [ |
|
| 1436 | - $this->_get_dir() . '/qtips/', |
|
| 1437 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1438 | - ]; |
|
| 1439 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - |
|
| 1444 | - /** |
|
| 1445 | - * _set_nav_tabs |
|
| 1446 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1447 | - * wish to add additional tabs or modify accordingly. |
|
| 1448 | - * |
|
| 1449 | - * @return void |
|
| 1450 | - * @throws InvalidArgumentException |
|
| 1451 | - * @throws InvalidInterfaceException |
|
| 1452 | - * @throws InvalidDataTypeException |
|
| 1453 | - */ |
|
| 1454 | - protected function _set_nav_tabs() |
|
| 1455 | - { |
|
| 1456 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1457 | - $i = 0; |
|
| 1458 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1459 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1460 | - continue; |
|
| 1461 | - } |
|
| 1462 | - // no nav tab for this config |
|
| 1463 | - // check for persistent flag |
|
| 1464 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1465 | - // nav tab is only to appear when route requested. |
|
| 1466 | - continue; |
|
| 1467 | - } |
|
| 1468 | - if (! $this->check_user_access($slug, true)) { |
|
| 1469 | - // no nav tab because current user does not have access. |
|
| 1470 | - continue; |
|
| 1471 | - } |
|
| 1472 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1473 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1474 | - 'url' => isset($config['nav']['url']) |
|
| 1475 | - ? $config['nav']['url'] |
|
| 1476 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1477 | - ['action' => $slug], |
|
| 1478 | - $this->_admin_base_url |
|
| 1479 | - ), |
|
| 1480 | - 'link_text' => isset($config['nav']['label']) |
|
| 1481 | - ? $config['nav']['label'] |
|
| 1482 | - : ucwords( |
|
| 1483 | - str_replace('_', ' ', $slug) |
|
| 1484 | - ), |
|
| 1485 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1486 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1487 | - ]; |
|
| 1488 | - $i++; |
|
| 1489 | - } |
|
| 1490 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1491 | - if (empty($this->_nav_tabs)) { |
|
| 1492 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1493 | - 'url' => $this->_admin_base_url, |
|
| 1494 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1495 | - 'css_class' => 'nav-tab-active', |
|
| 1496 | - 'order' => 10, |
|
| 1497 | - ]; |
|
| 1498 | - } |
|
| 1499 | - // now let's sort the tabs according to order |
|
| 1500 | - usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - |
|
| 1504 | - /** |
|
| 1505 | - * _set_current_labels |
|
| 1506 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1507 | - * property array |
|
| 1508 | - * |
|
| 1509 | - * @return void |
|
| 1510 | - */ |
|
| 1511 | - private function _set_current_labels() |
|
| 1512 | - { |
|
| 1513 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1514 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1515 | - if (is_array($text)) { |
|
| 1516 | - foreach ($text as $sublabel => $subtext) { |
|
| 1517 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1518 | - } |
|
| 1519 | - } else { |
|
| 1520 | - $this->_labels[ $label ] = $text; |
|
| 1521 | - } |
|
| 1522 | - } |
|
| 1523 | - } |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * verifies user access for this admin page |
|
| 1529 | - * |
|
| 1530 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1531 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1532 | - * return false if verify fail. |
|
| 1533 | - * @return bool |
|
| 1534 | - * @throws InvalidArgumentException |
|
| 1535 | - * @throws InvalidDataTypeException |
|
| 1536 | - * @throws InvalidInterfaceException |
|
| 1537 | - */ |
|
| 1538 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1539 | - { |
|
| 1540 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1541 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1542 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1543 | - && is_array($this->_page_routes[ $route_to_check ]) |
|
| 1544 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1545 | - ? $this->_page_routes[ $route_to_check ]['capability'] |
|
| 1546 | - : null; |
|
| 1547 | - |
|
| 1548 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1549 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1550 | - : $this->_route['capability']; |
|
| 1551 | - } else { |
|
| 1552 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1553 | - } |
|
| 1554 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1555 | - if ( |
|
| 1556 | - ! $this->request->isAjax() |
|
| 1557 | - && ( |
|
| 1558 | - ! function_exists('is_admin') |
|
| 1559 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1560 | - $capability, |
|
| 1561 | - $this->page_slug |
|
| 1562 | - . '_' |
|
| 1563 | - . $route_to_check, |
|
| 1564 | - $id |
|
| 1565 | - ) |
|
| 1566 | - ) |
|
| 1567 | - ) { |
|
| 1568 | - if ($verify_only) { |
|
| 1569 | - return false; |
|
| 1570 | - } |
|
| 1571 | - if (is_user_logged_in()) { |
|
| 1572 | - wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1573 | - } else { |
|
| 1574 | - return false; |
|
| 1575 | - } |
|
| 1576 | - } |
|
| 1577 | - return true; |
|
| 1578 | - } |
|
| 1579 | - |
|
| 1580 | - |
|
| 1581 | - /** |
|
| 1582 | - * @param string $box_id |
|
| 1583 | - * @param string $title |
|
| 1584 | - * @param callable|string|null $callback |
|
| 1585 | - * @param string|array|WP_Screen $screen |
|
| 1586 | - * @param string $context |
|
| 1587 | - * @param string $priority |
|
| 1588 | - * @param array|null $callback_args |
|
| 1589 | - */ |
|
| 1590 | - protected function addMetaBox( |
|
| 1591 | - string $box_id, |
|
| 1592 | - string $title, |
|
| 1593 | - $callback, |
|
| 1594 | - $screen, |
|
| 1595 | - string $context = 'normal', |
|
| 1596 | - string $priority = 'default', |
|
| 1597 | - ?array $callback_args = null |
|
| 1598 | - ) { |
|
| 1599 | - if (! is_callable($callback)) { |
|
| 1600 | - return; |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
|
| 1604 | - add_filter( |
|
| 1605 | - "postbox_classes_{$this->_wp_page_slug}_{$box_id}", |
|
| 1606 | - function ($classes) { |
|
| 1607 | - array_push($classes, 'ee-admin-container'); |
|
| 1608 | - return $classes; |
|
| 1609 | - } |
|
| 1610 | - ); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - |
|
| 1614 | - /** |
|
| 1615 | - * admin_init_global |
|
| 1616 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1617 | - * This method executes for ALL EE Admin pages. |
|
| 1618 | - * |
|
| 1619 | - * @return void |
|
| 1620 | - */ |
|
| 1621 | - public function admin_init_global() |
|
| 1622 | - { |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - |
|
| 1626 | - /** |
|
| 1627 | - * wp_loaded_global |
|
| 1628 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1629 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1630 | - * |
|
| 1631 | - * @return void |
|
| 1632 | - */ |
|
| 1633 | - public function wp_loaded() |
|
| 1634 | - { |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - /** |
|
| 1639 | - * admin_notices |
|
| 1640 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1641 | - * ALL EE_Admin pages. |
|
| 1642 | - * |
|
| 1643 | - * @return void |
|
| 1644 | - */ |
|
| 1645 | - public function admin_notices_global() |
|
| 1646 | - { |
|
| 1647 | - $this->_display_no_javascript_warning(); |
|
| 1648 | - $this->_display_espresso_notices(); |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - |
|
| 1652 | - public function network_admin_notices_global() |
|
| 1653 | - { |
|
| 1654 | - $this->_display_no_javascript_warning(); |
|
| 1655 | - $this->_display_espresso_notices(); |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - /** |
|
| 1660 | - * admin_footer_scripts_global |
|
| 1661 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1662 | - * will apply on ALL EE_Admin pages. |
|
| 1663 | - * |
|
| 1664 | - * @return void |
|
| 1665 | - */ |
|
| 1666 | - public function admin_footer_scripts_global() |
|
| 1667 | - { |
|
| 1668 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1669 | - $this->_add_admin_page_overlay(); |
|
| 1670 | - // if metaboxes are present we need to add the nonce field |
|
| 1671 | - if ( |
|
| 1672 | - isset($this->_route_config['metaboxes']) |
|
| 1673 | - || isset($this->_route_config['list_table']) |
|
| 1674 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1675 | - ) { |
|
| 1676 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1677 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1678 | - } |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - |
|
| 1682 | - /** |
|
| 1683 | - * admin_footer_global |
|
| 1684 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1685 | - * This particular method will apply on ALL EE_Admin Pages. |
|
| 1686 | - * |
|
| 1687 | - * @return void |
|
| 1688 | - */ |
|
| 1689 | - public function admin_footer_global() |
|
| 1690 | - { |
|
| 1691 | - // dialog container for dialog helper |
|
| 1692 | - echo ' |
|
| 141 | + /** |
|
| 142 | + * unprocessed value for the 'page' request param (default '') |
|
| 143 | + * |
|
| 144 | + * @var string |
|
| 145 | + */ |
|
| 146 | + protected $raw_req_page = ''; |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * sanitized request action (and nonce) |
|
| 150 | + * |
|
| 151 | + * @var string |
|
| 152 | + */ |
|
| 153 | + protected $_req_action = ''; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * sanitized request action nonce |
|
| 157 | + * |
|
| 158 | + * @var string |
|
| 159 | + */ |
|
| 160 | + protected $_req_nonce = ''; |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @var string |
|
| 164 | + */ |
|
| 165 | + protected $_search_btn_label = ''; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @var string |
|
| 169 | + */ |
|
| 170 | + protected $_search_box_callback = ''; |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @var WP_Screen |
|
| 174 | + */ |
|
| 175 | + protected $_current_screen; |
|
| 176 | + |
|
| 177 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 178 | + protected $_hook_obj; |
|
| 179 | + |
|
| 180 | + // for holding incoming request data |
|
| 181 | + protected $_req_data = []; |
|
| 182 | + |
|
| 183 | + // yes / no array for admin form fields |
|
| 184 | + protected $_yes_no_values = []; |
|
| 185 | + |
|
| 186 | + // some default things shared by all child classes |
|
| 187 | + protected $_default_espresso_metaboxes = [ |
|
| 188 | + '_espresso_news_post_box', |
|
| 189 | + '_espresso_links_post_box', |
|
| 190 | + '_espresso_ratings_request', |
|
| 191 | + '_espresso_sponsors_post_box', |
|
| 192 | + ]; |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @var EE_Registry |
|
| 196 | + */ |
|
| 197 | + protected $EE; |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 202 | + * |
|
| 203 | + * @var boolean |
|
| 204 | + */ |
|
| 205 | + protected $_is_caf = false; |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * whether or not initializePage() has run |
|
| 209 | + * |
|
| 210 | + * @var boolean |
|
| 211 | + */ |
|
| 212 | + protected $initialized = false; |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @var FeatureFlags |
|
| 216 | + */ |
|
| 217 | + protected $feature; |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @var string |
|
| 222 | + */ |
|
| 223 | + protected $class_name; |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * if the current class is an admin page extension, like: Extend_Events_Admin_Page, |
|
| 227 | + * then this would be the parent classname: Events_Admin_Page |
|
| 228 | + * |
|
| 229 | + * @var string |
|
| 230 | + */ |
|
| 231 | + protected $base_class_name; |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @Constructor |
|
| 236 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 237 | + * @throws InvalidArgumentException |
|
| 238 | + * @throws InvalidDataTypeException |
|
| 239 | + * @throws InvalidInterfaceException |
|
| 240 | + * @throws ReflectionException |
|
| 241 | + */ |
|
| 242 | + public function __construct($routing = true) |
|
| 243 | + { |
|
| 244 | + $this->loader = LoaderFactory::getLoader(); |
|
| 245 | + $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 246 | + $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 247 | + $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 248 | + // routing enabled? |
|
| 249 | + $this->_routing = $routing; |
|
| 250 | + |
|
| 251 | + $this->class_name = get_class($this); |
|
| 252 | + $this->base_class_name = strpos($this->class_name, 'Extend_') === 0 |
|
| 253 | + ? str_replace('Extend_', '', $this->class_name) |
|
| 254 | + : ''; |
|
| 255 | + |
|
| 256 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 257 | + $this->_is_caf = true; |
|
| 258 | + } |
|
| 259 | + $this->_yes_no_values = [ |
|
| 260 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 261 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 262 | + ]; |
|
| 263 | + // set the _req_data property. |
|
| 264 | + $this->_req_data = $this->request->requestParams(); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @return EE_Admin_Config |
|
| 270 | + */ |
|
| 271 | + public function adminConfig(): EE_Admin_Config |
|
| 272 | + { |
|
| 273 | + return $this->admin_config; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @return FeatureFlags |
|
| 279 | + */ |
|
| 280 | + public function feature(): FeatureFlags |
|
| 281 | + { |
|
| 282 | + return $this->feature; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 288 | + * for child classes that needed to set properties prior to these methods getting called, |
|
| 289 | + * but also needed the parent class to have its construction completed as well. |
|
| 290 | + * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 291 | + * and any complex initialization logic should only run after instantiation is complete. |
|
| 292 | + * |
|
| 293 | + * This method gets called immediately after construction from within |
|
| 294 | + * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 295 | + * |
|
| 296 | + * @throws EE_Error |
|
| 297 | + * @throws InvalidArgumentException |
|
| 298 | + * @throws InvalidDataTypeException |
|
| 299 | + * @throws InvalidInterfaceException |
|
| 300 | + * @throws ReflectionException |
|
| 301 | + * @since $VID:$ |
|
| 302 | + */ |
|
| 303 | + public function initializePage() |
|
| 304 | + { |
|
| 305 | + if ($this->initialized) { |
|
| 306 | + return; |
|
| 307 | + } |
|
| 308 | + // set initial page props (child method) |
|
| 309 | + $this->_init_page_props(); |
|
| 310 | + // set global defaults |
|
| 311 | + $this->_set_defaults(); |
|
| 312 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 313 | + $this->_global_ajax_hooks(); |
|
| 314 | + $this->_ajax_hooks(); |
|
| 315 | + // other_page_hooks have to be early too. |
|
| 316 | + $this->_do_other_page_hooks(); |
|
| 317 | + // set up page dependencies |
|
| 318 | + $this->_before_page_setup(); |
|
| 319 | + $this->_page_setup(); |
|
| 320 | + $this->initialized = true; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * _init_page_props |
|
| 326 | + * Child classes use to set at least the following properties: |
|
| 327 | + * $page_slug. |
|
| 328 | + * $page_label. |
|
| 329 | + * |
|
| 330 | + * @abstract |
|
| 331 | + * @return void |
|
| 332 | + */ |
|
| 333 | + abstract protected function _init_page_props(); |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * _ajax_hooks |
|
| 338 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 339 | + * Note: within the ajax callback methods. |
|
| 340 | + * |
|
| 341 | + * @abstract |
|
| 342 | + * @return void |
|
| 343 | + */ |
|
| 344 | + abstract protected function _ajax_hooks(); |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * _define_page_props |
|
| 349 | + * child classes define page properties in here. Must include at least: |
|
| 350 | + * $_admin_base_url = base_url for all admin pages |
|
| 351 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 352 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 353 | + * array( |
|
| 354 | + * 'buttons' => array( |
|
| 355 | + * 'add' => esc_html__('label for add new button'), |
|
| 356 | + * 'edit' => esc_html__('label for edit button'), |
|
| 357 | + * 'delete' => esc_html__('label for delete button') |
|
| 358 | + * ) |
|
| 359 | + * ) |
|
| 360 | + * |
|
| 361 | + * @abstract |
|
| 362 | + * @return void |
|
| 363 | + */ |
|
| 364 | + abstract protected function _define_page_props(); |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * _set_page_routes |
|
| 369 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 370 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 371 | + * have a 'default' route. Here's the format |
|
| 372 | + * $this->_page_routes = array( |
|
| 373 | + * 'default' => array( |
|
| 374 | + * 'func' => '_default_method_handling_route', |
|
| 375 | + * 'args' => array('array','of','args'), |
|
| 376 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 377 | + * ajax request, backend processing) |
|
| 378 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 379 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 380 | + * headers sent route. |
|
| 381 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 382 | + * this route. |
|
| 383 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 384 | + * checks). |
|
| 385 | + * ), |
|
| 386 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 387 | + * handling method. |
|
| 388 | + * ) |
|
| 389 | + * ) |
|
| 390 | + * |
|
| 391 | + * @abstract |
|
| 392 | + * @return void |
|
| 393 | + */ |
|
| 394 | + abstract protected function _set_page_routes(); |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * _set_page_config |
|
| 399 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 400 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 401 | + * $this->_page_config = array( |
|
| 402 | + * 'default' => array( |
|
| 403 | + * 'labels' => array( |
|
| 404 | + * 'buttons' => array( |
|
| 405 | + * 'add' => esc_html__('label for adding item'), |
|
| 406 | + * 'edit' => esc_html__('label for editing item'), |
|
| 407 | + * 'delete' => esc_html__('label for deleting item') |
|
| 408 | + * ), |
|
| 409 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 410 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 411 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 412 | + * _define_page_props() method |
|
| 413 | + * 'nav' => array( |
|
| 414 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 415 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 416 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 417 | + * 'order' => 10, //required to indicate tab position. |
|
| 418 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 419 | + * displayed then add this parameter. |
|
| 420 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 421 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 422 | + * metaboxes set for eventespresso admin pages. |
|
| 423 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 424 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 425 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 426 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 427 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 428 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 429 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 430 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 431 | + * want to display. |
|
| 432 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 433 | + * 'tab_id' => array( |
|
| 434 | + * 'title' => 'tab_title', |
|
| 435 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 436 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 437 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 438 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 439 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 440 | + * attempt to use the callback which should match the name of a method in the class |
|
| 441 | + * ), |
|
| 442 | + * 'tab2_id' => array( |
|
| 443 | + * 'title' => 'tab2 title', |
|
| 444 | + * 'filename' => 'file_name_2' |
|
| 445 | + * 'callback' => 'callback_method_for_content', |
|
| 446 | + * ), |
|
| 447 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 448 | + * help tab area on an admin page. @return void |
|
| 449 | + * |
|
| 450 | + * @abstract |
|
| 451 | + */ |
|
| 452 | + abstract protected function _set_page_config(); |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * _add_screen_options |
|
| 457 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 458 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 459 | + * to a particular view. |
|
| 460 | + * |
|
| 461 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 462 | + * see also WP_Screen object documents... |
|
| 463 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 464 | + * @abstract |
|
| 465 | + * @return void |
|
| 466 | + */ |
|
| 467 | + abstract protected function _add_screen_options(); |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * _add_feature_pointers |
|
| 472 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 473 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 474 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 475 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 476 | + * extended) also see: |
|
| 477 | + * |
|
| 478 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 479 | + * @abstract |
|
| 480 | + * @return void |
|
| 481 | + */ |
|
| 482 | + abstract protected function _add_feature_pointers(); |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * load_scripts_styles |
|
| 487 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 488 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 489 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 490 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 491 | + * |
|
| 492 | + * @abstract |
|
| 493 | + * @return void |
|
| 494 | + */ |
|
| 495 | + abstract public function load_scripts_styles(); |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * admin_init |
|
| 500 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 501 | + * all pages/views loaded by child class. |
|
| 502 | + * |
|
| 503 | + * @abstract |
|
| 504 | + * @return void |
|
| 505 | + */ |
|
| 506 | + abstract public function admin_init(); |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * admin_notices |
|
| 511 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 512 | + * all pages/views loaded by child class. |
|
| 513 | + * |
|
| 514 | + * @abstract |
|
| 515 | + * @return void |
|
| 516 | + */ |
|
| 517 | + abstract public function admin_notices(); |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * admin_footer_scripts |
|
| 522 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 523 | + * will apply to all pages/views loaded by child class. |
|
| 524 | + * |
|
| 525 | + * @return void |
|
| 526 | + */ |
|
| 527 | + abstract public function admin_footer_scripts(); |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * admin_footer |
|
| 532 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 533 | + * apply to all pages/views loaded by child class. |
|
| 534 | + * |
|
| 535 | + * @return void |
|
| 536 | + */ |
|
| 537 | + public function admin_footer() |
|
| 538 | + { |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * _global_ajax_hooks |
|
| 544 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 545 | + * Note: within the ajax callback methods. |
|
| 546 | + * |
|
| 547 | + * @abstract |
|
| 548 | + * @return void |
|
| 549 | + */ |
|
| 550 | + protected function _global_ajax_hooks() |
|
| 551 | + { |
|
| 552 | + // for lazy loading of metabox content |
|
| 553 | + add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 554 | + |
|
| 555 | + add_action( |
|
| 556 | + 'wp_ajax_espresso_hide_status_change_notice', |
|
| 557 | + [$this, 'hideStatusChangeNotice'] |
|
| 558 | + ); |
|
| 559 | + add_action( |
|
| 560 | + 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 561 | + [$this, 'hideStatusChangeNotice'] |
|
| 562 | + ); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + public function ajax_metabox_content() |
|
| 567 | + { |
|
| 568 | + $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 569 | + $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 570 | + EE_Admin_Page::cached_rss_display($content_id, $content_url); |
|
| 571 | + wp_die(); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + public function hideStatusChangeNotice() |
|
| 576 | + { |
|
| 577 | + $response = []; |
|
| 578 | + try { |
|
| 579 | + /** @var StatusChangeNotice $status_change_notice */ |
|
| 580 | + $status_change_notice = $this->loader->getShared( |
|
| 581 | + 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 582 | + ); |
|
| 583 | + $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 584 | + } catch (Exception $exception) { |
|
| 585 | + $response['errors'] = $exception->getMessage(); |
|
| 586 | + } |
|
| 587 | + echo wp_json_encode($response); |
|
| 588 | + exit(); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 594 | + * |
|
| 595 | + * @return void |
|
| 596 | + */ |
|
| 597 | + protected function _before_page_setup() |
|
| 598 | + { |
|
| 599 | + // default is to do nothing |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Makes sure any things that need to be loaded early get handled. |
|
| 605 | + * We also escape early here if the page requested doesn't match the object. |
|
| 606 | + * |
|
| 607 | + * @final |
|
| 608 | + * @return void |
|
| 609 | + * @throws EE_Error |
|
| 610 | + * @throws InvalidArgumentException |
|
| 611 | + * @throws ReflectionException |
|
| 612 | + * @throws InvalidDataTypeException |
|
| 613 | + * @throws InvalidInterfaceException |
|
| 614 | + */ |
|
| 615 | + final protected function _page_setup() |
|
| 616 | + { |
|
| 617 | + // requires? |
|
| 618 | + // admin_init stuff - global - we're setting this REALLY early |
|
| 619 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 620 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 621 | + add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 622 | + // next verify if we need to load anything... |
|
| 623 | + $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 624 | + $this->page_folder = strtolower( |
|
| 625 | + str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name) |
|
| 626 | + ); |
|
| 627 | + global $ee_menu_slugs; |
|
| 628 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 629 | + if ( |
|
| 630 | + ! $this->request->isAjax() |
|
| 631 | + && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 632 | + ) { |
|
| 633 | + return; |
|
| 634 | + } |
|
| 635 | + // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 636 | + // we need to copy the action from the second to the first |
|
| 637 | + $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 638 | + $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 639 | + $action = $action !== '-1' ? $action : $action2; |
|
| 640 | + $req_action = $action !== '-1' ? $action : 'default'; |
|
| 641 | + |
|
| 642 | + // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 643 | + // then let's use the route as the action. |
|
| 644 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 645 | + $route = $this->request->getRequestParam('route'); |
|
| 646 | + $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 647 | + ? $route |
|
| 648 | + : $req_action; |
|
| 649 | + |
|
| 650 | + $this->_current_view = $this->_req_action; |
|
| 651 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 652 | + $this->_define_page_props(); |
|
| 653 | + $this->_current_page_view_url = add_query_arg( |
|
| 654 | + ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 655 | + $this->_admin_base_url |
|
| 656 | + ); |
|
| 657 | + // set page configs |
|
| 658 | + $this->_set_page_routes(); |
|
| 659 | + $this->_set_page_config(); |
|
| 660 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 661 | + if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 662 | + $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 663 | + if ($wp_referer) { |
|
| 664 | + $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + // for caffeinated and other extended functionality. |
|
| 668 | + // If there is a _extend_page_config method |
|
| 669 | + // then let's run that to modify the all the various page configuration arrays |
|
| 670 | + if (method_exists($this, '_extend_page_config')) { |
|
| 671 | + $this->_extend_page_config(); |
|
| 672 | + } |
|
| 673 | + // for CPT and other extended functionality. |
|
| 674 | + // If there is an _extend_page_config_for_cpt |
|
| 675 | + // then let's run that to modify all the various page configuration arrays. |
|
| 676 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 677 | + $this->_extend_page_config_for_cpt(); |
|
| 678 | + } |
|
| 679 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 680 | + $this->_page_routes = apply_filters( |
|
| 681 | + 'FHEE__' . $this->class_name . '__page_setup__page_routes', |
|
| 682 | + $this->_page_routes, |
|
| 683 | + $this |
|
| 684 | + ); |
|
| 685 | + $this->_page_config = apply_filters( |
|
| 686 | + 'FHEE__' . $this->class_name . '__page_setup__page_config', |
|
| 687 | + $this->_page_config, |
|
| 688 | + $this |
|
| 689 | + ); |
|
| 690 | + if ($this->base_class_name !== '') { |
|
| 691 | + $this->_page_routes = apply_filters( |
|
| 692 | + 'FHEE__' . $this->base_class_name . '__page_setup__page_routes', |
|
| 693 | + $this->_page_routes, |
|
| 694 | + $this |
|
| 695 | + ); |
|
| 696 | + $this->_page_config = apply_filters( |
|
| 697 | + 'FHEE__' . $this->base_class_name . '__page_setup__page_config', |
|
| 698 | + $this->_page_config, |
|
| 699 | + $this |
|
| 700 | + ); |
|
| 701 | + } |
|
| 702 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 703 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 704 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 705 | + add_action( |
|
| 706 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 707 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 708 | + 10, |
|
| 709 | + 2 |
|
| 710 | + ); |
|
| 711 | + } |
|
| 712 | + // next route only if routing enabled |
|
| 713 | + if ($this->_routing && ! $this->request->isAjax()) { |
|
| 714 | + $this->_verify_routes(); |
|
| 715 | + // next let's just check user_access and kill if no access |
|
| 716 | + $this->check_user_access(); |
|
| 717 | + if ($this->_is_UI_request) { |
|
| 718 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 719 | + add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 720 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 721 | + add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 722 | + } |
|
| 723 | + } else { |
|
| 724 | + // hijack regular WP loading and route admin request immediately |
|
| 725 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 726 | + $this->route_admin_request(); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 734 | + * |
|
| 735 | + * @return void |
|
| 736 | + * @throws EE_Error |
|
| 737 | + */ |
|
| 738 | + private function _do_other_page_hooks() |
|
| 739 | + { |
|
| 740 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 741 | + foreach ($registered_pages as $page) { |
|
| 742 | + // now let's setup the file name and class that should be present |
|
| 743 | + $classname = str_replace('.class.php', '', $page); |
|
| 744 | + // autoloaders should take care of loading file |
|
| 745 | + if (! class_exists($classname)) { |
|
| 746 | + $error_msg[] = sprintf( |
|
| 747 | + esc_html__( |
|
| 748 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 749 | + 'event_espresso' |
|
| 750 | + ), |
|
| 751 | + $page |
|
| 752 | + ); |
|
| 753 | + $error_msg[] = $error_msg[0] |
|
| 754 | + . "\r\n" |
|
| 755 | + . sprintf( |
|
| 756 | + esc_html__( |
|
| 757 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 758 | + 'event_espresso' |
|
| 759 | + ), |
|
| 760 | + $page, |
|
| 761 | + '<br />', |
|
| 762 | + '<strong>' . $classname . '</strong>' |
|
| 763 | + ); |
|
| 764 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 765 | + } |
|
| 766 | + // notice we are passing the instance of this class to the hook object. |
|
| 767 | + $this->loader->getShared($classname, [$this]); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * @throws ReflectionException |
|
| 774 | + * @throws EE_Error |
|
| 775 | + */ |
|
| 776 | + public function load_page_dependencies() |
|
| 777 | + { |
|
| 778 | + try { |
|
| 779 | + $this->_load_page_dependencies(); |
|
| 780 | + } catch (EE_Error $e) { |
|
| 781 | + $e->get_error(); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + /** |
|
| 787 | + * load_page_dependencies |
|
| 788 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 789 | + * |
|
| 790 | + * @return void |
|
| 791 | + * @throws DomainException |
|
| 792 | + * @throws EE_Error |
|
| 793 | + * @throws InvalidArgumentException |
|
| 794 | + * @throws InvalidDataTypeException |
|
| 795 | + * @throws InvalidInterfaceException |
|
| 796 | + */ |
|
| 797 | + protected function _load_page_dependencies() |
|
| 798 | + { |
|
| 799 | + // let's set the current_screen and screen options to override what WP set |
|
| 800 | + $this->_current_screen = get_current_screen(); |
|
| 801 | + // load admin_notices - global, page class, and view specific |
|
| 802 | + add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 803 | + add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 804 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 805 | + add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 806 | + } |
|
| 807 | + // load network admin_notices - global, page class, and view specific |
|
| 808 | + add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 809 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 810 | + add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 811 | + } |
|
| 812 | + // this will save any per_page screen options if they are present |
|
| 813 | + $this->_set_per_page_screen_options(); |
|
| 814 | + // setup list table properties |
|
| 815 | + $this->_set_list_table(); |
|
| 816 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 817 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 818 | + $this->_add_registered_meta_boxes(); |
|
| 819 | + $this->_add_screen_columns(); |
|
| 820 | + // add screen options - global, page child class, and view specific |
|
| 821 | + $this->_add_global_screen_options(); |
|
| 822 | + $this->_add_screen_options(); |
|
| 823 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 824 | + if (method_exists($this, $add_screen_options)) { |
|
| 825 | + $this->{$add_screen_options}(); |
|
| 826 | + } |
|
| 827 | + // add help tab(s) - set via page_config and qtips. |
|
| 828 | + $this->_add_help_tabs(); |
|
| 829 | + $this->_add_qtips(); |
|
| 830 | + // add feature_pointers - global, page child class, and view specific |
|
| 831 | + $this->_add_feature_pointers(); |
|
| 832 | + $this->_add_global_feature_pointers(); |
|
| 833 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 834 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 835 | + $this->{$add_feature_pointer}(); |
|
| 836 | + } |
|
| 837 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 838 | + add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 839 | + add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 840 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 841 | + add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 842 | + } |
|
| 843 | + add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 844 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 845 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 846 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 847 | + // is a good use case. Notice the late priority we're giving these |
|
| 848 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 849 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 850 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 851 | + add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 852 | + } |
|
| 853 | + // admin footer scripts |
|
| 854 | + add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 855 | + add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 856 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 857 | + add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 858 | + } |
|
| 859 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 860 | + // targeted hook |
|
| 861 | + do_action( |
|
| 862 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 863 | + ); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * _set_defaults |
|
| 869 | + * This sets some global defaults for class properties. |
|
| 870 | + */ |
|
| 871 | + private function _set_defaults() |
|
| 872 | + { |
|
| 873 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 874 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 875 | + $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 876 | + $this->_page_config = $this->_default_route_query_args = []; |
|
| 877 | + $this->_default_nav_tab_name = 'overview'; |
|
| 878 | + // init template args |
|
| 879 | + $this->_template_args = [ |
|
| 880 | + 'admin_page_header' => '', |
|
| 881 | + 'admin_page_content' => '', |
|
| 882 | + 'post_body_content' => '', |
|
| 883 | + 'before_list_table' => '', |
|
| 884 | + 'after_list_table' => '', |
|
| 885 | + ]; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * route_admin_request |
|
| 891 | + * |
|
| 892 | + * @return void |
|
| 893 | + * @throws InvalidArgumentException |
|
| 894 | + * @throws InvalidInterfaceException |
|
| 895 | + * @throws InvalidDataTypeException |
|
| 896 | + * @throws EE_Error |
|
| 897 | + * @throws ReflectionException |
|
| 898 | + * @see _route_admin_request() |
|
| 899 | + */ |
|
| 900 | + public function route_admin_request() |
|
| 901 | + { |
|
| 902 | + try { |
|
| 903 | + $this->_route_admin_request(); |
|
| 904 | + } catch (EE_Error $e) { |
|
| 905 | + $e->get_error(); |
|
| 906 | + } |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + public function set_wp_page_slug($wp_page_slug) |
|
| 911 | + { |
|
| 912 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 913 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 914 | + if (is_network_admin()) { |
|
| 915 | + $this->_wp_page_slug .= '-network'; |
|
| 916 | + } |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * _verify_routes |
|
| 922 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 923 | + * we know if we need to drop out. |
|
| 924 | + * |
|
| 925 | + * @return bool |
|
| 926 | + * @throws EE_Error |
|
| 927 | + */ |
|
| 928 | + protected function _verify_routes() |
|
| 929 | + { |
|
| 930 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 931 | + if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 932 | + return false; |
|
| 933 | + } |
|
| 934 | + $this->_route = false; |
|
| 935 | + // check that the page_routes array is not empty |
|
| 936 | + if (empty($this->_page_routes)) { |
|
| 937 | + // user error msg |
|
| 938 | + $error_msg = sprintf( |
|
| 939 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 940 | + $this->_admin_page_title |
|
| 941 | + ); |
|
| 942 | + // developer error msg |
|
| 943 | + $error_msg .= '||' . $error_msg |
|
| 944 | + . esc_html__( |
|
| 945 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 946 | + 'event_espresso' |
|
| 947 | + ); |
|
| 948 | + throw new EE_Error($error_msg); |
|
| 949 | + } |
|
| 950 | + // and that the requested page route exists |
|
| 951 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 952 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 953 | + $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 954 | + } else { |
|
| 955 | + // user error msg |
|
| 956 | + $error_msg = sprintf( |
|
| 957 | + esc_html__( |
|
| 958 | + 'The requested page route does not exist for the %s admin page.', |
|
| 959 | + 'event_espresso' |
|
| 960 | + ), |
|
| 961 | + $this->_admin_page_title |
|
| 962 | + ); |
|
| 963 | + // developer error msg |
|
| 964 | + $error_msg .= '||' . $error_msg |
|
| 965 | + . sprintf( |
|
| 966 | + esc_html__( |
|
| 967 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 968 | + 'event_espresso' |
|
| 969 | + ), |
|
| 970 | + $this->_req_action |
|
| 971 | + ); |
|
| 972 | + throw new EE_Error($error_msg); |
|
| 973 | + } |
|
| 974 | + // and that a default route exists |
|
| 975 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 976 | + // user error msg |
|
| 977 | + $error_msg = sprintf( |
|
| 978 | + esc_html__( |
|
| 979 | + 'A default page route has not been set for the % admin page.', |
|
| 980 | + 'event_espresso' |
|
| 981 | + ), |
|
| 982 | + $this->_admin_page_title |
|
| 983 | + ); |
|
| 984 | + // developer error msg |
|
| 985 | + $error_msg .= '||' . $error_msg |
|
| 986 | + . esc_html__( |
|
| 987 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 988 | + 'event_espresso' |
|
| 989 | + ); |
|
| 990 | + throw new EE_Error($error_msg); |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + // first lets' catch if the UI request has EVER been set. |
|
| 994 | + if ($this->_is_UI_request === null) { |
|
| 995 | + // lets set if this is a UI request or not. |
|
| 996 | + $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 997 | + // wait a minute... we might have a noheader in the route array |
|
| 998 | + $this->_is_UI_request = ! ( |
|
| 999 | + is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 1000 | + ) |
|
| 1001 | + ? $this->_is_UI_request |
|
| 1002 | + : false; |
|
| 1003 | + } |
|
| 1004 | + $this->_set_current_labels(); |
|
| 1005 | + return true; |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + |
|
| 1009 | + /** |
|
| 1010 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 1011 | + * |
|
| 1012 | + * @param string $route the route name we're verifying |
|
| 1013 | + * @return bool we'll throw an exception if this isn't a valid route. |
|
| 1014 | + * @throws EE_Error |
|
| 1015 | + */ |
|
| 1016 | + protected function _verify_route($route) |
|
| 1017 | + { |
|
| 1018 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 1019 | + return true; |
|
| 1020 | + } |
|
| 1021 | + // user error msg |
|
| 1022 | + $error_msg = sprintf( |
|
| 1023 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 1024 | + $this->_admin_page_title |
|
| 1025 | + ); |
|
| 1026 | + // developer error msg |
|
| 1027 | + $error_msg .= '||' . $error_msg |
|
| 1028 | + . sprintf( |
|
| 1029 | + esc_html__( |
|
| 1030 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 1031 | + 'event_espresso' |
|
| 1032 | + ), |
|
| 1033 | + $route |
|
| 1034 | + ); |
|
| 1035 | + throw new EE_Error($error_msg); |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + |
|
| 1039 | + /** |
|
| 1040 | + * perform nonce verification |
|
| 1041 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 1042 | + * using this method (and save retyping!) |
|
| 1043 | + * |
|
| 1044 | + * @param string $nonce The nonce sent |
|
| 1045 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 1046 | + * @return void |
|
| 1047 | + * @throws EE_Error |
|
| 1048 | + * @throws InvalidArgumentException |
|
| 1049 | + * @throws InvalidDataTypeException |
|
| 1050 | + * @throws InvalidInterfaceException |
|
| 1051 | + */ |
|
| 1052 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 1053 | + { |
|
| 1054 | + // verify nonce against expected value |
|
| 1055 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1056 | + // these are not the droids you are looking for !!! |
|
| 1057 | + $msg = sprintf( |
|
| 1058 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1059 | + '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1060 | + '</a>' |
|
| 1061 | + ); |
|
| 1062 | + if (WP_DEBUG) { |
|
| 1063 | + $msg .= "\n "; |
|
| 1064 | + $msg .= sprintf( |
|
| 1065 | + esc_html__( |
|
| 1066 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1067 | + 'event_espresso' |
|
| 1068 | + ), |
|
| 1069 | + __CLASS__ |
|
| 1070 | + ); |
|
| 1071 | + } |
|
| 1072 | + if (! $this->request->isAjax()) { |
|
| 1073 | + wp_die($msg); |
|
| 1074 | + } |
|
| 1075 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1076 | + $this->_return_json(); |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * _route_admin_request() |
|
| 1083 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1084 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1085 | + * in the page routes and then will try to load the corresponding method. |
|
| 1086 | + * |
|
| 1087 | + * @return void |
|
| 1088 | + * @throws EE_Error |
|
| 1089 | + * @throws InvalidArgumentException |
|
| 1090 | + * @throws InvalidDataTypeException |
|
| 1091 | + * @throws InvalidInterfaceException |
|
| 1092 | + * @throws ReflectionException |
|
| 1093 | + */ |
|
| 1094 | + protected function _route_admin_request() |
|
| 1095 | + { |
|
| 1096 | + if (! $this->_is_UI_request) { |
|
| 1097 | + $this->_verify_routes(); |
|
| 1098 | + } |
|
| 1099 | + $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1100 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1101 | + // set nonce from post data |
|
| 1102 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1103 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1104 | + } |
|
| 1105 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 1106 | + if ($this->_is_UI_request) { |
|
| 1107 | + $this->_set_nav_tabs(); |
|
| 1108 | + } |
|
| 1109 | + // grab callback function |
|
| 1110 | + $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route; |
|
| 1111 | + // check if callback has args |
|
| 1112 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 1113 | + $error_msg = ''; |
|
| 1114 | + // action right before calling route |
|
| 1115 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1116 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1117 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1118 | + } |
|
| 1119 | + // strip _wp_http_referer from the server REQUEST_URI |
|
| 1120 | + // else it grows in length on every submission due to recursion, |
|
| 1121 | + // ultimately causing a "Request-URI Too Large" error |
|
| 1122 | + $request_uri = remove_query_arg( |
|
| 1123 | + '_wp_http_referer', |
|
| 1124 | + wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1125 | + ); |
|
| 1126 | + // set new value in both our Request object and the super global |
|
| 1127 | + $this->request->setServerParam('REQUEST_URI', $request_uri, true); |
|
| 1128 | + if (! empty($func)) { |
|
| 1129 | + if (is_array($func)) { |
|
| 1130 | + [$class, $method] = $func; |
|
| 1131 | + } elseif (strpos($func, '::') !== false) { |
|
| 1132 | + [$class, $method] = explode('::', $func); |
|
| 1133 | + } else { |
|
| 1134 | + $class = $this; |
|
| 1135 | + $method = $func; |
|
| 1136 | + } |
|
| 1137 | + if (! (is_object($class) && $class === $this)) { |
|
| 1138 | + // send along this admin page object for access by addons. |
|
| 1139 | + $args['admin_page_object'] = $this; |
|
| 1140 | + } |
|
| 1141 | + if ( |
|
| 1142 | + // is it a method on a class that doesn't work? |
|
| 1143 | + ( |
|
| 1144 | + ( |
|
| 1145 | + method_exists($class, $method) |
|
| 1146 | + && call_user_func_array([$class, $method], $args) === false |
|
| 1147 | + ) |
|
| 1148 | + && ( |
|
| 1149 | + // is it a standalone function that doesn't work? |
|
| 1150 | + function_exists($method) |
|
| 1151 | + && call_user_func_array( |
|
| 1152 | + $func, |
|
| 1153 | + array_merge(['admin_page_object' => $this], $args) |
|
| 1154 | + ) === false |
|
| 1155 | + ) |
|
| 1156 | + ) |
|
| 1157 | + || ( |
|
| 1158 | + // is it neither a class method NOR a standalone function? |
|
| 1159 | + ! method_exists($class, $method) |
|
| 1160 | + && ! function_exists($method) |
|
| 1161 | + ) |
|
| 1162 | + ) { |
|
| 1163 | + // user error msg |
|
| 1164 | + $error_msg = esc_html__( |
|
| 1165 | + 'An error occurred. The requested page route could not be found.', |
|
| 1166 | + 'event_espresso' |
|
| 1167 | + ); |
|
| 1168 | + // developer error msg |
|
| 1169 | + $error_msg .= '||'; |
|
| 1170 | + $error_msg .= sprintf( |
|
| 1171 | + esc_html__( |
|
| 1172 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1173 | + 'event_espresso' |
|
| 1174 | + ), |
|
| 1175 | + $method |
|
| 1176 | + ); |
|
| 1177 | + } |
|
| 1178 | + if (! empty($error_msg)) { |
|
| 1179 | + throw new EE_Error($error_msg); |
|
| 1180 | + } |
|
| 1181 | + } |
|
| 1182 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1183 | + // then we need to reset the routing properties to the new route. |
|
| 1184 | + // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1185 | + if ( |
|
| 1186 | + $this->_is_UI_request === false |
|
| 1187 | + && is_array($this->_route) |
|
| 1188 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1189 | + ) { |
|
| 1190 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1191 | + } |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + /** |
|
| 1196 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1197 | + * route redirects to a headers route in its route config. |
|
| 1198 | + * |
|
| 1199 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1200 | + * @return void |
|
| 1201 | + * @throws ReflectionException |
|
| 1202 | + * @throws InvalidArgumentException |
|
| 1203 | + * @throws InvalidInterfaceException |
|
| 1204 | + * @throws InvalidDataTypeException |
|
| 1205 | + * @throws EE_Error |
|
| 1206 | + * @since 4.3.0 |
|
| 1207 | + */ |
|
| 1208 | + protected function _reset_routing_properties($new_route) |
|
| 1209 | + { |
|
| 1210 | + $this->_is_UI_request = true; |
|
| 1211 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1212 | + $this->request->setRequestParam('action', $new_route); |
|
| 1213 | + // rerun page setup |
|
| 1214 | + $this->_page_setup(); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * _add_query_arg |
|
| 1220 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1221 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1222 | + * |
|
| 1223 | + * @param array $args |
|
| 1224 | + * @param string $url |
|
| 1225 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1226 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1227 | + * Example usage: If the current page is: |
|
| 1228 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1229 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1230 | + * &_wpnonce=5467821 |
|
| 1231 | + * and you call: |
|
| 1232 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1233 | + * array( |
|
| 1234 | + * 'action' => 'resend_something', |
|
| 1235 | + * 'page=>espresso_registrations' |
|
| 1236 | + * ), |
|
| 1237 | + * $some_url, |
|
| 1238 | + * true |
|
| 1239 | + * ); |
|
| 1240 | + * It will produce a url in this structure: |
|
| 1241 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1242 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1243 | + * month_range]=March%202015 |
|
| 1244 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1245 | + * @return string |
|
| 1246 | + */ |
|
| 1247 | + public static function add_query_args_and_nonce( |
|
| 1248 | + $args = [], |
|
| 1249 | + $url = '', |
|
| 1250 | + $sticky = false, |
|
| 1251 | + $exclude_nonce = false |
|
| 1252 | + ) { |
|
| 1253 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1254 | + if ($sticky) { |
|
| 1255 | + /** @var RequestInterface $request */ |
|
| 1256 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1257 | + $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true); |
|
| 1258 | + $request->unSetServerParam('_wp_http_referer', true); |
|
| 1259 | + foreach ($request->requestParams() as $key => $value) { |
|
| 1260 | + // do not add nonces |
|
| 1261 | + if (strpos($key, 'nonce') !== false) { |
|
| 1262 | + continue; |
|
| 1263 | + } |
|
| 1264 | + $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * This returns a generated link that will load the related help tab. |
|
| 1273 | + * |
|
| 1274 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1275 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1276 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1277 | + * @return string generated link |
|
| 1278 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1279 | + */ |
|
| 1280 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1281 | + { |
|
| 1282 | + return EEH_Template::get_help_tab_link( |
|
| 1283 | + $help_tab_id, |
|
| 1284 | + $this->page_slug, |
|
| 1285 | + $this->_req_action, |
|
| 1286 | + $icon_style, |
|
| 1287 | + $help_text |
|
| 1288 | + ); |
|
| 1289 | + } |
|
| 1290 | + |
|
| 1291 | + |
|
| 1292 | + /** |
|
| 1293 | + * _add_help_tabs |
|
| 1294 | + * Note child classes define their help tabs within the page_config array. |
|
| 1295 | + * |
|
| 1296 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1297 | + * @return void |
|
| 1298 | + * @throws DomainException |
|
| 1299 | + * @throws EE_Error |
|
| 1300 | + * @throws ReflectionException |
|
| 1301 | + */ |
|
| 1302 | + protected function _add_help_tabs() |
|
| 1303 | + { |
|
| 1304 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1305 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1306 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1307 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1308 | + // check that the callback given is valid |
|
| 1309 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1310 | + throw new EE_Error( |
|
| 1311 | + sprintf( |
|
| 1312 | + esc_html__( |
|
| 1313 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1314 | + 'event_espresso' |
|
| 1315 | + ), |
|
| 1316 | + $config['help_sidebar'], |
|
| 1317 | + $this->class_name |
|
| 1318 | + ) |
|
| 1319 | + ); |
|
| 1320 | + } |
|
| 1321 | + $content = apply_filters( |
|
| 1322 | + 'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar', |
|
| 1323 | + $this->{$config['help_sidebar']}() |
|
| 1324 | + ); |
|
| 1325 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1326 | + } |
|
| 1327 | + if (! isset($config['help_tabs'])) { |
|
| 1328 | + return; |
|
| 1329 | + } //no help tabs for this route |
|
| 1330 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1331 | + // we're here so there ARE help tabs! |
|
| 1332 | + // make sure we've got what we need |
|
| 1333 | + if (! isset($cfg['title'])) { |
|
| 1334 | + throw new EE_Error( |
|
| 1335 | + esc_html__( |
|
| 1336 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1337 | + 'event_espresso' |
|
| 1338 | + ) |
|
| 1339 | + ); |
|
| 1340 | + } |
|
| 1341 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1342 | + throw new EE_Error( |
|
| 1343 | + esc_html__( |
|
| 1344 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1345 | + 'event_espresso' |
|
| 1346 | + ) |
|
| 1347 | + ); |
|
| 1348 | + } |
|
| 1349 | + // first priority goes to content. |
|
| 1350 | + if (! empty($cfg['content'])) { |
|
| 1351 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1352 | + // second priority goes to filename |
|
| 1353 | + } elseif (! empty($cfg['filename'])) { |
|
| 1354 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1355 | + // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1356 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1357 | + . basename($this->_get_dir()) |
|
| 1358 | + . '/help_tabs/' |
|
| 1359 | + . $cfg['filename'] |
|
| 1360 | + . '.help_tab.php' : $file_path; |
|
| 1361 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1362 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1363 | + EE_Error::add_error( |
|
| 1364 | + sprintf( |
|
| 1365 | + esc_html__( |
|
| 1366 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1367 | + 'event_espresso' |
|
| 1368 | + ), |
|
| 1369 | + $tab_id, |
|
| 1370 | + key($config), |
|
| 1371 | + $file_path |
|
| 1372 | + ), |
|
| 1373 | + __FILE__, |
|
| 1374 | + __FUNCTION__, |
|
| 1375 | + __LINE__ |
|
| 1376 | + ); |
|
| 1377 | + return; |
|
| 1378 | + } |
|
| 1379 | + $template_args['admin_page_obj'] = $this; |
|
| 1380 | + $content = EEH_Template::display_template( |
|
| 1381 | + $file_path, |
|
| 1382 | + $template_args, |
|
| 1383 | + true |
|
| 1384 | + ); |
|
| 1385 | + } else { |
|
| 1386 | + $content = ''; |
|
| 1387 | + } |
|
| 1388 | + // check if callback is valid |
|
| 1389 | + if ( |
|
| 1390 | + empty($content) |
|
| 1391 | + && ( |
|
| 1392 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1393 | + ) |
|
| 1394 | + ) { |
|
| 1395 | + EE_Error::add_error( |
|
| 1396 | + sprintf( |
|
| 1397 | + esc_html__( |
|
| 1398 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1399 | + 'event_espresso' |
|
| 1400 | + ), |
|
| 1401 | + $cfg['title'] |
|
| 1402 | + ), |
|
| 1403 | + __FILE__, |
|
| 1404 | + __FUNCTION__, |
|
| 1405 | + __LINE__ |
|
| 1406 | + ); |
|
| 1407 | + return; |
|
| 1408 | + } |
|
| 1409 | + // setup config array for help tab method |
|
| 1410 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1411 | + $_ht = [ |
|
| 1412 | + 'id' => $id, |
|
| 1413 | + 'title' => $cfg['title'], |
|
| 1414 | + 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1415 | + 'content' => $content, |
|
| 1416 | + ]; |
|
| 1417 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + |
|
| 1423 | + /** |
|
| 1424 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1425 | + * |
|
| 1426 | + * @return void |
|
| 1427 | + * @throws ReflectionException |
|
| 1428 | + * @throws EE_Error |
|
| 1429 | + */ |
|
| 1430 | + protected function _add_qtips() |
|
| 1431 | + { |
|
| 1432 | + if (isset($this->_route_config['qtips'])) { |
|
| 1433 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1434 | + // load qtip loader |
|
| 1435 | + $path = [ |
|
| 1436 | + $this->_get_dir() . '/qtips/', |
|
| 1437 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1438 | + ]; |
|
| 1439 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + |
|
| 1444 | + /** |
|
| 1445 | + * _set_nav_tabs |
|
| 1446 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1447 | + * wish to add additional tabs or modify accordingly. |
|
| 1448 | + * |
|
| 1449 | + * @return void |
|
| 1450 | + * @throws InvalidArgumentException |
|
| 1451 | + * @throws InvalidInterfaceException |
|
| 1452 | + * @throws InvalidDataTypeException |
|
| 1453 | + */ |
|
| 1454 | + protected function _set_nav_tabs() |
|
| 1455 | + { |
|
| 1456 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1457 | + $i = 0; |
|
| 1458 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1459 | + if (! is_array($config) || empty($config['nav'])) { |
|
| 1460 | + continue; |
|
| 1461 | + } |
|
| 1462 | + // no nav tab for this config |
|
| 1463 | + // check for persistent flag |
|
| 1464 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1465 | + // nav tab is only to appear when route requested. |
|
| 1466 | + continue; |
|
| 1467 | + } |
|
| 1468 | + if (! $this->check_user_access($slug, true)) { |
|
| 1469 | + // no nav tab because current user does not have access. |
|
| 1470 | + continue; |
|
| 1471 | + } |
|
| 1472 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1473 | + $this->_nav_tabs[ $slug ] = [ |
|
| 1474 | + 'url' => isset($config['nav']['url']) |
|
| 1475 | + ? $config['nav']['url'] |
|
| 1476 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1477 | + ['action' => $slug], |
|
| 1478 | + $this->_admin_base_url |
|
| 1479 | + ), |
|
| 1480 | + 'link_text' => isset($config['nav']['label']) |
|
| 1481 | + ? $config['nav']['label'] |
|
| 1482 | + : ucwords( |
|
| 1483 | + str_replace('_', ' ', $slug) |
|
| 1484 | + ), |
|
| 1485 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1486 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1487 | + ]; |
|
| 1488 | + $i++; |
|
| 1489 | + } |
|
| 1490 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1491 | + if (empty($this->_nav_tabs)) { |
|
| 1492 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1493 | + 'url' => $this->_admin_base_url, |
|
| 1494 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1495 | + 'css_class' => 'nav-tab-active', |
|
| 1496 | + 'order' => 10, |
|
| 1497 | + ]; |
|
| 1498 | + } |
|
| 1499 | + // now let's sort the tabs according to order |
|
| 1500 | + usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + |
|
| 1504 | + /** |
|
| 1505 | + * _set_current_labels |
|
| 1506 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1507 | + * property array |
|
| 1508 | + * |
|
| 1509 | + * @return void |
|
| 1510 | + */ |
|
| 1511 | + private function _set_current_labels() |
|
| 1512 | + { |
|
| 1513 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1514 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1515 | + if (is_array($text)) { |
|
| 1516 | + foreach ($text as $sublabel => $subtext) { |
|
| 1517 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1518 | + } |
|
| 1519 | + } else { |
|
| 1520 | + $this->_labels[ $label ] = $text; |
|
| 1521 | + } |
|
| 1522 | + } |
|
| 1523 | + } |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * verifies user access for this admin page |
|
| 1529 | + * |
|
| 1530 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1531 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1532 | + * return false if verify fail. |
|
| 1533 | + * @return bool |
|
| 1534 | + * @throws InvalidArgumentException |
|
| 1535 | + * @throws InvalidDataTypeException |
|
| 1536 | + * @throws InvalidInterfaceException |
|
| 1537 | + */ |
|
| 1538 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1539 | + { |
|
| 1540 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1541 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1542 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1543 | + && is_array($this->_page_routes[ $route_to_check ]) |
|
| 1544 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1545 | + ? $this->_page_routes[ $route_to_check ]['capability'] |
|
| 1546 | + : null; |
|
| 1547 | + |
|
| 1548 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1549 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1550 | + : $this->_route['capability']; |
|
| 1551 | + } else { |
|
| 1552 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1553 | + } |
|
| 1554 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1555 | + if ( |
|
| 1556 | + ! $this->request->isAjax() |
|
| 1557 | + && ( |
|
| 1558 | + ! function_exists('is_admin') |
|
| 1559 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1560 | + $capability, |
|
| 1561 | + $this->page_slug |
|
| 1562 | + . '_' |
|
| 1563 | + . $route_to_check, |
|
| 1564 | + $id |
|
| 1565 | + ) |
|
| 1566 | + ) |
|
| 1567 | + ) { |
|
| 1568 | + if ($verify_only) { |
|
| 1569 | + return false; |
|
| 1570 | + } |
|
| 1571 | + if (is_user_logged_in()) { |
|
| 1572 | + wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1573 | + } else { |
|
| 1574 | + return false; |
|
| 1575 | + } |
|
| 1576 | + } |
|
| 1577 | + return true; |
|
| 1578 | + } |
|
| 1579 | + |
|
| 1580 | + |
|
| 1581 | + /** |
|
| 1582 | + * @param string $box_id |
|
| 1583 | + * @param string $title |
|
| 1584 | + * @param callable|string|null $callback |
|
| 1585 | + * @param string|array|WP_Screen $screen |
|
| 1586 | + * @param string $context |
|
| 1587 | + * @param string $priority |
|
| 1588 | + * @param array|null $callback_args |
|
| 1589 | + */ |
|
| 1590 | + protected function addMetaBox( |
|
| 1591 | + string $box_id, |
|
| 1592 | + string $title, |
|
| 1593 | + $callback, |
|
| 1594 | + $screen, |
|
| 1595 | + string $context = 'normal', |
|
| 1596 | + string $priority = 'default', |
|
| 1597 | + ?array $callback_args = null |
|
| 1598 | + ) { |
|
| 1599 | + if (! is_callable($callback)) { |
|
| 1600 | + return; |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
|
| 1604 | + add_filter( |
|
| 1605 | + "postbox_classes_{$this->_wp_page_slug}_{$box_id}", |
|
| 1606 | + function ($classes) { |
|
| 1607 | + array_push($classes, 'ee-admin-container'); |
|
| 1608 | + return $classes; |
|
| 1609 | + } |
|
| 1610 | + ); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + |
|
| 1614 | + /** |
|
| 1615 | + * admin_init_global |
|
| 1616 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1617 | + * This method executes for ALL EE Admin pages. |
|
| 1618 | + * |
|
| 1619 | + * @return void |
|
| 1620 | + */ |
|
| 1621 | + public function admin_init_global() |
|
| 1622 | + { |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + |
|
| 1626 | + /** |
|
| 1627 | + * wp_loaded_global |
|
| 1628 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1629 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1630 | + * |
|
| 1631 | + * @return void |
|
| 1632 | + */ |
|
| 1633 | + public function wp_loaded() |
|
| 1634 | + { |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + /** |
|
| 1639 | + * admin_notices |
|
| 1640 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1641 | + * ALL EE_Admin pages. |
|
| 1642 | + * |
|
| 1643 | + * @return void |
|
| 1644 | + */ |
|
| 1645 | + public function admin_notices_global() |
|
| 1646 | + { |
|
| 1647 | + $this->_display_no_javascript_warning(); |
|
| 1648 | + $this->_display_espresso_notices(); |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + |
|
| 1652 | + public function network_admin_notices_global() |
|
| 1653 | + { |
|
| 1654 | + $this->_display_no_javascript_warning(); |
|
| 1655 | + $this->_display_espresso_notices(); |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + /** |
|
| 1660 | + * admin_footer_scripts_global |
|
| 1661 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1662 | + * will apply on ALL EE_Admin pages. |
|
| 1663 | + * |
|
| 1664 | + * @return void |
|
| 1665 | + */ |
|
| 1666 | + public function admin_footer_scripts_global() |
|
| 1667 | + { |
|
| 1668 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1669 | + $this->_add_admin_page_overlay(); |
|
| 1670 | + // if metaboxes are present we need to add the nonce field |
|
| 1671 | + if ( |
|
| 1672 | + isset($this->_route_config['metaboxes']) |
|
| 1673 | + || isset($this->_route_config['list_table']) |
|
| 1674 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1675 | + ) { |
|
| 1676 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1677 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1678 | + } |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + |
|
| 1682 | + /** |
|
| 1683 | + * admin_footer_global |
|
| 1684 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1685 | + * This particular method will apply on ALL EE_Admin Pages. |
|
| 1686 | + * |
|
| 1687 | + * @return void |
|
| 1688 | + */ |
|
| 1689 | + public function admin_footer_global() |
|
| 1690 | + { |
|
| 1691 | + // dialog container for dialog helper |
|
| 1692 | + echo ' |
|
| 1693 | 1693 | <div class="ee-admin-dialog-container auto-hide hidden"> |
| 1694 | 1694 | <div class="ee-notices"></div> |
| 1695 | 1695 | <div class="ee-admin-dialog-container-inner-content"></div> |
| 1696 | 1696 | </div> |
| 1697 | 1697 | '; |
| 1698 | 1698 | |
| 1699 | - // current set timezone for timezone js |
|
| 1700 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1701 | - } |
|
| 1702 | - |
|
| 1703 | - |
|
| 1704 | - /** |
|
| 1705 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1706 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1707 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1708 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1709 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1710 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1711 | - * for the |
|
| 1712 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1713 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1714 | - * 'help_trigger_id' => array( |
|
| 1715 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1716 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1717 | - * ) |
|
| 1718 | - * ); |
|
| 1719 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1720 | - * |
|
| 1721 | - * @param array $help_array |
|
| 1722 | - * @param bool $display |
|
| 1723 | - * @return string content |
|
| 1724 | - * @throws DomainException |
|
| 1725 | - * @throws EE_Error |
|
| 1726 | - */ |
|
| 1727 | - protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1728 | - { |
|
| 1729 | - $content = ''; |
|
| 1730 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1731 | - // loop through the array and setup content |
|
| 1732 | - foreach ($help_array as $trigger => $help) { |
|
| 1733 | - // make sure the array is setup properly |
|
| 1734 | - if (! isset($help['title'], $help['content'])) { |
|
| 1735 | - throw new EE_Error( |
|
| 1736 | - esc_html__( |
|
| 1737 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1738 | - 'event_espresso' |
|
| 1739 | - ) |
|
| 1740 | - ); |
|
| 1741 | - } |
|
| 1742 | - // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1743 | - $template_args = [ |
|
| 1744 | - 'help_popup_id' => $trigger, |
|
| 1745 | - 'help_popup_title' => $help['title'], |
|
| 1746 | - 'help_popup_content' => $help['content'], |
|
| 1747 | - ]; |
|
| 1748 | - $content .= EEH_Template::display_template( |
|
| 1749 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1750 | - $template_args, |
|
| 1751 | - true |
|
| 1752 | - ); |
|
| 1753 | - } |
|
| 1754 | - if ($display) { |
|
| 1755 | - echo $content; // already escaped |
|
| 1756 | - return ''; |
|
| 1757 | - } |
|
| 1758 | - return $content; |
|
| 1759 | - } |
|
| 1760 | - |
|
| 1761 | - |
|
| 1762 | - /** |
|
| 1763 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1764 | - * |
|
| 1765 | - * @return array properly formatted array for help popup content |
|
| 1766 | - * @throws EE_Error |
|
| 1767 | - */ |
|
| 1768 | - private function _get_help_content() |
|
| 1769 | - { |
|
| 1770 | - // what is the method we're looking for? |
|
| 1771 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1772 | - // if method doesn't exist let's get out. |
|
| 1773 | - if (! method_exists($this, $method_name)) { |
|
| 1774 | - return []; |
|
| 1775 | - } |
|
| 1776 | - // k we're good to go let's retrieve the help array |
|
| 1777 | - $help_array = $this->{$method_name}(); |
|
| 1778 | - // make sure we've got an array! |
|
| 1779 | - if (! is_array($help_array)) { |
|
| 1780 | - throw new EE_Error( |
|
| 1781 | - esc_html__( |
|
| 1782 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1783 | - 'event_espresso' |
|
| 1784 | - ) |
|
| 1785 | - ); |
|
| 1786 | - } |
|
| 1787 | - return $help_array; |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - |
|
| 1791 | - /** |
|
| 1792 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1793 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1794 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1795 | - * |
|
| 1796 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1797 | - * @param boolean $display if false then we return the trigger string |
|
| 1798 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1799 | - * @return string |
|
| 1800 | - * @throws DomainException |
|
| 1801 | - * @throws EE_Error |
|
| 1802 | - */ |
|
| 1803 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1804 | - { |
|
| 1805 | - if ($this->request->isAjax()) { |
|
| 1806 | - return ''; |
|
| 1807 | - } |
|
| 1808 | - // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1809 | - $help_array = $this->_get_help_content(); |
|
| 1810 | - $help_content = ''; |
|
| 1811 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1812 | - $help_array[ $trigger_id ] = [ |
|
| 1813 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1814 | - 'content' => esc_html__( |
|
| 1815 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1816 | - 'event_espresso' |
|
| 1817 | - ), |
|
| 1818 | - ]; |
|
| 1819 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1820 | - } |
|
| 1821 | - // let's setup the trigger |
|
| 1822 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1823 | - . esc_attr($dimensions[0]) |
|
| 1824 | - . '&width=' |
|
| 1825 | - . esc_attr($dimensions[1]) |
|
| 1826 | - . '&inlineId=' |
|
| 1827 | - . esc_attr($trigger_id) |
|
| 1828 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1829 | - $content .= $help_content; |
|
| 1830 | - if ($display) { |
|
| 1831 | - echo $content; // already escaped |
|
| 1832 | - return ''; |
|
| 1833 | - } |
|
| 1834 | - return $content; |
|
| 1835 | - } |
|
| 1836 | - |
|
| 1837 | - |
|
| 1838 | - /** |
|
| 1839 | - * _add_global_screen_options |
|
| 1840 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1841 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1842 | - * |
|
| 1843 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1844 | - * see also WP_Screen object documents... |
|
| 1845 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1846 | - * @abstract |
|
| 1847 | - * @return void |
|
| 1848 | - */ |
|
| 1849 | - private function _add_global_screen_options() |
|
| 1850 | - { |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - |
|
| 1854 | - /** |
|
| 1855 | - * _add_global_feature_pointers |
|
| 1856 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1857 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1858 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1859 | - * |
|
| 1860 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1861 | - * extended) also see: |
|
| 1862 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1863 | - * @abstract |
|
| 1864 | - * @return void |
|
| 1865 | - */ |
|
| 1866 | - private function _add_global_feature_pointers() |
|
| 1867 | - { |
|
| 1868 | - } |
|
| 1869 | - |
|
| 1870 | - |
|
| 1871 | - /** |
|
| 1872 | - * load_global_scripts_styles |
|
| 1873 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1874 | - * |
|
| 1875 | - * @return void |
|
| 1876 | - */ |
|
| 1877 | - public function load_global_scripts_styles() |
|
| 1878 | - { |
|
| 1879 | - // add debugging styles |
|
| 1880 | - if (WP_DEBUG) { |
|
| 1881 | - add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1882 | - } |
|
| 1883 | - // taking care of metaboxes |
|
| 1884 | - if ( |
|
| 1885 | - empty($this->_cpt_route) |
|
| 1886 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1887 | - ) { |
|
| 1888 | - wp_enqueue_script('dashboard'); |
|
| 1889 | - } |
|
| 1890 | - |
|
| 1891 | - wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH); |
|
| 1892 | - wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN); |
|
| 1893 | - // LOCALIZED DATA |
|
| 1894 | - // localize script for ajax lazy loading |
|
| 1895 | - wp_localize_script( |
|
| 1896 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 1897 | - 'eeLazyLoadingContainers', |
|
| 1898 | - apply_filters( |
|
| 1899 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1900 | - ['espresso_news_post_box_content'] |
|
| 1901 | - ) |
|
| 1902 | - ); |
|
| 1903 | - StatusChangeNotice::loadAssets(); |
|
| 1904 | - |
|
| 1905 | - add_filter( |
|
| 1906 | - 'admin_body_class', |
|
| 1907 | - function ($classes) { |
|
| 1908 | - if (strpos($classes, 'espresso-admin') === false) { |
|
| 1909 | - $classes .= ' espresso-admin'; |
|
| 1910 | - } |
|
| 1911 | - return $classes; |
|
| 1912 | - } |
|
| 1913 | - ); |
|
| 1914 | - } |
|
| 1915 | - |
|
| 1916 | - |
|
| 1917 | - /** |
|
| 1918 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1919 | - * |
|
| 1920 | - * @return void |
|
| 1921 | - */ |
|
| 1922 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1923 | - { |
|
| 1924 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1925 | - EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1926 | - __( |
|
| 1927 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 1928 | - 'event_espresso' |
|
| 1929 | - ) |
|
| 1930 | - ); |
|
| 1931 | - EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1932 | - EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1933 | - EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1934 | - EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1935 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1936 | - EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1937 | - EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1938 | - EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1939 | - EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1940 | - EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1941 | - EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1942 | - EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1943 | - EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1944 | - EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1945 | - EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1946 | - EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1947 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1948 | - EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1949 | - EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1950 | - EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1951 | - EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1952 | - EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1953 | - EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1954 | - EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1955 | - EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1956 | - EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1957 | - EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1958 | - EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1959 | - EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1960 | - EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1961 | - EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1962 | - EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1963 | - EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1964 | - EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1965 | - EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1966 | - EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1967 | - EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1968 | - EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1969 | - } |
|
| 1970 | - |
|
| 1971 | - |
|
| 1972 | - /** |
|
| 1973 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1974 | - * |
|
| 1975 | - * @return void |
|
| 1976 | - */ |
|
| 1977 | - public function add_xdebug_style() |
|
| 1978 | - { |
|
| 1979 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - |
|
| 1983 | - /************************/ |
|
| 1984 | - /** LIST TABLE METHODS **/ |
|
| 1985 | - /************************/ |
|
| 1986 | - /** |
|
| 1987 | - * this sets up the list table if the current view requires it. |
|
| 1988 | - * |
|
| 1989 | - * @return void |
|
| 1990 | - * @throws EE_Error |
|
| 1991 | - * @throws InvalidArgumentException |
|
| 1992 | - * @throws InvalidDataTypeException |
|
| 1993 | - * @throws InvalidInterfaceException |
|
| 1994 | - */ |
|
| 1995 | - protected function _set_list_table() |
|
| 1996 | - { |
|
| 1997 | - // first is this a list_table view? |
|
| 1998 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1999 | - return; |
|
| 2000 | - } //not a list_table view so get out. |
|
| 2001 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2002 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2003 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2004 | - // user error msg |
|
| 2005 | - $error_msg = esc_html__( |
|
| 2006 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2007 | - 'event_espresso' |
|
| 2008 | - ); |
|
| 2009 | - // developer error msg |
|
| 2010 | - $error_msg .= '||' |
|
| 2011 | - . sprintf( |
|
| 2012 | - esc_html__( |
|
| 2013 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2014 | - 'event_espresso' |
|
| 2015 | - ), |
|
| 2016 | - $this->_req_action, |
|
| 2017 | - $list_table_view |
|
| 2018 | - ); |
|
| 2019 | - throw new EE_Error($error_msg); |
|
| 2020 | - } |
|
| 2021 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2022 | - $this->_views = apply_filters( |
|
| 2023 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2024 | - $this->_views |
|
| 2025 | - ); |
|
| 2026 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2027 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2028 | - $this->_set_list_table_view(); |
|
| 2029 | - $this->_set_list_table_object(); |
|
| 2030 | - } |
|
| 2031 | - |
|
| 2032 | - |
|
| 2033 | - /** |
|
| 2034 | - * set current view for List Table |
|
| 2035 | - * |
|
| 2036 | - * @return void |
|
| 2037 | - */ |
|
| 2038 | - protected function _set_list_table_view() |
|
| 2039 | - { |
|
| 2040 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2041 | - $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 2042 | - $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2043 | - ? $status |
|
| 2044 | - : $this->_view; |
|
| 2045 | - } |
|
| 2046 | - |
|
| 2047 | - |
|
| 2048 | - /** |
|
| 2049 | - * _set_list_table_object |
|
| 2050 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2051 | - * |
|
| 2052 | - * @throws InvalidInterfaceException |
|
| 2053 | - * @throws InvalidArgumentException |
|
| 2054 | - * @throws InvalidDataTypeException |
|
| 2055 | - * @throws EE_Error |
|
| 2056 | - * @throws InvalidInterfaceException |
|
| 2057 | - */ |
|
| 2058 | - protected function _set_list_table_object() |
|
| 2059 | - { |
|
| 2060 | - if (isset($this->_route_config['list_table'])) { |
|
| 2061 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2062 | - throw new EE_Error( |
|
| 2063 | - sprintf( |
|
| 2064 | - esc_html__( |
|
| 2065 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2066 | - 'event_espresso' |
|
| 2067 | - ), |
|
| 2068 | - $this->_route_config['list_table'], |
|
| 2069 | - $this->class_name |
|
| 2070 | - ) |
|
| 2071 | - ); |
|
| 2072 | - } |
|
| 2073 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2074 | - $this->_route_config['list_table'], |
|
| 2075 | - [$this] |
|
| 2076 | - ); |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - |
|
| 2080 | - |
|
| 2081 | - /** |
|
| 2082 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2083 | - * |
|
| 2084 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2085 | - * urls. The array should be indexed by the view it is being |
|
| 2086 | - * added to. |
|
| 2087 | - * @return array |
|
| 2088 | - */ |
|
| 2089 | - public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2090 | - { |
|
| 2091 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2092 | - if (empty($this->_views)) { |
|
| 2093 | - $this->_views = []; |
|
| 2094 | - } |
|
| 2095 | - // cycle thru views |
|
| 2096 | - foreach ($this->_views as $key => $view) { |
|
| 2097 | - $query_args = []; |
|
| 2098 | - // check for current view |
|
| 2099 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2100 | - $query_args['action'] = $this->_req_action; |
|
| 2101 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2102 | - $query_args['status'] = $view['slug']; |
|
| 2103 | - // merge any other arguments sent in. |
|
| 2104 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2105 | - foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2106 | - $query_args[] = $extra_query_arg; |
|
| 2107 | - } |
|
| 2108 | - } |
|
| 2109 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2110 | - } |
|
| 2111 | - return $this->_views; |
|
| 2112 | - } |
|
| 2113 | - |
|
| 2114 | - |
|
| 2115 | - /** |
|
| 2116 | - * _entries_per_page_dropdown |
|
| 2117 | - * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2118 | - * |
|
| 2119 | - * @param int $max_entries total number of rows in the table |
|
| 2120 | - * @return string |
|
| 2121 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2122 | - * WP does it. |
|
| 2123 | - */ |
|
| 2124 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2125 | - { |
|
| 2126 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2127 | - $values = [10, 25, 50, 100]; |
|
| 2128 | - $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2129 | - if ($max_entries) { |
|
| 2130 | - $values[] = $max_entries; |
|
| 2131 | - sort($values); |
|
| 2132 | - } |
|
| 2133 | - $entries_per_page_dropdown = ' |
|
| 1699 | + // current set timezone for timezone js |
|
| 1700 | + echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1701 | + } |
|
| 1702 | + |
|
| 1703 | + |
|
| 1704 | + /** |
|
| 1705 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1706 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1707 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1708 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1709 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1710 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1711 | + * for the |
|
| 1712 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1713 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1714 | + * 'help_trigger_id' => array( |
|
| 1715 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1716 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1717 | + * ) |
|
| 1718 | + * ); |
|
| 1719 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1720 | + * |
|
| 1721 | + * @param array $help_array |
|
| 1722 | + * @param bool $display |
|
| 1723 | + * @return string content |
|
| 1724 | + * @throws DomainException |
|
| 1725 | + * @throws EE_Error |
|
| 1726 | + */ |
|
| 1727 | + protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1728 | + { |
|
| 1729 | + $content = ''; |
|
| 1730 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1731 | + // loop through the array and setup content |
|
| 1732 | + foreach ($help_array as $trigger => $help) { |
|
| 1733 | + // make sure the array is setup properly |
|
| 1734 | + if (! isset($help['title'], $help['content'])) { |
|
| 1735 | + throw new EE_Error( |
|
| 1736 | + esc_html__( |
|
| 1737 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1738 | + 'event_espresso' |
|
| 1739 | + ) |
|
| 1740 | + ); |
|
| 1741 | + } |
|
| 1742 | + // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1743 | + $template_args = [ |
|
| 1744 | + 'help_popup_id' => $trigger, |
|
| 1745 | + 'help_popup_title' => $help['title'], |
|
| 1746 | + 'help_popup_content' => $help['content'], |
|
| 1747 | + ]; |
|
| 1748 | + $content .= EEH_Template::display_template( |
|
| 1749 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1750 | + $template_args, |
|
| 1751 | + true |
|
| 1752 | + ); |
|
| 1753 | + } |
|
| 1754 | + if ($display) { |
|
| 1755 | + echo $content; // already escaped |
|
| 1756 | + return ''; |
|
| 1757 | + } |
|
| 1758 | + return $content; |
|
| 1759 | + } |
|
| 1760 | + |
|
| 1761 | + |
|
| 1762 | + /** |
|
| 1763 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1764 | + * |
|
| 1765 | + * @return array properly formatted array for help popup content |
|
| 1766 | + * @throws EE_Error |
|
| 1767 | + */ |
|
| 1768 | + private function _get_help_content() |
|
| 1769 | + { |
|
| 1770 | + // what is the method we're looking for? |
|
| 1771 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1772 | + // if method doesn't exist let's get out. |
|
| 1773 | + if (! method_exists($this, $method_name)) { |
|
| 1774 | + return []; |
|
| 1775 | + } |
|
| 1776 | + // k we're good to go let's retrieve the help array |
|
| 1777 | + $help_array = $this->{$method_name}(); |
|
| 1778 | + // make sure we've got an array! |
|
| 1779 | + if (! is_array($help_array)) { |
|
| 1780 | + throw new EE_Error( |
|
| 1781 | + esc_html__( |
|
| 1782 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1783 | + 'event_espresso' |
|
| 1784 | + ) |
|
| 1785 | + ); |
|
| 1786 | + } |
|
| 1787 | + return $help_array; |
|
| 1788 | + } |
|
| 1789 | + |
|
| 1790 | + |
|
| 1791 | + /** |
|
| 1792 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1793 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1794 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1795 | + * |
|
| 1796 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1797 | + * @param boolean $display if false then we return the trigger string |
|
| 1798 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1799 | + * @return string |
|
| 1800 | + * @throws DomainException |
|
| 1801 | + * @throws EE_Error |
|
| 1802 | + */ |
|
| 1803 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1804 | + { |
|
| 1805 | + if ($this->request->isAjax()) { |
|
| 1806 | + return ''; |
|
| 1807 | + } |
|
| 1808 | + // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1809 | + $help_array = $this->_get_help_content(); |
|
| 1810 | + $help_content = ''; |
|
| 1811 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1812 | + $help_array[ $trigger_id ] = [ |
|
| 1813 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1814 | + 'content' => esc_html__( |
|
| 1815 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1816 | + 'event_espresso' |
|
| 1817 | + ), |
|
| 1818 | + ]; |
|
| 1819 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1820 | + } |
|
| 1821 | + // let's setup the trigger |
|
| 1822 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1823 | + . esc_attr($dimensions[0]) |
|
| 1824 | + . '&width=' |
|
| 1825 | + . esc_attr($dimensions[1]) |
|
| 1826 | + . '&inlineId=' |
|
| 1827 | + . esc_attr($trigger_id) |
|
| 1828 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1829 | + $content .= $help_content; |
|
| 1830 | + if ($display) { |
|
| 1831 | + echo $content; // already escaped |
|
| 1832 | + return ''; |
|
| 1833 | + } |
|
| 1834 | + return $content; |
|
| 1835 | + } |
|
| 1836 | + |
|
| 1837 | + |
|
| 1838 | + /** |
|
| 1839 | + * _add_global_screen_options |
|
| 1840 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1841 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1842 | + * |
|
| 1843 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1844 | + * see also WP_Screen object documents... |
|
| 1845 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1846 | + * @abstract |
|
| 1847 | + * @return void |
|
| 1848 | + */ |
|
| 1849 | + private function _add_global_screen_options() |
|
| 1850 | + { |
|
| 1851 | + } |
|
| 1852 | + |
|
| 1853 | + |
|
| 1854 | + /** |
|
| 1855 | + * _add_global_feature_pointers |
|
| 1856 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1857 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1858 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1859 | + * |
|
| 1860 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1861 | + * extended) also see: |
|
| 1862 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1863 | + * @abstract |
|
| 1864 | + * @return void |
|
| 1865 | + */ |
|
| 1866 | + private function _add_global_feature_pointers() |
|
| 1867 | + { |
|
| 1868 | + } |
|
| 1869 | + |
|
| 1870 | + |
|
| 1871 | + /** |
|
| 1872 | + * load_global_scripts_styles |
|
| 1873 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1874 | + * |
|
| 1875 | + * @return void |
|
| 1876 | + */ |
|
| 1877 | + public function load_global_scripts_styles() |
|
| 1878 | + { |
|
| 1879 | + // add debugging styles |
|
| 1880 | + if (WP_DEBUG) { |
|
| 1881 | + add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1882 | + } |
|
| 1883 | + // taking care of metaboxes |
|
| 1884 | + if ( |
|
| 1885 | + empty($this->_cpt_route) |
|
| 1886 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1887 | + ) { |
|
| 1888 | + wp_enqueue_script('dashboard'); |
|
| 1889 | + } |
|
| 1890 | + |
|
| 1891 | + wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH); |
|
| 1892 | + wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN); |
|
| 1893 | + // LOCALIZED DATA |
|
| 1894 | + // localize script for ajax lazy loading |
|
| 1895 | + wp_localize_script( |
|
| 1896 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 1897 | + 'eeLazyLoadingContainers', |
|
| 1898 | + apply_filters( |
|
| 1899 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1900 | + ['espresso_news_post_box_content'] |
|
| 1901 | + ) |
|
| 1902 | + ); |
|
| 1903 | + StatusChangeNotice::loadAssets(); |
|
| 1904 | + |
|
| 1905 | + add_filter( |
|
| 1906 | + 'admin_body_class', |
|
| 1907 | + function ($classes) { |
|
| 1908 | + if (strpos($classes, 'espresso-admin') === false) { |
|
| 1909 | + $classes .= ' espresso-admin'; |
|
| 1910 | + } |
|
| 1911 | + return $classes; |
|
| 1912 | + } |
|
| 1913 | + ); |
|
| 1914 | + } |
|
| 1915 | + |
|
| 1916 | + |
|
| 1917 | + /** |
|
| 1918 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1919 | + * |
|
| 1920 | + * @return void |
|
| 1921 | + */ |
|
| 1922 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1923 | + { |
|
| 1924 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1925 | + EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1926 | + __( |
|
| 1927 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 1928 | + 'event_espresso' |
|
| 1929 | + ) |
|
| 1930 | + ); |
|
| 1931 | + EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1932 | + EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1933 | + EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1934 | + EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1935 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1936 | + EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1937 | + EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1938 | + EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1939 | + EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1940 | + EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1941 | + EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1942 | + EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1943 | + EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1944 | + EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1945 | + EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1946 | + EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1947 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1948 | + EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1949 | + EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1950 | + EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1951 | + EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1952 | + EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1953 | + EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1954 | + EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1955 | + EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1956 | + EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1957 | + EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1958 | + EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1959 | + EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1960 | + EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1961 | + EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1962 | + EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1963 | + EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1964 | + EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1965 | + EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1966 | + EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1967 | + EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1968 | + EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1969 | + } |
|
| 1970 | + |
|
| 1971 | + |
|
| 1972 | + /** |
|
| 1973 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1974 | + * |
|
| 1975 | + * @return void |
|
| 1976 | + */ |
|
| 1977 | + public function add_xdebug_style() |
|
| 1978 | + { |
|
| 1979 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + |
|
| 1983 | + /************************/ |
|
| 1984 | + /** LIST TABLE METHODS **/ |
|
| 1985 | + /************************/ |
|
| 1986 | + /** |
|
| 1987 | + * this sets up the list table if the current view requires it. |
|
| 1988 | + * |
|
| 1989 | + * @return void |
|
| 1990 | + * @throws EE_Error |
|
| 1991 | + * @throws InvalidArgumentException |
|
| 1992 | + * @throws InvalidDataTypeException |
|
| 1993 | + * @throws InvalidInterfaceException |
|
| 1994 | + */ |
|
| 1995 | + protected function _set_list_table() |
|
| 1996 | + { |
|
| 1997 | + // first is this a list_table view? |
|
| 1998 | + if (! isset($this->_route_config['list_table'])) { |
|
| 1999 | + return; |
|
| 2000 | + } //not a list_table view so get out. |
|
| 2001 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2002 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2003 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2004 | + // user error msg |
|
| 2005 | + $error_msg = esc_html__( |
|
| 2006 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2007 | + 'event_espresso' |
|
| 2008 | + ); |
|
| 2009 | + // developer error msg |
|
| 2010 | + $error_msg .= '||' |
|
| 2011 | + . sprintf( |
|
| 2012 | + esc_html__( |
|
| 2013 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2014 | + 'event_espresso' |
|
| 2015 | + ), |
|
| 2016 | + $this->_req_action, |
|
| 2017 | + $list_table_view |
|
| 2018 | + ); |
|
| 2019 | + throw new EE_Error($error_msg); |
|
| 2020 | + } |
|
| 2021 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2022 | + $this->_views = apply_filters( |
|
| 2023 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2024 | + $this->_views |
|
| 2025 | + ); |
|
| 2026 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2027 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2028 | + $this->_set_list_table_view(); |
|
| 2029 | + $this->_set_list_table_object(); |
|
| 2030 | + } |
|
| 2031 | + |
|
| 2032 | + |
|
| 2033 | + /** |
|
| 2034 | + * set current view for List Table |
|
| 2035 | + * |
|
| 2036 | + * @return void |
|
| 2037 | + */ |
|
| 2038 | + protected function _set_list_table_view() |
|
| 2039 | + { |
|
| 2040 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2041 | + $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 2042 | + $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2043 | + ? $status |
|
| 2044 | + : $this->_view; |
|
| 2045 | + } |
|
| 2046 | + |
|
| 2047 | + |
|
| 2048 | + /** |
|
| 2049 | + * _set_list_table_object |
|
| 2050 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2051 | + * |
|
| 2052 | + * @throws InvalidInterfaceException |
|
| 2053 | + * @throws InvalidArgumentException |
|
| 2054 | + * @throws InvalidDataTypeException |
|
| 2055 | + * @throws EE_Error |
|
| 2056 | + * @throws InvalidInterfaceException |
|
| 2057 | + */ |
|
| 2058 | + protected function _set_list_table_object() |
|
| 2059 | + { |
|
| 2060 | + if (isset($this->_route_config['list_table'])) { |
|
| 2061 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2062 | + throw new EE_Error( |
|
| 2063 | + sprintf( |
|
| 2064 | + esc_html__( |
|
| 2065 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2066 | + 'event_espresso' |
|
| 2067 | + ), |
|
| 2068 | + $this->_route_config['list_table'], |
|
| 2069 | + $this->class_name |
|
| 2070 | + ) |
|
| 2071 | + ); |
|
| 2072 | + } |
|
| 2073 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2074 | + $this->_route_config['list_table'], |
|
| 2075 | + [$this] |
|
| 2076 | + ); |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + |
|
| 2080 | + |
|
| 2081 | + /** |
|
| 2082 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2083 | + * |
|
| 2084 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2085 | + * urls. The array should be indexed by the view it is being |
|
| 2086 | + * added to. |
|
| 2087 | + * @return array |
|
| 2088 | + */ |
|
| 2089 | + public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2090 | + { |
|
| 2091 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2092 | + if (empty($this->_views)) { |
|
| 2093 | + $this->_views = []; |
|
| 2094 | + } |
|
| 2095 | + // cycle thru views |
|
| 2096 | + foreach ($this->_views as $key => $view) { |
|
| 2097 | + $query_args = []; |
|
| 2098 | + // check for current view |
|
| 2099 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2100 | + $query_args['action'] = $this->_req_action; |
|
| 2101 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2102 | + $query_args['status'] = $view['slug']; |
|
| 2103 | + // merge any other arguments sent in. |
|
| 2104 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2105 | + foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2106 | + $query_args[] = $extra_query_arg; |
|
| 2107 | + } |
|
| 2108 | + } |
|
| 2109 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2110 | + } |
|
| 2111 | + return $this->_views; |
|
| 2112 | + } |
|
| 2113 | + |
|
| 2114 | + |
|
| 2115 | + /** |
|
| 2116 | + * _entries_per_page_dropdown |
|
| 2117 | + * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2118 | + * |
|
| 2119 | + * @param int $max_entries total number of rows in the table |
|
| 2120 | + * @return string |
|
| 2121 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2122 | + * WP does it. |
|
| 2123 | + */ |
|
| 2124 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2125 | + { |
|
| 2126 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2127 | + $values = [10, 25, 50, 100]; |
|
| 2128 | + $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2129 | + if ($max_entries) { |
|
| 2130 | + $values[] = $max_entries; |
|
| 2131 | + sort($values); |
|
| 2132 | + } |
|
| 2133 | + $entries_per_page_dropdown = ' |
|
| 2134 | 2134 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2135 | 2135 | <label class="hide-if-no-js"> |
| 2136 | 2136 | Show |
| 2137 | 2137 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2138 | - foreach ($values as $value) { |
|
| 2139 | - if ($value < $max_entries) { |
|
| 2140 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2141 | - $entries_per_page_dropdown .= ' |
|
| 2138 | + foreach ($values as $value) { |
|
| 2139 | + if ($value < $max_entries) { |
|
| 2140 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2141 | + $entries_per_page_dropdown .= ' |
|
| 2142 | 2142 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2143 | - } |
|
| 2144 | - } |
|
| 2145 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2146 | - $entries_per_page_dropdown .= ' |
|
| 2143 | + } |
|
| 2144 | + } |
|
| 2145 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2146 | + $entries_per_page_dropdown .= ' |
|
| 2147 | 2147 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2148 | - $entries_per_page_dropdown .= ' |
|
| 2148 | + $entries_per_page_dropdown .= ' |
|
| 2149 | 2149 | </select> |
| 2150 | 2150 | entries |
| 2151 | 2151 | </label> |
| 2152 | 2152 | <input id="entries-per-page-btn" class="button button--secondary" type="submit" value="Go" > |
| 2153 | 2153 | </div> |
| 2154 | 2154 | '; |
| 2155 | - return $entries_per_page_dropdown; |
|
| 2156 | - } |
|
| 2157 | - |
|
| 2158 | - |
|
| 2159 | - /** |
|
| 2160 | - * _set_search_attributes |
|
| 2161 | - * |
|
| 2162 | - * @return void |
|
| 2163 | - */ |
|
| 2164 | - public function _set_search_attributes() |
|
| 2165 | - { |
|
| 2166 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2167 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2168 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2169 | - : $this->_search_btn_label |
|
| 2170 | - ); |
|
| 2171 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2172 | - } |
|
| 2173 | - |
|
| 2174 | - |
|
| 2175 | - |
|
| 2176 | - /*** END LIST TABLE METHODS **/ |
|
| 2177 | - |
|
| 2178 | - |
|
| 2179 | - /** |
|
| 2180 | - * _add_registered_metaboxes |
|
| 2181 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2182 | - * |
|
| 2183 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2184 | - * @return void |
|
| 2185 | - * @throws EE_Error |
|
| 2186 | - */ |
|
| 2187 | - private function _add_registered_meta_boxes() |
|
| 2188 | - { |
|
| 2189 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2190 | - // we only add meta boxes if the page_route calls for it |
|
| 2191 | - if ( |
|
| 2192 | - is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2193 | - && is_array( |
|
| 2194 | - $this->_route_config['metaboxes'] |
|
| 2195 | - ) |
|
| 2196 | - ) { |
|
| 2197 | - // this simply loops through the callbacks provided |
|
| 2198 | - // and checks if there is a corresponding callback registered by the child |
|
| 2199 | - // if there is then we go ahead and process the metabox loader. |
|
| 2200 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2201 | - // first check for Closures |
|
| 2202 | - if ($metabox_callback instanceof Closure) { |
|
| 2203 | - $result = $metabox_callback(); |
|
| 2204 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2205 | - $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2206 | - } else { |
|
| 2207 | - $result = $this->{$metabox_callback}(); |
|
| 2208 | - } |
|
| 2209 | - if ($result === false) { |
|
| 2210 | - // user error msg |
|
| 2211 | - $error_msg = esc_html__( |
|
| 2212 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2213 | - 'event_espresso' |
|
| 2214 | - ); |
|
| 2215 | - // developer error msg |
|
| 2216 | - $error_msg .= '||' |
|
| 2217 | - . sprintf( |
|
| 2218 | - esc_html__( |
|
| 2219 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2220 | - 'event_espresso' |
|
| 2221 | - ), |
|
| 2222 | - $metabox_callback |
|
| 2223 | - ); |
|
| 2224 | - throw new EE_Error($error_msg); |
|
| 2225 | - } |
|
| 2226 | - } |
|
| 2227 | - } |
|
| 2228 | - } |
|
| 2229 | - |
|
| 2230 | - |
|
| 2231 | - /** |
|
| 2232 | - * _add_screen_columns |
|
| 2233 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2234 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2235 | - * |
|
| 2236 | - * @return void |
|
| 2237 | - */ |
|
| 2238 | - private function _add_screen_columns() |
|
| 2239 | - { |
|
| 2240 | - if ( |
|
| 2241 | - is_array($this->_route_config) |
|
| 2242 | - && isset($this->_route_config['columns']) |
|
| 2243 | - && is_array($this->_route_config['columns']) |
|
| 2244 | - && count($this->_route_config['columns']) === 2 |
|
| 2245 | - ) { |
|
| 2246 | - add_screen_option( |
|
| 2247 | - 'layout_columns', |
|
| 2248 | - [ |
|
| 2249 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2250 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2251 | - ] |
|
| 2252 | - ); |
|
| 2253 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2254 | - $screen_id = $this->_current_screen->id; |
|
| 2255 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2256 | - $total_columns = ! empty($screen_columns) |
|
| 2257 | - ? $screen_columns |
|
| 2258 | - : $this->_route_config['columns'][1]; |
|
| 2259 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2260 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2261 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2262 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2263 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2264 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2265 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2266 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2267 | - } |
|
| 2268 | - } |
|
| 2269 | - |
|
| 2270 | - |
|
| 2271 | - |
|
| 2272 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2273 | - |
|
| 2274 | - |
|
| 2275 | - /** |
|
| 2276 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2277 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2278 | - * these get loaded on. |
|
| 2279 | - */ |
|
| 2280 | - private function _espresso_news_post_box() |
|
| 2281 | - { |
|
| 2282 | - $news_box_title = apply_filters( |
|
| 2283 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2284 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2285 | - ); |
|
| 2286 | - $this->addMetaBox( |
|
| 2287 | - 'espresso_news_post_box', |
|
| 2288 | - $news_box_title, |
|
| 2289 | - [ |
|
| 2290 | - $this, |
|
| 2291 | - 'espresso_news_post_box', |
|
| 2292 | - ], |
|
| 2293 | - $this->_wp_page_slug, |
|
| 2294 | - 'side', |
|
| 2295 | - 'low' |
|
| 2296 | - ); |
|
| 2297 | - } |
|
| 2298 | - |
|
| 2299 | - |
|
| 2300 | - /** |
|
| 2301 | - * Code for setting up espresso ratings request metabox. |
|
| 2302 | - */ |
|
| 2303 | - protected function _espresso_ratings_request() |
|
| 2304 | - { |
|
| 2305 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2306 | - return; |
|
| 2307 | - } |
|
| 2308 | - $ratings_box_title = apply_filters( |
|
| 2309 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2310 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2311 | - ); |
|
| 2312 | - $this->addMetaBox( |
|
| 2313 | - 'espresso_ratings_request', |
|
| 2314 | - $ratings_box_title, |
|
| 2315 | - [ |
|
| 2316 | - $this, |
|
| 2317 | - 'espresso_ratings_request', |
|
| 2318 | - ], |
|
| 2319 | - $this->_wp_page_slug, |
|
| 2320 | - 'side' |
|
| 2321 | - ); |
|
| 2322 | - } |
|
| 2323 | - |
|
| 2324 | - |
|
| 2325 | - /** |
|
| 2326 | - * Code for setting up espresso ratings request metabox content. |
|
| 2327 | - * |
|
| 2328 | - * @throws DomainException |
|
| 2329 | - */ |
|
| 2330 | - public function espresso_ratings_request() |
|
| 2331 | - { |
|
| 2332 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2333 | - } |
|
| 2334 | - |
|
| 2335 | - |
|
| 2336 | - public static function cached_rss_display($rss_id, $url) |
|
| 2337 | - { |
|
| 2338 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2339 | - . esc_html__('Loading…', 'event_espresso') |
|
| 2340 | - . '</p><p class="hide-if-js">' |
|
| 2341 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2342 | - . '</p>'; |
|
| 2343 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2344 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2345 | - $post = '</div>' . "\n"; |
|
| 2346 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2347 | - $output = get_transient($cache_key); |
|
| 2348 | - if ($output !== false) { |
|
| 2349 | - echo $pre . $output . $post; // already escaped |
|
| 2350 | - return true; |
|
| 2351 | - } |
|
| 2352 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2353 | - echo $pre . $loading . $post; // already escaped |
|
| 2354 | - return false; |
|
| 2355 | - } |
|
| 2356 | - ob_start(); |
|
| 2357 | - wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2358 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2359 | - return true; |
|
| 2360 | - } |
|
| 2361 | - |
|
| 2362 | - |
|
| 2363 | - public function espresso_news_post_box() |
|
| 2364 | - { |
|
| 2365 | - ?> |
|
| 2155 | + return $entries_per_page_dropdown; |
|
| 2156 | + } |
|
| 2157 | + |
|
| 2158 | + |
|
| 2159 | + /** |
|
| 2160 | + * _set_search_attributes |
|
| 2161 | + * |
|
| 2162 | + * @return void |
|
| 2163 | + */ |
|
| 2164 | + public function _set_search_attributes() |
|
| 2165 | + { |
|
| 2166 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2167 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2168 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2169 | + : $this->_search_btn_label |
|
| 2170 | + ); |
|
| 2171 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2172 | + } |
|
| 2173 | + |
|
| 2174 | + |
|
| 2175 | + |
|
| 2176 | + /*** END LIST TABLE METHODS **/ |
|
| 2177 | + |
|
| 2178 | + |
|
| 2179 | + /** |
|
| 2180 | + * _add_registered_metaboxes |
|
| 2181 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2182 | + * |
|
| 2183 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2184 | + * @return void |
|
| 2185 | + * @throws EE_Error |
|
| 2186 | + */ |
|
| 2187 | + private function _add_registered_meta_boxes() |
|
| 2188 | + { |
|
| 2189 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2190 | + // we only add meta boxes if the page_route calls for it |
|
| 2191 | + if ( |
|
| 2192 | + is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2193 | + && is_array( |
|
| 2194 | + $this->_route_config['metaboxes'] |
|
| 2195 | + ) |
|
| 2196 | + ) { |
|
| 2197 | + // this simply loops through the callbacks provided |
|
| 2198 | + // and checks if there is a corresponding callback registered by the child |
|
| 2199 | + // if there is then we go ahead and process the metabox loader. |
|
| 2200 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2201 | + // first check for Closures |
|
| 2202 | + if ($metabox_callback instanceof Closure) { |
|
| 2203 | + $result = $metabox_callback(); |
|
| 2204 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2205 | + $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2206 | + } else { |
|
| 2207 | + $result = $this->{$metabox_callback}(); |
|
| 2208 | + } |
|
| 2209 | + if ($result === false) { |
|
| 2210 | + // user error msg |
|
| 2211 | + $error_msg = esc_html__( |
|
| 2212 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2213 | + 'event_espresso' |
|
| 2214 | + ); |
|
| 2215 | + // developer error msg |
|
| 2216 | + $error_msg .= '||' |
|
| 2217 | + . sprintf( |
|
| 2218 | + esc_html__( |
|
| 2219 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2220 | + 'event_espresso' |
|
| 2221 | + ), |
|
| 2222 | + $metabox_callback |
|
| 2223 | + ); |
|
| 2224 | + throw new EE_Error($error_msg); |
|
| 2225 | + } |
|
| 2226 | + } |
|
| 2227 | + } |
|
| 2228 | + } |
|
| 2229 | + |
|
| 2230 | + |
|
| 2231 | + /** |
|
| 2232 | + * _add_screen_columns |
|
| 2233 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2234 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2235 | + * |
|
| 2236 | + * @return void |
|
| 2237 | + */ |
|
| 2238 | + private function _add_screen_columns() |
|
| 2239 | + { |
|
| 2240 | + if ( |
|
| 2241 | + is_array($this->_route_config) |
|
| 2242 | + && isset($this->_route_config['columns']) |
|
| 2243 | + && is_array($this->_route_config['columns']) |
|
| 2244 | + && count($this->_route_config['columns']) === 2 |
|
| 2245 | + ) { |
|
| 2246 | + add_screen_option( |
|
| 2247 | + 'layout_columns', |
|
| 2248 | + [ |
|
| 2249 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2250 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2251 | + ] |
|
| 2252 | + ); |
|
| 2253 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2254 | + $screen_id = $this->_current_screen->id; |
|
| 2255 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2256 | + $total_columns = ! empty($screen_columns) |
|
| 2257 | + ? $screen_columns |
|
| 2258 | + : $this->_route_config['columns'][1]; |
|
| 2259 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2260 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2261 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2262 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2263 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2264 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2265 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2266 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2267 | + } |
|
| 2268 | + } |
|
| 2269 | + |
|
| 2270 | + |
|
| 2271 | + |
|
| 2272 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2273 | + |
|
| 2274 | + |
|
| 2275 | + /** |
|
| 2276 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2277 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2278 | + * these get loaded on. |
|
| 2279 | + */ |
|
| 2280 | + private function _espresso_news_post_box() |
|
| 2281 | + { |
|
| 2282 | + $news_box_title = apply_filters( |
|
| 2283 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2284 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2285 | + ); |
|
| 2286 | + $this->addMetaBox( |
|
| 2287 | + 'espresso_news_post_box', |
|
| 2288 | + $news_box_title, |
|
| 2289 | + [ |
|
| 2290 | + $this, |
|
| 2291 | + 'espresso_news_post_box', |
|
| 2292 | + ], |
|
| 2293 | + $this->_wp_page_slug, |
|
| 2294 | + 'side', |
|
| 2295 | + 'low' |
|
| 2296 | + ); |
|
| 2297 | + } |
|
| 2298 | + |
|
| 2299 | + |
|
| 2300 | + /** |
|
| 2301 | + * Code for setting up espresso ratings request metabox. |
|
| 2302 | + */ |
|
| 2303 | + protected function _espresso_ratings_request() |
|
| 2304 | + { |
|
| 2305 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2306 | + return; |
|
| 2307 | + } |
|
| 2308 | + $ratings_box_title = apply_filters( |
|
| 2309 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2310 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2311 | + ); |
|
| 2312 | + $this->addMetaBox( |
|
| 2313 | + 'espresso_ratings_request', |
|
| 2314 | + $ratings_box_title, |
|
| 2315 | + [ |
|
| 2316 | + $this, |
|
| 2317 | + 'espresso_ratings_request', |
|
| 2318 | + ], |
|
| 2319 | + $this->_wp_page_slug, |
|
| 2320 | + 'side' |
|
| 2321 | + ); |
|
| 2322 | + } |
|
| 2323 | + |
|
| 2324 | + |
|
| 2325 | + /** |
|
| 2326 | + * Code for setting up espresso ratings request metabox content. |
|
| 2327 | + * |
|
| 2328 | + * @throws DomainException |
|
| 2329 | + */ |
|
| 2330 | + public function espresso_ratings_request() |
|
| 2331 | + { |
|
| 2332 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2333 | + } |
|
| 2334 | + |
|
| 2335 | + |
|
| 2336 | + public static function cached_rss_display($rss_id, $url) |
|
| 2337 | + { |
|
| 2338 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2339 | + . esc_html__('Loading…', 'event_espresso') |
|
| 2340 | + . '</p><p class="hide-if-js">' |
|
| 2341 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2342 | + . '</p>'; |
|
| 2343 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2344 | + $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2345 | + $post = '</div>' . "\n"; |
|
| 2346 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2347 | + $output = get_transient($cache_key); |
|
| 2348 | + if ($output !== false) { |
|
| 2349 | + echo $pre . $output . $post; // already escaped |
|
| 2350 | + return true; |
|
| 2351 | + } |
|
| 2352 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2353 | + echo $pre . $loading . $post; // already escaped |
|
| 2354 | + return false; |
|
| 2355 | + } |
|
| 2356 | + ob_start(); |
|
| 2357 | + wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2358 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2359 | + return true; |
|
| 2360 | + } |
|
| 2361 | + |
|
| 2362 | + |
|
| 2363 | + public function espresso_news_post_box() |
|
| 2364 | + { |
|
| 2365 | + ?> |
|
| 2366 | 2366 | <div class="padding"> |
| 2367 | 2367 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2368 | 2368 | <?php |
| 2369 | - // Get RSS Feed(s) |
|
| 2370 | - EE_Admin_Page::cached_rss_display( |
|
| 2371 | - 'espresso_news_post_box_content', |
|
| 2372 | - esc_url_raw( |
|
| 2373 | - apply_filters( |
|
| 2374 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2375 | - 'https://eventespresso.com/feed/' |
|
| 2376 | - ) |
|
| 2377 | - ) |
|
| 2378 | - ); |
|
| 2379 | - ?> |
|
| 2369 | + // Get RSS Feed(s) |
|
| 2370 | + EE_Admin_Page::cached_rss_display( |
|
| 2371 | + 'espresso_news_post_box_content', |
|
| 2372 | + esc_url_raw( |
|
| 2373 | + apply_filters( |
|
| 2374 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2375 | + 'https://eventespresso.com/feed/' |
|
| 2376 | + ) |
|
| 2377 | + ) |
|
| 2378 | + ); |
|
| 2379 | + ?> |
|
| 2380 | 2380 | </div> |
| 2381 | 2381 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2382 | 2382 | </div> |
| 2383 | 2383 | <?php |
| 2384 | - } |
|
| 2385 | - |
|
| 2386 | - |
|
| 2387 | - private function _espresso_links_post_box() |
|
| 2388 | - { |
|
| 2389 | - // Hiding until we actually have content to put in here... |
|
| 2390 | - // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2391 | - } |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - public function espresso_links_post_box() |
|
| 2395 | - { |
|
| 2396 | - // Hiding until we actually have content to put in here... |
|
| 2397 | - // EEH_Template::display_template( |
|
| 2398 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2399 | - // ); |
|
| 2400 | - } |
|
| 2401 | - |
|
| 2402 | - |
|
| 2403 | - protected function _espresso_sponsors_post_box() |
|
| 2404 | - { |
|
| 2405 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2406 | - $this->addMetaBox( |
|
| 2407 | - 'espresso_sponsors_post_box', |
|
| 2408 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2409 | - [$this, 'espresso_sponsors_post_box'], |
|
| 2410 | - $this->_wp_page_slug, |
|
| 2411 | - 'side' |
|
| 2412 | - ); |
|
| 2413 | - } |
|
| 2414 | - } |
|
| 2415 | - |
|
| 2416 | - |
|
| 2417 | - public function espresso_sponsors_post_box() |
|
| 2418 | - { |
|
| 2419 | - EEH_Template::display_template( |
|
| 2420 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2421 | - ); |
|
| 2422 | - } |
|
| 2423 | - |
|
| 2424 | - |
|
| 2425 | - private function _publish_post_box() |
|
| 2426 | - { |
|
| 2427 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2428 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2429 | - // then we'll use that for the metabox label. |
|
| 2430 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2431 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2432 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2433 | - : $this->_labels['publishbox']; |
|
| 2434 | - } else { |
|
| 2435 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2436 | - } |
|
| 2437 | - $box_label = apply_filters( |
|
| 2438 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2439 | - $box_label, |
|
| 2440 | - $this->_req_action, |
|
| 2441 | - $this |
|
| 2442 | - ); |
|
| 2443 | - $this->addMetaBox( |
|
| 2444 | - $meta_box_ref, |
|
| 2445 | - $box_label, |
|
| 2446 | - [$this, 'editor_overview'], |
|
| 2447 | - $this->_current_screen->id, |
|
| 2448 | - 'side', |
|
| 2449 | - 'high' |
|
| 2450 | - ); |
|
| 2451 | - } |
|
| 2452 | - |
|
| 2453 | - |
|
| 2454 | - public function editor_overview() |
|
| 2455 | - { |
|
| 2456 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2457 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2458 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2459 | - : ''; |
|
| 2460 | - echo EEH_Template::display_template( |
|
| 2461 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2462 | - $this->_template_args, |
|
| 2463 | - true |
|
| 2464 | - ); |
|
| 2465 | - } |
|
| 2466 | - |
|
| 2467 | - |
|
| 2468 | - /** end of globally available metaboxes section **/ |
|
| 2469 | - |
|
| 2470 | - |
|
| 2471 | - /** |
|
| 2472 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2473 | - * protected method. |
|
| 2474 | - * |
|
| 2475 | - * @param string $name |
|
| 2476 | - * @param int $id |
|
| 2477 | - * @param bool $delete |
|
| 2478 | - * @param string $save_close_redirect_URL |
|
| 2479 | - * @param bool $both_btns |
|
| 2480 | - * @throws EE_Error |
|
| 2481 | - * @throws InvalidArgumentException |
|
| 2482 | - * @throws InvalidDataTypeException |
|
| 2483 | - * @throws InvalidInterfaceException |
|
| 2484 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2485 | - * @since 4.6.0 |
|
| 2486 | - */ |
|
| 2487 | - public function set_publish_post_box_vars( |
|
| 2488 | - $name = '', |
|
| 2489 | - $id = 0, |
|
| 2490 | - $delete = false, |
|
| 2491 | - $save_close_redirect_URL = '', |
|
| 2492 | - $both_btns = true |
|
| 2493 | - ) { |
|
| 2494 | - $this->_set_publish_post_box_vars( |
|
| 2495 | - $name, |
|
| 2496 | - $id, |
|
| 2497 | - $delete, |
|
| 2498 | - $save_close_redirect_URL, |
|
| 2499 | - $both_btns |
|
| 2500 | - ); |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - |
|
| 2504 | - /** |
|
| 2505 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2506 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2507 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2508 | - * values for the name and id arguments. |
|
| 2509 | - * |
|
| 2510 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2511 | - * @param int $id id attached to the item published |
|
| 2512 | - * @param string $delete page route callback for the delete action |
|
| 2513 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2514 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2515 | - * the Save button |
|
| 2516 | - * @throws EE_Error |
|
| 2517 | - * @throws InvalidArgumentException |
|
| 2518 | - * @throws InvalidDataTypeException |
|
| 2519 | - * @throws InvalidInterfaceException |
|
| 2520 | - * @todo Add in validation for name/id arguments. |
|
| 2521 | - */ |
|
| 2522 | - protected function _set_publish_post_box_vars( |
|
| 2523 | - $name = '', |
|
| 2524 | - $id = 0, |
|
| 2525 | - $delete = '', |
|
| 2526 | - $save_close_redirect_URL = '', |
|
| 2527 | - $both_btns = true |
|
| 2528 | - ) { |
|
| 2529 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2530 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2531 | - ? $save_close_redirect_URL |
|
| 2532 | - : $this->_admin_base_url; |
|
| 2533 | - // create the Save & Close and Save buttons |
|
| 2534 | - $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2535 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2536 | - $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? ''; |
|
| 2537 | - $delete_link = ''; |
|
| 2538 | - if ($delete && ! empty($id)) { |
|
| 2539 | - // make sure we have a default if just true is sent. |
|
| 2540 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2541 | - $delete_link = $this->get_action_link_or_button( |
|
| 2542 | - $delete, |
|
| 2543 | - $delete, |
|
| 2544 | - [$name => $id], |
|
| 2545 | - 'submitdelete deletion button button--outline button--caution' |
|
| 2546 | - ); |
|
| 2547 | - } |
|
| 2548 | - $this->_template_args['publish_delete_link'] = $delete_link; |
|
| 2549 | - if (! empty($name) && ! empty($id)) { |
|
| 2550 | - $hidden_field_arr[ $name ] = [ |
|
| 2551 | - 'type' => 'hidden', |
|
| 2552 | - 'value' => $id, |
|
| 2553 | - ]; |
|
| 2554 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2555 | - } else { |
|
| 2556 | - $hf = ''; |
|
| 2557 | - } |
|
| 2558 | - // add hidden field |
|
| 2559 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2560 | - ? $hf[ $name ]['field'] |
|
| 2561 | - : $hf; |
|
| 2562 | - } |
|
| 2563 | - |
|
| 2564 | - |
|
| 2565 | - /** |
|
| 2566 | - * displays an error message to ppl who have javascript disabled |
|
| 2567 | - * |
|
| 2568 | - * @return void |
|
| 2569 | - */ |
|
| 2570 | - private function _display_no_javascript_warning() |
|
| 2571 | - { |
|
| 2572 | - ?> |
|
| 2384 | + } |
|
| 2385 | + |
|
| 2386 | + |
|
| 2387 | + private function _espresso_links_post_box() |
|
| 2388 | + { |
|
| 2389 | + // Hiding until we actually have content to put in here... |
|
| 2390 | + // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2391 | + } |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + public function espresso_links_post_box() |
|
| 2395 | + { |
|
| 2396 | + // Hiding until we actually have content to put in here... |
|
| 2397 | + // EEH_Template::display_template( |
|
| 2398 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2399 | + // ); |
|
| 2400 | + } |
|
| 2401 | + |
|
| 2402 | + |
|
| 2403 | + protected function _espresso_sponsors_post_box() |
|
| 2404 | + { |
|
| 2405 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2406 | + $this->addMetaBox( |
|
| 2407 | + 'espresso_sponsors_post_box', |
|
| 2408 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2409 | + [$this, 'espresso_sponsors_post_box'], |
|
| 2410 | + $this->_wp_page_slug, |
|
| 2411 | + 'side' |
|
| 2412 | + ); |
|
| 2413 | + } |
|
| 2414 | + } |
|
| 2415 | + |
|
| 2416 | + |
|
| 2417 | + public function espresso_sponsors_post_box() |
|
| 2418 | + { |
|
| 2419 | + EEH_Template::display_template( |
|
| 2420 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2421 | + ); |
|
| 2422 | + } |
|
| 2423 | + |
|
| 2424 | + |
|
| 2425 | + private function _publish_post_box() |
|
| 2426 | + { |
|
| 2427 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2428 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2429 | + // then we'll use that for the metabox label. |
|
| 2430 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2431 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2432 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2433 | + : $this->_labels['publishbox']; |
|
| 2434 | + } else { |
|
| 2435 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2436 | + } |
|
| 2437 | + $box_label = apply_filters( |
|
| 2438 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2439 | + $box_label, |
|
| 2440 | + $this->_req_action, |
|
| 2441 | + $this |
|
| 2442 | + ); |
|
| 2443 | + $this->addMetaBox( |
|
| 2444 | + $meta_box_ref, |
|
| 2445 | + $box_label, |
|
| 2446 | + [$this, 'editor_overview'], |
|
| 2447 | + $this->_current_screen->id, |
|
| 2448 | + 'side', |
|
| 2449 | + 'high' |
|
| 2450 | + ); |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + |
|
| 2454 | + public function editor_overview() |
|
| 2455 | + { |
|
| 2456 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2457 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2458 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2459 | + : ''; |
|
| 2460 | + echo EEH_Template::display_template( |
|
| 2461 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2462 | + $this->_template_args, |
|
| 2463 | + true |
|
| 2464 | + ); |
|
| 2465 | + } |
|
| 2466 | + |
|
| 2467 | + |
|
| 2468 | + /** end of globally available metaboxes section **/ |
|
| 2469 | + |
|
| 2470 | + |
|
| 2471 | + /** |
|
| 2472 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2473 | + * protected method. |
|
| 2474 | + * |
|
| 2475 | + * @param string $name |
|
| 2476 | + * @param int $id |
|
| 2477 | + * @param bool $delete |
|
| 2478 | + * @param string $save_close_redirect_URL |
|
| 2479 | + * @param bool $both_btns |
|
| 2480 | + * @throws EE_Error |
|
| 2481 | + * @throws InvalidArgumentException |
|
| 2482 | + * @throws InvalidDataTypeException |
|
| 2483 | + * @throws InvalidInterfaceException |
|
| 2484 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2485 | + * @since 4.6.0 |
|
| 2486 | + */ |
|
| 2487 | + public function set_publish_post_box_vars( |
|
| 2488 | + $name = '', |
|
| 2489 | + $id = 0, |
|
| 2490 | + $delete = false, |
|
| 2491 | + $save_close_redirect_URL = '', |
|
| 2492 | + $both_btns = true |
|
| 2493 | + ) { |
|
| 2494 | + $this->_set_publish_post_box_vars( |
|
| 2495 | + $name, |
|
| 2496 | + $id, |
|
| 2497 | + $delete, |
|
| 2498 | + $save_close_redirect_URL, |
|
| 2499 | + $both_btns |
|
| 2500 | + ); |
|
| 2501 | + } |
|
| 2502 | + |
|
| 2503 | + |
|
| 2504 | + /** |
|
| 2505 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2506 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2507 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2508 | + * values for the name and id arguments. |
|
| 2509 | + * |
|
| 2510 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2511 | + * @param int $id id attached to the item published |
|
| 2512 | + * @param string $delete page route callback for the delete action |
|
| 2513 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2514 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2515 | + * the Save button |
|
| 2516 | + * @throws EE_Error |
|
| 2517 | + * @throws InvalidArgumentException |
|
| 2518 | + * @throws InvalidDataTypeException |
|
| 2519 | + * @throws InvalidInterfaceException |
|
| 2520 | + * @todo Add in validation for name/id arguments. |
|
| 2521 | + */ |
|
| 2522 | + protected function _set_publish_post_box_vars( |
|
| 2523 | + $name = '', |
|
| 2524 | + $id = 0, |
|
| 2525 | + $delete = '', |
|
| 2526 | + $save_close_redirect_URL = '', |
|
| 2527 | + $both_btns = true |
|
| 2528 | + ) { |
|
| 2529 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2530 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2531 | + ? $save_close_redirect_URL |
|
| 2532 | + : $this->_admin_base_url; |
|
| 2533 | + // create the Save & Close and Save buttons |
|
| 2534 | + $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2535 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2536 | + $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? ''; |
|
| 2537 | + $delete_link = ''; |
|
| 2538 | + if ($delete && ! empty($id)) { |
|
| 2539 | + // make sure we have a default if just true is sent. |
|
| 2540 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2541 | + $delete_link = $this->get_action_link_or_button( |
|
| 2542 | + $delete, |
|
| 2543 | + $delete, |
|
| 2544 | + [$name => $id], |
|
| 2545 | + 'submitdelete deletion button button--outline button--caution' |
|
| 2546 | + ); |
|
| 2547 | + } |
|
| 2548 | + $this->_template_args['publish_delete_link'] = $delete_link; |
|
| 2549 | + if (! empty($name) && ! empty($id)) { |
|
| 2550 | + $hidden_field_arr[ $name ] = [ |
|
| 2551 | + 'type' => 'hidden', |
|
| 2552 | + 'value' => $id, |
|
| 2553 | + ]; |
|
| 2554 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2555 | + } else { |
|
| 2556 | + $hf = ''; |
|
| 2557 | + } |
|
| 2558 | + // add hidden field |
|
| 2559 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2560 | + ? $hf[ $name ]['field'] |
|
| 2561 | + : $hf; |
|
| 2562 | + } |
|
| 2563 | + |
|
| 2564 | + |
|
| 2565 | + /** |
|
| 2566 | + * displays an error message to ppl who have javascript disabled |
|
| 2567 | + * |
|
| 2568 | + * @return void |
|
| 2569 | + */ |
|
| 2570 | + private function _display_no_javascript_warning() |
|
| 2571 | + { |
|
| 2572 | + ?> |
|
| 2573 | 2573 | <noscript> |
| 2574 | 2574 | <div id="no-js-message" class="error"> |
| 2575 | 2575 | <p style="font-size:1.3em;"> |
| 2576 | 2576 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2577 | 2577 | <?php esc_html_e( |
| 2578 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2579 | - 'event_espresso' |
|
| 2580 | - ); ?> |
|
| 2578 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2579 | + 'event_espresso' |
|
| 2580 | + ); ?> |
|
| 2581 | 2581 | </p> |
| 2582 | 2582 | </div> |
| 2583 | 2583 | </noscript> |
| 2584 | 2584 | <?php |
| 2585 | - } |
|
| 2586 | - |
|
| 2587 | - |
|
| 2588 | - /** |
|
| 2589 | - * displays espresso success and/or error notices |
|
| 2590 | - * |
|
| 2591 | - * @return void |
|
| 2592 | - */ |
|
| 2593 | - protected function _display_espresso_notices() |
|
| 2594 | - { |
|
| 2595 | - $notices = $this->_get_transient(true); |
|
| 2596 | - echo stripslashes($notices); |
|
| 2597 | - } |
|
| 2598 | - |
|
| 2599 | - |
|
| 2600 | - /** |
|
| 2601 | - * spinny things pacify the masses |
|
| 2602 | - * |
|
| 2603 | - * @return void |
|
| 2604 | - */ |
|
| 2605 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2606 | - { |
|
| 2607 | - ?> |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + |
|
| 2588 | + /** |
|
| 2589 | + * displays espresso success and/or error notices |
|
| 2590 | + * |
|
| 2591 | + * @return void |
|
| 2592 | + */ |
|
| 2593 | + protected function _display_espresso_notices() |
|
| 2594 | + { |
|
| 2595 | + $notices = $this->_get_transient(true); |
|
| 2596 | + echo stripslashes($notices); |
|
| 2597 | + } |
|
| 2598 | + |
|
| 2599 | + |
|
| 2600 | + /** |
|
| 2601 | + * spinny things pacify the masses |
|
| 2602 | + * |
|
| 2603 | + * @return void |
|
| 2604 | + */ |
|
| 2605 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2606 | + { |
|
| 2607 | + ?> |
|
| 2608 | 2608 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2609 | 2609 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2610 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2610 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2611 | 2611 | </div> |
| 2612 | 2612 | <?php |
| 2613 | - } |
|
| 2613 | + } |
|
| 2614 | 2614 | |
| 2615 | 2615 | |
| 2616 | - /** |
|
| 2617 | - * add admin page overlay for modal boxes |
|
| 2618 | - * |
|
| 2619 | - * @return void |
|
| 2620 | - */ |
|
| 2621 | - protected function _add_admin_page_overlay() |
|
| 2622 | - { |
|
| 2623 | - ?> |
|
| 2616 | + /** |
|
| 2617 | + * add admin page overlay for modal boxes |
|
| 2618 | + * |
|
| 2619 | + * @return void |
|
| 2620 | + */ |
|
| 2621 | + protected function _add_admin_page_overlay() |
|
| 2622 | + { |
|
| 2623 | + ?> |
|
| 2624 | 2624 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2625 | 2625 | <?php |
| 2626 | - } |
|
| 2627 | - |
|
| 2628 | - |
|
| 2629 | - /** |
|
| 2630 | - * facade for $this->addMetaBox() |
|
| 2631 | - * |
|
| 2632 | - * @param string $action where the metabox gets displayed |
|
| 2633 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2634 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2635 | - * instead of the one created in here. |
|
| 2636 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2637 | - * @param string $column what metabox column |
|
| 2638 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2639 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2640 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2641 | - * @throws DomainException |
|
| 2642 | - */ |
|
| 2643 | - public function _add_admin_page_meta_box( |
|
| 2644 | - $action, |
|
| 2645 | - $title, |
|
| 2646 | - $callback, |
|
| 2647 | - $callback_args, |
|
| 2648 | - $column = 'normal', |
|
| 2649 | - $priority = 'high', |
|
| 2650 | - $create_func = true |
|
| 2651 | - ) { |
|
| 2652 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2653 | - // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2654 | - if (empty($callback_args) && $create_func) { |
|
| 2655 | - $callback_args = [ |
|
| 2656 | - 'template_path' => $this->_template_path, |
|
| 2657 | - 'template_args' => $this->_template_args, |
|
| 2658 | - ]; |
|
| 2659 | - } |
|
| 2660 | - // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2661 | - $call_back_func = $create_func |
|
| 2662 | - ? static function ($post, $metabox) { |
|
| 2663 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2664 | - echo EEH_Template::display_template( |
|
| 2665 | - $metabox['args']['template_path'], |
|
| 2666 | - $metabox['args']['template_args'], |
|
| 2667 | - true |
|
| 2668 | - ); |
|
| 2669 | - } |
|
| 2670 | - : $callback; |
|
| 2671 | - $this->addMetaBox( |
|
| 2672 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2673 | - $title, |
|
| 2674 | - $call_back_func, |
|
| 2675 | - $this->_wp_page_slug, |
|
| 2676 | - $column, |
|
| 2677 | - $priority, |
|
| 2678 | - $callback_args |
|
| 2679 | - ); |
|
| 2680 | - } |
|
| 2681 | - |
|
| 2682 | - |
|
| 2683 | - /** |
|
| 2684 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2685 | - * |
|
| 2686 | - * @throws DomainException |
|
| 2687 | - * @throws EE_Error |
|
| 2688 | - * @throws InvalidArgumentException |
|
| 2689 | - * @throws InvalidDataTypeException |
|
| 2690 | - * @throws InvalidInterfaceException |
|
| 2691 | - */ |
|
| 2692 | - public function display_admin_page_with_metabox_columns() |
|
| 2693 | - { |
|
| 2694 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2695 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2696 | - $this->_column_template_path, |
|
| 2697 | - $this->_template_args, |
|
| 2698 | - true |
|
| 2699 | - ); |
|
| 2700 | - // the final wrapper |
|
| 2701 | - $this->admin_page_wrapper(); |
|
| 2702 | - } |
|
| 2703 | - |
|
| 2704 | - |
|
| 2705 | - /** |
|
| 2706 | - * generates HTML wrapper for an admin details page |
|
| 2707 | - * |
|
| 2708 | - * @return void |
|
| 2709 | - * @throws DomainException |
|
| 2710 | - * @throws EE_Error |
|
| 2711 | - * @throws InvalidArgumentException |
|
| 2712 | - * @throws InvalidDataTypeException |
|
| 2713 | - * @throws InvalidInterfaceException |
|
| 2714 | - */ |
|
| 2715 | - public function display_admin_page_with_sidebar() |
|
| 2716 | - { |
|
| 2717 | - $this->_display_admin_page(true); |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - |
|
| 2721 | - /** |
|
| 2722 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2723 | - * |
|
| 2724 | - * @return void |
|
| 2725 | - * @throws DomainException |
|
| 2726 | - * @throws EE_Error |
|
| 2727 | - * @throws InvalidArgumentException |
|
| 2728 | - * @throws InvalidDataTypeException |
|
| 2729 | - * @throws InvalidInterfaceException |
|
| 2730 | - */ |
|
| 2731 | - public function display_admin_page_with_no_sidebar() |
|
| 2732 | - { |
|
| 2733 | - $this->_display_admin_page(); |
|
| 2734 | - } |
|
| 2735 | - |
|
| 2736 | - |
|
| 2737 | - /** |
|
| 2738 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2739 | - * |
|
| 2740 | - * @return void |
|
| 2741 | - * @throws DomainException |
|
| 2742 | - * @throws EE_Error |
|
| 2743 | - * @throws InvalidArgumentException |
|
| 2744 | - * @throws InvalidDataTypeException |
|
| 2745 | - * @throws InvalidInterfaceException |
|
| 2746 | - */ |
|
| 2747 | - public function display_about_admin_page() |
|
| 2748 | - { |
|
| 2749 | - $this->_display_admin_page(false, true); |
|
| 2750 | - } |
|
| 2751 | - |
|
| 2752 | - |
|
| 2753 | - /** |
|
| 2754 | - * display_admin_page |
|
| 2755 | - * contains the code for actually displaying an admin page |
|
| 2756 | - * |
|
| 2757 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2758 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2759 | - * @return void |
|
| 2760 | - * @throws DomainException |
|
| 2761 | - * @throws EE_Error |
|
| 2762 | - * @throws InvalidArgumentException |
|
| 2763 | - * @throws InvalidDataTypeException |
|
| 2764 | - * @throws InvalidInterfaceException |
|
| 2765 | - */ |
|
| 2766 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2767 | - { |
|
| 2768 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2769 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2770 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2771 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2772 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2773 | - |
|
| 2774 | - $post_body_content = $this->_template_args['before_admin_page_content'] ?? ''; |
|
| 2775 | - |
|
| 2776 | - $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status' |
|
| 2777 | - && $this->_req_action !== 'data_reset' |
|
| 2778 | - && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages' |
|
| 2779 | - && strpos($post_body_content, 'wp-list-table') === false; |
|
| 2780 | - |
|
| 2781 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2782 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2783 | - ? 'poststuff' |
|
| 2784 | - : 'espresso-default-admin'; |
|
| 2785 | - $this->_template_args['admin_page_wrapper_div_class'] = str_replace( |
|
| 2786 | - 'event-espresso_page_espresso_', |
|
| 2787 | - '', |
|
| 2788 | - $this->_wp_page_slug |
|
| 2789 | - ) . ' ' . $this->_req_action . '-route'; |
|
| 2790 | - |
|
| 2791 | - $template_path = $sidebar |
|
| 2792 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2793 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2794 | - if ($this->request->isAjax()) { |
|
| 2795 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2796 | - } |
|
| 2797 | - $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2798 | - |
|
| 2799 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'] ?? ''; |
|
| 2800 | - $this->_template_args['before_admin_page_content'] = $post_body_content; |
|
| 2801 | - $this->_template_args['after_admin_page_content'] = $this->_template_args['after_admin_page_content'] ?? ''; |
|
| 2802 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2803 | - $template_path, |
|
| 2804 | - $this->_template_args, |
|
| 2805 | - true |
|
| 2806 | - ); |
|
| 2807 | - // the final template wrapper |
|
| 2808 | - $this->admin_page_wrapper($about); |
|
| 2809 | - } |
|
| 2810 | - |
|
| 2811 | - |
|
| 2812 | - /** |
|
| 2813 | - * This is used to display caf preview pages. |
|
| 2814 | - * |
|
| 2815 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2816 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2817 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2818 | - * @return void |
|
| 2819 | - * @throws DomainException |
|
| 2820 | - * @throws EE_Error |
|
| 2821 | - * @throws InvalidArgumentException |
|
| 2822 | - * @throws InvalidDataTypeException |
|
| 2823 | - * @throws InvalidInterfaceException |
|
| 2824 | - * @since 4.3.2 |
|
| 2825 | - */ |
|
| 2826 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2827 | - { |
|
| 2828 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2829 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2830 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2831 | - 'event_espresso' |
|
| 2832 | - ); |
|
| 2833 | - $buy_now_url = add_query_arg( |
|
| 2834 | - [ |
|
| 2835 | - 'ee_ver' => 'ee4', |
|
| 2836 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2837 | - 'utm_medium' => 'link', |
|
| 2838 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2839 | - 'utm_content' => 'buy_now_button', |
|
| 2840 | - ], |
|
| 2841 | - 'https://eventespresso.com/pricing/' |
|
| 2842 | - ); |
|
| 2843 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2844 | - ? $this->get_action_link_or_button( |
|
| 2845 | - '', |
|
| 2846 | - 'buy_now', |
|
| 2847 | - [], |
|
| 2848 | - 'button button--primary button--big', |
|
| 2849 | - esc_url_raw($buy_now_url), |
|
| 2850 | - true |
|
| 2851 | - ) |
|
| 2852 | - : $this->_template_args['preview_action_button']; |
|
| 2853 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2854 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2855 | - $this->_template_args, |
|
| 2856 | - true |
|
| 2857 | - ); |
|
| 2858 | - $this->_display_admin_page($display_sidebar); |
|
| 2859 | - } |
|
| 2860 | - |
|
| 2861 | - |
|
| 2862 | - /** |
|
| 2863 | - * display_admin_list_table_page_with_sidebar |
|
| 2864 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2865 | - * |
|
| 2866 | - * @return void |
|
| 2867 | - * @throws DomainException |
|
| 2868 | - * @throws EE_Error |
|
| 2869 | - * @throws InvalidArgumentException |
|
| 2870 | - * @throws InvalidDataTypeException |
|
| 2871 | - * @throws InvalidInterfaceException |
|
| 2872 | - */ |
|
| 2873 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2874 | - { |
|
| 2875 | - $this->_display_admin_list_table_page(true); |
|
| 2876 | - } |
|
| 2877 | - |
|
| 2878 | - |
|
| 2879 | - /** |
|
| 2880 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2881 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2882 | - * |
|
| 2883 | - * @return void |
|
| 2884 | - * @throws DomainException |
|
| 2885 | - * @throws EE_Error |
|
| 2886 | - * @throws InvalidArgumentException |
|
| 2887 | - * @throws InvalidDataTypeException |
|
| 2888 | - * @throws InvalidInterfaceException |
|
| 2889 | - */ |
|
| 2890 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2891 | - { |
|
| 2892 | - $this->_display_admin_list_table_page(); |
|
| 2893 | - } |
|
| 2894 | - |
|
| 2895 | - |
|
| 2896 | - /** |
|
| 2897 | - * generates html wrapper for an admin_list_table page |
|
| 2898 | - * |
|
| 2899 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2900 | - * @return void |
|
| 2901 | - * @throws DomainException |
|
| 2902 | - * @throws EE_Error |
|
| 2903 | - * @throws InvalidArgumentException |
|
| 2904 | - * @throws InvalidDataTypeException |
|
| 2905 | - * @throws InvalidInterfaceException |
|
| 2906 | - */ |
|
| 2907 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2908 | - { |
|
| 2909 | - // setup search attributes |
|
| 2910 | - $this->_set_search_attributes(); |
|
| 2911 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2912 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2913 | - $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2914 | - ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2915 | - : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2916 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2917 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2918 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2919 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2920 | - if (! empty($ajax_sorting_callback)) { |
|
| 2921 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2922 | - $ajax_sorting_callback . '_nonce', |
|
| 2923 | - $ajax_sorting_callback . '_nonce', |
|
| 2924 | - false, |
|
| 2925 | - false |
|
| 2926 | - ); |
|
| 2927 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2928 | - . $this->page_slug |
|
| 2929 | - . '" />'; |
|
| 2930 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2931 | - . $ajax_sorting_callback |
|
| 2932 | - . '" />'; |
|
| 2933 | - } else { |
|
| 2934 | - $sortable_list_table_form_fields = ''; |
|
| 2935 | - } |
|
| 2936 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2937 | - |
|
| 2938 | - $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? ''; |
|
| 2939 | - |
|
| 2940 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2941 | - $hidden_form_fields .= ' |
|
| 2626 | + } |
|
| 2627 | + |
|
| 2628 | + |
|
| 2629 | + /** |
|
| 2630 | + * facade for $this->addMetaBox() |
|
| 2631 | + * |
|
| 2632 | + * @param string $action where the metabox gets displayed |
|
| 2633 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2634 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2635 | + * instead of the one created in here. |
|
| 2636 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2637 | + * @param string $column what metabox column |
|
| 2638 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2639 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2640 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2641 | + * @throws DomainException |
|
| 2642 | + */ |
|
| 2643 | + public function _add_admin_page_meta_box( |
|
| 2644 | + $action, |
|
| 2645 | + $title, |
|
| 2646 | + $callback, |
|
| 2647 | + $callback_args, |
|
| 2648 | + $column = 'normal', |
|
| 2649 | + $priority = 'high', |
|
| 2650 | + $create_func = true |
|
| 2651 | + ) { |
|
| 2652 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2653 | + // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2654 | + if (empty($callback_args) && $create_func) { |
|
| 2655 | + $callback_args = [ |
|
| 2656 | + 'template_path' => $this->_template_path, |
|
| 2657 | + 'template_args' => $this->_template_args, |
|
| 2658 | + ]; |
|
| 2659 | + } |
|
| 2660 | + // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2661 | + $call_back_func = $create_func |
|
| 2662 | + ? static function ($post, $metabox) { |
|
| 2663 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2664 | + echo EEH_Template::display_template( |
|
| 2665 | + $metabox['args']['template_path'], |
|
| 2666 | + $metabox['args']['template_args'], |
|
| 2667 | + true |
|
| 2668 | + ); |
|
| 2669 | + } |
|
| 2670 | + : $callback; |
|
| 2671 | + $this->addMetaBox( |
|
| 2672 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2673 | + $title, |
|
| 2674 | + $call_back_func, |
|
| 2675 | + $this->_wp_page_slug, |
|
| 2676 | + $column, |
|
| 2677 | + $priority, |
|
| 2678 | + $callback_args |
|
| 2679 | + ); |
|
| 2680 | + } |
|
| 2681 | + |
|
| 2682 | + |
|
| 2683 | + /** |
|
| 2684 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2685 | + * |
|
| 2686 | + * @throws DomainException |
|
| 2687 | + * @throws EE_Error |
|
| 2688 | + * @throws InvalidArgumentException |
|
| 2689 | + * @throws InvalidDataTypeException |
|
| 2690 | + * @throws InvalidInterfaceException |
|
| 2691 | + */ |
|
| 2692 | + public function display_admin_page_with_metabox_columns() |
|
| 2693 | + { |
|
| 2694 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2695 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2696 | + $this->_column_template_path, |
|
| 2697 | + $this->_template_args, |
|
| 2698 | + true |
|
| 2699 | + ); |
|
| 2700 | + // the final wrapper |
|
| 2701 | + $this->admin_page_wrapper(); |
|
| 2702 | + } |
|
| 2703 | + |
|
| 2704 | + |
|
| 2705 | + /** |
|
| 2706 | + * generates HTML wrapper for an admin details page |
|
| 2707 | + * |
|
| 2708 | + * @return void |
|
| 2709 | + * @throws DomainException |
|
| 2710 | + * @throws EE_Error |
|
| 2711 | + * @throws InvalidArgumentException |
|
| 2712 | + * @throws InvalidDataTypeException |
|
| 2713 | + * @throws InvalidInterfaceException |
|
| 2714 | + */ |
|
| 2715 | + public function display_admin_page_with_sidebar() |
|
| 2716 | + { |
|
| 2717 | + $this->_display_admin_page(true); |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + |
|
| 2721 | + /** |
|
| 2722 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2723 | + * |
|
| 2724 | + * @return void |
|
| 2725 | + * @throws DomainException |
|
| 2726 | + * @throws EE_Error |
|
| 2727 | + * @throws InvalidArgumentException |
|
| 2728 | + * @throws InvalidDataTypeException |
|
| 2729 | + * @throws InvalidInterfaceException |
|
| 2730 | + */ |
|
| 2731 | + public function display_admin_page_with_no_sidebar() |
|
| 2732 | + { |
|
| 2733 | + $this->_display_admin_page(); |
|
| 2734 | + } |
|
| 2735 | + |
|
| 2736 | + |
|
| 2737 | + /** |
|
| 2738 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2739 | + * |
|
| 2740 | + * @return void |
|
| 2741 | + * @throws DomainException |
|
| 2742 | + * @throws EE_Error |
|
| 2743 | + * @throws InvalidArgumentException |
|
| 2744 | + * @throws InvalidDataTypeException |
|
| 2745 | + * @throws InvalidInterfaceException |
|
| 2746 | + */ |
|
| 2747 | + public function display_about_admin_page() |
|
| 2748 | + { |
|
| 2749 | + $this->_display_admin_page(false, true); |
|
| 2750 | + } |
|
| 2751 | + |
|
| 2752 | + |
|
| 2753 | + /** |
|
| 2754 | + * display_admin_page |
|
| 2755 | + * contains the code for actually displaying an admin page |
|
| 2756 | + * |
|
| 2757 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2758 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2759 | + * @return void |
|
| 2760 | + * @throws DomainException |
|
| 2761 | + * @throws EE_Error |
|
| 2762 | + * @throws InvalidArgumentException |
|
| 2763 | + * @throws InvalidDataTypeException |
|
| 2764 | + * @throws InvalidInterfaceException |
|
| 2765 | + */ |
|
| 2766 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2767 | + { |
|
| 2768 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2769 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2770 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2771 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2772 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2773 | + |
|
| 2774 | + $post_body_content = $this->_template_args['before_admin_page_content'] ?? ''; |
|
| 2775 | + |
|
| 2776 | + $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status' |
|
| 2777 | + && $this->_req_action !== 'data_reset' |
|
| 2778 | + && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages' |
|
| 2779 | + && strpos($post_body_content, 'wp-list-table') === false; |
|
| 2780 | + |
|
| 2781 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2782 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2783 | + ? 'poststuff' |
|
| 2784 | + : 'espresso-default-admin'; |
|
| 2785 | + $this->_template_args['admin_page_wrapper_div_class'] = str_replace( |
|
| 2786 | + 'event-espresso_page_espresso_', |
|
| 2787 | + '', |
|
| 2788 | + $this->_wp_page_slug |
|
| 2789 | + ) . ' ' . $this->_req_action . '-route'; |
|
| 2790 | + |
|
| 2791 | + $template_path = $sidebar |
|
| 2792 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2793 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2794 | + if ($this->request->isAjax()) { |
|
| 2795 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2796 | + } |
|
| 2797 | + $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2798 | + |
|
| 2799 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'] ?? ''; |
|
| 2800 | + $this->_template_args['before_admin_page_content'] = $post_body_content; |
|
| 2801 | + $this->_template_args['after_admin_page_content'] = $this->_template_args['after_admin_page_content'] ?? ''; |
|
| 2802 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2803 | + $template_path, |
|
| 2804 | + $this->_template_args, |
|
| 2805 | + true |
|
| 2806 | + ); |
|
| 2807 | + // the final template wrapper |
|
| 2808 | + $this->admin_page_wrapper($about); |
|
| 2809 | + } |
|
| 2810 | + |
|
| 2811 | + |
|
| 2812 | + /** |
|
| 2813 | + * This is used to display caf preview pages. |
|
| 2814 | + * |
|
| 2815 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2816 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2817 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2818 | + * @return void |
|
| 2819 | + * @throws DomainException |
|
| 2820 | + * @throws EE_Error |
|
| 2821 | + * @throws InvalidArgumentException |
|
| 2822 | + * @throws InvalidDataTypeException |
|
| 2823 | + * @throws InvalidInterfaceException |
|
| 2824 | + * @since 4.3.2 |
|
| 2825 | + */ |
|
| 2826 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2827 | + { |
|
| 2828 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2829 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2830 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2831 | + 'event_espresso' |
|
| 2832 | + ); |
|
| 2833 | + $buy_now_url = add_query_arg( |
|
| 2834 | + [ |
|
| 2835 | + 'ee_ver' => 'ee4', |
|
| 2836 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2837 | + 'utm_medium' => 'link', |
|
| 2838 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2839 | + 'utm_content' => 'buy_now_button', |
|
| 2840 | + ], |
|
| 2841 | + 'https://eventespresso.com/pricing/' |
|
| 2842 | + ); |
|
| 2843 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2844 | + ? $this->get_action_link_or_button( |
|
| 2845 | + '', |
|
| 2846 | + 'buy_now', |
|
| 2847 | + [], |
|
| 2848 | + 'button button--primary button--big', |
|
| 2849 | + esc_url_raw($buy_now_url), |
|
| 2850 | + true |
|
| 2851 | + ) |
|
| 2852 | + : $this->_template_args['preview_action_button']; |
|
| 2853 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2854 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2855 | + $this->_template_args, |
|
| 2856 | + true |
|
| 2857 | + ); |
|
| 2858 | + $this->_display_admin_page($display_sidebar); |
|
| 2859 | + } |
|
| 2860 | + |
|
| 2861 | + |
|
| 2862 | + /** |
|
| 2863 | + * display_admin_list_table_page_with_sidebar |
|
| 2864 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2865 | + * |
|
| 2866 | + * @return void |
|
| 2867 | + * @throws DomainException |
|
| 2868 | + * @throws EE_Error |
|
| 2869 | + * @throws InvalidArgumentException |
|
| 2870 | + * @throws InvalidDataTypeException |
|
| 2871 | + * @throws InvalidInterfaceException |
|
| 2872 | + */ |
|
| 2873 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2874 | + { |
|
| 2875 | + $this->_display_admin_list_table_page(true); |
|
| 2876 | + } |
|
| 2877 | + |
|
| 2878 | + |
|
| 2879 | + /** |
|
| 2880 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2881 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2882 | + * |
|
| 2883 | + * @return void |
|
| 2884 | + * @throws DomainException |
|
| 2885 | + * @throws EE_Error |
|
| 2886 | + * @throws InvalidArgumentException |
|
| 2887 | + * @throws InvalidDataTypeException |
|
| 2888 | + * @throws InvalidInterfaceException |
|
| 2889 | + */ |
|
| 2890 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2891 | + { |
|
| 2892 | + $this->_display_admin_list_table_page(); |
|
| 2893 | + } |
|
| 2894 | + |
|
| 2895 | + |
|
| 2896 | + /** |
|
| 2897 | + * generates html wrapper for an admin_list_table page |
|
| 2898 | + * |
|
| 2899 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2900 | + * @return void |
|
| 2901 | + * @throws DomainException |
|
| 2902 | + * @throws EE_Error |
|
| 2903 | + * @throws InvalidArgumentException |
|
| 2904 | + * @throws InvalidDataTypeException |
|
| 2905 | + * @throws InvalidInterfaceException |
|
| 2906 | + */ |
|
| 2907 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2908 | + { |
|
| 2909 | + // setup search attributes |
|
| 2910 | + $this->_set_search_attributes(); |
|
| 2911 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2912 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2913 | + $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2914 | + ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2915 | + : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2916 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2917 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2918 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2919 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2920 | + if (! empty($ajax_sorting_callback)) { |
|
| 2921 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2922 | + $ajax_sorting_callback . '_nonce', |
|
| 2923 | + $ajax_sorting_callback . '_nonce', |
|
| 2924 | + false, |
|
| 2925 | + false |
|
| 2926 | + ); |
|
| 2927 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2928 | + . $this->page_slug |
|
| 2929 | + . '" />'; |
|
| 2930 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2931 | + . $ajax_sorting_callback |
|
| 2932 | + . '" />'; |
|
| 2933 | + } else { |
|
| 2934 | + $sortable_list_table_form_fields = ''; |
|
| 2935 | + } |
|
| 2936 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2937 | + |
|
| 2938 | + $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? ''; |
|
| 2939 | + |
|
| 2940 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2941 | + $hidden_form_fields .= ' |
|
| 2942 | 2942 | <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
| 2943 | 2943 | |
| 2944 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2945 | - // display message about search results? |
|
| 2946 | - $search = $this->request->getRequestParam('s'); |
|
| 2947 | - $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2948 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2949 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2950 | - trim($search, '%') |
|
| 2951 | - ) . '</p>' |
|
| 2952 | - : ''; |
|
| 2953 | - // filter before_list_table template arg |
|
| 2954 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 2955 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2956 | - $this->_template_args['before_list_table'], |
|
| 2957 | - $this->page_slug, |
|
| 2958 | - $this->request->requestParams(), |
|
| 2959 | - $this->_req_action |
|
| 2960 | - ); |
|
| 2961 | - // convert to array and filter again |
|
| 2962 | - // arrays are easier to inject new items in a specific location, |
|
| 2963 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2964 | - $this->_template_args['before_list_table'] = implode( |
|
| 2965 | - " \n", |
|
| 2966 | - (array) apply_filters( |
|
| 2967 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2968 | - (array) $this->_template_args['before_list_table'], |
|
| 2969 | - $this->page_slug, |
|
| 2970 | - $this->request->requestParams(), |
|
| 2971 | - $this->_req_action |
|
| 2972 | - ) |
|
| 2973 | - ); |
|
| 2974 | - // filter after_list_table template arg |
|
| 2975 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 2976 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2977 | - $this->_template_args['after_list_table'], |
|
| 2978 | - $this->page_slug, |
|
| 2979 | - $this->request->requestParams(), |
|
| 2980 | - $this->_req_action |
|
| 2981 | - ); |
|
| 2982 | - // convert to array and filter again |
|
| 2983 | - // arrays are easier to inject new items in a specific location, |
|
| 2984 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2985 | - $this->_template_args['after_list_table'] = implode( |
|
| 2986 | - " \n", |
|
| 2987 | - (array) apply_filters( |
|
| 2988 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2989 | - (array) $this->_template_args['after_list_table'], |
|
| 2990 | - $this->page_slug, |
|
| 2991 | - $this->request->requestParams(), |
|
| 2992 | - $this->_req_action |
|
| 2993 | - ) |
|
| 2994 | - ); |
|
| 2995 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2996 | - $template_path, |
|
| 2997 | - $this->_template_args, |
|
| 2998 | - true |
|
| 2999 | - ); |
|
| 3000 | - // the final template wrapper |
|
| 3001 | - if ($sidebar) { |
|
| 3002 | - $this->display_admin_page_with_sidebar(); |
|
| 3003 | - } else { |
|
| 3004 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3005 | - } |
|
| 3006 | - } |
|
| 3007 | - |
|
| 3008 | - |
|
| 3009 | - /** |
|
| 3010 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3011 | - * html string for the legend. |
|
| 3012 | - * $items are expected in an array in the following format: |
|
| 3013 | - * $legend_items = array( |
|
| 3014 | - * 'item_id' => array( |
|
| 3015 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3016 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3017 | - * ) |
|
| 3018 | - * ); |
|
| 3019 | - * |
|
| 3020 | - * @param array $items see above for format of array |
|
| 3021 | - * @return string html string of legend |
|
| 3022 | - * @throws DomainException |
|
| 3023 | - */ |
|
| 3024 | - protected function _display_legend($items) |
|
| 3025 | - { |
|
| 3026 | - $this->_template_args['items'] = apply_filters( |
|
| 3027 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3028 | - (array) $items, |
|
| 3029 | - $this |
|
| 3030 | - ); |
|
| 3031 | - /** @var StatusChangeNotice $status_change_notice */ |
|
| 3032 | - $status_change_notice = $this->loader->getShared( |
|
| 3033 | - 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 3034 | - ); |
|
| 3035 | - $this->_template_args['status_change_notice'] = $status_change_notice->display( |
|
| 3036 | - '__admin-legend', |
|
| 3037 | - $this->page_slug |
|
| 3038 | - ); |
|
| 3039 | - return EEH_Template::display_template( |
|
| 3040 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3041 | - $this->_template_args, |
|
| 3042 | - true |
|
| 3043 | - ); |
|
| 3044 | - } |
|
| 3045 | - |
|
| 3046 | - |
|
| 3047 | - /** |
|
| 3048 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3049 | - * The returned json object is created from an array in the following format: |
|
| 3050 | - * array( |
|
| 3051 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3052 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3053 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3054 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3055 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3056 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3057 | - * that might be included in here) |
|
| 3058 | - * ) |
|
| 3059 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3060 | - * |
|
| 3061 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3062 | - * instead of displayed. |
|
| 3063 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3064 | - * @return void |
|
| 3065 | - * @throws EE_Error |
|
| 3066 | - * @throws InvalidArgumentException |
|
| 3067 | - * @throws InvalidDataTypeException |
|
| 3068 | - * @throws InvalidInterfaceException |
|
| 3069 | - */ |
|
| 3070 | - protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 3071 | - { |
|
| 3072 | - // make sure any EE_Error notices have been handled. |
|
| 3073 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3074 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 3075 | - unset($this->_template_args['data']); |
|
| 3076 | - $json = [ |
|
| 3077 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3078 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3079 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3080 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3081 | - 'notices' => EE_Error::get_notices(), |
|
| 3082 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3083 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3084 | - 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3085 | - 'isEEajax' => true |
|
| 3086 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3087 | - ]; |
|
| 3088 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3089 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3090 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3091 | - } |
|
| 3092 | - echo wp_json_encode($json); |
|
| 3093 | - exit(); |
|
| 3094 | - } |
|
| 3095 | - |
|
| 3096 | - |
|
| 3097 | - /** |
|
| 3098 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3099 | - * |
|
| 3100 | - * @return void |
|
| 3101 | - * @throws EE_Error |
|
| 3102 | - * @throws InvalidArgumentException |
|
| 3103 | - * @throws InvalidDataTypeException |
|
| 3104 | - * @throws InvalidInterfaceException |
|
| 3105 | - */ |
|
| 3106 | - public function return_json() |
|
| 3107 | - { |
|
| 3108 | - if ($this->request->isAjax()) { |
|
| 3109 | - $this->_return_json(); |
|
| 3110 | - } else { |
|
| 3111 | - throw new EE_Error( |
|
| 3112 | - sprintf( |
|
| 3113 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3114 | - __FUNCTION__ |
|
| 3115 | - ) |
|
| 3116 | - ); |
|
| 3117 | - } |
|
| 3118 | - } |
|
| 3119 | - |
|
| 3120 | - |
|
| 3121 | - /** |
|
| 3122 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3123 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3124 | - * |
|
| 3125 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3126 | - */ |
|
| 3127 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3128 | - { |
|
| 3129 | - $this->_hook_obj = $hook_obj; |
|
| 3130 | - } |
|
| 3131 | - |
|
| 3132 | - |
|
| 3133 | - /** |
|
| 3134 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3135 | - * |
|
| 3136 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3137 | - * @return void |
|
| 3138 | - * @throws DomainException |
|
| 3139 | - * @throws EE_Error |
|
| 3140 | - * @throws InvalidArgumentException |
|
| 3141 | - * @throws InvalidDataTypeException |
|
| 3142 | - * @throws InvalidInterfaceException |
|
| 3143 | - */ |
|
| 3144 | - public function admin_page_wrapper($about = false) |
|
| 3145 | - { |
|
| 3146 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3147 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3148 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3149 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3150 | - |
|
| 3151 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3152 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3153 | - $this->_template_args['before_admin_page_content'] ?? '' |
|
| 3154 | - ); |
|
| 3155 | - |
|
| 3156 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3157 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3158 | - $this->_template_args['after_admin_page_content'] ?? '' |
|
| 3159 | - ); |
|
| 3160 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3161 | - |
|
| 3162 | - if ($this->request->isAjax()) { |
|
| 3163 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3164 | - // $template_path, |
|
| 3165 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3166 | - $this->_template_args, |
|
| 3167 | - true |
|
| 3168 | - ); |
|
| 3169 | - $this->_return_json(); |
|
| 3170 | - } |
|
| 3171 | - // load settings page wrapper template |
|
| 3172 | - $template_path = $about |
|
| 3173 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3174 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3175 | - |
|
| 3176 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3177 | - } |
|
| 3178 | - |
|
| 3179 | - |
|
| 3180 | - /** |
|
| 3181 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3182 | - * |
|
| 3183 | - * @return string html |
|
| 3184 | - * @throws EE_Error |
|
| 3185 | - */ |
|
| 3186 | - protected function _get_main_nav_tabs() |
|
| 3187 | - { |
|
| 3188 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3189 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3190 | - // (rather than setting in the page_routes array) |
|
| 3191 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3192 | - } |
|
| 3193 | - |
|
| 3194 | - |
|
| 3195 | - /** |
|
| 3196 | - * sort nav tabs |
|
| 3197 | - * |
|
| 3198 | - * @param $a |
|
| 3199 | - * @param $b |
|
| 3200 | - * @return int |
|
| 3201 | - */ |
|
| 3202 | - private function _sort_nav_tabs($a, $b) |
|
| 3203 | - { |
|
| 3204 | - if ($a['order'] === $b['order']) { |
|
| 3205 | - return 0; |
|
| 3206 | - } |
|
| 3207 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3208 | - } |
|
| 3209 | - |
|
| 3210 | - |
|
| 3211 | - /** |
|
| 3212 | - * generates HTML for the forms used on admin pages |
|
| 3213 | - * |
|
| 3214 | - * @param array $input_vars - array of input field details |
|
| 3215 | - * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3216 | - * @param bool $id |
|
| 3217 | - * @return array|string |
|
| 3218 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3219 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3220 | - */ |
|
| 3221 | - protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3222 | - { |
|
| 3223 | - return $generator === 'string' |
|
| 3224 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3225 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3226 | - } |
|
| 3227 | - |
|
| 3228 | - |
|
| 3229 | - /** |
|
| 3230 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3231 | - * |
|
| 3232 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3233 | - * Close" button. |
|
| 3234 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3235 | - * 'Save', [1] => 'save & close') |
|
| 3236 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3237 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3238 | - * default actions by submitting some other value. |
|
| 3239 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3240 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3241 | - * close (normal form handling). |
|
| 3242 | - */ |
|
| 3243 | - protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3244 | - { |
|
| 3245 | - // make sure $text and $actions are in an array |
|
| 3246 | - $text = (array) $text; |
|
| 3247 | - $actions = (array) $actions; |
|
| 3248 | - $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3249 | - $button_text = ! empty($text) |
|
| 3250 | - ? $text |
|
| 3251 | - : [ |
|
| 3252 | - esc_html__('Save', 'event_espresso'), |
|
| 3253 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3254 | - ]; |
|
| 3255 | - $default_names = ['save', 'save_and_close']; |
|
| 3256 | - $buttons = ''; |
|
| 3257 | - foreach ($button_text as $key => $button) { |
|
| 3258 | - $ref = $default_names[ $key ]; |
|
| 3259 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3260 | - $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" ' |
|
| 3261 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3262 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3263 | - if (! $both) { |
|
| 3264 | - break; |
|
| 3265 | - } |
|
| 3266 | - } |
|
| 3267 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3268 | - $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3269 | - . $referrer_url |
|
| 3270 | - . '" />'; |
|
| 3271 | - $this->_template_args['save_buttons'] = $buttons; |
|
| 3272 | - } |
|
| 3273 | - |
|
| 3274 | - |
|
| 3275 | - /** |
|
| 3276 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3277 | - * |
|
| 3278 | - * @param string $route |
|
| 3279 | - * @param array $additional_hidden_fields |
|
| 3280 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3281 | - * @since 4.6.0 |
|
| 3282 | - */ |
|
| 3283 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3284 | - { |
|
| 3285 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3286 | - } |
|
| 3287 | - |
|
| 3288 | - |
|
| 3289 | - /** |
|
| 3290 | - * set form open and close tags on add/edit pages. |
|
| 3291 | - * |
|
| 3292 | - * @param string $route the route you want the form to direct to |
|
| 3293 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3294 | - * @return void |
|
| 3295 | - */ |
|
| 3296 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3297 | - { |
|
| 3298 | - if (empty($route)) { |
|
| 3299 | - $user_msg = esc_html__( |
|
| 3300 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3301 | - 'event_espresso' |
|
| 3302 | - ); |
|
| 3303 | - $dev_msg = $user_msg . "\n" |
|
| 3304 | - . sprintf( |
|
| 3305 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3306 | - __FUNCTION__, |
|
| 3307 | - __CLASS__ |
|
| 3308 | - ); |
|
| 3309 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3310 | - } |
|
| 3311 | - // open form |
|
| 3312 | - $action = $this->_admin_base_url; |
|
| 3313 | - $this->_template_args['before_admin_page_content'] = " |
|
| 2944 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2945 | + // display message about search results? |
|
| 2946 | + $search = $this->request->getRequestParam('s'); |
|
| 2947 | + $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2948 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 2949 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2950 | + trim($search, '%') |
|
| 2951 | + ) . '</p>' |
|
| 2952 | + : ''; |
|
| 2953 | + // filter before_list_table template arg |
|
| 2954 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 2955 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2956 | + $this->_template_args['before_list_table'], |
|
| 2957 | + $this->page_slug, |
|
| 2958 | + $this->request->requestParams(), |
|
| 2959 | + $this->_req_action |
|
| 2960 | + ); |
|
| 2961 | + // convert to array and filter again |
|
| 2962 | + // arrays are easier to inject new items in a specific location, |
|
| 2963 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2964 | + $this->_template_args['before_list_table'] = implode( |
|
| 2965 | + " \n", |
|
| 2966 | + (array) apply_filters( |
|
| 2967 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2968 | + (array) $this->_template_args['before_list_table'], |
|
| 2969 | + $this->page_slug, |
|
| 2970 | + $this->request->requestParams(), |
|
| 2971 | + $this->_req_action |
|
| 2972 | + ) |
|
| 2973 | + ); |
|
| 2974 | + // filter after_list_table template arg |
|
| 2975 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 2976 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2977 | + $this->_template_args['after_list_table'], |
|
| 2978 | + $this->page_slug, |
|
| 2979 | + $this->request->requestParams(), |
|
| 2980 | + $this->_req_action |
|
| 2981 | + ); |
|
| 2982 | + // convert to array and filter again |
|
| 2983 | + // arrays are easier to inject new items in a specific location, |
|
| 2984 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2985 | + $this->_template_args['after_list_table'] = implode( |
|
| 2986 | + " \n", |
|
| 2987 | + (array) apply_filters( |
|
| 2988 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2989 | + (array) $this->_template_args['after_list_table'], |
|
| 2990 | + $this->page_slug, |
|
| 2991 | + $this->request->requestParams(), |
|
| 2992 | + $this->_req_action |
|
| 2993 | + ) |
|
| 2994 | + ); |
|
| 2995 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2996 | + $template_path, |
|
| 2997 | + $this->_template_args, |
|
| 2998 | + true |
|
| 2999 | + ); |
|
| 3000 | + // the final template wrapper |
|
| 3001 | + if ($sidebar) { |
|
| 3002 | + $this->display_admin_page_with_sidebar(); |
|
| 3003 | + } else { |
|
| 3004 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3005 | + } |
|
| 3006 | + } |
|
| 3007 | + |
|
| 3008 | + |
|
| 3009 | + /** |
|
| 3010 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3011 | + * html string for the legend. |
|
| 3012 | + * $items are expected in an array in the following format: |
|
| 3013 | + * $legend_items = array( |
|
| 3014 | + * 'item_id' => array( |
|
| 3015 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3016 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3017 | + * ) |
|
| 3018 | + * ); |
|
| 3019 | + * |
|
| 3020 | + * @param array $items see above for format of array |
|
| 3021 | + * @return string html string of legend |
|
| 3022 | + * @throws DomainException |
|
| 3023 | + */ |
|
| 3024 | + protected function _display_legend($items) |
|
| 3025 | + { |
|
| 3026 | + $this->_template_args['items'] = apply_filters( |
|
| 3027 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3028 | + (array) $items, |
|
| 3029 | + $this |
|
| 3030 | + ); |
|
| 3031 | + /** @var StatusChangeNotice $status_change_notice */ |
|
| 3032 | + $status_change_notice = $this->loader->getShared( |
|
| 3033 | + 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 3034 | + ); |
|
| 3035 | + $this->_template_args['status_change_notice'] = $status_change_notice->display( |
|
| 3036 | + '__admin-legend', |
|
| 3037 | + $this->page_slug |
|
| 3038 | + ); |
|
| 3039 | + return EEH_Template::display_template( |
|
| 3040 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3041 | + $this->_template_args, |
|
| 3042 | + true |
|
| 3043 | + ); |
|
| 3044 | + } |
|
| 3045 | + |
|
| 3046 | + |
|
| 3047 | + /** |
|
| 3048 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3049 | + * The returned json object is created from an array in the following format: |
|
| 3050 | + * array( |
|
| 3051 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3052 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3053 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3054 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3055 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3056 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3057 | + * that might be included in here) |
|
| 3058 | + * ) |
|
| 3059 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3060 | + * |
|
| 3061 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3062 | + * instead of displayed. |
|
| 3063 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3064 | + * @return void |
|
| 3065 | + * @throws EE_Error |
|
| 3066 | + * @throws InvalidArgumentException |
|
| 3067 | + * @throws InvalidDataTypeException |
|
| 3068 | + * @throws InvalidInterfaceException |
|
| 3069 | + */ |
|
| 3070 | + protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 3071 | + { |
|
| 3072 | + // make sure any EE_Error notices have been handled. |
|
| 3073 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3074 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 3075 | + unset($this->_template_args['data']); |
|
| 3076 | + $json = [ |
|
| 3077 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3078 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3079 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3080 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3081 | + 'notices' => EE_Error::get_notices(), |
|
| 3082 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3083 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3084 | + 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3085 | + 'isEEajax' => true |
|
| 3086 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3087 | + ]; |
|
| 3088 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3089 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3090 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3091 | + } |
|
| 3092 | + echo wp_json_encode($json); |
|
| 3093 | + exit(); |
|
| 3094 | + } |
|
| 3095 | + |
|
| 3096 | + |
|
| 3097 | + /** |
|
| 3098 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3099 | + * |
|
| 3100 | + * @return void |
|
| 3101 | + * @throws EE_Error |
|
| 3102 | + * @throws InvalidArgumentException |
|
| 3103 | + * @throws InvalidDataTypeException |
|
| 3104 | + * @throws InvalidInterfaceException |
|
| 3105 | + */ |
|
| 3106 | + public function return_json() |
|
| 3107 | + { |
|
| 3108 | + if ($this->request->isAjax()) { |
|
| 3109 | + $this->_return_json(); |
|
| 3110 | + } else { |
|
| 3111 | + throw new EE_Error( |
|
| 3112 | + sprintf( |
|
| 3113 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3114 | + __FUNCTION__ |
|
| 3115 | + ) |
|
| 3116 | + ); |
|
| 3117 | + } |
|
| 3118 | + } |
|
| 3119 | + |
|
| 3120 | + |
|
| 3121 | + /** |
|
| 3122 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3123 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3124 | + * |
|
| 3125 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3126 | + */ |
|
| 3127 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3128 | + { |
|
| 3129 | + $this->_hook_obj = $hook_obj; |
|
| 3130 | + } |
|
| 3131 | + |
|
| 3132 | + |
|
| 3133 | + /** |
|
| 3134 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3135 | + * |
|
| 3136 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3137 | + * @return void |
|
| 3138 | + * @throws DomainException |
|
| 3139 | + * @throws EE_Error |
|
| 3140 | + * @throws InvalidArgumentException |
|
| 3141 | + * @throws InvalidDataTypeException |
|
| 3142 | + * @throws InvalidInterfaceException |
|
| 3143 | + */ |
|
| 3144 | + public function admin_page_wrapper($about = false) |
|
| 3145 | + { |
|
| 3146 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3147 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3148 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3149 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3150 | + |
|
| 3151 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3152 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3153 | + $this->_template_args['before_admin_page_content'] ?? '' |
|
| 3154 | + ); |
|
| 3155 | + |
|
| 3156 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3157 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3158 | + $this->_template_args['after_admin_page_content'] ?? '' |
|
| 3159 | + ); |
|
| 3160 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3161 | + |
|
| 3162 | + if ($this->request->isAjax()) { |
|
| 3163 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3164 | + // $template_path, |
|
| 3165 | + EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3166 | + $this->_template_args, |
|
| 3167 | + true |
|
| 3168 | + ); |
|
| 3169 | + $this->_return_json(); |
|
| 3170 | + } |
|
| 3171 | + // load settings page wrapper template |
|
| 3172 | + $template_path = $about |
|
| 3173 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3174 | + : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3175 | + |
|
| 3176 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3177 | + } |
|
| 3178 | + |
|
| 3179 | + |
|
| 3180 | + /** |
|
| 3181 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3182 | + * |
|
| 3183 | + * @return string html |
|
| 3184 | + * @throws EE_Error |
|
| 3185 | + */ |
|
| 3186 | + protected function _get_main_nav_tabs() |
|
| 3187 | + { |
|
| 3188 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3189 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3190 | + // (rather than setting in the page_routes array) |
|
| 3191 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3192 | + } |
|
| 3193 | + |
|
| 3194 | + |
|
| 3195 | + /** |
|
| 3196 | + * sort nav tabs |
|
| 3197 | + * |
|
| 3198 | + * @param $a |
|
| 3199 | + * @param $b |
|
| 3200 | + * @return int |
|
| 3201 | + */ |
|
| 3202 | + private function _sort_nav_tabs($a, $b) |
|
| 3203 | + { |
|
| 3204 | + if ($a['order'] === $b['order']) { |
|
| 3205 | + return 0; |
|
| 3206 | + } |
|
| 3207 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3208 | + } |
|
| 3209 | + |
|
| 3210 | + |
|
| 3211 | + /** |
|
| 3212 | + * generates HTML for the forms used on admin pages |
|
| 3213 | + * |
|
| 3214 | + * @param array $input_vars - array of input field details |
|
| 3215 | + * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3216 | + * @param bool $id |
|
| 3217 | + * @return array|string |
|
| 3218 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3219 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3220 | + */ |
|
| 3221 | + protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3222 | + { |
|
| 3223 | + return $generator === 'string' |
|
| 3224 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3225 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3226 | + } |
|
| 3227 | + |
|
| 3228 | + |
|
| 3229 | + /** |
|
| 3230 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3231 | + * |
|
| 3232 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3233 | + * Close" button. |
|
| 3234 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3235 | + * 'Save', [1] => 'save & close') |
|
| 3236 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3237 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3238 | + * default actions by submitting some other value. |
|
| 3239 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3240 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3241 | + * close (normal form handling). |
|
| 3242 | + */ |
|
| 3243 | + protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3244 | + { |
|
| 3245 | + // make sure $text and $actions are in an array |
|
| 3246 | + $text = (array) $text; |
|
| 3247 | + $actions = (array) $actions; |
|
| 3248 | + $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3249 | + $button_text = ! empty($text) |
|
| 3250 | + ? $text |
|
| 3251 | + : [ |
|
| 3252 | + esc_html__('Save', 'event_espresso'), |
|
| 3253 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3254 | + ]; |
|
| 3255 | + $default_names = ['save', 'save_and_close']; |
|
| 3256 | + $buttons = ''; |
|
| 3257 | + foreach ($button_text as $key => $button) { |
|
| 3258 | + $ref = $default_names[ $key ]; |
|
| 3259 | + $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3260 | + $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" ' |
|
| 3261 | + . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3262 | + . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3263 | + if (! $both) { |
|
| 3264 | + break; |
|
| 3265 | + } |
|
| 3266 | + } |
|
| 3267 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3268 | + $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3269 | + . $referrer_url |
|
| 3270 | + . '" />'; |
|
| 3271 | + $this->_template_args['save_buttons'] = $buttons; |
|
| 3272 | + } |
|
| 3273 | + |
|
| 3274 | + |
|
| 3275 | + /** |
|
| 3276 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3277 | + * |
|
| 3278 | + * @param string $route |
|
| 3279 | + * @param array $additional_hidden_fields |
|
| 3280 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3281 | + * @since 4.6.0 |
|
| 3282 | + */ |
|
| 3283 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3284 | + { |
|
| 3285 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3286 | + } |
|
| 3287 | + |
|
| 3288 | + |
|
| 3289 | + /** |
|
| 3290 | + * set form open and close tags on add/edit pages. |
|
| 3291 | + * |
|
| 3292 | + * @param string $route the route you want the form to direct to |
|
| 3293 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3294 | + * @return void |
|
| 3295 | + */ |
|
| 3296 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3297 | + { |
|
| 3298 | + if (empty($route)) { |
|
| 3299 | + $user_msg = esc_html__( |
|
| 3300 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3301 | + 'event_espresso' |
|
| 3302 | + ); |
|
| 3303 | + $dev_msg = $user_msg . "\n" |
|
| 3304 | + . sprintf( |
|
| 3305 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3306 | + __FUNCTION__, |
|
| 3307 | + __CLASS__ |
|
| 3308 | + ); |
|
| 3309 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3310 | + } |
|
| 3311 | + // open form |
|
| 3312 | + $action = $this->_admin_base_url; |
|
| 3313 | + $this->_template_args['before_admin_page_content'] = " |
|
| 3314 | 3314 | <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' > |
| 3315 | 3315 | "; |
| 3316 | - // add nonce |
|
| 3317 | - $nonce = |
|
| 3318 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3319 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3320 | - // add REQUIRED form action |
|
| 3321 | - $hidden_fields = [ |
|
| 3322 | - 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3323 | - ]; |
|
| 3324 | - // merge arrays |
|
| 3325 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3326 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3327 | - : $hidden_fields; |
|
| 3328 | - // generate form fields |
|
| 3329 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3330 | - // add fields to form |
|
| 3331 | - foreach ((array) $form_fields as $form_field) { |
|
| 3332 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3333 | - } |
|
| 3334 | - // close form |
|
| 3335 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3336 | - } |
|
| 3337 | - |
|
| 3338 | - |
|
| 3339 | - /** |
|
| 3340 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3341 | - * discovered it would be useful for external code to have access. |
|
| 3342 | - * |
|
| 3343 | - * @param bool $success |
|
| 3344 | - * @param string $what |
|
| 3345 | - * @param string $action_desc |
|
| 3346 | - * @param array $query_args |
|
| 3347 | - * @param bool $override_overwrite |
|
| 3348 | - * @throws EE_Error |
|
| 3349 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3350 | - * @since 4.5.0 |
|
| 3351 | - */ |
|
| 3352 | - public function redirect_after_action( |
|
| 3353 | - $success = false, |
|
| 3354 | - $what = 'item', |
|
| 3355 | - $action_desc = 'processed', |
|
| 3356 | - $query_args = [], |
|
| 3357 | - $override_overwrite = false |
|
| 3358 | - ) { |
|
| 3359 | - $this->_redirect_after_action( |
|
| 3360 | - $success, |
|
| 3361 | - $what, |
|
| 3362 | - $action_desc, |
|
| 3363 | - $query_args, |
|
| 3364 | - $override_overwrite |
|
| 3365 | - ); |
|
| 3366 | - } |
|
| 3367 | - |
|
| 3368 | - |
|
| 3369 | - /** |
|
| 3370 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3371 | - * |
|
| 3372 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3373 | - * filters are still applied. |
|
| 3374 | - * |
|
| 3375 | - * @param array $new_route_data |
|
| 3376 | - * @return array |
|
| 3377 | - */ |
|
| 3378 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3379 | - { |
|
| 3380 | - foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3381 | - // unset nonces |
|
| 3382 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3383 | - $this->request->unSetRequestParam($ref); |
|
| 3384 | - continue; |
|
| 3385 | - } |
|
| 3386 | - // urlencode values. |
|
| 3387 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3388 | - $this->request->setRequestParam($ref, $value); |
|
| 3389 | - } |
|
| 3390 | - return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3391 | - } |
|
| 3392 | - |
|
| 3393 | - |
|
| 3394 | - /** |
|
| 3395 | - * @param int|float|string $success - whether success was for two or more records, or just one, or none |
|
| 3396 | - * @param string $what - what the action was performed on |
|
| 3397 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3398 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to |
|
| 3399 | - * @param BOOL $override_overwrite - by default all EE_Error::success messages are overwritten, |
|
| 3400 | - * this allows you to override this so that they show. |
|
| 3401 | - * @return void |
|
| 3402 | - * @throws EE_Error |
|
| 3403 | - * @throws InvalidArgumentException |
|
| 3404 | - * @throws InvalidDataTypeException |
|
| 3405 | - * @throws InvalidInterfaceException |
|
| 3406 | - */ |
|
| 3407 | - protected function _redirect_after_action( |
|
| 3408 | - $success = 0, |
|
| 3409 | - string $what = 'item', |
|
| 3410 | - string $action_desc = 'processed', |
|
| 3411 | - array $query_args = [], |
|
| 3412 | - bool $override_overwrite = false |
|
| 3413 | - ) { |
|
| 3414 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3415 | - $notices = EE_Error::get_notices(false); |
|
| 3416 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3417 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3418 | - EE_Error::overwrite_success(); |
|
| 3419 | - } |
|
| 3420 | - if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3421 | - // how many records affected ? more than one record ? or just one ? |
|
| 3422 | - EE_Error::add_success( |
|
| 3423 | - sprintf( |
|
| 3424 | - esc_html( |
|
| 3425 | - _n( |
|
| 3426 | - 'The "%1$s" has been successfully %2$s.', |
|
| 3427 | - 'The "%1$s" have been successfully %2$s.', |
|
| 3428 | - $success, |
|
| 3429 | - 'event_espresso' |
|
| 3430 | - ) |
|
| 3431 | - ), |
|
| 3432 | - $what, |
|
| 3433 | - $action_desc |
|
| 3434 | - ), |
|
| 3435 | - __FILE__, |
|
| 3436 | - __FUNCTION__, |
|
| 3437 | - __LINE__ |
|
| 3438 | - ); |
|
| 3439 | - } |
|
| 3440 | - // check that $query_args isn't something crazy |
|
| 3441 | - if (! is_array($query_args)) { |
|
| 3442 | - $query_args = []; |
|
| 3443 | - } |
|
| 3444 | - /** |
|
| 3445 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3446 | - * redirections on save and close actions |
|
| 3447 | - * |
|
| 3448 | - * @param array $query_args The original query_args array coming into the |
|
| 3449 | - * method. |
|
| 3450 | - * @since 4.2.0 |
|
| 3451 | - */ |
|
| 3452 | - do_action( |
|
| 3453 | - "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3454 | - $query_args |
|
| 3455 | - ); |
|
| 3456 | - // set redirect url. |
|
| 3457 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3458 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3459 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3460 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3461 | - if ( |
|
| 3462 | - $this->request->requestParamIsSet('save_and_close') |
|
| 3463 | - && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3464 | - ) { |
|
| 3465 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3466 | - $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3467 | - // regenerate query args array from referrer URL |
|
| 3468 | - parse_str($parsed_url['query'], $query_args); |
|
| 3469 | - // correct page and action will be in the query args now |
|
| 3470 | - $redirect_url = admin_url('admin.php'); |
|
| 3471 | - } |
|
| 3472 | - // merge any default query_args set in _default_route_query_args property |
|
| 3473 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3474 | - $args_to_merge = []; |
|
| 3475 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3476 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3477 | - if ($query_param === 'wp_referer') { |
|
| 3478 | - $query_value = (array) $query_value; |
|
| 3479 | - foreach ($query_value as $reference => $value) { |
|
| 3480 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3481 | - continue; |
|
| 3482 | - } |
|
| 3483 | - // finally we will override any arguments in the referer with |
|
| 3484 | - // what might be set on the _default_route_query_args array. |
|
| 3485 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3486 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3487 | - } else { |
|
| 3488 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3489 | - } |
|
| 3490 | - } |
|
| 3491 | - continue; |
|
| 3492 | - } |
|
| 3493 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3494 | - } |
|
| 3495 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3496 | - // redirect. |
|
| 3497 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3498 | - } |
|
| 3499 | - $this->_process_notices($query_args); |
|
| 3500 | - // generate redirect url |
|
| 3501 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3502 | - if (isset($query_args['action'])) { |
|
| 3503 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3504 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3505 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3506 | - } |
|
| 3507 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3508 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3509 | - do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args); |
|
| 3510 | - $redirect_url = apply_filters( |
|
| 3511 | - 'FHEE_redirect_' . $this->class_name . $this->_req_action, |
|
| 3512 | - EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3513 | - $query_args |
|
| 3514 | - ); |
|
| 3515 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3516 | - if ($this->request->isAjax()) { |
|
| 3517 | - $default_data = [ |
|
| 3518 | - 'close' => true, |
|
| 3519 | - 'redirect_url' => $redirect_url, |
|
| 3520 | - 'where' => 'main', |
|
| 3521 | - 'what' => 'append', |
|
| 3522 | - ]; |
|
| 3523 | - $this->_template_args['success'] = $success; |
|
| 3524 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3525 | - $default_data, |
|
| 3526 | - $this->_template_args['data'] |
|
| 3527 | - ) : $default_data; |
|
| 3528 | - $this->_return_json(); |
|
| 3529 | - } |
|
| 3530 | - wp_safe_redirect($redirect_url); |
|
| 3531 | - exit(); |
|
| 3532 | - } |
|
| 3533 | - |
|
| 3534 | - |
|
| 3535 | - /** |
|
| 3536 | - * process any notices before redirecting (or returning ajax request) |
|
| 3537 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3538 | - * |
|
| 3539 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3540 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3541 | - * page_routes haven't been defined yet. |
|
| 3542 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3543 | - * still save a transient for the notice. |
|
| 3544 | - * @return void |
|
| 3545 | - * @throws EE_Error |
|
| 3546 | - * @throws InvalidArgumentException |
|
| 3547 | - * @throws InvalidDataTypeException |
|
| 3548 | - * @throws InvalidInterfaceException |
|
| 3549 | - */ |
|
| 3550 | - protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3551 | - { |
|
| 3552 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3553 | - if ($this->request->isAjax()) { |
|
| 3554 | - $notices = EE_Error::get_notices(false); |
|
| 3555 | - if (empty($this->_template_args['success'])) { |
|
| 3556 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3557 | - } |
|
| 3558 | - if (empty($this->_template_args['errors'])) { |
|
| 3559 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3560 | - } |
|
| 3561 | - if (empty($this->_template_args['attention'])) { |
|
| 3562 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3563 | - } |
|
| 3564 | - } |
|
| 3565 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3566 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3567 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3568 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3569 | - $this->_add_transient( |
|
| 3570 | - $route, |
|
| 3571 | - $this->_template_args['notices'], |
|
| 3572 | - true, |
|
| 3573 | - $skip_route_verify |
|
| 3574 | - ); |
|
| 3575 | - } |
|
| 3576 | - } |
|
| 3577 | - |
|
| 3578 | - |
|
| 3579 | - /** |
|
| 3580 | - * get_action_link_or_button |
|
| 3581 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3582 | - * |
|
| 3583 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3584 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3585 | - * property. |
|
| 3586 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3587 | - * @param string $class Use this to give the class for the button. Defaults to 'button--primary' |
|
| 3588 | - * @param string $base_url If this is not provided |
|
| 3589 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3590 | - * Otherwise this value will be used. |
|
| 3591 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3592 | - * @return string |
|
| 3593 | - * @throws InvalidArgumentException |
|
| 3594 | - * @throws InvalidInterfaceException |
|
| 3595 | - * @throws InvalidDataTypeException |
|
| 3596 | - * @throws EE_Error |
|
| 3597 | - */ |
|
| 3598 | - public function get_action_link_or_button( |
|
| 3599 | - $action, |
|
| 3600 | - $type = 'add', |
|
| 3601 | - $extra_request = [], |
|
| 3602 | - $class = 'button--primary', |
|
| 3603 | - $base_url = '', |
|
| 3604 | - $exclude_nonce = false |
|
| 3605 | - ) { |
|
| 3606 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3607 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3608 | - throw new EE_Error( |
|
| 3609 | - sprintf( |
|
| 3610 | - esc_html__( |
|
| 3611 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3612 | - 'event_espresso' |
|
| 3613 | - ), |
|
| 3614 | - $action |
|
| 3615 | - ) |
|
| 3616 | - ); |
|
| 3617 | - } |
|
| 3618 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3619 | - throw new EE_Error( |
|
| 3620 | - sprintf( |
|
| 3621 | - esc_html__( |
|
| 3622 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3623 | - 'event_espresso' |
|
| 3624 | - ), |
|
| 3625 | - $type |
|
| 3626 | - ) |
|
| 3627 | - ); |
|
| 3628 | - } |
|
| 3629 | - // finally check user access for this button. |
|
| 3630 | - $has_access = $this->check_user_access($action, true); |
|
| 3631 | - if (! $has_access) { |
|
| 3632 | - return ''; |
|
| 3633 | - } |
|
| 3634 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3635 | - $query_args = [ |
|
| 3636 | - 'action' => $action, |
|
| 3637 | - ]; |
|
| 3638 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3639 | - if (! empty($extra_request)) { |
|
| 3640 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3641 | - } |
|
| 3642 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3643 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3644 | - } |
|
| 3645 | - |
|
| 3646 | - |
|
| 3647 | - /** |
|
| 3648 | - * _per_page_screen_option |
|
| 3649 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3650 | - * |
|
| 3651 | - * @return void |
|
| 3652 | - * @throws InvalidArgumentException |
|
| 3653 | - * @throws InvalidInterfaceException |
|
| 3654 | - * @throws InvalidDataTypeException |
|
| 3655 | - */ |
|
| 3656 | - protected function _per_page_screen_option() |
|
| 3657 | - { |
|
| 3658 | - $option = 'per_page'; |
|
| 3659 | - $args = [ |
|
| 3660 | - 'label' => apply_filters( |
|
| 3661 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3662 | - $this->_admin_page_title, |
|
| 3663 | - $this |
|
| 3664 | - ), |
|
| 3665 | - 'default' => (int) apply_filters( |
|
| 3666 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3667 | - 20 |
|
| 3668 | - ), |
|
| 3669 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3670 | - ]; |
|
| 3671 | - // ONLY add the screen option if the user has access to it. |
|
| 3672 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3673 | - add_screen_option($option, $args); |
|
| 3674 | - } |
|
| 3675 | - } |
|
| 3676 | - |
|
| 3677 | - |
|
| 3678 | - /** |
|
| 3679 | - * set_per_page_screen_option |
|
| 3680 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3681 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3682 | - * admin_menu. |
|
| 3683 | - * |
|
| 3684 | - * @return void |
|
| 3685 | - */ |
|
| 3686 | - private function _set_per_page_screen_options() |
|
| 3687 | - { |
|
| 3688 | - if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3689 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3690 | - if (! $user = wp_get_current_user()) { |
|
| 3691 | - return; |
|
| 3692 | - } |
|
| 3693 | - $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3694 | - if (! $option) { |
|
| 3695 | - return; |
|
| 3696 | - } |
|
| 3697 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3698 | - $map_option = $option; |
|
| 3699 | - $option = str_replace('-', '_', $option); |
|
| 3700 | - switch ($map_option) { |
|
| 3701 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3702 | - $max_value = apply_filters( |
|
| 3703 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3704 | - 999, |
|
| 3705 | - $this->_current_page, |
|
| 3706 | - $this->_current_view |
|
| 3707 | - ); |
|
| 3708 | - if ($value < 1) { |
|
| 3709 | - return; |
|
| 3710 | - } |
|
| 3711 | - $value = min($value, $max_value); |
|
| 3712 | - break; |
|
| 3713 | - default: |
|
| 3714 | - $value = apply_filters( |
|
| 3715 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3716 | - false, |
|
| 3717 | - $option, |
|
| 3718 | - $value |
|
| 3719 | - ); |
|
| 3720 | - if (false === $value) { |
|
| 3721 | - return; |
|
| 3722 | - } |
|
| 3723 | - break; |
|
| 3724 | - } |
|
| 3725 | - update_user_meta($user->ID, $option, $value); |
|
| 3726 | - wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3727 | - exit; |
|
| 3728 | - } |
|
| 3729 | - } |
|
| 3730 | - |
|
| 3731 | - |
|
| 3732 | - /** |
|
| 3733 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3734 | - * |
|
| 3735 | - * @param array $data array that will be assigned to template args. |
|
| 3736 | - */ |
|
| 3737 | - public function set_template_args($data) |
|
| 3738 | - { |
|
| 3739 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3740 | - } |
|
| 3741 | - |
|
| 3742 | - |
|
| 3743 | - /** |
|
| 3744 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3745 | - * |
|
| 3746 | - * @param string $route the route that should receive the transient |
|
| 3747 | - * @param array $data the data that gets sent |
|
| 3748 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3749 | - * normal route transient. |
|
| 3750 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3751 | - * when we are adding a transient before page_routes have been defined. |
|
| 3752 | - * @return void |
|
| 3753 | - * @throws EE_Error |
|
| 3754 | - */ |
|
| 3755 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3756 | - { |
|
| 3757 | - $user_id = get_current_user_id(); |
|
| 3758 | - if (! $skip_route_verify) { |
|
| 3759 | - $this->_verify_route($route); |
|
| 3760 | - } |
|
| 3761 | - // now let's set the string for what kind of transient we're setting |
|
| 3762 | - $transient = $notices |
|
| 3763 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3764 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3765 | - $data = $notices ? ['notices' => $data] : $data; |
|
| 3766 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3767 | - $existing = is_multisite() && is_network_admin() |
|
| 3768 | - ? get_site_transient($transient) |
|
| 3769 | - : get_transient($transient); |
|
| 3770 | - if ($existing) { |
|
| 3771 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3772 | - } |
|
| 3773 | - if (is_multisite() && is_network_admin()) { |
|
| 3774 | - set_site_transient($transient, $data, 8); |
|
| 3775 | - } else { |
|
| 3776 | - set_transient($transient, $data, 8); |
|
| 3777 | - } |
|
| 3778 | - } |
|
| 3779 | - |
|
| 3780 | - |
|
| 3781 | - /** |
|
| 3782 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3783 | - * |
|
| 3784 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3785 | - * @param string $route |
|
| 3786 | - * @return mixed data |
|
| 3787 | - */ |
|
| 3788 | - protected function _get_transient($notices = false, $route = '') |
|
| 3789 | - { |
|
| 3790 | - $user_id = get_current_user_id(); |
|
| 3791 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3792 | - $transient = $notices |
|
| 3793 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3794 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3795 | - $data = is_multisite() && is_network_admin() |
|
| 3796 | - ? get_site_transient($transient) |
|
| 3797 | - : get_transient($transient); |
|
| 3798 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3799 | - if (is_multisite() && is_network_admin()) { |
|
| 3800 | - delete_site_transient($transient); |
|
| 3801 | - } else { |
|
| 3802 | - delete_transient($transient); |
|
| 3803 | - } |
|
| 3804 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3805 | - } |
|
| 3806 | - |
|
| 3807 | - |
|
| 3808 | - /** |
|
| 3809 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3810 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3811 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3812 | - * |
|
| 3813 | - * @return void |
|
| 3814 | - */ |
|
| 3815 | - protected function _transient_garbage_collection() |
|
| 3816 | - { |
|
| 3817 | - global $wpdb; |
|
| 3818 | - // retrieve all existing transients |
|
| 3819 | - $query = |
|
| 3820 | - "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3821 | - if ($results = $wpdb->get_results($query)) { |
|
| 3822 | - foreach ($results as $result) { |
|
| 3823 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3824 | - get_transient($transient); |
|
| 3825 | - if (is_multisite() && is_network_admin()) { |
|
| 3826 | - get_site_transient($transient); |
|
| 3827 | - } |
|
| 3828 | - } |
|
| 3829 | - } |
|
| 3830 | - } |
|
| 3831 | - |
|
| 3832 | - |
|
| 3833 | - /** |
|
| 3834 | - * get_view |
|
| 3835 | - * |
|
| 3836 | - * @return string content of _view property |
|
| 3837 | - */ |
|
| 3838 | - public function get_view() |
|
| 3839 | - { |
|
| 3840 | - return $this->_view; |
|
| 3841 | - } |
|
| 3842 | - |
|
| 3843 | - |
|
| 3844 | - /** |
|
| 3845 | - * getter for the protected $_views property |
|
| 3846 | - * |
|
| 3847 | - * @return array |
|
| 3848 | - */ |
|
| 3849 | - public function get_views() |
|
| 3850 | - { |
|
| 3851 | - return $this->_views; |
|
| 3852 | - } |
|
| 3853 | - |
|
| 3854 | - |
|
| 3855 | - /** |
|
| 3856 | - * get_current_page |
|
| 3857 | - * |
|
| 3858 | - * @return string _current_page property value |
|
| 3859 | - */ |
|
| 3860 | - public function get_current_page() |
|
| 3861 | - { |
|
| 3862 | - return $this->_current_page; |
|
| 3863 | - } |
|
| 3864 | - |
|
| 3865 | - |
|
| 3866 | - /** |
|
| 3867 | - * get_current_view |
|
| 3868 | - * |
|
| 3869 | - * @return string _current_view property value |
|
| 3870 | - */ |
|
| 3871 | - public function get_current_view() |
|
| 3872 | - { |
|
| 3873 | - return $this->_current_view; |
|
| 3874 | - } |
|
| 3875 | - |
|
| 3876 | - |
|
| 3877 | - /** |
|
| 3878 | - * get_current_screen |
|
| 3879 | - * |
|
| 3880 | - * @return object The current WP_Screen object |
|
| 3881 | - */ |
|
| 3882 | - public function get_current_screen() |
|
| 3883 | - { |
|
| 3884 | - return $this->_current_screen; |
|
| 3885 | - } |
|
| 3886 | - |
|
| 3887 | - |
|
| 3888 | - /** |
|
| 3889 | - * get_current_page_view_url |
|
| 3890 | - * |
|
| 3891 | - * @return string This returns the url for the current_page_view. |
|
| 3892 | - */ |
|
| 3893 | - public function get_current_page_view_url() |
|
| 3894 | - { |
|
| 3895 | - return $this->_current_page_view_url; |
|
| 3896 | - } |
|
| 3897 | - |
|
| 3898 | - |
|
| 3899 | - /** |
|
| 3900 | - * just returns the Request |
|
| 3901 | - * |
|
| 3902 | - * @return RequestInterface |
|
| 3903 | - */ |
|
| 3904 | - public function get_request() |
|
| 3905 | - { |
|
| 3906 | - return $this->request; |
|
| 3907 | - } |
|
| 3908 | - |
|
| 3909 | - |
|
| 3910 | - /** |
|
| 3911 | - * just returns the _req_data property |
|
| 3912 | - * |
|
| 3913 | - * @return array |
|
| 3914 | - */ |
|
| 3915 | - public function get_request_data() |
|
| 3916 | - { |
|
| 3917 | - return $this->request->requestParams(); |
|
| 3918 | - } |
|
| 3919 | - |
|
| 3920 | - |
|
| 3921 | - /** |
|
| 3922 | - * returns the _req_data protected property |
|
| 3923 | - * |
|
| 3924 | - * @return string |
|
| 3925 | - */ |
|
| 3926 | - public function get_req_action() |
|
| 3927 | - { |
|
| 3928 | - return $this->_req_action; |
|
| 3929 | - } |
|
| 3930 | - |
|
| 3931 | - |
|
| 3932 | - /** |
|
| 3933 | - * @return bool value of $_is_caf property |
|
| 3934 | - */ |
|
| 3935 | - public function is_caf() |
|
| 3936 | - { |
|
| 3937 | - return $this->_is_caf; |
|
| 3938 | - } |
|
| 3939 | - |
|
| 3940 | - |
|
| 3941 | - /** |
|
| 3942 | - * @return mixed |
|
| 3943 | - */ |
|
| 3944 | - public function default_espresso_metaboxes() |
|
| 3945 | - { |
|
| 3946 | - return $this->_default_espresso_metaboxes; |
|
| 3947 | - } |
|
| 3948 | - |
|
| 3949 | - |
|
| 3950 | - /** |
|
| 3951 | - * @return mixed |
|
| 3952 | - */ |
|
| 3953 | - public function admin_base_url() |
|
| 3954 | - { |
|
| 3955 | - return $this->_admin_base_url; |
|
| 3956 | - } |
|
| 3957 | - |
|
| 3958 | - |
|
| 3959 | - /** |
|
| 3960 | - * @return mixed |
|
| 3961 | - */ |
|
| 3962 | - public function wp_page_slug() |
|
| 3963 | - { |
|
| 3964 | - return $this->_wp_page_slug; |
|
| 3965 | - } |
|
| 3966 | - |
|
| 3967 | - |
|
| 3968 | - /** |
|
| 3969 | - * updates espresso configuration settings |
|
| 3970 | - * |
|
| 3971 | - * @param string $tab |
|
| 3972 | - * @param EE_Config_Base|EE_Config $config |
|
| 3973 | - * @param string $file file where error occurred |
|
| 3974 | - * @param string $func function where error occurred |
|
| 3975 | - * @param string $line line no where error occurred |
|
| 3976 | - * @return boolean |
|
| 3977 | - */ |
|
| 3978 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3979 | - { |
|
| 3980 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 3981 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 3982 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3983 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3984 | - update_option('ee_ueip_has_notified', true); |
|
| 3985 | - } |
|
| 3986 | - // and save it (note we're also doing the network save here) |
|
| 3987 | - $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 3988 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3989 | - if ($config_saved && $net_saved) { |
|
| 3990 | - EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3991 | - return true; |
|
| 3992 | - } |
|
| 3993 | - EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3994 | - return false; |
|
| 3995 | - } |
|
| 3996 | - |
|
| 3997 | - |
|
| 3998 | - /** |
|
| 3999 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4000 | - * |
|
| 4001 | - * @return array |
|
| 4002 | - */ |
|
| 4003 | - public function get_yes_no_values() |
|
| 4004 | - { |
|
| 4005 | - return $this->_yes_no_values; |
|
| 4006 | - } |
|
| 4007 | - |
|
| 4008 | - |
|
| 4009 | - /** |
|
| 4010 | - * @return string |
|
| 4011 | - * @throws ReflectionException |
|
| 4012 | - * @since $VID:$ |
|
| 4013 | - */ |
|
| 4014 | - protected function _get_dir() |
|
| 4015 | - { |
|
| 4016 | - $reflector = new ReflectionClass($this->class_name); |
|
| 4017 | - return dirname($reflector->getFileName()); |
|
| 4018 | - } |
|
| 4019 | - |
|
| 4020 | - |
|
| 4021 | - /** |
|
| 4022 | - * A helper for getting a "next link". |
|
| 4023 | - * |
|
| 4024 | - * @param string $url The url to link to |
|
| 4025 | - * @param string $class The class to use. |
|
| 4026 | - * @return string |
|
| 4027 | - */ |
|
| 4028 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4029 | - { |
|
| 4030 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4031 | - } |
|
| 4032 | - |
|
| 4033 | - |
|
| 4034 | - /** |
|
| 4035 | - * A helper for getting a "previous link". |
|
| 4036 | - * |
|
| 4037 | - * @param string $url The url to link to |
|
| 4038 | - * @param string $class The class to use. |
|
| 4039 | - * @return string |
|
| 4040 | - */ |
|
| 4041 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4042 | - { |
|
| 4043 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4044 | - } |
|
| 4045 | - |
|
| 4046 | - |
|
| 4047 | - |
|
| 4048 | - |
|
| 4049 | - |
|
| 4050 | - |
|
| 4051 | - |
|
| 4052 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4053 | - |
|
| 4054 | - |
|
| 4055 | - /** |
|
| 4056 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4057 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4058 | - * _req_data array. |
|
| 4059 | - * |
|
| 4060 | - * @return bool success/fail |
|
| 4061 | - * @throws EE_Error |
|
| 4062 | - * @throws InvalidArgumentException |
|
| 4063 | - * @throws ReflectionException |
|
| 4064 | - * @throws InvalidDataTypeException |
|
| 4065 | - * @throws InvalidInterfaceException |
|
| 4066 | - */ |
|
| 4067 | - protected function _process_resend_registration() |
|
| 4068 | - { |
|
| 4069 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4070 | - do_action( |
|
| 4071 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4072 | - $this->_template_args['success'], |
|
| 4073 | - $this->request->requestParams() |
|
| 4074 | - ); |
|
| 4075 | - return $this->_template_args['success']; |
|
| 4076 | - } |
|
| 4077 | - |
|
| 4078 | - |
|
| 4079 | - /** |
|
| 4080 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4081 | - * |
|
| 4082 | - * @param EE_Payment $payment |
|
| 4083 | - * @return bool success/fail |
|
| 4084 | - */ |
|
| 4085 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4086 | - { |
|
| 4087 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4088 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4089 | - $this->_template_args['success'] = apply_filters( |
|
| 4090 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4091 | - false, |
|
| 4092 | - $payment |
|
| 4093 | - ); |
|
| 4094 | - return $this->_template_args['success']; |
|
| 4095 | - } |
|
| 4096 | - |
|
| 4097 | - |
|
| 4098 | - /** |
|
| 4099 | - * @param EEM_Base $entity_model |
|
| 4100 | - * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
| 4101 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4102 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4103 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4104 | - * @return int|float |
|
| 4105 | - * @throws EE_Error |
|
| 4106 | - */ |
|
| 4107 | - protected function trashRestoreDeleteEntities( |
|
| 4108 | - EEM_Base $entity_model, |
|
| 4109 | - string $entity_PK_name, |
|
| 4110 | - string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
| 4111 | - string $delete_column = '', |
|
| 4112 | - callable $callback = null |
|
| 4113 | - ) { |
|
| 4114 | - $entity_PK = $entity_model->get_primary_key_field(); |
|
| 4115 | - $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
| 4116 | - $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
| 4117 | - // grab ID if deleting a single entity |
|
| 4118 | - if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
| 4119 | - $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
| 4120 | - return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
| 4121 | - } |
|
| 4122 | - // or grab checkbox array if bulk deleting |
|
| 4123 | - $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
| 4124 | - if (empty($checkboxes)) { |
|
| 4125 | - return 0; |
|
| 4126 | - } |
|
| 4127 | - $success = 0; |
|
| 4128 | - $IDs = array_keys($checkboxes); |
|
| 4129 | - // cycle thru bulk action checkboxes |
|
| 4130 | - foreach ($IDs as $ID) { |
|
| 4131 | - // increment $success |
|
| 4132 | - if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
| 4133 | - $success++; |
|
| 4134 | - } |
|
| 4135 | - } |
|
| 4136 | - $count = (int) count($checkboxes); |
|
| 4137 | - // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
| 4138 | - // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
| 4139 | - return $success === $count ? $count : $success / $count; |
|
| 4140 | - } |
|
| 4141 | - |
|
| 4142 | - |
|
| 4143 | - /** |
|
| 4144 | - * @param EE_Primary_Key_Field_Base $entity_PK |
|
| 4145 | - * @return string |
|
| 4146 | - * @throws EE_Error |
|
| 4147 | - * @since $VID:$ |
|
| 4148 | - */ |
|
| 4149 | - private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
| 4150 | - { |
|
| 4151 | - $entity_PK_type = $entity_PK->getSchemaType(); |
|
| 4152 | - switch ($entity_PK_type) { |
|
| 4153 | - case 'boolean': |
|
| 4154 | - return 'bool'; |
|
| 4155 | - case 'integer': |
|
| 4156 | - return 'int'; |
|
| 4157 | - case 'number': |
|
| 4158 | - return 'float'; |
|
| 4159 | - case 'string': |
|
| 4160 | - return 'string'; |
|
| 4161 | - } |
|
| 4162 | - throw new RuntimeException( |
|
| 4163 | - sprintf( |
|
| 4164 | - esc_html__( |
|
| 4165 | - '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
| 4166 | - 'event_espresso' |
|
| 4167 | - ), |
|
| 4168 | - $entity_PK_type, |
|
| 4169 | - $entity_PK->get_name() |
|
| 4170 | - ) |
|
| 4171 | - ); |
|
| 4172 | - } |
|
| 4173 | - |
|
| 4174 | - |
|
| 4175 | - /** |
|
| 4176 | - * @param EEM_Base $entity_model |
|
| 4177 | - * @param int|string $entity_ID |
|
| 4178 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4179 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4180 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4181 | - * @return bool |
|
| 4182 | - */ |
|
| 4183 | - protected function trashRestoreDeleteEntity( |
|
| 4184 | - EEM_Base $entity_model, |
|
| 4185 | - $entity_ID, |
|
| 4186 | - string $action, |
|
| 4187 | - string $delete_column, |
|
| 4188 | - ?callable $callback = null |
|
| 4189 | - ): bool { |
|
| 4190 | - $entity_ID = absint($entity_ID); |
|
| 4191 | - if (! $entity_ID) { |
|
| 4192 | - $this->trashRestoreDeleteError($action, $entity_model); |
|
| 4193 | - } |
|
| 4194 | - $result = 0; |
|
| 4195 | - try { |
|
| 4196 | - switch ($action) { |
|
| 4197 | - case EE_Admin_List_Table::ACTION_DELETE: |
|
| 4198 | - $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID); |
|
| 4199 | - break; |
|
| 4200 | - case EE_Admin_List_Table::ACTION_RESTORE: |
|
| 4201 | - $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4202 | - $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID); |
|
| 4203 | - break; |
|
| 4204 | - case EE_Admin_List_Table::ACTION_TRASH: |
|
| 4205 | - $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4206 | - $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID); |
|
| 4207 | - break; |
|
| 4208 | - } |
|
| 4209 | - } catch (Exception $exception) { |
|
| 4210 | - $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
| 4211 | - } |
|
| 4212 | - if (is_callable($callback)) { |
|
| 4213 | - call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
| 4214 | - } |
|
| 4215 | - return $result; |
|
| 4216 | - } |
|
| 4217 | - |
|
| 4218 | - |
|
| 4219 | - /** |
|
| 4220 | - * @param EEM_Base $entity_model |
|
| 4221 | - * @param string $delete_column |
|
| 4222 | - * @since $VID:$ |
|
| 4223 | - */ |
|
| 4224 | - private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
| 4225 | - { |
|
| 4226 | - if (empty($delete_column)) { |
|
| 4227 | - throw new DomainException( |
|
| 4228 | - sprintf( |
|
| 4229 | - esc_html__( |
|
| 4230 | - 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
| 4231 | - 'event_espresso' |
|
| 4232 | - ), |
|
| 4233 | - $entity_model->get_this_model_name() |
|
| 4234 | - ) |
|
| 4235 | - ); |
|
| 4236 | - } |
|
| 4237 | - if (! $entity_model->has_field($delete_column)) { |
|
| 4238 | - throw new DomainException( |
|
| 4239 | - sprintf( |
|
| 4240 | - esc_html__( |
|
| 4241 | - 'The %1$s field does not exist on the %2$s model.', |
|
| 4242 | - 'event_espresso' |
|
| 4243 | - ), |
|
| 4244 | - $delete_column, |
|
| 4245 | - $entity_model->get_this_model_name() |
|
| 4246 | - ) |
|
| 4247 | - ); |
|
| 4248 | - } |
|
| 4249 | - } |
|
| 4250 | - |
|
| 4251 | - |
|
| 4252 | - /** |
|
| 4253 | - * @param EEM_Base $entity_model |
|
| 4254 | - * @param Exception|null $exception |
|
| 4255 | - * @param string $action |
|
| 4256 | - * @since $VID:$ |
|
| 4257 | - */ |
|
| 4258 | - private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null) |
|
| 4259 | - { |
|
| 4260 | - if ($exception instanceof Exception) { |
|
| 4261 | - throw new RuntimeException( |
|
| 4262 | - sprintf( |
|
| 4263 | - esc_html__( |
|
| 4264 | - 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
| 4265 | - 'event_espresso' |
|
| 4266 | - ), |
|
| 4267 | - $action, |
|
| 4268 | - $entity_model->get_this_model_name(), |
|
| 4269 | - $exception->getMessage() |
|
| 4270 | - ) |
|
| 4271 | - ); |
|
| 4272 | - } |
|
| 4273 | - throw new RuntimeException( |
|
| 4274 | - sprintf( |
|
| 4275 | - esc_html__( |
|
| 4276 | - 'Could not %1$s the %2$s because an invalid ID was received.', |
|
| 4277 | - 'event_espresso' |
|
| 4278 | - ), |
|
| 4279 | - $action, |
|
| 4280 | - $entity_model->get_this_model_name() |
|
| 4281 | - ) |
|
| 4282 | - ); |
|
| 4283 | - } |
|
| 3316 | + // add nonce |
|
| 3317 | + $nonce = |
|
| 3318 | + wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3319 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3320 | + // add REQUIRED form action |
|
| 3321 | + $hidden_fields = [ |
|
| 3322 | + 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3323 | + ]; |
|
| 3324 | + // merge arrays |
|
| 3325 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3326 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3327 | + : $hidden_fields; |
|
| 3328 | + // generate form fields |
|
| 3329 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3330 | + // add fields to form |
|
| 3331 | + foreach ((array) $form_fields as $form_field) { |
|
| 3332 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3333 | + } |
|
| 3334 | + // close form |
|
| 3335 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3336 | + } |
|
| 3337 | + |
|
| 3338 | + |
|
| 3339 | + /** |
|
| 3340 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3341 | + * discovered it would be useful for external code to have access. |
|
| 3342 | + * |
|
| 3343 | + * @param bool $success |
|
| 3344 | + * @param string $what |
|
| 3345 | + * @param string $action_desc |
|
| 3346 | + * @param array $query_args |
|
| 3347 | + * @param bool $override_overwrite |
|
| 3348 | + * @throws EE_Error |
|
| 3349 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3350 | + * @since 4.5.0 |
|
| 3351 | + */ |
|
| 3352 | + public function redirect_after_action( |
|
| 3353 | + $success = false, |
|
| 3354 | + $what = 'item', |
|
| 3355 | + $action_desc = 'processed', |
|
| 3356 | + $query_args = [], |
|
| 3357 | + $override_overwrite = false |
|
| 3358 | + ) { |
|
| 3359 | + $this->_redirect_after_action( |
|
| 3360 | + $success, |
|
| 3361 | + $what, |
|
| 3362 | + $action_desc, |
|
| 3363 | + $query_args, |
|
| 3364 | + $override_overwrite |
|
| 3365 | + ); |
|
| 3366 | + } |
|
| 3367 | + |
|
| 3368 | + |
|
| 3369 | + /** |
|
| 3370 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3371 | + * |
|
| 3372 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3373 | + * filters are still applied. |
|
| 3374 | + * |
|
| 3375 | + * @param array $new_route_data |
|
| 3376 | + * @return array |
|
| 3377 | + */ |
|
| 3378 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3379 | + { |
|
| 3380 | + foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3381 | + // unset nonces |
|
| 3382 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3383 | + $this->request->unSetRequestParam($ref); |
|
| 3384 | + continue; |
|
| 3385 | + } |
|
| 3386 | + // urlencode values. |
|
| 3387 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3388 | + $this->request->setRequestParam($ref, $value); |
|
| 3389 | + } |
|
| 3390 | + return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3391 | + } |
|
| 3392 | + |
|
| 3393 | + |
|
| 3394 | + /** |
|
| 3395 | + * @param int|float|string $success - whether success was for two or more records, or just one, or none |
|
| 3396 | + * @param string $what - what the action was performed on |
|
| 3397 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3398 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to |
|
| 3399 | + * @param BOOL $override_overwrite - by default all EE_Error::success messages are overwritten, |
|
| 3400 | + * this allows you to override this so that they show. |
|
| 3401 | + * @return void |
|
| 3402 | + * @throws EE_Error |
|
| 3403 | + * @throws InvalidArgumentException |
|
| 3404 | + * @throws InvalidDataTypeException |
|
| 3405 | + * @throws InvalidInterfaceException |
|
| 3406 | + */ |
|
| 3407 | + protected function _redirect_after_action( |
|
| 3408 | + $success = 0, |
|
| 3409 | + string $what = 'item', |
|
| 3410 | + string $action_desc = 'processed', |
|
| 3411 | + array $query_args = [], |
|
| 3412 | + bool $override_overwrite = false |
|
| 3413 | + ) { |
|
| 3414 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3415 | + $notices = EE_Error::get_notices(false); |
|
| 3416 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3417 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3418 | + EE_Error::overwrite_success(); |
|
| 3419 | + } |
|
| 3420 | + if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3421 | + // how many records affected ? more than one record ? or just one ? |
|
| 3422 | + EE_Error::add_success( |
|
| 3423 | + sprintf( |
|
| 3424 | + esc_html( |
|
| 3425 | + _n( |
|
| 3426 | + 'The "%1$s" has been successfully %2$s.', |
|
| 3427 | + 'The "%1$s" have been successfully %2$s.', |
|
| 3428 | + $success, |
|
| 3429 | + 'event_espresso' |
|
| 3430 | + ) |
|
| 3431 | + ), |
|
| 3432 | + $what, |
|
| 3433 | + $action_desc |
|
| 3434 | + ), |
|
| 3435 | + __FILE__, |
|
| 3436 | + __FUNCTION__, |
|
| 3437 | + __LINE__ |
|
| 3438 | + ); |
|
| 3439 | + } |
|
| 3440 | + // check that $query_args isn't something crazy |
|
| 3441 | + if (! is_array($query_args)) { |
|
| 3442 | + $query_args = []; |
|
| 3443 | + } |
|
| 3444 | + /** |
|
| 3445 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3446 | + * redirections on save and close actions |
|
| 3447 | + * |
|
| 3448 | + * @param array $query_args The original query_args array coming into the |
|
| 3449 | + * method. |
|
| 3450 | + * @since 4.2.0 |
|
| 3451 | + */ |
|
| 3452 | + do_action( |
|
| 3453 | + "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3454 | + $query_args |
|
| 3455 | + ); |
|
| 3456 | + // set redirect url. |
|
| 3457 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3458 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3459 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3460 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3461 | + if ( |
|
| 3462 | + $this->request->requestParamIsSet('save_and_close') |
|
| 3463 | + && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3464 | + ) { |
|
| 3465 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3466 | + $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3467 | + // regenerate query args array from referrer URL |
|
| 3468 | + parse_str($parsed_url['query'], $query_args); |
|
| 3469 | + // correct page and action will be in the query args now |
|
| 3470 | + $redirect_url = admin_url('admin.php'); |
|
| 3471 | + } |
|
| 3472 | + // merge any default query_args set in _default_route_query_args property |
|
| 3473 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3474 | + $args_to_merge = []; |
|
| 3475 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3476 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3477 | + if ($query_param === 'wp_referer') { |
|
| 3478 | + $query_value = (array) $query_value; |
|
| 3479 | + foreach ($query_value as $reference => $value) { |
|
| 3480 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3481 | + continue; |
|
| 3482 | + } |
|
| 3483 | + // finally we will override any arguments in the referer with |
|
| 3484 | + // what might be set on the _default_route_query_args array. |
|
| 3485 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3486 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3487 | + } else { |
|
| 3488 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3489 | + } |
|
| 3490 | + } |
|
| 3491 | + continue; |
|
| 3492 | + } |
|
| 3493 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3494 | + } |
|
| 3495 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3496 | + // redirect. |
|
| 3497 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3498 | + } |
|
| 3499 | + $this->_process_notices($query_args); |
|
| 3500 | + // generate redirect url |
|
| 3501 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3502 | + if (isset($query_args['action'])) { |
|
| 3503 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3504 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3505 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3506 | + } |
|
| 3507 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3508 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3509 | + do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args); |
|
| 3510 | + $redirect_url = apply_filters( |
|
| 3511 | + 'FHEE_redirect_' . $this->class_name . $this->_req_action, |
|
| 3512 | + EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3513 | + $query_args |
|
| 3514 | + ); |
|
| 3515 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3516 | + if ($this->request->isAjax()) { |
|
| 3517 | + $default_data = [ |
|
| 3518 | + 'close' => true, |
|
| 3519 | + 'redirect_url' => $redirect_url, |
|
| 3520 | + 'where' => 'main', |
|
| 3521 | + 'what' => 'append', |
|
| 3522 | + ]; |
|
| 3523 | + $this->_template_args['success'] = $success; |
|
| 3524 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3525 | + $default_data, |
|
| 3526 | + $this->_template_args['data'] |
|
| 3527 | + ) : $default_data; |
|
| 3528 | + $this->_return_json(); |
|
| 3529 | + } |
|
| 3530 | + wp_safe_redirect($redirect_url); |
|
| 3531 | + exit(); |
|
| 3532 | + } |
|
| 3533 | + |
|
| 3534 | + |
|
| 3535 | + /** |
|
| 3536 | + * process any notices before redirecting (or returning ajax request) |
|
| 3537 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3538 | + * |
|
| 3539 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3540 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3541 | + * page_routes haven't been defined yet. |
|
| 3542 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3543 | + * still save a transient for the notice. |
|
| 3544 | + * @return void |
|
| 3545 | + * @throws EE_Error |
|
| 3546 | + * @throws InvalidArgumentException |
|
| 3547 | + * @throws InvalidDataTypeException |
|
| 3548 | + * @throws InvalidInterfaceException |
|
| 3549 | + */ |
|
| 3550 | + protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3551 | + { |
|
| 3552 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3553 | + if ($this->request->isAjax()) { |
|
| 3554 | + $notices = EE_Error::get_notices(false); |
|
| 3555 | + if (empty($this->_template_args['success'])) { |
|
| 3556 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3557 | + } |
|
| 3558 | + if (empty($this->_template_args['errors'])) { |
|
| 3559 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3560 | + } |
|
| 3561 | + if (empty($this->_template_args['attention'])) { |
|
| 3562 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3563 | + } |
|
| 3564 | + } |
|
| 3565 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3566 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3567 | + if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3568 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3569 | + $this->_add_transient( |
|
| 3570 | + $route, |
|
| 3571 | + $this->_template_args['notices'], |
|
| 3572 | + true, |
|
| 3573 | + $skip_route_verify |
|
| 3574 | + ); |
|
| 3575 | + } |
|
| 3576 | + } |
|
| 3577 | + |
|
| 3578 | + |
|
| 3579 | + /** |
|
| 3580 | + * get_action_link_or_button |
|
| 3581 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3582 | + * |
|
| 3583 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3584 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3585 | + * property. |
|
| 3586 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3587 | + * @param string $class Use this to give the class for the button. Defaults to 'button--primary' |
|
| 3588 | + * @param string $base_url If this is not provided |
|
| 3589 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3590 | + * Otherwise this value will be used. |
|
| 3591 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3592 | + * @return string |
|
| 3593 | + * @throws InvalidArgumentException |
|
| 3594 | + * @throws InvalidInterfaceException |
|
| 3595 | + * @throws InvalidDataTypeException |
|
| 3596 | + * @throws EE_Error |
|
| 3597 | + */ |
|
| 3598 | + public function get_action_link_or_button( |
|
| 3599 | + $action, |
|
| 3600 | + $type = 'add', |
|
| 3601 | + $extra_request = [], |
|
| 3602 | + $class = 'button--primary', |
|
| 3603 | + $base_url = '', |
|
| 3604 | + $exclude_nonce = false |
|
| 3605 | + ) { |
|
| 3606 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3607 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3608 | + throw new EE_Error( |
|
| 3609 | + sprintf( |
|
| 3610 | + esc_html__( |
|
| 3611 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3612 | + 'event_espresso' |
|
| 3613 | + ), |
|
| 3614 | + $action |
|
| 3615 | + ) |
|
| 3616 | + ); |
|
| 3617 | + } |
|
| 3618 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3619 | + throw new EE_Error( |
|
| 3620 | + sprintf( |
|
| 3621 | + esc_html__( |
|
| 3622 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3623 | + 'event_espresso' |
|
| 3624 | + ), |
|
| 3625 | + $type |
|
| 3626 | + ) |
|
| 3627 | + ); |
|
| 3628 | + } |
|
| 3629 | + // finally check user access for this button. |
|
| 3630 | + $has_access = $this->check_user_access($action, true); |
|
| 3631 | + if (! $has_access) { |
|
| 3632 | + return ''; |
|
| 3633 | + } |
|
| 3634 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3635 | + $query_args = [ |
|
| 3636 | + 'action' => $action, |
|
| 3637 | + ]; |
|
| 3638 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3639 | + if (! empty($extra_request)) { |
|
| 3640 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3641 | + } |
|
| 3642 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3643 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3644 | + } |
|
| 3645 | + |
|
| 3646 | + |
|
| 3647 | + /** |
|
| 3648 | + * _per_page_screen_option |
|
| 3649 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3650 | + * |
|
| 3651 | + * @return void |
|
| 3652 | + * @throws InvalidArgumentException |
|
| 3653 | + * @throws InvalidInterfaceException |
|
| 3654 | + * @throws InvalidDataTypeException |
|
| 3655 | + */ |
|
| 3656 | + protected function _per_page_screen_option() |
|
| 3657 | + { |
|
| 3658 | + $option = 'per_page'; |
|
| 3659 | + $args = [ |
|
| 3660 | + 'label' => apply_filters( |
|
| 3661 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3662 | + $this->_admin_page_title, |
|
| 3663 | + $this |
|
| 3664 | + ), |
|
| 3665 | + 'default' => (int) apply_filters( |
|
| 3666 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3667 | + 20 |
|
| 3668 | + ), |
|
| 3669 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3670 | + ]; |
|
| 3671 | + // ONLY add the screen option if the user has access to it. |
|
| 3672 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3673 | + add_screen_option($option, $args); |
|
| 3674 | + } |
|
| 3675 | + } |
|
| 3676 | + |
|
| 3677 | + |
|
| 3678 | + /** |
|
| 3679 | + * set_per_page_screen_option |
|
| 3680 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3681 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3682 | + * admin_menu. |
|
| 3683 | + * |
|
| 3684 | + * @return void |
|
| 3685 | + */ |
|
| 3686 | + private function _set_per_page_screen_options() |
|
| 3687 | + { |
|
| 3688 | + if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3689 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3690 | + if (! $user = wp_get_current_user()) { |
|
| 3691 | + return; |
|
| 3692 | + } |
|
| 3693 | + $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3694 | + if (! $option) { |
|
| 3695 | + return; |
|
| 3696 | + } |
|
| 3697 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3698 | + $map_option = $option; |
|
| 3699 | + $option = str_replace('-', '_', $option); |
|
| 3700 | + switch ($map_option) { |
|
| 3701 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3702 | + $max_value = apply_filters( |
|
| 3703 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3704 | + 999, |
|
| 3705 | + $this->_current_page, |
|
| 3706 | + $this->_current_view |
|
| 3707 | + ); |
|
| 3708 | + if ($value < 1) { |
|
| 3709 | + return; |
|
| 3710 | + } |
|
| 3711 | + $value = min($value, $max_value); |
|
| 3712 | + break; |
|
| 3713 | + default: |
|
| 3714 | + $value = apply_filters( |
|
| 3715 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3716 | + false, |
|
| 3717 | + $option, |
|
| 3718 | + $value |
|
| 3719 | + ); |
|
| 3720 | + if (false === $value) { |
|
| 3721 | + return; |
|
| 3722 | + } |
|
| 3723 | + break; |
|
| 3724 | + } |
|
| 3725 | + update_user_meta($user->ID, $option, $value); |
|
| 3726 | + wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3727 | + exit; |
|
| 3728 | + } |
|
| 3729 | + } |
|
| 3730 | + |
|
| 3731 | + |
|
| 3732 | + /** |
|
| 3733 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3734 | + * |
|
| 3735 | + * @param array $data array that will be assigned to template args. |
|
| 3736 | + */ |
|
| 3737 | + public function set_template_args($data) |
|
| 3738 | + { |
|
| 3739 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3740 | + } |
|
| 3741 | + |
|
| 3742 | + |
|
| 3743 | + /** |
|
| 3744 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3745 | + * |
|
| 3746 | + * @param string $route the route that should receive the transient |
|
| 3747 | + * @param array $data the data that gets sent |
|
| 3748 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3749 | + * normal route transient. |
|
| 3750 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3751 | + * when we are adding a transient before page_routes have been defined. |
|
| 3752 | + * @return void |
|
| 3753 | + * @throws EE_Error |
|
| 3754 | + */ |
|
| 3755 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3756 | + { |
|
| 3757 | + $user_id = get_current_user_id(); |
|
| 3758 | + if (! $skip_route_verify) { |
|
| 3759 | + $this->_verify_route($route); |
|
| 3760 | + } |
|
| 3761 | + // now let's set the string for what kind of transient we're setting |
|
| 3762 | + $transient = $notices |
|
| 3763 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3764 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3765 | + $data = $notices ? ['notices' => $data] : $data; |
|
| 3766 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3767 | + $existing = is_multisite() && is_network_admin() |
|
| 3768 | + ? get_site_transient($transient) |
|
| 3769 | + : get_transient($transient); |
|
| 3770 | + if ($existing) { |
|
| 3771 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3772 | + } |
|
| 3773 | + if (is_multisite() && is_network_admin()) { |
|
| 3774 | + set_site_transient($transient, $data, 8); |
|
| 3775 | + } else { |
|
| 3776 | + set_transient($transient, $data, 8); |
|
| 3777 | + } |
|
| 3778 | + } |
|
| 3779 | + |
|
| 3780 | + |
|
| 3781 | + /** |
|
| 3782 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3783 | + * |
|
| 3784 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3785 | + * @param string $route |
|
| 3786 | + * @return mixed data |
|
| 3787 | + */ |
|
| 3788 | + protected function _get_transient($notices = false, $route = '') |
|
| 3789 | + { |
|
| 3790 | + $user_id = get_current_user_id(); |
|
| 3791 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3792 | + $transient = $notices |
|
| 3793 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3794 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3795 | + $data = is_multisite() && is_network_admin() |
|
| 3796 | + ? get_site_transient($transient) |
|
| 3797 | + : get_transient($transient); |
|
| 3798 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3799 | + if (is_multisite() && is_network_admin()) { |
|
| 3800 | + delete_site_transient($transient); |
|
| 3801 | + } else { |
|
| 3802 | + delete_transient($transient); |
|
| 3803 | + } |
|
| 3804 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3805 | + } |
|
| 3806 | + |
|
| 3807 | + |
|
| 3808 | + /** |
|
| 3809 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3810 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3811 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3812 | + * |
|
| 3813 | + * @return void |
|
| 3814 | + */ |
|
| 3815 | + protected function _transient_garbage_collection() |
|
| 3816 | + { |
|
| 3817 | + global $wpdb; |
|
| 3818 | + // retrieve all existing transients |
|
| 3819 | + $query = |
|
| 3820 | + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3821 | + if ($results = $wpdb->get_results($query)) { |
|
| 3822 | + foreach ($results as $result) { |
|
| 3823 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3824 | + get_transient($transient); |
|
| 3825 | + if (is_multisite() && is_network_admin()) { |
|
| 3826 | + get_site_transient($transient); |
|
| 3827 | + } |
|
| 3828 | + } |
|
| 3829 | + } |
|
| 3830 | + } |
|
| 3831 | + |
|
| 3832 | + |
|
| 3833 | + /** |
|
| 3834 | + * get_view |
|
| 3835 | + * |
|
| 3836 | + * @return string content of _view property |
|
| 3837 | + */ |
|
| 3838 | + public function get_view() |
|
| 3839 | + { |
|
| 3840 | + return $this->_view; |
|
| 3841 | + } |
|
| 3842 | + |
|
| 3843 | + |
|
| 3844 | + /** |
|
| 3845 | + * getter for the protected $_views property |
|
| 3846 | + * |
|
| 3847 | + * @return array |
|
| 3848 | + */ |
|
| 3849 | + public function get_views() |
|
| 3850 | + { |
|
| 3851 | + return $this->_views; |
|
| 3852 | + } |
|
| 3853 | + |
|
| 3854 | + |
|
| 3855 | + /** |
|
| 3856 | + * get_current_page |
|
| 3857 | + * |
|
| 3858 | + * @return string _current_page property value |
|
| 3859 | + */ |
|
| 3860 | + public function get_current_page() |
|
| 3861 | + { |
|
| 3862 | + return $this->_current_page; |
|
| 3863 | + } |
|
| 3864 | + |
|
| 3865 | + |
|
| 3866 | + /** |
|
| 3867 | + * get_current_view |
|
| 3868 | + * |
|
| 3869 | + * @return string _current_view property value |
|
| 3870 | + */ |
|
| 3871 | + public function get_current_view() |
|
| 3872 | + { |
|
| 3873 | + return $this->_current_view; |
|
| 3874 | + } |
|
| 3875 | + |
|
| 3876 | + |
|
| 3877 | + /** |
|
| 3878 | + * get_current_screen |
|
| 3879 | + * |
|
| 3880 | + * @return object The current WP_Screen object |
|
| 3881 | + */ |
|
| 3882 | + public function get_current_screen() |
|
| 3883 | + { |
|
| 3884 | + return $this->_current_screen; |
|
| 3885 | + } |
|
| 3886 | + |
|
| 3887 | + |
|
| 3888 | + /** |
|
| 3889 | + * get_current_page_view_url |
|
| 3890 | + * |
|
| 3891 | + * @return string This returns the url for the current_page_view. |
|
| 3892 | + */ |
|
| 3893 | + public function get_current_page_view_url() |
|
| 3894 | + { |
|
| 3895 | + return $this->_current_page_view_url; |
|
| 3896 | + } |
|
| 3897 | + |
|
| 3898 | + |
|
| 3899 | + /** |
|
| 3900 | + * just returns the Request |
|
| 3901 | + * |
|
| 3902 | + * @return RequestInterface |
|
| 3903 | + */ |
|
| 3904 | + public function get_request() |
|
| 3905 | + { |
|
| 3906 | + return $this->request; |
|
| 3907 | + } |
|
| 3908 | + |
|
| 3909 | + |
|
| 3910 | + /** |
|
| 3911 | + * just returns the _req_data property |
|
| 3912 | + * |
|
| 3913 | + * @return array |
|
| 3914 | + */ |
|
| 3915 | + public function get_request_data() |
|
| 3916 | + { |
|
| 3917 | + return $this->request->requestParams(); |
|
| 3918 | + } |
|
| 3919 | + |
|
| 3920 | + |
|
| 3921 | + /** |
|
| 3922 | + * returns the _req_data protected property |
|
| 3923 | + * |
|
| 3924 | + * @return string |
|
| 3925 | + */ |
|
| 3926 | + public function get_req_action() |
|
| 3927 | + { |
|
| 3928 | + return $this->_req_action; |
|
| 3929 | + } |
|
| 3930 | + |
|
| 3931 | + |
|
| 3932 | + /** |
|
| 3933 | + * @return bool value of $_is_caf property |
|
| 3934 | + */ |
|
| 3935 | + public function is_caf() |
|
| 3936 | + { |
|
| 3937 | + return $this->_is_caf; |
|
| 3938 | + } |
|
| 3939 | + |
|
| 3940 | + |
|
| 3941 | + /** |
|
| 3942 | + * @return mixed |
|
| 3943 | + */ |
|
| 3944 | + public function default_espresso_metaboxes() |
|
| 3945 | + { |
|
| 3946 | + return $this->_default_espresso_metaboxes; |
|
| 3947 | + } |
|
| 3948 | + |
|
| 3949 | + |
|
| 3950 | + /** |
|
| 3951 | + * @return mixed |
|
| 3952 | + */ |
|
| 3953 | + public function admin_base_url() |
|
| 3954 | + { |
|
| 3955 | + return $this->_admin_base_url; |
|
| 3956 | + } |
|
| 3957 | + |
|
| 3958 | + |
|
| 3959 | + /** |
|
| 3960 | + * @return mixed |
|
| 3961 | + */ |
|
| 3962 | + public function wp_page_slug() |
|
| 3963 | + { |
|
| 3964 | + return $this->_wp_page_slug; |
|
| 3965 | + } |
|
| 3966 | + |
|
| 3967 | + |
|
| 3968 | + /** |
|
| 3969 | + * updates espresso configuration settings |
|
| 3970 | + * |
|
| 3971 | + * @param string $tab |
|
| 3972 | + * @param EE_Config_Base|EE_Config $config |
|
| 3973 | + * @param string $file file where error occurred |
|
| 3974 | + * @param string $func function where error occurred |
|
| 3975 | + * @param string $line line no where error occurred |
|
| 3976 | + * @return boolean |
|
| 3977 | + */ |
|
| 3978 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3979 | + { |
|
| 3980 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 3981 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 3982 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3983 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3984 | + update_option('ee_ueip_has_notified', true); |
|
| 3985 | + } |
|
| 3986 | + // and save it (note we're also doing the network save here) |
|
| 3987 | + $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 3988 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3989 | + if ($config_saved && $net_saved) { |
|
| 3990 | + EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3991 | + return true; |
|
| 3992 | + } |
|
| 3993 | + EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3994 | + return false; |
|
| 3995 | + } |
|
| 3996 | + |
|
| 3997 | + |
|
| 3998 | + /** |
|
| 3999 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4000 | + * |
|
| 4001 | + * @return array |
|
| 4002 | + */ |
|
| 4003 | + public function get_yes_no_values() |
|
| 4004 | + { |
|
| 4005 | + return $this->_yes_no_values; |
|
| 4006 | + } |
|
| 4007 | + |
|
| 4008 | + |
|
| 4009 | + /** |
|
| 4010 | + * @return string |
|
| 4011 | + * @throws ReflectionException |
|
| 4012 | + * @since $VID:$ |
|
| 4013 | + */ |
|
| 4014 | + protected function _get_dir() |
|
| 4015 | + { |
|
| 4016 | + $reflector = new ReflectionClass($this->class_name); |
|
| 4017 | + return dirname($reflector->getFileName()); |
|
| 4018 | + } |
|
| 4019 | + |
|
| 4020 | + |
|
| 4021 | + /** |
|
| 4022 | + * A helper for getting a "next link". |
|
| 4023 | + * |
|
| 4024 | + * @param string $url The url to link to |
|
| 4025 | + * @param string $class The class to use. |
|
| 4026 | + * @return string |
|
| 4027 | + */ |
|
| 4028 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4029 | + { |
|
| 4030 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4031 | + } |
|
| 4032 | + |
|
| 4033 | + |
|
| 4034 | + /** |
|
| 4035 | + * A helper for getting a "previous link". |
|
| 4036 | + * |
|
| 4037 | + * @param string $url The url to link to |
|
| 4038 | + * @param string $class The class to use. |
|
| 4039 | + * @return string |
|
| 4040 | + */ |
|
| 4041 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4042 | + { |
|
| 4043 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4044 | + } |
|
| 4045 | + |
|
| 4046 | + |
|
| 4047 | + |
|
| 4048 | + |
|
| 4049 | + |
|
| 4050 | + |
|
| 4051 | + |
|
| 4052 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4053 | + |
|
| 4054 | + |
|
| 4055 | + /** |
|
| 4056 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4057 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4058 | + * _req_data array. |
|
| 4059 | + * |
|
| 4060 | + * @return bool success/fail |
|
| 4061 | + * @throws EE_Error |
|
| 4062 | + * @throws InvalidArgumentException |
|
| 4063 | + * @throws ReflectionException |
|
| 4064 | + * @throws InvalidDataTypeException |
|
| 4065 | + * @throws InvalidInterfaceException |
|
| 4066 | + */ |
|
| 4067 | + protected function _process_resend_registration() |
|
| 4068 | + { |
|
| 4069 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4070 | + do_action( |
|
| 4071 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4072 | + $this->_template_args['success'], |
|
| 4073 | + $this->request->requestParams() |
|
| 4074 | + ); |
|
| 4075 | + return $this->_template_args['success']; |
|
| 4076 | + } |
|
| 4077 | + |
|
| 4078 | + |
|
| 4079 | + /** |
|
| 4080 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4081 | + * |
|
| 4082 | + * @param EE_Payment $payment |
|
| 4083 | + * @return bool success/fail |
|
| 4084 | + */ |
|
| 4085 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4086 | + { |
|
| 4087 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4088 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4089 | + $this->_template_args['success'] = apply_filters( |
|
| 4090 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4091 | + false, |
|
| 4092 | + $payment |
|
| 4093 | + ); |
|
| 4094 | + return $this->_template_args['success']; |
|
| 4095 | + } |
|
| 4096 | + |
|
| 4097 | + |
|
| 4098 | + /** |
|
| 4099 | + * @param EEM_Base $entity_model |
|
| 4100 | + * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
| 4101 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4102 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4103 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4104 | + * @return int|float |
|
| 4105 | + * @throws EE_Error |
|
| 4106 | + */ |
|
| 4107 | + protected function trashRestoreDeleteEntities( |
|
| 4108 | + EEM_Base $entity_model, |
|
| 4109 | + string $entity_PK_name, |
|
| 4110 | + string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
| 4111 | + string $delete_column = '', |
|
| 4112 | + callable $callback = null |
|
| 4113 | + ) { |
|
| 4114 | + $entity_PK = $entity_model->get_primary_key_field(); |
|
| 4115 | + $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
| 4116 | + $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
| 4117 | + // grab ID if deleting a single entity |
|
| 4118 | + if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
| 4119 | + $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
| 4120 | + return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
| 4121 | + } |
|
| 4122 | + // or grab checkbox array if bulk deleting |
|
| 4123 | + $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
| 4124 | + if (empty($checkboxes)) { |
|
| 4125 | + return 0; |
|
| 4126 | + } |
|
| 4127 | + $success = 0; |
|
| 4128 | + $IDs = array_keys($checkboxes); |
|
| 4129 | + // cycle thru bulk action checkboxes |
|
| 4130 | + foreach ($IDs as $ID) { |
|
| 4131 | + // increment $success |
|
| 4132 | + if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
| 4133 | + $success++; |
|
| 4134 | + } |
|
| 4135 | + } |
|
| 4136 | + $count = (int) count($checkboxes); |
|
| 4137 | + // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
| 4138 | + // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
| 4139 | + return $success === $count ? $count : $success / $count; |
|
| 4140 | + } |
|
| 4141 | + |
|
| 4142 | + |
|
| 4143 | + /** |
|
| 4144 | + * @param EE_Primary_Key_Field_Base $entity_PK |
|
| 4145 | + * @return string |
|
| 4146 | + * @throws EE_Error |
|
| 4147 | + * @since $VID:$ |
|
| 4148 | + */ |
|
| 4149 | + private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
| 4150 | + { |
|
| 4151 | + $entity_PK_type = $entity_PK->getSchemaType(); |
|
| 4152 | + switch ($entity_PK_type) { |
|
| 4153 | + case 'boolean': |
|
| 4154 | + return 'bool'; |
|
| 4155 | + case 'integer': |
|
| 4156 | + return 'int'; |
|
| 4157 | + case 'number': |
|
| 4158 | + return 'float'; |
|
| 4159 | + case 'string': |
|
| 4160 | + return 'string'; |
|
| 4161 | + } |
|
| 4162 | + throw new RuntimeException( |
|
| 4163 | + sprintf( |
|
| 4164 | + esc_html__( |
|
| 4165 | + '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
| 4166 | + 'event_espresso' |
|
| 4167 | + ), |
|
| 4168 | + $entity_PK_type, |
|
| 4169 | + $entity_PK->get_name() |
|
| 4170 | + ) |
|
| 4171 | + ); |
|
| 4172 | + } |
|
| 4173 | + |
|
| 4174 | + |
|
| 4175 | + /** |
|
| 4176 | + * @param EEM_Base $entity_model |
|
| 4177 | + * @param int|string $entity_ID |
|
| 4178 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4179 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4180 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4181 | + * @return bool |
|
| 4182 | + */ |
|
| 4183 | + protected function trashRestoreDeleteEntity( |
|
| 4184 | + EEM_Base $entity_model, |
|
| 4185 | + $entity_ID, |
|
| 4186 | + string $action, |
|
| 4187 | + string $delete_column, |
|
| 4188 | + ?callable $callback = null |
|
| 4189 | + ): bool { |
|
| 4190 | + $entity_ID = absint($entity_ID); |
|
| 4191 | + if (! $entity_ID) { |
|
| 4192 | + $this->trashRestoreDeleteError($action, $entity_model); |
|
| 4193 | + } |
|
| 4194 | + $result = 0; |
|
| 4195 | + try { |
|
| 4196 | + switch ($action) { |
|
| 4197 | + case EE_Admin_List_Table::ACTION_DELETE: |
|
| 4198 | + $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID); |
|
| 4199 | + break; |
|
| 4200 | + case EE_Admin_List_Table::ACTION_RESTORE: |
|
| 4201 | + $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4202 | + $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID); |
|
| 4203 | + break; |
|
| 4204 | + case EE_Admin_List_Table::ACTION_TRASH: |
|
| 4205 | + $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4206 | + $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID); |
|
| 4207 | + break; |
|
| 4208 | + } |
|
| 4209 | + } catch (Exception $exception) { |
|
| 4210 | + $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
| 4211 | + } |
|
| 4212 | + if (is_callable($callback)) { |
|
| 4213 | + call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
| 4214 | + } |
|
| 4215 | + return $result; |
|
| 4216 | + } |
|
| 4217 | + |
|
| 4218 | + |
|
| 4219 | + /** |
|
| 4220 | + * @param EEM_Base $entity_model |
|
| 4221 | + * @param string $delete_column |
|
| 4222 | + * @since $VID:$ |
|
| 4223 | + */ |
|
| 4224 | + private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
| 4225 | + { |
|
| 4226 | + if (empty($delete_column)) { |
|
| 4227 | + throw new DomainException( |
|
| 4228 | + sprintf( |
|
| 4229 | + esc_html__( |
|
| 4230 | + 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
| 4231 | + 'event_espresso' |
|
| 4232 | + ), |
|
| 4233 | + $entity_model->get_this_model_name() |
|
| 4234 | + ) |
|
| 4235 | + ); |
|
| 4236 | + } |
|
| 4237 | + if (! $entity_model->has_field($delete_column)) { |
|
| 4238 | + throw new DomainException( |
|
| 4239 | + sprintf( |
|
| 4240 | + esc_html__( |
|
| 4241 | + 'The %1$s field does not exist on the %2$s model.', |
|
| 4242 | + 'event_espresso' |
|
| 4243 | + ), |
|
| 4244 | + $delete_column, |
|
| 4245 | + $entity_model->get_this_model_name() |
|
| 4246 | + ) |
|
| 4247 | + ); |
|
| 4248 | + } |
|
| 4249 | + } |
|
| 4250 | + |
|
| 4251 | + |
|
| 4252 | + /** |
|
| 4253 | + * @param EEM_Base $entity_model |
|
| 4254 | + * @param Exception|null $exception |
|
| 4255 | + * @param string $action |
|
| 4256 | + * @since $VID:$ |
|
| 4257 | + */ |
|
| 4258 | + private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null) |
|
| 4259 | + { |
|
| 4260 | + if ($exception instanceof Exception) { |
|
| 4261 | + throw new RuntimeException( |
|
| 4262 | + sprintf( |
|
| 4263 | + esc_html__( |
|
| 4264 | + 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
| 4265 | + 'event_espresso' |
|
| 4266 | + ), |
|
| 4267 | + $action, |
|
| 4268 | + $entity_model->get_this_model_name(), |
|
| 4269 | + $exception->getMessage() |
|
| 4270 | + ) |
|
| 4271 | + ); |
|
| 4272 | + } |
|
| 4273 | + throw new RuntimeException( |
|
| 4274 | + sprintf( |
|
| 4275 | + esc_html__( |
|
| 4276 | + 'Could not %1$s the %2$s because an invalid ID was received.', |
|
| 4277 | + 'event_espresso' |
|
| 4278 | + ), |
|
| 4279 | + $action, |
|
| 4280 | + $entity_model->get_this_model_name() |
|
| 4281 | + ) |
|
| 4282 | + ); |
|
| 4283 | + } |
|
| 4284 | 4284 | } |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 629 | 629 | if ( |
| 630 | 630 | ! $this->request->isAjax() |
| 631 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 631 | + && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) |
|
| 632 | 632 | ) { |
| 633 | 633 | return; |
| 634 | 634 | } |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | : $req_action; |
| 649 | 649 | |
| 650 | 650 | $this->_current_view = $this->_req_action; |
| 651 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 651 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 652 | 652 | $this->_define_page_props(); |
| 653 | 653 | $this->_current_page_view_url = add_query_arg( |
| 654 | 654 | ['page' => $this->_current_page, 'action' => $this->_current_view], |
@@ -678,33 +678,33 @@ discard block |
||
| 678 | 678 | } |
| 679 | 679 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 680 | 680 | $this->_page_routes = apply_filters( |
| 681 | - 'FHEE__' . $this->class_name . '__page_setup__page_routes', |
|
| 681 | + 'FHEE__'.$this->class_name.'__page_setup__page_routes', |
|
| 682 | 682 | $this->_page_routes, |
| 683 | 683 | $this |
| 684 | 684 | ); |
| 685 | 685 | $this->_page_config = apply_filters( |
| 686 | - 'FHEE__' . $this->class_name . '__page_setup__page_config', |
|
| 686 | + 'FHEE__'.$this->class_name.'__page_setup__page_config', |
|
| 687 | 687 | $this->_page_config, |
| 688 | 688 | $this |
| 689 | 689 | ); |
| 690 | 690 | if ($this->base_class_name !== '') { |
| 691 | 691 | $this->_page_routes = apply_filters( |
| 692 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_routes', |
|
| 692 | + 'FHEE__'.$this->base_class_name.'__page_setup__page_routes', |
|
| 693 | 693 | $this->_page_routes, |
| 694 | 694 | $this |
| 695 | 695 | ); |
| 696 | 696 | $this->_page_config = apply_filters( |
| 697 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_config', |
|
| 697 | + 'FHEE__'.$this->base_class_name.'__page_setup__page_config', |
|
| 698 | 698 | $this->_page_config, |
| 699 | 699 | $this |
| 700 | 700 | ); |
| 701 | 701 | } |
| 702 | 702 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 703 | 703 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 704 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 704 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 705 | 705 | add_action( |
| 706 | 706 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 707 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 707 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view], |
|
| 708 | 708 | 10, |
| 709 | 709 | 2 |
| 710 | 710 | ); |
@@ -717,8 +717,8 @@ discard block |
||
| 717 | 717 | if ($this->_is_UI_request) { |
| 718 | 718 | // admin_init stuff - global, all views for this page class, specific view |
| 719 | 719 | add_action('admin_init', [$this, 'admin_init'], 10); |
| 720 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 721 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 720 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 721 | + add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15); |
|
| 722 | 722 | } |
| 723 | 723 | } else { |
| 724 | 724 | // hijack regular WP loading and route admin request immediately |
@@ -737,12 +737,12 @@ discard block |
||
| 737 | 737 | */ |
| 738 | 738 | private function _do_other_page_hooks() |
| 739 | 739 | { |
| 740 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 740 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []); |
|
| 741 | 741 | foreach ($registered_pages as $page) { |
| 742 | 742 | // now let's setup the file name and class that should be present |
| 743 | 743 | $classname = str_replace('.class.php', '', $page); |
| 744 | 744 | // autoloaders should take care of loading file |
| 745 | - if (! class_exists($classname)) { |
|
| 745 | + if ( ! class_exists($classname)) { |
|
| 746 | 746 | $error_msg[] = sprintf( |
| 747 | 747 | esc_html__( |
| 748 | 748 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | ), |
| 760 | 760 | $page, |
| 761 | 761 | '<br />', |
| 762 | - '<strong>' . $classname . '</strong>' |
|
| 762 | + '<strong>'.$classname.'</strong>' |
|
| 763 | 763 | ); |
| 764 | 764 | throw new EE_Error(implode('||', $error_msg)); |
| 765 | 765 | } |
@@ -801,13 +801,13 @@ discard block |
||
| 801 | 801 | // load admin_notices - global, page class, and view specific |
| 802 | 802 | add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
| 803 | 803 | add_action('admin_notices', [$this, 'admin_notices'], 10); |
| 804 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 805 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 804 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 805 | + add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15); |
|
| 806 | 806 | } |
| 807 | 807 | // load network admin_notices - global, page class, and view specific |
| 808 | 808 | add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
| 809 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 810 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 809 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 810 | + add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]); |
|
| 811 | 811 | } |
| 812 | 812 | // this will save any per_page screen options if they are present |
| 813 | 813 | $this->_set_per_page_screen_options(); |
@@ -928,7 +928,7 @@ discard block |
||
| 928 | 928 | protected function _verify_routes() |
| 929 | 929 | { |
| 930 | 930 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 931 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 931 | + if ( ! $this->_current_page && ! $this->request->isAjax()) { |
|
| 932 | 932 | return false; |
| 933 | 933 | } |
| 934 | 934 | $this->_route = false; |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | $this->_admin_page_title |
| 941 | 941 | ); |
| 942 | 942 | // developer error msg |
| 943 | - $error_msg .= '||' . $error_msg |
|
| 943 | + $error_msg .= '||'.$error_msg |
|
| 944 | 944 | . esc_html__( |
| 945 | 945 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 946 | 946 | 'event_espresso' |
@@ -949,8 +949,8 @@ discard block |
||
| 949 | 949 | } |
| 950 | 950 | // and that the requested page route exists |
| 951 | 951 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 952 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 953 | - $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 952 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 953 | + $this->_route_config = $this->_page_config[$this->_req_action] ?? []; |
|
| 954 | 954 | } else { |
| 955 | 955 | // user error msg |
| 956 | 956 | $error_msg = sprintf( |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | $this->_admin_page_title |
| 962 | 962 | ); |
| 963 | 963 | // developer error msg |
| 964 | - $error_msg .= '||' . $error_msg |
|
| 964 | + $error_msg .= '||'.$error_msg |
|
| 965 | 965 | . sprintf( |
| 966 | 966 | esc_html__( |
| 967 | 967 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | throw new EE_Error($error_msg); |
| 973 | 973 | } |
| 974 | 974 | // and that a default route exists |
| 975 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 975 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 976 | 976 | // user error msg |
| 977 | 977 | $error_msg = sprintf( |
| 978 | 978 | esc_html__( |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | $this->_admin_page_title |
| 983 | 983 | ); |
| 984 | 984 | // developer error msg |
| 985 | - $error_msg .= '||' . $error_msg |
|
| 985 | + $error_msg .= '||'.$error_msg |
|
| 986 | 986 | . esc_html__( |
| 987 | 987 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 988 | 988 | 'event_espresso' |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | $this->_admin_page_title |
| 1025 | 1025 | ); |
| 1026 | 1026 | // developer error msg |
| 1027 | - $error_msg .= '||' . $error_msg |
|
| 1027 | + $error_msg .= '||'.$error_msg |
|
| 1028 | 1028 | . sprintf( |
| 1029 | 1029 | esc_html__( |
| 1030 | 1030 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | protected function _verify_nonce($nonce, $nonce_ref) |
| 1053 | 1053 | { |
| 1054 | 1054 | // verify nonce against expected value |
| 1055 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1055 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1056 | 1056 | // these are not the droids you are looking for !!! |
| 1057 | 1057 | $msg = sprintf( |
| 1058 | 1058 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | __CLASS__ |
| 1070 | 1070 | ); |
| 1071 | 1071 | } |
| 1072 | - if (! $this->request->isAjax()) { |
|
| 1072 | + if ( ! $this->request->isAjax()) { |
|
| 1073 | 1073 | wp_die($msg); |
| 1074 | 1074 | } |
| 1075 | 1075 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -1093,7 +1093,7 @@ discard block |
||
| 1093 | 1093 | */ |
| 1094 | 1094 | protected function _route_admin_request() |
| 1095 | 1095 | { |
| 1096 | - if (! $this->_is_UI_request) { |
|
| 1096 | + if ( ! $this->_is_UI_request) { |
|
| 1097 | 1097 | $this->_verify_routes(); |
| 1098 | 1098 | } |
| 1099 | 1099 | $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | $error_msg = ''; |
| 1114 | 1114 | // action right before calling route |
| 1115 | 1115 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 1116 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1116 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1117 | 1117 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 1118 | 1118 | } |
| 1119 | 1119 | // strip _wp_http_referer from the server REQUEST_URI |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | ); |
| 1126 | 1126 | // set new value in both our Request object and the super global |
| 1127 | 1127 | $this->request->setServerParam('REQUEST_URI', $request_uri, true); |
| 1128 | - if (! empty($func)) { |
|
| 1128 | + if ( ! empty($func)) { |
|
| 1129 | 1129 | if (is_array($func)) { |
| 1130 | 1130 | [$class, $method] = $func; |
| 1131 | 1131 | } elseif (strpos($func, '::') !== false) { |
@@ -1134,7 +1134,7 @@ discard block |
||
| 1134 | 1134 | $class = $this; |
| 1135 | 1135 | $method = $func; |
| 1136 | 1136 | } |
| 1137 | - if (! (is_object($class) && $class === $this)) { |
|
| 1137 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 1138 | 1138 | // send along this admin page object for access by addons. |
| 1139 | 1139 | $args['admin_page_object'] = $this; |
| 1140 | 1140 | } |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | $method |
| 1176 | 1176 | ); |
| 1177 | 1177 | } |
| 1178 | - if (! empty($error_msg)) { |
|
| 1178 | + if ( ! empty($error_msg)) { |
|
| 1179 | 1179 | throw new EE_Error($error_msg); |
| 1180 | 1180 | } |
| 1181 | 1181 | } |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | if (strpos($key, 'nonce') !== false) { |
| 1262 | 1262 | continue; |
| 1263 | 1263 | } |
| 1264 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1264 | + $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1265 | 1265 | } |
| 1266 | 1266 | } |
| 1267 | 1267 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1301,12 +1301,12 @@ discard block |
||
| 1301 | 1301 | */ |
| 1302 | 1302 | protected function _add_help_tabs() |
| 1303 | 1303 | { |
| 1304 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1305 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1304 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1305 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1306 | 1306 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1307 | 1307 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1308 | 1308 | // check that the callback given is valid |
| 1309 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1309 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1310 | 1310 | throw new EE_Error( |
| 1311 | 1311 | sprintf( |
| 1312 | 1312 | esc_html__( |
@@ -1319,18 +1319,18 @@ discard block |
||
| 1319 | 1319 | ); |
| 1320 | 1320 | } |
| 1321 | 1321 | $content = apply_filters( |
| 1322 | - 'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar', |
|
| 1322 | + 'FHEE__'.$this->class_name.'__add_help_tabs__help_sidebar', |
|
| 1323 | 1323 | $this->{$config['help_sidebar']}() |
| 1324 | 1324 | ); |
| 1325 | 1325 | $this->_current_screen->set_help_sidebar($content); |
| 1326 | 1326 | } |
| 1327 | - if (! isset($config['help_tabs'])) { |
|
| 1327 | + if ( ! isset($config['help_tabs'])) { |
|
| 1328 | 1328 | return; |
| 1329 | 1329 | } //no help tabs for this route |
| 1330 | 1330 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1331 | 1331 | // we're here so there ARE help tabs! |
| 1332 | 1332 | // make sure we've got what we need |
| 1333 | - if (! isset($cfg['title'])) { |
|
| 1333 | + if ( ! isset($cfg['title'])) { |
|
| 1334 | 1334 | throw new EE_Error( |
| 1335 | 1335 | esc_html__( |
| 1336 | 1336 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1338,7 +1338,7 @@ discard block |
||
| 1338 | 1338 | ) |
| 1339 | 1339 | ); |
| 1340 | 1340 | } |
| 1341 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1341 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1342 | 1342 | throw new EE_Error( |
| 1343 | 1343 | esc_html__( |
| 1344 | 1344 | 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
@@ -1347,11 +1347,11 @@ discard block |
||
| 1347 | 1347 | ); |
| 1348 | 1348 | } |
| 1349 | 1349 | // first priority goes to content. |
| 1350 | - if (! empty($cfg['content'])) { |
|
| 1350 | + if ( ! empty($cfg['content'])) { |
|
| 1351 | 1351 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1352 | 1352 | // second priority goes to filename |
| 1353 | - } elseif (! empty($cfg['filename'])) { |
|
| 1354 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1353 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1354 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1355 | 1355 | // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
| 1356 | 1356 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1357 | 1357 | . basename($this->_get_dir()) |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | . $cfg['filename'] |
| 1360 | 1360 | . '.help_tab.php' : $file_path; |
| 1361 | 1361 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1362 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1362 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1363 | 1363 | EE_Error::add_error( |
| 1364 | 1364 | sprintf( |
| 1365 | 1365 | esc_html__( |
@@ -1407,7 +1407,7 @@ discard block |
||
| 1407 | 1407 | return; |
| 1408 | 1408 | } |
| 1409 | 1409 | // setup config array for help tab method |
| 1410 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1410 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1411 | 1411 | $_ht = [ |
| 1412 | 1412 | 'id' => $id, |
| 1413 | 1413 | 'title' => $cfg['title'], |
@@ -1433,8 +1433,8 @@ discard block |
||
| 1433 | 1433 | $qtips = (array) $this->_route_config['qtips']; |
| 1434 | 1434 | // load qtip loader |
| 1435 | 1435 | $path = [ |
| 1436 | - $this->_get_dir() . '/qtips/', |
|
| 1437 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1436 | + $this->_get_dir().'/qtips/', |
|
| 1437 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1438 | 1438 | ]; |
| 1439 | 1439 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1440 | 1440 | } |
@@ -1456,7 +1456,7 @@ discard block |
||
| 1456 | 1456 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1457 | 1457 | $i = 0; |
| 1458 | 1458 | foreach ($this->_page_config as $slug => $config) { |
| 1459 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1459 | + if ( ! is_array($config) || empty($config['nav'])) { |
|
| 1460 | 1460 | continue; |
| 1461 | 1461 | } |
| 1462 | 1462 | // no nav tab for this config |
@@ -1465,12 +1465,12 @@ discard block |
||
| 1465 | 1465 | // nav tab is only to appear when route requested. |
| 1466 | 1466 | continue; |
| 1467 | 1467 | } |
| 1468 | - if (! $this->check_user_access($slug, true)) { |
|
| 1468 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1469 | 1469 | // no nav tab because current user does not have access. |
| 1470 | 1470 | continue; |
| 1471 | 1471 | } |
| 1472 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1473 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1472 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1473 | + $this->_nav_tabs[$slug] = [ |
|
| 1474 | 1474 | 'url' => isset($config['nav']['url']) |
| 1475 | 1475 | ? $config['nav']['url'] |
| 1476 | 1476 | : EE_Admin_Page::add_query_args_and_nonce( |
@@ -1482,14 +1482,14 @@ discard block |
||
| 1482 | 1482 | : ucwords( |
| 1483 | 1483 | str_replace('_', ' ', $slug) |
| 1484 | 1484 | ), |
| 1485 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1485 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1486 | 1486 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1487 | 1487 | ]; |
| 1488 | 1488 | $i++; |
| 1489 | 1489 | } |
| 1490 | 1490 | // if $this->_nav_tabs is empty then lets set the default |
| 1491 | 1491 | if (empty($this->_nav_tabs)) { |
| 1492 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1492 | + $this->_nav_tabs[$this->_default_nav_tab_name] = [ |
|
| 1493 | 1493 | 'url' => $this->_admin_base_url, |
| 1494 | 1494 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1495 | 1495 | 'css_class' => 'nav-tab-active', |
@@ -1514,10 +1514,10 @@ discard block |
||
| 1514 | 1514 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1515 | 1515 | if (is_array($text)) { |
| 1516 | 1516 | foreach ($text as $sublabel => $subtext) { |
| 1517 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1517 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1518 | 1518 | } |
| 1519 | 1519 | } else { |
| 1520 | - $this->_labels[ $label ] = $text; |
|
| 1520 | + $this->_labels[$label] = $text; |
|
| 1521 | 1521 | } |
| 1522 | 1522 | } |
| 1523 | 1523 | } |
@@ -1539,10 +1539,10 @@ discard block |
||
| 1539 | 1539 | { |
| 1540 | 1540 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1541 | 1541 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
| 1542 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1543 | - && is_array($this->_page_routes[ $route_to_check ]) |
|
| 1544 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1545 | - ? $this->_page_routes[ $route_to_check ]['capability'] |
|
| 1542 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1543 | + && is_array($this->_page_routes[$route_to_check]) |
|
| 1544 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1545 | + ? $this->_page_routes[$route_to_check]['capability'] |
|
| 1546 | 1546 | : null; |
| 1547 | 1547 | |
| 1548 | 1548 | if (empty($capability) && empty($route_to_check)) { |
@@ -1596,14 +1596,14 @@ discard block |
||
| 1596 | 1596 | string $priority = 'default', |
| 1597 | 1597 | ?array $callback_args = null |
| 1598 | 1598 | ) { |
| 1599 | - if (! is_callable($callback)) { |
|
| 1599 | + if ( ! is_callable($callback)) { |
|
| 1600 | 1600 | return; |
| 1601 | 1601 | } |
| 1602 | 1602 | |
| 1603 | 1603 | add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
| 1604 | 1604 | add_filter( |
| 1605 | 1605 | "postbox_classes_{$this->_wp_page_slug}_{$box_id}", |
| 1606 | - function ($classes) { |
|
| 1606 | + function($classes) { |
|
| 1607 | 1607 | array_push($classes, 'ee-admin-container'); |
| 1608 | 1608 | return $classes; |
| 1609 | 1609 | } |
@@ -1697,7 +1697,7 @@ discard block |
||
| 1697 | 1697 | '; |
| 1698 | 1698 | |
| 1699 | 1699 | // current set timezone for timezone js |
| 1700 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1700 | + echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>'; |
|
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | |
@@ -1731,7 +1731,7 @@ discard block |
||
| 1731 | 1731 | // loop through the array and setup content |
| 1732 | 1732 | foreach ($help_array as $trigger => $help) { |
| 1733 | 1733 | // make sure the array is setup properly |
| 1734 | - if (! isset($help['title'], $help['content'])) { |
|
| 1734 | + if ( ! isset($help['title'], $help['content'])) { |
|
| 1735 | 1735 | throw new EE_Error( |
| 1736 | 1736 | esc_html__( |
| 1737 | 1737 | 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
@@ -1745,8 +1745,8 @@ discard block |
||
| 1745 | 1745 | 'help_popup_title' => $help['title'], |
| 1746 | 1746 | 'help_popup_content' => $help['content'], |
| 1747 | 1747 | ]; |
| 1748 | - $content .= EEH_Template::display_template( |
|
| 1749 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1748 | + $content .= EEH_Template::display_template( |
|
| 1749 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1750 | 1750 | $template_args, |
| 1751 | 1751 | true |
| 1752 | 1752 | ); |
@@ -1768,15 +1768,15 @@ discard block |
||
| 1768 | 1768 | private function _get_help_content() |
| 1769 | 1769 | { |
| 1770 | 1770 | // what is the method we're looking for? |
| 1771 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1771 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1772 | 1772 | // if method doesn't exist let's get out. |
| 1773 | - if (! method_exists($this, $method_name)) { |
|
| 1773 | + if ( ! method_exists($this, $method_name)) { |
|
| 1774 | 1774 | return []; |
| 1775 | 1775 | } |
| 1776 | 1776 | // k we're good to go let's retrieve the help array |
| 1777 | 1777 | $help_array = $this->{$method_name}(); |
| 1778 | 1778 | // make sure we've got an array! |
| 1779 | - if (! is_array($help_array)) { |
|
| 1779 | + if ( ! is_array($help_array)) { |
|
| 1780 | 1780 | throw new EE_Error( |
| 1781 | 1781 | esc_html__( |
| 1782 | 1782 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1808,8 +1808,8 @@ discard block |
||
| 1808 | 1808 | // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
| 1809 | 1809 | $help_array = $this->_get_help_content(); |
| 1810 | 1810 | $help_content = ''; |
| 1811 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1812 | - $help_array[ $trigger_id ] = [ |
|
| 1811 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1812 | + $help_array[$trigger_id] = [ |
|
| 1813 | 1813 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1814 | 1814 | 'content' => esc_html__( |
| 1815 | 1815 | 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
@@ -1904,7 +1904,7 @@ discard block |
||
| 1904 | 1904 | |
| 1905 | 1905 | add_filter( |
| 1906 | 1906 | 'admin_body_class', |
| 1907 | - function ($classes) { |
|
| 1907 | + function($classes) { |
|
| 1908 | 1908 | if (strpos($classes, 'espresso-admin') === false) { |
| 1909 | 1909 | $classes .= ' espresso-admin'; |
| 1910 | 1910 | } |
@@ -1995,12 +1995,12 @@ discard block |
||
| 1995 | 1995 | protected function _set_list_table() |
| 1996 | 1996 | { |
| 1997 | 1997 | // first is this a list_table view? |
| 1998 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1998 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 1999 | 1999 | return; |
| 2000 | 2000 | } //not a list_table view so get out. |
| 2001 | 2001 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 2002 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2003 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2002 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 2003 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2004 | 2004 | // user error msg |
| 2005 | 2005 | $error_msg = esc_html__( |
| 2006 | 2006 | 'An error occurred. The requested list table views could not be found.', |
@@ -2020,10 +2020,10 @@ discard block |
||
| 2020 | 2020 | } |
| 2021 | 2021 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 2022 | 2022 | $this->_views = apply_filters( |
| 2023 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2023 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 2024 | 2024 | $this->_views |
| 2025 | 2025 | ); |
| 2026 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2026 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 2027 | 2027 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 2028 | 2028 | $this->_set_list_table_view(); |
| 2029 | 2029 | $this->_set_list_table_object(); |
@@ -2058,7 +2058,7 @@ discard block |
||
| 2058 | 2058 | protected function _set_list_table_object() |
| 2059 | 2059 | { |
| 2060 | 2060 | if (isset($this->_route_config['list_table'])) { |
| 2061 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2061 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 2062 | 2062 | throw new EE_Error( |
| 2063 | 2063 | sprintf( |
| 2064 | 2064 | esc_html__( |
@@ -2096,17 +2096,17 @@ discard block |
||
| 2096 | 2096 | foreach ($this->_views as $key => $view) { |
| 2097 | 2097 | $query_args = []; |
| 2098 | 2098 | // check for current view |
| 2099 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2099 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2100 | 2100 | $query_args['action'] = $this->_req_action; |
| 2101 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2101 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2102 | 2102 | $query_args['status'] = $view['slug']; |
| 2103 | 2103 | // merge any other arguments sent in. |
| 2104 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2105 | - foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2104 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2105 | + foreach ($extra_query_args[$view['slug']] as $extra_query_arg) { |
|
| 2106 | 2106 | $query_args[] = $extra_query_arg; |
| 2107 | 2107 | } |
| 2108 | 2108 | } |
| 2109 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2109 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2110 | 2110 | } |
| 2111 | 2111 | return $this->_views; |
| 2112 | 2112 | } |
@@ -2137,14 +2137,14 @@ discard block |
||
| 2137 | 2137 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2138 | 2138 | foreach ($values as $value) { |
| 2139 | 2139 | if ($value < $max_entries) { |
| 2140 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2140 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2141 | 2141 | $entries_per_page_dropdown .= ' |
| 2142 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2142 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2143 | 2143 | } |
| 2144 | 2144 | } |
| 2145 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2145 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2146 | 2146 | $entries_per_page_dropdown .= ' |
| 2147 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2147 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2148 | 2148 | $entries_per_page_dropdown .= ' |
| 2149 | 2149 | </select> |
| 2150 | 2150 | entries |
@@ -2168,7 +2168,7 @@ discard block |
||
| 2168 | 2168 | empty($this->_search_btn_label) ? $this->page_label |
| 2169 | 2169 | : $this->_search_btn_label |
| 2170 | 2170 | ); |
| 2171 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2171 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2172 | 2172 | } |
| 2173 | 2173 | |
| 2174 | 2174 | |
@@ -2256,7 +2256,7 @@ discard block |
||
| 2256 | 2256 | $total_columns = ! empty($screen_columns) |
| 2257 | 2257 | ? $screen_columns |
| 2258 | 2258 | : $this->_route_config['columns'][1]; |
| 2259 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2259 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2260 | 2260 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2261 | 2261 | $this->_template_args['screen'] = $this->_current_screen; |
| 2262 | 2262 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2302,7 +2302,7 @@ discard block |
||
| 2302 | 2302 | */ |
| 2303 | 2303 | protected function _espresso_ratings_request() |
| 2304 | 2304 | { |
| 2305 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2305 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2306 | 2306 | return; |
| 2307 | 2307 | } |
| 2308 | 2308 | $ratings_box_title = apply_filters( |
@@ -2329,28 +2329,28 @@ discard block |
||
| 2329 | 2329 | */ |
| 2330 | 2330 | public function espresso_ratings_request() |
| 2331 | 2331 | { |
| 2332 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2332 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php'); |
|
| 2333 | 2333 | } |
| 2334 | 2334 | |
| 2335 | 2335 | |
| 2336 | 2336 | public static function cached_rss_display($rss_id, $url) |
| 2337 | 2337 | { |
| 2338 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2338 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2339 | 2339 | . esc_html__('Loading…', 'event_espresso') |
| 2340 | 2340 | . '</p><p class="hide-if-js">' |
| 2341 | 2341 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2342 | 2342 | . '</p>'; |
| 2343 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2344 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2345 | - $post = '</div>' . "\n"; |
|
| 2346 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2343 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2344 | + $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>'; |
|
| 2345 | + $post = '</div>'."\n"; |
|
| 2346 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2347 | 2347 | $output = get_transient($cache_key); |
| 2348 | 2348 | if ($output !== false) { |
| 2349 | - echo $pre . $output . $post; // already escaped |
|
| 2349 | + echo $pre.$output.$post; // already escaped |
|
| 2350 | 2350 | return true; |
| 2351 | 2351 | } |
| 2352 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2353 | - echo $pre . $loading . $post; // already escaped |
|
| 2352 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2353 | + echo $pre.$loading.$post; // already escaped |
|
| 2354 | 2354 | return false; |
| 2355 | 2355 | } |
| 2356 | 2356 | ob_start(); |
@@ -2417,19 +2417,19 @@ discard block |
||
| 2417 | 2417 | public function espresso_sponsors_post_box() |
| 2418 | 2418 | { |
| 2419 | 2419 | EEH_Template::display_template( |
| 2420 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2420 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2421 | 2421 | ); |
| 2422 | 2422 | } |
| 2423 | 2423 | |
| 2424 | 2424 | |
| 2425 | 2425 | private function _publish_post_box() |
| 2426 | 2426 | { |
| 2427 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2427 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2428 | 2428 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2429 | 2429 | // then we'll use that for the metabox label. |
| 2430 | 2430 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2431 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2432 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2431 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2432 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2433 | 2433 | : $this->_labels['publishbox']; |
| 2434 | 2434 | } else { |
| 2435 | 2435 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2458,7 +2458,7 @@ discard block |
||
| 2458 | 2458 | ? $this->_template_args['publish_box_extra_content'] |
| 2459 | 2459 | : ''; |
| 2460 | 2460 | echo EEH_Template::display_template( |
| 2461 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2461 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2462 | 2462 | $this->_template_args, |
| 2463 | 2463 | true |
| 2464 | 2464 | ); |
@@ -2546,18 +2546,18 @@ discard block |
||
| 2546 | 2546 | ); |
| 2547 | 2547 | } |
| 2548 | 2548 | $this->_template_args['publish_delete_link'] = $delete_link; |
| 2549 | - if (! empty($name) && ! empty($id)) { |
|
| 2550 | - $hidden_field_arr[ $name ] = [ |
|
| 2549 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2550 | + $hidden_field_arr[$name] = [ |
|
| 2551 | 2551 | 'type' => 'hidden', |
| 2552 | 2552 | 'value' => $id, |
| 2553 | 2553 | ]; |
| 2554 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2554 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2555 | 2555 | } else { |
| 2556 | 2556 | $hf = ''; |
| 2557 | 2557 | } |
| 2558 | 2558 | // add hidden field |
| 2559 | 2559 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
| 2560 | - ? $hf[ $name ]['field'] |
|
| 2560 | + ? $hf[$name]['field'] |
|
| 2561 | 2561 | : $hf; |
| 2562 | 2562 | } |
| 2563 | 2563 | |
@@ -2659,7 +2659,7 @@ discard block |
||
| 2659 | 2659 | } |
| 2660 | 2660 | // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
| 2661 | 2661 | $call_back_func = $create_func |
| 2662 | - ? static function ($post, $metabox) { |
|
| 2662 | + ? static function($post, $metabox) { |
|
| 2663 | 2663 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2664 | 2664 | echo EEH_Template::display_template( |
| 2665 | 2665 | $metabox['args']['template_path'], |
@@ -2669,7 +2669,7 @@ discard block |
||
| 2669 | 2669 | } |
| 2670 | 2670 | : $callback; |
| 2671 | 2671 | $this->addMetaBox( |
| 2672 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2672 | + str_replace('_', '-', $action).'-mbox', |
|
| 2673 | 2673 | $title, |
| 2674 | 2674 | $call_back_func, |
| 2675 | 2675 | $this->_wp_page_slug, |
@@ -2786,13 +2786,13 @@ discard block |
||
| 2786 | 2786 | 'event-espresso_page_espresso_', |
| 2787 | 2787 | '', |
| 2788 | 2788 | $this->_wp_page_slug |
| 2789 | - ) . ' ' . $this->_req_action . '-route'; |
|
| 2789 | + ).' '.$this->_req_action.'-route'; |
|
| 2790 | 2790 | |
| 2791 | 2791 | $template_path = $sidebar |
| 2792 | 2792 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2793 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2793 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2794 | 2794 | if ($this->request->isAjax()) { |
| 2795 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2795 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2796 | 2796 | } |
| 2797 | 2797 | $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
| 2798 | 2798 | |
@@ -2826,11 +2826,11 @@ discard block |
||
| 2826 | 2826 | public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
| 2827 | 2827 | { |
| 2828 | 2828 | // let's generate a default preview action button if there isn't one already present. |
| 2829 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2829 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2830 | 2830 | 'Upgrade to Event Espresso 4 Right Now', |
| 2831 | 2831 | 'event_espresso' |
| 2832 | 2832 | ); |
| 2833 | - $buy_now_url = add_query_arg( |
|
| 2833 | + $buy_now_url = add_query_arg( |
|
| 2834 | 2834 | [ |
| 2835 | 2835 | 'ee_ver' => 'ee4', |
| 2836 | 2836 | 'utm_source' => 'ee4_plugin_admin', |
@@ -2850,8 +2850,8 @@ discard block |
||
| 2850 | 2850 | true |
| 2851 | 2851 | ) |
| 2852 | 2852 | : $this->_template_args['preview_action_button']; |
| 2853 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2854 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2853 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2854 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2855 | 2855 | $this->_template_args, |
| 2856 | 2856 | true |
| 2857 | 2857 | ); |
@@ -2909,7 +2909,7 @@ discard block |
||
| 2909 | 2909 | // setup search attributes |
| 2910 | 2910 | $this->_set_search_attributes(); |
| 2911 | 2911 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2912 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2912 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2913 | 2913 | $this->_template_args['table_url'] = $this->request->isAjax() |
| 2914 | 2914 | ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
| 2915 | 2915 | : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
@@ -2917,10 +2917,10 @@ discard block |
||
| 2917 | 2917 | $this->_template_args['current_route'] = $this->_req_action; |
| 2918 | 2918 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 2919 | 2919 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2920 | - if (! empty($ajax_sorting_callback)) { |
|
| 2920 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2921 | 2921 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2922 | - $ajax_sorting_callback . '_nonce', |
|
| 2923 | - $ajax_sorting_callback . '_nonce', |
|
| 2922 | + $ajax_sorting_callback.'_nonce', |
|
| 2923 | + $ajax_sorting_callback.'_nonce', |
|
| 2924 | 2924 | false, |
| 2925 | 2925 | false |
| 2926 | 2926 | ); |
@@ -2937,18 +2937,18 @@ discard block |
||
| 2937 | 2937 | |
| 2938 | 2938 | $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? ''; |
| 2939 | 2939 | |
| 2940 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2940 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2941 | 2941 | $hidden_form_fields .= ' |
| 2942 | - <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2942 | + <input type="hidden" name="' . $nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">'; |
|
| 2943 | 2943 | |
| 2944 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2944 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2945 | 2945 | // display message about search results? |
| 2946 | 2946 | $search = $this->request->getRequestParam('s'); |
| 2947 | 2947 | $this->_template_args['before_list_table'] .= ! empty($search) |
| 2948 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2948 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 2949 | 2949 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 2950 | 2950 | trim($search, '%') |
| 2951 | - ) . '</p>' |
|
| 2951 | + ).'</p>' |
|
| 2952 | 2952 | : ''; |
| 2953 | 2953 | // filter before_list_table template arg |
| 2954 | 2954 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -2982,7 +2982,7 @@ discard block |
||
| 2982 | 2982 | // convert to array and filter again |
| 2983 | 2983 | // arrays are easier to inject new items in a specific location, |
| 2984 | 2984 | // but would not be backwards compatible, so we have to add a new filter |
| 2985 | - $this->_template_args['after_list_table'] = implode( |
|
| 2985 | + $this->_template_args['after_list_table'] = implode( |
|
| 2986 | 2986 | " \n", |
| 2987 | 2987 | (array) apply_filters( |
| 2988 | 2988 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
@@ -3037,7 +3037,7 @@ discard block |
||
| 3037 | 3037 | $this->page_slug |
| 3038 | 3038 | ); |
| 3039 | 3039 | return EEH_Template::display_template( |
| 3040 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3040 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 3041 | 3041 | $this->_template_args, |
| 3042 | 3042 | true |
| 3043 | 3043 | ); |
@@ -3153,16 +3153,16 @@ discard block |
||
| 3153 | 3153 | $this->_template_args['before_admin_page_content'] ?? '' |
| 3154 | 3154 | ); |
| 3155 | 3155 | |
| 3156 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3156 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3157 | 3157 | "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
| 3158 | 3158 | $this->_template_args['after_admin_page_content'] ?? '' |
| 3159 | 3159 | ); |
| 3160 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3160 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3161 | 3161 | |
| 3162 | 3162 | if ($this->request->isAjax()) { |
| 3163 | 3163 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 3164 | 3164 | // $template_path, |
| 3165 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3165 | + EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php', |
|
| 3166 | 3166 | $this->_template_args, |
| 3167 | 3167 | true |
| 3168 | 3168 | ); |
@@ -3171,7 +3171,7 @@ discard block |
||
| 3171 | 3171 | // load settings page wrapper template |
| 3172 | 3172 | $template_path = $about |
| 3173 | 3173 | ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
| 3174 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3174 | + : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php'; |
|
| 3175 | 3175 | |
| 3176 | 3176 | EEH_Template::display_template($template_path, $this->_template_args); |
| 3177 | 3177 | } |
@@ -3255,12 +3255,12 @@ discard block |
||
| 3255 | 3255 | $default_names = ['save', 'save_and_close']; |
| 3256 | 3256 | $buttons = ''; |
| 3257 | 3257 | foreach ($button_text as $key => $button) { |
| 3258 | - $ref = $default_names[ $key ]; |
|
| 3259 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3260 | - $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" ' |
|
| 3261 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3262 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3263 | - if (! $both) { |
|
| 3258 | + $ref = $default_names[$key]; |
|
| 3259 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 3260 | + $buttons .= '<input type="submit" class="button button--primary '.$ref.'" ' |
|
| 3261 | + . 'value="'.$button.'" name="'.$name.'" ' |
|
| 3262 | + . 'id="'.$this->_current_view.'_'.$ref.'" />'; |
|
| 3263 | + if ( ! $both) { |
|
| 3264 | 3264 | break; |
| 3265 | 3265 | } |
| 3266 | 3266 | } |
@@ -3300,13 +3300,13 @@ discard block |
||
| 3300 | 3300 | 'An error occurred. No action was set for this page\'s form.', |
| 3301 | 3301 | 'event_espresso' |
| 3302 | 3302 | ); |
| 3303 | - $dev_msg = $user_msg . "\n" |
|
| 3303 | + $dev_msg = $user_msg."\n" |
|
| 3304 | 3304 | . sprintf( |
| 3305 | 3305 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3306 | 3306 | __FUNCTION__, |
| 3307 | 3307 | __CLASS__ |
| 3308 | 3308 | ); |
| 3309 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3309 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3310 | 3310 | } |
| 3311 | 3311 | // open form |
| 3312 | 3312 | $action = $this->_admin_base_url; |
@@ -3314,9 +3314,9 @@ discard block |
||
| 3314 | 3314 | <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' > |
| 3315 | 3315 | "; |
| 3316 | 3316 | // add nonce |
| 3317 | - $nonce = |
|
| 3318 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3319 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3317 | + $nonce = |
|
| 3318 | + wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3319 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3320 | 3320 | // add REQUIRED form action |
| 3321 | 3321 | $hidden_fields = [ |
| 3322 | 3322 | 'action' => ['type' => 'hidden', 'value' => $route], |
@@ -3329,7 +3329,7 @@ discard block |
||
| 3329 | 3329 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3330 | 3330 | // add fields to form |
| 3331 | 3331 | foreach ((array) $form_fields as $form_field) { |
| 3332 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3332 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3333 | 3333 | } |
| 3334 | 3334 | // close form |
| 3335 | 3335 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3412,12 +3412,12 @@ discard block |
||
| 3412 | 3412 | bool $override_overwrite = false |
| 3413 | 3413 | ) { |
| 3414 | 3414 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 3415 | - $notices = EE_Error::get_notices(false); |
|
| 3415 | + $notices = EE_Error::get_notices(false); |
|
| 3416 | 3416 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3417 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3417 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3418 | 3418 | EE_Error::overwrite_success(); |
| 3419 | 3419 | } |
| 3420 | - if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3420 | + if ( ! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3421 | 3421 | // how many records affected ? more than one record ? or just one ? |
| 3422 | 3422 | EE_Error::add_success( |
| 3423 | 3423 | sprintf( |
@@ -3438,7 +3438,7 @@ discard block |
||
| 3438 | 3438 | ); |
| 3439 | 3439 | } |
| 3440 | 3440 | // check that $query_args isn't something crazy |
| 3441 | - if (! is_array($query_args)) { |
|
| 3441 | + if ( ! is_array($query_args)) { |
|
| 3442 | 3442 | $query_args = []; |
| 3443 | 3443 | } |
| 3444 | 3444 | /** |
@@ -3470,7 +3470,7 @@ discard block |
||
| 3470 | 3470 | $redirect_url = admin_url('admin.php'); |
| 3471 | 3471 | } |
| 3472 | 3472 | // merge any default query_args set in _default_route_query_args property |
| 3473 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3473 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3474 | 3474 | $args_to_merge = []; |
| 3475 | 3475 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3476 | 3476 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3482,15 +3482,15 @@ discard block |
||
| 3482 | 3482 | } |
| 3483 | 3483 | // finally we will override any arguments in the referer with |
| 3484 | 3484 | // what might be set on the _default_route_query_args array. |
| 3485 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3486 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3485 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3486 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3487 | 3487 | } else { |
| 3488 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3488 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3489 | 3489 | } |
| 3490 | 3490 | } |
| 3491 | 3491 | continue; |
| 3492 | 3492 | } |
| 3493 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3493 | + $args_to_merge[$query_param] = $query_value; |
|
| 3494 | 3494 | } |
| 3495 | 3495 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3496 | 3496 | // redirect. |
@@ -3502,19 +3502,19 @@ discard block |
||
| 3502 | 3502 | if (isset($query_args['action'])) { |
| 3503 | 3503 | // manually generate wp_nonce and merge that with the query vars |
| 3504 | 3504 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3505 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3505 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3506 | 3506 | } |
| 3507 | 3507 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3508 | 3508 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3509 | - do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args); |
|
| 3509 | + do_action('AHEE_redirect_'.$this->class_name.$this->_req_action, $query_args); |
|
| 3510 | 3510 | $redirect_url = apply_filters( |
| 3511 | - 'FHEE_redirect_' . $this->class_name . $this->_req_action, |
|
| 3511 | + 'FHEE_redirect_'.$this->class_name.$this->_req_action, |
|
| 3512 | 3512 | EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
| 3513 | 3513 | $query_args |
| 3514 | 3514 | ); |
| 3515 | 3515 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 3516 | 3516 | if ($this->request->isAjax()) { |
| 3517 | - $default_data = [ |
|
| 3517 | + $default_data = [ |
|
| 3518 | 3518 | 'close' => true, |
| 3519 | 3519 | 'redirect_url' => $redirect_url, |
| 3520 | 3520 | 'where' => 'main', |
@@ -3564,7 +3564,7 @@ discard block |
||
| 3564 | 3564 | } |
| 3565 | 3565 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3566 | 3566 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3567 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3567 | + if ( ! $this->request->isAjax() || $sticky_notices) { |
|
| 3568 | 3568 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3569 | 3569 | $this->_add_transient( |
| 3570 | 3570 | $route, |
@@ -3604,7 +3604,7 @@ discard block |
||
| 3604 | 3604 | $exclude_nonce = false |
| 3605 | 3605 | ) { |
| 3606 | 3606 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3607 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3607 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3608 | 3608 | throw new EE_Error( |
| 3609 | 3609 | sprintf( |
| 3610 | 3610 | esc_html__( |
@@ -3615,7 +3615,7 @@ discard block |
||
| 3615 | 3615 | ) |
| 3616 | 3616 | ); |
| 3617 | 3617 | } |
| 3618 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3618 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3619 | 3619 | throw new EE_Error( |
| 3620 | 3620 | sprintf( |
| 3621 | 3621 | esc_html__( |
@@ -3628,7 +3628,7 @@ discard block |
||
| 3628 | 3628 | } |
| 3629 | 3629 | // finally check user access for this button. |
| 3630 | 3630 | $has_access = $this->check_user_access($action, true); |
| 3631 | - if (! $has_access) { |
|
| 3631 | + if ( ! $has_access) { |
|
| 3632 | 3632 | return ''; |
| 3633 | 3633 | } |
| 3634 | 3634 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3636,11 +3636,11 @@ discard block |
||
| 3636 | 3636 | 'action' => $action, |
| 3637 | 3637 | ]; |
| 3638 | 3638 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3639 | - if (! empty($extra_request)) { |
|
| 3639 | + if ( ! empty($extra_request)) { |
|
| 3640 | 3640 | $query_args = array_merge($extra_request, $query_args); |
| 3641 | 3641 | } |
| 3642 | 3642 | $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3643 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3643 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3644 | 3644 | } |
| 3645 | 3645 | |
| 3646 | 3646 | |
@@ -3666,7 +3666,7 @@ discard block |
||
| 3666 | 3666 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3667 | 3667 | 20 |
| 3668 | 3668 | ), |
| 3669 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3669 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3670 | 3670 | ]; |
| 3671 | 3671 | // ONLY add the screen option if the user has access to it. |
| 3672 | 3672 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3687,18 +3687,18 @@ discard block |
||
| 3687 | 3687 | { |
| 3688 | 3688 | if ($this->request->requestParamIsSet('wp_screen_options')) { |
| 3689 | 3689 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3690 | - if (! $user = wp_get_current_user()) { |
|
| 3690 | + if ( ! $user = wp_get_current_user()) { |
|
| 3691 | 3691 | return; |
| 3692 | 3692 | } |
| 3693 | 3693 | $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
| 3694 | - if (! $option) { |
|
| 3694 | + if ( ! $option) { |
|
| 3695 | 3695 | return; |
| 3696 | 3696 | } |
| 3697 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3697 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3698 | 3698 | $map_option = $option; |
| 3699 | 3699 | $option = str_replace('-', '_', $option); |
| 3700 | 3700 | switch ($map_option) { |
| 3701 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3701 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3702 | 3702 | $max_value = apply_filters( |
| 3703 | 3703 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
| 3704 | 3704 | 999, |
@@ -3755,13 +3755,13 @@ discard block |
||
| 3755 | 3755 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3756 | 3756 | { |
| 3757 | 3757 | $user_id = get_current_user_id(); |
| 3758 | - if (! $skip_route_verify) { |
|
| 3758 | + if ( ! $skip_route_verify) { |
|
| 3759 | 3759 | $this->_verify_route($route); |
| 3760 | 3760 | } |
| 3761 | 3761 | // now let's set the string for what kind of transient we're setting |
| 3762 | 3762 | $transient = $notices |
| 3763 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3764 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3763 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3764 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3765 | 3765 | $data = $notices ? ['notices' => $data] : $data; |
| 3766 | 3766 | // is there already a transient for this route? If there is then let's ADD to that transient |
| 3767 | 3767 | $existing = is_multisite() && is_network_admin() |
@@ -3790,8 +3790,8 @@ discard block |
||
| 3790 | 3790 | $user_id = get_current_user_id(); |
| 3791 | 3791 | $route = ! $route ? $this->_req_action : $route; |
| 3792 | 3792 | $transient = $notices |
| 3793 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3794 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3793 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3794 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3795 | 3795 | $data = is_multisite() && is_network_admin() |
| 3796 | 3796 | ? get_site_transient($transient) |
| 3797 | 3797 | : get_transient($transient); |
@@ -4027,7 +4027,7 @@ discard block |
||
| 4027 | 4027 | */ |
| 4028 | 4028 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 4029 | 4029 | { |
| 4030 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4030 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4031 | 4031 | } |
| 4032 | 4032 | |
| 4033 | 4033 | |
@@ -4040,7 +4040,7 @@ discard block |
||
| 4040 | 4040 | */ |
| 4041 | 4041 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 4042 | 4042 | { |
| 4043 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4043 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4044 | 4044 | } |
| 4045 | 4045 | |
| 4046 | 4046 | |
@@ -4188,7 +4188,7 @@ discard block |
||
| 4188 | 4188 | ?callable $callback = null |
| 4189 | 4189 | ): bool { |
| 4190 | 4190 | $entity_ID = absint($entity_ID); |
| 4191 | - if (! $entity_ID) { |
|
| 4191 | + if ( ! $entity_ID) { |
|
| 4192 | 4192 | $this->trashRestoreDeleteError($action, $entity_model); |
| 4193 | 4193 | } |
| 4194 | 4194 | $result = 0; |
@@ -4234,7 +4234,7 @@ discard block |
||
| 4234 | 4234 | ) |
| 4235 | 4235 | ); |
| 4236 | 4236 | } |
| 4237 | - if (! $entity_model->has_field($delete_column)) { |
|
| 4237 | + if ( ! $entity_model->has_field($delete_column)) { |
|
| 4238 | 4238 | throw new DomainException( |
| 4239 | 4239 | sprintf( |
| 4240 | 4240 | esc_html__( |
@@ -2,34 +2,34 @@ |
||
| 2 | 2 | |
| 3 | 3 | class EE_Switch_Input extends EE_Form_Input_With_Options_Base |
| 4 | 4 | { |
| 5 | - public const OPTION_ON = 'ON'; |
|
| 5 | + public const OPTION_ON = 'ON'; |
|
| 6 | 6 | |
| 7 | - public const OPTION_OFF = 'OFF'; |
|
| 7 | + public const OPTION_OFF = 'OFF'; |
|
| 8 | 8 | |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @param array $input_settings |
|
| 12 | - * @param array $answer_options |
|
| 13 | - */ |
|
| 14 | - public function __construct($input_settings = [], array $answer_options = []) |
|
| 15 | - { |
|
| 16 | - $this->_set_display_strategy(new EE_Switch_Display_Strategy()); |
|
| 17 | - $this->_add_validation_strategy( |
|
| 18 | - new EE_Many_Valued_Validation_Strategy( |
|
| 19 | - [ |
|
| 20 | - new EE_Enum_Validation_Strategy( |
|
| 21 | - $input_settings['validation_error_message'] ?? null |
|
| 22 | - ), |
|
| 23 | - ] |
|
| 24 | - ) |
|
| 25 | - ); |
|
| 26 | - if (! is_array($answer_options) || empty($answer_options)) { |
|
| 27 | - $answer_options = [ |
|
| 28 | - EE_Switch_Input::OPTION_ON => esc_html__('enabled', 'event_espresso'), |
|
| 29 | - EE_Switch_Input::OPTION_OFF => esc_html__('disabled', 'event_espresso'), |
|
| 30 | - ]; |
|
| 31 | - } |
|
| 32 | - $this->_multiple_selections = false; |
|
| 33 | - parent::__construct($answer_options, $input_settings); |
|
| 34 | - } |
|
| 10 | + /** |
|
| 11 | + * @param array $input_settings |
|
| 12 | + * @param array $answer_options |
|
| 13 | + */ |
|
| 14 | + public function __construct($input_settings = [], array $answer_options = []) |
|
| 15 | + { |
|
| 16 | + $this->_set_display_strategy(new EE_Switch_Display_Strategy()); |
|
| 17 | + $this->_add_validation_strategy( |
|
| 18 | + new EE_Many_Valued_Validation_Strategy( |
|
| 19 | + [ |
|
| 20 | + new EE_Enum_Validation_Strategy( |
|
| 21 | + $input_settings['validation_error_message'] ?? null |
|
| 22 | + ), |
|
| 23 | + ] |
|
| 24 | + ) |
|
| 25 | + ); |
|
| 26 | + if (! is_array($answer_options) || empty($answer_options)) { |
|
| 27 | + $answer_options = [ |
|
| 28 | + EE_Switch_Input::OPTION_ON => esc_html__('enabled', 'event_espresso'), |
|
| 29 | + EE_Switch_Input::OPTION_OFF => esc_html__('disabled', 'event_espresso'), |
|
| 30 | + ]; |
|
| 31 | + } |
|
| 32 | + $this->_multiple_selections = false; |
|
| 33 | + parent::__construct($answer_options, $input_settings); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | ] |
| 24 | 24 | ) |
| 25 | 25 | ); |
| 26 | - if (! is_array($answer_options) || empty($answer_options)) { |
|
| 26 | + if ( ! is_array($answer_options) || empty($answer_options)) { |
|
| 27 | 27 | $answer_options = [ |
| 28 | 28 | EE_Switch_Input::OPTION_ON => esc_html__('enabled', 'event_espresso'), |
| 29 | 29 | EE_Switch_Input::OPTION_OFF => esc_html__('disabled', 'event_espresso'), |
@@ -14,23 +14,23 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Checkbox_Multi_Input extends EE_Form_Input_With_Options_Base |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @param array | EE_Question_Option[] $answer_options |
|
| 19 | - * @param array $input_settings |
|
| 20 | - */ |
|
| 21 | - public function __construct($answer_options, $input_settings = []) |
|
| 22 | - { |
|
| 23 | - $this->_set_display_strategy(new EE_Checkbox_Display_Strategy()); |
|
| 24 | - $this->_add_validation_strategy( |
|
| 25 | - new EE_Many_Valued_Validation_Strategy( |
|
| 26 | - [ |
|
| 27 | - new EE_Enum_Validation_Strategy( |
|
| 28 | - $input_settings['validation_error_message'] ?? null |
|
| 29 | - ) |
|
| 30 | - ] |
|
| 31 | - ) |
|
| 32 | - ); |
|
| 33 | - $this->_multiple_selections = true; |
|
| 34 | - parent::__construct($answer_options, $input_settings); |
|
| 35 | - } |
|
| 17 | + /** |
|
| 18 | + * @param array | EE_Question_Option[] $answer_options |
|
| 19 | + * @param array $input_settings |
|
| 20 | + */ |
|
| 21 | + public function __construct($answer_options, $input_settings = []) |
|
| 22 | + { |
|
| 23 | + $this->_set_display_strategy(new EE_Checkbox_Display_Strategy()); |
|
| 24 | + $this->_add_validation_strategy( |
|
| 25 | + new EE_Many_Valued_Validation_Strategy( |
|
| 26 | + [ |
|
| 27 | + new EE_Enum_Validation_Strategy( |
|
| 28 | + $input_settings['validation_error_message'] ?? null |
|
| 29 | + ) |
|
| 30 | + ] |
|
| 31 | + ) |
|
| 32 | + ); |
|
| 33 | + $this->_multiple_selections = true; |
|
| 34 | + parent::__construct($answer_options, $input_settings); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -15,1536 +15,1536 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 17 | 17 | { |
| 18 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Subsections |
|
| 22 | - * |
|
| 23 | - * @var EE_Form_Section_Validatable[] |
|
| 24 | - */ |
|
| 25 | - protected $_subsections = array(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Strategy for laying out the form |
|
| 29 | - * |
|
| 30 | - * @var EE_Form_Section_Layout_Base |
|
| 31 | - */ |
|
| 32 | - protected $_layout_strategy; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Whether or not this form has received and validated a form submission yet |
|
| 36 | - * |
|
| 37 | - * @var boolean |
|
| 38 | - */ |
|
| 39 | - protected $_received_submission = false; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * message displayed to users upon successful form submission |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - protected $_form_submission_success_message = ''; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * message displayed to users upon unsuccessful form submission |
|
| 50 | - * |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $_form_submission_error_message = ''; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var array like post / request |
|
| 57 | - */ |
|
| 58 | - protected $cached_request_data; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 62 | - * Starts off as null, but once the form is validated, it set to either true or false |
|
| 63 | - * @var boolean|null |
|
| 64 | - */ |
|
| 65 | - protected $is_valid; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Stores all the data that will localized for form validation |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - protected static $_js_localization = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * whether or not the form's localized validation JS vars have been set |
|
| 76 | - * |
|
| 77 | - * @type boolean |
|
| 78 | - */ |
|
| 79 | - protected static $_scripts_localized = false; |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 84 | - * so that they know who their parent is, and what name they've been given. |
|
| 85 | - * |
|
| 86 | - * @param array[] $options_array { |
|
| 87 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 88 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 89 | - * and in that order. This is handy if you want |
|
| 90 | - * the subsections to be ordered differently than the default, and if you override |
|
| 91 | - * which fields are shown |
|
| 92 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 93 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 94 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 95 | - * items from that list of inclusions) |
|
| 96 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 97 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 98 | - * @throws EE_Error |
|
| 99 | - */ |
|
| 100 | - public function __construct($options_array = array()) |
|
| 101 | - { |
|
| 102 | - $options_array = (array) apply_filters( |
|
| 103 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 104 | - $options_array, |
|
| 105 | - $this |
|
| 106 | - ); |
|
| 107 | - // call parent first, as it may be setting the name |
|
| 108 | - parent::__construct($options_array); |
|
| 109 | - // if they've included subsections in the constructor, add them now |
|
| 110 | - if (isset($options_array['include'])) { |
|
| 111 | - // we are going to make sure we ONLY have those subsections to include |
|
| 112 | - // AND we are going to make sure they're in that specified order |
|
| 113 | - $reordered_subsections = array(); |
|
| 114 | - foreach ($options_array['include'] as $input_name) { |
|
| 115 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 116 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - $this->_subsections = $reordered_subsections; |
|
| 120 | - } |
|
| 121 | - if (isset($options_array['exclude'])) { |
|
| 122 | - $exclude = $options_array['exclude']; |
|
| 123 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 124 | - } |
|
| 125 | - if (isset($options_array['layout_strategy'])) { |
|
| 126 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 127 | - } |
|
| 128 | - if (! $this->_layout_strategy) { |
|
| 129 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 130 | - } |
|
| 131 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 132 | - // ok so we are definitely going to want the forms JS, |
|
| 133 | - // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 134 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 135 | - // ok so they've constructed this object after when they should have. |
|
| 136 | - // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 137 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 138 | - } else { |
|
| 139 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 141 | - } |
|
| 142 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 143 | - /** |
|
| 144 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 145 | - * The form probably doesn't yet have a parent form section. |
|
| 146 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 147 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 148 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 149 | - * |
|
| 150 | - * @since 4.9.32 |
|
| 151 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 152 | - * except maybe calling _construct_finalize has been done |
|
| 153 | - * @param array $options_array options passed into the constructor |
|
| 154 | - */ |
|
| 155 | - do_action( |
|
| 156 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 157 | - $this, |
|
| 158 | - $options_array |
|
| 159 | - ); |
|
| 160 | - if (isset($options_array['name'])) { |
|
| 161 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Finishes construction given the parent form section and this form section's name |
|
| 168 | - * |
|
| 169 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 170 | - * @param string $name |
|
| 171 | - * @throws EE_Error |
|
| 172 | - */ |
|
| 173 | - public function _construct_finalize($parent_form_section, $name) |
|
| 174 | - { |
|
| 175 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 176 | - $this->_set_default_name_if_empty(); |
|
| 177 | - $this->_set_default_html_id_if_empty(); |
|
| 178 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 179 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 180 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 181 | - } else { |
|
| 182 | - throw new EE_Error( |
|
| 183 | - sprintf( |
|
| 184 | - esc_html__( |
|
| 185 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 186 | - 'event_espresso' |
|
| 187 | - ), |
|
| 188 | - $subsection_name, |
|
| 189 | - get_class($this), |
|
| 190 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - /** |
|
| 196 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 197 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 198 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 199 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 200 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 201 | - * ensured it has a name, HTML IDs, etc |
|
| 202 | - * |
|
| 203 | - * @param EE_Form_Section_Proper $this |
|
| 204 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 205 | - * @param string $name |
|
| 206 | - */ |
|
| 207 | - do_action( |
|
| 208 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 209 | - $this, |
|
| 210 | - $parent_form_section, |
|
| 211 | - $name |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Gets the layout strategy for this form section |
|
| 218 | - * |
|
| 219 | - * @return EE_Form_Section_Layout_Base |
|
| 220 | - */ |
|
| 221 | - public function get_layout_strategy() |
|
| 222 | - { |
|
| 223 | - return $this->_layout_strategy; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Gets the HTML for a single input for this form section according |
|
| 229 | - * to the layout strategy |
|
| 230 | - * |
|
| 231 | - * @param EE_Form_Input_Base $input |
|
| 232 | - * @return string |
|
| 233 | - */ |
|
| 234 | - public function get_html_for_input($input) |
|
| 235 | - { |
|
| 236 | - return $this->_layout_strategy->layout_input($input); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * was_submitted - checks if form inputs are present in request data |
|
| 242 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 243 | - * proper form sections and form inputs) |
|
| 244 | - * |
|
| 245 | - * @param null $form_data |
|
| 246 | - * @return boolean |
|
| 247 | - * @throws EE_Error |
|
| 248 | - */ |
|
| 249 | - public function was_submitted($form_data = null) |
|
| 250 | - { |
|
| 251 | - return $this->form_data_present_in($form_data); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 256 | - * something different, refresh the cache, and then return it |
|
| 257 | - * @param null $req_data |
|
| 258 | - * @return array |
|
| 259 | - */ |
|
| 260 | - protected function getCachedRequest($req_data = null) |
|
| 261 | - { |
|
| 262 | - if ( |
|
| 263 | - $this->cached_request_data === null |
|
| 264 | - || ( |
|
| 265 | - $req_data !== null |
|
| 266 | - && $req_data !== $this->cached_request_data |
|
| 267 | - ) |
|
| 268 | - ) { |
|
| 269 | - $req_data = apply_filters( |
|
| 270 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 271 | - $req_data, |
|
| 272 | - $this |
|
| 273 | - ); |
|
| 274 | - if ($req_data === null) { |
|
| 275 | - /** @var RequestInterface $request */ |
|
| 276 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 277 | - $req_data = $request->requestParams(); |
|
| 278 | - } |
|
| 279 | - $req_data = apply_filters( |
|
| 280 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 281 | - $req_data, |
|
| 282 | - $this |
|
| 283 | - ); |
|
| 284 | - $this->cached_request_data = (array) $req_data; |
|
| 285 | - } |
|
| 286 | - return $this->cached_request_data; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 292 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 293 | - * |
|
| 294 | - * @param array|null $req_data should usually be post data (the default). |
|
| 295 | - * However, you CAN supply a different array. |
|
| 296 | - * Consider using set_defaults() instead however. |
|
| 297 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 298 | - * the inputs will have the correct name in the request data for this function |
|
| 299 | - * to find them and populate the form with them. |
|
| 300 | - * If you have a flat form (with only input subsections), |
|
| 301 | - * you can supply a flat array where keys |
|
| 302 | - * are the form input names and values are their values) |
|
| 303 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 304 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 305 | - * But if the data has already been validated |
|
| 306 | - * (eg you validated the data then stored it in the DB) |
|
| 307 | - * you may want to skip this step. |
|
| 308 | - * @throws InvalidArgumentException |
|
| 309 | - * @throws InvalidInterfaceException |
|
| 310 | - * @throws InvalidDataTypeException |
|
| 311 | - * @throws EE_Error |
|
| 312 | - */ |
|
| 313 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 314 | - { |
|
| 315 | - $req_data = $this->getCachedRequest($req_data); |
|
| 316 | - $this->_normalize($req_data); |
|
| 317 | - if ($validate) { |
|
| 318 | - $this->_validate(); |
|
| 319 | - // if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 320 | - if (! $this->is_valid()) { |
|
| 321 | - $this->store_submitted_form_data_in_session(); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 325 | - $this->set_submission_error_message(); |
|
| 326 | - } |
|
| 327 | - do_action( |
|
| 328 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 329 | - $req_data, |
|
| 330 | - $this, |
|
| 331 | - $validate |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * caches the originally submitted input values in the session |
|
| 338 | - * so that they can be used to repopulate the form if it failed validation |
|
| 339 | - * |
|
| 340 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidInterfaceException |
|
| 343 | - * @throws InvalidDataTypeException |
|
| 344 | - * @throws EE_Error |
|
| 345 | - */ |
|
| 346 | - protected function store_submitted_form_data_in_session() |
|
| 347 | - { |
|
| 348 | - $session = EE_Registry::instance()->SSN; |
|
| 349 | - if ($session instanceof EE_Session) { |
|
| 350 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 351 | - [ |
|
| 352 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 353 | - ] |
|
| 354 | - ); |
|
| 355 | - } |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * retrieves the originally submitted input values in the session |
|
| 362 | - * so that they can be used to repopulate the form if it failed validation |
|
| 363 | - * |
|
| 364 | - * @return array |
|
| 365 | - * @throws InvalidArgumentException |
|
| 366 | - * @throws InvalidInterfaceException |
|
| 367 | - * @throws InvalidDataTypeException |
|
| 368 | - */ |
|
| 369 | - protected function get_submitted_form_data_from_session() |
|
| 370 | - { |
|
| 371 | - $session = EE_Registry::instance()->SSN; |
|
| 372 | - if ($session instanceof EE_Session) { |
|
| 373 | - return $session->get_session_data( |
|
| 374 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 375 | - ); |
|
| 376 | - } |
|
| 377 | - return array(); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * flushed the originally submitted input values from the session |
|
| 383 | - * |
|
| 384 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 385 | - * @throws InvalidArgumentException |
|
| 386 | - * @throws InvalidInterfaceException |
|
| 387 | - * @throws InvalidDataTypeException |
|
| 388 | - */ |
|
| 389 | - public static function flush_submitted_form_data_from_session() |
|
| 390 | - { |
|
| 391 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 392 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 393 | - ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Populates this form and its subsections with data from the session. |
|
| 399 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 400 | - * validation errors when displaying too) |
|
| 401 | - * Returns true if the form was populated from the session, false otherwise |
|
| 402 | - * |
|
| 403 | - * @return boolean |
|
| 404 | - * @throws InvalidArgumentException |
|
| 405 | - * @throws InvalidInterfaceException |
|
| 406 | - * @throws InvalidDataTypeException |
|
| 407 | - * @throws EE_Error |
|
| 408 | - */ |
|
| 409 | - public function populate_from_session() |
|
| 410 | - { |
|
| 411 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 412 | - if (empty($form_data_in_session)) { |
|
| 413 | - return false; |
|
| 414 | - } |
|
| 415 | - $this->receive_form_submission($form_data_in_session); |
|
| 416 | - add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
| 417 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 418 | - return true; |
|
| 419 | - } |
|
| 420 | - return false; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Populates the default data for the form, given an array where keys are |
|
| 426 | - * the input names, and values are their values (preferably normalized to be their |
|
| 427 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 428 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 429 | - * the value being an array formatted in teh same way |
|
| 430 | - * |
|
| 431 | - * @param array $default_data |
|
| 432 | - * @throws EE_Error |
|
| 433 | - */ |
|
| 434 | - public function populate_defaults($default_data) |
|
| 435 | - { |
|
| 436 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 437 | - if (isset($default_data[ $subsection_name ])) { |
|
| 438 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 439 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 440 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 441 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * returns true if subsection exists |
|
| 450 | - * |
|
| 451 | - * @param string $name |
|
| 452 | - * @return boolean |
|
| 453 | - */ |
|
| 454 | - public function subsection_exists($name) |
|
| 455 | - { |
|
| 456 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Gets the subsection specified by its name |
|
| 462 | - * |
|
| 463 | - * @param string $name |
|
| 464 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 465 | - * so that the inputs will be properly configured. |
|
| 466 | - * However, some client code may be ok |
|
| 467 | - * with construction finalize being called later |
|
| 468 | - * (realizing that the subsections' html names |
|
| 469 | - * might not be set yet, etc.) |
|
| 470 | - * @return EE_Form_Section_Base |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 474 | - { |
|
| 475 | - if ($require_construction_to_be_finalized) { |
|
| 476 | - $this->ensure_construct_finalized_called(); |
|
| 477 | - } |
|
| 478 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Gets all the validatable subsections of this form section |
|
| 484 | - * |
|
| 485 | - * @return EE_Form_Section_Validatable[] |
|
| 486 | - * @throws EE_Error |
|
| 487 | - */ |
|
| 488 | - public function get_validatable_subsections() |
|
| 489 | - { |
|
| 490 | - $validatable_subsections = array(); |
|
| 491 | - foreach ($this->subsections() as $name => $obj) { |
|
| 492 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 493 | - $validatable_subsections[ $name ] = $obj; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $validatable_subsections; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 502 | - * throw an EE_Error. |
|
| 503 | - * |
|
| 504 | - * @param string $name |
|
| 505 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 506 | - * leave this as TRUE so that the inputs will be properly |
|
| 507 | - * configured. However, some client code may be ok with |
|
| 508 | - * construction finalize being called later |
|
| 509 | - * (realizing that the subsections' html names might not be |
|
| 510 | - * set yet, etc.) |
|
| 511 | - * @return EE_Form_Input_Base |
|
| 512 | - * @throws EE_Error |
|
| 513 | - */ |
|
| 514 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 515 | - { |
|
| 516 | - $subsection = $this->get_subsection( |
|
| 517 | - $name, |
|
| 518 | - $require_construction_to_be_finalized |
|
| 519 | - ); |
|
| 520 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 521 | - throw new EE_Error( |
|
| 522 | - sprintf( |
|
| 523 | - esc_html__( |
|
| 524 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 525 | - 'event_espresso' |
|
| 526 | - ), |
|
| 527 | - $name, |
|
| 528 | - get_class($this), |
|
| 529 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 530 | - ) |
|
| 531 | - ); |
|
| 532 | - } |
|
| 533 | - return $subsection; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 539 | - * otherwise throws an EE_Error |
|
| 540 | - * |
|
| 541 | - * @param string $name |
|
| 542 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 543 | - * leave this as TRUE so that the inputs will be properly |
|
| 544 | - * configured. However, some client code may be ok with |
|
| 545 | - * construction finalize being called later |
|
| 546 | - * (realizing that the subsections' html names might not be |
|
| 547 | - * set yet, etc.) |
|
| 548 | - * @return EE_Form_Section_Proper |
|
| 549 | - * @throws EE_Error |
|
| 550 | - */ |
|
| 551 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 552 | - { |
|
| 553 | - $subsection = $this->get_subsection( |
|
| 554 | - $name, |
|
| 555 | - $require_construction_to_be_finalized |
|
| 556 | - ); |
|
| 557 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 558 | - throw new EE_Error( |
|
| 559 | - sprintf( |
|
| 560 | - esc_html__( |
|
| 561 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 562 | - 'event_espresso' |
|
| 563 | - ), |
|
| 564 | - $name, |
|
| 565 | - get_class($this) |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - } |
|
| 569 | - return $subsection; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 575 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 576 | - * |
|
| 577 | - * @param string $name |
|
| 578 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 579 | - * @throws EE_Error |
|
| 580 | - */ |
|
| 581 | - public function get_input_value($name) |
|
| 582 | - { |
|
| 583 | - $input = $this->get_input($name); |
|
| 584 | - return $input->normalized_value(); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 590 | - * |
|
| 591 | - * @throws EE_Error |
|
| 592 | - * @return boolean |
|
| 593 | - */ |
|
| 594 | - public function is_valid() |
|
| 595 | - { |
|
| 596 | - if ($this->is_valid === null) { |
|
| 597 | - if (! $this->has_received_submission()) { |
|
| 598 | - throw new EE_Error( |
|
| 599 | - sprintf( |
|
| 600 | - esc_html__( |
|
| 601 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 602 | - 'event_espresso' |
|
| 603 | - ) |
|
| 604 | - ) |
|
| 605 | - ); |
|
| 606 | - } |
|
| 607 | - if (! parent::is_valid()) { |
|
| 608 | - $this->is_valid = false; |
|
| 609 | - } else { |
|
| 610 | - // ok so no general errors to this entire form section. |
|
| 611 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 612 | - $this->is_valid = true; |
|
| 613 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 614 | - if (! $subsection->is_valid()) { |
|
| 615 | - $this->is_valid = false; |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - return $this->is_valid; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * gets the default name of this form section if none is specified |
|
| 626 | - * |
|
| 627 | - * @return void |
|
| 628 | - */ |
|
| 629 | - protected function _set_default_name_if_empty() |
|
| 630 | - { |
|
| 631 | - if (! $this->_name) { |
|
| 632 | - $classname = get_class($this); |
|
| 633 | - $default_name = str_replace('EE_', '', $classname); |
|
| 634 | - $this->_name = $default_name; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 641 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 642 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 643 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 644 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 645 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 646 | - * any CSS. |
|
| 647 | - * |
|
| 648 | - * @throws InvalidArgumentException |
|
| 649 | - * @throws InvalidInterfaceException |
|
| 650 | - * @throws InvalidDataTypeException |
|
| 651 | - * @throws EE_Error |
|
| 652 | - */ |
|
| 653 | - public function get_html_and_js() |
|
| 654 | - { |
|
| 655 | - $this->enqueue_js(); |
|
| 656 | - return $this->get_html(); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 662 | - * |
|
| 663 | - * @param bool $display_previously_submitted_data |
|
| 664 | - * @return string |
|
| 665 | - * @throws InvalidArgumentException |
|
| 666 | - * @throws InvalidInterfaceException |
|
| 667 | - * @throws InvalidDataTypeException |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws EE_Error |
|
| 670 | - * @throws EE_Error |
|
| 671 | - */ |
|
| 672 | - public function get_html($display_previously_submitted_data = true) |
|
| 673 | - { |
|
| 674 | - $this->ensure_construct_finalized_called(); |
|
| 675 | - if ($display_previously_submitted_data) { |
|
| 676 | - $this->populate_from_session(); |
|
| 677 | - } |
|
| 678 | - return $this->_form_html_filter |
|
| 679 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 680 | - : $this->_layout_strategy->layout_form(); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * enqueues JS and CSS for the form. |
|
| 686 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 687 | - * scripts and styles can be put in the header, but if called later |
|
| 688 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 689 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 690 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 691 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 692 | - * |
|
| 693 | - * @return void |
|
| 694 | - * @throws EE_Error |
|
| 695 | - */ |
|
| 696 | - public function enqueue_js() |
|
| 697 | - { |
|
| 698 | - $this->_enqueue_and_localize_form_js(); |
|
| 699 | - foreach ($this->subsections() as $subsection) { |
|
| 700 | - $subsection->enqueue_js(); |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 707 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 708 | - * the wp_enqueue_scripts hook. |
|
| 709 | - * However, registering the form js and localizing it can happen when we |
|
| 710 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 711 | - * could change until it's actually outputted) |
|
| 712 | - * |
|
| 713 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 714 | - * to be triggered automatically or not |
|
| 715 | - * @return void |
|
| 716 | - */ |
|
| 717 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 718 | - { |
|
| 719 | - wp_register_script( |
|
| 720 | - 'ee_form_section_validation', |
|
| 721 | - EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
| 722 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 723 | - EVENT_ESPRESSO_VERSION, |
|
| 724 | - true |
|
| 725 | - ); |
|
| 726 | - wp_localize_script( |
|
| 727 | - 'ee_form_section_validation', |
|
| 728 | - 'ee_form_section_validation_init', |
|
| 729 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 730 | - ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * gets the variables used by form_section_validation.js. |
|
| 736 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 737 | - * but before the wordpress hook wp_loaded |
|
| 738 | - * |
|
| 739 | - * @throws EE_Error |
|
| 740 | - */ |
|
| 741 | - public function _enqueue_and_localize_form_js() |
|
| 742 | - { |
|
| 743 | - $this->ensure_construct_finalized_called(); |
|
| 744 | - // actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 745 | - // so we need to add our form section data to a static variable accessible by all form sections |
|
| 746 | - // and localize it just before the footer |
|
| 747 | - $this->localize_validation_rules(); |
|
| 748 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 749 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * add our form section data to a static variable accessible by all form sections |
|
| 755 | - * |
|
| 756 | - * @param bool $return_for_subsection |
|
| 757 | - * @return void |
|
| 758 | - * @throws EE_Error |
|
| 759 | - */ |
|
| 760 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 761 | - { |
|
| 762 | - // we only want to localize vars ONCE for the entire form, |
|
| 763 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 764 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 765 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 766 | - 'form_section_id' => $this->html_id(true), |
|
| 767 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 768 | - 'other_data' => $this->get_other_js_data(), |
|
| 769 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 770 | - ); |
|
| 771 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 778 | - * This is primarily data added by inputs and forms in addition to any |
|
| 779 | - * scripts they might enqueue |
|
| 780 | - * |
|
| 781 | - * @param array $form_other_js_data |
|
| 782 | - * @return array |
|
| 783 | - * @throws EE_Error |
|
| 784 | - */ |
|
| 785 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 786 | - { |
|
| 787 | - foreach ($this->subsections() as $subsection) { |
|
| 788 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 789 | - } |
|
| 790 | - return $form_other_js_data; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 796 | - * Keys are their form names, and values are the inputs themselves |
|
| 797 | - * |
|
| 798 | - * @return EE_Form_Input_Base |
|
| 799 | - * @throws EE_Error |
|
| 800 | - */ |
|
| 801 | - public function inputs_in_subsections() |
|
| 802 | - { |
|
| 803 | - $inputs = array(); |
|
| 804 | - foreach ($this->subsections() as $subsection) { |
|
| 805 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 806 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 807 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 808 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - return $inputs; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Gets a flat array of all the validation errors. |
|
| 817 | - * Keys are html names (because those should be unique) |
|
| 818 | - * and values are a string of all their validation errors |
|
| 819 | - * |
|
| 820 | - * @return string[] |
|
| 821 | - * @throws EE_Error |
|
| 822 | - */ |
|
| 823 | - public function subsection_validation_errors_by_html_name() |
|
| 824 | - { |
|
| 825 | - $inputs = $this->inputs(); |
|
| 826 | - $errors = array(); |
|
| 827 | - foreach ($inputs as $form_input) { |
|
| 828 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 829 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - return $errors; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 838 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 839 | - * |
|
| 840 | - * @throws InvalidArgumentException |
|
| 841 | - * @throws InvalidInterfaceException |
|
| 842 | - * @throws InvalidDataTypeException |
|
| 843 | - */ |
|
| 844 | - public static function localize_script_for_all_forms() |
|
| 845 | - { |
|
| 846 | - // allow inputs and stuff to hook in their JS and stuff here |
|
| 847 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 848 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 849 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 850 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 851 | - : 'wp_default'; |
|
| 852 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 853 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 854 | - wp_localize_script( |
|
| 855 | - 'ee_form_section_validation', |
|
| 856 | - 'ee_form_section_vars', |
|
| 857 | - EE_Form_Section_Proper::$_js_localization |
|
| 858 | - ); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * ensure_scripts_localized |
|
| 864 | - * |
|
| 865 | - * @throws EE_Error |
|
| 866 | - */ |
|
| 867 | - public function ensure_scripts_localized() |
|
| 868 | - { |
|
| 869 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 870 | - $this->_enqueue_and_localize_form_js(); |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 877 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 878 | - * |
|
| 879 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 880 | - */ |
|
| 881 | - private static function _get_localized_error_messages() |
|
| 882 | - { |
|
| 883 | - return array( |
|
| 884 | - 'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')), |
|
| 885 | - 'regex' => wp_strip_all_tags(__('Please check your input', 'event_espresso')) |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * @return array |
|
| 892 | - */ |
|
| 893 | - public static function js_localization() |
|
| 894 | - { |
|
| 895 | - return self::$_js_localization; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * @return void |
|
| 901 | - */ |
|
| 902 | - public static function reset_js_localization() |
|
| 903 | - { |
|
| 904 | - self::$_js_localization = array(); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 910 | - * See parent function for more... |
|
| 911 | - * |
|
| 912 | - * @return array |
|
| 913 | - * @throws EE_Error |
|
| 914 | - */ |
|
| 915 | - public function get_jquery_validation_rules() |
|
| 916 | - { |
|
| 917 | - $jquery_validation_rules = array(); |
|
| 918 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 919 | - $jquery_validation_rules = array_merge( |
|
| 920 | - $jquery_validation_rules, |
|
| 921 | - $subsection->get_jquery_validation_rules() |
|
| 922 | - ); |
|
| 923 | - } |
|
| 924 | - return $jquery_validation_rules; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 930 | - * |
|
| 931 | - * @param array $req_data |
|
| 932 | - * @return void |
|
| 933 | - * @throws EE_Error |
|
| 934 | - */ |
|
| 935 | - protected function _normalize($req_data) |
|
| 936 | - { |
|
| 937 | - $this->_received_submission = true; |
|
| 938 | - $this->_validation_errors = array(); |
|
| 939 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 940 | - try { |
|
| 941 | - $subsection->_normalize($req_data); |
|
| 942 | - } catch (EE_Validation_Error $e) { |
|
| 943 | - $subsection->add_validation_error($e); |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * Performs validation on this form section and its subsections. |
|
| 951 | - * For each subsection, |
|
| 952 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 953 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 954 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 955 | - * you would be best to override this _validate method, |
|
| 956 | - * calling parent::_validate() first. |
|
| 957 | - * |
|
| 958 | - * @throws EE_Error |
|
| 959 | - */ |
|
| 960 | - protected function _validate() |
|
| 961 | - { |
|
| 962 | - // reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 963 | - $this->is_valid = null; |
|
| 964 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 965 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 966 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 967 | - } |
|
| 968 | - $subsection->_validate(); |
|
| 969 | - } |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - /** |
|
| 974 | - * Gets all the validated inputs for the form section |
|
| 975 | - * |
|
| 976 | - * @return array |
|
| 977 | - * @throws EE_Error |
|
| 978 | - */ |
|
| 979 | - public function valid_data() |
|
| 980 | - { |
|
| 981 | - $inputs = array(); |
|
| 982 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 983 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 984 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 985 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 986 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - return $inputs; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * Gets all the inputs on this form section |
|
| 995 | - * |
|
| 996 | - * @return EE_Form_Input_Base[] |
|
| 997 | - * @throws EE_Error |
|
| 998 | - */ |
|
| 999 | - public function inputs() |
|
| 1000 | - { |
|
| 1001 | - $inputs = array(); |
|
| 1002 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1003 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1004 | - $inputs[ $subsection_name ] = $subsection; |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - return $inputs; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * Gets all the subsections which are a proper form |
|
| 1013 | - * |
|
| 1014 | - * @return EE_Form_Section_Proper[] |
|
| 1015 | - * @throws EE_Error |
|
| 1016 | - */ |
|
| 1017 | - public function subforms() |
|
| 1018 | - { |
|
| 1019 | - $form_sections = array(); |
|
| 1020 | - foreach ($this->subsections() as $name => $obj) { |
|
| 1021 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1022 | - $form_sections[ $name ] = $obj; |
|
| 1023 | - } |
|
| 1024 | - } |
|
| 1025 | - return $form_sections; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - |
|
| 1029 | - /** |
|
| 1030 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1031 | - * Consider using inputs() or subforms() |
|
| 1032 | - * if you only want form inputs or proper form sections. |
|
| 1033 | - * |
|
| 1034 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1035 | - * leave this as TRUE so that the inputs will be properly |
|
| 1036 | - * configured. However, some client code may be ok with |
|
| 1037 | - * construction finalize being called later |
|
| 1038 | - * (realizing that the subsections' html names might not be |
|
| 1039 | - * set yet, etc.) |
|
| 1040 | - * @return EE_Form_Section_Proper[] |
|
| 1041 | - * @throws EE_Error |
|
| 1042 | - */ |
|
| 1043 | - public function subsections($require_construction_to_be_finalized = true) |
|
| 1044 | - { |
|
| 1045 | - if ($require_construction_to_be_finalized) { |
|
| 1046 | - $this->ensure_construct_finalized_called(); |
|
| 1047 | - } |
|
| 1048 | - return $this->_subsections; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * Returns whether this form has any subforms or inputs |
|
| 1054 | - * @return bool |
|
| 1055 | - */ |
|
| 1056 | - public function hasSubsections() |
|
| 1057 | - { |
|
| 1058 | - return ! empty($this->_subsections); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - |
|
| 1062 | - /** |
|
| 1063 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 1064 | - * values. (Similar to calling get_input_value on inputs) |
|
| 1065 | - * |
|
| 1066 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1067 | - * or just this forms' direct children inputs |
|
| 1068 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1069 | - * or allow multidimensional array |
|
| 1070 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1071 | - * with array keys being input names |
|
| 1072 | - * (regardless of whether they are from a subsection or not), |
|
| 1073 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1074 | - * where keys are always subsection names and values are either |
|
| 1075 | - * the input's normalized value, or an array like the top-level array |
|
| 1076 | - * @throws EE_Error |
|
| 1077 | - */ |
|
| 1078 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1079 | - { |
|
| 1080 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - /** |
|
| 1085 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1086 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1087 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 1088 | - * where keys are the input names, and values are their display values |
|
| 1089 | - * |
|
| 1090 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1091 | - * or just this forms' direct children inputs |
|
| 1092 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1093 | - * or allow multidimensional array |
|
| 1094 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1095 | - * with array keys being input names |
|
| 1096 | - * (regardless of whether they are from a subsection or not), |
|
| 1097 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1098 | - * where keys are always subsection names and values are either |
|
| 1099 | - * the input's normalized value, or an array like the top-level array |
|
| 1100 | - * @throws EE_Error |
|
| 1101 | - */ |
|
| 1102 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1103 | - { |
|
| 1104 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Gets the input values from the form |
|
| 1110 | - * |
|
| 1111 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1112 | - * or just the normalized value |
|
| 1113 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1114 | - * or just this forms' direct children inputs |
|
| 1115 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1116 | - * or allow multidimensional array |
|
| 1117 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1118 | - * input names (regardless of whether they are from a subsection or not), |
|
| 1119 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1120 | - * where keys are always subsection names and values are either |
|
| 1121 | - * the input's normalized value, or an array like the top-level array |
|
| 1122 | - * @throws EE_Error |
|
| 1123 | - */ |
|
| 1124 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1125 | - { |
|
| 1126 | - $input_values = array(); |
|
| 1127 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1128 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1129 | - $input_values[ $subsection_name ] = $pretty |
|
| 1130 | - ? $subsection->pretty_value() |
|
| 1131 | - : $subsection->normalized_value(); |
|
| 1132 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1133 | - $subform_input_values = $subsection->_input_values( |
|
| 1134 | - $pretty, |
|
| 1135 | - $include_subform_inputs, |
|
| 1136 | - $flatten |
|
| 1137 | - ); |
|
| 1138 | - if ($flatten) { |
|
| 1139 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1140 | - } else { |
|
| 1141 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - return $input_values; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Gets the originally submitted input values from the form |
|
| 1151 | - * |
|
| 1152 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1153 | - * or just this forms' direct children inputs |
|
| 1154 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1155 | - * with array keys being input names |
|
| 1156 | - * (regardless of whether they are from a subsection or not), |
|
| 1157 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1158 | - * where keys are always subsection names and values are either |
|
| 1159 | - * the input's normalized value, or an array like the top-level array |
|
| 1160 | - * @throws EE_Error |
|
| 1161 | - */ |
|
| 1162 | - public function submitted_values($include_subforms = false) |
|
| 1163 | - { |
|
| 1164 | - $submitted_values = array(); |
|
| 1165 | - foreach ($this->subsections() as $subsection) { |
|
| 1166 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1167 | - // is this input part of an array of inputs? |
|
| 1168 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1169 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1170 | - explode( |
|
| 1171 | - '[', |
|
| 1172 | - str_replace(']', '', $subsection->html_name()) |
|
| 1173 | - ), |
|
| 1174 | - $subsection->raw_value() |
|
| 1175 | - ); |
|
| 1176 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1177 | - } else { |
|
| 1178 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1179 | - } |
|
| 1180 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1181 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1182 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1185 | - return $submitted_values; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - |
|
| 1189 | - /** |
|
| 1190 | - * Indicates whether or not this form has received a submission yet |
|
| 1191 | - * (ie, had receive_form_submission called on it yet) |
|
| 1192 | - * |
|
| 1193 | - * @return boolean |
|
| 1194 | - * @throws EE_Error |
|
| 1195 | - */ |
|
| 1196 | - public function has_received_submission() |
|
| 1197 | - { |
|
| 1198 | - $this->ensure_construct_finalized_called(); |
|
| 1199 | - return $this->_received_submission; |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - |
|
| 1203 | - /** |
|
| 1204 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1205 | - * Removes the listed inputs from the form |
|
| 1206 | - * |
|
| 1207 | - * @param array $inputs_to_exclude values are the input names |
|
| 1208 | - * @return void |
|
| 1209 | - */ |
|
| 1210 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1211 | - { |
|
| 1212 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1213 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1220 | - * @param array $inputs_to_hide |
|
| 1221 | - * @throws EE_Error |
|
| 1222 | - */ |
|
| 1223 | - public function hide(array $inputs_to_hide = array()) |
|
| 1224 | - { |
|
| 1225 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1226 | - $input = $this->get_input($input_to_hide); |
|
| 1227 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * add_subsections |
|
| 1234 | - * Adds the listed subsections to the form section. |
|
| 1235 | - * If $subsection_name_to_target is provided, |
|
| 1236 | - * then new subsections are added before or after that subsection, |
|
| 1237 | - * otherwise to the start or end of the entire subsections array. |
|
| 1238 | - * |
|
| 1239 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1240 | - * where keys are their names |
|
| 1241 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1242 | - * should be added before or after |
|
| 1243 | - * IF $subsection_name_to_target is null, |
|
| 1244 | - * then $new_subsections will be added to |
|
| 1245 | - * the beginning or end of the entire subsections array |
|
| 1246 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1247 | - * $subsection_name_to_target, |
|
| 1248 | - * or if $subsection_name_to_target is null, |
|
| 1249 | - * before or after entire subsections array |
|
| 1250 | - * @return void |
|
| 1251 | - * @throws EE_Error |
|
| 1252 | - */ |
|
| 1253 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1254 | - { |
|
| 1255 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1256 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1257 | - EE_Error::add_error( |
|
| 1258 | - sprintf( |
|
| 1259 | - esc_html__( |
|
| 1260 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1261 | - 'event_espresso' |
|
| 1262 | - ), |
|
| 1263 | - get_class($subsection), |
|
| 1264 | - $subsection_name, |
|
| 1265 | - $this->name() |
|
| 1266 | - ) |
|
| 1267 | - ); |
|
| 1268 | - unset($new_subsections[ $subsection_name ]); |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1272 | - $this->_subsections, |
|
| 1273 | - $new_subsections, |
|
| 1274 | - $subsection_name_to_target, |
|
| 1275 | - $add_before |
|
| 1276 | - ); |
|
| 1277 | - if ($this->_construction_finalized) { |
|
| 1278 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1279 | - $subsection->_construct_finalize($this, $name); |
|
| 1280 | - } |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * @param string $subsection_name |
|
| 1287 | - * @param bool $recursive |
|
| 1288 | - * @return bool |
|
| 1289 | - */ |
|
| 1290 | - public function has_subsection($subsection_name, $recursive = false) |
|
| 1291 | - { |
|
| 1292 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1293 | - if ( |
|
| 1294 | - $name === $subsection_name |
|
| 1295 | - || ( |
|
| 1296 | - $recursive |
|
| 1297 | - && $subsection instanceof EE_Form_Section_Proper |
|
| 1298 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1299 | - ) |
|
| 1300 | - ) { |
|
| 1301 | - return true; |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1304 | - return false; |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1311 | - * |
|
| 1312 | - * @throws EE_Error |
|
| 1313 | - */ |
|
| 1314 | - public function clean_sensitive_data() |
|
| 1315 | - { |
|
| 1316 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1317 | - $subsection->clean_sensitive_data(); |
|
| 1318 | - } |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1324 | - * @param string $form_submission_error_message |
|
| 1325 | - * @param EE_Form_Section_Validatable $form_section unused |
|
| 1326 | - * @throws EE_Error |
|
| 1327 | - */ |
|
| 1328 | - public function set_submission_error_message( |
|
| 1329 | - $form_submission_error_message = '' |
|
| 1330 | - ) { |
|
| 1331 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1332 | - ? $form_submission_error_message |
|
| 1333 | - : $this->getAllValidationErrorsString(); |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - |
|
| 1337 | - /** |
|
| 1338 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1339 | - * (called during receive_form_submission) but it can be explicitly set using |
|
| 1340 | - * set_submission_error_message |
|
| 1341 | - * |
|
| 1342 | - * @return string |
|
| 1343 | - */ |
|
| 1344 | - public function submission_error_message() |
|
| 1345 | - { |
|
| 1346 | - return $this->_form_submission_error_message; |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * Sets a message to display if the data submitted to the form was valid. |
|
| 1352 | - * @param string $form_submission_success_message |
|
| 1353 | - */ |
|
| 1354 | - public function set_submission_success_message($form_submission_success_message = '') |
|
| 1355 | - { |
|
| 1356 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1357 | - ? $form_submission_success_message |
|
| 1358 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Gets a message appropriate for display when the form is correctly submitted |
|
| 1364 | - * @return string |
|
| 1365 | - */ |
|
| 1366 | - public function submission_success_message() |
|
| 1367 | - { |
|
| 1368 | - return $this->_form_submission_success_message; |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - |
|
| 1372 | - /** |
|
| 1373 | - * Returns the prefix that should be used on child of this form section for |
|
| 1374 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1375 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1376 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1377 | - * |
|
| 1378 | - * @return string |
|
| 1379 | - * @throws EE_Error |
|
| 1380 | - */ |
|
| 1381 | - public function html_name_prefix() |
|
| 1382 | - { |
|
| 1383 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1384 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1385 | - } |
|
| 1386 | - return $this->name(); |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1392 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1393 | - * was set, which is probably nothing, or the classname) |
|
| 1394 | - * |
|
| 1395 | - * @return string |
|
| 1396 | - * @throws EE_Error |
|
| 1397 | - */ |
|
| 1398 | - public function name() |
|
| 1399 | - { |
|
| 1400 | - $this->ensure_construct_finalized_called(); |
|
| 1401 | - return parent::name(); |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - |
|
| 1405 | - /** |
|
| 1406 | - * @return EE_Form_Section_Proper |
|
| 1407 | - * @throws EE_Error |
|
| 1408 | - */ |
|
| 1409 | - public function parent_section() |
|
| 1410 | - { |
|
| 1411 | - $this->ensure_construct_finalized_called(); |
|
| 1412 | - return parent::parent_section(); |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1418 | - * |
|
| 1419 | - * @return void |
|
| 1420 | - * @throws EE_Error |
|
| 1421 | - */ |
|
| 1422 | - public function ensure_construct_finalized_called() |
|
| 1423 | - { |
|
| 1424 | - if (! $this->_construction_finalized) { |
|
| 1425 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1426 | - } |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - |
|
| 1430 | - /** |
|
| 1431 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1432 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1433 | - * |
|
| 1434 | - * @param array $req_data |
|
| 1435 | - * @return boolean |
|
| 1436 | - * @throws EE_Error |
|
| 1437 | - */ |
|
| 1438 | - public function form_data_present_in($req_data = null) |
|
| 1439 | - { |
|
| 1440 | - $req_data = $this->getCachedRequest($req_data); |
|
| 1441 | - foreach ($this->subsections() as $subsection) { |
|
| 1442 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1443 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1444 | - return true; |
|
| 1445 | - } |
|
| 1446 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1447 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1448 | - return true; |
|
| 1449 | - } |
|
| 1450 | - } |
|
| 1451 | - } |
|
| 1452 | - return false; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - |
|
| 1456 | - /** |
|
| 1457 | - * Gets validation errors for this form section and subsections |
|
| 1458 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1459 | - * gets the validation errors for ALL subsection |
|
| 1460 | - * |
|
| 1461 | - * @return EE_Validation_Error[] |
|
| 1462 | - * @throws EE_Error |
|
| 1463 | - */ |
|
| 1464 | - public function get_validation_errors_accumulated() |
|
| 1465 | - { |
|
| 1466 | - $validation_errors = $this->get_validation_errors(); |
|
| 1467 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1468 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1469 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1470 | - } else { |
|
| 1471 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1472 | - } |
|
| 1473 | - if ($validation_errors_on_this_subsection) { |
|
| 1474 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1475 | - } |
|
| 1476 | - } |
|
| 1477 | - return $validation_errors; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - /** |
|
| 1481 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1482 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1483 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1484 | - * |
|
| 1485 | - * @return string |
|
| 1486 | - * @since 4.9.59.p |
|
| 1487 | - */ |
|
| 1488 | - protected function getAllValidationErrorsString() |
|
| 1489 | - { |
|
| 1490 | - $submission_error_messages = array(); |
|
| 1491 | - // bad, bad, bad registrant |
|
| 1492 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1493 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1494 | - $form_section = $validation_error->get_form_section(); |
|
| 1495 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1496 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1497 | - } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1498 | - $label = $validation_error->get_form_section()->name(); |
|
| 1499 | - } else { |
|
| 1500 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1501 | - } |
|
| 1502 | - $submission_error_messages[] = sprintf( |
|
| 1503 | - esc_html__('%s : %s', 'event_espresso'), |
|
| 1504 | - $label, |
|
| 1505 | - $validation_error->getMessage() |
|
| 1506 | - ); |
|
| 1507 | - } |
|
| 1508 | - } |
|
| 1509 | - return implode('<br>', $submission_error_messages); |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1515 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1516 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1517 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1518 | - * which will be returned. |
|
| 1519 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1520 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1521 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1522 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1523 | - * Etc |
|
| 1524 | - * |
|
| 1525 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1526 | - * @return EE_Form_Section_Base |
|
| 1527 | - * @throws EE_Error |
|
| 1528 | - */ |
|
| 1529 | - public function find_section_from_path($form_section_path) |
|
| 1530 | - { |
|
| 1531 | - // check if we can find the input from purely going straight up the tree |
|
| 1532 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1533 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1534 | - return $input; |
|
| 1535 | - } |
|
| 1536 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1537 | - if ($next_slash_pos !== false) { |
|
| 1538 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1539 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1540 | - } else { |
|
| 1541 | - $child_section_name = $form_section_path; |
|
| 1542 | - $subpath = ''; |
|
| 1543 | - } |
|
| 1544 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1545 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1546 | - return $child_section->find_section_from_path($subpath); |
|
| 1547 | - } |
|
| 1548 | - return null; |
|
| 1549 | - } |
|
| 18 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Subsections |
|
| 22 | + * |
|
| 23 | + * @var EE_Form_Section_Validatable[] |
|
| 24 | + */ |
|
| 25 | + protected $_subsections = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Strategy for laying out the form |
|
| 29 | + * |
|
| 30 | + * @var EE_Form_Section_Layout_Base |
|
| 31 | + */ |
|
| 32 | + protected $_layout_strategy; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Whether or not this form has received and validated a form submission yet |
|
| 36 | + * |
|
| 37 | + * @var boolean |
|
| 38 | + */ |
|
| 39 | + protected $_received_submission = false; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * message displayed to users upon successful form submission |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + protected $_form_submission_success_message = ''; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * message displayed to users upon unsuccessful form submission |
|
| 50 | + * |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $_form_submission_error_message = ''; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var array like post / request |
|
| 57 | + */ |
|
| 58 | + protected $cached_request_data; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 62 | + * Starts off as null, but once the form is validated, it set to either true or false |
|
| 63 | + * @var boolean|null |
|
| 64 | + */ |
|
| 65 | + protected $is_valid; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Stores all the data that will localized for form validation |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + protected static $_js_localization = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * whether or not the form's localized validation JS vars have been set |
|
| 76 | + * |
|
| 77 | + * @type boolean |
|
| 78 | + */ |
|
| 79 | + protected static $_scripts_localized = false; |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 84 | + * so that they know who their parent is, and what name they've been given. |
|
| 85 | + * |
|
| 86 | + * @param array[] $options_array { |
|
| 87 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 88 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 89 | + * and in that order. This is handy if you want |
|
| 90 | + * the subsections to be ordered differently than the default, and if you override |
|
| 91 | + * which fields are shown |
|
| 92 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 93 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 94 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 95 | + * items from that list of inclusions) |
|
| 96 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 97 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 98 | + * @throws EE_Error |
|
| 99 | + */ |
|
| 100 | + public function __construct($options_array = array()) |
|
| 101 | + { |
|
| 102 | + $options_array = (array) apply_filters( |
|
| 103 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 104 | + $options_array, |
|
| 105 | + $this |
|
| 106 | + ); |
|
| 107 | + // call parent first, as it may be setting the name |
|
| 108 | + parent::__construct($options_array); |
|
| 109 | + // if they've included subsections in the constructor, add them now |
|
| 110 | + if (isset($options_array['include'])) { |
|
| 111 | + // we are going to make sure we ONLY have those subsections to include |
|
| 112 | + // AND we are going to make sure they're in that specified order |
|
| 113 | + $reordered_subsections = array(); |
|
| 114 | + foreach ($options_array['include'] as $input_name) { |
|
| 115 | + if (isset($this->_subsections[ $input_name ])) { |
|
| 116 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + $this->_subsections = $reordered_subsections; |
|
| 120 | + } |
|
| 121 | + if (isset($options_array['exclude'])) { |
|
| 122 | + $exclude = $options_array['exclude']; |
|
| 123 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 124 | + } |
|
| 125 | + if (isset($options_array['layout_strategy'])) { |
|
| 126 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 127 | + } |
|
| 128 | + if (! $this->_layout_strategy) { |
|
| 129 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 130 | + } |
|
| 131 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 132 | + // ok so we are definitely going to want the forms JS, |
|
| 133 | + // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 134 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 135 | + // ok so they've constructed this object after when they should have. |
|
| 136 | + // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 137 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 138 | + } else { |
|
| 139 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 141 | + } |
|
| 142 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 143 | + /** |
|
| 144 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 145 | + * The form probably doesn't yet have a parent form section. |
|
| 146 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 147 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 148 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 149 | + * |
|
| 150 | + * @since 4.9.32 |
|
| 151 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 152 | + * except maybe calling _construct_finalize has been done |
|
| 153 | + * @param array $options_array options passed into the constructor |
|
| 154 | + */ |
|
| 155 | + do_action( |
|
| 156 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 157 | + $this, |
|
| 158 | + $options_array |
|
| 159 | + ); |
|
| 160 | + if (isset($options_array['name'])) { |
|
| 161 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Finishes construction given the parent form section and this form section's name |
|
| 168 | + * |
|
| 169 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 170 | + * @param string $name |
|
| 171 | + * @throws EE_Error |
|
| 172 | + */ |
|
| 173 | + public function _construct_finalize($parent_form_section, $name) |
|
| 174 | + { |
|
| 175 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 176 | + $this->_set_default_name_if_empty(); |
|
| 177 | + $this->_set_default_html_id_if_empty(); |
|
| 178 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 179 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 180 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 181 | + } else { |
|
| 182 | + throw new EE_Error( |
|
| 183 | + sprintf( |
|
| 184 | + esc_html__( |
|
| 185 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 186 | + 'event_espresso' |
|
| 187 | + ), |
|
| 188 | + $subsection_name, |
|
| 189 | + get_class($this), |
|
| 190 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + /** |
|
| 196 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 197 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 198 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 199 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 200 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 201 | + * ensured it has a name, HTML IDs, etc |
|
| 202 | + * |
|
| 203 | + * @param EE_Form_Section_Proper $this |
|
| 204 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 205 | + * @param string $name |
|
| 206 | + */ |
|
| 207 | + do_action( |
|
| 208 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 209 | + $this, |
|
| 210 | + $parent_form_section, |
|
| 211 | + $name |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Gets the layout strategy for this form section |
|
| 218 | + * |
|
| 219 | + * @return EE_Form_Section_Layout_Base |
|
| 220 | + */ |
|
| 221 | + public function get_layout_strategy() |
|
| 222 | + { |
|
| 223 | + return $this->_layout_strategy; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Gets the HTML for a single input for this form section according |
|
| 229 | + * to the layout strategy |
|
| 230 | + * |
|
| 231 | + * @param EE_Form_Input_Base $input |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 234 | + public function get_html_for_input($input) |
|
| 235 | + { |
|
| 236 | + return $this->_layout_strategy->layout_input($input); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * was_submitted - checks if form inputs are present in request data |
|
| 242 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 243 | + * proper form sections and form inputs) |
|
| 244 | + * |
|
| 245 | + * @param null $form_data |
|
| 246 | + * @return boolean |
|
| 247 | + * @throws EE_Error |
|
| 248 | + */ |
|
| 249 | + public function was_submitted($form_data = null) |
|
| 250 | + { |
|
| 251 | + return $this->form_data_present_in($form_data); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 256 | + * something different, refresh the cache, and then return it |
|
| 257 | + * @param null $req_data |
|
| 258 | + * @return array |
|
| 259 | + */ |
|
| 260 | + protected function getCachedRequest($req_data = null) |
|
| 261 | + { |
|
| 262 | + if ( |
|
| 263 | + $this->cached_request_data === null |
|
| 264 | + || ( |
|
| 265 | + $req_data !== null |
|
| 266 | + && $req_data !== $this->cached_request_data |
|
| 267 | + ) |
|
| 268 | + ) { |
|
| 269 | + $req_data = apply_filters( |
|
| 270 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 271 | + $req_data, |
|
| 272 | + $this |
|
| 273 | + ); |
|
| 274 | + if ($req_data === null) { |
|
| 275 | + /** @var RequestInterface $request */ |
|
| 276 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 277 | + $req_data = $request->requestParams(); |
|
| 278 | + } |
|
| 279 | + $req_data = apply_filters( |
|
| 280 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 281 | + $req_data, |
|
| 282 | + $this |
|
| 283 | + ); |
|
| 284 | + $this->cached_request_data = (array) $req_data; |
|
| 285 | + } |
|
| 286 | + return $this->cached_request_data; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 292 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 293 | + * |
|
| 294 | + * @param array|null $req_data should usually be post data (the default). |
|
| 295 | + * However, you CAN supply a different array. |
|
| 296 | + * Consider using set_defaults() instead however. |
|
| 297 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 298 | + * the inputs will have the correct name in the request data for this function |
|
| 299 | + * to find them and populate the form with them. |
|
| 300 | + * If you have a flat form (with only input subsections), |
|
| 301 | + * you can supply a flat array where keys |
|
| 302 | + * are the form input names and values are their values) |
|
| 303 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 304 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 305 | + * But if the data has already been validated |
|
| 306 | + * (eg you validated the data then stored it in the DB) |
|
| 307 | + * you may want to skip this step. |
|
| 308 | + * @throws InvalidArgumentException |
|
| 309 | + * @throws InvalidInterfaceException |
|
| 310 | + * @throws InvalidDataTypeException |
|
| 311 | + * @throws EE_Error |
|
| 312 | + */ |
|
| 313 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 314 | + { |
|
| 315 | + $req_data = $this->getCachedRequest($req_data); |
|
| 316 | + $this->_normalize($req_data); |
|
| 317 | + if ($validate) { |
|
| 318 | + $this->_validate(); |
|
| 319 | + // if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 320 | + if (! $this->is_valid()) { |
|
| 321 | + $this->store_submitted_form_data_in_session(); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 325 | + $this->set_submission_error_message(); |
|
| 326 | + } |
|
| 327 | + do_action( |
|
| 328 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 329 | + $req_data, |
|
| 330 | + $this, |
|
| 331 | + $validate |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * caches the originally submitted input values in the session |
|
| 338 | + * so that they can be used to repopulate the form if it failed validation |
|
| 339 | + * |
|
| 340 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidInterfaceException |
|
| 343 | + * @throws InvalidDataTypeException |
|
| 344 | + * @throws EE_Error |
|
| 345 | + */ |
|
| 346 | + protected function store_submitted_form_data_in_session() |
|
| 347 | + { |
|
| 348 | + $session = EE_Registry::instance()->SSN; |
|
| 349 | + if ($session instanceof EE_Session) { |
|
| 350 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 351 | + [ |
|
| 352 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 353 | + ] |
|
| 354 | + ); |
|
| 355 | + } |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * retrieves the originally submitted input values in the session |
|
| 362 | + * so that they can be used to repopulate the form if it failed validation |
|
| 363 | + * |
|
| 364 | + * @return array |
|
| 365 | + * @throws InvalidArgumentException |
|
| 366 | + * @throws InvalidInterfaceException |
|
| 367 | + * @throws InvalidDataTypeException |
|
| 368 | + */ |
|
| 369 | + protected function get_submitted_form_data_from_session() |
|
| 370 | + { |
|
| 371 | + $session = EE_Registry::instance()->SSN; |
|
| 372 | + if ($session instanceof EE_Session) { |
|
| 373 | + return $session->get_session_data( |
|
| 374 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 375 | + ); |
|
| 376 | + } |
|
| 377 | + return array(); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * flushed the originally submitted input values from the session |
|
| 383 | + * |
|
| 384 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 385 | + * @throws InvalidArgumentException |
|
| 386 | + * @throws InvalidInterfaceException |
|
| 387 | + * @throws InvalidDataTypeException |
|
| 388 | + */ |
|
| 389 | + public static function flush_submitted_form_data_from_session() |
|
| 390 | + { |
|
| 391 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 392 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 393 | + ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Populates this form and its subsections with data from the session. |
|
| 399 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 400 | + * validation errors when displaying too) |
|
| 401 | + * Returns true if the form was populated from the session, false otherwise |
|
| 402 | + * |
|
| 403 | + * @return boolean |
|
| 404 | + * @throws InvalidArgumentException |
|
| 405 | + * @throws InvalidInterfaceException |
|
| 406 | + * @throws InvalidDataTypeException |
|
| 407 | + * @throws EE_Error |
|
| 408 | + */ |
|
| 409 | + public function populate_from_session() |
|
| 410 | + { |
|
| 411 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 412 | + if (empty($form_data_in_session)) { |
|
| 413 | + return false; |
|
| 414 | + } |
|
| 415 | + $this->receive_form_submission($form_data_in_session); |
|
| 416 | + add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
| 417 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 418 | + return true; |
|
| 419 | + } |
|
| 420 | + return false; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Populates the default data for the form, given an array where keys are |
|
| 426 | + * the input names, and values are their values (preferably normalized to be their |
|
| 427 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 428 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 429 | + * the value being an array formatted in teh same way |
|
| 430 | + * |
|
| 431 | + * @param array $default_data |
|
| 432 | + * @throws EE_Error |
|
| 433 | + */ |
|
| 434 | + public function populate_defaults($default_data) |
|
| 435 | + { |
|
| 436 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 437 | + if (isset($default_data[ $subsection_name ])) { |
|
| 438 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 439 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
| 440 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 441 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * returns true if subsection exists |
|
| 450 | + * |
|
| 451 | + * @param string $name |
|
| 452 | + * @return boolean |
|
| 453 | + */ |
|
| 454 | + public function subsection_exists($name) |
|
| 455 | + { |
|
| 456 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Gets the subsection specified by its name |
|
| 462 | + * |
|
| 463 | + * @param string $name |
|
| 464 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 465 | + * so that the inputs will be properly configured. |
|
| 466 | + * However, some client code may be ok |
|
| 467 | + * with construction finalize being called later |
|
| 468 | + * (realizing that the subsections' html names |
|
| 469 | + * might not be set yet, etc.) |
|
| 470 | + * @return EE_Form_Section_Base |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 474 | + { |
|
| 475 | + if ($require_construction_to_be_finalized) { |
|
| 476 | + $this->ensure_construct_finalized_called(); |
|
| 477 | + } |
|
| 478 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Gets all the validatable subsections of this form section |
|
| 484 | + * |
|
| 485 | + * @return EE_Form_Section_Validatable[] |
|
| 486 | + * @throws EE_Error |
|
| 487 | + */ |
|
| 488 | + public function get_validatable_subsections() |
|
| 489 | + { |
|
| 490 | + $validatable_subsections = array(); |
|
| 491 | + foreach ($this->subsections() as $name => $obj) { |
|
| 492 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 493 | + $validatable_subsections[ $name ] = $obj; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $validatable_subsections; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 502 | + * throw an EE_Error. |
|
| 503 | + * |
|
| 504 | + * @param string $name |
|
| 505 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 506 | + * leave this as TRUE so that the inputs will be properly |
|
| 507 | + * configured. However, some client code may be ok with |
|
| 508 | + * construction finalize being called later |
|
| 509 | + * (realizing that the subsections' html names might not be |
|
| 510 | + * set yet, etc.) |
|
| 511 | + * @return EE_Form_Input_Base |
|
| 512 | + * @throws EE_Error |
|
| 513 | + */ |
|
| 514 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 515 | + { |
|
| 516 | + $subsection = $this->get_subsection( |
|
| 517 | + $name, |
|
| 518 | + $require_construction_to_be_finalized |
|
| 519 | + ); |
|
| 520 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 521 | + throw new EE_Error( |
|
| 522 | + sprintf( |
|
| 523 | + esc_html__( |
|
| 524 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 525 | + 'event_espresso' |
|
| 526 | + ), |
|
| 527 | + $name, |
|
| 528 | + get_class($this), |
|
| 529 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 530 | + ) |
|
| 531 | + ); |
|
| 532 | + } |
|
| 533 | + return $subsection; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 539 | + * otherwise throws an EE_Error |
|
| 540 | + * |
|
| 541 | + * @param string $name |
|
| 542 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 543 | + * leave this as TRUE so that the inputs will be properly |
|
| 544 | + * configured. However, some client code may be ok with |
|
| 545 | + * construction finalize being called later |
|
| 546 | + * (realizing that the subsections' html names might not be |
|
| 547 | + * set yet, etc.) |
|
| 548 | + * @return EE_Form_Section_Proper |
|
| 549 | + * @throws EE_Error |
|
| 550 | + */ |
|
| 551 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 552 | + { |
|
| 553 | + $subsection = $this->get_subsection( |
|
| 554 | + $name, |
|
| 555 | + $require_construction_to_be_finalized |
|
| 556 | + ); |
|
| 557 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 558 | + throw new EE_Error( |
|
| 559 | + sprintf( |
|
| 560 | + esc_html__( |
|
| 561 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 562 | + 'event_espresso' |
|
| 563 | + ), |
|
| 564 | + $name, |
|
| 565 | + get_class($this) |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + } |
|
| 569 | + return $subsection; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 575 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 576 | + * |
|
| 577 | + * @param string $name |
|
| 578 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 579 | + * @throws EE_Error |
|
| 580 | + */ |
|
| 581 | + public function get_input_value($name) |
|
| 582 | + { |
|
| 583 | + $input = $this->get_input($name); |
|
| 584 | + return $input->normalized_value(); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 590 | + * |
|
| 591 | + * @throws EE_Error |
|
| 592 | + * @return boolean |
|
| 593 | + */ |
|
| 594 | + public function is_valid() |
|
| 595 | + { |
|
| 596 | + if ($this->is_valid === null) { |
|
| 597 | + if (! $this->has_received_submission()) { |
|
| 598 | + throw new EE_Error( |
|
| 599 | + sprintf( |
|
| 600 | + esc_html__( |
|
| 601 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 602 | + 'event_espresso' |
|
| 603 | + ) |
|
| 604 | + ) |
|
| 605 | + ); |
|
| 606 | + } |
|
| 607 | + if (! parent::is_valid()) { |
|
| 608 | + $this->is_valid = false; |
|
| 609 | + } else { |
|
| 610 | + // ok so no general errors to this entire form section. |
|
| 611 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 612 | + $this->is_valid = true; |
|
| 613 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 614 | + if (! $subsection->is_valid()) { |
|
| 615 | + $this->is_valid = false; |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + return $this->is_valid; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * gets the default name of this form section if none is specified |
|
| 626 | + * |
|
| 627 | + * @return void |
|
| 628 | + */ |
|
| 629 | + protected function _set_default_name_if_empty() |
|
| 630 | + { |
|
| 631 | + if (! $this->_name) { |
|
| 632 | + $classname = get_class($this); |
|
| 633 | + $default_name = str_replace('EE_', '', $classname); |
|
| 634 | + $this->_name = $default_name; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 641 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 642 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 643 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 644 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 645 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 646 | + * any CSS. |
|
| 647 | + * |
|
| 648 | + * @throws InvalidArgumentException |
|
| 649 | + * @throws InvalidInterfaceException |
|
| 650 | + * @throws InvalidDataTypeException |
|
| 651 | + * @throws EE_Error |
|
| 652 | + */ |
|
| 653 | + public function get_html_and_js() |
|
| 654 | + { |
|
| 655 | + $this->enqueue_js(); |
|
| 656 | + return $this->get_html(); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 662 | + * |
|
| 663 | + * @param bool $display_previously_submitted_data |
|
| 664 | + * @return string |
|
| 665 | + * @throws InvalidArgumentException |
|
| 666 | + * @throws InvalidInterfaceException |
|
| 667 | + * @throws InvalidDataTypeException |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws EE_Error |
|
| 670 | + * @throws EE_Error |
|
| 671 | + */ |
|
| 672 | + public function get_html($display_previously_submitted_data = true) |
|
| 673 | + { |
|
| 674 | + $this->ensure_construct_finalized_called(); |
|
| 675 | + if ($display_previously_submitted_data) { |
|
| 676 | + $this->populate_from_session(); |
|
| 677 | + } |
|
| 678 | + return $this->_form_html_filter |
|
| 679 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 680 | + : $this->_layout_strategy->layout_form(); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * enqueues JS and CSS for the form. |
|
| 686 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 687 | + * scripts and styles can be put in the header, but if called later |
|
| 688 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 689 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 690 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 691 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 692 | + * |
|
| 693 | + * @return void |
|
| 694 | + * @throws EE_Error |
|
| 695 | + */ |
|
| 696 | + public function enqueue_js() |
|
| 697 | + { |
|
| 698 | + $this->_enqueue_and_localize_form_js(); |
|
| 699 | + foreach ($this->subsections() as $subsection) { |
|
| 700 | + $subsection->enqueue_js(); |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 707 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 708 | + * the wp_enqueue_scripts hook. |
|
| 709 | + * However, registering the form js and localizing it can happen when we |
|
| 710 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 711 | + * could change until it's actually outputted) |
|
| 712 | + * |
|
| 713 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 714 | + * to be triggered automatically or not |
|
| 715 | + * @return void |
|
| 716 | + */ |
|
| 717 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 718 | + { |
|
| 719 | + wp_register_script( |
|
| 720 | + 'ee_form_section_validation', |
|
| 721 | + EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
| 722 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 723 | + EVENT_ESPRESSO_VERSION, |
|
| 724 | + true |
|
| 725 | + ); |
|
| 726 | + wp_localize_script( |
|
| 727 | + 'ee_form_section_validation', |
|
| 728 | + 'ee_form_section_validation_init', |
|
| 729 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 730 | + ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * gets the variables used by form_section_validation.js. |
|
| 736 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 737 | + * but before the wordpress hook wp_loaded |
|
| 738 | + * |
|
| 739 | + * @throws EE_Error |
|
| 740 | + */ |
|
| 741 | + public function _enqueue_and_localize_form_js() |
|
| 742 | + { |
|
| 743 | + $this->ensure_construct_finalized_called(); |
|
| 744 | + // actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 745 | + // so we need to add our form section data to a static variable accessible by all form sections |
|
| 746 | + // and localize it just before the footer |
|
| 747 | + $this->localize_validation_rules(); |
|
| 748 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 749 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * add our form section data to a static variable accessible by all form sections |
|
| 755 | + * |
|
| 756 | + * @param bool $return_for_subsection |
|
| 757 | + * @return void |
|
| 758 | + * @throws EE_Error |
|
| 759 | + */ |
|
| 760 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 761 | + { |
|
| 762 | + // we only want to localize vars ONCE for the entire form, |
|
| 763 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 764 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 765 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 766 | + 'form_section_id' => $this->html_id(true), |
|
| 767 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 768 | + 'other_data' => $this->get_other_js_data(), |
|
| 769 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 770 | + ); |
|
| 771 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 778 | + * This is primarily data added by inputs and forms in addition to any |
|
| 779 | + * scripts they might enqueue |
|
| 780 | + * |
|
| 781 | + * @param array $form_other_js_data |
|
| 782 | + * @return array |
|
| 783 | + * @throws EE_Error |
|
| 784 | + */ |
|
| 785 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 786 | + { |
|
| 787 | + foreach ($this->subsections() as $subsection) { |
|
| 788 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 789 | + } |
|
| 790 | + return $form_other_js_data; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 796 | + * Keys are their form names, and values are the inputs themselves |
|
| 797 | + * |
|
| 798 | + * @return EE_Form_Input_Base |
|
| 799 | + * @throws EE_Error |
|
| 800 | + */ |
|
| 801 | + public function inputs_in_subsections() |
|
| 802 | + { |
|
| 803 | + $inputs = array(); |
|
| 804 | + foreach ($this->subsections() as $subsection) { |
|
| 805 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 806 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
| 807 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 808 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + return $inputs; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Gets a flat array of all the validation errors. |
|
| 817 | + * Keys are html names (because those should be unique) |
|
| 818 | + * and values are a string of all their validation errors |
|
| 819 | + * |
|
| 820 | + * @return string[] |
|
| 821 | + * @throws EE_Error |
|
| 822 | + */ |
|
| 823 | + public function subsection_validation_errors_by_html_name() |
|
| 824 | + { |
|
| 825 | + $inputs = $this->inputs(); |
|
| 826 | + $errors = array(); |
|
| 827 | + foreach ($inputs as $form_input) { |
|
| 828 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 829 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + return $errors; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 838 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 839 | + * |
|
| 840 | + * @throws InvalidArgumentException |
|
| 841 | + * @throws InvalidInterfaceException |
|
| 842 | + * @throws InvalidDataTypeException |
|
| 843 | + */ |
|
| 844 | + public static function localize_script_for_all_forms() |
|
| 845 | + { |
|
| 846 | + // allow inputs and stuff to hook in their JS and stuff here |
|
| 847 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 848 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 849 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 850 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 851 | + : 'wp_default'; |
|
| 852 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 853 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 854 | + wp_localize_script( |
|
| 855 | + 'ee_form_section_validation', |
|
| 856 | + 'ee_form_section_vars', |
|
| 857 | + EE_Form_Section_Proper::$_js_localization |
|
| 858 | + ); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * ensure_scripts_localized |
|
| 864 | + * |
|
| 865 | + * @throws EE_Error |
|
| 866 | + */ |
|
| 867 | + public function ensure_scripts_localized() |
|
| 868 | + { |
|
| 869 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 870 | + $this->_enqueue_and_localize_form_js(); |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 877 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 878 | + * |
|
| 879 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 880 | + */ |
|
| 881 | + private static function _get_localized_error_messages() |
|
| 882 | + { |
|
| 883 | + return array( |
|
| 884 | + 'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')), |
|
| 885 | + 'regex' => wp_strip_all_tags(__('Please check your input', 'event_espresso')) |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * @return array |
|
| 892 | + */ |
|
| 893 | + public static function js_localization() |
|
| 894 | + { |
|
| 895 | + return self::$_js_localization; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * @return void |
|
| 901 | + */ |
|
| 902 | + public static function reset_js_localization() |
|
| 903 | + { |
|
| 904 | + self::$_js_localization = array(); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 910 | + * See parent function for more... |
|
| 911 | + * |
|
| 912 | + * @return array |
|
| 913 | + * @throws EE_Error |
|
| 914 | + */ |
|
| 915 | + public function get_jquery_validation_rules() |
|
| 916 | + { |
|
| 917 | + $jquery_validation_rules = array(); |
|
| 918 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 919 | + $jquery_validation_rules = array_merge( |
|
| 920 | + $jquery_validation_rules, |
|
| 921 | + $subsection->get_jquery_validation_rules() |
|
| 922 | + ); |
|
| 923 | + } |
|
| 924 | + return $jquery_validation_rules; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 930 | + * |
|
| 931 | + * @param array $req_data |
|
| 932 | + * @return void |
|
| 933 | + * @throws EE_Error |
|
| 934 | + */ |
|
| 935 | + protected function _normalize($req_data) |
|
| 936 | + { |
|
| 937 | + $this->_received_submission = true; |
|
| 938 | + $this->_validation_errors = array(); |
|
| 939 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 940 | + try { |
|
| 941 | + $subsection->_normalize($req_data); |
|
| 942 | + } catch (EE_Validation_Error $e) { |
|
| 943 | + $subsection->add_validation_error($e); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * Performs validation on this form section and its subsections. |
|
| 951 | + * For each subsection, |
|
| 952 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 953 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 954 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 955 | + * you would be best to override this _validate method, |
|
| 956 | + * calling parent::_validate() first. |
|
| 957 | + * |
|
| 958 | + * @throws EE_Error |
|
| 959 | + */ |
|
| 960 | + protected function _validate() |
|
| 961 | + { |
|
| 962 | + // reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 963 | + $this->is_valid = null; |
|
| 964 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 965 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 966 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 967 | + } |
|
| 968 | + $subsection->_validate(); |
|
| 969 | + } |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + /** |
|
| 974 | + * Gets all the validated inputs for the form section |
|
| 975 | + * |
|
| 976 | + * @return array |
|
| 977 | + * @throws EE_Error |
|
| 978 | + */ |
|
| 979 | + public function valid_data() |
|
| 980 | + { |
|
| 981 | + $inputs = array(); |
|
| 982 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 983 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 984 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 985 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 986 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + return $inputs; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * Gets all the inputs on this form section |
|
| 995 | + * |
|
| 996 | + * @return EE_Form_Input_Base[] |
|
| 997 | + * @throws EE_Error |
|
| 998 | + */ |
|
| 999 | + public function inputs() |
|
| 1000 | + { |
|
| 1001 | + $inputs = array(); |
|
| 1002 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1003 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1004 | + $inputs[ $subsection_name ] = $subsection; |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + return $inputs; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * Gets all the subsections which are a proper form |
|
| 1013 | + * |
|
| 1014 | + * @return EE_Form_Section_Proper[] |
|
| 1015 | + * @throws EE_Error |
|
| 1016 | + */ |
|
| 1017 | + public function subforms() |
|
| 1018 | + { |
|
| 1019 | + $form_sections = array(); |
|
| 1020 | + foreach ($this->subsections() as $name => $obj) { |
|
| 1021 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1022 | + $form_sections[ $name ] = $obj; |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + return $form_sections; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + |
|
| 1029 | + /** |
|
| 1030 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1031 | + * Consider using inputs() or subforms() |
|
| 1032 | + * if you only want form inputs or proper form sections. |
|
| 1033 | + * |
|
| 1034 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1035 | + * leave this as TRUE so that the inputs will be properly |
|
| 1036 | + * configured. However, some client code may be ok with |
|
| 1037 | + * construction finalize being called later |
|
| 1038 | + * (realizing that the subsections' html names might not be |
|
| 1039 | + * set yet, etc.) |
|
| 1040 | + * @return EE_Form_Section_Proper[] |
|
| 1041 | + * @throws EE_Error |
|
| 1042 | + */ |
|
| 1043 | + public function subsections($require_construction_to_be_finalized = true) |
|
| 1044 | + { |
|
| 1045 | + if ($require_construction_to_be_finalized) { |
|
| 1046 | + $this->ensure_construct_finalized_called(); |
|
| 1047 | + } |
|
| 1048 | + return $this->_subsections; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * Returns whether this form has any subforms or inputs |
|
| 1054 | + * @return bool |
|
| 1055 | + */ |
|
| 1056 | + public function hasSubsections() |
|
| 1057 | + { |
|
| 1058 | + return ! empty($this->_subsections); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + |
|
| 1062 | + /** |
|
| 1063 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 1064 | + * values. (Similar to calling get_input_value on inputs) |
|
| 1065 | + * |
|
| 1066 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1067 | + * or just this forms' direct children inputs |
|
| 1068 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1069 | + * or allow multidimensional array |
|
| 1070 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1071 | + * with array keys being input names |
|
| 1072 | + * (regardless of whether they are from a subsection or not), |
|
| 1073 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1074 | + * where keys are always subsection names and values are either |
|
| 1075 | + * the input's normalized value, or an array like the top-level array |
|
| 1076 | + * @throws EE_Error |
|
| 1077 | + */ |
|
| 1078 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1079 | + { |
|
| 1080 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + /** |
|
| 1085 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1086 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1087 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 1088 | + * where keys are the input names, and values are their display values |
|
| 1089 | + * |
|
| 1090 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1091 | + * or just this forms' direct children inputs |
|
| 1092 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1093 | + * or allow multidimensional array |
|
| 1094 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1095 | + * with array keys being input names |
|
| 1096 | + * (regardless of whether they are from a subsection or not), |
|
| 1097 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1098 | + * where keys are always subsection names and values are either |
|
| 1099 | + * the input's normalized value, or an array like the top-level array |
|
| 1100 | + * @throws EE_Error |
|
| 1101 | + */ |
|
| 1102 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1103 | + { |
|
| 1104 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Gets the input values from the form |
|
| 1110 | + * |
|
| 1111 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1112 | + * or just the normalized value |
|
| 1113 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1114 | + * or just this forms' direct children inputs |
|
| 1115 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1116 | + * or allow multidimensional array |
|
| 1117 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1118 | + * input names (regardless of whether they are from a subsection or not), |
|
| 1119 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1120 | + * where keys are always subsection names and values are either |
|
| 1121 | + * the input's normalized value, or an array like the top-level array |
|
| 1122 | + * @throws EE_Error |
|
| 1123 | + */ |
|
| 1124 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1125 | + { |
|
| 1126 | + $input_values = array(); |
|
| 1127 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1128 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1129 | + $input_values[ $subsection_name ] = $pretty |
|
| 1130 | + ? $subsection->pretty_value() |
|
| 1131 | + : $subsection->normalized_value(); |
|
| 1132 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1133 | + $subform_input_values = $subsection->_input_values( |
|
| 1134 | + $pretty, |
|
| 1135 | + $include_subform_inputs, |
|
| 1136 | + $flatten |
|
| 1137 | + ); |
|
| 1138 | + if ($flatten) { |
|
| 1139 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1140 | + } else { |
|
| 1141 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + return $input_values; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Gets the originally submitted input values from the form |
|
| 1151 | + * |
|
| 1152 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1153 | + * or just this forms' direct children inputs |
|
| 1154 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1155 | + * with array keys being input names |
|
| 1156 | + * (regardless of whether they are from a subsection or not), |
|
| 1157 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1158 | + * where keys are always subsection names and values are either |
|
| 1159 | + * the input's normalized value, or an array like the top-level array |
|
| 1160 | + * @throws EE_Error |
|
| 1161 | + */ |
|
| 1162 | + public function submitted_values($include_subforms = false) |
|
| 1163 | + { |
|
| 1164 | + $submitted_values = array(); |
|
| 1165 | + foreach ($this->subsections() as $subsection) { |
|
| 1166 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1167 | + // is this input part of an array of inputs? |
|
| 1168 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1169 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1170 | + explode( |
|
| 1171 | + '[', |
|
| 1172 | + str_replace(']', '', $subsection->html_name()) |
|
| 1173 | + ), |
|
| 1174 | + $subsection->raw_value() |
|
| 1175 | + ); |
|
| 1176 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1177 | + } else { |
|
| 1178 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1179 | + } |
|
| 1180 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1181 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1182 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | + return $submitted_values; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + |
|
| 1189 | + /** |
|
| 1190 | + * Indicates whether or not this form has received a submission yet |
|
| 1191 | + * (ie, had receive_form_submission called on it yet) |
|
| 1192 | + * |
|
| 1193 | + * @return boolean |
|
| 1194 | + * @throws EE_Error |
|
| 1195 | + */ |
|
| 1196 | + public function has_received_submission() |
|
| 1197 | + { |
|
| 1198 | + $this->ensure_construct_finalized_called(); |
|
| 1199 | + return $this->_received_submission; |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + |
|
| 1203 | + /** |
|
| 1204 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1205 | + * Removes the listed inputs from the form |
|
| 1206 | + * |
|
| 1207 | + * @param array $inputs_to_exclude values are the input names |
|
| 1208 | + * @return void |
|
| 1209 | + */ |
|
| 1210 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1211 | + { |
|
| 1212 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1213 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1220 | + * @param array $inputs_to_hide |
|
| 1221 | + * @throws EE_Error |
|
| 1222 | + */ |
|
| 1223 | + public function hide(array $inputs_to_hide = array()) |
|
| 1224 | + { |
|
| 1225 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1226 | + $input = $this->get_input($input_to_hide); |
|
| 1227 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * add_subsections |
|
| 1234 | + * Adds the listed subsections to the form section. |
|
| 1235 | + * If $subsection_name_to_target is provided, |
|
| 1236 | + * then new subsections are added before or after that subsection, |
|
| 1237 | + * otherwise to the start or end of the entire subsections array. |
|
| 1238 | + * |
|
| 1239 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1240 | + * where keys are their names |
|
| 1241 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1242 | + * should be added before or after |
|
| 1243 | + * IF $subsection_name_to_target is null, |
|
| 1244 | + * then $new_subsections will be added to |
|
| 1245 | + * the beginning or end of the entire subsections array |
|
| 1246 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1247 | + * $subsection_name_to_target, |
|
| 1248 | + * or if $subsection_name_to_target is null, |
|
| 1249 | + * before or after entire subsections array |
|
| 1250 | + * @return void |
|
| 1251 | + * @throws EE_Error |
|
| 1252 | + */ |
|
| 1253 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1254 | + { |
|
| 1255 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1256 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1257 | + EE_Error::add_error( |
|
| 1258 | + sprintf( |
|
| 1259 | + esc_html__( |
|
| 1260 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1261 | + 'event_espresso' |
|
| 1262 | + ), |
|
| 1263 | + get_class($subsection), |
|
| 1264 | + $subsection_name, |
|
| 1265 | + $this->name() |
|
| 1266 | + ) |
|
| 1267 | + ); |
|
| 1268 | + unset($new_subsections[ $subsection_name ]); |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1272 | + $this->_subsections, |
|
| 1273 | + $new_subsections, |
|
| 1274 | + $subsection_name_to_target, |
|
| 1275 | + $add_before |
|
| 1276 | + ); |
|
| 1277 | + if ($this->_construction_finalized) { |
|
| 1278 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1279 | + $subsection->_construct_finalize($this, $name); |
|
| 1280 | + } |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * @param string $subsection_name |
|
| 1287 | + * @param bool $recursive |
|
| 1288 | + * @return bool |
|
| 1289 | + */ |
|
| 1290 | + public function has_subsection($subsection_name, $recursive = false) |
|
| 1291 | + { |
|
| 1292 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1293 | + if ( |
|
| 1294 | + $name === $subsection_name |
|
| 1295 | + || ( |
|
| 1296 | + $recursive |
|
| 1297 | + && $subsection instanceof EE_Form_Section_Proper |
|
| 1298 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1299 | + ) |
|
| 1300 | + ) { |
|
| 1301 | + return true; |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | + return false; |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1311 | + * |
|
| 1312 | + * @throws EE_Error |
|
| 1313 | + */ |
|
| 1314 | + public function clean_sensitive_data() |
|
| 1315 | + { |
|
| 1316 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1317 | + $subsection->clean_sensitive_data(); |
|
| 1318 | + } |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + |
|
| 1322 | + /** |
|
| 1323 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1324 | + * @param string $form_submission_error_message |
|
| 1325 | + * @param EE_Form_Section_Validatable $form_section unused |
|
| 1326 | + * @throws EE_Error |
|
| 1327 | + */ |
|
| 1328 | + public function set_submission_error_message( |
|
| 1329 | + $form_submission_error_message = '' |
|
| 1330 | + ) { |
|
| 1331 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1332 | + ? $form_submission_error_message |
|
| 1333 | + : $this->getAllValidationErrorsString(); |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + |
|
| 1337 | + /** |
|
| 1338 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1339 | + * (called during receive_form_submission) but it can be explicitly set using |
|
| 1340 | + * set_submission_error_message |
|
| 1341 | + * |
|
| 1342 | + * @return string |
|
| 1343 | + */ |
|
| 1344 | + public function submission_error_message() |
|
| 1345 | + { |
|
| 1346 | + return $this->_form_submission_error_message; |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * Sets a message to display if the data submitted to the form was valid. |
|
| 1352 | + * @param string $form_submission_success_message |
|
| 1353 | + */ |
|
| 1354 | + public function set_submission_success_message($form_submission_success_message = '') |
|
| 1355 | + { |
|
| 1356 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1357 | + ? $form_submission_success_message |
|
| 1358 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Gets a message appropriate for display when the form is correctly submitted |
|
| 1364 | + * @return string |
|
| 1365 | + */ |
|
| 1366 | + public function submission_success_message() |
|
| 1367 | + { |
|
| 1368 | + return $this->_form_submission_success_message; |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + |
|
| 1372 | + /** |
|
| 1373 | + * Returns the prefix that should be used on child of this form section for |
|
| 1374 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1375 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1376 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1377 | + * |
|
| 1378 | + * @return string |
|
| 1379 | + * @throws EE_Error |
|
| 1380 | + */ |
|
| 1381 | + public function html_name_prefix() |
|
| 1382 | + { |
|
| 1383 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1384 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1385 | + } |
|
| 1386 | + return $this->name(); |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1392 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1393 | + * was set, which is probably nothing, or the classname) |
|
| 1394 | + * |
|
| 1395 | + * @return string |
|
| 1396 | + * @throws EE_Error |
|
| 1397 | + */ |
|
| 1398 | + public function name() |
|
| 1399 | + { |
|
| 1400 | + $this->ensure_construct_finalized_called(); |
|
| 1401 | + return parent::name(); |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + |
|
| 1405 | + /** |
|
| 1406 | + * @return EE_Form_Section_Proper |
|
| 1407 | + * @throws EE_Error |
|
| 1408 | + */ |
|
| 1409 | + public function parent_section() |
|
| 1410 | + { |
|
| 1411 | + $this->ensure_construct_finalized_called(); |
|
| 1412 | + return parent::parent_section(); |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1418 | + * |
|
| 1419 | + * @return void |
|
| 1420 | + * @throws EE_Error |
|
| 1421 | + */ |
|
| 1422 | + public function ensure_construct_finalized_called() |
|
| 1423 | + { |
|
| 1424 | + if (! $this->_construction_finalized) { |
|
| 1425 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1426 | + } |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + |
|
| 1430 | + /** |
|
| 1431 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1432 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1433 | + * |
|
| 1434 | + * @param array $req_data |
|
| 1435 | + * @return boolean |
|
| 1436 | + * @throws EE_Error |
|
| 1437 | + */ |
|
| 1438 | + public function form_data_present_in($req_data = null) |
|
| 1439 | + { |
|
| 1440 | + $req_data = $this->getCachedRequest($req_data); |
|
| 1441 | + foreach ($this->subsections() as $subsection) { |
|
| 1442 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1443 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1444 | + return true; |
|
| 1445 | + } |
|
| 1446 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1447 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1448 | + return true; |
|
| 1449 | + } |
|
| 1450 | + } |
|
| 1451 | + } |
|
| 1452 | + return false; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + |
|
| 1456 | + /** |
|
| 1457 | + * Gets validation errors for this form section and subsections |
|
| 1458 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1459 | + * gets the validation errors for ALL subsection |
|
| 1460 | + * |
|
| 1461 | + * @return EE_Validation_Error[] |
|
| 1462 | + * @throws EE_Error |
|
| 1463 | + */ |
|
| 1464 | + public function get_validation_errors_accumulated() |
|
| 1465 | + { |
|
| 1466 | + $validation_errors = $this->get_validation_errors(); |
|
| 1467 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1468 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1469 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1470 | + } else { |
|
| 1471 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1472 | + } |
|
| 1473 | + if ($validation_errors_on_this_subsection) { |
|
| 1474 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1475 | + } |
|
| 1476 | + } |
|
| 1477 | + return $validation_errors; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + /** |
|
| 1481 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1482 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1483 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1484 | + * |
|
| 1485 | + * @return string |
|
| 1486 | + * @since 4.9.59.p |
|
| 1487 | + */ |
|
| 1488 | + protected function getAllValidationErrorsString() |
|
| 1489 | + { |
|
| 1490 | + $submission_error_messages = array(); |
|
| 1491 | + // bad, bad, bad registrant |
|
| 1492 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1493 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1494 | + $form_section = $validation_error->get_form_section(); |
|
| 1495 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1496 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1497 | + } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1498 | + $label = $validation_error->get_form_section()->name(); |
|
| 1499 | + } else { |
|
| 1500 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1501 | + } |
|
| 1502 | + $submission_error_messages[] = sprintf( |
|
| 1503 | + esc_html__('%s : %s', 'event_espresso'), |
|
| 1504 | + $label, |
|
| 1505 | + $validation_error->getMessage() |
|
| 1506 | + ); |
|
| 1507 | + } |
|
| 1508 | + } |
|
| 1509 | + return implode('<br>', $submission_error_messages); |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1515 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1516 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1517 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1518 | + * which will be returned. |
|
| 1519 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1520 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1521 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1522 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1523 | + * Etc |
|
| 1524 | + * |
|
| 1525 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1526 | + * @return EE_Form_Section_Base |
|
| 1527 | + * @throws EE_Error |
|
| 1528 | + */ |
|
| 1529 | + public function find_section_from_path($form_section_path) |
|
| 1530 | + { |
|
| 1531 | + // check if we can find the input from purely going straight up the tree |
|
| 1532 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1533 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1534 | + return $input; |
|
| 1535 | + } |
|
| 1536 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1537 | + if ($next_slash_pos !== false) { |
|
| 1538 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1539 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1540 | + } else { |
|
| 1541 | + $child_section_name = $form_section_path; |
|
| 1542 | + $subpath = ''; |
|
| 1543 | + } |
|
| 1544 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1545 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1546 | + return $child_section->find_section_from_path($subpath); |
|
| 1547 | + } |
|
| 1548 | + return null; |
|
| 1549 | + } |
|
| 1550 | 1550 | } |
@@ -2,25 +2,25 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class EE_Switch_Display_Strategy extends EE_Compound_Input_Display_Strategy |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * returns HTML and javascript related to the displaying of this input |
|
| 7 | - * |
|
| 8 | - * @return string |
|
| 9 | - * @throws EE_Error |
|
| 10 | - */ |
|
| 11 | - public function display(): string |
|
| 12 | - { |
|
| 13 | - $input = $this->get_input(); |
|
| 14 | - $input_raw_value = $input->raw_value(); |
|
| 5 | + /** |
|
| 6 | + * returns HTML and javascript related to the displaying of this input |
|
| 7 | + * |
|
| 8 | + * @return string |
|
| 9 | + * @throws EE_Error |
|
| 10 | + */ |
|
| 11 | + public function display(): string |
|
| 12 | + { |
|
| 13 | + $input = $this->get_input(); |
|
| 14 | + $input_raw_value = $input->raw_value(); |
|
| 15 | 15 | |
| 16 | - $html = ' |
|
| 16 | + $html = ' |
|
| 17 | 17 | <div class="ee-switch">'; |
| 18 | 18 | |
| 19 | - $html_id = $this->get_sub_input_id(1); |
|
| 20 | - $checked = $input_raw_value === EE_Switch_Input::OPTION_ON ? 'checked' : ''; |
|
| 21 | - $switch_value = EE_Switch_Input::OPTION_ON; |
|
| 19 | + $html_id = $this->get_sub_input_id(1); |
|
| 20 | + $checked = $input_raw_value === EE_Switch_Input::OPTION_ON ? 'checked' : ''; |
|
| 21 | + $switch_value = EE_Switch_Input::OPTION_ON; |
|
| 22 | 22 | |
| 23 | - $html .= " |
|
| 23 | + $html .= " |
|
| 24 | 24 | <input type='checkbox' |
| 25 | 25 | class='{$input->html_class()} ee-switch__input' |
| 26 | 26 | id='$html_id' |
@@ -34,15 +34,15 @@ discard block |
||
| 34 | 34 | <div class='ee-switch__label'> |
| 35 | 35 | "; |
| 36 | 36 | |
| 37 | - foreach ($input->options() as $value => $display_text) { |
|
| 38 | - $html .= " |
|
| 37 | + foreach ($input->options() as $value => $display_text) { |
|
| 38 | + $html .= " |
|
| 39 | 39 | <span class='ee-switch--$value'>$display_text</span>"; |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $html .= ' |
|
| 42 | + $html .= ' |
|
| 43 | 43 | </div> |
| 44 | 44 | </div>'; |
| 45 | 45 | |
| 46 | - return $html; |
|
| 47 | - } |
|
| 46 | + return $html; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -39,623 +39,623 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class RegistrationsReport extends JobHandlerFile |
| 41 | 41 | { |
| 42 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 43 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 44 | - /** |
|
| 45 | - * Performs any necessary setup for starting the job. This is also a good |
|
| 46 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 47 | - * when continue_job will be called |
|
| 48 | - * |
|
| 49 | - * @param JobParameters $job_parameters |
|
| 50 | - * @return JobStepResponse |
|
| 51 | - * @throws BatchRequestException |
|
| 52 | - * @throws EE_Error |
|
| 53 | - * @throws ReflectionException |
|
| 54 | - */ |
|
| 55 | - public function create_job(JobParameters $job_parameters) |
|
| 56 | - { |
|
| 57 | - $event_id = absint($job_parameters->request_datum('EVT_ID', '0')); |
|
| 58 | - if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 59 | - throw new BatchRequestException( |
|
| 60 | - esc_html__('You do not have permission to view registrations', 'event_espresso') |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - $filepath = $this->create_file_from_job_with_name( |
|
| 64 | - $job_parameters->job_id(), |
|
| 65 | - $this->get_filename() |
|
| 66 | - ); |
|
| 67 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
| 68 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
| 69 | - $query_params = maybe_unserialize($job_parameters->request_datum('filters', [])); |
|
| 70 | - } else { |
|
| 71 | - $query_params = apply_filters( |
|
| 72 | - 'FHEE__EE_Export__report_registration_for_event', |
|
| 73 | - [ |
|
| 74 | - [ |
|
| 75 | - 'OR' => [ |
|
| 76 | - // don't include registrations from failed or abandoned transactions... |
|
| 77 | - 'Transaction.STS_ID' => [ |
|
| 78 | - 'NOT IN', |
|
| 79 | - [ |
|
| 80 | - EEM_Transaction::failed_status_code, |
|
| 81 | - EEM_Transaction::abandoned_status_code, |
|
| 82 | - ], |
|
| 83 | - ], |
|
| 84 | - // unless the registration is approved, |
|
| 85 | - // in which case include it regardless of transaction status |
|
| 86 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 87 | - ], |
|
| 88 | - 'Ticket.TKT_deleted' => ['IN', [true, false]], |
|
| 89 | - ], |
|
| 90 | - 'order_by' => ['Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'], |
|
| 91 | - 'force_join' => ['Transaction', 'Ticket', 'Attendee'], |
|
| 92 | - 'caps' => EEM_Base::caps_read_admin, |
|
| 93 | - ], |
|
| 94 | - $event_id |
|
| 95 | - ); |
|
| 96 | - if ($event_id) { |
|
| 97 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 98 | - } else { |
|
| 99 | - $query_params['force_join'][] = 'Event'; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - if (! isset($query_params['force_join'])) { |
|
| 104 | - $query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee']; |
|
| 105 | - } |
|
| 106 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
| 107 | - $question_labels = $this->_get_question_labels($query_params); |
|
| 108 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
| 109 | - $job_parameters->set_job_size( |
|
| 110 | - EEM_Registration::instance()->count( |
|
| 111 | - array_diff_key( |
|
| 112 | - $query_params, |
|
| 113 | - array_flip(['limit']) |
|
| 114 | - ) |
|
| 115 | - ) |
|
| 116 | - ); |
|
| 117 | - // we need to set the header columns |
|
| 118 | - // but to do that we need to process one row so that we can extract ALL of the column headers |
|
| 119 | - $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $question_labels, $query_params); |
|
| 120 | - // but we don't want to write any actual data yet... |
|
| 121 | - // so let's blank out all of the values for that first row |
|
| 122 | - array_walk( |
|
| 123 | - $csv_data_for_row[0], |
|
| 124 | - function (&$value) { |
|
| 125 | - $value = null; |
|
| 126 | - } |
|
| 127 | - ); |
|
| 128 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true, true); |
|
| 129 | - $this->updateTextHeader( |
|
| 130 | - esc_html__('Registrations report started successfully...', 'event_espresso') |
|
| 131 | - ); |
|
| 132 | - return new JobStepResponse($job_parameters, $this->feedback); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Gets the filename |
|
| 138 | - * |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - protected function get_filename(): string |
|
| 142 | - { |
|
| 143 | - return apply_filters( |
|
| 144 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
| 145 | - sprintf( |
|
| 146 | - 'event-espresso-registrations-%s.csv', |
|
| 147 | - str_replace([':', ' '], '-', current_time('mysql')) |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Gets the questions which are to be used for this report, so they |
|
| 155 | - * can be remembered for later |
|
| 156 | - * |
|
| 157 | - * @param array $registration_query_params |
|
| 158 | - * @return array question admin labels to be used for this report |
|
| 159 | - * @throws EE_Error |
|
| 160 | - * @throws ReflectionException |
|
| 161 | - */ |
|
| 162 | - protected function _get_question_labels(array $registration_query_params): array |
|
| 163 | - { |
|
| 164 | - $where = $registration_query_params[0] ?? null; |
|
| 165 | - $question_query_params = []; |
|
| 166 | - if ($where !== null) { |
|
| 167 | - $question_query_params = [ |
|
| 168 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
| 169 | - ]; |
|
| 170 | - } |
|
| 171 | - // Make sure it's not a system question |
|
| 172 | - $question_query_params[0]['OR*not-system-questions'] = [ |
|
| 173 | - 'QST_system' => '', |
|
| 174 | - 'QST_system*null' => ['IS_NULL'], |
|
| 175 | - ]; |
|
| 176 | - if ( |
|
| 177 | - apply_filters( |
|
| 178 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
| 179 | - false, |
|
| 180 | - $registration_query_params |
|
| 181 | - ) |
|
| 182 | - ) { |
|
| 183 | - $question_query_params[0]['Answer.ANS_ID'] = ['IS_NOT_NULL']; |
|
| 184 | - } |
|
| 185 | - $question_query_params['group_by'] = ['QST_ID']; |
|
| 186 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Takes where params meant for registrations and changes them to work for questions |
|
| 192 | - * |
|
| 193 | - * @param array $reg_where_params |
|
| 194 | - * @return array |
|
| 195 | - * @throws EE_Error |
|
| 196 | - * @throws ReflectionException |
|
| 197 | - */ |
|
| 198 | - protected function _change_registration_where_params_to_question_where_params(array $reg_where_params): array |
|
| 199 | - { |
|
| 200 | - $question_where_params = []; |
|
| 201 | - foreach ($reg_where_params as $key => $val) { |
|
| 202 | - if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
| 203 | - $question_where_params[ $key ] = |
|
| 204 | - $this->_change_registration_where_params_to_question_where_params($val); |
|
| 205 | - } else { |
|
| 206 | - // it's a normal where condition |
|
| 207 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - return $question_where_params; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Performs another step of the job |
|
| 216 | - * |
|
| 217 | - * @param JobParameters $job_parameters |
|
| 218 | - * @param int $batch_size |
|
| 219 | - * @return JobStepResponse |
|
| 220 | - * @throws EE_Error |
|
| 221 | - * @throws ReflectionException |
|
| 222 | - */ |
|
| 223 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 224 | - { |
|
| 225 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
| 226 | - $csv_data = $this->get_csv_data_for( |
|
| 227 | - $job_parameters->request_datum('EVT_ID', '0'), |
|
| 228 | - $job_parameters->units_processed(), |
|
| 229 | - $batch_size, |
|
| 230 | - $job_parameters->extra_datum('question_labels'), |
|
| 231 | - $job_parameters->extra_datum('query_params') |
|
| 232 | - ); |
|
| 233 | - EEH_Export::write_data_array_to_csv( |
|
| 234 | - $job_parameters->extra_datum('filepath'), |
|
| 235 | - $csv_data, |
|
| 236 | - false |
|
| 237 | - ); |
|
| 238 | - $units_processed = count($csv_data); |
|
| 239 | - if ($units_processed) { |
|
| 240 | - $job_parameters->mark_processed($units_processed); |
|
| 241 | - $this->updateText( |
|
| 242 | - sprintf( |
|
| 243 | - esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
| 244 | - $units_processed |
|
| 245 | - ) |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - $extra_response_data = ['file_url' => '']; |
|
| 250 | - if ($job_parameters->units_processed() >= $job_parameters->job_size()) { |
|
| 251 | - $job_parameters->set_status(JobParameters::status_complete); |
|
| 252 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
| 253 | - $this->displayJobFinalResults($job_parameters); |
|
| 254 | - } else { |
|
| 255 | - $job_parameters->set_status(JobParameters::status_continue); |
|
| 256 | - } |
|
| 257 | - return new JobStepResponse($job_parameters, $this->feedback, $extra_response_data); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Gets the csv data for a batch of registrations |
|
| 263 | - * |
|
| 264 | - * @param int|null $event_id |
|
| 265 | - * @param int $offset |
|
| 266 | - * @param int $limit |
|
| 267 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
| 268 | - * @param array $query_params for using where querying the model |
|
| 269 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
| 270 | - * @throws EE_Error |
|
| 271 | - * @throws ReflectionException |
|
| 272 | - */ |
|
| 273 | - public function get_csv_data_for( |
|
| 274 | - ?int $event_id, |
|
| 275 | - int $offset, |
|
| 276 | - int $limit, |
|
| 277 | - array $question_labels, |
|
| 278 | - array $query_params |
|
| 279 | - ): array { |
|
| 280 | - $reg_fields_to_include = [ |
|
| 281 | - 'TXN_ID', |
|
| 282 | - 'ATT_ID', |
|
| 283 | - 'REG_ID', |
|
| 284 | - 'REG_date', |
|
| 285 | - 'REG_code', |
|
| 286 | - 'REG_count', |
|
| 287 | - 'REG_final_price', |
|
| 288 | - ]; |
|
| 289 | - $att_fields_to_include = [ |
|
| 290 | - 'ATT_fname', |
|
| 291 | - 'ATT_lname', |
|
| 292 | - 'ATT_email', |
|
| 293 | - 'ATT_address', |
|
| 294 | - 'ATT_address2', |
|
| 295 | - 'ATT_city', |
|
| 296 | - 'STA_ID', |
|
| 297 | - 'CNT_ISO', |
|
| 298 | - 'ATT_zip', |
|
| 299 | - 'ATT_phone', |
|
| 300 | - ]; |
|
| 301 | - |
|
| 302 | - // get models |
|
| 303 | - $event_model = EEM_Event::instance(); |
|
| 304 | - $date_model = EEM_Datetime::instance(); |
|
| 305 | - $ticket_model = EEM_Ticket::instance(); |
|
| 306 | - $txn_model = EEM_Transaction::instance(); |
|
| 307 | - $reg_model = EEM_Registration::instance(); |
|
| 308 | - $att_model = EEM_Attendee::instance(); |
|
| 309 | - $pay_model = EEM_Payment::instance(); |
|
| 310 | - $status_model = EEM_Status::instance(); |
|
| 311 | - $qst_model = EEM_Question::instance(); |
|
| 312 | - $answer_model = EEM_Answer::instance(); |
|
| 313 | - $state_model = EEM_State::instance(); |
|
| 314 | - $country_model = EEM_Country::instance(); |
|
| 315 | - |
|
| 316 | - $registrations_csv_ready_array = []; |
|
| 317 | - $query_params['limit'] = [$offset, $limit]; |
|
| 318 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 319 | - |
|
| 320 | - foreach ($registration_rows as $reg_row) { |
|
| 321 | - if (is_array($reg_row)) { |
|
| 322 | - $reg_csv_array = []; |
|
| 323 | - // ALL registrations, or is list filtered to just one? |
|
| 324 | - if (! $event_id) { |
|
| 325 | - // ALL registrations, so get each event's name and ID |
|
| 326 | - $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
| 327 | - /* translators: 1: event name, 2: event ID */ |
|
| 328 | - esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
| 329 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 330 | - $event_model, |
|
| 331 | - 'EVT_name', |
|
| 332 | - $reg_row['Event_CPT.post_title'] |
|
| 333 | - ), |
|
| 334 | - $reg_row['Event_CPT.ID'] |
|
| 335 | - ); |
|
| 336 | - } |
|
| 337 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1'; |
|
| 338 | - |
|
| 339 | - foreach ($reg_fields_to_include as $field_name) { |
|
| 340 | - $field = $reg_model->field_settings_for($field_name); |
|
| 341 | - switch ($field_name) { |
|
| 342 | - case 'REG_final_price': |
|
| 343 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 344 | - $reg_model, |
|
| 345 | - $field_name, |
|
| 346 | - $reg_row['Registration.REG_final_price'], |
|
| 347 | - 'localized_float' |
|
| 348 | - ); |
|
| 349 | - break; |
|
| 350 | - case 'REG_count': |
|
| 351 | - $value = sprintf( |
|
| 352 | - /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
| 353 | - esc_html__('%1$s of %2$s', 'event_espresso'), |
|
| 354 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 355 | - $reg_model, |
|
| 356 | - 'REG_count', |
|
| 357 | - $reg_row['Registration.REG_count'] |
|
| 358 | - ), |
|
| 359 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 360 | - $reg_model, |
|
| 361 | - 'REG_group_size', |
|
| 362 | - $reg_row['Registration.REG_group_size'] |
|
| 363 | - ) |
|
| 364 | - ); |
|
| 365 | - break; |
|
| 366 | - case 'REG_date': |
|
| 367 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 368 | - $reg_model, |
|
| 369 | - $field_name, |
|
| 370 | - $reg_row['Registration.REG_date'], |
|
| 371 | - 'no_html' |
|
| 372 | - ); |
|
| 373 | - break; |
|
| 374 | - default: |
|
| 375 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 376 | - $reg_model, |
|
| 377 | - $field_name, |
|
| 378 | - $reg_row[ $field->get_qualified_column() ] |
|
| 379 | - ); |
|
| 380 | - } |
|
| 381 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
| 382 | - if ($field_name == 'REG_final_price') { |
|
| 383 | - // add a column named Currency after the final price |
|
| 384 | - $reg_csv_array[ esc_html__('Currency', 'event_espresso') ] = |
|
| 385 | - EE_Config::instance()->currency->code; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - // get pretty status |
|
| 390 | - $stati = $status_model->localized_status( |
|
| 391 | - [ |
|
| 392 | - $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
| 393 | - $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
| 394 | - ], |
|
| 395 | - false, |
|
| 396 | - 'sentence' |
|
| 397 | - ); |
|
| 398 | - |
|
| 399 | - $reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] = |
|
| 400 | - $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 401 | - // get pretty transaction status |
|
| 402 | - $reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ] = |
|
| 403 | - $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 404 | - $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 405 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
| 406 | - $txn_model, |
|
| 407 | - 'TXN_total', |
|
| 408 | - $reg_row['TransactionTable.TXN_total'], |
|
| 409 | - 'localized_float' |
|
| 410 | - ) |
|
| 411 | - : '0.00'; |
|
| 412 | - |
|
| 413 | - $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 414 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
| 415 | - $txn_model, |
|
| 416 | - 'TXN_paid', |
|
| 417 | - $reg_row['TransactionTable.TXN_paid'], |
|
| 418 | - 'localized_float' |
|
| 419 | - ) |
|
| 420 | - : '0.00'; |
|
| 421 | - |
|
| 422 | - $payment_methods = []; |
|
| 423 | - $gateway_txn_ids_etc = []; |
|
| 424 | - $payment_times = []; |
|
| 425 | - |
|
| 426 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 427 | - $payments_info = $pay_model->get_all_wpdb_results( |
|
| 428 | - [ |
|
| 429 | - [ |
|
| 430 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 431 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
| 432 | - ], |
|
| 433 | - 'force_join' => ['Payment_Method'], |
|
| 434 | - ], |
|
| 435 | - ARRAY_A, |
|
| 436 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
| 437 | - ); |
|
| 438 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 439 | - $payment_methods[] = $payment_method_and_gateway_txn_id['name'] |
|
| 440 | - ?? esc_html__('Unknown', 'event_espresso'); |
|
| 441 | - $gateway_txn_ids_etc[] = $payment_method_and_gateway_txn_id['gateway_txn_id'] ?? ''; |
|
| 442 | - $payment_times[] = $payment_method_and_gateway_txn_id['payment_time'] ?? ''; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode( |
|
| 446 | - ',', |
|
| 447 | - $payment_times |
|
| 448 | - ); |
|
| 449 | - |
|
| 450 | - $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode( |
|
| 451 | - ',', |
|
| 452 | - $payment_methods |
|
| 453 | - ); |
|
| 454 | - |
|
| 455 | - $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 456 | - ',', |
|
| 457 | - $gateway_txn_ids_etc |
|
| 458 | - ); |
|
| 459 | - |
|
| 460 | - // get whether or not the user has checked in |
|
| 461 | - $reg_csv_array[ esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related( |
|
| 462 | - $reg_row['Registration.REG_ID'], |
|
| 463 | - 'Checkin' |
|
| 464 | - ); |
|
| 465 | - |
|
| 466 | - $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
| 467 | - $datetime_strings = [esc_html__('Unknown', 'event_espresso')]; |
|
| 468 | - |
|
| 469 | - // get ticket of registration and its price |
|
| 470 | - if ($reg_row['Ticket.TKT_ID']) { |
|
| 471 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
| 472 | - $ticket_model, |
|
| 473 | - 'TKT_name', |
|
| 474 | - $reg_row['Ticket.TKT_name'] |
|
| 475 | - ); |
|
| 476 | - $datetime_strings = []; |
|
| 477 | - $datetimes = $date_model->get_all_wpdb_results( |
|
| 478 | - [ |
|
| 479 | - ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']], |
|
| 480 | - 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
| 481 | - 'default_where_conditions' => 'none', |
|
| 482 | - ] |
|
| 483 | - ); |
|
| 484 | - foreach ($datetimes as $datetime) { |
|
| 485 | - $datetime_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
| 486 | - $date_model, |
|
| 487 | - 'DTT_EVT_start', |
|
| 488 | - $datetime['Datetime.DTT_EVT_start'] |
|
| 489 | - ); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 494 | - |
|
| 495 | - $reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode( |
|
| 496 | - ', ', |
|
| 497 | - $datetime_strings |
|
| 498 | - ); |
|
| 499 | - |
|
| 500 | - // get datetime(s) of registration |
|
| 501 | - // add attendee columns |
|
| 502 | - foreach ($att_fields_to_include as $att_field_name) { |
|
| 503 | - $field_obj = $att_model->field_settings_for($att_field_name); |
|
| 504 | - $value = ''; |
|
| 505 | - if ($reg_row['Attendee_CPT.ID']) { |
|
| 506 | - switch ($att_field_name) { |
|
| 507 | - case 'STA_ID': |
|
| 508 | - $value = $state_model->get_var( |
|
| 509 | - [['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]], |
|
| 510 | - 'STA_name' |
|
| 511 | - ); |
|
| 512 | - break; |
|
| 513 | - case 'CNT_ISO': |
|
| 514 | - $value = $country_model->get_var( |
|
| 515 | - [['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]], |
|
| 516 | - 'CNT_name' |
|
| 517 | - ); |
|
| 518 | - break; |
|
| 519 | - default: |
|
| 520 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 521 | - $att_model, |
|
| 522 | - $att_field_name, |
|
| 523 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
| 524 | - ); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
| 528 | - } |
|
| 529 | - // make sure each registration has the same questions in the same order |
|
| 530 | - foreach ($question_labels as $question_label) { |
|
| 531 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
| 532 | - $reg_csv_array[ $question_label ] = null; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - $answers = $answer_model->get_all_wpdb_results( |
|
| 536 | - [ |
|
| 537 | - ['REG_ID' => $reg_row['Registration.REG_ID']], |
|
| 538 | - 'force_join' => ['Question'], |
|
| 539 | - ] |
|
| 540 | - ); |
|
| 541 | - // now fill out the questions THEY answered |
|
| 542 | - foreach ($answers as $answer_row) { |
|
| 543 | - if ($answer_row['Question.QST_system']) { |
|
| 544 | - // it's an answer to a system question. That was already displayed as part of the attendee |
|
| 545 | - // fields, so don't write it out again thanks. |
|
| 546 | - continue; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - $question_label = $answer_row['Question.QST_ID'] |
|
| 550 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
| 551 | - $qst_model, |
|
| 552 | - 'QST_admin_label', |
|
| 553 | - $answer_row['Question.QST_admin_label'] |
|
| 554 | - ) |
|
| 555 | - : sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 556 | - |
|
| 557 | - $reg_csv_array[ $question_label ] = isset($answer_row['Question.QST_type']) |
|
| 558 | - && $answer_row['Question.QST_type'] |
|
| 559 | - === EEM_Question::QST_type_state |
|
| 560 | - ? $state_model->get_state_name_by_ID($answer_row['Answer.ANS_value']) |
|
| 561 | - // this isn't for html, so don't show html entities |
|
| 562 | - : html_entity_decode( |
|
| 563 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 564 | - $answer_model, |
|
| 565 | - 'ANS_value', |
|
| 566 | - $answer_row['Answer.ANS_value'] |
|
| 567 | - ) |
|
| 568 | - ); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
| 573 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
| 574 | - * Note when using: all rows in the CSV should have the same columns. |
|
| 575 | - * |
|
| 576 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
| 577 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
| 578 | - */ |
|
| 579 | - $registrations_csv_ready_array[] = apply_filters( |
|
| 580 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
| 581 | - $reg_csv_array, |
|
| 582 | - $reg_row |
|
| 583 | - ); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - // if we couldn't export anything, we want to at least show the column headers |
|
| 588 | - if (empty($registrations_csv_ready_array)) { |
|
| 589 | - $reg_csv_array = []; |
|
| 590 | - $model_and_fields_to_include = [ |
|
| 591 | - 'Registration' => $reg_fields_to_include, |
|
| 592 | - 'Attendee' => $att_fields_to_include, |
|
| 593 | - ]; |
|
| 594 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 595 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 596 | - foreach ($field_list as $field_name) { |
|
| 597 | - $field = |
|
| 598 | - $model->field_settings_for($field_name); |
|
| 599 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
| 603 | - } |
|
| 604 | - return $registrations_csv_ready_array; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Counts total unit to process |
|
| 610 | - * |
|
| 611 | - * @param int|array $event_id |
|
| 612 | - * @return int |
|
| 613 | - * @throws EE_Error |
|
| 614 | - * @throws ReflectionException |
|
| 615 | - * @deprecated since 4.9.19 |
|
| 616 | - */ |
|
| 617 | - public function count_units_to_process($event_id): int |
|
| 618 | - { |
|
| 619 | - // use the legacy filter |
|
| 620 | - if ($event_id) { |
|
| 621 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 622 | - } else { |
|
| 623 | - $query_params['force_join'][] = 'Event'; |
|
| 624 | - } |
|
| 625 | - return EEM_Registration::instance()->count($query_params); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Performs any clean-up logic when we know the job is completed. |
|
| 631 | - * In this case, we delete the temporary file |
|
| 632 | - * |
|
| 633 | - * @param JobParameters $job_parameters |
|
| 634 | - * @return JobStepResponse |
|
| 635 | - */ |
|
| 636 | - public function cleanup_job(JobParameters $job_parameters) |
|
| 637 | - { |
|
| 638 | - $this->updateText(esc_html__('File Generation complete and downloaded', 'event_espresso')); |
|
| 639 | - $this->_file_helper->delete( |
|
| 640 | - EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
| 641 | - true, |
|
| 642 | - 'd' |
|
| 643 | - ); |
|
| 644 | - $this->updateText(esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
| 645 | - $this->updateText( |
|
| 646 | - $this->infoWrapper( |
|
| 647 | - sprintf( |
|
| 648 | - esc_html__( |
|
| 649 | - 'If not automatically redirected in %1$s seconds, click here to return to the %2$sRegistrations List Table%3$s', |
|
| 650 | - 'event_espresso' |
|
| 651 | - ), |
|
| 652 | - '<span id="ee-redirect-timer">10</span>', |
|
| 653 | - '<a href="' . $job_parameters->request_datum('return_url') . '">', |
|
| 654 | - '</a>' |
|
| 655 | - ) |
|
| 656 | - ) |
|
| 657 | - ); |
|
| 658 | - |
|
| 659 | - return new JobStepResponse($job_parameters, $this->feedback); |
|
| 660 | - } |
|
| 42 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 43 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 44 | + /** |
|
| 45 | + * Performs any necessary setup for starting the job. This is also a good |
|
| 46 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 47 | + * when continue_job will be called |
|
| 48 | + * |
|
| 49 | + * @param JobParameters $job_parameters |
|
| 50 | + * @return JobStepResponse |
|
| 51 | + * @throws BatchRequestException |
|
| 52 | + * @throws EE_Error |
|
| 53 | + * @throws ReflectionException |
|
| 54 | + */ |
|
| 55 | + public function create_job(JobParameters $job_parameters) |
|
| 56 | + { |
|
| 57 | + $event_id = absint($job_parameters->request_datum('EVT_ID', '0')); |
|
| 58 | + if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 59 | + throw new BatchRequestException( |
|
| 60 | + esc_html__('You do not have permission to view registrations', 'event_espresso') |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + $filepath = $this->create_file_from_job_with_name( |
|
| 64 | + $job_parameters->job_id(), |
|
| 65 | + $this->get_filename() |
|
| 66 | + ); |
|
| 67 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
| 68 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
| 69 | + $query_params = maybe_unserialize($job_parameters->request_datum('filters', [])); |
|
| 70 | + } else { |
|
| 71 | + $query_params = apply_filters( |
|
| 72 | + 'FHEE__EE_Export__report_registration_for_event', |
|
| 73 | + [ |
|
| 74 | + [ |
|
| 75 | + 'OR' => [ |
|
| 76 | + // don't include registrations from failed or abandoned transactions... |
|
| 77 | + 'Transaction.STS_ID' => [ |
|
| 78 | + 'NOT IN', |
|
| 79 | + [ |
|
| 80 | + EEM_Transaction::failed_status_code, |
|
| 81 | + EEM_Transaction::abandoned_status_code, |
|
| 82 | + ], |
|
| 83 | + ], |
|
| 84 | + // unless the registration is approved, |
|
| 85 | + // in which case include it regardless of transaction status |
|
| 86 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 87 | + ], |
|
| 88 | + 'Ticket.TKT_deleted' => ['IN', [true, false]], |
|
| 89 | + ], |
|
| 90 | + 'order_by' => ['Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'], |
|
| 91 | + 'force_join' => ['Transaction', 'Ticket', 'Attendee'], |
|
| 92 | + 'caps' => EEM_Base::caps_read_admin, |
|
| 93 | + ], |
|
| 94 | + $event_id |
|
| 95 | + ); |
|
| 96 | + if ($event_id) { |
|
| 97 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 98 | + } else { |
|
| 99 | + $query_params['force_join'][] = 'Event'; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + if (! isset($query_params['force_join'])) { |
|
| 104 | + $query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee']; |
|
| 105 | + } |
|
| 106 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
| 107 | + $question_labels = $this->_get_question_labels($query_params); |
|
| 108 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
| 109 | + $job_parameters->set_job_size( |
|
| 110 | + EEM_Registration::instance()->count( |
|
| 111 | + array_diff_key( |
|
| 112 | + $query_params, |
|
| 113 | + array_flip(['limit']) |
|
| 114 | + ) |
|
| 115 | + ) |
|
| 116 | + ); |
|
| 117 | + // we need to set the header columns |
|
| 118 | + // but to do that we need to process one row so that we can extract ALL of the column headers |
|
| 119 | + $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $question_labels, $query_params); |
|
| 120 | + // but we don't want to write any actual data yet... |
|
| 121 | + // so let's blank out all of the values for that first row |
|
| 122 | + array_walk( |
|
| 123 | + $csv_data_for_row[0], |
|
| 124 | + function (&$value) { |
|
| 125 | + $value = null; |
|
| 126 | + } |
|
| 127 | + ); |
|
| 128 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true, true); |
|
| 129 | + $this->updateTextHeader( |
|
| 130 | + esc_html__('Registrations report started successfully...', 'event_espresso') |
|
| 131 | + ); |
|
| 132 | + return new JobStepResponse($job_parameters, $this->feedback); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Gets the filename |
|
| 138 | + * |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + protected function get_filename(): string |
|
| 142 | + { |
|
| 143 | + return apply_filters( |
|
| 144 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
| 145 | + sprintf( |
|
| 146 | + 'event-espresso-registrations-%s.csv', |
|
| 147 | + str_replace([':', ' '], '-', current_time('mysql')) |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Gets the questions which are to be used for this report, so they |
|
| 155 | + * can be remembered for later |
|
| 156 | + * |
|
| 157 | + * @param array $registration_query_params |
|
| 158 | + * @return array question admin labels to be used for this report |
|
| 159 | + * @throws EE_Error |
|
| 160 | + * @throws ReflectionException |
|
| 161 | + */ |
|
| 162 | + protected function _get_question_labels(array $registration_query_params): array |
|
| 163 | + { |
|
| 164 | + $where = $registration_query_params[0] ?? null; |
|
| 165 | + $question_query_params = []; |
|
| 166 | + if ($where !== null) { |
|
| 167 | + $question_query_params = [ |
|
| 168 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
| 169 | + ]; |
|
| 170 | + } |
|
| 171 | + // Make sure it's not a system question |
|
| 172 | + $question_query_params[0]['OR*not-system-questions'] = [ |
|
| 173 | + 'QST_system' => '', |
|
| 174 | + 'QST_system*null' => ['IS_NULL'], |
|
| 175 | + ]; |
|
| 176 | + if ( |
|
| 177 | + apply_filters( |
|
| 178 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
| 179 | + false, |
|
| 180 | + $registration_query_params |
|
| 181 | + ) |
|
| 182 | + ) { |
|
| 183 | + $question_query_params[0]['Answer.ANS_ID'] = ['IS_NOT_NULL']; |
|
| 184 | + } |
|
| 185 | + $question_query_params['group_by'] = ['QST_ID']; |
|
| 186 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Takes where params meant for registrations and changes them to work for questions |
|
| 192 | + * |
|
| 193 | + * @param array $reg_where_params |
|
| 194 | + * @return array |
|
| 195 | + * @throws EE_Error |
|
| 196 | + * @throws ReflectionException |
|
| 197 | + */ |
|
| 198 | + protected function _change_registration_where_params_to_question_where_params(array $reg_where_params): array |
|
| 199 | + { |
|
| 200 | + $question_where_params = []; |
|
| 201 | + foreach ($reg_where_params as $key => $val) { |
|
| 202 | + if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
| 203 | + $question_where_params[ $key ] = |
|
| 204 | + $this->_change_registration_where_params_to_question_where_params($val); |
|
| 205 | + } else { |
|
| 206 | + // it's a normal where condition |
|
| 207 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + return $question_where_params; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Performs another step of the job |
|
| 216 | + * |
|
| 217 | + * @param JobParameters $job_parameters |
|
| 218 | + * @param int $batch_size |
|
| 219 | + * @return JobStepResponse |
|
| 220 | + * @throws EE_Error |
|
| 221 | + * @throws ReflectionException |
|
| 222 | + */ |
|
| 223 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 224 | + { |
|
| 225 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
| 226 | + $csv_data = $this->get_csv_data_for( |
|
| 227 | + $job_parameters->request_datum('EVT_ID', '0'), |
|
| 228 | + $job_parameters->units_processed(), |
|
| 229 | + $batch_size, |
|
| 230 | + $job_parameters->extra_datum('question_labels'), |
|
| 231 | + $job_parameters->extra_datum('query_params') |
|
| 232 | + ); |
|
| 233 | + EEH_Export::write_data_array_to_csv( |
|
| 234 | + $job_parameters->extra_datum('filepath'), |
|
| 235 | + $csv_data, |
|
| 236 | + false |
|
| 237 | + ); |
|
| 238 | + $units_processed = count($csv_data); |
|
| 239 | + if ($units_processed) { |
|
| 240 | + $job_parameters->mark_processed($units_processed); |
|
| 241 | + $this->updateText( |
|
| 242 | + sprintf( |
|
| 243 | + esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
| 244 | + $units_processed |
|
| 245 | + ) |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + $extra_response_data = ['file_url' => '']; |
|
| 250 | + if ($job_parameters->units_processed() >= $job_parameters->job_size()) { |
|
| 251 | + $job_parameters->set_status(JobParameters::status_complete); |
|
| 252 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
| 253 | + $this->displayJobFinalResults($job_parameters); |
|
| 254 | + } else { |
|
| 255 | + $job_parameters->set_status(JobParameters::status_continue); |
|
| 256 | + } |
|
| 257 | + return new JobStepResponse($job_parameters, $this->feedback, $extra_response_data); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Gets the csv data for a batch of registrations |
|
| 263 | + * |
|
| 264 | + * @param int|null $event_id |
|
| 265 | + * @param int $offset |
|
| 266 | + * @param int $limit |
|
| 267 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
| 268 | + * @param array $query_params for using where querying the model |
|
| 269 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
| 270 | + * @throws EE_Error |
|
| 271 | + * @throws ReflectionException |
|
| 272 | + */ |
|
| 273 | + public function get_csv_data_for( |
|
| 274 | + ?int $event_id, |
|
| 275 | + int $offset, |
|
| 276 | + int $limit, |
|
| 277 | + array $question_labels, |
|
| 278 | + array $query_params |
|
| 279 | + ): array { |
|
| 280 | + $reg_fields_to_include = [ |
|
| 281 | + 'TXN_ID', |
|
| 282 | + 'ATT_ID', |
|
| 283 | + 'REG_ID', |
|
| 284 | + 'REG_date', |
|
| 285 | + 'REG_code', |
|
| 286 | + 'REG_count', |
|
| 287 | + 'REG_final_price', |
|
| 288 | + ]; |
|
| 289 | + $att_fields_to_include = [ |
|
| 290 | + 'ATT_fname', |
|
| 291 | + 'ATT_lname', |
|
| 292 | + 'ATT_email', |
|
| 293 | + 'ATT_address', |
|
| 294 | + 'ATT_address2', |
|
| 295 | + 'ATT_city', |
|
| 296 | + 'STA_ID', |
|
| 297 | + 'CNT_ISO', |
|
| 298 | + 'ATT_zip', |
|
| 299 | + 'ATT_phone', |
|
| 300 | + ]; |
|
| 301 | + |
|
| 302 | + // get models |
|
| 303 | + $event_model = EEM_Event::instance(); |
|
| 304 | + $date_model = EEM_Datetime::instance(); |
|
| 305 | + $ticket_model = EEM_Ticket::instance(); |
|
| 306 | + $txn_model = EEM_Transaction::instance(); |
|
| 307 | + $reg_model = EEM_Registration::instance(); |
|
| 308 | + $att_model = EEM_Attendee::instance(); |
|
| 309 | + $pay_model = EEM_Payment::instance(); |
|
| 310 | + $status_model = EEM_Status::instance(); |
|
| 311 | + $qst_model = EEM_Question::instance(); |
|
| 312 | + $answer_model = EEM_Answer::instance(); |
|
| 313 | + $state_model = EEM_State::instance(); |
|
| 314 | + $country_model = EEM_Country::instance(); |
|
| 315 | + |
|
| 316 | + $registrations_csv_ready_array = []; |
|
| 317 | + $query_params['limit'] = [$offset, $limit]; |
|
| 318 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 319 | + |
|
| 320 | + foreach ($registration_rows as $reg_row) { |
|
| 321 | + if (is_array($reg_row)) { |
|
| 322 | + $reg_csv_array = []; |
|
| 323 | + // ALL registrations, or is list filtered to just one? |
|
| 324 | + if (! $event_id) { |
|
| 325 | + // ALL registrations, so get each event's name and ID |
|
| 326 | + $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
| 327 | + /* translators: 1: event name, 2: event ID */ |
|
| 328 | + esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
| 329 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 330 | + $event_model, |
|
| 331 | + 'EVT_name', |
|
| 332 | + $reg_row['Event_CPT.post_title'] |
|
| 333 | + ), |
|
| 334 | + $reg_row['Event_CPT.ID'] |
|
| 335 | + ); |
|
| 336 | + } |
|
| 337 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1'; |
|
| 338 | + |
|
| 339 | + foreach ($reg_fields_to_include as $field_name) { |
|
| 340 | + $field = $reg_model->field_settings_for($field_name); |
|
| 341 | + switch ($field_name) { |
|
| 342 | + case 'REG_final_price': |
|
| 343 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 344 | + $reg_model, |
|
| 345 | + $field_name, |
|
| 346 | + $reg_row['Registration.REG_final_price'], |
|
| 347 | + 'localized_float' |
|
| 348 | + ); |
|
| 349 | + break; |
|
| 350 | + case 'REG_count': |
|
| 351 | + $value = sprintf( |
|
| 352 | + /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
| 353 | + esc_html__('%1$s of %2$s', 'event_espresso'), |
|
| 354 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 355 | + $reg_model, |
|
| 356 | + 'REG_count', |
|
| 357 | + $reg_row['Registration.REG_count'] |
|
| 358 | + ), |
|
| 359 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 360 | + $reg_model, |
|
| 361 | + 'REG_group_size', |
|
| 362 | + $reg_row['Registration.REG_group_size'] |
|
| 363 | + ) |
|
| 364 | + ); |
|
| 365 | + break; |
|
| 366 | + case 'REG_date': |
|
| 367 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 368 | + $reg_model, |
|
| 369 | + $field_name, |
|
| 370 | + $reg_row['Registration.REG_date'], |
|
| 371 | + 'no_html' |
|
| 372 | + ); |
|
| 373 | + break; |
|
| 374 | + default: |
|
| 375 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 376 | + $reg_model, |
|
| 377 | + $field_name, |
|
| 378 | + $reg_row[ $field->get_qualified_column() ] |
|
| 379 | + ); |
|
| 380 | + } |
|
| 381 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
| 382 | + if ($field_name == 'REG_final_price') { |
|
| 383 | + // add a column named Currency after the final price |
|
| 384 | + $reg_csv_array[ esc_html__('Currency', 'event_espresso') ] = |
|
| 385 | + EE_Config::instance()->currency->code; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + // get pretty status |
|
| 390 | + $stati = $status_model->localized_status( |
|
| 391 | + [ |
|
| 392 | + $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
| 393 | + $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
| 394 | + ], |
|
| 395 | + false, |
|
| 396 | + 'sentence' |
|
| 397 | + ); |
|
| 398 | + |
|
| 399 | + $reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] = |
|
| 400 | + $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 401 | + // get pretty transaction status |
|
| 402 | + $reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ] = |
|
| 403 | + $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 404 | + $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 405 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
| 406 | + $txn_model, |
|
| 407 | + 'TXN_total', |
|
| 408 | + $reg_row['TransactionTable.TXN_total'], |
|
| 409 | + 'localized_float' |
|
| 410 | + ) |
|
| 411 | + : '0.00'; |
|
| 412 | + |
|
| 413 | + $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 414 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
| 415 | + $txn_model, |
|
| 416 | + 'TXN_paid', |
|
| 417 | + $reg_row['TransactionTable.TXN_paid'], |
|
| 418 | + 'localized_float' |
|
| 419 | + ) |
|
| 420 | + : '0.00'; |
|
| 421 | + |
|
| 422 | + $payment_methods = []; |
|
| 423 | + $gateway_txn_ids_etc = []; |
|
| 424 | + $payment_times = []; |
|
| 425 | + |
|
| 426 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 427 | + $payments_info = $pay_model->get_all_wpdb_results( |
|
| 428 | + [ |
|
| 429 | + [ |
|
| 430 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 431 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
| 432 | + ], |
|
| 433 | + 'force_join' => ['Payment_Method'], |
|
| 434 | + ], |
|
| 435 | + ARRAY_A, |
|
| 436 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
| 437 | + ); |
|
| 438 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 439 | + $payment_methods[] = $payment_method_and_gateway_txn_id['name'] |
|
| 440 | + ?? esc_html__('Unknown', 'event_espresso'); |
|
| 441 | + $gateway_txn_ids_etc[] = $payment_method_and_gateway_txn_id['gateway_txn_id'] ?? ''; |
|
| 442 | + $payment_times[] = $payment_method_and_gateway_txn_id['payment_time'] ?? ''; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode( |
|
| 446 | + ',', |
|
| 447 | + $payment_times |
|
| 448 | + ); |
|
| 449 | + |
|
| 450 | + $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode( |
|
| 451 | + ',', |
|
| 452 | + $payment_methods |
|
| 453 | + ); |
|
| 454 | + |
|
| 455 | + $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 456 | + ',', |
|
| 457 | + $gateway_txn_ids_etc |
|
| 458 | + ); |
|
| 459 | + |
|
| 460 | + // get whether or not the user has checked in |
|
| 461 | + $reg_csv_array[ esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related( |
|
| 462 | + $reg_row['Registration.REG_ID'], |
|
| 463 | + 'Checkin' |
|
| 464 | + ); |
|
| 465 | + |
|
| 466 | + $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
| 467 | + $datetime_strings = [esc_html__('Unknown', 'event_espresso')]; |
|
| 468 | + |
|
| 469 | + // get ticket of registration and its price |
|
| 470 | + if ($reg_row['Ticket.TKT_ID']) { |
|
| 471 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
| 472 | + $ticket_model, |
|
| 473 | + 'TKT_name', |
|
| 474 | + $reg_row['Ticket.TKT_name'] |
|
| 475 | + ); |
|
| 476 | + $datetime_strings = []; |
|
| 477 | + $datetimes = $date_model->get_all_wpdb_results( |
|
| 478 | + [ |
|
| 479 | + ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']], |
|
| 480 | + 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
| 481 | + 'default_where_conditions' => 'none', |
|
| 482 | + ] |
|
| 483 | + ); |
|
| 484 | + foreach ($datetimes as $datetime) { |
|
| 485 | + $datetime_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
| 486 | + $date_model, |
|
| 487 | + 'DTT_EVT_start', |
|
| 488 | + $datetime['Datetime.DTT_EVT_start'] |
|
| 489 | + ); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 494 | + |
|
| 495 | + $reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode( |
|
| 496 | + ', ', |
|
| 497 | + $datetime_strings |
|
| 498 | + ); |
|
| 499 | + |
|
| 500 | + // get datetime(s) of registration |
|
| 501 | + // add attendee columns |
|
| 502 | + foreach ($att_fields_to_include as $att_field_name) { |
|
| 503 | + $field_obj = $att_model->field_settings_for($att_field_name); |
|
| 504 | + $value = ''; |
|
| 505 | + if ($reg_row['Attendee_CPT.ID']) { |
|
| 506 | + switch ($att_field_name) { |
|
| 507 | + case 'STA_ID': |
|
| 508 | + $value = $state_model->get_var( |
|
| 509 | + [['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]], |
|
| 510 | + 'STA_name' |
|
| 511 | + ); |
|
| 512 | + break; |
|
| 513 | + case 'CNT_ISO': |
|
| 514 | + $value = $country_model->get_var( |
|
| 515 | + [['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]], |
|
| 516 | + 'CNT_name' |
|
| 517 | + ); |
|
| 518 | + break; |
|
| 519 | + default: |
|
| 520 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 521 | + $att_model, |
|
| 522 | + $att_field_name, |
|
| 523 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
| 524 | + ); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
| 528 | + } |
|
| 529 | + // make sure each registration has the same questions in the same order |
|
| 530 | + foreach ($question_labels as $question_label) { |
|
| 531 | + if (! isset($reg_csv_array[ $question_label ])) { |
|
| 532 | + $reg_csv_array[ $question_label ] = null; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + $answers = $answer_model->get_all_wpdb_results( |
|
| 536 | + [ |
|
| 537 | + ['REG_ID' => $reg_row['Registration.REG_ID']], |
|
| 538 | + 'force_join' => ['Question'], |
|
| 539 | + ] |
|
| 540 | + ); |
|
| 541 | + // now fill out the questions THEY answered |
|
| 542 | + foreach ($answers as $answer_row) { |
|
| 543 | + if ($answer_row['Question.QST_system']) { |
|
| 544 | + // it's an answer to a system question. That was already displayed as part of the attendee |
|
| 545 | + // fields, so don't write it out again thanks. |
|
| 546 | + continue; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + $question_label = $answer_row['Question.QST_ID'] |
|
| 550 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
| 551 | + $qst_model, |
|
| 552 | + 'QST_admin_label', |
|
| 553 | + $answer_row['Question.QST_admin_label'] |
|
| 554 | + ) |
|
| 555 | + : sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 556 | + |
|
| 557 | + $reg_csv_array[ $question_label ] = isset($answer_row['Question.QST_type']) |
|
| 558 | + && $answer_row['Question.QST_type'] |
|
| 559 | + === EEM_Question::QST_type_state |
|
| 560 | + ? $state_model->get_state_name_by_ID($answer_row['Answer.ANS_value']) |
|
| 561 | + // this isn't for html, so don't show html entities |
|
| 562 | + : html_entity_decode( |
|
| 563 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 564 | + $answer_model, |
|
| 565 | + 'ANS_value', |
|
| 566 | + $answer_row['Answer.ANS_value'] |
|
| 567 | + ) |
|
| 568 | + ); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
| 573 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
| 574 | + * Note when using: all rows in the CSV should have the same columns. |
|
| 575 | + * |
|
| 576 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
| 577 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
| 578 | + */ |
|
| 579 | + $registrations_csv_ready_array[] = apply_filters( |
|
| 580 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
| 581 | + $reg_csv_array, |
|
| 582 | + $reg_row |
|
| 583 | + ); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + // if we couldn't export anything, we want to at least show the column headers |
|
| 588 | + if (empty($registrations_csv_ready_array)) { |
|
| 589 | + $reg_csv_array = []; |
|
| 590 | + $model_and_fields_to_include = [ |
|
| 591 | + 'Registration' => $reg_fields_to_include, |
|
| 592 | + 'Attendee' => $att_fields_to_include, |
|
| 593 | + ]; |
|
| 594 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 595 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 596 | + foreach ($field_list as $field_name) { |
|
| 597 | + $field = |
|
| 598 | + $model->field_settings_for($field_name); |
|
| 599 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
| 603 | + } |
|
| 604 | + return $registrations_csv_ready_array; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Counts total unit to process |
|
| 610 | + * |
|
| 611 | + * @param int|array $event_id |
|
| 612 | + * @return int |
|
| 613 | + * @throws EE_Error |
|
| 614 | + * @throws ReflectionException |
|
| 615 | + * @deprecated since 4.9.19 |
|
| 616 | + */ |
|
| 617 | + public function count_units_to_process($event_id): int |
|
| 618 | + { |
|
| 619 | + // use the legacy filter |
|
| 620 | + if ($event_id) { |
|
| 621 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 622 | + } else { |
|
| 623 | + $query_params['force_join'][] = 'Event'; |
|
| 624 | + } |
|
| 625 | + return EEM_Registration::instance()->count($query_params); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Performs any clean-up logic when we know the job is completed. |
|
| 631 | + * In this case, we delete the temporary file |
|
| 632 | + * |
|
| 633 | + * @param JobParameters $job_parameters |
|
| 634 | + * @return JobStepResponse |
|
| 635 | + */ |
|
| 636 | + public function cleanup_job(JobParameters $job_parameters) |
|
| 637 | + { |
|
| 638 | + $this->updateText(esc_html__('File Generation complete and downloaded', 'event_espresso')); |
|
| 639 | + $this->_file_helper->delete( |
|
| 640 | + EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
| 641 | + true, |
|
| 642 | + 'd' |
|
| 643 | + ); |
|
| 644 | + $this->updateText(esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
| 645 | + $this->updateText( |
|
| 646 | + $this->infoWrapper( |
|
| 647 | + sprintf( |
|
| 648 | + esc_html__( |
|
| 649 | + 'If not automatically redirected in %1$s seconds, click here to return to the %2$sRegistrations List Table%3$s', |
|
| 650 | + 'event_espresso' |
|
| 651 | + ), |
|
| 652 | + '<span id="ee-redirect-timer">10</span>', |
|
| 653 | + '<a href="' . $job_parameters->request_datum('return_url') . '">', |
|
| 654 | + '</a>' |
|
| 655 | + ) |
|
| 656 | + ) |
|
| 657 | + ); |
|
| 658 | + |
|
| 659 | + return new JobStepResponse($job_parameters, $this->feedback); |
|
| 660 | + } |
|
| 661 | 661 | } |