@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | use EventEspresso\core\exceptions\InvalidFormSubmissionException; |
| 13 | 13 | |
| 14 | 14 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 15 | - exit('No direct script access allowed'); |
|
| 15 | + exit('No direct script access allowed'); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | |
@@ -31,642 +31,642 @@ discard block |
||
| 31 | 31 | abstract class FormHandler implements FormHandlerInterface |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * will add opening and closing HTML form tags as well as a submit button |
|
| 36 | - */ |
|
| 37 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * will add opening and closing HTML form tags but NOT a submit button |
|
| 41 | - */ |
|
| 42 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 46 | - */ |
|
| 47 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 51 | - */ |
|
| 52 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * if set to false, then this form has no displayable content, |
|
| 56 | - * and will only be used for processing data sent passed via GET or POST |
|
| 57 | - * defaults to true ( ie: form has displayable content ) |
|
| 58 | - * |
|
| 59 | - * @var boolean $displayable |
|
| 60 | - */ |
|
| 61 | - private $displayable = true; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var string $form_name |
|
| 65 | - */ |
|
| 66 | - private $form_name; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var string $admin_name |
|
| 70 | - */ |
|
| 71 | - private $admin_name; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var string $slug |
|
| 75 | - */ |
|
| 76 | - private $slug; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var string $submit_btn_text |
|
| 80 | - */ |
|
| 81 | - private $submit_btn_text; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var string $form_action |
|
| 85 | - */ |
|
| 86 | - private $form_action; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * form params in key value pairs |
|
| 90 | - * can be added to form action URL or as hidden inputs |
|
| 91 | - * |
|
| 92 | - * @var array $form_args |
|
| 93 | - */ |
|
| 94 | - private $form_args = array(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * value of one of the string constant above |
|
| 98 | - * |
|
| 99 | - * @var string $form_config |
|
| 100 | - */ |
|
| 101 | - private $form_config; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * whether or not the form was determined to be invalid |
|
| 105 | - * |
|
| 106 | - * @var boolean $form_has_errors |
|
| 107 | - */ |
|
| 108 | - private $form_has_errors; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * the absolute top level form section being used on the page |
|
| 112 | - * |
|
| 113 | - * @var \EE_Form_Section_Proper $form |
|
| 114 | - */ |
|
| 115 | - private $form; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @var \EE_Registry $registry |
|
| 119 | - */ |
|
| 120 | - protected $registry; |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Form constructor. |
|
| 126 | - * |
|
| 127 | - * @param string $form_name |
|
| 128 | - * @param string $admin_name |
|
| 129 | - * @param string $slug |
|
| 130 | - * @param string $form_action |
|
| 131 | - * @param string $form_config |
|
| 132 | - * @param \EE_Registry $registry |
|
| 133 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 134 | - * @throws \DomainException |
|
| 135 | - * @throws \InvalidArgumentException |
|
| 136 | - */ |
|
| 137 | - public function __construct( |
|
| 138 | - $form_name, |
|
| 139 | - $admin_name, |
|
| 140 | - $slug, |
|
| 141 | - $form_action = '', |
|
| 142 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 143 | - \EE_Registry $registry |
|
| 144 | - ) { |
|
| 145 | - $this->setFormName($form_name); |
|
| 146 | - $this->setAdminName($admin_name); |
|
| 147 | - $this->setSlug($slug); |
|
| 148 | - $this->setFormAction($form_action); |
|
| 149 | - $this->setFormConfig($form_config); |
|
| 150 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 151 | - $this->registry = $registry; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - public static function getFormConfigConstants() |
|
| 160 | - { |
|
| 161 | - return array( |
|
| 162 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 163 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 164 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 165 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 166 | - ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param bool $for_display |
|
| 173 | - * @return \EE_Form_Section_Proper |
|
| 174 | - * @throws \EE_Error |
|
| 175 | - * @throws \LogicException |
|
| 176 | - */ |
|
| 177 | - public function form($for_display = false) |
|
| 178 | - { |
|
| 179 | - if (! $this->formIsValid()) { |
|
| 180 | - return null; |
|
| 181 | - } |
|
| 182 | - if ($for_display) { |
|
| 183 | - $form_config = $this->formConfig(); |
|
| 184 | - if ( |
|
| 185 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 186 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 187 | - ) { |
|
| 188 | - $this->appendSubmitButton(); |
|
| 189 | - $this->clearFormButtonFloats(); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - return $this->form; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @return boolean |
|
| 199 | - * @throws LogicException |
|
| 200 | - */ |
|
| 201 | - public function formIsValid() |
|
| 202 | - { |
|
| 203 | - if (! $this->form instanceof \EE_Form_Section_Proper) { |
|
| 204 | - static $generated = false; |
|
| 205 | - if (! $generated) { |
|
| 206 | - $generated = true; |
|
| 207 | - $form = apply_filters( |
|
| 208 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 209 | - $this->generate(), |
|
| 210 | - $this |
|
| 211 | - ); |
|
| 212 | - if ($form instanceof \EE_Form_Section_Proper) { |
|
| 213 | - $this->setForm($form); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - return $this->verifyForm(); |
|
| 217 | - } |
|
| 218 | - return true; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @return boolean |
|
| 225 | - * @throws LogicException |
|
| 226 | - */ |
|
| 227 | - public function verifyForm() |
|
| 228 | - { |
|
| 229 | - if ($this->form instanceof \EE_Form_Section_Proper) { |
|
| 230 | - return true; |
|
| 231 | - } |
|
| 232 | - throw new LogicException( |
|
| 233 | - sprintf( |
|
| 234 | - esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'), |
|
| 235 | - $this->form_name |
|
| 236 | - ) |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param \EE_Form_Section_Proper $form |
|
| 244 | - */ |
|
| 245 | - public function setForm(\EE_Form_Section_Proper $form) |
|
| 246 | - { |
|
| 247 | - $this->form = $form; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @return boolean |
|
| 254 | - */ |
|
| 255 | - public function displayable() |
|
| 256 | - { |
|
| 257 | - return $this->displayable; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param boolean $displayable |
|
| 264 | - */ |
|
| 265 | - public function setDisplayable($displayable = false) |
|
| 266 | - { |
|
| 267 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * a public name for the form that can be displayed on the frontend of a site |
|
| 274 | - * |
|
| 275 | - * @return string |
|
| 276 | - */ |
|
| 277 | - public function formName() |
|
| 278 | - { |
|
| 279 | - return $this->form_name; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @param string $form_name |
|
| 286 | - * @throws InvalidDataTypeException |
|
| 287 | - */ |
|
| 288 | - public function setFormName($form_name) |
|
| 289 | - { |
|
| 290 | - if (! is_string($form_name)) { |
|
| 291 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 292 | - } |
|
| 293 | - $this->form_name = $form_name; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * a public name for the form that can be displayed, but only in the admin |
|
| 300 | - * |
|
| 301 | - * @return string |
|
| 302 | - */ |
|
| 303 | - public function adminName() |
|
| 304 | - { |
|
| 305 | - return $this->admin_name; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param string $admin_name |
|
| 312 | - * @throws InvalidDataTypeException |
|
| 313 | - */ |
|
| 314 | - public function setAdminName($admin_name) |
|
| 315 | - { |
|
| 316 | - if (! is_string($admin_name)) { |
|
| 317 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 318 | - } |
|
| 319 | - $this->admin_name = $admin_name; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * a URL friendly string that can be used for identifying the form |
|
| 326 | - * |
|
| 327 | - * @return string |
|
| 328 | - */ |
|
| 329 | - public function slug() |
|
| 330 | - { |
|
| 331 | - return $this->slug; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param string $slug |
|
| 338 | - * @throws InvalidDataTypeException |
|
| 339 | - */ |
|
| 340 | - public function setSlug($slug) |
|
| 341 | - { |
|
| 342 | - if (! is_string($slug)) { |
|
| 343 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 344 | - } |
|
| 345 | - $this->slug = $slug; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - public function submitBtnText() |
|
| 354 | - { |
|
| 355 | - return $this->submit_btn_text; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @param string $submit_btn_text |
|
| 362 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 363 | - * @throws \InvalidArgumentException |
|
| 364 | - */ |
|
| 365 | - public function setSubmitBtnText($submit_btn_text) |
|
| 366 | - { |
|
| 367 | - if (! is_string($submit_btn_text)) { |
|
| 368 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 369 | - } |
|
| 370 | - if (empty($submit_btn_text)) { |
|
| 371 | - throw new InvalidArgumentException( |
|
| 372 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 373 | - ); |
|
| 374 | - } |
|
| 375 | - $this->submit_btn_text = $submit_btn_text; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @return string |
|
| 382 | - */ |
|
| 383 | - public function formAction() |
|
| 384 | - { |
|
| 385 | - return ! empty($this->form_args) |
|
| 386 | - ? add_query_arg($this->form_args, $this->form_action) |
|
| 387 | - : $this->form_action; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * @param string $form_action |
|
| 394 | - * @throws InvalidDataTypeException |
|
| 395 | - */ |
|
| 396 | - public function setFormAction($form_action) |
|
| 397 | - { |
|
| 398 | - if (! is_string($form_action)) { |
|
| 399 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 400 | - } |
|
| 401 | - $this->form_action = $form_action; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * @param array $form_args |
|
| 408 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 409 | - * @throws \InvalidArgumentException |
|
| 410 | - */ |
|
| 411 | - public function addFormActionArgs($form_args = array()) |
|
| 412 | - { |
|
| 413 | - if (is_object($form_args)) { |
|
| 414 | - throw new InvalidDataTypeException( |
|
| 415 | - '$form_args', |
|
| 416 | - $form_args, |
|
| 417 | - 'anything other than an object was expected.' |
|
| 418 | - ); |
|
| 419 | - } |
|
| 420 | - if (empty($form_args)) { |
|
| 421 | - throw new InvalidArgumentException( |
|
| 422 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 423 | - ); |
|
| 424 | - } |
|
| 425 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @return string |
|
| 432 | - */ |
|
| 433 | - public function formConfig() |
|
| 434 | - { |
|
| 435 | - return $this->form_config; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @param string $form_config |
|
| 442 | - * @throws DomainException |
|
| 443 | - */ |
|
| 444 | - public function setFormConfig($form_config) |
|
| 445 | - { |
|
| 446 | - if ( |
|
| 447 | - ! in_array( |
|
| 448 | - $form_config, |
|
| 449 | - array( |
|
| 450 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 451 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 452 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 453 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 454 | - ), |
|
| 455 | - true |
|
| 456 | - ) |
|
| 457 | - ) { |
|
| 458 | - throw new DomainException( |
|
| 459 | - sprintf( |
|
| 460 | - esc_html__('"%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', |
|
| 461 | - 'event_espresso'), |
|
| 462 | - $form_config |
|
| 463 | - ) |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - $this->form_config = $form_config; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * called after the form is instantiated |
|
| 473 | - * and used for performing any logic that needs to occur early |
|
| 474 | - * before any of the other methods are called. |
|
| 475 | - * returns true if everything is ok to proceed, |
|
| 476 | - * and false if no further form logic should be implemented |
|
| 477 | - * |
|
| 478 | - * @return boolean |
|
| 479 | - */ |
|
| 480 | - public function initialize() |
|
| 481 | - { |
|
| 482 | - $this->form_has_errors = \EE_Error::has_error(true); |
|
| 483 | - return true; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * used for setting up css and js |
|
| 490 | - * |
|
| 491 | - * @return void |
|
| 492 | - * @throws LogicException |
|
| 493 | - * @throws \EE_Error |
|
| 494 | - */ |
|
| 495 | - public function enqueueStylesAndScripts() |
|
| 496 | - { |
|
| 497 | - $this->form(false)->enqueue_js(); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * creates and returns the actual form |
|
| 504 | - * |
|
| 505 | - * @return EE_Form_Section_Proper |
|
| 506 | - */ |
|
| 507 | - abstract public function generate(); |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 513 | - * |
|
| 514 | - * @param string $text |
|
| 515 | - * @return \EE_Submit_Input |
|
| 516 | - */ |
|
| 517 | - public function generateSubmitButton($text = '') |
|
| 518 | - { |
|
| 519 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 520 | - return new EE_Submit_Input( |
|
| 521 | - array( |
|
| 522 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 523 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 524 | - 'html_class' => 'ee-form-submit', |
|
| 525 | - 'html_label' => ' ', |
|
| 526 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 527 | - 'default' => $text, |
|
| 528 | - ) |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 536 | - * |
|
| 537 | - * @param string $text |
|
| 538 | - * @return void |
|
| 539 | - * @throws \LogicException |
|
| 540 | - * @throws \EE_Error |
|
| 541 | - */ |
|
| 542 | - public function appendSubmitButton($text = '') |
|
| 543 | - { |
|
| 544 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 545 | - return; |
|
| 546 | - } |
|
| 547 | - $this->form->add_subsections( |
|
| 548 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 549 | - null, |
|
| 550 | - false |
|
| 551 | - ); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 558 | - * |
|
| 559 | - * @param string $text |
|
| 560 | - * @return \EE_Submit_Input |
|
| 561 | - */ |
|
| 562 | - public function generateCancelButton($text = '') |
|
| 563 | - { |
|
| 564 | - $cancel_button = new EE_Submit_Input( |
|
| 565 | - array( |
|
| 566 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 567 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 568 | - 'html_class' => 'ee-cancel-form', |
|
| 569 | - 'html_label' => ' ', |
|
| 570 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 571 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 572 | - ) |
|
| 573 | - ); |
|
| 574 | - $cancel_button->set_button_css_attributes(false); |
|
| 575 | - return $cancel_button; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * appends a float clearing div onto end of form |
|
| 582 | - * |
|
| 583 | - * @return void |
|
| 584 | - * @throws \EE_Error |
|
| 585 | - */ |
|
| 586 | - public function clearFormButtonFloats() |
|
| 587 | - { |
|
| 588 | - $this->form->add_subsections( |
|
| 589 | - array( |
|
| 590 | - 'clear-submit-btn-float' => new \EE_Form_Section_HTML( |
|
| 591 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 592 | - ), |
|
| 593 | - ), |
|
| 594 | - null, |
|
| 595 | - false |
|
| 596 | - ); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 603 | - * returns a string of HTML that can be directly echoed in a template |
|
| 604 | - * |
|
| 605 | - * @return string |
|
| 606 | - * @throws LogicException |
|
| 607 | - * @throws \EE_Error |
|
| 608 | - */ |
|
| 609 | - public function display() |
|
| 610 | - { |
|
| 611 | - $form_html = apply_filters( |
|
| 612 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 613 | - '' |
|
| 614 | - ); |
|
| 615 | - $form_config = $this->formConfig(); |
|
| 616 | - if ( |
|
| 617 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 618 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 619 | - ) { |
|
| 620 | - $form_html .= $this->form()->form_open($this->formAction()); |
|
| 621 | - } |
|
| 622 | - $form_html .= $this->form(true)->get_html($this->form_has_errors); |
|
| 623 | - if ( |
|
| 624 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 625 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 626 | - ) { |
|
| 627 | - $form_html .= $this->form()->form_close(); |
|
| 628 | - } |
|
| 629 | - $form_html .= apply_filters( |
|
| 630 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 631 | - '' |
|
| 632 | - ); |
|
| 633 | - return $form_html; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * handles processing the form submission |
|
| 640 | - * returns true or false depending on whether the form was processed successfully or not |
|
| 641 | - * |
|
| 642 | - * @param array $submitted_form_data |
|
| 643 | - * @return array |
|
| 644 | - * @throws \EE_Error |
|
| 645 | - * @throws \LogicException |
|
| 646 | - * @throws InvalidFormSubmissionException |
|
| 647 | - */ |
|
| 648 | - public function process($submitted_form_data = array()) |
|
| 649 | - { |
|
| 650 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 651 | - throw new InvalidFormSubmissionException($this->form_name); |
|
| 652 | - } |
|
| 653 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 654 | - if (! $this->form()->is_valid()) { |
|
| 655 | - throw new InvalidFormSubmissionException( |
|
| 656 | - $this->form_name, |
|
| 657 | - sprintf( |
|
| 658 | - esc_html__( |
|
| 659 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 660 | - 'event_espresso' |
|
| 661 | - ), |
|
| 662 | - $this->form_name, |
|
| 663 | - '<br />', |
|
| 664 | - $this->form()->submission_error_message() |
|
| 665 | - ) |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - return $this->form()->valid_data(); |
|
| 669 | - } |
|
| 34 | + /** |
|
| 35 | + * will add opening and closing HTML form tags as well as a submit button |
|
| 36 | + */ |
|
| 37 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * will add opening and closing HTML form tags but NOT a submit button |
|
| 41 | + */ |
|
| 42 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 46 | + */ |
|
| 47 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 51 | + */ |
|
| 52 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * if set to false, then this form has no displayable content, |
|
| 56 | + * and will only be used for processing data sent passed via GET or POST |
|
| 57 | + * defaults to true ( ie: form has displayable content ) |
|
| 58 | + * |
|
| 59 | + * @var boolean $displayable |
|
| 60 | + */ |
|
| 61 | + private $displayable = true; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var string $form_name |
|
| 65 | + */ |
|
| 66 | + private $form_name; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var string $admin_name |
|
| 70 | + */ |
|
| 71 | + private $admin_name; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var string $slug |
|
| 75 | + */ |
|
| 76 | + private $slug; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var string $submit_btn_text |
|
| 80 | + */ |
|
| 81 | + private $submit_btn_text; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var string $form_action |
|
| 85 | + */ |
|
| 86 | + private $form_action; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * form params in key value pairs |
|
| 90 | + * can be added to form action URL or as hidden inputs |
|
| 91 | + * |
|
| 92 | + * @var array $form_args |
|
| 93 | + */ |
|
| 94 | + private $form_args = array(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * value of one of the string constant above |
|
| 98 | + * |
|
| 99 | + * @var string $form_config |
|
| 100 | + */ |
|
| 101 | + private $form_config; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * whether or not the form was determined to be invalid |
|
| 105 | + * |
|
| 106 | + * @var boolean $form_has_errors |
|
| 107 | + */ |
|
| 108 | + private $form_has_errors; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * the absolute top level form section being used on the page |
|
| 112 | + * |
|
| 113 | + * @var \EE_Form_Section_Proper $form |
|
| 114 | + */ |
|
| 115 | + private $form; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @var \EE_Registry $registry |
|
| 119 | + */ |
|
| 120 | + protected $registry; |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Form constructor. |
|
| 126 | + * |
|
| 127 | + * @param string $form_name |
|
| 128 | + * @param string $admin_name |
|
| 129 | + * @param string $slug |
|
| 130 | + * @param string $form_action |
|
| 131 | + * @param string $form_config |
|
| 132 | + * @param \EE_Registry $registry |
|
| 133 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 134 | + * @throws \DomainException |
|
| 135 | + * @throws \InvalidArgumentException |
|
| 136 | + */ |
|
| 137 | + public function __construct( |
|
| 138 | + $form_name, |
|
| 139 | + $admin_name, |
|
| 140 | + $slug, |
|
| 141 | + $form_action = '', |
|
| 142 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 143 | + \EE_Registry $registry |
|
| 144 | + ) { |
|
| 145 | + $this->setFormName($form_name); |
|
| 146 | + $this->setAdminName($admin_name); |
|
| 147 | + $this->setSlug($slug); |
|
| 148 | + $this->setFormAction($form_action); |
|
| 149 | + $this->setFormConfig($form_config); |
|
| 150 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 151 | + $this->registry = $registry; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + public static function getFormConfigConstants() |
|
| 160 | + { |
|
| 161 | + return array( |
|
| 162 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 163 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 164 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 165 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 166 | + ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param bool $for_display |
|
| 173 | + * @return \EE_Form_Section_Proper |
|
| 174 | + * @throws \EE_Error |
|
| 175 | + * @throws \LogicException |
|
| 176 | + */ |
|
| 177 | + public function form($for_display = false) |
|
| 178 | + { |
|
| 179 | + if (! $this->formIsValid()) { |
|
| 180 | + return null; |
|
| 181 | + } |
|
| 182 | + if ($for_display) { |
|
| 183 | + $form_config = $this->formConfig(); |
|
| 184 | + if ( |
|
| 185 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 186 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 187 | + ) { |
|
| 188 | + $this->appendSubmitButton(); |
|
| 189 | + $this->clearFormButtonFloats(); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + return $this->form; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @return boolean |
|
| 199 | + * @throws LogicException |
|
| 200 | + */ |
|
| 201 | + public function formIsValid() |
|
| 202 | + { |
|
| 203 | + if (! $this->form instanceof \EE_Form_Section_Proper) { |
|
| 204 | + static $generated = false; |
|
| 205 | + if (! $generated) { |
|
| 206 | + $generated = true; |
|
| 207 | + $form = apply_filters( |
|
| 208 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 209 | + $this->generate(), |
|
| 210 | + $this |
|
| 211 | + ); |
|
| 212 | + if ($form instanceof \EE_Form_Section_Proper) { |
|
| 213 | + $this->setForm($form); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + return $this->verifyForm(); |
|
| 217 | + } |
|
| 218 | + return true; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @return boolean |
|
| 225 | + * @throws LogicException |
|
| 226 | + */ |
|
| 227 | + public function verifyForm() |
|
| 228 | + { |
|
| 229 | + if ($this->form instanceof \EE_Form_Section_Proper) { |
|
| 230 | + return true; |
|
| 231 | + } |
|
| 232 | + throw new LogicException( |
|
| 233 | + sprintf( |
|
| 234 | + esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'), |
|
| 235 | + $this->form_name |
|
| 236 | + ) |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param \EE_Form_Section_Proper $form |
|
| 244 | + */ |
|
| 245 | + public function setForm(\EE_Form_Section_Proper $form) |
|
| 246 | + { |
|
| 247 | + $this->form = $form; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @return boolean |
|
| 254 | + */ |
|
| 255 | + public function displayable() |
|
| 256 | + { |
|
| 257 | + return $this->displayable; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param boolean $displayable |
|
| 264 | + */ |
|
| 265 | + public function setDisplayable($displayable = false) |
|
| 266 | + { |
|
| 267 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * a public name for the form that can be displayed on the frontend of a site |
|
| 274 | + * |
|
| 275 | + * @return string |
|
| 276 | + */ |
|
| 277 | + public function formName() |
|
| 278 | + { |
|
| 279 | + return $this->form_name; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @param string $form_name |
|
| 286 | + * @throws InvalidDataTypeException |
|
| 287 | + */ |
|
| 288 | + public function setFormName($form_name) |
|
| 289 | + { |
|
| 290 | + if (! is_string($form_name)) { |
|
| 291 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 292 | + } |
|
| 293 | + $this->form_name = $form_name; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * a public name for the form that can be displayed, but only in the admin |
|
| 300 | + * |
|
| 301 | + * @return string |
|
| 302 | + */ |
|
| 303 | + public function adminName() |
|
| 304 | + { |
|
| 305 | + return $this->admin_name; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param string $admin_name |
|
| 312 | + * @throws InvalidDataTypeException |
|
| 313 | + */ |
|
| 314 | + public function setAdminName($admin_name) |
|
| 315 | + { |
|
| 316 | + if (! is_string($admin_name)) { |
|
| 317 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 318 | + } |
|
| 319 | + $this->admin_name = $admin_name; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * a URL friendly string that can be used for identifying the form |
|
| 326 | + * |
|
| 327 | + * @return string |
|
| 328 | + */ |
|
| 329 | + public function slug() |
|
| 330 | + { |
|
| 331 | + return $this->slug; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param string $slug |
|
| 338 | + * @throws InvalidDataTypeException |
|
| 339 | + */ |
|
| 340 | + public function setSlug($slug) |
|
| 341 | + { |
|
| 342 | + if (! is_string($slug)) { |
|
| 343 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 344 | + } |
|
| 345 | + $this->slug = $slug; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + public function submitBtnText() |
|
| 354 | + { |
|
| 355 | + return $this->submit_btn_text; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @param string $submit_btn_text |
|
| 362 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 363 | + * @throws \InvalidArgumentException |
|
| 364 | + */ |
|
| 365 | + public function setSubmitBtnText($submit_btn_text) |
|
| 366 | + { |
|
| 367 | + if (! is_string($submit_btn_text)) { |
|
| 368 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 369 | + } |
|
| 370 | + if (empty($submit_btn_text)) { |
|
| 371 | + throw new InvalidArgumentException( |
|
| 372 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 373 | + ); |
|
| 374 | + } |
|
| 375 | + $this->submit_btn_text = $submit_btn_text; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @return string |
|
| 382 | + */ |
|
| 383 | + public function formAction() |
|
| 384 | + { |
|
| 385 | + return ! empty($this->form_args) |
|
| 386 | + ? add_query_arg($this->form_args, $this->form_action) |
|
| 387 | + : $this->form_action; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * @param string $form_action |
|
| 394 | + * @throws InvalidDataTypeException |
|
| 395 | + */ |
|
| 396 | + public function setFormAction($form_action) |
|
| 397 | + { |
|
| 398 | + if (! is_string($form_action)) { |
|
| 399 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 400 | + } |
|
| 401 | + $this->form_action = $form_action; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * @param array $form_args |
|
| 408 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 409 | + * @throws \InvalidArgumentException |
|
| 410 | + */ |
|
| 411 | + public function addFormActionArgs($form_args = array()) |
|
| 412 | + { |
|
| 413 | + if (is_object($form_args)) { |
|
| 414 | + throw new InvalidDataTypeException( |
|
| 415 | + '$form_args', |
|
| 416 | + $form_args, |
|
| 417 | + 'anything other than an object was expected.' |
|
| 418 | + ); |
|
| 419 | + } |
|
| 420 | + if (empty($form_args)) { |
|
| 421 | + throw new InvalidArgumentException( |
|
| 422 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 423 | + ); |
|
| 424 | + } |
|
| 425 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @return string |
|
| 432 | + */ |
|
| 433 | + public function formConfig() |
|
| 434 | + { |
|
| 435 | + return $this->form_config; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @param string $form_config |
|
| 442 | + * @throws DomainException |
|
| 443 | + */ |
|
| 444 | + public function setFormConfig($form_config) |
|
| 445 | + { |
|
| 446 | + if ( |
|
| 447 | + ! in_array( |
|
| 448 | + $form_config, |
|
| 449 | + array( |
|
| 450 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 451 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 452 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 453 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 454 | + ), |
|
| 455 | + true |
|
| 456 | + ) |
|
| 457 | + ) { |
|
| 458 | + throw new DomainException( |
|
| 459 | + sprintf( |
|
| 460 | + esc_html__('"%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', |
|
| 461 | + 'event_espresso'), |
|
| 462 | + $form_config |
|
| 463 | + ) |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + $this->form_config = $form_config; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * called after the form is instantiated |
|
| 473 | + * and used for performing any logic that needs to occur early |
|
| 474 | + * before any of the other methods are called. |
|
| 475 | + * returns true if everything is ok to proceed, |
|
| 476 | + * and false if no further form logic should be implemented |
|
| 477 | + * |
|
| 478 | + * @return boolean |
|
| 479 | + */ |
|
| 480 | + public function initialize() |
|
| 481 | + { |
|
| 482 | + $this->form_has_errors = \EE_Error::has_error(true); |
|
| 483 | + return true; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * used for setting up css and js |
|
| 490 | + * |
|
| 491 | + * @return void |
|
| 492 | + * @throws LogicException |
|
| 493 | + * @throws \EE_Error |
|
| 494 | + */ |
|
| 495 | + public function enqueueStylesAndScripts() |
|
| 496 | + { |
|
| 497 | + $this->form(false)->enqueue_js(); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * creates and returns the actual form |
|
| 504 | + * |
|
| 505 | + * @return EE_Form_Section_Proper |
|
| 506 | + */ |
|
| 507 | + abstract public function generate(); |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 513 | + * |
|
| 514 | + * @param string $text |
|
| 515 | + * @return \EE_Submit_Input |
|
| 516 | + */ |
|
| 517 | + public function generateSubmitButton($text = '') |
|
| 518 | + { |
|
| 519 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 520 | + return new EE_Submit_Input( |
|
| 521 | + array( |
|
| 522 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 523 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 524 | + 'html_class' => 'ee-form-submit', |
|
| 525 | + 'html_label' => ' ', |
|
| 526 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 527 | + 'default' => $text, |
|
| 528 | + ) |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 536 | + * |
|
| 537 | + * @param string $text |
|
| 538 | + * @return void |
|
| 539 | + * @throws \LogicException |
|
| 540 | + * @throws \EE_Error |
|
| 541 | + */ |
|
| 542 | + public function appendSubmitButton($text = '') |
|
| 543 | + { |
|
| 544 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 545 | + return; |
|
| 546 | + } |
|
| 547 | + $this->form->add_subsections( |
|
| 548 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 549 | + null, |
|
| 550 | + false |
|
| 551 | + ); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 558 | + * |
|
| 559 | + * @param string $text |
|
| 560 | + * @return \EE_Submit_Input |
|
| 561 | + */ |
|
| 562 | + public function generateCancelButton($text = '') |
|
| 563 | + { |
|
| 564 | + $cancel_button = new EE_Submit_Input( |
|
| 565 | + array( |
|
| 566 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 567 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 568 | + 'html_class' => 'ee-cancel-form', |
|
| 569 | + 'html_label' => ' ', |
|
| 570 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 571 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 572 | + ) |
|
| 573 | + ); |
|
| 574 | + $cancel_button->set_button_css_attributes(false); |
|
| 575 | + return $cancel_button; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * appends a float clearing div onto end of form |
|
| 582 | + * |
|
| 583 | + * @return void |
|
| 584 | + * @throws \EE_Error |
|
| 585 | + */ |
|
| 586 | + public function clearFormButtonFloats() |
|
| 587 | + { |
|
| 588 | + $this->form->add_subsections( |
|
| 589 | + array( |
|
| 590 | + 'clear-submit-btn-float' => new \EE_Form_Section_HTML( |
|
| 591 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 592 | + ), |
|
| 593 | + ), |
|
| 594 | + null, |
|
| 595 | + false |
|
| 596 | + ); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 603 | + * returns a string of HTML that can be directly echoed in a template |
|
| 604 | + * |
|
| 605 | + * @return string |
|
| 606 | + * @throws LogicException |
|
| 607 | + * @throws \EE_Error |
|
| 608 | + */ |
|
| 609 | + public function display() |
|
| 610 | + { |
|
| 611 | + $form_html = apply_filters( |
|
| 612 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 613 | + '' |
|
| 614 | + ); |
|
| 615 | + $form_config = $this->formConfig(); |
|
| 616 | + if ( |
|
| 617 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 618 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 619 | + ) { |
|
| 620 | + $form_html .= $this->form()->form_open($this->formAction()); |
|
| 621 | + } |
|
| 622 | + $form_html .= $this->form(true)->get_html($this->form_has_errors); |
|
| 623 | + if ( |
|
| 624 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 625 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 626 | + ) { |
|
| 627 | + $form_html .= $this->form()->form_close(); |
|
| 628 | + } |
|
| 629 | + $form_html .= apply_filters( |
|
| 630 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 631 | + '' |
|
| 632 | + ); |
|
| 633 | + return $form_html; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * handles processing the form submission |
|
| 640 | + * returns true or false depending on whether the form was processed successfully or not |
|
| 641 | + * |
|
| 642 | + * @param array $submitted_form_data |
|
| 643 | + * @return array |
|
| 644 | + * @throws \EE_Error |
|
| 645 | + * @throws \LogicException |
|
| 646 | + * @throws InvalidFormSubmissionException |
|
| 647 | + */ |
|
| 648 | + public function process($submitted_form_data = array()) |
|
| 649 | + { |
|
| 650 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 651 | + throw new InvalidFormSubmissionException($this->form_name); |
|
| 652 | + } |
|
| 653 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 654 | + if (! $this->form()->is_valid()) { |
|
| 655 | + throw new InvalidFormSubmissionException( |
|
| 656 | + $this->form_name, |
|
| 657 | + sprintf( |
|
| 658 | + esc_html__( |
|
| 659 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 660 | + 'event_espresso' |
|
| 661 | + ), |
|
| 662 | + $this->form_name, |
|
| 663 | + '<br />', |
|
| 664 | + $this->form()->submission_error_message() |
|
| 665 | + ) |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + return $this->form()->valid_data(); |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | 671 | |
| 672 | 672 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 12 | 12 | use EventEspresso\core\exceptions\InvalidFormSubmissionException; |
| 13 | 13 | |
| 14 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 14 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 15 | 15 | exit('No direct script access allowed'); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function form($for_display = false) |
| 178 | 178 | { |
| 179 | - if (! $this->formIsValid()) { |
|
| 179 | + if ( ! $this->formIsValid()) { |
|
| 180 | 180 | return null; |
| 181 | 181 | } |
| 182 | 182 | if ($for_display) { |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | public function formIsValid() |
| 202 | 202 | { |
| 203 | - if (! $this->form instanceof \EE_Form_Section_Proper) { |
|
| 203 | + if ( ! $this->form instanceof \EE_Form_Section_Proper) { |
|
| 204 | 204 | static $generated = false; |
| 205 | - if (! $generated) { |
|
| 205 | + if ( ! $generated) { |
|
| 206 | 206 | $generated = true; |
| 207 | 207 | $form = apply_filters( |
| 208 | 208 | 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public function setFormName($form_name) |
| 289 | 289 | { |
| 290 | - if (! is_string($form_name)) { |
|
| 290 | + if ( ! is_string($form_name)) { |
|
| 291 | 291 | throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
| 292 | 292 | } |
| 293 | 293 | $this->form_name = $form_name; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | public function setAdminName($admin_name) |
| 315 | 315 | { |
| 316 | - if (! is_string($admin_name)) { |
|
| 316 | + if ( ! is_string($admin_name)) { |
|
| 317 | 317 | throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
| 318 | 318 | } |
| 319 | 319 | $this->admin_name = $admin_name; |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | public function setSlug($slug) |
| 341 | 341 | { |
| 342 | - if (! is_string($slug)) { |
|
| 342 | + if ( ! is_string($slug)) { |
|
| 343 | 343 | throw new InvalidDataTypeException('$slug', $slug, 'string'); |
| 344 | 344 | } |
| 345 | 345 | $this->slug = $slug; |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | public function setSubmitBtnText($submit_btn_text) |
| 366 | 366 | { |
| 367 | - if (! is_string($submit_btn_text)) { |
|
| 367 | + if ( ! is_string($submit_btn_text)) { |
|
| 368 | 368 | throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
| 369 | 369 | } |
| 370 | 370 | if (empty($submit_btn_text)) { |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | */ |
| 396 | 396 | public function setFormAction($form_action) |
| 397 | 397 | { |
| 398 | - if (! is_string($form_action)) { |
|
| 398 | + if ( ! is_string($form_action)) { |
|
| 399 | 399 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
| 400 | 400 | } |
| 401 | 401 | $this->form_action = $form_action; |
@@ -519,11 +519,11 @@ discard block |
||
| 519 | 519 | $text = ! empty($text) ? $text : $this->submitBtnText(); |
| 520 | 520 | return new EE_Submit_Input( |
| 521 | 521 | array( |
| 522 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 523 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 522 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
| 523 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
| 524 | 524 | 'html_class' => 'ee-form-submit', |
| 525 | 525 | 'html_label' => ' ', |
| 526 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 526 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
| 527 | 527 | 'default' => $text, |
| 528 | 528 | ) |
| 529 | 529 | ); |
@@ -541,11 +541,11 @@ discard block |
||
| 541 | 541 | */ |
| 542 | 542 | public function appendSubmitButton($text = '') |
| 543 | 543 | { |
| 544 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 544 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
| 545 | 545 | return; |
| 546 | 546 | } |
| 547 | 547 | $this->form->add_subsections( |
| 548 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 548 | + array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)), |
|
| 549 | 549 | null, |
| 550 | 550 | false |
| 551 | 551 | ); |
@@ -563,11 +563,11 @@ discard block |
||
| 563 | 563 | { |
| 564 | 564 | $cancel_button = new EE_Submit_Input( |
| 565 | 565 | array( |
| 566 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 567 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 566 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
| 567 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
| 568 | 568 | 'html_class' => 'ee-cancel-form', |
| 569 | 569 | 'html_label' => ' ', |
| 570 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 570 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
| 571 | 571 | 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
| 572 | 572 | ) |
| 573 | 573 | ); |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | $this->form->add_subsections( |
| 589 | 589 | array( |
| 590 | 590 | 'clear-submit-btn-float' => new \EE_Form_Section_HTML( |
| 591 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 591 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
| 592 | 592 | ), |
| 593 | 593 | ), |
| 594 | 594 | null, |
@@ -647,11 +647,11 @@ discard block |
||
| 647 | 647 | */ |
| 648 | 648 | public function process($submitted_form_data = array()) |
| 649 | 649 | { |
| 650 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 650 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
| 651 | 651 | throw new InvalidFormSubmissionException($this->form_name); |
| 652 | 652 | } |
| 653 | 653 | $this->form(true)->receive_form_submission($submitted_form_data); |
| 654 | - if (! $this->form()->is_valid()) { |
|
| 654 | + if ( ! $this->form()->is_valid()) { |
|
| 655 | 655 | throw new InvalidFormSubmissionException( |
| 656 | 656 | $this->form_name, |
| 657 | 657 | sprintf( |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | if (! class_exists('WP_List_Table')) { |
| 6 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); |
|
| 6 | + require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
@@ -22,782 +22,782 @@ discard block |
||
| 22 | 22 | abstract class EE_Admin_List_Table extends WP_List_Table |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * holds the data that will be processed for the table |
|
| 27 | - * |
|
| 28 | - * @var array $_data |
|
| 29 | - */ |
|
| 30 | - protected $_data; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This holds the value of all the data available for the given view (for all pages). |
|
| 35 | - * |
|
| 36 | - * @var int $_all_data_count |
|
| 37 | - */ |
|
| 38 | - protected $_all_data_count; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Will contain the count of trashed items for the view label. |
|
| 43 | - * |
|
| 44 | - * @var int $_trashed_count |
|
| 45 | - */ |
|
| 46 | - protected $_trashed_count; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * This is what will be referenced as the slug for the current screen |
|
| 51 | - * |
|
| 52 | - * @var string $_screen |
|
| 53 | - */ |
|
| 54 | - protected $_screen; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * this is the EE_Admin_Page object |
|
| 59 | - * |
|
| 60 | - * @var EE_Admin_Page $_admin_page |
|
| 61 | - */ |
|
| 62 | - protected $_admin_page; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * The current view |
|
| 67 | - * |
|
| 68 | - * @var string $_view |
|
| 69 | - */ |
|
| 70 | - protected $_view; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * array of possible views for this table |
|
| 75 | - * |
|
| 76 | - * @var array $_views |
|
| 77 | - */ |
|
| 78 | - protected $_views; |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * An array of key => value pairs containing information about the current table |
|
| 83 | - * array( |
|
| 84 | - * 'plural' => 'plural label', |
|
| 85 | - * 'singular' => 'singular label', |
|
| 86 | - * 'ajax' => false, //whether to use ajax or not |
|
| 87 | - * 'screen' => null, //string used to reference what screen this is |
|
| 88 | - * (WP_List_table converts to screen object) |
|
| 89 | - * ) |
|
| 90 | - * |
|
| 91 | - * @var array $_wp_list_args |
|
| 92 | - */ |
|
| 93 | - protected $_wp_list_args; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * an array of column names |
|
| 97 | - * array( |
|
| 98 | - * 'internal-name' => 'Title' |
|
| 99 | - * ) |
|
| 100 | - * |
|
| 101 | - * @var array $_columns |
|
| 102 | - */ |
|
| 103 | - protected $_columns; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of sortable columns |
|
| 107 | - * array( |
|
| 108 | - * 'internal-name' => 'orderby' //or |
|
| 109 | - * 'internal-name' => array( 'orderby', true ) |
|
| 110 | - * ) |
|
| 111 | - * |
|
| 112 | - * @var array $_sortable_columns |
|
| 113 | - */ |
|
| 114 | - protected $_sortable_columns; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * callback method used to perform AJAX row reordering |
|
| 118 | - * |
|
| 119 | - * @var string $_ajax_sorting_callback |
|
| 120 | - */ |
|
| 121 | - protected $_ajax_sorting_callback; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * An array of hidden columns (if needed) |
|
| 125 | - * array('internal-name', 'internal-name') |
|
| 126 | - * |
|
| 127 | - * @var array $_hidden_columns |
|
| 128 | - */ |
|
| 129 | - protected $_hidden_columns; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * holds the per_page value |
|
| 133 | - * |
|
| 134 | - * @var int $_per_page |
|
| 135 | - */ |
|
| 136 | - protected $_per_page; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * holds what page number is currently being viewed |
|
| 140 | - * |
|
| 141 | - * @var int $_current_page |
|
| 142 | - */ |
|
| 143 | - protected $_current_page; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * the reference string for the nonce_action |
|
| 147 | - * |
|
| 148 | - * @var string $_nonce_action_ref |
|
| 149 | - */ |
|
| 150 | - protected $_nonce_action_ref; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * property to hold incoming request data (as set by the admin_page_core) |
|
| 154 | - * |
|
| 155 | - * @var array $_req_data |
|
| 156 | - */ |
|
| 157 | - protected $_req_data; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * yes / no array for admin form fields |
|
| 162 | - * |
|
| 163 | - * @var array $_yes_no |
|
| 164 | - */ |
|
| 165 | - protected $_yes_no = array(); |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Array describing buttons that should appear at the bottom of the page |
|
| 169 | - * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 170 | - * and the values are another array with the following keys |
|
| 171 | - * array( |
|
| 172 | - * 'route' => 'page_route', |
|
| 173 | - * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 174 | - * ) |
|
| 175 | - * |
|
| 176 | - * @var array $_bottom_buttons |
|
| 177 | - */ |
|
| 178 | - protected $_bottom_buttons = array(); |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Used to indicate what should be the primary column for the list table. |
|
| 183 | - * If not present then falls back to what WP calculates |
|
| 184 | - * as the primary column. |
|
| 185 | - * |
|
| 186 | - * @type string $_primary_column |
|
| 187 | - */ |
|
| 188 | - protected $_primary_column = ''; |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Used to indicate whether the table has a checkbox column or not. |
|
| 193 | - * |
|
| 194 | - * @type bool $_has_checkbox_column |
|
| 195 | - */ |
|
| 196 | - protected $_has_checkbox_column = false; |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 201 | - */ |
|
| 202 | - public function __construct(EE_Admin_Page $admin_page) |
|
| 203 | - { |
|
| 204 | - $this->_admin_page = $admin_page; |
|
| 205 | - $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 206 | - $this->_view = $this->_admin_page->get_view(); |
|
| 207 | - $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 208 | - $this->_current_page = $this->get_pagenum(); |
|
| 209 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 210 | - $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
|
| 211 | - |
|
| 212 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10); |
|
| 213 | - |
|
| 214 | - $this->_setup_data(); |
|
| 215 | - $this->_add_view_counts(); |
|
| 216 | - |
|
| 217 | - $this->_nonce_action_ref = $this->_view; |
|
| 218 | - |
|
| 219 | - $this->_set_properties(); |
|
| 220 | - |
|
| 221 | - //set primary column |
|
| 222 | - add_filter('list_table_primary_column', array($this, 'set_primary_column')); |
|
| 223 | - |
|
| 224 | - //set parent defaults |
|
| 225 | - parent::__construct($this->_wp_list_args); |
|
| 226 | - |
|
| 227 | - $this->prepare_items(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * _setup_data |
|
| 233 | - * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 234 | - * |
|
| 235 | - * @uses $this->_admin_page |
|
| 236 | - * @return void |
|
| 237 | - */ |
|
| 238 | - abstract protected function _setup_data(); |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 243 | - * properties set: |
|
| 244 | - * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 245 | - * _columns = set the columns in an array. |
|
| 246 | - * _sortable_columns = columns that are sortable (array). |
|
| 247 | - * _hidden_columns = columns that are hidden (array) |
|
| 248 | - * _default_orderby = the default orderby for sorting. |
|
| 249 | - * |
|
| 250 | - * @abstract |
|
| 251 | - * @access protected |
|
| 252 | - * @return void |
|
| 253 | - */ |
|
| 254 | - abstract protected function _set_properties(); |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * _get_table_filters |
|
| 259 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 260 | - * get's shown in the table. |
|
| 261 | - * |
|
| 262 | - * @abstract |
|
| 263 | - * @access protected |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - abstract protected function _get_table_filters(); |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 271 | - * counts of the views is accurate. |
|
| 272 | - * |
|
| 273 | - * @abstract |
|
| 274 | - * @access protected |
|
| 275 | - * @return void |
|
| 276 | - */ |
|
| 277 | - abstract protected function _add_view_counts(); |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * _get_hidden_fields |
|
| 282 | - * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 283 | - * |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - protected function _get_hidden_fields() |
|
| 287 | - { |
|
| 288 | - $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 289 | - $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 290 | - //if action is STILL empty, then we set it to default |
|
| 291 | - $action = empty($action) ? 'default' : $action; |
|
| 292 | - $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
| 293 | - $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
| 294 | - $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
| 295 | - |
|
| 296 | - $bulk_actions = $this->_get_bulk_actions(); |
|
| 297 | - foreach ($bulk_actions as $bulk_action => $label) { |
|
| 298 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce" value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - return $field; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * _set_column_info |
|
| 307 | - * we're using this to set the column headers property. |
|
| 308 | - * |
|
| 309 | - * @access protected |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - protected function _set_column_info() |
|
| 313 | - { |
|
| 314 | - $columns = $this->get_columns(); |
|
| 315 | - $hidden = $this->get_hidden_columns(); |
|
| 316 | - $_sortable = $this->get_sortable_columns(); |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 320 | - * Note that $this->screen->id is in the format |
|
| 321 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 322 | - * table it is: event-espresso_page_espresso_messages. |
|
| 323 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 324 | - * hook prefix ("event-espresso") will be different. |
|
| 325 | - * |
|
| 326 | - * @var array |
|
| 327 | - */ |
|
| 328 | - $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 329 | - |
|
| 330 | - $sortable = array(); |
|
| 331 | - foreach ($_sortable as $id => $data) { |
|
| 332 | - if (empty($data)) { |
|
| 333 | - continue; |
|
| 334 | - } |
|
| 335 | - //fix for offset errors with WP_List_Table default get_columninfo() |
|
| 336 | - if (is_array($data)) { |
|
| 337 | - $_data[0] = key($data); |
|
| 338 | - $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 339 | - } else { |
|
| 340 | - $_data[0] = $data; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - $data = (array)$data; |
|
| 344 | - |
|
| 345 | - if (! isset($data[1])) { |
|
| 346 | - $_data[1] = false; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - $sortable[$id] = $_data; |
|
| 350 | - } |
|
| 351 | - $primary = $this->get_primary_column_name(); |
|
| 352 | - $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 358 | - * |
|
| 359 | - * @return string |
|
| 360 | - */ |
|
| 361 | - protected function get_primary_column_name() |
|
| 362 | - { |
|
| 363 | - foreach (class_parents($this) as $parent) { |
|
| 364 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 365 | - return parent::get_primary_column_name(); |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - return $this->_primary_column; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 374 | - * |
|
| 375 | - * @param EE_Base_Class $item |
|
| 376 | - * @param string $column_name |
|
| 377 | - * @param string $primary |
|
| 378 | - * @return string |
|
| 379 | - */ |
|
| 380 | - protected function handle_row_actions($item, $column_name, $primary) |
|
| 381 | - { |
|
| 382 | - foreach (class_parents($this) as $parent) { |
|
| 383 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 384 | - return parent::handle_row_actions($item, $column_name, $primary); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - return ''; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * _get_bulk_actions |
|
| 393 | - * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 394 | - * |
|
| 395 | - * @access protected |
|
| 396 | - * @return array bulk_actions |
|
| 397 | - */ |
|
| 398 | - protected function _get_bulk_actions() |
|
| 399 | - { |
|
| 400 | - $actions = array(); |
|
| 401 | - //the _views property should have the bulk_actions, so let's go through and extract them into a properly formatted array for the wp_list_table(); |
|
| 402 | - foreach ($this->_views as $view => $args) { |
|
| 403 | - if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 404 | - //each bulk action will correspond with a admin page route, so we can check whatever the capability is for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 405 | - foreach ($args['bulk_action'] as $route => $label) { |
|
| 406 | - if ($this->_admin_page->check_user_access($route, true)) { |
|
| 407 | - $actions[$route] = $label; |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - return $actions; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * _filters |
|
| 418 | - * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 419 | - * button. |
|
| 420 | - * |
|
| 421 | - * @access private |
|
| 422 | - * @return string html showing filters |
|
| 423 | - */ |
|
| 424 | - private function _filters() |
|
| 425 | - { |
|
| 426 | - $classname = get_class($this); |
|
| 427 | - $filters = apply_filters("FHEE__{$classname}__filters", (array)$this->_get_table_filters(), $this, |
|
| 428 | - $this->_screen); |
|
| 429 | - |
|
| 430 | - if (empty($filters)) { |
|
| 431 | - return; |
|
| 432 | - } |
|
| 433 | - foreach ($filters as $filter) { |
|
| 434 | - echo $filter; |
|
| 435 | - } |
|
| 436 | - //add filter button at end |
|
| 437 | - echo '<input type="submit" class="button-secondary" value="' . __('Filter', |
|
| 438 | - 'event_espresso') . '" id="post-query-submit" />'; |
|
| 439 | - //add reset filters button at end |
|
| 440 | - echo '<a class="button button-secondary" href="' . $this->_admin_page->get_current_page_view_url() . '" style="display:inline-block">' . __('Reset Filters', |
|
| 441 | - 'event_espresso') . '</a>'; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Callback for 'list_table_primary_column' WordPress filter |
|
| 447 | - * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 448 | - * column when class is instantiated. |
|
| 449 | - * |
|
| 450 | - * @see WP_List_Table::get_primary_column_name |
|
| 451 | - * @param string $column_name |
|
| 452 | - * @return string |
|
| 453 | - */ |
|
| 454 | - public function set_primary_column($column_name) |
|
| 455 | - { |
|
| 456 | - return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * |
|
| 462 | - */ |
|
| 463 | - public function prepare_items() |
|
| 464 | - { |
|
| 465 | - |
|
| 466 | - $this->_set_column_info(); |
|
| 467 | - //$this->_column_headers = $this->get_column_info(); |
|
| 468 | - $total_items = $this->_all_data_count; |
|
| 469 | - $this->process_bulk_action(); |
|
| 470 | - |
|
| 471 | - $this->items = $this->_data; |
|
| 472 | - $this->set_pagination_args( |
|
| 473 | - array( |
|
| 474 | - 'total_items' => $total_items, |
|
| 475 | - 'per_page' => $this->_per_page, |
|
| 476 | - 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 477 | - ) |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * This column is the default for when there is no defined column method for a registered column. |
|
| 484 | - * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 485 | - * |
|
| 486 | - * @param EE_Base_Class $item |
|
| 487 | - * @param string $column_name The column being called. |
|
| 488 | - * @return string html content for the column |
|
| 489 | - */ |
|
| 490 | - public function column_default($item, $column_name) |
|
| 491 | - { |
|
| 492 | - /** |
|
| 493 | - * Dynamic hook allowing for adding additional column content in this list table. |
|
| 494 | - * Note that $this->screen->id is in the format |
|
| 495 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 496 | - * table it is: event-espresso_page_espresso_messages. |
|
| 497 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 498 | - * hook prefix ("event-espresso") will be different. |
|
| 499 | - */ |
|
| 500 | - do_action('AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, $item, |
|
| 501 | - $this->_screen); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Get a list of columns. The format is: |
|
| 507 | - * 'internal-name' => 'Title' |
|
| 508 | - * |
|
| 509 | - * @since 3.1.0 |
|
| 510 | - * @access public |
|
| 511 | - * @abstract |
|
| 512 | - * @return array |
|
| 513 | - */ |
|
| 514 | - public function get_columns() |
|
| 515 | - { |
|
| 516 | - /** |
|
| 517 | - * Dynamic hook allowing for adding additional columns in this list table. |
|
| 518 | - * Note that $this->screen->id is in the format |
|
| 519 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 520 | - * table it is: event-espresso_page_espresso_messages. |
|
| 521 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 522 | - * hook prefix ("event-espresso") will be different. |
|
| 523 | - * |
|
| 524 | - * @var array |
|
| 525 | - */ |
|
| 526 | - $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 527 | - return $columns; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Get an associative array ( id => link ) with the list |
|
| 533 | - * of views available on this table. |
|
| 534 | - * |
|
| 535 | - * @since 3.1.0 |
|
| 536 | - * @access protected |
|
| 537 | - * @return array |
|
| 538 | - */ |
|
| 539 | - public function get_views() |
|
| 540 | - { |
|
| 541 | - return $this->_views; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - public function display_views() |
|
| 545 | - { |
|
| 546 | - $views = $this->get_views(); |
|
| 547 | - $assembled_views = array(); |
|
| 548 | - |
|
| 549 | - if (empty($views)) { |
|
| 550 | - return; |
|
| 551 | - } |
|
| 552 | - echo "<ul class='subsubsub'>\n"; |
|
| 553 | - foreach ($views as $view) { |
|
| 554 | - $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 555 | - if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 556 | - $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>" . '<a href="' . $view['url'] . '">' . $view['label'] . '</a> <span class="count">(' . $count . ')</span>'; |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
| 561 | - echo "</ul>"; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Generates content for a single row of the table |
|
| 567 | - * |
|
| 568 | - * @since 4.1 |
|
| 569 | - * @access public |
|
| 570 | - * @param EE_Base_Class $item The current item |
|
| 571 | - */ |
|
| 572 | - public function single_row($item) |
|
| 573 | - { |
|
| 574 | - $row_class = $this->_get_row_class($item); |
|
| 575 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 576 | - $this->single_row_columns($item); |
|
| 577 | - echo '</tr>'; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * This simply sets up the row class for the table rows. |
|
| 583 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 584 | - * |
|
| 585 | - * @param EE_Base_Class $item the current item |
|
| 586 | - * @return string |
|
| 587 | - */ |
|
| 588 | - protected function _get_row_class($item) |
|
| 589 | - { |
|
| 590 | - static $row_class = ''; |
|
| 591 | - $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 592 | - |
|
| 593 | - $new_row_class = $row_class; |
|
| 594 | - |
|
| 595 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 596 | - $new_row_class .= ' rowsortable'; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - return $new_row_class; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * @return array |
|
| 605 | - */ |
|
| 606 | - public function get_sortable_columns() |
|
| 607 | - { |
|
| 608 | - return (array)$this->_sortable_columns; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * @return string |
|
| 614 | - */ |
|
| 615 | - public function get_ajax_sorting_callback() |
|
| 616 | - { |
|
| 617 | - return $this->_ajax_sorting_callback; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @return array |
|
| 623 | - */ |
|
| 624 | - public function get_hidden_columns() |
|
| 625 | - { |
|
| 626 | - $user_id = get_current_user_id(); |
|
| 627 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 628 | - if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 629 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 630 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 631 | - } |
|
| 632 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 633 | - return (array)get_user_option($ref, $user_id); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Generates the columns for a single row of the table. |
|
| 639 | - * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 640 | - * column. |
|
| 641 | - * |
|
| 642 | - * @since 3.1.0 |
|
| 643 | - * @param EE_Base_Class $item The current item |
|
| 644 | - */ |
|
| 645 | - public function single_row_columns($item) |
|
| 646 | - { |
|
| 647 | - list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
| 648 | - |
|
| 649 | - global $wp_version; |
|
| 650 | - $use_hidden_class = version_compare($wp_version, '4.3-RC', '>='); |
|
| 651 | - |
|
| 652 | - foreach ($columns as $column_name => $column_display_name) { |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns are |
|
| 656 | - * hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 657 | - */ |
|
| 658 | - $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 659 | - $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
|
| 660 | - |
|
| 661 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 662 | - if ($primary === $column_name) { |
|
| 663 | - $classes .= ' has-row-actions column-primary'; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 667 | - |
|
| 668 | - $class = "class='$classes'"; |
|
| 669 | - |
|
| 670 | - $attributes = "$class$style$data"; |
|
| 671 | - |
|
| 672 | - if ($column_name === 'cb') { |
|
| 673 | - echo '<th scope="row" class="check-column">'; |
|
| 674 | - echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 675 | - $this->column_cb($item), $item, $this); |
|
| 676 | - echo '</th>'; |
|
| 677 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 678 | - echo "<td $attributes>"; |
|
| 679 | - echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 680 | - call_user_func(array($this, 'column_' . $column_name), $item), $item, $this); |
|
| 681 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 682 | - echo "</td>"; |
|
| 683 | - } else { |
|
| 684 | - echo "<td $attributes>"; |
|
| 685 | - echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 686 | - $this->column_default($item, $column_name), $item, $column_name, $this); |
|
| 687 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 688 | - echo "</td>"; |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Extra controls to be displayed between bulk actions and pagination |
|
| 696 | - * |
|
| 697 | - * @access public |
|
| 698 | - * @param string $which |
|
| 699 | - * @throws \EE_Error |
|
| 700 | - */ |
|
| 701 | - public function extra_tablenav($which) |
|
| 702 | - { |
|
| 703 | - if ($which === 'top') { |
|
| 704 | - $this->_filters(); |
|
| 705 | - echo $this->_get_hidden_fields(); |
|
| 706 | - } else { |
|
| 707 | - echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 708 | - foreach ($this->_bottom_buttons as $type => $action) { |
|
| 709 | - $route = isset($action['route']) ? $action['route'] : ''; |
|
| 710 | - $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
| 711 | - echo $this->_admin_page->get_action_link_or_button( |
|
| 712 | - $route, |
|
| 713 | - $type, |
|
| 714 | - $extra_request, |
|
| 715 | - 'button button-secondary', |
|
| 716 | - '', |
|
| 717 | - false |
|
| 718 | - ); |
|
| 719 | - } |
|
| 720 | - do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 721 | - echo '</div>'; |
|
| 722 | - } |
|
| 723 | - //echo $this->_entries_per_page_dropdown; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * Get an associative array ( option_name => option_title ) with the list |
|
| 729 | - * of bulk actions available on this table. |
|
| 730 | - * |
|
| 731 | - * @since 3.1.0 |
|
| 732 | - * @access protected |
|
| 733 | - * @return array |
|
| 734 | - */ |
|
| 735 | - public function get_bulk_actions() |
|
| 736 | - { |
|
| 737 | - return (array)$this->_get_bulk_actions(); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - public function process_bulk_action() |
|
| 741 | - { |
|
| 742 | - //this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for reference in case there is a case where it gets used. |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * returns the EE admin page this list table is associated with |
|
| 748 | - * |
|
| 749 | - * @return EE_Admin_Page |
|
| 750 | - */ |
|
| 751 | - public function get_admin_page() |
|
| 752 | - { |
|
| 753 | - return $this->_admin_page; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * A "helper" function for all children to provide an html string of |
|
| 759 | - * actions to output in their content. It is preferable for child classes |
|
| 760 | - * to use this method for generating their actions content so that it's |
|
| 761 | - * filterable by plugins |
|
| 762 | - * |
|
| 763 | - * @param string $action_container what are the html container |
|
| 764 | - * elements for this actions string? |
|
| 765 | - * @param string $action_class What class is for the container |
|
| 766 | - * element. |
|
| 767 | - * @param string $action_items The contents for the action items |
|
| 768 | - * container. This is filtered before |
|
| 769 | - * returned. |
|
| 770 | - * @param string $action_id What id (optional) is used for the |
|
| 771 | - * container element. |
|
| 772 | - * @param EE_Base_Class $item The object for the column displaying |
|
| 773 | - * the actions. |
|
| 774 | - * @return string The assembled action elements container. |
|
| 775 | - */ |
|
| 776 | - protected function _action_string( |
|
| 777 | - $action_items, |
|
| 778 | - $item, |
|
| 779 | - $action_container = 'ul', |
|
| 780 | - $action_class = '', |
|
| 781 | - $action_id = '' |
|
| 782 | - ) { |
|
| 783 | - $content = ''; |
|
| 784 | - $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
| 785 | - $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
| 786 | - $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 787 | - try { |
|
| 788 | - $content .= apply_filters( |
|
| 789 | - 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 790 | - $action_items, |
|
| 791 | - $item, |
|
| 792 | - $this |
|
| 793 | - ); |
|
| 794 | - } catch (\Exception $e) { |
|
| 795 | - if (WP_DEBUG) { |
|
| 796 | - \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 797 | - } |
|
| 798 | - $content .= $action_items; |
|
| 799 | - } |
|
| 800 | - $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 801 | - return $content; |
|
| 802 | - } |
|
| 25 | + /** |
|
| 26 | + * holds the data that will be processed for the table |
|
| 27 | + * |
|
| 28 | + * @var array $_data |
|
| 29 | + */ |
|
| 30 | + protected $_data; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This holds the value of all the data available for the given view (for all pages). |
|
| 35 | + * |
|
| 36 | + * @var int $_all_data_count |
|
| 37 | + */ |
|
| 38 | + protected $_all_data_count; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Will contain the count of trashed items for the view label. |
|
| 43 | + * |
|
| 44 | + * @var int $_trashed_count |
|
| 45 | + */ |
|
| 46 | + protected $_trashed_count; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * This is what will be referenced as the slug for the current screen |
|
| 51 | + * |
|
| 52 | + * @var string $_screen |
|
| 53 | + */ |
|
| 54 | + protected $_screen; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * this is the EE_Admin_Page object |
|
| 59 | + * |
|
| 60 | + * @var EE_Admin_Page $_admin_page |
|
| 61 | + */ |
|
| 62 | + protected $_admin_page; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * The current view |
|
| 67 | + * |
|
| 68 | + * @var string $_view |
|
| 69 | + */ |
|
| 70 | + protected $_view; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * array of possible views for this table |
|
| 75 | + * |
|
| 76 | + * @var array $_views |
|
| 77 | + */ |
|
| 78 | + protected $_views; |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * An array of key => value pairs containing information about the current table |
|
| 83 | + * array( |
|
| 84 | + * 'plural' => 'plural label', |
|
| 85 | + * 'singular' => 'singular label', |
|
| 86 | + * 'ajax' => false, //whether to use ajax or not |
|
| 87 | + * 'screen' => null, //string used to reference what screen this is |
|
| 88 | + * (WP_List_table converts to screen object) |
|
| 89 | + * ) |
|
| 90 | + * |
|
| 91 | + * @var array $_wp_list_args |
|
| 92 | + */ |
|
| 93 | + protected $_wp_list_args; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * an array of column names |
|
| 97 | + * array( |
|
| 98 | + * 'internal-name' => 'Title' |
|
| 99 | + * ) |
|
| 100 | + * |
|
| 101 | + * @var array $_columns |
|
| 102 | + */ |
|
| 103 | + protected $_columns; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of sortable columns |
|
| 107 | + * array( |
|
| 108 | + * 'internal-name' => 'orderby' //or |
|
| 109 | + * 'internal-name' => array( 'orderby', true ) |
|
| 110 | + * ) |
|
| 111 | + * |
|
| 112 | + * @var array $_sortable_columns |
|
| 113 | + */ |
|
| 114 | + protected $_sortable_columns; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * callback method used to perform AJAX row reordering |
|
| 118 | + * |
|
| 119 | + * @var string $_ajax_sorting_callback |
|
| 120 | + */ |
|
| 121 | + protected $_ajax_sorting_callback; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * An array of hidden columns (if needed) |
|
| 125 | + * array('internal-name', 'internal-name') |
|
| 126 | + * |
|
| 127 | + * @var array $_hidden_columns |
|
| 128 | + */ |
|
| 129 | + protected $_hidden_columns; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * holds the per_page value |
|
| 133 | + * |
|
| 134 | + * @var int $_per_page |
|
| 135 | + */ |
|
| 136 | + protected $_per_page; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * holds what page number is currently being viewed |
|
| 140 | + * |
|
| 141 | + * @var int $_current_page |
|
| 142 | + */ |
|
| 143 | + protected $_current_page; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * the reference string for the nonce_action |
|
| 147 | + * |
|
| 148 | + * @var string $_nonce_action_ref |
|
| 149 | + */ |
|
| 150 | + protected $_nonce_action_ref; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * property to hold incoming request data (as set by the admin_page_core) |
|
| 154 | + * |
|
| 155 | + * @var array $_req_data |
|
| 156 | + */ |
|
| 157 | + protected $_req_data; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * yes / no array for admin form fields |
|
| 162 | + * |
|
| 163 | + * @var array $_yes_no |
|
| 164 | + */ |
|
| 165 | + protected $_yes_no = array(); |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Array describing buttons that should appear at the bottom of the page |
|
| 169 | + * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 170 | + * and the values are another array with the following keys |
|
| 171 | + * array( |
|
| 172 | + * 'route' => 'page_route', |
|
| 173 | + * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 174 | + * ) |
|
| 175 | + * |
|
| 176 | + * @var array $_bottom_buttons |
|
| 177 | + */ |
|
| 178 | + protected $_bottom_buttons = array(); |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Used to indicate what should be the primary column for the list table. |
|
| 183 | + * If not present then falls back to what WP calculates |
|
| 184 | + * as the primary column. |
|
| 185 | + * |
|
| 186 | + * @type string $_primary_column |
|
| 187 | + */ |
|
| 188 | + protected $_primary_column = ''; |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Used to indicate whether the table has a checkbox column or not. |
|
| 193 | + * |
|
| 194 | + * @type bool $_has_checkbox_column |
|
| 195 | + */ |
|
| 196 | + protected $_has_checkbox_column = false; |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 201 | + */ |
|
| 202 | + public function __construct(EE_Admin_Page $admin_page) |
|
| 203 | + { |
|
| 204 | + $this->_admin_page = $admin_page; |
|
| 205 | + $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 206 | + $this->_view = $this->_admin_page->get_view(); |
|
| 207 | + $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 208 | + $this->_current_page = $this->get_pagenum(); |
|
| 209 | + $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 210 | + $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
|
| 211 | + |
|
| 212 | + $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10); |
|
| 213 | + |
|
| 214 | + $this->_setup_data(); |
|
| 215 | + $this->_add_view_counts(); |
|
| 216 | + |
|
| 217 | + $this->_nonce_action_ref = $this->_view; |
|
| 218 | + |
|
| 219 | + $this->_set_properties(); |
|
| 220 | + |
|
| 221 | + //set primary column |
|
| 222 | + add_filter('list_table_primary_column', array($this, 'set_primary_column')); |
|
| 223 | + |
|
| 224 | + //set parent defaults |
|
| 225 | + parent::__construct($this->_wp_list_args); |
|
| 226 | + |
|
| 227 | + $this->prepare_items(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * _setup_data |
|
| 233 | + * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 234 | + * |
|
| 235 | + * @uses $this->_admin_page |
|
| 236 | + * @return void |
|
| 237 | + */ |
|
| 238 | + abstract protected function _setup_data(); |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 243 | + * properties set: |
|
| 244 | + * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 245 | + * _columns = set the columns in an array. |
|
| 246 | + * _sortable_columns = columns that are sortable (array). |
|
| 247 | + * _hidden_columns = columns that are hidden (array) |
|
| 248 | + * _default_orderby = the default orderby for sorting. |
|
| 249 | + * |
|
| 250 | + * @abstract |
|
| 251 | + * @access protected |
|
| 252 | + * @return void |
|
| 253 | + */ |
|
| 254 | + abstract protected function _set_properties(); |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * _get_table_filters |
|
| 259 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 260 | + * get's shown in the table. |
|
| 261 | + * |
|
| 262 | + * @abstract |
|
| 263 | + * @access protected |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + abstract protected function _get_table_filters(); |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 271 | + * counts of the views is accurate. |
|
| 272 | + * |
|
| 273 | + * @abstract |
|
| 274 | + * @access protected |
|
| 275 | + * @return void |
|
| 276 | + */ |
|
| 277 | + abstract protected function _add_view_counts(); |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * _get_hidden_fields |
|
| 282 | + * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 283 | + * |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + protected function _get_hidden_fields() |
|
| 287 | + { |
|
| 288 | + $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 289 | + $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 290 | + //if action is STILL empty, then we set it to default |
|
| 291 | + $action = empty($action) ? 'default' : $action; |
|
| 292 | + $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
| 293 | + $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
| 294 | + $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
| 295 | + |
|
| 296 | + $bulk_actions = $this->_get_bulk_actions(); |
|
| 297 | + foreach ($bulk_actions as $bulk_action => $label) { |
|
| 298 | + $field .= '<input type="hidden" name="' . $bulk_action . '_nonce" value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + return $field; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * _set_column_info |
|
| 307 | + * we're using this to set the column headers property. |
|
| 308 | + * |
|
| 309 | + * @access protected |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + protected function _set_column_info() |
|
| 313 | + { |
|
| 314 | + $columns = $this->get_columns(); |
|
| 315 | + $hidden = $this->get_hidden_columns(); |
|
| 316 | + $_sortable = $this->get_sortable_columns(); |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 320 | + * Note that $this->screen->id is in the format |
|
| 321 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 322 | + * table it is: event-espresso_page_espresso_messages. |
|
| 323 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 324 | + * hook prefix ("event-espresso") will be different. |
|
| 325 | + * |
|
| 326 | + * @var array |
|
| 327 | + */ |
|
| 328 | + $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 329 | + |
|
| 330 | + $sortable = array(); |
|
| 331 | + foreach ($_sortable as $id => $data) { |
|
| 332 | + if (empty($data)) { |
|
| 333 | + continue; |
|
| 334 | + } |
|
| 335 | + //fix for offset errors with WP_List_Table default get_columninfo() |
|
| 336 | + if (is_array($data)) { |
|
| 337 | + $_data[0] = key($data); |
|
| 338 | + $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 339 | + } else { |
|
| 340 | + $_data[0] = $data; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + $data = (array)$data; |
|
| 344 | + |
|
| 345 | + if (! isset($data[1])) { |
|
| 346 | + $_data[1] = false; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + $sortable[$id] = $_data; |
|
| 350 | + } |
|
| 351 | + $primary = $this->get_primary_column_name(); |
|
| 352 | + $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 358 | + * |
|
| 359 | + * @return string |
|
| 360 | + */ |
|
| 361 | + protected function get_primary_column_name() |
|
| 362 | + { |
|
| 363 | + foreach (class_parents($this) as $parent) { |
|
| 364 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 365 | + return parent::get_primary_column_name(); |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + return $this->_primary_column; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 374 | + * |
|
| 375 | + * @param EE_Base_Class $item |
|
| 376 | + * @param string $column_name |
|
| 377 | + * @param string $primary |
|
| 378 | + * @return string |
|
| 379 | + */ |
|
| 380 | + protected function handle_row_actions($item, $column_name, $primary) |
|
| 381 | + { |
|
| 382 | + foreach (class_parents($this) as $parent) { |
|
| 383 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 384 | + return parent::handle_row_actions($item, $column_name, $primary); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + return ''; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * _get_bulk_actions |
|
| 393 | + * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 394 | + * |
|
| 395 | + * @access protected |
|
| 396 | + * @return array bulk_actions |
|
| 397 | + */ |
|
| 398 | + protected function _get_bulk_actions() |
|
| 399 | + { |
|
| 400 | + $actions = array(); |
|
| 401 | + //the _views property should have the bulk_actions, so let's go through and extract them into a properly formatted array for the wp_list_table(); |
|
| 402 | + foreach ($this->_views as $view => $args) { |
|
| 403 | + if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 404 | + //each bulk action will correspond with a admin page route, so we can check whatever the capability is for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 405 | + foreach ($args['bulk_action'] as $route => $label) { |
|
| 406 | + if ($this->_admin_page->check_user_access($route, true)) { |
|
| 407 | + $actions[$route] = $label; |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + return $actions; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * _filters |
|
| 418 | + * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 419 | + * button. |
|
| 420 | + * |
|
| 421 | + * @access private |
|
| 422 | + * @return string html showing filters |
|
| 423 | + */ |
|
| 424 | + private function _filters() |
|
| 425 | + { |
|
| 426 | + $classname = get_class($this); |
|
| 427 | + $filters = apply_filters("FHEE__{$classname}__filters", (array)$this->_get_table_filters(), $this, |
|
| 428 | + $this->_screen); |
|
| 429 | + |
|
| 430 | + if (empty($filters)) { |
|
| 431 | + return; |
|
| 432 | + } |
|
| 433 | + foreach ($filters as $filter) { |
|
| 434 | + echo $filter; |
|
| 435 | + } |
|
| 436 | + //add filter button at end |
|
| 437 | + echo '<input type="submit" class="button-secondary" value="' . __('Filter', |
|
| 438 | + 'event_espresso') . '" id="post-query-submit" />'; |
|
| 439 | + //add reset filters button at end |
|
| 440 | + echo '<a class="button button-secondary" href="' . $this->_admin_page->get_current_page_view_url() . '" style="display:inline-block">' . __('Reset Filters', |
|
| 441 | + 'event_espresso') . '</a>'; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Callback for 'list_table_primary_column' WordPress filter |
|
| 447 | + * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 448 | + * column when class is instantiated. |
|
| 449 | + * |
|
| 450 | + * @see WP_List_Table::get_primary_column_name |
|
| 451 | + * @param string $column_name |
|
| 452 | + * @return string |
|
| 453 | + */ |
|
| 454 | + public function set_primary_column($column_name) |
|
| 455 | + { |
|
| 456 | + return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * |
|
| 462 | + */ |
|
| 463 | + public function prepare_items() |
|
| 464 | + { |
|
| 465 | + |
|
| 466 | + $this->_set_column_info(); |
|
| 467 | + //$this->_column_headers = $this->get_column_info(); |
|
| 468 | + $total_items = $this->_all_data_count; |
|
| 469 | + $this->process_bulk_action(); |
|
| 470 | + |
|
| 471 | + $this->items = $this->_data; |
|
| 472 | + $this->set_pagination_args( |
|
| 473 | + array( |
|
| 474 | + 'total_items' => $total_items, |
|
| 475 | + 'per_page' => $this->_per_page, |
|
| 476 | + 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 477 | + ) |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * This column is the default for when there is no defined column method for a registered column. |
|
| 484 | + * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 485 | + * |
|
| 486 | + * @param EE_Base_Class $item |
|
| 487 | + * @param string $column_name The column being called. |
|
| 488 | + * @return string html content for the column |
|
| 489 | + */ |
|
| 490 | + public function column_default($item, $column_name) |
|
| 491 | + { |
|
| 492 | + /** |
|
| 493 | + * Dynamic hook allowing for adding additional column content in this list table. |
|
| 494 | + * Note that $this->screen->id is in the format |
|
| 495 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 496 | + * table it is: event-espresso_page_espresso_messages. |
|
| 497 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 498 | + * hook prefix ("event-espresso") will be different. |
|
| 499 | + */ |
|
| 500 | + do_action('AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, $item, |
|
| 501 | + $this->_screen); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Get a list of columns. The format is: |
|
| 507 | + * 'internal-name' => 'Title' |
|
| 508 | + * |
|
| 509 | + * @since 3.1.0 |
|
| 510 | + * @access public |
|
| 511 | + * @abstract |
|
| 512 | + * @return array |
|
| 513 | + */ |
|
| 514 | + public function get_columns() |
|
| 515 | + { |
|
| 516 | + /** |
|
| 517 | + * Dynamic hook allowing for adding additional columns in this list table. |
|
| 518 | + * Note that $this->screen->id is in the format |
|
| 519 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 520 | + * table it is: event-espresso_page_espresso_messages. |
|
| 521 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 522 | + * hook prefix ("event-espresso") will be different. |
|
| 523 | + * |
|
| 524 | + * @var array |
|
| 525 | + */ |
|
| 526 | + $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 527 | + return $columns; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Get an associative array ( id => link ) with the list |
|
| 533 | + * of views available on this table. |
|
| 534 | + * |
|
| 535 | + * @since 3.1.0 |
|
| 536 | + * @access protected |
|
| 537 | + * @return array |
|
| 538 | + */ |
|
| 539 | + public function get_views() |
|
| 540 | + { |
|
| 541 | + return $this->_views; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + public function display_views() |
|
| 545 | + { |
|
| 546 | + $views = $this->get_views(); |
|
| 547 | + $assembled_views = array(); |
|
| 548 | + |
|
| 549 | + if (empty($views)) { |
|
| 550 | + return; |
|
| 551 | + } |
|
| 552 | + echo "<ul class='subsubsub'>\n"; |
|
| 553 | + foreach ($views as $view) { |
|
| 554 | + $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 555 | + if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 556 | + $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>" . '<a href="' . $view['url'] . '">' . $view['label'] . '</a> <span class="count">(' . $count . ')</span>'; |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
| 561 | + echo "</ul>"; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Generates content for a single row of the table |
|
| 567 | + * |
|
| 568 | + * @since 4.1 |
|
| 569 | + * @access public |
|
| 570 | + * @param EE_Base_Class $item The current item |
|
| 571 | + */ |
|
| 572 | + public function single_row($item) |
|
| 573 | + { |
|
| 574 | + $row_class = $this->_get_row_class($item); |
|
| 575 | + echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 576 | + $this->single_row_columns($item); |
|
| 577 | + echo '</tr>'; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * This simply sets up the row class for the table rows. |
|
| 583 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 584 | + * |
|
| 585 | + * @param EE_Base_Class $item the current item |
|
| 586 | + * @return string |
|
| 587 | + */ |
|
| 588 | + protected function _get_row_class($item) |
|
| 589 | + { |
|
| 590 | + static $row_class = ''; |
|
| 591 | + $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 592 | + |
|
| 593 | + $new_row_class = $row_class; |
|
| 594 | + |
|
| 595 | + if (! empty($this->_ajax_sorting_callback)) { |
|
| 596 | + $new_row_class .= ' rowsortable'; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + return $new_row_class; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * @return array |
|
| 605 | + */ |
|
| 606 | + public function get_sortable_columns() |
|
| 607 | + { |
|
| 608 | + return (array)$this->_sortable_columns; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * @return string |
|
| 614 | + */ |
|
| 615 | + public function get_ajax_sorting_callback() |
|
| 616 | + { |
|
| 617 | + return $this->_ajax_sorting_callback; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @return array |
|
| 623 | + */ |
|
| 624 | + public function get_hidden_columns() |
|
| 625 | + { |
|
| 626 | + $user_id = get_current_user_id(); |
|
| 627 | + $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 628 | + if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 629 | + update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 630 | + update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 631 | + } |
|
| 632 | + $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 633 | + return (array)get_user_option($ref, $user_id); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Generates the columns for a single row of the table. |
|
| 639 | + * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 640 | + * column. |
|
| 641 | + * |
|
| 642 | + * @since 3.1.0 |
|
| 643 | + * @param EE_Base_Class $item The current item |
|
| 644 | + */ |
|
| 645 | + public function single_row_columns($item) |
|
| 646 | + { |
|
| 647 | + list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
| 648 | + |
|
| 649 | + global $wp_version; |
|
| 650 | + $use_hidden_class = version_compare($wp_version, '4.3-RC', '>='); |
|
| 651 | + |
|
| 652 | + foreach ($columns as $column_name => $column_display_name) { |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns are |
|
| 656 | + * hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 657 | + */ |
|
| 658 | + $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 659 | + $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
|
| 660 | + |
|
| 661 | + $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 662 | + if ($primary === $column_name) { |
|
| 663 | + $classes .= ' has-row-actions column-primary'; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 667 | + |
|
| 668 | + $class = "class='$classes'"; |
|
| 669 | + |
|
| 670 | + $attributes = "$class$style$data"; |
|
| 671 | + |
|
| 672 | + if ($column_name === 'cb') { |
|
| 673 | + echo '<th scope="row" class="check-column">'; |
|
| 674 | + echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 675 | + $this->column_cb($item), $item, $this); |
|
| 676 | + echo '</th>'; |
|
| 677 | + } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 678 | + echo "<td $attributes>"; |
|
| 679 | + echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 680 | + call_user_func(array($this, 'column_' . $column_name), $item), $item, $this); |
|
| 681 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 682 | + echo "</td>"; |
|
| 683 | + } else { |
|
| 684 | + echo "<td $attributes>"; |
|
| 685 | + echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 686 | + $this->column_default($item, $column_name), $item, $column_name, $this); |
|
| 687 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 688 | + echo "</td>"; |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Extra controls to be displayed between bulk actions and pagination |
|
| 696 | + * |
|
| 697 | + * @access public |
|
| 698 | + * @param string $which |
|
| 699 | + * @throws \EE_Error |
|
| 700 | + */ |
|
| 701 | + public function extra_tablenav($which) |
|
| 702 | + { |
|
| 703 | + if ($which === 'top') { |
|
| 704 | + $this->_filters(); |
|
| 705 | + echo $this->_get_hidden_fields(); |
|
| 706 | + } else { |
|
| 707 | + echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 708 | + foreach ($this->_bottom_buttons as $type => $action) { |
|
| 709 | + $route = isset($action['route']) ? $action['route'] : ''; |
|
| 710 | + $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
| 711 | + echo $this->_admin_page->get_action_link_or_button( |
|
| 712 | + $route, |
|
| 713 | + $type, |
|
| 714 | + $extra_request, |
|
| 715 | + 'button button-secondary', |
|
| 716 | + '', |
|
| 717 | + false |
|
| 718 | + ); |
|
| 719 | + } |
|
| 720 | + do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 721 | + echo '</div>'; |
|
| 722 | + } |
|
| 723 | + //echo $this->_entries_per_page_dropdown; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * Get an associative array ( option_name => option_title ) with the list |
|
| 729 | + * of bulk actions available on this table. |
|
| 730 | + * |
|
| 731 | + * @since 3.1.0 |
|
| 732 | + * @access protected |
|
| 733 | + * @return array |
|
| 734 | + */ |
|
| 735 | + public function get_bulk_actions() |
|
| 736 | + { |
|
| 737 | + return (array)$this->_get_bulk_actions(); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + public function process_bulk_action() |
|
| 741 | + { |
|
| 742 | + //this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for reference in case there is a case where it gets used. |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * returns the EE admin page this list table is associated with |
|
| 748 | + * |
|
| 749 | + * @return EE_Admin_Page |
|
| 750 | + */ |
|
| 751 | + public function get_admin_page() |
|
| 752 | + { |
|
| 753 | + return $this->_admin_page; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * A "helper" function for all children to provide an html string of |
|
| 759 | + * actions to output in their content. It is preferable for child classes |
|
| 760 | + * to use this method for generating their actions content so that it's |
|
| 761 | + * filterable by plugins |
|
| 762 | + * |
|
| 763 | + * @param string $action_container what are the html container |
|
| 764 | + * elements for this actions string? |
|
| 765 | + * @param string $action_class What class is for the container |
|
| 766 | + * element. |
|
| 767 | + * @param string $action_items The contents for the action items |
|
| 768 | + * container. This is filtered before |
|
| 769 | + * returned. |
|
| 770 | + * @param string $action_id What id (optional) is used for the |
|
| 771 | + * container element. |
|
| 772 | + * @param EE_Base_Class $item The object for the column displaying |
|
| 773 | + * the actions. |
|
| 774 | + * @return string The assembled action elements container. |
|
| 775 | + */ |
|
| 776 | + protected function _action_string( |
|
| 777 | + $action_items, |
|
| 778 | + $item, |
|
| 779 | + $action_container = 'ul', |
|
| 780 | + $action_class = '', |
|
| 781 | + $action_id = '' |
|
| 782 | + ) { |
|
| 783 | + $content = ''; |
|
| 784 | + $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
| 785 | + $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
| 786 | + $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 787 | + try { |
|
| 788 | + $content .= apply_filters( |
|
| 789 | + 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 790 | + $action_items, |
|
| 791 | + $item, |
|
| 792 | + $this |
|
| 793 | + ); |
|
| 794 | + } catch (\Exception $e) { |
|
| 795 | + if (WP_DEBUG) { |
|
| 796 | + \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 797 | + } |
|
| 798 | + $content .= $action_items; |
|
| 799 | + } |
|
| 800 | + $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 801 | + return $content; |
|
| 802 | + } |
|
| 803 | 803 | } |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | -if (! class_exists('WP_List_Table')) { |
|
| 6 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); |
|
| 5 | +if ( ! class_exists('WP_List_Table')) { |
|
| 6 | + require_once(ABSPATH.'wp-admin/includes/class-wp-list-table.php'); |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
@@ -206,10 +206,10 @@ discard block |
||
| 206 | 206 | $this->_view = $this->_admin_page->get_view(); |
| 207 | 207 | $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
| 208 | 208 | $this->_current_page = $this->get_pagenum(); |
| 209 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 209 | + $this->_screen = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view(); |
|
| 210 | 210 | $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
| 211 | 211 | |
| 212 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10); |
|
| 212 | + $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page', 10); |
|
| 213 | 213 | |
| 214 | 214 | $this->_setup_data(); |
| 215 | 215 | $this->_add_view_counts(); |
@@ -289,13 +289,13 @@ discard block |
||
| 289 | 289 | $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
| 290 | 290 | //if action is STILL empty, then we set it to default |
| 291 | 291 | $action = empty($action) ? 'default' : $action; |
| 292 | - $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
| 293 | - $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
| 294 | - $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
| 292 | + $field = '<input type="hidden" name="page" value="'.$this->_req_data['page'].'" />'."\n"; |
|
| 293 | + $field .= '<input type="hidden" name="route" value="'.$action.'" />'."\n"; /**/ |
|
| 294 | + $field .= '<input type="hidden" name="perpage" value="'.$this->_per_page.'" />'."\n"; |
|
| 295 | 295 | |
| 296 | 296 | $bulk_actions = $this->_get_bulk_actions(); |
| 297 | 297 | foreach ($bulk_actions as $bulk_action => $label) { |
| 298 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce" value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 298 | + $field .= '<input type="hidden" name="'.$bulk_action.'_nonce" value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n"; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | return $field; |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | $_data[0] = $data; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - $data = (array)$data; |
|
| 343 | + $data = (array) $data; |
|
| 344 | 344 | |
| 345 | - if (! isset($data[1])) { |
|
| 345 | + if ( ! isset($data[1])) { |
|
| 346 | 346 | $_data[1] = false; |
| 347 | 347 | } |
| 348 | 348 | |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | private function _filters() |
| 425 | 425 | { |
| 426 | 426 | $classname = get_class($this); |
| 427 | - $filters = apply_filters("FHEE__{$classname}__filters", (array)$this->_get_table_filters(), $this, |
|
| 427 | + $filters = apply_filters("FHEE__{$classname}__filters", (array) $this->_get_table_filters(), $this, |
|
| 428 | 428 | $this->_screen); |
| 429 | 429 | |
| 430 | 430 | if (empty($filters)) { |
@@ -434,11 +434,11 @@ discard block |
||
| 434 | 434 | echo $filter; |
| 435 | 435 | } |
| 436 | 436 | //add filter button at end |
| 437 | - echo '<input type="submit" class="button-secondary" value="' . __('Filter', |
|
| 438 | - 'event_espresso') . '" id="post-query-submit" />'; |
|
| 437 | + echo '<input type="submit" class="button-secondary" value="'.__('Filter', |
|
| 438 | + 'event_espresso').'" id="post-query-submit" />'; |
|
| 439 | 439 | //add reset filters button at end |
| 440 | - echo '<a class="button button-secondary" href="' . $this->_admin_page->get_current_page_view_url() . '" style="display:inline-block">' . __('Reset Filters', |
|
| 441 | - 'event_espresso') . '</a>'; |
|
| 440 | + echo '<a class="button button-secondary" href="'.$this->_admin_page->get_current_page_view_url().'" style="display:inline-block">'.__('Reset Filters', |
|
| 441 | + 'event_espresso').'</a>'; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
| 498 | 498 | * hook prefix ("event-espresso") will be different. |
| 499 | 499 | */ |
| 500 | - do_action('AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, $item, |
|
| 500 | + do_action('AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id, $item, |
|
| 501 | 501 | $this->_screen); |
| 502 | 502 | } |
| 503 | 503 | |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | * |
| 524 | 524 | * @var array |
| 525 | 525 | */ |
| 526 | - $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 526 | + $columns = apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen); |
|
| 527 | 527 | return $columns; |
| 528 | 528 | } |
| 529 | 529 | |
@@ -553,11 +553,11 @@ discard block |
||
| 553 | 553 | foreach ($views as $view) { |
| 554 | 554 | $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
| 555 | 555 | if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
| 556 | - $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>" . '<a href="' . $view['url'] . '">' . $view['label'] . '</a> <span class="count">(' . $count . ')</span>'; |
|
| 556 | + $assembled_views[$view['slug']] = "\t<li class='".$view['class']."'>".'<a href="'.$view['url'].'">'.$view['label'].'</a> <span class="count">('.$count.')</span>'; |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | - echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
| 560 | + echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views)."</li>\n" : ''; |
|
| 561 | 561 | echo "</ul>"; |
| 562 | 562 | } |
| 563 | 563 | |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | public function single_row($item) |
| 573 | 573 | { |
| 574 | 574 | $row_class = $this->_get_row_class($item); |
| 575 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 575 | + echo '<tr class="'.esc_attr($row_class).'">'; |
|
| 576 | 576 | $this->single_row_columns($item); |
| 577 | 577 | echo '</tr>'; |
| 578 | 578 | } |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | |
| 593 | 593 | $new_row_class = $row_class; |
| 594 | 594 | |
| 595 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 595 | + if ( ! empty($this->_ajax_sorting_callback)) { |
|
| 596 | 596 | $new_row_class .= ' rowsortable'; |
| 597 | 597 | } |
| 598 | 598 | |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | */ |
| 606 | 606 | public function get_sortable_columns() |
| 607 | 607 | { |
| 608 | - return (array)$this->_sortable_columns; |
|
| 608 | + return (array) $this->_sortable_columns; |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | |
@@ -624,13 +624,13 @@ discard block |
||
| 624 | 624 | public function get_hidden_columns() |
| 625 | 625 | { |
| 626 | 626 | $user_id = get_current_user_id(); |
| 627 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 627 | + $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id); |
|
| 628 | 628 | if (empty($has_default) && ! empty($this->_hidden_columns)) { |
| 629 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 630 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 629 | + update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true); |
|
| 630 | + update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true); |
|
| 631 | 631 | } |
| 632 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 633 | - return (array)get_user_option($ref, $user_id); |
|
| 632 | + $ref = 'manage'.$this->screen->id.'columnshidden'; |
|
| 633 | + return (array) get_user_option($ref, $user_id); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | |
@@ -658,12 +658,12 @@ discard block |
||
| 658 | 658 | $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
| 659 | 659 | $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
| 660 | 660 | |
| 661 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 661 | + $classes = $column_name.' column-'.$column_name.$hidden_class; |
|
| 662 | 662 | if ($primary === $column_name) { |
| 663 | 663 | $classes .= ' has-row-actions column-primary'; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 666 | + $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"'; |
|
| 667 | 667 | |
| 668 | 668 | $class = "class='$classes'"; |
| 669 | 669 | |
@@ -674,10 +674,10 @@ discard block |
||
| 674 | 674 | echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
| 675 | 675 | $this->column_cb($item), $item, $this); |
| 676 | 676 | echo '</th>'; |
| 677 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 677 | + } elseif (method_exists($this, 'column_'.$column_name)) { |
|
| 678 | 678 | echo "<td $attributes>"; |
| 679 | - echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 680 | - call_user_func(array($this, 'column_' . $column_name), $item), $item, $this); |
|
| 679 | + echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content', |
|
| 680 | + call_user_func(array($this, 'column_'.$column_name), $item), $item, $this); |
|
| 681 | 681 | echo $this->handle_row_actions($item, $column_name, $primary); |
| 682 | 682 | echo "</td>"; |
| 683 | 683 | } else { |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | */ |
| 735 | 735 | public function get_bulk_actions() |
| 736 | 736 | { |
| 737 | - return (array)$this->_get_bulk_actions(); |
|
| 737 | + return (array) $this->_get_bulk_actions(); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | public function process_bulk_action() |
@@ -781,9 +781,9 @@ discard block |
||
| 781 | 781 | $action_id = '' |
| 782 | 782 | ) { |
| 783 | 783 | $content = ''; |
| 784 | - $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
| 785 | - $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
| 786 | - $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 784 | + $action_class = ! empty($action_class) ? ' class="'.$action_class.'"' : ''; |
|
| 785 | + $action_id = ! empty($action_id) ? ' id="'.$action_id.'"' : ''; |
|
| 786 | + $content .= ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : ''; |
|
| 787 | 787 | try { |
| 788 | 788 | $content .= apply_filters( |
| 789 | 789 | 'FHEE__EE_Admin_List_Table___action_string__action_items', |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | } |
| 798 | 798 | $content .= $action_items; |
| 799 | 799 | } |
| 800 | - $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 800 | + $content .= ! empty($action_container) ? '</'.$action_container.'>' : ''; |
|
| 801 | 801 | return $content; |
| 802 | 802 | } |
| 803 | 803 | } |
@@ -23,396 +23,396 @@ |
||
| 23 | 23 | class Registry |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Template_Config $template_config |
|
| 28 | - */ |
|
| 29 | - protected $template_config; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Currency_Config $currency_config |
|
| 33 | - */ |
|
| 34 | - protected $currency_config; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $jsdata = array(); |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Registry constructor. |
|
| 47 | - * Hooking into WP actions for script registry. |
|
| 48 | - * |
|
| 49 | - * @param EE_Template_Config $template_config |
|
| 50 | - * @param EE_Currency_Config $currency_config |
|
| 51 | - */ |
|
| 52 | - public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config) |
|
| 53 | - { |
|
| 54 | - $this->template_config = $template_config; |
|
| 55 | - $this->currency_config = $currency_config; |
|
| 56 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 57 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 58 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 59 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 60 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 61 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Callback for the WP script actions. |
|
| 68 | - * Used to register globally accessible core scripts. |
|
| 69 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 70 | - */ |
|
| 71 | - public function scripts() |
|
| 72 | - { |
|
| 73 | - global $wp_version; |
|
| 74 | - wp_register_script( |
|
| 75 | - 'eejs-core', |
|
| 76 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 77 | - array(), |
|
| 78 | - EVENT_ESPRESSO_VERSION, |
|
| 79 | - true |
|
| 80 | - ); |
|
| 81 | - //only run this if WordPress 4.4.0 > is in use. |
|
| 82 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 83 | - //js.api |
|
| 84 | - wp_register_script( |
|
| 85 | - 'eejs-api', |
|
| 86 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 87 | - array('underscore', 'eejs-core'), |
|
| 88 | - EVENT_ESPRESSO_VERSION, |
|
| 89 | - true |
|
| 90 | - ); |
|
| 91 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 92 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 93 | - } |
|
| 94 | - if (! is_admin()) { |
|
| 95 | - $this->loadCoreCss(); |
|
| 96 | - } |
|
| 97 | - $this->loadCoreJs(); |
|
| 98 | - $this->loadJqueryValidate(); |
|
| 99 | - $this->loadAccountingJs(); |
|
| 100 | - $this->loadQtipJs(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Call back for the script print in frontend and backend. |
|
| 107 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 108 | - * |
|
| 109 | - * @since 4.9.31.rc.015 |
|
| 110 | - */ |
|
| 111 | - public function enqueueData() |
|
| 112 | - { |
|
| 113 | - wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 114 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 115 | - $this->localizeAccountingJs(); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Used to add data to eejs.data object. |
|
| 122 | - * Note: Overriding existing data is not allowed. |
|
| 123 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 124 | - * If the data you add is something like this: |
|
| 125 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 126 | - * It will be exposed in the page source as: |
|
| 127 | - * eejs.data.my_plugin_data.foo == gar |
|
| 128 | - * |
|
| 129 | - * @param string $key Key used to access your data |
|
| 130 | - * @param string|array $value Value to attach to key |
|
| 131 | - * @throws InvalidArgumentException |
|
| 132 | - */ |
|
| 133 | - public function addData($key, $value) |
|
| 134 | - { |
|
| 135 | - if ($this->verifyDataNotExisting($key)) { |
|
| 136 | - $this->jsdata[$key] = $value; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 144 | - * elements in an array. |
|
| 145 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 146 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 147 | - * object like this, eejs.data.test = [ my_data, |
|
| 148 | - * ] |
|
| 149 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 150 | - * this will throw an exception. |
|
| 151 | - * |
|
| 152 | - * @param string $key Key to attach data to. |
|
| 153 | - * @param string|array $value Value being registered. |
|
| 154 | - * @throws InvalidArgumentException |
|
| 155 | - */ |
|
| 156 | - public function pushData($key, $value) |
|
| 157 | - { |
|
| 158 | - if (isset($this->jsdata[$key]) |
|
| 159 | - && ! is_array($this->jsdata[$key]) |
|
| 160 | - ) { |
|
| 161 | - throw new invalidArgumentException( |
|
| 162 | - sprintf( |
|
| 163 | - __( |
|
| 164 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 26 | + /** |
|
| 27 | + * @var EE_Template_Config $template_config |
|
| 28 | + */ |
|
| 29 | + protected $template_config; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Currency_Config $currency_config |
|
| 33 | + */ |
|
| 34 | + protected $currency_config; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $jsdata = array(); |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Registry constructor. |
|
| 47 | + * Hooking into WP actions for script registry. |
|
| 48 | + * |
|
| 49 | + * @param EE_Template_Config $template_config |
|
| 50 | + * @param EE_Currency_Config $currency_config |
|
| 51 | + */ |
|
| 52 | + public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config) |
|
| 53 | + { |
|
| 54 | + $this->template_config = $template_config; |
|
| 55 | + $this->currency_config = $currency_config; |
|
| 56 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 57 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 58 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 59 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 60 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 61 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Callback for the WP script actions. |
|
| 68 | + * Used to register globally accessible core scripts. |
|
| 69 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 70 | + */ |
|
| 71 | + public function scripts() |
|
| 72 | + { |
|
| 73 | + global $wp_version; |
|
| 74 | + wp_register_script( |
|
| 75 | + 'eejs-core', |
|
| 76 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 77 | + array(), |
|
| 78 | + EVENT_ESPRESSO_VERSION, |
|
| 79 | + true |
|
| 80 | + ); |
|
| 81 | + //only run this if WordPress 4.4.0 > is in use. |
|
| 82 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 83 | + //js.api |
|
| 84 | + wp_register_script( |
|
| 85 | + 'eejs-api', |
|
| 86 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 87 | + array('underscore', 'eejs-core'), |
|
| 88 | + EVENT_ESPRESSO_VERSION, |
|
| 89 | + true |
|
| 90 | + ); |
|
| 91 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 92 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 93 | + } |
|
| 94 | + if (! is_admin()) { |
|
| 95 | + $this->loadCoreCss(); |
|
| 96 | + } |
|
| 97 | + $this->loadCoreJs(); |
|
| 98 | + $this->loadJqueryValidate(); |
|
| 99 | + $this->loadAccountingJs(); |
|
| 100 | + $this->loadQtipJs(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Call back for the script print in frontend and backend. |
|
| 107 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 108 | + * |
|
| 109 | + * @since 4.9.31.rc.015 |
|
| 110 | + */ |
|
| 111 | + public function enqueueData() |
|
| 112 | + { |
|
| 113 | + wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 114 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 115 | + $this->localizeAccountingJs(); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Used to add data to eejs.data object. |
|
| 122 | + * Note: Overriding existing data is not allowed. |
|
| 123 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 124 | + * If the data you add is something like this: |
|
| 125 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 126 | + * It will be exposed in the page source as: |
|
| 127 | + * eejs.data.my_plugin_data.foo == gar |
|
| 128 | + * |
|
| 129 | + * @param string $key Key used to access your data |
|
| 130 | + * @param string|array $value Value to attach to key |
|
| 131 | + * @throws InvalidArgumentException |
|
| 132 | + */ |
|
| 133 | + public function addData($key, $value) |
|
| 134 | + { |
|
| 135 | + if ($this->verifyDataNotExisting($key)) { |
|
| 136 | + $this->jsdata[$key] = $value; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 144 | + * elements in an array. |
|
| 145 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 146 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 147 | + * object like this, eejs.data.test = [ my_data, |
|
| 148 | + * ] |
|
| 149 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 150 | + * this will throw an exception. |
|
| 151 | + * |
|
| 152 | + * @param string $key Key to attach data to. |
|
| 153 | + * @param string|array $value Value being registered. |
|
| 154 | + * @throws InvalidArgumentException |
|
| 155 | + */ |
|
| 156 | + public function pushData($key, $value) |
|
| 157 | + { |
|
| 158 | + if (isset($this->jsdata[$key]) |
|
| 159 | + && ! is_array($this->jsdata[$key]) |
|
| 160 | + ) { |
|
| 161 | + throw new invalidArgumentException( |
|
| 162 | + sprintf( |
|
| 163 | + __( |
|
| 164 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 165 | 165 | push values to this data element when it is an array.', |
| 166 | - 'event_espresso' |
|
| 167 | - ), |
|
| 168 | - $key, |
|
| 169 | - __METHOD__ |
|
| 170 | - ) |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - $this->jsdata[$key][] = $value; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Used to set content used by javascript for a template. |
|
| 180 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 181 | - * |
|
| 182 | - * @param string $template_reference |
|
| 183 | - * @param string $template_content |
|
| 184 | - * @throws InvalidArgumentException |
|
| 185 | - */ |
|
| 186 | - public function addTemplate($template_reference, $template_content) |
|
| 187 | - { |
|
| 188 | - if (! isset($this->jsdata['templates'])) { |
|
| 189 | - $this->jsdata['templates'] = array(); |
|
| 190 | - } |
|
| 191 | - //no overrides allowed. |
|
| 192 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 193 | - throw new invalidArgumentException( |
|
| 194 | - sprintf( |
|
| 195 | - __( |
|
| 196 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 197 | - 'event_espresso' |
|
| 198 | - ), |
|
| 199 | - $template_reference |
|
| 200 | - ) |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Retrieve the template content already registered for the given reference. |
|
| 210 | - * |
|
| 211 | - * @param string $template_reference |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public function getTemplate($template_reference) |
|
| 215 | - { |
|
| 216 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 217 | - ? $this->jsdata['templates'][$template_reference] |
|
| 218 | - : ''; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Retrieve registered data. |
|
| 225 | - * |
|
| 226 | - * @param string $key Name of key to attach data to. |
|
| 227 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 228 | - */ |
|
| 229 | - public function getData($key) |
|
| 230 | - { |
|
| 231 | - return isset($this->jsdata[$key]) |
|
| 232 | - ? $this->jsdata[$key] |
|
| 233 | - : false; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 240 | - * Overriding data is not allowed. |
|
| 241 | - * |
|
| 242 | - * @param string $key Index for data. |
|
| 243 | - * @return bool If valid then return true. |
|
| 244 | - * @throws InvalidArgumentException if data already exists. |
|
| 245 | - */ |
|
| 246 | - protected function verifyDataNotExisting($key) |
|
| 247 | - { |
|
| 248 | - if (isset($this->jsdata[$key])) { |
|
| 249 | - if (is_array($this->jsdata[$key])) { |
|
| 250 | - throw new InvalidArgumentException( |
|
| 251 | - sprintf( |
|
| 252 | - __( |
|
| 253 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 166 | + 'event_espresso' |
|
| 167 | + ), |
|
| 168 | + $key, |
|
| 169 | + __METHOD__ |
|
| 170 | + ) |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + $this->jsdata[$key][] = $value; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Used to set content used by javascript for a template. |
|
| 180 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 181 | + * |
|
| 182 | + * @param string $template_reference |
|
| 183 | + * @param string $template_content |
|
| 184 | + * @throws InvalidArgumentException |
|
| 185 | + */ |
|
| 186 | + public function addTemplate($template_reference, $template_content) |
|
| 187 | + { |
|
| 188 | + if (! isset($this->jsdata['templates'])) { |
|
| 189 | + $this->jsdata['templates'] = array(); |
|
| 190 | + } |
|
| 191 | + //no overrides allowed. |
|
| 192 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 193 | + throw new invalidArgumentException( |
|
| 194 | + sprintf( |
|
| 195 | + __( |
|
| 196 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 197 | + 'event_espresso' |
|
| 198 | + ), |
|
| 199 | + $template_reference |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Retrieve the template content already registered for the given reference. |
|
| 210 | + * |
|
| 211 | + * @param string $template_reference |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public function getTemplate($template_reference) |
|
| 215 | + { |
|
| 216 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 217 | + ? $this->jsdata['templates'][$template_reference] |
|
| 218 | + : ''; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Retrieve registered data. |
|
| 225 | + * |
|
| 226 | + * @param string $key Name of key to attach data to. |
|
| 227 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 228 | + */ |
|
| 229 | + public function getData($key) |
|
| 230 | + { |
|
| 231 | + return isset($this->jsdata[$key]) |
|
| 232 | + ? $this->jsdata[$key] |
|
| 233 | + : false; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 240 | + * Overriding data is not allowed. |
|
| 241 | + * |
|
| 242 | + * @param string $key Index for data. |
|
| 243 | + * @return bool If valid then return true. |
|
| 244 | + * @throws InvalidArgumentException if data already exists. |
|
| 245 | + */ |
|
| 246 | + protected function verifyDataNotExisting($key) |
|
| 247 | + { |
|
| 248 | + if (isset($this->jsdata[$key])) { |
|
| 249 | + if (is_array($this->jsdata[$key])) { |
|
| 250 | + throw new InvalidArgumentException( |
|
| 251 | + sprintf( |
|
| 252 | + __( |
|
| 253 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 254 | 254 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 255 | 255 | %2$s method to push your value to the array.', |
| 256 | - 'event_espresso' |
|
| 257 | - ), |
|
| 258 | - $key, |
|
| 259 | - 'pushData()' |
|
| 260 | - ) |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - throw new InvalidArgumentException( |
|
| 264 | - sprintf( |
|
| 265 | - __( |
|
| 266 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 256 | + 'event_espresso' |
|
| 257 | + ), |
|
| 258 | + $key, |
|
| 259 | + 'pushData()' |
|
| 260 | + ) |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + throw new InvalidArgumentException( |
|
| 264 | + sprintf( |
|
| 265 | + __( |
|
| 266 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 267 | 267 | allowed. Consider attaching your value to a different key', |
| 268 | - 'event_espresso' |
|
| 269 | - ), |
|
| 270 | - $key |
|
| 271 | - ) |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - return true; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * registers core default stylesheets |
|
| 281 | - */ |
|
| 282 | - private function loadCoreCss() |
|
| 283 | - { |
|
| 284 | - if ($this->template_config->enable_default_style) { |
|
| 285 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 286 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 287 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 288 | - wp_register_style( |
|
| 289 | - 'espresso_default', |
|
| 290 | - $default_stylesheet_path, |
|
| 291 | - array('dashicons'), |
|
| 292 | - EVENT_ESPRESSO_VERSION |
|
| 293 | - ); |
|
| 294 | - //Load custom style sheet if available |
|
| 295 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 296 | - wp_register_style( |
|
| 297 | - 'espresso_custom_css', |
|
| 298 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 299 | - array('espresso_default'), |
|
| 300 | - EVENT_ESPRESSO_VERSION |
|
| 301 | - ); |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * registers core default javascript |
|
| 310 | - */ |
|
| 311 | - private function loadCoreJs() |
|
| 312 | - { |
|
| 313 | - // load core js |
|
| 314 | - wp_register_script( |
|
| 315 | - 'espresso_core', |
|
| 316 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 317 | - array('jquery'), |
|
| 318 | - EVENT_ESPRESSO_VERSION, |
|
| 319 | - true |
|
| 320 | - ); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * registers jQuery Validate for form validation |
|
| 327 | - */ |
|
| 328 | - private function loadJqueryValidate() |
|
| 329 | - { |
|
| 330 | - // register jQuery Validate and additional methods |
|
| 331 | - wp_register_script( |
|
| 332 | - 'jquery-validate', |
|
| 333 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 334 | - array('jquery'), |
|
| 335 | - '1.15.0', |
|
| 336 | - true |
|
| 337 | - ); |
|
| 338 | - wp_register_script( |
|
| 339 | - 'jquery-validate-extra-methods', |
|
| 340 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 341 | - array('jquery', 'jquery-validate'), |
|
| 342 | - '1.15.0', |
|
| 343 | - true |
|
| 344 | - ); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * registers accounting.js for performing client-side calculations |
|
| 351 | - */ |
|
| 352 | - private function loadAccountingJs() |
|
| 353 | - { |
|
| 354 | - //accounting.js library |
|
| 355 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 356 | - wp_register_script( |
|
| 357 | - 'ee-accounting-core', |
|
| 358 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 359 | - array('underscore'), |
|
| 360 | - '0.3.2', |
|
| 361 | - true |
|
| 362 | - ); |
|
| 363 | - wp_register_script( |
|
| 364 | - 'ee-accounting', |
|
| 365 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 366 | - array('ee-accounting-core'), |
|
| 367 | - EVENT_ESPRESSO_VERSION, |
|
| 368 | - true |
|
| 369 | - ); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * registers accounting.js for performing client-side calculations |
|
| 376 | - */ |
|
| 377 | - private function localizeAccountingJs() |
|
| 378 | - { |
|
| 379 | - wp_localize_script( |
|
| 380 | - 'ee-accounting', |
|
| 381 | - 'EE_ACCOUNTING_CFG', |
|
| 382 | - array( |
|
| 383 | - 'currency' => array( |
|
| 384 | - 'symbol' => $this->currency_config->sign, |
|
| 385 | - 'format' => array( |
|
| 386 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 387 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 388 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 389 | - ), |
|
| 390 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 391 | - 'thousand' => $this->currency_config->thsnds, |
|
| 392 | - 'precision' => $this->currency_config->dec_plc, |
|
| 393 | - ), |
|
| 394 | - 'number' => array( |
|
| 395 | - 'precision' => $this->currency_config->dec_plc, |
|
| 396 | - 'thousand' => $this->currency_config->thsnds, |
|
| 397 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 398 | - ), |
|
| 399 | - ) |
|
| 400 | - ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * registers assets for cleaning your ears |
|
| 407 | - */ |
|
| 408 | - private function loadQtipJs() |
|
| 409 | - { |
|
| 410 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 411 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 412 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 413 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 414 | - } |
|
| 415 | - } |
|
| 268 | + 'event_espresso' |
|
| 269 | + ), |
|
| 270 | + $key |
|
| 271 | + ) |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + return true; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * registers core default stylesheets |
|
| 281 | + */ |
|
| 282 | + private function loadCoreCss() |
|
| 283 | + { |
|
| 284 | + if ($this->template_config->enable_default_style) { |
|
| 285 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 286 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 287 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 288 | + wp_register_style( |
|
| 289 | + 'espresso_default', |
|
| 290 | + $default_stylesheet_path, |
|
| 291 | + array('dashicons'), |
|
| 292 | + EVENT_ESPRESSO_VERSION |
|
| 293 | + ); |
|
| 294 | + //Load custom style sheet if available |
|
| 295 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 296 | + wp_register_style( |
|
| 297 | + 'espresso_custom_css', |
|
| 298 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 299 | + array('espresso_default'), |
|
| 300 | + EVENT_ESPRESSO_VERSION |
|
| 301 | + ); |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * registers core default javascript |
|
| 310 | + */ |
|
| 311 | + private function loadCoreJs() |
|
| 312 | + { |
|
| 313 | + // load core js |
|
| 314 | + wp_register_script( |
|
| 315 | + 'espresso_core', |
|
| 316 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 317 | + array('jquery'), |
|
| 318 | + EVENT_ESPRESSO_VERSION, |
|
| 319 | + true |
|
| 320 | + ); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * registers jQuery Validate for form validation |
|
| 327 | + */ |
|
| 328 | + private function loadJqueryValidate() |
|
| 329 | + { |
|
| 330 | + // register jQuery Validate and additional methods |
|
| 331 | + wp_register_script( |
|
| 332 | + 'jquery-validate', |
|
| 333 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 334 | + array('jquery'), |
|
| 335 | + '1.15.0', |
|
| 336 | + true |
|
| 337 | + ); |
|
| 338 | + wp_register_script( |
|
| 339 | + 'jquery-validate-extra-methods', |
|
| 340 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 341 | + array('jquery', 'jquery-validate'), |
|
| 342 | + '1.15.0', |
|
| 343 | + true |
|
| 344 | + ); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * registers accounting.js for performing client-side calculations |
|
| 351 | + */ |
|
| 352 | + private function loadAccountingJs() |
|
| 353 | + { |
|
| 354 | + //accounting.js library |
|
| 355 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 356 | + wp_register_script( |
|
| 357 | + 'ee-accounting-core', |
|
| 358 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 359 | + array('underscore'), |
|
| 360 | + '0.3.2', |
|
| 361 | + true |
|
| 362 | + ); |
|
| 363 | + wp_register_script( |
|
| 364 | + 'ee-accounting', |
|
| 365 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 366 | + array('ee-accounting-core'), |
|
| 367 | + EVENT_ESPRESSO_VERSION, |
|
| 368 | + true |
|
| 369 | + ); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * registers accounting.js for performing client-side calculations |
|
| 376 | + */ |
|
| 377 | + private function localizeAccountingJs() |
|
| 378 | + { |
|
| 379 | + wp_localize_script( |
|
| 380 | + 'ee-accounting', |
|
| 381 | + 'EE_ACCOUNTING_CFG', |
|
| 382 | + array( |
|
| 383 | + 'currency' => array( |
|
| 384 | + 'symbol' => $this->currency_config->sign, |
|
| 385 | + 'format' => array( |
|
| 386 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 387 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 388 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 389 | + ), |
|
| 390 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 391 | + 'thousand' => $this->currency_config->thsnds, |
|
| 392 | + 'precision' => $this->currency_config->dec_plc, |
|
| 393 | + ), |
|
| 394 | + 'number' => array( |
|
| 395 | + 'precision' => $this->currency_config->dec_plc, |
|
| 396 | + 'thousand' => $this->currency_config->thsnds, |
|
| 397 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 398 | + ), |
|
| 399 | + ) |
|
| 400 | + ); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * registers assets for cleaning your ears |
|
| 407 | + */ |
|
| 408 | + private function loadQtipJs() |
|
| 409 | + { |
|
| 410 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 411 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 412 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 413 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | 417 | |
| 418 | 418 | |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\Codeception\helpers; |
| 3 | 3 | |
| 4 | -use Page\CoreAdmin; |
|
| 5 | 4 | use Page\CountrySettingsAdmin as CountrySettings; |
| 6 | 5 | |
| 7 | 6 | trait CountrySettingsAdmin |
@@ -6,59 +6,59 @@ |
||
| 6 | 6 | |
| 7 | 7 | trait CountrySettingsAdmin |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Instructs the actor to browse to the country settings page. |
|
| 11 | - * Assumes the actor is already logged in. |
|
| 12 | - * @param string $additional_params |
|
| 13 | - */ |
|
| 14 | - public function amOnCountrySettingsAdminPage($additional_params = '') |
|
| 15 | - { |
|
| 16 | - $this->actor()->amOnAdminPage(CountrySettings::url($additional_params)); |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * Instructs the actor to browse to the country settings page. |
|
| 11 | + * Assumes the actor is already logged in. |
|
| 12 | + * @param string $additional_params |
|
| 13 | + */ |
|
| 14 | + public function amOnCountrySettingsAdminPage($additional_params = '') |
|
| 15 | + { |
|
| 16 | + $this->actor()->amOnAdminPage(CountrySettings::url($additional_params)); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Instructs the actor to select the given decimal places radio option. |
|
| 22 | - * Assumes the actor is already on the country settings page. |
|
| 23 | - * @param string $decimal_places |
|
| 24 | - * @param string $country_code |
|
| 25 | - */ |
|
| 26 | - public function setCurrencyDecimalPlacesTo($decimal_places = '2', $country_code = 'US') |
|
| 27 | - { |
|
| 28 | - $this->actor()->click(CountrySettings::currencyDecimalPlacesRadioField($decimal_places, $country_code)); |
|
| 29 | - } |
|
| 20 | + /** |
|
| 21 | + * Instructs the actor to select the given decimal places radio option. |
|
| 22 | + * Assumes the actor is already on the country settings page. |
|
| 23 | + * @param string $decimal_places |
|
| 24 | + * @param string $country_code |
|
| 25 | + */ |
|
| 26 | + public function setCurrencyDecimalPlacesTo($decimal_places = '2', $country_code = 'US') |
|
| 27 | + { |
|
| 28 | + $this->actor()->click(CountrySettings::currencyDecimalPlacesRadioField($decimal_places, $country_code)); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Instructs the actor to select the given decimal mark radio option. |
|
| 34 | - * Assumes the actor is already on the country settings page. |
|
| 35 | - * @param string $decimal_mark |
|
| 36 | - */ |
|
| 37 | - public function setCurrencyDecimalMarkTo($decimal_mark = '.') |
|
| 38 | - { |
|
| 39 | - $this->actor()->click(CountrySettings::currencyDecimalMarkRadioField($decimal_mark)); |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * Instructs the actor to select the given decimal mark radio option. |
|
| 34 | + * Assumes the actor is already on the country settings page. |
|
| 35 | + * @param string $decimal_mark |
|
| 36 | + */ |
|
| 37 | + public function setCurrencyDecimalMarkTo($decimal_mark = '.') |
|
| 38 | + { |
|
| 39 | + $this->actor()->click(CountrySettings::currencyDecimalMarkRadioField($decimal_mark)); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Instructs the actor to select the given thousands separator radio option. |
|
| 45 | - * Assumes the actor is already on the country settings page. |
|
| 46 | - * @param string $thousands_seperator |
|
| 47 | - */ |
|
| 48 | - public function setCurrencyThousandsSeparatorTo($thousands_seperator = ',') |
|
| 49 | - { |
|
| 50 | - $this->actor()->click(CountrySettings::currencyThousandsSeparatorField($thousands_seperator)); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Instructs the actor to select the given thousands separator radio option. |
|
| 45 | + * Assumes the actor is already on the country settings page. |
|
| 46 | + * @param string $thousands_seperator |
|
| 47 | + */ |
|
| 48 | + public function setCurrencyThousandsSeparatorTo($thousands_seperator = ',') |
|
| 49 | + { |
|
| 50 | + $this->actor()->click(CountrySettings::currencyThousandsSeparatorField($thousands_seperator)); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Clicks the country settings submit button. |
|
| 56 | - * Assumes the actor is on the country settings admin page. |
|
| 57 | - */ |
|
| 58 | - public function saveCountrySettings() |
|
| 59 | - { |
|
| 60 | - $this->actor()->click(CountrySettings::COUNTRY_SETTINGS_SAVE_BUTTON); |
|
| 61 | - //no indicator on the page when stuff has been updated so just give a bit of time for it to finish. |
|
| 62 | - $this->actor()->wait(5); |
|
| 63 | - } |
|
| 54 | + /** |
|
| 55 | + * Clicks the country settings submit button. |
|
| 56 | + * Assumes the actor is on the country settings admin page. |
|
| 57 | + */ |
|
| 58 | + public function saveCountrySettings() |
|
| 59 | + { |
|
| 60 | + $this->actor()->click(CountrySettings::COUNTRY_SETTINGS_SAVE_BUTTON); |
|
| 61 | + //no indicator on the page when stuff has been updated so just give a bit of time for it to finish. |
|
| 62 | + $this->actor()->wait(5); |
|
| 63 | + } |
|
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |
@@ -14,118 +14,118 @@ |
||
| 14 | 14 | trait EventsAdmin |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $additional_params |
|
| 19 | - */ |
|
| 20 | - public function amOnDefaultEventsListTablePage($additional_params = '') |
|
| 21 | - { |
|
| 22 | - $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Triggers the publishing of the Event. |
|
| 28 | - */ |
|
| 29 | - public function publishEvent() |
|
| 30 | - { |
|
| 31 | - $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Triggers saving the Event. |
|
| 37 | - */ |
|
| 38 | - public function saveEvent() |
|
| 39 | - { |
|
| 40 | - $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
| 46 | - * First this will search using the given title and then attempt to edit from the results of the search. |
|
| 47 | - * |
|
| 48 | - * Assumes actor is already logged in. |
|
| 49 | - * @param $event_title |
|
| 50 | - */ |
|
| 51 | - public function amEditingTheEventWithTitle($event_title) |
|
| 52 | - { |
|
| 53 | - $this->amOnDefaultEventsListTablePage(); |
|
| 54 | - $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
| 55 | - $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
| 56 | - $this->actor()->waitForText('Displaying search results for'); |
|
| 57 | - $this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title)); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
| 63 | - * link for the event in the event list table. |
|
| 64 | - * Assumes the actor is already logged in and on the Event list table page. |
|
| 65 | - * |
|
| 66 | - * @param string $event_title |
|
| 67 | - */ |
|
| 68 | - public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
| 69 | - { |
|
| 70 | - $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 71 | - $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
| 77 | - * Assumes the actor is already logged in and editing an event. |
|
| 78 | - * |
|
| 79 | - * @param int $row_number What ticket row to toggle open/close. |
|
| 80 | - */ |
|
| 81 | - public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
| 82 | - { |
|
| 83 | - $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
| 89 | - * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
| 90 | - * ticket is "open". |
|
| 91 | - * |
|
| 92 | - * @param int $row_number What ticket row to toggle the checkbox for. |
|
| 93 | - */ |
|
| 94 | - public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
| 95 | - { |
|
| 96 | - $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Use to change the default registration status for the event. |
|
| 102 | - * Assumes the view is already on the event editor. |
|
| 103 | - * @param $registration_status |
|
| 104 | - */ |
|
| 105 | - public function changeDefaultRegistrationStatusTo($registration_status) |
|
| 106 | - { |
|
| 107 | - $this->actor()->selectOption( |
|
| 108 | - EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
| 109 | - $registration_status |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Use this from the context of the event editor to select the given custom template for a given message type and |
|
| 116 | - * messenger. |
|
| 117 | - * |
|
| 118 | - * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
| 119 | - * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
| 120 | - * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
| 121 | - * selected. |
|
| 122 | - */ |
|
| 123 | - public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
| 124 | - { |
|
| 125 | - $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
| 126 | - $this->actor()->selectOption( |
|
| 127 | - EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
| 128 | - $custom_template_label |
|
| 129 | - ); |
|
| 130 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $additional_params |
|
| 19 | + */ |
|
| 20 | + public function amOnDefaultEventsListTablePage($additional_params = '') |
|
| 21 | + { |
|
| 22 | + $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Triggers the publishing of the Event. |
|
| 28 | + */ |
|
| 29 | + public function publishEvent() |
|
| 30 | + { |
|
| 31 | + $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Triggers saving the Event. |
|
| 37 | + */ |
|
| 38 | + public function saveEvent() |
|
| 39 | + { |
|
| 40 | + $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
| 46 | + * First this will search using the given title and then attempt to edit from the results of the search. |
|
| 47 | + * |
|
| 48 | + * Assumes actor is already logged in. |
|
| 49 | + * @param $event_title |
|
| 50 | + */ |
|
| 51 | + public function amEditingTheEventWithTitle($event_title) |
|
| 52 | + { |
|
| 53 | + $this->amOnDefaultEventsListTablePage(); |
|
| 54 | + $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
| 55 | + $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
| 56 | + $this->actor()->waitForText('Displaying search results for'); |
|
| 57 | + $this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title)); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
| 63 | + * link for the event in the event list table. |
|
| 64 | + * Assumes the actor is already logged in and on the Event list table page. |
|
| 65 | + * |
|
| 66 | + * @param string $event_title |
|
| 67 | + */ |
|
| 68 | + public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
| 69 | + { |
|
| 70 | + $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 71 | + $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
| 77 | + * Assumes the actor is already logged in and editing an event. |
|
| 78 | + * |
|
| 79 | + * @param int $row_number What ticket row to toggle open/close. |
|
| 80 | + */ |
|
| 81 | + public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
| 82 | + { |
|
| 83 | + $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
| 89 | + * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
| 90 | + * ticket is "open". |
|
| 91 | + * |
|
| 92 | + * @param int $row_number What ticket row to toggle the checkbox for. |
|
| 93 | + */ |
|
| 94 | + public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
| 95 | + { |
|
| 96 | + $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Use to change the default registration status for the event. |
|
| 102 | + * Assumes the view is already on the event editor. |
|
| 103 | + * @param $registration_status |
|
| 104 | + */ |
|
| 105 | + public function changeDefaultRegistrationStatusTo($registration_status) |
|
| 106 | + { |
|
| 107 | + $this->actor()->selectOption( |
|
| 108 | + EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
| 109 | + $registration_status |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Use this from the context of the event editor to select the given custom template for a given message type and |
|
| 116 | + * messenger. |
|
| 117 | + * |
|
| 118 | + * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
| 119 | + * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
| 120 | + * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
| 121 | + * selected. |
|
| 122 | + */ |
|
| 123 | + public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
| 124 | + { |
|
| 125 | + $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
| 126 | + $this->actor()->selectOption( |
|
| 127 | + EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
| 128 | + $custom_template_label |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | 131 | } |
| 132 | 132 | \ No newline at end of file |
@@ -14,231 +14,231 @@ |
||
| 14 | 14 | class EventsAdmin extends CoreAdmin |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Selector for the Add new Event button in the admin. |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Selector for the Event Title field in the event editor |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Selector for the publish submit button in the event editor. |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Selector for the save button in the event editor |
|
| 39 | - */ |
|
| 40 | - const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = "#save-post"; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
| 17 | + /** |
|
| 18 | + * Selector for the Add new Event button in the admin. |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Selector for the Event Title field in the event editor |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Selector for the publish submit button in the event editor. |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Selector for the save button in the event editor |
|
| 39 | + */ |
|
| 40 | + const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = "#save-post"; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Selector for the view link after publishing an event. |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
| 48 | + /** |
|
| 49 | + * Selector for the view link after publishing an event. |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Selector for the ID of the event in the event editor |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
| 55 | + /** |
|
| 56 | + * Selector for the ID of the event in the event editor |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Selector for the search input on the event list table page. |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param string $additional_params |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public static function defaultEventsListTableUrl($additional_params = '') |
|
| 76 | - { |
|
| 77 | - return self::adminUrl('espresso_events', 'default', $additional_params); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * The selector for the DTTname field for the given row in the event editor. |
|
| 83 | - * @param int $row_number |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
| 87 | - { |
|
| 88 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
| 94 | - * @param int $row_number |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
| 98 | - { |
|
| 99 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
| 105 | - * |
|
| 106 | - * @param string $field_name |
|
| 107 | - * @param int $row_number |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
| 111 | - { |
|
| 112 | - return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * The selector for the TKT_name field for the given display row in the event editor. |
|
| 118 | - * @param int $row_number |
|
| 119 | - * @return string |
|
| 120 | - */ |
|
| 121 | - public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
| 122 | - { |
|
| 123 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
| 128 | - { |
|
| 129 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
| 134 | - { |
|
| 135 | - return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
| 140 | - { |
|
| 141 | - return "//span[@id='price-total-amount-$row_number']"; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
| 146 | - { |
|
| 147 | - return "//span[@id='price-total-amount-$row_number']"; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
| 152 | - { |
|
| 153 | - return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
| 159 | - * given ticket (row) and the given tax id (PRC_ID). |
|
| 160 | - * |
|
| 161 | - * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
| 162 | - * setup on a fresh install. |
|
| 163 | - * @param int $row_number What row representing the ticket you want the locator for. |
|
| 164 | - * @return string |
|
| 165 | - */ |
|
| 166 | - public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
| 167 | - { |
|
| 168 | - return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
| 174 | - * @param $field_name |
|
| 175 | - * @param int $row_number |
|
| 176 | - * @return string |
|
| 177 | - */ |
|
| 178 | - public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
| 179 | - { |
|
| 180 | - return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
| 186 | - * @param string $event_title |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
| 190 | - { |
|
| 191 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Locator for for the ID column in the event list table for a given event title. |
|
| 197 | - * @param string $event_title |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - public static function eventListTableEventIdSelectorForTitle($event_title) |
|
| 201 | - { |
|
| 202 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 203 | - . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Locator for the view link in the row of an event list table for the given event title. |
|
| 209 | - * @param string $event_title |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
| 213 | - { |
|
| 214 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 215 | - . "//ancestor::td//span[@class='view']/a"; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
| 221 | - * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
| 225 | - { |
|
| 226 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 227 | - . "//a[@rel='ee-tab-$messenger_slug']"; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Locator for the select input within the notifications metabox. |
|
| 233 | - * Note, this assumes the tab content for the related messenger is already visible. |
|
| 234 | - * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
| 235 | - * @return string |
|
| 236 | - */ |
|
| 237 | - public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
| 238 | - { |
|
| 239 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 240 | - . "//table[@class='messages-custom-template-switcher']" |
|
| 241 | - . "//tr/td[contains(.,'Registration Approved')]" |
|
| 242 | - . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
| 243 | - } |
|
| 62 | + /** |
|
| 63 | + * Selector for the search input on the event list table page. |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param string $additional_params |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public static function defaultEventsListTableUrl($additional_params = '') |
|
| 76 | + { |
|
| 77 | + return self::adminUrl('espresso_events', 'default', $additional_params); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * The selector for the DTTname field for the given row in the event editor. |
|
| 83 | + * @param int $row_number |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
| 87 | + { |
|
| 88 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
| 94 | + * @param int $row_number |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
| 98 | + { |
|
| 99 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
| 105 | + * |
|
| 106 | + * @param string $field_name |
|
| 107 | + * @param int $row_number |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
| 111 | + { |
|
| 112 | + return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * The selector for the TKT_name field for the given display row in the event editor. |
|
| 118 | + * @param int $row_number |
|
| 119 | + * @return string |
|
| 120 | + */ |
|
| 121 | + public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
| 122 | + { |
|
| 123 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
| 128 | + { |
|
| 129 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
| 134 | + { |
|
| 135 | + return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
| 140 | + { |
|
| 141 | + return "//span[@id='price-total-amount-$row_number']"; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
| 146 | + { |
|
| 147 | + return "//span[@id='price-total-amount-$row_number']"; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
| 152 | + { |
|
| 153 | + return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
| 159 | + * given ticket (row) and the given tax id (PRC_ID). |
|
| 160 | + * |
|
| 161 | + * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
| 162 | + * setup on a fresh install. |
|
| 163 | + * @param int $row_number What row representing the ticket you want the locator for. |
|
| 164 | + * @return string |
|
| 165 | + */ |
|
| 166 | + public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
| 167 | + { |
|
| 168 | + return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
| 174 | + * @param $field_name |
|
| 175 | + * @param int $row_number |
|
| 176 | + * @return string |
|
| 177 | + */ |
|
| 178 | + public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
| 179 | + { |
|
| 180 | + return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
| 186 | + * @param string $event_title |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
| 190 | + { |
|
| 191 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Locator for for the ID column in the event list table for a given event title. |
|
| 197 | + * @param string $event_title |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + public static function eventListTableEventIdSelectorForTitle($event_title) |
|
| 201 | + { |
|
| 202 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 203 | + . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Locator for the view link in the row of an event list table for the given event title. |
|
| 209 | + * @param string $event_title |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
| 213 | + { |
|
| 214 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 215 | + . "//ancestor::td//span[@class='view']/a"; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
| 221 | + * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
| 225 | + { |
|
| 226 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 227 | + . "//a[@rel='ee-tab-$messenger_slug']"; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Locator for the select input within the notifications metabox. |
|
| 233 | + * Note, this assumes the tab content for the related messenger is already visible. |
|
| 234 | + * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
| 235 | + * @return string |
|
| 236 | + */ |
|
| 237 | + public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
| 238 | + { |
|
| 239 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 240 | + . "//table[@class='messages-custom-template-switcher']" |
|
| 241 | + . "//tr/td[contains(.,'Registration Approved')]" |
|
| 242 | + . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
| 243 | + } |
|
| 244 | 244 | } |
@@ -14,51 +14,51 @@ |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - const COUNTRY_SETTINGS_SAVE_BUTTON = '#country_settings_save_2'; |
|
| 17 | + const COUNTRY_SETTINGS_SAVE_BUTTON = '#country_settings_save_2'; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Return the url for the country settings admin page. |
|
| 23 | - * @param string $additional_params |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public static function url($additional_params = '') |
|
| 27 | - { |
|
| 28 | - return self::adminUrl('espresso_general_settings', 'country_settings', $additional_params); |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * Return the url for the country settings admin page. |
|
| 23 | + * @param string $additional_params |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public static function url($additional_params = '') |
|
| 27 | + { |
|
| 28 | + return self::adminUrl('espresso_general_settings', 'country_settings', $additional_params); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Return the decimal places (precision) radio field locator for selection. |
|
| 34 | - * @param int $decimal_place_value |
|
| 35 | - * @param string $country_code |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public static function currencyDecimalPlacesRadioField($decimal_place_value = 2, $country_code = 'US') |
|
| 39 | - { |
|
| 40 | - return "//input[@id='CNT_cur_dec_plc-$country_code-$decimal_place_value']"; |
|
| 41 | - } |
|
| 32 | + /** |
|
| 33 | + * Return the decimal places (precision) radio field locator for selection. |
|
| 34 | + * @param int $decimal_place_value |
|
| 35 | + * @param string $country_code |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public static function currencyDecimalPlacesRadioField($decimal_place_value = 2, $country_code = 'US') |
|
| 39 | + { |
|
| 40 | + return "//input[@id='CNT_cur_dec_plc-$country_code-$decimal_place_value']"; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Return the currency decimal mark field locator for selection. |
|
| 46 | - * @param string $decimal_mark |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public static function currencyDecimalMarkRadioField($decimal_mark = '.') |
|
| 50 | - { |
|
| 51 | - return "//input[@class='CNT_cur_dec_mrk' and @value='$decimal_mark']"; |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * Return the currency decimal mark field locator for selection. |
|
| 46 | + * @param string $decimal_mark |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public static function currencyDecimalMarkRadioField($decimal_mark = '.') |
|
| 50 | + { |
|
| 51 | + return "//input[@class='CNT_cur_dec_mrk' and @value='$decimal_mark']"; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Return the currency thousands separator field locator for selection. |
|
| 57 | - * @param string $thousands_separator |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public static function currencyThousandsSeparatorField($thousands_separator = ',') |
|
| 61 | - { |
|
| 62 | - return "//input[@class='CNT_cur_thsnds' and @value='$thousands_separator']"; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Return the currency thousands separator field locator for selection. |
|
| 57 | + * @param string $thousands_separator |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public static function currencyThousandsSeparatorField($thousands_separator = ',') |
|
| 61 | + { |
|
| 62 | + return "//input[@class='CNT_cur_thsnds' and @value='$thousands_separator']"; |
|
| 63 | + } |
|
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.002'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.002'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - // for older WP versions |
|
| 197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * espresso_plugin_activation |
|
| 202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | - */ |
|
| 204 | - function espresso_plugin_activation() |
|
| 205 | - { |
|
| 206 | - update_option('ee_espresso_activation', true); |
|
| 207 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + // for older WP versions |
|
| 197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * espresso_plugin_activation |
|
| 202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | + */ |
|
| 204 | + function espresso_plugin_activation() |
|
| 205 | + { |
|
| 206 | + update_option('ee_espresso_activation', true); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | - /** |
|
| 211 | - * espresso_load_error_handling |
|
| 212 | - * this function loads EE's class for handling exceptions and errors |
|
| 213 | - */ |
|
| 214 | - function espresso_load_error_handling() |
|
| 215 | - { |
|
| 216 | - // load debugging tools |
|
| 217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | - EEH_Debug_Tools::instance(); |
|
| 220 | - } |
|
| 221 | - // load error handling |
|
| 222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | - } else { |
|
| 225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | - } |
|
| 227 | - } |
|
| 209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | + /** |
|
| 211 | + * espresso_load_error_handling |
|
| 212 | + * this function loads EE's class for handling exceptions and errors |
|
| 213 | + */ |
|
| 214 | + function espresso_load_error_handling() |
|
| 215 | + { |
|
| 216 | + // load debugging tools |
|
| 217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | + EEH_Debug_Tools::instance(); |
|
| 220 | + } |
|
| 221 | + // load error handling |
|
| 222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | + } else { |
|
| 225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * espresso_load_required |
|
| 231 | - * given a class name and path, this function will load that file or throw an exception |
|
| 232 | - * |
|
| 233 | - * @param string $classname |
|
| 234 | - * @param string $full_path_to_file |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | - { |
|
| 239 | - static $error_handling_loaded = false; |
|
| 240 | - if ( ! $error_handling_loaded) { |
|
| 241 | - espresso_load_error_handling(); |
|
| 242 | - $error_handling_loaded = true; |
|
| 243 | - } |
|
| 244 | - if (is_readable($full_path_to_file)) { |
|
| 245 | - require_once($full_path_to_file); |
|
| 246 | - } else { |
|
| 247 | - throw new EE_Error ( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $classname |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 229 | + /** |
|
| 230 | + * espresso_load_required |
|
| 231 | + * given a class name and path, this function will load that file or throw an exception |
|
| 232 | + * |
|
| 233 | + * @param string $classname |
|
| 234 | + * @param string $full_path_to_file |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | + { |
|
| 239 | + static $error_handling_loaded = false; |
|
| 240 | + if ( ! $error_handling_loaded) { |
|
| 241 | + espresso_load_error_handling(); |
|
| 242 | + $error_handling_loaded = true; |
|
| 243 | + } |
|
| 244 | + if (is_readable($full_path_to_file)) { |
|
| 245 | + require_once($full_path_to_file); |
|
| 246 | + } else { |
|
| 247 | + throw new EE_Error ( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $classname |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | - new EE_Bootstrap(); |
|
| 263 | - } |
|
| 259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | + new EE_Bootstrap(); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 266 | - /** |
|
| 267 | - * deactivate_plugin |
|
| 268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | - * |
|
| 270 | - * @access public |
|
| 271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | - { |
|
| 276 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | - } |
|
| 279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | - deactivate_plugins($plugin_basename); |
|
| 281 | - } |
|
| 266 | + /** |
|
| 267 | + * deactivate_plugin |
|
| 268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | + * |
|
| 270 | + * @access public |
|
| 271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | + { |
|
| 276 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | + } |
|
| 279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | + deactivate_plugins($plugin_basename); |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | \ No newline at end of file |