@@ -18,2023 +18,2023 @@ |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Used to reference when a registration has never been checked in. |
|
| 23 | - * |
|
| 24 | - * @deprecated use \EE_Checkin::status_checked_never instead |
|
| 25 | - * @type int |
|
| 26 | - */ |
|
| 27 | - const checkin_status_never = 2; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Used to reference when a registration has been checked in. |
|
| 31 | - * |
|
| 32 | - * @deprecated use \EE_Checkin::status_checked_in instead |
|
| 33 | - * @type int |
|
| 34 | - */ |
|
| 35 | - const checkin_status_in = 1; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Used to reference when a registration has been checked out. |
|
| 40 | - * |
|
| 41 | - * @deprecated use \EE_Checkin::status_checked_out instead |
|
| 42 | - * @type int |
|
| 43 | - */ |
|
| 44 | - const checkin_status_out = 0; |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * extra meta key for tracking reg status os trashed registrations |
|
| 49 | - * |
|
| 50 | - * @type string |
|
| 51 | - */ |
|
| 52 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * extra meta key for tracking if registration has reserved ticket |
|
| 57 | - * |
|
| 58 | - * @type string |
|
| 59 | - */ |
|
| 60 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param array $props_n_values incoming values |
|
| 65 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 66 | - * used.) |
|
| 67 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 68 | - * date_format and the second value is the time format |
|
| 69 | - * @return EE_Registration |
|
| 70 | - * @throws EE_Error |
|
| 71 | - */ |
|
| 72 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 73 | - { |
|
| 74 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 75 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param array $props_n_values incoming values from the database |
|
| 81 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 82 | - * the website will be used. |
|
| 83 | - * @return EE_Registration |
|
| 84 | - */ |
|
| 85 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 86 | - { |
|
| 87 | - return new self($props_n_values, true, $timezone); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set Event ID |
|
| 93 | - * |
|
| 94 | - * @param int $EVT_ID Event ID |
|
| 95 | - * @throws EE_Error |
|
| 96 | - * @throws RuntimeException |
|
| 97 | - */ |
|
| 98 | - public function set_event($EVT_ID = 0) |
|
| 99 | - { |
|
| 100 | - $this->set('EVT_ID', $EVT_ID); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
| 106 | - * be routed to internal methods |
|
| 107 | - * |
|
| 108 | - * @param string $field_name |
|
| 109 | - * @param mixed $field_value |
|
| 110 | - * @param bool $use_default |
|
| 111 | - * @throws EE_Error |
|
| 112 | - * @throws EntityNotFoundException |
|
| 113 | - * @throws InvalidArgumentException |
|
| 114 | - * @throws InvalidDataTypeException |
|
| 115 | - * @throws InvalidInterfaceException |
|
| 116 | - * @throws ReflectionException |
|
| 117 | - * @throws RuntimeException |
|
| 118 | - */ |
|
| 119 | - public function set($field_name, $field_value, $use_default = false) |
|
| 120 | - { |
|
| 121 | - switch ($field_name) { |
|
| 122 | - case 'REG_code': |
|
| 123 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
| 124 | - $this->set_reg_code($field_value, $use_default); |
|
| 125 | - } |
|
| 126 | - break; |
|
| 127 | - case 'STS_ID': |
|
| 128 | - $this->set_status($field_value, $use_default); |
|
| 129 | - break; |
|
| 130 | - default: |
|
| 131 | - parent::set($field_name, $field_value, $use_default); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Set Status ID |
|
| 138 | - * updates the registration status and ALSO... |
|
| 139 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
| 140 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
| 141 | - * |
|
| 142 | - * @param string $new_STS_ID |
|
| 143 | - * @param boolean $use_default |
|
| 144 | - * @param ContextInterface|null $context |
|
| 145 | - * @return bool |
|
| 146 | - * @throws EE_Error |
|
| 147 | - * @throws EntityNotFoundException |
|
| 148 | - * @throws InvalidArgumentException |
|
| 149 | - * @throws ReflectionException |
|
| 150 | - * @throws RuntimeException |
|
| 151 | - * @throws InvalidDataTypeException |
|
| 152 | - * @throws InvalidInterfaceException |
|
| 153 | - */ |
|
| 154 | - public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
| 155 | - { |
|
| 156 | - // get current REG_Status |
|
| 157 | - $old_STS_ID = $this->status_ID(); |
|
| 158 | - // if status has changed |
|
| 159 | - if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
| 160 | - && ! empty($old_STS_ID) // and that old status is actually set |
|
| 161 | - && ! empty($new_STS_ID) // as well as the new status |
|
| 162 | - && $this->ID() // ensure registration is in the db |
|
| 163 | - ) { |
|
| 164 | - // TO approved |
|
| 165 | - if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
| 166 | - // reserve a space by incrementing ticket and datetime sold values |
|
| 167 | - $this->_reserve_registration_space(); |
|
| 168 | - do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 169 | - // OR FROM approved |
|
| 170 | - } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
| 171 | - // release a space by decrementing ticket and datetime sold values |
|
| 172 | - $this->_release_registration_space(); |
|
| 173 | - do_action( |
|
| 174 | - 'AHEE__EE_Registration__set_status__from_approved', |
|
| 175 | - $this, |
|
| 176 | - $old_STS_ID, |
|
| 177 | - $new_STS_ID, |
|
| 178 | - $context |
|
| 179 | - ); |
|
| 180 | - } |
|
| 181 | - // update status |
|
| 182 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 183 | - $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
| 184 | - if($this->statusChangeUpdatesTransaction($context)) { |
|
| 185 | - $this->updateTransactionAfterStatusChange(); |
|
| 186 | - } |
|
| 187 | - do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 190 | - //even though the old value matches the new value, it's still good to |
|
| 191 | - //allow the parent set method to have a say |
|
| 192 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 199 | - * |
|
| 200 | - * @param string $new_STS_ID |
|
| 201 | - * @param string $old_STS_ID |
|
| 202 | - * @param ContextInterface|null $context |
|
| 203 | - * @throws EE_Error |
|
| 204 | - * @throws InvalidArgumentException |
|
| 205 | - * @throws InvalidDataTypeException |
|
| 206 | - * @throws InvalidInterfaceException |
|
| 207 | - * @throws ReflectionException |
|
| 208 | - */ |
|
| 209 | - private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 210 | - { |
|
| 211 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
| 212 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
| 213 | - // true if registration has been cancelled or declined |
|
| 214 | - $this->updateIfCanceled( |
|
| 215 | - $closed_reg_statuses, |
|
| 216 | - $new_STS_ID, |
|
| 217 | - $old_STS_ID, |
|
| 218 | - $context |
|
| 219 | - ); |
|
| 220 | - $this->updateIfDeclined( |
|
| 221 | - $closed_reg_statuses, |
|
| 222 | - $new_STS_ID, |
|
| 223 | - $old_STS_ID, |
|
| 224 | - $context |
|
| 225 | - ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 231 | - * |
|
| 232 | - * @param array $closed_reg_statuses |
|
| 233 | - * @param string $new_STS_ID |
|
| 234 | - * @param string $old_STS_ID |
|
| 235 | - * @param ContextInterface|null $context |
|
| 236 | - * @throws EE_Error |
|
| 237 | - * @throws InvalidArgumentException |
|
| 238 | - * @throws InvalidDataTypeException |
|
| 239 | - * @throws InvalidInterfaceException |
|
| 240 | - * @throws ReflectionException |
|
| 241 | - */ |
|
| 242 | - private function updateIfCanceled(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 243 | - { |
|
| 244 | - // true if registration has been cancelled or declined |
|
| 245 | - if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 246 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 247 | - ) { |
|
| 248 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 249 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 250 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 251 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 252 | - // cancelled or declined registration |
|
| 253 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
| 254 | - $this, |
|
| 255 | - $closed_reg_statuses |
|
| 256 | - ); |
|
| 257 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
| 258 | - $this, |
|
| 259 | - $closed_reg_statuses, |
|
| 260 | - false |
|
| 261 | - ); |
|
| 262 | - do_action( |
|
| 263 | - 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
| 264 | - $this, |
|
| 265 | - $old_STS_ID, |
|
| 266 | - $new_STS_ID, |
|
| 267 | - $context |
|
| 268 | - ); |
|
| 269 | - return; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 276 | - * |
|
| 277 | - * @param array $closed_reg_statuses |
|
| 278 | - * @param string $new_STS_ID |
|
| 279 | - * @param string $old_STS_ID |
|
| 280 | - * @param ContextInterface|null $context |
|
| 281 | - * @throws EE_Error |
|
| 282 | - * @throws InvalidArgumentException |
|
| 283 | - * @throws InvalidDataTypeException |
|
| 284 | - * @throws InvalidInterfaceException |
|
| 285 | - * @throws ReflectionException |
|
| 286 | - */ |
|
| 287 | - private function updateIfDeclined(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 288 | - { |
|
| 289 | - // true if reinstating cancelled or declined registration |
|
| 290 | - if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 291 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 292 | - ) { |
|
| 293 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 294 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 295 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 296 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 297 | - // reinstating cancelled or declined registration |
|
| 298 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
| 299 | - $this, |
|
| 300 | - $closed_reg_statuses |
|
| 301 | - ); |
|
| 302 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
| 303 | - $this, |
|
| 304 | - $closed_reg_statuses, |
|
| 305 | - false |
|
| 306 | - ); |
|
| 307 | - do_action( |
|
| 308 | - 'AHEE__EE_Registration__set_status__after_reinstated', |
|
| 309 | - $this, |
|
| 310 | - $old_STS_ID, |
|
| 311 | - $new_STS_ID, |
|
| 312 | - $context |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @param ContextInterface|null $context |
|
| 320 | - * @return bool |
|
| 321 | - */ |
|
| 322 | - private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
| 323 | - { |
|
| 324 | - $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
| 325 | - 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
| 326 | - array('spco_reg_step_attendee_information_process_registrations'), |
|
| 327 | - $context, |
|
| 328 | - $this |
|
| 329 | - ); |
|
| 330 | - return ! ( |
|
| 331 | - $context instanceof ContextInterface |
|
| 332 | - && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @throws EE_Error |
|
| 339 | - * @throws EntityNotFoundException |
|
| 340 | - * @throws InvalidArgumentException |
|
| 341 | - * @throws InvalidDataTypeException |
|
| 342 | - * @throws InvalidInterfaceException |
|
| 343 | - * @throws ReflectionException |
|
| 344 | - * @throws RuntimeException |
|
| 345 | - */ |
|
| 346 | - private function updateTransactionAfterStatusChange() |
|
| 347 | - { |
|
| 348 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 349 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 350 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
| 351 | - $this->transaction()->update_status_based_on_total_paid(true); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * get Status ID |
|
| 357 | - */ |
|
| 358 | - public function status_ID() |
|
| 359 | - { |
|
| 360 | - return $this->get('STS_ID'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
| 366 | - * |
|
| 367 | - * @return void |
|
| 368 | - * @throws EE_Error |
|
| 369 | - * @throws EntityNotFoundException |
|
| 370 | - */ |
|
| 371 | - private function _reserve_registration_space() |
|
| 372 | - { |
|
| 373 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
| 374 | - // so stop tracking that this reg has a ticket reserved |
|
| 375 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:". __LINE__ . ')'); |
|
| 376 | - $ticket = $this->ticket(); |
|
| 377 | - $ticket->increase_sold(); |
|
| 378 | - $ticket->save(); |
|
| 379 | - // possibly set event status to sold out |
|
| 380 | - $this->event()->perform_sold_out_status_check(); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Gets the ticket this registration is for |
|
| 386 | - * |
|
| 387 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
| 388 | - * |
|
| 389 | - * @return EE_Ticket|EE_Base_Class |
|
| 390 | - * @throws EE_Error |
|
| 391 | - */ |
|
| 392 | - public function ticket($include_archived = true) |
|
| 393 | - { |
|
| 394 | - $query_params = array(); |
|
| 395 | - if ($include_archived) { |
|
| 396 | - $query_params['default_where_conditions'] = 'none'; |
|
| 397 | - } |
|
| 398 | - return $this->get_first_related('Ticket', $query_params); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Gets the event this registration is for |
|
| 404 | - * |
|
| 405 | - * @return EE_Event |
|
| 406 | - * @throws EE_Error |
|
| 407 | - * @throws EntityNotFoundException |
|
| 408 | - */ |
|
| 409 | - public function event() |
|
| 410 | - { |
|
| 411 | - $event = $this->get_first_related('Event'); |
|
| 412 | - if (! $event instanceof \EE_Event) { |
|
| 413 | - throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
| 414 | - } |
|
| 415 | - return $event; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
| 421 | - * with the author of the event this registration is for. |
|
| 422 | - * |
|
| 423 | - * @since 4.5.0 |
|
| 424 | - * @return int |
|
| 425 | - * @throws EE_Error |
|
| 426 | - * @throws EntityNotFoundException |
|
| 427 | - */ |
|
| 428 | - public function wp_user() |
|
| 429 | - { |
|
| 430 | - $event = $this->event(); |
|
| 431 | - if ($event instanceof EE_Event) { |
|
| 432 | - return $event->wp_user(); |
|
| 433 | - } |
|
| 434 | - return 0; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
| 440 | - * |
|
| 441 | - * @return void |
|
| 442 | - * @throws EE_Error |
|
| 443 | - */ |
|
| 444 | - private function _release_registration_space() |
|
| 445 | - { |
|
| 446 | - $ticket = $this->ticket(); |
|
| 447 | - $ticket->decrease_sold(); |
|
| 448 | - $ticket->save(); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * tracks this registration's ticket reservation in extra meta |
|
| 454 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
| 455 | - * |
|
| 456 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
| 457 | - * @return void |
|
| 458 | - * @throws EE_Error |
|
| 459 | - * @throws InvalidArgumentException |
|
| 460 | - * @throws InvalidDataTypeException |
|
| 461 | - * @throws InvalidInterfaceException |
|
| 462 | - * @throws ReflectionException |
|
| 463 | - */ |
|
| 464 | - public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
| 465 | - { |
|
| 466 | - // only reserve ticket if space is not currently reserved |
|
| 467 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
| 468 | - $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 469 | - // IMPORTANT !!! |
|
| 470 | - // although checking $update_ticket first would be more efficient, |
|
| 471 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 472 | - if ( |
|
| 473 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
| 474 | - && $update_ticket |
|
| 475 | - ) { |
|
| 476 | - $ticket = $this->ticket(); |
|
| 477 | - $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 478 | - $ticket->save(); |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * stops tracking this registration's ticket reservation in extra meta |
|
| 486 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
| 487 | - * |
|
| 488 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
| 489 | - * @return void |
|
| 490 | - * @throws EE_Error |
|
| 491 | - * @throws InvalidArgumentException |
|
| 492 | - * @throws InvalidDataTypeException |
|
| 493 | - * @throws InvalidInterfaceException |
|
| 494 | - * @throws ReflectionException |
|
| 495 | - */ |
|
| 496 | - public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
| 497 | - { |
|
| 498 | - // only release ticket if space is currently reserved |
|
| 499 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
| 500 | - $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 501 | - // IMPORTANT !!! |
|
| 502 | - // although checking $update_ticket first would be more efficient, |
|
| 503 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 504 | - if ( |
|
| 505 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
| 506 | - && $update_ticket |
|
| 507 | - ) { |
|
| 508 | - $ticket = $this->ticket(); |
|
| 509 | - $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 510 | - $ticket->save(); |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Set Attendee ID |
|
| 518 | - * |
|
| 519 | - * @param int $ATT_ID Attendee ID |
|
| 520 | - * @throws EE_Error |
|
| 521 | - * @throws RuntimeException |
|
| 522 | - */ |
|
| 523 | - public function set_attendee_id($ATT_ID = 0) |
|
| 524 | - { |
|
| 525 | - $this->set('ATT_ID', $ATT_ID); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Set Transaction ID |
|
| 531 | - * |
|
| 532 | - * @param int $TXN_ID Transaction ID |
|
| 533 | - * @throws EE_Error |
|
| 534 | - * @throws RuntimeException |
|
| 535 | - */ |
|
| 536 | - public function set_transaction_id($TXN_ID = 0) |
|
| 537 | - { |
|
| 538 | - $this->set('TXN_ID', $TXN_ID); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Set Session |
|
| 544 | - * |
|
| 545 | - * @param string $REG_session PHP Session ID |
|
| 546 | - * @throws EE_Error |
|
| 547 | - * @throws RuntimeException |
|
| 548 | - */ |
|
| 549 | - public function set_session($REG_session = '') |
|
| 550 | - { |
|
| 551 | - $this->set('REG_session', $REG_session); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Set Registration URL Link |
|
| 557 | - * |
|
| 558 | - * @param string $REG_url_link Registration URL Link |
|
| 559 | - * @throws EE_Error |
|
| 560 | - * @throws RuntimeException |
|
| 561 | - */ |
|
| 562 | - public function set_reg_url_link($REG_url_link = '') |
|
| 563 | - { |
|
| 564 | - $this->set('REG_url_link', $REG_url_link); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Set Attendee Counter |
|
| 570 | - * |
|
| 571 | - * @param int $REG_count Primary Attendee |
|
| 572 | - * @throws EE_Error |
|
| 573 | - * @throws RuntimeException |
|
| 574 | - */ |
|
| 575 | - public function set_count($REG_count = 1) |
|
| 576 | - { |
|
| 577 | - $this->set('REG_count', $REG_count); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Set Group Size |
|
| 583 | - * |
|
| 584 | - * @param boolean $REG_group_size Group Registration |
|
| 585 | - * @throws EE_Error |
|
| 586 | - * @throws RuntimeException |
|
| 587 | - */ |
|
| 588 | - public function set_group_size($REG_group_size = false) |
|
| 589 | - { |
|
| 590 | - $this->set('REG_group_size', $REG_group_size); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
| 596 | - * EEM_Registration::status_id_not_approved |
|
| 597 | - * |
|
| 598 | - * @return boolean |
|
| 599 | - */ |
|
| 600 | - public function is_not_approved() |
|
| 601 | - { |
|
| 602 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
| 608 | - * EEM_Registration::status_id_pending_payment |
|
| 609 | - * |
|
| 610 | - * @return boolean |
|
| 611 | - */ |
|
| 612 | - public function is_pending_payment() |
|
| 613 | - { |
|
| 614 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
| 620 | - * |
|
| 621 | - * @return boolean |
|
| 622 | - */ |
|
| 623 | - public function is_approved() |
|
| 624 | - { |
|
| 625 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
| 631 | - * |
|
| 632 | - * @return boolean |
|
| 633 | - */ |
|
| 634 | - public function is_cancelled() |
|
| 635 | - { |
|
| 636 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
| 642 | - * |
|
| 643 | - * @return boolean |
|
| 644 | - */ |
|
| 645 | - public function is_declined() |
|
| 646 | - { |
|
| 647 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
| 653 | - * EEM_Registration::status_id_incomplete |
|
| 654 | - * |
|
| 655 | - * @return boolean |
|
| 656 | - */ |
|
| 657 | - public function is_incomplete() |
|
| 658 | - { |
|
| 659 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Set Registration Date |
|
| 665 | - * |
|
| 666 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
| 667 | - * Date |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws RuntimeException |
|
| 670 | - */ |
|
| 671 | - public function set_reg_date($REG_date = false) |
|
| 672 | - { |
|
| 673 | - $this->set('REG_date', $REG_date); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - /** |
|
| 678 | - * Set final price owing for this registration after all ticket/price modifications |
|
| 679 | - * |
|
| 680 | - * @access public |
|
| 681 | - * @param float $REG_final_price |
|
| 682 | - * @throws EE_Error |
|
| 683 | - * @throws RuntimeException |
|
| 684 | - */ |
|
| 685 | - public function set_final_price($REG_final_price = 0.00) |
|
| 686 | - { |
|
| 687 | - $this->set('REG_final_price', $REG_final_price); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Set amount paid towards this registration's final price |
|
| 693 | - * |
|
| 694 | - * @access public |
|
| 695 | - * @param float $REG_paid |
|
| 696 | - * @throws EE_Error |
|
| 697 | - * @throws RuntimeException |
|
| 698 | - */ |
|
| 699 | - public function set_paid($REG_paid = 0.00) |
|
| 700 | - { |
|
| 701 | - $this->set('REG_paid', $REG_paid); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * Attendee Is Going |
|
| 707 | - * |
|
| 708 | - * @param boolean $REG_att_is_going Attendee Is Going |
|
| 709 | - * @throws EE_Error |
|
| 710 | - * @throws RuntimeException |
|
| 711 | - */ |
|
| 712 | - public function set_att_is_going($REG_att_is_going = false) |
|
| 713 | - { |
|
| 714 | - $this->set('REG_att_is_going', $REG_att_is_going); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Gets the related attendee |
|
| 720 | - * |
|
| 721 | - * @return EE_Attendee |
|
| 722 | - * @throws EE_Error |
|
| 723 | - */ |
|
| 724 | - public function attendee() |
|
| 725 | - { |
|
| 726 | - return $this->get_first_related('Attendee'); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * get Event ID |
|
| 732 | - */ |
|
| 733 | - public function event_ID() |
|
| 734 | - { |
|
| 735 | - return $this->get('EVT_ID'); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * get Event ID |
|
| 741 | - */ |
|
| 742 | - public function event_name() |
|
| 743 | - { |
|
| 744 | - $event = $this->event_obj(); |
|
| 745 | - if ($event) { |
|
| 746 | - return $event->name(); |
|
| 747 | - } else { |
|
| 748 | - return null; |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * Fetches the event this registration is for |
|
| 755 | - * |
|
| 756 | - * @return EE_Event |
|
| 757 | - * @throws EE_Error |
|
| 758 | - */ |
|
| 759 | - public function event_obj() |
|
| 760 | - { |
|
| 761 | - return $this->get_first_related('Event'); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * get Attendee ID |
|
| 767 | - */ |
|
| 768 | - public function attendee_ID() |
|
| 769 | - { |
|
| 770 | - return $this->get('ATT_ID'); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * get PHP Session ID |
|
| 776 | - */ |
|
| 777 | - public function session_ID() |
|
| 778 | - { |
|
| 779 | - return $this->get('REG_session'); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
| 785 | - * |
|
| 786 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 787 | - * @return string |
|
| 788 | - */ |
|
| 789 | - public function receipt_url($messenger = 'html') |
|
| 790 | - { |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
| 794 | - * already in use on old system. If there is then we just return the standard url for it. |
|
| 795 | - * |
|
| 796 | - * @since 4.5.0 |
|
| 797 | - */ |
|
| 798 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
| 799 | - $has_custom = EEH_Template::locate_template( |
|
| 800 | - $template_relative_path, |
|
| 801 | - array(), |
|
| 802 | - true, |
|
| 803 | - true, |
|
| 804 | - true |
|
| 805 | - ); |
|
| 806 | - |
|
| 807 | - if ($has_custom) { |
|
| 808 | - return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
| 809 | - } |
|
| 810 | - return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
| 816 | - * |
|
| 817 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 818 | - * @return string |
|
| 819 | - * @throws EE_Error |
|
| 820 | - */ |
|
| 821 | - public function invoice_url($messenger = 'html') |
|
| 822 | - { |
|
| 823 | - /** |
|
| 824 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
| 825 | - * already in use on old system. If there is then we just return the standard url for it. |
|
| 826 | - * |
|
| 827 | - * @since 4.5.0 |
|
| 828 | - */ |
|
| 829 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
| 830 | - $has_custom = EEH_Template::locate_template( |
|
| 831 | - $template_relative_path, |
|
| 832 | - array(), |
|
| 833 | - true, |
|
| 834 | - true, |
|
| 835 | - true |
|
| 836 | - ); |
|
| 837 | - |
|
| 838 | - if ($has_custom) { |
|
| 839 | - if ($messenger == 'html') { |
|
| 840 | - return $this->invoice_url('launch'); |
|
| 841 | - } |
|
| 842 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
| 843 | - |
|
| 844 | - $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
| 845 | - if ($messenger == 'html') { |
|
| 846 | - $query_args['html'] = true; |
|
| 847 | - } |
|
| 848 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
| 849 | - } |
|
| 850 | - return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * get Registration URL Link |
|
| 856 | - * |
|
| 857 | - * @access public |
|
| 858 | - * @return string |
|
| 859 | - * @throws EE_Error |
|
| 860 | - */ |
|
| 861 | - public function reg_url_link() |
|
| 862 | - { |
|
| 863 | - return (string) $this->get('REG_url_link'); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * Echoes out invoice_url() |
|
| 869 | - * |
|
| 870 | - * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
| 871 | - * @return void |
|
| 872 | - * @throws EE_Error |
|
| 873 | - */ |
|
| 874 | - public function e_invoice_url($type = 'launch') |
|
| 875 | - { |
|
| 876 | - echo $this->invoice_url($type); |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Echoes out payment_overview_url |
|
| 882 | - */ |
|
| 883 | - public function e_payment_overview_url() |
|
| 884 | - { |
|
| 885 | - echo $this->payment_overview_url(); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * Gets the URL for the checkout payment options reg step |
|
| 891 | - * with this registration's REG_url_link added as a query parameter |
|
| 892 | - * |
|
| 893 | - * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
| 894 | - * payment overview url. |
|
| 895 | - * @return string |
|
| 896 | - * @throws InvalidInterfaceException |
|
| 897 | - * @throws InvalidDataTypeException |
|
| 898 | - * @throws EE_Error |
|
| 899 | - * @throws InvalidArgumentException |
|
| 900 | - */ |
|
| 901 | - public function payment_overview_url($clear_session = false) |
|
| 902 | - { |
|
| 903 | - return add_query_arg( |
|
| 904 | - (array) apply_filters( |
|
| 905 | - 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
| 906 | - array( |
|
| 907 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
| 908 | - 'step' => 'payment_options', |
|
| 909 | - 'revisit' => true, |
|
| 910 | - 'clear_session' => (bool) $clear_session, |
|
| 911 | - ), |
|
| 912 | - $this |
|
| 913 | - ), |
|
| 914 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 915 | - ); |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * Gets the URL for the checkout attendee information reg step |
|
| 921 | - * with this registration's REG_url_link added as a query parameter |
|
| 922 | - * |
|
| 923 | - * @return string |
|
| 924 | - * @throws InvalidInterfaceException |
|
| 925 | - * @throws InvalidDataTypeException |
|
| 926 | - * @throws EE_Error |
|
| 927 | - * @throws InvalidArgumentException |
|
| 928 | - */ |
|
| 929 | - public function edit_attendee_information_url() |
|
| 930 | - { |
|
| 931 | - return add_query_arg( |
|
| 932 | - (array) apply_filters( |
|
| 933 | - 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
| 934 | - array( |
|
| 935 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
| 936 | - 'step' => 'attendee_information', |
|
| 937 | - 'revisit' => true, |
|
| 938 | - ), |
|
| 939 | - $this |
|
| 940 | - ), |
|
| 941 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 942 | - ); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * Simply generates and returns the appropriate admin_url link to edit this registration |
|
| 948 | - * |
|
| 949 | - * @return string |
|
| 950 | - * @throws EE_Error |
|
| 951 | - */ |
|
| 952 | - public function get_admin_edit_url() |
|
| 953 | - { |
|
| 954 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 955 | - 'page' => 'espresso_registrations', |
|
| 956 | - 'action' => 'view_registration', |
|
| 957 | - '_REG_ID' => $this->ID(), |
|
| 958 | - ), admin_url('admin.php')); |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * is_primary_registrant? |
|
| 964 | - */ |
|
| 965 | - public function is_primary_registrant() |
|
| 966 | - { |
|
| 967 | - return $this->get('REG_count') == 1 ? true : false; |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * This returns the primary registration object for this registration group (which may be this object). |
|
| 973 | - * |
|
| 974 | - * @return EE_Registration |
|
| 975 | - * @throws EE_Error |
|
| 976 | - */ |
|
| 977 | - public function get_primary_registration() |
|
| 978 | - { |
|
| 979 | - if ($this->is_primary_registrant()) { |
|
| 980 | - return $this; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
| 984 | - /** @var EE_Registration $primary_registrant */ |
|
| 985 | - $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
| 986 | - array( |
|
| 987 | - 'TXN_ID' => $this->transaction_ID(), |
|
| 988 | - 'REG_count' => 1, |
|
| 989 | - ), |
|
| 990 | - )); |
|
| 991 | - return $primary_registrant; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * get Attendee Number |
|
| 997 | - * |
|
| 998 | - * @access public |
|
| 999 | - */ |
|
| 1000 | - public function count() |
|
| 1001 | - { |
|
| 1002 | - return $this->get('REG_count'); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * get Group Size |
|
| 1008 | - */ |
|
| 1009 | - public function group_size() |
|
| 1010 | - { |
|
| 1011 | - return $this->get('REG_group_size'); |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * get Registration Date |
|
| 1017 | - */ |
|
| 1018 | - public function date() |
|
| 1019 | - { |
|
| 1020 | - return $this->get('REG_date'); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - |
|
| 1024 | - /** |
|
| 1025 | - * gets a pretty date |
|
| 1026 | - * |
|
| 1027 | - * @param string $date_format |
|
| 1028 | - * @param string $time_format |
|
| 1029 | - * @return string |
|
| 1030 | - * @throws EE_Error |
|
| 1031 | - */ |
|
| 1032 | - public function pretty_date($date_format = null, $time_format = null) |
|
| 1033 | - { |
|
| 1034 | - return $this->get_datetime('REG_date', $date_format, $time_format); |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - |
|
| 1038 | - /** |
|
| 1039 | - * final_price |
|
| 1040 | - * the registration's share of the transaction total, so that the |
|
| 1041 | - * sum of all the transaction's REG_final_prices equal the transaction's total |
|
| 1042 | - * |
|
| 1043 | - * @return float |
|
| 1044 | - * @throws EE_Error |
|
| 1045 | - */ |
|
| 1046 | - public function final_price() |
|
| 1047 | - { |
|
| 1048 | - return $this->get('REG_final_price'); |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * pretty_final_price |
|
| 1054 | - * final price as formatted string, with correct decimal places and currency symbol |
|
| 1055 | - * |
|
| 1056 | - * @return string |
|
| 1057 | - * @throws EE_Error |
|
| 1058 | - */ |
|
| 1059 | - public function pretty_final_price() |
|
| 1060 | - { |
|
| 1061 | - return $this->get_pretty('REG_final_price'); |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * get paid (yeah) |
|
| 1067 | - * |
|
| 1068 | - * @return float |
|
| 1069 | - * @throws EE_Error |
|
| 1070 | - */ |
|
| 1071 | - public function paid() |
|
| 1072 | - { |
|
| 1073 | - return $this->get('REG_paid'); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * pretty_paid |
|
| 1079 | - * |
|
| 1080 | - * @return float |
|
| 1081 | - * @throws EE_Error |
|
| 1082 | - */ |
|
| 1083 | - public function pretty_paid() |
|
| 1084 | - { |
|
| 1085 | - return $this->get_pretty('REG_paid'); |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * owes_monies_and_can_pay |
|
| 1091 | - * whether or not this registration has monies owing and it's' status allows payment |
|
| 1092 | - * |
|
| 1093 | - * @param array $requires_payment |
|
| 1094 | - * @return bool |
|
| 1095 | - * @throws EE_Error |
|
| 1096 | - */ |
|
| 1097 | - public function owes_monies_and_can_pay($requires_payment = array()) |
|
| 1098 | - { |
|
| 1099 | - // these reg statuses require payment (if event is not free) |
|
| 1100 | - $requires_payment = ! empty($requires_payment) |
|
| 1101 | - ? $requires_payment |
|
| 1102 | - : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 1103 | - if (in_array($this->status_ID(), $requires_payment) && |
|
| 1104 | - $this->final_price() != 0 && |
|
| 1105 | - $this->final_price() != $this->paid() |
|
| 1106 | - ) { |
|
| 1107 | - return true; |
|
| 1108 | - } else { |
|
| 1109 | - return false; |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * Prints out the return value of $this->pretty_status() |
|
| 1116 | - * |
|
| 1117 | - * @param bool $show_icons |
|
| 1118 | - * @return void |
|
| 1119 | - * @throws EE_Error |
|
| 1120 | - */ |
|
| 1121 | - public function e_pretty_status($show_icons = false) |
|
| 1122 | - { |
|
| 1123 | - echo $this->pretty_status($show_icons); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * Returns a nice version of the status for displaying to customers |
|
| 1129 | - * |
|
| 1130 | - * @param bool $show_icons |
|
| 1131 | - * @return string |
|
| 1132 | - * @throws EE_Error |
|
| 1133 | - */ |
|
| 1134 | - public function pretty_status($show_icons = false) |
|
| 1135 | - { |
|
| 1136 | - $status = EEM_Status::instance()->localized_status( |
|
| 1137 | - array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 1138 | - false, |
|
| 1139 | - 'sentence' |
|
| 1140 | - ); |
|
| 1141 | - $icon = ''; |
|
| 1142 | - switch ($this->status_ID()) { |
|
| 1143 | - case EEM_Registration::status_id_approved: |
|
| 1144 | - $icon = $show_icons |
|
| 1145 | - ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
| 1146 | - : ''; |
|
| 1147 | - break; |
|
| 1148 | - case EEM_Registration::status_id_pending_payment: |
|
| 1149 | - $icon = $show_icons |
|
| 1150 | - ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
| 1151 | - : ''; |
|
| 1152 | - break; |
|
| 1153 | - case EEM_Registration::status_id_not_approved: |
|
| 1154 | - $icon = $show_icons |
|
| 1155 | - ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
| 1156 | - : ''; |
|
| 1157 | - break; |
|
| 1158 | - case EEM_Registration::status_id_cancelled: |
|
| 1159 | - $icon = $show_icons |
|
| 1160 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 1161 | - : ''; |
|
| 1162 | - break; |
|
| 1163 | - case EEM_Registration::status_id_incomplete: |
|
| 1164 | - $icon = $show_icons |
|
| 1165 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
| 1166 | - : ''; |
|
| 1167 | - break; |
|
| 1168 | - case EEM_Registration::status_id_declined: |
|
| 1169 | - $icon = $show_icons |
|
| 1170 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 1171 | - : ''; |
|
| 1172 | - break; |
|
| 1173 | - case EEM_Registration::status_id_wait_list: |
|
| 1174 | - $icon = $show_icons |
|
| 1175 | - ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
| 1176 | - : ''; |
|
| 1177 | - break; |
|
| 1178 | - } |
|
| 1179 | - return $icon . $status[$this->status_ID()]; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - |
|
| 1183 | - /** |
|
| 1184 | - * get Attendee Is Going |
|
| 1185 | - */ |
|
| 1186 | - public function att_is_going() |
|
| 1187 | - { |
|
| 1188 | - return $this->get('REG_att_is_going'); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * Gets related answers |
|
| 1194 | - * |
|
| 1195 | - * @param array $query_params like EEM_Base::get_all |
|
| 1196 | - * @return EE_Answer[] |
|
| 1197 | - * @throws EE_Error |
|
| 1198 | - */ |
|
| 1199 | - public function answers($query_params = null) |
|
| 1200 | - { |
|
| 1201 | - return $this->get_many_related('Answer', $query_params); |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - |
|
| 1205 | - /** |
|
| 1206 | - * Gets the registration's answer value to the specified question |
|
| 1207 | - * (either the question's ID or a question object) |
|
| 1208 | - * |
|
| 1209 | - * @param EE_Question|int $question |
|
| 1210 | - * @param bool $pretty_value |
|
| 1211 | - * @return array|string if pretty_value= true, the result will always be a string |
|
| 1212 | - * (because the answer might be an array of answer values, so passing pretty_value=true |
|
| 1213 | - * will convert it into some kind of string) |
|
| 1214 | - * @throws EE_Error |
|
| 1215 | - */ |
|
| 1216 | - public function answer_value_to_question($question, $pretty_value = true) |
|
| 1217 | - { |
|
| 1218 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
| 1219 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * question_groups |
|
| 1225 | - * returns an array of EE_Question_Group objects for this registration |
|
| 1226 | - * |
|
| 1227 | - * @return EE_Question_Group[] |
|
| 1228 | - * @throws EE_Error |
|
| 1229 | - * @throws EntityNotFoundException |
|
| 1230 | - */ |
|
| 1231 | - public function question_groups() |
|
| 1232 | - { |
|
| 1233 | - $question_groups = array(); |
|
| 1234 | - if ($this->event() instanceof EE_Event) { |
|
| 1235 | - $question_groups = $this->event()->question_groups( |
|
| 1236 | - array( |
|
| 1237 | - array( |
|
| 1238 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1239 | - ), |
|
| 1240 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 1241 | - ) |
|
| 1242 | - ); |
|
| 1243 | - } |
|
| 1244 | - return $question_groups; |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - |
|
| 1248 | - /** |
|
| 1249 | - * count_question_groups |
|
| 1250 | - * returns a count of the number of EE_Question_Group objects for this registration |
|
| 1251 | - * |
|
| 1252 | - * @return int |
|
| 1253 | - * @throws EE_Error |
|
| 1254 | - * @throws EntityNotFoundException |
|
| 1255 | - */ |
|
| 1256 | - public function count_question_groups() |
|
| 1257 | - { |
|
| 1258 | - $qg_count = 0; |
|
| 1259 | - if ($this->event() instanceof EE_Event) { |
|
| 1260 | - $qg_count = $this->event()->count_related( |
|
| 1261 | - 'Question_Group', |
|
| 1262 | - array( |
|
| 1263 | - array( |
|
| 1264 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1265 | - ), |
|
| 1266 | - ) |
|
| 1267 | - ); |
|
| 1268 | - } |
|
| 1269 | - return $qg_count; |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * Returns the registration date in the 'standard' string format |
|
| 1275 | - * (function may be improved in the future to allow for different formats and timezones) |
|
| 1276 | - * |
|
| 1277 | - * @return string |
|
| 1278 | - * @throws EE_Error |
|
| 1279 | - */ |
|
| 1280 | - public function reg_date() |
|
| 1281 | - { |
|
| 1282 | - return $this->get_datetime('REG_date'); |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - |
|
| 1286 | - /** |
|
| 1287 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
| 1288 | - * the ticket this registration purchased, or the datetime they have registered |
|
| 1289 | - * to attend) |
|
| 1290 | - * |
|
| 1291 | - * @return EE_Datetime_Ticket |
|
| 1292 | - * @throws EE_Error |
|
| 1293 | - */ |
|
| 1294 | - public function datetime_ticket() |
|
| 1295 | - { |
|
| 1296 | - return $this->get_first_related('Datetime_Ticket'); |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - |
|
| 1300 | - /** |
|
| 1301 | - * Sets the registration's datetime_ticket. |
|
| 1302 | - * |
|
| 1303 | - * @param EE_Datetime_Ticket $datetime_ticket |
|
| 1304 | - * @return EE_Datetime_Ticket |
|
| 1305 | - * @throws EE_Error |
|
| 1306 | - */ |
|
| 1307 | - public function set_datetime_ticket($datetime_ticket) |
|
| 1308 | - { |
|
| 1309 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * Gets deleted |
|
| 1314 | - * |
|
| 1315 | - * @return bool |
|
| 1316 | - * @throws EE_Error |
|
| 1317 | - */ |
|
| 1318 | - public function deleted() |
|
| 1319 | - { |
|
| 1320 | - return $this->get('REG_deleted'); |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - /** |
|
| 1324 | - * Sets deleted |
|
| 1325 | - * |
|
| 1326 | - * @param boolean $deleted |
|
| 1327 | - * @return bool |
|
| 1328 | - * @throws EE_Error |
|
| 1329 | - * @throws RuntimeException |
|
| 1330 | - */ |
|
| 1331 | - public function set_deleted($deleted) |
|
| 1332 | - { |
|
| 1333 | - if ($deleted) { |
|
| 1334 | - $this->delete(); |
|
| 1335 | - } else { |
|
| 1336 | - $this->restore(); |
|
| 1337 | - } |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * Get the status object of this object |
|
| 1343 | - * |
|
| 1344 | - * @return EE_Status |
|
| 1345 | - * @throws EE_Error |
|
| 1346 | - */ |
|
| 1347 | - public function status_obj() |
|
| 1348 | - { |
|
| 1349 | - return $this->get_first_related('Status'); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * Returns the number of times this registration has checked into any of the datetimes |
|
| 1355 | - * its available for |
|
| 1356 | - * |
|
| 1357 | - * @return int |
|
| 1358 | - * @throws EE_Error |
|
| 1359 | - */ |
|
| 1360 | - public function count_checkins() |
|
| 1361 | - { |
|
| 1362 | - return $this->get_model()->count_related($this, 'Checkin'); |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - |
|
| 1366 | - /** |
|
| 1367 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
| 1368 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
| 1369 | - * |
|
| 1370 | - * @return int |
|
| 1371 | - * @throws EE_Error |
|
| 1372 | - */ |
|
| 1373 | - public function count_checkins_not_checkedout() |
|
| 1374 | - { |
|
| 1375 | - return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - |
|
| 1379 | - /** |
|
| 1380 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
| 1381 | - * |
|
| 1382 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1383 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
| 1384 | - * consider registration status as well as datetime access. |
|
| 1385 | - * @return bool |
|
| 1386 | - * @throws EE_Error |
|
| 1387 | - */ |
|
| 1388 | - public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
| 1389 | - { |
|
| 1390 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1391 | - |
|
| 1392 | - //first check registration status |
|
| 1393 | - if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
| 1394 | - return false; |
|
| 1395 | - } |
|
| 1396 | - //is there a datetime ticket that matches this dtt_ID? |
|
| 1397 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1398 | - array( |
|
| 1399 | - 'TKT_ID' => $this->get('TKT_ID'), |
|
| 1400 | - 'DTT_ID' => $DTT_ID, |
|
| 1401 | - ), |
|
| 1402 | - ))) |
|
| 1403 | - ) { |
|
| 1404 | - return false; |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - //final check is against TKT_uses |
|
| 1408 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - |
|
| 1412 | - /** |
|
| 1413 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
| 1414 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
| 1415 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
| 1416 | - * then return false. Otherwise return true. |
|
| 1417 | - * |
|
| 1418 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1419 | - * @return bool true means can checkin. false means cannot checkin. |
|
| 1420 | - * @throws EE_Error |
|
| 1421 | - */ |
|
| 1422 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
| 1423 | - { |
|
| 1424 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1425 | - |
|
| 1426 | - if (! $DTT_ID) { |
|
| 1427 | - return false; |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
| 1431 | - |
|
| 1432 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
| 1433 | - // check-in or not. |
|
| 1434 | - if (! $max_uses || $max_uses === EE_INF) { |
|
| 1435 | - return true; |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
| 1439 | - //go ahead and toggle. |
|
| 1440 | - if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
| 1441 | - return true; |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
| 1445 | - //disallows further check-ins. |
|
| 1446 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
| 1447 | - array( |
|
| 1448 | - 'REG_ID' => $this->ID(), |
|
| 1449 | - 'CHK_in' => true, |
|
| 1450 | - ), |
|
| 1451 | - ), 'DTT_ID', true); |
|
| 1452 | - // checkins have already reached their max number of uses |
|
| 1453 | - // so registrant can NOT checkin |
|
| 1454 | - if ($count_unique_dtt_checkins >= $max_uses) { |
|
| 1455 | - EE_Error::add_error( |
|
| 1456 | - esc_html__( |
|
| 1457 | - 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
| 1458 | - 'event_espresso' |
|
| 1459 | - ), |
|
| 1460 | - __FILE__, |
|
| 1461 | - __FUNCTION__, |
|
| 1462 | - __LINE__ |
|
| 1463 | - ); |
|
| 1464 | - return false; |
|
| 1465 | - } |
|
| 1466 | - return true; |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * toggle Check-in status for this registration |
|
| 1472 | - * Check-ins are toggled in the following order: |
|
| 1473 | - * never checked in -> checked in |
|
| 1474 | - * checked in -> checked out |
|
| 1475 | - * checked out -> checked in |
|
| 1476 | - * |
|
| 1477 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
| 1478 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
| 1479 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
| 1480 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
| 1481 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
| 1482 | - * @throws EE_Error |
|
| 1483 | - */ |
|
| 1484 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
| 1485 | - { |
|
| 1486 | - if (empty($DTT_ID)) { |
|
| 1487 | - $datetime = $this->get_latest_related_datetime(); |
|
| 1488 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
| 1489 | - // verify the registration can checkin for the given DTT_ID |
|
| 1490 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1491 | - EE_Error::add_error( |
|
| 1492 | - sprintf( |
|
| 1493 | - esc_html__( |
|
| 1494 | - 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
| 1495 | - 'event_espresso' |
|
| 1496 | - ), |
|
| 1497 | - $this->ID(), |
|
| 1498 | - $DTT_ID |
|
| 1499 | - ), |
|
| 1500 | - __FILE__, |
|
| 1501 | - __FUNCTION__, |
|
| 1502 | - __LINE__ |
|
| 1503 | - ); |
|
| 1504 | - return false; |
|
| 1505 | - } |
|
| 1506 | - $status_paths = array( |
|
| 1507 | - EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
| 1508 | - EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
| 1509 | - EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
| 1510 | - ); |
|
| 1511 | - //start by getting the current status so we know what status we'll be changing to. |
|
| 1512 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
| 1513 | - $status_to = $status_paths[$cur_status]; |
|
| 1514 | - // database only records true for checked IN or false for checked OUT |
|
| 1515 | - // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
| 1516 | - $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
| 1517 | - // add relation - note Check-ins are always creating new rows |
|
| 1518 | - // because we are keeping track of Check-ins over time. |
|
| 1519 | - // Eventually we'll probably want to show a list table |
|
| 1520 | - // for the individual Check-ins so that they can be managed. |
|
| 1521 | - $checkin = EE_Checkin::new_instance(array( |
|
| 1522 | - 'REG_ID' => $this->ID(), |
|
| 1523 | - 'DTT_ID' => $DTT_ID, |
|
| 1524 | - 'CHK_in' => $new_status, |
|
| 1525 | - )); |
|
| 1526 | - // if the record could not be saved then return false |
|
| 1527 | - if ($checkin->save() === 0) { |
|
| 1528 | - if (WP_DEBUG) { |
|
| 1529 | - global $wpdb; |
|
| 1530 | - $error = sprintf( |
|
| 1531 | - esc_html__( |
|
| 1532 | - 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
| 1533 | - 'event_espresso' |
|
| 1534 | - ), |
|
| 1535 | - '<br />', |
|
| 1536 | - $wpdb->last_error |
|
| 1537 | - ); |
|
| 1538 | - } else { |
|
| 1539 | - $error = esc_html__( |
|
| 1540 | - 'Registration check in update failed because of an unknown database error', |
|
| 1541 | - 'event_espresso' |
|
| 1542 | - ); |
|
| 1543 | - } |
|
| 1544 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 1545 | - return false; |
|
| 1546 | - } |
|
| 1547 | - return $status_to; |
|
| 1548 | - } |
|
| 1549 | - |
|
| 1550 | - |
|
| 1551 | - /** |
|
| 1552 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
| 1553 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
| 1554 | - * |
|
| 1555 | - * @return EE_Datetime|null |
|
| 1556 | - * @throws EE_Error |
|
| 1557 | - */ |
|
| 1558 | - public function get_latest_related_datetime() |
|
| 1559 | - { |
|
| 1560 | - return EEM_Datetime::instance()->get_one( |
|
| 1561 | - array( |
|
| 1562 | - array( |
|
| 1563 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1564 | - ), |
|
| 1565 | - 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
| 1566 | - ) |
|
| 1567 | - ); |
|
| 1568 | - } |
|
| 1569 | - |
|
| 1570 | - |
|
| 1571 | - /** |
|
| 1572 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
| 1573 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
| 1574 | - * |
|
| 1575 | - * @throws EE_Error |
|
| 1576 | - */ |
|
| 1577 | - public function get_earliest_related_datetime() |
|
| 1578 | - { |
|
| 1579 | - return EEM_Datetime::instance()->get_one( |
|
| 1580 | - array( |
|
| 1581 | - array( |
|
| 1582 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1583 | - ), |
|
| 1584 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 1585 | - ) |
|
| 1586 | - ); |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - /** |
|
| 1591 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
| 1592 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
| 1593 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
| 1594 | - * |
|
| 1595 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
| 1596 | - * (if empty we'll get the primary datetime for |
|
| 1597 | - * this registration (via event) and use it's ID); |
|
| 1598 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
| 1599 | - * |
|
| 1600 | - * @return int Integer representing Check-in status. |
|
| 1601 | - * @throws EE_Error |
|
| 1602 | - */ |
|
| 1603 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
| 1604 | - { |
|
| 1605 | - $checkin_query_params = array( |
|
| 1606 | - 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
| 1607 | - ); |
|
| 1608 | - |
|
| 1609 | - if ($DTT_ID > 0) { |
|
| 1610 | - $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - //get checkin object (if exists) |
|
| 1614 | - $checkin = $checkin instanceof EE_Checkin |
|
| 1615 | - ? $checkin |
|
| 1616 | - : $this->get_first_related('Checkin', $checkin_query_params); |
|
| 1617 | - if ($checkin instanceof EE_Checkin) { |
|
| 1618 | - if ($checkin->get('CHK_in')) { |
|
| 1619 | - return EE_Checkin::status_checked_in; //checked in |
|
| 1620 | - } |
|
| 1621 | - return EE_Checkin::status_checked_out; //had checked in but is now checked out. |
|
| 1622 | - } |
|
| 1623 | - return EE_Checkin::status_checked_never; //never been checked in |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - |
|
| 1627 | - /** |
|
| 1628 | - * This method returns a localized message for the toggled Check-in message. |
|
| 1629 | - * |
|
| 1630 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
| 1631 | - * then it is assumed Check-in for primary datetime was toggled. |
|
| 1632 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
| 1633 | - * message can be customized with the attendee name. |
|
| 1634 | - * @return string internationalized message |
|
| 1635 | - * @throws EE_Error |
|
| 1636 | - */ |
|
| 1637 | - public function get_checkin_msg($DTT_ID, $error = false) |
|
| 1638 | - { |
|
| 1639 | - //let's get the attendee first so we can include the name of the attendee |
|
| 1640 | - $attendee = $this->get_first_related('Attendee'); |
|
| 1641 | - if ($attendee instanceof EE_Attendee) { |
|
| 1642 | - if ($error) { |
|
| 1643 | - return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
| 1644 | - } |
|
| 1645 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
| 1646 | - //what is the status message going to be? |
|
| 1647 | - switch ($cur_status) { |
|
| 1648 | - case EE_Checkin::status_checked_never: |
|
| 1649 | - return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
| 1650 | - $attendee->full_name()); |
|
| 1651 | - break; |
|
| 1652 | - case EE_Checkin::status_checked_in: |
|
| 1653 | - return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
| 1654 | - break; |
|
| 1655 | - case EE_Checkin::status_checked_out: |
|
| 1656 | - return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
| 1657 | - break; |
|
| 1658 | - } |
|
| 1659 | - } |
|
| 1660 | - return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - |
|
| 1664 | - /** |
|
| 1665 | - * Returns the related EE_Transaction to this registration |
|
| 1666 | - * |
|
| 1667 | - * @return EE_Transaction |
|
| 1668 | - * @throws EE_Error |
|
| 1669 | - * @throws EntityNotFoundException |
|
| 1670 | - */ |
|
| 1671 | - public function transaction() |
|
| 1672 | - { |
|
| 1673 | - $transaction = $this->get_first_related('Transaction'); |
|
| 1674 | - if (! $transaction instanceof \EE_Transaction) { |
|
| 1675 | - throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
| 1676 | - } |
|
| 1677 | - return $transaction; |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - |
|
| 1681 | - /** |
|
| 1682 | - * get Registration Code |
|
| 1683 | - */ |
|
| 1684 | - public function reg_code() |
|
| 1685 | - { |
|
| 1686 | - return $this->get('REG_code'); |
|
| 1687 | - } |
|
| 1688 | - |
|
| 1689 | - |
|
| 1690 | - /** |
|
| 1691 | - * get Transaction ID |
|
| 1692 | - */ |
|
| 1693 | - public function transaction_ID() |
|
| 1694 | - { |
|
| 1695 | - return $this->get('TXN_ID'); |
|
| 1696 | - } |
|
| 1697 | - |
|
| 1698 | - |
|
| 1699 | - /** |
|
| 1700 | - * @return int |
|
| 1701 | - * @throws EE_Error |
|
| 1702 | - */ |
|
| 1703 | - public function ticket_ID() |
|
| 1704 | - { |
|
| 1705 | - return $this->get('TKT_ID'); |
|
| 1706 | - } |
|
| 1707 | - |
|
| 1708 | - |
|
| 1709 | - /** |
|
| 1710 | - * Set Registration Code |
|
| 1711 | - * |
|
| 1712 | - * @access public |
|
| 1713 | - * @param string $REG_code Registration Code |
|
| 1714 | - * @param boolean $use_default |
|
| 1715 | - * @throws EE_Error |
|
| 1716 | - */ |
|
| 1717 | - public function set_reg_code($REG_code, $use_default = false) |
|
| 1718 | - { |
|
| 1719 | - if (empty($REG_code)) { |
|
| 1720 | - EE_Error::add_error( |
|
| 1721 | - esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
| 1722 | - __FILE__, |
|
| 1723 | - __FUNCTION__, |
|
| 1724 | - __LINE__ |
|
| 1725 | - ); |
|
| 1726 | - return; |
|
| 1727 | - } |
|
| 1728 | - if (! $this->reg_code()) { |
|
| 1729 | - parent::set('REG_code', $REG_code, $use_default); |
|
| 1730 | - } else { |
|
| 1731 | - EE_Error::doing_it_wrong( |
|
| 1732 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1733 | - esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
| 1734 | - '4.6.0' |
|
| 1735 | - ); |
|
| 1736 | - } |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
| 1742 | - * Note, if you want to just get all registrations in the same transaction (group), use: |
|
| 1743 | - * $registration->transaction()->registrations(); |
|
| 1744 | - * |
|
| 1745 | - * @since 4.5.0 |
|
| 1746 | - * @return EE_Registration[] or empty array if this isn't a group registration. |
|
| 1747 | - * @throws EE_Error |
|
| 1748 | - */ |
|
| 1749 | - public function get_all_other_registrations_in_group() |
|
| 1750 | - { |
|
| 1751 | - if ($this->group_size() < 2) { |
|
| 1752 | - return array(); |
|
| 1753 | - } |
|
| 1754 | - |
|
| 1755 | - $query[0] = array( |
|
| 1756 | - 'TXN_ID' => $this->transaction_ID(), |
|
| 1757 | - 'REG_ID' => array('!=', $this->ID()), |
|
| 1758 | - 'TKT_ID' => $this->ticket_ID(), |
|
| 1759 | - ); |
|
| 1760 | - /** @var EE_Registration[] $registrations */ |
|
| 1761 | - $registrations = $this->get_model()->get_all($query); |
|
| 1762 | - return $registrations; |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - /** |
|
| 1766 | - * Return the link to the admin details for the object. |
|
| 1767 | - * |
|
| 1768 | - * @return string |
|
| 1769 | - * @throws EE_Error |
|
| 1770 | - */ |
|
| 1771 | - public function get_admin_details_link() |
|
| 1772 | - { |
|
| 1773 | - EE_Registry::instance()->load_helper('URL'); |
|
| 1774 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1775 | - array( |
|
| 1776 | - 'page' => 'espresso_registrations', |
|
| 1777 | - 'action' => 'view_registration', |
|
| 1778 | - '_REG_ID' => $this->ID(), |
|
| 1779 | - ), |
|
| 1780 | - admin_url('admin.php') |
|
| 1781 | - ); |
|
| 1782 | - } |
|
| 1783 | - |
|
| 1784 | - /** |
|
| 1785 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 1786 | - * |
|
| 1787 | - * @return string |
|
| 1788 | - * @throws EE_Error |
|
| 1789 | - */ |
|
| 1790 | - public function get_admin_edit_link() |
|
| 1791 | - { |
|
| 1792 | - return $this->get_admin_details_link(); |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - /** |
|
| 1796 | - * Returns the link to a settings page for the object. |
|
| 1797 | - * |
|
| 1798 | - * @return string |
|
| 1799 | - * @throws EE_Error |
|
| 1800 | - */ |
|
| 1801 | - public function get_admin_settings_link() |
|
| 1802 | - { |
|
| 1803 | - return $this->get_admin_details_link(); |
|
| 1804 | - } |
|
| 1805 | - |
|
| 1806 | - /** |
|
| 1807 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 1808 | - * |
|
| 1809 | - * @return string |
|
| 1810 | - */ |
|
| 1811 | - public function get_admin_overview_link() |
|
| 1812 | - { |
|
| 1813 | - EE_Registry::instance()->load_helper('URL'); |
|
| 1814 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1815 | - array( |
|
| 1816 | - 'page' => 'espresso_registrations', |
|
| 1817 | - ), |
|
| 1818 | - admin_url('admin.php') |
|
| 1819 | - ); |
|
| 1820 | - } |
|
| 1821 | - |
|
| 1822 | - |
|
| 1823 | - /** |
|
| 1824 | - * @param array $query_params |
|
| 1825 | - * |
|
| 1826 | - * @return \EE_Registration[] |
|
| 1827 | - * @throws EE_Error |
|
| 1828 | - */ |
|
| 1829 | - public function payments($query_params = array()) |
|
| 1830 | - { |
|
| 1831 | - return $this->get_many_related('Payment', $query_params); |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - |
|
| 1835 | - /** |
|
| 1836 | - * @param array $query_params |
|
| 1837 | - * |
|
| 1838 | - * @return \EE_Registration_Payment[] |
|
| 1839 | - * @throws EE_Error |
|
| 1840 | - */ |
|
| 1841 | - public function registration_payments($query_params = array()) |
|
| 1842 | - { |
|
| 1843 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - |
|
| 1847 | - /** |
|
| 1848 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
| 1849 | - * Note: if there are no payments on the registration there will be no payment method returned. |
|
| 1850 | - * |
|
| 1851 | - * @return EE_Payment_Method|null |
|
| 1852 | - */ |
|
| 1853 | - public function payment_method() |
|
| 1854 | - { |
|
| 1855 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
| 1856 | - } |
|
| 1857 | - |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * @return \EE_Line_Item |
|
| 1861 | - * @throws EntityNotFoundException |
|
| 1862 | - * @throws EE_Error |
|
| 1863 | - */ |
|
| 1864 | - public function ticket_line_item() |
|
| 1865 | - { |
|
| 1866 | - $ticket = $this->ticket(); |
|
| 1867 | - $transaction = $this->transaction(); |
|
| 1868 | - $line_item = null; |
|
| 1869 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 1870 | - $transaction->total_line_item(), |
|
| 1871 | - 'Ticket', |
|
| 1872 | - array($ticket->ID()) |
|
| 1873 | - ); |
|
| 1874 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1875 | - if ( |
|
| 1876 | - $ticket_line_item instanceof \EE_Line_Item |
|
| 1877 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
| 1878 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
| 1879 | - ) { |
|
| 1880 | - $line_item = $ticket_line_item; |
|
| 1881 | - break; |
|
| 1882 | - } |
|
| 1883 | - } |
|
| 1884 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1885 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
| 1886 | - } |
|
| 1887 | - return $line_item; |
|
| 1888 | - } |
|
| 1889 | - |
|
| 1890 | - |
|
| 1891 | - /** |
|
| 1892 | - * Soft Deletes this model object. |
|
| 1893 | - * |
|
| 1894 | - * @return boolean | int |
|
| 1895 | - * @throws RuntimeException |
|
| 1896 | - * @throws EE_Error |
|
| 1897 | - */ |
|
| 1898 | - public function delete() |
|
| 1899 | - { |
|
| 1900 | - if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1901 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
| 1902 | - } |
|
| 1903 | - return parent::delete(); |
|
| 1904 | - } |
|
| 1905 | - |
|
| 1906 | - |
|
| 1907 | - /** |
|
| 1908 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
| 1909 | - * |
|
| 1910 | - * @throws EE_Error |
|
| 1911 | - * @throws RuntimeException |
|
| 1912 | - */ |
|
| 1913 | - public function restore() |
|
| 1914 | - { |
|
| 1915 | - $previous_status = $this->get_extra_meta( |
|
| 1916 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
| 1917 | - true, |
|
| 1918 | - EEM_Registration::status_id_cancelled |
|
| 1919 | - ); |
|
| 1920 | - if ($previous_status) { |
|
| 1921 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
| 1922 | - $this->set_status($previous_status); |
|
| 1923 | - } |
|
| 1924 | - return parent::restore(); |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - |
|
| 1928 | - /** |
|
| 1929 | - * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
| 1930 | - * |
|
| 1931 | - * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
| 1932 | - * depending on whether the reg status changes to or from "Approved" |
|
| 1933 | - * @return boolean whether the Registration status was updated |
|
| 1934 | - * @throws EE_Error |
|
| 1935 | - * @throws RuntimeException |
|
| 1936 | - */ |
|
| 1937 | - public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
| 1938 | - { |
|
| 1939 | - $paid = $this->paid(); |
|
| 1940 | - $price = $this->final_price(); |
|
| 1941 | - switch(true) { |
|
| 1942 | - // overpaid or paid |
|
| 1943 | - case EEH_Money::compare_floats($paid, $price, '>'): |
|
| 1944 | - case EEH_Money::compare_floats($paid, $price): |
|
| 1945 | - $new_status = EEM_Registration::status_id_approved; |
|
| 1946 | - break; |
|
| 1947 | - // underpaid |
|
| 1948 | - case EEH_Money::compare_floats($paid, $price, '<'): |
|
| 1949 | - $new_status = EEM_Registration::status_id_pending_payment; |
|
| 1950 | - break; |
|
| 1951 | - // uhhh Houston... |
|
| 1952 | - default: |
|
| 1953 | - throw new RuntimeException( |
|
| 1954 | - esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
| 1955 | - ); |
|
| 1956 | - } |
|
| 1957 | - if ($new_status !== $this->status_ID()) { |
|
| 1958 | - if ($trigger_set_status_logic) { |
|
| 1959 | - return $this->set_status($new_status); |
|
| 1960 | - } |
|
| 1961 | - parent::set('STS_ID', $new_status); |
|
| 1962 | - return true; |
|
| 1963 | - } |
|
| 1964 | - return false; |
|
| 1965 | - } |
|
| 1966 | - |
|
| 1967 | - |
|
| 1968 | - /*************************** DEPRECATED ***************************/ |
|
| 1969 | - |
|
| 1970 | - |
|
| 1971 | - /** |
|
| 1972 | - * @deprecated |
|
| 1973 | - * @since 4.7.0 |
|
| 1974 | - * @access public |
|
| 1975 | - */ |
|
| 1976 | - public function price_paid() |
|
| 1977 | - { |
|
| 1978 | - EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
| 1979 | - esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
| 1980 | - '4.7.0'); |
|
| 1981 | - return $this->final_price(); |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - |
|
| 1985 | - /** |
|
| 1986 | - * @deprecated |
|
| 1987 | - * @since 4.7.0 |
|
| 1988 | - * @access public |
|
| 1989 | - * @param float $REG_final_price |
|
| 1990 | - * @throws EE_Error |
|
| 1991 | - * @throws RuntimeException |
|
| 1992 | - */ |
|
| 1993 | - public function set_price_paid($REG_final_price = 0.00) |
|
| 1994 | - { |
|
| 1995 | - EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
| 1996 | - esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
| 1997 | - '4.7.0'); |
|
| 1998 | - $this->set_final_price($REG_final_price); |
|
| 1999 | - } |
|
| 2000 | - |
|
| 2001 | - |
|
| 2002 | - /** |
|
| 2003 | - * @deprecated |
|
| 2004 | - * @since 4.7.0 |
|
| 2005 | - * @return string |
|
| 2006 | - * @throws EE_Error |
|
| 2007 | - */ |
|
| 2008 | - public function pretty_price_paid() |
|
| 2009 | - { |
|
| 2010 | - EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
| 2011 | - esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
| 2012 | - 'event_espresso'), '4.7.0'); |
|
| 2013 | - return $this->pretty_final_price(); |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - |
|
| 2017 | - /** |
|
| 2018 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
| 2019 | - * |
|
| 2020 | - * @deprecated 4.9.17 |
|
| 2021 | - * @return EE_Datetime |
|
| 2022 | - * @throws EE_Error |
|
| 2023 | - * @throws EntityNotFoundException |
|
| 2024 | - */ |
|
| 2025 | - public function get_related_primary_datetime() |
|
| 2026 | - { |
|
| 2027 | - EE_Error::doing_it_wrong( |
|
| 2028 | - __METHOD__, |
|
| 2029 | - esc_html__( |
|
| 2030 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
| 2031 | - 'event_espresso' |
|
| 2032 | - ), |
|
| 2033 | - '4.9.17', |
|
| 2034 | - '5.0.0' |
|
| 2035 | - ); |
|
| 2036 | - return $this->event()->primary_datetime(); |
|
| 2037 | - } |
|
| 21 | + /** |
|
| 22 | + * Used to reference when a registration has never been checked in. |
|
| 23 | + * |
|
| 24 | + * @deprecated use \EE_Checkin::status_checked_never instead |
|
| 25 | + * @type int |
|
| 26 | + */ |
|
| 27 | + const checkin_status_never = 2; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Used to reference when a registration has been checked in. |
|
| 31 | + * |
|
| 32 | + * @deprecated use \EE_Checkin::status_checked_in instead |
|
| 33 | + * @type int |
|
| 34 | + */ |
|
| 35 | + const checkin_status_in = 1; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Used to reference when a registration has been checked out. |
|
| 40 | + * |
|
| 41 | + * @deprecated use \EE_Checkin::status_checked_out instead |
|
| 42 | + * @type int |
|
| 43 | + */ |
|
| 44 | + const checkin_status_out = 0; |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * extra meta key for tracking reg status os trashed registrations |
|
| 49 | + * |
|
| 50 | + * @type string |
|
| 51 | + */ |
|
| 52 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * extra meta key for tracking if registration has reserved ticket |
|
| 57 | + * |
|
| 58 | + * @type string |
|
| 59 | + */ |
|
| 60 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param array $props_n_values incoming values |
|
| 65 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 66 | + * used.) |
|
| 67 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 68 | + * date_format and the second value is the time format |
|
| 69 | + * @return EE_Registration |
|
| 70 | + * @throws EE_Error |
|
| 71 | + */ |
|
| 72 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 73 | + { |
|
| 74 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 75 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param array $props_n_values incoming values from the database |
|
| 81 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 82 | + * the website will be used. |
|
| 83 | + * @return EE_Registration |
|
| 84 | + */ |
|
| 85 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 86 | + { |
|
| 87 | + return new self($props_n_values, true, $timezone); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set Event ID |
|
| 93 | + * |
|
| 94 | + * @param int $EVT_ID Event ID |
|
| 95 | + * @throws EE_Error |
|
| 96 | + * @throws RuntimeException |
|
| 97 | + */ |
|
| 98 | + public function set_event($EVT_ID = 0) |
|
| 99 | + { |
|
| 100 | + $this->set('EVT_ID', $EVT_ID); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
| 106 | + * be routed to internal methods |
|
| 107 | + * |
|
| 108 | + * @param string $field_name |
|
| 109 | + * @param mixed $field_value |
|
| 110 | + * @param bool $use_default |
|
| 111 | + * @throws EE_Error |
|
| 112 | + * @throws EntityNotFoundException |
|
| 113 | + * @throws InvalidArgumentException |
|
| 114 | + * @throws InvalidDataTypeException |
|
| 115 | + * @throws InvalidInterfaceException |
|
| 116 | + * @throws ReflectionException |
|
| 117 | + * @throws RuntimeException |
|
| 118 | + */ |
|
| 119 | + public function set($field_name, $field_value, $use_default = false) |
|
| 120 | + { |
|
| 121 | + switch ($field_name) { |
|
| 122 | + case 'REG_code': |
|
| 123 | + if (! empty($field_value) && $this->reg_code() === null) { |
|
| 124 | + $this->set_reg_code($field_value, $use_default); |
|
| 125 | + } |
|
| 126 | + break; |
|
| 127 | + case 'STS_ID': |
|
| 128 | + $this->set_status($field_value, $use_default); |
|
| 129 | + break; |
|
| 130 | + default: |
|
| 131 | + parent::set($field_name, $field_value, $use_default); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Set Status ID |
|
| 138 | + * updates the registration status and ALSO... |
|
| 139 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
| 140 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
| 141 | + * |
|
| 142 | + * @param string $new_STS_ID |
|
| 143 | + * @param boolean $use_default |
|
| 144 | + * @param ContextInterface|null $context |
|
| 145 | + * @return bool |
|
| 146 | + * @throws EE_Error |
|
| 147 | + * @throws EntityNotFoundException |
|
| 148 | + * @throws InvalidArgumentException |
|
| 149 | + * @throws ReflectionException |
|
| 150 | + * @throws RuntimeException |
|
| 151 | + * @throws InvalidDataTypeException |
|
| 152 | + * @throws InvalidInterfaceException |
|
| 153 | + */ |
|
| 154 | + public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
| 155 | + { |
|
| 156 | + // get current REG_Status |
|
| 157 | + $old_STS_ID = $this->status_ID(); |
|
| 158 | + // if status has changed |
|
| 159 | + if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
| 160 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
| 161 | + && ! empty($new_STS_ID) // as well as the new status |
|
| 162 | + && $this->ID() // ensure registration is in the db |
|
| 163 | + ) { |
|
| 164 | + // TO approved |
|
| 165 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
| 166 | + // reserve a space by incrementing ticket and datetime sold values |
|
| 167 | + $this->_reserve_registration_space(); |
|
| 168 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 169 | + // OR FROM approved |
|
| 170 | + } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
| 171 | + // release a space by decrementing ticket and datetime sold values |
|
| 172 | + $this->_release_registration_space(); |
|
| 173 | + do_action( |
|
| 174 | + 'AHEE__EE_Registration__set_status__from_approved', |
|
| 175 | + $this, |
|
| 176 | + $old_STS_ID, |
|
| 177 | + $new_STS_ID, |
|
| 178 | + $context |
|
| 179 | + ); |
|
| 180 | + } |
|
| 181 | + // update status |
|
| 182 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 183 | + $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
| 184 | + if($this->statusChangeUpdatesTransaction($context)) { |
|
| 185 | + $this->updateTransactionAfterStatusChange(); |
|
| 186 | + } |
|
| 187 | + do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | + //even though the old value matches the new value, it's still good to |
|
| 191 | + //allow the parent set method to have a say |
|
| 192 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 199 | + * |
|
| 200 | + * @param string $new_STS_ID |
|
| 201 | + * @param string $old_STS_ID |
|
| 202 | + * @param ContextInterface|null $context |
|
| 203 | + * @throws EE_Error |
|
| 204 | + * @throws InvalidArgumentException |
|
| 205 | + * @throws InvalidDataTypeException |
|
| 206 | + * @throws InvalidInterfaceException |
|
| 207 | + * @throws ReflectionException |
|
| 208 | + */ |
|
| 209 | + private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 210 | + { |
|
| 211 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
| 212 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
| 213 | + // true if registration has been cancelled or declined |
|
| 214 | + $this->updateIfCanceled( |
|
| 215 | + $closed_reg_statuses, |
|
| 216 | + $new_STS_ID, |
|
| 217 | + $old_STS_ID, |
|
| 218 | + $context |
|
| 219 | + ); |
|
| 220 | + $this->updateIfDeclined( |
|
| 221 | + $closed_reg_statuses, |
|
| 222 | + $new_STS_ID, |
|
| 223 | + $old_STS_ID, |
|
| 224 | + $context |
|
| 225 | + ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 231 | + * |
|
| 232 | + * @param array $closed_reg_statuses |
|
| 233 | + * @param string $new_STS_ID |
|
| 234 | + * @param string $old_STS_ID |
|
| 235 | + * @param ContextInterface|null $context |
|
| 236 | + * @throws EE_Error |
|
| 237 | + * @throws InvalidArgumentException |
|
| 238 | + * @throws InvalidDataTypeException |
|
| 239 | + * @throws InvalidInterfaceException |
|
| 240 | + * @throws ReflectionException |
|
| 241 | + */ |
|
| 242 | + private function updateIfCanceled(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 243 | + { |
|
| 244 | + // true if registration has been cancelled or declined |
|
| 245 | + if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 246 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 247 | + ) { |
|
| 248 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 249 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 250 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 251 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 252 | + // cancelled or declined registration |
|
| 253 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
| 254 | + $this, |
|
| 255 | + $closed_reg_statuses |
|
| 256 | + ); |
|
| 257 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
| 258 | + $this, |
|
| 259 | + $closed_reg_statuses, |
|
| 260 | + false |
|
| 261 | + ); |
|
| 262 | + do_action( |
|
| 263 | + 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
| 264 | + $this, |
|
| 265 | + $old_STS_ID, |
|
| 266 | + $new_STS_ID, |
|
| 267 | + $context |
|
| 268 | + ); |
|
| 269 | + return; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 276 | + * |
|
| 277 | + * @param array $closed_reg_statuses |
|
| 278 | + * @param string $new_STS_ID |
|
| 279 | + * @param string $old_STS_ID |
|
| 280 | + * @param ContextInterface|null $context |
|
| 281 | + * @throws EE_Error |
|
| 282 | + * @throws InvalidArgumentException |
|
| 283 | + * @throws InvalidDataTypeException |
|
| 284 | + * @throws InvalidInterfaceException |
|
| 285 | + * @throws ReflectionException |
|
| 286 | + */ |
|
| 287 | + private function updateIfDeclined(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 288 | + { |
|
| 289 | + // true if reinstating cancelled or declined registration |
|
| 290 | + if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 291 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 292 | + ) { |
|
| 293 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 294 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 295 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 296 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 297 | + // reinstating cancelled or declined registration |
|
| 298 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
| 299 | + $this, |
|
| 300 | + $closed_reg_statuses |
|
| 301 | + ); |
|
| 302 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
| 303 | + $this, |
|
| 304 | + $closed_reg_statuses, |
|
| 305 | + false |
|
| 306 | + ); |
|
| 307 | + do_action( |
|
| 308 | + 'AHEE__EE_Registration__set_status__after_reinstated', |
|
| 309 | + $this, |
|
| 310 | + $old_STS_ID, |
|
| 311 | + $new_STS_ID, |
|
| 312 | + $context |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @param ContextInterface|null $context |
|
| 320 | + * @return bool |
|
| 321 | + */ |
|
| 322 | + private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
| 323 | + { |
|
| 324 | + $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
| 325 | + 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
| 326 | + array('spco_reg_step_attendee_information_process_registrations'), |
|
| 327 | + $context, |
|
| 328 | + $this |
|
| 329 | + ); |
|
| 330 | + return ! ( |
|
| 331 | + $context instanceof ContextInterface |
|
| 332 | + && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @throws EE_Error |
|
| 339 | + * @throws EntityNotFoundException |
|
| 340 | + * @throws InvalidArgumentException |
|
| 341 | + * @throws InvalidDataTypeException |
|
| 342 | + * @throws InvalidInterfaceException |
|
| 343 | + * @throws ReflectionException |
|
| 344 | + * @throws RuntimeException |
|
| 345 | + */ |
|
| 346 | + private function updateTransactionAfterStatusChange() |
|
| 347 | + { |
|
| 348 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 349 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 350 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
| 351 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * get Status ID |
|
| 357 | + */ |
|
| 358 | + public function status_ID() |
|
| 359 | + { |
|
| 360 | + return $this->get('STS_ID'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
| 366 | + * |
|
| 367 | + * @return void |
|
| 368 | + * @throws EE_Error |
|
| 369 | + * @throws EntityNotFoundException |
|
| 370 | + */ |
|
| 371 | + private function _reserve_registration_space() |
|
| 372 | + { |
|
| 373 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
| 374 | + // so stop tracking that this reg has a ticket reserved |
|
| 375 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:". __LINE__ . ')'); |
|
| 376 | + $ticket = $this->ticket(); |
|
| 377 | + $ticket->increase_sold(); |
|
| 378 | + $ticket->save(); |
|
| 379 | + // possibly set event status to sold out |
|
| 380 | + $this->event()->perform_sold_out_status_check(); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Gets the ticket this registration is for |
|
| 386 | + * |
|
| 387 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
| 388 | + * |
|
| 389 | + * @return EE_Ticket|EE_Base_Class |
|
| 390 | + * @throws EE_Error |
|
| 391 | + */ |
|
| 392 | + public function ticket($include_archived = true) |
|
| 393 | + { |
|
| 394 | + $query_params = array(); |
|
| 395 | + if ($include_archived) { |
|
| 396 | + $query_params['default_where_conditions'] = 'none'; |
|
| 397 | + } |
|
| 398 | + return $this->get_first_related('Ticket', $query_params); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Gets the event this registration is for |
|
| 404 | + * |
|
| 405 | + * @return EE_Event |
|
| 406 | + * @throws EE_Error |
|
| 407 | + * @throws EntityNotFoundException |
|
| 408 | + */ |
|
| 409 | + public function event() |
|
| 410 | + { |
|
| 411 | + $event = $this->get_first_related('Event'); |
|
| 412 | + if (! $event instanceof \EE_Event) { |
|
| 413 | + throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
| 414 | + } |
|
| 415 | + return $event; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
| 421 | + * with the author of the event this registration is for. |
|
| 422 | + * |
|
| 423 | + * @since 4.5.0 |
|
| 424 | + * @return int |
|
| 425 | + * @throws EE_Error |
|
| 426 | + * @throws EntityNotFoundException |
|
| 427 | + */ |
|
| 428 | + public function wp_user() |
|
| 429 | + { |
|
| 430 | + $event = $this->event(); |
|
| 431 | + if ($event instanceof EE_Event) { |
|
| 432 | + return $event->wp_user(); |
|
| 433 | + } |
|
| 434 | + return 0; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
| 440 | + * |
|
| 441 | + * @return void |
|
| 442 | + * @throws EE_Error |
|
| 443 | + */ |
|
| 444 | + private function _release_registration_space() |
|
| 445 | + { |
|
| 446 | + $ticket = $this->ticket(); |
|
| 447 | + $ticket->decrease_sold(); |
|
| 448 | + $ticket->save(); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * tracks this registration's ticket reservation in extra meta |
|
| 454 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
| 455 | + * |
|
| 456 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
| 457 | + * @return void |
|
| 458 | + * @throws EE_Error |
|
| 459 | + * @throws InvalidArgumentException |
|
| 460 | + * @throws InvalidDataTypeException |
|
| 461 | + * @throws InvalidInterfaceException |
|
| 462 | + * @throws ReflectionException |
|
| 463 | + */ |
|
| 464 | + public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
| 465 | + { |
|
| 466 | + // only reserve ticket if space is not currently reserved |
|
| 467 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
| 468 | + $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 469 | + // IMPORTANT !!! |
|
| 470 | + // although checking $update_ticket first would be more efficient, |
|
| 471 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 472 | + if ( |
|
| 473 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
| 474 | + && $update_ticket |
|
| 475 | + ) { |
|
| 476 | + $ticket = $this->ticket(); |
|
| 477 | + $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 478 | + $ticket->save(); |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * stops tracking this registration's ticket reservation in extra meta |
|
| 486 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
| 487 | + * |
|
| 488 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
| 489 | + * @return void |
|
| 490 | + * @throws EE_Error |
|
| 491 | + * @throws InvalidArgumentException |
|
| 492 | + * @throws InvalidDataTypeException |
|
| 493 | + * @throws InvalidInterfaceException |
|
| 494 | + * @throws ReflectionException |
|
| 495 | + */ |
|
| 496 | + public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
| 497 | + { |
|
| 498 | + // only release ticket if space is currently reserved |
|
| 499 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
| 500 | + $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 501 | + // IMPORTANT !!! |
|
| 502 | + // although checking $update_ticket first would be more efficient, |
|
| 503 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 504 | + if ( |
|
| 505 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
| 506 | + && $update_ticket |
|
| 507 | + ) { |
|
| 508 | + $ticket = $this->ticket(); |
|
| 509 | + $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 510 | + $ticket->save(); |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Set Attendee ID |
|
| 518 | + * |
|
| 519 | + * @param int $ATT_ID Attendee ID |
|
| 520 | + * @throws EE_Error |
|
| 521 | + * @throws RuntimeException |
|
| 522 | + */ |
|
| 523 | + public function set_attendee_id($ATT_ID = 0) |
|
| 524 | + { |
|
| 525 | + $this->set('ATT_ID', $ATT_ID); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Set Transaction ID |
|
| 531 | + * |
|
| 532 | + * @param int $TXN_ID Transaction ID |
|
| 533 | + * @throws EE_Error |
|
| 534 | + * @throws RuntimeException |
|
| 535 | + */ |
|
| 536 | + public function set_transaction_id($TXN_ID = 0) |
|
| 537 | + { |
|
| 538 | + $this->set('TXN_ID', $TXN_ID); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Set Session |
|
| 544 | + * |
|
| 545 | + * @param string $REG_session PHP Session ID |
|
| 546 | + * @throws EE_Error |
|
| 547 | + * @throws RuntimeException |
|
| 548 | + */ |
|
| 549 | + public function set_session($REG_session = '') |
|
| 550 | + { |
|
| 551 | + $this->set('REG_session', $REG_session); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Set Registration URL Link |
|
| 557 | + * |
|
| 558 | + * @param string $REG_url_link Registration URL Link |
|
| 559 | + * @throws EE_Error |
|
| 560 | + * @throws RuntimeException |
|
| 561 | + */ |
|
| 562 | + public function set_reg_url_link($REG_url_link = '') |
|
| 563 | + { |
|
| 564 | + $this->set('REG_url_link', $REG_url_link); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Set Attendee Counter |
|
| 570 | + * |
|
| 571 | + * @param int $REG_count Primary Attendee |
|
| 572 | + * @throws EE_Error |
|
| 573 | + * @throws RuntimeException |
|
| 574 | + */ |
|
| 575 | + public function set_count($REG_count = 1) |
|
| 576 | + { |
|
| 577 | + $this->set('REG_count', $REG_count); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Set Group Size |
|
| 583 | + * |
|
| 584 | + * @param boolean $REG_group_size Group Registration |
|
| 585 | + * @throws EE_Error |
|
| 586 | + * @throws RuntimeException |
|
| 587 | + */ |
|
| 588 | + public function set_group_size($REG_group_size = false) |
|
| 589 | + { |
|
| 590 | + $this->set('REG_group_size', $REG_group_size); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
| 596 | + * EEM_Registration::status_id_not_approved |
|
| 597 | + * |
|
| 598 | + * @return boolean |
|
| 599 | + */ |
|
| 600 | + public function is_not_approved() |
|
| 601 | + { |
|
| 602 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
| 608 | + * EEM_Registration::status_id_pending_payment |
|
| 609 | + * |
|
| 610 | + * @return boolean |
|
| 611 | + */ |
|
| 612 | + public function is_pending_payment() |
|
| 613 | + { |
|
| 614 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
| 620 | + * |
|
| 621 | + * @return boolean |
|
| 622 | + */ |
|
| 623 | + public function is_approved() |
|
| 624 | + { |
|
| 625 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
| 631 | + * |
|
| 632 | + * @return boolean |
|
| 633 | + */ |
|
| 634 | + public function is_cancelled() |
|
| 635 | + { |
|
| 636 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
| 642 | + * |
|
| 643 | + * @return boolean |
|
| 644 | + */ |
|
| 645 | + public function is_declined() |
|
| 646 | + { |
|
| 647 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
| 653 | + * EEM_Registration::status_id_incomplete |
|
| 654 | + * |
|
| 655 | + * @return boolean |
|
| 656 | + */ |
|
| 657 | + public function is_incomplete() |
|
| 658 | + { |
|
| 659 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Set Registration Date |
|
| 665 | + * |
|
| 666 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
| 667 | + * Date |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws RuntimeException |
|
| 670 | + */ |
|
| 671 | + public function set_reg_date($REG_date = false) |
|
| 672 | + { |
|
| 673 | + $this->set('REG_date', $REG_date); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + /** |
|
| 678 | + * Set final price owing for this registration after all ticket/price modifications |
|
| 679 | + * |
|
| 680 | + * @access public |
|
| 681 | + * @param float $REG_final_price |
|
| 682 | + * @throws EE_Error |
|
| 683 | + * @throws RuntimeException |
|
| 684 | + */ |
|
| 685 | + public function set_final_price($REG_final_price = 0.00) |
|
| 686 | + { |
|
| 687 | + $this->set('REG_final_price', $REG_final_price); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Set amount paid towards this registration's final price |
|
| 693 | + * |
|
| 694 | + * @access public |
|
| 695 | + * @param float $REG_paid |
|
| 696 | + * @throws EE_Error |
|
| 697 | + * @throws RuntimeException |
|
| 698 | + */ |
|
| 699 | + public function set_paid($REG_paid = 0.00) |
|
| 700 | + { |
|
| 701 | + $this->set('REG_paid', $REG_paid); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * Attendee Is Going |
|
| 707 | + * |
|
| 708 | + * @param boolean $REG_att_is_going Attendee Is Going |
|
| 709 | + * @throws EE_Error |
|
| 710 | + * @throws RuntimeException |
|
| 711 | + */ |
|
| 712 | + public function set_att_is_going($REG_att_is_going = false) |
|
| 713 | + { |
|
| 714 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Gets the related attendee |
|
| 720 | + * |
|
| 721 | + * @return EE_Attendee |
|
| 722 | + * @throws EE_Error |
|
| 723 | + */ |
|
| 724 | + public function attendee() |
|
| 725 | + { |
|
| 726 | + return $this->get_first_related('Attendee'); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * get Event ID |
|
| 732 | + */ |
|
| 733 | + public function event_ID() |
|
| 734 | + { |
|
| 735 | + return $this->get('EVT_ID'); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * get Event ID |
|
| 741 | + */ |
|
| 742 | + public function event_name() |
|
| 743 | + { |
|
| 744 | + $event = $this->event_obj(); |
|
| 745 | + if ($event) { |
|
| 746 | + return $event->name(); |
|
| 747 | + } else { |
|
| 748 | + return null; |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * Fetches the event this registration is for |
|
| 755 | + * |
|
| 756 | + * @return EE_Event |
|
| 757 | + * @throws EE_Error |
|
| 758 | + */ |
|
| 759 | + public function event_obj() |
|
| 760 | + { |
|
| 761 | + return $this->get_first_related('Event'); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * get Attendee ID |
|
| 767 | + */ |
|
| 768 | + public function attendee_ID() |
|
| 769 | + { |
|
| 770 | + return $this->get('ATT_ID'); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * get PHP Session ID |
|
| 776 | + */ |
|
| 777 | + public function session_ID() |
|
| 778 | + { |
|
| 779 | + return $this->get('REG_session'); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
| 785 | + * |
|
| 786 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 787 | + * @return string |
|
| 788 | + */ |
|
| 789 | + public function receipt_url($messenger = 'html') |
|
| 790 | + { |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
| 794 | + * already in use on old system. If there is then we just return the standard url for it. |
|
| 795 | + * |
|
| 796 | + * @since 4.5.0 |
|
| 797 | + */ |
|
| 798 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
| 799 | + $has_custom = EEH_Template::locate_template( |
|
| 800 | + $template_relative_path, |
|
| 801 | + array(), |
|
| 802 | + true, |
|
| 803 | + true, |
|
| 804 | + true |
|
| 805 | + ); |
|
| 806 | + |
|
| 807 | + if ($has_custom) { |
|
| 808 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
| 809 | + } |
|
| 810 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
| 816 | + * |
|
| 817 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 818 | + * @return string |
|
| 819 | + * @throws EE_Error |
|
| 820 | + */ |
|
| 821 | + public function invoice_url($messenger = 'html') |
|
| 822 | + { |
|
| 823 | + /** |
|
| 824 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
| 825 | + * already in use on old system. If there is then we just return the standard url for it. |
|
| 826 | + * |
|
| 827 | + * @since 4.5.0 |
|
| 828 | + */ |
|
| 829 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
| 830 | + $has_custom = EEH_Template::locate_template( |
|
| 831 | + $template_relative_path, |
|
| 832 | + array(), |
|
| 833 | + true, |
|
| 834 | + true, |
|
| 835 | + true |
|
| 836 | + ); |
|
| 837 | + |
|
| 838 | + if ($has_custom) { |
|
| 839 | + if ($messenger == 'html') { |
|
| 840 | + return $this->invoice_url('launch'); |
|
| 841 | + } |
|
| 842 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
| 843 | + |
|
| 844 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
| 845 | + if ($messenger == 'html') { |
|
| 846 | + $query_args['html'] = true; |
|
| 847 | + } |
|
| 848 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
| 849 | + } |
|
| 850 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * get Registration URL Link |
|
| 856 | + * |
|
| 857 | + * @access public |
|
| 858 | + * @return string |
|
| 859 | + * @throws EE_Error |
|
| 860 | + */ |
|
| 861 | + public function reg_url_link() |
|
| 862 | + { |
|
| 863 | + return (string) $this->get('REG_url_link'); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * Echoes out invoice_url() |
|
| 869 | + * |
|
| 870 | + * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
| 871 | + * @return void |
|
| 872 | + * @throws EE_Error |
|
| 873 | + */ |
|
| 874 | + public function e_invoice_url($type = 'launch') |
|
| 875 | + { |
|
| 876 | + echo $this->invoice_url($type); |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Echoes out payment_overview_url |
|
| 882 | + */ |
|
| 883 | + public function e_payment_overview_url() |
|
| 884 | + { |
|
| 885 | + echo $this->payment_overview_url(); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * Gets the URL for the checkout payment options reg step |
|
| 891 | + * with this registration's REG_url_link added as a query parameter |
|
| 892 | + * |
|
| 893 | + * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
| 894 | + * payment overview url. |
|
| 895 | + * @return string |
|
| 896 | + * @throws InvalidInterfaceException |
|
| 897 | + * @throws InvalidDataTypeException |
|
| 898 | + * @throws EE_Error |
|
| 899 | + * @throws InvalidArgumentException |
|
| 900 | + */ |
|
| 901 | + public function payment_overview_url($clear_session = false) |
|
| 902 | + { |
|
| 903 | + return add_query_arg( |
|
| 904 | + (array) apply_filters( |
|
| 905 | + 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
| 906 | + array( |
|
| 907 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
| 908 | + 'step' => 'payment_options', |
|
| 909 | + 'revisit' => true, |
|
| 910 | + 'clear_session' => (bool) $clear_session, |
|
| 911 | + ), |
|
| 912 | + $this |
|
| 913 | + ), |
|
| 914 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 915 | + ); |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * Gets the URL for the checkout attendee information reg step |
|
| 921 | + * with this registration's REG_url_link added as a query parameter |
|
| 922 | + * |
|
| 923 | + * @return string |
|
| 924 | + * @throws InvalidInterfaceException |
|
| 925 | + * @throws InvalidDataTypeException |
|
| 926 | + * @throws EE_Error |
|
| 927 | + * @throws InvalidArgumentException |
|
| 928 | + */ |
|
| 929 | + public function edit_attendee_information_url() |
|
| 930 | + { |
|
| 931 | + return add_query_arg( |
|
| 932 | + (array) apply_filters( |
|
| 933 | + 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
| 934 | + array( |
|
| 935 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
| 936 | + 'step' => 'attendee_information', |
|
| 937 | + 'revisit' => true, |
|
| 938 | + ), |
|
| 939 | + $this |
|
| 940 | + ), |
|
| 941 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 942 | + ); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Simply generates and returns the appropriate admin_url link to edit this registration |
|
| 948 | + * |
|
| 949 | + * @return string |
|
| 950 | + * @throws EE_Error |
|
| 951 | + */ |
|
| 952 | + public function get_admin_edit_url() |
|
| 953 | + { |
|
| 954 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 955 | + 'page' => 'espresso_registrations', |
|
| 956 | + 'action' => 'view_registration', |
|
| 957 | + '_REG_ID' => $this->ID(), |
|
| 958 | + ), admin_url('admin.php')); |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * is_primary_registrant? |
|
| 964 | + */ |
|
| 965 | + public function is_primary_registrant() |
|
| 966 | + { |
|
| 967 | + return $this->get('REG_count') == 1 ? true : false; |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * This returns the primary registration object for this registration group (which may be this object). |
|
| 973 | + * |
|
| 974 | + * @return EE_Registration |
|
| 975 | + * @throws EE_Error |
|
| 976 | + */ |
|
| 977 | + public function get_primary_registration() |
|
| 978 | + { |
|
| 979 | + if ($this->is_primary_registrant()) { |
|
| 980 | + return $this; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
| 984 | + /** @var EE_Registration $primary_registrant */ |
|
| 985 | + $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
| 986 | + array( |
|
| 987 | + 'TXN_ID' => $this->transaction_ID(), |
|
| 988 | + 'REG_count' => 1, |
|
| 989 | + ), |
|
| 990 | + )); |
|
| 991 | + return $primary_registrant; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * get Attendee Number |
|
| 997 | + * |
|
| 998 | + * @access public |
|
| 999 | + */ |
|
| 1000 | + public function count() |
|
| 1001 | + { |
|
| 1002 | + return $this->get('REG_count'); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * get Group Size |
|
| 1008 | + */ |
|
| 1009 | + public function group_size() |
|
| 1010 | + { |
|
| 1011 | + return $this->get('REG_group_size'); |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * get Registration Date |
|
| 1017 | + */ |
|
| 1018 | + public function date() |
|
| 1019 | + { |
|
| 1020 | + return $this->get('REG_date'); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + |
|
| 1024 | + /** |
|
| 1025 | + * gets a pretty date |
|
| 1026 | + * |
|
| 1027 | + * @param string $date_format |
|
| 1028 | + * @param string $time_format |
|
| 1029 | + * @return string |
|
| 1030 | + * @throws EE_Error |
|
| 1031 | + */ |
|
| 1032 | + public function pretty_date($date_format = null, $time_format = null) |
|
| 1033 | + { |
|
| 1034 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + |
|
| 1038 | + /** |
|
| 1039 | + * final_price |
|
| 1040 | + * the registration's share of the transaction total, so that the |
|
| 1041 | + * sum of all the transaction's REG_final_prices equal the transaction's total |
|
| 1042 | + * |
|
| 1043 | + * @return float |
|
| 1044 | + * @throws EE_Error |
|
| 1045 | + */ |
|
| 1046 | + public function final_price() |
|
| 1047 | + { |
|
| 1048 | + return $this->get('REG_final_price'); |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * pretty_final_price |
|
| 1054 | + * final price as formatted string, with correct decimal places and currency symbol |
|
| 1055 | + * |
|
| 1056 | + * @return string |
|
| 1057 | + * @throws EE_Error |
|
| 1058 | + */ |
|
| 1059 | + public function pretty_final_price() |
|
| 1060 | + { |
|
| 1061 | + return $this->get_pretty('REG_final_price'); |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * get paid (yeah) |
|
| 1067 | + * |
|
| 1068 | + * @return float |
|
| 1069 | + * @throws EE_Error |
|
| 1070 | + */ |
|
| 1071 | + public function paid() |
|
| 1072 | + { |
|
| 1073 | + return $this->get('REG_paid'); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * pretty_paid |
|
| 1079 | + * |
|
| 1080 | + * @return float |
|
| 1081 | + * @throws EE_Error |
|
| 1082 | + */ |
|
| 1083 | + public function pretty_paid() |
|
| 1084 | + { |
|
| 1085 | + return $this->get_pretty('REG_paid'); |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * owes_monies_and_can_pay |
|
| 1091 | + * whether or not this registration has monies owing and it's' status allows payment |
|
| 1092 | + * |
|
| 1093 | + * @param array $requires_payment |
|
| 1094 | + * @return bool |
|
| 1095 | + * @throws EE_Error |
|
| 1096 | + */ |
|
| 1097 | + public function owes_monies_and_can_pay($requires_payment = array()) |
|
| 1098 | + { |
|
| 1099 | + // these reg statuses require payment (if event is not free) |
|
| 1100 | + $requires_payment = ! empty($requires_payment) |
|
| 1101 | + ? $requires_payment |
|
| 1102 | + : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 1103 | + if (in_array($this->status_ID(), $requires_payment) && |
|
| 1104 | + $this->final_price() != 0 && |
|
| 1105 | + $this->final_price() != $this->paid() |
|
| 1106 | + ) { |
|
| 1107 | + return true; |
|
| 1108 | + } else { |
|
| 1109 | + return false; |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * Prints out the return value of $this->pretty_status() |
|
| 1116 | + * |
|
| 1117 | + * @param bool $show_icons |
|
| 1118 | + * @return void |
|
| 1119 | + * @throws EE_Error |
|
| 1120 | + */ |
|
| 1121 | + public function e_pretty_status($show_icons = false) |
|
| 1122 | + { |
|
| 1123 | + echo $this->pretty_status($show_icons); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * Returns a nice version of the status for displaying to customers |
|
| 1129 | + * |
|
| 1130 | + * @param bool $show_icons |
|
| 1131 | + * @return string |
|
| 1132 | + * @throws EE_Error |
|
| 1133 | + */ |
|
| 1134 | + public function pretty_status($show_icons = false) |
|
| 1135 | + { |
|
| 1136 | + $status = EEM_Status::instance()->localized_status( |
|
| 1137 | + array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 1138 | + false, |
|
| 1139 | + 'sentence' |
|
| 1140 | + ); |
|
| 1141 | + $icon = ''; |
|
| 1142 | + switch ($this->status_ID()) { |
|
| 1143 | + case EEM_Registration::status_id_approved: |
|
| 1144 | + $icon = $show_icons |
|
| 1145 | + ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
| 1146 | + : ''; |
|
| 1147 | + break; |
|
| 1148 | + case EEM_Registration::status_id_pending_payment: |
|
| 1149 | + $icon = $show_icons |
|
| 1150 | + ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
| 1151 | + : ''; |
|
| 1152 | + break; |
|
| 1153 | + case EEM_Registration::status_id_not_approved: |
|
| 1154 | + $icon = $show_icons |
|
| 1155 | + ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
| 1156 | + : ''; |
|
| 1157 | + break; |
|
| 1158 | + case EEM_Registration::status_id_cancelled: |
|
| 1159 | + $icon = $show_icons |
|
| 1160 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 1161 | + : ''; |
|
| 1162 | + break; |
|
| 1163 | + case EEM_Registration::status_id_incomplete: |
|
| 1164 | + $icon = $show_icons |
|
| 1165 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
| 1166 | + : ''; |
|
| 1167 | + break; |
|
| 1168 | + case EEM_Registration::status_id_declined: |
|
| 1169 | + $icon = $show_icons |
|
| 1170 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 1171 | + : ''; |
|
| 1172 | + break; |
|
| 1173 | + case EEM_Registration::status_id_wait_list: |
|
| 1174 | + $icon = $show_icons |
|
| 1175 | + ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
| 1176 | + : ''; |
|
| 1177 | + break; |
|
| 1178 | + } |
|
| 1179 | + return $icon . $status[$this->status_ID()]; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + |
|
| 1183 | + /** |
|
| 1184 | + * get Attendee Is Going |
|
| 1185 | + */ |
|
| 1186 | + public function att_is_going() |
|
| 1187 | + { |
|
| 1188 | + return $this->get('REG_att_is_going'); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * Gets related answers |
|
| 1194 | + * |
|
| 1195 | + * @param array $query_params like EEM_Base::get_all |
|
| 1196 | + * @return EE_Answer[] |
|
| 1197 | + * @throws EE_Error |
|
| 1198 | + */ |
|
| 1199 | + public function answers($query_params = null) |
|
| 1200 | + { |
|
| 1201 | + return $this->get_many_related('Answer', $query_params); |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + |
|
| 1205 | + /** |
|
| 1206 | + * Gets the registration's answer value to the specified question |
|
| 1207 | + * (either the question's ID or a question object) |
|
| 1208 | + * |
|
| 1209 | + * @param EE_Question|int $question |
|
| 1210 | + * @param bool $pretty_value |
|
| 1211 | + * @return array|string if pretty_value= true, the result will always be a string |
|
| 1212 | + * (because the answer might be an array of answer values, so passing pretty_value=true |
|
| 1213 | + * will convert it into some kind of string) |
|
| 1214 | + * @throws EE_Error |
|
| 1215 | + */ |
|
| 1216 | + public function answer_value_to_question($question, $pretty_value = true) |
|
| 1217 | + { |
|
| 1218 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
| 1219 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * question_groups |
|
| 1225 | + * returns an array of EE_Question_Group objects for this registration |
|
| 1226 | + * |
|
| 1227 | + * @return EE_Question_Group[] |
|
| 1228 | + * @throws EE_Error |
|
| 1229 | + * @throws EntityNotFoundException |
|
| 1230 | + */ |
|
| 1231 | + public function question_groups() |
|
| 1232 | + { |
|
| 1233 | + $question_groups = array(); |
|
| 1234 | + if ($this->event() instanceof EE_Event) { |
|
| 1235 | + $question_groups = $this->event()->question_groups( |
|
| 1236 | + array( |
|
| 1237 | + array( |
|
| 1238 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1239 | + ), |
|
| 1240 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 1241 | + ) |
|
| 1242 | + ); |
|
| 1243 | + } |
|
| 1244 | + return $question_groups; |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + |
|
| 1248 | + /** |
|
| 1249 | + * count_question_groups |
|
| 1250 | + * returns a count of the number of EE_Question_Group objects for this registration |
|
| 1251 | + * |
|
| 1252 | + * @return int |
|
| 1253 | + * @throws EE_Error |
|
| 1254 | + * @throws EntityNotFoundException |
|
| 1255 | + */ |
|
| 1256 | + public function count_question_groups() |
|
| 1257 | + { |
|
| 1258 | + $qg_count = 0; |
|
| 1259 | + if ($this->event() instanceof EE_Event) { |
|
| 1260 | + $qg_count = $this->event()->count_related( |
|
| 1261 | + 'Question_Group', |
|
| 1262 | + array( |
|
| 1263 | + array( |
|
| 1264 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1265 | + ), |
|
| 1266 | + ) |
|
| 1267 | + ); |
|
| 1268 | + } |
|
| 1269 | + return $qg_count; |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * Returns the registration date in the 'standard' string format |
|
| 1275 | + * (function may be improved in the future to allow for different formats and timezones) |
|
| 1276 | + * |
|
| 1277 | + * @return string |
|
| 1278 | + * @throws EE_Error |
|
| 1279 | + */ |
|
| 1280 | + public function reg_date() |
|
| 1281 | + { |
|
| 1282 | + return $this->get_datetime('REG_date'); |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + |
|
| 1286 | + /** |
|
| 1287 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
| 1288 | + * the ticket this registration purchased, or the datetime they have registered |
|
| 1289 | + * to attend) |
|
| 1290 | + * |
|
| 1291 | + * @return EE_Datetime_Ticket |
|
| 1292 | + * @throws EE_Error |
|
| 1293 | + */ |
|
| 1294 | + public function datetime_ticket() |
|
| 1295 | + { |
|
| 1296 | + return $this->get_first_related('Datetime_Ticket'); |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + |
|
| 1300 | + /** |
|
| 1301 | + * Sets the registration's datetime_ticket. |
|
| 1302 | + * |
|
| 1303 | + * @param EE_Datetime_Ticket $datetime_ticket |
|
| 1304 | + * @return EE_Datetime_Ticket |
|
| 1305 | + * @throws EE_Error |
|
| 1306 | + */ |
|
| 1307 | + public function set_datetime_ticket($datetime_ticket) |
|
| 1308 | + { |
|
| 1309 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * Gets deleted |
|
| 1314 | + * |
|
| 1315 | + * @return bool |
|
| 1316 | + * @throws EE_Error |
|
| 1317 | + */ |
|
| 1318 | + public function deleted() |
|
| 1319 | + { |
|
| 1320 | + return $this->get('REG_deleted'); |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * Sets deleted |
|
| 1325 | + * |
|
| 1326 | + * @param boolean $deleted |
|
| 1327 | + * @return bool |
|
| 1328 | + * @throws EE_Error |
|
| 1329 | + * @throws RuntimeException |
|
| 1330 | + */ |
|
| 1331 | + public function set_deleted($deleted) |
|
| 1332 | + { |
|
| 1333 | + if ($deleted) { |
|
| 1334 | + $this->delete(); |
|
| 1335 | + } else { |
|
| 1336 | + $this->restore(); |
|
| 1337 | + } |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * Get the status object of this object |
|
| 1343 | + * |
|
| 1344 | + * @return EE_Status |
|
| 1345 | + * @throws EE_Error |
|
| 1346 | + */ |
|
| 1347 | + public function status_obj() |
|
| 1348 | + { |
|
| 1349 | + return $this->get_first_related('Status'); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * Returns the number of times this registration has checked into any of the datetimes |
|
| 1355 | + * its available for |
|
| 1356 | + * |
|
| 1357 | + * @return int |
|
| 1358 | + * @throws EE_Error |
|
| 1359 | + */ |
|
| 1360 | + public function count_checkins() |
|
| 1361 | + { |
|
| 1362 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + |
|
| 1366 | + /** |
|
| 1367 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
| 1368 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
| 1369 | + * |
|
| 1370 | + * @return int |
|
| 1371 | + * @throws EE_Error |
|
| 1372 | + */ |
|
| 1373 | + public function count_checkins_not_checkedout() |
|
| 1374 | + { |
|
| 1375 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + |
|
| 1379 | + /** |
|
| 1380 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
| 1381 | + * |
|
| 1382 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1383 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
| 1384 | + * consider registration status as well as datetime access. |
|
| 1385 | + * @return bool |
|
| 1386 | + * @throws EE_Error |
|
| 1387 | + */ |
|
| 1388 | + public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
| 1389 | + { |
|
| 1390 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1391 | + |
|
| 1392 | + //first check registration status |
|
| 1393 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
| 1394 | + return false; |
|
| 1395 | + } |
|
| 1396 | + //is there a datetime ticket that matches this dtt_ID? |
|
| 1397 | + if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1398 | + array( |
|
| 1399 | + 'TKT_ID' => $this->get('TKT_ID'), |
|
| 1400 | + 'DTT_ID' => $DTT_ID, |
|
| 1401 | + ), |
|
| 1402 | + ))) |
|
| 1403 | + ) { |
|
| 1404 | + return false; |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + //final check is against TKT_uses |
|
| 1408 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
| 1414 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
| 1415 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
| 1416 | + * then return false. Otherwise return true. |
|
| 1417 | + * |
|
| 1418 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1419 | + * @return bool true means can checkin. false means cannot checkin. |
|
| 1420 | + * @throws EE_Error |
|
| 1421 | + */ |
|
| 1422 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
| 1423 | + { |
|
| 1424 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1425 | + |
|
| 1426 | + if (! $DTT_ID) { |
|
| 1427 | + return false; |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
| 1431 | + |
|
| 1432 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
| 1433 | + // check-in or not. |
|
| 1434 | + if (! $max_uses || $max_uses === EE_INF) { |
|
| 1435 | + return true; |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
| 1439 | + //go ahead and toggle. |
|
| 1440 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
| 1441 | + return true; |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
| 1445 | + //disallows further check-ins. |
|
| 1446 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
| 1447 | + array( |
|
| 1448 | + 'REG_ID' => $this->ID(), |
|
| 1449 | + 'CHK_in' => true, |
|
| 1450 | + ), |
|
| 1451 | + ), 'DTT_ID', true); |
|
| 1452 | + // checkins have already reached their max number of uses |
|
| 1453 | + // so registrant can NOT checkin |
|
| 1454 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
| 1455 | + EE_Error::add_error( |
|
| 1456 | + esc_html__( |
|
| 1457 | + 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
| 1458 | + 'event_espresso' |
|
| 1459 | + ), |
|
| 1460 | + __FILE__, |
|
| 1461 | + __FUNCTION__, |
|
| 1462 | + __LINE__ |
|
| 1463 | + ); |
|
| 1464 | + return false; |
|
| 1465 | + } |
|
| 1466 | + return true; |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * toggle Check-in status for this registration |
|
| 1472 | + * Check-ins are toggled in the following order: |
|
| 1473 | + * never checked in -> checked in |
|
| 1474 | + * checked in -> checked out |
|
| 1475 | + * checked out -> checked in |
|
| 1476 | + * |
|
| 1477 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
| 1478 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
| 1479 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
| 1480 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
| 1481 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
| 1482 | + * @throws EE_Error |
|
| 1483 | + */ |
|
| 1484 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
| 1485 | + { |
|
| 1486 | + if (empty($DTT_ID)) { |
|
| 1487 | + $datetime = $this->get_latest_related_datetime(); |
|
| 1488 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
| 1489 | + // verify the registration can checkin for the given DTT_ID |
|
| 1490 | + } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1491 | + EE_Error::add_error( |
|
| 1492 | + sprintf( |
|
| 1493 | + esc_html__( |
|
| 1494 | + 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
| 1495 | + 'event_espresso' |
|
| 1496 | + ), |
|
| 1497 | + $this->ID(), |
|
| 1498 | + $DTT_ID |
|
| 1499 | + ), |
|
| 1500 | + __FILE__, |
|
| 1501 | + __FUNCTION__, |
|
| 1502 | + __LINE__ |
|
| 1503 | + ); |
|
| 1504 | + return false; |
|
| 1505 | + } |
|
| 1506 | + $status_paths = array( |
|
| 1507 | + EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
| 1508 | + EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
| 1509 | + EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
| 1510 | + ); |
|
| 1511 | + //start by getting the current status so we know what status we'll be changing to. |
|
| 1512 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
| 1513 | + $status_to = $status_paths[$cur_status]; |
|
| 1514 | + // database only records true for checked IN or false for checked OUT |
|
| 1515 | + // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
| 1516 | + $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
| 1517 | + // add relation - note Check-ins are always creating new rows |
|
| 1518 | + // because we are keeping track of Check-ins over time. |
|
| 1519 | + // Eventually we'll probably want to show a list table |
|
| 1520 | + // for the individual Check-ins so that they can be managed. |
|
| 1521 | + $checkin = EE_Checkin::new_instance(array( |
|
| 1522 | + 'REG_ID' => $this->ID(), |
|
| 1523 | + 'DTT_ID' => $DTT_ID, |
|
| 1524 | + 'CHK_in' => $new_status, |
|
| 1525 | + )); |
|
| 1526 | + // if the record could not be saved then return false |
|
| 1527 | + if ($checkin->save() === 0) { |
|
| 1528 | + if (WP_DEBUG) { |
|
| 1529 | + global $wpdb; |
|
| 1530 | + $error = sprintf( |
|
| 1531 | + esc_html__( |
|
| 1532 | + 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
| 1533 | + 'event_espresso' |
|
| 1534 | + ), |
|
| 1535 | + '<br />', |
|
| 1536 | + $wpdb->last_error |
|
| 1537 | + ); |
|
| 1538 | + } else { |
|
| 1539 | + $error = esc_html__( |
|
| 1540 | + 'Registration check in update failed because of an unknown database error', |
|
| 1541 | + 'event_espresso' |
|
| 1542 | + ); |
|
| 1543 | + } |
|
| 1544 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 1545 | + return false; |
|
| 1546 | + } |
|
| 1547 | + return $status_to; |
|
| 1548 | + } |
|
| 1549 | + |
|
| 1550 | + |
|
| 1551 | + /** |
|
| 1552 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
| 1553 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
| 1554 | + * |
|
| 1555 | + * @return EE_Datetime|null |
|
| 1556 | + * @throws EE_Error |
|
| 1557 | + */ |
|
| 1558 | + public function get_latest_related_datetime() |
|
| 1559 | + { |
|
| 1560 | + return EEM_Datetime::instance()->get_one( |
|
| 1561 | + array( |
|
| 1562 | + array( |
|
| 1563 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1564 | + ), |
|
| 1565 | + 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
| 1566 | + ) |
|
| 1567 | + ); |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + |
|
| 1571 | + /** |
|
| 1572 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
| 1573 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
| 1574 | + * |
|
| 1575 | + * @throws EE_Error |
|
| 1576 | + */ |
|
| 1577 | + public function get_earliest_related_datetime() |
|
| 1578 | + { |
|
| 1579 | + return EEM_Datetime::instance()->get_one( |
|
| 1580 | + array( |
|
| 1581 | + array( |
|
| 1582 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1583 | + ), |
|
| 1584 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 1585 | + ) |
|
| 1586 | + ); |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + /** |
|
| 1591 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
| 1592 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
| 1593 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
| 1594 | + * |
|
| 1595 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
| 1596 | + * (if empty we'll get the primary datetime for |
|
| 1597 | + * this registration (via event) and use it's ID); |
|
| 1598 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
| 1599 | + * |
|
| 1600 | + * @return int Integer representing Check-in status. |
|
| 1601 | + * @throws EE_Error |
|
| 1602 | + */ |
|
| 1603 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
| 1604 | + { |
|
| 1605 | + $checkin_query_params = array( |
|
| 1606 | + 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
| 1607 | + ); |
|
| 1608 | + |
|
| 1609 | + if ($DTT_ID > 0) { |
|
| 1610 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + //get checkin object (if exists) |
|
| 1614 | + $checkin = $checkin instanceof EE_Checkin |
|
| 1615 | + ? $checkin |
|
| 1616 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
| 1617 | + if ($checkin instanceof EE_Checkin) { |
|
| 1618 | + if ($checkin->get('CHK_in')) { |
|
| 1619 | + return EE_Checkin::status_checked_in; //checked in |
|
| 1620 | + } |
|
| 1621 | + return EE_Checkin::status_checked_out; //had checked in but is now checked out. |
|
| 1622 | + } |
|
| 1623 | + return EE_Checkin::status_checked_never; //never been checked in |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + |
|
| 1627 | + /** |
|
| 1628 | + * This method returns a localized message for the toggled Check-in message. |
|
| 1629 | + * |
|
| 1630 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
| 1631 | + * then it is assumed Check-in for primary datetime was toggled. |
|
| 1632 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
| 1633 | + * message can be customized with the attendee name. |
|
| 1634 | + * @return string internationalized message |
|
| 1635 | + * @throws EE_Error |
|
| 1636 | + */ |
|
| 1637 | + public function get_checkin_msg($DTT_ID, $error = false) |
|
| 1638 | + { |
|
| 1639 | + //let's get the attendee first so we can include the name of the attendee |
|
| 1640 | + $attendee = $this->get_first_related('Attendee'); |
|
| 1641 | + if ($attendee instanceof EE_Attendee) { |
|
| 1642 | + if ($error) { |
|
| 1643 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
| 1644 | + } |
|
| 1645 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
| 1646 | + //what is the status message going to be? |
|
| 1647 | + switch ($cur_status) { |
|
| 1648 | + case EE_Checkin::status_checked_never: |
|
| 1649 | + return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
| 1650 | + $attendee->full_name()); |
|
| 1651 | + break; |
|
| 1652 | + case EE_Checkin::status_checked_in: |
|
| 1653 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
| 1654 | + break; |
|
| 1655 | + case EE_Checkin::status_checked_out: |
|
| 1656 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
| 1657 | + break; |
|
| 1658 | + } |
|
| 1659 | + } |
|
| 1660 | + return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + |
|
| 1664 | + /** |
|
| 1665 | + * Returns the related EE_Transaction to this registration |
|
| 1666 | + * |
|
| 1667 | + * @return EE_Transaction |
|
| 1668 | + * @throws EE_Error |
|
| 1669 | + * @throws EntityNotFoundException |
|
| 1670 | + */ |
|
| 1671 | + public function transaction() |
|
| 1672 | + { |
|
| 1673 | + $transaction = $this->get_first_related('Transaction'); |
|
| 1674 | + if (! $transaction instanceof \EE_Transaction) { |
|
| 1675 | + throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
| 1676 | + } |
|
| 1677 | + return $transaction; |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + |
|
| 1681 | + /** |
|
| 1682 | + * get Registration Code |
|
| 1683 | + */ |
|
| 1684 | + public function reg_code() |
|
| 1685 | + { |
|
| 1686 | + return $this->get('REG_code'); |
|
| 1687 | + } |
|
| 1688 | + |
|
| 1689 | + |
|
| 1690 | + /** |
|
| 1691 | + * get Transaction ID |
|
| 1692 | + */ |
|
| 1693 | + public function transaction_ID() |
|
| 1694 | + { |
|
| 1695 | + return $this->get('TXN_ID'); |
|
| 1696 | + } |
|
| 1697 | + |
|
| 1698 | + |
|
| 1699 | + /** |
|
| 1700 | + * @return int |
|
| 1701 | + * @throws EE_Error |
|
| 1702 | + */ |
|
| 1703 | + public function ticket_ID() |
|
| 1704 | + { |
|
| 1705 | + return $this->get('TKT_ID'); |
|
| 1706 | + } |
|
| 1707 | + |
|
| 1708 | + |
|
| 1709 | + /** |
|
| 1710 | + * Set Registration Code |
|
| 1711 | + * |
|
| 1712 | + * @access public |
|
| 1713 | + * @param string $REG_code Registration Code |
|
| 1714 | + * @param boolean $use_default |
|
| 1715 | + * @throws EE_Error |
|
| 1716 | + */ |
|
| 1717 | + public function set_reg_code($REG_code, $use_default = false) |
|
| 1718 | + { |
|
| 1719 | + if (empty($REG_code)) { |
|
| 1720 | + EE_Error::add_error( |
|
| 1721 | + esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
| 1722 | + __FILE__, |
|
| 1723 | + __FUNCTION__, |
|
| 1724 | + __LINE__ |
|
| 1725 | + ); |
|
| 1726 | + return; |
|
| 1727 | + } |
|
| 1728 | + if (! $this->reg_code()) { |
|
| 1729 | + parent::set('REG_code', $REG_code, $use_default); |
|
| 1730 | + } else { |
|
| 1731 | + EE_Error::doing_it_wrong( |
|
| 1732 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 1733 | + esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
| 1734 | + '4.6.0' |
|
| 1735 | + ); |
|
| 1736 | + } |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
| 1742 | + * Note, if you want to just get all registrations in the same transaction (group), use: |
|
| 1743 | + * $registration->transaction()->registrations(); |
|
| 1744 | + * |
|
| 1745 | + * @since 4.5.0 |
|
| 1746 | + * @return EE_Registration[] or empty array if this isn't a group registration. |
|
| 1747 | + * @throws EE_Error |
|
| 1748 | + */ |
|
| 1749 | + public function get_all_other_registrations_in_group() |
|
| 1750 | + { |
|
| 1751 | + if ($this->group_size() < 2) { |
|
| 1752 | + return array(); |
|
| 1753 | + } |
|
| 1754 | + |
|
| 1755 | + $query[0] = array( |
|
| 1756 | + 'TXN_ID' => $this->transaction_ID(), |
|
| 1757 | + 'REG_ID' => array('!=', $this->ID()), |
|
| 1758 | + 'TKT_ID' => $this->ticket_ID(), |
|
| 1759 | + ); |
|
| 1760 | + /** @var EE_Registration[] $registrations */ |
|
| 1761 | + $registrations = $this->get_model()->get_all($query); |
|
| 1762 | + return $registrations; |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + /** |
|
| 1766 | + * Return the link to the admin details for the object. |
|
| 1767 | + * |
|
| 1768 | + * @return string |
|
| 1769 | + * @throws EE_Error |
|
| 1770 | + */ |
|
| 1771 | + public function get_admin_details_link() |
|
| 1772 | + { |
|
| 1773 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1774 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1775 | + array( |
|
| 1776 | + 'page' => 'espresso_registrations', |
|
| 1777 | + 'action' => 'view_registration', |
|
| 1778 | + '_REG_ID' => $this->ID(), |
|
| 1779 | + ), |
|
| 1780 | + admin_url('admin.php') |
|
| 1781 | + ); |
|
| 1782 | + } |
|
| 1783 | + |
|
| 1784 | + /** |
|
| 1785 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 1786 | + * |
|
| 1787 | + * @return string |
|
| 1788 | + * @throws EE_Error |
|
| 1789 | + */ |
|
| 1790 | + public function get_admin_edit_link() |
|
| 1791 | + { |
|
| 1792 | + return $this->get_admin_details_link(); |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + /** |
|
| 1796 | + * Returns the link to a settings page for the object. |
|
| 1797 | + * |
|
| 1798 | + * @return string |
|
| 1799 | + * @throws EE_Error |
|
| 1800 | + */ |
|
| 1801 | + public function get_admin_settings_link() |
|
| 1802 | + { |
|
| 1803 | + return $this->get_admin_details_link(); |
|
| 1804 | + } |
|
| 1805 | + |
|
| 1806 | + /** |
|
| 1807 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 1808 | + * |
|
| 1809 | + * @return string |
|
| 1810 | + */ |
|
| 1811 | + public function get_admin_overview_link() |
|
| 1812 | + { |
|
| 1813 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1814 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1815 | + array( |
|
| 1816 | + 'page' => 'espresso_registrations', |
|
| 1817 | + ), |
|
| 1818 | + admin_url('admin.php') |
|
| 1819 | + ); |
|
| 1820 | + } |
|
| 1821 | + |
|
| 1822 | + |
|
| 1823 | + /** |
|
| 1824 | + * @param array $query_params |
|
| 1825 | + * |
|
| 1826 | + * @return \EE_Registration[] |
|
| 1827 | + * @throws EE_Error |
|
| 1828 | + */ |
|
| 1829 | + public function payments($query_params = array()) |
|
| 1830 | + { |
|
| 1831 | + return $this->get_many_related('Payment', $query_params); |
|
| 1832 | + } |
|
| 1833 | + |
|
| 1834 | + |
|
| 1835 | + /** |
|
| 1836 | + * @param array $query_params |
|
| 1837 | + * |
|
| 1838 | + * @return \EE_Registration_Payment[] |
|
| 1839 | + * @throws EE_Error |
|
| 1840 | + */ |
|
| 1841 | + public function registration_payments($query_params = array()) |
|
| 1842 | + { |
|
| 1843 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + |
|
| 1847 | + /** |
|
| 1848 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
| 1849 | + * Note: if there are no payments on the registration there will be no payment method returned. |
|
| 1850 | + * |
|
| 1851 | + * @return EE_Payment_Method|null |
|
| 1852 | + */ |
|
| 1853 | + public function payment_method() |
|
| 1854 | + { |
|
| 1855 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
| 1856 | + } |
|
| 1857 | + |
|
| 1858 | + |
|
| 1859 | + /** |
|
| 1860 | + * @return \EE_Line_Item |
|
| 1861 | + * @throws EntityNotFoundException |
|
| 1862 | + * @throws EE_Error |
|
| 1863 | + */ |
|
| 1864 | + public function ticket_line_item() |
|
| 1865 | + { |
|
| 1866 | + $ticket = $this->ticket(); |
|
| 1867 | + $transaction = $this->transaction(); |
|
| 1868 | + $line_item = null; |
|
| 1869 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 1870 | + $transaction->total_line_item(), |
|
| 1871 | + 'Ticket', |
|
| 1872 | + array($ticket->ID()) |
|
| 1873 | + ); |
|
| 1874 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1875 | + if ( |
|
| 1876 | + $ticket_line_item instanceof \EE_Line_Item |
|
| 1877 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
| 1878 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
| 1879 | + ) { |
|
| 1880 | + $line_item = $ticket_line_item; |
|
| 1881 | + break; |
|
| 1882 | + } |
|
| 1883 | + } |
|
| 1884 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1885 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
| 1886 | + } |
|
| 1887 | + return $line_item; |
|
| 1888 | + } |
|
| 1889 | + |
|
| 1890 | + |
|
| 1891 | + /** |
|
| 1892 | + * Soft Deletes this model object. |
|
| 1893 | + * |
|
| 1894 | + * @return boolean | int |
|
| 1895 | + * @throws RuntimeException |
|
| 1896 | + * @throws EE_Error |
|
| 1897 | + */ |
|
| 1898 | + public function delete() |
|
| 1899 | + { |
|
| 1900 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1901 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
| 1902 | + } |
|
| 1903 | + return parent::delete(); |
|
| 1904 | + } |
|
| 1905 | + |
|
| 1906 | + |
|
| 1907 | + /** |
|
| 1908 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
| 1909 | + * |
|
| 1910 | + * @throws EE_Error |
|
| 1911 | + * @throws RuntimeException |
|
| 1912 | + */ |
|
| 1913 | + public function restore() |
|
| 1914 | + { |
|
| 1915 | + $previous_status = $this->get_extra_meta( |
|
| 1916 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
| 1917 | + true, |
|
| 1918 | + EEM_Registration::status_id_cancelled |
|
| 1919 | + ); |
|
| 1920 | + if ($previous_status) { |
|
| 1921 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
| 1922 | + $this->set_status($previous_status); |
|
| 1923 | + } |
|
| 1924 | + return parent::restore(); |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + |
|
| 1928 | + /** |
|
| 1929 | + * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
| 1930 | + * |
|
| 1931 | + * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
| 1932 | + * depending on whether the reg status changes to or from "Approved" |
|
| 1933 | + * @return boolean whether the Registration status was updated |
|
| 1934 | + * @throws EE_Error |
|
| 1935 | + * @throws RuntimeException |
|
| 1936 | + */ |
|
| 1937 | + public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
| 1938 | + { |
|
| 1939 | + $paid = $this->paid(); |
|
| 1940 | + $price = $this->final_price(); |
|
| 1941 | + switch(true) { |
|
| 1942 | + // overpaid or paid |
|
| 1943 | + case EEH_Money::compare_floats($paid, $price, '>'): |
|
| 1944 | + case EEH_Money::compare_floats($paid, $price): |
|
| 1945 | + $new_status = EEM_Registration::status_id_approved; |
|
| 1946 | + break; |
|
| 1947 | + // underpaid |
|
| 1948 | + case EEH_Money::compare_floats($paid, $price, '<'): |
|
| 1949 | + $new_status = EEM_Registration::status_id_pending_payment; |
|
| 1950 | + break; |
|
| 1951 | + // uhhh Houston... |
|
| 1952 | + default: |
|
| 1953 | + throw new RuntimeException( |
|
| 1954 | + esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
| 1955 | + ); |
|
| 1956 | + } |
|
| 1957 | + if ($new_status !== $this->status_ID()) { |
|
| 1958 | + if ($trigger_set_status_logic) { |
|
| 1959 | + return $this->set_status($new_status); |
|
| 1960 | + } |
|
| 1961 | + parent::set('STS_ID', $new_status); |
|
| 1962 | + return true; |
|
| 1963 | + } |
|
| 1964 | + return false; |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + |
|
| 1968 | + /*************************** DEPRECATED ***************************/ |
|
| 1969 | + |
|
| 1970 | + |
|
| 1971 | + /** |
|
| 1972 | + * @deprecated |
|
| 1973 | + * @since 4.7.0 |
|
| 1974 | + * @access public |
|
| 1975 | + */ |
|
| 1976 | + public function price_paid() |
|
| 1977 | + { |
|
| 1978 | + EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
| 1979 | + esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
| 1980 | + '4.7.0'); |
|
| 1981 | + return $this->final_price(); |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + |
|
| 1985 | + /** |
|
| 1986 | + * @deprecated |
|
| 1987 | + * @since 4.7.0 |
|
| 1988 | + * @access public |
|
| 1989 | + * @param float $REG_final_price |
|
| 1990 | + * @throws EE_Error |
|
| 1991 | + * @throws RuntimeException |
|
| 1992 | + */ |
|
| 1993 | + public function set_price_paid($REG_final_price = 0.00) |
|
| 1994 | + { |
|
| 1995 | + EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
| 1996 | + esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
| 1997 | + '4.7.0'); |
|
| 1998 | + $this->set_final_price($REG_final_price); |
|
| 1999 | + } |
|
| 2000 | + |
|
| 2001 | + |
|
| 2002 | + /** |
|
| 2003 | + * @deprecated |
|
| 2004 | + * @since 4.7.0 |
|
| 2005 | + * @return string |
|
| 2006 | + * @throws EE_Error |
|
| 2007 | + */ |
|
| 2008 | + public function pretty_price_paid() |
|
| 2009 | + { |
|
| 2010 | + EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
| 2011 | + esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
| 2012 | + 'event_espresso'), '4.7.0'); |
|
| 2013 | + return $this->pretty_final_price(); |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + |
|
| 2017 | + /** |
|
| 2018 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
| 2019 | + * |
|
| 2020 | + * @deprecated 4.9.17 |
|
| 2021 | + * @return EE_Datetime |
|
| 2022 | + * @throws EE_Error |
|
| 2023 | + * @throws EntityNotFoundException |
|
| 2024 | + */ |
|
| 2025 | + public function get_related_primary_datetime() |
|
| 2026 | + { |
|
| 2027 | + EE_Error::doing_it_wrong( |
|
| 2028 | + __METHOD__, |
|
| 2029 | + esc_html__( |
|
| 2030 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
| 2031 | + 'event_espresso' |
|
| 2032 | + ), |
|
| 2033 | + '4.9.17', |
|
| 2034 | + '5.0.0' |
|
| 2035 | + ); |
|
| 2036 | + return $this->event()->primary_datetime(); |
|
| 2037 | + } |
|
| 2038 | 2038 | |
| 2039 | 2039 | |
| 2040 | 2040 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | switch ($field_name) { |
| 122 | 122 | case 'REG_code': |
| 123 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
| 123 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
| 124 | 124 | $this->set_reg_code($field_value, $use_default); |
| 125 | 125 | } |
| 126 | 126 | break; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | // update status |
| 182 | 182 | parent::set('STS_ID', $new_STS_ID, $use_default); |
| 183 | 183 | $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
| 184 | - if($this->statusChangeUpdatesTransaction($context)) { |
|
| 184 | + if ($this->statusChangeUpdatesTransaction($context)) { |
|
| 185 | 185 | $this->updateTransactionAfterStatusChange(); |
| 186 | 186 | } |
| 187 | 187 | do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | { |
| 373 | 373 | // reserved ticket and datetime counts will be decremented as sold counts are incremented |
| 374 | 374 | // so stop tracking that this reg has a ticket reserved |
| 375 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:". __LINE__ . ')'); |
|
| 375 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 376 | 376 | $ticket = $this->ticket(); |
| 377 | 377 | $ticket->increase_sold(); |
| 378 | 378 | $ticket->save(); |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | public function event() |
| 410 | 410 | { |
| 411 | 411 | $event = $this->get_first_related('Event'); |
| 412 | - if (! $event instanceof \EE_Event) { |
|
| 412 | + if ( ! $event instanceof \EE_Event) { |
|
| 413 | 413 | throw new EntityNotFoundException('Event ID', $this->event_ID()); |
| 414 | 414 | } |
| 415 | 415 | return $event; |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | && $update_ticket |
| 475 | 475 | ) { |
| 476 | 476 | $ticket = $this->ticket(); |
| 477 | - $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 477 | + $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 478 | 478 | $ticket->save(); |
| 479 | 479 | } |
| 480 | 480 | } |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | && $update_ticket |
| 507 | 507 | ) { |
| 508 | 508 | $ticket = $this->ticket(); |
| 509 | - $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 509 | + $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 510 | 510 | $ticket->save(); |
| 511 | 511 | } |
| 512 | 512 | } |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | false, |
| 1139 | 1139 | 'sentence' |
| 1140 | 1140 | ); |
| 1141 | - $icon = ''; |
|
| 1141 | + $icon = ''; |
|
| 1142 | 1142 | switch ($this->status_ID()) { |
| 1143 | 1143 | case EEM_Registration::status_id_approved: |
| 1144 | 1144 | $icon = $show_icons |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | : ''; |
| 1177 | 1177 | break; |
| 1178 | 1178 | } |
| 1179 | - return $icon . $status[$this->status_ID()]; |
|
| 1179 | + return $icon.$status[$this->status_ID()]; |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | return false; |
| 1395 | 1395 | } |
| 1396 | 1396 | //is there a datetime ticket that matches this dtt_ID? |
| 1397 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1397 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1398 | 1398 | array( |
| 1399 | 1399 | 'TKT_ID' => $this->get('TKT_ID'), |
| 1400 | 1400 | 'DTT_ID' => $DTT_ID, |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | { |
| 1424 | 1424 | $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
| 1425 | 1425 | |
| 1426 | - if (! $DTT_ID) { |
|
| 1426 | + if ( ! $DTT_ID) { |
|
| 1427 | 1427 | return false; |
| 1428 | 1428 | } |
| 1429 | 1429 | |
@@ -1431,7 +1431,7 @@ discard block |
||
| 1431 | 1431 | |
| 1432 | 1432 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
| 1433 | 1433 | // check-in or not. |
| 1434 | - if (! $max_uses || $max_uses === EE_INF) { |
|
| 1434 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
| 1435 | 1435 | return true; |
| 1436 | 1436 | } |
| 1437 | 1437 | |
@@ -1487,7 +1487,7 @@ discard block |
||
| 1487 | 1487 | $datetime = $this->get_latest_related_datetime(); |
| 1488 | 1488 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
| 1489 | 1489 | // verify the registration can checkin for the given DTT_ID |
| 1490 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1490 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1491 | 1491 | EE_Error::add_error( |
| 1492 | 1492 | sprintf( |
| 1493 | 1493 | esc_html__( |
@@ -1671,7 +1671,7 @@ discard block |
||
| 1671 | 1671 | public function transaction() |
| 1672 | 1672 | { |
| 1673 | 1673 | $transaction = $this->get_first_related('Transaction'); |
| 1674 | - if (! $transaction instanceof \EE_Transaction) { |
|
| 1674 | + if ( ! $transaction instanceof \EE_Transaction) { |
|
| 1675 | 1675 | throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
| 1676 | 1676 | } |
| 1677 | 1677 | return $transaction; |
@@ -1725,11 +1725,11 @@ discard block |
||
| 1725 | 1725 | ); |
| 1726 | 1726 | return; |
| 1727 | 1727 | } |
| 1728 | - if (! $this->reg_code()) { |
|
| 1728 | + if ( ! $this->reg_code()) { |
|
| 1729 | 1729 | parent::set('REG_code', $REG_code, $use_default); |
| 1730 | 1730 | } else { |
| 1731 | 1731 | EE_Error::doing_it_wrong( |
| 1732 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1732 | + __CLASS__.'::'.__FUNCTION__, |
|
| 1733 | 1733 | esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
| 1734 | 1734 | '4.6.0' |
| 1735 | 1735 | ); |
@@ -1881,7 +1881,7 @@ discard block |
||
| 1881 | 1881 | break; |
| 1882 | 1882 | } |
| 1883 | 1883 | } |
| 1884 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1884 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1885 | 1885 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
| 1886 | 1886 | } |
| 1887 | 1887 | return $line_item; |
@@ -1938,7 +1938,7 @@ discard block |
||
| 1938 | 1938 | { |
| 1939 | 1939 | $paid = $this->paid(); |
| 1940 | 1940 | $price = $this->final_price(); |
| 1941 | - switch(true) { |
|
| 1941 | + switch (true) { |
|
| 1942 | 1942 | // overpaid or paid |
| 1943 | 1943 | case EEH_Money::compare_floats($paid, $price, '>'): |
| 1944 | 1944 | case EEH_Money::compare_floats($paid, $price): |
@@ -23,186 +23,186 @@ |
||
| 23 | 23 | class RecommendedVersions extends Middleware |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * converts a Request to a Response |
|
| 28 | - * |
|
| 29 | - * @param RequestInterface $request |
|
| 30 | - * @param ResponseInterface $response |
|
| 31 | - * @return ResponseInterface |
|
| 32 | - * @throws InvalidDataTypeException |
|
| 33 | - */ |
|
| 34 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 35 | - { |
|
| 36 | - $this->request = $request; |
|
| 37 | - $this->response = $response; |
|
| 38 | - // check required WP version |
|
| 39 | - if (! $this->minimumWordPressVersionRequired()) { |
|
| 40 | - $this->request->unSetRequestParam('activate', true); |
|
| 41 | - add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
| 42 | - $this->response->terminateRequest(); |
|
| 43 | - $this->response->deactivatePlugin(); |
|
| 44 | - } |
|
| 45 | - // check recommended PHP version |
|
| 46 | - if (! $this->minimumPhpVersionRecommended()) { |
|
| 47 | - $this->displayMinimumRecommendedPhpVersionNotice(); |
|
| 48 | - } |
|
| 49 | - //upcoming required version |
|
| 50 | - if (! $this->upcomingRequiredPhpVersion()) { |
|
| 51 | - $this->displayUpcomingRequiredVersion(); |
|
| 52 | - } |
|
| 53 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 54 | - return $this->response; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Helper method to assess installed wp version against given values. |
|
| 60 | - * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
| 61 | - * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
| 62 | - * against) so consider that when sending in your values. |
|
| 63 | - * |
|
| 64 | - * @param string $version_to_check |
|
| 65 | - * @param string $operator |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 68 | - public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
| 69 | - { |
|
| 70 | - global $wp_version; |
|
| 71 | - return version_compare( |
|
| 72 | - // first account for wp_version being pre-release |
|
| 73 | - // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
| 74 | - strpos($wp_version, '-') > 0 |
|
| 75 | - ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
| 76 | - : $wp_version, |
|
| 77 | - $version_to_check, |
|
| 78 | - $operator |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - private function minimumWordPressVersionRequired() |
|
| 88 | - { |
|
| 89 | - return RecommendedVersions::compareWordPressVersion(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $min_version |
|
| 96 | - * @return boolean |
|
| 97 | - */ |
|
| 98 | - private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
| 99 | - { |
|
| 100 | - return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return boolean |
|
| 107 | - */ |
|
| 108 | - private function minimumPhpVersionRecommended() |
|
| 109 | - { |
|
| 110 | - return $this->checkPhpVersion(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return void |
|
| 117 | - */ |
|
| 118 | - public function minimumWpVersionError() |
|
| 119 | - { |
|
| 120 | - global $wp_version; |
|
| 121 | - ?> |
|
| 26 | + /** |
|
| 27 | + * converts a Request to a Response |
|
| 28 | + * |
|
| 29 | + * @param RequestInterface $request |
|
| 30 | + * @param ResponseInterface $response |
|
| 31 | + * @return ResponseInterface |
|
| 32 | + * @throws InvalidDataTypeException |
|
| 33 | + */ |
|
| 34 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 35 | + { |
|
| 36 | + $this->request = $request; |
|
| 37 | + $this->response = $response; |
|
| 38 | + // check required WP version |
|
| 39 | + if (! $this->minimumWordPressVersionRequired()) { |
|
| 40 | + $this->request->unSetRequestParam('activate', true); |
|
| 41 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
| 42 | + $this->response->terminateRequest(); |
|
| 43 | + $this->response->deactivatePlugin(); |
|
| 44 | + } |
|
| 45 | + // check recommended PHP version |
|
| 46 | + if (! $this->minimumPhpVersionRecommended()) { |
|
| 47 | + $this->displayMinimumRecommendedPhpVersionNotice(); |
|
| 48 | + } |
|
| 49 | + //upcoming required version |
|
| 50 | + if (! $this->upcomingRequiredPhpVersion()) { |
|
| 51 | + $this->displayUpcomingRequiredVersion(); |
|
| 52 | + } |
|
| 53 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 54 | + return $this->response; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Helper method to assess installed wp version against given values. |
|
| 60 | + * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
| 61 | + * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
| 62 | + * against) so consider that when sending in your values. |
|
| 63 | + * |
|
| 64 | + * @param string $version_to_check |
|
| 65 | + * @param string $operator |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | + public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
| 69 | + { |
|
| 70 | + global $wp_version; |
|
| 71 | + return version_compare( |
|
| 72 | + // first account for wp_version being pre-release |
|
| 73 | + // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
| 74 | + strpos($wp_version, '-') > 0 |
|
| 75 | + ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
| 76 | + : $wp_version, |
|
| 77 | + $version_to_check, |
|
| 78 | + $operator |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + private function minimumWordPressVersionRequired() |
|
| 88 | + { |
|
| 89 | + return RecommendedVersions::compareWordPressVersion(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $min_version |
|
| 96 | + * @return boolean |
|
| 97 | + */ |
|
| 98 | + private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
| 99 | + { |
|
| 100 | + return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return boolean |
|
| 107 | + */ |
|
| 108 | + private function minimumPhpVersionRecommended() |
|
| 109 | + { |
|
| 110 | + return $this->checkPhpVersion(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return void |
|
| 117 | + */ |
|
| 118 | + public function minimumWpVersionError() |
|
| 119 | + { |
|
| 120 | + global $wp_version; |
|
| 121 | + ?> |
|
| 122 | 122 | <div class="error"> |
| 123 | 123 | <p> |
| 124 | 124 | <?php |
| 125 | - printf( |
|
| 126 | - __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
| 127 | - 'event_espresso'), |
|
| 128 | - EE_MIN_WP_VER_REQUIRED, |
|
| 129 | - $wp_version, |
|
| 130 | - '<br/>', |
|
| 131 | - '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
| 132 | - ); |
|
| 133 | - ?> |
|
| 125 | + printf( |
|
| 126 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
| 127 | + 'event_espresso'), |
|
| 128 | + EE_MIN_WP_VER_REQUIRED, |
|
| 129 | + $wp_version, |
|
| 130 | + '<br/>', |
|
| 131 | + '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
| 132 | + ); |
|
| 133 | + ?> |
|
| 134 | 134 | </p> |
| 135 | 135 | </div> |
| 136 | 136 | <?php |
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * _display_minimum_recommended_php_version_notice |
|
| 143 | - * |
|
| 144 | - * @access private |
|
| 145 | - * @return void |
|
| 146 | - * @throws InvalidDataTypeException |
|
| 147 | - */ |
|
| 148 | - private function displayMinimumRecommendedPhpVersionNotice() |
|
| 149 | - { |
|
| 150 | - if ($this->request->isAdmin()) { |
|
| 151 | - new PersistentAdminNotice( |
|
| 152 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
| 153 | - sprintf( |
|
| 154 | - esc_html__( |
|
| 155 | - 'Event Espresso recommends PHP version %1$s or greater for optimal performance. 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.', |
|
| 156 | - 'event_espresso' |
|
| 157 | - ), |
|
| 158 | - EE_MIN_PHP_VER_RECOMMENDED, |
|
| 159 | - PHP_VERSION, |
|
| 160 | - '<br/>', |
|
| 161 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Returns whether the provided php version number is greater than the current version of php installed on the server. |
|
| 170 | - * |
|
| 171 | - * @param string $version_required |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - private function upcomingRequiredPhpVersion($version_required = '5.5') |
|
| 175 | - { |
|
| 176 | - return $this->checkPhpVersion($version_required); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Sets a notice for an upcoming required version of PHP in the next update of EE core. |
|
| 182 | - */ |
|
| 183 | - private function displayUpcomingRequiredVersion() |
|
| 184 | - { |
|
| 185 | - if ($this->request->isAdmin() |
|
| 186 | - && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request) |
|
| 187 | - && current_user_can('update_plugins') |
|
| 188 | - ) { |
|
| 189 | - add_action('admin_notices', function () |
|
| 190 | - { |
|
| 191 | - echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
|
| 192 | - . sprintf( |
|
| 193 | - esc_html__( |
|
| 194 | - 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater. Your web server\'s PHP version is %3$s. You can contact your host and ask them to update your PHP version to at least PHP 5.6. Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s', |
|
| 195 | - 'event_espresso' |
|
| 196 | - ), |
|
| 197 | - '<strong>', |
|
| 198 | - '</strong>', |
|
| 199 | - PHP_VERSION, |
|
| 200 | - '<a href="https://wordpress.org/support/upgrade-php/">', |
|
| 201 | - '</a>' |
|
| 202 | - ) |
|
| 203 | - . '</p></div>'; |
|
| 204 | - }); |
|
| 205 | - } |
|
| 206 | - } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * _display_minimum_recommended_php_version_notice |
|
| 143 | + * |
|
| 144 | + * @access private |
|
| 145 | + * @return void |
|
| 146 | + * @throws InvalidDataTypeException |
|
| 147 | + */ |
|
| 148 | + private function displayMinimumRecommendedPhpVersionNotice() |
|
| 149 | + { |
|
| 150 | + if ($this->request->isAdmin()) { |
|
| 151 | + new PersistentAdminNotice( |
|
| 152 | + 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
| 153 | + sprintf( |
|
| 154 | + esc_html__( |
|
| 155 | + 'Event Espresso recommends PHP version %1$s or greater for optimal performance. 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.', |
|
| 156 | + 'event_espresso' |
|
| 157 | + ), |
|
| 158 | + EE_MIN_PHP_VER_RECOMMENDED, |
|
| 159 | + PHP_VERSION, |
|
| 160 | + '<br/>', |
|
| 161 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Returns whether the provided php version number is greater than the current version of php installed on the server. |
|
| 170 | + * |
|
| 171 | + * @param string $version_required |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + private function upcomingRequiredPhpVersion($version_required = '5.5') |
|
| 175 | + { |
|
| 176 | + return $this->checkPhpVersion($version_required); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Sets a notice for an upcoming required version of PHP in the next update of EE core. |
|
| 182 | + */ |
|
| 183 | + private function displayUpcomingRequiredVersion() |
|
| 184 | + { |
|
| 185 | + if ($this->request->isAdmin() |
|
| 186 | + && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request) |
|
| 187 | + && current_user_can('update_plugins') |
|
| 188 | + ) { |
|
| 189 | + add_action('admin_notices', function () |
|
| 190 | + { |
|
| 191 | + echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
|
| 192 | + . sprintf( |
|
| 193 | + esc_html__( |
|
| 194 | + 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater. Your web server\'s PHP version is %3$s. You can contact your host and ask them to update your PHP version to at least PHP 5.6. Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s', |
|
| 195 | + 'event_espresso' |
|
| 196 | + ), |
|
| 197 | + '<strong>', |
|
| 198 | + '</strong>', |
|
| 199 | + PHP_VERSION, |
|
| 200 | + '<a href="https://wordpress.org/support/upgrade-php/">', |
|
| 201 | + '</a>' |
|
| 202 | + ) |
|
| 203 | + . '</p></div>'; |
|
| 204 | + }); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | } |
| 208 | 208 | // Location: RecommendedVersions.php |
@@ -36,18 +36,18 @@ discard block |
||
| 36 | 36 | $this->request = $request; |
| 37 | 37 | $this->response = $response; |
| 38 | 38 | // check required WP version |
| 39 | - if (! $this->minimumWordPressVersionRequired()) { |
|
| 39 | + if ( ! $this->minimumWordPressVersionRequired()) { |
|
| 40 | 40 | $this->request->unSetRequestParam('activate', true); |
| 41 | 41 | add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
| 42 | 42 | $this->response->terminateRequest(); |
| 43 | 43 | $this->response->deactivatePlugin(); |
| 44 | 44 | } |
| 45 | 45 | // check recommended PHP version |
| 46 | - if (! $this->minimumPhpVersionRecommended()) { |
|
| 46 | + if ( ! $this->minimumPhpVersionRecommended()) { |
|
| 47 | 47 | $this->displayMinimumRecommendedPhpVersionNotice(); |
| 48 | 48 | } |
| 49 | 49 | //upcoming required version |
| 50 | - if (! $this->upcomingRequiredPhpVersion()) { |
|
| 50 | + if ( ! $this->upcomingRequiredPhpVersion()) { |
|
| 51 | 51 | $this->displayUpcomingRequiredVersion(); |
| 52 | 52 | } |
| 53 | 53 | $this->response = $this->processRequestStack($this->request, $this->response); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | { |
| 150 | 150 | if ($this->request->isAdmin()) { |
| 151 | 151 | new PersistentAdminNotice( |
| 152 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
| 152 | + 'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended', |
|
| 153 | 153 | sprintf( |
| 154 | 154 | esc_html__( |
| 155 | 155 | 'Event Espresso recommends PHP version %1$s or greater for optimal performance. 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.', |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request) |
| 187 | 187 | && current_user_can('update_plugins') |
| 188 | 188 | ) { |
| 189 | - add_action('admin_notices', function () |
|
| 189 | + add_action('admin_notices', function() |
|
| 190 | 190 | { |
| 191 | 191 | echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
| 192 | 192 | . sprintf( |
@@ -21,77 +21,77 @@ |
||
| 21 | 21 | { |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @deprecated |
|
| 26 | - * @param EE_Request $request |
|
| 27 | - * @param EE_Response $response |
|
| 28 | - * @return EE_Response |
|
| 29 | - */ |
|
| 30 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
| 31 | - { |
|
| 32 | - EE_Error::doing_it_wrong( |
|
| 33 | - __METHOD__, |
|
| 34 | - sprintf( |
|
| 35 | - esc_html__( |
|
| 36 | - 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 37 | - 'event_espresso' |
|
| 38 | - ), |
|
| 39 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions', |
|
| 40 | - '\core\services\request', |
|
| 41 | - 'EventEspresso\core\services\request' |
|
| 42 | - ), |
|
| 43 | - '4.9.52' |
|
| 44 | - ); |
|
| 45 | - return $response; |
|
| 46 | - } |
|
| 24 | + /** |
|
| 25 | + * @deprecated |
|
| 26 | + * @param EE_Request $request |
|
| 27 | + * @param EE_Response $response |
|
| 28 | + * @return EE_Response |
|
| 29 | + */ |
|
| 30 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
| 31 | + { |
|
| 32 | + EE_Error::doing_it_wrong( |
|
| 33 | + __METHOD__, |
|
| 34 | + sprintf( |
|
| 35 | + esc_html__( |
|
| 36 | + 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 37 | + 'event_espresso' |
|
| 38 | + ), |
|
| 39 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions', |
|
| 40 | + '\core\services\request', |
|
| 41 | + 'EventEspresso\core\services\request' |
|
| 42 | + ), |
|
| 43 | + '4.9.52' |
|
| 44 | + ); |
|
| 45 | + return $response; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @deprecated |
|
| 51 | - * @param string $version_to_check |
|
| 52 | - * @param string $operator |
|
| 53 | - * @return bool |
|
| 54 | - */ |
|
| 55 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
| 56 | - { |
|
| 57 | - EE_Error::doing_it_wrong( |
|
| 58 | - __METHOD__, |
|
| 59 | - sprintf( |
|
| 60 | - esc_html__( |
|
| 61 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 62 | - 'event_espresso' |
|
| 63 | - ), |
|
| 64 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions::compareWordPressVersion()', |
|
| 65 | - '\core\services\request', |
|
| 66 | - 'EventEspresso\core\services\request' |
|
| 67 | - ), |
|
| 68 | - '4.9.52', |
|
| 69 | - '5.0.0' |
|
| 70 | - ); |
|
| 71 | - return RecommendedVersions::compareWordPressVersion($version_to_check, $operator); |
|
| 72 | - } |
|
| 49 | + /** |
|
| 50 | + * @deprecated |
|
| 51 | + * @param string $version_to_check |
|
| 52 | + * @param string $operator |
|
| 53 | + * @return bool |
|
| 54 | + */ |
|
| 55 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
| 56 | + { |
|
| 57 | + EE_Error::doing_it_wrong( |
|
| 58 | + __METHOD__, |
|
| 59 | + sprintf( |
|
| 60 | + esc_html__( |
|
| 61 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 62 | + 'event_espresso' |
|
| 63 | + ), |
|
| 64 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions::compareWordPressVersion()', |
|
| 65 | + '\core\services\request', |
|
| 66 | + 'EventEspresso\core\services\request' |
|
| 67 | + ), |
|
| 68 | + '4.9.52', |
|
| 69 | + '5.0.0' |
|
| 70 | + ); |
|
| 71 | + return RecommendedVersions::compareWordPressVersion($version_to_check, $operator); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @deprecated |
|
| 78 | - * @return void |
|
| 79 | - */ |
|
| 80 | - public function minimum_wp_version_error() |
|
| 81 | - { |
|
| 82 | - EE_Error::doing_it_wrong( |
|
| 83 | - __METHOD__, |
|
| 84 | - sprintf( |
|
| 85 | - esc_html__( |
|
| 86 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 87 | - 'event_espresso' |
|
| 88 | - ), |
|
| 89 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions::minimumWpVersionError()', |
|
| 90 | - '\core\services\request', |
|
| 91 | - 'EventEspresso\core\services\request' |
|
| 92 | - ), |
|
| 93 | - '4.9.52' |
|
| 94 | - ); |
|
| 95 | - } |
|
| 76 | + /** |
|
| 77 | + * @deprecated |
|
| 78 | + * @return void |
|
| 79 | + */ |
|
| 80 | + public function minimum_wp_version_error() |
|
| 81 | + { |
|
| 82 | + EE_Error::doing_it_wrong( |
|
| 83 | + __METHOD__, |
|
| 84 | + sprintf( |
|
| 85 | + esc_html__( |
|
| 86 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 87 | + 'event_espresso' |
|
| 88 | + ), |
|
| 89 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions::minimumWpVersionError()', |
|
| 90 | + '\core\services\request', |
|
| 91 | + 'EventEspresso\core\services\request' |
|
| 92 | + ), |
|
| 93 | + '4.9.52' |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | } |
@@ -647,15 +647,15 @@ |
||
| 647 | 647 | |
| 648 | 648 | if ( $send ) { |
| 649 | 649 | //are we overriding any existing template fields? |
| 650 | - $settings = apply_filters( |
|
| 651 | - 'FHEE__EE_messenger__get_preview__messenger_test_settings', |
|
| 652 | - $this->get_existing_test_settings(), |
|
| 653 | - $this, |
|
| 654 | - $send, |
|
| 655 | - $message, |
|
| 656 | - $message_type |
|
| 657 | - ); |
|
| 658 | - if ( ! empty( $settings ) ) { |
|
| 650 | + $settings = apply_filters( |
|
| 651 | + 'FHEE__EE_messenger__get_preview__messenger_test_settings', |
|
| 652 | + $this->get_existing_test_settings(), |
|
| 653 | + $this, |
|
| 654 | + $send, |
|
| 655 | + $message, |
|
| 656 | + $message_type |
|
| 657 | + ); |
|
| 658 | + if ( ! empty( $settings ) ) { |
|
| 659 | 659 | foreach ( $settings as $field => $value ) { |
| 660 | 660 | $this->_set_template_value( $field, $value ); |
| 661 | 661 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | use \EventEspresso\core\exceptions\SendMessageException; |
| 3 | 3 | |
| 4 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 5 | 5 | exit('NO direct script access allowed'); |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @return void |
| 280 | 280 | */ |
| 281 | 281 | public function enqueue_scripts_styles() { |
| 282 | - do_action( 'AHEE__EE_messenger__enqueue_scripts_styles'); |
|
| 282 | + do_action('AHEE__EE_messenger__enqueue_scripts_styles'); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | $this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure. Usually these affect things like font style, color, borders etc. In some cases the styles will also make minor layout changes.'); |
| 351 | 351 | |
| 352 | - $this->_supports_labels = apply_filters( 'FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this ); |
|
| 352 | + $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
@@ -364,10 +364,10 @@ discard block |
||
| 364 | 364 | * @return stdClass |
| 365 | 365 | */ |
| 366 | 366 | public function get_supports_labels() { |
| 367 | - if ( empty( $this->_supports_labels->template_pack ) || empty( $this->_supports_labels->template_variation) ) { |
|
| 367 | + if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) { |
|
| 368 | 368 | $this->_set_supports_labels_defaults(); |
| 369 | 369 | } |
| 370 | - return apply_filters( 'FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this ); |
|
| 370 | + return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | |
@@ -387,10 +387,10 @@ discard block |
||
| 387 | 387 | * |
| 388 | 388 | * @return string path or url for the requested variation. |
| 389 | 389 | */ |
| 390 | - public function get_variation( EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE ) { |
|
| 390 | + public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE) { |
|
| 391 | 391 | $this->_tmp_pack = $pack; |
| 392 | - $variation_path = apply_filters( 'EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters ); |
|
| 393 | - $variation_path = empty( $variation_path ) ? $this->_tmp_pack->get_variation( $this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters ) : $variation_path; |
|
| 392 | + $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters); |
|
| 393 | + $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path; |
|
| 394 | 394 | return $variation_path; |
| 395 | 395 | |
| 396 | 396 | } |
@@ -408,13 +408,13 @@ discard block |
||
| 408 | 408 | * @return array |
| 409 | 409 | */ |
| 410 | 410 | public function get_default_message_types() { |
| 411 | - $class = get_class( $this ); |
|
| 411 | + $class = get_class($this); |
|
| 412 | 412 | |
| 413 | 413 | //messenger specific filter |
| 414 | - $default_types = apply_filters( 'FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this ); |
|
| 414 | + $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this); |
|
| 415 | 415 | |
| 416 | 416 | //all messengers filter |
| 417 | - $default_types = apply_filters( 'FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this ); |
|
| 417 | + $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); |
|
| 418 | 418 | return $default_types; |
| 419 | 419 | } |
| 420 | 420 | |
@@ -429,14 +429,14 @@ discard block |
||
| 429 | 429 | * @return array |
| 430 | 430 | */ |
| 431 | 431 | public function get_valid_message_types() { |
| 432 | - $class = get_class( $this ); |
|
| 432 | + $class = get_class($this); |
|
| 433 | 433 | |
| 434 | 434 | //messenger specific filter |
| 435 | 435 | //messenger specific filter |
| 436 | - $valid_types = apply_filters( 'FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this ); |
|
| 436 | + $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this); |
|
| 437 | 437 | |
| 438 | 438 | //all messengers filter |
| 439 | - $valid_types = apply_filters( 'FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this ); |
|
| 439 | + $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); |
|
| 440 | 440 | return $valid_types; |
| 441 | 441 | } |
| 442 | 442 | |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | * @access public |
| 451 | 451 | * @param array $new_config Whatever is put in here will reset the _validator_config property |
| 452 | 452 | */ |
| 453 | - public function set_validator_config( $new_config ) { |
|
| 453 | + public function set_validator_config($new_config) { |
|
| 454 | 454 | $this->_validator_config = $new_config; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -466,8 +466,8 @@ discard block |
||
| 466 | 466 | public function get_validator_config() { |
| 467 | 467 | $class = get_class($this); |
| 468 | 468 | |
| 469 | - $config = apply_filters( 'FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this ); |
|
| 470 | - $config = apply_filters( 'FHEE__EE_messenger__get_validator_config', $config, $this ); |
|
| 469 | + $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this); |
|
| 470 | + $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); |
|
| 471 | 471 | return $config; |
| 472 | 472 | } |
| 473 | 473 | |
@@ -484,8 +484,8 @@ discard block |
||
| 484 | 484 | * @access public |
| 485 | 485 | * @return string content for page |
| 486 | 486 | */ |
| 487 | - public function get_messenger_admin_page_content( $page, $action = null, $extra = array(), $message_types = array() ) { |
|
| 488 | - return $this->_get_admin_page_content( $page, $action, $extra, $message_types ); |
|
| 487 | + public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array()) { |
|
| 488 | + return $this->_get_admin_page_content($page, $action, $extra, $message_types); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -495,20 +495,20 @@ discard block |
||
| 495 | 495 | * @param array $extra |
| 496 | 496 | * @return mixed|string |
| 497 | 497 | */ |
| 498 | - protected function _get_admin_content_events_edit( $message_types, $extra ) { |
|
| 498 | + protected function _get_admin_content_events_edit($message_types, $extra) { |
|
| 499 | 499 | //defaults |
| 500 | 500 | $template_args = array(); |
| 501 | 501 | $selector_rows = ''; |
| 502 | 502 | |
| 503 | 503 | //we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event. |
| 504 | - $event_id = isset( $extra['event'] ) ? $extra['event'] : NULL; |
|
| 504 | + $event_id = isset($extra['event']) ? $extra['event'] : NULL; |
|
| 505 | 505 | |
| 506 | - $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
| 507 | - $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
| 506 | + $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
| 507 | + $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
| 508 | 508 | |
| 509 | 509 | //array of template objects for global and custom (non-trashed) (but remember just for this messenger!) |
| 510 | 510 | $global_templates = EEM_Message_Template_Group::instance()->get_all( |
| 511 | - array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) ) |
|
| 511 | + array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true)) |
|
| 512 | 512 | ); |
| 513 | 513 | $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event( |
| 514 | 514 | $event_id, |
@@ -517,55 +517,55 @@ discard block |
||
| 517 | 517 | 'MTP_is_active' => true |
| 518 | 518 | ) |
| 519 | 519 | ); |
| 520 | - $templates_for_event = !empty( $templates_for_event ) ? $templates_for_event : array(); |
|
| 520 | + $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array(); |
|
| 521 | 521 | |
| 522 | 522 | //so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups) |
| 523 | - foreach ( $global_templates as $mtpgID => $mtpg ) { |
|
| 524 | - if ( $mtpg instanceof EE_Message_Template_Group ) { |
|
| 523 | + foreach ($global_templates as $mtpgID => $mtpg) { |
|
| 524 | + if ($mtpg instanceof EE_Message_Template_Group) { |
|
| 525 | 525 | //verify this message type is supposed to show on this page |
| 526 | 526 | $mtp_obj = $mtpg->message_type_obj(); |
| 527 | - if ( ! $mtp_obj instanceof EE_message_type ) { |
|
| 527 | + if ( ! $mtp_obj instanceof EE_message_type) { |
|
| 528 | 528 | continue; |
| 529 | 529 | } |
| 530 | - $mtp_obj->admin_registered_pages = (array)$mtp_obj->admin_registered_pages; |
|
| 531 | - if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) ) { |
|
| 530 | + $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages; |
|
| 531 | + if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) { |
|
| 532 | 532 | continue; |
| 533 | 533 | } |
| 534 | 534 | $select_values = array(); |
| 535 | - $select_values[ $mtpgID ] = __( 'Global', 'event_espresso' ); |
|
| 536 | - $default_value = array_key_exists( $mtpgID, $templates_for_event ) && ! $mtpg->get( 'MTP_is_override' ) ? $mtpgID : null; |
|
| 535 | + $select_values[$mtpgID] = __('Global', 'event_espresso'); |
|
| 536 | + $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null; |
|
| 537 | 537 | //if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override. |
| 538 | - if ( ! $mtpg->get( 'MTP_is_override' ) ) { |
|
| 538 | + if ( ! $mtpg->get('MTP_is_override')) { |
|
| 539 | 539 | //any custom templates for this message type? |
| 540 | - $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt( $this->name, $mtpg->message_type() ); |
|
| 541 | - foreach ( $custom_templates as $cmtpgID => $cmtpg ) { |
|
| 542 | - $select_values[ $cmtpgID ] = $cmtpg->name(); |
|
| 543 | - $default_value = array_key_exists( $cmtpgID, $templates_for_event ) ? $cmtpgID : $default_value; |
|
| 540 | + $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type()); |
|
| 541 | + foreach ($custom_templates as $cmtpgID => $cmtpg) { |
|
| 542 | + $select_values[$cmtpgID] = $cmtpg->name(); |
|
| 543 | + $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value; |
|
| 544 | 544 | } |
| 545 | 545 | } |
| 546 | 546 | //if there is no $default_value then we set it as the global |
| 547 | - $default_value = empty( $default_value ) ? $mtpgID : $default_value; |
|
| 548 | - $edit_url = EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url( 'admin.php' ) ); |
|
| 549 | - $create_url = EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url( 'admin.php' ) ); |
|
| 550 | - $st_args[ 'mt_name' ] = ucwords( $mtp_obj->label[ 'singular' ] ); |
|
| 551 | - $st_args[ 'mt_slug' ] = $mtpg->message_type(); |
|
| 552 | - $st_args[ 'messenger_slug' ] = $this->name; |
|
| 553 | - $st_args[ 'selector' ] = EEH_Form_Fields::select_input( 'event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector' ); |
|
| 547 | + $default_value = empty($default_value) ? $mtpgID : $default_value; |
|
| 548 | + $edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php')); |
|
| 549 | + $create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value), admin_url('admin.php')); |
|
| 550 | + $st_args['mt_name'] = ucwords($mtp_obj->label['singular']); |
|
| 551 | + $st_args['mt_slug'] = $mtpg->message_type(); |
|
| 552 | + $st_args['messenger_slug'] = $this->name; |
|
| 553 | + $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector'); |
|
| 554 | 554 | //note that message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates). |
| 555 | - $st_args[ 'create_button' ] = $mtpg->get( 'MTP_is_override' ) ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __( 'Create New Custom', 'event_espresso' ) . '</a>'; |
|
| 556 | - $st_args[ 'create_button' ] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_messages', 'espresso_messages_add_new_message_template' ) ? $st_args[ 'create_button' ] : ''; |
|
| 557 | - $st_args[ 'edit_button' ] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID ) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __( 'Edit', 'event_espresso' ) . '</a>' : ''; |
|
| 558 | - $selector_rows .= EEH_Template::display_template( $template_row_path, $st_args, true ); |
|
| 555 | + $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>'; |
|
| 556 | + $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : ''; |
|
| 557 | + $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : ''; |
|
| 558 | + $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true); |
|
| 559 | 559 | } |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | //if no selectors present then get out. |
| 563 | - if ( empty( $selector_rows ) ) { |
|
| 563 | + if (empty($selector_rows)) { |
|
| 564 | 564 | return ''; |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | $template_args['selector_rows'] = $selector_rows; |
| 568 | - return EEH_Template::display_template( $template_wrapper_path, $template_args, TRUE ); |
|
| 568 | + return EEH_Template::display_template($template_wrapper_path, $template_args, TRUE); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | * @return array $this->_template_fields |
| 581 | 581 | */ |
| 582 | 582 | public function get_template_fields() { |
| 583 | - $template_fields = apply_filters( 'FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this ); |
|
| 584 | - $template_fields = apply_filters( 'FHEE__EE_messenger__get_template_fields', $template_fields, $this ); |
|
| 583 | + $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this); |
|
| 584 | + $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this); |
|
| 585 | 585 | return $template_fields; |
| 586 | 586 | } |
| 587 | 587 | |
@@ -595,9 +595,9 @@ discard block |
||
| 595 | 595 | * @param mixed $value |
| 596 | 596 | */ |
| 597 | 597 | protected function _set_template_value($item, $value) { |
| 598 | - if ( array_key_exists($item, $this->_template_fields) ) { |
|
| 599 | - $prop = '_' . $item; |
|
| 600 | - $this->{$prop}= $value; |
|
| 598 | + if (array_key_exists($item, $this->_template_fields)) { |
|
| 599 | + $prop = '_'.$item; |
|
| 600 | + $this->{$prop} = $value; |
|
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | |
@@ -615,18 +615,18 @@ discard block |
||
| 615 | 615 | * |
| 616 | 616 | * @throws SendMessageException |
| 617 | 617 | */ |
| 618 | - final public function send_message( $message, EE_message_type $message_type ) { |
|
| 618 | + final public function send_message($message, EE_message_type $message_type) { |
|
| 619 | 619 | try { |
| 620 | - $this->_validate_and_setup( $message ); |
|
| 620 | + $this->_validate_and_setup($message); |
|
| 621 | 621 | $this->_incoming_message_type = $message_type; |
| 622 | 622 | $response = $this->_send_message(); |
| 623 | - if ( $response instanceof WP_Error ) { |
|
| 624 | - EE_Error::add_error( $response->get_error_message(), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 623 | + if ($response instanceof WP_Error) { |
|
| 624 | + EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
| 625 | 625 | $response = false; |
| 626 | 626 | } |
| 627 | - } catch ( \Exception $e ) { |
|
| 627 | + } catch (\Exception $e) { |
|
| 628 | 628 | //convert to an instance of SendMessageException |
| 629 | - throw new SendMessageException( $e->getMessage() ); |
|
| 629 | + throw new SendMessageException($e->getMessage()); |
|
| 630 | 630 | } |
| 631 | 631 | return $response; |
| 632 | 632 | } |
@@ -640,12 +640,12 @@ discard block |
||
| 640 | 640 | * @param bool $send true we will actually use the _send method (for test sends). FALSE we just return preview |
| 641 | 641 | * @return string return the message html content |
| 642 | 642 | */ |
| 643 | - public function get_preview( EE_Message $message, EE_message_type $message_type, $send = false ) { |
|
| 644 | - $this->_validate_and_setup( $message ); |
|
| 643 | + public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false) { |
|
| 644 | + $this->_validate_and_setup($message); |
|
| 645 | 645 | |
| 646 | 646 | $this->_incoming_message_type = $message_type; |
| 647 | 647 | |
| 648 | - if ( $send ) { |
|
| 648 | + if ($send) { |
|
| 649 | 649 | //are we overriding any existing template fields? |
| 650 | 650 | $settings = apply_filters( |
| 651 | 651 | 'FHEE__EE_messenger__get_preview__messenger_test_settings', |
@@ -655,20 +655,20 @@ discard block |
||
| 655 | 655 | $message, |
| 656 | 656 | $message_type |
| 657 | 657 | ); |
| 658 | - if ( ! empty( $settings ) ) { |
|
| 659 | - foreach ( $settings as $field => $value ) { |
|
| 660 | - $this->_set_template_value( $field, $value ); |
|
| 658 | + if ( ! empty($settings)) { |
|
| 659 | + foreach ($settings as $field => $value) { |
|
| 660 | + $this->_set_template_value($field, $value); |
|
| 661 | 661 | } |
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | //enqueue preview js so that any links/buttons on the page are disabled. |
| 666 | - if ( ! $send ) { |
|
| 666 | + if ( ! $send) { |
|
| 667 | 667 | // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles, |
| 668 | 668 | // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup. |
| 669 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10 ); |
|
| 670 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10 ); |
|
| 671 | - add_action( 'AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10 ); |
|
| 669 | + add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10); |
|
| 670 | + add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10); |
|
| 671 | + add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | return $send ? $this->_send_message() : $this->_preview(); |
@@ -686,10 +686,10 @@ discard block |
||
| 686 | 686 | */ |
| 687 | 687 | public function add_preview_script() { |
| 688 | 688 | //error message |
| 689 | - EE_Registry::$i18n_js_strings[ 'links_disabled' ] = __( 'All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup. To test generated links, you must trigger an actual message notification.', 'event_espresso' ); |
|
| 690 | - wp_register_script( 'ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true ); |
|
| 691 | - wp_localize_script( 'ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings ); |
|
| 692 | - wp_enqueue_script( 'ee-messages-preview-js' ); |
|
| 689 | + EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup. To test generated links, you must trigger an actual message notification.', 'event_espresso'); |
|
| 690 | + wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 691 | + wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 692 | + wp_enqueue_script('ee-messages-preview-js'); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | |
@@ -700,13 +700,13 @@ discard block |
||
| 700 | 700 | * @param EE_Message $message |
| 701 | 701 | * @throws EE_Error |
| 702 | 702 | */ |
| 703 | - protected function _validate_and_setup( EE_Message $message ) { |
|
| 703 | + protected function _validate_and_setup(EE_Message $message) { |
|
| 704 | 704 | $template_pack = $message->get_template_pack(); |
| 705 | 705 | $variation = $message->get_template_pack_variation(); |
| 706 | 706 | |
| 707 | 707 | //verify we have the required template pack value on the $message object. |
| 708 | - if ( ! $template_pack instanceof EE_Messages_Template_Pack ) { |
|
| 709 | - throw new EE_Error( __('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso' ) ); |
|
| 708 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack) { |
|
| 709 | + throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso')); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | $this->_tmp_pack = $template_pack; |
@@ -715,11 +715,11 @@ discard block |
||
| 715 | 715 | |
| 716 | 716 | $template_fields = $this->get_template_fields(); |
| 717 | 717 | |
| 718 | - foreach ( $template_fields as $template => $value ) { |
|
| 719 | - if ( $template !== 'extra' ) { |
|
| 720 | - $column_value = $message->get_field_or_extra_meta( 'MSG_' . $template ); |
|
| 718 | + foreach ($template_fields as $template => $value) { |
|
| 719 | + if ($template !== 'extra') { |
|
| 720 | + $column_value = $message->get_field_or_extra_meta('MSG_'.$template); |
|
| 721 | 721 | $message_template_value = $column_value ? $column_value : null; |
| 722 | - $this->_set_template_value( $template, $message_template_value ); |
|
| 722 | + $this->_set_template_value($template, $message_template_value); |
|
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | } |
@@ -734,19 +734,19 @@ discard block |
||
| 734 | 734 | * @return string |
| 735 | 735 | * @throws \EE_Error |
| 736 | 736 | */ |
| 737 | - protected function _get_main_template( $preview = FALSE ) { |
|
| 737 | + protected function _get_main_template($preview = FALSE) { |
|
| 738 | 738 | $type = $preview ? 'preview' : 'main'; |
| 739 | 739 | |
| 740 | - $wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type ); |
|
| 740 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type); |
|
| 741 | 741 | |
| 742 | 742 | //check file exists and is readable |
| 743 | - if ( !is_readable( $wrapper_template ) ) |
|
| 744 | - throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) ); |
|
| 743 | + if ( ! is_readable($wrapper_template)) |
|
| 744 | + throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template)); |
|
| 745 | 745 | |
| 746 | 746 | //add message type to template args |
| 747 | 747 | $this->_template_args['message_type'] = $this->_incoming_message_type; |
| 748 | 748 | |
| 749 | - return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE ); |
|
| 749 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | |
@@ -782,9 +782,9 @@ discard block |
||
| 782 | 782 | */ |
| 783 | 783 | public function get_existing_test_settings() { |
| 784 | 784 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
| 785 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 785 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 786 | 786 | $settings = $Message_Resource_Manager->get_active_messengers_option(); |
| 787 | - return isset( $settings[ $this->name ]['test_settings'] ) ? $settings[ $this->name ]['test_settings'] : array(); |
|
| 787 | + return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array(); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | |
@@ -796,12 +796,12 @@ discard block |
||
| 796 | 796 | * @param $settings |
| 797 | 797 | * @return bool success/fail |
| 798 | 798 | */ |
| 799 | - public function set_existing_test_settings( $settings ) { |
|
| 799 | + public function set_existing_test_settings($settings) { |
|
| 800 | 800 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
| 801 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 801 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 802 | 802 | $existing = $Message_Resource_Manager->get_active_messengers_option(); |
| 803 | - $existing[ $this->name ]['test_settings'] = $settings; |
|
| 804 | - return $Message_Resource_Manager->update_active_messengers_option( $existing ); |
|
| 803 | + $existing[$this->name]['test_settings'] = $settings; |
|
| 804 | + return $Message_Resource_Manager->update_active_messengers_option($existing); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | |
@@ -814,21 +814,21 @@ discard block |
||
| 814 | 814 | * @param string $field The field to retrieve the label for |
| 815 | 815 | * @return string The label |
| 816 | 816 | */ |
| 817 | - public function get_field_label( $field ) { |
|
| 817 | + public function get_field_label($field) { |
|
| 818 | 818 | //first let's see if the field requests is in the top level array. |
| 819 | - if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) |
|
| 819 | + if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) |
|
| 820 | 820 | return $this->_template[$field]['label']; |
| 821 | 821 | |
| 822 | 822 | //nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index. |
| 823 | - if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] ) ) |
|
| 823 | + if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) |
|
| 824 | 824 | return $this->_template_fields['extra'][$field]['main']['label']; |
| 825 | 825 | |
| 826 | 826 | //now it's possible this field may just be existing in any of the extra array items. |
| 827 | - if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) { |
|
| 828 | - foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) { |
|
| 829 | - if ( !is_array( $subfields ) ) |
|
| 827 | + if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { |
|
| 828 | + foreach ($this->_template_fields['extra'] as $main_field => $subfields) { |
|
| 829 | + if ( ! is_array($subfields)) |
|
| 830 | 830 | continue; |
| 831 | - if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) |
|
| 831 | + if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) |
|
| 832 | 832 | return $subfields[$field]['label']; |
| 833 | 833 | } |
| 834 | 834 | } |
@@ -849,7 +849,7 @@ discard block |
||
| 849 | 849 | * |
| 850 | 850 | * @return void |
| 851 | 851 | */ |
| 852 | - public function do_secondary_messenger_hooks( $sending_messenger_name ) { |
|
| 852 | + public function do_secondary_messenger_hooks($sending_messenger_name) { |
|
| 853 | 853 | return; |
| 854 | 854 | } |
| 855 | 855 | |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('NO direct script access allowed'); |
|
| 8 | + exit('NO direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /** |
@@ -23,2554 +23,2554 @@ discard block |
||
| 23 | 23 | class Messages_Admin_Page extends EE_Admin_Page |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | - */ |
|
| 29 | - protected $_message_resource_manager; |
|
| 26 | + /** |
|
| 27 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | + */ |
|
| 29 | + protected $_message_resource_manager; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @type string $_active_message_type_name |
|
| 33 | - */ |
|
| 34 | - protected $_active_message_type_name = ''; |
|
| 31 | + /** |
|
| 32 | + * @type string $_active_message_type_name |
|
| 33 | + */ |
|
| 34 | + protected $_active_message_type_name = ''; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @type EE_messenger $_active_messenger |
|
| 38 | - */ |
|
| 39 | - protected $_active_messenger; |
|
| 40 | - protected $_activate_state; |
|
| 41 | - protected $_activate_meta_box_type; |
|
| 42 | - protected $_current_message_meta_box; |
|
| 43 | - protected $_current_message_meta_box_object; |
|
| 44 | - protected $_context_switcher; |
|
| 45 | - protected $_shortcodes = array(); |
|
| 46 | - protected $_active_messengers = array(); |
|
| 47 | - protected $_active_message_types = array(); |
|
| 36 | + /** |
|
| 37 | + * @type EE_messenger $_active_messenger |
|
| 38 | + */ |
|
| 39 | + protected $_active_messenger; |
|
| 40 | + protected $_activate_state; |
|
| 41 | + protected $_activate_meta_box_type; |
|
| 42 | + protected $_current_message_meta_box; |
|
| 43 | + protected $_current_message_meta_box_object; |
|
| 44 | + protected $_context_switcher; |
|
| 45 | + protected $_shortcodes = array(); |
|
| 46 | + protected $_active_messengers = array(); |
|
| 47 | + protected $_active_message_types = array(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | - */ |
|
| 52 | - protected $_message_template_group; |
|
| 53 | - protected $_m_mt_settings = array(); |
|
| 49 | + /** |
|
| 50 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | + */ |
|
| 52 | + protected $_message_template_group; |
|
| 53 | + protected $_m_mt_settings = array(); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | - * |
|
| 60 | - * @since 4.5.0 |
|
| 61 | - * |
|
| 62 | - * @var EE_Messages_Template_Pack |
|
| 63 | - */ |
|
| 64 | - protected $_template_pack; |
|
| 56 | + /** |
|
| 57 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | + * |
|
| 60 | + * @since 4.5.0 |
|
| 61 | + * |
|
| 62 | + * @var EE_Messages_Template_Pack |
|
| 63 | + */ |
|
| 64 | + protected $_template_pack; |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | - * group is. If there is no group then it automatically gets set to default. |
|
| 70 | - * |
|
| 71 | - * @since 4.5.0 |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - protected $_variation; |
|
| 67 | + /** |
|
| 68 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | + * group is. If there is no group then it automatically gets set to default. |
|
| 70 | + * |
|
| 71 | + * @since 4.5.0 |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + protected $_variation; |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param bool $routing |
|
| 80 | - * @throws EE_Error |
|
| 81 | - */ |
|
| 82 | - public function __construct($routing = true) |
|
| 83 | - { |
|
| 84 | - //make sure messages autoloader is running |
|
| 85 | - EED_Messages::set_autoloaders(); |
|
| 86 | - parent::__construct($routing); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * @param bool $routing |
|
| 80 | + * @throws EE_Error |
|
| 81 | + */ |
|
| 82 | + public function __construct($routing = true) |
|
| 83 | + { |
|
| 84 | + //make sure messages autoloader is running |
|
| 85 | + EED_Messages::set_autoloaders(); |
|
| 86 | + parent::__construct($routing); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - protected function _init_page_props() |
|
| 91 | - { |
|
| 92 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 93 | - $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 94 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 95 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 96 | - |
|
| 97 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 98 | - |
|
| 99 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 100 | - $this->_load_message_resource_manager(); |
|
| 101 | - } |
|
| 90 | + protected function _init_page_props() |
|
| 91 | + { |
|
| 92 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 93 | + $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 94 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 95 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 96 | + |
|
| 97 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 98 | + |
|
| 99 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 100 | + $this->_load_message_resource_manager(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 106 | - * |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws InvalidDataTypeException |
|
| 109 | - * @throws InvalidInterfaceException |
|
| 110 | - * @throws InvalidArgumentException |
|
| 111 | - * @throws ReflectionException |
|
| 112 | - */ |
|
| 113 | - protected function _load_message_resource_manager() |
|
| 114 | - { |
|
| 115 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 116 | - } |
|
| 104 | + /** |
|
| 105 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 106 | + * |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws InvalidDataTypeException |
|
| 109 | + * @throws InvalidInterfaceException |
|
| 110 | + * @throws InvalidArgumentException |
|
| 111 | + * @throws ReflectionException |
|
| 112 | + */ |
|
| 113 | + protected function _load_message_resource_manager() |
|
| 114 | + { |
|
| 115 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * @deprecated 4.9.9.rc.014 |
|
| 121 | - * @return array |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws InvalidArgumentException |
|
| 124 | - * @throws InvalidDataTypeException |
|
| 125 | - * @throws InvalidInterfaceException |
|
| 126 | - */ |
|
| 127 | - public function get_messengers_for_list_table() |
|
| 128 | - { |
|
| 129 | - EE_Error::doing_it_wrong( |
|
| 130 | - __METHOD__, |
|
| 131 | - sprintf( |
|
| 132 | - esc_html__( |
|
| 133 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 134 | - 'event_espresso' |
|
| 135 | - ), |
|
| 136 | - 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 137 | - ), |
|
| 138 | - '4.9.9.rc.014' |
|
| 139 | - ); |
|
| 140 | - |
|
| 141 | - $m_values = array(); |
|
| 142 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 143 | - //setup messengers for selects |
|
| 144 | - $i = 1; |
|
| 145 | - foreach ($active_messengers as $active_messenger) { |
|
| 146 | - if ($active_messenger instanceof EE_Message) { |
|
| 147 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 148 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 149 | - $i++; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $m_values; |
|
| 154 | - } |
|
| 119 | + /** |
|
| 120 | + * @deprecated 4.9.9.rc.014 |
|
| 121 | + * @return array |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws InvalidArgumentException |
|
| 124 | + * @throws InvalidDataTypeException |
|
| 125 | + * @throws InvalidInterfaceException |
|
| 126 | + */ |
|
| 127 | + public function get_messengers_for_list_table() |
|
| 128 | + { |
|
| 129 | + EE_Error::doing_it_wrong( |
|
| 130 | + __METHOD__, |
|
| 131 | + sprintf( |
|
| 132 | + esc_html__( |
|
| 133 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 134 | + 'event_espresso' |
|
| 135 | + ), |
|
| 136 | + 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 137 | + ), |
|
| 138 | + '4.9.9.rc.014' |
|
| 139 | + ); |
|
| 140 | + |
|
| 141 | + $m_values = array(); |
|
| 142 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 143 | + //setup messengers for selects |
|
| 144 | + $i = 1; |
|
| 145 | + foreach ($active_messengers as $active_messenger) { |
|
| 146 | + if ($active_messenger instanceof EE_Message) { |
|
| 147 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 148 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 149 | + $i++; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $m_values; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * @deprecated 4.9.9.rc.014 |
|
| 159 | - * @return array |
|
| 160 | - * @throws EE_Error |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - */ |
|
| 165 | - public function get_message_types_for_list_table() |
|
| 166 | - { |
|
| 167 | - EE_Error::doing_it_wrong( |
|
| 168 | - __METHOD__, |
|
| 169 | - sprintf( |
|
| 170 | - esc_html__( |
|
| 171 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 172 | - 'event_espresso' |
|
| 173 | - ), |
|
| 174 | - 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 175 | - ), |
|
| 176 | - '4.9.9.rc.014' |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - $mt_values = array(); |
|
| 180 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 181 | - $i = 1; |
|
| 182 | - foreach ($active_messages as $active_message) { |
|
| 183 | - if ($active_message instanceof EE_Message) { |
|
| 184 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 185 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 186 | - $i++; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $mt_values; |
|
| 191 | - } |
|
| 157 | + /** |
|
| 158 | + * @deprecated 4.9.9.rc.014 |
|
| 159 | + * @return array |
|
| 160 | + * @throws EE_Error |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + */ |
|
| 165 | + public function get_message_types_for_list_table() |
|
| 166 | + { |
|
| 167 | + EE_Error::doing_it_wrong( |
|
| 168 | + __METHOD__, |
|
| 169 | + sprintf( |
|
| 170 | + esc_html__( |
|
| 171 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 172 | + 'event_espresso' |
|
| 173 | + ), |
|
| 174 | + 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 175 | + ), |
|
| 176 | + '4.9.9.rc.014' |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + $mt_values = array(); |
|
| 180 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 181 | + $i = 1; |
|
| 182 | + foreach ($active_messages as $active_message) { |
|
| 183 | + if ($active_message instanceof EE_Message) { |
|
| 184 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 185 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 186 | + $i++; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return $mt_values; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * @deprecated 4.9.9.rc.014 |
|
| 196 | - * @return array |
|
| 197 | - * @throws EE_Error |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidDataTypeException |
|
| 200 | - * @throws InvalidInterfaceException |
|
| 201 | - */ |
|
| 202 | - public function get_contexts_for_message_types_for_list_table() |
|
| 203 | - { |
|
| 204 | - EE_Error::doing_it_wrong( |
|
| 205 | - __METHOD__, |
|
| 206 | - sprintf( |
|
| 207 | - esc_html__( |
|
| 208 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 209 | - 'event_espresso' |
|
| 210 | - ), |
|
| 211 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 212 | - ), |
|
| 213 | - '4.9.9.rc.014' |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - $contexts = array(); |
|
| 217 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 218 | - foreach ($active_message_contexts as $active_message) { |
|
| 219 | - if ($active_message instanceof EE_Message) { |
|
| 220 | - $message_type = $active_message->message_type_object(); |
|
| 221 | - if ($message_type instanceof EE_message_type) { |
|
| 222 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 223 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 224 | - $contexts[$context] = $context_details['label']; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $contexts; |
|
| 231 | - } |
|
| 194 | + /** |
|
| 195 | + * @deprecated 4.9.9.rc.014 |
|
| 196 | + * @return array |
|
| 197 | + * @throws EE_Error |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidDataTypeException |
|
| 200 | + * @throws InvalidInterfaceException |
|
| 201 | + */ |
|
| 202 | + public function get_contexts_for_message_types_for_list_table() |
|
| 203 | + { |
|
| 204 | + EE_Error::doing_it_wrong( |
|
| 205 | + __METHOD__, |
|
| 206 | + sprintf( |
|
| 207 | + esc_html__( |
|
| 208 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 209 | + 'event_espresso' |
|
| 210 | + ), |
|
| 211 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 212 | + ), |
|
| 213 | + '4.9.9.rc.014' |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + $contexts = array(); |
|
| 217 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 218 | + foreach ($active_message_contexts as $active_message) { |
|
| 219 | + if ($active_message instanceof EE_Message) { |
|
| 220 | + $message_type = $active_message->message_type_object(); |
|
| 221 | + if ($message_type instanceof EE_message_type) { |
|
| 222 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 223 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 224 | + $contexts[$context] = $context_details['label']; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $contexts; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Generate select input with provided messenger options array. |
|
| 236 | - * |
|
| 237 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 238 | - * labels. |
|
| 239 | - * @return string |
|
| 240 | - * @throws EE_Error |
|
| 241 | - */ |
|
| 242 | - public function get_messengers_select_input($messenger_options) |
|
| 243 | - { |
|
| 244 | - //if empty or just one value then just return an empty string |
|
| 245 | - if (empty($messenger_options) |
|
| 246 | - || ! is_array($messenger_options) |
|
| 247 | - || count($messenger_options) === 1 |
|
| 248 | - ) { |
|
| 249 | - return ''; |
|
| 250 | - } |
|
| 251 | - //merge in default |
|
| 252 | - $messenger_options = array_merge( |
|
| 253 | - array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 254 | - $messenger_options |
|
| 255 | - ); |
|
| 256 | - $input = new EE_Select_Input( |
|
| 257 | - $messenger_options, |
|
| 258 | - array( |
|
| 259 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 260 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 261 | - 'html_class' => 'wide', |
|
| 262 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 264 | - : 'none_selected' |
|
| 265 | - ) |
|
| 266 | - ); |
|
| 267 | - |
|
| 268 | - return $input->get_html_for_input(); |
|
| 269 | - } |
|
| 234 | + /** |
|
| 235 | + * Generate select input with provided messenger options array. |
|
| 236 | + * |
|
| 237 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 238 | + * labels. |
|
| 239 | + * @return string |
|
| 240 | + * @throws EE_Error |
|
| 241 | + */ |
|
| 242 | + public function get_messengers_select_input($messenger_options) |
|
| 243 | + { |
|
| 244 | + //if empty or just one value then just return an empty string |
|
| 245 | + if (empty($messenger_options) |
|
| 246 | + || ! is_array($messenger_options) |
|
| 247 | + || count($messenger_options) === 1 |
|
| 248 | + ) { |
|
| 249 | + return ''; |
|
| 250 | + } |
|
| 251 | + //merge in default |
|
| 252 | + $messenger_options = array_merge( |
|
| 253 | + array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 254 | + $messenger_options |
|
| 255 | + ); |
|
| 256 | + $input = new EE_Select_Input( |
|
| 257 | + $messenger_options, |
|
| 258 | + array( |
|
| 259 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 260 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 261 | + 'html_class' => 'wide', |
|
| 262 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 264 | + : 'none_selected' |
|
| 265 | + ) |
|
| 266 | + ); |
|
| 267 | + |
|
| 268 | + return $input->get_html_for_input(); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Generate select input with provided message type options array. |
|
| 274 | - * |
|
| 275 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 276 | - * message type labels |
|
| 277 | - * @return string |
|
| 278 | - * @throws EE_Error |
|
| 279 | - */ |
|
| 280 | - public function get_message_types_select_input($message_type_options) |
|
| 281 | - { |
|
| 282 | - //if empty or count of options is 1 then just return an empty string |
|
| 283 | - if (empty($message_type_options) |
|
| 284 | - || ! is_array($message_type_options) |
|
| 285 | - || count($message_type_options) === 1 |
|
| 286 | - ) { |
|
| 287 | - return ''; |
|
| 288 | - } |
|
| 289 | - //merge in default |
|
| 290 | - $message_type_options = array_merge( |
|
| 291 | - array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 292 | - $message_type_options |
|
| 293 | - ); |
|
| 294 | - $input = new EE_Select_Input( |
|
| 295 | - $message_type_options, |
|
| 296 | - array( |
|
| 297 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 298 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 299 | - 'html_class' => 'wide', |
|
| 300 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 302 | - : 'none_selected', |
|
| 303 | - ) |
|
| 304 | - ); |
|
| 305 | - |
|
| 306 | - return $input->get_html_for_input(); |
|
| 307 | - } |
|
| 272 | + /** |
|
| 273 | + * Generate select input with provided message type options array. |
|
| 274 | + * |
|
| 275 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 276 | + * message type labels |
|
| 277 | + * @return string |
|
| 278 | + * @throws EE_Error |
|
| 279 | + */ |
|
| 280 | + public function get_message_types_select_input($message_type_options) |
|
| 281 | + { |
|
| 282 | + //if empty or count of options is 1 then just return an empty string |
|
| 283 | + if (empty($message_type_options) |
|
| 284 | + || ! is_array($message_type_options) |
|
| 285 | + || count($message_type_options) === 1 |
|
| 286 | + ) { |
|
| 287 | + return ''; |
|
| 288 | + } |
|
| 289 | + //merge in default |
|
| 290 | + $message_type_options = array_merge( |
|
| 291 | + array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 292 | + $message_type_options |
|
| 293 | + ); |
|
| 294 | + $input = new EE_Select_Input( |
|
| 295 | + $message_type_options, |
|
| 296 | + array( |
|
| 297 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 298 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 299 | + 'html_class' => 'wide', |
|
| 300 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 302 | + : 'none_selected', |
|
| 303 | + ) |
|
| 304 | + ); |
|
| 305 | + |
|
| 306 | + return $input->get_html_for_input(); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * Generate select input with provide message type contexts array. |
|
| 312 | - * |
|
| 313 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 314 | - * context label. |
|
| 315 | - * @return string |
|
| 316 | - * @throws EE_Error |
|
| 317 | - */ |
|
| 318 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 319 | - { |
|
| 320 | - //if empty or count of options is one then just return empty string |
|
| 321 | - if (empty($context_options) |
|
| 322 | - || ! is_array($context_options) |
|
| 323 | - || count($context_options) === 1 |
|
| 324 | - ) { |
|
| 325 | - return ''; |
|
| 326 | - } |
|
| 327 | - //merge in default |
|
| 328 | - $context_options = array_merge( |
|
| 329 | - array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | - $context_options |
|
| 331 | - ); |
|
| 332 | - $input = new EE_Select_Input( |
|
| 333 | - $context_options, |
|
| 334 | - array( |
|
| 335 | - 'html_name' => 'ee_context_filter_by', |
|
| 336 | - 'html_id' => 'ee_context_filter_by', |
|
| 337 | - 'html_class' => 'wide', |
|
| 338 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | - : 'none_selected', |
|
| 341 | - ) |
|
| 342 | - ); |
|
| 343 | - |
|
| 344 | - return $input->get_html_for_input(); |
|
| 345 | - } |
|
| 310 | + /** |
|
| 311 | + * Generate select input with provide message type contexts array. |
|
| 312 | + * |
|
| 313 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 314 | + * context label. |
|
| 315 | + * @return string |
|
| 316 | + * @throws EE_Error |
|
| 317 | + */ |
|
| 318 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 319 | + { |
|
| 320 | + //if empty or count of options is one then just return empty string |
|
| 321 | + if (empty($context_options) |
|
| 322 | + || ! is_array($context_options) |
|
| 323 | + || count($context_options) === 1 |
|
| 324 | + ) { |
|
| 325 | + return ''; |
|
| 326 | + } |
|
| 327 | + //merge in default |
|
| 328 | + $context_options = array_merge( |
|
| 329 | + array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | + $context_options |
|
| 331 | + ); |
|
| 332 | + $input = new EE_Select_Input( |
|
| 333 | + $context_options, |
|
| 334 | + array( |
|
| 335 | + 'html_name' => 'ee_context_filter_by', |
|
| 336 | + 'html_id' => 'ee_context_filter_by', |
|
| 337 | + 'html_class' => 'wide', |
|
| 338 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | + : 'none_selected', |
|
| 341 | + ) |
|
| 342 | + ); |
|
| 343 | + |
|
| 344 | + return $input->get_html_for_input(); |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | 347 | |
| 348 | - protected function _ajax_hooks() |
|
| 349 | - { |
|
| 350 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | - add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | - } |
|
| 348 | + protected function _ajax_hooks() |
|
| 349 | + { |
|
| 350 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | + add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | 358 | |
| 359 | - protected function _define_page_props() |
|
| 360 | - { |
|
| 361 | - $this->_admin_page_title = $this->page_label; |
|
| 362 | - $this->_labels = array( |
|
| 363 | - 'buttons' => array( |
|
| 364 | - 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | - 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | - 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 367 | - ), |
|
| 368 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 369 | - ); |
|
| 370 | - } |
|
| 359 | + protected function _define_page_props() |
|
| 360 | + { |
|
| 361 | + $this->_admin_page_title = $this->page_label; |
|
| 362 | + $this->_labels = array( |
|
| 363 | + 'buttons' => array( |
|
| 364 | + 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | + 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | + 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 367 | + ), |
|
| 368 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 369 | + ); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | - * @access protected |
|
| 376 | - * @return void |
|
| 377 | - */ |
|
| 378 | - protected function _set_page_routes() |
|
| 379 | - { |
|
| 380 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 381 | - ? $this->_req_data['GRP_ID'] |
|
| 382 | - : 0; |
|
| 383 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 384 | - ? $this->_req_data['id'] |
|
| 385 | - : $grp_id; |
|
| 386 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 387 | - ? $this->_req_data['MSG_ID'] |
|
| 388 | - : 0; |
|
| 389 | - |
|
| 390 | - $this->_page_routes = array( |
|
| 391 | - 'default' => array( |
|
| 392 | - 'func' => '_message_queue_list_table', |
|
| 393 | - 'capability' => 'ee_read_global_messages' |
|
| 394 | - ), |
|
| 395 | - 'global_mtps' => array( |
|
| 396 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 397 | - 'capability' => 'ee_read_global_messages' |
|
| 398 | - ), |
|
| 399 | - 'custom_mtps' => array( |
|
| 400 | - 'func' => '_custom_mtps_preview', |
|
| 401 | - 'capability' => 'ee_read_messages' |
|
| 402 | - ), |
|
| 403 | - 'add_new_message_template' => array( |
|
| 404 | - 'func' => '_add_message_template', |
|
| 405 | - 'capability' => 'ee_edit_messages', |
|
| 406 | - 'noheader' => true |
|
| 407 | - ), |
|
| 408 | - 'edit_message_template' => array( |
|
| 409 | - 'func' => '_edit_message_template', |
|
| 410 | - 'capability' => 'ee_edit_message', |
|
| 411 | - 'obj_id' => $grp_id |
|
| 412 | - ), |
|
| 413 | - 'preview_message' => array( |
|
| 414 | - 'func' => '_preview_message', |
|
| 415 | - 'capability' => 'ee_read_message', |
|
| 416 | - 'obj_id' => $grp_id, |
|
| 417 | - 'noheader' => true, |
|
| 418 | - 'headers_sent_route' => 'display_preview_message' |
|
| 419 | - ), |
|
| 420 | - 'display_preview_message' => array( |
|
| 421 | - 'func' => '_display_preview_message', |
|
| 422 | - 'capability' => 'ee_read_message', |
|
| 423 | - 'obj_id' => $grp_id |
|
| 424 | - ), |
|
| 425 | - 'insert_message_template' => array( |
|
| 426 | - 'func' => '_insert_or_update_message_template', |
|
| 427 | - 'capability' => 'ee_edit_messages', |
|
| 428 | - 'args' => array('new_template' => true), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'update_message_template' => array( |
|
| 432 | - 'func' => '_insert_or_update_message_template', |
|
| 433 | - 'capability' => 'ee_edit_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'args' => array('new_template' => false), |
|
| 436 | - 'noheader' => true |
|
| 437 | - ), |
|
| 438 | - 'trash_message_template' => array( |
|
| 439 | - 'func' => '_trash_or_restore_message_template', |
|
| 440 | - 'capability' => 'ee_delete_message', |
|
| 441 | - 'obj_id' => $grp_id, |
|
| 442 | - 'args' => array('trash' => true, 'all' => true), |
|
| 443 | - 'noheader' => true |
|
| 444 | - ), |
|
| 445 | - 'trash_message_template_context' => array( |
|
| 446 | - 'func' => '_trash_or_restore_message_template', |
|
| 447 | - 'capability' => 'ee_delete_message', |
|
| 448 | - 'obj_id' => $grp_id, |
|
| 449 | - 'args' => array('trash' => true), |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'restore_message_template' => array( |
|
| 453 | - 'func' => '_trash_or_restore_message_template', |
|
| 454 | - 'capability' => 'ee_delete_message', |
|
| 455 | - 'obj_id' => $grp_id, |
|
| 456 | - 'args' => array('trash' => false, 'all' => true), |
|
| 457 | - 'noheader' => true |
|
| 458 | - ), |
|
| 459 | - 'restore_message_template_context' => array( |
|
| 460 | - 'func' => '_trash_or_restore_message_template', |
|
| 461 | - 'capability' => 'ee_delete_message', |
|
| 462 | - 'obj_id' => $grp_id, |
|
| 463 | - 'args' => array('trash' => false), |
|
| 464 | - 'noheader' => true |
|
| 465 | - ), |
|
| 466 | - 'delete_message_template' => array( |
|
| 467 | - 'func' => '_delete_message_template', |
|
| 468 | - 'capability' => 'ee_delete_message', |
|
| 469 | - 'obj_id' => $grp_id, |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'reset_to_default' => array( |
|
| 473 | - 'func' => '_reset_to_default_template', |
|
| 474 | - 'capability' => 'ee_edit_message', |
|
| 475 | - 'obj_id' => $grp_id, |
|
| 476 | - 'noheader' => true |
|
| 477 | - ), |
|
| 478 | - 'settings' => array( |
|
| 479 | - 'func' => '_settings', |
|
| 480 | - 'capability' => 'manage_options' |
|
| 481 | - ), |
|
| 482 | - 'update_global_settings' => array( |
|
| 483 | - 'func' => '_update_global_settings', |
|
| 484 | - 'capability' => 'manage_options', |
|
| 485 | - 'noheader' => true |
|
| 486 | - ), |
|
| 487 | - 'generate_now' => array( |
|
| 488 | - 'func' => '_generate_now', |
|
| 489 | - 'capability' => 'ee_send_message', |
|
| 490 | - 'noheader' => true |
|
| 491 | - ), |
|
| 492 | - 'generate_and_send_now' => array( |
|
| 493 | - 'func' => '_generate_and_send_now', |
|
| 494 | - 'capability' => 'ee_send_message', |
|
| 495 | - 'noheader' => true |
|
| 496 | - ), |
|
| 497 | - 'queue_for_resending' => array( |
|
| 498 | - 'func' => '_queue_for_resending', |
|
| 499 | - 'capability' => 'ee_send_message', |
|
| 500 | - 'noheader' => true |
|
| 501 | - ), |
|
| 502 | - 'send_now' => array( |
|
| 503 | - 'func' => '_send_now', |
|
| 504 | - 'capability' => 'ee_send_message', |
|
| 505 | - 'noheader' => true |
|
| 506 | - ), |
|
| 507 | - 'delete_ee_message' => array( |
|
| 508 | - 'func' => '_delete_ee_messages', |
|
| 509 | - 'capability' => 'ee_delete_messages', |
|
| 510 | - 'noheader' => true |
|
| 511 | - ), |
|
| 512 | - 'delete_ee_messages' => array( |
|
| 513 | - 'func' => '_delete_ee_messages', |
|
| 514 | - 'capability' => 'ee_delete_messages', |
|
| 515 | - 'noheader' => true, |
|
| 516 | - 'obj_id' => $msg_id |
|
| 517 | - ) |
|
| 518 | - ); |
|
| 519 | - } |
|
| 373 | + /** |
|
| 374 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | + * @access protected |
|
| 376 | + * @return void |
|
| 377 | + */ |
|
| 378 | + protected function _set_page_routes() |
|
| 379 | + { |
|
| 380 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 381 | + ? $this->_req_data['GRP_ID'] |
|
| 382 | + : 0; |
|
| 383 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 384 | + ? $this->_req_data['id'] |
|
| 385 | + : $grp_id; |
|
| 386 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 387 | + ? $this->_req_data['MSG_ID'] |
|
| 388 | + : 0; |
|
| 389 | + |
|
| 390 | + $this->_page_routes = array( |
|
| 391 | + 'default' => array( |
|
| 392 | + 'func' => '_message_queue_list_table', |
|
| 393 | + 'capability' => 'ee_read_global_messages' |
|
| 394 | + ), |
|
| 395 | + 'global_mtps' => array( |
|
| 396 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 397 | + 'capability' => 'ee_read_global_messages' |
|
| 398 | + ), |
|
| 399 | + 'custom_mtps' => array( |
|
| 400 | + 'func' => '_custom_mtps_preview', |
|
| 401 | + 'capability' => 'ee_read_messages' |
|
| 402 | + ), |
|
| 403 | + 'add_new_message_template' => array( |
|
| 404 | + 'func' => '_add_message_template', |
|
| 405 | + 'capability' => 'ee_edit_messages', |
|
| 406 | + 'noheader' => true |
|
| 407 | + ), |
|
| 408 | + 'edit_message_template' => array( |
|
| 409 | + 'func' => '_edit_message_template', |
|
| 410 | + 'capability' => 'ee_edit_message', |
|
| 411 | + 'obj_id' => $grp_id |
|
| 412 | + ), |
|
| 413 | + 'preview_message' => array( |
|
| 414 | + 'func' => '_preview_message', |
|
| 415 | + 'capability' => 'ee_read_message', |
|
| 416 | + 'obj_id' => $grp_id, |
|
| 417 | + 'noheader' => true, |
|
| 418 | + 'headers_sent_route' => 'display_preview_message' |
|
| 419 | + ), |
|
| 420 | + 'display_preview_message' => array( |
|
| 421 | + 'func' => '_display_preview_message', |
|
| 422 | + 'capability' => 'ee_read_message', |
|
| 423 | + 'obj_id' => $grp_id |
|
| 424 | + ), |
|
| 425 | + 'insert_message_template' => array( |
|
| 426 | + 'func' => '_insert_or_update_message_template', |
|
| 427 | + 'capability' => 'ee_edit_messages', |
|
| 428 | + 'args' => array('new_template' => true), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'update_message_template' => array( |
|
| 432 | + 'func' => '_insert_or_update_message_template', |
|
| 433 | + 'capability' => 'ee_edit_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'args' => array('new_template' => false), |
|
| 436 | + 'noheader' => true |
|
| 437 | + ), |
|
| 438 | + 'trash_message_template' => array( |
|
| 439 | + 'func' => '_trash_or_restore_message_template', |
|
| 440 | + 'capability' => 'ee_delete_message', |
|
| 441 | + 'obj_id' => $grp_id, |
|
| 442 | + 'args' => array('trash' => true, 'all' => true), |
|
| 443 | + 'noheader' => true |
|
| 444 | + ), |
|
| 445 | + 'trash_message_template_context' => array( |
|
| 446 | + 'func' => '_trash_or_restore_message_template', |
|
| 447 | + 'capability' => 'ee_delete_message', |
|
| 448 | + 'obj_id' => $grp_id, |
|
| 449 | + 'args' => array('trash' => true), |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'restore_message_template' => array( |
|
| 453 | + 'func' => '_trash_or_restore_message_template', |
|
| 454 | + 'capability' => 'ee_delete_message', |
|
| 455 | + 'obj_id' => $grp_id, |
|
| 456 | + 'args' => array('trash' => false, 'all' => true), |
|
| 457 | + 'noheader' => true |
|
| 458 | + ), |
|
| 459 | + 'restore_message_template_context' => array( |
|
| 460 | + 'func' => '_trash_or_restore_message_template', |
|
| 461 | + 'capability' => 'ee_delete_message', |
|
| 462 | + 'obj_id' => $grp_id, |
|
| 463 | + 'args' => array('trash' => false), |
|
| 464 | + 'noheader' => true |
|
| 465 | + ), |
|
| 466 | + 'delete_message_template' => array( |
|
| 467 | + 'func' => '_delete_message_template', |
|
| 468 | + 'capability' => 'ee_delete_message', |
|
| 469 | + 'obj_id' => $grp_id, |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'reset_to_default' => array( |
|
| 473 | + 'func' => '_reset_to_default_template', |
|
| 474 | + 'capability' => 'ee_edit_message', |
|
| 475 | + 'obj_id' => $grp_id, |
|
| 476 | + 'noheader' => true |
|
| 477 | + ), |
|
| 478 | + 'settings' => array( |
|
| 479 | + 'func' => '_settings', |
|
| 480 | + 'capability' => 'manage_options' |
|
| 481 | + ), |
|
| 482 | + 'update_global_settings' => array( |
|
| 483 | + 'func' => '_update_global_settings', |
|
| 484 | + 'capability' => 'manage_options', |
|
| 485 | + 'noheader' => true |
|
| 486 | + ), |
|
| 487 | + 'generate_now' => array( |
|
| 488 | + 'func' => '_generate_now', |
|
| 489 | + 'capability' => 'ee_send_message', |
|
| 490 | + 'noheader' => true |
|
| 491 | + ), |
|
| 492 | + 'generate_and_send_now' => array( |
|
| 493 | + 'func' => '_generate_and_send_now', |
|
| 494 | + 'capability' => 'ee_send_message', |
|
| 495 | + 'noheader' => true |
|
| 496 | + ), |
|
| 497 | + 'queue_for_resending' => array( |
|
| 498 | + 'func' => '_queue_for_resending', |
|
| 499 | + 'capability' => 'ee_send_message', |
|
| 500 | + 'noheader' => true |
|
| 501 | + ), |
|
| 502 | + 'send_now' => array( |
|
| 503 | + 'func' => '_send_now', |
|
| 504 | + 'capability' => 'ee_send_message', |
|
| 505 | + 'noheader' => true |
|
| 506 | + ), |
|
| 507 | + 'delete_ee_message' => array( |
|
| 508 | + 'func' => '_delete_ee_messages', |
|
| 509 | + 'capability' => 'ee_delete_messages', |
|
| 510 | + 'noheader' => true |
|
| 511 | + ), |
|
| 512 | + 'delete_ee_messages' => array( |
|
| 513 | + 'func' => '_delete_ee_messages', |
|
| 514 | + 'capability' => 'ee_delete_messages', |
|
| 515 | + 'noheader' => true, |
|
| 516 | + 'obj_id' => $msg_id |
|
| 517 | + ) |
|
| 518 | + ); |
|
| 519 | + } |
|
| 520 | 520 | |
| 521 | 521 | |
| 522 | - protected function _set_page_config() |
|
| 523 | - { |
|
| 524 | - $this->_page_config = array( |
|
| 525 | - 'default' => array( |
|
| 526 | - 'nav' => array( |
|
| 527 | - 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 528 | - 'order' => 10 |
|
| 529 | - ), |
|
| 530 | - 'list_table' => 'EE_Message_List_Table', |
|
| 531 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 532 | - 'require_nonce' => false |
|
| 533 | - ), |
|
| 534 | - 'global_mtps' => array( |
|
| 535 | - 'nav' => array( |
|
| 536 | - 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 537 | - 'order' => 20 |
|
| 538 | - ), |
|
| 539 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 540 | - 'help_tabs' => array( |
|
| 541 | - 'messages_overview_help_tab' => array( |
|
| 542 | - 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 543 | - 'filename' => 'messages_overview' |
|
| 544 | - ), |
|
| 545 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 546 | - 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 547 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 548 | - ), |
|
| 549 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 550 | - 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 551 | - 'filename' => 'messages_overview_filters' |
|
| 552 | - ), |
|
| 553 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 554 | - 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 555 | - 'filename' => 'messages_overview_views' |
|
| 556 | - ), |
|
| 557 | - 'message_overview_message_types_help_tab' => array( |
|
| 558 | - 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 559 | - 'filename' => 'messages_overview_types' |
|
| 560 | - ), |
|
| 561 | - 'messages_overview_messengers_help_tab' => array( |
|
| 562 | - 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 563 | - 'filename' => 'messages_overview_messengers', |
|
| 564 | - ), |
|
| 565 | - ), |
|
| 566 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 567 | - 'require_nonce' => false |
|
| 568 | - ), |
|
| 569 | - 'custom_mtps' => array( |
|
| 570 | - 'nav' => array( |
|
| 571 | - 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 572 | - 'order' => 30 |
|
| 573 | - ), |
|
| 574 | - 'help_tabs' => array(), |
|
| 575 | - 'help_tour' => array(), |
|
| 576 | - 'require_nonce' => false |
|
| 577 | - ), |
|
| 578 | - 'add_new_message_template' => array( |
|
| 579 | - 'nav' => array( |
|
| 580 | - 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 581 | - 'order' => 5, |
|
| 582 | - 'persistent' => false |
|
| 583 | - ), |
|
| 584 | - 'require_nonce' => false |
|
| 585 | - ), |
|
| 586 | - 'edit_message_template' => array( |
|
| 587 | - 'labels' => array( |
|
| 588 | - 'buttons' => array( |
|
| 589 | - 'reset' => esc_html__('Reset Templates'), |
|
| 590 | - ), |
|
| 591 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 592 | - ), |
|
| 593 | - 'nav' => array( |
|
| 594 | - 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 595 | - 'order' => 5, |
|
| 596 | - 'persistent' => false, |
|
| 597 | - 'url' => '' |
|
| 598 | - ), |
|
| 599 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 600 | - 'has_metaboxes' => true, |
|
| 601 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 602 | - 'help_tabs' => array( |
|
| 603 | - 'edit_message_template' => array( |
|
| 604 | - 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 605 | - 'callback' => 'edit_message_template_help_tab' |
|
| 606 | - ), |
|
| 607 | - 'message_templates_help_tab' => array( |
|
| 608 | - 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 609 | - 'filename' => 'messages_templates' |
|
| 610 | - ), |
|
| 611 | - 'message_template_shortcodes' => array( |
|
| 612 | - 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 613 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 614 | - ), |
|
| 615 | - 'message_preview_help_tab' => array( |
|
| 616 | - 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 617 | - 'filename' => 'messages_preview' |
|
| 618 | - ), |
|
| 619 | - 'messages_overview_other_help_tab' => array( |
|
| 620 | - 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 621 | - 'filename' => 'messages_overview_other', |
|
| 622 | - ), |
|
| 623 | - ), |
|
| 624 | - 'require_nonce' => false |
|
| 625 | - ), |
|
| 626 | - 'display_preview_message' => array( |
|
| 627 | - 'nav' => array( |
|
| 628 | - 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 629 | - 'order' => 5, |
|
| 630 | - 'url' => '', |
|
| 631 | - 'persistent' => false |
|
| 632 | - ), |
|
| 633 | - 'help_tabs' => array( |
|
| 634 | - 'preview_message' => array( |
|
| 635 | - 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 636 | - 'callback' => 'preview_message_help_tab' |
|
| 637 | - ) |
|
| 638 | - ), |
|
| 639 | - 'require_nonce' => false |
|
| 640 | - ), |
|
| 641 | - 'settings' => array( |
|
| 642 | - 'nav' => array( |
|
| 643 | - 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 644 | - 'order' => 40 |
|
| 645 | - ), |
|
| 646 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 647 | - 'help_tabs' => array( |
|
| 648 | - 'messages_settings_help_tab' => array( |
|
| 649 | - 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 650 | - 'filename' => 'messages_settings' |
|
| 651 | - ), |
|
| 652 | - 'messages_settings_message_types_help_tab' => array( |
|
| 653 | - 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 654 | - 'filename' => 'messages_settings_message_types' |
|
| 655 | - ), |
|
| 656 | - 'messages_settings_messengers_help_tab' => array( |
|
| 657 | - 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 658 | - 'filename' => 'messages_settings_messengers' |
|
| 659 | - ), |
|
| 660 | - ), |
|
| 661 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 662 | - 'require_nonce' => false |
|
| 663 | - ) |
|
| 664 | - ); |
|
| 665 | - } |
|
| 522 | + protected function _set_page_config() |
|
| 523 | + { |
|
| 524 | + $this->_page_config = array( |
|
| 525 | + 'default' => array( |
|
| 526 | + 'nav' => array( |
|
| 527 | + 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 528 | + 'order' => 10 |
|
| 529 | + ), |
|
| 530 | + 'list_table' => 'EE_Message_List_Table', |
|
| 531 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 532 | + 'require_nonce' => false |
|
| 533 | + ), |
|
| 534 | + 'global_mtps' => array( |
|
| 535 | + 'nav' => array( |
|
| 536 | + 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 537 | + 'order' => 20 |
|
| 538 | + ), |
|
| 539 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 540 | + 'help_tabs' => array( |
|
| 541 | + 'messages_overview_help_tab' => array( |
|
| 542 | + 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 543 | + 'filename' => 'messages_overview' |
|
| 544 | + ), |
|
| 545 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 546 | + 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 547 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 548 | + ), |
|
| 549 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 550 | + 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 551 | + 'filename' => 'messages_overview_filters' |
|
| 552 | + ), |
|
| 553 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 554 | + 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 555 | + 'filename' => 'messages_overview_views' |
|
| 556 | + ), |
|
| 557 | + 'message_overview_message_types_help_tab' => array( |
|
| 558 | + 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 559 | + 'filename' => 'messages_overview_types' |
|
| 560 | + ), |
|
| 561 | + 'messages_overview_messengers_help_tab' => array( |
|
| 562 | + 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 563 | + 'filename' => 'messages_overview_messengers', |
|
| 564 | + ), |
|
| 565 | + ), |
|
| 566 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 567 | + 'require_nonce' => false |
|
| 568 | + ), |
|
| 569 | + 'custom_mtps' => array( |
|
| 570 | + 'nav' => array( |
|
| 571 | + 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 572 | + 'order' => 30 |
|
| 573 | + ), |
|
| 574 | + 'help_tabs' => array(), |
|
| 575 | + 'help_tour' => array(), |
|
| 576 | + 'require_nonce' => false |
|
| 577 | + ), |
|
| 578 | + 'add_new_message_template' => array( |
|
| 579 | + 'nav' => array( |
|
| 580 | + 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 581 | + 'order' => 5, |
|
| 582 | + 'persistent' => false |
|
| 583 | + ), |
|
| 584 | + 'require_nonce' => false |
|
| 585 | + ), |
|
| 586 | + 'edit_message_template' => array( |
|
| 587 | + 'labels' => array( |
|
| 588 | + 'buttons' => array( |
|
| 589 | + 'reset' => esc_html__('Reset Templates'), |
|
| 590 | + ), |
|
| 591 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 592 | + ), |
|
| 593 | + 'nav' => array( |
|
| 594 | + 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 595 | + 'order' => 5, |
|
| 596 | + 'persistent' => false, |
|
| 597 | + 'url' => '' |
|
| 598 | + ), |
|
| 599 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 600 | + 'has_metaboxes' => true, |
|
| 601 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 602 | + 'help_tabs' => array( |
|
| 603 | + 'edit_message_template' => array( |
|
| 604 | + 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 605 | + 'callback' => 'edit_message_template_help_tab' |
|
| 606 | + ), |
|
| 607 | + 'message_templates_help_tab' => array( |
|
| 608 | + 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 609 | + 'filename' => 'messages_templates' |
|
| 610 | + ), |
|
| 611 | + 'message_template_shortcodes' => array( |
|
| 612 | + 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 613 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 614 | + ), |
|
| 615 | + 'message_preview_help_tab' => array( |
|
| 616 | + 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 617 | + 'filename' => 'messages_preview' |
|
| 618 | + ), |
|
| 619 | + 'messages_overview_other_help_tab' => array( |
|
| 620 | + 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 621 | + 'filename' => 'messages_overview_other', |
|
| 622 | + ), |
|
| 623 | + ), |
|
| 624 | + 'require_nonce' => false |
|
| 625 | + ), |
|
| 626 | + 'display_preview_message' => array( |
|
| 627 | + 'nav' => array( |
|
| 628 | + 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 629 | + 'order' => 5, |
|
| 630 | + 'url' => '', |
|
| 631 | + 'persistent' => false |
|
| 632 | + ), |
|
| 633 | + 'help_tabs' => array( |
|
| 634 | + 'preview_message' => array( |
|
| 635 | + 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 636 | + 'callback' => 'preview_message_help_tab' |
|
| 637 | + ) |
|
| 638 | + ), |
|
| 639 | + 'require_nonce' => false |
|
| 640 | + ), |
|
| 641 | + 'settings' => array( |
|
| 642 | + 'nav' => array( |
|
| 643 | + 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 644 | + 'order' => 40 |
|
| 645 | + ), |
|
| 646 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 647 | + 'help_tabs' => array( |
|
| 648 | + 'messages_settings_help_tab' => array( |
|
| 649 | + 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 650 | + 'filename' => 'messages_settings' |
|
| 651 | + ), |
|
| 652 | + 'messages_settings_message_types_help_tab' => array( |
|
| 653 | + 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 654 | + 'filename' => 'messages_settings_message_types' |
|
| 655 | + ), |
|
| 656 | + 'messages_settings_messengers_help_tab' => array( |
|
| 657 | + 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 658 | + 'filename' => 'messages_settings_messengers' |
|
| 659 | + ), |
|
| 660 | + ), |
|
| 661 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 662 | + 'require_nonce' => false |
|
| 663 | + ) |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | 667 | |
| 668 | - protected function _add_screen_options() |
|
| 669 | - { |
|
| 670 | - //todo |
|
| 671 | - } |
|
| 668 | + protected function _add_screen_options() |
|
| 669 | + { |
|
| 670 | + //todo |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | 673 | |
| 674 | - protected function _add_screen_options_global_mtps() |
|
| 675 | - { |
|
| 676 | - /** |
|
| 677 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 678 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 679 | - */ |
|
| 680 | - $page_title = $this->_admin_page_title; |
|
| 681 | - $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 682 | - $this->_per_page_screen_option(); |
|
| 683 | - $this->_admin_page_title = $page_title; |
|
| 684 | - } |
|
| 674 | + protected function _add_screen_options_global_mtps() |
|
| 675 | + { |
|
| 676 | + /** |
|
| 677 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 678 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 679 | + */ |
|
| 680 | + $page_title = $this->_admin_page_title; |
|
| 681 | + $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 682 | + $this->_per_page_screen_option(); |
|
| 683 | + $this->_admin_page_title = $page_title; |
|
| 684 | + } |
|
| 685 | 685 | |
| 686 | 686 | |
| 687 | - protected function _add_screen_options_default() |
|
| 688 | - { |
|
| 689 | - $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 690 | - $this->_per_page_screen_option(); |
|
| 691 | - } |
|
| 687 | + protected function _add_screen_options_default() |
|
| 688 | + { |
|
| 689 | + $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 690 | + $this->_per_page_screen_option(); |
|
| 691 | + } |
|
| 692 | 692 | |
| 693 | 693 | |
| 694 | - //none of the below group are currently used for Messages |
|
| 695 | - protected function _add_feature_pointers() |
|
| 696 | - { |
|
| 697 | - } |
|
| 694 | + //none of the below group are currently used for Messages |
|
| 695 | + protected function _add_feature_pointers() |
|
| 696 | + { |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - public function admin_init() |
|
| 700 | - { |
|
| 701 | - } |
|
| 699 | + public function admin_init() |
|
| 700 | + { |
|
| 701 | + } |
|
| 702 | 702 | |
| 703 | - public function admin_notices() |
|
| 704 | - { |
|
| 705 | - } |
|
| 703 | + public function admin_notices() |
|
| 704 | + { |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - public function admin_footer_scripts() |
|
| 708 | - { |
|
| 709 | - } |
|
| 707 | + public function admin_footer_scripts() |
|
| 708 | + { |
|
| 709 | + } |
|
| 710 | 710 | |
| 711 | 711 | |
| 712 | - public function messages_help_tab() |
|
| 713 | - { |
|
| 714 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 715 | - } |
|
| 712 | + public function messages_help_tab() |
|
| 713 | + { |
|
| 714 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | |
| 718 | - public function messengers_help_tab() |
|
| 719 | - { |
|
| 720 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 721 | - } |
|
| 718 | + public function messengers_help_tab() |
|
| 719 | + { |
|
| 720 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | 723 | |
| 724 | - public function message_types_help_tab() |
|
| 725 | - { |
|
| 726 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 727 | - } |
|
| 724 | + public function message_types_help_tab() |
|
| 725 | + { |
|
| 726 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | 729 | |
| 730 | - public function messages_overview_help_tab() |
|
| 731 | - { |
|
| 732 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 733 | - } |
|
| 730 | + public function messages_overview_help_tab() |
|
| 731 | + { |
|
| 732 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | 735 | |
| 736 | - public function message_templates_help_tab() |
|
| 737 | - { |
|
| 738 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 739 | - } |
|
| 736 | + public function message_templates_help_tab() |
|
| 737 | + { |
|
| 738 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | |
| 742 | - public function edit_message_template_help_tab() |
|
| 743 | - { |
|
| 744 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 745 | - . esc_attr__('Editor Title', 'event_espresso') |
|
| 746 | - . '" />'; |
|
| 747 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 748 | - . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 749 | - . '" />'; |
|
| 750 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 751 | - . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 752 | - . '" />'; |
|
| 753 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 754 | - . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 755 | - . '" />'; |
|
| 756 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 757 | - . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 758 | - . '" />'; |
|
| 759 | - EEH_Template::display_template( |
|
| 760 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 761 | - $args |
|
| 762 | - ); |
|
| 763 | - } |
|
| 742 | + public function edit_message_template_help_tab() |
|
| 743 | + { |
|
| 744 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 745 | + . esc_attr__('Editor Title', 'event_espresso') |
|
| 746 | + . '" />'; |
|
| 747 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 748 | + . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 749 | + . '" />'; |
|
| 750 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 751 | + . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 752 | + . '" />'; |
|
| 753 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 754 | + . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 755 | + . '" />'; |
|
| 756 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 757 | + . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 758 | + . '" />'; |
|
| 759 | + EEH_Template::display_template( |
|
| 760 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 761 | + $args |
|
| 762 | + ); |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | |
| 766 | - public function message_template_shortcodes_help_tab() |
|
| 767 | - { |
|
| 768 | - $this->_set_shortcodes(); |
|
| 769 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 770 | - EEH_Template::display_template( |
|
| 771 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 772 | - $args |
|
| 773 | - ); |
|
| 774 | - } |
|
| 766 | + public function message_template_shortcodes_help_tab() |
|
| 767 | + { |
|
| 768 | + $this->_set_shortcodes(); |
|
| 769 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 770 | + EEH_Template::display_template( |
|
| 771 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 772 | + $args |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | 776 | |
| 777 | - public function preview_message_help_tab() |
|
| 778 | - { |
|
| 779 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 780 | - } |
|
| 777 | + public function preview_message_help_tab() |
|
| 778 | + { |
|
| 779 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 780 | + } |
|
| 781 | 781 | |
| 782 | 782 | |
| 783 | - public function settings_help_tab() |
|
| 784 | - { |
|
| 785 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 786 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 787 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 788 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 789 | - $args['img3'] = '<div class="switch">' |
|
| 790 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 791 | - . ' type="checkbox" checked="checked">' |
|
| 792 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 793 | - . '</div>'; |
|
| 794 | - $args['img4'] = '<div class="switch">' |
|
| 795 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 796 | - . ' type="checkbox">' |
|
| 797 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 798 | - . '</div>'; |
|
| 799 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 800 | - } |
|
| 783 | + public function settings_help_tab() |
|
| 784 | + { |
|
| 785 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 786 | + . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 787 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 788 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 789 | + $args['img3'] = '<div class="switch">' |
|
| 790 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 791 | + . ' type="checkbox" checked="checked">' |
|
| 792 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 793 | + . '</div>'; |
|
| 794 | + $args['img4'] = '<div class="switch">' |
|
| 795 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 796 | + . ' type="checkbox">' |
|
| 797 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 798 | + . '</div>'; |
|
| 799 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 800 | + } |
|
| 801 | 801 | |
| 802 | 802 | |
| 803 | - public function load_scripts_styles() |
|
| 804 | - { |
|
| 805 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 806 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 807 | - |
|
| 808 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 809 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 810 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 811 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 812 | - } |
|
| 803 | + public function load_scripts_styles() |
|
| 804 | + { |
|
| 805 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 806 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 807 | + |
|
| 808 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 809 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 810 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 811 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | 814 | |
| 815 | - public function load_scripts_styles_default() |
|
| 816 | - { |
|
| 817 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 818 | - } |
|
| 815 | + public function load_scripts_styles_default() |
|
| 816 | + { |
|
| 817 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | |
| 821 | - public function wp_editor_css($mce_css) |
|
| 822 | - { |
|
| 823 | - //if we're on the edit_message_template route |
|
| 824 | - if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 825 | - $message_type_name = $this->_active_message_type_name; |
|
| 821 | + public function wp_editor_css($mce_css) |
|
| 822 | + { |
|
| 823 | + //if we're on the edit_message_template route |
|
| 824 | + if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 825 | + $message_type_name = $this->_active_message_type_name; |
|
| 826 | 826 | |
| 827 | - //we're going to REPLACE the existing mce css |
|
| 828 | - //we need to get the css file location from the active messenger |
|
| 829 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 830 | - 'wpeditor', $this->_variation); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - return $mce_css; |
|
| 834 | - } |
|
| 827 | + //we're going to REPLACE the existing mce css |
|
| 828 | + //we need to get the css file location from the active messenger |
|
| 829 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 830 | + 'wpeditor', $this->_variation); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + return $mce_css; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | 836 | |
| 837 | - public function load_scripts_styles_edit_message_template() |
|
| 838 | - { |
|
| 839 | - |
|
| 840 | - $this->_set_shortcodes(); |
|
| 841 | - |
|
| 842 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 843 | - esc_html__( |
|
| 844 | - 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 845 | - 'event_espresso' |
|
| 846 | - ), |
|
| 847 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 848 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 849 | - ); |
|
| 850 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 851 | - 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 852 | - 'event_espresso' |
|
| 853 | - ); |
|
| 854 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 855 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 856 | - 'event_espresso' |
|
| 857 | - ); |
|
| 858 | - |
|
| 859 | - wp_register_script( |
|
| 860 | - 'ee_msgs_edit_js', |
|
| 861 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 862 | - array('jquery'), |
|
| 863 | - EVENT_ESPRESSO_VERSION |
|
| 864 | - ); |
|
| 865 | - |
|
| 866 | - wp_enqueue_script('ee_admin_js'); |
|
| 867 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 868 | - |
|
| 869 | - //add in special css for tiny_mce |
|
| 870 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 871 | - } |
|
| 837 | + public function load_scripts_styles_edit_message_template() |
|
| 838 | + { |
|
| 839 | + |
|
| 840 | + $this->_set_shortcodes(); |
|
| 841 | + |
|
| 842 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 843 | + esc_html__( |
|
| 844 | + 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 845 | + 'event_espresso' |
|
| 846 | + ), |
|
| 847 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 848 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 849 | + ); |
|
| 850 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 851 | + 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 852 | + 'event_espresso' |
|
| 853 | + ); |
|
| 854 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 855 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 856 | + 'event_espresso' |
|
| 857 | + ); |
|
| 858 | + |
|
| 859 | + wp_register_script( |
|
| 860 | + 'ee_msgs_edit_js', |
|
| 861 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 862 | + array('jquery'), |
|
| 863 | + EVENT_ESPRESSO_VERSION |
|
| 864 | + ); |
|
| 865 | + |
|
| 866 | + wp_enqueue_script('ee_admin_js'); |
|
| 867 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 868 | + |
|
| 869 | + //add in special css for tiny_mce |
|
| 870 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 871 | + } |
|
| 872 | 872 | |
| 873 | 873 | |
| 874 | - public function load_scripts_styles_display_preview_message() |
|
| 875 | - { |
|
| 876 | - |
|
| 877 | - $this->_set_message_template_group(); |
|
| 878 | - |
|
| 879 | - if (isset($this->_req_data['messenger'])) { |
|
| 880 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 881 | - $this->_req_data['messenger'] |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - wp_enqueue_style('espresso_preview_css', |
|
| 889 | - $this->_active_messenger->get_variation( |
|
| 890 | - $this->_template_pack, |
|
| 891 | - $message_type_name, |
|
| 892 | - true, |
|
| 893 | - 'preview', |
|
| 894 | - $this->_variation |
|
| 895 | - ) |
|
| 896 | - ); |
|
| 897 | - } |
|
| 874 | + public function load_scripts_styles_display_preview_message() |
|
| 875 | + { |
|
| 876 | + |
|
| 877 | + $this->_set_message_template_group(); |
|
| 878 | + |
|
| 879 | + if (isset($this->_req_data['messenger'])) { |
|
| 880 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 881 | + $this->_req_data['messenger'] |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + wp_enqueue_style('espresso_preview_css', |
|
| 889 | + $this->_active_messenger->get_variation( |
|
| 890 | + $this->_template_pack, |
|
| 891 | + $message_type_name, |
|
| 892 | + true, |
|
| 893 | + 'preview', |
|
| 894 | + $this->_variation |
|
| 895 | + ) |
|
| 896 | + ); |
|
| 897 | + } |
|
| 898 | 898 | |
| 899 | 899 | |
| 900 | - public function load_scripts_styles_settings() |
|
| 901 | - { |
|
| 902 | - wp_register_style( |
|
| 903 | - 'ee-message-settings', |
|
| 904 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 905 | - array(), |
|
| 906 | - EVENT_ESPRESSO_VERSION |
|
| 907 | - ); |
|
| 908 | - wp_enqueue_style('ee-text-links'); |
|
| 909 | - wp_enqueue_style('ee-message-settings'); |
|
| 910 | - wp_enqueue_script('ee-messages-settings'); |
|
| 911 | - } |
|
| 900 | + public function load_scripts_styles_settings() |
|
| 901 | + { |
|
| 902 | + wp_register_style( |
|
| 903 | + 'ee-message-settings', |
|
| 904 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 905 | + array(), |
|
| 906 | + EVENT_ESPRESSO_VERSION |
|
| 907 | + ); |
|
| 908 | + wp_enqueue_style('ee-text-links'); |
|
| 909 | + wp_enqueue_style('ee-message-settings'); |
|
| 910 | + wp_enqueue_script('ee-messages-settings'); |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | 913 | |
| 914 | - /** |
|
| 915 | - * set views array for List Table |
|
| 916 | - */ |
|
| 917 | - public function _set_list_table_views_global_mtps() |
|
| 918 | - { |
|
| 919 | - $this->_views = array( |
|
| 920 | - 'in_use' => array( |
|
| 921 | - 'slug' => 'in_use', |
|
| 922 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 923 | - 'count' => 0, |
|
| 924 | - ) |
|
| 925 | - ); |
|
| 926 | - } |
|
| 914 | + /** |
|
| 915 | + * set views array for List Table |
|
| 916 | + */ |
|
| 917 | + public function _set_list_table_views_global_mtps() |
|
| 918 | + { |
|
| 919 | + $this->_views = array( |
|
| 920 | + 'in_use' => array( |
|
| 921 | + 'slug' => 'in_use', |
|
| 922 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 923 | + 'count' => 0, |
|
| 924 | + ) |
|
| 925 | + ); |
|
| 926 | + } |
|
| 927 | 927 | |
| 928 | 928 | |
| 929 | - /** |
|
| 930 | - * Set views array for the Custom Template List Table |
|
| 931 | - */ |
|
| 932 | - public function _set_list_table_views_custom_mtps() |
|
| 933 | - { |
|
| 934 | - $this->_set_list_table_views_global_mtps(); |
|
| 935 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 936 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 937 | - ); |
|
| 938 | - } |
|
| 929 | + /** |
|
| 930 | + * Set views array for the Custom Template List Table |
|
| 931 | + */ |
|
| 932 | + public function _set_list_table_views_custom_mtps() |
|
| 933 | + { |
|
| 934 | + $this->_set_list_table_views_global_mtps(); |
|
| 935 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 936 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 937 | + ); |
|
| 938 | + } |
|
| 939 | 939 | |
| 940 | 940 | |
| 941 | - /** |
|
| 942 | - * set views array for message queue list table |
|
| 943 | - * |
|
| 944 | - * @throws InvalidDataTypeException |
|
| 945 | - * @throws InvalidInterfaceException |
|
| 946 | - * @throws InvalidArgumentException |
|
| 947 | - * @throws EE_Error |
|
| 948 | - * @throws ReflectionException |
|
| 949 | - */ |
|
| 950 | - public function _set_list_table_views_default() |
|
| 951 | - { |
|
| 952 | - EE_Registry::instance()->load_helper('Template'); |
|
| 953 | - |
|
| 954 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 955 | - 'ee_send_message', |
|
| 956 | - 'message_list_table_bulk_actions' |
|
| 957 | - ) |
|
| 958 | - ? array( |
|
| 959 | - 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 960 | - 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 961 | - 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 962 | - 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 963 | - ) |
|
| 964 | - : array(); |
|
| 965 | - |
|
| 966 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 967 | - 'ee_delete_messages', |
|
| 968 | - 'message_list_table_bulk_actions' |
|
| 969 | - ) |
|
| 970 | - ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 971 | - : array(); |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - $this->_views = array( |
|
| 975 | - 'all' => array( |
|
| 976 | - 'slug' => 'all', |
|
| 977 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 978 | - 'count' => 0, |
|
| 979 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 980 | - ) |
|
| 981 | - ); |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 985 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 986 | - continue; |
|
| 987 | - } |
|
| 988 | - $status_bulk_actions = $common_bulk_actions; |
|
| 989 | - //unset bulk actions not applying to status |
|
| 990 | - if (! empty($status_bulk_actions)) { |
|
| 991 | - switch ($status) { |
|
| 992 | - case EEM_Message::status_idle: |
|
| 993 | - case EEM_Message::status_resend: |
|
| 994 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 995 | - break; |
|
| 941 | + /** |
|
| 942 | + * set views array for message queue list table |
|
| 943 | + * |
|
| 944 | + * @throws InvalidDataTypeException |
|
| 945 | + * @throws InvalidInterfaceException |
|
| 946 | + * @throws InvalidArgumentException |
|
| 947 | + * @throws EE_Error |
|
| 948 | + * @throws ReflectionException |
|
| 949 | + */ |
|
| 950 | + public function _set_list_table_views_default() |
|
| 951 | + { |
|
| 952 | + EE_Registry::instance()->load_helper('Template'); |
|
| 953 | + |
|
| 954 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 955 | + 'ee_send_message', |
|
| 956 | + 'message_list_table_bulk_actions' |
|
| 957 | + ) |
|
| 958 | + ? array( |
|
| 959 | + 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 960 | + 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 961 | + 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 962 | + 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 963 | + ) |
|
| 964 | + : array(); |
|
| 965 | + |
|
| 966 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 967 | + 'ee_delete_messages', |
|
| 968 | + 'message_list_table_bulk_actions' |
|
| 969 | + ) |
|
| 970 | + ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 971 | + : array(); |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + $this->_views = array( |
|
| 975 | + 'all' => array( |
|
| 976 | + 'slug' => 'all', |
|
| 977 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 978 | + 'count' => 0, |
|
| 979 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 980 | + ) |
|
| 981 | + ); |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 985 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 986 | + continue; |
|
| 987 | + } |
|
| 988 | + $status_bulk_actions = $common_bulk_actions; |
|
| 989 | + //unset bulk actions not applying to status |
|
| 990 | + if (! empty($status_bulk_actions)) { |
|
| 991 | + switch ($status) { |
|
| 992 | + case EEM_Message::status_idle: |
|
| 993 | + case EEM_Message::status_resend: |
|
| 994 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 995 | + break; |
|
| 996 | 996 | |
| 997 | - case EEM_Message::status_failed: |
|
| 998 | - case EEM_Message::status_debug_only: |
|
| 999 | - case EEM_Message::status_messenger_executing: |
|
| 1000 | - $status_bulk_actions = array(); |
|
| 1001 | - break; |
|
| 997 | + case EEM_Message::status_failed: |
|
| 998 | + case EEM_Message::status_debug_only: |
|
| 999 | + case EEM_Message::status_messenger_executing: |
|
| 1000 | + $status_bulk_actions = array(); |
|
| 1001 | + break; |
|
| 1002 | 1002 | |
| 1003 | - case EEM_Message::status_incomplete: |
|
| 1004 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1005 | - break; |
|
| 1003 | + case EEM_Message::status_incomplete: |
|
| 1004 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1005 | + break; |
|
| 1006 | 1006 | |
| 1007 | - case EEM_Message::status_retry: |
|
| 1008 | - case EEM_Message::status_sent: |
|
| 1009 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1010 | - break; |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1007 | + case EEM_Message::status_retry: |
|
| 1008 | + case EEM_Message::status_sent: |
|
| 1009 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1010 | + break; |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | 1013 | |
| 1014 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1015 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1016 | - continue; |
|
| 1017 | - } |
|
| 1014 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1015 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1016 | + continue; |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | - $this->_views[strtolower($status)] = array( |
|
| 1020 | - 'slug' => strtolower($status), |
|
| 1021 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1022 | - 'count' => 0, |
|
| 1023 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1024 | - ); |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1019 | + $this->_views[strtolower($status)] = array( |
|
| 1020 | + 'slug' => strtolower($status), |
|
| 1021 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1022 | + 'count' => 0, |
|
| 1023 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1024 | + ); |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | 1027 | |
| 1028 | 1028 | |
| 1029 | - protected function _ee_default_messages_overview_list_table() |
|
| 1030 | - { |
|
| 1031 | - $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1032 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1033 | - } |
|
| 1029 | + protected function _ee_default_messages_overview_list_table() |
|
| 1030 | + { |
|
| 1031 | + $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1032 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1033 | + } |
|
| 1034 | 1034 | |
| 1035 | 1035 | |
| 1036 | - protected function _message_queue_list_table() |
|
| 1037 | - { |
|
| 1038 | - $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1039 | - $this->_template_args['per_column'] = 6; |
|
| 1040 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1041 | - $this->_template_args['before_list_table'] = '<h3>' |
|
| 1042 | - . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1043 | - . '</h3>'; |
|
| 1044 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1045 | - } |
|
| 1036 | + protected function _message_queue_list_table() |
|
| 1037 | + { |
|
| 1038 | + $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1039 | + $this->_template_args['per_column'] = 6; |
|
| 1040 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1041 | + $this->_template_args['before_list_table'] = '<h3>' |
|
| 1042 | + . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1043 | + . '</h3>'; |
|
| 1044 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1045 | + } |
|
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | - protected function _message_legend_items() |
|
| 1049 | - { |
|
| 1050 | - |
|
| 1051 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1052 | - $action_items = array(); |
|
| 1053 | - |
|
| 1054 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1055 | - if ($action_item === 'see_notifications_for') { |
|
| 1056 | - continue; |
|
| 1057 | - } |
|
| 1058 | - $action_items[$action_item] = array( |
|
| 1059 | - 'class' => $action_details['css_class'], |
|
| 1060 | - 'desc' => $action_details['label'] |
|
| 1061 | - ); |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - /** @type array $status_items status legend setup */ |
|
| 1065 | - $status_items = array( |
|
| 1066 | - 'sent_status' => array( |
|
| 1067 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1068 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1069 | - ), |
|
| 1070 | - 'idle_status' => array( |
|
| 1071 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1072 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1073 | - ), |
|
| 1074 | - 'failed_status' => array( |
|
| 1075 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1076 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1077 | - ), |
|
| 1078 | - 'messenger_executing_status' => array( |
|
| 1079 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1080 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1081 | - ), |
|
| 1082 | - 'resend_status' => array( |
|
| 1083 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1084 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1085 | - ), |
|
| 1086 | - 'incomplete_status' => array( |
|
| 1087 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1088 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1089 | - ), |
|
| 1090 | - 'retry_status' => array( |
|
| 1091 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1092 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1093 | - ) |
|
| 1094 | - ); |
|
| 1095 | - if (EEM_Message::debug()) { |
|
| 1096 | - $status_items['debug_only_status'] = array( |
|
| 1097 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1098 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1099 | - ); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - return array_merge($action_items, $status_items); |
|
| 1103 | - } |
|
| 1048 | + protected function _message_legend_items() |
|
| 1049 | + { |
|
| 1050 | + |
|
| 1051 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1052 | + $action_items = array(); |
|
| 1053 | + |
|
| 1054 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1055 | + if ($action_item === 'see_notifications_for') { |
|
| 1056 | + continue; |
|
| 1057 | + } |
|
| 1058 | + $action_items[$action_item] = array( |
|
| 1059 | + 'class' => $action_details['css_class'], |
|
| 1060 | + 'desc' => $action_details['label'] |
|
| 1061 | + ); |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + /** @type array $status_items status legend setup */ |
|
| 1065 | + $status_items = array( |
|
| 1066 | + 'sent_status' => array( |
|
| 1067 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1068 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1069 | + ), |
|
| 1070 | + 'idle_status' => array( |
|
| 1071 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1072 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1073 | + ), |
|
| 1074 | + 'failed_status' => array( |
|
| 1075 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1076 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1077 | + ), |
|
| 1078 | + 'messenger_executing_status' => array( |
|
| 1079 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1080 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1081 | + ), |
|
| 1082 | + 'resend_status' => array( |
|
| 1083 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1084 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1085 | + ), |
|
| 1086 | + 'incomplete_status' => array( |
|
| 1087 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1088 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1089 | + ), |
|
| 1090 | + 'retry_status' => array( |
|
| 1091 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1092 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1093 | + ) |
|
| 1094 | + ); |
|
| 1095 | + if (EEM_Message::debug()) { |
|
| 1096 | + $status_items['debug_only_status'] = array( |
|
| 1097 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1098 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1099 | + ); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + return array_merge($action_items, $status_items); |
|
| 1103 | + } |
|
| 1104 | 1104 | |
| 1105 | 1105 | |
| 1106 | - protected function _custom_mtps_preview() |
|
| 1107 | - { |
|
| 1108 | - $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1109 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1110 | - . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1111 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 1112 | - . esc_html__( |
|
| 1113 | - 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1114 | - 'event_espresso' |
|
| 1115 | - ) |
|
| 1116 | - . '</strong>'; |
|
| 1106 | + protected function _custom_mtps_preview() |
|
| 1107 | + { |
|
| 1108 | + $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1109 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1110 | + . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1111 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 1112 | + . esc_html__( |
|
| 1113 | + 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1114 | + 'event_espresso' |
|
| 1115 | + ) |
|
| 1116 | + . '</strong>'; |
|
| 1117 | 1117 | |
| 1118 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1119 | - } |
|
| 1118 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | 1121 | |
| 1122 | - /** |
|
| 1123 | - * get_message_templates |
|
| 1124 | - * This gets all the message templates for listing on the overview list. |
|
| 1125 | - * |
|
| 1126 | - * @access public |
|
| 1127 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1128 | - * @param string $type the current _view we're getting templates for |
|
| 1129 | - * @param bool $count return count? |
|
| 1130 | - * @param bool $all disregard any paging info (get all data); |
|
| 1131 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1132 | - * @return array |
|
| 1133 | - * @throws EE_Error |
|
| 1134 | - * @throws InvalidArgumentException |
|
| 1135 | - * @throws InvalidDataTypeException |
|
| 1136 | - * @throws InvalidInterfaceException |
|
| 1137 | - */ |
|
| 1138 | - public function get_message_templates( |
|
| 1139 | - $perpage = 10, |
|
| 1140 | - $type = 'in_use', |
|
| 1141 | - $count = false, |
|
| 1142 | - $all = false, |
|
| 1143 | - $global = true) |
|
| 1144 | - { |
|
| 1145 | - |
|
| 1146 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1147 | - |
|
| 1148 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1149 | - $orderby = $this->_req_data['orderby']; |
|
| 1150 | - |
|
| 1151 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1152 | - ? $this->_req_data['order'] |
|
| 1153 | - : 'ASC'; |
|
| 1154 | - |
|
| 1155 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1156 | - ? $this->_req_data['paged'] |
|
| 1157 | - : 1; |
|
| 1158 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1159 | - ? $this->_req_data['perpage'] |
|
| 1160 | - : $perpage; |
|
| 1161 | - |
|
| 1162 | - $offset = ($current_page - 1) * $per_page; |
|
| 1163 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - //options will match what is in the _views array property |
|
| 1167 | - switch ($type) { |
|
| 1168 | - case 'in_use': |
|
| 1169 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1170 | - break; |
|
| 1171 | - default: |
|
| 1172 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - return $templates; |
|
| 1176 | - } |
|
| 1122 | + /** |
|
| 1123 | + * get_message_templates |
|
| 1124 | + * This gets all the message templates for listing on the overview list. |
|
| 1125 | + * |
|
| 1126 | + * @access public |
|
| 1127 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1128 | + * @param string $type the current _view we're getting templates for |
|
| 1129 | + * @param bool $count return count? |
|
| 1130 | + * @param bool $all disregard any paging info (get all data); |
|
| 1131 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1132 | + * @return array |
|
| 1133 | + * @throws EE_Error |
|
| 1134 | + * @throws InvalidArgumentException |
|
| 1135 | + * @throws InvalidDataTypeException |
|
| 1136 | + * @throws InvalidInterfaceException |
|
| 1137 | + */ |
|
| 1138 | + public function get_message_templates( |
|
| 1139 | + $perpage = 10, |
|
| 1140 | + $type = 'in_use', |
|
| 1141 | + $count = false, |
|
| 1142 | + $all = false, |
|
| 1143 | + $global = true) |
|
| 1144 | + { |
|
| 1145 | + |
|
| 1146 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1147 | + |
|
| 1148 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1149 | + $orderby = $this->_req_data['orderby']; |
|
| 1150 | + |
|
| 1151 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1152 | + ? $this->_req_data['order'] |
|
| 1153 | + : 'ASC'; |
|
| 1154 | + |
|
| 1155 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1156 | + ? $this->_req_data['paged'] |
|
| 1157 | + : 1; |
|
| 1158 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1159 | + ? $this->_req_data['perpage'] |
|
| 1160 | + : $perpage; |
|
| 1161 | + |
|
| 1162 | + $offset = ($current_page - 1) * $per_page; |
|
| 1163 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + //options will match what is in the _views array property |
|
| 1167 | + switch ($type) { |
|
| 1168 | + case 'in_use': |
|
| 1169 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1170 | + break; |
|
| 1171 | + default: |
|
| 1172 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + return $templates; |
|
| 1176 | + } |
|
| 1177 | 1177 | |
| 1178 | 1178 | |
| 1179 | - /** |
|
| 1180 | - * filters etc might need a list of installed message_types |
|
| 1181 | - * @return array an array of message type objects |
|
| 1182 | - */ |
|
| 1183 | - public function get_installed_message_types() |
|
| 1184 | - { |
|
| 1185 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1186 | - $installed = array(); |
|
| 1187 | - |
|
| 1188 | - foreach ($installed_message_types as $message_type) { |
|
| 1189 | - $installed[$message_type->name] = $message_type; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - return $installed; |
|
| 1193 | - } |
|
| 1179 | + /** |
|
| 1180 | + * filters etc might need a list of installed message_types |
|
| 1181 | + * @return array an array of message type objects |
|
| 1182 | + */ |
|
| 1183 | + public function get_installed_message_types() |
|
| 1184 | + { |
|
| 1185 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1186 | + $installed = array(); |
|
| 1187 | + |
|
| 1188 | + foreach ($installed_message_types as $message_type) { |
|
| 1189 | + $installed[$message_type->name] = $message_type; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + return $installed; |
|
| 1193 | + } |
|
| 1194 | 1194 | |
| 1195 | 1195 | |
| 1196 | - /** |
|
| 1197 | - * _add_message_template |
|
| 1198 | - * |
|
| 1199 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1200 | - * |
|
| 1201 | - * @param string $message_type |
|
| 1202 | - * @param string $messenger |
|
| 1203 | - * @param string $GRP_ID |
|
| 1204 | - * |
|
| 1205 | - * @throws EE_error |
|
| 1206 | - */ |
|
| 1207 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1208 | - { |
|
| 1209 | - //set values override any request data |
|
| 1210 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1211 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1212 | - ? $this->_req_data['message_type'] |
|
| 1213 | - : $message_type; |
|
| 1214 | - |
|
| 1215 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1216 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1217 | - ? $this->_req_data['messenger'] |
|
| 1218 | - : $messenger; |
|
| 1219 | - |
|
| 1220 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1221 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1222 | - |
|
| 1223 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1224 | - if (empty($message_type) || empty($messenger)) { |
|
| 1225 | - throw new EE_Error( |
|
| 1226 | - esc_html__( |
|
| 1227 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1228 | - 'event_espresso' |
|
| 1229 | - ) |
|
| 1230 | - ); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1234 | - if (empty($GRP_ID)) { |
|
| 1235 | - throw new EE_Error( |
|
| 1236 | - esc_html__( |
|
| 1237 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1238 | - 'event_espresso' |
|
| 1239 | - ) |
|
| 1240 | - ); |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - //let's just make sure the template gets generated! |
|
| 1244 | - |
|
| 1245 | - //we need to reassign some variables for what the insert is expecting |
|
| 1246 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1247 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1248 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1249 | - $this->_insert_or_update_message_template(true); |
|
| 1250 | - } |
|
| 1196 | + /** |
|
| 1197 | + * _add_message_template |
|
| 1198 | + * |
|
| 1199 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1200 | + * |
|
| 1201 | + * @param string $message_type |
|
| 1202 | + * @param string $messenger |
|
| 1203 | + * @param string $GRP_ID |
|
| 1204 | + * |
|
| 1205 | + * @throws EE_error |
|
| 1206 | + */ |
|
| 1207 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1208 | + { |
|
| 1209 | + //set values override any request data |
|
| 1210 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1211 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1212 | + ? $this->_req_data['message_type'] |
|
| 1213 | + : $message_type; |
|
| 1214 | + |
|
| 1215 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1216 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1217 | + ? $this->_req_data['messenger'] |
|
| 1218 | + : $messenger; |
|
| 1219 | + |
|
| 1220 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1221 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1222 | + |
|
| 1223 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1224 | + if (empty($message_type) || empty($messenger)) { |
|
| 1225 | + throw new EE_Error( |
|
| 1226 | + esc_html__( |
|
| 1227 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1228 | + 'event_espresso' |
|
| 1229 | + ) |
|
| 1230 | + ); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1234 | + if (empty($GRP_ID)) { |
|
| 1235 | + throw new EE_Error( |
|
| 1236 | + esc_html__( |
|
| 1237 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1238 | + 'event_espresso' |
|
| 1239 | + ) |
|
| 1240 | + ); |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + //let's just make sure the template gets generated! |
|
| 1244 | + |
|
| 1245 | + //we need to reassign some variables for what the insert is expecting |
|
| 1246 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1247 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1248 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1249 | + $this->_insert_or_update_message_template(true); |
|
| 1250 | + } |
|
| 1251 | 1251 | |
| 1252 | 1252 | |
| 1253 | - /** |
|
| 1254 | - * public wrapper for the _add_message_template method |
|
| 1255 | - * |
|
| 1256 | - * @param string $message_type message type slug |
|
| 1257 | - * @param string $messenger messenger slug |
|
| 1258 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1259 | - * off of. |
|
| 1260 | - * @throws EE_error |
|
| 1261 | - */ |
|
| 1262 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1263 | - { |
|
| 1264 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1265 | - } |
|
| 1253 | + /** |
|
| 1254 | + * public wrapper for the _add_message_template method |
|
| 1255 | + * |
|
| 1256 | + * @param string $message_type message type slug |
|
| 1257 | + * @param string $messenger messenger slug |
|
| 1258 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1259 | + * off of. |
|
| 1260 | + * @throws EE_error |
|
| 1261 | + */ |
|
| 1262 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1263 | + { |
|
| 1264 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1265 | + } |
|
| 1266 | 1266 | |
| 1267 | 1267 | |
| 1268 | - /** |
|
| 1269 | - * _edit_message_template |
|
| 1270 | - * |
|
| 1271 | - * @access protected |
|
| 1272 | - * @return void |
|
| 1273 | - * @throws InvalidIdentifierException |
|
| 1274 | - * @throws DomainException |
|
| 1275 | - * @throws EE_Error |
|
| 1276 | - * @throws InvalidArgumentException |
|
| 1277 | - * @throws ReflectionException |
|
| 1278 | - * @throws InvalidDataTypeException |
|
| 1279 | - * @throws InvalidInterfaceException |
|
| 1280 | - */ |
|
| 1281 | - protected function _edit_message_template() |
|
| 1282 | - { |
|
| 1283 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1284 | - $template_fields = ''; |
|
| 1285 | - $sidebar_fields = ''; |
|
| 1286 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1287 | - // valid html in the templates. |
|
| 1288 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1289 | - |
|
| 1290 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1291 | - ? absint($this->_req_data['id']) |
|
| 1292 | - : false; |
|
| 1293 | - |
|
| 1294 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1295 | - $message_template_group = $this->_message_template_group; |
|
| 1296 | - $c_label = $message_template_group->context_label(); |
|
| 1297 | - $c_config = $message_template_group->contexts_config(); |
|
| 1298 | - |
|
| 1299 | - reset($c_config); |
|
| 1300 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1301 | - ? strtolower($this->_req_data['context']) |
|
| 1302 | - : key($c_config); |
|
| 1303 | - |
|
| 1304 | - |
|
| 1305 | - if (empty($GRP_ID)) { |
|
| 1306 | - $action = 'insert_message_template'; |
|
| 1307 | - $edit_message_template_form_url = add_query_arg( |
|
| 1308 | - array('action' => $action, 'noheader' => true), |
|
| 1309 | - EE_MSG_ADMIN_URL |
|
| 1310 | - ); |
|
| 1311 | - } else { |
|
| 1312 | - $action = 'update_message_template'; |
|
| 1313 | - $edit_message_template_form_url = add_query_arg( |
|
| 1314 | - array('action' => $action, 'noheader' => true), |
|
| 1315 | - EE_MSG_ADMIN_URL |
|
| 1316 | - ); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - //set active messenger for this view |
|
| 1320 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1321 | - $message_template_group->messenger() |
|
| 1322 | - ); |
|
| 1323 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - //Do we have any validation errors? |
|
| 1327 | - $validators = $this->_get_transient(); |
|
| 1328 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - //we need to assemble the title from Various details |
|
| 1332 | - $context_label = sprintf( |
|
| 1333 | - esc_html__('(%s %s)', 'event_espresso'), |
|
| 1334 | - $c_config[$context]['label'], |
|
| 1335 | - ucwords($c_label['label']) |
|
| 1336 | - ); |
|
| 1337 | - |
|
| 1338 | - $title = sprintf( |
|
| 1339 | - esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1340 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1341 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1342 | - $context_label |
|
| 1343 | - ); |
|
| 1344 | - |
|
| 1345 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1346 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1347 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1351 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1352 | - $message_template_group->messenger(), |
|
| 1353 | - $message_template_group->message_type() |
|
| 1354 | - ); |
|
| 1355 | - |
|
| 1356 | - if ( ! $template_field_structure) { |
|
| 1357 | - $template_field_structure = false; |
|
| 1358 | - $template_fields = esc_html__( |
|
| 1359 | - 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1360 | - 'event_espresso' |
|
| 1361 | - ); |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - $message_templates = $message_template_group->context_templates(); |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1369 | - // will get handled in the "extra" array. |
|
| 1370 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1371 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1372 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1377 | - if ( ! empty($template_field_structure)) { |
|
| 1378 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1379 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1380 | - // the extra array and reset them. |
|
| 1381 | - if ($template_field === 'extra') { |
|
| 1382 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1383 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1384 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1385 | - $content = $message_template instanceof EE_Message_Template |
|
| 1386 | - ? $message_template->get('MTP_content') |
|
| 1387 | - : ''; |
|
| 1388 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1389 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1390 | - $continue = false; |
|
| 1391 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1392 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1393 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1394 | - $continue = true; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - if ($continue) { |
|
| 1398 | - continue; |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1268 | + /** |
|
| 1269 | + * _edit_message_template |
|
| 1270 | + * |
|
| 1271 | + * @access protected |
|
| 1272 | + * @return void |
|
| 1273 | + * @throws InvalidIdentifierException |
|
| 1274 | + * @throws DomainException |
|
| 1275 | + * @throws EE_Error |
|
| 1276 | + * @throws InvalidArgumentException |
|
| 1277 | + * @throws ReflectionException |
|
| 1278 | + * @throws InvalidDataTypeException |
|
| 1279 | + * @throws InvalidInterfaceException |
|
| 1280 | + */ |
|
| 1281 | + protected function _edit_message_template() |
|
| 1282 | + { |
|
| 1283 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1284 | + $template_fields = ''; |
|
| 1285 | + $sidebar_fields = ''; |
|
| 1286 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1287 | + // valid html in the templates. |
|
| 1288 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1289 | + |
|
| 1290 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1291 | + ? absint($this->_req_data['id']) |
|
| 1292 | + : false; |
|
| 1293 | + |
|
| 1294 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1295 | + $message_template_group = $this->_message_template_group; |
|
| 1296 | + $c_label = $message_template_group->context_label(); |
|
| 1297 | + $c_config = $message_template_group->contexts_config(); |
|
| 1298 | + |
|
| 1299 | + reset($c_config); |
|
| 1300 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1301 | + ? strtolower($this->_req_data['context']) |
|
| 1302 | + : key($c_config); |
|
| 1303 | + |
|
| 1304 | + |
|
| 1305 | + if (empty($GRP_ID)) { |
|
| 1306 | + $action = 'insert_message_template'; |
|
| 1307 | + $edit_message_template_form_url = add_query_arg( |
|
| 1308 | + array('action' => $action, 'noheader' => true), |
|
| 1309 | + EE_MSG_ADMIN_URL |
|
| 1310 | + ); |
|
| 1311 | + } else { |
|
| 1312 | + $action = 'update_message_template'; |
|
| 1313 | + $edit_message_template_form_url = add_query_arg( |
|
| 1314 | + array('action' => $action, 'noheader' => true), |
|
| 1315 | + EE_MSG_ADMIN_URL |
|
| 1316 | + ); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + //set active messenger for this view |
|
| 1320 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1321 | + $message_template_group->messenger() |
|
| 1322 | + ); |
|
| 1323 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + //Do we have any validation errors? |
|
| 1327 | + $validators = $this->_get_transient(); |
|
| 1328 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + //we need to assemble the title from Various details |
|
| 1332 | + $context_label = sprintf( |
|
| 1333 | + esc_html__('(%s %s)', 'event_espresso'), |
|
| 1334 | + $c_config[$context]['label'], |
|
| 1335 | + ucwords($c_label['label']) |
|
| 1336 | + ); |
|
| 1337 | + |
|
| 1338 | + $title = sprintf( |
|
| 1339 | + esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1340 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1341 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1342 | + $context_label |
|
| 1343 | + ); |
|
| 1344 | + |
|
| 1345 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1346 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1347 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1351 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1352 | + $message_template_group->messenger(), |
|
| 1353 | + $message_template_group->message_type() |
|
| 1354 | + ); |
|
| 1355 | + |
|
| 1356 | + if ( ! $template_field_structure) { |
|
| 1357 | + $template_field_structure = false; |
|
| 1358 | + $template_fields = esc_html__( |
|
| 1359 | + 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1360 | + 'event_espresso' |
|
| 1361 | + ); |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + $message_templates = $message_template_group->context_templates(); |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1369 | + // will get handled in the "extra" array. |
|
| 1370 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1371 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1372 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1377 | + if ( ! empty($template_field_structure)) { |
|
| 1378 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1379 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1380 | + // the extra array and reset them. |
|
| 1381 | + if ($template_field === 'extra') { |
|
| 1382 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1383 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1384 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1385 | + $content = $message_template instanceof EE_Message_Template |
|
| 1386 | + ? $message_template->get('MTP_content') |
|
| 1387 | + : ''; |
|
| 1388 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1389 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1390 | + $continue = false; |
|
| 1391 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1392 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1393 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1394 | + $continue = true; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + if ($continue) { |
|
| 1398 | + continue; |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | 1401 | |
| 1402 | - $field_id = $reference_field |
|
| 1403 | - . '-' |
|
| 1404 | - . $extra_field |
|
| 1405 | - . '-content'; |
|
| 1406 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1407 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1408 | - . $reference_field |
|
| 1409 | - . '][content][' |
|
| 1410 | - . $extra_field . ']'; |
|
| 1411 | - $css_class = isset($extra_array['css_class']) |
|
| 1412 | - ? $extra_array['css_class'] |
|
| 1413 | - : ''; |
|
| 1402 | + $field_id = $reference_field |
|
| 1403 | + . '-' |
|
| 1404 | + . $extra_field |
|
| 1405 | + . '-content'; |
|
| 1406 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1407 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1408 | + . $reference_field |
|
| 1409 | + . '][content][' |
|
| 1410 | + . $extra_field . ']'; |
|
| 1411 | + $css_class = isset($extra_array['css_class']) |
|
| 1412 | + ? $extra_array['css_class'] |
|
| 1413 | + : ''; |
|
| 1414 | 1414 | |
| 1415 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1416 | - && in_array($extra_field, $v_fields, true) |
|
| 1417 | - && |
|
| 1418 | - ( |
|
| 1419 | - is_array($validators[$extra_field]) |
|
| 1420 | - && isset($validators[$extra_field]['msg']) |
|
| 1421 | - ) |
|
| 1422 | - ? 'validate-error ' . $css_class |
|
| 1423 | - : $css_class; |
|
| 1415 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1416 | + && in_array($extra_field, $v_fields, true) |
|
| 1417 | + && |
|
| 1418 | + ( |
|
| 1419 | + is_array($validators[$extra_field]) |
|
| 1420 | + && isset($validators[$extra_field]['msg']) |
|
| 1421 | + ) |
|
| 1422 | + ? 'validate-error ' . $css_class |
|
| 1423 | + : $css_class; |
|
| 1424 | 1424 | |
| 1425 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1426 | - && isset($content[$extra_field]) |
|
| 1427 | - ? $content[$extra_field] |
|
| 1428 | - : ''; |
|
| 1425 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1426 | + && isset($content[$extra_field]) |
|
| 1427 | + ? $content[$extra_field] |
|
| 1428 | + : ''; |
|
| 1429 | 1429 | |
| 1430 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1431 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1432 | - ? $validators[$extra_field]['value'] |
|
| 1433 | - : $template_form_fields[$field_id]['value']; |
|
| 1430 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1431 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1432 | + ? $validators[$extra_field]['value'] |
|
| 1433 | + : $template_form_fields[$field_id]['value']; |
|
| 1434 | 1434 | |
| 1435 | 1435 | |
| 1436 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1436 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1437 | 1437 | |
| 1438 | - //shortcode selector |
|
| 1439 | - $field_name_to_use = $extra_field === 'main' |
|
| 1440 | - ? 'content' |
|
| 1441 | - : $extra_field; |
|
| 1442 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1443 | - $field_name_to_use, |
|
| 1444 | - $field_id |
|
| 1445 | - ); |
|
| 1438 | + //shortcode selector |
|
| 1439 | + $field_name_to_use = $extra_field === 'main' |
|
| 1440 | + ? 'content' |
|
| 1441 | + : $extra_field; |
|
| 1442 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1443 | + $field_name_to_use, |
|
| 1444 | + $field_id |
|
| 1445 | + ); |
|
| 1446 | 1446 | |
| 1447 | - if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1448 | - //we want to decode the entities |
|
| 1449 | - $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value']; |
|
| 1447 | + if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1448 | + //we want to decode the entities |
|
| 1449 | + $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value']; |
|
| 1450 | 1450 | |
| 1451 | - }/**/ |
|
| 1452 | - } |
|
| 1453 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1454 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1451 | + }/**/ |
|
| 1452 | + } |
|
| 1453 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1454 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1455 | 1455 | |
| 1456 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1457 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1458 | - 'label' => null, |
|
| 1459 | - 'input' => 'hidden', |
|
| 1460 | - 'type' => 'int', |
|
| 1461 | - 'required' => false, |
|
| 1462 | - 'validation' => false, |
|
| 1463 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1464 | - 'css_class' => '', |
|
| 1465 | - 'format' => '%d', |
|
| 1466 | - 'db-col' => 'MTP_ID' |
|
| 1467 | - ); |
|
| 1456 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1457 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1458 | + 'label' => null, |
|
| 1459 | + 'input' => 'hidden', |
|
| 1460 | + 'type' => 'int', |
|
| 1461 | + 'required' => false, |
|
| 1462 | + 'validation' => false, |
|
| 1463 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1464 | + 'css_class' => '', |
|
| 1465 | + 'format' => '%d', |
|
| 1466 | + 'db-col' => 'MTP_ID' |
|
| 1467 | + ); |
|
| 1468 | 1468 | |
| 1469 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1470 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1471 | - 'label' => null, |
|
| 1472 | - 'input' => 'hidden', |
|
| 1473 | - 'type' => 'string', |
|
| 1474 | - 'required' => false, |
|
| 1475 | - 'validation' => true, |
|
| 1476 | - 'value' => $reference_field, |
|
| 1477 | - 'css_class' => '', |
|
| 1478 | - 'format' => '%s', |
|
| 1479 | - 'db-col' => 'MTP_template_field' |
|
| 1480 | - ); |
|
| 1481 | - } |
|
| 1482 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1483 | - } else { |
|
| 1484 | - $field_id = $template_field . '-content'; |
|
| 1485 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1486 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1487 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1488 | - ? $message_templates[$context][$template_field] |
|
| 1489 | - : null; |
|
| 1490 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1491 | - && is_array($message_templates[$context]) |
|
| 1492 | - && $message_template instanceof EE_Message_Template |
|
| 1493 | - ? $message_template->get('MTP_content') |
|
| 1494 | - : ''; |
|
| 1469 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1470 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1471 | + 'label' => null, |
|
| 1472 | + 'input' => 'hidden', |
|
| 1473 | + 'type' => 'string', |
|
| 1474 | + 'required' => false, |
|
| 1475 | + 'validation' => true, |
|
| 1476 | + 'value' => $reference_field, |
|
| 1477 | + 'css_class' => '', |
|
| 1478 | + 'format' => '%s', |
|
| 1479 | + 'db-col' => 'MTP_template_field' |
|
| 1480 | + ); |
|
| 1481 | + } |
|
| 1482 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1483 | + } else { |
|
| 1484 | + $field_id = $template_field . '-content'; |
|
| 1485 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1486 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1487 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1488 | + ? $message_templates[$context][$template_field] |
|
| 1489 | + : null; |
|
| 1490 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1491 | + && is_array($message_templates[$context]) |
|
| 1492 | + && $message_template instanceof EE_Message_Template |
|
| 1493 | + ? $message_template->get('MTP_content') |
|
| 1494 | + : ''; |
|
| 1495 | 1495 | |
| 1496 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1497 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1498 | - ? $validators[$template_field]['value'] |
|
| 1499 | - : $template_form_fields[$field_id]['value']; |
|
| 1496 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1497 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1498 | + ? $validators[$template_field]['value'] |
|
| 1499 | + : $template_form_fields[$field_id]['value']; |
|
| 1500 | 1500 | |
| 1501 | 1501 | |
| 1502 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1503 | - $css_class = isset($field_setup_array['css_class']) |
|
| 1504 | - ? $field_setup_array['css_class'] |
|
| 1505 | - : ''; |
|
| 1506 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1507 | - && in_array($template_field, $v_fields, true) |
|
| 1508 | - && isset($validators[$template_field]['msg']) |
|
| 1509 | - ? 'validate-error ' . $css_class |
|
| 1510 | - : $css_class; |
|
| 1502 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1503 | + $css_class = isset($field_setup_array['css_class']) |
|
| 1504 | + ? $field_setup_array['css_class'] |
|
| 1505 | + : ''; |
|
| 1506 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1507 | + && in_array($template_field, $v_fields, true) |
|
| 1508 | + && isset($validators[$template_field]['msg']) |
|
| 1509 | + ? 'validate-error ' . $css_class |
|
| 1510 | + : $css_class; |
|
| 1511 | 1511 | |
| 1512 | - //shortcode selector |
|
| 1513 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1514 | - $template_field, $field_id |
|
| 1515 | - ); |
|
| 1516 | - } |
|
| 1512 | + //shortcode selector |
|
| 1513 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1514 | + $template_field, $field_id |
|
| 1515 | + ); |
|
| 1516 | + } |
|
| 1517 | 1517 | |
| 1518 | - //k took care of content field(s) now let's take care of others. |
|
| 1518 | + //k took care of content field(s) now let's take care of others. |
|
| 1519 | 1519 | |
| 1520 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1521 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1520 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1521 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1522 | 1522 | |
| 1523 | - //foreach template field there are actually two form fields created |
|
| 1524 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1525 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1526 | - 'label' => null, |
|
| 1527 | - 'input' => 'hidden', |
|
| 1528 | - 'type' => 'int', |
|
| 1529 | - 'required' => false, |
|
| 1530 | - 'validation' => true, |
|
| 1531 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1532 | - 'css_class' => '', |
|
| 1533 | - 'format' => '%d', |
|
| 1534 | - 'db-col' => 'MTP_ID' |
|
| 1535 | - ); |
|
| 1523 | + //foreach template field there are actually two form fields created |
|
| 1524 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1525 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1526 | + 'label' => null, |
|
| 1527 | + 'input' => 'hidden', |
|
| 1528 | + 'type' => 'int', |
|
| 1529 | + 'required' => false, |
|
| 1530 | + 'validation' => true, |
|
| 1531 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1532 | + 'css_class' => '', |
|
| 1533 | + 'format' => '%d', |
|
| 1534 | + 'db-col' => 'MTP_ID' |
|
| 1535 | + ); |
|
| 1536 | 1536 | |
| 1537 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1538 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1539 | - 'label' => null, |
|
| 1540 | - 'input' => 'hidden', |
|
| 1541 | - 'type' => 'string', |
|
| 1542 | - 'required' => false, |
|
| 1543 | - 'validation' => true, |
|
| 1544 | - 'value' => $template_field, |
|
| 1545 | - 'css_class' => '', |
|
| 1546 | - 'format' => '%s', |
|
| 1547 | - 'db-col' => 'MTP_template_field' |
|
| 1548 | - ); |
|
| 1537 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1538 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1539 | + 'label' => null, |
|
| 1540 | + 'input' => 'hidden', |
|
| 1541 | + 'type' => 'string', |
|
| 1542 | + 'required' => false, |
|
| 1543 | + 'validation' => true, |
|
| 1544 | + 'value' => $template_field, |
|
| 1545 | + 'css_class' => '', |
|
| 1546 | + 'format' => '%s', |
|
| 1547 | + 'db-col' => 'MTP_template_field' |
|
| 1548 | + ); |
|
| 1549 | 1549 | |
| 1550 | - } |
|
| 1550 | + } |
|
| 1551 | 1551 | |
| 1552 | - //add other fields |
|
| 1553 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1554 | - 'name' => 'MTP_context', |
|
| 1555 | - 'label' => null, |
|
| 1556 | - 'input' => 'hidden', |
|
| 1557 | - 'type' => 'string', |
|
| 1558 | - 'required' => false, |
|
| 1559 | - 'validation' => true, |
|
| 1560 | - 'value' => $context, |
|
| 1561 | - 'css_class' => '', |
|
| 1562 | - 'format' => '%s', |
|
| 1563 | - 'db-col' => 'MTP_context' |
|
| 1564 | - ); |
|
| 1552 | + //add other fields |
|
| 1553 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1554 | + 'name' => 'MTP_context', |
|
| 1555 | + 'label' => null, |
|
| 1556 | + 'input' => 'hidden', |
|
| 1557 | + 'type' => 'string', |
|
| 1558 | + 'required' => false, |
|
| 1559 | + 'validation' => true, |
|
| 1560 | + 'value' => $context, |
|
| 1561 | + 'css_class' => '', |
|
| 1562 | + 'format' => '%s', |
|
| 1563 | + 'db-col' => 'MTP_context' |
|
| 1564 | + ); |
|
| 1565 | 1565 | |
| 1566 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1567 | - 'name' => 'GRP_ID', |
|
| 1568 | - 'label' => null, |
|
| 1569 | - 'input' => 'hidden', |
|
| 1570 | - 'type' => 'int', |
|
| 1571 | - 'required' => false, |
|
| 1572 | - 'validation' => true, |
|
| 1573 | - 'value' => $GRP_ID, |
|
| 1574 | - 'css_class' => '', |
|
| 1575 | - 'format' => '%d', |
|
| 1576 | - 'db-col' => 'GRP_ID' |
|
| 1577 | - ); |
|
| 1566 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1567 | + 'name' => 'GRP_ID', |
|
| 1568 | + 'label' => null, |
|
| 1569 | + 'input' => 'hidden', |
|
| 1570 | + 'type' => 'int', |
|
| 1571 | + 'required' => false, |
|
| 1572 | + 'validation' => true, |
|
| 1573 | + 'value' => $GRP_ID, |
|
| 1574 | + 'css_class' => '', |
|
| 1575 | + 'format' => '%d', |
|
| 1576 | + 'db-col' => 'GRP_ID' |
|
| 1577 | + ); |
|
| 1578 | 1578 | |
| 1579 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1580 | - 'name' => 'MTP_messenger', |
|
| 1581 | - 'label' => null, |
|
| 1582 | - 'input' => 'hidden', |
|
| 1583 | - 'type' => 'string', |
|
| 1584 | - 'required' => false, |
|
| 1585 | - 'validation' => true, |
|
| 1586 | - 'value' => $message_template_group->messenger(), |
|
| 1587 | - 'css_class' => '', |
|
| 1588 | - 'format' => '%s', |
|
| 1589 | - 'db-col' => 'MTP_messenger' |
|
| 1590 | - ); |
|
| 1579 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1580 | + 'name' => 'MTP_messenger', |
|
| 1581 | + 'label' => null, |
|
| 1582 | + 'input' => 'hidden', |
|
| 1583 | + 'type' => 'string', |
|
| 1584 | + 'required' => false, |
|
| 1585 | + 'validation' => true, |
|
| 1586 | + 'value' => $message_template_group->messenger(), |
|
| 1587 | + 'css_class' => '', |
|
| 1588 | + 'format' => '%s', |
|
| 1589 | + 'db-col' => 'MTP_messenger' |
|
| 1590 | + ); |
|
| 1591 | 1591 | |
| 1592 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1593 | - 'name' => 'MTP_message_type', |
|
| 1594 | - 'label' => null, |
|
| 1595 | - 'input' => 'hidden', |
|
| 1596 | - 'type' => 'string', |
|
| 1597 | - 'required' => false, |
|
| 1598 | - 'validation' => true, |
|
| 1599 | - 'value' => $message_template_group->message_type(), |
|
| 1600 | - 'css_class' => '', |
|
| 1601 | - 'format' => '%s', |
|
| 1602 | - 'db-col' => 'MTP_message_type' |
|
| 1603 | - ); |
|
| 1592 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1593 | + 'name' => 'MTP_message_type', |
|
| 1594 | + 'label' => null, |
|
| 1595 | + 'input' => 'hidden', |
|
| 1596 | + 'type' => 'string', |
|
| 1597 | + 'required' => false, |
|
| 1598 | + 'validation' => true, |
|
| 1599 | + 'value' => $message_template_group->message_type(), |
|
| 1600 | + 'css_class' => '', |
|
| 1601 | + 'format' => '%s', |
|
| 1602 | + 'db-col' => 'MTP_message_type' |
|
| 1603 | + ); |
|
| 1604 | 1604 | |
| 1605 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1606 | - 'name' => 'MTP_is_global', |
|
| 1607 | - 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1608 | - 'input' => 'hidden', |
|
| 1609 | - 'type' => 'int', |
|
| 1610 | - 'required' => false, |
|
| 1611 | - 'validation' => true, |
|
| 1612 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1613 | - 'css_class' => '', |
|
| 1614 | - 'format' => '%d', |
|
| 1615 | - 'db-col' => 'MTP_is_global' |
|
| 1616 | - ); |
|
| 1605 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1606 | + 'name' => 'MTP_is_global', |
|
| 1607 | + 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1608 | + 'input' => 'hidden', |
|
| 1609 | + 'type' => 'int', |
|
| 1610 | + 'required' => false, |
|
| 1611 | + 'validation' => true, |
|
| 1612 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1613 | + 'css_class' => '', |
|
| 1614 | + 'format' => '%d', |
|
| 1615 | + 'db-col' => 'MTP_is_global' |
|
| 1616 | + ); |
|
| 1617 | 1617 | |
| 1618 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1619 | - 'name' => 'MTP_is_override', |
|
| 1620 | - 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1621 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1622 | - 'type' => 'int', |
|
| 1623 | - 'required' => false, |
|
| 1624 | - 'validation' => true, |
|
| 1625 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1626 | - 'css_class' => '', |
|
| 1627 | - 'format' => '%d', |
|
| 1628 | - 'db-col' => 'MTP_is_override' |
|
| 1629 | - ); |
|
| 1618 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1619 | + 'name' => 'MTP_is_override', |
|
| 1620 | + 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1621 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1622 | + 'type' => 'int', |
|
| 1623 | + 'required' => false, |
|
| 1624 | + 'validation' => true, |
|
| 1625 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1626 | + 'css_class' => '', |
|
| 1627 | + 'format' => '%d', |
|
| 1628 | + 'db-col' => 'MTP_is_override' |
|
| 1629 | + ); |
|
| 1630 | 1630 | |
| 1631 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1632 | - 'name' => 'MTP_is_active', |
|
| 1633 | - 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1634 | - 'input' => 'hidden', |
|
| 1635 | - 'type' => 'int', |
|
| 1636 | - 'required' => false, |
|
| 1637 | - 'validation' => true, |
|
| 1638 | - 'value' => $message_template_group->is_active(), |
|
| 1639 | - 'css_class' => '', |
|
| 1640 | - 'format' => '%d', |
|
| 1641 | - 'db-col' => 'MTP_is_active' |
|
| 1642 | - ); |
|
| 1631 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1632 | + 'name' => 'MTP_is_active', |
|
| 1633 | + 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1634 | + 'input' => 'hidden', |
|
| 1635 | + 'type' => 'int', |
|
| 1636 | + 'required' => false, |
|
| 1637 | + 'validation' => true, |
|
| 1638 | + 'value' => $message_template_group->is_active(), |
|
| 1639 | + 'css_class' => '', |
|
| 1640 | + 'format' => '%d', |
|
| 1641 | + 'db-col' => 'MTP_is_active' |
|
| 1642 | + ); |
|
| 1643 | 1643 | |
| 1644 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1645 | - 'name' => 'MTP_deleted', |
|
| 1646 | - 'label' => null, |
|
| 1647 | - 'input' => 'hidden', |
|
| 1648 | - 'type' => 'int', |
|
| 1649 | - 'required' => false, |
|
| 1650 | - 'validation' => true, |
|
| 1651 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1652 | - 'css_class' => '', |
|
| 1653 | - 'format' => '%d', |
|
| 1654 | - 'db-col' => 'MTP_deleted' |
|
| 1655 | - ); |
|
| 1656 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1657 | - 'name' => 'MTP_user_id', |
|
| 1658 | - 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1659 | - 'input' => 'hidden', |
|
| 1660 | - 'type' => 'int', |
|
| 1661 | - 'required' => false, |
|
| 1662 | - 'validation' => false, |
|
| 1663 | - 'value' => $message_template_group->user(), |
|
| 1664 | - 'format' => '%d', |
|
| 1665 | - 'db-col' => 'MTP_user_id' |
|
| 1666 | - ); |
|
| 1644 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1645 | + 'name' => 'MTP_deleted', |
|
| 1646 | + 'label' => null, |
|
| 1647 | + 'input' => 'hidden', |
|
| 1648 | + 'type' => 'int', |
|
| 1649 | + 'required' => false, |
|
| 1650 | + 'validation' => true, |
|
| 1651 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1652 | + 'css_class' => '', |
|
| 1653 | + 'format' => '%d', |
|
| 1654 | + 'db-col' => 'MTP_deleted' |
|
| 1655 | + ); |
|
| 1656 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1657 | + 'name' => 'MTP_user_id', |
|
| 1658 | + 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1659 | + 'input' => 'hidden', |
|
| 1660 | + 'type' => 'int', |
|
| 1661 | + 'required' => false, |
|
| 1662 | + 'validation' => false, |
|
| 1663 | + 'value' => $message_template_group->user(), |
|
| 1664 | + 'format' => '%d', |
|
| 1665 | + 'db-col' => 'MTP_user_id' |
|
| 1666 | + ); |
|
| 1667 | 1667 | |
| 1668 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1669 | - 'name' => 'action', |
|
| 1670 | - 'input' => 'hidden', |
|
| 1671 | - 'type' => 'string', |
|
| 1672 | - 'value' => $action |
|
| 1673 | - ); |
|
| 1668 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1669 | + 'name' => 'action', |
|
| 1670 | + 'input' => 'hidden', |
|
| 1671 | + 'type' => 'string', |
|
| 1672 | + 'value' => $action |
|
| 1673 | + ); |
|
| 1674 | 1674 | |
| 1675 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1676 | - 'name' => 'id', |
|
| 1677 | - 'input' => 'hidden', |
|
| 1678 | - 'type' => 'int', |
|
| 1679 | - 'value' => $GRP_ID |
|
| 1680 | - ); |
|
| 1681 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1682 | - 'name' => $action . '_nonce', |
|
| 1683 | - 'input' => 'hidden', |
|
| 1684 | - 'type' => 'string', |
|
| 1685 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1686 | - ); |
|
| 1675 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1676 | + 'name' => 'id', |
|
| 1677 | + 'input' => 'hidden', |
|
| 1678 | + 'type' => 'int', |
|
| 1679 | + 'value' => $GRP_ID |
|
| 1680 | + ); |
|
| 1681 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1682 | + 'name' => $action . '_nonce', |
|
| 1683 | + 'input' => 'hidden', |
|
| 1684 | + 'type' => 'string', |
|
| 1685 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1686 | + ); |
|
| 1687 | 1687 | |
| 1688 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1689 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1690 | - 'name' => 'template_switch', |
|
| 1691 | - 'input' => 'hidden', |
|
| 1692 | - 'type' => 'int', |
|
| 1693 | - 'value' => 1 |
|
| 1694 | - ); |
|
| 1695 | - } |
|
| 1688 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1689 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1690 | + 'name' => 'template_switch', |
|
| 1691 | + 'input' => 'hidden', |
|
| 1692 | + 'type' => 'int', |
|
| 1693 | + 'value' => 1 |
|
| 1694 | + ); |
|
| 1695 | + } |
|
| 1696 | 1696 | |
| 1697 | 1697 | |
| 1698 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1699 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1698 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1699 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1700 | 1700 | |
| 1701 | 1701 | |
| 1702 | - } //end if ( !empty($template_field_structure) ) |
|
| 1703 | - |
|
| 1704 | - //set extra content for publish box |
|
| 1705 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1706 | - $this->_set_publish_post_box_vars( |
|
| 1707 | - 'id', |
|
| 1708 | - $GRP_ID, |
|
| 1709 | - false, |
|
| 1710 | - add_query_arg( |
|
| 1711 | - array('action' => 'global_mtps'), |
|
| 1712 | - $this->_admin_base_url |
|
| 1713 | - ) |
|
| 1714 | - ); |
|
| 1715 | - |
|
| 1716 | - //add preview button |
|
| 1717 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1718 | - array( |
|
| 1719 | - 'message_type' => $message_template_group->message_type(), |
|
| 1720 | - 'messenger' => $message_template_group->messenger(), |
|
| 1721 | - 'context' => $context, |
|
| 1722 | - 'GRP_ID' => $GRP_ID, |
|
| 1723 | - 'action' => 'preview_message' |
|
| 1724 | - ), |
|
| 1725 | - $this->_admin_base_url |
|
| 1726 | - ); |
|
| 1727 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1728 | - . esc_html__('Preview', 'event_espresso') |
|
| 1729 | - . '</a>'; |
|
| 1730 | - |
|
| 1731 | - |
|
| 1732 | - //setup context switcher |
|
| 1733 | - $context_switcher_args = array( |
|
| 1734 | - 'page' => 'espresso_messages', |
|
| 1735 | - 'action' => 'edit_message_template', |
|
| 1736 | - 'id' => $GRP_ID, |
|
| 1737 | - 'context' => $context, |
|
| 1738 | - 'extra' => $preview_button |
|
| 1739 | - ); |
|
| 1740 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1741 | - |
|
| 1742 | - |
|
| 1743 | - //main box |
|
| 1744 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1745 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1746 | - $this->_template_args['action'] = $action; |
|
| 1747 | - $this->_template_args['context'] = $context; |
|
| 1748 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1749 | - $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1750 | - $this->_learn_more_about_message_templates_link(); |
|
| 1751 | - |
|
| 1752 | - |
|
| 1753 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1754 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1755 | - $message_template_group, |
|
| 1756 | - $context, |
|
| 1757 | - $context_label |
|
| 1758 | - ); |
|
| 1759 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1760 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1761 | - |
|
| 1762 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1763 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1764 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1765 | - |
|
| 1766 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1767 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1768 | - |
|
| 1769 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1770 | - $this->_template_path, |
|
| 1771 | - $this->_template_args, |
|
| 1772 | - true |
|
| 1773 | - ); |
|
| 1774 | - |
|
| 1775 | - |
|
| 1776 | - //finally, let's set the admin_page title |
|
| 1777 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1781 | - $this->_set_shortcodes(); |
|
| 1782 | - |
|
| 1783 | - |
|
| 1784 | - //final template wrapper |
|
| 1785 | - $this->display_admin_page_with_sidebar(); |
|
| 1786 | - } |
|
| 1702 | + } //end if ( !empty($template_field_structure) ) |
|
| 1703 | + |
|
| 1704 | + //set extra content for publish box |
|
| 1705 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1706 | + $this->_set_publish_post_box_vars( |
|
| 1707 | + 'id', |
|
| 1708 | + $GRP_ID, |
|
| 1709 | + false, |
|
| 1710 | + add_query_arg( |
|
| 1711 | + array('action' => 'global_mtps'), |
|
| 1712 | + $this->_admin_base_url |
|
| 1713 | + ) |
|
| 1714 | + ); |
|
| 1715 | + |
|
| 1716 | + //add preview button |
|
| 1717 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1718 | + array( |
|
| 1719 | + 'message_type' => $message_template_group->message_type(), |
|
| 1720 | + 'messenger' => $message_template_group->messenger(), |
|
| 1721 | + 'context' => $context, |
|
| 1722 | + 'GRP_ID' => $GRP_ID, |
|
| 1723 | + 'action' => 'preview_message' |
|
| 1724 | + ), |
|
| 1725 | + $this->_admin_base_url |
|
| 1726 | + ); |
|
| 1727 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1728 | + . esc_html__('Preview', 'event_espresso') |
|
| 1729 | + . '</a>'; |
|
| 1730 | + |
|
| 1731 | + |
|
| 1732 | + //setup context switcher |
|
| 1733 | + $context_switcher_args = array( |
|
| 1734 | + 'page' => 'espresso_messages', |
|
| 1735 | + 'action' => 'edit_message_template', |
|
| 1736 | + 'id' => $GRP_ID, |
|
| 1737 | + 'context' => $context, |
|
| 1738 | + 'extra' => $preview_button |
|
| 1739 | + ); |
|
| 1740 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1741 | + |
|
| 1742 | + |
|
| 1743 | + //main box |
|
| 1744 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1745 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1746 | + $this->_template_args['action'] = $action; |
|
| 1747 | + $this->_template_args['context'] = $context; |
|
| 1748 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1749 | + $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1750 | + $this->_learn_more_about_message_templates_link(); |
|
| 1751 | + |
|
| 1752 | + |
|
| 1753 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1754 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1755 | + $message_template_group, |
|
| 1756 | + $context, |
|
| 1757 | + $context_label |
|
| 1758 | + ); |
|
| 1759 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1760 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1761 | + |
|
| 1762 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1763 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1764 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1765 | + |
|
| 1766 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1767 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1768 | + |
|
| 1769 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1770 | + $this->_template_path, |
|
| 1771 | + $this->_template_args, |
|
| 1772 | + true |
|
| 1773 | + ); |
|
| 1774 | + |
|
| 1775 | + |
|
| 1776 | + //finally, let's set the admin_page title |
|
| 1777 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1781 | + $this->_set_shortcodes(); |
|
| 1782 | + |
|
| 1783 | + |
|
| 1784 | + //final template wrapper |
|
| 1785 | + $this->display_admin_page_with_sidebar(); |
|
| 1786 | + } |
|
| 1787 | 1787 | |
| 1788 | 1788 | |
| 1789 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1790 | - { |
|
| 1791 | - return $mceInit; |
|
| 1792 | - } |
|
| 1789 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1790 | + { |
|
| 1791 | + return $mceInit; |
|
| 1792 | + } |
|
| 1793 | 1793 | |
| 1794 | 1794 | |
| 1795 | - public function add_context_switcher() |
|
| 1796 | - { |
|
| 1797 | - return $this->_context_switcher; |
|
| 1798 | - } |
|
| 1795 | + public function add_context_switcher() |
|
| 1796 | + { |
|
| 1797 | + return $this->_context_switcher; |
|
| 1798 | + } |
|
| 1799 | 1799 | |
| 1800 | 1800 | |
| 1801 | - /** |
|
| 1802 | - * Adds the activation/deactivation toggle for the message template context. |
|
| 1803 | - * |
|
| 1804 | - * @param EE_Message_Template_Group $message_template_group |
|
| 1805 | - * @param string $context |
|
| 1806 | - * @param string $context_label |
|
| 1807 | - * @return string |
|
| 1808 | - * @throws DomainException |
|
| 1809 | - * @throws EE_Error |
|
| 1810 | - * @throws InvalidIdentifierException |
|
| 1811 | - */ |
|
| 1812 | - protected function add_active_context_element( |
|
| 1813 | - EE_Message_Template_Group $message_template_group, |
|
| 1814 | - $context, |
|
| 1815 | - $context_label |
|
| 1816 | - ) { |
|
| 1817 | - $template_args = array( |
|
| 1818 | - 'context' => $context, |
|
| 1819 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1820 | - 'is_active' => $message_template_group->is_context_active($context), |
|
| 1821 | - 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1822 | - ? 'context-off' |
|
| 1823 | - : 'context-on', |
|
| 1824 | - 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1825 | - 'message_template_group_id' => $message_template_group->ID() |
|
| 1826 | - ); |
|
| 1827 | - return EEH_Template::display_template( |
|
| 1828 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1829 | - $template_args, |
|
| 1830 | - true |
|
| 1831 | - ); |
|
| 1832 | - } |
|
| 1801 | + /** |
|
| 1802 | + * Adds the activation/deactivation toggle for the message template context. |
|
| 1803 | + * |
|
| 1804 | + * @param EE_Message_Template_Group $message_template_group |
|
| 1805 | + * @param string $context |
|
| 1806 | + * @param string $context_label |
|
| 1807 | + * @return string |
|
| 1808 | + * @throws DomainException |
|
| 1809 | + * @throws EE_Error |
|
| 1810 | + * @throws InvalidIdentifierException |
|
| 1811 | + */ |
|
| 1812 | + protected function add_active_context_element( |
|
| 1813 | + EE_Message_Template_Group $message_template_group, |
|
| 1814 | + $context, |
|
| 1815 | + $context_label |
|
| 1816 | + ) { |
|
| 1817 | + $template_args = array( |
|
| 1818 | + 'context' => $context, |
|
| 1819 | + 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1820 | + 'is_active' => $message_template_group->is_context_active($context), |
|
| 1821 | + 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1822 | + ? 'context-off' |
|
| 1823 | + : 'context-on', |
|
| 1824 | + 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1825 | + 'message_template_group_id' => $message_template_group->ID() |
|
| 1826 | + ); |
|
| 1827 | + return EEH_Template::display_template( |
|
| 1828 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1829 | + $template_args, |
|
| 1830 | + true |
|
| 1831 | + ); |
|
| 1832 | + } |
|
| 1833 | 1833 | |
| 1834 | 1834 | |
| 1835 | - /** |
|
| 1836 | - * Ajax callback for `toggle_context_template` ajax action. |
|
| 1837 | - * Handles toggling the message context on or off. |
|
| 1838 | - * @throws EE_Error |
|
| 1839 | - * @throws InvalidArgumentException |
|
| 1840 | - * @throws InvalidDataTypeException |
|
| 1841 | - * @throws InvalidIdentifierException |
|
| 1842 | - * @throws InvalidInterfaceException |
|
| 1843 | - */ |
|
| 1844 | - public function toggle_context_template() |
|
| 1845 | - { |
|
| 1846 | - $success = true; |
|
| 1847 | - //check for required data |
|
| 1848 | - if (!isset( |
|
| 1849 | - $this->_req_data['message_template_group_id'], |
|
| 1850 | - $this->_req_data['context'], |
|
| 1851 | - $this->_req_data['status'] |
|
| 1852 | - )) { |
|
| 1853 | - EE_Error::add_error( |
|
| 1854 | - esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1855 | - __FILE__, |
|
| 1856 | - __FUNCTION__, |
|
| 1857 | - __LINE__ |
|
| 1858 | - ); |
|
| 1859 | - $success = false; |
|
| 1860 | - } |
|
| 1835 | + /** |
|
| 1836 | + * Ajax callback for `toggle_context_template` ajax action. |
|
| 1837 | + * Handles toggling the message context on or off. |
|
| 1838 | + * @throws EE_Error |
|
| 1839 | + * @throws InvalidArgumentException |
|
| 1840 | + * @throws InvalidDataTypeException |
|
| 1841 | + * @throws InvalidIdentifierException |
|
| 1842 | + * @throws InvalidInterfaceException |
|
| 1843 | + */ |
|
| 1844 | + public function toggle_context_template() |
|
| 1845 | + { |
|
| 1846 | + $success = true; |
|
| 1847 | + //check for required data |
|
| 1848 | + if (!isset( |
|
| 1849 | + $this->_req_data['message_template_group_id'], |
|
| 1850 | + $this->_req_data['context'], |
|
| 1851 | + $this->_req_data['status'] |
|
| 1852 | + )) { |
|
| 1853 | + EE_Error::add_error( |
|
| 1854 | + esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1855 | + __FILE__, |
|
| 1856 | + __FUNCTION__, |
|
| 1857 | + __LINE__ |
|
| 1858 | + ); |
|
| 1859 | + $success = false; |
|
| 1860 | + } |
|
| 1861 | 1861 | |
| 1862 | - $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1863 | - ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1864 | - : ''; |
|
| 1865 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1866 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1867 | - $status = $this->_req_data['status']; |
|
| 1868 | - if ($status !== 'off' && $status !=='on') { |
|
| 1869 | - EE_Error::add_error( |
|
| 1870 | - sprintf( |
|
| 1871 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1872 | - $this->_req_data['status'] |
|
| 1873 | - ), |
|
| 1874 | - __FILE__, |
|
| 1875 | - __FUNCTION__, |
|
| 1876 | - __LINE__ |
|
| 1877 | - ); |
|
| 1878 | - $success = false; |
|
| 1879 | - } |
|
| 1880 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1881 | - $this->_req_data['message_template_group_id'] |
|
| 1882 | - ); |
|
| 1883 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1884 | - EE_Error::add_error( |
|
| 1885 | - sprintf( |
|
| 1886 | - esc_html__( |
|
| 1887 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1888 | - 'event_espresso' |
|
| 1889 | - ), |
|
| 1890 | - $this->_req_data['message_template_group_id'], |
|
| 1891 | - 'EE_Message_Template_Group' |
|
| 1892 | - ), |
|
| 1893 | - __FILE__, |
|
| 1894 | - __FUNCTION__, |
|
| 1895 | - __LINE__ |
|
| 1896 | - ); |
|
| 1897 | - $success = false; |
|
| 1898 | - } |
|
| 1899 | - if ($success) { |
|
| 1900 | - $success = $status === 'off' |
|
| 1901 | - ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1902 | - : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1903 | - } |
|
| 1904 | - $this->_template_args['success'] = $success; |
|
| 1905 | - $this->_return_json(); |
|
| 1906 | - } |
|
| 1862 | + $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1863 | + ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1864 | + : ''; |
|
| 1865 | + $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1866 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1867 | + $status = $this->_req_data['status']; |
|
| 1868 | + if ($status !== 'off' && $status !=='on') { |
|
| 1869 | + EE_Error::add_error( |
|
| 1870 | + sprintf( |
|
| 1871 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1872 | + $this->_req_data['status'] |
|
| 1873 | + ), |
|
| 1874 | + __FILE__, |
|
| 1875 | + __FUNCTION__, |
|
| 1876 | + __LINE__ |
|
| 1877 | + ); |
|
| 1878 | + $success = false; |
|
| 1879 | + } |
|
| 1880 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1881 | + $this->_req_data['message_template_group_id'] |
|
| 1882 | + ); |
|
| 1883 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1884 | + EE_Error::add_error( |
|
| 1885 | + sprintf( |
|
| 1886 | + esc_html__( |
|
| 1887 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1888 | + 'event_espresso' |
|
| 1889 | + ), |
|
| 1890 | + $this->_req_data['message_template_group_id'], |
|
| 1891 | + 'EE_Message_Template_Group' |
|
| 1892 | + ), |
|
| 1893 | + __FILE__, |
|
| 1894 | + __FUNCTION__, |
|
| 1895 | + __LINE__ |
|
| 1896 | + ); |
|
| 1897 | + $success = false; |
|
| 1898 | + } |
|
| 1899 | + if ($success) { |
|
| 1900 | + $success = $status === 'off' |
|
| 1901 | + ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1902 | + : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1903 | + } |
|
| 1904 | + $this->_template_args['success'] = $success; |
|
| 1905 | + $this->_return_json(); |
|
| 1906 | + } |
|
| 1907 | 1907 | |
| 1908 | 1908 | |
| 1909 | 1909 | |
| 1910 | - public function _add_form_element_before() |
|
| 1911 | - { |
|
| 1912 | - return '<form method="post" action="' |
|
| 1913 | - . $this->_template_args["edit_message_template_form_url"] |
|
| 1914 | - . '" id="ee-msg-edit-frm">'; |
|
| 1915 | - } |
|
| 1910 | + public function _add_form_element_before() |
|
| 1911 | + { |
|
| 1912 | + return '<form method="post" action="' |
|
| 1913 | + . $this->_template_args["edit_message_template_form_url"] |
|
| 1914 | + . '" id="ee-msg-edit-frm">'; |
|
| 1915 | + } |
|
| 1916 | 1916 | |
| 1917 | - public function _add_form_element_after() |
|
| 1918 | - { |
|
| 1919 | - return '</form>'; |
|
| 1920 | - } |
|
| 1917 | + public function _add_form_element_after() |
|
| 1918 | + { |
|
| 1919 | + return '</form>'; |
|
| 1920 | + } |
|
| 1921 | 1921 | |
| 1922 | 1922 | |
| 1923 | - /** |
|
| 1924 | - * This executes switching the template pack for a message template. |
|
| 1925 | - * |
|
| 1926 | - * @since 4.5.0 |
|
| 1927 | - * @throws EE_Error |
|
| 1928 | - * @throws InvalidDataTypeException |
|
| 1929 | - * @throws InvalidInterfaceException |
|
| 1930 | - * @throws InvalidArgumentException |
|
| 1931 | - * @throws ReflectionException |
|
| 1932 | - */ |
|
| 1933 | - public function switch_template_pack() |
|
| 1934 | - { |
|
| 1935 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1936 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1937 | - |
|
| 1938 | - //verify we have needed values. |
|
| 1939 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1940 | - $this->_template_args['error'] = true; |
|
| 1941 | - EE_Error::add_error( |
|
| 1942 | - esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1943 | - __FILE__, |
|
| 1944 | - __FUNCTION__, |
|
| 1945 | - __LINE__ |
|
| 1946 | - ); |
|
| 1947 | - } else { |
|
| 1948 | - //get template, set the new template_pack and then reset to default |
|
| 1949 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1950 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1923 | + /** |
|
| 1924 | + * This executes switching the template pack for a message template. |
|
| 1925 | + * |
|
| 1926 | + * @since 4.5.0 |
|
| 1927 | + * @throws EE_Error |
|
| 1928 | + * @throws InvalidDataTypeException |
|
| 1929 | + * @throws InvalidInterfaceException |
|
| 1930 | + * @throws InvalidArgumentException |
|
| 1931 | + * @throws ReflectionException |
|
| 1932 | + */ |
|
| 1933 | + public function switch_template_pack() |
|
| 1934 | + { |
|
| 1935 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1936 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1937 | + |
|
| 1938 | + //verify we have needed values. |
|
| 1939 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1940 | + $this->_template_args['error'] = true; |
|
| 1941 | + EE_Error::add_error( |
|
| 1942 | + esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1943 | + __FILE__, |
|
| 1944 | + __FUNCTION__, |
|
| 1945 | + __LINE__ |
|
| 1946 | + ); |
|
| 1947 | + } else { |
|
| 1948 | + //get template, set the new template_pack and then reset to default |
|
| 1949 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1950 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1951 | 1951 | |
| 1952 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1953 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1954 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1952 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1953 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1954 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1955 | 1955 | |
| 1956 | - $query_args = $this->_reset_to_default_template(); |
|
| 1956 | + $query_args = $this->_reset_to_default_template(); |
|
| 1957 | 1957 | |
| 1958 | - if (empty($query_args['id'])) { |
|
| 1959 | - EE_Error::add_error( |
|
| 1960 | - esc_html__( |
|
| 1961 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1962 | - 'event_espresso' |
|
| 1963 | - ), |
|
| 1964 | - __FILE__, |
|
| 1965 | - __FUNCTION__, |
|
| 1966 | - __LINE__ |
|
| 1967 | - ); |
|
| 1968 | - $this->_template_args['error'] = true; |
|
| 1969 | - } else { |
|
| 1970 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1971 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1972 | - EE_Error::add_success( |
|
| 1973 | - sprintf( |
|
| 1974 | - esc_html__( |
|
| 1975 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1976 | - 'event_espresso' |
|
| 1977 | - ), |
|
| 1978 | - $template_label, |
|
| 1979 | - $template_pack_labels->template_pack |
|
| 1980 | - ) |
|
| 1981 | - ); |
|
| 1982 | - //generate the redirect url for js. |
|
| 1983 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1984 | - $this->_admin_base_url); |
|
| 1985 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1986 | - $this->_template_args['success'] = true; |
|
| 1987 | - } |
|
| 1958 | + if (empty($query_args['id'])) { |
|
| 1959 | + EE_Error::add_error( |
|
| 1960 | + esc_html__( |
|
| 1961 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1962 | + 'event_espresso' |
|
| 1963 | + ), |
|
| 1964 | + __FILE__, |
|
| 1965 | + __FUNCTION__, |
|
| 1966 | + __LINE__ |
|
| 1967 | + ); |
|
| 1968 | + $this->_template_args['error'] = true; |
|
| 1969 | + } else { |
|
| 1970 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1971 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1972 | + EE_Error::add_success( |
|
| 1973 | + sprintf( |
|
| 1974 | + esc_html__( |
|
| 1975 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1976 | + 'event_espresso' |
|
| 1977 | + ), |
|
| 1978 | + $template_label, |
|
| 1979 | + $template_pack_labels->template_pack |
|
| 1980 | + ) |
|
| 1981 | + ); |
|
| 1982 | + //generate the redirect url for js. |
|
| 1983 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1984 | + $this->_admin_base_url); |
|
| 1985 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1986 | + $this->_template_args['success'] = true; |
|
| 1987 | + } |
|
| 1988 | 1988 | |
| 1989 | - $this->_return_json(); |
|
| 1989 | + $this->_return_json(); |
|
| 1990 | 1990 | |
| 1991 | - } |
|
| 1992 | - } |
|
| 1991 | + } |
|
| 1992 | + } |
|
| 1993 | 1993 | |
| 1994 | 1994 | |
| 1995 | - /** |
|
| 1996 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1997 | - * they want. |
|
| 1998 | - * |
|
| 1999 | - * @access protected |
|
| 2000 | - * @return array|null |
|
| 2001 | - * @throws EE_Error |
|
| 2002 | - * @throws InvalidArgumentException |
|
| 2003 | - * @throws InvalidDataTypeException |
|
| 2004 | - * @throws InvalidInterfaceException |
|
| 2005 | - */ |
|
| 2006 | - protected function _reset_to_default_template() |
|
| 2007 | - { |
|
| 2008 | - |
|
| 2009 | - $templates = array(); |
|
| 2010 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2011 | - //we need to make sure we've got the info we need. |
|
| 2012 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2013 | - EE_Error::add_error( |
|
| 2014 | - esc_html__( |
|
| 2015 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2016 | - 'event_espresso' |
|
| 2017 | - ), |
|
| 2018 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2019 | - ); |
|
| 2020 | - } |
|
| 2021 | - |
|
| 2022 | - // all templates will be reset to whatever the defaults are |
|
| 2023 | - // for the global template matching the messenger and message type. |
|
| 2024 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 2025 | - |
|
| 2026 | - if ($success) { |
|
| 1995 | + /** |
|
| 1996 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1997 | + * they want. |
|
| 1998 | + * |
|
| 1999 | + * @access protected |
|
| 2000 | + * @return array|null |
|
| 2001 | + * @throws EE_Error |
|
| 2002 | + * @throws InvalidArgumentException |
|
| 2003 | + * @throws InvalidDataTypeException |
|
| 2004 | + * @throws InvalidInterfaceException |
|
| 2005 | + */ |
|
| 2006 | + protected function _reset_to_default_template() |
|
| 2007 | + { |
|
| 2008 | + |
|
| 2009 | + $templates = array(); |
|
| 2010 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2011 | + //we need to make sure we've got the info we need. |
|
| 2012 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2013 | + EE_Error::add_error( |
|
| 2014 | + esc_html__( |
|
| 2015 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2016 | + 'event_espresso' |
|
| 2017 | + ), |
|
| 2018 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2019 | + ); |
|
| 2020 | + } |
|
| 2021 | + |
|
| 2022 | + // all templates will be reset to whatever the defaults are |
|
| 2023 | + // for the global template matching the messenger and message type. |
|
| 2024 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 2025 | + |
|
| 2026 | + if ($success) { |
|
| 2027 | 2027 | |
| 2028 | - //let's first determine if the incoming template is a global template, |
|
| 2029 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2030 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2028 | + //let's first determine if the incoming template is a global template, |
|
| 2029 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2030 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2031 | 2031 | |
| 2032 | 2032 | |
| 2033 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2034 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2033 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2034 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2035 | 2035 | |
| 2036 | - if ($success) { |
|
| 2037 | - // if successfully deleted, lets generate the new ones. |
|
| 2038 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2039 | - // will use the related global template defaults for regeneration. |
|
| 2040 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2041 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 2042 | - // for the current custom template when resetting. |
|
| 2043 | - $templates = $this->_generate_new_templates( |
|
| 2044 | - $this->_req_data['msgr'], |
|
| 2045 | - $this->_req_data['mt'], |
|
| 2046 | - $GRP_ID, |
|
| 2047 | - true |
|
| 2048 | - ); |
|
| 2049 | - } |
|
| 2036 | + if ($success) { |
|
| 2037 | + // if successfully deleted, lets generate the new ones. |
|
| 2038 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2039 | + // will use the related global template defaults for regeneration. |
|
| 2040 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2041 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 2042 | + // for the current custom template when resetting. |
|
| 2043 | + $templates = $this->_generate_new_templates( |
|
| 2044 | + $this->_req_data['msgr'], |
|
| 2045 | + $this->_req_data['mt'], |
|
| 2046 | + $GRP_ID, |
|
| 2047 | + true |
|
| 2048 | + ); |
|
| 2049 | + } |
|
| 2050 | 2050 | |
| 2051 | - } |
|
| 2052 | - |
|
| 2053 | - //any error messages? |
|
| 2054 | - if ( ! $success) { |
|
| 2055 | - EE_Error::add_error( |
|
| 2056 | - esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2057 | - 'event_espresso'), |
|
| 2058 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2059 | - ); |
|
| 2060 | - } |
|
| 2061 | - |
|
| 2062 | - //all good, let's add a success message! |
|
| 2063 | - if ($success && ! empty($templates)) { |
|
| 2064 | - //the info for the template we generated is the first element in the returned array |
|
| 2065 | - // $templates = $templates[0]; |
|
| 2066 | - EE_Error::overwrite_success(); |
|
| 2067 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2068 | - } |
|
| 2069 | - |
|
| 2070 | - |
|
| 2071 | - $query_args = array( |
|
| 2072 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2073 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2074 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2075 | - ); |
|
| 2076 | - |
|
| 2077 | - //if called via ajax then we return query args otherwise redirect |
|
| 2078 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2079 | - return $query_args; |
|
| 2080 | - } else { |
|
| 2081 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2051 | + } |
|
| 2052 | + |
|
| 2053 | + //any error messages? |
|
| 2054 | + if ( ! $success) { |
|
| 2055 | + EE_Error::add_error( |
|
| 2056 | + esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2057 | + 'event_espresso'), |
|
| 2058 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2059 | + ); |
|
| 2060 | + } |
|
| 2061 | + |
|
| 2062 | + //all good, let's add a success message! |
|
| 2063 | + if ($success && ! empty($templates)) { |
|
| 2064 | + //the info for the template we generated is the first element in the returned array |
|
| 2065 | + // $templates = $templates[0]; |
|
| 2066 | + EE_Error::overwrite_success(); |
|
| 2067 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2068 | + } |
|
| 2069 | + |
|
| 2070 | + |
|
| 2071 | + $query_args = array( |
|
| 2072 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2073 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2074 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2075 | + ); |
|
| 2076 | + |
|
| 2077 | + //if called via ajax then we return query args otherwise redirect |
|
| 2078 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2079 | + return $query_args; |
|
| 2080 | + } else { |
|
| 2081 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2082 | 2082 | |
| 2083 | - return null; |
|
| 2084 | - } |
|
| 2085 | - } |
|
| 2083 | + return null; |
|
| 2084 | + } |
|
| 2085 | + } |
|
| 2086 | 2086 | |
| 2087 | 2087 | |
| 2088 | - /** |
|
| 2089 | - * Retrieve and set the message preview for display. |
|
| 2090 | - * |
|
| 2091 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2092 | - * @return string |
|
| 2093 | - * @throws ReflectionException |
|
| 2094 | - * @throws EE_Error |
|
| 2095 | - * @throws InvalidArgumentException |
|
| 2096 | - * @throws InvalidDataTypeException |
|
| 2097 | - * @throws InvalidInterfaceException |
|
| 2098 | - */ |
|
| 2099 | - public function _preview_message($send = false) |
|
| 2100 | - { |
|
| 2101 | - //first make sure we've got the necessary parameters |
|
| 2102 | - if ( |
|
| 2103 | - ! isset( |
|
| 2104 | - $this->_req_data['message_type'], |
|
| 2105 | - $this->_req_data['messenger'], |
|
| 2106 | - $this->_req_data['messenger'], |
|
| 2107 | - $this->_req_data['GRP_ID'] |
|
| 2108 | - ) |
|
| 2109 | - ) { |
|
| 2110 | - EE_Error::add_error( |
|
| 2111 | - esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2112 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | - ); |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2117 | - |
|
| 2118 | - |
|
| 2119 | - //get the preview! |
|
| 2120 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2121 | - $this->_req_data['messenger'], $send); |
|
| 2122 | - |
|
| 2123 | - if ($send) { |
|
| 2124 | - return $preview; |
|
| 2125 | - } |
|
| 2126 | - |
|
| 2127 | - //let's add a button to go back to the edit view |
|
| 2128 | - $query_args = array( |
|
| 2129 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2130 | - 'context' => $this->_req_data['context'], |
|
| 2131 | - 'action' => 'edit_message_template' |
|
| 2132 | - ); |
|
| 2133 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2134 | - $preview_button = '<a href="' |
|
| 2135 | - . $go_back_url |
|
| 2136 | - . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2137 | - . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2138 | - . '</a>'; |
|
| 2139 | - $message_types = $this->get_installed_message_types(); |
|
| 2140 | - $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2141 | - $this->_req_data['messenger'] |
|
| 2142 | - ); |
|
| 2143 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2144 | - ? ucwords($active_messenger->label['singular']) |
|
| 2145 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2146 | - //let's provide a helpful title for context |
|
| 2147 | - $preview_title = sprintf( |
|
| 2148 | - esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2149 | - $active_messenger_label, |
|
| 2150 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2151 | - ); |
|
| 2152 | - //setup display of preview. |
|
| 2153 | - $this->_admin_page_title = $preview_title; |
|
| 2154 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; |
|
| 2155 | - $this->_template_args['data']['force_json'] = true; |
|
| 2156 | - |
|
| 2157 | - return ''; |
|
| 2158 | - } |
|
| 2088 | + /** |
|
| 2089 | + * Retrieve and set the message preview for display. |
|
| 2090 | + * |
|
| 2091 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2092 | + * @return string |
|
| 2093 | + * @throws ReflectionException |
|
| 2094 | + * @throws EE_Error |
|
| 2095 | + * @throws InvalidArgumentException |
|
| 2096 | + * @throws InvalidDataTypeException |
|
| 2097 | + * @throws InvalidInterfaceException |
|
| 2098 | + */ |
|
| 2099 | + public function _preview_message($send = false) |
|
| 2100 | + { |
|
| 2101 | + //first make sure we've got the necessary parameters |
|
| 2102 | + if ( |
|
| 2103 | + ! isset( |
|
| 2104 | + $this->_req_data['message_type'], |
|
| 2105 | + $this->_req_data['messenger'], |
|
| 2106 | + $this->_req_data['messenger'], |
|
| 2107 | + $this->_req_data['GRP_ID'] |
|
| 2108 | + ) |
|
| 2109 | + ) { |
|
| 2110 | + EE_Error::add_error( |
|
| 2111 | + esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2112 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | + ); |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2117 | + |
|
| 2118 | + |
|
| 2119 | + //get the preview! |
|
| 2120 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2121 | + $this->_req_data['messenger'], $send); |
|
| 2122 | + |
|
| 2123 | + if ($send) { |
|
| 2124 | + return $preview; |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + //let's add a button to go back to the edit view |
|
| 2128 | + $query_args = array( |
|
| 2129 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2130 | + 'context' => $this->_req_data['context'], |
|
| 2131 | + 'action' => 'edit_message_template' |
|
| 2132 | + ); |
|
| 2133 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2134 | + $preview_button = '<a href="' |
|
| 2135 | + . $go_back_url |
|
| 2136 | + . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2137 | + . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2138 | + . '</a>'; |
|
| 2139 | + $message_types = $this->get_installed_message_types(); |
|
| 2140 | + $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2141 | + $this->_req_data['messenger'] |
|
| 2142 | + ); |
|
| 2143 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2144 | + ? ucwords($active_messenger->label['singular']) |
|
| 2145 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2146 | + //let's provide a helpful title for context |
|
| 2147 | + $preview_title = sprintf( |
|
| 2148 | + esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2149 | + $active_messenger_label, |
|
| 2150 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2151 | + ); |
|
| 2152 | + //setup display of preview. |
|
| 2153 | + $this->_admin_page_title = $preview_title; |
|
| 2154 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; |
|
| 2155 | + $this->_template_args['data']['force_json'] = true; |
|
| 2156 | + |
|
| 2157 | + return ''; |
|
| 2158 | + } |
|
| 2159 | 2159 | |
| 2160 | 2160 | |
| 2161 | - /** |
|
| 2162 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2163 | - * gets called automatically. |
|
| 2164 | - * |
|
| 2165 | - * @since 4.5.0 |
|
| 2166 | - * |
|
| 2167 | - * @return string |
|
| 2168 | - */ |
|
| 2169 | - protected function _display_preview_message() |
|
| 2170 | - { |
|
| 2171 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2172 | - } |
|
| 2161 | + /** |
|
| 2162 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2163 | + * gets called automatically. |
|
| 2164 | + * |
|
| 2165 | + * @since 4.5.0 |
|
| 2166 | + * |
|
| 2167 | + * @return string |
|
| 2168 | + */ |
|
| 2169 | + protected function _display_preview_message() |
|
| 2170 | + { |
|
| 2171 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2172 | + } |
|
| 2173 | 2173 | |
| 2174 | 2174 | |
| 2175 | - /** |
|
| 2176 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2177 | - * |
|
| 2178 | - * @access protected |
|
| 2179 | - * @return void |
|
| 2180 | - */ |
|
| 2181 | - protected function _register_edit_meta_boxes() |
|
| 2182 | - { |
|
| 2183 | - add_meta_box( |
|
| 2184 | - 'mtp_valid_shortcodes', |
|
| 2185 | - esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2186 | - array($this, 'shortcode_meta_box'), |
|
| 2187 | - $this->_current_screen->id, |
|
| 2188 | - 'side', |
|
| 2189 | - 'default'); |
|
| 2190 | - add_meta_box( |
|
| 2191 | - 'mtp_extra_actions', |
|
| 2192 | - esc_html__('Extra Actions', 'event_espresso'), |
|
| 2193 | - array($this, 'extra_actions_meta_box'), |
|
| 2194 | - $this->_current_screen->id, |
|
| 2195 | - 'side', |
|
| 2196 | - 'high' |
|
| 2197 | - ); |
|
| 2198 | - add_meta_box( |
|
| 2199 | - 'mtp_templates', |
|
| 2200 | - esc_html__('Template Styles', 'event_espresso'), |
|
| 2201 | - array($this, 'template_pack_meta_box'), |
|
| 2202 | - $this->_current_screen->id, |
|
| 2203 | - 'side', |
|
| 2204 | - 'high' |
|
| 2205 | - ); |
|
| 2206 | - } |
|
| 2175 | + /** |
|
| 2176 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2177 | + * |
|
| 2178 | + * @access protected |
|
| 2179 | + * @return void |
|
| 2180 | + */ |
|
| 2181 | + protected function _register_edit_meta_boxes() |
|
| 2182 | + { |
|
| 2183 | + add_meta_box( |
|
| 2184 | + 'mtp_valid_shortcodes', |
|
| 2185 | + esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2186 | + array($this, 'shortcode_meta_box'), |
|
| 2187 | + $this->_current_screen->id, |
|
| 2188 | + 'side', |
|
| 2189 | + 'default'); |
|
| 2190 | + add_meta_box( |
|
| 2191 | + 'mtp_extra_actions', |
|
| 2192 | + esc_html__('Extra Actions', 'event_espresso'), |
|
| 2193 | + array($this, 'extra_actions_meta_box'), |
|
| 2194 | + $this->_current_screen->id, |
|
| 2195 | + 'side', |
|
| 2196 | + 'high' |
|
| 2197 | + ); |
|
| 2198 | + add_meta_box( |
|
| 2199 | + 'mtp_templates', |
|
| 2200 | + esc_html__('Template Styles', 'event_espresso'), |
|
| 2201 | + array($this, 'template_pack_meta_box'), |
|
| 2202 | + $this->_current_screen->id, |
|
| 2203 | + 'side', |
|
| 2204 | + 'high' |
|
| 2205 | + ); |
|
| 2206 | + } |
|
| 2207 | 2207 | |
| 2208 | 2208 | |
| 2209 | - /** |
|
| 2210 | - * metabox content for all template pack and variation selection. |
|
| 2211 | - * |
|
| 2212 | - * @since 4.5.0 |
|
| 2213 | - * @return string |
|
| 2214 | - * @throws DomainException |
|
| 2215 | - * @throws EE_Error |
|
| 2216 | - * @throws InvalidArgumentException |
|
| 2217 | - * @throws ReflectionException |
|
| 2218 | - * @throws InvalidDataTypeException |
|
| 2219 | - * @throws InvalidInterfaceException |
|
| 2220 | - */ |
|
| 2221 | - public function template_pack_meta_box() |
|
| 2222 | - { |
|
| 2223 | - $this->_set_message_template_group(); |
|
| 2224 | - |
|
| 2225 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2226 | - |
|
| 2227 | - $tp_select_values = array(); |
|
| 2228 | - |
|
| 2229 | - foreach ($tp_collection as $tp) { |
|
| 2230 | - //only include template packs that support this messenger and message type! |
|
| 2231 | - $supports = $tp->get_supports(); |
|
| 2232 | - if ( |
|
| 2233 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2234 | - || ! in_array( |
|
| 2235 | - $this->_message_template_group->message_type(), |
|
| 2236 | - $supports[$this->_message_template_group->messenger()], |
|
| 2237 | - true |
|
| 2238 | - ) |
|
| 2239 | - ) { |
|
| 2240 | - //not supported |
|
| 2241 | - continue; |
|
| 2242 | - } |
|
| 2209 | + /** |
|
| 2210 | + * metabox content for all template pack and variation selection. |
|
| 2211 | + * |
|
| 2212 | + * @since 4.5.0 |
|
| 2213 | + * @return string |
|
| 2214 | + * @throws DomainException |
|
| 2215 | + * @throws EE_Error |
|
| 2216 | + * @throws InvalidArgumentException |
|
| 2217 | + * @throws ReflectionException |
|
| 2218 | + * @throws InvalidDataTypeException |
|
| 2219 | + * @throws InvalidInterfaceException |
|
| 2220 | + */ |
|
| 2221 | + public function template_pack_meta_box() |
|
| 2222 | + { |
|
| 2223 | + $this->_set_message_template_group(); |
|
| 2224 | + |
|
| 2225 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2226 | + |
|
| 2227 | + $tp_select_values = array(); |
|
| 2228 | + |
|
| 2229 | + foreach ($tp_collection as $tp) { |
|
| 2230 | + //only include template packs that support this messenger and message type! |
|
| 2231 | + $supports = $tp->get_supports(); |
|
| 2232 | + if ( |
|
| 2233 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2234 | + || ! in_array( |
|
| 2235 | + $this->_message_template_group->message_type(), |
|
| 2236 | + $supports[$this->_message_template_group->messenger()], |
|
| 2237 | + true |
|
| 2238 | + ) |
|
| 2239 | + ) { |
|
| 2240 | + //not supported |
|
| 2241 | + continue; |
|
| 2242 | + } |
|
| 2243 | 2243 | |
| 2244 | - $tp_select_values[] = array( |
|
| 2245 | - 'text' => $tp->label, |
|
| 2246 | - 'id' => $tp->dbref |
|
| 2247 | - ); |
|
| 2248 | - } |
|
| 2249 | - |
|
| 2250 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2251 | - // the default template pack. This still allows for the odd template pack to override. |
|
| 2252 | - if (empty($tp_select_values)) { |
|
| 2253 | - $tp_select_values[] = array( |
|
| 2254 | - 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2255 | - 'id' => 'default' |
|
| 2256 | - ); |
|
| 2257 | - } |
|
| 2258 | - |
|
| 2259 | - //setup variation select values for the currently selected template. |
|
| 2260 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2261 | - $this->_message_template_group->messenger(), |
|
| 2262 | - $this->_message_template_group->message_type() |
|
| 2263 | - ); |
|
| 2264 | - $variations_select_values = array(); |
|
| 2265 | - foreach ($variations as $variation => $label) { |
|
| 2266 | - $variations_select_values[] = array( |
|
| 2267 | - 'text' => $label, |
|
| 2268 | - 'id' => $variation |
|
| 2269 | - ); |
|
| 2270 | - } |
|
| 2271 | - |
|
| 2272 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2273 | - |
|
| 2274 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2275 | - 'MTP_template_pack', |
|
| 2276 | - $tp_select_values, |
|
| 2277 | - $this->_message_template_group->get_template_pack_name() |
|
| 2278 | - ); |
|
| 2279 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2280 | - 'MTP_template_variation', |
|
| 2281 | - $variations_select_values, |
|
| 2282 | - $this->_message_template_group->get_template_pack_variation() |
|
| 2283 | - ); |
|
| 2284 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2285 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2286 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2287 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2288 | - |
|
| 2289 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2290 | - |
|
| 2291 | - EEH_Template::display_template($template, $template_args); |
|
| 2292 | - } |
|
| 2244 | + $tp_select_values[] = array( |
|
| 2245 | + 'text' => $tp->label, |
|
| 2246 | + 'id' => $tp->dbref |
|
| 2247 | + ); |
|
| 2248 | + } |
|
| 2249 | + |
|
| 2250 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2251 | + // the default template pack. This still allows for the odd template pack to override. |
|
| 2252 | + if (empty($tp_select_values)) { |
|
| 2253 | + $tp_select_values[] = array( |
|
| 2254 | + 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2255 | + 'id' => 'default' |
|
| 2256 | + ); |
|
| 2257 | + } |
|
| 2258 | + |
|
| 2259 | + //setup variation select values for the currently selected template. |
|
| 2260 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2261 | + $this->_message_template_group->messenger(), |
|
| 2262 | + $this->_message_template_group->message_type() |
|
| 2263 | + ); |
|
| 2264 | + $variations_select_values = array(); |
|
| 2265 | + foreach ($variations as $variation => $label) { |
|
| 2266 | + $variations_select_values[] = array( |
|
| 2267 | + 'text' => $label, |
|
| 2268 | + 'id' => $variation |
|
| 2269 | + ); |
|
| 2270 | + } |
|
| 2271 | + |
|
| 2272 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2273 | + |
|
| 2274 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2275 | + 'MTP_template_pack', |
|
| 2276 | + $tp_select_values, |
|
| 2277 | + $this->_message_template_group->get_template_pack_name() |
|
| 2278 | + ); |
|
| 2279 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2280 | + 'MTP_template_variation', |
|
| 2281 | + $variations_select_values, |
|
| 2282 | + $this->_message_template_group->get_template_pack_variation() |
|
| 2283 | + ); |
|
| 2284 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2285 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2286 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2287 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2288 | + |
|
| 2289 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2290 | + |
|
| 2291 | + EEH_Template::display_template($template, $template_args); |
|
| 2292 | + } |
|
| 2293 | 2293 | |
| 2294 | 2294 | |
| 2295 | - /** |
|
| 2296 | - * This meta box holds any extra actions related to Message Templates |
|
| 2297 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2298 | - * |
|
| 2299 | - * @access public |
|
| 2300 | - * @return void |
|
| 2301 | - * @throws EE_Error |
|
| 2302 | - */ |
|
| 2303 | - public function extra_actions_meta_box() |
|
| 2304 | - { |
|
| 2305 | - $template_form_fields = array(); |
|
| 2306 | - |
|
| 2307 | - $extra_args = array( |
|
| 2308 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2309 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2310 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2311 | - ); |
|
| 2312 | - //first we need to see if there are any fields |
|
| 2313 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2314 | - |
|
| 2315 | - if ( ! empty($fields)) { |
|
| 2316 | - //yup there be fields |
|
| 2317 | - foreach ($fields as $field => $config) { |
|
| 2318 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2319 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2320 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2321 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2295 | + /** |
|
| 2296 | + * This meta box holds any extra actions related to Message Templates |
|
| 2297 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2298 | + * |
|
| 2299 | + * @access public |
|
| 2300 | + * @return void |
|
| 2301 | + * @throws EE_Error |
|
| 2302 | + */ |
|
| 2303 | + public function extra_actions_meta_box() |
|
| 2304 | + { |
|
| 2305 | + $template_form_fields = array(); |
|
| 2306 | + |
|
| 2307 | + $extra_args = array( |
|
| 2308 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2309 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2310 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2311 | + ); |
|
| 2312 | + //first we need to see if there are any fields |
|
| 2313 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2314 | + |
|
| 2315 | + if ( ! empty($fields)) { |
|
| 2316 | + //yup there be fields |
|
| 2317 | + foreach ($fields as $field => $config) { |
|
| 2318 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2319 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2320 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2321 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2322 | 2322 | |
| 2323 | - // if type is hidden and the value is empty |
|
| 2324 | - // something may have gone wrong so let's correct with the defaults |
|
| 2325 | - $fix = $config['input'] === 'hidden' |
|
| 2326 | - && isset($existing[$field]) |
|
| 2327 | - && empty($existing[$field]) |
|
| 2328 | - ? $default |
|
| 2329 | - : ''; |
|
| 2330 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2331 | - ? $existing[$field] |
|
| 2332 | - : $fix; |
|
| 2323 | + // if type is hidden and the value is empty |
|
| 2324 | + // something may have gone wrong so let's correct with the defaults |
|
| 2325 | + $fix = $config['input'] === 'hidden' |
|
| 2326 | + && isset($existing[$field]) |
|
| 2327 | + && empty($existing[$field]) |
|
| 2328 | + ? $default |
|
| 2329 | + : ''; |
|
| 2330 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2331 | + ? $existing[$field] |
|
| 2332 | + : $fix; |
|
| 2333 | 2333 | |
| 2334 | - $template_form_fields[$field_id] = array( |
|
| 2335 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2336 | - 'label' => $config['label'], |
|
| 2337 | - 'input' => $config['input'], |
|
| 2338 | - 'type' => $config['type'], |
|
| 2339 | - 'required' => $config['required'], |
|
| 2340 | - 'validation' => $config['validation'], |
|
| 2341 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2342 | - 'css_class' => $config['css_class'], |
|
| 2343 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2344 | - 'default' => $default, |
|
| 2345 | - 'format' => $config['format'] |
|
| 2346 | - ); |
|
| 2347 | - } |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2351 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2352 | - : ''; |
|
| 2353 | - |
|
| 2354 | - $test_settings_html = ''; |
|
| 2355 | - //print out $test_settings_fields |
|
| 2356 | - if ( ! empty($test_settings_fields)) { |
|
| 2357 | - echo $test_settings_fields; |
|
| 2358 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2359 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2360 | - $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2361 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2362 | - } |
|
| 2363 | - |
|
| 2364 | - //and button |
|
| 2365 | - $test_settings_html .= '<p>' |
|
| 2366 | - . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2367 | - . '</p>'; |
|
| 2368 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2369 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2370 | - 'reset_to_default', |
|
| 2371 | - 'reset', |
|
| 2372 | - $extra_args, |
|
| 2373 | - 'button-primary reset-default-button' |
|
| 2374 | - ); |
|
| 2375 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2376 | - echo $test_settings_html; |
|
| 2377 | - } |
|
| 2334 | + $template_form_fields[$field_id] = array( |
|
| 2335 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2336 | + 'label' => $config['label'], |
|
| 2337 | + 'input' => $config['input'], |
|
| 2338 | + 'type' => $config['type'], |
|
| 2339 | + 'required' => $config['required'], |
|
| 2340 | + 'validation' => $config['validation'], |
|
| 2341 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2342 | + 'css_class' => $config['css_class'], |
|
| 2343 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2344 | + 'default' => $default, |
|
| 2345 | + 'format' => $config['format'] |
|
| 2346 | + ); |
|
| 2347 | + } |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2351 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2352 | + : ''; |
|
| 2353 | + |
|
| 2354 | + $test_settings_html = ''; |
|
| 2355 | + //print out $test_settings_fields |
|
| 2356 | + if ( ! empty($test_settings_fields)) { |
|
| 2357 | + echo $test_settings_fields; |
|
| 2358 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2359 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2360 | + $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2361 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2362 | + } |
|
| 2363 | + |
|
| 2364 | + //and button |
|
| 2365 | + $test_settings_html .= '<p>' |
|
| 2366 | + . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2367 | + . '</p>'; |
|
| 2368 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2369 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2370 | + 'reset_to_default', |
|
| 2371 | + 'reset', |
|
| 2372 | + $extra_args, |
|
| 2373 | + 'button-primary reset-default-button' |
|
| 2374 | + ); |
|
| 2375 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2376 | + echo $test_settings_html; |
|
| 2377 | + } |
|
| 2378 | 2378 | |
| 2379 | 2379 | |
| 2380 | - /** |
|
| 2381 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2382 | - * |
|
| 2383 | - * @since 4.9.rc.000 |
|
| 2384 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2385 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2386 | - * @return string |
|
| 2387 | - * @throws DomainException |
|
| 2388 | - * @throws EE_Error |
|
| 2389 | - * @throws InvalidArgumentException |
|
| 2390 | - * @throws ReflectionException |
|
| 2391 | - * @throws InvalidDataTypeException |
|
| 2392 | - * @throws InvalidInterfaceException |
|
| 2393 | - */ |
|
| 2394 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2395 | - { |
|
| 2396 | - $template_args = array( |
|
| 2397 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2398 | - 'fieldname' => $field, |
|
| 2399 | - 'linked_input_id' => $linked_input_id |
|
| 2400 | - ); |
|
| 2401 | - |
|
| 2402 | - return EEH_Template::display_template( |
|
| 2403 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2404 | - $template_args, |
|
| 2405 | - true |
|
| 2406 | - ); |
|
| 2407 | - } |
|
| 2380 | + /** |
|
| 2381 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2382 | + * |
|
| 2383 | + * @since 4.9.rc.000 |
|
| 2384 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2385 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2386 | + * @return string |
|
| 2387 | + * @throws DomainException |
|
| 2388 | + * @throws EE_Error |
|
| 2389 | + * @throws InvalidArgumentException |
|
| 2390 | + * @throws ReflectionException |
|
| 2391 | + * @throws InvalidDataTypeException |
|
| 2392 | + * @throws InvalidInterfaceException |
|
| 2393 | + */ |
|
| 2394 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2395 | + { |
|
| 2396 | + $template_args = array( |
|
| 2397 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2398 | + 'fieldname' => $field, |
|
| 2399 | + 'linked_input_id' => $linked_input_id |
|
| 2400 | + ); |
|
| 2401 | + |
|
| 2402 | + return EEH_Template::display_template( |
|
| 2403 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2404 | + $template_args, |
|
| 2405 | + true |
|
| 2406 | + ); |
|
| 2407 | + } |
|
| 2408 | 2408 | |
| 2409 | 2409 | |
| 2410 | - /** |
|
| 2411 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2412 | - * page) |
|
| 2413 | - * |
|
| 2414 | - * @access public |
|
| 2415 | - * @return void |
|
| 2416 | - * @throws EE_Error |
|
| 2417 | - * @throws InvalidArgumentException |
|
| 2418 | - * @throws ReflectionException |
|
| 2419 | - * @throws InvalidDataTypeException |
|
| 2420 | - * @throws InvalidInterfaceException |
|
| 2421 | - */ |
|
| 2422 | - public function shortcode_meta_box() |
|
| 2423 | - { |
|
| 2424 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2425 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2426 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2427 | - if (empty($shortcodes)) { |
|
| 2428 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2429 | - echo $content; |
|
| 2430 | - } else { |
|
| 2431 | - //$alt = 0; |
|
| 2432 | - ?> |
|
| 2410 | + /** |
|
| 2411 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2412 | + * page) |
|
| 2413 | + * |
|
| 2414 | + * @access public |
|
| 2415 | + * @return void |
|
| 2416 | + * @throws EE_Error |
|
| 2417 | + * @throws InvalidArgumentException |
|
| 2418 | + * @throws ReflectionException |
|
| 2419 | + * @throws InvalidDataTypeException |
|
| 2420 | + * @throws InvalidInterfaceException |
|
| 2421 | + */ |
|
| 2422 | + public function shortcode_meta_box() |
|
| 2423 | + { |
|
| 2424 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2425 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2426 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2427 | + if (empty($shortcodes)) { |
|
| 2428 | + $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2429 | + echo $content; |
|
| 2430 | + } else { |
|
| 2431 | + //$alt = 0; |
|
| 2432 | + ?> |
|
| 2433 | 2433 | <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2434 | 2434 | <p class="small-text"><?php printf( |
| 2435 | - esc_html__( |
|
| 2436 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2437 | - 'event_espresso' |
|
| 2438 | - ), |
|
| 2439 | - '<span class="dashicons dashicons-menu"></span>' |
|
| 2440 | - ); ?></p> |
|
| 2435 | + esc_html__( |
|
| 2436 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2437 | + 'event_espresso' |
|
| 2438 | + ), |
|
| 2439 | + '<span class="dashicons dashicons-menu"></span>' |
|
| 2440 | + ); ?></p> |
|
| 2441 | 2441 | <?php |
| 2442 | - } |
|
| 2442 | + } |
|
| 2443 | 2443 | |
| 2444 | 2444 | |
| 2445 | - } |
|
| 2445 | + } |
|
| 2446 | 2446 | |
| 2447 | 2447 | |
| 2448 | - /** |
|
| 2449 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2450 | - * |
|
| 2451 | - * @access protected |
|
| 2452 | - * @return void |
|
| 2453 | - * @throws EE_Error |
|
| 2454 | - * @throws InvalidArgumentException |
|
| 2455 | - * @throws ReflectionException |
|
| 2456 | - * @throws InvalidDataTypeException |
|
| 2457 | - * @throws InvalidInterfaceException |
|
| 2458 | - */ |
|
| 2459 | - protected function _set_shortcodes() |
|
| 2460 | - { |
|
| 2461 | - |
|
| 2462 | - //no need to run this if the property is already set |
|
| 2463 | - if ( ! empty($this->_shortcodes)) { |
|
| 2464 | - return; |
|
| 2465 | - } |
|
| 2466 | - |
|
| 2467 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2468 | - } |
|
| 2448 | + /** |
|
| 2449 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2450 | + * |
|
| 2451 | + * @access protected |
|
| 2452 | + * @return void |
|
| 2453 | + * @throws EE_Error |
|
| 2454 | + * @throws InvalidArgumentException |
|
| 2455 | + * @throws ReflectionException |
|
| 2456 | + * @throws InvalidDataTypeException |
|
| 2457 | + * @throws InvalidInterfaceException |
|
| 2458 | + */ |
|
| 2459 | + protected function _set_shortcodes() |
|
| 2460 | + { |
|
| 2461 | + |
|
| 2462 | + //no need to run this if the property is already set |
|
| 2463 | + if ( ! empty($this->_shortcodes)) { |
|
| 2464 | + return; |
|
| 2465 | + } |
|
| 2466 | + |
|
| 2467 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2468 | + } |
|
| 2469 | 2469 | |
| 2470 | 2470 | |
| 2471 | - /** |
|
| 2472 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2473 | - * property) |
|
| 2474 | - * |
|
| 2475 | - * @access protected |
|
| 2476 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2477 | - * for. Defaults to all (for the given context) |
|
| 2478 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2479 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2480 | - * true just an array of shortcode/label pairs. |
|
| 2481 | - * @throws EE_Error |
|
| 2482 | - * @throws InvalidArgumentException |
|
| 2483 | - * @throws ReflectionException |
|
| 2484 | - * @throws InvalidDataTypeException |
|
| 2485 | - * @throws InvalidInterfaceException |
|
| 2486 | - */ |
|
| 2487 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2488 | - { |
|
| 2489 | - $this->_set_message_template_group(); |
|
| 2490 | - |
|
| 2491 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2492 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2493 | - ? absint($this->_req_data['id']) |
|
| 2494 | - : false; |
|
| 2495 | - $context = isset($this->_req_data['context']) |
|
| 2496 | - ? $this->_req_data['context'] |
|
| 2497 | - : key($this->_message_template_group->contexts_config()); |
|
| 2498 | - |
|
| 2499 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2500 | - } |
|
| 2471 | + /** |
|
| 2472 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2473 | + * property) |
|
| 2474 | + * |
|
| 2475 | + * @access protected |
|
| 2476 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2477 | + * for. Defaults to all (for the given context) |
|
| 2478 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2479 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2480 | + * true just an array of shortcode/label pairs. |
|
| 2481 | + * @throws EE_Error |
|
| 2482 | + * @throws InvalidArgumentException |
|
| 2483 | + * @throws ReflectionException |
|
| 2484 | + * @throws InvalidDataTypeException |
|
| 2485 | + * @throws InvalidInterfaceException |
|
| 2486 | + */ |
|
| 2487 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2488 | + { |
|
| 2489 | + $this->_set_message_template_group(); |
|
| 2490 | + |
|
| 2491 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2492 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2493 | + ? absint($this->_req_data['id']) |
|
| 2494 | + : false; |
|
| 2495 | + $context = isset($this->_req_data['context']) |
|
| 2496 | + ? $this->_req_data['context'] |
|
| 2497 | + : key($this->_message_template_group->contexts_config()); |
|
| 2498 | + |
|
| 2499 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2500 | + } |
|
| 2501 | 2501 | |
| 2502 | 2502 | |
| 2503 | - /** |
|
| 2504 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2505 | - * |
|
| 2506 | - * @access protected |
|
| 2507 | - * @return void |
|
| 2508 | - * @throws EE_Error |
|
| 2509 | - * @throws InvalidArgumentException |
|
| 2510 | - * @throws ReflectionException |
|
| 2511 | - * @throws InvalidDataTypeException |
|
| 2512 | - * @throws InvalidInterfaceException |
|
| 2513 | - */ |
|
| 2514 | - protected function _set_message_template_group() |
|
| 2515 | - { |
|
| 2516 | - |
|
| 2517 | - if ( ! empty($this->_message_template_group)) { |
|
| 2518 | - return; |
|
| 2519 | - } //get out if this is already set. |
|
| 2520 | - |
|
| 2521 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2522 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2523 | - |
|
| 2524 | - //let's get the message templates |
|
| 2525 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2526 | - |
|
| 2527 | - if (empty($GRP_ID)) { |
|
| 2528 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2529 | - } else { |
|
| 2530 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2531 | - } |
|
| 2532 | - |
|
| 2533 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2534 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2535 | - |
|
| 2536 | - } |
|
| 2503 | + /** |
|
| 2504 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2505 | + * |
|
| 2506 | + * @access protected |
|
| 2507 | + * @return void |
|
| 2508 | + * @throws EE_Error |
|
| 2509 | + * @throws InvalidArgumentException |
|
| 2510 | + * @throws ReflectionException |
|
| 2511 | + * @throws InvalidDataTypeException |
|
| 2512 | + * @throws InvalidInterfaceException |
|
| 2513 | + */ |
|
| 2514 | + protected function _set_message_template_group() |
|
| 2515 | + { |
|
| 2516 | + |
|
| 2517 | + if ( ! empty($this->_message_template_group)) { |
|
| 2518 | + return; |
|
| 2519 | + } //get out if this is already set. |
|
| 2520 | + |
|
| 2521 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2522 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2523 | + |
|
| 2524 | + //let's get the message templates |
|
| 2525 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2526 | + |
|
| 2527 | + if (empty($GRP_ID)) { |
|
| 2528 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2529 | + } else { |
|
| 2530 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2531 | + } |
|
| 2532 | + |
|
| 2533 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2534 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2535 | + |
|
| 2536 | + } |
|
| 2537 | 2537 | |
| 2538 | 2538 | |
| 2539 | - /** |
|
| 2540 | - * sets up a context switcher for edit forms |
|
| 2541 | - * |
|
| 2542 | - * @access protected |
|
| 2543 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2544 | - * @param array $args various things the context switcher needs. |
|
| 2545 | - * @throws EE_Error |
|
| 2546 | - */ |
|
| 2547 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2548 | - { |
|
| 2549 | - $context_details = $template_group_object->contexts_config(); |
|
| 2550 | - $context_label = $template_group_object->context_label(); |
|
| 2551 | - ob_start(); |
|
| 2552 | - ?> |
|
| 2539 | + /** |
|
| 2540 | + * sets up a context switcher for edit forms |
|
| 2541 | + * |
|
| 2542 | + * @access protected |
|
| 2543 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2544 | + * @param array $args various things the context switcher needs. |
|
| 2545 | + * @throws EE_Error |
|
| 2546 | + */ |
|
| 2547 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2548 | + { |
|
| 2549 | + $context_details = $template_group_object->contexts_config(); |
|
| 2550 | + $context_label = $template_group_object->context_label(); |
|
| 2551 | + ob_start(); |
|
| 2552 | + ?> |
|
| 2553 | 2553 | <div class="ee-msg-switcher-container"> |
| 2554 | 2554 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2555 | 2555 | <?php |
| 2556 | - foreach ($args as $name => $value) { |
|
| 2557 | - if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2558 | - continue; |
|
| 2559 | - } |
|
| 2560 | - ?> |
|
| 2556 | + foreach ($args as $name => $value) { |
|
| 2557 | + if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2558 | + continue; |
|
| 2559 | + } |
|
| 2560 | + ?> |
|
| 2561 | 2561 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2562 | 2562 | <?php |
| 2563 | - } |
|
| 2564 | - //setup nonce_url |
|
| 2565 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2566 | - ?> |
|
| 2563 | + } |
|
| 2564 | + //setup nonce_url |
|
| 2565 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2566 | + ?> |
|
| 2567 | 2567 | <select name="context"> |
| 2568 | 2568 | <?php |
| 2569 | - $context_templates = $template_group_object->context_templates(); |
|
| 2570 | - if (is_array($context_templates)) : |
|
| 2571 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2572 | - $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2573 | - ?> |
|
| 2569 | + $context_templates = $template_group_object->context_templates(); |
|
| 2570 | + if (is_array($context_templates)) : |
|
| 2571 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2572 | + $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2573 | + ?> |
|
| 2574 | 2574 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2575 | 2575 | <?php echo $context_details[$context]['label']; ?> |
| 2576 | 2576 | </option> |
@@ -2583,1898 +2583,1898 @@ discard block |
||
| 2583 | 2583 | <?php echo $args['extra']; ?> |
| 2584 | 2584 | </div> <!-- end .ee-msg-switcher-container --> |
| 2585 | 2585 | <?php |
| 2586 | - $output = ob_get_contents(); |
|
| 2587 | - ob_clean(); |
|
| 2588 | - $this->_context_switcher = $output; |
|
| 2589 | - } |
|
| 2586 | + $output = ob_get_contents(); |
|
| 2587 | + ob_clean(); |
|
| 2588 | + $this->_context_switcher = $output; |
|
| 2589 | + } |
|
| 2590 | 2590 | |
| 2591 | 2591 | |
| 2592 | - /** |
|
| 2593 | - * utility for sanitizing new values coming in. |
|
| 2594 | - * Note: this is only used when updating a context. |
|
| 2595 | - * |
|
| 2596 | - * @access protected |
|
| 2597 | - * |
|
| 2598 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2599 | - * |
|
| 2600 | - * @return array |
|
| 2601 | - */ |
|
| 2602 | - protected function _set_message_template_column_values($index) |
|
| 2603 | - { |
|
| 2604 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2605 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2606 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2607 | - } |
|
| 2608 | - } |
|
| 2609 | - |
|
| 2610 | - |
|
| 2611 | - $set_column_values = array( |
|
| 2612 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2613 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2614 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2615 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2616 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2617 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2618 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2619 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2620 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2621 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2622 | - : 0, |
|
| 2623 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2624 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2625 | - : 0, |
|
| 2626 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2627 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2628 | - ); |
|
| 2629 | - |
|
| 2630 | - |
|
| 2631 | - return $set_column_values; |
|
| 2632 | - } |
|
| 2592 | + /** |
|
| 2593 | + * utility for sanitizing new values coming in. |
|
| 2594 | + * Note: this is only used when updating a context. |
|
| 2595 | + * |
|
| 2596 | + * @access protected |
|
| 2597 | + * |
|
| 2598 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2599 | + * |
|
| 2600 | + * @return array |
|
| 2601 | + */ |
|
| 2602 | + protected function _set_message_template_column_values($index) |
|
| 2603 | + { |
|
| 2604 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2605 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2606 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2607 | + } |
|
| 2608 | + } |
|
| 2609 | + |
|
| 2610 | + |
|
| 2611 | + $set_column_values = array( |
|
| 2612 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2613 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2614 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2615 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2616 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2617 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2618 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2619 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2620 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2621 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2622 | + : 0, |
|
| 2623 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2624 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2625 | + : 0, |
|
| 2626 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2627 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2628 | + ); |
|
| 2629 | + |
|
| 2630 | + |
|
| 2631 | + return $set_column_values; |
|
| 2632 | + } |
|
| 2633 | 2633 | |
| 2634 | 2634 | |
| 2635 | - protected function _insert_or_update_message_template($new = false) |
|
| 2636 | - { |
|
| 2637 | - |
|
| 2638 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2639 | - $success = 0; |
|
| 2640 | - $override = false; |
|
| 2641 | - |
|
| 2642 | - //setup notices description |
|
| 2643 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2644 | - |
|
| 2645 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2646 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2647 | - $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2648 | - ? ucwords($messenger_object->label['singular']) |
|
| 2649 | - : ''; |
|
| 2650 | - |
|
| 2651 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2652 | - ? $this->_req_data['MTP_message_type'] |
|
| 2653 | - : ''; |
|
| 2654 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2655 | - |
|
| 2656 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2657 | - ? ucwords($message_type_object->label['singular']) |
|
| 2658 | - : ''; |
|
| 2659 | - |
|
| 2660 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2661 | - ? $this->_req_data['MTP_context'] |
|
| 2662 | - : ''; |
|
| 2663 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2664 | - |
|
| 2665 | - $item_desc = $messenger_label && $message_type_label |
|
| 2666 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2667 | - : ''; |
|
| 2668 | - $item_desc .= 'Message Template'; |
|
| 2669 | - $query_args = array(); |
|
| 2670 | - $edit_array = array(); |
|
| 2671 | - $action_desc = ''; |
|
| 2672 | - |
|
| 2673 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2674 | - // user to edit. |
|
| 2675 | - if ($new) { |
|
| 2676 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2677 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2678 | - if (empty($edit_array)) { |
|
| 2679 | - $success = 0; |
|
| 2680 | - } else { |
|
| 2681 | - $success = 1; |
|
| 2682 | - $edit_array = $edit_array[0]; |
|
| 2683 | - $query_args = array( |
|
| 2684 | - 'id' => $edit_array['GRP_ID'], |
|
| 2685 | - 'context' => $edit_array['MTP_context'], |
|
| 2686 | - 'action' => 'edit_message_template' |
|
| 2687 | - ); |
|
| 2688 | - } |
|
| 2689 | - } |
|
| 2690 | - $action_desc = 'created'; |
|
| 2691 | - } else { |
|
| 2692 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2693 | - $MTP = EEM_Message_Template::instance(); |
|
| 2635 | + protected function _insert_or_update_message_template($new = false) |
|
| 2636 | + { |
|
| 2637 | + |
|
| 2638 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2639 | + $success = 0; |
|
| 2640 | + $override = false; |
|
| 2641 | + |
|
| 2642 | + //setup notices description |
|
| 2643 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2644 | + |
|
| 2645 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2646 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2647 | + $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2648 | + ? ucwords($messenger_object->label['singular']) |
|
| 2649 | + : ''; |
|
| 2650 | + |
|
| 2651 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2652 | + ? $this->_req_data['MTP_message_type'] |
|
| 2653 | + : ''; |
|
| 2654 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2655 | + |
|
| 2656 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2657 | + ? ucwords($message_type_object->label['singular']) |
|
| 2658 | + : ''; |
|
| 2659 | + |
|
| 2660 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2661 | + ? $this->_req_data['MTP_context'] |
|
| 2662 | + : ''; |
|
| 2663 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2664 | + |
|
| 2665 | + $item_desc = $messenger_label && $message_type_label |
|
| 2666 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2667 | + : ''; |
|
| 2668 | + $item_desc .= 'Message Template'; |
|
| 2669 | + $query_args = array(); |
|
| 2670 | + $edit_array = array(); |
|
| 2671 | + $action_desc = ''; |
|
| 2672 | + |
|
| 2673 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2674 | + // user to edit. |
|
| 2675 | + if ($new) { |
|
| 2676 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2677 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2678 | + if (empty($edit_array)) { |
|
| 2679 | + $success = 0; |
|
| 2680 | + } else { |
|
| 2681 | + $success = 1; |
|
| 2682 | + $edit_array = $edit_array[0]; |
|
| 2683 | + $query_args = array( |
|
| 2684 | + 'id' => $edit_array['GRP_ID'], |
|
| 2685 | + 'context' => $edit_array['MTP_context'], |
|
| 2686 | + 'action' => 'edit_message_template' |
|
| 2687 | + ); |
|
| 2688 | + } |
|
| 2689 | + } |
|
| 2690 | + $action_desc = 'created'; |
|
| 2691 | + } else { |
|
| 2692 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2693 | + $MTP = EEM_Message_Template::instance(); |
|
| 2694 | 2694 | |
| 2695 | 2695 | |
| 2696 | - //run update for each template field in displayed context |
|
| 2697 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2698 | - EE_Error::add_error( |
|
| 2699 | - esc_html__( |
|
| 2700 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2701 | - 'event_espresso' |
|
| 2702 | - ), |
|
| 2703 | - __FILE__, |
|
| 2704 | - __FUNCTION__, |
|
| 2705 | - __LINE__ |
|
| 2706 | - ); |
|
| 2707 | - $success = 0; |
|
| 2696 | + //run update for each template field in displayed context |
|
| 2697 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2698 | + EE_Error::add_error( |
|
| 2699 | + esc_html__( |
|
| 2700 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2701 | + 'event_espresso' |
|
| 2702 | + ), |
|
| 2703 | + __FILE__, |
|
| 2704 | + __FUNCTION__, |
|
| 2705 | + __LINE__ |
|
| 2706 | + ); |
|
| 2707 | + $success = 0; |
|
| 2708 | 2708 | |
| 2709 | - } else { |
|
| 2710 | - //first validate all fields! |
|
| 2711 | - // this filter allows client code to add its own validation to the template fields as well. |
|
| 2712 | - // returning an empty array means everything passed validation. |
|
| 2713 | - // errors in validation should be represented in an array with the following shape: |
|
| 2714 | - // array( |
|
| 2715 | - // 'fieldname' => array( |
|
| 2716 | - // 'msg' => 'error message' |
|
| 2717 | - // 'value' => 'value for field producing error' |
|
| 2718 | - // ) |
|
| 2719 | - $custom_validation = (array) apply_filters( |
|
| 2720 | - 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', |
|
| 2721 | - array(), |
|
| 2722 | - $this->_req_data['MTP_template_fields'], |
|
| 2723 | - $context_slug, |
|
| 2724 | - $messenger_slug, |
|
| 2725 | - $message_type_slug |
|
| 2726 | - ); |
|
| 2709 | + } else { |
|
| 2710 | + //first validate all fields! |
|
| 2711 | + // this filter allows client code to add its own validation to the template fields as well. |
|
| 2712 | + // returning an empty array means everything passed validation. |
|
| 2713 | + // errors in validation should be represented in an array with the following shape: |
|
| 2714 | + // array( |
|
| 2715 | + // 'fieldname' => array( |
|
| 2716 | + // 'msg' => 'error message' |
|
| 2717 | + // 'value' => 'value for field producing error' |
|
| 2718 | + // ) |
|
| 2719 | + $custom_validation = (array) apply_filters( |
|
| 2720 | + 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', |
|
| 2721 | + array(), |
|
| 2722 | + $this->_req_data['MTP_template_fields'], |
|
| 2723 | + $context_slug, |
|
| 2724 | + $messenger_slug, |
|
| 2725 | + $message_type_slug |
|
| 2726 | + ); |
|
| 2727 | 2727 | |
| 2728 | - $system_validation = $MTPG->validate( |
|
| 2729 | - $this->_req_data['MTP_template_fields'], |
|
| 2730 | - $context_slug, |
|
| 2731 | - $messenger_slug, |
|
| 2732 | - $message_type_slug |
|
| 2733 | - ); |
|
| 2728 | + $system_validation = $MTPG->validate( |
|
| 2729 | + $this->_req_data['MTP_template_fields'], |
|
| 2730 | + $context_slug, |
|
| 2731 | + $messenger_slug, |
|
| 2732 | + $message_type_slug |
|
| 2733 | + ); |
|
| 2734 | 2734 | |
| 2735 | - $system_validation = ! is_array($system_validation) && $system_validation ? array() : $system_validation; |
|
| 2736 | - $validates = array_merge($custom_validation, $system_validation); |
|
| 2735 | + $system_validation = ! is_array($system_validation) && $system_validation ? array() : $system_validation; |
|
| 2736 | + $validates = array_merge($custom_validation, $system_validation); |
|
| 2737 | 2737 | |
| 2738 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2739 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2740 | - // WE need to make sure there is no actual error messages in validates. |
|
| 2741 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2742 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2743 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2738 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2739 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2740 | + // WE need to make sure there is no actual error messages in validates. |
|
| 2741 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2742 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2743 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2744 | 2744 | |
| 2745 | - $success = 0; |
|
| 2745 | + $success = 0; |
|
| 2746 | 2746 | |
| 2747 | - //setup notices |
|
| 2748 | - foreach ($validates as $field => $error) { |
|
| 2749 | - if (isset($error['msg'])) { |
|
| 2750 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2751 | - } |
|
| 2752 | - } |
|
| 2747 | + //setup notices |
|
| 2748 | + foreach ($validates as $field => $error) { |
|
| 2749 | + if (isset($error['msg'])) { |
|
| 2750 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2751 | + } |
|
| 2752 | + } |
|
| 2753 | 2753 | |
| 2754 | - } else { |
|
| 2755 | - $set_column_values = array(); |
|
| 2756 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2757 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2754 | + } else { |
|
| 2755 | + $set_column_values = array(); |
|
| 2756 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2757 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2758 | 2758 | |
| 2759 | - $where_cols_n_values = array( |
|
| 2760 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2761 | - ); |
|
| 2762 | - //if they aren't allowed to use all JS, restrict them to just posty-y tags |
|
| 2763 | - if (! current_user_can('unfiltered_html')){ |
|
| 2764 | - if (is_array($set_column_values['MTP_content'])){ |
|
| 2765 | - foreach($set_column_values['MTP_content'] as $key => $value) { |
|
| 2766 | - //remove slashes so wp_kses works properly (its wp_kses_stripslashes() function |
|
| 2767 | - //only removes slashes from double-quotes, so attributes using single quotes always |
|
| 2768 | - //appear invalid.) But currently the models expect slashed data, so after wp_kses |
|
| 2769 | - //runs we need to re-slash the data. Sheesh. See |
|
| 2770 | - //https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
| 2771 | - $set_column_values['MTP_content'][$key] = addslashes( |
|
| 2772 | - wp_kses( |
|
| 2773 | - stripslashes($value), |
|
| 2774 | - wp_kses_allowed_html('post') |
|
| 2775 | - ) |
|
| 2776 | - ); |
|
| 2777 | - } |
|
| 2778 | - } else { |
|
| 2779 | - $set_column_values['MTP_content'] = wp_kses( |
|
| 2780 | - $set_column_values['MTP_content'], |
|
| 2781 | - wp_kses_allowed_html('post') |
|
| 2782 | - ); |
|
| 2783 | - } |
|
| 2784 | - } |
|
| 2785 | - $message_template_fields = array( |
|
| 2786 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2787 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2788 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2789 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2790 | - ); |
|
| 2791 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2792 | - if ($updated === false) { |
|
| 2793 | - EE_Error::add_error( |
|
| 2794 | - sprintf( |
|
| 2795 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2796 | - $template_field |
|
| 2797 | - ), |
|
| 2798 | - __FILE__, |
|
| 2799 | - __FUNCTION__, |
|
| 2800 | - __LINE__ |
|
| 2801 | - ); |
|
| 2802 | - } else { |
|
| 2803 | - $success = 1; |
|
| 2804 | - } |
|
| 2805 | - } else { |
|
| 2806 | - //only do this logic if we don't have a MTP_ID for this field |
|
| 2807 | - if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2808 | - //this has already been through the template field validator and sanitized, so it will be |
|
| 2809 | - //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2810 | - //message template field in a messenger/message type and existing users don't have the |
|
| 2811 | - //default setup for it. |
|
| 2812 | - //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2813 | - $updated = $MTP->insert($message_template_fields); |
|
| 2814 | - if (! $updated || is_wp_error($updated)) { |
|
| 2815 | - EE_Error::add_error( |
|
| 2816 | - sprintf( |
|
| 2817 | - esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2818 | - $template_field |
|
| 2819 | - ), |
|
| 2820 | - __FILE__, |
|
| 2821 | - __FUNCTION__, |
|
| 2822 | - __LINE__ |
|
| 2823 | - ); |
|
| 2824 | - $success = 0; |
|
| 2825 | - } else { |
|
| 2826 | - $success = 1; |
|
| 2827 | - } |
|
| 2828 | - } |
|
| 2829 | - } |
|
| 2830 | - $action_desc = 'updated'; |
|
| 2831 | - } |
|
| 2759 | + $where_cols_n_values = array( |
|
| 2760 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2761 | + ); |
|
| 2762 | + //if they aren't allowed to use all JS, restrict them to just posty-y tags |
|
| 2763 | + if (! current_user_can('unfiltered_html')){ |
|
| 2764 | + if (is_array($set_column_values['MTP_content'])){ |
|
| 2765 | + foreach($set_column_values['MTP_content'] as $key => $value) { |
|
| 2766 | + //remove slashes so wp_kses works properly (its wp_kses_stripslashes() function |
|
| 2767 | + //only removes slashes from double-quotes, so attributes using single quotes always |
|
| 2768 | + //appear invalid.) But currently the models expect slashed data, so after wp_kses |
|
| 2769 | + //runs we need to re-slash the data. Sheesh. See |
|
| 2770 | + //https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
| 2771 | + $set_column_values['MTP_content'][$key] = addslashes( |
|
| 2772 | + wp_kses( |
|
| 2773 | + stripslashes($value), |
|
| 2774 | + wp_kses_allowed_html('post') |
|
| 2775 | + ) |
|
| 2776 | + ); |
|
| 2777 | + } |
|
| 2778 | + } else { |
|
| 2779 | + $set_column_values['MTP_content'] = wp_kses( |
|
| 2780 | + $set_column_values['MTP_content'], |
|
| 2781 | + wp_kses_allowed_html('post') |
|
| 2782 | + ); |
|
| 2783 | + } |
|
| 2784 | + } |
|
| 2785 | + $message_template_fields = array( |
|
| 2786 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2787 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2788 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2789 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2790 | + ); |
|
| 2791 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2792 | + if ($updated === false) { |
|
| 2793 | + EE_Error::add_error( |
|
| 2794 | + sprintf( |
|
| 2795 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2796 | + $template_field |
|
| 2797 | + ), |
|
| 2798 | + __FILE__, |
|
| 2799 | + __FUNCTION__, |
|
| 2800 | + __LINE__ |
|
| 2801 | + ); |
|
| 2802 | + } else { |
|
| 2803 | + $success = 1; |
|
| 2804 | + } |
|
| 2805 | + } else { |
|
| 2806 | + //only do this logic if we don't have a MTP_ID for this field |
|
| 2807 | + if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2808 | + //this has already been through the template field validator and sanitized, so it will be |
|
| 2809 | + //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2810 | + //message template field in a messenger/message type and existing users don't have the |
|
| 2811 | + //default setup for it. |
|
| 2812 | + //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2813 | + $updated = $MTP->insert($message_template_fields); |
|
| 2814 | + if (! $updated || is_wp_error($updated)) { |
|
| 2815 | + EE_Error::add_error( |
|
| 2816 | + sprintf( |
|
| 2817 | + esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2818 | + $template_field |
|
| 2819 | + ), |
|
| 2820 | + __FILE__, |
|
| 2821 | + __FUNCTION__, |
|
| 2822 | + __LINE__ |
|
| 2823 | + ); |
|
| 2824 | + $success = 0; |
|
| 2825 | + } else { |
|
| 2826 | + $success = 1; |
|
| 2827 | + } |
|
| 2828 | + } |
|
| 2829 | + } |
|
| 2830 | + $action_desc = 'updated'; |
|
| 2831 | + } |
|
| 2832 | 2832 | |
| 2833 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2834 | - $mtpg_fields = array( |
|
| 2835 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2836 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2837 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2838 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2839 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2840 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2841 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2842 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2843 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2844 | - : '', |
|
| 2845 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2846 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2847 | - : '' |
|
| 2848 | - ); |
|
| 2833 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2834 | + $mtpg_fields = array( |
|
| 2835 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2836 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2837 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2838 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2839 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2840 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2841 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2842 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2843 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2844 | + : '', |
|
| 2845 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2846 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2847 | + : '' |
|
| 2848 | + ); |
|
| 2849 | 2849 | |
| 2850 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2851 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2850 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2851 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2852 | 2852 | |
| 2853 | - if ($updated === false) { |
|
| 2854 | - EE_Error::add_error( |
|
| 2855 | - sprintf( |
|
| 2856 | - esc_html__( |
|
| 2857 | - 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2858 | - 'event_espresso' |
|
| 2859 | - ), |
|
| 2860 | - $set_column_values['GRP_ID'] |
|
| 2861 | - ), |
|
| 2862 | - __FILE__, |
|
| 2863 | - __FUNCTION__, |
|
| 2864 | - __LINE__ |
|
| 2865 | - ); |
|
| 2866 | - } else { |
|
| 2867 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2868 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2869 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2870 | - : 'default'; |
|
| 2853 | + if ($updated === false) { |
|
| 2854 | + EE_Error::add_error( |
|
| 2855 | + sprintf( |
|
| 2856 | + esc_html__( |
|
| 2857 | + 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2858 | + 'event_espresso' |
|
| 2859 | + ), |
|
| 2860 | + $set_column_values['GRP_ID'] |
|
| 2861 | + ), |
|
| 2862 | + __FILE__, |
|
| 2863 | + __FUNCTION__, |
|
| 2864 | + __LINE__ |
|
| 2865 | + ); |
|
| 2866 | + } else { |
|
| 2867 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2868 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2869 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2870 | + : 'default'; |
|
| 2871 | 2871 | |
| 2872 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2873 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2874 | - : 'default'; |
|
| 2872 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2873 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2874 | + : 'default'; |
|
| 2875 | 2875 | |
| 2876 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2877 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2878 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2879 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2880 | - } |
|
| 2881 | - $success = 1; |
|
| 2882 | - } |
|
| 2883 | - } |
|
| 2884 | - } |
|
| 2876 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2877 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2878 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2879 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2880 | + } |
|
| 2881 | + $success = 1; |
|
| 2882 | + } |
|
| 2883 | + } |
|
| 2884 | + } |
|
| 2885 | 2885 | |
| 2886 | - } |
|
| 2887 | - |
|
| 2888 | - //we return things differently if doing ajax |
|
| 2889 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2890 | - $this->_template_args['success'] = $success; |
|
| 2891 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2892 | - $this->_template_args['content'] = ''; |
|
| 2893 | - $this->_template_args['data'] = array( |
|
| 2894 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2895 | - 'templateName' => $edit_array['template_name'] |
|
| 2896 | - ); |
|
| 2897 | - if ($success) { |
|
| 2898 | - EE_Error::overwrite_success(); |
|
| 2899 | - EE_Error::add_success( |
|
| 2900 | - esc_html__( |
|
| 2901 | - 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2902 | - 'event_espresso' |
|
| 2903 | - ) |
|
| 2904 | - ); |
|
| 2905 | - } |
|
| 2886 | + } |
|
| 2887 | + |
|
| 2888 | + //we return things differently if doing ajax |
|
| 2889 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2890 | + $this->_template_args['success'] = $success; |
|
| 2891 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2892 | + $this->_template_args['content'] = ''; |
|
| 2893 | + $this->_template_args['data'] = array( |
|
| 2894 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2895 | + 'templateName' => $edit_array['template_name'] |
|
| 2896 | + ); |
|
| 2897 | + if ($success) { |
|
| 2898 | + EE_Error::overwrite_success(); |
|
| 2899 | + EE_Error::add_success( |
|
| 2900 | + esc_html__( |
|
| 2901 | + 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2902 | + 'event_espresso' |
|
| 2903 | + ) |
|
| 2904 | + ); |
|
| 2905 | + } |
|
| 2906 | 2906 | |
| 2907 | - $this->_return_json(); |
|
| 2908 | - } |
|
| 2909 | - |
|
| 2910 | - |
|
| 2911 | - //was a test send triggered? |
|
| 2912 | - if (isset($this->_req_data['test_button'])) { |
|
| 2913 | - EE_Error::overwrite_success(); |
|
| 2914 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2915 | - $override = true; |
|
| 2916 | - } |
|
| 2917 | - |
|
| 2918 | - if (empty($query_args)) { |
|
| 2919 | - $query_args = array( |
|
| 2920 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2921 | - 'context' => $context_slug, |
|
| 2922 | - 'action' => 'edit_message_template' |
|
| 2923 | - ); |
|
| 2924 | - } |
|
| 2925 | - |
|
| 2926 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2927 | - } |
|
| 2907 | + $this->_return_json(); |
|
| 2908 | + } |
|
| 2909 | + |
|
| 2910 | + |
|
| 2911 | + //was a test send triggered? |
|
| 2912 | + if (isset($this->_req_data['test_button'])) { |
|
| 2913 | + EE_Error::overwrite_success(); |
|
| 2914 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2915 | + $override = true; |
|
| 2916 | + } |
|
| 2917 | + |
|
| 2918 | + if (empty($query_args)) { |
|
| 2919 | + $query_args = array( |
|
| 2920 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2921 | + 'context' => $context_slug, |
|
| 2922 | + 'action' => 'edit_message_template' |
|
| 2923 | + ); |
|
| 2924 | + } |
|
| 2925 | + |
|
| 2926 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2927 | + } |
|
| 2928 | 2928 | |
| 2929 | 2929 | |
| 2930 | - /** |
|
| 2931 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2932 | - * |
|
| 2933 | - * @param string $context what context being tested |
|
| 2934 | - * @param string $messenger messenger being tested |
|
| 2935 | - * @param string $message_type message type being tested |
|
| 2936 | - * @throws EE_Error |
|
| 2937 | - * @throws InvalidArgumentException |
|
| 2938 | - * @throws InvalidDataTypeException |
|
| 2939 | - * @throws InvalidInterfaceException |
|
| 2940 | - */ |
|
| 2941 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2942 | - { |
|
| 2943 | - //set things up for preview |
|
| 2944 | - $this->_req_data['messenger'] = $messenger; |
|
| 2945 | - $this->_req_data['message_type'] = $message_type; |
|
| 2946 | - $this->_req_data['context'] = $context; |
|
| 2947 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2948 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2949 | - |
|
| 2950 | - //let's save any existing fields that might be required by the messenger |
|
| 2951 | - if ( |
|
| 2952 | - isset($this->_req_data['test_settings_fld']) |
|
| 2953 | - && $active_messenger instanceof EE_messenger |
|
| 2954 | - && apply_filters( |
|
| 2955 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2956 | - true, |
|
| 2957 | - $this->_req_data['test_settings_fld'], |
|
| 2958 | - $active_messenger |
|
| 2959 | - ) |
|
| 2960 | - ) { |
|
| 2961 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2962 | - } |
|
| 2930 | + /** |
|
| 2931 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2932 | + * |
|
| 2933 | + * @param string $context what context being tested |
|
| 2934 | + * @param string $messenger messenger being tested |
|
| 2935 | + * @param string $message_type message type being tested |
|
| 2936 | + * @throws EE_Error |
|
| 2937 | + * @throws InvalidArgumentException |
|
| 2938 | + * @throws InvalidDataTypeException |
|
| 2939 | + * @throws InvalidInterfaceException |
|
| 2940 | + */ |
|
| 2941 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2942 | + { |
|
| 2943 | + //set things up for preview |
|
| 2944 | + $this->_req_data['messenger'] = $messenger; |
|
| 2945 | + $this->_req_data['message_type'] = $message_type; |
|
| 2946 | + $this->_req_data['context'] = $context; |
|
| 2947 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2948 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2949 | + |
|
| 2950 | + //let's save any existing fields that might be required by the messenger |
|
| 2951 | + if ( |
|
| 2952 | + isset($this->_req_data['test_settings_fld']) |
|
| 2953 | + && $active_messenger instanceof EE_messenger |
|
| 2954 | + && apply_filters( |
|
| 2955 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2956 | + true, |
|
| 2957 | + $this->_req_data['test_settings_fld'], |
|
| 2958 | + $active_messenger |
|
| 2959 | + ) |
|
| 2960 | + ) { |
|
| 2961 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2962 | + } |
|
| 2963 | 2963 | |
| 2964 | - /** |
|
| 2965 | - * Use filter to add additional controls on whether message can send or not |
|
| 2966 | - */ |
|
| 2967 | - if (apply_filters( |
|
| 2968 | - 'FHEE__Messages_Admin_Page__do_test_send__can_send', |
|
| 2969 | - true, |
|
| 2970 | - $context, |
|
| 2971 | - $this->_req_data, |
|
| 2972 | - $messenger, |
|
| 2973 | - $message_type |
|
| 2974 | - )) { |
|
| 2975 | - $success = $this->_preview_message(true); |
|
| 2976 | - if ($success) { |
|
| 2977 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2978 | - } else { |
|
| 2979 | - EE_Error::add_error( |
|
| 2980 | - esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2981 | - __FILE__, |
|
| 2982 | - __FUNCTION__, |
|
| 2983 | - __LINE__ |
|
| 2984 | - ); |
|
| 2985 | - } |
|
| 2986 | - } |
|
| 2987 | - } |
|
| 2964 | + /** |
|
| 2965 | + * Use filter to add additional controls on whether message can send or not |
|
| 2966 | + */ |
|
| 2967 | + if (apply_filters( |
|
| 2968 | + 'FHEE__Messages_Admin_Page__do_test_send__can_send', |
|
| 2969 | + true, |
|
| 2970 | + $context, |
|
| 2971 | + $this->_req_data, |
|
| 2972 | + $messenger, |
|
| 2973 | + $message_type |
|
| 2974 | + )) { |
|
| 2975 | + $success = $this->_preview_message(true); |
|
| 2976 | + if ($success) { |
|
| 2977 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2978 | + } else { |
|
| 2979 | + EE_Error::add_error( |
|
| 2980 | + esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2981 | + __FILE__, |
|
| 2982 | + __FUNCTION__, |
|
| 2983 | + __LINE__ |
|
| 2984 | + ); |
|
| 2985 | + } |
|
| 2986 | + } |
|
| 2987 | + } |
|
| 2988 | 2988 | |
| 2989 | 2989 | |
| 2990 | - /** |
|
| 2991 | - * _generate_new_templates |
|
| 2992 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2993 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2994 | - * for the event. |
|
| 2995 | - * |
|
| 2996 | - * |
|
| 2997 | - * @param string $messenger the messenger we are generating templates for |
|
| 2998 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2999 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 3000 | - * indicate the message_template_group being used as the base. |
|
| 3001 | - * |
|
| 3002 | - * @param bool $global |
|
| 3003 | - * |
|
| 3004 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 3005 | - * encountering problems. |
|
| 3006 | - * @throws EE_Error |
|
| 3007 | - */ |
|
| 3008 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 3009 | - { |
|
| 3010 | - |
|
| 3011 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 3012 | - // just don't generate any templates. |
|
| 3013 | - if (empty($message_types)) { |
|
| 3014 | - return true; |
|
| 3015 | - } |
|
| 3016 | - |
|
| 3017 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 3018 | - } |
|
| 2990 | + /** |
|
| 2991 | + * _generate_new_templates |
|
| 2992 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2993 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2994 | + * for the event. |
|
| 2995 | + * |
|
| 2996 | + * |
|
| 2997 | + * @param string $messenger the messenger we are generating templates for |
|
| 2998 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2999 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 3000 | + * indicate the message_template_group being used as the base. |
|
| 3001 | + * |
|
| 3002 | + * @param bool $global |
|
| 3003 | + * |
|
| 3004 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 3005 | + * encountering problems. |
|
| 3006 | + * @throws EE_Error |
|
| 3007 | + */ |
|
| 3008 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 3009 | + { |
|
| 3010 | + |
|
| 3011 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 3012 | + // just don't generate any templates. |
|
| 3013 | + if (empty($message_types)) { |
|
| 3014 | + return true; |
|
| 3015 | + } |
|
| 3016 | + |
|
| 3017 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 3018 | + } |
|
| 3019 | 3019 | |
| 3020 | 3020 | |
| 3021 | - /** |
|
| 3022 | - * [_trash_or_restore_message_template] |
|
| 3023 | - * |
|
| 3024 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 3025 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 3026 | - * an individual context (FALSE). |
|
| 3027 | - * @return void |
|
| 3028 | - * @throws EE_Error |
|
| 3029 | - * @throws InvalidArgumentException |
|
| 3030 | - * @throws InvalidDataTypeException |
|
| 3031 | - * @throws InvalidInterfaceException |
|
| 3032 | - */ |
|
| 3033 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 3034 | - { |
|
| 3035 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3036 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 3037 | - |
|
| 3038 | - $success = 1; |
|
| 3039 | - |
|
| 3040 | - //incoming GRP_IDs |
|
| 3041 | - if ($all) { |
|
| 3042 | - //Checkboxes |
|
| 3043 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3044 | - //if array has more than one element then success message should be plural. |
|
| 3045 | - //todo: what about nonce? |
|
| 3046 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3021 | + /** |
|
| 3022 | + * [_trash_or_restore_message_template] |
|
| 3023 | + * |
|
| 3024 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 3025 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 3026 | + * an individual context (FALSE). |
|
| 3027 | + * @return void |
|
| 3028 | + * @throws EE_Error |
|
| 3029 | + * @throws InvalidArgumentException |
|
| 3030 | + * @throws InvalidDataTypeException |
|
| 3031 | + * @throws InvalidInterfaceException |
|
| 3032 | + */ |
|
| 3033 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 3034 | + { |
|
| 3035 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3036 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 3037 | + |
|
| 3038 | + $success = 1; |
|
| 3039 | + |
|
| 3040 | + //incoming GRP_IDs |
|
| 3041 | + if ($all) { |
|
| 3042 | + //Checkboxes |
|
| 3043 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3044 | + //if array has more than one element then success message should be plural. |
|
| 3045 | + //todo: what about nonce? |
|
| 3046 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3047 | 3047 | |
| 3048 | - //cycle through checkboxes |
|
| 3049 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3050 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3051 | - if ( ! $trashed_or_restored) { |
|
| 3052 | - $success = 0; |
|
| 3053 | - } |
|
| 3054 | - } |
|
| 3055 | - } else { |
|
| 3056 | - //grab single GRP_ID and handle |
|
| 3057 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3058 | - if ( ! empty($GRP_ID)) { |
|
| 3059 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3060 | - if ( ! $trashed_or_restored) { |
|
| 3061 | - $success = 0; |
|
| 3062 | - } |
|
| 3063 | - } else { |
|
| 3064 | - $success = 0; |
|
| 3065 | - } |
|
| 3066 | - } |
|
| 3048 | + //cycle through checkboxes |
|
| 3049 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3050 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3051 | + if ( ! $trashed_or_restored) { |
|
| 3052 | + $success = 0; |
|
| 3053 | + } |
|
| 3054 | + } |
|
| 3055 | + } else { |
|
| 3056 | + //grab single GRP_ID and handle |
|
| 3057 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3058 | + if ( ! empty($GRP_ID)) { |
|
| 3059 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3060 | + if ( ! $trashed_or_restored) { |
|
| 3061 | + $success = 0; |
|
| 3062 | + } |
|
| 3063 | + } else { |
|
| 3064 | + $success = 0; |
|
| 3065 | + } |
|
| 3066 | + } |
|
| 3067 | 3067 | |
| 3068 | - } |
|
| 3068 | + } |
|
| 3069 | 3069 | |
| 3070 | - $action_desc = $trash |
|
| 3071 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3072 | - : esc_html__('restored', 'event_espresso'); |
|
| 3070 | + $action_desc = $trash |
|
| 3071 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3072 | + : esc_html__('restored', 'event_espresso'); |
|
| 3073 | 3073 | |
| 3074 | - $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3074 | + $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3075 | 3075 | |
| 3076 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3077 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3076 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3077 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3078 | 3078 | |
| 3079 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3080 | - 'event_espresso') : $item_desc; |
|
| 3079 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3080 | + 'event_espresso') : $item_desc; |
|
| 3081 | 3081 | |
| 3082 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3082 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3083 | 3083 | |
| 3084 | - } |
|
| 3084 | + } |
|
| 3085 | 3085 | |
| 3086 | 3086 | |
| 3087 | - /** |
|
| 3088 | - * [_delete_message_template] |
|
| 3089 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3090 | - * |
|
| 3091 | - * @return void |
|
| 3092 | - * @throws EE_Error |
|
| 3093 | - * @throws InvalidArgumentException |
|
| 3094 | - * @throws InvalidDataTypeException |
|
| 3095 | - * @throws InvalidInterfaceException |
|
| 3096 | - */ |
|
| 3097 | - protected function _delete_message_template() |
|
| 3098 | - { |
|
| 3099 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3100 | - |
|
| 3101 | - //checkboxes |
|
| 3102 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3103 | - //if array has more than one element then success message should be plural |
|
| 3104 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3087 | + /** |
|
| 3088 | + * [_delete_message_template] |
|
| 3089 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3090 | + * |
|
| 3091 | + * @return void |
|
| 3092 | + * @throws EE_Error |
|
| 3093 | + * @throws InvalidArgumentException |
|
| 3094 | + * @throws InvalidDataTypeException |
|
| 3095 | + * @throws InvalidInterfaceException |
|
| 3096 | + */ |
|
| 3097 | + protected function _delete_message_template() |
|
| 3098 | + { |
|
| 3099 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3100 | + |
|
| 3101 | + //checkboxes |
|
| 3102 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3103 | + //if array has more than one element then success message should be plural |
|
| 3104 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3105 | 3105 | |
| 3106 | - //cycle through bulk action checkboxes |
|
| 3107 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3108 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3109 | - } |
|
| 3110 | - } else { |
|
| 3111 | - //grab single grp_id and delete |
|
| 3112 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 3113 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3114 | - } |
|
| 3115 | - |
|
| 3116 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3117 | - |
|
| 3118 | - } |
|
| 3106 | + //cycle through bulk action checkboxes |
|
| 3107 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3108 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3109 | + } |
|
| 3110 | + } else { |
|
| 3111 | + //grab single grp_id and delete |
|
| 3112 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 3113 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3114 | + } |
|
| 3115 | + |
|
| 3116 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3117 | + |
|
| 3118 | + } |
|
| 3119 | 3119 | |
| 3120 | 3120 | |
| 3121 | - /** |
|
| 3122 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 3123 | - * |
|
| 3124 | - * @param int $GRP_ID The group being deleted |
|
| 3125 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3126 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3127 | - * @throws EE_Error |
|
| 3128 | - * @throws InvalidArgumentException |
|
| 3129 | - * @throws InvalidDataTypeException |
|
| 3130 | - * @throws InvalidInterfaceException |
|
| 3131 | - */ |
|
| 3132 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3133 | - { |
|
| 3134 | - $success = 1; |
|
| 3135 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3136 | - //first let's GET this group |
|
| 3137 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3138 | - //then delete permanently all the related Message Templates |
|
| 3139 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3140 | - |
|
| 3141 | - if ($deleted === 0) { |
|
| 3142 | - $success = 0; |
|
| 3143 | - } |
|
| 3144 | - |
|
| 3145 | - //now delete permanently this particular group |
|
| 3146 | - |
|
| 3147 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3148 | - $success = 0; |
|
| 3149 | - } |
|
| 3150 | - |
|
| 3151 | - return $success; |
|
| 3152 | - } |
|
| 3121 | + /** |
|
| 3122 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 3123 | + * |
|
| 3124 | + * @param int $GRP_ID The group being deleted |
|
| 3125 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3126 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 3127 | + * @throws EE_Error |
|
| 3128 | + * @throws InvalidArgumentException |
|
| 3129 | + * @throws InvalidDataTypeException |
|
| 3130 | + * @throws InvalidInterfaceException |
|
| 3131 | + */ |
|
| 3132 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3133 | + { |
|
| 3134 | + $success = 1; |
|
| 3135 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3136 | + //first let's GET this group |
|
| 3137 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3138 | + //then delete permanently all the related Message Templates |
|
| 3139 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3140 | + |
|
| 3141 | + if ($deleted === 0) { |
|
| 3142 | + $success = 0; |
|
| 3143 | + } |
|
| 3144 | + |
|
| 3145 | + //now delete permanently this particular group |
|
| 3146 | + |
|
| 3147 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3148 | + $success = 0; |
|
| 3149 | + } |
|
| 3150 | + |
|
| 3151 | + return $success; |
|
| 3152 | + } |
|
| 3153 | 3153 | |
| 3154 | 3154 | |
| 3155 | - /** |
|
| 3156 | - * _learn_more_about_message_templates_link |
|
| 3157 | - * @access protected |
|
| 3158 | - * @return string |
|
| 3159 | - */ |
|
| 3160 | - protected function _learn_more_about_message_templates_link() |
|
| 3161 | - { |
|
| 3162 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3163 | - . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3164 | - . '</a>'; |
|
| 3165 | - } |
|
| 3155 | + /** |
|
| 3156 | + * _learn_more_about_message_templates_link |
|
| 3157 | + * @access protected |
|
| 3158 | + * @return string |
|
| 3159 | + */ |
|
| 3160 | + protected function _learn_more_about_message_templates_link() |
|
| 3161 | + { |
|
| 3162 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3163 | + . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3164 | + . '</a>'; |
|
| 3165 | + } |
|
| 3166 | 3166 | |
| 3167 | 3167 | |
| 3168 | - /** |
|
| 3169 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3170 | - * ajax and other routes. |
|
| 3171 | - * |
|
| 3172 | - * @return void |
|
| 3173 | - * @throws DomainException |
|
| 3174 | - */ |
|
| 3175 | - protected function _settings() |
|
| 3176 | - { |
|
| 3177 | - |
|
| 3178 | - |
|
| 3179 | - $this->_set_m_mt_settings(); |
|
| 3180 | - |
|
| 3181 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3182 | - ? $this->_req_data['selected_messenger'] |
|
| 3183 | - : 'email'; |
|
| 3184 | - |
|
| 3185 | - //let's setup the messenger tabs |
|
| 3186 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3187 | - $this->_m_mt_settings['messenger_tabs'], |
|
| 3188 | - 'messenger_links', |
|
| 3189 | - '|', |
|
| 3190 | - $selected_messenger |
|
| 3191 | - ); |
|
| 3192 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3193 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3194 | - |
|
| 3195 | - $this->display_admin_page_with_sidebar(); |
|
| 3196 | - |
|
| 3197 | - } |
|
| 3168 | + /** |
|
| 3169 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3170 | + * ajax and other routes. |
|
| 3171 | + * |
|
| 3172 | + * @return void |
|
| 3173 | + * @throws DomainException |
|
| 3174 | + */ |
|
| 3175 | + protected function _settings() |
|
| 3176 | + { |
|
| 3177 | + |
|
| 3178 | + |
|
| 3179 | + $this->_set_m_mt_settings(); |
|
| 3180 | + |
|
| 3181 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3182 | + ? $this->_req_data['selected_messenger'] |
|
| 3183 | + : 'email'; |
|
| 3184 | + |
|
| 3185 | + //let's setup the messenger tabs |
|
| 3186 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3187 | + $this->_m_mt_settings['messenger_tabs'], |
|
| 3188 | + 'messenger_links', |
|
| 3189 | + '|', |
|
| 3190 | + $selected_messenger |
|
| 3191 | + ); |
|
| 3192 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3193 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3194 | + |
|
| 3195 | + $this->display_admin_page_with_sidebar(); |
|
| 3196 | + |
|
| 3197 | + } |
|
| 3198 | 3198 | |
| 3199 | 3199 | |
| 3200 | - /** |
|
| 3201 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3202 | - * |
|
| 3203 | - * @access protected |
|
| 3204 | - * @return void |
|
| 3205 | - * @throws DomainException |
|
| 3206 | - */ |
|
| 3207 | - protected function _set_m_mt_settings() |
|
| 3208 | - { |
|
| 3209 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 3210 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 3211 | - return; |
|
| 3212 | - } |
|
| 3213 | - |
|
| 3214 | - //get all installed messengers and message_types |
|
| 3215 | - /** @type EE_messenger[] $messengers */ |
|
| 3216 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3217 | - /** @type EE_message_type[] $message_types */ |
|
| 3218 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3219 | - |
|
| 3220 | - |
|
| 3221 | - //assemble the array for the _tab_text_links helper |
|
| 3222 | - |
|
| 3223 | - foreach ($messengers as $messenger) { |
|
| 3224 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3225 | - 'label' => ucwords($messenger->label['singular']), |
|
| 3226 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3227 | - ? 'messenger-active' |
|
| 3228 | - : '', |
|
| 3229 | - 'href' => $messenger->name, |
|
| 3230 | - 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3231 | - 'slug' => $messenger->name, |
|
| 3232 | - 'obj' => $messenger |
|
| 3233 | - ); |
|
| 3200 | + /** |
|
| 3201 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3202 | + * |
|
| 3203 | + * @access protected |
|
| 3204 | + * @return void |
|
| 3205 | + * @throws DomainException |
|
| 3206 | + */ |
|
| 3207 | + protected function _set_m_mt_settings() |
|
| 3208 | + { |
|
| 3209 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 3210 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 3211 | + return; |
|
| 3212 | + } |
|
| 3213 | + |
|
| 3214 | + //get all installed messengers and message_types |
|
| 3215 | + /** @type EE_messenger[] $messengers */ |
|
| 3216 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3217 | + /** @type EE_message_type[] $message_types */ |
|
| 3218 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3219 | + |
|
| 3220 | + |
|
| 3221 | + //assemble the array for the _tab_text_links helper |
|
| 3222 | + |
|
| 3223 | + foreach ($messengers as $messenger) { |
|
| 3224 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3225 | + 'label' => ucwords($messenger->label['singular']), |
|
| 3226 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3227 | + ? 'messenger-active' |
|
| 3228 | + : '', |
|
| 3229 | + 'href' => $messenger->name, |
|
| 3230 | + 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3231 | + 'slug' => $messenger->name, |
|
| 3232 | + 'obj' => $messenger |
|
| 3233 | + ); |
|
| 3234 | 3234 | |
| 3235 | 3235 | |
| 3236 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3236 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3237 | 3237 | |
| 3238 | - foreach ($message_types as $message_type) { |
|
| 3239 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3240 | - // it shouldn't show in either the inactive OR active metabox. |
|
| 3241 | - if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3242 | - continue; |
|
| 3243 | - } |
|
| 3238 | + foreach ($message_types as $message_type) { |
|
| 3239 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3240 | + // it shouldn't show in either the inactive OR active metabox. |
|
| 3241 | + if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3242 | + continue; |
|
| 3243 | + } |
|
| 3244 | 3244 | |
| 3245 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3246 | - $messenger->name, |
|
| 3247 | - $message_type->name |
|
| 3248 | - ) |
|
| 3249 | - ? 'active' |
|
| 3250 | - : 'inactive'; |
|
| 3245 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3246 | + $messenger->name, |
|
| 3247 | + $message_type->name |
|
| 3248 | + ) |
|
| 3249 | + ? 'active' |
|
| 3250 | + : 'inactive'; |
|
| 3251 | 3251 | |
| 3252 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3253 | - 'label' => ucwords($message_type->label['singular']), |
|
| 3254 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3255 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3256 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3257 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3258 | - 'title' => $a_or_i === 'active' |
|
| 3259 | - ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3260 | - : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3261 | - 'content' => $a_or_i === 'active' |
|
| 3262 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3263 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3264 | - 'slug' => $message_type->name, |
|
| 3265 | - 'active' => $a_or_i === 'active', |
|
| 3266 | - 'obj' => $message_type |
|
| 3267 | - ); |
|
| 3268 | - } |
|
| 3269 | - } |
|
| 3270 | - } |
|
| 3252 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3253 | + 'label' => ucwords($message_type->label['singular']), |
|
| 3254 | + 'class' => 'message-type-' . $a_or_i, |
|
| 3255 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3256 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3257 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3258 | + 'title' => $a_or_i === 'active' |
|
| 3259 | + ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3260 | + : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3261 | + 'content' => $a_or_i === 'active' |
|
| 3262 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3263 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3264 | + 'slug' => $message_type->name, |
|
| 3265 | + 'active' => $a_or_i === 'active', |
|
| 3266 | + 'obj' => $message_type |
|
| 3267 | + ); |
|
| 3268 | + } |
|
| 3269 | + } |
|
| 3270 | + } |
|
| 3271 | 3271 | |
| 3272 | 3272 | |
| 3273 | - /** |
|
| 3274 | - * This just prepares the content for the message type settings |
|
| 3275 | - * |
|
| 3276 | - * @param EE_message_type $message_type The message type object |
|
| 3277 | - * @param EE_messenger $messenger The messenger object |
|
| 3278 | - * @param boolean $active Whether the message type is active or not |
|
| 3279 | - * @return string html output for the content |
|
| 3280 | - * @throws DomainException |
|
| 3281 | - */ |
|
| 3282 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3283 | - { |
|
| 3284 | - //get message type fields |
|
| 3285 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 3286 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3287 | - |
|
| 3288 | - if ( ! empty($fields) && $active) { |
|
| 3273 | + /** |
|
| 3274 | + * This just prepares the content for the message type settings |
|
| 3275 | + * |
|
| 3276 | + * @param EE_message_type $message_type The message type object |
|
| 3277 | + * @param EE_messenger $messenger The messenger object |
|
| 3278 | + * @param boolean $active Whether the message type is active or not |
|
| 3279 | + * @return string html output for the content |
|
| 3280 | + * @throws DomainException |
|
| 3281 | + */ |
|
| 3282 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3283 | + { |
|
| 3284 | + //get message type fields |
|
| 3285 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 3286 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3287 | + |
|
| 3288 | + if ( ! empty($fields) && $active) { |
|
| 3289 | 3289 | |
| 3290 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3290 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3291 | 3291 | |
| 3292 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3293 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3294 | - $template_form_field[$field_id] = array( |
|
| 3295 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3296 | - 'label' => $fldprops['label'], |
|
| 3297 | - 'input' => $fldprops['field_type'], |
|
| 3298 | - 'type' => $fldprops['value_type'], |
|
| 3299 | - 'required' => $fldprops['required'], |
|
| 3300 | - 'validation' => $fldprops['validation'], |
|
| 3301 | - 'value' => isset($existing_settings[$fldname]) |
|
| 3302 | - ? $existing_settings[$fldname] |
|
| 3303 | - : $fldprops['default'], |
|
| 3304 | - 'options' => isset($fldprops['options']) |
|
| 3305 | - ? $fldprops['options'] |
|
| 3306 | - : array(), |
|
| 3307 | - 'default' => isset($existing_settings[$fldname]) |
|
| 3308 | - ? $existing_settings[$fldname] |
|
| 3309 | - : $fldprops['default'], |
|
| 3310 | - 'css_class' => 'no-drag', |
|
| 3311 | - 'format' => $fldprops['format'] |
|
| 3312 | - ); |
|
| 3313 | - } |
|
| 3292 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3293 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3294 | + $template_form_field[$field_id] = array( |
|
| 3295 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3296 | + 'label' => $fldprops['label'], |
|
| 3297 | + 'input' => $fldprops['field_type'], |
|
| 3298 | + 'type' => $fldprops['value_type'], |
|
| 3299 | + 'required' => $fldprops['required'], |
|
| 3300 | + 'validation' => $fldprops['validation'], |
|
| 3301 | + 'value' => isset($existing_settings[$fldname]) |
|
| 3302 | + ? $existing_settings[$fldname] |
|
| 3303 | + : $fldprops['default'], |
|
| 3304 | + 'options' => isset($fldprops['options']) |
|
| 3305 | + ? $fldprops['options'] |
|
| 3306 | + : array(), |
|
| 3307 | + 'default' => isset($existing_settings[$fldname]) |
|
| 3308 | + ? $existing_settings[$fldname] |
|
| 3309 | + : $fldprops['default'], |
|
| 3310 | + 'css_class' => 'no-drag', |
|
| 3311 | + 'format' => $fldprops['format'] |
|
| 3312 | + ); |
|
| 3313 | + } |
|
| 3314 | 3314 | |
| 3315 | 3315 | |
| 3316 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3317 | - ? $this->_generate_admin_form_fields( |
|
| 3318 | - $template_form_field, |
|
| 3319 | - 'string', |
|
| 3320 | - 'ee_mt_activate_form' |
|
| 3321 | - ) |
|
| 3322 | - : ''; |
|
| 3323 | - } |
|
| 3324 | - |
|
| 3325 | - $settings_template_args['description'] = $message_type->description; |
|
| 3326 | - //we also need some hidden fields |
|
| 3327 | - $settings_template_args['hidden_fields'] = array( |
|
| 3328 | - 'message_type_settings[messenger]' => array( |
|
| 3329 | - 'type' => 'hidden', |
|
| 3330 | - 'value' => $messenger->name |
|
| 3331 | - ), |
|
| 3332 | - 'message_type_settings[message_type]' => array( |
|
| 3333 | - 'type' => 'hidden', |
|
| 3334 | - 'value' => $message_type->name |
|
| 3335 | - ), |
|
| 3336 | - 'type' => array( |
|
| 3337 | - 'type' => 'hidden', |
|
| 3338 | - 'value' => 'message_type' |
|
| 3339 | - ) |
|
| 3340 | - ); |
|
| 3341 | - |
|
| 3342 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3343 | - $settings_template_args['hidden_fields'], |
|
| 3344 | - 'array' |
|
| 3345 | - ); |
|
| 3346 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3347 | - ? ' hidden' |
|
| 3348 | - : ''; |
|
| 3349 | - |
|
| 3350 | - |
|
| 3351 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3352 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3353 | - |
|
| 3354 | - return $content; |
|
| 3355 | - } |
|
| 3316 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3317 | + ? $this->_generate_admin_form_fields( |
|
| 3318 | + $template_form_field, |
|
| 3319 | + 'string', |
|
| 3320 | + 'ee_mt_activate_form' |
|
| 3321 | + ) |
|
| 3322 | + : ''; |
|
| 3323 | + } |
|
| 3324 | + |
|
| 3325 | + $settings_template_args['description'] = $message_type->description; |
|
| 3326 | + //we also need some hidden fields |
|
| 3327 | + $settings_template_args['hidden_fields'] = array( |
|
| 3328 | + 'message_type_settings[messenger]' => array( |
|
| 3329 | + 'type' => 'hidden', |
|
| 3330 | + 'value' => $messenger->name |
|
| 3331 | + ), |
|
| 3332 | + 'message_type_settings[message_type]' => array( |
|
| 3333 | + 'type' => 'hidden', |
|
| 3334 | + 'value' => $message_type->name |
|
| 3335 | + ), |
|
| 3336 | + 'type' => array( |
|
| 3337 | + 'type' => 'hidden', |
|
| 3338 | + 'value' => 'message_type' |
|
| 3339 | + ) |
|
| 3340 | + ); |
|
| 3341 | + |
|
| 3342 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3343 | + $settings_template_args['hidden_fields'], |
|
| 3344 | + 'array' |
|
| 3345 | + ); |
|
| 3346 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3347 | + ? ' hidden' |
|
| 3348 | + : ''; |
|
| 3349 | + |
|
| 3350 | + |
|
| 3351 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3352 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3353 | + |
|
| 3354 | + return $content; |
|
| 3355 | + } |
|
| 3356 | 3356 | |
| 3357 | 3357 | |
| 3358 | - /** |
|
| 3359 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3360 | - * |
|
| 3361 | - * @access protected |
|
| 3362 | - * @return void |
|
| 3363 | - * @throws DomainException |
|
| 3364 | - */ |
|
| 3365 | - protected function _messages_settings_metaboxes() |
|
| 3366 | - { |
|
| 3367 | - $this->_set_m_mt_settings(); |
|
| 3368 | - $m_boxes = $mt_boxes = array(); |
|
| 3369 | - $m_template_args = $mt_template_args = array(); |
|
| 3370 | - |
|
| 3371 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3372 | - ? $this->_req_data['selected_messenger'] |
|
| 3373 | - : 'email'; |
|
| 3374 | - |
|
| 3375 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3376 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3377 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3378 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3379 | - //messenger meta boxes |
|
| 3380 | - $active = $selected_messenger === $messenger; |
|
| 3381 | - $active_mt_tabs = isset( |
|
| 3382 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3383 | - ) |
|
| 3384 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3385 | - : ''; |
|
| 3386 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3387 | - esc_html__('%s Settings', 'event_espresso'), |
|
| 3388 | - $tab_array['label'] |
|
| 3389 | - ); |
|
| 3390 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 3391 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3392 | - 'inactive_message_types' => isset( |
|
| 3393 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3394 | - ) |
|
| 3395 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3396 | - : '', |
|
| 3397 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3398 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3399 | - 'hide_on_message' => $hide_on_message, |
|
| 3400 | - 'messenger' => $messenger, |
|
| 3401 | - 'active' => $active |
|
| 3402 | - ); |
|
| 3403 | - // message type meta boxes |
|
| 3404 | - // (which is really just the inactive container for each messenger |
|
| 3405 | - // showing inactive message types for that messenger) |
|
| 3406 | - $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3407 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3408 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3409 | - 'inactive_message_types' => isset( |
|
| 3410 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3411 | - ) |
|
| 3412 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3413 | - : '', |
|
| 3414 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3415 | - 'hide_on_message' => $hide_on_message, |
|
| 3416 | - 'hide_off_message' => $hide_off_message, |
|
| 3417 | - 'messenger' => $messenger, |
|
| 3418 | - 'active' => $active |
|
| 3419 | - ); |
|
| 3420 | - } |
|
| 3421 | - } |
|
| 3422 | - |
|
| 3423 | - |
|
| 3424 | - //register messenger metaboxes |
|
| 3425 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3426 | - foreach ($m_boxes as $box => $label) { |
|
| 3427 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3428 | - $msgr = str_replace('_a_box', '', $box); |
|
| 3429 | - add_meta_box( |
|
| 3430 | - 'espresso_' . $msgr . '_settings', |
|
| 3431 | - $label, |
|
| 3432 | - function ($post, $metabox) { |
|
| 3433 | - echo EEH_Template::display_template( |
|
| 3434 | - $metabox["args"]["template_path"], |
|
| 3435 | - $metabox["args"]["template_args"], |
|
| 3436 | - true |
|
| 3437 | - ); |
|
| 3438 | - }, |
|
| 3439 | - $this->_current_screen->id, |
|
| 3440 | - 'normal', |
|
| 3441 | - 'high', |
|
| 3442 | - $callback_args |
|
| 3443 | - ); |
|
| 3444 | - } |
|
| 3445 | - |
|
| 3446 | - //register message type metaboxes |
|
| 3447 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3448 | - foreach ($mt_boxes as $box => $label) { |
|
| 3449 | - $callback_args = array( |
|
| 3450 | - 'template_path' => $mt_template_path, |
|
| 3451 | - 'template_args' => $mt_template_args[$box] |
|
| 3452 | - ); |
|
| 3453 | - $mt = str_replace('_i_box', '', $box); |
|
| 3454 | - add_meta_box( |
|
| 3455 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3456 | - $label, |
|
| 3457 | - function ($post, $metabox) { |
|
| 3458 | - echo EEH_Template::display_template( |
|
| 3459 | - $metabox["args"]["template_path"], |
|
| 3460 | - $metabox["args"]["template_args"], |
|
| 3461 | - true |
|
| 3462 | - ); |
|
| 3463 | - }, |
|
| 3464 | - $this->_current_screen->id, |
|
| 3465 | - 'side', |
|
| 3466 | - 'high', |
|
| 3467 | - $callback_args |
|
| 3468 | - ); |
|
| 3469 | - } |
|
| 3470 | - |
|
| 3471 | - //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3472 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3473 | - if (is_main_site()) { |
|
| 3474 | - add_meta_box( |
|
| 3475 | - 'espresso_global_message_settings', |
|
| 3476 | - esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3477 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 3478 | - $this->_current_screen->id, |
|
| 3479 | - 'normal', |
|
| 3480 | - 'low', |
|
| 3481 | - array() |
|
| 3482 | - ); |
|
| 3483 | - } |
|
| 3484 | - |
|
| 3485 | - } |
|
| 3358 | + /** |
|
| 3359 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3360 | + * |
|
| 3361 | + * @access protected |
|
| 3362 | + * @return void |
|
| 3363 | + * @throws DomainException |
|
| 3364 | + */ |
|
| 3365 | + protected function _messages_settings_metaboxes() |
|
| 3366 | + { |
|
| 3367 | + $this->_set_m_mt_settings(); |
|
| 3368 | + $m_boxes = $mt_boxes = array(); |
|
| 3369 | + $m_template_args = $mt_template_args = array(); |
|
| 3370 | + |
|
| 3371 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3372 | + ? $this->_req_data['selected_messenger'] |
|
| 3373 | + : 'email'; |
|
| 3374 | + |
|
| 3375 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3376 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3377 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3378 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3379 | + //messenger meta boxes |
|
| 3380 | + $active = $selected_messenger === $messenger; |
|
| 3381 | + $active_mt_tabs = isset( |
|
| 3382 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3383 | + ) |
|
| 3384 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3385 | + : ''; |
|
| 3386 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3387 | + esc_html__('%s Settings', 'event_espresso'), |
|
| 3388 | + $tab_array['label'] |
|
| 3389 | + ); |
|
| 3390 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 3391 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3392 | + 'inactive_message_types' => isset( |
|
| 3393 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3394 | + ) |
|
| 3395 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3396 | + : '', |
|
| 3397 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3398 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3399 | + 'hide_on_message' => $hide_on_message, |
|
| 3400 | + 'messenger' => $messenger, |
|
| 3401 | + 'active' => $active |
|
| 3402 | + ); |
|
| 3403 | + // message type meta boxes |
|
| 3404 | + // (which is really just the inactive container for each messenger |
|
| 3405 | + // showing inactive message types for that messenger) |
|
| 3406 | + $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3407 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3408 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3409 | + 'inactive_message_types' => isset( |
|
| 3410 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3411 | + ) |
|
| 3412 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3413 | + : '', |
|
| 3414 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3415 | + 'hide_on_message' => $hide_on_message, |
|
| 3416 | + 'hide_off_message' => $hide_off_message, |
|
| 3417 | + 'messenger' => $messenger, |
|
| 3418 | + 'active' => $active |
|
| 3419 | + ); |
|
| 3420 | + } |
|
| 3421 | + } |
|
| 3422 | + |
|
| 3423 | + |
|
| 3424 | + //register messenger metaboxes |
|
| 3425 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3426 | + foreach ($m_boxes as $box => $label) { |
|
| 3427 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3428 | + $msgr = str_replace('_a_box', '', $box); |
|
| 3429 | + add_meta_box( |
|
| 3430 | + 'espresso_' . $msgr . '_settings', |
|
| 3431 | + $label, |
|
| 3432 | + function ($post, $metabox) { |
|
| 3433 | + echo EEH_Template::display_template( |
|
| 3434 | + $metabox["args"]["template_path"], |
|
| 3435 | + $metabox["args"]["template_args"], |
|
| 3436 | + true |
|
| 3437 | + ); |
|
| 3438 | + }, |
|
| 3439 | + $this->_current_screen->id, |
|
| 3440 | + 'normal', |
|
| 3441 | + 'high', |
|
| 3442 | + $callback_args |
|
| 3443 | + ); |
|
| 3444 | + } |
|
| 3445 | + |
|
| 3446 | + //register message type metaboxes |
|
| 3447 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3448 | + foreach ($mt_boxes as $box => $label) { |
|
| 3449 | + $callback_args = array( |
|
| 3450 | + 'template_path' => $mt_template_path, |
|
| 3451 | + 'template_args' => $mt_template_args[$box] |
|
| 3452 | + ); |
|
| 3453 | + $mt = str_replace('_i_box', '', $box); |
|
| 3454 | + add_meta_box( |
|
| 3455 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 3456 | + $label, |
|
| 3457 | + function ($post, $metabox) { |
|
| 3458 | + echo EEH_Template::display_template( |
|
| 3459 | + $metabox["args"]["template_path"], |
|
| 3460 | + $metabox["args"]["template_args"], |
|
| 3461 | + true |
|
| 3462 | + ); |
|
| 3463 | + }, |
|
| 3464 | + $this->_current_screen->id, |
|
| 3465 | + 'side', |
|
| 3466 | + 'high', |
|
| 3467 | + $callback_args |
|
| 3468 | + ); |
|
| 3469 | + } |
|
| 3470 | + |
|
| 3471 | + //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3472 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3473 | + if (is_main_site()) { |
|
| 3474 | + add_meta_box( |
|
| 3475 | + 'espresso_global_message_settings', |
|
| 3476 | + esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3477 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 3478 | + $this->_current_screen->id, |
|
| 3479 | + 'normal', |
|
| 3480 | + 'low', |
|
| 3481 | + array() |
|
| 3482 | + ); |
|
| 3483 | + } |
|
| 3484 | + |
|
| 3485 | + } |
|
| 3486 | 3486 | |
| 3487 | 3487 | |
| 3488 | - /** |
|
| 3489 | - * This generates the content for the global messages settings metabox. |
|
| 3490 | - * |
|
| 3491 | - * @return string |
|
| 3492 | - * @throws EE_Error |
|
| 3493 | - * @throws InvalidArgumentException |
|
| 3494 | - * @throws ReflectionException |
|
| 3495 | - * @throws InvalidDataTypeException |
|
| 3496 | - * @throws InvalidInterfaceException |
|
| 3497 | - */ |
|
| 3498 | - public function global_messages_settings_metabox_content() |
|
| 3499 | - { |
|
| 3500 | - $form = $this->_generate_global_settings_form(); |
|
| 3501 | - echo $form->form_open( |
|
| 3502 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3503 | - 'POST' |
|
| 3504 | - ) |
|
| 3505 | - . $form->get_html() |
|
| 3506 | - . $form->form_close(); |
|
| 3507 | - } |
|
| 3488 | + /** |
|
| 3489 | + * This generates the content for the global messages settings metabox. |
|
| 3490 | + * |
|
| 3491 | + * @return string |
|
| 3492 | + * @throws EE_Error |
|
| 3493 | + * @throws InvalidArgumentException |
|
| 3494 | + * @throws ReflectionException |
|
| 3495 | + * @throws InvalidDataTypeException |
|
| 3496 | + * @throws InvalidInterfaceException |
|
| 3497 | + */ |
|
| 3498 | + public function global_messages_settings_metabox_content() |
|
| 3499 | + { |
|
| 3500 | + $form = $this->_generate_global_settings_form(); |
|
| 3501 | + echo $form->form_open( |
|
| 3502 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3503 | + 'POST' |
|
| 3504 | + ) |
|
| 3505 | + . $form->get_html() |
|
| 3506 | + . $form->form_close(); |
|
| 3507 | + } |
|
| 3508 | 3508 | |
| 3509 | 3509 | |
| 3510 | - /** |
|
| 3511 | - * This generates and returns the form object for the global messages settings. |
|
| 3512 | - * |
|
| 3513 | - * @return EE_Form_Section_Proper |
|
| 3514 | - * @throws EE_Error |
|
| 3515 | - * @throws InvalidArgumentException |
|
| 3516 | - * @throws ReflectionException |
|
| 3517 | - * @throws InvalidDataTypeException |
|
| 3518 | - * @throws InvalidInterfaceException |
|
| 3519 | - */ |
|
| 3520 | - protected function _generate_global_settings_form() |
|
| 3521 | - { |
|
| 3522 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3523 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3524 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3525 | - |
|
| 3526 | - return new EE_Form_Section_Proper( |
|
| 3527 | - array( |
|
| 3528 | - 'name' => 'global_messages_settings', |
|
| 3529 | - 'html_id' => 'global_messages_settings', |
|
| 3530 | - 'html_class' => 'form-table', |
|
| 3531 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3532 | - 'subsections' => apply_filters( |
|
| 3533 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3534 | - array( |
|
| 3535 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3536 | - array( |
|
| 3537 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3538 | - false => esc_html__("On a separate request", "event_espresso") |
|
| 3539 | - ), |
|
| 3540 | - array( |
|
| 3541 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3542 | - 'html_label_text' => esc_html__( |
|
| 3543 | - 'Generate and send all messages:', |
|
| 3544 | - 'event_espresso' |
|
| 3545 | - ), |
|
| 3546 | - 'html_help_text' => esc_html__( |
|
| 3547 | - 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3548 | - 'event_espresso' |
|
| 3549 | - ), |
|
| 3550 | - ) |
|
| 3551 | - ), |
|
| 3552 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3553 | - array( |
|
| 3554 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3555 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3556 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3557 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3558 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3559 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3560 | - 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3561 | - ), |
|
| 3562 | - array( |
|
| 3563 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3564 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3565 | - 'html_help_text' => esc_html__( |
|
| 3566 | - 'You can control how long a record of processed messages is kept via this option.', |
|
| 3567 | - 'event_espresso' |
|
| 3568 | - ), |
|
| 3569 | - ) |
|
| 3570 | - ), |
|
| 3571 | - 'update_settings' => new EE_Submit_Input( |
|
| 3572 | - array( |
|
| 3573 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3574 | - 'html_label_text' => ' ' |
|
| 3575 | - ) |
|
| 3576 | - ) |
|
| 3577 | - ) |
|
| 3578 | - ) |
|
| 3579 | - ) |
|
| 3580 | - ); |
|
| 3581 | - } |
|
| 3510 | + /** |
|
| 3511 | + * This generates and returns the form object for the global messages settings. |
|
| 3512 | + * |
|
| 3513 | + * @return EE_Form_Section_Proper |
|
| 3514 | + * @throws EE_Error |
|
| 3515 | + * @throws InvalidArgumentException |
|
| 3516 | + * @throws ReflectionException |
|
| 3517 | + * @throws InvalidDataTypeException |
|
| 3518 | + * @throws InvalidInterfaceException |
|
| 3519 | + */ |
|
| 3520 | + protected function _generate_global_settings_form() |
|
| 3521 | + { |
|
| 3522 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3523 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3524 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3525 | + |
|
| 3526 | + return new EE_Form_Section_Proper( |
|
| 3527 | + array( |
|
| 3528 | + 'name' => 'global_messages_settings', |
|
| 3529 | + 'html_id' => 'global_messages_settings', |
|
| 3530 | + 'html_class' => 'form-table', |
|
| 3531 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3532 | + 'subsections' => apply_filters( |
|
| 3533 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3534 | + array( |
|
| 3535 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3536 | + array( |
|
| 3537 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3538 | + false => esc_html__("On a separate request", "event_espresso") |
|
| 3539 | + ), |
|
| 3540 | + array( |
|
| 3541 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3542 | + 'html_label_text' => esc_html__( |
|
| 3543 | + 'Generate and send all messages:', |
|
| 3544 | + 'event_espresso' |
|
| 3545 | + ), |
|
| 3546 | + 'html_help_text' => esc_html__( |
|
| 3547 | + 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3548 | + 'event_espresso' |
|
| 3549 | + ), |
|
| 3550 | + ) |
|
| 3551 | + ), |
|
| 3552 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3553 | + array( |
|
| 3554 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3555 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3556 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3557 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3558 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3559 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3560 | + 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3561 | + ), |
|
| 3562 | + array( |
|
| 3563 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3564 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3565 | + 'html_help_text' => esc_html__( |
|
| 3566 | + 'You can control how long a record of processed messages is kept via this option.', |
|
| 3567 | + 'event_espresso' |
|
| 3568 | + ), |
|
| 3569 | + ) |
|
| 3570 | + ), |
|
| 3571 | + 'update_settings' => new EE_Submit_Input( |
|
| 3572 | + array( |
|
| 3573 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3574 | + 'html_label_text' => ' ' |
|
| 3575 | + ) |
|
| 3576 | + ) |
|
| 3577 | + ) |
|
| 3578 | + ) |
|
| 3579 | + ) |
|
| 3580 | + ); |
|
| 3581 | + } |
|
| 3582 | 3582 | |
| 3583 | 3583 | |
| 3584 | - /** |
|
| 3585 | - * This handles updating the global settings set on the admin page. |
|
| 3586 | - * |
|
| 3587 | - * @throws EE_Error |
|
| 3588 | - * @throws InvalidDataTypeException |
|
| 3589 | - * @throws InvalidInterfaceException |
|
| 3590 | - * @throws InvalidArgumentException |
|
| 3591 | - * @throws ReflectionException |
|
| 3592 | - */ |
|
| 3593 | - protected function _update_global_settings() |
|
| 3594 | - { |
|
| 3595 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3596 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3597 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3598 | - $form = $this->_generate_global_settings_form(); |
|
| 3599 | - if ($form->was_submitted()) { |
|
| 3600 | - $form->receive_form_submission(); |
|
| 3601 | - if ($form->is_valid()) { |
|
| 3602 | - $valid_data = $form->valid_data(); |
|
| 3603 | - foreach ($valid_data as $property => $value) { |
|
| 3604 | - $setter = 'set_' . $property; |
|
| 3605 | - if (method_exists($network_config, $setter)) { |
|
| 3606 | - $network_config->{$setter}($value); |
|
| 3607 | - } else if ( |
|
| 3608 | - property_exists($network_config, $property) |
|
| 3609 | - && $network_config->{$property} !== $value |
|
| 3610 | - ) { |
|
| 3611 | - $network_config->{$property} = $value; |
|
| 3612 | - } else if ( |
|
| 3613 | - property_exists($messages_config, $property) |
|
| 3614 | - && $messages_config->{$property} !== $value |
|
| 3615 | - ) { |
|
| 3616 | - $messages_config->{$property} = $value; |
|
| 3617 | - } |
|
| 3618 | - } |
|
| 3619 | - //only update if the form submission was valid! |
|
| 3620 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3621 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3622 | - EE_Error::overwrite_success(); |
|
| 3623 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3624 | - } |
|
| 3625 | - } |
|
| 3626 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3627 | - } |
|
| 3584 | + /** |
|
| 3585 | + * This handles updating the global settings set on the admin page. |
|
| 3586 | + * |
|
| 3587 | + * @throws EE_Error |
|
| 3588 | + * @throws InvalidDataTypeException |
|
| 3589 | + * @throws InvalidInterfaceException |
|
| 3590 | + * @throws InvalidArgumentException |
|
| 3591 | + * @throws ReflectionException |
|
| 3592 | + */ |
|
| 3593 | + protected function _update_global_settings() |
|
| 3594 | + { |
|
| 3595 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3596 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3597 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3598 | + $form = $this->_generate_global_settings_form(); |
|
| 3599 | + if ($form->was_submitted()) { |
|
| 3600 | + $form->receive_form_submission(); |
|
| 3601 | + if ($form->is_valid()) { |
|
| 3602 | + $valid_data = $form->valid_data(); |
|
| 3603 | + foreach ($valid_data as $property => $value) { |
|
| 3604 | + $setter = 'set_' . $property; |
|
| 3605 | + if (method_exists($network_config, $setter)) { |
|
| 3606 | + $network_config->{$setter}($value); |
|
| 3607 | + } else if ( |
|
| 3608 | + property_exists($network_config, $property) |
|
| 3609 | + && $network_config->{$property} !== $value |
|
| 3610 | + ) { |
|
| 3611 | + $network_config->{$property} = $value; |
|
| 3612 | + } else if ( |
|
| 3613 | + property_exists($messages_config, $property) |
|
| 3614 | + && $messages_config->{$property} !== $value |
|
| 3615 | + ) { |
|
| 3616 | + $messages_config->{$property} = $value; |
|
| 3617 | + } |
|
| 3618 | + } |
|
| 3619 | + //only update if the form submission was valid! |
|
| 3620 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3621 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3622 | + EE_Error::overwrite_success(); |
|
| 3623 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3624 | + } |
|
| 3625 | + } |
|
| 3626 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3627 | + } |
|
| 3628 | 3628 | |
| 3629 | 3629 | |
| 3630 | - /** |
|
| 3631 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3632 | - * |
|
| 3633 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3634 | - * @return string html formatted tabs |
|
| 3635 | - * @throws DomainException |
|
| 3636 | - */ |
|
| 3637 | - protected function _get_mt_tabs($tab_array) |
|
| 3638 | - { |
|
| 3639 | - $tab_array = (array)$tab_array; |
|
| 3640 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3641 | - $tabs = ''; |
|
| 3642 | - |
|
| 3643 | - foreach ($tab_array as $tab) { |
|
| 3644 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3645 | - } |
|
| 3646 | - |
|
| 3647 | - return $tabs; |
|
| 3648 | - } |
|
| 3630 | + /** |
|
| 3631 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3632 | + * |
|
| 3633 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3634 | + * @return string html formatted tabs |
|
| 3635 | + * @throws DomainException |
|
| 3636 | + */ |
|
| 3637 | + protected function _get_mt_tabs($tab_array) |
|
| 3638 | + { |
|
| 3639 | + $tab_array = (array)$tab_array; |
|
| 3640 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3641 | + $tabs = ''; |
|
| 3642 | + |
|
| 3643 | + foreach ($tab_array as $tab) { |
|
| 3644 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3645 | + } |
|
| 3646 | + |
|
| 3647 | + return $tabs; |
|
| 3648 | + } |
|
| 3649 | 3649 | |
| 3650 | 3650 | |
| 3651 | - /** |
|
| 3652 | - * This prepares the content of the messenger meta box admin settings |
|
| 3653 | - * |
|
| 3654 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3655 | - * @return string html formatted content |
|
| 3656 | - * @throws DomainException |
|
| 3657 | - */ |
|
| 3658 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3659 | - { |
|
| 3651 | + /** |
|
| 3652 | + * This prepares the content of the messenger meta box admin settings |
|
| 3653 | + * |
|
| 3654 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3655 | + * @return string html formatted content |
|
| 3656 | + * @throws DomainException |
|
| 3657 | + */ |
|
| 3658 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3659 | + { |
|
| 3660 | 3660 | |
| 3661 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3662 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3661 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3662 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3663 | 3663 | |
| 3664 | - //is $messenger active? |
|
| 3665 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3664 | + //is $messenger active? |
|
| 3665 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3666 | 3666 | |
| 3667 | 3667 | |
| 3668 | - if ( ! empty($fields)) { |
|
| 3668 | + if ( ! empty($fields)) { |
|
| 3669 | 3669 | |
| 3670 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3670 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3671 | 3671 | |
| 3672 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3673 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3674 | - $template_form_field[$field_id] = array( |
|
| 3675 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3676 | - 'label' => $fldprops['label'], |
|
| 3677 | - 'input' => $fldprops['field_type'], |
|
| 3678 | - 'type' => $fldprops['value_type'], |
|
| 3679 | - 'required' => $fldprops['required'], |
|
| 3680 | - 'validation' => $fldprops['validation'], |
|
| 3681 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3682 | - ? $existing_settings[$field_id] |
|
| 3683 | - : $fldprops['default'], |
|
| 3684 | - 'css_class' => '', |
|
| 3685 | - 'format' => $fldprops['format'] |
|
| 3686 | - ); |
|
| 3687 | - } |
|
| 3672 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3673 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3674 | + $template_form_field[$field_id] = array( |
|
| 3675 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3676 | + 'label' => $fldprops['label'], |
|
| 3677 | + 'input' => $fldprops['field_type'], |
|
| 3678 | + 'type' => $fldprops['value_type'], |
|
| 3679 | + 'required' => $fldprops['required'], |
|
| 3680 | + 'validation' => $fldprops['validation'], |
|
| 3681 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3682 | + ? $existing_settings[$field_id] |
|
| 3683 | + : $fldprops['default'], |
|
| 3684 | + 'css_class' => '', |
|
| 3685 | + 'format' => $fldprops['format'] |
|
| 3686 | + ); |
|
| 3687 | + } |
|
| 3688 | 3688 | |
| 3689 | 3689 | |
| 3690 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3691 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3692 | - : ''; |
|
| 3693 | - } |
|
| 3694 | - |
|
| 3695 | - //we also need some hidden fields |
|
| 3696 | - $settings_template_args['hidden_fields'] = array( |
|
| 3697 | - 'messenger_settings[messenger]' => array( |
|
| 3698 | - 'type' => 'hidden', |
|
| 3699 | - 'value' => $messenger->name |
|
| 3700 | - ), |
|
| 3701 | - 'type' => array( |
|
| 3702 | - 'type' => 'hidden', |
|
| 3703 | - 'value' => 'messenger' |
|
| 3704 | - ) |
|
| 3705 | - ); |
|
| 3706 | - |
|
| 3707 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3708 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3709 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3710 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3711 | - 'type' => 'hidden', |
|
| 3712 | - 'value' => $mt |
|
| 3713 | - ); |
|
| 3714 | - } |
|
| 3715 | - } |
|
| 3716 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3717 | - $settings_template_args['hidden_fields'], |
|
| 3718 | - 'array' |
|
| 3719 | - ); |
|
| 3720 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3721 | - |
|
| 3722 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3723 | - $settings_template_args['description'] = $messenger->description; |
|
| 3724 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3725 | - |
|
| 3726 | - |
|
| 3727 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3728 | - $messenger->name |
|
| 3729 | - ) |
|
| 3730 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3731 | - : ' hidden'; |
|
| 3732 | - |
|
| 3733 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3734 | - ? ' hidden' |
|
| 3735 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3736 | - |
|
| 3737 | - |
|
| 3738 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3739 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3740 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3741 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3742 | - $content = EEH_Template::display_template( |
|
| 3743 | - $template, |
|
| 3744 | - $settings_template_args, |
|
| 3745 | - true |
|
| 3746 | - ); |
|
| 3747 | - |
|
| 3748 | - return $content; |
|
| 3749 | - } |
|
| 3690 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3691 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3692 | + : ''; |
|
| 3693 | + } |
|
| 3694 | + |
|
| 3695 | + //we also need some hidden fields |
|
| 3696 | + $settings_template_args['hidden_fields'] = array( |
|
| 3697 | + 'messenger_settings[messenger]' => array( |
|
| 3698 | + 'type' => 'hidden', |
|
| 3699 | + 'value' => $messenger->name |
|
| 3700 | + ), |
|
| 3701 | + 'type' => array( |
|
| 3702 | + 'type' => 'hidden', |
|
| 3703 | + 'value' => 'messenger' |
|
| 3704 | + ) |
|
| 3705 | + ); |
|
| 3706 | + |
|
| 3707 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3708 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3709 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3710 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3711 | + 'type' => 'hidden', |
|
| 3712 | + 'value' => $mt |
|
| 3713 | + ); |
|
| 3714 | + } |
|
| 3715 | + } |
|
| 3716 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3717 | + $settings_template_args['hidden_fields'], |
|
| 3718 | + 'array' |
|
| 3719 | + ); |
|
| 3720 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3721 | + |
|
| 3722 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3723 | + $settings_template_args['description'] = $messenger->description; |
|
| 3724 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3725 | + |
|
| 3726 | + |
|
| 3727 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3728 | + $messenger->name |
|
| 3729 | + ) |
|
| 3730 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3731 | + : ' hidden'; |
|
| 3732 | + |
|
| 3733 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3734 | + ? ' hidden' |
|
| 3735 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3736 | + |
|
| 3737 | + |
|
| 3738 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3739 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3740 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3741 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3742 | + $content = EEH_Template::display_template( |
|
| 3743 | + $template, |
|
| 3744 | + $settings_template_args, |
|
| 3745 | + true |
|
| 3746 | + ); |
|
| 3747 | + |
|
| 3748 | + return $content; |
|
| 3749 | + } |
|
| 3750 | 3750 | |
| 3751 | 3751 | |
| 3752 | - /** |
|
| 3753 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3754 | - * |
|
| 3755 | - * @throws DomainException |
|
| 3756 | - * @throws EE_Error |
|
| 3757 | - * @throws InvalidDataTypeException |
|
| 3758 | - * @throws InvalidInterfaceException |
|
| 3759 | - * @throws InvalidArgumentException |
|
| 3760 | - * @throws ReflectionException |
|
| 3761 | - */ |
|
| 3762 | - public function activate_messenger_toggle() |
|
| 3763 | - { |
|
| 3764 | - $success = true; |
|
| 3765 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3766 | - //let's check that we have required data |
|
| 3767 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3768 | - EE_Error::add_error( |
|
| 3769 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3770 | - __FILE__, |
|
| 3771 | - __FUNCTION__, |
|
| 3772 | - __LINE__ |
|
| 3773 | - ); |
|
| 3774 | - $success = false; |
|
| 3775 | - } |
|
| 3776 | - |
|
| 3777 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3778 | - $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3779 | - ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3780 | - : ''; |
|
| 3781 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3782 | - |
|
| 3783 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3784 | - |
|
| 3785 | - |
|
| 3786 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3787 | - EE_Error::add_error( |
|
| 3788 | - esc_html__( |
|
| 3789 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3790 | - 'event_espresso' |
|
| 3791 | - ), |
|
| 3792 | - __FILE__, |
|
| 3793 | - __FUNCTION__, |
|
| 3794 | - __LINE__ |
|
| 3795 | - ); |
|
| 3796 | - $success = false; |
|
| 3797 | - } |
|
| 3798 | - |
|
| 3799 | - //do check to verify we have a valid status. |
|
| 3800 | - $status = $this->_req_data['status']; |
|
| 3801 | - |
|
| 3802 | - if ($status !== 'off' && $status !== 'on') { |
|
| 3803 | - EE_Error::add_error( |
|
| 3804 | - sprintf( |
|
| 3805 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3806 | - $this->_req_data['status'] |
|
| 3807 | - ), |
|
| 3808 | - __FILE__, |
|
| 3809 | - __FUNCTION__, |
|
| 3810 | - __LINE__ |
|
| 3811 | - ); |
|
| 3812 | - $success = false; |
|
| 3813 | - } |
|
| 3814 | - |
|
| 3815 | - if ($success) { |
|
| 3816 | - //made it here? Stop dawdling then!! |
|
| 3817 | - $success = $status === 'off' |
|
| 3818 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3819 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3820 | - } |
|
| 3821 | - |
|
| 3822 | - $this->_template_args['success'] = $success; |
|
| 3823 | - |
|
| 3824 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3825 | - $this->_return_json(); |
|
| 3826 | - |
|
| 3827 | - } |
|
| 3752 | + /** |
|
| 3753 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3754 | + * |
|
| 3755 | + * @throws DomainException |
|
| 3756 | + * @throws EE_Error |
|
| 3757 | + * @throws InvalidDataTypeException |
|
| 3758 | + * @throws InvalidInterfaceException |
|
| 3759 | + * @throws InvalidArgumentException |
|
| 3760 | + * @throws ReflectionException |
|
| 3761 | + */ |
|
| 3762 | + public function activate_messenger_toggle() |
|
| 3763 | + { |
|
| 3764 | + $success = true; |
|
| 3765 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3766 | + //let's check that we have required data |
|
| 3767 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3768 | + EE_Error::add_error( |
|
| 3769 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3770 | + __FILE__, |
|
| 3771 | + __FUNCTION__, |
|
| 3772 | + __LINE__ |
|
| 3773 | + ); |
|
| 3774 | + $success = false; |
|
| 3775 | + } |
|
| 3776 | + |
|
| 3777 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3778 | + $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3779 | + ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3780 | + : ''; |
|
| 3781 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3782 | + |
|
| 3783 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3784 | + |
|
| 3785 | + |
|
| 3786 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3787 | + EE_Error::add_error( |
|
| 3788 | + esc_html__( |
|
| 3789 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3790 | + 'event_espresso' |
|
| 3791 | + ), |
|
| 3792 | + __FILE__, |
|
| 3793 | + __FUNCTION__, |
|
| 3794 | + __LINE__ |
|
| 3795 | + ); |
|
| 3796 | + $success = false; |
|
| 3797 | + } |
|
| 3798 | + |
|
| 3799 | + //do check to verify we have a valid status. |
|
| 3800 | + $status = $this->_req_data['status']; |
|
| 3801 | + |
|
| 3802 | + if ($status !== 'off' && $status !== 'on') { |
|
| 3803 | + EE_Error::add_error( |
|
| 3804 | + sprintf( |
|
| 3805 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3806 | + $this->_req_data['status'] |
|
| 3807 | + ), |
|
| 3808 | + __FILE__, |
|
| 3809 | + __FUNCTION__, |
|
| 3810 | + __LINE__ |
|
| 3811 | + ); |
|
| 3812 | + $success = false; |
|
| 3813 | + } |
|
| 3814 | + |
|
| 3815 | + if ($success) { |
|
| 3816 | + //made it here? Stop dawdling then!! |
|
| 3817 | + $success = $status === 'off' |
|
| 3818 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3819 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3820 | + } |
|
| 3821 | + |
|
| 3822 | + $this->_template_args['success'] = $success; |
|
| 3823 | + |
|
| 3824 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3825 | + $this->_return_json(); |
|
| 3826 | + |
|
| 3827 | + } |
|
| 3828 | 3828 | |
| 3829 | 3829 | |
| 3830 | - /** |
|
| 3831 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3832 | - * |
|
| 3833 | - * @throws DomainException |
|
| 3834 | - * @throws EE_Error |
|
| 3835 | - * @throws ReflectionException |
|
| 3836 | - * @throws InvalidDataTypeException |
|
| 3837 | - * @throws InvalidInterfaceException |
|
| 3838 | - * @throws InvalidArgumentException |
|
| 3839 | - */ |
|
| 3840 | - public function activate_mt_toggle() |
|
| 3841 | - { |
|
| 3842 | - $success = true; |
|
| 3843 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3844 | - |
|
| 3845 | - //let's make sure we have the necessary data |
|
| 3846 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3847 | - EE_Error::add_error( |
|
| 3848 | - esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3849 | - __FILE__, |
|
| 3850 | - __FUNCTION__, |
|
| 3851 | - __LINE__ |
|
| 3852 | - ); |
|
| 3853 | - $success = false; |
|
| 3854 | - } |
|
| 3855 | - |
|
| 3856 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3857 | - EE_Error::add_error( |
|
| 3858 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3859 | - __FILE__, |
|
| 3860 | - __FUNCTION__, |
|
| 3861 | - __LINE__ |
|
| 3862 | - ); |
|
| 3863 | - $success = false; |
|
| 3864 | - } |
|
| 3865 | - |
|
| 3866 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3867 | - EE_Error::add_error( |
|
| 3868 | - esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3869 | - 'event_espresso'), |
|
| 3870 | - __FILE__, |
|
| 3871 | - __FUNCTION__, |
|
| 3872 | - __LINE__ |
|
| 3873 | - ); |
|
| 3874 | - $success = false; |
|
| 3875 | - } |
|
| 3876 | - |
|
| 3877 | - |
|
| 3878 | - //do check to verify we have a valid status. |
|
| 3879 | - $status = $this->_req_data['status']; |
|
| 3880 | - |
|
| 3881 | - if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3882 | - EE_Error::add_error( |
|
| 3883 | - sprintf( |
|
| 3884 | - esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3885 | - $this->_req_data['status'] |
|
| 3886 | - ), |
|
| 3887 | - __FILE__, |
|
| 3888 | - __FUNCTION__, |
|
| 3889 | - __LINE__ |
|
| 3890 | - ); |
|
| 3891 | - $success = false; |
|
| 3892 | - } |
|
| 3893 | - |
|
| 3894 | - |
|
| 3895 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3896 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3897 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3898 | - |
|
| 3899 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3900 | - |
|
| 3901 | - if ($success) { |
|
| 3902 | - //made it here? um, what are you waiting for then? |
|
| 3903 | - $success = $status === 'deactivate' |
|
| 3904 | - ? $this->_deactivate_message_type_for_messenger( |
|
| 3905 | - $this->_req_data['messenger'], |
|
| 3906 | - $this->_req_data['message_type'] |
|
| 3907 | - ) |
|
| 3908 | - : $this->_activate_message_type_for_messenger( |
|
| 3909 | - $this->_req_data['messenger'], |
|
| 3910 | - $this->_req_data['message_type'] |
|
| 3911 | - ); |
|
| 3912 | - } |
|
| 3913 | - |
|
| 3914 | - $this->_template_args['success'] = $success; |
|
| 3915 | - $this->_return_json(); |
|
| 3916 | - } |
|
| 3830 | + /** |
|
| 3831 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3832 | + * |
|
| 3833 | + * @throws DomainException |
|
| 3834 | + * @throws EE_Error |
|
| 3835 | + * @throws ReflectionException |
|
| 3836 | + * @throws InvalidDataTypeException |
|
| 3837 | + * @throws InvalidInterfaceException |
|
| 3838 | + * @throws InvalidArgumentException |
|
| 3839 | + */ |
|
| 3840 | + public function activate_mt_toggle() |
|
| 3841 | + { |
|
| 3842 | + $success = true; |
|
| 3843 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3844 | + |
|
| 3845 | + //let's make sure we have the necessary data |
|
| 3846 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3847 | + EE_Error::add_error( |
|
| 3848 | + esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3849 | + __FILE__, |
|
| 3850 | + __FUNCTION__, |
|
| 3851 | + __LINE__ |
|
| 3852 | + ); |
|
| 3853 | + $success = false; |
|
| 3854 | + } |
|
| 3855 | + |
|
| 3856 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3857 | + EE_Error::add_error( |
|
| 3858 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3859 | + __FILE__, |
|
| 3860 | + __FUNCTION__, |
|
| 3861 | + __LINE__ |
|
| 3862 | + ); |
|
| 3863 | + $success = false; |
|
| 3864 | + } |
|
| 3865 | + |
|
| 3866 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3867 | + EE_Error::add_error( |
|
| 3868 | + esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3869 | + 'event_espresso'), |
|
| 3870 | + __FILE__, |
|
| 3871 | + __FUNCTION__, |
|
| 3872 | + __LINE__ |
|
| 3873 | + ); |
|
| 3874 | + $success = false; |
|
| 3875 | + } |
|
| 3876 | + |
|
| 3877 | + |
|
| 3878 | + //do check to verify we have a valid status. |
|
| 3879 | + $status = $this->_req_data['status']; |
|
| 3880 | + |
|
| 3881 | + if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3882 | + EE_Error::add_error( |
|
| 3883 | + sprintf( |
|
| 3884 | + esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3885 | + $this->_req_data['status'] |
|
| 3886 | + ), |
|
| 3887 | + __FILE__, |
|
| 3888 | + __FUNCTION__, |
|
| 3889 | + __LINE__ |
|
| 3890 | + ); |
|
| 3891 | + $success = false; |
|
| 3892 | + } |
|
| 3893 | + |
|
| 3894 | + |
|
| 3895 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3896 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3897 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3898 | + |
|
| 3899 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3900 | + |
|
| 3901 | + if ($success) { |
|
| 3902 | + //made it here? um, what are you waiting for then? |
|
| 3903 | + $success = $status === 'deactivate' |
|
| 3904 | + ? $this->_deactivate_message_type_for_messenger( |
|
| 3905 | + $this->_req_data['messenger'], |
|
| 3906 | + $this->_req_data['message_type'] |
|
| 3907 | + ) |
|
| 3908 | + : $this->_activate_message_type_for_messenger( |
|
| 3909 | + $this->_req_data['messenger'], |
|
| 3910 | + $this->_req_data['message_type'] |
|
| 3911 | + ); |
|
| 3912 | + } |
|
| 3913 | + |
|
| 3914 | + $this->_template_args['success'] = $success; |
|
| 3915 | + $this->_return_json(); |
|
| 3916 | + } |
|
| 3917 | 3917 | |
| 3918 | 3918 | |
| 3919 | - /** |
|
| 3920 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3921 | - * |
|
| 3922 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3923 | - * @return bool |
|
| 3924 | - * @throws DomainException |
|
| 3925 | - * @throws EE_Error |
|
| 3926 | - * @throws InvalidArgumentException |
|
| 3927 | - * @throws ReflectionException |
|
| 3928 | - * @throws InvalidDataTypeException |
|
| 3929 | - * @throws InvalidInterfaceException |
|
| 3930 | - */ |
|
| 3931 | - protected function _activate_messenger($messenger_name) |
|
| 3932 | - { |
|
| 3933 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3934 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3935 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3936 | - ? $active_messenger->get_default_message_types() |
|
| 3937 | - : array(); |
|
| 3938 | - |
|
| 3939 | - //ensure is active |
|
| 3940 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3941 | - |
|
| 3942 | - //set response_data for reload |
|
| 3943 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3944 | - /** @var EE_message_type $message_type */ |
|
| 3945 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3946 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3947 | - $messenger_name, |
|
| 3948 | - $message_type_name |
|
| 3949 | - ) |
|
| 3950 | - && $message_type instanceof EE_message_type |
|
| 3951 | - ) { |
|
| 3952 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3953 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3954 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3955 | - } |
|
| 3956 | - } |
|
| 3957 | - } |
|
| 3958 | - |
|
| 3959 | - //add success message for activating messenger |
|
| 3960 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3961 | - |
|
| 3962 | - } |
|
| 3919 | + /** |
|
| 3920 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3921 | + * |
|
| 3922 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3923 | + * @return bool |
|
| 3924 | + * @throws DomainException |
|
| 3925 | + * @throws EE_Error |
|
| 3926 | + * @throws InvalidArgumentException |
|
| 3927 | + * @throws ReflectionException |
|
| 3928 | + * @throws InvalidDataTypeException |
|
| 3929 | + * @throws InvalidInterfaceException |
|
| 3930 | + */ |
|
| 3931 | + protected function _activate_messenger($messenger_name) |
|
| 3932 | + { |
|
| 3933 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3934 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3935 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3936 | + ? $active_messenger->get_default_message_types() |
|
| 3937 | + : array(); |
|
| 3938 | + |
|
| 3939 | + //ensure is active |
|
| 3940 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3941 | + |
|
| 3942 | + //set response_data for reload |
|
| 3943 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3944 | + /** @var EE_message_type $message_type */ |
|
| 3945 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3946 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3947 | + $messenger_name, |
|
| 3948 | + $message_type_name |
|
| 3949 | + ) |
|
| 3950 | + && $message_type instanceof EE_message_type |
|
| 3951 | + ) { |
|
| 3952 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3953 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3954 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3955 | + } |
|
| 3956 | + } |
|
| 3957 | + } |
|
| 3958 | + |
|
| 3959 | + //add success message for activating messenger |
|
| 3960 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3961 | + |
|
| 3962 | + } |
|
| 3963 | 3963 | |
| 3964 | 3964 | |
| 3965 | - /** |
|
| 3966 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3967 | - * |
|
| 3968 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3969 | - * @return bool |
|
| 3970 | - * @throws DomainException |
|
| 3971 | - * @throws EE_Error |
|
| 3972 | - * @throws InvalidArgumentException |
|
| 3973 | - * @throws ReflectionException |
|
| 3974 | - * @throws InvalidDataTypeException |
|
| 3975 | - * @throws InvalidInterfaceException |
|
| 3976 | - */ |
|
| 3977 | - protected function _deactivate_messenger($messenger_name) |
|
| 3978 | - { |
|
| 3979 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3980 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3981 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3982 | - |
|
| 3983 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3984 | - } |
|
| 3965 | + /** |
|
| 3966 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3967 | + * |
|
| 3968 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3969 | + * @return bool |
|
| 3970 | + * @throws DomainException |
|
| 3971 | + * @throws EE_Error |
|
| 3972 | + * @throws InvalidArgumentException |
|
| 3973 | + * @throws ReflectionException |
|
| 3974 | + * @throws InvalidDataTypeException |
|
| 3975 | + * @throws InvalidInterfaceException |
|
| 3976 | + */ |
|
| 3977 | + protected function _deactivate_messenger($messenger_name) |
|
| 3978 | + { |
|
| 3979 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3980 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3981 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3982 | + |
|
| 3983 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3984 | + } |
|
| 3985 | 3985 | |
| 3986 | 3986 | |
| 3987 | - /** |
|
| 3988 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3989 | - * |
|
| 3990 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3991 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3992 | - * @return bool |
|
| 3993 | - * @throws DomainException |
|
| 3994 | - * @throws EE_Error |
|
| 3995 | - * @throws InvalidArgumentException |
|
| 3996 | - * @throws ReflectionException |
|
| 3997 | - * @throws InvalidDataTypeException |
|
| 3998 | - * @throws InvalidInterfaceException |
|
| 3999 | - */ |
|
| 4000 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4001 | - { |
|
| 4002 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4003 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4004 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4005 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4006 | - |
|
| 4007 | - //ensure is active |
|
| 4008 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 4009 | - |
|
| 4010 | - //set response for load |
|
| 4011 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 4012 | - $message_type_name) |
|
| 4013 | - ) { |
|
| 4014 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 4015 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 4016 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 4017 | - } |
|
| 4018 | - } |
|
| 4019 | - |
|
| 4020 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 4021 | - $message_type_to_activate); |
|
| 4022 | - } |
|
| 3987 | + /** |
|
| 3988 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3989 | + * |
|
| 3990 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3991 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3992 | + * @return bool |
|
| 3993 | + * @throws DomainException |
|
| 3994 | + * @throws EE_Error |
|
| 3995 | + * @throws InvalidArgumentException |
|
| 3996 | + * @throws ReflectionException |
|
| 3997 | + * @throws InvalidDataTypeException |
|
| 3998 | + * @throws InvalidInterfaceException |
|
| 3999 | + */ |
|
| 4000 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4001 | + { |
|
| 4002 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4003 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4004 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4005 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4006 | + |
|
| 4007 | + //ensure is active |
|
| 4008 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 4009 | + |
|
| 4010 | + //set response for load |
|
| 4011 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 4012 | + $message_type_name) |
|
| 4013 | + ) { |
|
| 4014 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 4015 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 4016 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 4017 | + } |
|
| 4018 | + } |
|
| 4019 | + |
|
| 4020 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 4021 | + $message_type_to_activate); |
|
| 4022 | + } |
|
| 4023 | 4023 | |
| 4024 | 4024 | |
| 4025 | - /** |
|
| 4026 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 4027 | - * |
|
| 4028 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 4029 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 4030 | - * @return bool |
|
| 4031 | - * @throws DomainException |
|
| 4032 | - * @throws EE_Error |
|
| 4033 | - * @throws InvalidArgumentException |
|
| 4034 | - * @throws ReflectionException |
|
| 4035 | - * @throws InvalidDataTypeException |
|
| 4036 | - * @throws InvalidInterfaceException |
|
| 4037 | - */ |
|
| 4038 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4039 | - { |
|
| 4040 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4041 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4042 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4043 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4044 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 4045 | - |
|
| 4046 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 4047 | - $message_type_to_deactivate); |
|
| 4048 | - } |
|
| 4025 | + /** |
|
| 4026 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 4027 | + * |
|
| 4028 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 4029 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 4030 | + * @return bool |
|
| 4031 | + * @throws DomainException |
|
| 4032 | + * @throws EE_Error |
|
| 4033 | + * @throws InvalidArgumentException |
|
| 4034 | + * @throws ReflectionException |
|
| 4035 | + * @throws InvalidDataTypeException |
|
| 4036 | + * @throws InvalidInterfaceException |
|
| 4037 | + */ |
|
| 4038 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4039 | + { |
|
| 4040 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4041 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4042 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4043 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4044 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 4045 | + |
|
| 4046 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 4047 | + $message_type_to_deactivate); |
|
| 4048 | + } |
|
| 4049 | 4049 | |
| 4050 | 4050 | |
| 4051 | - /** |
|
| 4052 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 4053 | - */ |
|
| 4054 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4055 | - { |
|
| 4056 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 4057 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 4058 | - } |
|
| 4051 | + /** |
|
| 4052 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 4053 | + */ |
|
| 4054 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4055 | + { |
|
| 4056 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 4057 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 4058 | + } |
|
| 4059 | 4059 | |
| 4060 | 4060 | |
| 4061 | - /** |
|
| 4062 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 4063 | - * |
|
| 4064 | - * @param EE_messenger $messenger |
|
| 4065 | - * @param EE_message_type|null $message_type |
|
| 4066 | - * @return bool |
|
| 4067 | - * @throws DomainException |
|
| 4068 | - * @throws EE_Error |
|
| 4069 | - * @throws InvalidArgumentException |
|
| 4070 | - * @throws ReflectionException |
|
| 4071 | - * @throws InvalidDataTypeException |
|
| 4072 | - * @throws InvalidInterfaceException |
|
| 4073 | - */ |
|
| 4074 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4075 | - $messenger, |
|
| 4076 | - EE_Message_Type $message_type = null |
|
| 4077 | - ) { |
|
| 4078 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4079 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4080 | - EE_Error::add_error( |
|
| 4081 | - esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4082 | - __FILE__, |
|
| 4083 | - __FUNCTION__, |
|
| 4084 | - __LINE__ |
|
| 4085 | - ); |
|
| 4061 | + /** |
|
| 4062 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 4063 | + * |
|
| 4064 | + * @param EE_messenger $messenger |
|
| 4065 | + * @param EE_message_type|null $message_type |
|
| 4066 | + * @return bool |
|
| 4067 | + * @throws DomainException |
|
| 4068 | + * @throws EE_Error |
|
| 4069 | + * @throws InvalidArgumentException |
|
| 4070 | + * @throws ReflectionException |
|
| 4071 | + * @throws InvalidDataTypeException |
|
| 4072 | + * @throws InvalidInterfaceException |
|
| 4073 | + */ |
|
| 4074 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4075 | + $messenger, |
|
| 4076 | + EE_Message_Type $message_type = null |
|
| 4077 | + ) { |
|
| 4078 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4079 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4080 | + EE_Error::add_error( |
|
| 4081 | + esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4082 | + __FILE__, |
|
| 4083 | + __FUNCTION__, |
|
| 4084 | + __LINE__ |
|
| 4085 | + ); |
|
| 4086 | 4086 | |
| 4087 | - return false; |
|
| 4088 | - } |
|
| 4089 | - //activated |
|
| 4090 | - if ($this->_template_args['data']['active_mts']) { |
|
| 4091 | - EE_Error::overwrite_success(); |
|
| 4092 | - //activated a message type with the messenger |
|
| 4093 | - if ($message_type instanceof EE_message_type) { |
|
| 4094 | - EE_Error::add_success( |
|
| 4095 | - sprintf( |
|
| 4096 | - esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4097 | - ucwords($message_type->label['singular']), |
|
| 4098 | - ucwords($messenger->label['singular']) |
|
| 4099 | - ) |
|
| 4100 | - ); |
|
| 4087 | + return false; |
|
| 4088 | + } |
|
| 4089 | + //activated |
|
| 4090 | + if ($this->_template_args['data']['active_mts']) { |
|
| 4091 | + EE_Error::overwrite_success(); |
|
| 4092 | + //activated a message type with the messenger |
|
| 4093 | + if ($message_type instanceof EE_message_type) { |
|
| 4094 | + EE_Error::add_success( |
|
| 4095 | + sprintf( |
|
| 4096 | + esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4097 | + ucwords($message_type->label['singular']), |
|
| 4098 | + ucwords($messenger->label['singular']) |
|
| 4099 | + ) |
|
| 4100 | + ); |
|
| 4101 | 4101 | |
| 4102 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4103 | - if ($message_type->name === 'invoice') { |
|
| 4104 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4105 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4106 | - if ($pm instanceof EE_Payment_Method) { |
|
| 4107 | - EE_Error::add_attention( |
|
| 4108 | - esc_html__( |
|
| 4109 | - 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4110 | - 'event_espresso' |
|
| 4111 | - ) |
|
| 4112 | - ); |
|
| 4113 | - } |
|
| 4114 | - } |
|
| 4115 | - //just toggles the entire messenger |
|
| 4116 | - } else { |
|
| 4117 | - EE_Error::add_success( |
|
| 4118 | - sprintf( |
|
| 4119 | - esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4120 | - ucwords($messenger->label['singular']) |
|
| 4121 | - ) |
|
| 4122 | - ); |
|
| 4123 | - } |
|
| 4102 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4103 | + if ($message_type->name === 'invoice') { |
|
| 4104 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4105 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4106 | + if ($pm instanceof EE_Payment_Method) { |
|
| 4107 | + EE_Error::add_attention( |
|
| 4108 | + esc_html__( |
|
| 4109 | + 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4110 | + 'event_espresso' |
|
| 4111 | + ) |
|
| 4112 | + ); |
|
| 4113 | + } |
|
| 4114 | + } |
|
| 4115 | + //just toggles the entire messenger |
|
| 4116 | + } else { |
|
| 4117 | + EE_Error::add_success( |
|
| 4118 | + sprintf( |
|
| 4119 | + esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4120 | + ucwords($messenger->label['singular']) |
|
| 4121 | + ) |
|
| 4122 | + ); |
|
| 4123 | + } |
|
| 4124 | 4124 | |
| 4125 | - return true; |
|
| 4125 | + return true; |
|
| 4126 | 4126 | |
| 4127 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4128 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4129 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 4130 | - } else { |
|
| 4131 | - if ( ! $messenger->get_default_message_types()) { |
|
| 4132 | - //messenger doesn't have any default message types so still a success. |
|
| 4133 | - EE_Error::add_success( |
|
| 4134 | - sprintf( |
|
| 4135 | - esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4136 | - ucwords($messenger->label['singular']) |
|
| 4137 | - ) |
|
| 4138 | - ); |
|
| 4127 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4128 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4129 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 4130 | + } else { |
|
| 4131 | + if ( ! $messenger->get_default_message_types()) { |
|
| 4132 | + //messenger doesn't have any default message types so still a success. |
|
| 4133 | + EE_Error::add_success( |
|
| 4134 | + sprintf( |
|
| 4135 | + esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4136 | + ucwords($messenger->label['singular']) |
|
| 4137 | + ) |
|
| 4138 | + ); |
|
| 4139 | 4139 | |
| 4140 | - return true; |
|
| 4141 | - } else { |
|
| 4142 | - EE_Error::add_error( |
|
| 4143 | - $message_type instanceof EE_message_type |
|
| 4144 | - ? sprintf( |
|
| 4145 | - esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4146 | - ucwords($message_type->label['singular']), |
|
| 4147 | - ucwords($messenger->label['singular']) |
|
| 4148 | - ) |
|
| 4149 | - : sprintf( |
|
| 4150 | - esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4151 | - ucwords($messenger->label['singular']) |
|
| 4152 | - ), |
|
| 4153 | - __FILE__, |
|
| 4154 | - __FUNCTION__, |
|
| 4155 | - __LINE__ |
|
| 4156 | - ); |
|
| 4140 | + return true; |
|
| 4141 | + } else { |
|
| 4142 | + EE_Error::add_error( |
|
| 4143 | + $message_type instanceof EE_message_type |
|
| 4144 | + ? sprintf( |
|
| 4145 | + esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4146 | + ucwords($message_type->label['singular']), |
|
| 4147 | + ucwords($messenger->label['singular']) |
|
| 4148 | + ) |
|
| 4149 | + : sprintf( |
|
| 4150 | + esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4151 | + ucwords($messenger->label['singular']) |
|
| 4152 | + ), |
|
| 4153 | + __FILE__, |
|
| 4154 | + __FUNCTION__, |
|
| 4155 | + __LINE__ |
|
| 4156 | + ); |
|
| 4157 | 4157 | |
| 4158 | - return false; |
|
| 4159 | - } |
|
| 4160 | - } |
|
| 4161 | - } |
|
| 4158 | + return false; |
|
| 4159 | + } |
|
| 4160 | + } |
|
| 4161 | + } |
|
| 4162 | 4162 | |
| 4163 | 4163 | |
| 4164 | - /** |
|
| 4165 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4166 | - * |
|
| 4167 | - * @param EE_messenger $messenger |
|
| 4168 | - * @param EE_message_type|null $message_type |
|
| 4169 | - * @return bool |
|
| 4170 | - * @throws DomainException |
|
| 4171 | - * @throws EE_Error |
|
| 4172 | - * @throws InvalidArgumentException |
|
| 4173 | - * @throws ReflectionException |
|
| 4174 | - * @throws InvalidDataTypeException |
|
| 4175 | - * @throws InvalidInterfaceException |
|
| 4176 | - */ |
|
| 4177 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4178 | - $messenger, |
|
| 4179 | - EE_message_type $message_type = null |
|
| 4180 | - ) { |
|
| 4181 | - EE_Error::overwrite_success(); |
|
| 4182 | - |
|
| 4183 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4184 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4185 | - EE_Error::add_error( |
|
| 4186 | - esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4187 | - __FILE__, |
|
| 4188 | - __FUNCTION__, |
|
| 4189 | - __LINE__ |
|
| 4190 | - ); |
|
| 4164 | + /** |
|
| 4165 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4166 | + * |
|
| 4167 | + * @param EE_messenger $messenger |
|
| 4168 | + * @param EE_message_type|null $message_type |
|
| 4169 | + * @return bool |
|
| 4170 | + * @throws DomainException |
|
| 4171 | + * @throws EE_Error |
|
| 4172 | + * @throws InvalidArgumentException |
|
| 4173 | + * @throws ReflectionException |
|
| 4174 | + * @throws InvalidDataTypeException |
|
| 4175 | + * @throws InvalidInterfaceException |
|
| 4176 | + */ |
|
| 4177 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4178 | + $messenger, |
|
| 4179 | + EE_message_type $message_type = null |
|
| 4180 | + ) { |
|
| 4181 | + EE_Error::overwrite_success(); |
|
| 4182 | + |
|
| 4183 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4184 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4185 | + EE_Error::add_error( |
|
| 4186 | + esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4187 | + __FILE__, |
|
| 4188 | + __FUNCTION__, |
|
| 4189 | + __LINE__ |
|
| 4190 | + ); |
|
| 4191 | 4191 | |
| 4192 | - return false; |
|
| 4193 | - } |
|
| 4194 | - |
|
| 4195 | - if ($message_type instanceof EE_message_type) { |
|
| 4196 | - $message_type_name = $message_type->name; |
|
| 4197 | - EE_Error::add_success( |
|
| 4198 | - sprintf( |
|
| 4199 | - esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4200 | - ucwords($message_type->label['singular']), |
|
| 4201 | - ucwords($messenger->label['singular']) |
|
| 4202 | - ) |
|
| 4203 | - ); |
|
| 4204 | - } else { |
|
| 4205 | - $message_type_name = ''; |
|
| 4206 | - EE_Error::add_success( |
|
| 4207 | - sprintf( |
|
| 4208 | - esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4209 | - ucwords($messenger->label['singular']) |
|
| 4210 | - ) |
|
| 4211 | - ); |
|
| 4212 | - } |
|
| 4213 | - |
|
| 4214 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4215 | - if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4216 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4217 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4218 | - if ($count_updated > 0) { |
|
| 4219 | - $msg = $message_type_name === 'invoice' |
|
| 4220 | - ? esc_html__( |
|
| 4221 | - 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4222 | - 'event_espresso' |
|
| 4223 | - ) |
|
| 4224 | - : esc_html__( |
|
| 4225 | - 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4226 | - 'event_espresso' |
|
| 4227 | - ); |
|
| 4228 | - EE_Error::add_attention($msg); |
|
| 4229 | - } |
|
| 4230 | - } |
|
| 4231 | - |
|
| 4232 | - return true; |
|
| 4233 | - } |
|
| 4192 | + return false; |
|
| 4193 | + } |
|
| 4194 | + |
|
| 4195 | + if ($message_type instanceof EE_message_type) { |
|
| 4196 | + $message_type_name = $message_type->name; |
|
| 4197 | + EE_Error::add_success( |
|
| 4198 | + sprintf( |
|
| 4199 | + esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4200 | + ucwords($message_type->label['singular']), |
|
| 4201 | + ucwords($messenger->label['singular']) |
|
| 4202 | + ) |
|
| 4203 | + ); |
|
| 4204 | + } else { |
|
| 4205 | + $message_type_name = ''; |
|
| 4206 | + EE_Error::add_success( |
|
| 4207 | + sprintf( |
|
| 4208 | + esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4209 | + ucwords($messenger->label['singular']) |
|
| 4210 | + ) |
|
| 4211 | + ); |
|
| 4212 | + } |
|
| 4213 | + |
|
| 4214 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4215 | + if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4216 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4217 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4218 | + if ($count_updated > 0) { |
|
| 4219 | + $msg = $message_type_name === 'invoice' |
|
| 4220 | + ? esc_html__( |
|
| 4221 | + 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4222 | + 'event_espresso' |
|
| 4223 | + ) |
|
| 4224 | + : esc_html__( |
|
| 4225 | + 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4226 | + 'event_espresso' |
|
| 4227 | + ); |
|
| 4228 | + EE_Error::add_attention($msg); |
|
| 4229 | + } |
|
| 4230 | + } |
|
| 4231 | + |
|
| 4232 | + return true; |
|
| 4233 | + } |
|
| 4234 | 4234 | |
| 4235 | 4235 | |
| 4236 | - /** |
|
| 4237 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4238 | - * |
|
| 4239 | - * @throws DomainException |
|
| 4240 | - */ |
|
| 4241 | - public function update_mt_form() |
|
| 4242 | - { |
|
| 4243 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4244 | - EE_Error::add_error( |
|
| 4245 | - esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4246 | - __FILE__, |
|
| 4247 | - __FUNCTION__, |
|
| 4248 | - __LINE__ |
|
| 4249 | - ); |
|
| 4250 | - $this->_return_json(); |
|
| 4251 | - } |
|
| 4252 | - |
|
| 4253 | - $message_types = $this->get_installed_message_types(); |
|
| 4254 | - |
|
| 4255 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4256 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4257 | - |
|
| 4258 | - $content = $this->_message_type_settings_content( |
|
| 4259 | - $message_type, |
|
| 4260 | - $messenger, |
|
| 4261 | - true |
|
| 4262 | - ); |
|
| 4263 | - $this->_template_args['success'] = true; |
|
| 4264 | - $this->_template_args['content'] = $content; |
|
| 4265 | - $this->_return_json(); |
|
| 4266 | - } |
|
| 4236 | + /** |
|
| 4237 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4238 | + * |
|
| 4239 | + * @throws DomainException |
|
| 4240 | + */ |
|
| 4241 | + public function update_mt_form() |
|
| 4242 | + { |
|
| 4243 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4244 | + EE_Error::add_error( |
|
| 4245 | + esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4246 | + __FILE__, |
|
| 4247 | + __FUNCTION__, |
|
| 4248 | + __LINE__ |
|
| 4249 | + ); |
|
| 4250 | + $this->_return_json(); |
|
| 4251 | + } |
|
| 4252 | + |
|
| 4253 | + $message_types = $this->get_installed_message_types(); |
|
| 4254 | + |
|
| 4255 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4256 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4257 | + |
|
| 4258 | + $content = $this->_message_type_settings_content( |
|
| 4259 | + $message_type, |
|
| 4260 | + $messenger, |
|
| 4261 | + true |
|
| 4262 | + ); |
|
| 4263 | + $this->_template_args['success'] = true; |
|
| 4264 | + $this->_template_args['content'] = $content; |
|
| 4265 | + $this->_return_json(); |
|
| 4266 | + } |
|
| 4267 | 4267 | |
| 4268 | 4268 | |
| 4269 | - /** |
|
| 4270 | - * this handles saving the settings for a messenger or message type |
|
| 4271 | - * |
|
| 4272 | - */ |
|
| 4273 | - public function save_settings() |
|
| 4274 | - { |
|
| 4275 | - if ( ! isset($this->_req_data['type'])) { |
|
| 4276 | - EE_Error::add_error( |
|
| 4277 | - esc_html__( |
|
| 4278 | - 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4279 | - 'event_espresso' |
|
| 4280 | - ), |
|
| 4281 | - __FILE__, |
|
| 4282 | - __FUNCTION__, |
|
| 4283 | - __LINE__ |
|
| 4284 | - ); |
|
| 4285 | - $this->_template_args['error'] = true; |
|
| 4286 | - $this->_return_json(); |
|
| 4287 | - } |
|
| 4288 | - |
|
| 4289 | - |
|
| 4290 | - if ($this->_req_data['type'] === 'messenger') { |
|
| 4291 | - //this should be an array. |
|
| 4292 | - $settings = $this->_req_data['messenger_settings']; |
|
| 4293 | - $messenger = $settings['messenger']; |
|
| 4294 | - //let's setup the settings data |
|
| 4295 | - foreach ($settings as $key => $value) { |
|
| 4296 | - switch ($key) { |
|
| 4297 | - case 'messenger' : |
|
| 4298 | - unset($settings['messenger']); |
|
| 4299 | - break; |
|
| 4300 | - case 'message_types' : |
|
| 4301 | - unset($settings['message_types']); |
|
| 4302 | - break; |
|
| 4303 | - default : |
|
| 4304 | - $settings[$key] = $value; |
|
| 4305 | - break; |
|
| 4306 | - } |
|
| 4307 | - } |
|
| 4308 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4309 | - } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4310 | - $settings = $this->_req_data['message_type_settings']; |
|
| 4311 | - $messenger = $settings['messenger']; |
|
| 4312 | - $message_type = $settings['message_type']; |
|
| 4269 | + /** |
|
| 4270 | + * this handles saving the settings for a messenger or message type |
|
| 4271 | + * |
|
| 4272 | + */ |
|
| 4273 | + public function save_settings() |
|
| 4274 | + { |
|
| 4275 | + if ( ! isset($this->_req_data['type'])) { |
|
| 4276 | + EE_Error::add_error( |
|
| 4277 | + esc_html__( |
|
| 4278 | + 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4279 | + 'event_espresso' |
|
| 4280 | + ), |
|
| 4281 | + __FILE__, |
|
| 4282 | + __FUNCTION__, |
|
| 4283 | + __LINE__ |
|
| 4284 | + ); |
|
| 4285 | + $this->_template_args['error'] = true; |
|
| 4286 | + $this->_return_json(); |
|
| 4287 | + } |
|
| 4288 | + |
|
| 4289 | + |
|
| 4290 | + if ($this->_req_data['type'] === 'messenger') { |
|
| 4291 | + //this should be an array. |
|
| 4292 | + $settings = $this->_req_data['messenger_settings']; |
|
| 4293 | + $messenger = $settings['messenger']; |
|
| 4294 | + //let's setup the settings data |
|
| 4295 | + foreach ($settings as $key => $value) { |
|
| 4296 | + switch ($key) { |
|
| 4297 | + case 'messenger' : |
|
| 4298 | + unset($settings['messenger']); |
|
| 4299 | + break; |
|
| 4300 | + case 'message_types' : |
|
| 4301 | + unset($settings['message_types']); |
|
| 4302 | + break; |
|
| 4303 | + default : |
|
| 4304 | + $settings[$key] = $value; |
|
| 4305 | + break; |
|
| 4306 | + } |
|
| 4307 | + } |
|
| 4308 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4309 | + } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4310 | + $settings = $this->_req_data['message_type_settings']; |
|
| 4311 | + $messenger = $settings['messenger']; |
|
| 4312 | + $message_type = $settings['message_type']; |
|
| 4313 | 4313 | |
| 4314 | - foreach ($settings as $key => $value) { |
|
| 4315 | - switch ($key) { |
|
| 4316 | - case 'messenger' : |
|
| 4317 | - unset($settings['messenger']); |
|
| 4318 | - break; |
|
| 4319 | - case 'message_type' : |
|
| 4320 | - unset($settings['message_type']); |
|
| 4321 | - break; |
|
| 4322 | - default : |
|
| 4323 | - $settings[$key] = $value; |
|
| 4324 | - break; |
|
| 4325 | - } |
|
| 4326 | - } |
|
| 4314 | + foreach ($settings as $key => $value) { |
|
| 4315 | + switch ($key) { |
|
| 4316 | + case 'messenger' : |
|
| 4317 | + unset($settings['messenger']); |
|
| 4318 | + break; |
|
| 4319 | + case 'message_type' : |
|
| 4320 | + unset($settings['message_type']); |
|
| 4321 | + break; |
|
| 4322 | + default : |
|
| 4323 | + $settings[$key] = $value; |
|
| 4324 | + break; |
|
| 4325 | + } |
|
| 4326 | + } |
|
| 4327 | 4327 | |
| 4328 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4329 | - } |
|
| 4330 | - |
|
| 4331 | - //okay we should have the data all setup. Now we just update! |
|
| 4332 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4333 | - |
|
| 4334 | - if ($success) { |
|
| 4335 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4336 | - } else { |
|
| 4337 | - EE_Error::add_error( |
|
| 4338 | - esc_html__( |
|
| 4339 | - 'Settings did not get updated', |
|
| 4340 | - 'event_espresso' |
|
| 4341 | - ), |
|
| 4342 | - __FILE__, |
|
| 4343 | - __FUNCTION__, |
|
| 4344 | - __LINE__ |
|
| 4345 | - ); |
|
| 4346 | - } |
|
| 4347 | - |
|
| 4348 | - $this->_template_args['success'] = $success; |
|
| 4349 | - $this->_return_json(); |
|
| 4350 | - } |
|
| 4328 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4329 | + } |
|
| 4330 | + |
|
| 4331 | + //okay we should have the data all setup. Now we just update! |
|
| 4332 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4333 | + |
|
| 4334 | + if ($success) { |
|
| 4335 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4336 | + } else { |
|
| 4337 | + EE_Error::add_error( |
|
| 4338 | + esc_html__( |
|
| 4339 | + 'Settings did not get updated', |
|
| 4340 | + 'event_espresso' |
|
| 4341 | + ), |
|
| 4342 | + __FILE__, |
|
| 4343 | + __FUNCTION__, |
|
| 4344 | + __LINE__ |
|
| 4345 | + ); |
|
| 4346 | + } |
|
| 4347 | + |
|
| 4348 | + $this->_template_args['success'] = $success; |
|
| 4349 | + $this->_return_json(); |
|
| 4350 | + } |
|
| 4351 | 4351 | |
| 4352 | 4352 | |
| 4353 | 4353 | |
| 4354 | 4354 | |
| 4355 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4355 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4356 | 4356 | |
| 4357 | 4357 | |
| 4358 | - /** |
|
| 4359 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4360 | - * However, this does not send immediately, it just queues for sending. |
|
| 4361 | - * |
|
| 4362 | - * @since 4.9.0 |
|
| 4363 | - * @throws EE_Error |
|
| 4364 | - * @throws InvalidDataTypeException |
|
| 4365 | - * @throws InvalidInterfaceException |
|
| 4366 | - * @throws InvalidArgumentException |
|
| 4367 | - * @throws ReflectionException |
|
| 4368 | - */ |
|
| 4369 | - protected function _generate_now() |
|
| 4370 | - { |
|
| 4371 | - EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4372 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4373 | - } |
|
| 4358 | + /** |
|
| 4359 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4360 | + * However, this does not send immediately, it just queues for sending. |
|
| 4361 | + * |
|
| 4362 | + * @since 4.9.0 |
|
| 4363 | + * @throws EE_Error |
|
| 4364 | + * @throws InvalidDataTypeException |
|
| 4365 | + * @throws InvalidInterfaceException |
|
| 4366 | + * @throws InvalidArgumentException |
|
| 4367 | + * @throws ReflectionException |
|
| 4368 | + */ |
|
| 4369 | + protected function _generate_now() |
|
| 4370 | + { |
|
| 4371 | + EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4372 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4373 | + } |
|
| 4374 | 4374 | |
| 4375 | 4375 | |
| 4376 | - /** |
|
| 4377 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4378 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4379 | - * |
|
| 4380 | - * @since 4.9.0 |
|
| 4381 | - * @throws EE_Error |
|
| 4382 | - * @throws InvalidDataTypeException |
|
| 4383 | - * @throws InvalidInterfaceException |
|
| 4384 | - * @throws InvalidArgumentException |
|
| 4385 | - * @throws ReflectionException |
|
| 4386 | - */ |
|
| 4387 | - protected function _generate_and_send_now() |
|
| 4388 | - { |
|
| 4389 | - EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4390 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4391 | - } |
|
| 4376 | + /** |
|
| 4377 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4378 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4379 | + * |
|
| 4380 | + * @since 4.9.0 |
|
| 4381 | + * @throws EE_Error |
|
| 4382 | + * @throws InvalidDataTypeException |
|
| 4383 | + * @throws InvalidInterfaceException |
|
| 4384 | + * @throws InvalidArgumentException |
|
| 4385 | + * @throws ReflectionException |
|
| 4386 | + */ |
|
| 4387 | + protected function _generate_and_send_now() |
|
| 4388 | + { |
|
| 4389 | + EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4390 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4391 | + } |
|
| 4392 | 4392 | |
| 4393 | 4393 | |
| 4394 | - /** |
|
| 4395 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4396 | - * |
|
| 4397 | - * @since 4.9.0 |
|
| 4398 | - * @throws EE_Error |
|
| 4399 | - * @throws InvalidDataTypeException |
|
| 4400 | - * @throws InvalidInterfaceException |
|
| 4401 | - * @throws InvalidArgumentException |
|
| 4402 | - * @throws ReflectionException |
|
| 4403 | - */ |
|
| 4404 | - protected function _queue_for_resending() |
|
| 4405 | - { |
|
| 4406 | - EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4407 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4408 | - } |
|
| 4394 | + /** |
|
| 4395 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4396 | + * |
|
| 4397 | + * @since 4.9.0 |
|
| 4398 | + * @throws EE_Error |
|
| 4399 | + * @throws InvalidDataTypeException |
|
| 4400 | + * @throws InvalidInterfaceException |
|
| 4401 | + * @throws InvalidArgumentException |
|
| 4402 | + * @throws ReflectionException |
|
| 4403 | + */ |
|
| 4404 | + protected function _queue_for_resending() |
|
| 4405 | + { |
|
| 4406 | + EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4407 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4408 | + } |
|
| 4409 | 4409 | |
| 4410 | 4410 | |
| 4411 | - /** |
|
| 4412 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4413 | - * |
|
| 4414 | - * @since 4.9.0 |
|
| 4415 | - * @throws EE_Error |
|
| 4416 | - * @throws InvalidDataTypeException |
|
| 4417 | - * @throws InvalidInterfaceException |
|
| 4418 | - * @throws InvalidArgumentException |
|
| 4419 | - * @throws ReflectionException |
|
| 4420 | - */ |
|
| 4421 | - protected function _send_now() |
|
| 4422 | - { |
|
| 4423 | - EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4424 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4425 | - } |
|
| 4411 | + /** |
|
| 4412 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4413 | + * |
|
| 4414 | + * @since 4.9.0 |
|
| 4415 | + * @throws EE_Error |
|
| 4416 | + * @throws InvalidDataTypeException |
|
| 4417 | + * @throws InvalidInterfaceException |
|
| 4418 | + * @throws InvalidArgumentException |
|
| 4419 | + * @throws ReflectionException |
|
| 4420 | + */ |
|
| 4421 | + protected function _send_now() |
|
| 4422 | + { |
|
| 4423 | + EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4424 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4425 | + } |
|
| 4426 | 4426 | |
| 4427 | 4427 | |
| 4428 | - /** |
|
| 4429 | - * Deletes EE_messages for IDs in the request. |
|
| 4430 | - * |
|
| 4431 | - * @since 4.9.0 |
|
| 4432 | - * @throws EE_Error |
|
| 4433 | - * @throws InvalidDataTypeException |
|
| 4434 | - * @throws InvalidInterfaceException |
|
| 4435 | - * @throws InvalidArgumentException |
|
| 4436 | - */ |
|
| 4437 | - protected function _delete_ee_messages() |
|
| 4438 | - { |
|
| 4439 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4440 | - $deleted_count = 0; |
|
| 4441 | - foreach ($msg_ids as $msg_id) { |
|
| 4442 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4443 | - $deleted_count++; |
|
| 4444 | - } |
|
| 4445 | - } |
|
| 4446 | - if ($deleted_count) { |
|
| 4447 | - EE_Error::add_success(esc_html(_n('Message successfully deleted', 'Messages successfully deleted', $deleted_count, 'event_espresso'))); |
|
| 4448 | - $this->_redirect_after_action( |
|
| 4449 | - false, |
|
| 4450 | - '', |
|
| 4451 | - '', |
|
| 4452 | - array(), |
|
| 4453 | - true |
|
| 4454 | - ); |
|
| 4455 | - } else { |
|
| 4456 | - EE_Error::add_error( |
|
| 4457 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4458 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 4459 | - ); |
|
| 4460 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4461 | - } |
|
| 4462 | - } |
|
| 4428 | + /** |
|
| 4429 | + * Deletes EE_messages for IDs in the request. |
|
| 4430 | + * |
|
| 4431 | + * @since 4.9.0 |
|
| 4432 | + * @throws EE_Error |
|
| 4433 | + * @throws InvalidDataTypeException |
|
| 4434 | + * @throws InvalidInterfaceException |
|
| 4435 | + * @throws InvalidArgumentException |
|
| 4436 | + */ |
|
| 4437 | + protected function _delete_ee_messages() |
|
| 4438 | + { |
|
| 4439 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4440 | + $deleted_count = 0; |
|
| 4441 | + foreach ($msg_ids as $msg_id) { |
|
| 4442 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4443 | + $deleted_count++; |
|
| 4444 | + } |
|
| 4445 | + } |
|
| 4446 | + if ($deleted_count) { |
|
| 4447 | + EE_Error::add_success(esc_html(_n('Message successfully deleted', 'Messages successfully deleted', $deleted_count, 'event_espresso'))); |
|
| 4448 | + $this->_redirect_after_action( |
|
| 4449 | + false, |
|
| 4450 | + '', |
|
| 4451 | + '', |
|
| 4452 | + array(), |
|
| 4453 | + true |
|
| 4454 | + ); |
|
| 4455 | + } else { |
|
| 4456 | + EE_Error::add_error( |
|
| 4457 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4458 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 4459 | + ); |
|
| 4460 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4461 | + } |
|
| 4462 | + } |
|
| 4463 | 4463 | |
| 4464 | 4464 | |
| 4465 | - /** |
|
| 4466 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4467 | - * @since 4.9.0 |
|
| 4468 | - * @return array |
|
| 4469 | - */ |
|
| 4470 | - protected function _get_msg_ids_from_request() |
|
| 4471 | - { |
|
| 4472 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4473 | - return array(); |
|
| 4474 | - } |
|
| 4475 | - |
|
| 4476 | - return is_array($this->_req_data['MSG_ID']) |
|
| 4477 | - ? array_keys($this->_req_data['MSG_ID']) |
|
| 4478 | - : array($this->_req_data['MSG_ID']); |
|
| 4479 | - } |
|
| 4465 | + /** |
|
| 4466 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4467 | + * @since 4.9.0 |
|
| 4468 | + * @return array |
|
| 4469 | + */ |
|
| 4470 | + protected function _get_msg_ids_from_request() |
|
| 4471 | + { |
|
| 4472 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4473 | + return array(); |
|
| 4474 | + } |
|
| 4475 | + |
|
| 4476 | + return is_array($this->_req_data['MSG_ID']) |
|
| 4477 | + ? array_keys($this->_req_data['MSG_ID']) |
|
| 4478 | + : array($this->_req_data['MSG_ID']); |
|
| 4479 | + } |
|
| 4480 | 4480 | } |
@@ -14,28 +14,28 @@ |
||
| 14 | 14 | class EE_Detect_File_Editor_Request extends EE_Middleware |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @deprecated |
|
| 19 | - * @param EE_Request $request |
|
| 20 | - * @param EE_Response $response |
|
| 21 | - * @return EE_Response |
|
| 22 | - */ |
|
| 23 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
| 24 | - { |
|
| 25 | - EE_Error::doing_it_wrong( |
|
| 26 | - __METHOD__, |
|
| 27 | - sprintf( |
|
| 28 | - esc_html__( |
|
| 29 | - 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 30 | - 'event_espresso' |
|
| 31 | - ), |
|
| 32 | - 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest', |
|
| 33 | - '\core\services\request', |
|
| 34 | - 'EventEspresso\core\services\request' |
|
| 35 | - ), |
|
| 36 | - '4.9.52' |
|
| 37 | - ); |
|
| 38 | - return $response; |
|
| 39 | - } |
|
| 17 | + /** |
|
| 18 | + * @deprecated |
|
| 19 | + * @param EE_Request $request |
|
| 20 | + * @param EE_Response $response |
|
| 21 | + * @return EE_Response |
|
| 22 | + */ |
|
| 23 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
| 24 | + { |
|
| 25 | + EE_Error::doing_it_wrong( |
|
| 26 | + __METHOD__, |
|
| 27 | + sprintf( |
|
| 28 | + esc_html__( |
|
| 29 | + 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 30 | + 'event_espresso' |
|
| 31 | + ), |
|
| 32 | + 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest', |
|
| 33 | + '\core\services\request', |
|
| 34 | + 'EventEspresso\core\services\request' |
|
| 35 | + ), |
|
| 36 | + '4.9.52' |
|
| 37 | + ); |
|
| 38 | + return $response; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | } |
@@ -21,45 +21,45 @@ |
||
| 21 | 21 | class DetectFileEditorRequest extends Middleware |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * converts a Request to a Response |
|
| 26 | - * |
|
| 27 | - * @param RequestInterface $request |
|
| 28 | - * @param ResponseInterface $response |
|
| 29 | - * @return ResponseInterface |
|
| 30 | - */ |
|
| 31 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 32 | - { |
|
| 33 | - $this->request = $request; |
|
| 34 | - $this->response = $response; |
|
| 35 | - if ($this->isFileEditorRequest()) { |
|
| 36 | - $this->setFiltersForRequest(); |
|
| 37 | - } |
|
| 38 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 39 | - return $this->response; |
|
| 40 | - } |
|
| 24 | + /** |
|
| 25 | + * converts a Request to a Response |
|
| 26 | + * |
|
| 27 | + * @param RequestInterface $request |
|
| 28 | + * @param ResponseInterface $response |
|
| 29 | + * @return ResponseInterface |
|
| 30 | + */ |
|
| 31 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 32 | + { |
|
| 33 | + $this->request = $request; |
|
| 34 | + $this->response = $response; |
|
| 35 | + if ($this->isFileEditorRequest()) { |
|
| 36 | + $this->setFiltersForRequest(); |
|
| 37 | + } |
|
| 38 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 39 | + return $this->response; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * This sets any filters that need set on this request. |
|
| 45 | - */ |
|
| 46 | - protected function setFiltersForRequest() |
|
| 47 | - { |
|
| 48 | - add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * This sets any filters that need set on this request. |
|
| 45 | + */ |
|
| 46 | + protected function setFiltersForRequest() |
|
| 47 | + { |
|
| 48 | + add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Conditions for a "file editor request" |
|
| 54 | - * |
|
| 55 | - * @see wp-admin/includes/file.php |
|
| 56 | - * The file editor does a loopback request to the admin AND to the frontend when checking active theme or |
|
| 57 | - * active plugin edits. So these conditions consider that. |
|
| 58 | - * @return bool |
|
| 59 | - */ |
|
| 60 | - protected function isFileEditorRequest() |
|
| 61 | - { |
|
| 62 | - return $this->request->getRequestParam('wp_scrape_key') |
|
| 63 | - && $this->request->getRequestParam('wp_scrape_nonce'); |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * Conditions for a "file editor request" |
|
| 54 | + * |
|
| 55 | + * @see wp-admin/includes/file.php |
|
| 56 | + * The file editor does a loopback request to the admin AND to the frontend when checking active theme or |
|
| 57 | + * active plugin edits. So these conditions consider that. |
|
| 58 | + * @return bool |
|
| 59 | + */ |
|
| 60 | + protected function isFileEditorRequest() |
|
| 61 | + { |
|
| 62 | + return $this->request->getRequestParam('wp_scrape_key') |
|
| 63 | + && $this->request->getRequestParam('wp_scrape_nonce'); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -21,1215 +21,1215 @@ discard block |
||
| 21 | 21 | class EE_Session implements SessionIdentifierInterface |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - const session_id_prefix = 'ee_ssn_'; |
|
| 25 | - |
|
| 26 | - const hash_check_prefix = 'ee_shc_'; |
|
| 27 | - |
|
| 28 | - const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
| 29 | - |
|
| 30 | - const STATUS_CLOSED = 0; |
|
| 31 | - |
|
| 32 | - const STATUS_OPEN = 1; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * instance of the EE_Session object |
|
| 36 | - * |
|
| 37 | - * @var EE_Session |
|
| 38 | - */ |
|
| 39 | - private static $_instance; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var CacheStorageInterface $cache_storage |
|
| 43 | - */ |
|
| 44 | - protected $cache_storage; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * EE_Encryption object |
|
| 48 | - * |
|
| 49 | - * @var EE_Encryption |
|
| 50 | - */ |
|
| 51 | - protected $encryption; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * the session id |
|
| 55 | - * |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - private $_sid; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * session id salt |
|
| 62 | - * |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - private $_sid_salt; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * session data |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - private $_session_data = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * how long an EE session lasts |
|
| 76 | - * default session lifespan of 2 hours (for not so instant IPNs) |
|
| 77 | - * |
|
| 78 | - * @var int |
|
| 79 | - */ |
|
| 80 | - private $_lifespan; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * session expiration time as Unix timestamp in GMT |
|
| 84 | - * |
|
| 85 | - * @var int |
|
| 86 | - */ |
|
| 87 | - private $_expiration; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * whether or not session has expired at some point |
|
| 91 | - * |
|
| 92 | - * @var boolean |
|
| 93 | - */ |
|
| 94 | - private $_expired = false; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * current time as Unix timestamp in GMT |
|
| 98 | - * |
|
| 99 | - * @var int |
|
| 100 | - */ |
|
| 101 | - private $_time; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * whether to encrypt session data |
|
| 105 | - * |
|
| 106 | - * @var bool |
|
| 107 | - */ |
|
| 108 | - private $_use_encryption; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * well... according to the server... |
|
| 112 | - * |
|
| 113 | - * @var null |
|
| 114 | - */ |
|
| 115 | - private $_user_agent; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * do you really trust the server ? |
|
| 119 | - * |
|
| 120 | - * @var null |
|
| 121 | - */ |
|
| 122 | - private $_ip_address; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * current WP user_id |
|
| 126 | - * |
|
| 127 | - * @var null |
|
| 128 | - */ |
|
| 129 | - private $_wp_user_id; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * array for defining default session vars |
|
| 133 | - * |
|
| 134 | - * @var array |
|
| 135 | - */ |
|
| 136 | - private $_default_session_vars = array( |
|
| 137 | - 'id' => null, |
|
| 138 | - 'user_id' => null, |
|
| 139 | - 'ip_address' => null, |
|
| 140 | - 'user_agent' => null, |
|
| 141 | - 'init_access' => null, |
|
| 142 | - 'last_access' => null, |
|
| 143 | - 'expiration' => null, |
|
| 144 | - 'pages_visited' => array(), |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * timestamp for when last garbage collection cycle was performed |
|
| 149 | - * |
|
| 150 | - * @var int $_last_gc |
|
| 151 | - */ |
|
| 152 | - private $_last_gc; |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @var RequestInterface $request |
|
| 156 | - */ |
|
| 157 | - protected $request; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * whether session is active or not |
|
| 161 | - * |
|
| 162 | - * @var int $status |
|
| 163 | - */ |
|
| 164 | - private $status = EE_Session::STATUS_CLOSED; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @singleton method used to instantiate class object |
|
| 170 | - * @param CacheStorageInterface $cache_storage |
|
| 171 | - * @param RequestInterface $request |
|
| 172 | - * @param EE_Encryption $encryption |
|
| 173 | - * @return EE_Session |
|
| 174 | - * @throws InvalidArgumentException |
|
| 175 | - * @throws InvalidDataTypeException |
|
| 176 | - * @throws InvalidInterfaceException |
|
| 177 | - */ |
|
| 178 | - public static function instance( |
|
| 179 | - CacheStorageInterface $cache_storage = null, |
|
| 180 | - RequestInterface $request = null, |
|
| 181 | - EE_Encryption $encryption = null |
|
| 182 | - ) { |
|
| 183 | - // check if class object is instantiated |
|
| 184 | - // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
| 185 | - // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 186 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 187 | - self::$_instance = new self($cache_storage, $request, $encryption); |
|
| 188 | - } |
|
| 189 | - return self::$_instance; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * protected constructor to prevent direct creation |
|
| 196 | - * |
|
| 197 | - * @param CacheStorageInterface $cache_storage |
|
| 198 | - * @param RequestInterface $request |
|
| 199 | - * @param EE_Encryption $encryption |
|
| 200 | - * @throws InvalidArgumentException |
|
| 201 | - * @throws InvalidDataTypeException |
|
| 202 | - * @throws InvalidInterfaceException |
|
| 203 | - */ |
|
| 204 | - protected function __construct( |
|
| 205 | - CacheStorageInterface $cache_storage, |
|
| 206 | - RequestInterface $request, |
|
| 207 | - EE_Encryption $encryption = null |
|
| 208 | - ) { |
|
| 209 | - // session loading is turned ON by default, |
|
| 210 | - // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
| 211 | - // (which currently fires on the init hook at priority 9), |
|
| 212 | - // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 213 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 214 | - return; |
|
| 215 | - } |
|
| 216 | - $this->request = $request; |
|
| 217 | - if (! defined('ESPRESSO_SESSION')) { |
|
| 218 | - define('ESPRESSO_SESSION', true); |
|
| 219 | - } |
|
| 220 | - // default session lifespan in seconds |
|
| 221 | - $this->_lifespan = apply_filters( |
|
| 222 | - 'FHEE__EE_Session__construct___lifespan', |
|
| 223 | - 60 * MINUTE_IN_SECONDS |
|
| 224 | - ) + 1; |
|
| 225 | - /* |
|
| 24 | + const session_id_prefix = 'ee_ssn_'; |
|
| 25 | + |
|
| 26 | + const hash_check_prefix = 'ee_shc_'; |
|
| 27 | + |
|
| 28 | + const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
| 29 | + |
|
| 30 | + const STATUS_CLOSED = 0; |
|
| 31 | + |
|
| 32 | + const STATUS_OPEN = 1; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * instance of the EE_Session object |
|
| 36 | + * |
|
| 37 | + * @var EE_Session |
|
| 38 | + */ |
|
| 39 | + private static $_instance; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var CacheStorageInterface $cache_storage |
|
| 43 | + */ |
|
| 44 | + protected $cache_storage; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * EE_Encryption object |
|
| 48 | + * |
|
| 49 | + * @var EE_Encryption |
|
| 50 | + */ |
|
| 51 | + protected $encryption; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * the session id |
|
| 55 | + * |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + private $_sid; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * session id salt |
|
| 62 | + * |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + private $_sid_salt; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * session data |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + private $_session_data = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * how long an EE session lasts |
|
| 76 | + * default session lifespan of 2 hours (for not so instant IPNs) |
|
| 77 | + * |
|
| 78 | + * @var int |
|
| 79 | + */ |
|
| 80 | + private $_lifespan; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * session expiration time as Unix timestamp in GMT |
|
| 84 | + * |
|
| 85 | + * @var int |
|
| 86 | + */ |
|
| 87 | + private $_expiration; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * whether or not session has expired at some point |
|
| 91 | + * |
|
| 92 | + * @var boolean |
|
| 93 | + */ |
|
| 94 | + private $_expired = false; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * current time as Unix timestamp in GMT |
|
| 98 | + * |
|
| 99 | + * @var int |
|
| 100 | + */ |
|
| 101 | + private $_time; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * whether to encrypt session data |
|
| 105 | + * |
|
| 106 | + * @var bool |
|
| 107 | + */ |
|
| 108 | + private $_use_encryption; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * well... according to the server... |
|
| 112 | + * |
|
| 113 | + * @var null |
|
| 114 | + */ |
|
| 115 | + private $_user_agent; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * do you really trust the server ? |
|
| 119 | + * |
|
| 120 | + * @var null |
|
| 121 | + */ |
|
| 122 | + private $_ip_address; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * current WP user_id |
|
| 126 | + * |
|
| 127 | + * @var null |
|
| 128 | + */ |
|
| 129 | + private $_wp_user_id; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * array for defining default session vars |
|
| 133 | + * |
|
| 134 | + * @var array |
|
| 135 | + */ |
|
| 136 | + private $_default_session_vars = array( |
|
| 137 | + 'id' => null, |
|
| 138 | + 'user_id' => null, |
|
| 139 | + 'ip_address' => null, |
|
| 140 | + 'user_agent' => null, |
|
| 141 | + 'init_access' => null, |
|
| 142 | + 'last_access' => null, |
|
| 143 | + 'expiration' => null, |
|
| 144 | + 'pages_visited' => array(), |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * timestamp for when last garbage collection cycle was performed |
|
| 149 | + * |
|
| 150 | + * @var int $_last_gc |
|
| 151 | + */ |
|
| 152 | + private $_last_gc; |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @var RequestInterface $request |
|
| 156 | + */ |
|
| 157 | + protected $request; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * whether session is active or not |
|
| 161 | + * |
|
| 162 | + * @var int $status |
|
| 163 | + */ |
|
| 164 | + private $status = EE_Session::STATUS_CLOSED; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @singleton method used to instantiate class object |
|
| 170 | + * @param CacheStorageInterface $cache_storage |
|
| 171 | + * @param RequestInterface $request |
|
| 172 | + * @param EE_Encryption $encryption |
|
| 173 | + * @return EE_Session |
|
| 174 | + * @throws InvalidArgumentException |
|
| 175 | + * @throws InvalidDataTypeException |
|
| 176 | + * @throws InvalidInterfaceException |
|
| 177 | + */ |
|
| 178 | + public static function instance( |
|
| 179 | + CacheStorageInterface $cache_storage = null, |
|
| 180 | + RequestInterface $request = null, |
|
| 181 | + EE_Encryption $encryption = null |
|
| 182 | + ) { |
|
| 183 | + // check if class object is instantiated |
|
| 184 | + // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
| 185 | + // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 186 | + if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 187 | + self::$_instance = new self($cache_storage, $request, $encryption); |
|
| 188 | + } |
|
| 189 | + return self::$_instance; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * protected constructor to prevent direct creation |
|
| 196 | + * |
|
| 197 | + * @param CacheStorageInterface $cache_storage |
|
| 198 | + * @param RequestInterface $request |
|
| 199 | + * @param EE_Encryption $encryption |
|
| 200 | + * @throws InvalidArgumentException |
|
| 201 | + * @throws InvalidDataTypeException |
|
| 202 | + * @throws InvalidInterfaceException |
|
| 203 | + */ |
|
| 204 | + protected function __construct( |
|
| 205 | + CacheStorageInterface $cache_storage, |
|
| 206 | + RequestInterface $request, |
|
| 207 | + EE_Encryption $encryption = null |
|
| 208 | + ) { |
|
| 209 | + // session loading is turned ON by default, |
|
| 210 | + // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
| 211 | + // (which currently fires on the init hook at priority 9), |
|
| 212 | + // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
| 213 | + if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 214 | + return; |
|
| 215 | + } |
|
| 216 | + $this->request = $request; |
|
| 217 | + if (! defined('ESPRESSO_SESSION')) { |
|
| 218 | + define('ESPRESSO_SESSION', true); |
|
| 219 | + } |
|
| 220 | + // default session lifespan in seconds |
|
| 221 | + $this->_lifespan = apply_filters( |
|
| 222 | + 'FHEE__EE_Session__construct___lifespan', |
|
| 223 | + 60 * MINUTE_IN_SECONDS |
|
| 224 | + ) + 1; |
|
| 225 | + /* |
|
| 226 | 226 | * do something like the following to adjust the session lifespan: |
| 227 | 227 | * public static function session_lifespan() { |
| 228 | 228 | * return 15 * MINUTE_IN_SECONDS; |
| 229 | 229 | * } |
| 230 | 230 | */ |
| 231 | - // retrieve session options from db |
|
| 232 | - $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 233 | - if (! empty($session_settings)) { |
|
| 234 | - // cycle though existing session options |
|
| 235 | - foreach ($session_settings as $var_name => $session_setting) { |
|
| 236 | - // set values for class properties |
|
| 237 | - $var_name = '_' . $var_name; |
|
| 238 | - $this->{$var_name} = $session_setting; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - $this->cache_storage = $cache_storage; |
|
| 242 | - // are we using encryption? |
|
| 243 | - $this->_use_encryption = $encryption instanceof EE_Encryption |
|
| 244 | - && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 245 | - // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
| 246 | - // encrypt data via: $this->encryption->encrypt(); |
|
| 247 | - $this->encryption = $encryption; |
|
| 248 | - // filter hook allows outside functions/classes/plugins to change default empty cart |
|
| 249 | - $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
| 250 | - array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
| 251 | - // apply default session vars |
|
| 252 | - $this->_set_defaults(); |
|
| 253 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 254 | - // check request for 'clear_session' param |
|
| 255 | - add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
| 256 | - // once everything is all said and done, |
|
| 257 | - add_action('shutdown', array($this, 'update'), 100); |
|
| 258 | - add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
| 259 | - $this->configure_garbage_collection_filters(); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @return bool |
|
| 265 | - * @throws InvalidArgumentException |
|
| 266 | - * @throws InvalidDataTypeException |
|
| 267 | - * @throws InvalidInterfaceException |
|
| 268 | - */ |
|
| 269 | - public static function isLoadedAndActive() |
|
| 270 | - { |
|
| 271 | - return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
| 272 | - && EE_Session::instance() instanceof EE_Session |
|
| 273 | - && EE_Session::instance()->isActive(); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @return bool |
|
| 279 | - */ |
|
| 280 | - public function isActive() |
|
| 281 | - { |
|
| 282 | - return $this->status === EE_Session::STATUS_OPEN; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @return void |
|
| 289 | - * @throws EE_Error |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - * @throws InvalidDataTypeException |
|
| 292 | - * @throws InvalidInterfaceException |
|
| 293 | - * @throws InvalidSessionDataException |
|
| 294 | - */ |
|
| 295 | - public function open_session() |
|
| 296 | - { |
|
| 297 | - // check for existing session and retrieve it from db |
|
| 298 | - if (! $this->_espresso_session()) { |
|
| 299 | - // or just start a new one |
|
| 300 | - $this->_create_espresso_session(); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @return bool |
|
| 308 | - */ |
|
| 309 | - public function expired() |
|
| 310 | - { |
|
| 311 | - return $this->_expired; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @return void |
|
| 318 | - */ |
|
| 319 | - public function reset_expired() |
|
| 320 | - { |
|
| 321 | - $this->_expired = false; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * @return int |
|
| 327 | - */ |
|
| 328 | - public function expiration() |
|
| 329 | - { |
|
| 330 | - return $this->_expiration; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @return int |
|
| 337 | - */ |
|
| 338 | - public function extension() |
|
| 339 | - { |
|
| 340 | - return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @param int $time number of seconds to add to session expiration |
|
| 347 | - */ |
|
| 348 | - public function extend_expiration($time = 0) |
|
| 349 | - { |
|
| 350 | - $time = $time ? $time : $this->extension(); |
|
| 351 | - $this->_expiration += absint($time); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * @return int |
|
| 358 | - */ |
|
| 359 | - public function lifespan() |
|
| 360 | - { |
|
| 361 | - return $this->_lifespan; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * This just sets some defaults for the _session data property |
|
| 368 | - * |
|
| 369 | - * @access private |
|
| 370 | - * @return void |
|
| 371 | - */ |
|
| 372 | - private function _set_defaults() |
|
| 373 | - { |
|
| 374 | - // set some defaults |
|
| 375 | - foreach ($this->_default_session_vars as $key => $default_var) { |
|
| 376 | - if (is_array($default_var)) { |
|
| 377 | - $this->_session_data[ $key ] = array(); |
|
| 378 | - } else { |
|
| 379 | - $this->_session_data[ $key ] = ''; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - } |
|
| 231 | + // retrieve session options from db |
|
| 232 | + $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 233 | + if (! empty($session_settings)) { |
|
| 234 | + // cycle though existing session options |
|
| 235 | + foreach ($session_settings as $var_name => $session_setting) { |
|
| 236 | + // set values for class properties |
|
| 237 | + $var_name = '_' . $var_name; |
|
| 238 | + $this->{$var_name} = $session_setting; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + $this->cache_storage = $cache_storage; |
|
| 242 | + // are we using encryption? |
|
| 243 | + $this->_use_encryption = $encryption instanceof EE_Encryption |
|
| 244 | + && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
| 245 | + // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
| 246 | + // encrypt data via: $this->encryption->encrypt(); |
|
| 247 | + $this->encryption = $encryption; |
|
| 248 | + // filter hook allows outside functions/classes/plugins to change default empty cart |
|
| 249 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
| 250 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
| 251 | + // apply default session vars |
|
| 252 | + $this->_set_defaults(); |
|
| 253 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
| 254 | + // check request for 'clear_session' param |
|
| 255 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
| 256 | + // once everything is all said and done, |
|
| 257 | + add_action('shutdown', array($this, 'update'), 100); |
|
| 258 | + add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
| 259 | + $this->configure_garbage_collection_filters(); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @return bool |
|
| 265 | + * @throws InvalidArgumentException |
|
| 266 | + * @throws InvalidDataTypeException |
|
| 267 | + * @throws InvalidInterfaceException |
|
| 268 | + */ |
|
| 269 | + public static function isLoadedAndActive() |
|
| 270 | + { |
|
| 271 | + return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
| 272 | + && EE_Session::instance() instanceof EE_Session |
|
| 273 | + && EE_Session::instance()->isActive(); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @return bool |
|
| 279 | + */ |
|
| 280 | + public function isActive() |
|
| 281 | + { |
|
| 282 | + return $this->status === EE_Session::STATUS_OPEN; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @return void |
|
| 289 | + * @throws EE_Error |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + * @throws InvalidDataTypeException |
|
| 292 | + * @throws InvalidInterfaceException |
|
| 293 | + * @throws InvalidSessionDataException |
|
| 294 | + */ |
|
| 295 | + public function open_session() |
|
| 296 | + { |
|
| 297 | + // check for existing session and retrieve it from db |
|
| 298 | + if (! $this->_espresso_session()) { |
|
| 299 | + // or just start a new one |
|
| 300 | + $this->_create_espresso_session(); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @return bool |
|
| 308 | + */ |
|
| 309 | + public function expired() |
|
| 310 | + { |
|
| 311 | + return $this->_expired; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @return void |
|
| 318 | + */ |
|
| 319 | + public function reset_expired() |
|
| 320 | + { |
|
| 321 | + $this->_expired = false; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * @return int |
|
| 327 | + */ |
|
| 328 | + public function expiration() |
|
| 329 | + { |
|
| 330 | + return $this->_expiration; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @return int |
|
| 337 | + */ |
|
| 338 | + public function extension() |
|
| 339 | + { |
|
| 340 | + return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @param int $time number of seconds to add to session expiration |
|
| 347 | + */ |
|
| 348 | + public function extend_expiration($time = 0) |
|
| 349 | + { |
|
| 350 | + $time = $time ? $time : $this->extension(); |
|
| 351 | + $this->_expiration += absint($time); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * @return int |
|
| 358 | + */ |
|
| 359 | + public function lifespan() |
|
| 360 | + { |
|
| 361 | + return $this->_lifespan; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * This just sets some defaults for the _session data property |
|
| 368 | + * |
|
| 369 | + * @access private |
|
| 370 | + * @return void |
|
| 371 | + */ |
|
| 372 | + private function _set_defaults() |
|
| 373 | + { |
|
| 374 | + // set some defaults |
|
| 375 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
| 376 | + if (is_array($default_var)) { |
|
| 377 | + $this->_session_data[ $key ] = array(); |
|
| 378 | + } else { |
|
| 379 | + $this->_session_data[ $key ] = ''; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | 384 | |
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * @retrieve session data |
|
| 388 | - * @access public |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 391 | - public function id() |
|
| 392 | - { |
|
| 393 | - return $this->_sid; |
|
| 394 | - } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * @retrieve session data |
|
| 388 | + * @access public |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | + public function id() |
|
| 392 | + { |
|
| 393 | + return $this->_sid; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | 396 | |
| 397 | 397 | |
| 398 | - /** |
|
| 399 | - * @param \EE_Cart $cart |
|
| 400 | - * @return bool |
|
| 401 | - */ |
|
| 402 | - public function set_cart(EE_Cart $cart) |
|
| 403 | - { |
|
| 404 | - $this->_session_data['cart'] = $cart; |
|
| 405 | - return true; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * reset_cart |
|
| 412 | - */ |
|
| 413 | - public function reset_cart() |
|
| 414 | - { |
|
| 415 | - do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
| 416 | - $this->_session_data['cart'] = null; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * @return \EE_Cart |
|
| 423 | - */ |
|
| 424 | - public function cart() |
|
| 425 | - { |
|
| 426 | - return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
| 427 | - ? $this->_session_data['cart'] |
|
| 428 | - : null; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @param \EE_Checkout $checkout |
|
| 435 | - * @return bool |
|
| 436 | - */ |
|
| 437 | - public function set_checkout(EE_Checkout $checkout) |
|
| 438 | - { |
|
| 439 | - $this->_session_data['checkout'] = $checkout; |
|
| 440 | - return true; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * reset_checkout |
|
| 447 | - */ |
|
| 448 | - public function reset_checkout() |
|
| 449 | - { |
|
| 450 | - do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
| 451 | - $this->_session_data['checkout'] = null; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * @return \EE_Checkout |
|
| 458 | - */ |
|
| 459 | - public function checkout() |
|
| 460 | - { |
|
| 461 | - return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
| 462 | - ? $this->_session_data['checkout'] |
|
| 463 | - : null; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @param \EE_Transaction $transaction |
|
| 470 | - * @return bool |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function set_transaction(EE_Transaction $transaction) |
|
| 474 | - { |
|
| 475 | - // first remove the session from the transaction before we save the transaction in the session |
|
| 476 | - $transaction->set_txn_session_data(null); |
|
| 477 | - $this->_session_data['transaction'] = $transaction; |
|
| 478 | - return true; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * reset_transaction |
|
| 485 | - */ |
|
| 486 | - public function reset_transaction() |
|
| 487 | - { |
|
| 488 | - do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
| 489 | - $this->_session_data['transaction'] = null; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * @return \EE_Transaction |
|
| 496 | - */ |
|
| 497 | - public function transaction() |
|
| 498 | - { |
|
| 499 | - return isset($this->_session_data['transaction']) |
|
| 500 | - && $this->_session_data['transaction'] instanceof EE_Transaction |
|
| 501 | - ? $this->_session_data['transaction'] |
|
| 502 | - : null; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * retrieve session data |
|
| 508 | - * |
|
| 509 | - * @param null $key |
|
| 510 | - * @param bool $reset_cache |
|
| 511 | - * @return array |
|
| 512 | - */ |
|
| 513 | - public function get_session_data($key = null, $reset_cache = false) |
|
| 514 | - { |
|
| 515 | - if ($reset_cache) { |
|
| 516 | - $this->reset_cart(); |
|
| 517 | - $this->reset_checkout(); |
|
| 518 | - $this->reset_transaction(); |
|
| 519 | - } |
|
| 520 | - if (! empty($key)) { |
|
| 521 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 522 | - } |
|
| 523 | - return $this->_session_data; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * Returns TRUE on success, FALSE on fail |
|
| 529 | - * |
|
| 530 | - * @param array $data |
|
| 531 | - * @return bool |
|
| 532 | - */ |
|
| 533 | - public function set_session_data($data) |
|
| 534 | - { |
|
| 535 | - |
|
| 536 | - // nothing ??? bad data ??? go home! |
|
| 537 | - if (empty($data) || ! is_array($data)) { |
|
| 538 | - EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, |
|
| 539 | - __FUNCTION__, __LINE__); |
|
| 540 | - return false; |
|
| 541 | - } |
|
| 542 | - foreach ($data as $key => $value) { |
|
| 543 | - if (isset($this->_default_session_vars[ $key ])) { |
|
| 544 | - EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 545 | - 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
|
| 546 | - return false; |
|
| 547 | - } |
|
| 548 | - $this->_session_data[ $key ] = $value; |
|
| 549 | - } |
|
| 550 | - return true; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * @initiate session |
|
| 557 | - * @access private |
|
| 558 | - * @return TRUE on success, FALSE on fail |
|
| 559 | - * @throws EE_Error |
|
| 560 | - * @throws InvalidArgumentException |
|
| 561 | - * @throws InvalidDataTypeException |
|
| 562 | - * @throws InvalidInterfaceException |
|
| 563 | - * @throws InvalidSessionDataException |
|
| 564 | - */ |
|
| 565 | - private function _espresso_session() |
|
| 566 | - { |
|
| 567 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 568 | - // check that session has started |
|
| 569 | - if (session_id() === '') { |
|
| 570 | - //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
| 571 | - session_start(); |
|
| 572 | - } |
|
| 573 | - $this->status = EE_Session::STATUS_OPEN; |
|
| 574 | - // get our modified session ID |
|
| 575 | - $this->_sid = $this->_generate_session_id(); |
|
| 576 | - // and the visitors IP |
|
| 577 | - $this->_ip_address = $this->request->ipAddress(); |
|
| 578 | - // set the "user agent" |
|
| 579 | - $this->_user_agent = $this->request->userAgent(); |
|
| 580 | - // now let's retrieve what's in the db |
|
| 581 | - $session_data = $this->_retrieve_session_data(); |
|
| 582 | - if (! empty($session_data)) { |
|
| 583 | - // get the current time in UTC |
|
| 584 | - $this->_time = $this->_time !== null ? $this->_time : time(); |
|
| 585 | - // and reset the session expiration |
|
| 586 | - $this->_expiration = isset($session_data['expiration']) |
|
| 587 | - ? $session_data['expiration'] |
|
| 588 | - : $this->_time + $this->_lifespan; |
|
| 589 | - } else { |
|
| 590 | - // set initial site access time and the session expiration |
|
| 591 | - $this->_set_init_access_and_expiration(); |
|
| 592 | - // set referer |
|
| 593 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 594 | - ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 595 | - : ''; |
|
| 596 | - // no previous session = go back and create one (on top of the data above) |
|
| 597 | - return false; |
|
| 598 | - } |
|
| 599 | - // now the user agent |
|
| 600 | - if ($session_data['user_agent'] !== $this->_user_agent) { |
|
| 601 | - return false; |
|
| 602 | - } |
|
| 603 | - // wait a minute... how old are you? |
|
| 604 | - if ($this->_time > $this->_expiration) { |
|
| 605 | - // yer too old fer me! |
|
| 606 | - $this->_expired = true; |
|
| 607 | - // wipe out everything that isn't a default session datum |
|
| 608 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 609 | - } |
|
| 610 | - // make event espresso session data available to plugin |
|
| 611 | - $this->_session_data = array_merge($this->_session_data, $session_data); |
|
| 612 | - return true; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * _get_session_data |
|
| 619 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
| 620 | - * databases |
|
| 621 | - * |
|
| 622 | - * @return array |
|
| 623 | - * @throws EE_Error |
|
| 624 | - * @throws InvalidArgumentException |
|
| 625 | - * @throws InvalidSessionDataException |
|
| 626 | - * @throws InvalidDataTypeException |
|
| 627 | - * @throws InvalidInterfaceException |
|
| 628 | - */ |
|
| 629 | - protected function _retrieve_session_data() |
|
| 630 | - { |
|
| 631 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 632 | - try { |
|
| 633 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 634 | - $session_data = $this->cache_storage->get($ssn_key, false); |
|
| 635 | - if (empty($session_data)) { |
|
| 636 | - return array(); |
|
| 637 | - } |
|
| 638 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 639 | - $hash_check = $this->cache_storage->get( |
|
| 640 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 641 | - false |
|
| 642 | - ); |
|
| 643 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 644 | - EE_Error::add_error( |
|
| 645 | - sprintf( |
|
| 646 | - __( |
|
| 647 | - 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
| 648 | - 'event_espresso' |
|
| 649 | - ), |
|
| 650 | - EE_Session::session_id_prefix . $this->_sid |
|
| 651 | - ), |
|
| 652 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 653 | - ); |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - } catch (Exception $e) { |
|
| 657 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
| 658 | - global $wpdb; |
|
| 659 | - $row = $wpdb->get_row( |
|
| 660 | - $wpdb->prepare( |
|
| 661 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 662 | - '_transient_' . $ssn_key |
|
| 663 | - ) |
|
| 664 | - ); |
|
| 665 | - $session_data = is_object($row) ? $row->option_value : null; |
|
| 666 | - if ($session_data) { |
|
| 667 | - $session_data = preg_replace_callback( |
|
| 668 | - '!s:(d+):"(.*?)";!', |
|
| 669 | - function ($match) |
|
| 670 | - { |
|
| 671 | - return $match[1] === strlen($match[2]) |
|
| 672 | - ? $match[0] |
|
| 673 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 674 | - }, |
|
| 675 | - $session_data |
|
| 676 | - ); |
|
| 677 | - } |
|
| 678 | - $session_data = maybe_unserialize($session_data); |
|
| 679 | - } |
|
| 680 | - // in case the data is encoded... try to decode it |
|
| 681 | - $session_data = $this->encryption instanceof EE_Encryption |
|
| 682 | - ? $this->encryption->base64_string_decode($session_data) |
|
| 683 | - : $session_data; |
|
| 684 | - if (! is_array($session_data)) { |
|
| 685 | - try { |
|
| 686 | - $session_data = maybe_unserialize($session_data); |
|
| 687 | - } catch (Exception $e) { |
|
| 688 | - $msg = esc_html__( |
|
| 689 | - 'An error occurred while attempting to unserialize the session data.', |
|
| 690 | - 'event_espresso' |
|
| 691 | - ); |
|
| 692 | - $msg .= WP_DEBUG |
|
| 693 | - ? '<br><pre>' |
|
| 694 | - . print_r($session_data, true) |
|
| 695 | - . '</pre><br>' |
|
| 696 | - . $this->find_serialize_error($session_data) |
|
| 697 | - : ''; |
|
| 698 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 699 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - // just a check to make sure the session array is indeed an array |
|
| 703 | - if (! is_array($session_data)) { |
|
| 704 | - // no?!?! then something is wrong |
|
| 705 | - $msg = esc_html__( |
|
| 706 | - 'The session data is missing, invalid, or corrupted.', |
|
| 707 | - 'event_espresso' |
|
| 708 | - ); |
|
| 709 | - $msg .= WP_DEBUG |
|
| 710 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 711 | - : ''; |
|
| 712 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 713 | - throw new InvalidSessionDataException($msg); |
|
| 714 | - } |
|
| 715 | - if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
| 716 | - $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 717 | - $session_data['transaction'] |
|
| 718 | - ); |
|
| 719 | - } |
|
| 720 | - return $session_data; |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * _generate_session_id |
|
| 727 | - * Retrieves the PHP session id either directly from the PHP session, |
|
| 728 | - * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
| 729 | - * The session id is then salted and hashed (mmm sounds tasty) |
|
| 730 | - * so that it can be safely used as a $_REQUEST param |
|
| 731 | - * |
|
| 732 | - * @return string |
|
| 733 | - */ |
|
| 734 | - protected function _generate_session_id() |
|
| 735 | - { |
|
| 736 | - // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
| 737 | - if (isset($_REQUEST['EESID'])) { |
|
| 738 | - $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
| 739 | - } else { |
|
| 740 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 741 | - } |
|
| 742 | - return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * _get_sid_salt |
|
| 749 | - * |
|
| 750 | - * @return string |
|
| 751 | - */ |
|
| 752 | - protected function _get_sid_salt() |
|
| 753 | - { |
|
| 754 | - // was session id salt already saved to db ? |
|
| 755 | - if (empty($this->_sid_salt)) { |
|
| 756 | - // no? then maybe use WP defined constant |
|
| 757 | - if (defined('AUTH_SALT')) { |
|
| 758 | - $this->_sid_salt = AUTH_SALT; |
|
| 759 | - } |
|
| 760 | - // if salt doesn't exist or is too short |
|
| 761 | - if (strlen($this->_sid_salt) < 32) { |
|
| 762 | - // create a new one |
|
| 763 | - $this->_sid_salt = wp_generate_password(64); |
|
| 764 | - } |
|
| 765 | - // and save it as a permanent session setting |
|
| 766 | - $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
| 767 | - } |
|
| 768 | - return $this->_sid_salt; |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * _set_init_access_and_expiration |
|
| 775 | - * |
|
| 776 | - * @return void |
|
| 777 | - */ |
|
| 778 | - protected function _set_init_access_and_expiration() |
|
| 779 | - { |
|
| 780 | - $this->_time = time(); |
|
| 781 | - $this->_expiration = $this->_time + $this->_lifespan; |
|
| 782 | - // set initial site access time |
|
| 783 | - $this->_session_data['init_access'] = $this->_time; |
|
| 784 | - // and the session expiration |
|
| 785 | - $this->_session_data['expiration'] = $this->_expiration; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * @update session data prior to saving to the db |
|
| 792 | - * @access public |
|
| 793 | - * @param bool $new_session |
|
| 794 | - * @return TRUE on success, FALSE on fail |
|
| 795 | - * @throws EE_Error |
|
| 796 | - * @throws InvalidArgumentException |
|
| 797 | - * @throws InvalidDataTypeException |
|
| 798 | - * @throws InvalidInterfaceException |
|
| 799 | - */ |
|
| 800 | - public function update($new_session = false) |
|
| 801 | - { |
|
| 802 | - $this->_session_data = $this->_session_data !== null |
|
| 803 | - && is_array($this->_session_data) |
|
| 804 | - && isset($this->_session_data['id']) |
|
| 805 | - ? $this->_session_data |
|
| 806 | - : array(); |
|
| 807 | - if (empty($this->_session_data)) { |
|
| 808 | - $this->_set_defaults(); |
|
| 809 | - } |
|
| 810 | - $session_data = array(); |
|
| 811 | - foreach ($this->_session_data as $key => $value) { |
|
| 812 | - |
|
| 813 | - switch ($key) { |
|
| 814 | - |
|
| 815 | - case 'id' : |
|
| 816 | - // session ID |
|
| 817 | - $session_data['id'] = $this->_sid; |
|
| 818 | - break; |
|
| 819 | - case 'ip_address' : |
|
| 820 | - // visitor ip address |
|
| 821 | - $session_data['ip_address'] = $this->request->ipAddress(); |
|
| 822 | - break; |
|
| 823 | - case 'user_agent' : |
|
| 824 | - // visitor user_agent |
|
| 825 | - $session_data['user_agent'] = $this->_user_agent; |
|
| 826 | - break; |
|
| 827 | - case 'init_access' : |
|
| 828 | - $session_data['init_access'] = absint($value); |
|
| 829 | - break; |
|
| 830 | - case 'last_access' : |
|
| 831 | - // current access time |
|
| 832 | - $session_data['last_access'] = $this->_time; |
|
| 833 | - break; |
|
| 834 | - case 'expiration' : |
|
| 835 | - // when the session expires |
|
| 836 | - $session_data['expiration'] = ! empty($this->_expiration) |
|
| 837 | - ? $this->_expiration |
|
| 838 | - : $session_data['init_access'] + $this->_lifespan; |
|
| 839 | - break; |
|
| 840 | - case 'user_id' : |
|
| 841 | - // current user if logged in |
|
| 842 | - $session_data['user_id'] = $this->_wp_user_id(); |
|
| 843 | - break; |
|
| 844 | - case 'pages_visited' : |
|
| 845 | - $page_visit = $this->_get_page_visit(); |
|
| 846 | - if ($page_visit) { |
|
| 847 | - // set pages visited where the first will be the http referrer |
|
| 848 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 849 | - // we'll only save the last 10 page visits. |
|
| 850 | - $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
| 851 | - } |
|
| 852 | - break; |
|
| 853 | - default : |
|
| 854 | - // carry any other data over |
|
| 855 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - $this->_session_data = $session_data; |
|
| 859 | - // creating a new session does not require saving to the db just yet |
|
| 860 | - if (! $new_session) { |
|
| 861 | - // ready? let's save |
|
| 862 | - if ($this->_save_session_to_db()) { |
|
| 863 | - return true; |
|
| 864 | - } |
|
| 865 | - return false; |
|
| 866 | - } |
|
| 867 | - // meh, why not? |
|
| 868 | - return true; |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * @create session data array |
|
| 875 | - * @access public |
|
| 876 | - * @return bool |
|
| 877 | - * @throws EE_Error |
|
| 878 | - * @throws InvalidArgumentException |
|
| 879 | - * @throws InvalidDataTypeException |
|
| 880 | - * @throws InvalidInterfaceException |
|
| 881 | - */ |
|
| 882 | - private function _create_espresso_session() |
|
| 883 | - { |
|
| 884 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
| 885 | - // use the update function for now with $new_session arg set to TRUE |
|
| 886 | - return $this->update(true) ? true : false; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * _save_session_to_db |
|
| 893 | - * |
|
| 894 | - * @param bool $clear_session |
|
| 895 | - * @return string |
|
| 896 | - * @throws EE_Error |
|
| 897 | - * @throws InvalidArgumentException |
|
| 898 | - * @throws InvalidDataTypeException |
|
| 899 | - * @throws InvalidInterfaceException |
|
| 900 | - */ |
|
| 901 | - private function _save_session_to_db($clear_session = false) |
|
| 902 | - { |
|
| 903 | - // don't save sessions for crawlers |
|
| 904 | - // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
| 905 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 906 | - return false; |
|
| 907 | - } |
|
| 908 | - $transaction = $this->transaction(); |
|
| 909 | - if ($transaction instanceof EE_Transaction) { |
|
| 910 | - if (! $transaction->ID()) { |
|
| 911 | - $transaction->save(); |
|
| 912 | - } |
|
| 913 | - $this->_session_data['transaction'] = $transaction->ID(); |
|
| 914 | - } |
|
| 915 | - // then serialize all of our session data |
|
| 916 | - $session_data = serialize($this->_session_data); |
|
| 917 | - // do we need to also encode it to avoid corrupted data when saved to the db? |
|
| 918 | - $session_data = $this->_use_encryption |
|
| 919 | - ? $this->encryption->base64_string_encode($session_data) |
|
| 920 | - : $session_data; |
|
| 921 | - // maybe save hash check |
|
| 922 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 923 | - $this->cache_storage->add( |
|
| 924 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 925 | - md5($session_data), |
|
| 926 | - $this->_lifespan |
|
| 927 | - ); |
|
| 928 | - } |
|
| 929 | - // we're using the Transient API for storing session data, |
|
| 930 | - return $this->cache_storage->add( |
|
| 931 | - EE_Session::session_id_prefix . $this->_sid, |
|
| 932 | - $session_data, |
|
| 933 | - $this->_lifespan |
|
| 934 | - ); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * @get the full page request the visitor is accessing |
|
| 940 | - * @access public |
|
| 941 | - * @return string |
|
| 942 | - */ |
|
| 943 | - public function _get_page_visit() |
|
| 944 | - { |
|
| 945 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 946 | - // check for request url |
|
| 947 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 948 | - $http_host = ''; |
|
| 949 | - $page_id = '?'; |
|
| 950 | - $e_reg = ''; |
|
| 951 | - $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
| 952 | - $ru_bits = explode('?', $request_uri); |
|
| 953 | - $request_uri = $ru_bits[0]; |
|
| 954 | - // check for and grab host as well |
|
| 955 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
| 956 | - $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
| 957 | - } |
|
| 958 | - // check for page_id in SERVER REQUEST |
|
| 959 | - if (isset($_REQUEST['page_id'])) { |
|
| 960 | - // rebuild $e_reg without any of the extra parameters |
|
| 961 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 962 | - } |
|
| 963 | - // check for $e_reg in SERVER REQUEST |
|
| 964 | - if (isset($_REQUEST['ee'])) { |
|
| 965 | - // rebuild $e_reg without any of the extra parameters |
|
| 966 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 967 | - } |
|
| 968 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 969 | - } |
|
| 970 | - return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - |
|
| 975 | - /** |
|
| 976 | - * @the current wp user id |
|
| 977 | - * @access public |
|
| 978 | - * @return int |
|
| 979 | - */ |
|
| 980 | - public function _wp_user_id() |
|
| 981 | - { |
|
| 982 | - // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
| 983 | - $this->_wp_user_id = get_current_user_id(); |
|
| 984 | - return $this->_wp_user_id; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * Clear EE_Session data |
|
| 991 | - * |
|
| 992 | - * @access public |
|
| 993 | - * @param string $class |
|
| 994 | - * @param string $function |
|
| 995 | - * @return void |
|
| 996 | - * @throws EE_Error |
|
| 997 | - * @throws InvalidArgumentException |
|
| 998 | - * @throws InvalidDataTypeException |
|
| 999 | - * @throws InvalidInterfaceException |
|
| 1000 | - */ |
|
| 1001 | - public function clear_session($class = '', $function = '') |
|
| 1002 | - { |
|
| 1003 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1004 | - $this->reset_cart(); |
|
| 1005 | - $this->reset_checkout(); |
|
| 1006 | - $this->reset_transaction(); |
|
| 1007 | - // wipe out everything that isn't a default session datum |
|
| 1008 | - $this->reset_data(array_keys($this->_session_data)); |
|
| 1009 | - // reset initial site access time and the session expiration |
|
| 1010 | - $this->_set_init_access_and_expiration(); |
|
| 1011 | - $this->_save_session_to_db(true); |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
| 1017 | - * |
|
| 1018 | - * @param array|mixed $data_to_reset |
|
| 1019 | - * @param bool $show_all_notices |
|
| 1020 | - * @return bool |
|
| 1021 | - */ |
|
| 1022 | - public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
| 1023 | - { |
|
| 1024 | - // if $data_to_reset is not in an array, then put it in one |
|
| 1025 | - if (! is_array($data_to_reset)) { |
|
| 1026 | - $data_to_reset = array($data_to_reset); |
|
| 1027 | - } |
|
| 1028 | - // nothing ??? go home! |
|
| 1029 | - if (empty($data_to_reset)) { |
|
| 1030 | - EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
| 1031 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1032 | - return false; |
|
| 1033 | - } |
|
| 1034 | - $return_value = true; |
|
| 1035 | - // since $data_to_reset is an array, cycle through the values |
|
| 1036 | - foreach ($data_to_reset as $reset) { |
|
| 1037 | - |
|
| 1038 | - // first check to make sure it is a valid session var |
|
| 1039 | - if (isset($this->_session_data[ $reset ])) { |
|
| 1040 | - // then check to make sure it is not a default var |
|
| 1041 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1042 | - // remove session var |
|
| 1043 | - unset($this->_session_data[ $reset ]); |
|
| 1044 | - if ($show_all_notices) { |
|
| 1045 | - EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
| 1046 | - $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1047 | - } |
|
| 1048 | - } else { |
|
| 1049 | - // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
| 1050 | - if ($show_all_notices) { |
|
| 1051 | - EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 1052 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1053 | - } |
|
| 1054 | - $return_value = false; |
|
| 1055 | - } |
|
| 1056 | - } elseif ($show_all_notices) { |
|
| 1057 | - // oops! that session var does not exist! |
|
| 1058 | - EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
| 1059 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1060 | - $return_value = false; |
|
| 1061 | - } |
|
| 1062 | - } // end of foreach |
|
| 1063 | - return $return_value; |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - /** |
|
| 1069 | - * wp_loaded |
|
| 1070 | - * |
|
| 1071 | - * @access public |
|
| 1072 | - * @throws EE_Error |
|
| 1073 | - * @throws InvalidDataTypeException |
|
| 1074 | - * @throws InvalidInterfaceException |
|
| 1075 | - * @throws InvalidArgumentException |
|
| 1076 | - */ |
|
| 1077 | - public function wp_loaded() |
|
| 1078 | - { |
|
| 1079 | - if ($this->request->requestParamIsSet('clear_session')) { |
|
| 1080 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * Used to reset the entire object (for tests). |
|
| 1088 | - * |
|
| 1089 | - * @since 4.3.0 |
|
| 1090 | - * @throws EE_Error |
|
| 1091 | - * @throws InvalidDataTypeException |
|
| 1092 | - * @throws InvalidInterfaceException |
|
| 1093 | - * @throws InvalidArgumentException |
|
| 1094 | - */ |
|
| 1095 | - public function reset_instance() |
|
| 1096 | - { |
|
| 1097 | - $this->clear_session(); |
|
| 1098 | - self::$_instance = null; |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - public function configure_garbage_collection_filters() |
|
| 1104 | - { |
|
| 1105 | - // run old filter we had for controlling session cleanup |
|
| 1106 | - $expired_session_transient_delete_query_limit = absint( |
|
| 1107 | - apply_filters( |
|
| 1108 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1109 | - 50 |
|
| 1110 | - ) |
|
| 1111 | - ); |
|
| 1112 | - // is there a value? or one that is different than the default 50 records? |
|
| 1113 | - if ($expired_session_transient_delete_query_limit === 0) { |
|
| 1114 | - // hook into TransientCacheStorage in case Session cleanup was turned off |
|
| 1115 | - add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
| 1116 | - } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
| 1117 | - // or use that for the new transient cleanup query limit |
|
| 1118 | - add_filter( |
|
| 1119 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
| 1120 | - function () use ($expired_session_transient_delete_query_limit) |
|
| 1121 | - { |
|
| 1122 | - return $expired_session_transient_delete_query_limit; |
|
| 1123 | - } |
|
| 1124 | - ); |
|
| 1125 | - } |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
| 1132 | - * @param $data1 |
|
| 1133 | - * @return string |
|
| 1134 | - */ |
|
| 1135 | - private function find_serialize_error($data1) |
|
| 1136 | - { |
|
| 1137 | - $error = '<pre>'; |
|
| 1138 | - $data2 = preg_replace_callback( |
|
| 1139 | - '!s:(\d+):"(.*?)";!', |
|
| 1140 | - function ($match) |
|
| 1141 | - { |
|
| 1142 | - return ($match[1] === strlen($match[2])) |
|
| 1143 | - ? $match[0] |
|
| 1144 | - : 's:' |
|
| 1145 | - . strlen($match[2]) |
|
| 1146 | - . ':"' |
|
| 1147 | - . $match[2] |
|
| 1148 | - . '";'; |
|
| 1149 | - }, |
|
| 1150 | - $data1 |
|
| 1151 | - ); |
|
| 1152 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1153 | - $error .= $data1 . PHP_EOL; |
|
| 1154 | - $error .= $data2 . PHP_EOL; |
|
| 1155 | - for ($i = 0; $i < $max; $i++) { |
|
| 1156 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1157 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1158 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1159 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1160 | - $start = ($i - 20); |
|
| 1161 | - $start = ($start < 0) ? 0 : $start; |
|
| 1162 | - $length = 40; |
|
| 1163 | - $point = $max - $i; |
|
| 1164 | - if ($point < 20) { |
|
| 1165 | - $rlength = 1; |
|
| 1166 | - $rpoint = -$point; |
|
| 1167 | - } else { |
|
| 1168 | - $rpoint = $length - 20; |
|
| 1169 | - $rlength = 1; |
|
| 1170 | - } |
|
| 1171 | - $error .= "\t-> Section Data1 = "; |
|
| 1172 | - $error .= substr_replace( |
|
| 1173 | - substr($data1, $start, $length), |
|
| 1174 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1175 | - $rpoint, |
|
| 1176 | - $rlength |
|
| 1177 | - ); |
|
| 1178 | - $error .= PHP_EOL; |
|
| 1179 | - $error .= "\t-> Section Data2 = "; |
|
| 1180 | - $error .= substr_replace( |
|
| 1181 | - substr($data2, $start, $length), |
|
| 1182 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1183 | - $rpoint, |
|
| 1184 | - $rlength |
|
| 1185 | - ); |
|
| 1186 | - $error .= PHP_EOL; |
|
| 1187 | - } |
|
| 1188 | - } |
|
| 1189 | - $error .= '</pre>'; |
|
| 1190 | - return $error; |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - |
|
| 1194 | - /** |
|
| 1195 | - * Saves an array of settings used for configuring aspects of session behaviour |
|
| 1196 | - * |
|
| 1197 | - * @param array $updated_settings |
|
| 1198 | - */ |
|
| 1199 | - private function updateSessionSettings(array $updated_settings = array()) |
|
| 1200 | - { |
|
| 1201 | - // add existing settings, but only if not included in incoming $updated_settings array |
|
| 1202 | - $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 1203 | - update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - |
|
| 1207 | - /** |
|
| 1208 | - * garbage_collection |
|
| 1209 | - */ |
|
| 1210 | - public function garbageCollection() |
|
| 1211 | - { |
|
| 1212 | - // only perform during regular requests if last garbage collection was over an hour ago |
|
| 1213 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1214 | - $this->_last_gc = time(); |
|
| 1215 | - $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
| 1216 | - /** @type WPDB $wpdb */ |
|
| 1217 | - global $wpdb; |
|
| 1218 | - // filter the query limit. Set to 0 to turn off garbage collection |
|
| 1219 | - $expired_session_transient_delete_query_limit = absint( |
|
| 1220 | - apply_filters( |
|
| 1221 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1222 | - 50 |
|
| 1223 | - ) |
|
| 1224 | - ); |
|
| 1225 | - // non-zero LIMIT means take out the trash |
|
| 1226 | - if ($expired_session_transient_delete_query_limit) { |
|
| 1227 | - $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
| 1228 | - $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
| 1229 | - // since transient expiration timestamps are set in the future, we can compare against NOW |
|
| 1230 | - // but we only want to pick up any trash that's been around for more than a day |
|
| 1231 | - $expiration = time() - DAY_IN_SECONDS; |
|
| 1232 | - $SQL = " |
|
| 398 | + /** |
|
| 399 | + * @param \EE_Cart $cart |
|
| 400 | + * @return bool |
|
| 401 | + */ |
|
| 402 | + public function set_cart(EE_Cart $cart) |
|
| 403 | + { |
|
| 404 | + $this->_session_data['cart'] = $cart; |
|
| 405 | + return true; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * reset_cart |
|
| 412 | + */ |
|
| 413 | + public function reset_cart() |
|
| 414 | + { |
|
| 415 | + do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
| 416 | + $this->_session_data['cart'] = null; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * @return \EE_Cart |
|
| 423 | + */ |
|
| 424 | + public function cart() |
|
| 425 | + { |
|
| 426 | + return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
| 427 | + ? $this->_session_data['cart'] |
|
| 428 | + : null; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @param \EE_Checkout $checkout |
|
| 435 | + * @return bool |
|
| 436 | + */ |
|
| 437 | + public function set_checkout(EE_Checkout $checkout) |
|
| 438 | + { |
|
| 439 | + $this->_session_data['checkout'] = $checkout; |
|
| 440 | + return true; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * reset_checkout |
|
| 447 | + */ |
|
| 448 | + public function reset_checkout() |
|
| 449 | + { |
|
| 450 | + do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
| 451 | + $this->_session_data['checkout'] = null; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * @return \EE_Checkout |
|
| 458 | + */ |
|
| 459 | + public function checkout() |
|
| 460 | + { |
|
| 461 | + return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
| 462 | + ? $this->_session_data['checkout'] |
|
| 463 | + : null; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @param \EE_Transaction $transaction |
|
| 470 | + * @return bool |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function set_transaction(EE_Transaction $transaction) |
|
| 474 | + { |
|
| 475 | + // first remove the session from the transaction before we save the transaction in the session |
|
| 476 | + $transaction->set_txn_session_data(null); |
|
| 477 | + $this->_session_data['transaction'] = $transaction; |
|
| 478 | + return true; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * reset_transaction |
|
| 485 | + */ |
|
| 486 | + public function reset_transaction() |
|
| 487 | + { |
|
| 488 | + do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
| 489 | + $this->_session_data['transaction'] = null; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * @return \EE_Transaction |
|
| 496 | + */ |
|
| 497 | + public function transaction() |
|
| 498 | + { |
|
| 499 | + return isset($this->_session_data['transaction']) |
|
| 500 | + && $this->_session_data['transaction'] instanceof EE_Transaction |
|
| 501 | + ? $this->_session_data['transaction'] |
|
| 502 | + : null; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * retrieve session data |
|
| 508 | + * |
|
| 509 | + * @param null $key |
|
| 510 | + * @param bool $reset_cache |
|
| 511 | + * @return array |
|
| 512 | + */ |
|
| 513 | + public function get_session_data($key = null, $reset_cache = false) |
|
| 514 | + { |
|
| 515 | + if ($reset_cache) { |
|
| 516 | + $this->reset_cart(); |
|
| 517 | + $this->reset_checkout(); |
|
| 518 | + $this->reset_transaction(); |
|
| 519 | + } |
|
| 520 | + if (! empty($key)) { |
|
| 521 | + return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 522 | + } |
|
| 523 | + return $this->_session_data; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * Returns TRUE on success, FALSE on fail |
|
| 529 | + * |
|
| 530 | + * @param array $data |
|
| 531 | + * @return bool |
|
| 532 | + */ |
|
| 533 | + public function set_session_data($data) |
|
| 534 | + { |
|
| 535 | + |
|
| 536 | + // nothing ??? bad data ??? go home! |
|
| 537 | + if (empty($data) || ! is_array($data)) { |
|
| 538 | + EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, |
|
| 539 | + __FUNCTION__, __LINE__); |
|
| 540 | + return false; |
|
| 541 | + } |
|
| 542 | + foreach ($data as $key => $value) { |
|
| 543 | + if (isset($this->_default_session_vars[ $key ])) { |
|
| 544 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 545 | + 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
|
| 546 | + return false; |
|
| 547 | + } |
|
| 548 | + $this->_session_data[ $key ] = $value; |
|
| 549 | + } |
|
| 550 | + return true; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * @initiate session |
|
| 557 | + * @access private |
|
| 558 | + * @return TRUE on success, FALSE on fail |
|
| 559 | + * @throws EE_Error |
|
| 560 | + * @throws InvalidArgumentException |
|
| 561 | + * @throws InvalidDataTypeException |
|
| 562 | + * @throws InvalidInterfaceException |
|
| 563 | + * @throws InvalidSessionDataException |
|
| 564 | + */ |
|
| 565 | + private function _espresso_session() |
|
| 566 | + { |
|
| 567 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 568 | + // check that session has started |
|
| 569 | + if (session_id() === '') { |
|
| 570 | + //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
| 571 | + session_start(); |
|
| 572 | + } |
|
| 573 | + $this->status = EE_Session::STATUS_OPEN; |
|
| 574 | + // get our modified session ID |
|
| 575 | + $this->_sid = $this->_generate_session_id(); |
|
| 576 | + // and the visitors IP |
|
| 577 | + $this->_ip_address = $this->request->ipAddress(); |
|
| 578 | + // set the "user agent" |
|
| 579 | + $this->_user_agent = $this->request->userAgent(); |
|
| 580 | + // now let's retrieve what's in the db |
|
| 581 | + $session_data = $this->_retrieve_session_data(); |
|
| 582 | + if (! empty($session_data)) { |
|
| 583 | + // get the current time in UTC |
|
| 584 | + $this->_time = $this->_time !== null ? $this->_time : time(); |
|
| 585 | + // and reset the session expiration |
|
| 586 | + $this->_expiration = isset($session_data['expiration']) |
|
| 587 | + ? $session_data['expiration'] |
|
| 588 | + : $this->_time + $this->_lifespan; |
|
| 589 | + } else { |
|
| 590 | + // set initial site access time and the session expiration |
|
| 591 | + $this->_set_init_access_and_expiration(); |
|
| 592 | + // set referer |
|
| 593 | + $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 594 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 595 | + : ''; |
|
| 596 | + // no previous session = go back and create one (on top of the data above) |
|
| 597 | + return false; |
|
| 598 | + } |
|
| 599 | + // now the user agent |
|
| 600 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
| 601 | + return false; |
|
| 602 | + } |
|
| 603 | + // wait a minute... how old are you? |
|
| 604 | + if ($this->_time > $this->_expiration) { |
|
| 605 | + // yer too old fer me! |
|
| 606 | + $this->_expired = true; |
|
| 607 | + // wipe out everything that isn't a default session datum |
|
| 608 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 609 | + } |
|
| 610 | + // make event espresso session data available to plugin |
|
| 611 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
| 612 | + return true; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * _get_session_data |
|
| 619 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
| 620 | + * databases |
|
| 621 | + * |
|
| 622 | + * @return array |
|
| 623 | + * @throws EE_Error |
|
| 624 | + * @throws InvalidArgumentException |
|
| 625 | + * @throws InvalidSessionDataException |
|
| 626 | + * @throws InvalidDataTypeException |
|
| 627 | + * @throws InvalidInterfaceException |
|
| 628 | + */ |
|
| 629 | + protected function _retrieve_session_data() |
|
| 630 | + { |
|
| 631 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 632 | + try { |
|
| 633 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
| 634 | + $session_data = $this->cache_storage->get($ssn_key, false); |
|
| 635 | + if (empty($session_data)) { |
|
| 636 | + return array(); |
|
| 637 | + } |
|
| 638 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 639 | + $hash_check = $this->cache_storage->get( |
|
| 640 | + EE_Session::hash_check_prefix . $this->_sid, |
|
| 641 | + false |
|
| 642 | + ); |
|
| 643 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
| 644 | + EE_Error::add_error( |
|
| 645 | + sprintf( |
|
| 646 | + __( |
|
| 647 | + 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
| 648 | + 'event_espresso' |
|
| 649 | + ), |
|
| 650 | + EE_Session::session_id_prefix . $this->_sid |
|
| 651 | + ), |
|
| 652 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 653 | + ); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + } catch (Exception $e) { |
|
| 657 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
| 658 | + global $wpdb; |
|
| 659 | + $row = $wpdb->get_row( |
|
| 660 | + $wpdb->prepare( |
|
| 661 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
| 662 | + '_transient_' . $ssn_key |
|
| 663 | + ) |
|
| 664 | + ); |
|
| 665 | + $session_data = is_object($row) ? $row->option_value : null; |
|
| 666 | + if ($session_data) { |
|
| 667 | + $session_data = preg_replace_callback( |
|
| 668 | + '!s:(d+):"(.*?)";!', |
|
| 669 | + function ($match) |
|
| 670 | + { |
|
| 671 | + return $match[1] === strlen($match[2]) |
|
| 672 | + ? $match[0] |
|
| 673 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 674 | + }, |
|
| 675 | + $session_data |
|
| 676 | + ); |
|
| 677 | + } |
|
| 678 | + $session_data = maybe_unserialize($session_data); |
|
| 679 | + } |
|
| 680 | + // in case the data is encoded... try to decode it |
|
| 681 | + $session_data = $this->encryption instanceof EE_Encryption |
|
| 682 | + ? $this->encryption->base64_string_decode($session_data) |
|
| 683 | + : $session_data; |
|
| 684 | + if (! is_array($session_data)) { |
|
| 685 | + try { |
|
| 686 | + $session_data = maybe_unserialize($session_data); |
|
| 687 | + } catch (Exception $e) { |
|
| 688 | + $msg = esc_html__( |
|
| 689 | + 'An error occurred while attempting to unserialize the session data.', |
|
| 690 | + 'event_espresso' |
|
| 691 | + ); |
|
| 692 | + $msg .= WP_DEBUG |
|
| 693 | + ? '<br><pre>' |
|
| 694 | + . print_r($session_data, true) |
|
| 695 | + . '</pre><br>' |
|
| 696 | + . $this->find_serialize_error($session_data) |
|
| 697 | + : ''; |
|
| 698 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 699 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + // just a check to make sure the session array is indeed an array |
|
| 703 | + if (! is_array($session_data)) { |
|
| 704 | + // no?!?! then something is wrong |
|
| 705 | + $msg = esc_html__( |
|
| 706 | + 'The session data is missing, invalid, or corrupted.', |
|
| 707 | + 'event_espresso' |
|
| 708 | + ); |
|
| 709 | + $msg .= WP_DEBUG |
|
| 710 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 711 | + : ''; |
|
| 712 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 713 | + throw new InvalidSessionDataException($msg); |
|
| 714 | + } |
|
| 715 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
| 716 | + $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
| 717 | + $session_data['transaction'] |
|
| 718 | + ); |
|
| 719 | + } |
|
| 720 | + return $session_data; |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * _generate_session_id |
|
| 727 | + * Retrieves the PHP session id either directly from the PHP session, |
|
| 728 | + * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
| 729 | + * The session id is then salted and hashed (mmm sounds tasty) |
|
| 730 | + * so that it can be safely used as a $_REQUEST param |
|
| 731 | + * |
|
| 732 | + * @return string |
|
| 733 | + */ |
|
| 734 | + protected function _generate_session_id() |
|
| 735 | + { |
|
| 736 | + // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
| 737 | + if (isset($_REQUEST['EESID'])) { |
|
| 738 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
| 739 | + } else { |
|
| 740 | + $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 741 | + } |
|
| 742 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * _get_sid_salt |
|
| 749 | + * |
|
| 750 | + * @return string |
|
| 751 | + */ |
|
| 752 | + protected function _get_sid_salt() |
|
| 753 | + { |
|
| 754 | + // was session id salt already saved to db ? |
|
| 755 | + if (empty($this->_sid_salt)) { |
|
| 756 | + // no? then maybe use WP defined constant |
|
| 757 | + if (defined('AUTH_SALT')) { |
|
| 758 | + $this->_sid_salt = AUTH_SALT; |
|
| 759 | + } |
|
| 760 | + // if salt doesn't exist or is too short |
|
| 761 | + if (strlen($this->_sid_salt) < 32) { |
|
| 762 | + // create a new one |
|
| 763 | + $this->_sid_salt = wp_generate_password(64); |
|
| 764 | + } |
|
| 765 | + // and save it as a permanent session setting |
|
| 766 | + $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
| 767 | + } |
|
| 768 | + return $this->_sid_salt; |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * _set_init_access_and_expiration |
|
| 775 | + * |
|
| 776 | + * @return void |
|
| 777 | + */ |
|
| 778 | + protected function _set_init_access_and_expiration() |
|
| 779 | + { |
|
| 780 | + $this->_time = time(); |
|
| 781 | + $this->_expiration = $this->_time + $this->_lifespan; |
|
| 782 | + // set initial site access time |
|
| 783 | + $this->_session_data['init_access'] = $this->_time; |
|
| 784 | + // and the session expiration |
|
| 785 | + $this->_session_data['expiration'] = $this->_expiration; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * @update session data prior to saving to the db |
|
| 792 | + * @access public |
|
| 793 | + * @param bool $new_session |
|
| 794 | + * @return TRUE on success, FALSE on fail |
|
| 795 | + * @throws EE_Error |
|
| 796 | + * @throws InvalidArgumentException |
|
| 797 | + * @throws InvalidDataTypeException |
|
| 798 | + * @throws InvalidInterfaceException |
|
| 799 | + */ |
|
| 800 | + public function update($new_session = false) |
|
| 801 | + { |
|
| 802 | + $this->_session_data = $this->_session_data !== null |
|
| 803 | + && is_array($this->_session_data) |
|
| 804 | + && isset($this->_session_data['id']) |
|
| 805 | + ? $this->_session_data |
|
| 806 | + : array(); |
|
| 807 | + if (empty($this->_session_data)) { |
|
| 808 | + $this->_set_defaults(); |
|
| 809 | + } |
|
| 810 | + $session_data = array(); |
|
| 811 | + foreach ($this->_session_data as $key => $value) { |
|
| 812 | + |
|
| 813 | + switch ($key) { |
|
| 814 | + |
|
| 815 | + case 'id' : |
|
| 816 | + // session ID |
|
| 817 | + $session_data['id'] = $this->_sid; |
|
| 818 | + break; |
|
| 819 | + case 'ip_address' : |
|
| 820 | + // visitor ip address |
|
| 821 | + $session_data['ip_address'] = $this->request->ipAddress(); |
|
| 822 | + break; |
|
| 823 | + case 'user_agent' : |
|
| 824 | + // visitor user_agent |
|
| 825 | + $session_data['user_agent'] = $this->_user_agent; |
|
| 826 | + break; |
|
| 827 | + case 'init_access' : |
|
| 828 | + $session_data['init_access'] = absint($value); |
|
| 829 | + break; |
|
| 830 | + case 'last_access' : |
|
| 831 | + // current access time |
|
| 832 | + $session_data['last_access'] = $this->_time; |
|
| 833 | + break; |
|
| 834 | + case 'expiration' : |
|
| 835 | + // when the session expires |
|
| 836 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
| 837 | + ? $this->_expiration |
|
| 838 | + : $session_data['init_access'] + $this->_lifespan; |
|
| 839 | + break; |
|
| 840 | + case 'user_id' : |
|
| 841 | + // current user if logged in |
|
| 842 | + $session_data['user_id'] = $this->_wp_user_id(); |
|
| 843 | + break; |
|
| 844 | + case 'pages_visited' : |
|
| 845 | + $page_visit = $this->_get_page_visit(); |
|
| 846 | + if ($page_visit) { |
|
| 847 | + // set pages visited where the first will be the http referrer |
|
| 848 | + $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 849 | + // we'll only save the last 10 page visits. |
|
| 850 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
| 851 | + } |
|
| 852 | + break; |
|
| 853 | + default : |
|
| 854 | + // carry any other data over |
|
| 855 | + $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + $this->_session_data = $session_data; |
|
| 859 | + // creating a new session does not require saving to the db just yet |
|
| 860 | + if (! $new_session) { |
|
| 861 | + // ready? let's save |
|
| 862 | + if ($this->_save_session_to_db()) { |
|
| 863 | + return true; |
|
| 864 | + } |
|
| 865 | + return false; |
|
| 866 | + } |
|
| 867 | + // meh, why not? |
|
| 868 | + return true; |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * @create session data array |
|
| 875 | + * @access public |
|
| 876 | + * @return bool |
|
| 877 | + * @throws EE_Error |
|
| 878 | + * @throws InvalidArgumentException |
|
| 879 | + * @throws InvalidDataTypeException |
|
| 880 | + * @throws InvalidInterfaceException |
|
| 881 | + */ |
|
| 882 | + private function _create_espresso_session() |
|
| 883 | + { |
|
| 884 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
| 885 | + // use the update function for now with $new_session arg set to TRUE |
|
| 886 | + return $this->update(true) ? true : false; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * _save_session_to_db |
|
| 893 | + * |
|
| 894 | + * @param bool $clear_session |
|
| 895 | + * @return string |
|
| 896 | + * @throws EE_Error |
|
| 897 | + * @throws InvalidArgumentException |
|
| 898 | + * @throws InvalidDataTypeException |
|
| 899 | + * @throws InvalidInterfaceException |
|
| 900 | + */ |
|
| 901 | + private function _save_session_to_db($clear_session = false) |
|
| 902 | + { |
|
| 903 | + // don't save sessions for crawlers |
|
| 904 | + // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
| 905 | + if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 908 | + $transaction = $this->transaction(); |
|
| 909 | + if ($transaction instanceof EE_Transaction) { |
|
| 910 | + if (! $transaction->ID()) { |
|
| 911 | + $transaction->save(); |
|
| 912 | + } |
|
| 913 | + $this->_session_data['transaction'] = $transaction->ID(); |
|
| 914 | + } |
|
| 915 | + // then serialize all of our session data |
|
| 916 | + $session_data = serialize($this->_session_data); |
|
| 917 | + // do we need to also encode it to avoid corrupted data when saved to the db? |
|
| 918 | + $session_data = $this->_use_encryption |
|
| 919 | + ? $this->encryption->base64_string_encode($session_data) |
|
| 920 | + : $session_data; |
|
| 921 | + // maybe save hash check |
|
| 922 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
| 923 | + $this->cache_storage->add( |
|
| 924 | + EE_Session::hash_check_prefix . $this->_sid, |
|
| 925 | + md5($session_data), |
|
| 926 | + $this->_lifespan |
|
| 927 | + ); |
|
| 928 | + } |
|
| 929 | + // we're using the Transient API for storing session data, |
|
| 930 | + return $this->cache_storage->add( |
|
| 931 | + EE_Session::session_id_prefix . $this->_sid, |
|
| 932 | + $session_data, |
|
| 933 | + $this->_lifespan |
|
| 934 | + ); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * @get the full page request the visitor is accessing |
|
| 940 | + * @access public |
|
| 941 | + * @return string |
|
| 942 | + */ |
|
| 943 | + public function _get_page_visit() |
|
| 944 | + { |
|
| 945 | + $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 946 | + // check for request url |
|
| 947 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 948 | + $http_host = ''; |
|
| 949 | + $page_id = '?'; |
|
| 950 | + $e_reg = ''; |
|
| 951 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
| 952 | + $ru_bits = explode('?', $request_uri); |
|
| 953 | + $request_uri = $ru_bits[0]; |
|
| 954 | + // check for and grab host as well |
|
| 955 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
| 956 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
| 957 | + } |
|
| 958 | + // check for page_id in SERVER REQUEST |
|
| 959 | + if (isset($_REQUEST['page_id'])) { |
|
| 960 | + // rebuild $e_reg without any of the extra parameters |
|
| 961 | + $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 962 | + } |
|
| 963 | + // check for $e_reg in SERVER REQUEST |
|
| 964 | + if (isset($_REQUEST['ee'])) { |
|
| 965 | + // rebuild $e_reg without any of the extra parameters |
|
| 966 | + $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 967 | + } |
|
| 968 | + $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 969 | + } |
|
| 970 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + |
|
| 975 | + /** |
|
| 976 | + * @the current wp user id |
|
| 977 | + * @access public |
|
| 978 | + * @return int |
|
| 979 | + */ |
|
| 980 | + public function _wp_user_id() |
|
| 981 | + { |
|
| 982 | + // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
| 983 | + $this->_wp_user_id = get_current_user_id(); |
|
| 984 | + return $this->_wp_user_id; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * Clear EE_Session data |
|
| 991 | + * |
|
| 992 | + * @access public |
|
| 993 | + * @param string $class |
|
| 994 | + * @param string $function |
|
| 995 | + * @return void |
|
| 996 | + * @throws EE_Error |
|
| 997 | + * @throws InvalidArgumentException |
|
| 998 | + * @throws InvalidDataTypeException |
|
| 999 | + * @throws InvalidInterfaceException |
|
| 1000 | + */ |
|
| 1001 | + public function clear_session($class = '', $function = '') |
|
| 1002 | + { |
|
| 1003 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1004 | + $this->reset_cart(); |
|
| 1005 | + $this->reset_checkout(); |
|
| 1006 | + $this->reset_transaction(); |
|
| 1007 | + // wipe out everything that isn't a default session datum |
|
| 1008 | + $this->reset_data(array_keys($this->_session_data)); |
|
| 1009 | + // reset initial site access time and the session expiration |
|
| 1010 | + $this->_set_init_access_and_expiration(); |
|
| 1011 | + $this->_save_session_to_db(true); |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
| 1017 | + * |
|
| 1018 | + * @param array|mixed $data_to_reset |
|
| 1019 | + * @param bool $show_all_notices |
|
| 1020 | + * @return bool |
|
| 1021 | + */ |
|
| 1022 | + public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
| 1023 | + { |
|
| 1024 | + // if $data_to_reset is not in an array, then put it in one |
|
| 1025 | + if (! is_array($data_to_reset)) { |
|
| 1026 | + $data_to_reset = array($data_to_reset); |
|
| 1027 | + } |
|
| 1028 | + // nothing ??? go home! |
|
| 1029 | + if (empty($data_to_reset)) { |
|
| 1030 | + EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
| 1031 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1032 | + return false; |
|
| 1033 | + } |
|
| 1034 | + $return_value = true; |
|
| 1035 | + // since $data_to_reset is an array, cycle through the values |
|
| 1036 | + foreach ($data_to_reset as $reset) { |
|
| 1037 | + |
|
| 1038 | + // first check to make sure it is a valid session var |
|
| 1039 | + if (isset($this->_session_data[ $reset ])) { |
|
| 1040 | + // then check to make sure it is not a default var |
|
| 1041 | + if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1042 | + // remove session var |
|
| 1043 | + unset($this->_session_data[ $reset ]); |
|
| 1044 | + if ($show_all_notices) { |
|
| 1045 | + EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
| 1046 | + $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1047 | + } |
|
| 1048 | + } else { |
|
| 1049 | + // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
| 1050 | + if ($show_all_notices) { |
|
| 1051 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
| 1052 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1053 | + } |
|
| 1054 | + $return_value = false; |
|
| 1055 | + } |
|
| 1056 | + } elseif ($show_all_notices) { |
|
| 1057 | + // oops! that session var does not exist! |
|
| 1058 | + EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
| 1059 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
| 1060 | + $return_value = false; |
|
| 1061 | + } |
|
| 1062 | + } // end of foreach |
|
| 1063 | + return $return_value; |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + /** |
|
| 1069 | + * wp_loaded |
|
| 1070 | + * |
|
| 1071 | + * @access public |
|
| 1072 | + * @throws EE_Error |
|
| 1073 | + * @throws InvalidDataTypeException |
|
| 1074 | + * @throws InvalidInterfaceException |
|
| 1075 | + * @throws InvalidArgumentException |
|
| 1076 | + */ |
|
| 1077 | + public function wp_loaded() |
|
| 1078 | + { |
|
| 1079 | + if ($this->request->requestParamIsSet('clear_session')) { |
|
| 1080 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * Used to reset the entire object (for tests). |
|
| 1088 | + * |
|
| 1089 | + * @since 4.3.0 |
|
| 1090 | + * @throws EE_Error |
|
| 1091 | + * @throws InvalidDataTypeException |
|
| 1092 | + * @throws InvalidInterfaceException |
|
| 1093 | + * @throws InvalidArgumentException |
|
| 1094 | + */ |
|
| 1095 | + public function reset_instance() |
|
| 1096 | + { |
|
| 1097 | + $this->clear_session(); |
|
| 1098 | + self::$_instance = null; |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + public function configure_garbage_collection_filters() |
|
| 1104 | + { |
|
| 1105 | + // run old filter we had for controlling session cleanup |
|
| 1106 | + $expired_session_transient_delete_query_limit = absint( |
|
| 1107 | + apply_filters( |
|
| 1108 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1109 | + 50 |
|
| 1110 | + ) |
|
| 1111 | + ); |
|
| 1112 | + // is there a value? or one that is different than the default 50 records? |
|
| 1113 | + if ($expired_session_transient_delete_query_limit === 0) { |
|
| 1114 | + // hook into TransientCacheStorage in case Session cleanup was turned off |
|
| 1115 | + add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
| 1116 | + } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
| 1117 | + // or use that for the new transient cleanup query limit |
|
| 1118 | + add_filter( |
|
| 1119 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
| 1120 | + function () use ($expired_session_transient_delete_query_limit) |
|
| 1121 | + { |
|
| 1122 | + return $expired_session_transient_delete_query_limit; |
|
| 1123 | + } |
|
| 1124 | + ); |
|
| 1125 | + } |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
| 1132 | + * @param $data1 |
|
| 1133 | + * @return string |
|
| 1134 | + */ |
|
| 1135 | + private function find_serialize_error($data1) |
|
| 1136 | + { |
|
| 1137 | + $error = '<pre>'; |
|
| 1138 | + $data2 = preg_replace_callback( |
|
| 1139 | + '!s:(\d+):"(.*?)";!', |
|
| 1140 | + function ($match) |
|
| 1141 | + { |
|
| 1142 | + return ($match[1] === strlen($match[2])) |
|
| 1143 | + ? $match[0] |
|
| 1144 | + : 's:' |
|
| 1145 | + . strlen($match[2]) |
|
| 1146 | + . ':"' |
|
| 1147 | + . $match[2] |
|
| 1148 | + . '";'; |
|
| 1149 | + }, |
|
| 1150 | + $data1 |
|
| 1151 | + ); |
|
| 1152 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1153 | + $error .= $data1 . PHP_EOL; |
|
| 1154 | + $error .= $data2 . PHP_EOL; |
|
| 1155 | + for ($i = 0; $i < $max; $i++) { |
|
| 1156 | + if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1157 | + $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1158 | + $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1159 | + $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1160 | + $start = ($i - 20); |
|
| 1161 | + $start = ($start < 0) ? 0 : $start; |
|
| 1162 | + $length = 40; |
|
| 1163 | + $point = $max - $i; |
|
| 1164 | + if ($point < 20) { |
|
| 1165 | + $rlength = 1; |
|
| 1166 | + $rpoint = -$point; |
|
| 1167 | + } else { |
|
| 1168 | + $rpoint = $length - 20; |
|
| 1169 | + $rlength = 1; |
|
| 1170 | + } |
|
| 1171 | + $error .= "\t-> Section Data1 = "; |
|
| 1172 | + $error .= substr_replace( |
|
| 1173 | + substr($data1, $start, $length), |
|
| 1174 | + "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1175 | + $rpoint, |
|
| 1176 | + $rlength |
|
| 1177 | + ); |
|
| 1178 | + $error .= PHP_EOL; |
|
| 1179 | + $error .= "\t-> Section Data2 = "; |
|
| 1180 | + $error .= substr_replace( |
|
| 1181 | + substr($data2, $start, $length), |
|
| 1182 | + "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1183 | + $rpoint, |
|
| 1184 | + $rlength |
|
| 1185 | + ); |
|
| 1186 | + $error .= PHP_EOL; |
|
| 1187 | + } |
|
| 1188 | + } |
|
| 1189 | + $error .= '</pre>'; |
|
| 1190 | + return $error; |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Saves an array of settings used for configuring aspects of session behaviour |
|
| 1196 | + * |
|
| 1197 | + * @param array $updated_settings |
|
| 1198 | + */ |
|
| 1199 | + private function updateSessionSettings(array $updated_settings = array()) |
|
| 1200 | + { |
|
| 1201 | + // add existing settings, but only if not included in incoming $updated_settings array |
|
| 1202 | + $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
| 1203 | + update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + |
|
| 1207 | + /** |
|
| 1208 | + * garbage_collection |
|
| 1209 | + */ |
|
| 1210 | + public function garbageCollection() |
|
| 1211 | + { |
|
| 1212 | + // only perform during regular requests if last garbage collection was over an hour ago |
|
| 1213 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1214 | + $this->_last_gc = time(); |
|
| 1215 | + $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
| 1216 | + /** @type WPDB $wpdb */ |
|
| 1217 | + global $wpdb; |
|
| 1218 | + // filter the query limit. Set to 0 to turn off garbage collection |
|
| 1219 | + $expired_session_transient_delete_query_limit = absint( |
|
| 1220 | + apply_filters( |
|
| 1221 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
| 1222 | + 50 |
|
| 1223 | + ) |
|
| 1224 | + ); |
|
| 1225 | + // non-zero LIMIT means take out the trash |
|
| 1226 | + if ($expired_session_transient_delete_query_limit) { |
|
| 1227 | + $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
| 1228 | + $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
| 1229 | + // since transient expiration timestamps are set in the future, we can compare against NOW |
|
| 1230 | + // but we only want to pick up any trash that's been around for more than a day |
|
| 1231 | + $expiration = time() - DAY_IN_SECONDS; |
|
| 1232 | + $SQL = " |
|
| 1233 | 1233 | SELECT option_name |
| 1234 | 1234 | FROM {$wpdb->options} |
| 1235 | 1235 | WHERE |
@@ -1238,19 +1238,19 @@ discard block |
||
| 1238 | 1238 | AND option_value < {$expiration} |
| 1239 | 1239 | LIMIT {$expired_session_transient_delete_query_limit} |
| 1240 | 1240 | "; |
| 1241 | - // produces something like: |
|
| 1242 | - // SELECT option_name FROM wp_options |
|
| 1243 | - // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
| 1244 | - // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
| 1245 | - // AND option_value < 1508368198 LIMIT 50 |
|
| 1246 | - $expired_sessions = $wpdb->get_col($SQL); |
|
| 1247 | - // valid results? |
|
| 1248 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1249 | - $this->cache_storage->deleteMany($expired_sessions, true); |
|
| 1250 | - } |
|
| 1251 | - } |
|
| 1252 | - } |
|
| 1253 | - } |
|
| 1241 | + // produces something like: |
|
| 1242 | + // SELECT option_name FROM wp_options |
|
| 1243 | + // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
| 1244 | + // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
| 1245 | + // AND option_value < 1508368198 LIMIT 50 |
|
| 1246 | + $expired_sessions = $wpdb->get_col($SQL); |
|
| 1247 | + // valid results? |
|
| 1248 | + if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1249 | + $this->cache_storage->deleteMany($expired_sessions, true); |
|
| 1250 | + } |
|
| 1251 | + } |
|
| 1252 | + } |
|
| 1253 | + } |
|
| 1254 | 1254 | |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | // check if class object is instantiated |
| 184 | 184 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
| 185 | 185 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 186 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 186 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
| 187 | 187 | self::$_instance = new self($cache_storage, $request, $encryption); |
| 188 | 188 | } |
| 189 | 189 | return self::$_instance; |
@@ -210,11 +210,11 @@ discard block |
||
| 210 | 210 | // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
| 211 | 211 | // (which currently fires on the init hook at priority 9), |
| 212 | 212 | // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
| 213 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 213 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
| 214 | 214 | return; |
| 215 | 215 | } |
| 216 | 216 | $this->request = $request; |
| 217 | - if (! defined('ESPRESSO_SESSION')) { |
|
| 217 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
| 218 | 218 | define('ESPRESSO_SESSION', true); |
| 219 | 219 | } |
| 220 | 220 | // default session lifespan in seconds |
@@ -230,11 +230,11 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | // retrieve session options from db |
| 232 | 232 | $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
| 233 | - if (! empty($session_settings)) { |
|
| 233 | + if ( ! empty($session_settings)) { |
|
| 234 | 234 | // cycle though existing session options |
| 235 | 235 | foreach ($session_settings as $var_name => $session_setting) { |
| 236 | 236 | // set values for class properties |
| 237 | - $var_name = '_' . $var_name; |
|
| 237 | + $var_name = '_'.$var_name; |
|
| 238 | 238 | $this->{$var_name} = $session_setting; |
| 239 | 239 | } |
| 240 | 240 | } |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | public function open_session() |
| 296 | 296 | { |
| 297 | 297 | // check for existing session and retrieve it from db |
| 298 | - if (! $this->_espresso_session()) { |
|
| 298 | + if ( ! $this->_espresso_session()) { |
|
| 299 | 299 | // or just start a new one |
| 300 | 300 | $this->_create_espresso_session(); |
| 301 | 301 | } |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | public function extend_expiration($time = 0) |
| 349 | 349 | { |
| 350 | - $time = $time ? $time : $this->extension(); |
|
| 350 | + $time = $time ? $time : $this->extension(); |
|
| 351 | 351 | $this->_expiration += absint($time); |
| 352 | 352 | } |
| 353 | 353 | |
@@ -374,9 +374,9 @@ discard block |
||
| 374 | 374 | // set some defaults |
| 375 | 375 | foreach ($this->_default_session_vars as $key => $default_var) { |
| 376 | 376 | if (is_array($default_var)) { |
| 377 | - $this->_session_data[ $key ] = array(); |
|
| 377 | + $this->_session_data[$key] = array(); |
|
| 378 | 378 | } else { |
| 379 | - $this->_session_data[ $key ] = ''; |
|
| 379 | + $this->_session_data[$key] = ''; |
|
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -517,8 +517,8 @@ discard block |
||
| 517 | 517 | $this->reset_checkout(); |
| 518 | 518 | $this->reset_transaction(); |
| 519 | 519 | } |
| 520 | - if (! empty($key)) { |
|
| 521 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
| 520 | + if ( ! empty($key)) { |
|
| 521 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null; |
|
| 522 | 522 | } |
| 523 | 523 | return $this->_session_data; |
| 524 | 524 | } |
@@ -540,12 +540,12 @@ discard block |
||
| 540 | 540 | return false; |
| 541 | 541 | } |
| 542 | 542 | foreach ($data as $key => $value) { |
| 543 | - if (isset($this->_default_session_vars[ $key ])) { |
|
| 543 | + if (isset($this->_default_session_vars[$key])) { |
|
| 544 | 544 | EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
| 545 | 545 | 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
| 546 | 546 | return false; |
| 547 | 547 | } |
| 548 | - $this->_session_data[ $key ] = $value; |
|
| 548 | + $this->_session_data[$key] = $value; |
|
| 549 | 549 | } |
| 550 | 550 | return true; |
| 551 | 551 | } |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | $this->_user_agent = $this->request->userAgent(); |
| 580 | 580 | // now let's retrieve what's in the db |
| 581 | 581 | $session_data = $this->_retrieve_session_data(); |
| 582 | - if (! empty($session_data)) { |
|
| 582 | + if ( ! empty($session_data)) { |
|
| 583 | 583 | // get the current time in UTC |
| 584 | 584 | $this->_time = $this->_time !== null ? $this->_time : time(); |
| 585 | 585 | // and reset the session expiration |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | // set initial site access time and the session expiration |
| 591 | 591 | $this->_set_init_access_and_expiration(); |
| 592 | 592 | // set referer |
| 593 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
| 593 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
| 594 | 594 | ? esc_attr($_SERVER['HTTP_REFERER']) |
| 595 | 595 | : ''; |
| 596 | 596 | // no previous session = go back and create one (on top of the data above) |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | */ |
| 629 | 629 | protected function _retrieve_session_data() |
| 630 | 630 | { |
| 631 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
| 631 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
| 632 | 632 | try { |
| 633 | 633 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
| 634 | 634 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | } |
| 638 | 638 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
| 639 | 639 | $hash_check = $this->cache_storage->get( |
| 640 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 640 | + EE_Session::hash_check_prefix.$this->_sid, |
|
| 641 | 641 | false |
| 642 | 642 | ); |
| 643 | 643 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
| 648 | 648 | 'event_espresso' |
| 649 | 649 | ), |
| 650 | - EE_Session::session_id_prefix . $this->_sid |
|
| 650 | + EE_Session::session_id_prefix.$this->_sid |
|
| 651 | 651 | ), |
| 652 | 652 | __FILE__, __FUNCTION__, __LINE__ |
| 653 | 653 | ); |
@@ -656,21 +656,21 @@ discard block |
||
| 656 | 656 | } catch (Exception $e) { |
| 657 | 657 | // let's just eat that error for now and attempt to correct any corrupted data |
| 658 | 658 | global $wpdb; |
| 659 | - $row = $wpdb->get_row( |
|
| 659 | + $row = $wpdb->get_row( |
|
| 660 | 660 | $wpdb->prepare( |
| 661 | 661 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
| 662 | - '_transient_' . $ssn_key |
|
| 662 | + '_transient_'.$ssn_key |
|
| 663 | 663 | ) |
| 664 | 664 | ); |
| 665 | 665 | $session_data = is_object($row) ? $row->option_value : null; |
| 666 | 666 | if ($session_data) { |
| 667 | 667 | $session_data = preg_replace_callback( |
| 668 | 668 | '!s:(d+):"(.*?)";!', |
| 669 | - function ($match) |
|
| 669 | + function($match) |
|
| 670 | 670 | { |
| 671 | 671 | return $match[1] === strlen($match[2]) |
| 672 | 672 | ? $match[0] |
| 673 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
| 673 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
| 674 | 674 | }, |
| 675 | 675 | $session_data |
| 676 | 676 | ); |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | $session_data = $this->encryption instanceof EE_Encryption |
| 682 | 682 | ? $this->encryption->base64_string_decode($session_data) |
| 683 | 683 | : $session_data; |
| 684 | - if (! is_array($session_data)) { |
|
| 684 | + if ( ! is_array($session_data)) { |
|
| 685 | 685 | try { |
| 686 | 686 | $session_data = maybe_unserialize($session_data); |
| 687 | 687 | } catch (Exception $e) { |
@@ -695,21 +695,21 @@ discard block |
||
| 695 | 695 | . '</pre><br>' |
| 696 | 696 | . $this->find_serialize_error($session_data) |
| 697 | 697 | : ''; |
| 698 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 698 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
| 699 | 699 | throw new InvalidSessionDataException($msg, 0, $e); |
| 700 | 700 | } |
| 701 | 701 | } |
| 702 | 702 | // just a check to make sure the session array is indeed an array |
| 703 | - if (! is_array($session_data)) { |
|
| 703 | + if ( ! is_array($session_data)) { |
|
| 704 | 704 | // no?!?! then something is wrong |
| 705 | 705 | $msg = esc_html__( |
| 706 | 706 | 'The session data is missing, invalid, or corrupted.', |
| 707 | 707 | 'event_espresso' |
| 708 | 708 | ); |
| 709 | 709 | $msg .= WP_DEBUG |
| 710 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
| 710 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
| 711 | 711 | : ''; |
| 712 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
| 712 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
| 713 | 713 | throw new InvalidSessionDataException($msg); |
| 714 | 714 | } |
| 715 | 715 | if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | if (isset($_REQUEST['EESID'])) { |
| 738 | 738 | $session_id = sanitize_text_field($_REQUEST['EESID']); |
| 739 | 739 | } else { |
| 740 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
| 740 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
| 741 | 741 | } |
| 742 | 742 | return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
| 743 | 743 | } |
@@ -845,19 +845,19 @@ discard block |
||
| 845 | 845 | $page_visit = $this->_get_page_visit(); |
| 846 | 846 | if ($page_visit) { |
| 847 | 847 | // set pages visited where the first will be the http referrer |
| 848 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
| 848 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
| 849 | 849 | // we'll only save the last 10 page visits. |
| 850 | 850 | $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
| 851 | 851 | } |
| 852 | 852 | break; |
| 853 | 853 | default : |
| 854 | 854 | // carry any other data over |
| 855 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
| 855 | + $session_data[$key] = $this->_session_data[$key]; |
|
| 856 | 856 | } |
| 857 | 857 | } |
| 858 | 858 | $this->_session_data = $session_data; |
| 859 | 859 | // creating a new session does not require saving to the db just yet |
| 860 | - if (! $new_session) { |
|
| 860 | + if ( ! $new_session) { |
|
| 861 | 861 | // ready? let's save |
| 862 | 862 | if ($this->_save_session_to_db()) { |
| 863 | 863 | return true; |
@@ -902,12 +902,12 @@ discard block |
||
| 902 | 902 | { |
| 903 | 903 | // don't save sessions for crawlers |
| 904 | 904 | // and unless we're deleting the session data, don't save anything if there isn't a cart |
| 905 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 905 | + if ($this->request->isBot() || ( ! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
| 906 | 906 | return false; |
| 907 | 907 | } |
| 908 | 908 | $transaction = $this->transaction(); |
| 909 | 909 | if ($transaction instanceof EE_Transaction) { |
| 910 | - if (! $transaction->ID()) { |
|
| 910 | + if ( ! $transaction->ID()) { |
|
| 911 | 911 | $transaction->save(); |
| 912 | 912 | } |
| 913 | 913 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -921,14 +921,14 @@ discard block |
||
| 921 | 921 | // maybe save hash check |
| 922 | 922 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
| 923 | 923 | $this->cache_storage->add( |
| 924 | - EE_Session::hash_check_prefix . $this->_sid, |
|
| 924 | + EE_Session::hash_check_prefix.$this->_sid, |
|
| 925 | 925 | md5($session_data), |
| 926 | 926 | $this->_lifespan |
| 927 | 927 | ); |
| 928 | 928 | } |
| 929 | 929 | // we're using the Transient API for storing session data, |
| 930 | 930 | return $this->cache_storage->add( |
| 931 | - EE_Session::session_id_prefix . $this->_sid, |
|
| 931 | + EE_Session::session_id_prefix.$this->_sid, |
|
| 932 | 932 | $session_data, |
| 933 | 933 | $this->_lifespan |
| 934 | 934 | ); |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | */ |
| 943 | 943 | public function _get_page_visit() |
| 944 | 944 | { |
| 945 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
| 945 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
| 946 | 946 | // check for request url |
| 947 | 947 | if (isset($_SERVER['REQUEST_URI'])) { |
| 948 | 948 | $http_host = ''; |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | // check for page_id in SERVER REQUEST |
| 959 | 959 | if (isset($_REQUEST['page_id'])) { |
| 960 | 960 | // rebuild $e_reg without any of the extra parameters |
| 961 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
| 961 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
| 962 | 962 | } |
| 963 | 963 | // check for $e_reg in SERVER REQUEST |
| 964 | 964 | if (isset($_REQUEST['ee'])) { |
| 965 | 965 | // rebuild $e_reg without any of the extra parameters |
| 966 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
| 966 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
| 967 | 967 | } |
| 968 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
| 968 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
| 969 | 969 | } |
| 970 | 970 | return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
| 971 | 971 | } |
@@ -1000,7 +1000,7 @@ discard block |
||
| 1000 | 1000 | */ |
| 1001 | 1001 | public function clear_session($class = '', $function = '') |
| 1002 | 1002 | { |
| 1003 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
| 1003 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
| 1004 | 1004 | $this->reset_cart(); |
| 1005 | 1005 | $this->reset_checkout(); |
| 1006 | 1006 | $this->reset_transaction(); |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | public function reset_data($data_to_reset = array(), $show_all_notices = false) |
| 1023 | 1023 | { |
| 1024 | 1024 | // if $data_to_reset is not in an array, then put it in one |
| 1025 | - if (! is_array($data_to_reset)) { |
|
| 1025 | + if ( ! is_array($data_to_reset)) { |
|
| 1026 | 1026 | $data_to_reset = array($data_to_reset); |
| 1027 | 1027 | } |
| 1028 | 1028 | // nothing ??? go home! |
@@ -1036,11 +1036,11 @@ discard block |
||
| 1036 | 1036 | foreach ($data_to_reset as $reset) { |
| 1037 | 1037 | |
| 1038 | 1038 | // first check to make sure it is a valid session var |
| 1039 | - if (isset($this->_session_data[ $reset ])) { |
|
| 1039 | + if (isset($this->_session_data[$reset])) { |
|
| 1040 | 1040 | // then check to make sure it is not a default var |
| 1041 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1041 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
| 1042 | 1042 | // remove session var |
| 1043 | - unset($this->_session_data[ $reset ]); |
|
| 1043 | + unset($this->_session_data[$reset]); |
|
| 1044 | 1044 | if ($show_all_notices) { |
| 1045 | 1045 | EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
| 1046 | 1046 | $reset), __FILE__, __FUNCTION__, __LINE__); |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | // or use that for the new transient cleanup query limit |
| 1118 | 1118 | add_filter( |
| 1119 | 1119 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
| 1120 | - function () use ($expired_session_transient_delete_query_limit) |
|
| 1120 | + function() use ($expired_session_transient_delete_query_limit) |
|
| 1121 | 1121 | { |
| 1122 | 1122 | return $expired_session_transient_delete_query_limit; |
| 1123 | 1123 | } |
@@ -1137,7 +1137,7 @@ discard block |
||
| 1137 | 1137 | $error = '<pre>'; |
| 1138 | 1138 | $data2 = preg_replace_callback( |
| 1139 | 1139 | '!s:(\d+):"(.*?)";!', |
| 1140 | - function ($match) |
|
| 1140 | + function($match) |
|
| 1141 | 1141 | { |
| 1142 | 1142 | return ($match[1] === strlen($match[2])) |
| 1143 | 1143 | ? $match[0] |
@@ -1149,14 +1149,14 @@ discard block |
||
| 1149 | 1149 | }, |
| 1150 | 1150 | $data1 |
| 1151 | 1151 | ); |
| 1152 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1153 | - $error .= $data1 . PHP_EOL; |
|
| 1154 | - $error .= $data2 . PHP_EOL; |
|
| 1152 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
| 1153 | + $error .= $data1.PHP_EOL; |
|
| 1154 | + $error .= $data2.PHP_EOL; |
|
| 1155 | 1155 | for ($i = 0; $i < $max; $i++) { |
| 1156 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
| 1157 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
| 1158 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
| 1159 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
| 1156 | + if (@$data1[$i] !== @$data2[$i]) { |
|
| 1157 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
| 1158 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
| 1159 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
| 1160 | 1160 | $start = ($i - 20); |
| 1161 | 1161 | $start = ($start < 0) ? 0 : $start; |
| 1162 | 1162 | $length = 40; |
@@ -1171,7 +1171,7 @@ discard block |
||
| 1171 | 1171 | $error .= "\t-> Section Data1 = "; |
| 1172 | 1172 | $error .= substr_replace( |
| 1173 | 1173 | substr($data1, $start, $length), |
| 1174 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
| 1174 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
| 1175 | 1175 | $rpoint, |
| 1176 | 1176 | $rlength |
| 1177 | 1177 | ); |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | $error .= "\t-> Section Data2 = "; |
| 1180 | 1180 | $error .= substr_replace( |
| 1181 | 1181 | substr($data2, $start, $length), |
| 1182 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
| 1182 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
| 1183 | 1183 | $rpoint, |
| 1184 | 1184 | $rlength |
| 1185 | 1185 | ); |
@@ -1210,7 +1210,7 @@ discard block |
||
| 1210 | 1210 | public function garbageCollection() |
| 1211 | 1211 | { |
| 1212 | 1212 | // only perform during regular requests if last garbage collection was over an hour ago |
| 1213 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1213 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
| 1214 | 1214 | $this->_last_gc = time(); |
| 1215 | 1215 | $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
| 1216 | 1216 | /** @type WPDB $wpdb */ |
@@ -1245,7 +1245,7 @@ discard block |
||
| 1245 | 1245 | // AND option_value < 1508368198 LIMIT 50 |
| 1246 | 1246 | $expired_sessions = $wpdb->get_col($SQL); |
| 1247 | 1247 | // valid results? |
| 1248 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1248 | + if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
| 1249 | 1249 | $this->cache_storage->deleteMany($expired_sessions, true); |
| 1250 | 1250 | } |
| 1251 | 1251 | } |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | // if you're a dev and want to receive all errors via email |
| 12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
| 13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
| 14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
| 15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
| 15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | |
@@ -27,258 +27,258 @@ discard block |
||
| 27 | 27 | class EE_Error extends Exception |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * name of the file to log exceptions to |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * stores details for all exception |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - private static $_all_exceptions = array(); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * tracks number of errors |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - private static $_error_count = 0; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var array $_espresso_notices |
|
| 56 | - */ |
|
| 57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @override default exception handling |
|
| 63 | - * @param string $message |
|
| 64 | - * @param int $code |
|
| 65 | - * @param Exception|null $previous |
|
| 66 | - */ |
|
| 67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
| 68 | - { |
|
| 69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 70 | - parent::__construct($message, $code); |
|
| 71 | - } else { |
|
| 72 | - parent::__construct($message, $code, $previous); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * error_handler |
|
| 79 | - * |
|
| 80 | - * @param $code |
|
| 81 | - * @param $message |
|
| 82 | - * @param $file |
|
| 83 | - * @param $line |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public static function error_handler($code, $message, $file, $line) |
|
| 87 | - { |
|
| 88 | - $type = EE_Error::error_type($code); |
|
| 89 | - $site = site_url(); |
|
| 90 | - switch ($site) { |
|
| 91 | - case 'http://ee4.eventespresso.com/' : |
|
| 92 | - case 'http://ee4decaf.eventespresso.com/' : |
|
| 93 | - case 'http://ee4hf.eventespresso.com/' : |
|
| 94 | - case 'http://ee4a.eventespresso.com/' : |
|
| 95 | - case 'http://ee4ad.eventespresso.com/' : |
|
| 96 | - case 'http://ee4b.eventespresso.com/' : |
|
| 97 | - case 'http://ee4bd.eventespresso.com/' : |
|
| 98 | - case 'http://ee4d.eventespresso.com/' : |
|
| 99 | - case 'http://ee4dd.eventespresso.com/' : |
|
| 100 | - $to = '[email protected]'; |
|
| 101 | - break; |
|
| 102 | - default : |
|
| 103 | - $to = get_option('admin_email'); |
|
| 104 | - } |
|
| 105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 106 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 107 | - if (function_exists('wp_mail')) { |
|
| 108 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 109 | - wp_mail($to, $subject, $msg); |
|
| 110 | - } |
|
| 111 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 113 | - echo '<br /></p></div>'; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * error_type |
|
| 120 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 121 | - * |
|
| 122 | - * @param $code |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public static function error_type($code) |
|
| 126 | - { |
|
| 127 | - switch ($code) { |
|
| 128 | - case E_ERROR: // 1 // |
|
| 129 | - return 'E_ERROR'; |
|
| 130 | - case E_WARNING: // 2 // |
|
| 131 | - return 'E_WARNING'; |
|
| 132 | - case E_PARSE: // 4 // |
|
| 133 | - return 'E_PARSE'; |
|
| 134 | - case E_NOTICE: // 8 // |
|
| 135 | - return 'E_NOTICE'; |
|
| 136 | - case E_CORE_ERROR: // 16 // |
|
| 137 | - return 'E_CORE_ERROR'; |
|
| 138 | - case E_CORE_WARNING: // 32 // |
|
| 139 | - return 'E_CORE_WARNING'; |
|
| 140 | - case E_COMPILE_ERROR: // 64 // |
|
| 141 | - return 'E_COMPILE_ERROR'; |
|
| 142 | - case E_COMPILE_WARNING: // 128 // |
|
| 143 | - return 'E_COMPILE_WARNING'; |
|
| 144 | - case E_USER_ERROR: // 256 // |
|
| 145 | - return 'E_USER_ERROR'; |
|
| 146 | - case E_USER_WARNING: // 512 // |
|
| 147 | - return 'E_USER_WARNING'; |
|
| 148 | - case E_USER_NOTICE: // 1024 // |
|
| 149 | - return 'E_USER_NOTICE'; |
|
| 150 | - case E_STRICT: // 2048 // |
|
| 151 | - return 'E_STRICT'; |
|
| 152 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
| 153 | - return 'E_RECOVERABLE_ERROR'; |
|
| 154 | - case E_DEPRECATED: // 8192 // |
|
| 155 | - return 'E_DEPRECATED'; |
|
| 156 | - case E_USER_DEPRECATED: // 16384 // |
|
| 157 | - return 'E_USER_DEPRECATED'; |
|
| 158 | - case E_ALL: // 16384 // |
|
| 159 | - return 'E_ALL'; |
|
| 160 | - } |
|
| 161 | - return ''; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * fatal_error_handler |
|
| 168 | - * |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - public static function fatal_error_handler() |
|
| 172 | - { |
|
| 173 | - $last_error = error_get_last(); |
|
| 174 | - if ($last_error['type'] === E_ERROR) { |
|
| 175 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * _format_error |
|
| 183 | - * |
|
| 184 | - * @param $code |
|
| 185 | - * @param $message |
|
| 186 | - * @param $file |
|
| 187 | - * @param $line |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - private static function _format_error($code, $message, $file, $line) |
|
| 191 | - { |
|
| 192 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 193 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 194 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 195 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 196 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 197 | - $html .= '</tbody></table>'; |
|
| 198 | - return $html; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * set_content_type |
|
| 205 | - * |
|
| 206 | - * @param $content_type |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - public static function set_content_type($content_type) |
|
| 210 | - { |
|
| 211 | - return 'text/html'; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @return void |
|
| 218 | - * @throws EE_Error |
|
| 219 | - * @throws ReflectionException |
|
| 220 | - */ |
|
| 221 | - public function get_error() |
|
| 222 | - { |
|
| 223 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 224 | - throw $this; |
|
| 225 | - } |
|
| 226 | - // get separate user and developer messages if they exist |
|
| 227 | - $msg = explode('||', $this->getMessage()); |
|
| 228 | - $user_msg = $msg[0]; |
|
| 229 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 230 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 231 | - // add details to _all_exceptions array |
|
| 232 | - $x_time = time(); |
|
| 233 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 234 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 235 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 236 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 237 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 238 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 239 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 240 | - self::$_error_count++; |
|
| 241 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 242 | - $this->display_errors(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param bool $check_stored |
|
| 248 | - * @param string $type_to_check |
|
| 249 | - * @return bool |
|
| 250 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 251 | - * @throws \InvalidArgumentException |
|
| 252 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 253 | - * @throws InvalidInterfaceException |
|
| 254 | - */ |
|
| 255 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 256 | - { |
|
| 257 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 258 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 259 | - ? true |
|
| 260 | - : false; |
|
| 261 | - if ($check_stored && ! $has_error) { |
|
| 262 | - $notices = EE_Error::getStoredNotices(); |
|
| 263 | - foreach ($notices as $type => $notice) { |
|
| 264 | - if ($type === $type_to_check && $notice) { |
|
| 265 | - return true; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - return $has_error; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @echo string |
|
| 276 | - * @throws \ReflectionException |
|
| 277 | - */ |
|
| 278 | - public function display_errors() |
|
| 279 | - { |
|
| 280 | - $trace_details = ''; |
|
| 281 | - $output = ' |
|
| 30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * name of the file to log exceptions to |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * stores details for all exception |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + private static $_all_exceptions = array(); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * tracks number of errors |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + private static $_error_count = 0; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var array $_espresso_notices |
|
| 56 | + */ |
|
| 57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @override default exception handling |
|
| 63 | + * @param string $message |
|
| 64 | + * @param int $code |
|
| 65 | + * @param Exception|null $previous |
|
| 66 | + */ |
|
| 67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
| 68 | + { |
|
| 69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 70 | + parent::__construct($message, $code); |
|
| 71 | + } else { |
|
| 72 | + parent::__construct($message, $code, $previous); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * error_handler |
|
| 79 | + * |
|
| 80 | + * @param $code |
|
| 81 | + * @param $message |
|
| 82 | + * @param $file |
|
| 83 | + * @param $line |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public static function error_handler($code, $message, $file, $line) |
|
| 87 | + { |
|
| 88 | + $type = EE_Error::error_type($code); |
|
| 89 | + $site = site_url(); |
|
| 90 | + switch ($site) { |
|
| 91 | + case 'http://ee4.eventespresso.com/' : |
|
| 92 | + case 'http://ee4decaf.eventespresso.com/' : |
|
| 93 | + case 'http://ee4hf.eventespresso.com/' : |
|
| 94 | + case 'http://ee4a.eventespresso.com/' : |
|
| 95 | + case 'http://ee4ad.eventespresso.com/' : |
|
| 96 | + case 'http://ee4b.eventespresso.com/' : |
|
| 97 | + case 'http://ee4bd.eventespresso.com/' : |
|
| 98 | + case 'http://ee4d.eventespresso.com/' : |
|
| 99 | + case 'http://ee4dd.eventespresso.com/' : |
|
| 100 | + $to = '[email protected]'; |
|
| 101 | + break; |
|
| 102 | + default : |
|
| 103 | + $to = get_option('admin_email'); |
|
| 104 | + } |
|
| 105 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
| 106 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
| 107 | + if (function_exists('wp_mail')) { |
|
| 108 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
| 109 | + wp_mail($to, $subject, $msg); |
|
| 110 | + } |
|
| 111 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
| 112 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
| 113 | + echo '<br /></p></div>'; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * error_type |
|
| 120 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
| 121 | + * |
|
| 122 | + * @param $code |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public static function error_type($code) |
|
| 126 | + { |
|
| 127 | + switch ($code) { |
|
| 128 | + case E_ERROR: // 1 // |
|
| 129 | + return 'E_ERROR'; |
|
| 130 | + case E_WARNING: // 2 // |
|
| 131 | + return 'E_WARNING'; |
|
| 132 | + case E_PARSE: // 4 // |
|
| 133 | + return 'E_PARSE'; |
|
| 134 | + case E_NOTICE: // 8 // |
|
| 135 | + return 'E_NOTICE'; |
|
| 136 | + case E_CORE_ERROR: // 16 // |
|
| 137 | + return 'E_CORE_ERROR'; |
|
| 138 | + case E_CORE_WARNING: // 32 // |
|
| 139 | + return 'E_CORE_WARNING'; |
|
| 140 | + case E_COMPILE_ERROR: // 64 // |
|
| 141 | + return 'E_COMPILE_ERROR'; |
|
| 142 | + case E_COMPILE_WARNING: // 128 // |
|
| 143 | + return 'E_COMPILE_WARNING'; |
|
| 144 | + case E_USER_ERROR: // 256 // |
|
| 145 | + return 'E_USER_ERROR'; |
|
| 146 | + case E_USER_WARNING: // 512 // |
|
| 147 | + return 'E_USER_WARNING'; |
|
| 148 | + case E_USER_NOTICE: // 1024 // |
|
| 149 | + return 'E_USER_NOTICE'; |
|
| 150 | + case E_STRICT: // 2048 // |
|
| 151 | + return 'E_STRICT'; |
|
| 152 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
| 153 | + return 'E_RECOVERABLE_ERROR'; |
|
| 154 | + case E_DEPRECATED: // 8192 // |
|
| 155 | + return 'E_DEPRECATED'; |
|
| 156 | + case E_USER_DEPRECATED: // 16384 // |
|
| 157 | + return 'E_USER_DEPRECATED'; |
|
| 158 | + case E_ALL: // 16384 // |
|
| 159 | + return 'E_ALL'; |
|
| 160 | + } |
|
| 161 | + return ''; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * fatal_error_handler |
|
| 168 | + * |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + public static function fatal_error_handler() |
|
| 172 | + { |
|
| 173 | + $last_error = error_get_last(); |
|
| 174 | + if ($last_error['type'] === E_ERROR) { |
|
| 175 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * _format_error |
|
| 183 | + * |
|
| 184 | + * @param $code |
|
| 185 | + * @param $message |
|
| 186 | + * @param $file |
|
| 187 | + * @param $line |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + private static function _format_error($code, $message, $file, $line) |
|
| 191 | + { |
|
| 192 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
| 193 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
| 194 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
| 195 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
| 196 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
| 197 | + $html .= '</tbody></table>'; |
|
| 198 | + return $html; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * set_content_type |
|
| 205 | + * |
|
| 206 | + * @param $content_type |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + public static function set_content_type($content_type) |
|
| 210 | + { |
|
| 211 | + return 'text/html'; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @return void |
|
| 218 | + * @throws EE_Error |
|
| 219 | + * @throws ReflectionException |
|
| 220 | + */ |
|
| 221 | + public function get_error() |
|
| 222 | + { |
|
| 223 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
| 224 | + throw $this; |
|
| 225 | + } |
|
| 226 | + // get separate user and developer messages if they exist |
|
| 227 | + $msg = explode('||', $this->getMessage()); |
|
| 228 | + $user_msg = $msg[0]; |
|
| 229 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 230 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 231 | + // add details to _all_exceptions array |
|
| 232 | + $x_time = time(); |
|
| 233 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
| 234 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
| 235 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
| 236 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
| 237 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
| 238 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
| 239 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
| 240 | + self::$_error_count++; |
|
| 241 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
| 242 | + $this->display_errors(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param bool $check_stored |
|
| 248 | + * @param string $type_to_check |
|
| 249 | + * @return bool |
|
| 250 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 251 | + * @throws \InvalidArgumentException |
|
| 252 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 253 | + * @throws InvalidInterfaceException |
|
| 254 | + */ |
|
| 255 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
| 256 | + { |
|
| 257 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
| 258 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
| 259 | + ? true |
|
| 260 | + : false; |
|
| 261 | + if ($check_stored && ! $has_error) { |
|
| 262 | + $notices = EE_Error::getStoredNotices(); |
|
| 263 | + foreach ($notices as $type => $notice) { |
|
| 264 | + if ($type === $type_to_check && $notice) { |
|
| 265 | + return true; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + return $has_error; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @echo string |
|
| 276 | + * @throws \ReflectionException |
|
| 277 | + */ |
|
| 278 | + public function display_errors() |
|
| 279 | + { |
|
| 280 | + $trace_details = ''; |
|
| 281 | + $output = ' |
|
| 282 | 282 | <style type="text/css"> |
| 283 | 283 | #ee-error-message { |
| 284 | 284 | max-width:90% !important; |
@@ -334,21 +334,21 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | </style> |
| 336 | 336 | <div id="ee-error-message" class="error">'; |
| 337 | - if (! WP_DEBUG) { |
|
| 338 | - $output .= ' |
|
| 337 | + if (! WP_DEBUG) { |
|
| 338 | + $output .= ' |
|
| 339 | 339 | <p>'; |
| 340 | - } |
|
| 341 | - // cycle thru errors |
|
| 342 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
| 343 | - $error_code = ''; |
|
| 344 | - // process trace info |
|
| 345 | - if (empty($ex['trace'])) { |
|
| 346 | - $trace_details .= __( |
|
| 347 | - 'Sorry, but no trace information was available for this exception.', |
|
| 348 | - 'event_espresso' |
|
| 349 | - ); |
|
| 350 | - } else { |
|
| 351 | - $trace_details .= ' |
|
| 340 | + } |
|
| 341 | + // cycle thru errors |
|
| 342 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
| 343 | + $error_code = ''; |
|
| 344 | + // process trace info |
|
| 345 | + if (empty($ex['trace'])) { |
|
| 346 | + $trace_details .= __( |
|
| 347 | + 'Sorry, but no trace information was available for this exception.', |
|
| 348 | + 'event_espresso' |
|
| 349 | + ); |
|
| 350 | + } else { |
|
| 351 | + $trace_details .= ' |
|
| 352 | 352 | <div id="ee-trace-details"> |
| 353 | 353 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
| 354 | 354 | <tr> |
@@ -358,43 +358,43 @@ discard block |
||
| 358 | 358 | <th scope="col" align="left">Class</th> |
| 359 | 359 | <th scope="col" align="left">Method( arguments )</th> |
| 360 | 360 | </tr>'; |
| 361 | - $last_on_stack = count($ex['trace']) - 1; |
|
| 362 | - // reverse array so that stack is in proper chronological order |
|
| 363 | - $sorted_trace = array_reverse($ex['trace']); |
|
| 364 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
| 365 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 366 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 367 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 368 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 369 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 370 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 371 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 372 | - if (empty($file) && ! empty($class)) { |
|
| 373 | - $a = new ReflectionClass($class); |
|
| 374 | - $file = $a->getFileName(); |
|
| 375 | - if (empty($line) && ! empty($function)) { |
|
| 376 | - try { |
|
| 377 | - //if $function is a closure, this throws an exception |
|
| 378 | - $b = new ReflectionMethod($class, $function); |
|
| 379 | - $line = $b->getStartLine(); |
|
| 380 | - } catch (Exception $closure_exception) { |
|
| 381 | - $line = 'unknown'; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - if ($nmbr === $last_on_stack) { |
|
| 386 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 387 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 388 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 389 | - } |
|
| 390 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 391 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
| 392 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
| 393 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
| 394 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
| 395 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
| 396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 397 | - $trace_details .= ' |
|
| 361 | + $last_on_stack = count($ex['trace']) - 1; |
|
| 362 | + // reverse array so that stack is in proper chronological order |
|
| 363 | + $sorted_trace = array_reverse($ex['trace']); |
|
| 364 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
| 365 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 366 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
| 367 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 368 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 369 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 370 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 371 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
| 372 | + if (empty($file) && ! empty($class)) { |
|
| 373 | + $a = new ReflectionClass($class); |
|
| 374 | + $file = $a->getFileName(); |
|
| 375 | + if (empty($line) && ! empty($function)) { |
|
| 376 | + try { |
|
| 377 | + //if $function is a closure, this throws an exception |
|
| 378 | + $b = new ReflectionMethod($class, $function); |
|
| 379 | + $line = $b->getStartLine(); |
|
| 380 | + } catch (Exception $closure_exception) { |
|
| 381 | + $line = 'unknown'; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + if ($nmbr === $last_on_stack) { |
|
| 386 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
| 387 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
| 388 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
| 389 | + } |
|
| 390 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
| 391 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
| 392 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
| 393 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
| 394 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
| 395 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
| 396 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
| 397 | + $trace_details .= ' |
|
| 398 | 398 | <tr> |
| 399 | 399 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
| 400 | 400 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -402,633 +402,633 @@ discard block |
||
| 402 | 402 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
| 403 | 403 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
| 404 | 404 | </tr>'; |
| 405 | - } |
|
| 406 | - $trace_details .= ' |
|
| 405 | + } |
|
| 406 | + $trace_details .= ' |
|
| 407 | 407 | </table> |
| 408 | 408 | </div>'; |
| 409 | - } |
|
| 410 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 411 | - // add generic non-identifying messages for non-privileged users |
|
| 412 | - if (! WP_DEBUG) { |
|
| 413 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
| 414 | - . trim($ex['msg']) |
|
| 415 | - . '</span> <sup>' |
|
| 416 | - . $ex['code'] |
|
| 417 | - . '</sup><br />'; |
|
| 418 | - } else { |
|
| 419 | - // or helpful developer messages if debugging is on |
|
| 420 | - $output .= ' |
|
| 409 | + } |
|
| 410 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
| 411 | + // add generic non-identifying messages for non-privileged users |
|
| 412 | + if (! WP_DEBUG) { |
|
| 413 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
| 414 | + . trim($ex['msg']) |
|
| 415 | + . '</span> <sup>' |
|
| 416 | + . $ex['code'] |
|
| 417 | + . '</sup><br />'; |
|
| 418 | + } else { |
|
| 419 | + // or helpful developer messages if debugging is on |
|
| 420 | + $output .= ' |
|
| 421 | 421 | <div class="ee-error-dev-msg-dv"> |
| 422 | 422 | <p class="ee-error-dev-msg-pg"> |
| 423 | 423 | <strong class="ee-error-dev-msg-str">An ' |
| 424 | - . $ex['name'] |
|
| 425 | - . ' exception was thrown!</strong> <span>code: ' |
|
| 426 | - . $ex['code'] |
|
| 427 | - . '</span><br /> |
|
| 424 | + . $ex['name'] |
|
| 425 | + . ' exception was thrown!</strong> <span>code: ' |
|
| 426 | + . $ex['code'] |
|
| 427 | + . '</span><br /> |
|
| 428 | 428 | <span class="big-text">"' |
| 429 | - . trim($ex['msg']) |
|
| 430 | - . '"</span><br/> |
|
| 429 | + . trim($ex['msg']) |
|
| 430 | + . '"</span><br/> |
|
| 431 | 431 | <a id="display-ee-error-trace-' |
| 432 | - . self::$_error_count |
|
| 433 | - . $time |
|
| 434 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 435 | - . self::$_error_count |
|
| 436 | - . $time |
|
| 437 | - . '"> |
|
| 432 | + . self::$_error_count |
|
| 433 | + . $time |
|
| 434 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
| 435 | + . self::$_error_count |
|
| 436 | + . $time |
|
| 437 | + . '"> |
|
| 438 | 438 | ' |
| 439 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 440 | - . ' |
|
| 439 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
| 440 | + . ' |
|
| 441 | 441 | </a><br /> |
| 442 | 442 | <span class="small-text lt-grey-text">' |
| 443 | - . $ex['file'] |
|
| 444 | - . ' ( line no: ' |
|
| 445 | - . $ex['line'] |
|
| 446 | - . ' )</span> |
|
| 443 | + . $ex['file'] |
|
| 444 | + . ' ( line no: ' |
|
| 445 | + . $ex['line'] |
|
| 446 | + . ' )</span> |
|
| 447 | 447 | </p> |
| 448 | 448 | <div id="ee-error-trace-' |
| 449 | - . self::$_error_count |
|
| 450 | - . $time |
|
| 451 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 449 | + . self::$_error_count |
|
| 450 | + . $time |
|
| 451 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 452 | 452 | ' |
| 453 | - . $trace_details; |
|
| 454 | - if (! empty($class)) { |
|
| 455 | - $output .= ' |
|
| 453 | + . $trace_details; |
|
| 454 | + if (! empty($class)) { |
|
| 455 | + $output .= ' |
|
| 456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
| 457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
| 458 | 458 | <h3>Class Details</h3>'; |
| 459 | - $a = new ReflectionClass($class); |
|
| 460 | - $output .= ' |
|
| 459 | + $a = new ReflectionClass($class); |
|
| 460 | + $output .= ' |
|
| 461 | 461 | <pre>' . $a . '</pre> |
| 462 | 462 | </div> |
| 463 | 463 | </div>'; |
| 464 | - } |
|
| 465 | - $output .= ' |
|
| 464 | + } |
|
| 465 | + $output .= ' |
|
| 466 | 466 | </div> |
| 467 | 467 | </div> |
| 468 | 468 | <br />'; |
| 469 | - } |
|
| 470 | - $this->write_to_error_log($time, $ex); |
|
| 471 | - } |
|
| 472 | - // remove last linebreak |
|
| 473 | - $output = substr($output, 0, -6); |
|
| 474 | - if (! WP_DEBUG) { |
|
| 475 | - $output .= ' |
|
| 469 | + } |
|
| 470 | + $this->write_to_error_log($time, $ex); |
|
| 471 | + } |
|
| 472 | + // remove last linebreak |
|
| 473 | + $output = substr($output, 0, -6); |
|
| 474 | + if (! WP_DEBUG) { |
|
| 475 | + $output .= ' |
|
| 476 | 476 | </p>'; |
| 477 | - } |
|
| 478 | - $output .= ' |
|
| 477 | + } |
|
| 478 | + $output .= ' |
|
| 479 | 479 | </div>'; |
| 480 | - $output .= self::_print_scripts(true); |
|
| 481 | - if (defined('DOING_AJAX')) { |
|
| 482 | - echo wp_json_encode(array('error' => $output)); |
|
| 483 | - exit(); |
|
| 484 | - } |
|
| 485 | - echo $output; |
|
| 486 | - die(); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * generate string from exception trace args |
|
| 493 | - * |
|
| 494 | - * @param array $arguments |
|
| 495 | - * @param bool $array |
|
| 496 | - * @return string |
|
| 497 | - */ |
|
| 498 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 499 | - { |
|
| 500 | - $arg_string = ''; |
|
| 501 | - if (! empty($arguments)) { |
|
| 502 | - $args = array(); |
|
| 503 | - foreach ($arguments as $arg) { |
|
| 504 | - if (! empty($arg)) { |
|
| 505 | - if (is_string($arg)) { |
|
| 506 | - $args[] = " '" . $arg . "'"; |
|
| 507 | - } elseif (is_array($arg)) { |
|
| 508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 509 | - } elseif ($arg === null) { |
|
| 510 | - $args[] = ' NULL'; |
|
| 511 | - } elseif (is_bool($arg)) { |
|
| 512 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 513 | - } elseif (is_object($arg)) { |
|
| 514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
| 515 | - } elseif (is_resource($arg)) { |
|
| 516 | - $args[] = get_resource_type($arg); |
|
| 517 | - } else { |
|
| 518 | - $args[] = $arg; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - $arg_string = implode(', ', $args); |
|
| 523 | - } |
|
| 524 | - if ($array) { |
|
| 525 | - $arg_string .= ' )'; |
|
| 526 | - } |
|
| 527 | - return $arg_string; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * add error message |
|
| 534 | - * |
|
| 535 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 536 | - * separate messages for user || dev |
|
| 537 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 538 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 539 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 540 | - * @return void |
|
| 541 | - */ |
|
| 542 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 543 | - { |
|
| 544 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 545 | - self::$_error_count++; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 552 | - * adds an error |
|
| 553 | - * |
|
| 554 | - * @param string $msg |
|
| 555 | - * @param string $file |
|
| 556 | - * @param string $func |
|
| 557 | - * @param string $line |
|
| 558 | - * @throws EE_Error |
|
| 559 | - */ |
|
| 560 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 561 | - { |
|
| 562 | - if (WP_DEBUG) { |
|
| 563 | - throw new EE_Error($msg); |
|
| 564 | - } |
|
| 565 | - EE_Error::add_error($msg, $file, $func, $line); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * add success message |
|
| 572 | - * |
|
| 573 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 574 | - * separate messages for user || dev |
|
| 575 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 576 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 577 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 578 | - * @return void |
|
| 579 | - */ |
|
| 580 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 581 | - { |
|
| 582 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * add attention message |
|
| 589 | - * |
|
| 590 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 591 | - * separate messages for user || dev |
|
| 592 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 593 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 594 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 595 | - * @return void |
|
| 596 | - */ |
|
| 597 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 598 | - { |
|
| 599 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @param string $type whether the message is for a success or error notification |
|
| 606 | - * @param string $msg the message to display to users or developers |
|
| 607 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
| 608 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 609 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 610 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 611 | - * @return void |
|
| 612 | - */ |
|
| 613 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
| 614 | - { |
|
| 615 | - if (empty($msg)) { |
|
| 616 | - EE_Error::doing_it_wrong( |
|
| 617 | - 'EE_Error::add_' . $type . '()', |
|
| 618 | - sprintf( |
|
| 619 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 620 | - 'event_espresso'), |
|
| 621 | - $type, |
|
| 622 | - $file, |
|
| 623 | - $line |
|
| 624 | - ), |
|
| 625 | - EVENT_ESPRESSO_VERSION |
|
| 626 | - ); |
|
| 627 | - } |
|
| 628 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 629 | - EE_Error::doing_it_wrong( |
|
| 630 | - 'EE_Error::add_error()', |
|
| 631 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 632 | - 'event_espresso'), |
|
| 633 | - EVENT_ESPRESSO_VERSION |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - // get separate user and developer messages if they exist |
|
| 637 | - $msg = explode('||', $msg); |
|
| 638 | - $user_msg = $msg[0]; |
|
| 639 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 640 | - /** |
|
| 641 | - * Do an action so other code can be triggered when a notice is created |
|
| 642 | - * |
|
| 643 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
| 644 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 645 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 646 | - * @param string $file file where error was generated |
|
| 647 | - * @param string $func function where error was generated |
|
| 648 | - * @param string $line line where error was generated |
|
| 649 | - */ |
|
| 650 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 651 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 652 | - // add notice if message exists |
|
| 653 | - if (! empty($msg)) { |
|
| 654 | - // get error code |
|
| 655 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 656 | - if (WP_DEBUG && $type === 'errors') { |
|
| 657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 658 | - } |
|
| 659 | - // add notice. Index by code if it's not blank |
|
| 660 | - if ($notice_code) { |
|
| 661 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 662 | - } else { |
|
| 663 | - self::$_espresso_notices[$type][] = $msg; |
|
| 664 | - } |
|
| 665 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * in some case it may be necessary to overwrite the existing success messages |
|
| 672 | - * |
|
| 673 | - * @return void |
|
| 674 | - */ |
|
| 675 | - public static function overwrite_success() |
|
| 676 | - { |
|
| 677 | - self::$_espresso_notices['success'] = false; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * in some case it may be necessary to overwrite the existing attention messages |
|
| 684 | - * |
|
| 685 | - * @return void |
|
| 686 | - */ |
|
| 687 | - public static function overwrite_attention() |
|
| 688 | - { |
|
| 689 | - self::$_espresso_notices['attention'] = false; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * in some case it may be necessary to overwrite the existing error messages |
|
| 696 | - * |
|
| 697 | - * @return void |
|
| 698 | - */ |
|
| 699 | - public static function overwrite_errors() |
|
| 700 | - { |
|
| 701 | - self::$_espresso_notices['errors'] = false; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * @return void |
|
| 708 | - */ |
|
| 709 | - public static function reset_notices() |
|
| 710 | - { |
|
| 711 | - self::$_espresso_notices['success'] = false; |
|
| 712 | - self::$_espresso_notices['attention'] = false; |
|
| 713 | - self::$_espresso_notices['errors'] = false; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * @return int |
|
| 720 | - */ |
|
| 721 | - public static function has_notices() |
|
| 722 | - { |
|
| 723 | - $has_notices = 0; |
|
| 724 | - // check for success messages |
|
| 725 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
| 726 | - ? 3 |
|
| 727 | - : $has_notices; |
|
| 728 | - // check for attention messages |
|
| 729 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
| 730 | - ? 2 |
|
| 731 | - : $has_notices; |
|
| 732 | - // check for error messages |
|
| 733 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
| 734 | - ? 1 |
|
| 735 | - : $has_notices; |
|
| 736 | - return $has_notices; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | - * |
|
| 743 | - * @since 4.9.0 |
|
| 744 | - * @return array |
|
| 745 | - */ |
|
| 746 | - public static function get_vanilla_notices() |
|
| 747 | - { |
|
| 748 | - return array( |
|
| 749 | - 'success' => isset(self::$_espresso_notices['success']) |
|
| 750 | - ? self::$_espresso_notices['success'] |
|
| 751 | - : array(), |
|
| 752 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
| 753 | - ? self::$_espresso_notices['attention'] |
|
| 754 | - : array(), |
|
| 755 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
| 756 | - ? self::$_espresso_notices['errors'] |
|
| 757 | - : array(), |
|
| 758 | - ); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * @return array |
|
| 764 | - * @throws InvalidArgumentException |
|
| 765 | - * @throws InvalidDataTypeException |
|
| 766 | - * @throws InvalidInterfaceException |
|
| 767 | - */ |
|
| 768 | - public static function getStoredNotices() |
|
| 769 | - { |
|
| 770 | - if ($user_id = get_current_user_id()) { |
|
| 771 | - // get notices for logged in user |
|
| 772 | - $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
| 773 | - return is_array($notices) ? $notices : array(); |
|
| 774 | - } |
|
| 775 | - if (EE_Session::isLoadedAndActive()) { |
|
| 776 | - // get notices for user currently engaged in a session |
|
| 777 | - $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 778 | - return is_array($session_data) ? $session_data : array(); |
|
| 779 | - } |
|
| 780 | - // get global notices and hope they apply to the current site visitor |
|
| 781 | - $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 782 | - return is_array($notices) ? $notices : array(); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - /** |
|
| 787 | - * @param array $notices |
|
| 788 | - * @return bool |
|
| 789 | - * @throws InvalidArgumentException |
|
| 790 | - * @throws InvalidDataTypeException |
|
| 791 | - * @throws InvalidInterfaceException |
|
| 792 | - */ |
|
| 793 | - public static function storeNotices(array $notices) |
|
| 794 | - { |
|
| 795 | - if ($user_id = get_current_user_id()) { |
|
| 796 | - // store notices for logged in user |
|
| 797 | - return (bool) update_user_option( |
|
| 798 | - $user_id, |
|
| 799 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
| 800 | - $notices |
|
| 801 | - ); |
|
| 802 | - } |
|
| 803 | - if (EE_Session::isLoadedAndActive()) { |
|
| 804 | - // store notices for user currently engaged in a session |
|
| 805 | - return EE_Session::instance()->set_session_data( |
|
| 806 | - array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
| 807 | - ); |
|
| 808 | - } |
|
| 809 | - // store global notices and hope they apply to the same site visitor on the next request |
|
| 810 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * @return bool|TRUE |
|
| 816 | - * @throws InvalidArgumentException |
|
| 817 | - * @throws InvalidDataTypeException |
|
| 818 | - * @throws InvalidInterfaceException |
|
| 819 | - */ |
|
| 820 | - public static function clearNotices() |
|
| 821 | - { |
|
| 822 | - if ($user_id = get_current_user_id()) { |
|
| 823 | - // clear notices for logged in user |
|
| 824 | - return (bool) update_user_option( |
|
| 825 | - $user_id, |
|
| 826 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
| 827 | - array() |
|
| 828 | - ); |
|
| 829 | - } |
|
| 830 | - if (EE_Session::isLoadedAndActive()) { |
|
| 831 | - // clear notices for user currently engaged in a session |
|
| 832 | - return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 833 | - } |
|
| 834 | - // clear global notices and hope none belonged to some for some other site visitor |
|
| 835 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * saves notices to the db for retrieval on next request |
|
| 841 | - * |
|
| 842 | - * @return void |
|
| 843 | - * @throws InvalidArgumentException |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws InvalidInterfaceException |
|
| 846 | - */ |
|
| 847 | - public static function stashNoticesBeforeRedirect() |
|
| 848 | - { |
|
| 849 | - EE_Error::get_notices(false, true); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * compile all error or success messages into one string |
|
| 855 | - * |
|
| 856 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 857 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 858 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 859 | - * - ONLY do this just before redirecting |
|
| 860 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
| 861 | - * @return array |
|
| 862 | - * @throws InvalidArgumentException |
|
| 863 | - * @throws InvalidDataTypeException |
|
| 864 | - * @throws InvalidInterfaceException |
|
| 865 | - */ |
|
| 866 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 867 | - { |
|
| 868 | - $success_messages = ''; |
|
| 869 | - $attention_messages = ''; |
|
| 870 | - $error_messages = ''; |
|
| 871 | - // either save notices to the db |
|
| 872 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
| 873 | - self::$_espresso_notices = array_merge( |
|
| 874 | - EE_Error::getStoredNotices(), |
|
| 875 | - self::$_espresso_notices |
|
| 876 | - ); |
|
| 877 | - EE_Error::storeNotices(self::$_espresso_notices); |
|
| 878 | - return array(); |
|
| 879 | - } |
|
| 880 | - $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
| 881 | - // check for success messages |
|
| 882 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 883 | - // combine messages |
|
| 884 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
| 885 | - $print_scripts = true; |
|
| 886 | - } |
|
| 887 | - // check for attention messages |
|
| 888 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 889 | - // combine messages |
|
| 890 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
| 891 | - $print_scripts = true; |
|
| 892 | - } |
|
| 893 | - // check for error messages |
|
| 894 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 895 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 896 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 897 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
| 898 | - // combine messages |
|
| 899 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
| 900 | - $print_scripts = true; |
|
| 901 | - } |
|
| 902 | - if ($format_output) { |
|
| 903 | - $notices = EE_Error::formatNoticesOutput( |
|
| 904 | - $success_messages, |
|
| 905 | - $attention_messages, |
|
| 906 | - $error_messages |
|
| 907 | - ); |
|
| 908 | - } else { |
|
| 909 | - $notices = array( |
|
| 910 | - 'success' => $success_messages, |
|
| 911 | - 'attention' => $attention_messages, |
|
| 912 | - 'errors' => $error_messages, |
|
| 913 | - ); |
|
| 914 | - if ($remove_empty) { |
|
| 915 | - // remove empty notices |
|
| 916 | - foreach ($notices as $type => $notice) { |
|
| 917 | - if (empty($notice)) { |
|
| 918 | - unset($notices[$type]); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - if ($print_scripts) { |
|
| 924 | - self::_print_scripts(); |
|
| 925 | - } |
|
| 926 | - return $notices; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * @return bool |
|
| 932 | - * @throws InvalidArgumentException |
|
| 933 | - * @throws InvalidDataTypeException |
|
| 934 | - * @throws InvalidInterfaceException |
|
| 935 | - */ |
|
| 936 | - private static function combineExistingAndNewNotices() |
|
| 937 | - { |
|
| 938 | - $print_scripts = false; |
|
| 939 | - // grab any notices that have been previously saved |
|
| 940 | - $notices = EE_Error::getStoredNotices(); |
|
| 941 | - if (! empty($notices)) { |
|
| 942 | - foreach ($notices as $type => $notice) { |
|
| 943 | - if (is_array($notice) && ! empty($notice)) { |
|
| 944 | - // make sure that existing notice type is an array |
|
| 945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
| 947 | - ? self::$_espresso_notices[ $type ] |
|
| 948 | - : array(); |
|
| 949 | - // add newly created notices to existing ones |
|
| 950 | - self::$_espresso_notices[ $type ] += $notice; |
|
| 951 | - $print_scripts = true; |
|
| 952 | - } |
|
| 953 | - } |
|
| 954 | - // now clear any stored notices |
|
| 955 | - EE_Error::clearNotices(); |
|
| 956 | - } |
|
| 957 | - return $print_scripts; |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * @param string $success_messages |
|
| 963 | - * @param string $attention_messages |
|
| 964 | - * @param string $error_messages |
|
| 965 | - * @return string |
|
| 966 | - */ |
|
| 967 | - private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
| 968 | - { |
|
| 969 | - $notices = '<div id="espresso-notices">'; |
|
| 970 | - $close = is_admin() |
|
| 971 | - ? '' |
|
| 972 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
| 973 | - if ($success_messages !== '') { |
|
| 974 | - $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
| 975 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 976 | - //showMessage( $success_messages ); |
|
| 977 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 979 | - . 'style="display:none;">' |
|
| 980 | - . '<p>' . $success_messages . '</p>' |
|
| 981 | - . $close |
|
| 982 | - . '</div>'; |
|
| 983 | - } |
|
| 984 | - if ($attention_messages !== '') { |
|
| 985 | - $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
| 986 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 987 | - //showMessage( $error_messages, TRUE ); |
|
| 988 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 990 | - . 'style="display:none;">' |
|
| 991 | - . '<p>' . $attention_messages . '</p>' |
|
| 992 | - . $close |
|
| 993 | - . '</div>'; |
|
| 994 | - } |
|
| 995 | - if ($error_messages !== '') { |
|
| 996 | - $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
| 997 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 998 | - //showMessage( $error_messages, TRUE ); |
|
| 999 | - $notices .= '<div id="' . $css_id . '" ' |
|
| 1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
| 1001 | - . 'style="display:none;">' |
|
| 1002 | - . '<p>' . $error_messages . '</p>' |
|
| 1003 | - . $close |
|
| 1004 | - . '</div>'; |
|
| 1005 | - } |
|
| 1006 | - $notices .= '</div>'; |
|
| 1007 | - return $notices; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * _print_scripts |
|
| 1014 | - * |
|
| 1015 | - * @param bool $force_print |
|
| 1016 | - * @return string |
|
| 1017 | - */ |
|
| 1018 | - private static function _print_scripts($force_print = false) |
|
| 1019 | - { |
|
| 1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1021 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1022 | - return ''; |
|
| 1023 | - } |
|
| 1024 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1025 | - wp_enqueue_style('espresso_default'); |
|
| 1026 | - wp_enqueue_style('espresso_custom_css'); |
|
| 1027 | - wp_enqueue_script('ee_error_js'); |
|
| 1028 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1029 | - } |
|
| 1030 | - } else { |
|
| 1031 | - return ' |
|
| 480 | + $output .= self::_print_scripts(true); |
|
| 481 | + if (defined('DOING_AJAX')) { |
|
| 482 | + echo wp_json_encode(array('error' => $output)); |
|
| 483 | + exit(); |
|
| 484 | + } |
|
| 485 | + echo $output; |
|
| 486 | + die(); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * generate string from exception trace args |
|
| 493 | + * |
|
| 494 | + * @param array $arguments |
|
| 495 | + * @param bool $array |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
| 499 | + { |
|
| 500 | + $arg_string = ''; |
|
| 501 | + if (! empty($arguments)) { |
|
| 502 | + $args = array(); |
|
| 503 | + foreach ($arguments as $arg) { |
|
| 504 | + if (! empty($arg)) { |
|
| 505 | + if (is_string($arg)) { |
|
| 506 | + $args[] = " '" . $arg . "'"; |
|
| 507 | + } elseif (is_array($arg)) { |
|
| 508 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
| 509 | + } elseif ($arg === null) { |
|
| 510 | + $args[] = ' NULL'; |
|
| 511 | + } elseif (is_bool($arg)) { |
|
| 512 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
| 513 | + } elseif (is_object($arg)) { |
|
| 514 | + $args[] = ' OBJECT ' . get_class($arg); |
|
| 515 | + } elseif (is_resource($arg)) { |
|
| 516 | + $args[] = get_resource_type($arg); |
|
| 517 | + } else { |
|
| 518 | + $args[] = $arg; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + $arg_string = implode(', ', $args); |
|
| 523 | + } |
|
| 524 | + if ($array) { |
|
| 525 | + $arg_string .= ' )'; |
|
| 526 | + } |
|
| 527 | + return $arg_string; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * add error message |
|
| 534 | + * |
|
| 535 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 536 | + * separate messages for user || dev |
|
| 537 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 538 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 539 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 540 | + * @return void |
|
| 541 | + */ |
|
| 542 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
| 543 | + { |
|
| 544 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
| 545 | + self::$_error_count++; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
| 552 | + * adds an error |
|
| 553 | + * |
|
| 554 | + * @param string $msg |
|
| 555 | + * @param string $file |
|
| 556 | + * @param string $func |
|
| 557 | + * @param string $line |
|
| 558 | + * @throws EE_Error |
|
| 559 | + */ |
|
| 560 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
| 561 | + { |
|
| 562 | + if (WP_DEBUG) { |
|
| 563 | + throw new EE_Error($msg); |
|
| 564 | + } |
|
| 565 | + EE_Error::add_error($msg, $file, $func, $line); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * add success message |
|
| 572 | + * |
|
| 573 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 574 | + * separate messages for user || dev |
|
| 575 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 576 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 577 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 578 | + * @return void |
|
| 579 | + */ |
|
| 580 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
| 581 | + { |
|
| 582 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * add attention message |
|
| 589 | + * |
|
| 590 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
| 591 | + * separate messages for user || dev |
|
| 592 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 593 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 594 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 595 | + * @return void |
|
| 596 | + */ |
|
| 597 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
| 598 | + { |
|
| 599 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @param string $type whether the message is for a success or error notification |
|
| 606 | + * @param string $msg the message to display to users or developers |
|
| 607 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
| 608 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
| 609 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
| 610 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
| 611 | + * @return void |
|
| 612 | + */ |
|
| 613 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
| 614 | + { |
|
| 615 | + if (empty($msg)) { |
|
| 616 | + EE_Error::doing_it_wrong( |
|
| 617 | + 'EE_Error::add_' . $type . '()', |
|
| 618 | + sprintf( |
|
| 619 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
| 620 | + 'event_espresso'), |
|
| 621 | + $type, |
|
| 622 | + $file, |
|
| 623 | + $line |
|
| 624 | + ), |
|
| 625 | + EVENT_ESPRESSO_VERSION |
|
| 626 | + ); |
|
| 627 | + } |
|
| 628 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
| 629 | + EE_Error::doing_it_wrong( |
|
| 630 | + 'EE_Error::add_error()', |
|
| 631 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
| 632 | + 'event_espresso'), |
|
| 633 | + EVENT_ESPRESSO_VERSION |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + // get separate user and developer messages if they exist |
|
| 637 | + $msg = explode('||', $msg); |
|
| 638 | + $user_msg = $msg[0]; |
|
| 639 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 640 | + /** |
|
| 641 | + * Do an action so other code can be triggered when a notice is created |
|
| 642 | + * |
|
| 643 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
| 644 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
| 645 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
| 646 | + * @param string $file file where error was generated |
|
| 647 | + * @param string $func function where error was generated |
|
| 648 | + * @param string $line line where error was generated |
|
| 649 | + */ |
|
| 650 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
| 651 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 652 | + // add notice if message exists |
|
| 653 | + if (! empty($msg)) { |
|
| 654 | + // get error code |
|
| 655 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
| 656 | + if (WP_DEBUG && $type === 'errors') { |
|
| 657 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
| 658 | + } |
|
| 659 | + // add notice. Index by code if it's not blank |
|
| 660 | + if ($notice_code) { |
|
| 661 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
| 662 | + } else { |
|
| 663 | + self::$_espresso_notices[$type][] = $msg; |
|
| 664 | + } |
|
| 665 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * in some case it may be necessary to overwrite the existing success messages |
|
| 672 | + * |
|
| 673 | + * @return void |
|
| 674 | + */ |
|
| 675 | + public static function overwrite_success() |
|
| 676 | + { |
|
| 677 | + self::$_espresso_notices['success'] = false; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * in some case it may be necessary to overwrite the existing attention messages |
|
| 684 | + * |
|
| 685 | + * @return void |
|
| 686 | + */ |
|
| 687 | + public static function overwrite_attention() |
|
| 688 | + { |
|
| 689 | + self::$_espresso_notices['attention'] = false; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * in some case it may be necessary to overwrite the existing error messages |
|
| 696 | + * |
|
| 697 | + * @return void |
|
| 698 | + */ |
|
| 699 | + public static function overwrite_errors() |
|
| 700 | + { |
|
| 701 | + self::$_espresso_notices['errors'] = false; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * @return void |
|
| 708 | + */ |
|
| 709 | + public static function reset_notices() |
|
| 710 | + { |
|
| 711 | + self::$_espresso_notices['success'] = false; |
|
| 712 | + self::$_espresso_notices['attention'] = false; |
|
| 713 | + self::$_espresso_notices['errors'] = false; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * @return int |
|
| 720 | + */ |
|
| 721 | + public static function has_notices() |
|
| 722 | + { |
|
| 723 | + $has_notices = 0; |
|
| 724 | + // check for success messages |
|
| 725 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
| 726 | + ? 3 |
|
| 727 | + : $has_notices; |
|
| 728 | + // check for attention messages |
|
| 729 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
| 730 | + ? 2 |
|
| 731 | + : $has_notices; |
|
| 732 | + // check for error messages |
|
| 733 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
| 734 | + ? 1 |
|
| 735 | + : $has_notices; |
|
| 736 | + return $has_notices; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
| 742 | + * |
|
| 743 | + * @since 4.9.0 |
|
| 744 | + * @return array |
|
| 745 | + */ |
|
| 746 | + public static function get_vanilla_notices() |
|
| 747 | + { |
|
| 748 | + return array( |
|
| 749 | + 'success' => isset(self::$_espresso_notices['success']) |
|
| 750 | + ? self::$_espresso_notices['success'] |
|
| 751 | + : array(), |
|
| 752 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
| 753 | + ? self::$_espresso_notices['attention'] |
|
| 754 | + : array(), |
|
| 755 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
| 756 | + ? self::$_espresso_notices['errors'] |
|
| 757 | + : array(), |
|
| 758 | + ); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * @return array |
|
| 764 | + * @throws InvalidArgumentException |
|
| 765 | + * @throws InvalidDataTypeException |
|
| 766 | + * @throws InvalidInterfaceException |
|
| 767 | + */ |
|
| 768 | + public static function getStoredNotices() |
|
| 769 | + { |
|
| 770 | + if ($user_id = get_current_user_id()) { |
|
| 771 | + // get notices for logged in user |
|
| 772 | + $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
| 773 | + return is_array($notices) ? $notices : array(); |
|
| 774 | + } |
|
| 775 | + if (EE_Session::isLoadedAndActive()) { |
|
| 776 | + // get notices for user currently engaged in a session |
|
| 777 | + $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 778 | + return is_array($session_data) ? $session_data : array(); |
|
| 779 | + } |
|
| 780 | + // get global notices and hope they apply to the current site visitor |
|
| 781 | + $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 782 | + return is_array($notices) ? $notices : array(); |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + /** |
|
| 787 | + * @param array $notices |
|
| 788 | + * @return bool |
|
| 789 | + * @throws InvalidArgumentException |
|
| 790 | + * @throws InvalidDataTypeException |
|
| 791 | + * @throws InvalidInterfaceException |
|
| 792 | + */ |
|
| 793 | + public static function storeNotices(array $notices) |
|
| 794 | + { |
|
| 795 | + if ($user_id = get_current_user_id()) { |
|
| 796 | + // store notices for logged in user |
|
| 797 | + return (bool) update_user_option( |
|
| 798 | + $user_id, |
|
| 799 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
| 800 | + $notices |
|
| 801 | + ); |
|
| 802 | + } |
|
| 803 | + if (EE_Session::isLoadedAndActive()) { |
|
| 804 | + // store notices for user currently engaged in a session |
|
| 805 | + return EE_Session::instance()->set_session_data( |
|
| 806 | + array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
| 807 | + ); |
|
| 808 | + } |
|
| 809 | + // store global notices and hope they apply to the same site visitor on the next request |
|
| 810 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * @return bool|TRUE |
|
| 816 | + * @throws InvalidArgumentException |
|
| 817 | + * @throws InvalidDataTypeException |
|
| 818 | + * @throws InvalidInterfaceException |
|
| 819 | + */ |
|
| 820 | + public static function clearNotices() |
|
| 821 | + { |
|
| 822 | + if ($user_id = get_current_user_id()) { |
|
| 823 | + // clear notices for logged in user |
|
| 824 | + return (bool) update_user_option( |
|
| 825 | + $user_id, |
|
| 826 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
| 827 | + array() |
|
| 828 | + ); |
|
| 829 | + } |
|
| 830 | + if (EE_Session::isLoadedAndActive()) { |
|
| 831 | + // clear notices for user currently engaged in a session |
|
| 832 | + return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
| 833 | + } |
|
| 834 | + // clear global notices and hope none belonged to some for some other site visitor |
|
| 835 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * saves notices to the db for retrieval on next request |
|
| 841 | + * |
|
| 842 | + * @return void |
|
| 843 | + * @throws InvalidArgumentException |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws InvalidInterfaceException |
|
| 846 | + */ |
|
| 847 | + public static function stashNoticesBeforeRedirect() |
|
| 848 | + { |
|
| 849 | + EE_Error::get_notices(false, true); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * compile all error or success messages into one string |
|
| 855 | + * |
|
| 856 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
| 857 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
| 858 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
| 859 | + * - ONLY do this just before redirecting |
|
| 860 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
| 861 | + * @return array |
|
| 862 | + * @throws InvalidArgumentException |
|
| 863 | + * @throws InvalidDataTypeException |
|
| 864 | + * @throws InvalidInterfaceException |
|
| 865 | + */ |
|
| 866 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
| 867 | + { |
|
| 868 | + $success_messages = ''; |
|
| 869 | + $attention_messages = ''; |
|
| 870 | + $error_messages = ''; |
|
| 871 | + // either save notices to the db |
|
| 872 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
| 873 | + self::$_espresso_notices = array_merge( |
|
| 874 | + EE_Error::getStoredNotices(), |
|
| 875 | + self::$_espresso_notices |
|
| 876 | + ); |
|
| 877 | + EE_Error::storeNotices(self::$_espresso_notices); |
|
| 878 | + return array(); |
|
| 879 | + } |
|
| 880 | + $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
| 881 | + // check for success messages |
|
| 882 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
| 883 | + // combine messages |
|
| 884 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
| 885 | + $print_scripts = true; |
|
| 886 | + } |
|
| 887 | + // check for attention messages |
|
| 888 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
| 889 | + // combine messages |
|
| 890 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
| 891 | + $print_scripts = true; |
|
| 892 | + } |
|
| 893 | + // check for error messages |
|
| 894 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
| 895 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
| 896 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
| 897 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
| 898 | + // combine messages |
|
| 899 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
| 900 | + $print_scripts = true; |
|
| 901 | + } |
|
| 902 | + if ($format_output) { |
|
| 903 | + $notices = EE_Error::formatNoticesOutput( |
|
| 904 | + $success_messages, |
|
| 905 | + $attention_messages, |
|
| 906 | + $error_messages |
|
| 907 | + ); |
|
| 908 | + } else { |
|
| 909 | + $notices = array( |
|
| 910 | + 'success' => $success_messages, |
|
| 911 | + 'attention' => $attention_messages, |
|
| 912 | + 'errors' => $error_messages, |
|
| 913 | + ); |
|
| 914 | + if ($remove_empty) { |
|
| 915 | + // remove empty notices |
|
| 916 | + foreach ($notices as $type => $notice) { |
|
| 917 | + if (empty($notice)) { |
|
| 918 | + unset($notices[$type]); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + if ($print_scripts) { |
|
| 924 | + self::_print_scripts(); |
|
| 925 | + } |
|
| 926 | + return $notices; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * @return bool |
|
| 932 | + * @throws InvalidArgumentException |
|
| 933 | + * @throws InvalidDataTypeException |
|
| 934 | + * @throws InvalidInterfaceException |
|
| 935 | + */ |
|
| 936 | + private static function combineExistingAndNewNotices() |
|
| 937 | + { |
|
| 938 | + $print_scripts = false; |
|
| 939 | + // grab any notices that have been previously saved |
|
| 940 | + $notices = EE_Error::getStoredNotices(); |
|
| 941 | + if (! empty($notices)) { |
|
| 942 | + foreach ($notices as $type => $notice) { |
|
| 943 | + if (is_array($notice) && ! empty($notice)) { |
|
| 944 | + // make sure that existing notice type is an array |
|
| 945 | + self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
| 946 | + && ! empty(self::$_espresso_notices[ $type ]) |
|
| 947 | + ? self::$_espresso_notices[ $type ] |
|
| 948 | + : array(); |
|
| 949 | + // add newly created notices to existing ones |
|
| 950 | + self::$_espresso_notices[ $type ] += $notice; |
|
| 951 | + $print_scripts = true; |
|
| 952 | + } |
|
| 953 | + } |
|
| 954 | + // now clear any stored notices |
|
| 955 | + EE_Error::clearNotices(); |
|
| 956 | + } |
|
| 957 | + return $print_scripts; |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * @param string $success_messages |
|
| 963 | + * @param string $attention_messages |
|
| 964 | + * @param string $error_messages |
|
| 965 | + * @return string |
|
| 966 | + */ |
|
| 967 | + private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
| 968 | + { |
|
| 969 | + $notices = '<div id="espresso-notices">'; |
|
| 970 | + $close = is_admin() |
|
| 971 | + ? '' |
|
| 972 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
| 973 | + if ($success_messages !== '') { |
|
| 974 | + $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
| 975 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
| 976 | + //showMessage( $success_messages ); |
|
| 977 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 978 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 979 | + . 'style="display:none;">' |
|
| 980 | + . '<p>' . $success_messages . '</p>' |
|
| 981 | + . $close |
|
| 982 | + . '</div>'; |
|
| 983 | + } |
|
| 984 | + if ($attention_messages !== '') { |
|
| 985 | + $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
| 986 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
| 987 | + //showMessage( $error_messages, TRUE ); |
|
| 988 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 989 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 990 | + . 'style="display:none;">' |
|
| 991 | + . '<p>' . $attention_messages . '</p>' |
|
| 992 | + . $close |
|
| 993 | + . '</div>'; |
|
| 994 | + } |
|
| 995 | + if ($error_messages !== '') { |
|
| 996 | + $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
| 997 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
| 998 | + //showMessage( $error_messages, TRUE ); |
|
| 999 | + $notices .= '<div id="' . $css_id . '" ' |
|
| 1000 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
| 1001 | + . 'style="display:none;">' |
|
| 1002 | + . '<p>' . $error_messages . '</p>' |
|
| 1003 | + . $close |
|
| 1004 | + . '</div>'; |
|
| 1005 | + } |
|
| 1006 | + $notices .= '</div>'; |
|
| 1007 | + return $notices; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * _print_scripts |
|
| 1014 | + * |
|
| 1015 | + * @param bool $force_print |
|
| 1016 | + * @return string |
|
| 1017 | + */ |
|
| 1018 | + private static function _print_scripts($force_print = false) |
|
| 1019 | + { |
|
| 1020 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 1021 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
| 1022 | + return ''; |
|
| 1023 | + } |
|
| 1024 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
| 1025 | + wp_enqueue_style('espresso_default'); |
|
| 1026 | + wp_enqueue_style('espresso_custom_css'); |
|
| 1027 | + wp_enqueue_script('ee_error_js'); |
|
| 1028 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 1029 | + } |
|
| 1030 | + } else { |
|
| 1031 | + return ' |
|
| 1032 | 1032 | <script> |
| 1033 | 1033 | /* <![CDATA[ */ |
| 1034 | 1034 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -1038,223 +1038,223 @@ discard block |
||
| 1038 | 1038 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1039 | 1039 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
| 1040 | 1040 | '; |
| 1041 | - } |
|
| 1042 | - return ''; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function enqueue_error_scripts() |
|
| 1051 | - { |
|
| 1052 | - self::_print_scripts(); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - |
|
| 1057 | - /** |
|
| 1058 | - * create error code from filepath, function name, |
|
| 1059 | - * and line number where exception or error was thrown |
|
| 1060 | - * |
|
| 1061 | - * @param string $file |
|
| 1062 | - * @param string $func |
|
| 1063 | - * @param string $line |
|
| 1064 | - * @return string |
|
| 1065 | - */ |
|
| 1066 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1067 | - { |
|
| 1068 | - $file = explode('.', basename($file)); |
|
| 1069 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1072 | - return $error_code; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * write exception details to log file |
|
| 1079 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
| 1080 | - * |
|
| 1081 | - * @param int $time |
|
| 1082 | - * @param array $ex |
|
| 1083 | - * @param bool $clear |
|
| 1084 | - * @return void |
|
| 1085 | - */ |
|
| 1086 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1087 | - { |
|
| 1088 | - if (empty($ex)) { |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - if (! $time) { |
|
| 1092 | - $time = time(); |
|
| 1093 | - } |
|
| 1094 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1095 | - . PHP_EOL; |
|
| 1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1103 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1104 | - . PHP_EOL; |
|
| 1105 | - try { |
|
| 1106 | - error_log($exception_log); |
|
| 1107 | - } catch (EE_Error $e) { |
|
| 1108 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1109 | - 'event_espresso'), $e->getMessage())); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1117 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1118 | - * but the code execution is done in a manner that could lead to unexpected results |
|
| 1119 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1120 | - * A good test for knowing whether to use this method is: |
|
| 1121 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1122 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1123 | - * 2. If this is loaded before something else, it won't break anything, |
|
| 1124 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1125 | - * |
|
| 1126 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1127 | - * @param string $function The function that was called |
|
| 1128 | - * @param string $message A message explaining what has been done incorrectly |
|
| 1129 | - * @param string $version The version of Event Espresso where the error was added |
|
| 1130 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1131 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1132 | - * but not have any notices appear until a later version. This allows developers |
|
| 1133 | - * extra time to update their code before notices appear. |
|
| 1134 | - * @param int $error_type |
|
| 1135 | - */ |
|
| 1136 | - public static function doing_it_wrong( |
|
| 1137 | - $function, |
|
| 1138 | - $message, |
|
| 1139 | - $version, |
|
| 1140 | - $applies_when = '', |
|
| 1141 | - $error_type = null |
|
| 1142 | - ) { |
|
| 1143 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1144 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1152 | - * |
|
| 1153 | - * @return array { |
|
| 1154 | - * @type array $success all the success messages |
|
| 1155 | - * @type array $errors all the error messages |
|
| 1156 | - * @type array $attention all the attention messages |
|
| 1157 | - * } |
|
| 1158 | - */ |
|
| 1159 | - public static function get_raw_notices() |
|
| 1160 | - { |
|
| 1161 | - return self::$_espresso_notices; |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * @deprecated 4.9.27 |
|
| 1168 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1169 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1170 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 1171 | - * @return void |
|
| 1172 | - * @throws InvalidDataTypeException |
|
| 1173 | - */ |
|
| 1174 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 1175 | - { |
|
| 1176 | - new PersistentAdminNotice( |
|
| 1177 | - $pan_name, |
|
| 1178 | - $pan_message, |
|
| 1179 | - $force_update |
|
| 1180 | - ); |
|
| 1181 | - EE_Error::doing_it_wrong( |
|
| 1182 | - __METHOD__, |
|
| 1183 | - sprintf( |
|
| 1184 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1185 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
| 1186 | - ), |
|
| 1187 | - '4.9.27' |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - /** |
|
| 1194 | - * @deprecated 4.9.27 |
|
| 1195 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 1196 | - * @param bool $purge |
|
| 1197 | - * @param bool $return |
|
| 1198 | - * @throws DomainException |
|
| 1199 | - * @throws InvalidInterfaceException |
|
| 1200 | - * @throws InvalidDataTypeException |
|
| 1201 | - * @throws ServiceNotFoundException |
|
| 1202 | - * @throws InvalidArgumentException |
|
| 1203 | - */ |
|
| 1204 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
| 1205 | - { |
|
| 1206 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 1207 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 1208 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1209 | - ); |
|
| 1210 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
| 1211 | - EE_Error::doing_it_wrong( |
|
| 1212 | - __METHOD__, |
|
| 1213 | - sprintf( |
|
| 1214 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1215 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1216 | - ), |
|
| 1217 | - '4.9.27' |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * @deprecated 4.9.27 |
|
| 1225 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1226 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1227 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 1228 | - */ |
|
| 1229 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 1230 | - { |
|
| 1231 | - EE_Error::doing_it_wrong( |
|
| 1232 | - __METHOD__, |
|
| 1233 | - sprintf( |
|
| 1234 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1235 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1236 | - ), |
|
| 1237 | - '4.9.27' |
|
| 1238 | - ); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * @deprecated 4.9.27 |
|
| 1245 | - * @param string $return_url |
|
| 1246 | - */ |
|
| 1247 | - public static function get_persistent_admin_notices($return_url = '') |
|
| 1248 | - { |
|
| 1249 | - EE_Error::doing_it_wrong( |
|
| 1250 | - __METHOD__, |
|
| 1251 | - sprintf( |
|
| 1252 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1253 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1254 | - ), |
|
| 1255 | - '4.9.27' |
|
| 1256 | - ); |
|
| 1257 | - } |
|
| 1041 | + } |
|
| 1042 | + return ''; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function enqueue_error_scripts() |
|
| 1051 | + { |
|
| 1052 | + self::_print_scripts(); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + |
|
| 1057 | + /** |
|
| 1058 | + * create error code from filepath, function name, |
|
| 1059 | + * and line number where exception or error was thrown |
|
| 1060 | + * |
|
| 1061 | + * @param string $file |
|
| 1062 | + * @param string $func |
|
| 1063 | + * @param string $line |
|
| 1064 | + * @return string |
|
| 1065 | + */ |
|
| 1066 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
| 1067 | + { |
|
| 1068 | + $file = explode('.', basename($file)); |
|
| 1069 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
| 1070 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 1071 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 1072 | + return $error_code; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * write exception details to log file |
|
| 1079 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
| 1080 | + * |
|
| 1081 | + * @param int $time |
|
| 1082 | + * @param array $ex |
|
| 1083 | + * @param bool $clear |
|
| 1084 | + * @return void |
|
| 1085 | + */ |
|
| 1086 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
| 1087 | + { |
|
| 1088 | + if (empty($ex)) { |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + if (! $time) { |
|
| 1092 | + $time = time(); |
|
| 1093 | + } |
|
| 1094 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
| 1095 | + . PHP_EOL; |
|
| 1096 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 1097 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
| 1098 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
| 1099 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
| 1100 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
| 1101 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 1102 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
| 1103 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
| 1104 | + . PHP_EOL; |
|
| 1105 | + try { |
|
| 1106 | + error_log($exception_log); |
|
| 1107 | + } catch (EE_Error $e) { |
|
| 1108 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
| 1109 | + 'event_espresso'), $e->getMessage())); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
| 1117 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
| 1118 | + * but the code execution is done in a manner that could lead to unexpected results |
|
| 1119 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
| 1120 | + * A good test for knowing whether to use this method is: |
|
| 1121 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
| 1122 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
| 1123 | + * 2. If this is loaded before something else, it won't break anything, |
|
| 1124 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
| 1125 | + * |
|
| 1126 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
| 1127 | + * @param string $function The function that was called |
|
| 1128 | + * @param string $message A message explaining what has been done incorrectly |
|
| 1129 | + * @param string $version The version of Event Espresso where the error was added |
|
| 1130 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 1131 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 1132 | + * but not have any notices appear until a later version. This allows developers |
|
| 1133 | + * extra time to update their code before notices appear. |
|
| 1134 | + * @param int $error_type |
|
| 1135 | + */ |
|
| 1136 | + public static function doing_it_wrong( |
|
| 1137 | + $function, |
|
| 1138 | + $message, |
|
| 1139 | + $version, |
|
| 1140 | + $applies_when = '', |
|
| 1141 | + $error_type = null |
|
| 1142 | + ) { |
|
| 1143 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 1144 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
| 1152 | + * |
|
| 1153 | + * @return array { |
|
| 1154 | + * @type array $success all the success messages |
|
| 1155 | + * @type array $errors all the error messages |
|
| 1156 | + * @type array $attention all the attention messages |
|
| 1157 | + * } |
|
| 1158 | + */ |
|
| 1159 | + public static function get_raw_notices() |
|
| 1160 | + { |
|
| 1161 | + return self::$_espresso_notices; |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * @deprecated 4.9.27 |
|
| 1168 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1169 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1170 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
| 1171 | + * @return void |
|
| 1172 | + * @throws InvalidDataTypeException |
|
| 1173 | + */ |
|
| 1174 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
| 1175 | + { |
|
| 1176 | + new PersistentAdminNotice( |
|
| 1177 | + $pan_name, |
|
| 1178 | + $pan_message, |
|
| 1179 | + $force_update |
|
| 1180 | + ); |
|
| 1181 | + EE_Error::doing_it_wrong( |
|
| 1182 | + __METHOD__, |
|
| 1183 | + sprintf( |
|
| 1184 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1185 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
| 1186 | + ), |
|
| 1187 | + '4.9.27' |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + /** |
|
| 1194 | + * @deprecated 4.9.27 |
|
| 1195 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
| 1196 | + * @param bool $purge |
|
| 1197 | + * @param bool $return |
|
| 1198 | + * @throws DomainException |
|
| 1199 | + * @throws InvalidInterfaceException |
|
| 1200 | + * @throws InvalidDataTypeException |
|
| 1201 | + * @throws ServiceNotFoundException |
|
| 1202 | + * @throws InvalidArgumentException |
|
| 1203 | + */ |
|
| 1204 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
| 1205 | + { |
|
| 1206 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 1207 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 1208 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1209 | + ); |
|
| 1210 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
| 1211 | + EE_Error::doing_it_wrong( |
|
| 1212 | + __METHOD__, |
|
| 1213 | + sprintf( |
|
| 1214 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1215 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1216 | + ), |
|
| 1217 | + '4.9.27' |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * @deprecated 4.9.27 |
|
| 1225 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
| 1226 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
| 1227 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
| 1228 | + */ |
|
| 1229 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
| 1230 | + { |
|
| 1231 | + EE_Error::doing_it_wrong( |
|
| 1232 | + __METHOD__, |
|
| 1233 | + sprintf( |
|
| 1234 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1235 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1236 | + ), |
|
| 1237 | + '4.9.27' |
|
| 1238 | + ); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * @deprecated 4.9.27 |
|
| 1245 | + * @param string $return_url |
|
| 1246 | + */ |
|
| 1247 | + public static function get_persistent_admin_notices($return_url = '') |
|
| 1248 | + { |
|
| 1249 | + EE_Error::doing_it_wrong( |
|
| 1250 | + __METHOD__, |
|
| 1251 | + sprintf( |
|
| 1252 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1253 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 1254 | + ), |
|
| 1255 | + '4.9.27' |
|
| 1256 | + ); |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | 1259 | |
| 1260 | 1260 | |
@@ -1269,27 +1269,27 @@ discard block |
||
| 1269 | 1269 | */ |
| 1270 | 1270 | function espresso_error_enqueue_scripts() |
| 1271 | 1271 | { |
| 1272 | - // js for error handling |
|
| 1273 | - wp_register_script( |
|
| 1274 | - 'espresso_core', |
|
| 1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1276 | - array('jquery'), |
|
| 1277 | - EVENT_ESPRESSO_VERSION, |
|
| 1278 | - false |
|
| 1279 | - ); |
|
| 1280 | - wp_register_script( |
|
| 1281 | - 'ee_error_js', |
|
| 1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1283 | - array('espresso_core'), |
|
| 1284 | - EVENT_ESPRESSO_VERSION, |
|
| 1285 | - false |
|
| 1286 | - ); |
|
| 1272 | + // js for error handling |
|
| 1273 | + wp_register_script( |
|
| 1274 | + 'espresso_core', |
|
| 1275 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 1276 | + array('jquery'), |
|
| 1277 | + EVENT_ESPRESSO_VERSION, |
|
| 1278 | + false |
|
| 1279 | + ); |
|
| 1280 | + wp_register_script( |
|
| 1281 | + 'ee_error_js', |
|
| 1282 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
| 1283 | + array('espresso_core'), |
|
| 1284 | + EVENT_ESPRESSO_VERSION, |
|
| 1285 | + false |
|
| 1286 | + ); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | if (is_admin()) { |
| 1290 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1290 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1291 | 1291 | } else { |
| 1292 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1292 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | |