@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @return void |
290 | 290 | */ |
291 | 291 | public function enqueue_scripts_styles() { |
292 | - do_action( 'AHEE__EE_messenger__enqueue_scripts_styles'); |
|
292 | + do_action('AHEE__EE_messenger__enqueue_scripts_styles'); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | |
326 | 326 | $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.'); |
327 | 327 | |
328 | - $this->_supports_labels = apply_filters( 'FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this ); |
|
328 | + $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | * @return stdClass |
341 | 341 | */ |
342 | 342 | public function get_supports_labels() { |
343 | - if ( empty( $this->_supports_labels->template_pack ) || empty( $this->_supports_labels->template_variation) ) { |
|
343 | + if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) { |
|
344 | 344 | $this->_set_supports_labels_defaults(); |
345 | 345 | } |
346 | - return apply_filters( 'FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this ); |
|
346 | + return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | |
@@ -363,10 +363,10 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return string path or url for the requested variation. |
365 | 365 | */ |
366 | - public function get_variation( EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE ) { |
|
366 | + public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE) { |
|
367 | 367 | $this->_tmp_pack = $pack; |
368 | - $variation_path = apply_filters( 'EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters ); |
|
369 | - $variation_path = empty( $variation_path ) ? $this->_tmp_pack->get_variation( $this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters ) : $variation_path; |
|
368 | + $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters); |
|
369 | + $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path; |
|
370 | 370 | return $variation_path; |
371 | 371 | |
372 | 372 | } |
@@ -384,13 +384,13 @@ discard block |
||
384 | 384 | * @return array |
385 | 385 | */ |
386 | 386 | public function get_default_message_types() { |
387 | - $class = get_class( $this ); |
|
387 | + $class = get_class($this); |
|
388 | 388 | |
389 | 389 | //messenger specific filter |
390 | - $default_types = apply_filters( 'FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this ); |
|
390 | + $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this); |
|
391 | 391 | |
392 | 392 | //all messengers filter |
393 | - $default_types = apply_filters( 'FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this ); |
|
393 | + $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); |
|
394 | 394 | return $default_types; |
395 | 395 | } |
396 | 396 | |
@@ -405,14 +405,14 @@ discard block |
||
405 | 405 | * @return array |
406 | 406 | */ |
407 | 407 | public function get_valid_message_types() { |
408 | - $class = get_class( $this ); |
|
408 | + $class = get_class($this); |
|
409 | 409 | |
410 | 410 | //messenger specific filter |
411 | 411 | //messenger specific filter |
412 | - $valid_types = apply_filters( 'FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this ); |
|
412 | + $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this); |
|
413 | 413 | |
414 | 414 | //all messengers filter |
415 | - $valid_types = apply_filters( 'FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this ); |
|
415 | + $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); |
|
416 | 416 | return $valid_types; |
417 | 417 | } |
418 | 418 | |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @access public |
427 | 427 | * @param array $new_config Whatever is put in here will reset the _validator_config property |
428 | 428 | */ |
429 | - public function set_validator_config( $new_config ) { |
|
429 | + public function set_validator_config($new_config) { |
|
430 | 430 | $this->_validator_config = $new_config; |
431 | 431 | } |
432 | 432 | |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | public function get_validator_config() { |
443 | 443 | $class = get_class($this); |
444 | 444 | |
445 | - $config = apply_filters( 'FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this ); |
|
446 | - $config = apply_filters( 'FHEE__EE_messenger__get_validator_config', $config, $this ); |
|
445 | + $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this); |
|
446 | + $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); |
|
447 | 447 | return $config; |
448 | 448 | } |
449 | 449 | |
@@ -460,8 +460,8 @@ discard block |
||
460 | 460 | * @access public |
461 | 461 | * @return string content for page |
462 | 462 | */ |
463 | - public function get_messenger_admin_page_content( $page, $action = null, $extra = array(), $message_types = array() ) { |
|
464 | - return $this->_get_admin_page_content( $page, $action, $extra, $message_types ); |
|
463 | + public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array()) { |
|
464 | + return $this->_get_admin_page_content($page, $action, $extra, $message_types); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | |
@@ -470,76 +470,76 @@ discard block |
||
470 | 470 | |
471 | 471 | |
472 | 472 | |
473 | - protected function _get_admin_content_events_edit( $message_types, $extra ) { |
|
473 | + protected function _get_admin_content_events_edit($message_types, $extra) { |
|
474 | 474 | //defaults |
475 | 475 | $template_args = array(); |
476 | 476 | $custom_templates = array(); |
477 | 477 | $selector_rows = ''; |
478 | 478 | |
479 | 479 | //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. |
480 | - $event_id = isset( $extra['event'] ) ? $extra['event'] : NULL; |
|
480 | + $event_id = isset($extra['event']) ? $extra['event'] : NULL; |
|
481 | 481 | |
482 | - $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
483 | - $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
482 | + $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
483 | + $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
484 | 484 | |
485 | 485 | //array of template objects for global and custom (non-trashed) (but remember just for this messenger!) |
486 | - $global_templates = EEM_Message_Template_Group::instance()->get_all( array( array('MTP_messenger' => $this->name, 'MTP_is_global' => TRUE, 'MTP_is_active' => TRUE ) ) ); |
|
487 | - $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event( $event_id, array( 'MTP_messenger' => $this->name, 'MTP_is_active' => TRUE ) ); |
|
488 | - $templates_for_event = !empty( $templates_for_event ) ? $templates_for_event : array(); |
|
486 | + $global_templates = EEM_Message_Template_Group::instance()->get_all(array(array('MTP_messenger' => $this->name, 'MTP_is_global' => TRUE, 'MTP_is_active' => TRUE))); |
|
487 | + $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event($event_id, array('MTP_messenger' => $this->name, 'MTP_is_active' => TRUE)); |
|
488 | + $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array(); |
|
489 | 489 | |
490 | 490 | //so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups) |
491 | - foreach ( $global_templates as $mtpgID => $mtpg ) { |
|
491 | + foreach ($global_templates as $mtpgID => $mtpg) { |
|
492 | 492 | //verify this message type is supposed to show on this page |
493 | 493 | $mtp_obj = $mtpg->message_type_obj(); |
494 | - if ( ! $mtp_obj instanceof EE_message_type ) { |
|
494 | + if ( ! $mtp_obj instanceof EE_message_type) { |
|
495 | 495 | continue; |
496 | 496 | } |
497 | 497 | $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages; |
498 | - if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) ) |
|
498 | + if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) |
|
499 | 499 | continue; |
500 | 500 | $stargs = array(); |
501 | 501 | $default_value = ''; |
502 | 502 | $select_values = array(); |
503 | 503 | $select_values[$mtpgID] = __('Global', 'event_espresso'); |
504 | - $default_value = array_key_exists( $mtpgID, $templates_for_event ) && ! $mtpg->get('MTP_is_override' ) ? $mtpgID : NULL; |
|
504 | + $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : NULL; |
|
505 | 505 | |
506 | 506 | //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. |
507 | 507 | |
508 | - if ( ! $mtpg->get('MTP_is_override' ) ) { |
|
508 | + if ( ! $mtpg->get('MTP_is_override')) { |
|
509 | 509 | //any custom templates for this message type? |
510 | - $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt( $this->name, $mtpg->message_type() ); |
|
510 | + $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type()); |
|
511 | 511 | |
512 | - foreach( $custom_templates as $cmtpgID => $cmtpg ) { |
|
512 | + foreach ($custom_templates as $cmtpgID => $cmtpg) { |
|
513 | 513 | $select_values[$cmtpgID] = $cmtpg->name(); |
514 | - $default_value = array_key_exists( $cmtpgID, $templates_for_event ) ? $cmtpgID : $default_value; |
|
514 | + $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value; |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
518 | 518 | //if there is no $default_value then we set it as the global |
519 | - $default_value = empty( $default_value ) ? $mtpgID : $default_value; |
|
519 | + $default_value = empty($default_value) ? $mtpgID : $default_value; |
|
520 | 520 | |
521 | - $edit_url = EEH_URL::add_query_args_and_nonce( array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php') ); |
|
522 | - $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' ) ); |
|
521 | + $edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php')); |
|
522 | + $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')); |
|
523 | 523 | |
524 | - $st_args['mt_name'] = ucwords( $mtp_obj->label['singular'] ); |
|
524 | + $st_args['mt_name'] = ucwords($mtp_obj->label['singular']); |
|
525 | 525 | $st_args['mt_slug'] = $mtpg->message_type(); |
526 | 526 | $st_args['messenger_slug'] = $this->name; |
527 | - $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' ); |
|
527 | + $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'); |
|
528 | 528 | |
529 | 529 | //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). |
530 | - $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>'; |
|
531 | - $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_messages', 'espresso_messsages_add_new_message_template' ) ? $st_args['create_button'] : ''; |
|
532 | - $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>' : ''; |
|
533 | - $selector_rows .= EEH_Template::display_template( $template_row_path, $st_args, TRUE ); |
|
530 | + $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>'; |
|
531 | + $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messsages_add_new_message_template') ? $st_args['create_button'] : ''; |
|
532 | + $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>' : ''; |
|
533 | + $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, TRUE); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | //if no selectors present then get out. |
537 | - if ( empty( $selector_rows ) ) { |
|
537 | + if (empty($selector_rows)) { |
|
538 | 538 | return ''; |
539 | 539 | } |
540 | 540 | |
541 | 541 | $template_args['selector_rows'] = $selector_rows; |
542 | - return EEH_Template::display_template( $template_wrapper_path, $template_args, TRUE ); |
|
542 | + return EEH_Template::display_template($template_wrapper_path, $template_args, TRUE); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | * @return array $this->_template_fields |
555 | 555 | */ |
556 | 556 | public function get_template_fields() { |
557 | - $template_fields = apply_filters( 'FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this ); |
|
558 | - $template_fields = apply_filters( 'FHEE__EE_messenger__get_template_fields', $template_fields, $this ); |
|
557 | + $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this); |
|
558 | + $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this); |
|
559 | 559 | return $template_fields; |
560 | 560 | } |
561 | 561 | |
@@ -568,9 +568,9 @@ discard block |
||
568 | 568 | * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger |
569 | 569 | */ |
570 | 570 | protected function _set_template_value($item, $value) { |
571 | - if ( array_key_exists($item, $this->_template_fields) ) { |
|
572 | - $prop = '_' . $item; |
|
573 | - $this->{$prop}= $value; |
|
571 | + if (array_key_exists($item, $this->_template_fields)) { |
|
572 | + $prop = '_'.$item; |
|
573 | + $this->{$prop} = $value; |
|
574 | 574 | } |
575 | 575 | } |
576 | 576 | |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message. |
581 | 581 | * @return bool | WP_Error |
582 | 582 | */ |
583 | - public function send_message( $message, EE_message_type $message_type ) { |
|
584 | - $this->_validate_and_setup( $message ); |
|
583 | + public function send_message($message, EE_message_type $message_type) { |
|
584 | + $this->_validate_and_setup($message); |
|
585 | 585 | $this->_incoming_message_type = $message_type; |
586 | 586 | return $this->_send_message(); |
587 | 587 | } |
@@ -595,28 +595,28 @@ discard block |
||
595 | 595 | * @param bool $send true we will actually use the _send method (for test sends). FALSE we just return preview |
596 | 596 | * @return string return the message html content |
597 | 597 | */ |
598 | - public function get_preview( $message, EE_message_type $message_type, $send = FALSE ) { |
|
599 | - $this->_validate_and_setup( $message ); |
|
598 | + public function get_preview($message, EE_message_type $message_type, $send = FALSE) { |
|
599 | + $this->_validate_and_setup($message); |
|
600 | 600 | |
601 | 601 | $this->_incoming_message_type = $message_type; |
602 | 602 | |
603 | - if ( $send ) { |
|
603 | + if ($send) { |
|
604 | 604 | //are we overriding any existing template fields? |
605 | 605 | $settings = $this->get_existing_test_settings(); |
606 | - if ( !empty( $settings ) ) { |
|
607 | - foreach( $settings as $field => $value ) { |
|
608 | - $this->_set_template_value( $field, $value ); |
|
606 | + if ( ! empty($settings)) { |
|
607 | + foreach ($settings as $field => $value) { |
|
608 | + $this->_set_template_value($field, $value); |
|
609 | 609 | } |
610 | 610 | } |
611 | 611 | } |
612 | 612 | |
613 | 613 | //enqueue preview js so that any links/buttons on the page are disabled. |
614 | - if ( ! $send ) { |
|
614 | + if ( ! $send) { |
|
615 | 615 | // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles, |
616 | 616 | // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup. |
617 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10 ); |
|
618 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10 ); |
|
619 | - add_action( 'AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10 ); |
|
617 | + add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10); |
|
618 | + add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10); |
|
619 | + add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | return $send ? $this->_send_message() : $this->_preview(); |
@@ -634,10 +634,10 @@ discard block |
||
634 | 634 | */ |
635 | 635 | public function add_preview_script() { |
636 | 636 | //error message |
637 | - 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' ); |
|
638 | - wp_register_script( 'ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true ); |
|
639 | - wp_localize_script( 'ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings ); |
|
640 | - wp_enqueue_script( 'ee-messages-preview-js' ); |
|
637 | + 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'); |
|
638 | + wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
639 | + wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); |
|
640 | + wp_enqueue_script('ee-messages-preview-js'); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | |
@@ -647,23 +647,23 @@ discard block |
||
647 | 647 | * @param object $message message object |
648 | 648 | * @throws \EE_Error |
649 | 649 | */ |
650 | - protected function _validate_and_setup( $message ) { |
|
651 | - if ( !is_object( $message ) ) |
|
652 | - throw new EE_Error( __('Incoming "$message" must be an object', 'event_espresso' ) ); |
|
650 | + protected function _validate_and_setup($message) { |
|
651 | + if ( ! is_object($message)) |
|
652 | + throw new EE_Error(__('Incoming "$message" must be an object', 'event_espresso')); |
|
653 | 653 | |
654 | 654 | //verify we have the required template pack value on the $message object. |
655 | - if ( empty( $message->template_pack ) || ! $message->template_pack instanceof EE_Messages_Template_Pack ) { |
|
656 | - throw new EE_Error( __('Incoming $message object must have a EE_Messages_Template_Pack object assigned to the template_pack property', 'event_espresso' ) ); |
|
655 | + if (empty($message->template_pack) || ! $message->template_pack instanceof EE_Messages_Template_Pack) { |
|
656 | + throw new EE_Error(__('Incoming $message object must have a EE_Messages_Template_Pack object assigned to the template_pack property', 'event_espresso')); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | $this->_tmp_pack = $message->template_pack; |
660 | 660 | |
661 | - $this->_variation = !empty ( $message->variation ) ? $message->variation : 'default'; |
|
661 | + $this->_variation = ! empty ($message->variation) ? $message->variation : 'default'; |
|
662 | 662 | |
663 | 663 | $template_fields = $this->get_template_fields(); |
664 | 664 | |
665 | - foreach ( $template_fields as $template => $value ) { |
|
666 | - if ( $template !== 'extra' ) |
|
665 | + foreach ($template_fields as $template => $value) { |
|
666 | + if ($template !== 'extra') |
|
667 | 667 | $this->_set_template_value($template, $message->{$template}); |
668 | 668 | } |
669 | 669 | } |
@@ -678,21 +678,21 @@ discard block |
||
678 | 678 | * @return string |
679 | 679 | * @throws \EE_Error |
680 | 680 | */ |
681 | - protected function _get_main_template( $preview = FALSE ) { |
|
681 | + protected function _get_main_template($preview = FALSE) { |
|
682 | 682 | $type = $preview ? 'preview' : 'main'; |
683 | 683 | |
684 | - $wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type ); |
|
684 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type); |
|
685 | 685 | |
686 | 686 | //check file exists and is readable |
687 | - if ( !is_readable( $wrapper_template ) ) |
|
688 | - 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 ) ); |
|
687 | + if ( ! is_readable($wrapper_template)) |
|
688 | + 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)); |
|
689 | 689 | |
690 | 690 | //add message type to template args |
691 | 691 | $this->_template_args['message_type'] = $this->_incoming_message_type; |
692 | 692 | |
693 | 693 | //require template helper |
694 | - EE_Registry::instance()->load_helper( 'Template' ); |
|
695 | - return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE ); |
|
694 | + EE_Registry::instance()->load_helper('Template'); |
|
695 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | */ |
729 | 729 | public function get_existing_test_settings() { |
730 | 730 | $settings = EEH_MSG_Template::get_active_messengers_in_db(); |
731 | - return isset( $settings[$this->name]['test_settings'] ) ? $settings[$this->name]['test_settings'] : array(); |
|
731 | + return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array(); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | |
@@ -739,10 +739,10 @@ discard block |
||
739 | 739 | * @access public |
740 | 740 | * @return bool success/fail |
741 | 741 | */ |
742 | - public function set_existing_test_settings( $settings ) { |
|
742 | + public function set_existing_test_settings($settings) { |
|
743 | 743 | $existing = EEH_MSG_Template::get_active_messengers_in_db(); |
744 | 744 | $existing[$this->name]['test_settings'] = $settings; |
745 | - return EEH_MSG_Template::update_active_messengers_in_db( $existing ); |
|
745 | + return EEH_MSG_Template::update_active_messengers_in_db($existing); |
|
746 | 746 | } |
747 | 747 | |
748 | 748 | |
@@ -755,21 +755,21 @@ discard block |
||
755 | 755 | * @param string $field The field to retrieve the label for |
756 | 756 | * @return string The label |
757 | 757 | */ |
758 | - public function get_field_label( $field ) { |
|
758 | + public function get_field_label($field) { |
|
759 | 759 | //first let's see if the field requests is in the top level array. |
760 | - if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) |
|
760 | + if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) |
|
761 | 761 | return $this->_template[$field]['label']; |
762 | 762 | |
763 | 763 | //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. |
764 | - if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] ) ) |
|
764 | + if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) |
|
765 | 765 | return $this->_template_fields['extra'][$field]['main']['label']; |
766 | 766 | |
767 | 767 | //now it's possible this field may just be existing in any of the extra array items. |
768 | - if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) { |
|
769 | - foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) { |
|
770 | - if ( !is_array( $subfields ) ) |
|
768 | + if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { |
|
769 | + foreach ($this->_template_fields['extra'] as $main_field => $subfields) { |
|
770 | + if ( ! is_array($subfields)) |
|
771 | 771 | continue; |
772 | - if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) |
|
772 | + if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) |
|
773 | 773 | return $subfields[$field]['label']; |
774 | 774 | } |
775 | 775 | } |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | * |
791 | 791 | * @return void |
792 | 792 | */ |
793 | - public function do_secondary_messenger_hooks( $sending_messenger_name ) { |
|
793 | + public function do_secondary_messenger_hooks($sending_messenger_name) { |
|
794 | 794 | return; |
795 | 795 | } |
796 | 796 |
@@ -1,6 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | +} |
|
4 | 5 | |
5 | 6 | /** |
6 | 7 | * Event Espresso |
@@ -495,8 +496,9 @@ discard block |
||
495 | 496 | continue; |
496 | 497 | } |
497 | 498 | $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages; |
498 | - if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) ) |
|
499 | - continue; |
|
499 | + if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) ) { |
|
500 | + continue; |
|
501 | + } |
|
500 | 502 | $stargs = array(); |
501 | 503 | $default_value = ''; |
502 | 504 | $select_values = array(); |
@@ -648,8 +650,9 @@ discard block |
||
648 | 650 | * @throws \EE_Error |
649 | 651 | */ |
650 | 652 | protected function _validate_and_setup( $message ) { |
651 | - if ( !is_object( $message ) ) |
|
652 | - throw new EE_Error( __('Incoming "$message" must be an object', 'event_espresso' ) ); |
|
653 | + if ( !is_object( $message ) ) { |
|
654 | + throw new EE_Error( __('Incoming "$message" must be an object', 'event_espresso' ) ); |
|
655 | + } |
|
653 | 656 | |
654 | 657 | //verify we have the required template pack value on the $message object. |
655 | 658 | if ( empty( $message->template_pack ) || ! $message->template_pack instanceof EE_Messages_Template_Pack ) { |
@@ -663,8 +666,9 @@ discard block |
||
663 | 666 | $template_fields = $this->get_template_fields(); |
664 | 667 | |
665 | 668 | foreach ( $template_fields as $template => $value ) { |
666 | - if ( $template !== 'extra' ) |
|
667 | - $this->_set_template_value($template, $message->{$template}); |
|
669 | + if ( $template !== 'extra' ) { |
|
670 | + $this->_set_template_value($template, $message->{$template}); |
|
671 | + } |
|
668 | 672 | } |
669 | 673 | } |
670 | 674 | |
@@ -684,8 +688,9 @@ discard block |
||
684 | 688 | $wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type ); |
685 | 689 | |
686 | 690 | //check file exists and is readable |
687 | - if ( !is_readable( $wrapper_template ) ) |
|
688 | - 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 ) ); |
|
691 | + if ( !is_readable( $wrapper_template ) ) { |
|
692 | + 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 ) ); |
|
693 | + } |
|
689 | 694 | |
690 | 695 | //add message type to template args |
691 | 696 | $this->_template_args['message_type'] = $this->_incoming_message_type; |
@@ -757,20 +762,24 @@ discard block |
||
757 | 762 | */ |
758 | 763 | public function get_field_label( $field ) { |
759 | 764 | //first let's see if the field requests is in the top level array. |
760 | - if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) |
|
761 | - return $this->_template[$field]['label']; |
|
765 | + if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) { |
|
766 | + return $this->_template[$field]['label']; |
|
767 | + } |
|
762 | 768 | |
763 | 769 | //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. |
764 | - if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] ) ) |
|
765 | - return $this->_template_fields['extra'][$field]['main']['label']; |
|
770 | + if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] ) ) { |
|
771 | + return $this->_template_fields['extra'][$field]['main']['label']; |
|
772 | + } |
|
766 | 773 | |
767 | 774 | //now it's possible this field may just be existing in any of the extra array items. |
768 | 775 | if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) { |
769 | 776 | foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) { |
770 | - if ( !is_array( $subfields ) ) |
|
771 | - continue; |
|
772 | - if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) |
|
773 | - return $subfields[$field]['label']; |
|
777 | + if ( !is_array( $subfields ) ) { |
|
778 | + continue; |
|
779 | + } |
|
780 | + if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) { |
|
781 | + return $subfields[$field]['label']; |
|
782 | + } |
|
774 | 783 | } |
775 | 784 | } |
776 | 785 |
@@ -1,7 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
3 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | +} |
|
5 | 6 | |
6 | 7 | /** |
7 | 8 | * Event Espresso |
@@ -166,8 +167,9 @@ discard block |
||
166 | 167 | protected function _set_properties() { |
167 | 168 | |
168 | 169 | foreach ( $this->_data as $prop => $value ) { |
169 | - if( EEH_Class_Tools::has_property( $this, $prop ) ) |
|
170 | - $this->{$prop} = $value; |
|
170 | + if( EEH_Class_Tools::has_property( $this, $prop ) ) { |
|
171 | + $this->{$prop} = $value; |
|
172 | + } |
|
171 | 173 | } |
172 | 174 | |
173 | 175 | //if user_id present we'll use this to set the fname and lname and admin_email. |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public static function instance() { |
37 | 37 | // check if class object is instantiated, and instantiated properly |
38 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager ) { |
|
38 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
39 | 39 | self::$_instance = new self(); |
40 | 40 | } |
41 | 41 | EE_Registry::instance()->load_lib('PMT_Base'); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * Resets the instance and returns a new one |
47 | 47 | * @return EE_Payment_Method_Manager |
48 | 48 | */ |
49 | - public static function reset(){ |
|
49 | + public static function reset() { |
|
50 | 50 | self::$_instance = NULL; |
51 | 51 | return self::instance(); |
52 | 52 | } |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * or just re-use the PMTs we found last time we checked during this request (if |
58 | 58 | * we have not yet checked during this request, then we need to check anyways) |
59 | 59 | */ |
60 | - public function maybe_register_payment_methods( $force_recheck = FALSE ){ |
|
61 | - if( ! $this->_payment_method_types || $force_recheck ){ |
|
60 | + public function maybe_register_payment_methods($force_recheck = FALSE) { |
|
61 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
62 | 62 | $this->_register_payment_methods(); |
63 | 63 | //if in admin lets ensure caps are set. |
64 | - if ( is_admin() ) { |
|
65 | - add_filter( 'FHEE__EE_Capabilities__init_caps_map__caps', array( $this, 'add_payment_method_caps' ) ); |
|
64 | + if (is_admin()) { |
|
65 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
66 | 66 | EE_Registry::instance()->CAP->init_caps(); |
67 | 67 | } |
68 | 68 | } |
@@ -75,19 +75,19 @@ discard block |
||
75 | 75 | */ |
76 | 76 | protected function _register_payment_methods() { |
77 | 77 | // grab list of installed modules |
78 | - $pm_to_register = glob( EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR ); |
|
78 | + $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
79 | 79 | // filter list of modules to register |
80 | - $pm_to_register = apply_filters( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', $pm_to_register ); |
|
80 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', $pm_to_register); |
|
81 | 81 | |
82 | 82 | // loop through folders |
83 | - foreach ( $pm_to_register as $pm_path ) { |
|
84 | - $this->register_payment_method( $pm_path ); |
|
83 | + foreach ($pm_to_register as $pm_path) { |
|
84 | + $this->register_payment_method($pm_path); |
|
85 | 85 | } |
86 | - do_action( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods' ); |
|
86 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
87 | 87 | // filter list of installed modules |
88 | 88 | //keep them organized alphabetically by the payment method type's name |
89 | - ksort( $this->_payment_method_types ); |
|
90 | - return apply_filters( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', $this->_payment_method_types ); |
|
89 | + ksort($this->_payment_method_types); |
|
90 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', $this->_payment_method_types); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -99,35 +99,35 @@ discard block |
||
99 | 99 | * @param string $payment_method_path - full path up to and including payment method folder |
100 | 100 | * @return boolean |
101 | 101 | */ |
102 | - public function register_payment_method( $payment_method_path = '' ) { |
|
103 | - do_action( 'AHEE__EE_Payment_Method_Manager__register_payment_method__begin',$payment_method_path ); |
|
102 | + public function register_payment_method($payment_method_path = '') { |
|
103 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
104 | 104 | $module_ext = '.pm.php'; |
105 | 105 | // make all separators match |
106 | - $payment_method_path = rtrim( str_replace( '/\\', DS, $payment_method_path ), DS ); |
|
106 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
107 | 107 | // grab and sanitize module name |
108 | - $module_dir = basename( $payment_method_path ); |
|
108 | + $module_dir = basename($payment_method_path); |
|
109 | 109 | // create classname from module directory name |
110 | - $module = str_replace( ' ', '_', str_replace( '_', ' ', $module_dir )); |
|
110 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
111 | 111 | // add class prefix |
112 | - $module_class = 'EE_PMT_' . $module; |
|
112 | + $module_class = 'EE_PMT_'.$module; |
|
113 | 113 | // does the module exist ? |
114 | - if ( ! is_readable( $payment_method_path . DS . $module_class . $module_ext )) { |
|
115 | - $msg = sprintf( __( 'The requested %s payment method file could not be found or is not readable due to file permissions.', 'event_espresso' ), $module ); |
|
116 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
114 | + if ( ! is_readable($payment_method_path.DS.$module_class.$module_ext)) { |
|
115 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', 'event_espresso'), $module); |
|
116 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
117 | 117 | return FALSE; |
118 | 118 | } |
119 | - if ( WP_DEBUG === TRUE ) { EEH_Debug_Tools::instance()->start_timer(); } |
|
119 | + if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->start_timer(); } |
|
120 | 120 | // load the module class file |
121 | - require_once( $payment_method_path . DS . $module_class . $module_ext ); |
|
122 | - if ( WP_DEBUG === TRUE ) { EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); } |
|
121 | + require_once($payment_method_path.DS.$module_class.$module_ext); |
|
122 | + if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); } |
|
123 | 123 | // verify that class exists |
124 | - if ( ! class_exists( $module_class )) { |
|
125 | - $msg = sprintf( __( 'The requested %s module class does not exist.', 'event_espresso' ), $module_class ); |
|
126 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
124 | + if ( ! class_exists($module_class)) { |
|
125 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
126 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
127 | 127 | return FALSE; |
128 | 128 | } |
129 | 129 | // add to array of registered modules |
130 | - $this->_payment_method_types[ $module ] = $payment_method_path . DS . $module_class . $module_ext; |
|
130 | + $this->_payment_method_types[$module] = $payment_method_path.DS.$module_class.$module_ext; |
|
131 | 131 | return TRUE; |
132 | 132 | } |
133 | 133 | /** |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | * @param boolean $force_recheck whether to force re-checking for new payment method types |
137 | 137 | * @return boolean |
138 | 138 | */ |
139 | - public function payment_method_type_exists($payment_method_name, $force_recheck = FALSE){ |
|
140 | - if ( ! is_array( $this->_payment_method_types ) || ! isset( $this->_payment_method_types[$payment_method_name] ) |
|
141 | - || $force_recheck ) { |
|
139 | + public function payment_method_type_exists($payment_method_name, $force_recheck = FALSE) { |
|
140 | + if ( ! is_array($this->_payment_method_types) || ! isset($this->_payment_method_types[$payment_method_name]) |
|
141 | + || $force_recheck) { |
|
142 | 142 | $this->maybe_register_payment_methods($force_recheck); |
143 | 143 | } |
144 | - if(isset($this->_payment_method_types[$payment_method_name])){ |
|
144 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
145 | 145 | require_once($this->_payment_method_types[$payment_method_name]); |
146 | 146 | return true; |
147 | - }else{ |
|
147 | + } else { |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | } |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | * @param boolean $force_recheck whether to force re-checking for new payment method types |
156 | 156 | * @return array |
157 | 157 | */ |
158 | - public function payment_method_type_names($with_prefixes = FALSE, $force_recheck = FALSE ){ |
|
158 | + public function payment_method_type_names($with_prefixes = FALSE, $force_recheck = FALSE) { |
|
159 | 159 | $this->maybe_register_payment_methods($force_recheck); |
160 | - if($with_prefixes){ |
|
160 | + if ($with_prefixes) { |
|
161 | 161 | $classnames = array_keys($this->_payment_method_types); |
162 | 162 | $payment_methods = array(); |
163 | - foreach($classnames as $classname){ |
|
163 | + foreach ($classnames as $classname) { |
|
164 | 164 | $payment_methods[] = $this->payment_method_class_from_type($classname); |
165 | 165 | } |
166 | 166 | return $payment_methods; |
167 | - }else{ |
|
167 | + } else { |
|
168 | 168 | return array_keys($this->_payment_method_types); |
169 | 169 | } |
170 | 170 | } |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | * @param boolean $force_recheck whether to force re-checking for new payment method types |
175 | 175 | * @return EE_PMT_Base[] |
176 | 176 | */ |
177 | - public function payment_method_types( $force_recheck = FALSE ){ |
|
177 | + public function payment_method_types($force_recheck = FALSE) { |
|
178 | 178 | $this->maybe_register_payment_methods($force_recheck); |
179 | 179 | $pmt_objs = array(); |
180 | - foreach($this->payment_method_type_names(true) as $classname){ |
|
180 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
181 | 181 | $pmt_objs[] = new $classname; |
182 | 182 | } |
183 | 183 | return $pmt_objs; |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | * @param string $classname |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - public function payment_method_type_sans_class_prefix($classname){ |
|
193 | - $pmt_name = str_replace("EE_PMT_","",$classname); |
|
192 | + public function payment_method_type_sans_class_prefix($classname) { |
|
193 | + $pmt_name = str_replace("EE_PMT_", "", $classname); |
|
194 | 194 | return $pmt_name; |
195 | 195 | } |
196 | 196 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @param string $type |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function payment_method_class_from_type($type){ |
|
202 | + public function payment_method_class_from_type($type) { |
|
203 | 203 | $this->maybe_register_payment_methods(); |
204 | 204 | return "EE_PMT_".$type; |
205 | 205 | } |
@@ -213,38 +213,38 @@ discard block |
||
213 | 213 | * @return \EE_Payment_Method |
214 | 214 | * @throws \EE_Error |
215 | 215 | */ |
216 | - public function activate_a_payment_method_of_type( $payment_method_type ){ |
|
216 | + public function activate_a_payment_method_of_type($payment_method_type) { |
|
217 | 217 | $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
218 | - if( ! $payment_method instanceof EE_Payment_Method ){ |
|
218 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
219 | 219 | $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
220 | - if(class_exists($pm_type_class)){ |
|
220 | + if (class_exists($pm_type_class)) { |
|
221 | 221 | /** @var $pm_type_obj EE_PMT_Base */ |
222 | 222 | $pm_type_obj = new $pm_type_class; |
223 | 223 | $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
224 | - if( ! $payment_method){ |
|
225 | - $payment_method = $this->create_payment_method_of_type( $pm_type_obj ); |
|
224 | + if ( ! $payment_method) { |
|
225 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
226 | 226 | } |
227 | - $payment_method->set_type( $payment_method_type ); |
|
228 | - $this->initialize_payment_method( $payment_method ); |
|
227 | + $payment_method->set_type($payment_method_type); |
|
228 | + $this->initialize_payment_method($payment_method); |
|
229 | 229 | } else { |
230 | 230 | throw new EE_Error( |
231 | 231 | sprintf( |
232 | - __( 'There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
232 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
233 | 233 | $pm_type_class ) |
234 | 234 | ); |
235 | 235 | } |
236 | 236 | } |
237 | 237 | $payment_method->set_active(); |
238 | 238 | $payment_method->save(); |
239 | - $this->set_usable_currencies_on_payment_method( $payment_method ); |
|
240 | - if( $payment_method->type() == 'Invoice' ){ |
|
241 | - $messages = EE_Registry::instance()->load_lib( 'messages' ); |
|
242 | - $messages->ensure_message_type_is_active( 'invoice', 'html' ); |
|
243 | - $messages->ensure_messenger_is_active( 'pdf' ); |
|
239 | + $this->set_usable_currencies_on_payment_method($payment_method); |
|
240 | + if ($payment_method->type() == 'Invoice') { |
|
241 | + $messages = EE_Registry::instance()->load_lib('messages'); |
|
242 | + $messages->ensure_message_type_is_active('invoice', 'html'); |
|
243 | + $messages->ensure_messenger_is_active('pdf'); |
|
244 | 244 | EE_Error::add_attention( |
245 | 245 | sprintf( |
246 | - __( 'Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso' ), |
|
247 | - '<a href="' . admin_url( 'admin.php?page=espresso_messages') . '">', |
|
246 | + __('Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso'), |
|
247 | + '<a href="'.admin_url('admin.php?page=espresso_messages').'">', |
|
248 | 248 | '</a>' |
249 | 249 | ) |
250 | 250 | ); |
@@ -258,17 +258,17 @@ discard block |
||
258 | 258 | * @param EE_PMT_Base $pm_type_obj |
259 | 259 | * @return EE_Payment_Method |
260 | 260 | */ |
261 | - public function create_payment_method_of_type( $pm_type_obj ) { |
|
261 | + public function create_payment_method_of_type($pm_type_obj) { |
|
262 | 262 | global $current_user; |
263 | 263 | $payment_method = EE_Payment_Method::new_instance( |
264 | 264 | array( |
265 | 265 | 'PMD_type' => $pm_type_obj->system_name(), |
266 | 266 | 'PMD_name' => $pm_type_obj->pretty_name(), |
267 | 267 | 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
268 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
268 | + 'PMD_slug' => $pm_type_obj->system_name(), //automatically converted to slug |
|
269 | 269 | 'PMD_wp_user' => $current_user->ID, |
270 | 270 | 'PMD_order' => EEM_Payment_Method::instance()->count( |
271 | - array( array( 'PMD_type' => array( '!=', 'Admin_Only' ))) |
|
271 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
272 | 272 | ) * 10, |
273 | 273 | ) |
274 | 274 | ); |
@@ -280,21 +280,21 @@ discard block |
||
280 | 280 | * @param EE_Payment_Method $payment_method |
281 | 281 | * @return EE_Payment_Method |
282 | 282 | */ |
283 | - public function initialize_payment_method( $payment_method ) { |
|
283 | + public function initialize_payment_method($payment_method) { |
|
284 | 284 | $pm_type_obj = $payment_method->type_obj(); |
285 | - $payment_method->set_description( $pm_type_obj->default_description() ); |
|
286 | - if( ! $payment_method->button_url() ){ |
|
287 | - $payment_method->set_button_url( $pm_type_obj->default_button_url() ); |
|
285 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
286 | + if ( ! $payment_method->button_url()) { |
|
287 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
288 | 288 | } |
289 | 289 | //now add setup its default extra meta properties |
290 | 290 | $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
291 | - if ( ! empty( $extra_metas ) ) { |
|
291 | + if ( ! empty($extra_metas)) { |
|
292 | 292 | //verify the payment method has an ID before adding extra meta |
293 | - if ( ! $payment_method->ID() ) { |
|
293 | + if ( ! $payment_method->ID()) { |
|
294 | 294 | $payment_method->save(); |
295 | 295 | } |
296 | - foreach ( $extra_metas as $meta_name => $input ) { |
|
297 | - $payment_method->update_extra_meta( $meta_name, $input->raw_value() ); |
|
296 | + foreach ($extra_metas as $meta_name => $input) { |
|
297 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | return $payment_method; |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | * @param EE_Payment_Method $payment_method |
306 | 306 | * @return EE_Payment_Method |
307 | 307 | */ |
308 | - public function set_usable_currencies_on_payment_method( $payment_method ) { |
|
309 | - foreach($payment_method->get_all_usable_currencies() as $currency_obj){ |
|
308 | + public function set_usable_currencies_on_payment_method($payment_method) { |
|
309 | + foreach ($payment_method->get_all_usable_currencies() as $currency_obj) { |
|
310 | 310 | $payment_method->_add_relation_to($currency_obj, 'Currency'); |
311 | 311 | } |
312 | 312 | return $payment_method; |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | * |
325 | 325 | * @return int count of rows updated. |
326 | 326 | */ |
327 | - public function deactivate_payment_method( $payment_method_slug ) { |
|
328 | - $count_updated = EEM_Payment_Method::instance()->update(array('PMD_scope'=>array()),array(array('PMD_slug'=>$payment_method_slug))); |
|
327 | + public function deactivate_payment_method($payment_method_slug) { |
|
328 | + $count_updated = EEM_Payment_Method::instance()->update(array('PMD_scope'=>array()), array(array('PMD_slug'=>$payment_method_slug))); |
|
329 | 329 | return $count_updated; |
330 | 330 | } |
331 | 331 | |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @param array $caps capabilities being filtered |
339 | 339 | * @return array |
340 | 340 | */ |
341 | - public function add_payment_method_caps( $caps ) { |
|
341 | + public function add_payment_method_caps($caps) { |
|
342 | 342 | /* add dynamic caps from payment methods |
343 | 343 | * at the time of writing, october 20 2014, these are the caps added: |
344 | 344 | * ee_payment_method_admin_only |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * their related capability automatically added too, so long as they are |
354 | 354 | * registered properly using EE_Register_Payment_Method::register() |
355 | 355 | */ |
356 | - foreach( $this->payment_method_types() as $payment_method_type_obj ){ |
|
356 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
357 | 357 | $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
358 | 358 | } |
359 | 359 | return $caps; |
@@ -177,8 +177,9 @@ discard block |
||
177 | 177 | protected function _construct_tips() { |
178 | 178 | foreach ( $this->_qtipsa as $qt ) { |
179 | 179 | //make sure we have what we need. |
180 | - if ( !isset( $qt['content_id'] ) || !isset( $qt['target'] ) || !isset( $qt['content'] ) ) |
|
181 | - throw new EE_Error( sprintf( __('There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', 'event_espresso'), get_class($this), var_export($qt, true) ) ); |
|
180 | + if ( !isset( $qt['content_id'] ) || !isset( $qt['target'] ) || !isset( $qt['content'] ) ) { |
|
181 | + throw new EE_Error( sprintf( __('There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', 'event_espresso'), get_class($this), var_export($qt, true) ) ); |
|
182 | + } |
|
182 | 183 | |
183 | 184 | //make sure the options include defaults and just override via set config. |
184 | 185 | $options_override = isset( $qt['options'] ) ? (array) $qt['options'] : array(); |
@@ -266,8 +267,9 @@ discard block |
||
266 | 267 | |
267 | 268 | public function __construct( $setup_array ) { |
268 | 269 | foreach ( $setup_array as $prop => $value ) { |
269 | - if ( EEH_Class_Tools::has_property( $this, $prop ) ) |
|
270 | - $this->{$prop} = $value; |
|
270 | + if ( EEH_Class_Tools::has_property( $this, $prop ) ) { |
|
271 | + $this->{$prop} = $value; |
|
272 | + } |
|
271 | 273 | } |
272 | 274 | } |
273 | 275 | } |
274 | 276 | \ No newline at end of file |
@@ -13,13 +13,13 @@ discard block |
||
13 | 13 | //is for lower than 4.8.33 |
14 | 14 | add_filter( |
15 | 15 | 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
16 | - array( $this, 'remove_checkin_routes_earlier_than_4_8_33' ), |
|
16 | + array($this, 'remove_checkin_routes_earlier_than_4_8_33'), |
|
17 | 17 | 10, |
18 | 18 | 2 |
19 | 19 | ); |
20 | 20 | add_filter( |
21 | 21 | 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
22 | - array( $this, 'dont_add_headers_from_ee_notices' ), |
|
22 | + array($this, 'dont_add_headers_from_ee_notices'), |
|
23 | 23 | 10, |
24 | 24 | 2 |
25 | 25 | ); |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * @param string $version |
33 | 33 | * @return array like $routes_on_this_version |
34 | 34 | */ |
35 | - public function remove_checkin_routes_earlier_than_4_8_33( $routes_on_this_version, $version ) { |
|
36 | - if( $this->applies_to_version( $version ) ) { |
|
37 | - unset( $routes_on_this_version[ 'registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)' ] ); |
|
35 | + public function remove_checkin_routes_earlier_than_4_8_33($routes_on_this_version, $version) { |
|
36 | + if ($this->applies_to_version($version)) { |
|
37 | + unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']); |
|
38 | 38 | } |
39 | 39 | return $routes_on_this_version; |
40 | 40 | } |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @param string $requested_version |
46 | 46 | * @return array |
47 | 47 | */ |
48 | - public function dont_add_headers_from_ee_notices( $headers_from_ee_notices, $requested_version ) { |
|
49 | - if( $this->applies_to_version( $requested_version ) ) { |
|
48 | + public function dont_add_headers_from_ee_notices($headers_from_ee_notices, $requested_version) { |
|
49 | + if ($this->applies_to_version($requested_version)) { |
|
50 | 50 | return array(); |
51 | 51 | } |
52 | 52 | return $headers_from_ee_notices; |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @return boolean true: this class' name indicates its filters and actions |
57 | 57 | * should take effect. False: this class' name indicates it shouldn't do anything |
58 | 58 | */ |
59 | - public function applies_to_version( $requested_version ) { |
|
60 | - if( $this->version() > $requested_version ) { |
|
59 | + public function applies_to_version($requested_version) { |
|
60 | + if ($this->version() > $requested_version) { |
|
61 | 61 | return true; |
62 | 62 | } |
63 | 63 | return false; |
@@ -71,24 +71,24 @@ discard block |
||
71 | 71 | * @throws \EE_Error |
72 | 72 | */ |
73 | 73 | public function version() { |
74 | - if( $this->_version === null ) { |
|
74 | + if ($this->_version === null) { |
|
75 | 75 | $matches = array(); |
76 | 76 | $regex = '~Changes_In_(.*)_(.*)_(.*)$~'; |
77 | 77 | $success = preg_match( |
78 | 78 | $regex, |
79 | - get_class( $this ), |
|
79 | + get_class($this), |
|
80 | 80 | $matches |
81 | 81 | ); |
82 | - if( ! $success ) { |
|
82 | + if ( ! $success) { |
|
83 | 83 | throw new \EE_Error( |
84 | 84 | sprintf( |
85 | - __( 'The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso' ), |
|
86 | - get_class( $this ), |
|
85 | + __('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'), |
|
86 | + get_class($this), |
|
87 | 87 | $regex |
88 | 88 | ) |
89 | 89 | ); |
90 | 90 | } |
91 | - $this->_version = $matches[1] . '.' . $matches[2] . '.' . $matches[3]; |
|
91 | + $this->_version = $matches[1].'.'.$matches[2].'.'.$matches[3]; |
|
92 | 92 | } |
93 | 93 | return $this->_version; |
94 | 94 | } |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers; |
3 | 3 | |
4 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | protected $_requested_version; |
37 | 37 | |
38 | 38 | public function __construct() { |
39 | - $this->_debug_mode = defined( 'EE_REST_API_DEBUG_MODE' ) ? EE_REST_API_DEBUG_MODE : false; |
|
39 | + $this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * Sets the version the user requested |
45 | 45 | * @param string $version eg '4.8' |
46 | 46 | */ |
47 | - public function set_requested_version( $version ) { |
|
47 | + public function set_requested_version($version) { |
|
48 | 48 | $this->_requested_version = $version; |
49 | 49 | } |
50 | 50 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @param string $key |
54 | 54 | * @param string|array $info |
55 | 55 | */ |
56 | - protected function _set_debug_info( $key, $info ){ |
|
57 | - $this->_debug_info[ $key ] = $info; |
|
56 | + protected function _set_debug_info($key, $info) { |
|
57 | + $this->_debug_info[$key] = $info; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | * @param \WP_Error $wp_error_response |
63 | 63 | * @return \WP_Error |
64 | 64 | */ |
65 | - protected function _add_ee_errors_to_response( \WP_Error $wp_error_response ) { |
|
65 | + protected function _add_ee_errors_to_response(\WP_Error $wp_error_response) { |
|
66 | 66 | $notices_during_checkin = \EE_Error::get_raw_notices(); |
67 | - if( ! empty( $notices_during_checkin[ 'errors' ] ) ) { |
|
68 | - foreach( $notices_during_checkin[ 'errors' ] as $error_code => $error_message ) { |
|
67 | + if ( ! empty($notices_during_checkin['errors'])) { |
|
68 | + foreach ($notices_during_checkin['errors'] as $error_code => $error_message) { |
|
69 | 69 | $wp_error_response->add( |
70 | - sanitize_key( $error_code ), |
|
71 | - strip_tags( $error_message ) ); |
|
70 | + sanitize_key($error_code), |
|
71 | + strip_tags($error_message) ); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | return $wp_error_response; |
@@ -86,28 +86,28 @@ discard block |
||
86 | 86 | * @param array|\WP_Error|\Exception $response |
87 | 87 | * @return \WP_REST_Response |
88 | 88 | */ |
89 | - public function send_response( $response ) { |
|
90 | - if( $response instanceof \Exception ) { |
|
91 | - $response = new \WP_Error( $response->getCode(), $response->getMessage() ); |
|
89 | + public function send_response($response) { |
|
90 | + if ($response instanceof \Exception) { |
|
91 | + $response = new \WP_Error($response->getCode(), $response->getMessage()); |
|
92 | 92 | } |
93 | - if( $response instanceof \WP_Error ) { |
|
94 | - $response = $this->_add_ee_errors_to_response( $response ); |
|
95 | - $rest_response = $this->_create_rest_response_from_wp_error( $response ); |
|
96 | - }else{ |
|
97 | - $rest_response = new \WP_REST_Response( $response, 200 ); |
|
93 | + if ($response instanceof \WP_Error) { |
|
94 | + $response = $this->_add_ee_errors_to_response($response); |
|
95 | + $rest_response = $this->_create_rest_response_from_wp_error($response); |
|
96 | + } else { |
|
97 | + $rest_response = new \WP_REST_Response($response, 200); |
|
98 | 98 | } |
99 | 99 | $headers = array(); |
100 | - if( $this->_debug_mode && is_array( $this->_debug_info ) ) { |
|
101 | - foreach( $this->_debug_info as $debug_key => $debug_info ) { |
|
102 | - if( is_array( $debug_info ) ) { |
|
103 | - $debug_info = json_encode( $debug_info ); |
|
100 | + if ($this->_debug_mode && is_array($this->_debug_info)) { |
|
101 | + foreach ($this->_debug_info as $debug_key => $debug_info) { |
|
102 | + if (is_array($debug_info)) { |
|
103 | + $debug_info = json_encode($debug_info); |
|
104 | 104 | } |
105 | - $headers[ 'X-EE4-Debug-' . ucwords( $debug_key ) ] = $debug_info; |
|
105 | + $headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info; |
|
106 | 106 | } |
107 | 107 | } |
108 | - $headers = array_merge( $headers, $this->_get_headers_from_ee_notices() ); |
|
108 | + $headers = array_merge($headers, $this->_get_headers_from_ee_notices()); |
|
109 | 109 | |
110 | - $rest_response->set_headers( $headers ); |
|
110 | + $rest_response->set_headers($headers); |
|
111 | 111 | return $rest_response; |
112 | 112 | } |
113 | 113 | |
@@ -118,31 +118,31 @@ discard block |
||
118 | 118 | * @param \WP_Error $wp_error |
119 | 119 | * @return \WP_REST_Response |
120 | 120 | */ |
121 | - protected function _create_rest_response_from_wp_error( \WP_Error $wp_error ) { |
|
121 | + protected function _create_rest_response_from_wp_error(\WP_Error $wp_error) { |
|
122 | 122 | $error_data = $wp_error->get_error_data(); |
123 | - if ( is_array( $error_data ) && isset( $error_data['status'] ) ) { |
|
123 | + if (is_array($error_data) && isset($error_data['status'])) { |
|
124 | 124 | $status = $error_data['status']; |
125 | 125 | } else { |
126 | 126 | $status = 500; |
127 | 127 | } |
128 | 128 | |
129 | 129 | $errors = array(); |
130 | - foreach ( (array) $wp_error->errors as $code => $messages ) { |
|
131 | - foreach ( (array) $messages as $message ) { |
|
130 | + foreach ((array) $wp_error->errors as $code => $messages) { |
|
131 | + foreach ((array) $messages as $message) { |
|
132 | 132 | $errors[] = array( |
133 | 133 | 'code' => $code, |
134 | 134 | 'message' => $message, |
135 | - 'data' => $wp_error->get_error_data( $code ) |
|
135 | + 'data' => $wp_error->get_error_data($code) |
|
136 | 136 | ); |
137 | 137 | } |
138 | 138 | } |
139 | - $data = isset( $errors[0] ) ? $errors[0] : array(); |
|
140 | - if ( count( $errors ) > 1 ) { |
|
139 | + $data = isset($errors[0]) ? $errors[0] : array(); |
|
140 | + if (count($errors) > 1) { |
|
141 | 141 | // Remove the primary error. |
142 | - array_shift( $errors ); |
|
142 | + array_shift($errors); |
|
143 | 143 | $data['additional_errors'] = $errors; |
144 | 144 | } |
145 | - return new \WP_REST_Response( $data, $status ); |
|
145 | + return new \WP_REST_Response($data, $status); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | protected function _get_headers_from_ee_notices() { |
153 | 153 | $headers = array(); |
154 | 154 | $notices = \EE_Error::get_raw_notices(); |
155 | - foreach( $notices as $notice_type => $sub_notices ) { |
|
156 | - if( ! is_array( $sub_notices ) ) { |
|
155 | + foreach ($notices as $notice_type => $sub_notices) { |
|
156 | + if ( ! is_array($sub_notices)) { |
|
157 | 157 | continue; |
158 | 158 | } |
159 | - foreach( $sub_notices as $notice_code => $sub_notice ) { |
|
160 | - $headers[ 'X-EE4-Notices-' . \EEH_Inflector::humanize( $notice_type ) . '[' . $notice_code . ']' ] = strip_tags( $sub_notice ); |
|
159 | + foreach ($sub_notices as $notice_code => $sub_notice) { |
|
160 | + $headers['X-EE4-Notices-'.\EEH_Inflector::humanize($notice_type).'['.$notice_code.']'] = strip_tags($sub_notice); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | return apply_filters( |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | * @param string $route |
176 | 176 | * @return string |
177 | 177 | */ |
178 | - public function get_requested_version( $route ) { |
|
178 | + public function get_requested_version($route) { |
|
179 | 179 | $matches = $this->parse_route( |
180 | 180 | $route, |
181 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~', |
|
182 | - array( 'version' ) |
|
181 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'~', |
|
182 | + array('version') |
|
183 | 183 | ); |
184 | - if( isset( $matches[ 'version' ] ) ) { |
|
185 | - return $matches[ 'version' ]; |
|
184 | + if (isset($matches['version'])) { |
|
185 | + return $matches['version']; |
|
186 | 186 | } else { |
187 | 187 | return \EED_Core_Rest_Api::latest_rest_api_version(); |
188 | 188 | } |
@@ -207,23 +207,23 @@ discard block |
||
207 | 207 | * array( 'model' => 'foo', 'id' => 'bar' ) |
208 | 208 | * @throws \EE_Error if it couldn't be parsed |
209 | 209 | */ |
210 | - public function parse_route( $route, $regex, $match_keys ) { |
|
210 | + public function parse_route($route, $regex, $match_keys) { |
|
211 | 211 | $indexed_matches = array(); |
212 | - $success = preg_match( $regex, $route, $matches ); |
|
213 | - if( |
|
214 | - is_array( $matches ) ) { |
|
212 | + $success = preg_match($regex, $route, $matches); |
|
213 | + if ( |
|
214 | + is_array($matches) ) { |
|
215 | 215 | //skip the overall regex match. Who cares |
216 | - for( $i = 1; $i <= count( $match_keys ); $i++ ) { |
|
217 | - if( ! isset( $matches[ $i ] ) ) { |
|
216 | + for ($i = 1; $i <= count($match_keys); $i++) { |
|
217 | + if ( ! isset($matches[$i])) { |
|
218 | 218 | $success = false; |
219 | 219 | } else { |
220 | - $indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ]; |
|
220 | + $indexed_matches[$match_keys[$i - 1]] = $matches[$i]; |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | } |
224 | - if( ! $success ) { |
|
224 | + if ( ! $success) { |
|
225 | 225 | throw new \EE_Error( |
226 | - __( 'We could not parse the URL. Please contact Event Espresso Support', 'event_espresso' ), |
|
226 | + __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
|
227 | 227 | 'endpoint_parsing_error' |
228 | 228 | ); |
229 | 229 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers\model; |
3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -22,20 +22,20 @@ discard block |
||
22 | 22 | * @param \WP_REST_Request $request |
23 | 23 | * @return array|\WP_REST_Response |
24 | 24 | */ |
25 | - public static function handle_request_models_meta( \WP_REST_Request $request ) { |
|
25 | + public static function handle_request_models_meta(\WP_REST_Request $request) { |
|
26 | 26 | $controller = new Meta(); |
27 | - try{ |
|
27 | + try { |
|
28 | 28 | $matches = $controller->parse_route( |
29 | 29 | $request->get_route(), |
30 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . 'resources~', |
|
31 | - array( 'version' ) ); |
|
32 | - if( $matches instanceof \WP_REST_Response ) { |
|
30 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'resources~', |
|
31 | + array('version') ); |
|
32 | + if ($matches instanceof \WP_REST_Response) { |
|
33 | 33 | return $matches; |
34 | 34 | } |
35 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
36 | - return $controller->send_response( $controller->_get_models_metadata_entity() ); |
|
37 | - } catch( \Exception $e ) { |
|
38 | - return $controller->send_response( $e ); |
|
35 | + $controller->set_requested_version($matches['version']); |
|
36 | + return $controller->send_response($controller->_get_models_metadata_entity()); |
|
37 | + } catch (\Exception $e) { |
|
38 | + return $controller->send_response($e); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -43,58 +43,58 @@ discard block |
||
43 | 43 | * Gets the model metadata resource entity |
44 | 44 | * @return array for JSON response, describing all the models available in teh requested version |
45 | 45 | */ |
46 | - protected function _get_models_metadata_entity(){ |
|
46 | + protected function _get_models_metadata_entity() { |
|
47 | 47 | $response = array(); |
48 | - foreach( $this->get_model_version_info()->models_for_requested_version() as $model_name => $model_classname ){ |
|
49 | - $model = $this->get_model_version_info()->load_model( $model_name ); |
|
48 | + foreach ($this->get_model_version_info()->models_for_requested_version() as $model_name => $model_classname) { |
|
49 | + $model = $this->get_model_version_info()->load_model($model_name); |
|
50 | 50 | $fields_json = array(); |
51 | - foreach( $this->get_model_version_info()->fields_on_model_in_this_version( $model ) as $field_name => $field_obj ) { |
|
52 | - if( $this->get_model_version_info()->field_is_ignored( $field_obj ) ) { |
|
51 | + foreach ($this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => $field_obj) { |
|
52 | + if ($this->get_model_version_info()->field_is_ignored($field_obj)) { |
|
53 | 53 | continue; |
54 | 54 | } |
55 | - if( $field_obj instanceof \EE_Boolean_Field ) { |
|
55 | + if ($field_obj instanceof \EE_Boolean_Field) { |
|
56 | 56 | $datatype = 'Boolean'; |
57 | - }elseif( $field_obj->get_wpdb_data_type() == '%d' ) { |
|
57 | + }elseif ($field_obj->get_wpdb_data_type() == '%d') { |
|
58 | 58 | $datatype = 'Number'; |
59 | - }elseif( $field_name instanceof \EE_Serialized_Text_Field ) { |
|
59 | + }elseif ($field_name instanceof \EE_Serialized_Text_Field) { |
|
60 | 60 | $datatype = 'Object'; |
61 | - }else{ |
|
61 | + } else { |
|
62 | 62 | $datatype = 'String'; |
63 | 63 | } |
64 | 64 | $default_value = $field_obj->get_default_value(); |
65 | - if( $default_value === EE_INF ) { |
|
65 | + if ($default_value === EE_INF) { |
|
66 | 66 | $default_value = EE_INF_IN_DB; |
67 | - } elseif( $field_obj instanceof \EE_Datetime_Field && |
|
68 | - $default_value instanceof \DateTime ) { |
|
69 | - $default_value = $default_value->format( 'c' ); |
|
67 | + } elseif ($field_obj instanceof \EE_Datetime_Field && |
|
68 | + $default_value instanceof \DateTime) { |
|
69 | + $default_value = $default_value->format('c'); |
|
70 | 70 | } |
71 | 71 | $field_json = array( |
72 | 72 | 'name' => $field_name, |
73 | 73 | 'nicename' => $field_obj->get_nicename(), |
74 | - 'has_rendered_format' => $this->get_model_version_info()->field_has_rendered_format( $field_obj ), |
|
75 | - 'has_pretty_format' => $this->get_model_version_info()->field_has_pretty_format( $field_obj ), |
|
76 | - 'type' => str_replace('EE_', '', get_class( $field_obj ) ), |
|
74 | + 'has_rendered_format' => $this->get_model_version_info()->field_has_rendered_format($field_obj), |
|
75 | + 'has_pretty_format' => $this->get_model_version_info()->field_has_pretty_format($field_obj), |
|
76 | + 'type' => str_replace('EE_', '', get_class($field_obj)), |
|
77 | 77 | 'datatype' => $datatype, |
78 | 78 | 'nullable' => $field_obj->is_nullable(), |
79 | 79 | 'default' => $default_value, |
80 | 80 | 'table_alias' => $field_obj->get_table_alias(), |
81 | 81 | 'table_column' => $field_obj->get_table_column(), |
82 | 82 | ); |
83 | - $fields_json[ $field_json[ 'name' ] ] = $field_json; |
|
83 | + $fields_json[$field_json['name']] = $field_json; |
|
84 | 84 | |
85 | 85 | } |
86 | - $fields_json = array_merge( $fields_json, $this->get_model_version_info()->extra_resource_properties_for_model( $model ) ); |
|
87 | - $response[ $model_name ]['fields'] = apply_filters( 'FHEE__Meta__handle_request_models_meta__fields', $fields_json, $model ); |
|
86 | + $fields_json = array_merge($fields_json, $this->get_model_version_info()->extra_resource_properties_for_model($model)); |
|
87 | + $response[$model_name]['fields'] = apply_filters('FHEE__Meta__handle_request_models_meta__fields', $fields_json, $model); |
|
88 | 88 | $relations_json = array(); |
89 | - foreach( $model->relation_settings() as $relation_name => $relation_obj ) { |
|
89 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
90 | 90 | $relation_json = array( |
91 | 91 | 'name' => $relation_name, |
92 | - 'type' => str_replace( 'EE_', '', get_class( $relation_obj ) ), |
|
92 | + 'type' => str_replace('EE_', '', get_class($relation_obj)), |
|
93 | 93 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
94 | 94 | ); |
95 | - $relations_json[ $relation_name ] = $relation_json; |
|
95 | + $relations_json[$relation_name] = $relation_json; |
|
96 | 96 | } |
97 | - $response[ $model_name ][ 'relations' ] = apply_filters( 'FHEE__Meta__handle_request_models_meta__relations', $relations_json, $model ); |
|
97 | + $response[$model_name]['relations'] = apply_filters('FHEE__Meta__handle_request_models_meta__relations', $relations_json, $model); |
|
98 | 98 | } |
99 | 99 | return $response; |
100 | 100 | } |
@@ -104,23 +104,23 @@ discard block |
||
104 | 104 | * @param \WP_REST_Response $rest_response_obj |
105 | 105 | * @return \WP_REST_Response |
106 | 106 | */ |
107 | - public static function filter_ee_metadata_into_index( \WP_REST_Response $rest_response_obj ) { |
|
107 | + public static function filter_ee_metadata_into_index(\WP_REST_Response $rest_response_obj) { |
|
108 | 108 | $response_data = $rest_response_obj->get_data(); |
109 | 109 | $addons = array(); |
110 | - foreach( \EE_Registry::instance()->addons as $addon){ |
|
110 | + foreach (\EE_Registry::instance()->addons as $addon) { |
|
111 | 111 | $addon_json = array( |
112 | 112 | 'name' => $addon->name(), |
113 | 113 | 'version' => $addon->version() |
114 | 114 | ); |
115 | - $addons[ $addon_json[ 'name' ] ] = $addon_json; |
|
115 | + $addons[$addon_json['name']] = $addon_json; |
|
116 | 116 | } |
117 | - $response_data[ 'ee' ] = array( |
|
117 | + $response_data['ee'] = array( |
|
118 | 118 | 'version' => \EEM_System_Status::instance()->get_ee_version(), |
119 | 119 | 'addons' => $addons, |
120 | 120 | 'maintenance_mode' => \EE_Maintenance_Mode::instance()->real_level(), |
121 | - 'served_core_versions' => array_keys( \EED_Core_Rest_Api::versions_served() ) |
|
121 | + 'served_core_versions' => array_keys(\EED_Core_Rest_Api::versions_served()) |
|
122 | 122 | ); |
123 | - $rest_response_obj->set_data( $response_data ); |
|
123 | + $rest_response_obj->set_data($response_data); |
|
124 | 124 | return $rest_response_obj; |
125 | 125 | } |
126 | 126 | } |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | use EventEspresso\core\libraries\rest_api\controllers\Base as Base; |
3 | 3 | use EventEspresso\core\libraries\rest_api\controllers\model\Read; |
4 | 4 | |
5 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
6 | - exit( 'No direct script access allowed' ); |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /** |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | * @param \WP_REST_Request $request |
25 | 25 | * @return \WP_Error|\WP_REST_Response |
26 | 26 | */ |
27 | - public static function handle_request_toggle_checkin( \WP_REST_Request $request ) { |
|
27 | + public static function handle_request_toggle_checkin(\WP_REST_Request $request) { |
|
28 | 28 | $controller = new Checkin(); |
29 | - return $controller->_create_checkin_checkout_object( $request ); |
|
29 | + return $controller->_create_checkin_checkout_object($request); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | |
@@ -37,47 +37,47 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request |
38 | 38 | * @return \WP_Error|\WP_REST_Response |
39 | 39 | */ |
40 | - protected function _create_checkin_checkout_object( \WP_REST_Request $request ) { |
|
41 | - $reg_id = $request->get_param( 'REG_ID' ); |
|
42 | - $dtt_id = $request->get_param( 'DTT_ID' ); |
|
43 | - $force = $request->get_param( 'force' ); |
|
44 | - if( $force == 'true' ) { |
|
40 | + protected function _create_checkin_checkout_object(\WP_REST_Request $request) { |
|
41 | + $reg_id = $request->get_param('REG_ID'); |
|
42 | + $dtt_id = $request->get_param('DTT_ID'); |
|
43 | + $force = $request->get_param('force'); |
|
44 | + if ($force == 'true') { |
|
45 | 45 | $force = true; |
46 | 46 | } else { |
47 | 47 | $force = false; |
48 | 48 | } |
49 | - $reg = \EEM_Registration::instance()->get_one_by_ID( $reg_id ); |
|
50 | - if( ! $reg instanceof \EE_Registration ) { |
|
49 | + $reg = \EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
50 | + if ( ! $reg instanceof \EE_Registration) { |
|
51 | 51 | return $this->send_response( |
52 | 52 | new \WP_Error( |
53 | 53 | 'rest_registration_toggle_checkin_invalid_id', |
54 | 54 | sprintf( |
55 | - __( 'You cannot checkin registration with ID %1$s because it doesn\'t exist.', 'event_espresso' ), |
|
55 | + __('You cannot checkin registration with ID %1$s because it doesn\'t exist.', 'event_espresso'), |
|
56 | 56 | $reg_id |
57 | 57 | ), |
58 | - array( 'status' => 422 ) |
|
58 | + array('status' => 422) |
|
59 | 59 | ) |
60 | 60 | ); |
61 | 61 | } |
62 | - if( ! \EE_Capabilities::instance()->current_user_can( 'ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id ) ) { |
|
62 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) { |
|
63 | 63 | return $this->send_response( |
64 | 64 | new \WP_Error( |
65 | 65 | 'rest_user_cannot_toggle_checkin', |
66 | 66 | sprintf( |
67 | - __( 'You are not allowed to checkin registration with ID %1$s.', 'event_espresso' ), |
|
67 | + __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), |
|
68 | 68 | $reg_id |
69 | 69 | ), |
70 | - array( 'status' => 403 ) |
|
70 | + array('status' => 403) |
|
71 | 71 | ) |
72 | 72 | ); |
73 | 73 | } |
74 | - $success = $reg->toggle_checkin_status( $dtt_id, ! $force ); |
|
75 | - if( $success === false ) { |
|
74 | + $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
|
75 | + if ($success === false) { |
|
76 | 76 | //rely on EE_Error::add_error messages to have been added to give more data about hwy it failed |
77 | 77 | return $this->send_response( |
78 | 78 | new \WP_Error( |
79 | 79 | 'rest_toggle_checkin_failed', |
80 | - __( 'Registration checkin failed. Please see additional error data.', 'event_espresso' ) |
|
80 | + __('Registration checkin failed. Please see additional error data.', 'event_espresso') |
|
81 | 81 | ) |
82 | 82 | ); |
83 | 83 | } |
@@ -92,28 +92,28 @@ discard block |
||
92 | 92 | ) |
93 | 93 | ) |
94 | 94 | ); |
95 | - if( ! $checkin instanceof \EE_Checkin ) { |
|
95 | + if ( ! $checkin instanceof \EE_Checkin) { |
|
96 | 96 | return $this->send_response( |
97 | 97 | new \WP_Error( |
98 | 98 | 'rest_toggle_checkin_error', |
99 | 99 | sprintf( |
100 | - __( 'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', 'event_espresso' ), |
|
100 | + __('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', 'event_espresso'), |
|
101 | 101 | $reg_id, |
102 | 102 | $dtt_id |
103 | 103 | ) |
104 | 104 | ) |
105 | 105 | ); |
106 | 106 | } |
107 | - $requested_version = $this->get_requested_version( $request->get_route() ); |
|
107 | + $requested_version = $this->get_requested_version($request->get_route()); |
|
108 | 108 | $get_request = new \WP_REST_Request( |
109 | 109 | 'GET', |
110 | - \EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID() |
|
110 | + \EED_Core_Rest_Api::ee_api_namespace.$requested_version.'/checkins/'.$checkin->ID() |
|
111 | 111 | ); |
112 | 112 | $get_request->set_url_params( |
113 | 113 | array( |
114 | 114 | 'id' => $checkin->ID() |
115 | 115 | ) |
116 | 116 | ); |
117 | - return Read::handle_request_get_one( $get_request ); |
|
117 | + return Read::handle_request_get_one($get_request); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | \ No newline at end of file |