@@ -3065,7 +3065,7 @@ |
||
| 3065 | 3065 | * |
| 3066 | 3066 | * @param int $GRP_ID The group being deleted |
| 3067 | 3067 | * @param bool $include_group whether to delete the Message Template Group as well. |
| 3068 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3068 | + * @return integer boolean to indicate the success of the deletes or not. |
|
| 3069 | 3069 | * @throws EE_Error |
| 3070 | 3070 | * @throws InvalidArgumentException |
| 3071 | 3071 | * @throws InvalidDataTypeException |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $this->_admin_base_url = EE_MSG_ADMIN_URL; |
| 94 | 94 | $this->_admin_base_path = EE_MSG_ADMIN; |
| 95 | 95 | |
| 96 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 96 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
|
| 97 | 97 | |
| 98 | 98 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
| 99 | 99 | $this->_load_message_resource_manager(); |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
| 253 | 253 | $messenger_options |
| 254 | 254 | ); |
| 255 | - $input = new EE_Select_Input( |
|
| 255 | + $input = new EE_Select_Input( |
|
| 256 | 256 | $messenger_options, |
| 257 | 257 | array( |
| 258 | 258 | 'html_name' => 'ee_messenger_filter_by', |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
| 291 | 291 | $message_type_options |
| 292 | 292 | ); |
| 293 | - $input = new EE_Select_Input( |
|
| 293 | + $input = new EE_Select_Input( |
|
| 294 | 294 | $message_type_options, |
| 295 | 295 | array( |
| 296 | 296 | 'html_name' => 'ee_message_type_filter_by', |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
| 329 | 329 | $context_options |
| 330 | 330 | ); |
| 331 | - $input = new EE_Select_Input( |
|
| 331 | + $input = new EE_Select_Input( |
|
| 332 | 332 | $context_options, |
| 333 | 333 | array( |
| 334 | 334 | 'html_name' => 'ee_context_filter_by', |
@@ -710,53 +710,53 @@ discard block |
||
| 710 | 710 | |
| 711 | 711 | public function messages_help_tab() |
| 712 | 712 | { |
| 713 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 713 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | |
| 717 | 717 | public function messengers_help_tab() |
| 718 | 718 | { |
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
| 723 | 723 | public function message_types_help_tab() |
| 724 | 724 | { |
| 725 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 725 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | |
| 729 | 729 | public function messages_overview_help_tab() |
| 730 | 730 | { |
| 731 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 731 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | |
| 735 | 735 | public function message_templates_help_tab() |
| 736 | 736 | { |
| 737 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 737 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | |
| 741 | 741 | public function edit_message_template_help_tab() |
| 742 | 742 | { |
| 743 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 743 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="' |
|
| 744 | 744 | . esc_attr__('Editor Title', 'event_espresso') |
| 745 | 745 | . '" />'; |
| 746 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 746 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="' |
|
| 747 | 747 | . esc_attr__('Context Switcher and Preview', 'event_espresso') |
| 748 | 748 | . '" />'; |
| 749 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 749 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="' |
|
| 750 | 750 | . esc_attr__('Message Template Form Fields', 'event_espresso') |
| 751 | 751 | . '" />'; |
| 752 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 752 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="' |
|
| 753 | 753 | . esc_attr__('Shortcodes Metabox', 'event_espresso') |
| 754 | 754 | . '" />'; |
| 755 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 755 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="' |
|
| 756 | 756 | . esc_attr__('Publish Metabox', 'event_espresso') |
| 757 | 757 | . '" />'; |
| 758 | 758 | EEH_Template::display_template( |
| 759 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 759 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 760 | 760 | $args |
| 761 | 761 | ); |
| 762 | 762 | } |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | $this->_set_shortcodes(); |
| 768 | 768 | $args['shortcodes'] = $this->_shortcodes; |
| 769 | 769 | EEH_Template::display_template( |
| 770 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 770 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 771 | 771 | $args |
| 772 | 772 | ); |
| 773 | 773 | } |
@@ -775,16 +775,16 @@ discard block |
||
| 775 | 775 | |
| 776 | 776 | public function preview_message_help_tab() |
| 777 | 777 | { |
| 778 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 778 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
| 782 | 782 | public function settings_help_tab() |
| 783 | 783 | { |
| 784 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 785 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 786 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 787 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 784 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png' |
|
| 785 | + . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'; |
|
| 786 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png' |
|
| 787 | + . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'; |
|
| 788 | 788 | $args['img3'] = '<div class="switch">' |
| 789 | 789 | . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
| 790 | 790 | . ' type="checkbox" checked="checked">' |
@@ -795,18 +795,18 @@ discard block |
||
| 795 | 795 | . ' type="checkbox">' |
| 796 | 796 | . '<label for="ee-on-off-toggle-on"></label>' |
| 797 | 797 | . '</div>'; |
| 798 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 798 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | |
| 802 | 802 | public function load_scripts_styles() |
| 803 | 803 | { |
| 804 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 804 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 805 | 805 | wp_enqueue_style('espresso_ee_msg'); |
| 806 | 806 | |
| 807 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 807 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 808 | 808 | array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
| 809 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 809 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 810 | 810 | array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
| 811 | 811 | } |
| 812 | 812 | |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | |
| 839 | 839 | $this->_set_shortcodes(); |
| 840 | 840 | |
| 841 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 841 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 842 | 842 | esc_html__( |
| 843 | 843 | '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.', |
| 844 | 844 | 'event_espresso' |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | |
| 854 | 854 | wp_register_script( |
| 855 | 855 | 'ee_msgs_edit_js', |
| 856 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 856 | + EE_MSG_ASSETS_URL.'ee_message_editor.js', |
|
| 857 | 857 | array('jquery'), |
| 858 | 858 | EVENT_ESPRESSO_VERSION |
| 859 | 859 | ); |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | { |
| 897 | 897 | wp_register_style( |
| 898 | 898 | 'ee-message-settings', |
| 899 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 899 | + EE_MSG_ASSETS_URL.'ee_message_settings.css', |
|
| 900 | 900 | array(), |
| 901 | 901 | EVENT_ESPRESSO_VERSION |
| 902 | 902 | ); |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | } |
| 983 | 983 | $status_bulk_actions = $common_bulk_actions; |
| 984 | 984 | //unset bulk actions not applying to status |
| 985 | - if (! empty($status_bulk_actions)) { |
|
| 985 | + if ( ! empty($status_bulk_actions)) { |
|
| 986 | 986 | switch ($status) { |
| 987 | 987 | case EEM_Message::status_idle: |
| 988 | 988 | case EEM_Message::status_resend: |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | //skip adding messenger executing status to views because it will be included with the Failed view. |
| 1010 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1010 | + if ($status === EEM_Message::status_messenger_executing) { |
|
| 1011 | 1011 | continue; |
| 1012 | 1012 | } |
| 1013 | 1013 | |
@@ -1059,37 +1059,37 @@ discard block |
||
| 1059 | 1059 | /** @type array $status_items status legend setup */ |
| 1060 | 1060 | $status_items = array( |
| 1061 | 1061 | 'sent_status' => array( |
| 1062 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1062 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 1063 | 1063 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
| 1064 | 1064 | ), |
| 1065 | 1065 | 'idle_status' => array( |
| 1066 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1066 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 1067 | 1067 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
| 1068 | 1068 | ), |
| 1069 | 1069 | 'failed_status' => array( |
| 1070 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1070 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 1071 | 1071 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
| 1072 | 1072 | ), |
| 1073 | 1073 | 'messenger_executing_status' => array( |
| 1074 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1074 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing, |
|
| 1075 | 1075 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
| 1076 | 1076 | ), |
| 1077 | 1077 | 'resend_status' => array( |
| 1078 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1078 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 1079 | 1079 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
| 1080 | 1080 | ), |
| 1081 | 1081 | 'incomplete_status' => array( |
| 1082 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1082 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 1083 | 1083 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
| 1084 | 1084 | ), |
| 1085 | 1085 | 'retry_status' => array( |
| 1086 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1086 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 1087 | 1087 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
| 1088 | 1088 | ) |
| 1089 | 1089 | ); |
| 1090 | 1090 | if (EEM_Message::debug()) { |
| 1091 | 1091 | $status_items['debug_only_status'] = array( |
| 1092 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1092 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 1093 | 1093 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
| 1094 | 1094 | ); |
| 1095 | 1095 | } |
@@ -1101,8 +1101,8 @@ discard block |
||
| 1101 | 1101 | protected function _custom_mtps_preview() |
| 1102 | 1102 | { |
| 1103 | 1103 | $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
| 1104 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1105 | - . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1104 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"' |
|
| 1105 | + . ' alt="'.esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso').'" />'; |
|
| 1106 | 1106 | $this->_template_args['preview_text'] = '<strong>' |
| 1107 | 1107 | . esc_html__( |
| 1108 | 1108 | '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.', |
@@ -1384,7 +1384,7 @@ discard block |
||
| 1384 | 1384 | //let's verify if we need this extra field via the shortcodes parameter. |
| 1385 | 1385 | $continue = false; |
| 1386 | 1386 | if (isset($extra_array['shortcodes_required'])) { |
| 1387 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1387 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1388 | 1388 | if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
| 1389 | 1389 | $continue = true; |
| 1390 | 1390 | } |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | } |
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | - $field_id = $reference_field |
|
| 1397 | + $field_id = $reference_field |
|
| 1398 | 1398 | . '-' |
| 1399 | 1399 | . $extra_field |
| 1400 | 1400 | . '-content'; |
@@ -1402,8 +1402,8 @@ discard block |
||
| 1402 | 1402 | $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
| 1403 | 1403 | . $reference_field |
| 1404 | 1404 | . '][content][' |
| 1405 | - . $extra_field . ']'; |
|
| 1406 | - $css_class = isset($extra_array['css_class']) |
|
| 1405 | + . $extra_field.']'; |
|
| 1406 | + $css_class = isset($extra_array['css_class']) |
|
| 1407 | 1407 | ? $extra_array['css_class'] |
| 1408 | 1408 | : ''; |
| 1409 | 1409 | |
@@ -1414,7 +1414,7 @@ discard block |
||
| 1414 | 1414 | is_array($validators[$extra_field]) |
| 1415 | 1415 | && isset($validators[$extra_field]['msg']) |
| 1416 | 1416 | ) |
| 1417 | - ? 'validate-error ' . $css_class |
|
| 1417 | + ? 'validate-error '.$css_class |
|
| 1418 | 1418 | : $css_class; |
| 1419 | 1419 | |
| 1420 | 1420 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
@@ -1450,11 +1450,11 @@ discard block |
||
| 1450 | 1450 | |
| 1451 | 1451 | }/**/ |
| 1452 | 1452 | } |
| 1453 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1454 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1453 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1454 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1455 | 1455 | |
| 1456 | 1456 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1457 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1457 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1458 | 1458 | 'label' => null, |
| 1459 | 1459 | 'input' => 'hidden', |
| 1460 | 1460 | 'type' => 'int', |
@@ -1467,7 +1467,7 @@ discard block |
||
| 1467 | 1467 | ); |
| 1468 | 1468 | |
| 1469 | 1469 | $template_form_fields[$templatefield_templatename_id] = array( |
| 1470 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1470 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1471 | 1471 | 'label' => null, |
| 1472 | 1472 | 'input' => 'hidden', |
| 1473 | 1473 | 'type' => 'string', |
@@ -1481,9 +1481,9 @@ discard block |
||
| 1481 | 1481 | } |
| 1482 | 1482 | continue; //skip the next stuff, we got the necessary fields here for this dataset. |
| 1483 | 1483 | } else { |
| 1484 | - $field_id = $template_field . '-content'; |
|
| 1484 | + $field_id = $template_field.'-content'; |
|
| 1485 | 1485 | $template_form_fields[$field_id] = $field_setup_array; |
| 1486 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1486 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1487 | 1487 | $message_template = isset($message_templates[$context][$template_field]) |
| 1488 | 1488 | ? $message_templates[$context][$template_field] |
| 1489 | 1489 | : null; |
@@ -1506,7 +1506,7 @@ discard block |
||
| 1506 | 1506 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
| 1507 | 1507 | && in_array($template_field, $v_fields, true) |
| 1508 | 1508 | && isset($validators[$template_field]['msg']) |
| 1509 | - ? 'validate-error ' . $css_class |
|
| 1509 | + ? 'validate-error '.$css_class |
|
| 1510 | 1510 | : $css_class; |
| 1511 | 1511 | |
| 1512 | 1512 | //shortcode selector |
@@ -1517,12 +1517,12 @@ discard block |
||
| 1517 | 1517 | |
| 1518 | 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 | 1523 | //foreach template field there are actually two form fields created |
| 1524 | 1524 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1525 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1525 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1526 | 1526 | 'label' => null, |
| 1527 | 1527 | 'input' => 'hidden', |
| 1528 | 1528 | 'type' => 'int', |
@@ -1535,7 +1535,7 @@ discard block |
||
| 1535 | 1535 | ); |
| 1536 | 1536 | |
| 1537 | 1537 | $template_form_fields[$templatefield_field_templatename_id] = array( |
| 1538 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1538 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1539 | 1539 | 'label' => null, |
| 1540 | 1540 | 'input' => 'hidden', |
| 1541 | 1541 | 'type' => 'string', |
@@ -1653,7 +1653,7 @@ discard block |
||
| 1653 | 1653 | 'format' => '%d', |
| 1654 | 1654 | 'db-col' => 'MTP_deleted' |
| 1655 | 1655 | ); |
| 1656 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1656 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1657 | 1657 | 'name' => 'MTP_user_id', |
| 1658 | 1658 | 'label' => esc_html__('Author', 'event_espresso'), |
| 1659 | 1659 | 'input' => 'hidden', |
@@ -1672,17 +1672,17 @@ discard block |
||
| 1672 | 1672 | 'value' => $action |
| 1673 | 1673 | ); |
| 1674 | 1674 | |
| 1675 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1675 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1676 | 1676 | 'name' => 'id', |
| 1677 | 1677 | 'input' => 'hidden', |
| 1678 | 1678 | 'type' => 'int', |
| 1679 | 1679 | 'value' => $GRP_ID |
| 1680 | 1680 | ); |
| 1681 | 1681 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1682 | - 'name' => $action . '_nonce', |
|
| 1682 | + 'name' => $action.'_nonce', |
|
| 1683 | 1683 | 'input' => 'hidden', |
| 1684 | 1684 | 'type' => 'string', |
| 1685 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1685 | + 'value' => wp_create_nonce($action.'_nonce') |
|
| 1686 | 1686 | ); |
| 1687 | 1687 | |
| 1688 | 1688 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1714,7 +1714,7 @@ discard block |
||
| 1714 | 1714 | ); |
| 1715 | 1715 | |
| 1716 | 1716 | //add preview button |
| 1717 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1717 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1718 | 1718 | array( |
| 1719 | 1719 | 'message_type' => $message_template_group->message_type(), |
| 1720 | 1720 | 'messenger' => $message_template_group->messenger(), |
@@ -1724,7 +1724,7 @@ discard block |
||
| 1724 | 1724 | ), |
| 1725 | 1725 | $this->_admin_base_url |
| 1726 | 1726 | ); |
| 1727 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1727 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">' |
|
| 1728 | 1728 | . esc_html__('Preview', 'event_espresso') |
| 1729 | 1729 | . '</a>'; |
| 1730 | 1730 | |
@@ -1761,7 +1761,7 @@ discard block |
||
| 1761 | 1761 | |
| 1762 | 1762 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1763 | 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'; |
|
| 1764 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1765 | 1765 | |
| 1766 | 1766 | //send along EE_Message_Template_Group object for further template use. |
| 1767 | 1767 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1816,7 +1816,7 @@ discard block |
||
| 1816 | 1816 | ) { |
| 1817 | 1817 | $template_args = array( |
| 1818 | 1818 | 'context' => $context, |
| 1819 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1819 | + 'nonce' => wp_create_nonce('activate_'.$context.'_toggle_nonce'), |
|
| 1820 | 1820 | 'is_active' => $message_template_group->is_context_active($context), |
| 1821 | 1821 | 'on_off_action' => $message_template_group->is_context_active($context) |
| 1822 | 1822 | ? 'context-off' |
@@ -1825,7 +1825,7 @@ discard block |
||
| 1825 | 1825 | 'message_template_group_id' => $message_template_group->ID() |
| 1826 | 1826 | ); |
| 1827 | 1827 | return EEH_Template::display_template( |
| 1828 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1828 | + EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php', |
|
| 1829 | 1829 | $template_args, |
| 1830 | 1830 | true |
| 1831 | 1831 | ); |
@@ -1845,7 +1845,7 @@ discard block |
||
| 1845 | 1845 | { |
| 1846 | 1846 | $success = true; |
| 1847 | 1847 | //check for required data |
| 1848 | - if (!isset( |
|
| 1848 | + if ( ! isset( |
|
| 1849 | 1849 | $this->_req_data['message_template_group_id'], |
| 1850 | 1850 | $this->_req_data['context'], |
| 1851 | 1851 | $this->_req_data['status'] |
@@ -1862,10 +1862,10 @@ discard block |
||
| 1862 | 1862 | $nonce = isset($this->_req_data['toggle_context_nonce']) |
| 1863 | 1863 | ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
| 1864 | 1864 | : ''; |
| 1865 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1865 | + $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce'; |
|
| 1866 | 1866 | $this->_verify_nonce($nonce, $nonce_ref); |
| 1867 | 1867 | $status = $this->_req_data['status']; |
| 1868 | - if ($status !== 'off' && $status !=='on') { |
|
| 1868 | + if ($status !== 'off' && $status !== 'on') { |
|
| 1869 | 1869 | EE_Error::add_error( |
| 1870 | 1870 | sprintf( |
| 1871 | 1871 | esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
@@ -1880,7 +1880,7 @@ discard block |
||
| 1880 | 1880 | $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
| 1881 | 1881 | $this->_req_data['message_template_group_id'] |
| 1882 | 1882 | ); |
| 1883 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1883 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1884 | 1884 | EE_Error::add_error( |
| 1885 | 1885 | sprintf( |
| 1886 | 1886 | esc_html__( |
@@ -2124,7 +2124,7 @@ discard block |
||
| 2124 | 2124 | } |
| 2125 | 2125 | |
| 2126 | 2126 | //let's add a button to go back to the edit view |
| 2127 | - $query_args = array( |
|
| 2127 | + $query_args = array( |
|
| 2128 | 2128 | 'id' => $this->_req_data['GRP_ID'], |
| 2129 | 2129 | 'context' => $this->_req_data['context'], |
| 2130 | 2130 | 'action' => 'edit_message_template' |
@@ -2150,7 +2150,7 @@ discard block |
||
| 2150 | 2150 | ); |
| 2151 | 2151 | //setup display of preview. |
| 2152 | 2152 | $this->_admin_page_title = $preview_title; |
| 2153 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2153 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview); |
|
| 2154 | 2154 | $this->_template_args['data']['force_json'] = true; |
| 2155 | 2155 | |
| 2156 | 2156 | return ''; |
@@ -2256,7 +2256,7 @@ discard block |
||
| 2256 | 2256 | } |
| 2257 | 2257 | |
| 2258 | 2258 | //setup variation select values for the currently selected template. |
| 2259 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2259 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2260 | 2260 | $this->_message_template_group->messenger(), |
| 2261 | 2261 | $this->_message_template_group->message_type() |
| 2262 | 2262 | ); |
@@ -2270,12 +2270,12 @@ discard block |
||
| 2270 | 2270 | |
| 2271 | 2271 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
| 2272 | 2272 | |
| 2273 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2273 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2274 | 2274 | 'MTP_template_pack', |
| 2275 | 2275 | $tp_select_values, |
| 2276 | 2276 | $this->_message_template_group->get_template_pack_name() |
| 2277 | 2277 | ); |
| 2278 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2278 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2279 | 2279 | 'MTP_template_variation', |
| 2280 | 2280 | $variations_select_values, |
| 2281 | 2281 | $this->_message_template_group->get_template_pack_variation() |
@@ -2285,7 +2285,7 @@ discard block |
||
| 2285 | 2285 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 2286 | 2286 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 2287 | 2287 | |
| 2288 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2288 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 2289 | 2289 | |
| 2290 | 2290 | EEH_Template::display_template($template, $template_args); |
| 2291 | 2291 | } |
@@ -2314,14 +2314,14 @@ discard block |
||
| 2314 | 2314 | if ( ! empty($fields)) { |
| 2315 | 2315 | //yup there be fields |
| 2316 | 2316 | foreach ($fields as $field => $config) { |
| 2317 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2317 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 2318 | 2318 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 2319 | 2319 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2320 | 2320 | $default = isset($config['value']) ? $config['value'] : $default; |
| 2321 | 2321 | |
| 2322 | 2322 | // if type is hidden and the value is empty |
| 2323 | 2323 | // something may have gone wrong so let's correct with the defaults |
| 2324 | - $fix = $config['input'] === 'hidden' |
|
| 2324 | + $fix = $config['input'] === 'hidden' |
|
| 2325 | 2325 | && isset($existing[$field]) |
| 2326 | 2326 | && empty($existing[$field]) |
| 2327 | 2327 | ? $default |
@@ -2331,7 +2331,7 @@ discard block |
||
| 2331 | 2331 | : $fix; |
| 2332 | 2332 | |
| 2333 | 2333 | $template_form_fields[$field_id] = array( |
| 2334 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2334 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2335 | 2335 | 'label' => $config['label'], |
| 2336 | 2336 | 'input' => $config['input'], |
| 2337 | 2337 | 'type' => $config['type'], |
@@ -2399,7 +2399,7 @@ discard block |
||
| 2399 | 2399 | ); |
| 2400 | 2400 | |
| 2401 | 2401 | return EEH_Template::display_template( |
| 2402 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2402 | + EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2403 | 2403 | $template_args, |
| 2404 | 2404 | true |
| 2405 | 2405 | ); |
@@ -2424,7 +2424,7 @@ discard block |
||
| 2424 | 2424 | //$messenger = $this->_message_template_group->messenger_obj(); |
| 2425 | 2425 | //now let's set the content depending on the status of the shortcodes array |
| 2426 | 2426 | if (empty($shortcodes)) { |
| 2427 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2427 | + $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2428 | 2428 | echo $content; |
| 2429 | 2429 | } else { |
| 2430 | 2430 | //$alt = 0; |
@@ -2561,7 +2561,7 @@ discard block |
||
| 2561 | 2561 | <?php |
| 2562 | 2562 | } |
| 2563 | 2563 | //setup nonce_url |
| 2564 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2564 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2565 | 2565 | ?> |
| 2566 | 2566 | <select name="context"> |
| 2567 | 2567 | <?php |
@@ -2662,7 +2662,7 @@ discard block |
||
| 2662 | 2662 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2663 | 2663 | |
| 2664 | 2664 | $item_desc = $messenger_label && $message_type_label |
| 2665 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2665 | + ? $messenger_label.' '.$message_type_label.' '.$context.' ' |
|
| 2666 | 2666 | : ''; |
| 2667 | 2667 | $item_desc .= 'Message Template'; |
| 2668 | 2668 | $query_args = array(); |
@@ -2764,7 +2764,7 @@ discard block |
||
| 2764 | 2764 | //default setup for it. |
| 2765 | 2765 | //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
| 2766 | 2766 | $updated = $MTP->insert($message_template_fields); |
| 2767 | - if (! $updated || is_wp_error($updated)) { |
|
| 2767 | + if ( ! $updated || is_wp_error($updated)) { |
|
| 2768 | 2768 | EE_Error::add_error( |
| 2769 | 2769 | sprintf( |
| 2770 | 2770 | esc_html__('%s field could not be updated.', 'event_espresso'), |
@@ -3125,7 +3125,7 @@ discard block |
||
| 3125 | 3125 | : 'email'; |
| 3126 | 3126 | |
| 3127 | 3127 | //let's setup the messenger tabs |
| 3128 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3128 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3129 | 3129 | $this->_m_mt_settings['messenger_tabs'], |
| 3130 | 3130 | 'messenger_links', |
| 3131 | 3131 | '|', |
@@ -3193,10 +3193,10 @@ discard block |
||
| 3193 | 3193 | |
| 3194 | 3194 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
| 3195 | 3195 | 'label' => ucwords($message_type->label['singular']), |
| 3196 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3197 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3198 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3199 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3196 | + 'class' => 'message-type-'.$a_or_i, |
|
| 3197 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 3198 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 3199 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 3200 | 3200 | 'title' => $a_or_i === 'active' |
| 3201 | 3201 | ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 3202 | 3202 | : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -3232,9 +3232,9 @@ discard block |
||
| 3232 | 3232 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 3233 | 3233 | |
| 3234 | 3234 | foreach ($fields as $fldname => $fldprops) { |
| 3235 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3235 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 3236 | 3236 | $template_form_field[$field_id] = array( |
| 3237 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3237 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 3238 | 3238 | 'label' => $fldprops['label'], |
| 3239 | 3239 | 'input' => $fldprops['field_type'], |
| 3240 | 3240 | 'type' => $fldprops['value_type'], |
@@ -3285,12 +3285,12 @@ discard block |
||
| 3285 | 3285 | $settings_template_args['hidden_fields'], |
| 3286 | 3286 | 'array' |
| 3287 | 3287 | ); |
| 3288 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3288 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3289 | 3289 | ? ' hidden' |
| 3290 | 3290 | : ''; |
| 3291 | 3291 | |
| 3292 | 3292 | |
| 3293 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3293 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 3294 | 3294 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 3295 | 3295 | |
| 3296 | 3296 | return $content; |
@@ -3325,11 +3325,11 @@ discard block |
||
| 3325 | 3325 | ) |
| 3326 | 3326 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
| 3327 | 3327 | : ''; |
| 3328 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3328 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 3329 | 3329 | esc_html__('%s Settings', 'event_espresso'), |
| 3330 | 3330 | $tab_array['label'] |
| 3331 | 3331 | ); |
| 3332 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 3332 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 3333 | 3333 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 3334 | 3334 | 'inactive_message_types' => isset( |
| 3335 | 3335 | $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
@@ -3345,8 +3345,8 @@ discard block |
||
| 3345 | 3345 | // message type meta boxes |
| 3346 | 3346 | // (which is really just the inactive container for each messenger |
| 3347 | 3347 | // showing inactive message types for that messenger) |
| 3348 | - $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3349 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3348 | + $mt_boxes[$messenger.'_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3349 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 3350 | 3350 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 3351 | 3351 | 'inactive_message_types' => isset( |
| 3352 | 3352 | $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
@@ -3364,14 +3364,14 @@ discard block |
||
| 3364 | 3364 | |
| 3365 | 3365 | |
| 3366 | 3366 | //register messenger metaboxes |
| 3367 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3367 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3368 | 3368 | foreach ($m_boxes as $box => $label) { |
| 3369 | 3369 | $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
| 3370 | 3370 | $msgr = str_replace('_a_box', '', $box); |
| 3371 | 3371 | add_meta_box( |
| 3372 | - 'espresso_' . $msgr . '_settings', |
|
| 3372 | + 'espresso_'.$msgr.'_settings', |
|
| 3373 | 3373 | $label, |
| 3374 | - function ($post, $metabox) { |
|
| 3374 | + function($post, $metabox) { |
|
| 3375 | 3375 | echo EEH_Template::display_template( |
| 3376 | 3376 | $metabox["args"]["template_path"], |
| 3377 | 3377 | $metabox["args"]["template_args"], |
@@ -3386,17 +3386,17 @@ discard block |
||
| 3386 | 3386 | } |
| 3387 | 3387 | |
| 3388 | 3388 | //register message type metaboxes |
| 3389 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3389 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3390 | 3390 | foreach ($mt_boxes as $box => $label) { |
| 3391 | 3391 | $callback_args = array( |
| 3392 | 3392 | 'template_path' => $mt_template_path, |
| 3393 | 3393 | 'template_args' => $mt_template_args[$box] |
| 3394 | 3394 | ); |
| 3395 | - $mt = str_replace('_i_box', '', $box); |
|
| 3395 | + $mt = str_replace('_i_box', '', $box); |
|
| 3396 | 3396 | add_meta_box( |
| 3397 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3397 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 3398 | 3398 | $label, |
| 3399 | - function ($post, $metabox) { |
|
| 3399 | + function($post, $metabox) { |
|
| 3400 | 3400 | echo EEH_Template::display_template( |
| 3401 | 3401 | $metabox["args"]["template_path"], |
| 3402 | 3402 | $metabox["args"]["template_args"], |
@@ -3543,7 +3543,7 @@ discard block |
||
| 3543 | 3543 | if ($form->is_valid()) { |
| 3544 | 3544 | $valid_data = $form->valid_data(); |
| 3545 | 3545 | foreach ($valid_data as $property => $value) { |
| 3546 | - $setter = 'set_' . $property; |
|
| 3546 | + $setter = 'set_'.$property; |
|
| 3547 | 3547 | if (method_exists($network_config, $setter)) { |
| 3548 | 3548 | $network_config->{$setter}($value); |
| 3549 | 3549 | } else if ( |
@@ -3578,8 +3578,8 @@ discard block |
||
| 3578 | 3578 | */ |
| 3579 | 3579 | protected function _get_mt_tabs($tab_array) |
| 3580 | 3580 | { |
| 3581 | - $tab_array = (array)$tab_array; |
|
| 3582 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3581 | + $tab_array = (array) $tab_array; |
|
| 3582 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3583 | 3583 | $tabs = ''; |
| 3584 | 3584 | |
| 3585 | 3585 | foreach ($tab_array as $tab) { |
@@ -3612,9 +3612,9 @@ discard block |
||
| 3612 | 3612 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3613 | 3613 | |
| 3614 | 3614 | foreach ($fields as $fldname => $fldprops) { |
| 3615 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3615 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3616 | 3616 | $template_form_field[$field_id] = array( |
| 3617 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3617 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3618 | 3618 | 'label' => $fldprops['label'], |
| 3619 | 3619 | 'input' => $fldprops['field_type'], |
| 3620 | 3620 | 'type' => $fldprops['value_type'], |
@@ -3649,7 +3649,7 @@ discard block |
||
| 3649 | 3649 | //make sure any active message types that are existing are included in the hidden fields |
| 3650 | 3650 | if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
| 3651 | 3651 | foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
| 3652 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3652 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3653 | 3653 | 'type' => 'hidden', |
| 3654 | 3654 | 'value' => $mt |
| 3655 | 3655 | ); |
@@ -3678,9 +3678,9 @@ discard block |
||
| 3678 | 3678 | |
| 3679 | 3679 | |
| 3680 | 3680 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3681 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3681 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3682 | 3682 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3683 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3683 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3684 | 3684 | $content = EEH_Template::display_template( |
| 3685 | 3685 | $template, |
| 3686 | 3686 | $settings_template_args, |
@@ -3720,7 +3720,7 @@ discard block |
||
| 3720 | 3720 | $nonce = isset($this->_req_data['activate_nonce']) |
| 3721 | 3721 | ? sanitize_text_field($this->_req_data['activate_nonce']) |
| 3722 | 3722 | : ''; |
| 3723 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3723 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3724 | 3724 | |
| 3725 | 3725 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3726 | 3726 | |
@@ -3836,7 +3836,7 @@ discard block |
||
| 3836 | 3836 | |
| 3837 | 3837 | //do a nonce check here since we're not arriving via a normal route |
| 3838 | 3838 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3839 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3839 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3840 | 3840 | |
| 3841 | 3841 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3842 | 3842 | |
@@ -4197,7 +4197,7 @@ discard block |
||
| 4197 | 4197 | $message_type = $message_types[$this->_req_data['message_type']]; |
| 4198 | 4198 | $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 4199 | 4199 | |
| 4200 | - $content = $this->_message_type_settings_content( |
|
| 4200 | + $content = $this->_message_type_settings_content( |
|
| 4201 | 4201 | $message_type, |
| 4202 | 4202 | $messenger, |
| 4203 | 4203 | true |
@@ -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,2557 +23,2557 @@ 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 | - */ |
|
| 81 | - public function __construct($routing = true) |
|
| 82 | - { |
|
| 83 | - //make sure messages autoloader is running |
|
| 84 | - EED_Messages::set_autoloaders(); |
|
| 85 | - parent::__construct($routing); |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * @param bool $routing |
|
| 80 | + */ |
|
| 81 | + public function __construct($routing = true) |
|
| 82 | + { |
|
| 83 | + //make sure messages autoloader is running |
|
| 84 | + EED_Messages::set_autoloaders(); |
|
| 85 | + parent::__construct($routing); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - protected function _init_page_props() |
|
| 90 | - { |
|
| 91 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 92 | - $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 93 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 94 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 95 | - |
|
| 96 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 97 | - |
|
| 98 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 99 | - $this->_load_message_resource_manager(); |
|
| 100 | - } |
|
| 89 | + protected function _init_page_props() |
|
| 90 | + { |
|
| 91 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 92 | + $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 93 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 94 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 95 | + |
|
| 96 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 97 | + |
|
| 98 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 99 | + $this->_load_message_resource_manager(); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 105 | - * |
|
| 106 | - * @throws EE_Error |
|
| 107 | - * @throws InvalidDataTypeException |
|
| 108 | - * @throws InvalidInterfaceException |
|
| 109 | - * @throws InvalidArgumentException |
|
| 110 | - * @throws ReflectionException |
|
| 111 | - */ |
|
| 112 | - protected function _load_message_resource_manager() |
|
| 113 | - { |
|
| 114 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 115 | - } |
|
| 103 | + /** |
|
| 104 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 105 | + * |
|
| 106 | + * @throws EE_Error |
|
| 107 | + * @throws InvalidDataTypeException |
|
| 108 | + * @throws InvalidInterfaceException |
|
| 109 | + * @throws InvalidArgumentException |
|
| 110 | + * @throws ReflectionException |
|
| 111 | + */ |
|
| 112 | + protected function _load_message_resource_manager() |
|
| 113 | + { |
|
| 114 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @deprecated 4.9.9.rc.014 |
|
| 120 | - * @return array |
|
| 121 | - * @throws EE_Error |
|
| 122 | - * @throws InvalidArgumentException |
|
| 123 | - * @throws InvalidDataTypeException |
|
| 124 | - * @throws InvalidInterfaceException |
|
| 125 | - */ |
|
| 126 | - public function get_messengers_for_list_table() |
|
| 127 | - { |
|
| 128 | - EE_Error::doing_it_wrong( |
|
| 129 | - __METHOD__, |
|
| 130 | - sprintf( |
|
| 131 | - esc_html__( |
|
| 132 | - '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', |
|
| 133 | - 'event_espresso' |
|
| 134 | - ), |
|
| 135 | - 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 136 | - ), |
|
| 137 | - '4.9.9.rc.014' |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - $m_values = array(); |
|
| 141 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 142 | - //setup messengers for selects |
|
| 143 | - $i = 1; |
|
| 144 | - foreach ($active_messengers as $active_messenger) { |
|
| 145 | - if ($active_messenger instanceof EE_Message) { |
|
| 146 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 147 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 148 | - $i++; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $m_values; |
|
| 153 | - } |
|
| 118 | + /** |
|
| 119 | + * @deprecated 4.9.9.rc.014 |
|
| 120 | + * @return array |
|
| 121 | + * @throws EE_Error |
|
| 122 | + * @throws InvalidArgumentException |
|
| 123 | + * @throws InvalidDataTypeException |
|
| 124 | + * @throws InvalidInterfaceException |
|
| 125 | + */ |
|
| 126 | + public function get_messengers_for_list_table() |
|
| 127 | + { |
|
| 128 | + EE_Error::doing_it_wrong( |
|
| 129 | + __METHOD__, |
|
| 130 | + sprintf( |
|
| 131 | + esc_html__( |
|
| 132 | + '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', |
|
| 133 | + 'event_espresso' |
|
| 134 | + ), |
|
| 135 | + 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 136 | + ), |
|
| 137 | + '4.9.9.rc.014' |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + $m_values = array(); |
|
| 141 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 142 | + //setup messengers for selects |
|
| 143 | + $i = 1; |
|
| 144 | + foreach ($active_messengers as $active_messenger) { |
|
| 145 | + if ($active_messenger instanceof EE_Message) { |
|
| 146 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 147 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 148 | + $i++; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $m_values; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @deprecated 4.9.9.rc.014 |
|
| 158 | - * @return array |
|
| 159 | - * @throws EE_Error |
|
| 160 | - * @throws InvalidArgumentException |
|
| 161 | - * @throws InvalidDataTypeException |
|
| 162 | - * @throws InvalidInterfaceException |
|
| 163 | - */ |
|
| 164 | - public function get_message_types_for_list_table() |
|
| 165 | - { |
|
| 166 | - EE_Error::doing_it_wrong( |
|
| 167 | - __METHOD__, |
|
| 168 | - sprintf( |
|
| 169 | - esc_html__( |
|
| 170 | - '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', |
|
| 171 | - 'event_espresso' |
|
| 172 | - ), |
|
| 173 | - 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 174 | - ), |
|
| 175 | - '4.9.9.rc.014' |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - $mt_values = array(); |
|
| 179 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 180 | - $i = 1; |
|
| 181 | - foreach ($active_messages as $active_message) { |
|
| 182 | - if ($active_message instanceof EE_Message) { |
|
| 183 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 184 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 185 | - $i++; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return $mt_values; |
|
| 190 | - } |
|
| 156 | + /** |
|
| 157 | + * @deprecated 4.9.9.rc.014 |
|
| 158 | + * @return array |
|
| 159 | + * @throws EE_Error |
|
| 160 | + * @throws InvalidArgumentException |
|
| 161 | + * @throws InvalidDataTypeException |
|
| 162 | + * @throws InvalidInterfaceException |
|
| 163 | + */ |
|
| 164 | + public function get_message_types_for_list_table() |
|
| 165 | + { |
|
| 166 | + EE_Error::doing_it_wrong( |
|
| 167 | + __METHOD__, |
|
| 168 | + sprintf( |
|
| 169 | + esc_html__( |
|
| 170 | + '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', |
|
| 171 | + 'event_espresso' |
|
| 172 | + ), |
|
| 173 | + 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 174 | + ), |
|
| 175 | + '4.9.9.rc.014' |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + $mt_values = array(); |
|
| 179 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 180 | + $i = 1; |
|
| 181 | + foreach ($active_messages as $active_message) { |
|
| 182 | + if ($active_message instanceof EE_Message) { |
|
| 183 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 184 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 185 | + $i++; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $mt_values; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @deprecated 4.9.9.rc.014 |
|
| 195 | - * @return array |
|
| 196 | - * @throws EE_Error |
|
| 197 | - * @throws InvalidArgumentException |
|
| 198 | - * @throws InvalidDataTypeException |
|
| 199 | - * @throws InvalidInterfaceException |
|
| 200 | - */ |
|
| 201 | - public function get_contexts_for_message_types_for_list_table() |
|
| 202 | - { |
|
| 203 | - EE_Error::doing_it_wrong( |
|
| 204 | - __METHOD__, |
|
| 205 | - sprintf( |
|
| 206 | - esc_html__( |
|
| 207 | - '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', |
|
| 208 | - 'event_espresso' |
|
| 209 | - ), |
|
| 210 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 211 | - ), |
|
| 212 | - '4.9.9.rc.014' |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - $contexts = array(); |
|
| 216 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 217 | - foreach ($active_message_contexts as $active_message) { |
|
| 218 | - if ($active_message instanceof EE_Message) { |
|
| 219 | - $message_type = $active_message->message_type_object(); |
|
| 220 | - if ($message_type instanceof EE_message_type) { |
|
| 221 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 222 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 223 | - $contexts[$context] = $context_details['label']; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $contexts; |
|
| 230 | - } |
|
| 193 | + /** |
|
| 194 | + * @deprecated 4.9.9.rc.014 |
|
| 195 | + * @return array |
|
| 196 | + * @throws EE_Error |
|
| 197 | + * @throws InvalidArgumentException |
|
| 198 | + * @throws InvalidDataTypeException |
|
| 199 | + * @throws InvalidInterfaceException |
|
| 200 | + */ |
|
| 201 | + public function get_contexts_for_message_types_for_list_table() |
|
| 202 | + { |
|
| 203 | + EE_Error::doing_it_wrong( |
|
| 204 | + __METHOD__, |
|
| 205 | + sprintf( |
|
| 206 | + esc_html__( |
|
| 207 | + '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', |
|
| 208 | + 'event_espresso' |
|
| 209 | + ), |
|
| 210 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 211 | + ), |
|
| 212 | + '4.9.9.rc.014' |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + $contexts = array(); |
|
| 216 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 217 | + foreach ($active_message_contexts as $active_message) { |
|
| 218 | + if ($active_message instanceof EE_Message) { |
|
| 219 | + $message_type = $active_message->message_type_object(); |
|
| 220 | + if ($message_type instanceof EE_message_type) { |
|
| 221 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 222 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 223 | + $contexts[$context] = $context_details['label']; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $contexts; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Generate select input with provided messenger options array. |
|
| 235 | - * |
|
| 236 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 237 | - * labels. |
|
| 238 | - * @return string |
|
| 239 | - * @throws EE_Error |
|
| 240 | - */ |
|
| 241 | - public function get_messengers_select_input($messenger_options) |
|
| 242 | - { |
|
| 243 | - //if empty or just one value then just return an empty string |
|
| 244 | - if (empty($messenger_options) |
|
| 245 | - || ! is_array($messenger_options) |
|
| 246 | - || count($messenger_options) === 1 |
|
| 247 | - ) { |
|
| 248 | - return ''; |
|
| 249 | - } |
|
| 250 | - //merge in default |
|
| 251 | - $messenger_options = array_merge( |
|
| 252 | - array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 253 | - $messenger_options |
|
| 254 | - ); |
|
| 255 | - $input = new EE_Select_Input( |
|
| 256 | - $messenger_options, |
|
| 257 | - array( |
|
| 258 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 259 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 260 | - 'html_class' => 'wide', |
|
| 261 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 262 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | - : 'none_selected' |
|
| 264 | - ) |
|
| 265 | - ); |
|
| 266 | - |
|
| 267 | - return $input->get_html_for_input(); |
|
| 268 | - } |
|
| 233 | + /** |
|
| 234 | + * Generate select input with provided messenger options array. |
|
| 235 | + * |
|
| 236 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 237 | + * labels. |
|
| 238 | + * @return string |
|
| 239 | + * @throws EE_Error |
|
| 240 | + */ |
|
| 241 | + public function get_messengers_select_input($messenger_options) |
|
| 242 | + { |
|
| 243 | + //if empty or just one value then just return an empty string |
|
| 244 | + if (empty($messenger_options) |
|
| 245 | + || ! is_array($messenger_options) |
|
| 246 | + || count($messenger_options) === 1 |
|
| 247 | + ) { |
|
| 248 | + return ''; |
|
| 249 | + } |
|
| 250 | + //merge in default |
|
| 251 | + $messenger_options = array_merge( |
|
| 252 | + array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 253 | + $messenger_options |
|
| 254 | + ); |
|
| 255 | + $input = new EE_Select_Input( |
|
| 256 | + $messenger_options, |
|
| 257 | + array( |
|
| 258 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 259 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 260 | + 'html_class' => 'wide', |
|
| 261 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 262 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | + : 'none_selected' |
|
| 264 | + ) |
|
| 265 | + ); |
|
| 266 | + |
|
| 267 | + return $input->get_html_for_input(); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Generate select input with provided message type options array. |
|
| 273 | - * |
|
| 274 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 275 | - * message type labels |
|
| 276 | - * @return string |
|
| 277 | - * @throws EE_Error |
|
| 278 | - */ |
|
| 279 | - public function get_message_types_select_input($message_type_options) |
|
| 280 | - { |
|
| 281 | - //if empty or count of options is 1 then just return an empty string |
|
| 282 | - if (empty($message_type_options) |
|
| 283 | - || ! is_array($message_type_options) |
|
| 284 | - || count($message_type_options) === 1 |
|
| 285 | - ) { |
|
| 286 | - return ''; |
|
| 287 | - } |
|
| 288 | - //merge in default |
|
| 289 | - $message_type_options = array_merge( |
|
| 290 | - array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 291 | - $message_type_options |
|
| 292 | - ); |
|
| 293 | - $input = new EE_Select_Input( |
|
| 294 | - $message_type_options, |
|
| 295 | - array( |
|
| 296 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 297 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 298 | - 'html_class' => 'wide', |
|
| 299 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 300 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | - : 'none_selected', |
|
| 302 | - ) |
|
| 303 | - ); |
|
| 304 | - |
|
| 305 | - return $input->get_html_for_input(); |
|
| 306 | - } |
|
| 271 | + /** |
|
| 272 | + * Generate select input with provided message type options array. |
|
| 273 | + * |
|
| 274 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 275 | + * message type labels |
|
| 276 | + * @return string |
|
| 277 | + * @throws EE_Error |
|
| 278 | + */ |
|
| 279 | + public function get_message_types_select_input($message_type_options) |
|
| 280 | + { |
|
| 281 | + //if empty or count of options is 1 then just return an empty string |
|
| 282 | + if (empty($message_type_options) |
|
| 283 | + || ! is_array($message_type_options) |
|
| 284 | + || count($message_type_options) === 1 |
|
| 285 | + ) { |
|
| 286 | + return ''; |
|
| 287 | + } |
|
| 288 | + //merge in default |
|
| 289 | + $message_type_options = array_merge( |
|
| 290 | + array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 291 | + $message_type_options |
|
| 292 | + ); |
|
| 293 | + $input = new EE_Select_Input( |
|
| 294 | + $message_type_options, |
|
| 295 | + array( |
|
| 296 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 297 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 298 | + 'html_class' => 'wide', |
|
| 299 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 300 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | + : 'none_selected', |
|
| 302 | + ) |
|
| 303 | + ); |
|
| 304 | + |
|
| 305 | + return $input->get_html_for_input(); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Generate select input with provide message type contexts array. |
|
| 311 | - * |
|
| 312 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 313 | - * context label. |
|
| 314 | - * @return string |
|
| 315 | - * @throws EE_Error |
|
| 316 | - */ |
|
| 317 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 318 | - { |
|
| 319 | - //if empty or count of options is one then just return empty string |
|
| 320 | - if (empty($context_options) |
|
| 321 | - || ! is_array($context_options) |
|
| 322 | - || count($context_options) === 1 |
|
| 323 | - ) { |
|
| 324 | - return ''; |
|
| 325 | - } |
|
| 326 | - //merge in default |
|
| 327 | - $context_options = array_merge( |
|
| 328 | - array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 329 | - $context_options |
|
| 330 | - ); |
|
| 331 | - $input = new EE_Select_Input( |
|
| 332 | - $context_options, |
|
| 333 | - array( |
|
| 334 | - 'html_name' => 'ee_context_filter_by', |
|
| 335 | - 'html_id' => 'ee_context_filter_by', |
|
| 336 | - 'html_class' => 'wide', |
|
| 337 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 338 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 339 | - : 'none_selected', |
|
| 340 | - ) |
|
| 341 | - ); |
|
| 342 | - |
|
| 343 | - return $input->get_html_for_input(); |
|
| 344 | - } |
|
| 309 | + /** |
|
| 310 | + * Generate select input with provide message type contexts array. |
|
| 311 | + * |
|
| 312 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 313 | + * context label. |
|
| 314 | + * @return string |
|
| 315 | + * @throws EE_Error |
|
| 316 | + */ |
|
| 317 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 318 | + { |
|
| 319 | + //if empty or count of options is one then just return empty string |
|
| 320 | + if (empty($context_options) |
|
| 321 | + || ! is_array($context_options) |
|
| 322 | + || count($context_options) === 1 |
|
| 323 | + ) { |
|
| 324 | + return ''; |
|
| 325 | + } |
|
| 326 | + //merge in default |
|
| 327 | + $context_options = array_merge( |
|
| 328 | + array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 329 | + $context_options |
|
| 330 | + ); |
|
| 331 | + $input = new EE_Select_Input( |
|
| 332 | + $context_options, |
|
| 333 | + array( |
|
| 334 | + 'html_name' => 'ee_context_filter_by', |
|
| 335 | + 'html_id' => 'ee_context_filter_by', |
|
| 336 | + 'html_class' => 'wide', |
|
| 337 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 338 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 339 | + : 'none_selected', |
|
| 340 | + ) |
|
| 341 | + ); |
|
| 342 | + |
|
| 343 | + return $input->get_html_for_input(); |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | 346 | |
| 347 | - protected function _ajax_hooks() |
|
| 348 | - { |
|
| 349 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 350 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 351 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 352 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 353 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 354 | - add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 355 | - } |
|
| 347 | + protected function _ajax_hooks() |
|
| 348 | + { |
|
| 349 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 350 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 351 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 352 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 353 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 354 | + add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | |
| 358 | - protected function _define_page_props() |
|
| 359 | - { |
|
| 360 | - $this->_admin_page_title = $this->page_label; |
|
| 361 | - $this->_labels = array( |
|
| 362 | - 'buttons' => array( |
|
| 363 | - 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 364 | - 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 365 | - 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 366 | - ), |
|
| 367 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 368 | - ); |
|
| 369 | - } |
|
| 358 | + protected function _define_page_props() |
|
| 359 | + { |
|
| 360 | + $this->_admin_page_title = $this->page_label; |
|
| 361 | + $this->_labels = array( |
|
| 362 | + 'buttons' => array( |
|
| 363 | + 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 364 | + 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 365 | + 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 366 | + ), |
|
| 367 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 368 | + ); |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | 371 | |
| 372 | - /** |
|
| 373 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 374 | - * @access protected |
|
| 375 | - * @return void |
|
| 376 | - */ |
|
| 377 | - protected function _set_page_routes() |
|
| 378 | - { |
|
| 379 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 380 | - ? $this->_req_data['GRP_ID'] |
|
| 381 | - : 0; |
|
| 382 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 383 | - ? $this->_req_data['id'] |
|
| 384 | - : $grp_id; |
|
| 385 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 386 | - ? $this->_req_data['MSG_ID'] |
|
| 387 | - : 0; |
|
| 388 | - |
|
| 389 | - $this->_page_routes = array( |
|
| 390 | - 'default' => array( |
|
| 391 | - 'func' => '_message_queue_list_table', |
|
| 392 | - 'capability' => 'ee_read_global_messages' |
|
| 393 | - ), |
|
| 394 | - 'global_mtps' => array( |
|
| 395 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 396 | - 'capability' => 'ee_read_global_messages' |
|
| 397 | - ), |
|
| 398 | - 'custom_mtps' => array( |
|
| 399 | - 'func' => '_custom_mtps_preview', |
|
| 400 | - 'capability' => 'ee_read_messages' |
|
| 401 | - ), |
|
| 402 | - 'add_new_message_template' => array( |
|
| 403 | - 'func' => '_add_message_template', |
|
| 404 | - 'capability' => 'ee_edit_messages', |
|
| 405 | - 'noheader' => true |
|
| 406 | - ), |
|
| 407 | - 'edit_message_template' => array( |
|
| 408 | - 'func' => '_edit_message_template', |
|
| 409 | - 'capability' => 'ee_edit_message', |
|
| 410 | - 'obj_id' => $grp_id |
|
| 411 | - ), |
|
| 412 | - 'preview_message' => array( |
|
| 413 | - 'func' => '_preview_message', |
|
| 414 | - 'capability' => 'ee_read_message', |
|
| 415 | - 'obj_id' => $grp_id, |
|
| 416 | - 'noheader' => true, |
|
| 417 | - 'headers_sent_route' => 'display_preview_message' |
|
| 418 | - ), |
|
| 419 | - 'display_preview_message' => array( |
|
| 420 | - 'func' => '_display_preview_message', |
|
| 421 | - 'capability' => 'ee_read_message', |
|
| 422 | - 'obj_id' => $grp_id |
|
| 423 | - ), |
|
| 424 | - 'insert_message_template' => array( |
|
| 425 | - 'func' => '_insert_or_update_message_template', |
|
| 426 | - 'capability' => 'ee_edit_messages', |
|
| 427 | - 'args' => array('new_template' => true), |
|
| 428 | - 'noheader' => true |
|
| 429 | - ), |
|
| 430 | - 'update_message_template' => array( |
|
| 431 | - 'func' => '_insert_or_update_message_template', |
|
| 432 | - 'capability' => 'ee_edit_message', |
|
| 433 | - 'obj_id' => $grp_id, |
|
| 434 | - 'args' => array('new_template' => false), |
|
| 435 | - 'noheader' => true |
|
| 436 | - ), |
|
| 437 | - 'trash_message_template' => array( |
|
| 438 | - 'func' => '_trash_or_restore_message_template', |
|
| 439 | - 'capability' => 'ee_delete_message', |
|
| 440 | - 'obj_id' => $grp_id, |
|
| 441 | - 'args' => array('trash' => true, 'all' => true), |
|
| 442 | - 'noheader' => true |
|
| 443 | - ), |
|
| 444 | - 'trash_message_template_context' => array( |
|
| 445 | - 'func' => '_trash_or_restore_message_template', |
|
| 446 | - 'capability' => 'ee_delete_message', |
|
| 447 | - 'obj_id' => $grp_id, |
|
| 448 | - 'args' => array('trash' => true), |
|
| 449 | - 'noheader' => true |
|
| 450 | - ), |
|
| 451 | - 'restore_message_template' => array( |
|
| 452 | - 'func' => '_trash_or_restore_message_template', |
|
| 453 | - 'capability' => 'ee_delete_message', |
|
| 454 | - 'obj_id' => $grp_id, |
|
| 455 | - 'args' => array('trash' => false, 'all' => true), |
|
| 456 | - 'noheader' => true |
|
| 457 | - ), |
|
| 458 | - 'restore_message_template_context' => array( |
|
| 459 | - 'func' => '_trash_or_restore_message_template', |
|
| 460 | - 'capability' => 'ee_delete_message', |
|
| 461 | - 'obj_id' => $grp_id, |
|
| 462 | - 'args' => array('trash' => false), |
|
| 463 | - 'noheader' => true |
|
| 464 | - ), |
|
| 465 | - 'delete_message_template' => array( |
|
| 466 | - 'func' => '_delete_message_template', |
|
| 467 | - 'capability' => 'ee_delete_message', |
|
| 468 | - 'obj_id' => $grp_id, |
|
| 469 | - 'noheader' => true |
|
| 470 | - ), |
|
| 471 | - 'reset_to_default' => array( |
|
| 472 | - 'func' => '_reset_to_default_template', |
|
| 473 | - 'capability' => 'ee_edit_message', |
|
| 474 | - 'obj_id' => $grp_id, |
|
| 475 | - 'noheader' => true |
|
| 476 | - ), |
|
| 477 | - 'settings' => array( |
|
| 478 | - 'func' => '_settings', |
|
| 479 | - 'capability' => 'manage_options' |
|
| 480 | - ), |
|
| 481 | - 'update_global_settings' => array( |
|
| 482 | - 'func' => '_update_global_settings', |
|
| 483 | - 'capability' => 'manage_options', |
|
| 484 | - 'noheader' => true |
|
| 485 | - ), |
|
| 486 | - 'generate_now' => array( |
|
| 487 | - 'func' => '_generate_now', |
|
| 488 | - 'capability' => 'ee_send_message', |
|
| 489 | - 'noheader' => true |
|
| 490 | - ), |
|
| 491 | - 'generate_and_send_now' => array( |
|
| 492 | - 'func' => '_generate_and_send_now', |
|
| 493 | - 'capability' => 'ee_send_message', |
|
| 494 | - 'noheader' => true |
|
| 495 | - ), |
|
| 496 | - 'queue_for_resending' => array( |
|
| 497 | - 'func' => '_queue_for_resending', |
|
| 498 | - 'capability' => 'ee_send_message', |
|
| 499 | - 'noheader' => true |
|
| 500 | - ), |
|
| 501 | - 'send_now' => array( |
|
| 502 | - 'func' => '_send_now', |
|
| 503 | - 'capability' => 'ee_send_message', |
|
| 504 | - 'noheader' => true |
|
| 505 | - ), |
|
| 506 | - 'delete_ee_message' => array( |
|
| 507 | - 'func' => '_delete_ee_messages', |
|
| 508 | - 'capability' => 'ee_delete_messages', |
|
| 509 | - 'noheader' => true |
|
| 510 | - ), |
|
| 511 | - 'delete_ee_messages' => array( |
|
| 512 | - 'func' => '_delete_ee_messages', |
|
| 513 | - 'capability' => 'ee_delete_messages', |
|
| 514 | - 'noheader' => true, |
|
| 515 | - 'obj_id' => $msg_id |
|
| 516 | - ) |
|
| 517 | - ); |
|
| 518 | - } |
|
| 372 | + /** |
|
| 373 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 374 | + * @access protected |
|
| 375 | + * @return void |
|
| 376 | + */ |
|
| 377 | + protected function _set_page_routes() |
|
| 378 | + { |
|
| 379 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 380 | + ? $this->_req_data['GRP_ID'] |
|
| 381 | + : 0; |
|
| 382 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 383 | + ? $this->_req_data['id'] |
|
| 384 | + : $grp_id; |
|
| 385 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 386 | + ? $this->_req_data['MSG_ID'] |
|
| 387 | + : 0; |
|
| 388 | + |
|
| 389 | + $this->_page_routes = array( |
|
| 390 | + 'default' => array( |
|
| 391 | + 'func' => '_message_queue_list_table', |
|
| 392 | + 'capability' => 'ee_read_global_messages' |
|
| 393 | + ), |
|
| 394 | + 'global_mtps' => array( |
|
| 395 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 396 | + 'capability' => 'ee_read_global_messages' |
|
| 397 | + ), |
|
| 398 | + 'custom_mtps' => array( |
|
| 399 | + 'func' => '_custom_mtps_preview', |
|
| 400 | + 'capability' => 'ee_read_messages' |
|
| 401 | + ), |
|
| 402 | + 'add_new_message_template' => array( |
|
| 403 | + 'func' => '_add_message_template', |
|
| 404 | + 'capability' => 'ee_edit_messages', |
|
| 405 | + 'noheader' => true |
|
| 406 | + ), |
|
| 407 | + 'edit_message_template' => array( |
|
| 408 | + 'func' => '_edit_message_template', |
|
| 409 | + 'capability' => 'ee_edit_message', |
|
| 410 | + 'obj_id' => $grp_id |
|
| 411 | + ), |
|
| 412 | + 'preview_message' => array( |
|
| 413 | + 'func' => '_preview_message', |
|
| 414 | + 'capability' => 'ee_read_message', |
|
| 415 | + 'obj_id' => $grp_id, |
|
| 416 | + 'noheader' => true, |
|
| 417 | + 'headers_sent_route' => 'display_preview_message' |
|
| 418 | + ), |
|
| 419 | + 'display_preview_message' => array( |
|
| 420 | + 'func' => '_display_preview_message', |
|
| 421 | + 'capability' => 'ee_read_message', |
|
| 422 | + 'obj_id' => $grp_id |
|
| 423 | + ), |
|
| 424 | + 'insert_message_template' => array( |
|
| 425 | + 'func' => '_insert_or_update_message_template', |
|
| 426 | + 'capability' => 'ee_edit_messages', |
|
| 427 | + 'args' => array('new_template' => true), |
|
| 428 | + 'noheader' => true |
|
| 429 | + ), |
|
| 430 | + 'update_message_template' => array( |
|
| 431 | + 'func' => '_insert_or_update_message_template', |
|
| 432 | + 'capability' => 'ee_edit_message', |
|
| 433 | + 'obj_id' => $grp_id, |
|
| 434 | + 'args' => array('new_template' => false), |
|
| 435 | + 'noheader' => true |
|
| 436 | + ), |
|
| 437 | + 'trash_message_template' => array( |
|
| 438 | + 'func' => '_trash_or_restore_message_template', |
|
| 439 | + 'capability' => 'ee_delete_message', |
|
| 440 | + 'obj_id' => $grp_id, |
|
| 441 | + 'args' => array('trash' => true, 'all' => true), |
|
| 442 | + 'noheader' => true |
|
| 443 | + ), |
|
| 444 | + 'trash_message_template_context' => array( |
|
| 445 | + 'func' => '_trash_or_restore_message_template', |
|
| 446 | + 'capability' => 'ee_delete_message', |
|
| 447 | + 'obj_id' => $grp_id, |
|
| 448 | + 'args' => array('trash' => true), |
|
| 449 | + 'noheader' => true |
|
| 450 | + ), |
|
| 451 | + 'restore_message_template' => array( |
|
| 452 | + 'func' => '_trash_or_restore_message_template', |
|
| 453 | + 'capability' => 'ee_delete_message', |
|
| 454 | + 'obj_id' => $grp_id, |
|
| 455 | + 'args' => array('trash' => false, 'all' => true), |
|
| 456 | + 'noheader' => true |
|
| 457 | + ), |
|
| 458 | + 'restore_message_template_context' => array( |
|
| 459 | + 'func' => '_trash_or_restore_message_template', |
|
| 460 | + 'capability' => 'ee_delete_message', |
|
| 461 | + 'obj_id' => $grp_id, |
|
| 462 | + 'args' => array('trash' => false), |
|
| 463 | + 'noheader' => true |
|
| 464 | + ), |
|
| 465 | + 'delete_message_template' => array( |
|
| 466 | + 'func' => '_delete_message_template', |
|
| 467 | + 'capability' => 'ee_delete_message', |
|
| 468 | + 'obj_id' => $grp_id, |
|
| 469 | + 'noheader' => true |
|
| 470 | + ), |
|
| 471 | + 'reset_to_default' => array( |
|
| 472 | + 'func' => '_reset_to_default_template', |
|
| 473 | + 'capability' => 'ee_edit_message', |
|
| 474 | + 'obj_id' => $grp_id, |
|
| 475 | + 'noheader' => true |
|
| 476 | + ), |
|
| 477 | + 'settings' => array( |
|
| 478 | + 'func' => '_settings', |
|
| 479 | + 'capability' => 'manage_options' |
|
| 480 | + ), |
|
| 481 | + 'update_global_settings' => array( |
|
| 482 | + 'func' => '_update_global_settings', |
|
| 483 | + 'capability' => 'manage_options', |
|
| 484 | + 'noheader' => true |
|
| 485 | + ), |
|
| 486 | + 'generate_now' => array( |
|
| 487 | + 'func' => '_generate_now', |
|
| 488 | + 'capability' => 'ee_send_message', |
|
| 489 | + 'noheader' => true |
|
| 490 | + ), |
|
| 491 | + 'generate_and_send_now' => array( |
|
| 492 | + 'func' => '_generate_and_send_now', |
|
| 493 | + 'capability' => 'ee_send_message', |
|
| 494 | + 'noheader' => true |
|
| 495 | + ), |
|
| 496 | + 'queue_for_resending' => array( |
|
| 497 | + 'func' => '_queue_for_resending', |
|
| 498 | + 'capability' => 'ee_send_message', |
|
| 499 | + 'noheader' => true |
|
| 500 | + ), |
|
| 501 | + 'send_now' => array( |
|
| 502 | + 'func' => '_send_now', |
|
| 503 | + 'capability' => 'ee_send_message', |
|
| 504 | + 'noheader' => true |
|
| 505 | + ), |
|
| 506 | + 'delete_ee_message' => array( |
|
| 507 | + 'func' => '_delete_ee_messages', |
|
| 508 | + 'capability' => 'ee_delete_messages', |
|
| 509 | + 'noheader' => true |
|
| 510 | + ), |
|
| 511 | + 'delete_ee_messages' => array( |
|
| 512 | + 'func' => '_delete_ee_messages', |
|
| 513 | + 'capability' => 'ee_delete_messages', |
|
| 514 | + 'noheader' => true, |
|
| 515 | + 'obj_id' => $msg_id |
|
| 516 | + ) |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | 520 | |
| 521 | - protected function _set_page_config() |
|
| 522 | - { |
|
| 523 | - $this->_page_config = array( |
|
| 524 | - 'default' => array( |
|
| 525 | - 'nav' => array( |
|
| 526 | - 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 527 | - 'order' => 10 |
|
| 528 | - ), |
|
| 529 | - 'list_table' => 'EE_Message_List_Table', |
|
| 530 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 531 | - 'require_nonce' => false |
|
| 532 | - ), |
|
| 533 | - 'global_mtps' => array( |
|
| 534 | - 'nav' => array( |
|
| 535 | - 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 536 | - 'order' => 20 |
|
| 537 | - ), |
|
| 538 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 539 | - 'help_tabs' => array( |
|
| 540 | - 'messages_overview_help_tab' => array( |
|
| 541 | - 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 542 | - 'filename' => 'messages_overview' |
|
| 543 | - ), |
|
| 544 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 545 | - 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 546 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 547 | - ), |
|
| 548 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 549 | - 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 550 | - 'filename' => 'messages_overview_filters' |
|
| 551 | - ), |
|
| 552 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 553 | - 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 554 | - 'filename' => 'messages_overview_views' |
|
| 555 | - ), |
|
| 556 | - 'message_overview_message_types_help_tab' => array( |
|
| 557 | - 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 558 | - 'filename' => 'messages_overview_types' |
|
| 559 | - ), |
|
| 560 | - 'messages_overview_messengers_help_tab' => array( |
|
| 561 | - 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 562 | - 'filename' => 'messages_overview_messengers', |
|
| 563 | - ), |
|
| 564 | - ), |
|
| 565 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 566 | - 'require_nonce' => false |
|
| 567 | - ), |
|
| 568 | - 'custom_mtps' => array( |
|
| 569 | - 'nav' => array( |
|
| 570 | - 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 571 | - 'order' => 30 |
|
| 572 | - ), |
|
| 573 | - 'help_tabs' => array(), |
|
| 574 | - 'help_tour' => array(), |
|
| 575 | - 'require_nonce' => false |
|
| 576 | - ), |
|
| 577 | - 'add_new_message_template' => array( |
|
| 578 | - 'nav' => array( |
|
| 579 | - 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 580 | - 'order' => 5, |
|
| 581 | - 'persistent' => false |
|
| 582 | - ), |
|
| 583 | - 'require_nonce' => false |
|
| 584 | - ), |
|
| 585 | - 'edit_message_template' => array( |
|
| 586 | - 'labels' => array( |
|
| 587 | - 'buttons' => array( |
|
| 588 | - 'reset' => esc_html__('Reset Templates'), |
|
| 589 | - ), |
|
| 590 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 591 | - ), |
|
| 592 | - 'nav' => array( |
|
| 593 | - 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 594 | - 'order' => 5, |
|
| 595 | - 'persistent' => false, |
|
| 596 | - 'url' => '' |
|
| 597 | - ), |
|
| 598 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 599 | - 'has_metaboxes' => true, |
|
| 600 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 601 | - 'help_tabs' => array( |
|
| 602 | - 'edit_message_template' => array( |
|
| 603 | - 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 604 | - 'callback' => 'edit_message_template_help_tab' |
|
| 605 | - ), |
|
| 606 | - 'message_templates_help_tab' => array( |
|
| 607 | - 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 608 | - 'filename' => 'messages_templates' |
|
| 609 | - ), |
|
| 610 | - 'message_template_shortcodes' => array( |
|
| 611 | - 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 612 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 613 | - ), |
|
| 614 | - 'message_preview_help_tab' => array( |
|
| 615 | - 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 616 | - 'filename' => 'messages_preview' |
|
| 617 | - ), |
|
| 618 | - 'messages_overview_other_help_tab' => array( |
|
| 619 | - 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 620 | - 'filename' => 'messages_overview_other', |
|
| 621 | - ), |
|
| 622 | - ), |
|
| 623 | - 'require_nonce' => false |
|
| 624 | - ), |
|
| 625 | - 'display_preview_message' => array( |
|
| 626 | - 'nav' => array( |
|
| 627 | - 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 628 | - 'order' => 5, |
|
| 629 | - 'url' => '', |
|
| 630 | - 'persistent' => false |
|
| 631 | - ), |
|
| 632 | - 'help_tabs' => array( |
|
| 633 | - 'preview_message' => array( |
|
| 634 | - 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 635 | - 'callback' => 'preview_message_help_tab' |
|
| 636 | - ) |
|
| 637 | - ), |
|
| 638 | - 'require_nonce' => false |
|
| 639 | - ), |
|
| 640 | - 'settings' => array( |
|
| 641 | - 'nav' => array( |
|
| 642 | - 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 643 | - 'order' => 40 |
|
| 644 | - ), |
|
| 645 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 646 | - 'help_tabs' => array( |
|
| 647 | - 'messages_settings_help_tab' => array( |
|
| 648 | - 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 649 | - 'filename' => 'messages_settings' |
|
| 650 | - ), |
|
| 651 | - 'messages_settings_message_types_help_tab' => array( |
|
| 652 | - 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 653 | - 'filename' => 'messages_settings_message_types' |
|
| 654 | - ), |
|
| 655 | - 'messages_settings_messengers_help_tab' => array( |
|
| 656 | - 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 657 | - 'filename' => 'messages_settings_messengers' |
|
| 658 | - ), |
|
| 659 | - ), |
|
| 660 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 661 | - 'require_nonce' => false |
|
| 662 | - ) |
|
| 663 | - ); |
|
| 664 | - } |
|
| 521 | + protected function _set_page_config() |
|
| 522 | + { |
|
| 523 | + $this->_page_config = array( |
|
| 524 | + 'default' => array( |
|
| 525 | + 'nav' => array( |
|
| 526 | + 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 527 | + 'order' => 10 |
|
| 528 | + ), |
|
| 529 | + 'list_table' => 'EE_Message_List_Table', |
|
| 530 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 531 | + 'require_nonce' => false |
|
| 532 | + ), |
|
| 533 | + 'global_mtps' => array( |
|
| 534 | + 'nav' => array( |
|
| 535 | + 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 536 | + 'order' => 20 |
|
| 537 | + ), |
|
| 538 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 539 | + 'help_tabs' => array( |
|
| 540 | + 'messages_overview_help_tab' => array( |
|
| 541 | + 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 542 | + 'filename' => 'messages_overview' |
|
| 543 | + ), |
|
| 544 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 545 | + 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 546 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 547 | + ), |
|
| 548 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 549 | + 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 550 | + 'filename' => 'messages_overview_filters' |
|
| 551 | + ), |
|
| 552 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 553 | + 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 554 | + 'filename' => 'messages_overview_views' |
|
| 555 | + ), |
|
| 556 | + 'message_overview_message_types_help_tab' => array( |
|
| 557 | + 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 558 | + 'filename' => 'messages_overview_types' |
|
| 559 | + ), |
|
| 560 | + 'messages_overview_messengers_help_tab' => array( |
|
| 561 | + 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 562 | + 'filename' => 'messages_overview_messengers', |
|
| 563 | + ), |
|
| 564 | + ), |
|
| 565 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 566 | + 'require_nonce' => false |
|
| 567 | + ), |
|
| 568 | + 'custom_mtps' => array( |
|
| 569 | + 'nav' => array( |
|
| 570 | + 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 571 | + 'order' => 30 |
|
| 572 | + ), |
|
| 573 | + 'help_tabs' => array(), |
|
| 574 | + 'help_tour' => array(), |
|
| 575 | + 'require_nonce' => false |
|
| 576 | + ), |
|
| 577 | + 'add_new_message_template' => array( |
|
| 578 | + 'nav' => array( |
|
| 579 | + 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 580 | + 'order' => 5, |
|
| 581 | + 'persistent' => false |
|
| 582 | + ), |
|
| 583 | + 'require_nonce' => false |
|
| 584 | + ), |
|
| 585 | + 'edit_message_template' => array( |
|
| 586 | + 'labels' => array( |
|
| 587 | + 'buttons' => array( |
|
| 588 | + 'reset' => esc_html__('Reset Templates'), |
|
| 589 | + ), |
|
| 590 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 591 | + ), |
|
| 592 | + 'nav' => array( |
|
| 593 | + 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 594 | + 'order' => 5, |
|
| 595 | + 'persistent' => false, |
|
| 596 | + 'url' => '' |
|
| 597 | + ), |
|
| 598 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 599 | + 'has_metaboxes' => true, |
|
| 600 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 601 | + 'help_tabs' => array( |
|
| 602 | + 'edit_message_template' => array( |
|
| 603 | + 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 604 | + 'callback' => 'edit_message_template_help_tab' |
|
| 605 | + ), |
|
| 606 | + 'message_templates_help_tab' => array( |
|
| 607 | + 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 608 | + 'filename' => 'messages_templates' |
|
| 609 | + ), |
|
| 610 | + 'message_template_shortcodes' => array( |
|
| 611 | + 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 612 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 613 | + ), |
|
| 614 | + 'message_preview_help_tab' => array( |
|
| 615 | + 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 616 | + 'filename' => 'messages_preview' |
|
| 617 | + ), |
|
| 618 | + 'messages_overview_other_help_tab' => array( |
|
| 619 | + 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 620 | + 'filename' => 'messages_overview_other', |
|
| 621 | + ), |
|
| 622 | + ), |
|
| 623 | + 'require_nonce' => false |
|
| 624 | + ), |
|
| 625 | + 'display_preview_message' => array( |
|
| 626 | + 'nav' => array( |
|
| 627 | + 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 628 | + 'order' => 5, |
|
| 629 | + 'url' => '', |
|
| 630 | + 'persistent' => false |
|
| 631 | + ), |
|
| 632 | + 'help_tabs' => array( |
|
| 633 | + 'preview_message' => array( |
|
| 634 | + 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 635 | + 'callback' => 'preview_message_help_tab' |
|
| 636 | + ) |
|
| 637 | + ), |
|
| 638 | + 'require_nonce' => false |
|
| 639 | + ), |
|
| 640 | + 'settings' => array( |
|
| 641 | + 'nav' => array( |
|
| 642 | + 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 643 | + 'order' => 40 |
|
| 644 | + ), |
|
| 645 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 646 | + 'help_tabs' => array( |
|
| 647 | + 'messages_settings_help_tab' => array( |
|
| 648 | + 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 649 | + 'filename' => 'messages_settings' |
|
| 650 | + ), |
|
| 651 | + 'messages_settings_message_types_help_tab' => array( |
|
| 652 | + 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 653 | + 'filename' => 'messages_settings_message_types' |
|
| 654 | + ), |
|
| 655 | + 'messages_settings_messengers_help_tab' => array( |
|
| 656 | + 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 657 | + 'filename' => 'messages_settings_messengers' |
|
| 658 | + ), |
|
| 659 | + ), |
|
| 660 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 661 | + 'require_nonce' => false |
|
| 662 | + ) |
|
| 663 | + ); |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | |
| 667 | - protected function _add_screen_options() |
|
| 668 | - { |
|
| 669 | - //todo |
|
| 670 | - } |
|
| 667 | + protected function _add_screen_options() |
|
| 668 | + { |
|
| 669 | + //todo |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | 672 | |
| 673 | - protected function _add_screen_options_global_mtps() |
|
| 674 | - { |
|
| 675 | - /** |
|
| 676 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 677 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 678 | - */ |
|
| 679 | - $page_title = $this->_admin_page_title; |
|
| 680 | - $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 681 | - $this->_per_page_screen_option(); |
|
| 682 | - $this->_admin_page_title = $page_title; |
|
| 683 | - } |
|
| 673 | + protected function _add_screen_options_global_mtps() |
|
| 674 | + { |
|
| 675 | + /** |
|
| 676 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 677 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 678 | + */ |
|
| 679 | + $page_title = $this->_admin_page_title; |
|
| 680 | + $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 681 | + $this->_per_page_screen_option(); |
|
| 682 | + $this->_admin_page_title = $page_title; |
|
| 683 | + } |
|
| 684 | 684 | |
| 685 | 685 | |
| 686 | - protected function _add_screen_options_default() |
|
| 687 | - { |
|
| 688 | - $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 689 | - $this->_per_page_screen_option(); |
|
| 690 | - } |
|
| 686 | + protected function _add_screen_options_default() |
|
| 687 | + { |
|
| 688 | + $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 689 | + $this->_per_page_screen_option(); |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | 692 | |
| 693 | - //none of the below group are currently used for Messages |
|
| 694 | - protected function _add_feature_pointers() |
|
| 695 | - { |
|
| 696 | - } |
|
| 693 | + //none of the below group are currently used for Messages |
|
| 694 | + protected function _add_feature_pointers() |
|
| 695 | + { |
|
| 696 | + } |
|
| 697 | 697 | |
| 698 | - public function admin_init() |
|
| 699 | - { |
|
| 700 | - } |
|
| 698 | + public function admin_init() |
|
| 699 | + { |
|
| 700 | + } |
|
| 701 | 701 | |
| 702 | - public function admin_notices() |
|
| 703 | - { |
|
| 704 | - } |
|
| 702 | + public function admin_notices() |
|
| 703 | + { |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | - public function admin_footer_scripts() |
|
| 707 | - { |
|
| 708 | - } |
|
| 706 | + public function admin_footer_scripts() |
|
| 707 | + { |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | 710 | |
| 711 | - public function messages_help_tab() |
|
| 712 | - { |
|
| 713 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 714 | - } |
|
| 711 | + public function messages_help_tab() |
|
| 712 | + { |
|
| 713 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | 716 | |
| 717 | - public function messengers_help_tab() |
|
| 718 | - { |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 720 | - } |
|
| 717 | + public function messengers_help_tab() |
|
| 718 | + { |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | 722 | |
| 723 | - public function message_types_help_tab() |
|
| 724 | - { |
|
| 725 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 726 | - } |
|
| 723 | + public function message_types_help_tab() |
|
| 724 | + { |
|
| 725 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 726 | + } |
|
| 727 | 727 | |
| 728 | 728 | |
| 729 | - public function messages_overview_help_tab() |
|
| 730 | - { |
|
| 731 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 732 | - } |
|
| 729 | + public function messages_overview_help_tab() |
|
| 730 | + { |
|
| 731 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 732 | + } |
|
| 733 | 733 | |
| 734 | 734 | |
| 735 | - public function message_templates_help_tab() |
|
| 736 | - { |
|
| 737 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 738 | - } |
|
| 735 | + public function message_templates_help_tab() |
|
| 736 | + { |
|
| 737 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | 740 | |
| 741 | - public function edit_message_template_help_tab() |
|
| 742 | - { |
|
| 743 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 744 | - . esc_attr__('Editor Title', 'event_espresso') |
|
| 745 | - . '" />'; |
|
| 746 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 747 | - . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 748 | - . '" />'; |
|
| 749 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 750 | - . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 751 | - . '" />'; |
|
| 752 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 753 | - . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 754 | - . '" />'; |
|
| 755 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 756 | - . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 757 | - . '" />'; |
|
| 758 | - EEH_Template::display_template( |
|
| 759 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 760 | - $args |
|
| 761 | - ); |
|
| 762 | - } |
|
| 741 | + public function edit_message_template_help_tab() |
|
| 742 | + { |
|
| 743 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 744 | + . esc_attr__('Editor Title', 'event_espresso') |
|
| 745 | + . '" />'; |
|
| 746 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 747 | + . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 748 | + . '" />'; |
|
| 749 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 750 | + . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 751 | + . '" />'; |
|
| 752 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 753 | + . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 754 | + . '" />'; |
|
| 755 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 756 | + . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 757 | + . '" />'; |
|
| 758 | + EEH_Template::display_template( |
|
| 759 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 760 | + $args |
|
| 761 | + ); |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | 764 | |
| 765 | - public function message_template_shortcodes_help_tab() |
|
| 766 | - { |
|
| 767 | - $this->_set_shortcodes(); |
|
| 768 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 769 | - EEH_Template::display_template( |
|
| 770 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 771 | - $args |
|
| 772 | - ); |
|
| 773 | - } |
|
| 765 | + public function message_template_shortcodes_help_tab() |
|
| 766 | + { |
|
| 767 | + $this->_set_shortcodes(); |
|
| 768 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 769 | + EEH_Template::display_template( |
|
| 770 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 771 | + $args |
|
| 772 | + ); |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | 775 | |
| 776 | - public function preview_message_help_tab() |
|
| 777 | - { |
|
| 778 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 779 | - } |
|
| 776 | + public function preview_message_help_tab() |
|
| 777 | + { |
|
| 778 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | 781 | |
| 782 | - public function settings_help_tab() |
|
| 783 | - { |
|
| 784 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 785 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 786 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 787 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 788 | - $args['img3'] = '<div class="switch">' |
|
| 789 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 790 | - . ' type="checkbox" checked="checked">' |
|
| 791 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 792 | - . '</div>'; |
|
| 793 | - $args['img4'] = '<div class="switch">' |
|
| 794 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 795 | - . ' type="checkbox">' |
|
| 796 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 797 | - . '</div>'; |
|
| 798 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 799 | - } |
|
| 782 | + public function settings_help_tab() |
|
| 783 | + { |
|
| 784 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 785 | + . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 786 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 787 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 788 | + $args['img3'] = '<div class="switch">' |
|
| 789 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 790 | + . ' type="checkbox" checked="checked">' |
|
| 791 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 792 | + . '</div>'; |
|
| 793 | + $args['img4'] = '<div class="switch">' |
|
| 794 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 795 | + . ' type="checkbox">' |
|
| 796 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 797 | + . '</div>'; |
|
| 798 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | 801 | |
| 802 | - public function load_scripts_styles() |
|
| 803 | - { |
|
| 804 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 805 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 806 | - |
|
| 807 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 808 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 809 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 810 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 811 | - } |
|
| 802 | + public function load_scripts_styles() |
|
| 803 | + { |
|
| 804 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 805 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 806 | + |
|
| 807 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 808 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 809 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 810 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 811 | + } |
|
| 812 | 812 | |
| 813 | 813 | |
| 814 | - public function load_scripts_styles_default() |
|
| 815 | - { |
|
| 816 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 817 | - } |
|
| 814 | + public function load_scripts_styles_default() |
|
| 815 | + { |
|
| 816 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | 819 | |
| 820 | - public function wp_editor_css($mce_css) |
|
| 821 | - { |
|
| 822 | - //if we're on the edit_message_template route |
|
| 823 | - if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 824 | - $message_type_name = $this->_active_message_type_name; |
|
| 820 | + public function wp_editor_css($mce_css) |
|
| 821 | + { |
|
| 822 | + //if we're on the edit_message_template route |
|
| 823 | + if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 824 | + $message_type_name = $this->_active_message_type_name; |
|
| 825 | 825 | |
| 826 | - //we're going to REPLACE the existing mce css |
|
| 827 | - //we need to get the css file location from the active messenger |
|
| 828 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 829 | - 'wpeditor', $this->_variation); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - return $mce_css; |
|
| 833 | - } |
|
| 826 | + //we're going to REPLACE the existing mce css |
|
| 827 | + //we need to get the css file location from the active messenger |
|
| 828 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 829 | + 'wpeditor', $this->_variation); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + return $mce_css; |
|
| 833 | + } |
|
| 834 | 834 | |
| 835 | 835 | |
| 836 | - public function load_scripts_styles_edit_message_template() |
|
| 837 | - { |
|
| 838 | - |
|
| 839 | - $this->_set_shortcodes(); |
|
| 840 | - |
|
| 841 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 842 | - esc_html__( |
|
| 843 | - '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.', |
|
| 844 | - 'event_espresso' |
|
| 845 | - ), |
|
| 846 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 847 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 848 | - ); |
|
| 849 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 850 | - '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?', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ); |
|
| 853 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 854 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 855 | - 'event_espresso' |
|
| 856 | - ); |
|
| 857 | - |
|
| 858 | - wp_register_script( |
|
| 859 | - 'ee_msgs_edit_js', |
|
| 860 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 861 | - array('jquery'), |
|
| 862 | - EVENT_ESPRESSO_VERSION |
|
| 863 | - ); |
|
| 864 | - |
|
| 865 | - wp_enqueue_script('ee_admin_js'); |
|
| 866 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 867 | - |
|
| 868 | - //add in special css for tiny_mce |
|
| 869 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 870 | - } |
|
| 836 | + public function load_scripts_styles_edit_message_template() |
|
| 837 | + { |
|
| 838 | + |
|
| 839 | + $this->_set_shortcodes(); |
|
| 840 | + |
|
| 841 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 842 | + esc_html__( |
|
| 843 | + '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.', |
|
| 844 | + 'event_espresso' |
|
| 845 | + ), |
|
| 846 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 847 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 848 | + ); |
|
| 849 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 850 | + '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?', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ); |
|
| 853 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 854 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 855 | + 'event_espresso' |
|
| 856 | + ); |
|
| 857 | + |
|
| 858 | + wp_register_script( |
|
| 859 | + 'ee_msgs_edit_js', |
|
| 860 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 861 | + array('jquery'), |
|
| 862 | + EVENT_ESPRESSO_VERSION |
|
| 863 | + ); |
|
| 864 | + |
|
| 865 | + wp_enqueue_script('ee_admin_js'); |
|
| 866 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 867 | + |
|
| 868 | + //add in special css for tiny_mce |
|
| 869 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 870 | + } |
|
| 871 | 871 | |
| 872 | 872 | |
| 873 | - public function load_scripts_styles_display_preview_message() |
|
| 874 | - { |
|
| 875 | - |
|
| 876 | - $this->_set_message_template_group(); |
|
| 877 | - |
|
| 878 | - if (isset($this->_req_data['messenger'])) { |
|
| 879 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 880 | - $this->_req_data['messenger'] |
|
| 881 | - ); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - wp_enqueue_style('espresso_preview_css', |
|
| 888 | - $this->_active_messenger->get_variation( |
|
| 889 | - $this->_template_pack, |
|
| 890 | - $message_type_name, |
|
| 891 | - true, |
|
| 892 | - 'preview', |
|
| 893 | - $this->_variation |
|
| 894 | - ) |
|
| 895 | - ); |
|
| 896 | - } |
|
| 873 | + public function load_scripts_styles_display_preview_message() |
|
| 874 | + { |
|
| 875 | + |
|
| 876 | + $this->_set_message_template_group(); |
|
| 877 | + |
|
| 878 | + if (isset($this->_req_data['messenger'])) { |
|
| 879 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 880 | + $this->_req_data['messenger'] |
|
| 881 | + ); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + wp_enqueue_style('espresso_preview_css', |
|
| 888 | + $this->_active_messenger->get_variation( |
|
| 889 | + $this->_template_pack, |
|
| 890 | + $message_type_name, |
|
| 891 | + true, |
|
| 892 | + 'preview', |
|
| 893 | + $this->_variation |
|
| 894 | + ) |
|
| 895 | + ); |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | 898 | |
| 899 | - public function load_scripts_styles_settings() |
|
| 900 | - { |
|
| 901 | - wp_register_style( |
|
| 902 | - 'ee-message-settings', |
|
| 903 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 904 | - array(), |
|
| 905 | - EVENT_ESPRESSO_VERSION |
|
| 906 | - ); |
|
| 907 | - wp_enqueue_style('ee-text-links'); |
|
| 908 | - wp_enqueue_style('ee-message-settings'); |
|
| 909 | - wp_enqueue_script('ee-messages-settings'); |
|
| 910 | - } |
|
| 899 | + public function load_scripts_styles_settings() |
|
| 900 | + { |
|
| 901 | + wp_register_style( |
|
| 902 | + 'ee-message-settings', |
|
| 903 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 904 | + array(), |
|
| 905 | + EVENT_ESPRESSO_VERSION |
|
| 906 | + ); |
|
| 907 | + wp_enqueue_style('ee-text-links'); |
|
| 908 | + wp_enqueue_style('ee-message-settings'); |
|
| 909 | + wp_enqueue_script('ee-messages-settings'); |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | 912 | |
| 913 | - /** |
|
| 914 | - * set views array for List Table |
|
| 915 | - */ |
|
| 916 | - public function _set_list_table_views_global_mtps() |
|
| 917 | - { |
|
| 918 | - $this->_views = array( |
|
| 919 | - 'in_use' => array( |
|
| 920 | - 'slug' => 'in_use', |
|
| 921 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 922 | - 'count' => 0, |
|
| 923 | - ) |
|
| 924 | - ); |
|
| 925 | - } |
|
| 913 | + /** |
|
| 914 | + * set views array for List Table |
|
| 915 | + */ |
|
| 916 | + public function _set_list_table_views_global_mtps() |
|
| 917 | + { |
|
| 918 | + $this->_views = array( |
|
| 919 | + 'in_use' => array( |
|
| 920 | + 'slug' => 'in_use', |
|
| 921 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 922 | + 'count' => 0, |
|
| 923 | + ) |
|
| 924 | + ); |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | 927 | |
| 928 | - /** |
|
| 929 | - * Set views array for the Custom Template List Table |
|
| 930 | - */ |
|
| 931 | - public function _set_list_table_views_custom_mtps() |
|
| 932 | - { |
|
| 933 | - $this->_set_list_table_views_global_mtps(); |
|
| 934 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 935 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 936 | - ); |
|
| 937 | - } |
|
| 928 | + /** |
|
| 929 | + * Set views array for the Custom Template List Table |
|
| 930 | + */ |
|
| 931 | + public function _set_list_table_views_custom_mtps() |
|
| 932 | + { |
|
| 933 | + $this->_set_list_table_views_global_mtps(); |
|
| 934 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 935 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 936 | + ); |
|
| 937 | + } |
|
| 938 | 938 | |
| 939 | 939 | |
| 940 | - /** |
|
| 941 | - * set views array for message queue list table |
|
| 942 | - * |
|
| 943 | - * @throws InvalidDataTypeException |
|
| 944 | - * @throws InvalidInterfaceException |
|
| 945 | - * @throws InvalidArgumentException |
|
| 946 | - * @throws EE_Error |
|
| 947 | - * @throws ReflectionException |
|
| 948 | - */ |
|
| 949 | - public function _set_list_table_views_default() |
|
| 950 | - { |
|
| 951 | - EE_Registry::instance()->load_helper('Template'); |
|
| 952 | - |
|
| 953 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 954 | - 'ee_send_message', |
|
| 955 | - 'message_list_table_bulk_actions' |
|
| 956 | - ) |
|
| 957 | - ? array( |
|
| 958 | - 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 959 | - 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 960 | - 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 961 | - 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 962 | - ) |
|
| 963 | - : array(); |
|
| 964 | - |
|
| 965 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 966 | - 'ee_delete_messages', |
|
| 967 | - 'message_list_table_bulk_actions' |
|
| 968 | - ) |
|
| 969 | - ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 970 | - : array(); |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - $this->_views = array( |
|
| 974 | - 'all' => array( |
|
| 975 | - 'slug' => 'all', |
|
| 976 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 977 | - 'count' => 0, |
|
| 978 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 979 | - ) |
|
| 980 | - ); |
|
| 981 | - |
|
| 982 | - |
|
| 983 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 984 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 985 | - continue; |
|
| 986 | - } |
|
| 987 | - $status_bulk_actions = $common_bulk_actions; |
|
| 988 | - //unset bulk actions not applying to status |
|
| 989 | - if (! empty($status_bulk_actions)) { |
|
| 990 | - switch ($status) { |
|
| 991 | - case EEM_Message::status_idle: |
|
| 992 | - case EEM_Message::status_resend: |
|
| 993 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 994 | - break; |
|
| 940 | + /** |
|
| 941 | + * set views array for message queue list table |
|
| 942 | + * |
|
| 943 | + * @throws InvalidDataTypeException |
|
| 944 | + * @throws InvalidInterfaceException |
|
| 945 | + * @throws InvalidArgumentException |
|
| 946 | + * @throws EE_Error |
|
| 947 | + * @throws ReflectionException |
|
| 948 | + */ |
|
| 949 | + public function _set_list_table_views_default() |
|
| 950 | + { |
|
| 951 | + EE_Registry::instance()->load_helper('Template'); |
|
| 952 | + |
|
| 953 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 954 | + 'ee_send_message', |
|
| 955 | + 'message_list_table_bulk_actions' |
|
| 956 | + ) |
|
| 957 | + ? array( |
|
| 958 | + 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 959 | + 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 960 | + 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 961 | + 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 962 | + ) |
|
| 963 | + : array(); |
|
| 964 | + |
|
| 965 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 966 | + 'ee_delete_messages', |
|
| 967 | + 'message_list_table_bulk_actions' |
|
| 968 | + ) |
|
| 969 | + ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 970 | + : array(); |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + $this->_views = array( |
|
| 974 | + 'all' => array( |
|
| 975 | + 'slug' => 'all', |
|
| 976 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 977 | + 'count' => 0, |
|
| 978 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 979 | + ) |
|
| 980 | + ); |
|
| 981 | + |
|
| 982 | + |
|
| 983 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 984 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 985 | + continue; |
|
| 986 | + } |
|
| 987 | + $status_bulk_actions = $common_bulk_actions; |
|
| 988 | + //unset bulk actions not applying to status |
|
| 989 | + if (! empty($status_bulk_actions)) { |
|
| 990 | + switch ($status) { |
|
| 991 | + case EEM_Message::status_idle: |
|
| 992 | + case EEM_Message::status_resend: |
|
| 993 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 994 | + break; |
|
| 995 | 995 | |
| 996 | - case EEM_Message::status_failed: |
|
| 997 | - case EEM_Message::status_debug_only: |
|
| 998 | - case EEM_Message::status_messenger_executing: |
|
| 999 | - $status_bulk_actions = array(); |
|
| 1000 | - break; |
|
| 996 | + case EEM_Message::status_failed: |
|
| 997 | + case EEM_Message::status_debug_only: |
|
| 998 | + case EEM_Message::status_messenger_executing: |
|
| 999 | + $status_bulk_actions = array(); |
|
| 1000 | + break; |
|
| 1001 | 1001 | |
| 1002 | - case EEM_Message::status_incomplete: |
|
| 1003 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1004 | - break; |
|
| 1002 | + case EEM_Message::status_incomplete: |
|
| 1003 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1004 | + break; |
|
| 1005 | 1005 | |
| 1006 | - case EEM_Message::status_retry: |
|
| 1007 | - case EEM_Message::status_sent: |
|
| 1008 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1009 | - break; |
|
| 1010 | - } |
|
| 1011 | - } |
|
| 1006 | + case EEM_Message::status_retry: |
|
| 1007 | + case EEM_Message::status_sent: |
|
| 1008 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1009 | + break; |
|
| 1010 | + } |
|
| 1011 | + } |
|
| 1012 | 1012 | |
| 1013 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1014 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1015 | - continue; |
|
| 1016 | - } |
|
| 1013 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1014 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1015 | + continue; |
|
| 1016 | + } |
|
| 1017 | 1017 | |
| 1018 | - $this->_views[strtolower($status)] = array( |
|
| 1019 | - 'slug' => strtolower($status), |
|
| 1020 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1021 | - 'count' => 0, |
|
| 1022 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1023 | - ); |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1018 | + $this->_views[strtolower($status)] = array( |
|
| 1019 | + 'slug' => strtolower($status), |
|
| 1020 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1021 | + 'count' => 0, |
|
| 1022 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1023 | + ); |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | 1026 | |
| 1027 | 1027 | |
| 1028 | - protected function _ee_default_messages_overview_list_table() |
|
| 1029 | - { |
|
| 1030 | - $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1031 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1032 | - } |
|
| 1028 | + protected function _ee_default_messages_overview_list_table() |
|
| 1029 | + { |
|
| 1030 | + $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1031 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1032 | + } |
|
| 1033 | 1033 | |
| 1034 | 1034 | |
| 1035 | - protected function _message_queue_list_table() |
|
| 1036 | - { |
|
| 1037 | - $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1038 | - $this->_template_args['per_column'] = 6; |
|
| 1039 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1040 | - $this->_template_args['before_list_table'] = '<h3>' |
|
| 1041 | - . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1042 | - . '</h3>'; |
|
| 1043 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1044 | - } |
|
| 1035 | + protected function _message_queue_list_table() |
|
| 1036 | + { |
|
| 1037 | + $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1038 | + $this->_template_args['per_column'] = 6; |
|
| 1039 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1040 | + $this->_template_args['before_list_table'] = '<h3>' |
|
| 1041 | + . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1042 | + . '</h3>'; |
|
| 1043 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | 1046 | |
| 1047 | - protected function _message_legend_items() |
|
| 1048 | - { |
|
| 1049 | - |
|
| 1050 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1051 | - $action_items = array(); |
|
| 1052 | - |
|
| 1053 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1054 | - if ($action_item === 'see_notifications_for') { |
|
| 1055 | - continue; |
|
| 1056 | - } |
|
| 1057 | - $action_items[$action_item] = array( |
|
| 1058 | - 'class' => $action_details['css_class'], |
|
| 1059 | - 'desc' => $action_details['label'] |
|
| 1060 | - ); |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - /** @type array $status_items status legend setup */ |
|
| 1064 | - $status_items = array( |
|
| 1065 | - 'sent_status' => array( |
|
| 1066 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1067 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1068 | - ), |
|
| 1069 | - 'idle_status' => array( |
|
| 1070 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1071 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1072 | - ), |
|
| 1073 | - 'failed_status' => array( |
|
| 1074 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1075 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1076 | - ), |
|
| 1077 | - 'messenger_executing_status' => array( |
|
| 1078 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1079 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1080 | - ), |
|
| 1081 | - 'resend_status' => array( |
|
| 1082 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1083 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1084 | - ), |
|
| 1085 | - 'incomplete_status' => array( |
|
| 1086 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1087 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1088 | - ), |
|
| 1089 | - 'retry_status' => array( |
|
| 1090 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1091 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1092 | - ) |
|
| 1093 | - ); |
|
| 1094 | - if (EEM_Message::debug()) { |
|
| 1095 | - $status_items['debug_only_status'] = array( |
|
| 1096 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1097 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1098 | - ); |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - return array_merge($action_items, $status_items); |
|
| 1102 | - } |
|
| 1047 | + protected function _message_legend_items() |
|
| 1048 | + { |
|
| 1049 | + |
|
| 1050 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1051 | + $action_items = array(); |
|
| 1052 | + |
|
| 1053 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1054 | + if ($action_item === 'see_notifications_for') { |
|
| 1055 | + continue; |
|
| 1056 | + } |
|
| 1057 | + $action_items[$action_item] = array( |
|
| 1058 | + 'class' => $action_details['css_class'], |
|
| 1059 | + 'desc' => $action_details['label'] |
|
| 1060 | + ); |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + /** @type array $status_items status legend setup */ |
|
| 1064 | + $status_items = array( |
|
| 1065 | + 'sent_status' => array( |
|
| 1066 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1067 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1068 | + ), |
|
| 1069 | + 'idle_status' => array( |
|
| 1070 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1071 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1072 | + ), |
|
| 1073 | + 'failed_status' => array( |
|
| 1074 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1075 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1076 | + ), |
|
| 1077 | + 'messenger_executing_status' => array( |
|
| 1078 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1079 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1080 | + ), |
|
| 1081 | + 'resend_status' => array( |
|
| 1082 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1083 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1084 | + ), |
|
| 1085 | + 'incomplete_status' => array( |
|
| 1086 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1087 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1088 | + ), |
|
| 1089 | + 'retry_status' => array( |
|
| 1090 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1091 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1092 | + ) |
|
| 1093 | + ); |
|
| 1094 | + if (EEM_Message::debug()) { |
|
| 1095 | + $status_items['debug_only_status'] = array( |
|
| 1096 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1097 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1098 | + ); |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + return array_merge($action_items, $status_items); |
|
| 1102 | + } |
|
| 1103 | 1103 | |
| 1104 | 1104 | |
| 1105 | - protected function _custom_mtps_preview() |
|
| 1106 | - { |
|
| 1107 | - $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1108 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1109 | - . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1110 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 1111 | - . esc_html__( |
|
| 1112 | - '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.', |
|
| 1113 | - 'event_espresso' |
|
| 1114 | - ) |
|
| 1115 | - . '</strong>'; |
|
| 1105 | + protected function _custom_mtps_preview() |
|
| 1106 | + { |
|
| 1107 | + $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1108 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1109 | + . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1110 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 1111 | + . esc_html__( |
|
| 1112 | + '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.', |
|
| 1113 | + 'event_espresso' |
|
| 1114 | + ) |
|
| 1115 | + . '</strong>'; |
|
| 1116 | 1116 | |
| 1117 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1118 | - } |
|
| 1117 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1118 | + } |
|
| 1119 | 1119 | |
| 1120 | 1120 | |
| 1121 | - /** |
|
| 1122 | - * get_message_templates |
|
| 1123 | - * This gets all the message templates for listing on the overview list. |
|
| 1124 | - * |
|
| 1125 | - * @access public |
|
| 1126 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1127 | - * @param string $type the current _view we're getting templates for |
|
| 1128 | - * @param bool $count return count? |
|
| 1129 | - * @param bool $all disregard any paging info (get all data); |
|
| 1130 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1131 | - * @return array |
|
| 1132 | - * @throws EE_Error |
|
| 1133 | - * @throws InvalidArgumentException |
|
| 1134 | - * @throws InvalidDataTypeException |
|
| 1135 | - * @throws InvalidInterfaceException |
|
| 1136 | - */ |
|
| 1137 | - public function get_message_templates( |
|
| 1138 | - $perpage = 10, |
|
| 1139 | - $type = 'in_use', |
|
| 1140 | - $count = false, |
|
| 1141 | - $all = false, |
|
| 1142 | - $global = true) |
|
| 1143 | - { |
|
| 1144 | - |
|
| 1145 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1146 | - |
|
| 1147 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1148 | - $orderby = $this->_req_data['orderby']; |
|
| 1149 | - |
|
| 1150 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1151 | - ? $this->_req_data['order'] |
|
| 1152 | - : 'ASC'; |
|
| 1153 | - |
|
| 1154 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1155 | - ? $this->_req_data['paged'] |
|
| 1156 | - : 1; |
|
| 1157 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1158 | - ? $this->_req_data['perpage'] |
|
| 1159 | - : $perpage; |
|
| 1160 | - |
|
| 1161 | - $offset = ($current_page - 1) * $per_page; |
|
| 1162 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1163 | - |
|
| 1164 | - |
|
| 1165 | - //options will match what is in the _views array property |
|
| 1166 | - switch ($type) { |
|
| 1167 | - case 'in_use': |
|
| 1168 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1169 | - break; |
|
| 1170 | - default: |
|
| 1171 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - return $templates; |
|
| 1175 | - } |
|
| 1121 | + /** |
|
| 1122 | + * get_message_templates |
|
| 1123 | + * This gets all the message templates for listing on the overview list. |
|
| 1124 | + * |
|
| 1125 | + * @access public |
|
| 1126 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1127 | + * @param string $type the current _view we're getting templates for |
|
| 1128 | + * @param bool $count return count? |
|
| 1129 | + * @param bool $all disregard any paging info (get all data); |
|
| 1130 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1131 | + * @return array |
|
| 1132 | + * @throws EE_Error |
|
| 1133 | + * @throws InvalidArgumentException |
|
| 1134 | + * @throws InvalidDataTypeException |
|
| 1135 | + * @throws InvalidInterfaceException |
|
| 1136 | + */ |
|
| 1137 | + public function get_message_templates( |
|
| 1138 | + $perpage = 10, |
|
| 1139 | + $type = 'in_use', |
|
| 1140 | + $count = false, |
|
| 1141 | + $all = false, |
|
| 1142 | + $global = true) |
|
| 1143 | + { |
|
| 1144 | + |
|
| 1145 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1146 | + |
|
| 1147 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1148 | + $orderby = $this->_req_data['orderby']; |
|
| 1149 | + |
|
| 1150 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1151 | + ? $this->_req_data['order'] |
|
| 1152 | + : 'ASC'; |
|
| 1153 | + |
|
| 1154 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1155 | + ? $this->_req_data['paged'] |
|
| 1156 | + : 1; |
|
| 1157 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1158 | + ? $this->_req_data['perpage'] |
|
| 1159 | + : $perpage; |
|
| 1160 | + |
|
| 1161 | + $offset = ($current_page - 1) * $per_page; |
|
| 1162 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1163 | + |
|
| 1164 | + |
|
| 1165 | + //options will match what is in the _views array property |
|
| 1166 | + switch ($type) { |
|
| 1167 | + case 'in_use': |
|
| 1168 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1169 | + break; |
|
| 1170 | + default: |
|
| 1171 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + return $templates; |
|
| 1175 | + } |
|
| 1176 | 1176 | |
| 1177 | 1177 | |
| 1178 | - /** |
|
| 1179 | - * filters etc might need a list of installed message_types |
|
| 1180 | - * @return array an array of message type objects |
|
| 1181 | - */ |
|
| 1182 | - public function get_installed_message_types() |
|
| 1183 | - { |
|
| 1184 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1185 | - $installed = array(); |
|
| 1186 | - |
|
| 1187 | - foreach ($installed_message_types as $message_type) { |
|
| 1188 | - $installed[$message_type->name] = $message_type; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - return $installed; |
|
| 1192 | - } |
|
| 1178 | + /** |
|
| 1179 | + * filters etc might need a list of installed message_types |
|
| 1180 | + * @return array an array of message type objects |
|
| 1181 | + */ |
|
| 1182 | + public function get_installed_message_types() |
|
| 1183 | + { |
|
| 1184 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1185 | + $installed = array(); |
|
| 1186 | + |
|
| 1187 | + foreach ($installed_message_types as $message_type) { |
|
| 1188 | + $installed[$message_type->name] = $message_type; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + return $installed; |
|
| 1192 | + } |
|
| 1193 | 1193 | |
| 1194 | 1194 | |
| 1195 | - /** |
|
| 1196 | - * _add_message_template |
|
| 1197 | - * |
|
| 1198 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1199 | - * |
|
| 1200 | - * @param string $message_type |
|
| 1201 | - * @param string $messenger |
|
| 1202 | - * @param string $GRP_ID |
|
| 1203 | - * |
|
| 1204 | - * @throws EE_error |
|
| 1205 | - */ |
|
| 1206 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1207 | - { |
|
| 1208 | - //set values override any request data |
|
| 1209 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1210 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1211 | - ? $this->_req_data['message_type'] |
|
| 1212 | - : $message_type; |
|
| 1213 | - |
|
| 1214 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1215 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1216 | - ? $this->_req_data['messenger'] |
|
| 1217 | - : $messenger; |
|
| 1218 | - |
|
| 1219 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1220 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1221 | - |
|
| 1222 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1223 | - if (empty($message_type) || empty($messenger)) { |
|
| 1224 | - throw new EE_Error( |
|
| 1225 | - esc_html__( |
|
| 1226 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1227 | - 'event_espresso' |
|
| 1228 | - ) |
|
| 1229 | - ); |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1233 | - if (empty($GRP_ID)) { |
|
| 1234 | - throw new EE_Error( |
|
| 1235 | - esc_html__( |
|
| 1236 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1237 | - 'event_espresso' |
|
| 1238 | - ) |
|
| 1239 | - ); |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - //let's just make sure the template gets generated! |
|
| 1243 | - |
|
| 1244 | - //we need to reassign some variables for what the insert is expecting |
|
| 1245 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1246 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1247 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1248 | - $this->_insert_or_update_message_template(true); |
|
| 1249 | - } |
|
| 1195 | + /** |
|
| 1196 | + * _add_message_template |
|
| 1197 | + * |
|
| 1198 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1199 | + * |
|
| 1200 | + * @param string $message_type |
|
| 1201 | + * @param string $messenger |
|
| 1202 | + * @param string $GRP_ID |
|
| 1203 | + * |
|
| 1204 | + * @throws EE_error |
|
| 1205 | + */ |
|
| 1206 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1207 | + { |
|
| 1208 | + //set values override any request data |
|
| 1209 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1210 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1211 | + ? $this->_req_data['message_type'] |
|
| 1212 | + : $message_type; |
|
| 1213 | + |
|
| 1214 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1215 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1216 | + ? $this->_req_data['messenger'] |
|
| 1217 | + : $messenger; |
|
| 1218 | + |
|
| 1219 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1220 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1221 | + |
|
| 1222 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1223 | + if (empty($message_type) || empty($messenger)) { |
|
| 1224 | + throw new EE_Error( |
|
| 1225 | + esc_html__( |
|
| 1226 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1227 | + 'event_espresso' |
|
| 1228 | + ) |
|
| 1229 | + ); |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1233 | + if (empty($GRP_ID)) { |
|
| 1234 | + throw new EE_Error( |
|
| 1235 | + esc_html__( |
|
| 1236 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1237 | + 'event_espresso' |
|
| 1238 | + ) |
|
| 1239 | + ); |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + //let's just make sure the template gets generated! |
|
| 1243 | + |
|
| 1244 | + //we need to reassign some variables for what the insert is expecting |
|
| 1245 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1246 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1247 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1248 | + $this->_insert_or_update_message_template(true); |
|
| 1249 | + } |
|
| 1250 | 1250 | |
| 1251 | 1251 | |
| 1252 | - /** |
|
| 1253 | - * public wrapper for the _add_message_template method |
|
| 1254 | - * |
|
| 1255 | - * @param string $message_type message type slug |
|
| 1256 | - * @param string $messenger messenger slug |
|
| 1257 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1258 | - * off of. |
|
| 1259 | - * @throws EE_error |
|
| 1260 | - */ |
|
| 1261 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1262 | - { |
|
| 1263 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1264 | - } |
|
| 1252 | + /** |
|
| 1253 | + * public wrapper for the _add_message_template method |
|
| 1254 | + * |
|
| 1255 | + * @param string $message_type message type slug |
|
| 1256 | + * @param string $messenger messenger slug |
|
| 1257 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1258 | + * off of. |
|
| 1259 | + * @throws EE_error |
|
| 1260 | + */ |
|
| 1261 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1262 | + { |
|
| 1263 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1264 | + } |
|
| 1265 | 1265 | |
| 1266 | 1266 | |
| 1267 | - /** |
|
| 1268 | - * _edit_message_template |
|
| 1269 | - * |
|
| 1270 | - * @access protected |
|
| 1271 | - * @return void |
|
| 1272 | - * @throws InvalidIdentifierException |
|
| 1273 | - * @throws DomainException |
|
| 1274 | - * @throws EE_Error |
|
| 1275 | - * @throws InvalidArgumentException |
|
| 1276 | - * @throws ReflectionException |
|
| 1277 | - * @throws InvalidDataTypeException |
|
| 1278 | - * @throws InvalidInterfaceException |
|
| 1279 | - */ |
|
| 1280 | - protected function _edit_message_template() |
|
| 1281 | - { |
|
| 1282 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1283 | - $template_fields = ''; |
|
| 1284 | - $sidebar_fields = ''; |
|
| 1285 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1286 | - // valid html in the templates. |
|
| 1287 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1288 | - |
|
| 1289 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1290 | - ? absint($this->_req_data['id']) |
|
| 1291 | - : false; |
|
| 1292 | - |
|
| 1293 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1294 | - $message_template_group = $this->_message_template_group; |
|
| 1295 | - $c_label = $message_template_group->context_label(); |
|
| 1296 | - $c_config = $message_template_group->contexts_config(); |
|
| 1297 | - |
|
| 1298 | - reset($c_config); |
|
| 1299 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1300 | - ? strtolower($this->_req_data['context']) |
|
| 1301 | - : key($c_config); |
|
| 1302 | - |
|
| 1303 | - |
|
| 1304 | - if (empty($GRP_ID)) { |
|
| 1305 | - $action = 'insert_message_template'; |
|
| 1306 | - $edit_message_template_form_url = add_query_arg( |
|
| 1307 | - array('action' => $action, 'noheader' => true), |
|
| 1308 | - EE_MSG_ADMIN_URL |
|
| 1309 | - ); |
|
| 1310 | - } else { |
|
| 1311 | - $action = 'update_message_template'; |
|
| 1312 | - $edit_message_template_form_url = add_query_arg( |
|
| 1313 | - array('action' => $action, 'noheader' => true), |
|
| 1314 | - EE_MSG_ADMIN_URL |
|
| 1315 | - ); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - //set active messenger for this view |
|
| 1319 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1320 | - $message_template_group->messenger() |
|
| 1321 | - ); |
|
| 1322 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - //Do we have any validation errors? |
|
| 1326 | - $validators = $this->_get_transient(); |
|
| 1327 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1328 | - |
|
| 1329 | - |
|
| 1330 | - //we need to assemble the title from Various details |
|
| 1331 | - $context_label = sprintf( |
|
| 1332 | - esc_html__('(%s %s)', 'event_espresso'), |
|
| 1333 | - $c_config[$context]['label'], |
|
| 1334 | - ucwords($c_label['label']) |
|
| 1335 | - ); |
|
| 1336 | - |
|
| 1337 | - $title = sprintf( |
|
| 1338 | - esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1339 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1340 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1341 | - $context_label |
|
| 1342 | - ); |
|
| 1343 | - |
|
| 1344 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1345 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1346 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1350 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1351 | - $message_template_group->messenger(), |
|
| 1352 | - $message_template_group->message_type() |
|
| 1353 | - ); |
|
| 1354 | - |
|
| 1355 | - if ( ! $template_field_structure) { |
|
| 1356 | - $template_field_structure = false; |
|
| 1357 | - $template_fields = esc_html__( |
|
| 1358 | - 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1359 | - 'event_espresso' |
|
| 1360 | - ); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - |
|
| 1364 | - $message_templates = $message_template_group->context_templates(); |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1368 | - // will get handled in the "extra" array. |
|
| 1369 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1370 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1371 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1376 | - if ( ! empty($template_field_structure)) { |
|
| 1377 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1378 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1379 | - // the extra array and reset them. |
|
| 1380 | - if ($template_field === 'extra') { |
|
| 1381 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1382 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1383 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1384 | - $content = $message_template instanceof EE_Message_Template |
|
| 1385 | - ? $message_template->get('MTP_content') |
|
| 1386 | - : ''; |
|
| 1387 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1388 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1389 | - $continue = false; |
|
| 1390 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1391 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1392 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1393 | - $continue = true; |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - if ($continue) { |
|
| 1397 | - continue; |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1267 | + /** |
|
| 1268 | + * _edit_message_template |
|
| 1269 | + * |
|
| 1270 | + * @access protected |
|
| 1271 | + * @return void |
|
| 1272 | + * @throws InvalidIdentifierException |
|
| 1273 | + * @throws DomainException |
|
| 1274 | + * @throws EE_Error |
|
| 1275 | + * @throws InvalidArgumentException |
|
| 1276 | + * @throws ReflectionException |
|
| 1277 | + * @throws InvalidDataTypeException |
|
| 1278 | + * @throws InvalidInterfaceException |
|
| 1279 | + */ |
|
| 1280 | + protected function _edit_message_template() |
|
| 1281 | + { |
|
| 1282 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1283 | + $template_fields = ''; |
|
| 1284 | + $sidebar_fields = ''; |
|
| 1285 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1286 | + // valid html in the templates. |
|
| 1287 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1288 | + |
|
| 1289 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1290 | + ? absint($this->_req_data['id']) |
|
| 1291 | + : false; |
|
| 1292 | + |
|
| 1293 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1294 | + $message_template_group = $this->_message_template_group; |
|
| 1295 | + $c_label = $message_template_group->context_label(); |
|
| 1296 | + $c_config = $message_template_group->contexts_config(); |
|
| 1297 | + |
|
| 1298 | + reset($c_config); |
|
| 1299 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1300 | + ? strtolower($this->_req_data['context']) |
|
| 1301 | + : key($c_config); |
|
| 1302 | + |
|
| 1303 | + |
|
| 1304 | + if (empty($GRP_ID)) { |
|
| 1305 | + $action = 'insert_message_template'; |
|
| 1306 | + $edit_message_template_form_url = add_query_arg( |
|
| 1307 | + array('action' => $action, 'noheader' => true), |
|
| 1308 | + EE_MSG_ADMIN_URL |
|
| 1309 | + ); |
|
| 1310 | + } else { |
|
| 1311 | + $action = 'update_message_template'; |
|
| 1312 | + $edit_message_template_form_url = add_query_arg( |
|
| 1313 | + array('action' => $action, 'noheader' => true), |
|
| 1314 | + EE_MSG_ADMIN_URL |
|
| 1315 | + ); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + //set active messenger for this view |
|
| 1319 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1320 | + $message_template_group->messenger() |
|
| 1321 | + ); |
|
| 1322 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + //Do we have any validation errors? |
|
| 1326 | + $validators = $this->_get_transient(); |
|
| 1327 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1328 | + |
|
| 1329 | + |
|
| 1330 | + //we need to assemble the title from Various details |
|
| 1331 | + $context_label = sprintf( |
|
| 1332 | + esc_html__('(%s %s)', 'event_espresso'), |
|
| 1333 | + $c_config[$context]['label'], |
|
| 1334 | + ucwords($c_label['label']) |
|
| 1335 | + ); |
|
| 1336 | + |
|
| 1337 | + $title = sprintf( |
|
| 1338 | + esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1339 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1340 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1341 | + $context_label |
|
| 1342 | + ); |
|
| 1343 | + |
|
| 1344 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1345 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1346 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1350 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1351 | + $message_template_group->messenger(), |
|
| 1352 | + $message_template_group->message_type() |
|
| 1353 | + ); |
|
| 1354 | + |
|
| 1355 | + if ( ! $template_field_structure) { |
|
| 1356 | + $template_field_structure = false; |
|
| 1357 | + $template_fields = esc_html__( |
|
| 1358 | + 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1359 | + 'event_espresso' |
|
| 1360 | + ); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + |
|
| 1364 | + $message_templates = $message_template_group->context_templates(); |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1368 | + // will get handled in the "extra" array. |
|
| 1369 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1370 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1371 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1376 | + if ( ! empty($template_field_structure)) { |
|
| 1377 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1378 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1379 | + // the extra array and reset them. |
|
| 1380 | + if ($template_field === 'extra') { |
|
| 1381 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1382 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1383 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1384 | + $content = $message_template instanceof EE_Message_Template |
|
| 1385 | + ? $message_template->get('MTP_content') |
|
| 1386 | + : ''; |
|
| 1387 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1388 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1389 | + $continue = false; |
|
| 1390 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1391 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1392 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1393 | + $continue = true; |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + if ($continue) { |
|
| 1397 | + continue; |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | 1400 | |
| 1401 | - $field_id = $reference_field |
|
| 1402 | - . '-' |
|
| 1403 | - . $extra_field |
|
| 1404 | - . '-content'; |
|
| 1405 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1406 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1407 | - . $reference_field |
|
| 1408 | - . '][content][' |
|
| 1409 | - . $extra_field . ']'; |
|
| 1410 | - $css_class = isset($extra_array['css_class']) |
|
| 1411 | - ? $extra_array['css_class'] |
|
| 1412 | - : ''; |
|
| 1401 | + $field_id = $reference_field |
|
| 1402 | + . '-' |
|
| 1403 | + . $extra_field |
|
| 1404 | + . '-content'; |
|
| 1405 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1406 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1407 | + . $reference_field |
|
| 1408 | + . '][content][' |
|
| 1409 | + . $extra_field . ']'; |
|
| 1410 | + $css_class = isset($extra_array['css_class']) |
|
| 1411 | + ? $extra_array['css_class'] |
|
| 1412 | + : ''; |
|
| 1413 | 1413 | |
| 1414 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1415 | - && in_array($extra_field, $v_fields, true) |
|
| 1416 | - && |
|
| 1417 | - ( |
|
| 1418 | - is_array($validators[$extra_field]) |
|
| 1419 | - && isset($validators[$extra_field]['msg']) |
|
| 1420 | - ) |
|
| 1421 | - ? 'validate-error ' . $css_class |
|
| 1422 | - : $css_class; |
|
| 1414 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1415 | + && in_array($extra_field, $v_fields, true) |
|
| 1416 | + && |
|
| 1417 | + ( |
|
| 1418 | + is_array($validators[$extra_field]) |
|
| 1419 | + && isset($validators[$extra_field]['msg']) |
|
| 1420 | + ) |
|
| 1421 | + ? 'validate-error ' . $css_class |
|
| 1422 | + : $css_class; |
|
| 1423 | 1423 | |
| 1424 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1425 | - && isset($content[$extra_field]) |
|
| 1426 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1427 | - : ''; |
|
| 1424 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1425 | + && isset($content[$extra_field]) |
|
| 1426 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1427 | + : ''; |
|
| 1428 | 1428 | |
| 1429 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1430 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1431 | - ? $validators[$extra_field]['value'] |
|
| 1432 | - : $template_form_fields[$field_id]['value']; |
|
| 1429 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1430 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1431 | + ? $validators[$extra_field]['value'] |
|
| 1432 | + : $template_form_fields[$field_id]['value']; |
|
| 1433 | 1433 | |
| 1434 | 1434 | |
| 1435 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1435 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1436 | 1436 | |
| 1437 | - //shortcode selector |
|
| 1438 | - $field_name_to_use = $extra_field === 'main' |
|
| 1439 | - ? 'content' |
|
| 1440 | - : $extra_field; |
|
| 1441 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1442 | - $field_name_to_use, |
|
| 1443 | - $field_id |
|
| 1444 | - ); |
|
| 1437 | + //shortcode selector |
|
| 1438 | + $field_name_to_use = $extra_field === 'main' |
|
| 1439 | + ? 'content' |
|
| 1440 | + : $extra_field; |
|
| 1441 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1442 | + $field_name_to_use, |
|
| 1443 | + $field_id |
|
| 1444 | + ); |
|
| 1445 | 1445 | |
| 1446 | - if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1447 | - //we want to decode the entities |
|
| 1448 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1449 | - html_entity_decode( |
|
| 1450 | - $template_form_fields[$field_id]['value'], |
|
| 1451 | - ENT_QUOTES, |
|
| 1452 | - "UTF-8") |
|
| 1453 | - ); |
|
| 1446 | + if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1447 | + //we want to decode the entities |
|
| 1448 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1449 | + html_entity_decode( |
|
| 1450 | + $template_form_fields[$field_id]['value'], |
|
| 1451 | + ENT_QUOTES, |
|
| 1452 | + "UTF-8") |
|
| 1453 | + ); |
|
| 1454 | 1454 | |
| 1455 | - }/**/ |
|
| 1456 | - } |
|
| 1457 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1458 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1455 | + }/**/ |
|
| 1456 | + } |
|
| 1457 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1458 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1459 | 1459 | |
| 1460 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1461 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1462 | - 'label' => null, |
|
| 1463 | - 'input' => 'hidden', |
|
| 1464 | - 'type' => 'int', |
|
| 1465 | - 'required' => false, |
|
| 1466 | - 'validation' => false, |
|
| 1467 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1468 | - 'css_class' => '', |
|
| 1469 | - 'format' => '%d', |
|
| 1470 | - 'db-col' => 'MTP_ID' |
|
| 1471 | - ); |
|
| 1460 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1461 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1462 | + 'label' => null, |
|
| 1463 | + 'input' => 'hidden', |
|
| 1464 | + 'type' => 'int', |
|
| 1465 | + 'required' => false, |
|
| 1466 | + 'validation' => false, |
|
| 1467 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1468 | + 'css_class' => '', |
|
| 1469 | + 'format' => '%d', |
|
| 1470 | + 'db-col' => 'MTP_ID' |
|
| 1471 | + ); |
|
| 1472 | 1472 | |
| 1473 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1474 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1475 | - 'label' => null, |
|
| 1476 | - 'input' => 'hidden', |
|
| 1477 | - 'type' => 'string', |
|
| 1478 | - 'required' => false, |
|
| 1479 | - 'validation' => true, |
|
| 1480 | - 'value' => $reference_field, |
|
| 1481 | - 'css_class' => '', |
|
| 1482 | - 'format' => '%s', |
|
| 1483 | - 'db-col' => 'MTP_template_field' |
|
| 1484 | - ); |
|
| 1485 | - } |
|
| 1486 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1487 | - } else { |
|
| 1488 | - $field_id = $template_field . '-content'; |
|
| 1489 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1490 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1491 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1492 | - ? $message_templates[$context][$template_field] |
|
| 1493 | - : null; |
|
| 1494 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1495 | - && is_array($message_templates[$context]) |
|
| 1496 | - && $message_template instanceof EE_Message_Template |
|
| 1497 | - ? $message_template->get('MTP_content') |
|
| 1498 | - : ''; |
|
| 1473 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1474 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1475 | + 'label' => null, |
|
| 1476 | + 'input' => 'hidden', |
|
| 1477 | + 'type' => 'string', |
|
| 1478 | + 'required' => false, |
|
| 1479 | + 'validation' => true, |
|
| 1480 | + 'value' => $reference_field, |
|
| 1481 | + 'css_class' => '', |
|
| 1482 | + 'format' => '%s', |
|
| 1483 | + 'db-col' => 'MTP_template_field' |
|
| 1484 | + ); |
|
| 1485 | + } |
|
| 1486 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1487 | + } else { |
|
| 1488 | + $field_id = $template_field . '-content'; |
|
| 1489 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1490 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1491 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1492 | + ? $message_templates[$context][$template_field] |
|
| 1493 | + : null; |
|
| 1494 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1495 | + && is_array($message_templates[$context]) |
|
| 1496 | + && $message_template instanceof EE_Message_Template |
|
| 1497 | + ? $message_template->get('MTP_content') |
|
| 1498 | + : ''; |
|
| 1499 | 1499 | |
| 1500 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1501 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1502 | - ? $validators[$template_field]['value'] |
|
| 1503 | - : $template_form_fields[$field_id]['value']; |
|
| 1500 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1501 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1502 | + ? $validators[$template_field]['value'] |
|
| 1503 | + : $template_form_fields[$field_id]['value']; |
|
| 1504 | 1504 | |
| 1505 | 1505 | |
| 1506 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1507 | - $css_class = isset($field_setup_array['css_class']) |
|
| 1508 | - ? $field_setup_array['css_class'] |
|
| 1509 | - : ''; |
|
| 1510 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1511 | - && in_array($template_field, $v_fields, true) |
|
| 1512 | - && isset($validators[$template_field]['msg']) |
|
| 1513 | - ? 'validate-error ' . $css_class |
|
| 1514 | - : $css_class; |
|
| 1506 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1507 | + $css_class = isset($field_setup_array['css_class']) |
|
| 1508 | + ? $field_setup_array['css_class'] |
|
| 1509 | + : ''; |
|
| 1510 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1511 | + && in_array($template_field, $v_fields, true) |
|
| 1512 | + && isset($validators[$template_field]['msg']) |
|
| 1513 | + ? 'validate-error ' . $css_class |
|
| 1514 | + : $css_class; |
|
| 1515 | 1515 | |
| 1516 | - //shortcode selector |
|
| 1517 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1518 | - $template_field, $field_id |
|
| 1519 | - ); |
|
| 1520 | - } |
|
| 1516 | + //shortcode selector |
|
| 1517 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1518 | + $template_field, $field_id |
|
| 1519 | + ); |
|
| 1520 | + } |
|
| 1521 | 1521 | |
| 1522 | - //k took care of content field(s) now let's take care of others. |
|
| 1522 | + //k took care of content field(s) now let's take care of others. |
|
| 1523 | 1523 | |
| 1524 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1525 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1524 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1525 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1526 | 1526 | |
| 1527 | - //foreach template field there are actually two form fields created |
|
| 1528 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1529 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1530 | - 'label' => null, |
|
| 1531 | - 'input' => 'hidden', |
|
| 1532 | - 'type' => 'int', |
|
| 1533 | - 'required' => false, |
|
| 1534 | - 'validation' => true, |
|
| 1535 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1536 | - 'css_class' => '', |
|
| 1537 | - 'format' => '%d', |
|
| 1538 | - 'db-col' => 'MTP_ID' |
|
| 1539 | - ); |
|
| 1527 | + //foreach template field there are actually two form fields created |
|
| 1528 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1529 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1530 | + 'label' => null, |
|
| 1531 | + 'input' => 'hidden', |
|
| 1532 | + 'type' => 'int', |
|
| 1533 | + 'required' => false, |
|
| 1534 | + 'validation' => true, |
|
| 1535 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1536 | + 'css_class' => '', |
|
| 1537 | + 'format' => '%d', |
|
| 1538 | + 'db-col' => 'MTP_ID' |
|
| 1539 | + ); |
|
| 1540 | 1540 | |
| 1541 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1542 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1543 | - 'label' => null, |
|
| 1544 | - 'input' => 'hidden', |
|
| 1545 | - 'type' => 'string', |
|
| 1546 | - 'required' => false, |
|
| 1547 | - 'validation' => true, |
|
| 1548 | - 'value' => $template_field, |
|
| 1549 | - 'css_class' => '', |
|
| 1550 | - 'format' => '%s', |
|
| 1551 | - 'db-col' => 'MTP_template_field' |
|
| 1552 | - ); |
|
| 1541 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1542 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1543 | + 'label' => null, |
|
| 1544 | + 'input' => 'hidden', |
|
| 1545 | + 'type' => 'string', |
|
| 1546 | + 'required' => false, |
|
| 1547 | + 'validation' => true, |
|
| 1548 | + 'value' => $template_field, |
|
| 1549 | + 'css_class' => '', |
|
| 1550 | + 'format' => '%s', |
|
| 1551 | + 'db-col' => 'MTP_template_field' |
|
| 1552 | + ); |
|
| 1553 | 1553 | |
| 1554 | - } |
|
| 1554 | + } |
|
| 1555 | 1555 | |
| 1556 | - //add other fields |
|
| 1557 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1558 | - 'name' => 'MTP_context', |
|
| 1559 | - 'label' => null, |
|
| 1560 | - 'input' => 'hidden', |
|
| 1561 | - 'type' => 'string', |
|
| 1562 | - 'required' => false, |
|
| 1563 | - 'validation' => true, |
|
| 1564 | - 'value' => $context, |
|
| 1565 | - 'css_class' => '', |
|
| 1566 | - 'format' => '%s', |
|
| 1567 | - 'db-col' => 'MTP_context' |
|
| 1568 | - ); |
|
| 1556 | + //add other fields |
|
| 1557 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1558 | + 'name' => 'MTP_context', |
|
| 1559 | + 'label' => null, |
|
| 1560 | + 'input' => 'hidden', |
|
| 1561 | + 'type' => 'string', |
|
| 1562 | + 'required' => false, |
|
| 1563 | + 'validation' => true, |
|
| 1564 | + 'value' => $context, |
|
| 1565 | + 'css_class' => '', |
|
| 1566 | + 'format' => '%s', |
|
| 1567 | + 'db-col' => 'MTP_context' |
|
| 1568 | + ); |
|
| 1569 | 1569 | |
| 1570 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1571 | - 'name' => 'GRP_ID', |
|
| 1572 | - 'label' => null, |
|
| 1573 | - 'input' => 'hidden', |
|
| 1574 | - 'type' => 'int', |
|
| 1575 | - 'required' => false, |
|
| 1576 | - 'validation' => true, |
|
| 1577 | - 'value' => $GRP_ID, |
|
| 1578 | - 'css_class' => '', |
|
| 1579 | - 'format' => '%d', |
|
| 1580 | - 'db-col' => 'GRP_ID' |
|
| 1581 | - ); |
|
| 1570 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1571 | + 'name' => 'GRP_ID', |
|
| 1572 | + 'label' => null, |
|
| 1573 | + 'input' => 'hidden', |
|
| 1574 | + 'type' => 'int', |
|
| 1575 | + 'required' => false, |
|
| 1576 | + 'validation' => true, |
|
| 1577 | + 'value' => $GRP_ID, |
|
| 1578 | + 'css_class' => '', |
|
| 1579 | + 'format' => '%d', |
|
| 1580 | + 'db-col' => 'GRP_ID' |
|
| 1581 | + ); |
|
| 1582 | 1582 | |
| 1583 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1584 | - 'name' => 'MTP_messenger', |
|
| 1585 | - 'label' => null, |
|
| 1586 | - 'input' => 'hidden', |
|
| 1587 | - 'type' => 'string', |
|
| 1588 | - 'required' => false, |
|
| 1589 | - 'validation' => true, |
|
| 1590 | - 'value' => $message_template_group->messenger(), |
|
| 1591 | - 'css_class' => '', |
|
| 1592 | - 'format' => '%s', |
|
| 1593 | - 'db-col' => 'MTP_messenger' |
|
| 1594 | - ); |
|
| 1583 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1584 | + 'name' => 'MTP_messenger', |
|
| 1585 | + 'label' => null, |
|
| 1586 | + 'input' => 'hidden', |
|
| 1587 | + 'type' => 'string', |
|
| 1588 | + 'required' => false, |
|
| 1589 | + 'validation' => true, |
|
| 1590 | + 'value' => $message_template_group->messenger(), |
|
| 1591 | + 'css_class' => '', |
|
| 1592 | + 'format' => '%s', |
|
| 1593 | + 'db-col' => 'MTP_messenger' |
|
| 1594 | + ); |
|
| 1595 | 1595 | |
| 1596 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1597 | - 'name' => 'MTP_message_type', |
|
| 1598 | - 'label' => null, |
|
| 1599 | - 'input' => 'hidden', |
|
| 1600 | - 'type' => 'string', |
|
| 1601 | - 'required' => false, |
|
| 1602 | - 'validation' => true, |
|
| 1603 | - 'value' => $message_template_group->message_type(), |
|
| 1604 | - 'css_class' => '', |
|
| 1605 | - 'format' => '%s', |
|
| 1606 | - 'db-col' => 'MTP_message_type' |
|
| 1607 | - ); |
|
| 1596 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1597 | + 'name' => 'MTP_message_type', |
|
| 1598 | + 'label' => null, |
|
| 1599 | + 'input' => 'hidden', |
|
| 1600 | + 'type' => 'string', |
|
| 1601 | + 'required' => false, |
|
| 1602 | + 'validation' => true, |
|
| 1603 | + 'value' => $message_template_group->message_type(), |
|
| 1604 | + 'css_class' => '', |
|
| 1605 | + 'format' => '%s', |
|
| 1606 | + 'db-col' => 'MTP_message_type' |
|
| 1607 | + ); |
|
| 1608 | 1608 | |
| 1609 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1610 | - 'name' => 'MTP_is_global', |
|
| 1611 | - 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1612 | - 'input' => 'hidden', |
|
| 1613 | - 'type' => 'int', |
|
| 1614 | - 'required' => false, |
|
| 1615 | - 'validation' => true, |
|
| 1616 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1617 | - 'css_class' => '', |
|
| 1618 | - 'format' => '%d', |
|
| 1619 | - 'db-col' => 'MTP_is_global' |
|
| 1620 | - ); |
|
| 1609 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1610 | + 'name' => 'MTP_is_global', |
|
| 1611 | + 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1612 | + 'input' => 'hidden', |
|
| 1613 | + 'type' => 'int', |
|
| 1614 | + 'required' => false, |
|
| 1615 | + 'validation' => true, |
|
| 1616 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1617 | + 'css_class' => '', |
|
| 1618 | + 'format' => '%d', |
|
| 1619 | + 'db-col' => 'MTP_is_global' |
|
| 1620 | + ); |
|
| 1621 | 1621 | |
| 1622 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1623 | - 'name' => 'MTP_is_override', |
|
| 1624 | - 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1625 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1626 | - 'type' => 'int', |
|
| 1627 | - 'required' => false, |
|
| 1628 | - 'validation' => true, |
|
| 1629 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1630 | - 'css_class' => '', |
|
| 1631 | - 'format' => '%d', |
|
| 1632 | - 'db-col' => 'MTP_is_override' |
|
| 1633 | - ); |
|
| 1622 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1623 | + 'name' => 'MTP_is_override', |
|
| 1624 | + 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1625 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1626 | + 'type' => 'int', |
|
| 1627 | + 'required' => false, |
|
| 1628 | + 'validation' => true, |
|
| 1629 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1630 | + 'css_class' => '', |
|
| 1631 | + 'format' => '%d', |
|
| 1632 | + 'db-col' => 'MTP_is_override' |
|
| 1633 | + ); |
|
| 1634 | 1634 | |
| 1635 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1636 | - 'name' => 'MTP_is_active', |
|
| 1637 | - 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1638 | - 'input' => 'hidden', |
|
| 1639 | - 'type' => 'int', |
|
| 1640 | - 'required' => false, |
|
| 1641 | - 'validation' => true, |
|
| 1642 | - 'value' => $message_template_group->is_active(), |
|
| 1643 | - 'css_class' => '', |
|
| 1644 | - 'format' => '%d', |
|
| 1645 | - 'db-col' => 'MTP_is_active' |
|
| 1646 | - ); |
|
| 1635 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1636 | + 'name' => 'MTP_is_active', |
|
| 1637 | + 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1638 | + 'input' => 'hidden', |
|
| 1639 | + 'type' => 'int', |
|
| 1640 | + 'required' => false, |
|
| 1641 | + 'validation' => true, |
|
| 1642 | + 'value' => $message_template_group->is_active(), |
|
| 1643 | + 'css_class' => '', |
|
| 1644 | + 'format' => '%d', |
|
| 1645 | + 'db-col' => 'MTP_is_active' |
|
| 1646 | + ); |
|
| 1647 | 1647 | |
| 1648 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1649 | - 'name' => 'MTP_deleted', |
|
| 1650 | - 'label' => null, |
|
| 1651 | - 'input' => 'hidden', |
|
| 1652 | - 'type' => 'int', |
|
| 1653 | - 'required' => false, |
|
| 1654 | - 'validation' => true, |
|
| 1655 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1656 | - 'css_class' => '', |
|
| 1657 | - 'format' => '%d', |
|
| 1658 | - 'db-col' => 'MTP_deleted' |
|
| 1659 | - ); |
|
| 1660 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1661 | - 'name' => 'MTP_user_id', |
|
| 1662 | - 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1663 | - 'input' => 'hidden', |
|
| 1664 | - 'type' => 'int', |
|
| 1665 | - 'required' => false, |
|
| 1666 | - 'validation' => false, |
|
| 1667 | - 'value' => $message_template_group->user(), |
|
| 1668 | - 'format' => '%d', |
|
| 1669 | - 'db-col' => 'MTP_user_id' |
|
| 1670 | - ); |
|
| 1648 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1649 | + 'name' => 'MTP_deleted', |
|
| 1650 | + 'label' => null, |
|
| 1651 | + 'input' => 'hidden', |
|
| 1652 | + 'type' => 'int', |
|
| 1653 | + 'required' => false, |
|
| 1654 | + 'validation' => true, |
|
| 1655 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1656 | + 'css_class' => '', |
|
| 1657 | + 'format' => '%d', |
|
| 1658 | + 'db-col' => 'MTP_deleted' |
|
| 1659 | + ); |
|
| 1660 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1661 | + 'name' => 'MTP_user_id', |
|
| 1662 | + 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1663 | + 'input' => 'hidden', |
|
| 1664 | + 'type' => 'int', |
|
| 1665 | + 'required' => false, |
|
| 1666 | + 'validation' => false, |
|
| 1667 | + 'value' => $message_template_group->user(), |
|
| 1668 | + 'format' => '%d', |
|
| 1669 | + 'db-col' => 'MTP_user_id' |
|
| 1670 | + ); |
|
| 1671 | 1671 | |
| 1672 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1673 | - 'name' => 'action', |
|
| 1674 | - 'input' => 'hidden', |
|
| 1675 | - 'type' => 'string', |
|
| 1676 | - 'value' => $action |
|
| 1677 | - ); |
|
| 1672 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1673 | + 'name' => 'action', |
|
| 1674 | + 'input' => 'hidden', |
|
| 1675 | + 'type' => 'string', |
|
| 1676 | + 'value' => $action |
|
| 1677 | + ); |
|
| 1678 | 1678 | |
| 1679 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1680 | - 'name' => 'id', |
|
| 1681 | - 'input' => 'hidden', |
|
| 1682 | - 'type' => 'int', |
|
| 1683 | - 'value' => $GRP_ID |
|
| 1684 | - ); |
|
| 1685 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1686 | - 'name' => $action . '_nonce', |
|
| 1687 | - 'input' => 'hidden', |
|
| 1688 | - 'type' => 'string', |
|
| 1689 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1690 | - ); |
|
| 1679 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1680 | + 'name' => 'id', |
|
| 1681 | + 'input' => 'hidden', |
|
| 1682 | + 'type' => 'int', |
|
| 1683 | + 'value' => $GRP_ID |
|
| 1684 | + ); |
|
| 1685 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1686 | + 'name' => $action . '_nonce', |
|
| 1687 | + 'input' => 'hidden', |
|
| 1688 | + 'type' => 'string', |
|
| 1689 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1690 | + ); |
|
| 1691 | 1691 | |
| 1692 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1693 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1694 | - 'name' => 'template_switch', |
|
| 1695 | - 'input' => 'hidden', |
|
| 1696 | - 'type' => 'int', |
|
| 1697 | - 'value' => 1 |
|
| 1698 | - ); |
|
| 1699 | - } |
|
| 1692 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1693 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1694 | + 'name' => 'template_switch', |
|
| 1695 | + 'input' => 'hidden', |
|
| 1696 | + 'type' => 'int', |
|
| 1697 | + 'value' => 1 |
|
| 1698 | + ); |
|
| 1699 | + } |
|
| 1700 | 1700 | |
| 1701 | 1701 | |
| 1702 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1703 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1702 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1703 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1704 | 1704 | |
| 1705 | 1705 | |
| 1706 | - } //end if ( !empty($template_field_structure) ) |
|
| 1707 | - |
|
| 1708 | - //set extra content for publish box |
|
| 1709 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1710 | - $this->_set_publish_post_box_vars( |
|
| 1711 | - 'id', |
|
| 1712 | - $GRP_ID, |
|
| 1713 | - false, |
|
| 1714 | - add_query_arg( |
|
| 1715 | - array('action' => 'global_mtps'), |
|
| 1716 | - $this->_admin_base_url |
|
| 1717 | - ) |
|
| 1718 | - ); |
|
| 1719 | - |
|
| 1720 | - //add preview button |
|
| 1721 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1722 | - array( |
|
| 1723 | - 'message_type' => $message_template_group->message_type(), |
|
| 1724 | - 'messenger' => $message_template_group->messenger(), |
|
| 1725 | - 'context' => $context, |
|
| 1726 | - 'GRP_ID' => $GRP_ID, |
|
| 1727 | - 'action' => 'preview_message' |
|
| 1728 | - ), |
|
| 1729 | - $this->_admin_base_url |
|
| 1730 | - ); |
|
| 1731 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1732 | - . esc_html__('Preview', 'event_espresso') |
|
| 1733 | - . '</a>'; |
|
| 1734 | - |
|
| 1735 | - |
|
| 1736 | - //setup context switcher |
|
| 1737 | - $context_switcher_args = array( |
|
| 1738 | - 'page' => 'espresso_messages', |
|
| 1739 | - 'action' => 'edit_message_template', |
|
| 1740 | - 'id' => $GRP_ID, |
|
| 1741 | - 'context' => $context, |
|
| 1742 | - 'extra' => $preview_button |
|
| 1743 | - ); |
|
| 1744 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1745 | - |
|
| 1746 | - |
|
| 1747 | - //main box |
|
| 1748 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1749 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1750 | - $this->_template_args['action'] = $action; |
|
| 1751 | - $this->_template_args['context'] = $context; |
|
| 1752 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1753 | - $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1754 | - $this->_learn_more_about_message_templates_link(); |
|
| 1755 | - |
|
| 1756 | - |
|
| 1757 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1758 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1759 | - $message_template_group, |
|
| 1760 | - $context, |
|
| 1761 | - $context_label |
|
| 1762 | - ); |
|
| 1763 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1764 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1765 | - |
|
| 1766 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1767 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1768 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1769 | - |
|
| 1770 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1771 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1772 | - |
|
| 1773 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1774 | - $this->_template_path, |
|
| 1775 | - $this->_template_args, |
|
| 1776 | - true |
|
| 1777 | - ); |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - //finally, let's set the admin_page title |
|
| 1781 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1782 | - |
|
| 1783 | - |
|
| 1784 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1785 | - $this->_set_shortcodes(); |
|
| 1786 | - |
|
| 1787 | - |
|
| 1788 | - //final template wrapper |
|
| 1789 | - $this->display_admin_page_with_sidebar(); |
|
| 1790 | - } |
|
| 1706 | + } //end if ( !empty($template_field_structure) ) |
|
| 1707 | + |
|
| 1708 | + //set extra content for publish box |
|
| 1709 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1710 | + $this->_set_publish_post_box_vars( |
|
| 1711 | + 'id', |
|
| 1712 | + $GRP_ID, |
|
| 1713 | + false, |
|
| 1714 | + add_query_arg( |
|
| 1715 | + array('action' => 'global_mtps'), |
|
| 1716 | + $this->_admin_base_url |
|
| 1717 | + ) |
|
| 1718 | + ); |
|
| 1719 | + |
|
| 1720 | + //add preview button |
|
| 1721 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1722 | + array( |
|
| 1723 | + 'message_type' => $message_template_group->message_type(), |
|
| 1724 | + 'messenger' => $message_template_group->messenger(), |
|
| 1725 | + 'context' => $context, |
|
| 1726 | + 'GRP_ID' => $GRP_ID, |
|
| 1727 | + 'action' => 'preview_message' |
|
| 1728 | + ), |
|
| 1729 | + $this->_admin_base_url |
|
| 1730 | + ); |
|
| 1731 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1732 | + . esc_html__('Preview', 'event_espresso') |
|
| 1733 | + . '</a>'; |
|
| 1734 | + |
|
| 1735 | + |
|
| 1736 | + //setup context switcher |
|
| 1737 | + $context_switcher_args = array( |
|
| 1738 | + 'page' => 'espresso_messages', |
|
| 1739 | + 'action' => 'edit_message_template', |
|
| 1740 | + 'id' => $GRP_ID, |
|
| 1741 | + 'context' => $context, |
|
| 1742 | + 'extra' => $preview_button |
|
| 1743 | + ); |
|
| 1744 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1745 | + |
|
| 1746 | + |
|
| 1747 | + //main box |
|
| 1748 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1749 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1750 | + $this->_template_args['action'] = $action; |
|
| 1751 | + $this->_template_args['context'] = $context; |
|
| 1752 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1753 | + $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1754 | + $this->_learn_more_about_message_templates_link(); |
|
| 1755 | + |
|
| 1756 | + |
|
| 1757 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1758 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1759 | + $message_template_group, |
|
| 1760 | + $context, |
|
| 1761 | + $context_label |
|
| 1762 | + ); |
|
| 1763 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1764 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1765 | + |
|
| 1766 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1767 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1768 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1769 | + |
|
| 1770 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1771 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1772 | + |
|
| 1773 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1774 | + $this->_template_path, |
|
| 1775 | + $this->_template_args, |
|
| 1776 | + true |
|
| 1777 | + ); |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + //finally, let's set the admin_page title |
|
| 1781 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1782 | + |
|
| 1783 | + |
|
| 1784 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1785 | + $this->_set_shortcodes(); |
|
| 1786 | + |
|
| 1787 | + |
|
| 1788 | + //final template wrapper |
|
| 1789 | + $this->display_admin_page_with_sidebar(); |
|
| 1790 | + } |
|
| 1791 | 1791 | |
| 1792 | 1792 | |
| 1793 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1794 | - { |
|
| 1795 | - return $mceInit; |
|
| 1796 | - } |
|
| 1793 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1794 | + { |
|
| 1795 | + return $mceInit; |
|
| 1796 | + } |
|
| 1797 | 1797 | |
| 1798 | 1798 | |
| 1799 | - public function add_context_switcher() |
|
| 1800 | - { |
|
| 1801 | - return $this->_context_switcher; |
|
| 1802 | - } |
|
| 1799 | + public function add_context_switcher() |
|
| 1800 | + { |
|
| 1801 | + return $this->_context_switcher; |
|
| 1802 | + } |
|
| 1803 | 1803 | |
| 1804 | 1804 | |
| 1805 | - /** |
|
| 1806 | - * Adds the activation/deactivation toggle for the message template context. |
|
| 1807 | - * |
|
| 1808 | - * @param EE_Message_Template_Group $message_template_group |
|
| 1809 | - * @param string $context |
|
| 1810 | - * @param string $context_label |
|
| 1811 | - * @return string |
|
| 1812 | - * @throws DomainException |
|
| 1813 | - * @throws EE_Error |
|
| 1814 | - * @throws InvalidIdentifierException |
|
| 1815 | - */ |
|
| 1816 | - protected function add_active_context_element( |
|
| 1817 | - EE_Message_Template_Group $message_template_group, |
|
| 1818 | - $context, |
|
| 1819 | - $context_label |
|
| 1820 | - ) { |
|
| 1821 | - $template_args = array( |
|
| 1822 | - 'context' => $context, |
|
| 1823 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1824 | - 'is_active' => $message_template_group->is_context_active($context), |
|
| 1825 | - 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1826 | - ? 'context-off' |
|
| 1827 | - : 'context-on', |
|
| 1828 | - 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1829 | - 'message_template_group_id' => $message_template_group->ID() |
|
| 1830 | - ); |
|
| 1831 | - return EEH_Template::display_template( |
|
| 1832 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1833 | - $template_args, |
|
| 1834 | - true |
|
| 1835 | - ); |
|
| 1836 | - } |
|
| 1805 | + /** |
|
| 1806 | + * Adds the activation/deactivation toggle for the message template context. |
|
| 1807 | + * |
|
| 1808 | + * @param EE_Message_Template_Group $message_template_group |
|
| 1809 | + * @param string $context |
|
| 1810 | + * @param string $context_label |
|
| 1811 | + * @return string |
|
| 1812 | + * @throws DomainException |
|
| 1813 | + * @throws EE_Error |
|
| 1814 | + * @throws InvalidIdentifierException |
|
| 1815 | + */ |
|
| 1816 | + protected function add_active_context_element( |
|
| 1817 | + EE_Message_Template_Group $message_template_group, |
|
| 1818 | + $context, |
|
| 1819 | + $context_label |
|
| 1820 | + ) { |
|
| 1821 | + $template_args = array( |
|
| 1822 | + 'context' => $context, |
|
| 1823 | + 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1824 | + 'is_active' => $message_template_group->is_context_active($context), |
|
| 1825 | + 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1826 | + ? 'context-off' |
|
| 1827 | + : 'context-on', |
|
| 1828 | + 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1829 | + 'message_template_group_id' => $message_template_group->ID() |
|
| 1830 | + ); |
|
| 1831 | + return EEH_Template::display_template( |
|
| 1832 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1833 | + $template_args, |
|
| 1834 | + true |
|
| 1835 | + ); |
|
| 1836 | + } |
|
| 1837 | 1837 | |
| 1838 | 1838 | |
| 1839 | - /** |
|
| 1840 | - * Ajax callback for `toggle_context_template` ajax action. |
|
| 1841 | - * Handles toggling the message context on or off. |
|
| 1842 | - * @throws EE_Error |
|
| 1843 | - * @throws InvalidArgumentException |
|
| 1844 | - * @throws InvalidDataTypeException |
|
| 1845 | - * @throws InvalidIdentifierException |
|
| 1846 | - * @throws InvalidInterfaceException |
|
| 1847 | - */ |
|
| 1848 | - public function toggle_context_template() |
|
| 1849 | - { |
|
| 1850 | - $success = true; |
|
| 1851 | - //check for required data |
|
| 1852 | - if (!isset( |
|
| 1853 | - $this->_req_data['message_template_group_id'], |
|
| 1854 | - $this->_req_data['context'], |
|
| 1855 | - $this->_req_data['status'] |
|
| 1856 | - )) { |
|
| 1857 | - EE_Error::add_error( |
|
| 1858 | - esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1859 | - __FILE__, |
|
| 1860 | - __FUNCTION__, |
|
| 1861 | - __LINE__ |
|
| 1862 | - ); |
|
| 1863 | - $success = false; |
|
| 1864 | - } |
|
| 1839 | + /** |
|
| 1840 | + * Ajax callback for `toggle_context_template` ajax action. |
|
| 1841 | + * Handles toggling the message context on or off. |
|
| 1842 | + * @throws EE_Error |
|
| 1843 | + * @throws InvalidArgumentException |
|
| 1844 | + * @throws InvalidDataTypeException |
|
| 1845 | + * @throws InvalidIdentifierException |
|
| 1846 | + * @throws InvalidInterfaceException |
|
| 1847 | + */ |
|
| 1848 | + public function toggle_context_template() |
|
| 1849 | + { |
|
| 1850 | + $success = true; |
|
| 1851 | + //check for required data |
|
| 1852 | + if (!isset( |
|
| 1853 | + $this->_req_data['message_template_group_id'], |
|
| 1854 | + $this->_req_data['context'], |
|
| 1855 | + $this->_req_data['status'] |
|
| 1856 | + )) { |
|
| 1857 | + EE_Error::add_error( |
|
| 1858 | + esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1859 | + __FILE__, |
|
| 1860 | + __FUNCTION__, |
|
| 1861 | + __LINE__ |
|
| 1862 | + ); |
|
| 1863 | + $success = false; |
|
| 1864 | + } |
|
| 1865 | 1865 | |
| 1866 | - $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1867 | - ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1868 | - : ''; |
|
| 1869 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1870 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1871 | - $status = $this->_req_data['status']; |
|
| 1872 | - if ($status !== 'off' && $status !=='on') { |
|
| 1873 | - EE_Error::add_error( |
|
| 1874 | - sprintf( |
|
| 1875 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1876 | - $this->_req_data['status'] |
|
| 1877 | - ), |
|
| 1878 | - __FILE__, |
|
| 1879 | - __FUNCTION__, |
|
| 1880 | - __LINE__ |
|
| 1881 | - ); |
|
| 1882 | - $success = false; |
|
| 1883 | - } |
|
| 1884 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1885 | - $this->_req_data['message_template_group_id'] |
|
| 1886 | - ); |
|
| 1887 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1888 | - EE_Error::add_error( |
|
| 1889 | - sprintf( |
|
| 1890 | - esc_html__( |
|
| 1891 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1892 | - 'event_espresso' |
|
| 1893 | - ), |
|
| 1894 | - $this->_req_data['message_template_group_id'], |
|
| 1895 | - 'EE_Message_Template_Group' |
|
| 1896 | - ), |
|
| 1897 | - __FILE__, |
|
| 1898 | - __FUNCTION__, |
|
| 1899 | - __LINE__ |
|
| 1900 | - ); |
|
| 1901 | - $success = false; |
|
| 1902 | - } |
|
| 1903 | - if ($success) { |
|
| 1904 | - $success = $status === 'off' |
|
| 1905 | - ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1906 | - : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1907 | - } |
|
| 1908 | - $this->_template_args['success'] = $success; |
|
| 1909 | - $this->_return_json(); |
|
| 1910 | - } |
|
| 1866 | + $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1867 | + ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1868 | + : ''; |
|
| 1869 | + $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1870 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1871 | + $status = $this->_req_data['status']; |
|
| 1872 | + if ($status !== 'off' && $status !=='on') { |
|
| 1873 | + EE_Error::add_error( |
|
| 1874 | + sprintf( |
|
| 1875 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1876 | + $this->_req_data['status'] |
|
| 1877 | + ), |
|
| 1878 | + __FILE__, |
|
| 1879 | + __FUNCTION__, |
|
| 1880 | + __LINE__ |
|
| 1881 | + ); |
|
| 1882 | + $success = false; |
|
| 1883 | + } |
|
| 1884 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1885 | + $this->_req_data['message_template_group_id'] |
|
| 1886 | + ); |
|
| 1887 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1888 | + EE_Error::add_error( |
|
| 1889 | + sprintf( |
|
| 1890 | + esc_html__( |
|
| 1891 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1892 | + 'event_espresso' |
|
| 1893 | + ), |
|
| 1894 | + $this->_req_data['message_template_group_id'], |
|
| 1895 | + 'EE_Message_Template_Group' |
|
| 1896 | + ), |
|
| 1897 | + __FILE__, |
|
| 1898 | + __FUNCTION__, |
|
| 1899 | + __LINE__ |
|
| 1900 | + ); |
|
| 1901 | + $success = false; |
|
| 1902 | + } |
|
| 1903 | + if ($success) { |
|
| 1904 | + $success = $status === 'off' |
|
| 1905 | + ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1906 | + : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1907 | + } |
|
| 1908 | + $this->_template_args['success'] = $success; |
|
| 1909 | + $this->_return_json(); |
|
| 1910 | + } |
|
| 1911 | 1911 | |
| 1912 | 1912 | |
| 1913 | 1913 | |
| 1914 | - public function _add_form_element_before() |
|
| 1915 | - { |
|
| 1916 | - return '<form method="post" action="' |
|
| 1917 | - . $this->_template_args["edit_message_template_form_url"] |
|
| 1918 | - . '" id="ee-msg-edit-frm">'; |
|
| 1919 | - } |
|
| 1914 | + public function _add_form_element_before() |
|
| 1915 | + { |
|
| 1916 | + return '<form method="post" action="' |
|
| 1917 | + . $this->_template_args["edit_message_template_form_url"] |
|
| 1918 | + . '" id="ee-msg-edit-frm">'; |
|
| 1919 | + } |
|
| 1920 | 1920 | |
| 1921 | - public function _add_form_element_after() |
|
| 1922 | - { |
|
| 1923 | - return '</form>'; |
|
| 1924 | - } |
|
| 1921 | + public function _add_form_element_after() |
|
| 1922 | + { |
|
| 1923 | + return '</form>'; |
|
| 1924 | + } |
|
| 1925 | 1925 | |
| 1926 | 1926 | |
| 1927 | - /** |
|
| 1928 | - * This executes switching the template pack for a message template. |
|
| 1929 | - * |
|
| 1930 | - * @since 4.5.0 |
|
| 1931 | - * @throws EE_Error |
|
| 1932 | - * @throws InvalidDataTypeException |
|
| 1933 | - * @throws InvalidInterfaceException |
|
| 1934 | - * @throws InvalidArgumentException |
|
| 1935 | - * @throws ReflectionException |
|
| 1936 | - */ |
|
| 1937 | - public function switch_template_pack() |
|
| 1938 | - { |
|
| 1939 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1940 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1941 | - |
|
| 1942 | - //verify we have needed values. |
|
| 1943 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1944 | - $this->_template_args['error'] = true; |
|
| 1945 | - EE_Error::add_error( |
|
| 1946 | - esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1947 | - __FILE__, |
|
| 1948 | - __FUNCTION__, |
|
| 1949 | - __LINE__ |
|
| 1950 | - ); |
|
| 1951 | - } else { |
|
| 1952 | - //get template, set the new template_pack and then reset to default |
|
| 1953 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1954 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1927 | + /** |
|
| 1928 | + * This executes switching the template pack for a message template. |
|
| 1929 | + * |
|
| 1930 | + * @since 4.5.0 |
|
| 1931 | + * @throws EE_Error |
|
| 1932 | + * @throws InvalidDataTypeException |
|
| 1933 | + * @throws InvalidInterfaceException |
|
| 1934 | + * @throws InvalidArgumentException |
|
| 1935 | + * @throws ReflectionException |
|
| 1936 | + */ |
|
| 1937 | + public function switch_template_pack() |
|
| 1938 | + { |
|
| 1939 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1940 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1941 | + |
|
| 1942 | + //verify we have needed values. |
|
| 1943 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1944 | + $this->_template_args['error'] = true; |
|
| 1945 | + EE_Error::add_error( |
|
| 1946 | + esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1947 | + __FILE__, |
|
| 1948 | + __FUNCTION__, |
|
| 1949 | + __LINE__ |
|
| 1950 | + ); |
|
| 1951 | + } else { |
|
| 1952 | + //get template, set the new template_pack and then reset to default |
|
| 1953 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1954 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1955 | 1955 | |
| 1956 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1957 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1958 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1956 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1957 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1958 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1959 | 1959 | |
| 1960 | - $query_args = $this->_reset_to_default_template(); |
|
| 1960 | + $query_args = $this->_reset_to_default_template(); |
|
| 1961 | 1961 | |
| 1962 | - if (empty($query_args['id'])) { |
|
| 1963 | - EE_Error::add_error( |
|
| 1964 | - esc_html__( |
|
| 1965 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1966 | - 'event_espresso' |
|
| 1967 | - ), |
|
| 1968 | - __FILE__, |
|
| 1969 | - __FUNCTION__, |
|
| 1970 | - __LINE__ |
|
| 1971 | - ); |
|
| 1972 | - $this->_template_args['error'] = true; |
|
| 1973 | - } else { |
|
| 1974 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1975 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1976 | - EE_Error::add_success( |
|
| 1977 | - sprintf( |
|
| 1978 | - esc_html__( |
|
| 1979 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1980 | - 'event_espresso' |
|
| 1981 | - ), |
|
| 1982 | - $template_label, |
|
| 1983 | - $template_pack_labels->template_pack |
|
| 1984 | - ) |
|
| 1985 | - ); |
|
| 1986 | - //generate the redirect url for js. |
|
| 1987 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1988 | - $this->_admin_base_url); |
|
| 1989 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1990 | - $this->_template_args['success'] = true; |
|
| 1991 | - } |
|
| 1962 | + if (empty($query_args['id'])) { |
|
| 1963 | + EE_Error::add_error( |
|
| 1964 | + esc_html__( |
|
| 1965 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1966 | + 'event_espresso' |
|
| 1967 | + ), |
|
| 1968 | + __FILE__, |
|
| 1969 | + __FUNCTION__, |
|
| 1970 | + __LINE__ |
|
| 1971 | + ); |
|
| 1972 | + $this->_template_args['error'] = true; |
|
| 1973 | + } else { |
|
| 1974 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1975 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1976 | + EE_Error::add_success( |
|
| 1977 | + sprintf( |
|
| 1978 | + esc_html__( |
|
| 1979 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1980 | + 'event_espresso' |
|
| 1981 | + ), |
|
| 1982 | + $template_label, |
|
| 1983 | + $template_pack_labels->template_pack |
|
| 1984 | + ) |
|
| 1985 | + ); |
|
| 1986 | + //generate the redirect url for js. |
|
| 1987 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1988 | + $this->_admin_base_url); |
|
| 1989 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1990 | + $this->_template_args['success'] = true; |
|
| 1991 | + } |
|
| 1992 | 1992 | |
| 1993 | - $this->_return_json(); |
|
| 1993 | + $this->_return_json(); |
|
| 1994 | 1994 | |
| 1995 | - } |
|
| 1996 | - } |
|
| 1995 | + } |
|
| 1996 | + } |
|
| 1997 | 1997 | |
| 1998 | 1998 | |
| 1999 | - /** |
|
| 2000 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2001 | - * they want. |
|
| 2002 | - * |
|
| 2003 | - * @access protected |
|
| 2004 | - * @return array|null |
|
| 2005 | - * @throws EE_Error |
|
| 2006 | - * @throws InvalidArgumentException |
|
| 2007 | - * @throws InvalidDataTypeException |
|
| 2008 | - * @throws InvalidInterfaceException |
|
| 2009 | - */ |
|
| 2010 | - protected function _reset_to_default_template() |
|
| 2011 | - { |
|
| 2012 | - |
|
| 2013 | - $templates = array(); |
|
| 2014 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2015 | - //we need to make sure we've got the info we need. |
|
| 2016 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2017 | - EE_Error::add_error( |
|
| 2018 | - esc_html__( |
|
| 2019 | - '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.', |
|
| 2020 | - 'event_espresso' |
|
| 2021 | - ), |
|
| 2022 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2023 | - ); |
|
| 2024 | - } |
|
| 2025 | - |
|
| 2026 | - // all templates will be reset to whatever the defaults are |
|
| 2027 | - // for the global template matching the messenger and message type. |
|
| 2028 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 2029 | - |
|
| 2030 | - if ($success) { |
|
| 1999 | + /** |
|
| 2000 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2001 | + * they want. |
|
| 2002 | + * |
|
| 2003 | + * @access protected |
|
| 2004 | + * @return array|null |
|
| 2005 | + * @throws EE_Error |
|
| 2006 | + * @throws InvalidArgumentException |
|
| 2007 | + * @throws InvalidDataTypeException |
|
| 2008 | + * @throws InvalidInterfaceException |
|
| 2009 | + */ |
|
| 2010 | + protected function _reset_to_default_template() |
|
| 2011 | + { |
|
| 2012 | + |
|
| 2013 | + $templates = array(); |
|
| 2014 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2015 | + //we need to make sure we've got the info we need. |
|
| 2016 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2017 | + EE_Error::add_error( |
|
| 2018 | + esc_html__( |
|
| 2019 | + '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.', |
|
| 2020 | + 'event_espresso' |
|
| 2021 | + ), |
|
| 2022 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2023 | + ); |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + // all templates will be reset to whatever the defaults are |
|
| 2027 | + // for the global template matching the messenger and message type. |
|
| 2028 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 2029 | + |
|
| 2030 | + if ($success) { |
|
| 2031 | 2031 | |
| 2032 | - //let's first determine if the incoming template is a global template, |
|
| 2033 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2034 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2032 | + //let's first determine if the incoming template is a global template, |
|
| 2033 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2034 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2035 | 2035 | |
| 2036 | 2036 | |
| 2037 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2038 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2037 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2038 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2039 | 2039 | |
| 2040 | - if ($success) { |
|
| 2041 | - // if successfully deleted, lets generate the new ones. |
|
| 2042 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2043 | - // will use the related global template defaults for regeneration. |
|
| 2044 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2045 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 2046 | - // for the current custom template when resetting. |
|
| 2047 | - $templates = $this->_generate_new_templates( |
|
| 2048 | - $this->_req_data['msgr'], |
|
| 2049 | - $this->_req_data['mt'], |
|
| 2050 | - $GRP_ID, |
|
| 2051 | - true |
|
| 2052 | - ); |
|
| 2053 | - } |
|
| 2040 | + if ($success) { |
|
| 2041 | + // if successfully deleted, lets generate the new ones. |
|
| 2042 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2043 | + // will use the related global template defaults for regeneration. |
|
| 2044 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2045 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 2046 | + // for the current custom template when resetting. |
|
| 2047 | + $templates = $this->_generate_new_templates( |
|
| 2048 | + $this->_req_data['msgr'], |
|
| 2049 | + $this->_req_data['mt'], |
|
| 2050 | + $GRP_ID, |
|
| 2051 | + true |
|
| 2052 | + ); |
|
| 2053 | + } |
|
| 2054 | 2054 | |
| 2055 | - } |
|
| 2056 | - |
|
| 2057 | - //any error messages? |
|
| 2058 | - if ( ! $success) { |
|
| 2059 | - EE_Error::add_error( |
|
| 2060 | - esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2061 | - 'event_espresso'), |
|
| 2062 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2063 | - ); |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - //all good, let's add a success message! |
|
| 2067 | - if ($success && ! empty($templates)) { |
|
| 2068 | - //the info for the template we generated is the first element in the returned array |
|
| 2069 | - // $templates = $templates[0]; |
|
| 2070 | - EE_Error::overwrite_success(); |
|
| 2071 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2072 | - } |
|
| 2073 | - |
|
| 2074 | - |
|
| 2075 | - $query_args = array( |
|
| 2076 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2077 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2078 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2079 | - ); |
|
| 2080 | - |
|
| 2081 | - //if called via ajax then we return query args otherwise redirect |
|
| 2082 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2083 | - return $query_args; |
|
| 2084 | - } else { |
|
| 2085 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + //any error messages? |
|
| 2058 | + if ( ! $success) { |
|
| 2059 | + EE_Error::add_error( |
|
| 2060 | + esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2061 | + 'event_espresso'), |
|
| 2062 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2063 | + ); |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + //all good, let's add a success message! |
|
| 2067 | + if ($success && ! empty($templates)) { |
|
| 2068 | + //the info for the template we generated is the first element in the returned array |
|
| 2069 | + // $templates = $templates[0]; |
|
| 2070 | + EE_Error::overwrite_success(); |
|
| 2071 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2072 | + } |
|
| 2073 | + |
|
| 2074 | + |
|
| 2075 | + $query_args = array( |
|
| 2076 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2077 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2078 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2079 | + ); |
|
| 2080 | + |
|
| 2081 | + //if called via ajax then we return query args otherwise redirect |
|
| 2082 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2083 | + return $query_args; |
|
| 2084 | + } else { |
|
| 2085 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2086 | 2086 | |
| 2087 | - return null; |
|
| 2088 | - } |
|
| 2089 | - } |
|
| 2087 | + return null; |
|
| 2088 | + } |
|
| 2089 | + } |
|
| 2090 | 2090 | |
| 2091 | 2091 | |
| 2092 | - /** |
|
| 2093 | - * Retrieve and set the message preview for display. |
|
| 2094 | - * |
|
| 2095 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2096 | - * @return string |
|
| 2097 | - * @throws EE_Error |
|
| 2098 | - * @throws InvalidArgumentException |
|
| 2099 | - * @throws InvalidDataTypeException |
|
| 2100 | - * @throws InvalidInterfaceException |
|
| 2101 | - */ |
|
| 2102 | - public function _preview_message($send = false) |
|
| 2103 | - { |
|
| 2104 | - //first make sure we've got the necessary parameters |
|
| 2105 | - if ( |
|
| 2106 | - ! isset( |
|
| 2107 | - $this->_req_data['message_type'], |
|
| 2108 | - $this->_req_data['messenger'], |
|
| 2109 | - $this->_req_data['messenger'], |
|
| 2110 | - $this->_req_data['GRP_ID'] |
|
| 2111 | - ) |
|
| 2112 | - ) { |
|
| 2113 | - EE_Error::add_error( |
|
| 2114 | - esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2115 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2116 | - ); |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2120 | - |
|
| 2121 | - |
|
| 2122 | - //get the preview! |
|
| 2123 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2124 | - $this->_req_data['messenger'], $send); |
|
| 2125 | - |
|
| 2126 | - if ($send) { |
|
| 2127 | - return $preview; |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - //let's add a button to go back to the edit view |
|
| 2131 | - $query_args = array( |
|
| 2132 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2133 | - 'context' => $this->_req_data['context'], |
|
| 2134 | - 'action' => 'edit_message_template' |
|
| 2135 | - ); |
|
| 2136 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2137 | - $preview_button = '<a href="' |
|
| 2138 | - . $go_back_url |
|
| 2139 | - . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2140 | - . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2141 | - . '</a>'; |
|
| 2142 | - $message_types = $this->get_installed_message_types(); |
|
| 2143 | - $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2144 | - $this->_req_data['messenger'] |
|
| 2145 | - ); |
|
| 2146 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2147 | - ? ucwords($active_messenger->label['singular']) |
|
| 2148 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2149 | - //let's provide a helpful title for context |
|
| 2150 | - $preview_title = sprintf( |
|
| 2151 | - esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2152 | - $active_messenger_label, |
|
| 2153 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2154 | - ); |
|
| 2155 | - //setup display of preview. |
|
| 2156 | - $this->_admin_page_title = $preview_title; |
|
| 2157 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2158 | - $this->_template_args['data']['force_json'] = true; |
|
| 2159 | - |
|
| 2160 | - return ''; |
|
| 2161 | - } |
|
| 2092 | + /** |
|
| 2093 | + * Retrieve and set the message preview for display. |
|
| 2094 | + * |
|
| 2095 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2096 | + * @return string |
|
| 2097 | + * @throws EE_Error |
|
| 2098 | + * @throws InvalidArgumentException |
|
| 2099 | + * @throws InvalidDataTypeException |
|
| 2100 | + * @throws InvalidInterfaceException |
|
| 2101 | + */ |
|
| 2102 | + public function _preview_message($send = false) |
|
| 2103 | + { |
|
| 2104 | + //first make sure we've got the necessary parameters |
|
| 2105 | + if ( |
|
| 2106 | + ! isset( |
|
| 2107 | + $this->_req_data['message_type'], |
|
| 2108 | + $this->_req_data['messenger'], |
|
| 2109 | + $this->_req_data['messenger'], |
|
| 2110 | + $this->_req_data['GRP_ID'] |
|
| 2111 | + ) |
|
| 2112 | + ) { |
|
| 2113 | + EE_Error::add_error( |
|
| 2114 | + esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2115 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2116 | + ); |
|
| 2117 | + } |
|
| 2118 | + |
|
| 2119 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2120 | + |
|
| 2121 | + |
|
| 2122 | + //get the preview! |
|
| 2123 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2124 | + $this->_req_data['messenger'], $send); |
|
| 2125 | + |
|
| 2126 | + if ($send) { |
|
| 2127 | + return $preview; |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + //let's add a button to go back to the edit view |
|
| 2131 | + $query_args = array( |
|
| 2132 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2133 | + 'context' => $this->_req_data['context'], |
|
| 2134 | + 'action' => 'edit_message_template' |
|
| 2135 | + ); |
|
| 2136 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2137 | + $preview_button = '<a href="' |
|
| 2138 | + . $go_back_url |
|
| 2139 | + . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2140 | + . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2141 | + . '</a>'; |
|
| 2142 | + $message_types = $this->get_installed_message_types(); |
|
| 2143 | + $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2144 | + $this->_req_data['messenger'] |
|
| 2145 | + ); |
|
| 2146 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2147 | + ? ucwords($active_messenger->label['singular']) |
|
| 2148 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2149 | + //let's provide a helpful title for context |
|
| 2150 | + $preview_title = sprintf( |
|
| 2151 | + esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2152 | + $active_messenger_label, |
|
| 2153 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2154 | + ); |
|
| 2155 | + //setup display of preview. |
|
| 2156 | + $this->_admin_page_title = $preview_title; |
|
| 2157 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2158 | + $this->_template_args['data']['force_json'] = true; |
|
| 2159 | + |
|
| 2160 | + return ''; |
|
| 2161 | + } |
|
| 2162 | 2162 | |
| 2163 | 2163 | |
| 2164 | - /** |
|
| 2165 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2166 | - * gets called automatically. |
|
| 2167 | - * |
|
| 2168 | - * @since 4.5.0 |
|
| 2169 | - * |
|
| 2170 | - * @return string |
|
| 2171 | - */ |
|
| 2172 | - protected function _display_preview_message() |
|
| 2173 | - { |
|
| 2174 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2175 | - } |
|
| 2164 | + /** |
|
| 2165 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2166 | + * gets called automatically. |
|
| 2167 | + * |
|
| 2168 | + * @since 4.5.0 |
|
| 2169 | + * |
|
| 2170 | + * @return string |
|
| 2171 | + */ |
|
| 2172 | + protected function _display_preview_message() |
|
| 2173 | + { |
|
| 2174 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2175 | + } |
|
| 2176 | 2176 | |
| 2177 | 2177 | |
| 2178 | - /** |
|
| 2179 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2180 | - * |
|
| 2181 | - * @access protected |
|
| 2182 | - * @return void |
|
| 2183 | - */ |
|
| 2184 | - protected function _register_edit_meta_boxes() |
|
| 2185 | - { |
|
| 2186 | - add_meta_box( |
|
| 2187 | - 'mtp_valid_shortcodes', |
|
| 2188 | - esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2189 | - array($this, 'shortcode_meta_box'), |
|
| 2190 | - $this->_current_screen->id, |
|
| 2191 | - 'side', |
|
| 2192 | - 'default'); |
|
| 2193 | - add_meta_box( |
|
| 2194 | - 'mtp_extra_actions', |
|
| 2195 | - esc_html__('Extra Actions', 'event_espresso'), |
|
| 2196 | - array($this, 'extra_actions_meta_box'), |
|
| 2197 | - $this->_current_screen->id, |
|
| 2198 | - 'side', |
|
| 2199 | - 'high' |
|
| 2200 | - ); |
|
| 2201 | - add_meta_box( |
|
| 2202 | - 'mtp_templates', |
|
| 2203 | - esc_html__('Template Styles', 'event_espresso'), |
|
| 2204 | - array($this, 'template_pack_meta_box'), |
|
| 2205 | - $this->_current_screen->id, |
|
| 2206 | - 'side', |
|
| 2207 | - 'high' |
|
| 2208 | - ); |
|
| 2209 | - } |
|
| 2178 | + /** |
|
| 2179 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2180 | + * |
|
| 2181 | + * @access protected |
|
| 2182 | + * @return void |
|
| 2183 | + */ |
|
| 2184 | + protected function _register_edit_meta_boxes() |
|
| 2185 | + { |
|
| 2186 | + add_meta_box( |
|
| 2187 | + 'mtp_valid_shortcodes', |
|
| 2188 | + esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2189 | + array($this, 'shortcode_meta_box'), |
|
| 2190 | + $this->_current_screen->id, |
|
| 2191 | + 'side', |
|
| 2192 | + 'default'); |
|
| 2193 | + add_meta_box( |
|
| 2194 | + 'mtp_extra_actions', |
|
| 2195 | + esc_html__('Extra Actions', 'event_espresso'), |
|
| 2196 | + array($this, 'extra_actions_meta_box'), |
|
| 2197 | + $this->_current_screen->id, |
|
| 2198 | + 'side', |
|
| 2199 | + 'high' |
|
| 2200 | + ); |
|
| 2201 | + add_meta_box( |
|
| 2202 | + 'mtp_templates', |
|
| 2203 | + esc_html__('Template Styles', 'event_espresso'), |
|
| 2204 | + array($this, 'template_pack_meta_box'), |
|
| 2205 | + $this->_current_screen->id, |
|
| 2206 | + 'side', |
|
| 2207 | + 'high' |
|
| 2208 | + ); |
|
| 2209 | + } |
|
| 2210 | 2210 | |
| 2211 | 2211 | |
| 2212 | - /** |
|
| 2213 | - * metabox content for all template pack and variation selection. |
|
| 2214 | - * |
|
| 2215 | - * @since 4.5.0 |
|
| 2216 | - * @return string |
|
| 2217 | - * @throws DomainException |
|
| 2218 | - * @throws EE_Error |
|
| 2219 | - * @throws InvalidArgumentException |
|
| 2220 | - * @throws ReflectionException |
|
| 2221 | - * @throws InvalidDataTypeException |
|
| 2222 | - * @throws InvalidInterfaceException |
|
| 2223 | - */ |
|
| 2224 | - public function template_pack_meta_box() |
|
| 2225 | - { |
|
| 2226 | - $this->_set_message_template_group(); |
|
| 2227 | - |
|
| 2228 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2229 | - |
|
| 2230 | - $tp_select_values = array(); |
|
| 2231 | - |
|
| 2232 | - foreach ($tp_collection as $tp) { |
|
| 2233 | - //only include template packs that support this messenger and message type! |
|
| 2234 | - $supports = $tp->get_supports(); |
|
| 2235 | - if ( |
|
| 2236 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2237 | - || ! in_array( |
|
| 2238 | - $this->_message_template_group->message_type(), |
|
| 2239 | - $supports[$this->_message_template_group->messenger()], |
|
| 2240 | - true |
|
| 2241 | - ) |
|
| 2242 | - ) { |
|
| 2243 | - //not supported |
|
| 2244 | - continue; |
|
| 2245 | - } |
|
| 2212 | + /** |
|
| 2213 | + * metabox content for all template pack and variation selection. |
|
| 2214 | + * |
|
| 2215 | + * @since 4.5.0 |
|
| 2216 | + * @return string |
|
| 2217 | + * @throws DomainException |
|
| 2218 | + * @throws EE_Error |
|
| 2219 | + * @throws InvalidArgumentException |
|
| 2220 | + * @throws ReflectionException |
|
| 2221 | + * @throws InvalidDataTypeException |
|
| 2222 | + * @throws InvalidInterfaceException |
|
| 2223 | + */ |
|
| 2224 | + public function template_pack_meta_box() |
|
| 2225 | + { |
|
| 2226 | + $this->_set_message_template_group(); |
|
| 2227 | + |
|
| 2228 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2229 | + |
|
| 2230 | + $tp_select_values = array(); |
|
| 2231 | + |
|
| 2232 | + foreach ($tp_collection as $tp) { |
|
| 2233 | + //only include template packs that support this messenger and message type! |
|
| 2234 | + $supports = $tp->get_supports(); |
|
| 2235 | + if ( |
|
| 2236 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2237 | + || ! in_array( |
|
| 2238 | + $this->_message_template_group->message_type(), |
|
| 2239 | + $supports[$this->_message_template_group->messenger()], |
|
| 2240 | + true |
|
| 2241 | + ) |
|
| 2242 | + ) { |
|
| 2243 | + //not supported |
|
| 2244 | + continue; |
|
| 2245 | + } |
|
| 2246 | 2246 | |
| 2247 | - $tp_select_values[] = array( |
|
| 2248 | - 'text' => $tp->label, |
|
| 2249 | - 'id' => $tp->dbref |
|
| 2250 | - ); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2254 | - // the default template pack. This still allows for the odd template pack to override. |
|
| 2255 | - if (empty($tp_select_values)) { |
|
| 2256 | - $tp_select_values[] = array( |
|
| 2257 | - 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2258 | - 'id' => 'default' |
|
| 2259 | - ); |
|
| 2260 | - } |
|
| 2261 | - |
|
| 2262 | - //setup variation select values for the currently selected template. |
|
| 2263 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2264 | - $this->_message_template_group->messenger(), |
|
| 2265 | - $this->_message_template_group->message_type() |
|
| 2266 | - ); |
|
| 2267 | - $variations_select_values = array(); |
|
| 2268 | - foreach ($variations as $variation => $label) { |
|
| 2269 | - $variations_select_values[] = array( |
|
| 2270 | - 'text' => $label, |
|
| 2271 | - 'id' => $variation |
|
| 2272 | - ); |
|
| 2273 | - } |
|
| 2274 | - |
|
| 2275 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2276 | - |
|
| 2277 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2278 | - 'MTP_template_pack', |
|
| 2279 | - $tp_select_values, |
|
| 2280 | - $this->_message_template_group->get_template_pack_name() |
|
| 2281 | - ); |
|
| 2282 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2283 | - 'MTP_template_variation', |
|
| 2284 | - $variations_select_values, |
|
| 2285 | - $this->_message_template_group->get_template_pack_variation() |
|
| 2286 | - ); |
|
| 2287 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2288 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2289 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2290 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2291 | - |
|
| 2292 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2293 | - |
|
| 2294 | - EEH_Template::display_template($template, $template_args); |
|
| 2295 | - } |
|
| 2247 | + $tp_select_values[] = array( |
|
| 2248 | + 'text' => $tp->label, |
|
| 2249 | + 'id' => $tp->dbref |
|
| 2250 | + ); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2254 | + // the default template pack. This still allows for the odd template pack to override. |
|
| 2255 | + if (empty($tp_select_values)) { |
|
| 2256 | + $tp_select_values[] = array( |
|
| 2257 | + 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2258 | + 'id' => 'default' |
|
| 2259 | + ); |
|
| 2260 | + } |
|
| 2261 | + |
|
| 2262 | + //setup variation select values for the currently selected template. |
|
| 2263 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2264 | + $this->_message_template_group->messenger(), |
|
| 2265 | + $this->_message_template_group->message_type() |
|
| 2266 | + ); |
|
| 2267 | + $variations_select_values = array(); |
|
| 2268 | + foreach ($variations as $variation => $label) { |
|
| 2269 | + $variations_select_values[] = array( |
|
| 2270 | + 'text' => $label, |
|
| 2271 | + 'id' => $variation |
|
| 2272 | + ); |
|
| 2273 | + } |
|
| 2274 | + |
|
| 2275 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2276 | + |
|
| 2277 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2278 | + 'MTP_template_pack', |
|
| 2279 | + $tp_select_values, |
|
| 2280 | + $this->_message_template_group->get_template_pack_name() |
|
| 2281 | + ); |
|
| 2282 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2283 | + 'MTP_template_variation', |
|
| 2284 | + $variations_select_values, |
|
| 2285 | + $this->_message_template_group->get_template_pack_variation() |
|
| 2286 | + ); |
|
| 2287 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2288 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2289 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2290 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2291 | + |
|
| 2292 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2293 | + |
|
| 2294 | + EEH_Template::display_template($template, $template_args); |
|
| 2295 | + } |
|
| 2296 | 2296 | |
| 2297 | 2297 | |
| 2298 | - /** |
|
| 2299 | - * This meta box holds any extra actions related to Message Templates |
|
| 2300 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2301 | - * |
|
| 2302 | - * @access public |
|
| 2303 | - * @return void |
|
| 2304 | - * @throws EE_Error |
|
| 2305 | - */ |
|
| 2306 | - public function extra_actions_meta_box() |
|
| 2307 | - { |
|
| 2308 | - $template_form_fields = array(); |
|
| 2309 | - |
|
| 2310 | - $extra_args = array( |
|
| 2311 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2312 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2313 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2314 | - ); |
|
| 2315 | - //first we need to see if there are any fields |
|
| 2316 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2317 | - |
|
| 2318 | - if ( ! empty($fields)) { |
|
| 2319 | - //yup there be fields |
|
| 2320 | - foreach ($fields as $field => $config) { |
|
| 2321 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2322 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2323 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2324 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2298 | + /** |
|
| 2299 | + * This meta box holds any extra actions related to Message Templates |
|
| 2300 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2301 | + * |
|
| 2302 | + * @access public |
|
| 2303 | + * @return void |
|
| 2304 | + * @throws EE_Error |
|
| 2305 | + */ |
|
| 2306 | + public function extra_actions_meta_box() |
|
| 2307 | + { |
|
| 2308 | + $template_form_fields = array(); |
|
| 2309 | + |
|
| 2310 | + $extra_args = array( |
|
| 2311 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2312 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2313 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2314 | + ); |
|
| 2315 | + //first we need to see if there are any fields |
|
| 2316 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2317 | + |
|
| 2318 | + if ( ! empty($fields)) { |
|
| 2319 | + //yup there be fields |
|
| 2320 | + foreach ($fields as $field => $config) { |
|
| 2321 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2322 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2323 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2324 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2325 | 2325 | |
| 2326 | - // if type is hidden and the value is empty |
|
| 2327 | - // something may have gone wrong so let's correct with the defaults |
|
| 2328 | - $fix = $config['input'] === 'hidden' |
|
| 2329 | - && isset($existing[$field]) |
|
| 2330 | - && empty($existing[$field]) |
|
| 2331 | - ? $default |
|
| 2332 | - : ''; |
|
| 2333 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2334 | - ? $existing[$field] |
|
| 2335 | - : $fix; |
|
| 2326 | + // if type is hidden and the value is empty |
|
| 2327 | + // something may have gone wrong so let's correct with the defaults |
|
| 2328 | + $fix = $config['input'] === 'hidden' |
|
| 2329 | + && isset($existing[$field]) |
|
| 2330 | + && empty($existing[$field]) |
|
| 2331 | + ? $default |
|
| 2332 | + : ''; |
|
| 2333 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2334 | + ? $existing[$field] |
|
| 2335 | + : $fix; |
|
| 2336 | 2336 | |
| 2337 | - $template_form_fields[$field_id] = array( |
|
| 2338 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2339 | - 'label' => $config['label'], |
|
| 2340 | - 'input' => $config['input'], |
|
| 2341 | - 'type' => $config['type'], |
|
| 2342 | - 'required' => $config['required'], |
|
| 2343 | - 'validation' => $config['validation'], |
|
| 2344 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2345 | - 'css_class' => $config['css_class'], |
|
| 2346 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2347 | - 'default' => $default, |
|
| 2348 | - 'format' => $config['format'] |
|
| 2349 | - ); |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - |
|
| 2353 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2354 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2355 | - : ''; |
|
| 2356 | - |
|
| 2357 | - $test_settings_html = ''; |
|
| 2358 | - //print out $test_settings_fields |
|
| 2359 | - if ( ! empty($test_settings_fields)) { |
|
| 2360 | - echo $test_settings_fields; |
|
| 2361 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2362 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2363 | - $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2364 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2365 | - } |
|
| 2366 | - |
|
| 2367 | - //and button |
|
| 2368 | - $test_settings_html .= '<p>' |
|
| 2369 | - . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2370 | - . '</p>'; |
|
| 2371 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2372 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2373 | - 'reset_to_default', |
|
| 2374 | - 'reset', |
|
| 2375 | - $extra_args, |
|
| 2376 | - 'button-primary reset-default-button' |
|
| 2377 | - ); |
|
| 2378 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2379 | - echo $test_settings_html; |
|
| 2380 | - } |
|
| 2337 | + $template_form_fields[$field_id] = array( |
|
| 2338 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2339 | + 'label' => $config['label'], |
|
| 2340 | + 'input' => $config['input'], |
|
| 2341 | + 'type' => $config['type'], |
|
| 2342 | + 'required' => $config['required'], |
|
| 2343 | + 'validation' => $config['validation'], |
|
| 2344 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2345 | + 'css_class' => $config['css_class'], |
|
| 2346 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2347 | + 'default' => $default, |
|
| 2348 | + 'format' => $config['format'] |
|
| 2349 | + ); |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + |
|
| 2353 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2354 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2355 | + : ''; |
|
| 2356 | + |
|
| 2357 | + $test_settings_html = ''; |
|
| 2358 | + //print out $test_settings_fields |
|
| 2359 | + if ( ! empty($test_settings_fields)) { |
|
| 2360 | + echo $test_settings_fields; |
|
| 2361 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2362 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2363 | + $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2364 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2365 | + } |
|
| 2366 | + |
|
| 2367 | + //and button |
|
| 2368 | + $test_settings_html .= '<p>' |
|
| 2369 | + . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2370 | + . '</p>'; |
|
| 2371 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2372 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2373 | + 'reset_to_default', |
|
| 2374 | + 'reset', |
|
| 2375 | + $extra_args, |
|
| 2376 | + 'button-primary reset-default-button' |
|
| 2377 | + ); |
|
| 2378 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2379 | + echo $test_settings_html; |
|
| 2380 | + } |
|
| 2381 | 2381 | |
| 2382 | 2382 | |
| 2383 | - /** |
|
| 2384 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2385 | - * |
|
| 2386 | - * @since 4.9.rc.000 |
|
| 2387 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2388 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2389 | - * @return string |
|
| 2390 | - * @throws DomainException |
|
| 2391 | - * @throws EE_Error |
|
| 2392 | - * @throws InvalidArgumentException |
|
| 2393 | - * @throws ReflectionException |
|
| 2394 | - * @throws InvalidDataTypeException |
|
| 2395 | - * @throws InvalidInterfaceException |
|
| 2396 | - */ |
|
| 2397 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2398 | - { |
|
| 2399 | - $template_args = array( |
|
| 2400 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2401 | - 'fieldname' => $field, |
|
| 2402 | - 'linked_input_id' => $linked_input_id |
|
| 2403 | - ); |
|
| 2404 | - |
|
| 2405 | - return EEH_Template::display_template( |
|
| 2406 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2407 | - $template_args, |
|
| 2408 | - true |
|
| 2409 | - ); |
|
| 2410 | - } |
|
| 2383 | + /** |
|
| 2384 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2385 | + * |
|
| 2386 | + * @since 4.9.rc.000 |
|
| 2387 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2388 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2389 | + * @return string |
|
| 2390 | + * @throws DomainException |
|
| 2391 | + * @throws EE_Error |
|
| 2392 | + * @throws InvalidArgumentException |
|
| 2393 | + * @throws ReflectionException |
|
| 2394 | + * @throws InvalidDataTypeException |
|
| 2395 | + * @throws InvalidInterfaceException |
|
| 2396 | + */ |
|
| 2397 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2398 | + { |
|
| 2399 | + $template_args = array( |
|
| 2400 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2401 | + 'fieldname' => $field, |
|
| 2402 | + 'linked_input_id' => $linked_input_id |
|
| 2403 | + ); |
|
| 2404 | + |
|
| 2405 | + return EEH_Template::display_template( |
|
| 2406 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2407 | + $template_args, |
|
| 2408 | + true |
|
| 2409 | + ); |
|
| 2410 | + } |
|
| 2411 | 2411 | |
| 2412 | 2412 | |
| 2413 | - /** |
|
| 2414 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2415 | - * page) |
|
| 2416 | - * |
|
| 2417 | - * @access public |
|
| 2418 | - * @return void |
|
| 2419 | - * @throws EE_Error |
|
| 2420 | - * @throws InvalidArgumentException |
|
| 2421 | - * @throws ReflectionException |
|
| 2422 | - * @throws InvalidDataTypeException |
|
| 2423 | - * @throws InvalidInterfaceException |
|
| 2424 | - */ |
|
| 2425 | - public function shortcode_meta_box() |
|
| 2426 | - { |
|
| 2427 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2428 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2429 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2430 | - if (empty($shortcodes)) { |
|
| 2431 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2432 | - echo $content; |
|
| 2433 | - } else { |
|
| 2434 | - //$alt = 0; |
|
| 2435 | - ?> |
|
| 2413 | + /** |
|
| 2414 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2415 | + * page) |
|
| 2416 | + * |
|
| 2417 | + * @access public |
|
| 2418 | + * @return void |
|
| 2419 | + * @throws EE_Error |
|
| 2420 | + * @throws InvalidArgumentException |
|
| 2421 | + * @throws ReflectionException |
|
| 2422 | + * @throws InvalidDataTypeException |
|
| 2423 | + * @throws InvalidInterfaceException |
|
| 2424 | + */ |
|
| 2425 | + public function shortcode_meta_box() |
|
| 2426 | + { |
|
| 2427 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2428 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2429 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2430 | + if (empty($shortcodes)) { |
|
| 2431 | + $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2432 | + echo $content; |
|
| 2433 | + } else { |
|
| 2434 | + //$alt = 0; |
|
| 2435 | + ?> |
|
| 2436 | 2436 | <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2437 | 2437 | <p class="small-text"><?php printf( |
| 2438 | - esc_html__( |
|
| 2439 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2440 | - 'event_espresso' |
|
| 2441 | - ), |
|
| 2442 | - '<span class="dashicons dashicons-menu"></span>' |
|
| 2443 | - ); ?></p> |
|
| 2438 | + esc_html__( |
|
| 2439 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2440 | + 'event_espresso' |
|
| 2441 | + ), |
|
| 2442 | + '<span class="dashicons dashicons-menu"></span>' |
|
| 2443 | + ); ?></p> |
|
| 2444 | 2444 | <?php |
| 2445 | - } |
|
| 2445 | + } |
|
| 2446 | 2446 | |
| 2447 | 2447 | |
| 2448 | - } |
|
| 2448 | + } |
|
| 2449 | 2449 | |
| 2450 | 2450 | |
| 2451 | - /** |
|
| 2452 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2453 | - * |
|
| 2454 | - * @access protected |
|
| 2455 | - * @return void |
|
| 2456 | - * @throws EE_Error |
|
| 2457 | - * @throws InvalidArgumentException |
|
| 2458 | - * @throws ReflectionException |
|
| 2459 | - * @throws InvalidDataTypeException |
|
| 2460 | - * @throws InvalidInterfaceException |
|
| 2461 | - */ |
|
| 2462 | - protected function _set_shortcodes() |
|
| 2463 | - { |
|
| 2464 | - |
|
| 2465 | - //no need to run this if the property is already set |
|
| 2466 | - if ( ! empty($this->_shortcodes)) { |
|
| 2467 | - return; |
|
| 2468 | - } |
|
| 2469 | - |
|
| 2470 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2471 | - } |
|
| 2451 | + /** |
|
| 2452 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2453 | + * |
|
| 2454 | + * @access protected |
|
| 2455 | + * @return void |
|
| 2456 | + * @throws EE_Error |
|
| 2457 | + * @throws InvalidArgumentException |
|
| 2458 | + * @throws ReflectionException |
|
| 2459 | + * @throws InvalidDataTypeException |
|
| 2460 | + * @throws InvalidInterfaceException |
|
| 2461 | + */ |
|
| 2462 | + protected function _set_shortcodes() |
|
| 2463 | + { |
|
| 2464 | + |
|
| 2465 | + //no need to run this if the property is already set |
|
| 2466 | + if ( ! empty($this->_shortcodes)) { |
|
| 2467 | + return; |
|
| 2468 | + } |
|
| 2469 | + |
|
| 2470 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2471 | + } |
|
| 2472 | 2472 | |
| 2473 | 2473 | |
| 2474 | - /** |
|
| 2475 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2476 | - * property) |
|
| 2477 | - * |
|
| 2478 | - * @access protected |
|
| 2479 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2480 | - * for. Defaults to all (for the given context) |
|
| 2481 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2482 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2483 | - * true just an array of shortcode/label pairs. |
|
| 2484 | - * @throws EE_Error |
|
| 2485 | - * @throws InvalidArgumentException |
|
| 2486 | - * @throws ReflectionException |
|
| 2487 | - * @throws InvalidDataTypeException |
|
| 2488 | - * @throws InvalidInterfaceException |
|
| 2489 | - */ |
|
| 2490 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2491 | - { |
|
| 2492 | - $this->_set_message_template_group(); |
|
| 2493 | - |
|
| 2494 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2495 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2496 | - ? absint($this->_req_data['id']) |
|
| 2497 | - : false; |
|
| 2498 | - $context = isset($this->_req_data['context']) |
|
| 2499 | - ? $this->_req_data['context'] |
|
| 2500 | - : key($this->_message_template_group->contexts_config()); |
|
| 2501 | - |
|
| 2502 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2503 | - } |
|
| 2474 | + /** |
|
| 2475 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2476 | + * property) |
|
| 2477 | + * |
|
| 2478 | + * @access protected |
|
| 2479 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2480 | + * for. Defaults to all (for the given context) |
|
| 2481 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2482 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2483 | + * true just an array of shortcode/label pairs. |
|
| 2484 | + * @throws EE_Error |
|
| 2485 | + * @throws InvalidArgumentException |
|
| 2486 | + * @throws ReflectionException |
|
| 2487 | + * @throws InvalidDataTypeException |
|
| 2488 | + * @throws InvalidInterfaceException |
|
| 2489 | + */ |
|
| 2490 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2491 | + { |
|
| 2492 | + $this->_set_message_template_group(); |
|
| 2493 | + |
|
| 2494 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2495 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2496 | + ? absint($this->_req_data['id']) |
|
| 2497 | + : false; |
|
| 2498 | + $context = isset($this->_req_data['context']) |
|
| 2499 | + ? $this->_req_data['context'] |
|
| 2500 | + : key($this->_message_template_group->contexts_config()); |
|
| 2501 | + |
|
| 2502 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2503 | + } |
|
| 2504 | 2504 | |
| 2505 | 2505 | |
| 2506 | - /** |
|
| 2507 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2508 | - * |
|
| 2509 | - * @access protected |
|
| 2510 | - * @return void |
|
| 2511 | - * @throws EE_Error |
|
| 2512 | - * @throws InvalidArgumentException |
|
| 2513 | - * @throws ReflectionException |
|
| 2514 | - * @throws InvalidDataTypeException |
|
| 2515 | - * @throws InvalidInterfaceException |
|
| 2516 | - */ |
|
| 2517 | - protected function _set_message_template_group() |
|
| 2518 | - { |
|
| 2519 | - |
|
| 2520 | - if ( ! empty($this->_message_template_group)) { |
|
| 2521 | - return; |
|
| 2522 | - } //get out if this is already set. |
|
| 2523 | - |
|
| 2524 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2525 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2526 | - |
|
| 2527 | - //let's get the message templates |
|
| 2528 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2529 | - |
|
| 2530 | - if (empty($GRP_ID)) { |
|
| 2531 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2532 | - } else { |
|
| 2533 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2534 | - } |
|
| 2535 | - |
|
| 2536 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2537 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2538 | - |
|
| 2539 | - } |
|
| 2506 | + /** |
|
| 2507 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2508 | + * |
|
| 2509 | + * @access protected |
|
| 2510 | + * @return void |
|
| 2511 | + * @throws EE_Error |
|
| 2512 | + * @throws InvalidArgumentException |
|
| 2513 | + * @throws ReflectionException |
|
| 2514 | + * @throws InvalidDataTypeException |
|
| 2515 | + * @throws InvalidInterfaceException |
|
| 2516 | + */ |
|
| 2517 | + protected function _set_message_template_group() |
|
| 2518 | + { |
|
| 2519 | + |
|
| 2520 | + if ( ! empty($this->_message_template_group)) { |
|
| 2521 | + return; |
|
| 2522 | + } //get out if this is already set. |
|
| 2523 | + |
|
| 2524 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2525 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2526 | + |
|
| 2527 | + //let's get the message templates |
|
| 2528 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2529 | + |
|
| 2530 | + if (empty($GRP_ID)) { |
|
| 2531 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2532 | + } else { |
|
| 2533 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2534 | + } |
|
| 2535 | + |
|
| 2536 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2537 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2538 | + |
|
| 2539 | + } |
|
| 2540 | 2540 | |
| 2541 | 2541 | |
| 2542 | - /** |
|
| 2543 | - * sets up a context switcher for edit forms |
|
| 2544 | - * |
|
| 2545 | - * @access protected |
|
| 2546 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2547 | - * @param array $args various things the context switcher needs. |
|
| 2548 | - * @throws EE_Error |
|
| 2549 | - */ |
|
| 2550 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2551 | - { |
|
| 2552 | - $context_details = $template_group_object->contexts_config(); |
|
| 2553 | - $context_label = $template_group_object->context_label(); |
|
| 2554 | - ob_start(); |
|
| 2555 | - ?> |
|
| 2542 | + /** |
|
| 2543 | + * sets up a context switcher for edit forms |
|
| 2544 | + * |
|
| 2545 | + * @access protected |
|
| 2546 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2547 | + * @param array $args various things the context switcher needs. |
|
| 2548 | + * @throws EE_Error |
|
| 2549 | + */ |
|
| 2550 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2551 | + { |
|
| 2552 | + $context_details = $template_group_object->contexts_config(); |
|
| 2553 | + $context_label = $template_group_object->context_label(); |
|
| 2554 | + ob_start(); |
|
| 2555 | + ?> |
|
| 2556 | 2556 | <div class="ee-msg-switcher-container"> |
| 2557 | 2557 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2558 | 2558 | <?php |
| 2559 | - foreach ($args as $name => $value) { |
|
| 2560 | - if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2561 | - continue; |
|
| 2562 | - } |
|
| 2563 | - ?> |
|
| 2559 | + foreach ($args as $name => $value) { |
|
| 2560 | + if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2561 | + continue; |
|
| 2562 | + } |
|
| 2563 | + ?> |
|
| 2564 | 2564 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2565 | 2565 | <?php |
| 2566 | - } |
|
| 2567 | - //setup nonce_url |
|
| 2568 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2569 | - ?> |
|
| 2566 | + } |
|
| 2567 | + //setup nonce_url |
|
| 2568 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2569 | + ?> |
|
| 2570 | 2570 | <select name="context"> |
| 2571 | 2571 | <?php |
| 2572 | - $context_templates = $template_group_object->context_templates(); |
|
| 2573 | - if (is_array($context_templates)) : |
|
| 2574 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2575 | - $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2576 | - ?> |
|
| 2572 | + $context_templates = $template_group_object->context_templates(); |
|
| 2573 | + if (is_array($context_templates)) : |
|
| 2574 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2575 | + $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2576 | + ?> |
|
| 2577 | 2577 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2578 | 2578 | <?php echo $context_details[$context]['label']; ?> |
| 2579 | 2579 | </option> |
@@ -2586,1823 +2586,1823 @@ discard block |
||
| 2586 | 2586 | <?php echo $args['extra']; ?> |
| 2587 | 2587 | </div> <!-- end .ee-msg-switcher-container --> |
| 2588 | 2588 | <?php |
| 2589 | - $output = ob_get_contents(); |
|
| 2590 | - ob_clean(); |
|
| 2591 | - $this->_context_switcher = $output; |
|
| 2592 | - } |
|
| 2589 | + $output = ob_get_contents(); |
|
| 2590 | + ob_clean(); |
|
| 2591 | + $this->_context_switcher = $output; |
|
| 2592 | + } |
|
| 2593 | 2593 | |
| 2594 | 2594 | |
| 2595 | - /** |
|
| 2596 | - * utility for sanitizing new values coming in. |
|
| 2597 | - * Note: this is only used when updating a context. |
|
| 2598 | - * |
|
| 2599 | - * @access protected |
|
| 2600 | - * |
|
| 2601 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2602 | - * |
|
| 2603 | - * @return array |
|
| 2604 | - */ |
|
| 2605 | - protected function _set_message_template_column_values($index) |
|
| 2606 | - { |
|
| 2607 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2608 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2609 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2610 | - } |
|
| 2611 | - } |
|
| 2612 | - |
|
| 2613 | - |
|
| 2614 | - $set_column_values = array( |
|
| 2615 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2616 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2617 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2618 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2619 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2620 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2621 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2622 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2623 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2624 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2625 | - : 0, |
|
| 2626 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2627 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2628 | - : 0, |
|
| 2629 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2630 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2631 | - ); |
|
| 2632 | - |
|
| 2633 | - |
|
| 2634 | - return $set_column_values; |
|
| 2635 | - } |
|
| 2595 | + /** |
|
| 2596 | + * utility for sanitizing new values coming in. |
|
| 2597 | + * Note: this is only used when updating a context. |
|
| 2598 | + * |
|
| 2599 | + * @access protected |
|
| 2600 | + * |
|
| 2601 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2602 | + * |
|
| 2603 | + * @return array |
|
| 2604 | + */ |
|
| 2605 | + protected function _set_message_template_column_values($index) |
|
| 2606 | + { |
|
| 2607 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2608 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2609 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2610 | + } |
|
| 2611 | + } |
|
| 2612 | + |
|
| 2613 | + |
|
| 2614 | + $set_column_values = array( |
|
| 2615 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2616 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2617 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2618 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2619 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2620 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2621 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2622 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2623 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2624 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2625 | + : 0, |
|
| 2626 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2627 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2628 | + : 0, |
|
| 2629 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2630 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2631 | + ); |
|
| 2632 | + |
|
| 2633 | + |
|
| 2634 | + return $set_column_values; |
|
| 2635 | + } |
|
| 2636 | 2636 | |
| 2637 | 2637 | |
| 2638 | - protected function _insert_or_update_message_template($new = false) |
|
| 2639 | - { |
|
| 2640 | - |
|
| 2641 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2642 | - $success = 0; |
|
| 2643 | - $override = false; |
|
| 2644 | - |
|
| 2645 | - //setup notices description |
|
| 2646 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2647 | - |
|
| 2648 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2649 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2650 | - $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2651 | - ? ucwords($messenger_object->label['singular']) |
|
| 2652 | - : ''; |
|
| 2653 | - |
|
| 2654 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2655 | - ? $this->_req_data['MTP_message_type'] |
|
| 2656 | - : ''; |
|
| 2657 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2658 | - |
|
| 2659 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2660 | - ? ucwords($message_type_object->label['singular']) |
|
| 2661 | - : ''; |
|
| 2662 | - |
|
| 2663 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2664 | - ? $this->_req_data['MTP_context'] |
|
| 2665 | - : ''; |
|
| 2666 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2667 | - |
|
| 2668 | - $item_desc = $messenger_label && $message_type_label |
|
| 2669 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2670 | - : ''; |
|
| 2671 | - $item_desc .= 'Message Template'; |
|
| 2672 | - $query_args = array(); |
|
| 2673 | - $edit_array = array(); |
|
| 2674 | - $action_desc = ''; |
|
| 2675 | - |
|
| 2676 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2677 | - // user to edit. |
|
| 2678 | - if ($new) { |
|
| 2679 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2680 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2681 | - if (empty($edit_array)) { |
|
| 2682 | - $success = 0; |
|
| 2683 | - } else { |
|
| 2684 | - $success = 1; |
|
| 2685 | - $edit_array = $edit_array[0]; |
|
| 2686 | - $query_args = array( |
|
| 2687 | - 'id' => $edit_array['GRP_ID'], |
|
| 2688 | - 'context' => $edit_array['MTP_context'], |
|
| 2689 | - 'action' => 'edit_message_template' |
|
| 2690 | - ); |
|
| 2691 | - } |
|
| 2692 | - } |
|
| 2693 | - $action_desc = 'created'; |
|
| 2694 | - } else { |
|
| 2695 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2696 | - $MTP = EEM_Message_Template::instance(); |
|
| 2638 | + protected function _insert_or_update_message_template($new = false) |
|
| 2639 | + { |
|
| 2640 | + |
|
| 2641 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2642 | + $success = 0; |
|
| 2643 | + $override = false; |
|
| 2644 | + |
|
| 2645 | + //setup notices description |
|
| 2646 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2647 | + |
|
| 2648 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2649 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2650 | + $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2651 | + ? ucwords($messenger_object->label['singular']) |
|
| 2652 | + : ''; |
|
| 2653 | + |
|
| 2654 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2655 | + ? $this->_req_data['MTP_message_type'] |
|
| 2656 | + : ''; |
|
| 2657 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2658 | + |
|
| 2659 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2660 | + ? ucwords($message_type_object->label['singular']) |
|
| 2661 | + : ''; |
|
| 2662 | + |
|
| 2663 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2664 | + ? $this->_req_data['MTP_context'] |
|
| 2665 | + : ''; |
|
| 2666 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2667 | + |
|
| 2668 | + $item_desc = $messenger_label && $message_type_label |
|
| 2669 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2670 | + : ''; |
|
| 2671 | + $item_desc .= 'Message Template'; |
|
| 2672 | + $query_args = array(); |
|
| 2673 | + $edit_array = array(); |
|
| 2674 | + $action_desc = ''; |
|
| 2675 | + |
|
| 2676 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2677 | + // user to edit. |
|
| 2678 | + if ($new) { |
|
| 2679 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2680 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2681 | + if (empty($edit_array)) { |
|
| 2682 | + $success = 0; |
|
| 2683 | + } else { |
|
| 2684 | + $success = 1; |
|
| 2685 | + $edit_array = $edit_array[0]; |
|
| 2686 | + $query_args = array( |
|
| 2687 | + 'id' => $edit_array['GRP_ID'], |
|
| 2688 | + 'context' => $edit_array['MTP_context'], |
|
| 2689 | + 'action' => 'edit_message_template' |
|
| 2690 | + ); |
|
| 2691 | + } |
|
| 2692 | + } |
|
| 2693 | + $action_desc = 'created'; |
|
| 2694 | + } else { |
|
| 2695 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2696 | + $MTP = EEM_Message_Template::instance(); |
|
| 2697 | 2697 | |
| 2698 | 2698 | |
| 2699 | - //run update for each template field in displayed context |
|
| 2700 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2701 | - EE_Error::add_error( |
|
| 2702 | - esc_html__( |
|
| 2703 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2704 | - 'event_espresso' |
|
| 2705 | - ), |
|
| 2706 | - __FILE__, |
|
| 2707 | - __FUNCTION__, |
|
| 2708 | - __LINE__ |
|
| 2709 | - ); |
|
| 2710 | - $success = 0; |
|
| 2699 | + //run update for each template field in displayed context |
|
| 2700 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2701 | + EE_Error::add_error( |
|
| 2702 | + esc_html__( |
|
| 2703 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2704 | + 'event_espresso' |
|
| 2705 | + ), |
|
| 2706 | + __FILE__, |
|
| 2707 | + __FUNCTION__, |
|
| 2708 | + __LINE__ |
|
| 2709 | + ); |
|
| 2710 | + $success = 0; |
|
| 2711 | 2711 | |
| 2712 | - } else { |
|
| 2713 | - //first validate all fields! |
|
| 2714 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2715 | - $message_type_slug); |
|
| 2712 | + } else { |
|
| 2713 | + //first validate all fields! |
|
| 2714 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2715 | + $message_type_slug); |
|
| 2716 | 2716 | |
| 2717 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2718 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2719 | - // WE need to make sure there is no actual error messages in validates. |
|
| 2720 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2721 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2722 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2717 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2718 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2719 | + // WE need to make sure there is no actual error messages in validates. |
|
| 2720 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2721 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2722 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2723 | 2723 | |
| 2724 | - $success = 0; |
|
| 2724 | + $success = 0; |
|
| 2725 | 2725 | |
| 2726 | - //setup notices |
|
| 2727 | - foreach ($validates as $field => $error) { |
|
| 2728 | - if (isset($error['msg'])) { |
|
| 2729 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2730 | - } |
|
| 2731 | - } |
|
| 2726 | + //setup notices |
|
| 2727 | + foreach ($validates as $field => $error) { |
|
| 2728 | + if (isset($error['msg'])) { |
|
| 2729 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2730 | + } |
|
| 2731 | + } |
|
| 2732 | 2732 | |
| 2733 | - } else { |
|
| 2734 | - $set_column_values = array(); |
|
| 2735 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2736 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2733 | + } else { |
|
| 2734 | + $set_column_values = array(); |
|
| 2735 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2736 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2737 | 2737 | |
| 2738 | - $where_cols_n_values = array( |
|
| 2739 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2740 | - ); |
|
| 2738 | + $where_cols_n_values = array( |
|
| 2739 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2740 | + ); |
|
| 2741 | 2741 | |
| 2742 | - $message_template_fields = array( |
|
| 2743 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2744 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2745 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2746 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2747 | - ); |
|
| 2748 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2749 | - if ($updated === false) { |
|
| 2750 | - EE_Error::add_error( |
|
| 2751 | - sprintf( |
|
| 2752 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2753 | - $template_field |
|
| 2754 | - ), |
|
| 2755 | - __FILE__, |
|
| 2756 | - __FUNCTION__, |
|
| 2757 | - __LINE__ |
|
| 2758 | - ); |
|
| 2759 | - } else { |
|
| 2760 | - $success = 1; |
|
| 2761 | - } |
|
| 2762 | - } else { |
|
| 2763 | - //only do this logic if we don't have a MTP_ID for this field |
|
| 2764 | - if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2765 | - //this has already been through the template field validator and sanitized, so it will be |
|
| 2766 | - //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2767 | - //message template field in a messenger/message type and existing users don't have the |
|
| 2768 | - //default setup for it. |
|
| 2769 | - //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2770 | - $updated = $MTP->insert($message_template_fields); |
|
| 2771 | - if (! $updated || is_wp_error($updated)) { |
|
| 2772 | - EE_Error::add_error( |
|
| 2773 | - sprintf( |
|
| 2774 | - esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2775 | - $template_field |
|
| 2776 | - ), |
|
| 2777 | - __FILE__, |
|
| 2778 | - __FUNCTION__, |
|
| 2779 | - __LINE__ |
|
| 2780 | - ); |
|
| 2781 | - $success = 0; |
|
| 2782 | - } else { |
|
| 2783 | - $success = 1; |
|
| 2784 | - } |
|
| 2785 | - } |
|
| 2786 | - } |
|
| 2787 | - $action_desc = 'updated'; |
|
| 2788 | - } |
|
| 2742 | + $message_template_fields = array( |
|
| 2743 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2744 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2745 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2746 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2747 | + ); |
|
| 2748 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2749 | + if ($updated === false) { |
|
| 2750 | + EE_Error::add_error( |
|
| 2751 | + sprintf( |
|
| 2752 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2753 | + $template_field |
|
| 2754 | + ), |
|
| 2755 | + __FILE__, |
|
| 2756 | + __FUNCTION__, |
|
| 2757 | + __LINE__ |
|
| 2758 | + ); |
|
| 2759 | + } else { |
|
| 2760 | + $success = 1; |
|
| 2761 | + } |
|
| 2762 | + } else { |
|
| 2763 | + //only do this logic if we don't have a MTP_ID for this field |
|
| 2764 | + if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2765 | + //this has already been through the template field validator and sanitized, so it will be |
|
| 2766 | + //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2767 | + //message template field in a messenger/message type and existing users don't have the |
|
| 2768 | + //default setup for it. |
|
| 2769 | + //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2770 | + $updated = $MTP->insert($message_template_fields); |
|
| 2771 | + if (! $updated || is_wp_error($updated)) { |
|
| 2772 | + EE_Error::add_error( |
|
| 2773 | + sprintf( |
|
| 2774 | + esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2775 | + $template_field |
|
| 2776 | + ), |
|
| 2777 | + __FILE__, |
|
| 2778 | + __FUNCTION__, |
|
| 2779 | + __LINE__ |
|
| 2780 | + ); |
|
| 2781 | + $success = 0; |
|
| 2782 | + } else { |
|
| 2783 | + $success = 1; |
|
| 2784 | + } |
|
| 2785 | + } |
|
| 2786 | + } |
|
| 2787 | + $action_desc = 'updated'; |
|
| 2788 | + } |
|
| 2789 | 2789 | |
| 2790 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2791 | - $mtpg_fields = array( |
|
| 2792 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2793 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2794 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2795 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2796 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2797 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2798 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2799 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2800 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2801 | - : '', |
|
| 2802 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2803 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2804 | - : '' |
|
| 2805 | - ); |
|
| 2790 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2791 | + $mtpg_fields = array( |
|
| 2792 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2793 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2794 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2795 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2796 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2797 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2798 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2799 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2800 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2801 | + : '', |
|
| 2802 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2803 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2804 | + : '' |
|
| 2805 | + ); |
|
| 2806 | 2806 | |
| 2807 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2808 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2807 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2808 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2809 | 2809 | |
| 2810 | - if ($updated === false) { |
|
| 2811 | - EE_Error::add_error( |
|
| 2812 | - sprintf( |
|
| 2813 | - esc_html__( |
|
| 2814 | - 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2815 | - 'event_espresso' |
|
| 2816 | - ), |
|
| 2817 | - $set_column_values['GRP_ID'] |
|
| 2818 | - ), |
|
| 2819 | - __FILE__, |
|
| 2820 | - __FUNCTION__, |
|
| 2821 | - __LINE__ |
|
| 2822 | - ); |
|
| 2823 | - } else { |
|
| 2824 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2825 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2826 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2827 | - : 'default'; |
|
| 2810 | + if ($updated === false) { |
|
| 2811 | + EE_Error::add_error( |
|
| 2812 | + sprintf( |
|
| 2813 | + esc_html__( |
|
| 2814 | + 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2815 | + 'event_espresso' |
|
| 2816 | + ), |
|
| 2817 | + $set_column_values['GRP_ID'] |
|
| 2818 | + ), |
|
| 2819 | + __FILE__, |
|
| 2820 | + __FUNCTION__, |
|
| 2821 | + __LINE__ |
|
| 2822 | + ); |
|
| 2823 | + } else { |
|
| 2824 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2825 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2826 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2827 | + : 'default'; |
|
| 2828 | 2828 | |
| 2829 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2830 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2831 | - : 'default'; |
|
| 2829 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2830 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2831 | + : 'default'; |
|
| 2832 | 2832 | |
| 2833 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2834 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2835 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2836 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2837 | - } |
|
| 2838 | - $success = 1; |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - } |
|
| 2833 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2834 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2835 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2836 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2837 | + } |
|
| 2838 | + $success = 1; |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + } |
|
| 2842 | 2842 | |
| 2843 | - } |
|
| 2844 | - |
|
| 2845 | - //we return things differently if doing ajax |
|
| 2846 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2847 | - $this->_template_args['success'] = $success; |
|
| 2848 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2849 | - $this->_template_args['content'] = ''; |
|
| 2850 | - $this->_template_args['data'] = array( |
|
| 2851 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2852 | - 'templateName' => $edit_array['template_name'] |
|
| 2853 | - ); |
|
| 2854 | - if ($success) { |
|
| 2855 | - EE_Error::overwrite_success(); |
|
| 2856 | - EE_Error::add_success( |
|
| 2857 | - esc_html__( |
|
| 2858 | - '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.', |
|
| 2859 | - 'event_espresso' |
|
| 2860 | - ) |
|
| 2861 | - ); |
|
| 2862 | - } |
|
| 2843 | + } |
|
| 2844 | + |
|
| 2845 | + //we return things differently if doing ajax |
|
| 2846 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2847 | + $this->_template_args['success'] = $success; |
|
| 2848 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2849 | + $this->_template_args['content'] = ''; |
|
| 2850 | + $this->_template_args['data'] = array( |
|
| 2851 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2852 | + 'templateName' => $edit_array['template_name'] |
|
| 2853 | + ); |
|
| 2854 | + if ($success) { |
|
| 2855 | + EE_Error::overwrite_success(); |
|
| 2856 | + EE_Error::add_success( |
|
| 2857 | + esc_html__( |
|
| 2858 | + '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.', |
|
| 2859 | + 'event_espresso' |
|
| 2860 | + ) |
|
| 2861 | + ); |
|
| 2862 | + } |
|
| 2863 | 2863 | |
| 2864 | - $this->_return_json(); |
|
| 2865 | - } |
|
| 2866 | - |
|
| 2867 | - |
|
| 2868 | - //was a test send triggered? |
|
| 2869 | - if (isset($this->_req_data['test_button'])) { |
|
| 2870 | - EE_Error::overwrite_success(); |
|
| 2871 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2872 | - $override = true; |
|
| 2873 | - } |
|
| 2874 | - |
|
| 2875 | - if (empty($query_args)) { |
|
| 2876 | - $query_args = array( |
|
| 2877 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2878 | - 'context' => $context_slug, |
|
| 2879 | - 'action' => 'edit_message_template' |
|
| 2880 | - ); |
|
| 2881 | - } |
|
| 2882 | - |
|
| 2883 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2884 | - } |
|
| 2864 | + $this->_return_json(); |
|
| 2865 | + } |
|
| 2866 | + |
|
| 2867 | + |
|
| 2868 | + //was a test send triggered? |
|
| 2869 | + if (isset($this->_req_data['test_button'])) { |
|
| 2870 | + EE_Error::overwrite_success(); |
|
| 2871 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2872 | + $override = true; |
|
| 2873 | + } |
|
| 2874 | + |
|
| 2875 | + if (empty($query_args)) { |
|
| 2876 | + $query_args = array( |
|
| 2877 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2878 | + 'context' => $context_slug, |
|
| 2879 | + 'action' => 'edit_message_template' |
|
| 2880 | + ); |
|
| 2881 | + } |
|
| 2882 | + |
|
| 2883 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2884 | + } |
|
| 2885 | 2885 | |
| 2886 | 2886 | |
| 2887 | - /** |
|
| 2888 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2889 | - * |
|
| 2890 | - * @param string $context what context being tested |
|
| 2891 | - * @param string $messenger messenger being tested |
|
| 2892 | - * @param string $message_type message type being tested |
|
| 2893 | - * @throws EE_Error |
|
| 2894 | - * @throws InvalidArgumentException |
|
| 2895 | - * @throws InvalidDataTypeException |
|
| 2896 | - * @throws InvalidInterfaceException |
|
| 2897 | - */ |
|
| 2898 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2899 | - { |
|
| 2900 | - //set things up for preview |
|
| 2901 | - $this->_req_data['messenger'] = $messenger; |
|
| 2902 | - $this->_req_data['message_type'] = $message_type; |
|
| 2903 | - $this->_req_data['context'] = $context; |
|
| 2904 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2905 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2906 | - |
|
| 2907 | - //let's save any existing fields that might be required by the messenger |
|
| 2908 | - if ( |
|
| 2909 | - isset($this->_req_data['test_settings_fld']) |
|
| 2910 | - && $active_messenger instanceof EE_messenger |
|
| 2911 | - && apply_filters( |
|
| 2912 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2913 | - true, |
|
| 2914 | - $this->_req_data['test_settings_fld'], |
|
| 2915 | - $active_messenger |
|
| 2916 | - ) |
|
| 2917 | - ) { |
|
| 2918 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2919 | - } |
|
| 2920 | - |
|
| 2921 | - $success = $this->_preview_message(true); |
|
| 2922 | - |
|
| 2923 | - if ($success) { |
|
| 2924 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2925 | - } else { |
|
| 2926 | - EE_Error::add_error( |
|
| 2927 | - esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2928 | - __FILE__, |
|
| 2929 | - __FUNCTION__, |
|
| 2930 | - __LINE__ |
|
| 2931 | - ); |
|
| 2932 | - } |
|
| 2933 | - } |
|
| 2887 | + /** |
|
| 2888 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2889 | + * |
|
| 2890 | + * @param string $context what context being tested |
|
| 2891 | + * @param string $messenger messenger being tested |
|
| 2892 | + * @param string $message_type message type being tested |
|
| 2893 | + * @throws EE_Error |
|
| 2894 | + * @throws InvalidArgumentException |
|
| 2895 | + * @throws InvalidDataTypeException |
|
| 2896 | + * @throws InvalidInterfaceException |
|
| 2897 | + */ |
|
| 2898 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2899 | + { |
|
| 2900 | + //set things up for preview |
|
| 2901 | + $this->_req_data['messenger'] = $messenger; |
|
| 2902 | + $this->_req_data['message_type'] = $message_type; |
|
| 2903 | + $this->_req_data['context'] = $context; |
|
| 2904 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2905 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2906 | + |
|
| 2907 | + //let's save any existing fields that might be required by the messenger |
|
| 2908 | + if ( |
|
| 2909 | + isset($this->_req_data['test_settings_fld']) |
|
| 2910 | + && $active_messenger instanceof EE_messenger |
|
| 2911 | + && apply_filters( |
|
| 2912 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2913 | + true, |
|
| 2914 | + $this->_req_data['test_settings_fld'], |
|
| 2915 | + $active_messenger |
|
| 2916 | + ) |
|
| 2917 | + ) { |
|
| 2918 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2919 | + } |
|
| 2920 | + |
|
| 2921 | + $success = $this->_preview_message(true); |
|
| 2922 | + |
|
| 2923 | + if ($success) { |
|
| 2924 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2925 | + } else { |
|
| 2926 | + EE_Error::add_error( |
|
| 2927 | + esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2928 | + __FILE__, |
|
| 2929 | + __FUNCTION__, |
|
| 2930 | + __LINE__ |
|
| 2931 | + ); |
|
| 2932 | + } |
|
| 2933 | + } |
|
| 2934 | 2934 | |
| 2935 | 2935 | |
| 2936 | - /** |
|
| 2937 | - * _generate_new_templates |
|
| 2938 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2939 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2940 | - * for the event. |
|
| 2941 | - * |
|
| 2942 | - * |
|
| 2943 | - * @param string $messenger the messenger we are generating templates for |
|
| 2944 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2945 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2946 | - * indicate the message_template_group being used as the base. |
|
| 2947 | - * |
|
| 2948 | - * @param bool $global |
|
| 2949 | - * |
|
| 2950 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2951 | - * encountering problems. |
|
| 2952 | - * @throws EE_Error |
|
| 2953 | - */ |
|
| 2954 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2955 | - { |
|
| 2956 | - |
|
| 2957 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2958 | - // just don't generate any templates. |
|
| 2959 | - if (empty($message_types)) { |
|
| 2960 | - return true; |
|
| 2961 | - } |
|
| 2962 | - |
|
| 2963 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2964 | - } |
|
| 2936 | + /** |
|
| 2937 | + * _generate_new_templates |
|
| 2938 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2939 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2940 | + * for the event. |
|
| 2941 | + * |
|
| 2942 | + * |
|
| 2943 | + * @param string $messenger the messenger we are generating templates for |
|
| 2944 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2945 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2946 | + * indicate the message_template_group being used as the base. |
|
| 2947 | + * |
|
| 2948 | + * @param bool $global |
|
| 2949 | + * |
|
| 2950 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2951 | + * encountering problems. |
|
| 2952 | + * @throws EE_Error |
|
| 2953 | + */ |
|
| 2954 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2955 | + { |
|
| 2956 | + |
|
| 2957 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2958 | + // just don't generate any templates. |
|
| 2959 | + if (empty($message_types)) { |
|
| 2960 | + return true; |
|
| 2961 | + } |
|
| 2962 | + |
|
| 2963 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2964 | + } |
|
| 2965 | 2965 | |
| 2966 | 2966 | |
| 2967 | - /** |
|
| 2968 | - * [_trash_or_restore_message_template] |
|
| 2969 | - * |
|
| 2970 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2971 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2972 | - * an individual context (FALSE). |
|
| 2973 | - * @return void |
|
| 2974 | - * @throws EE_Error |
|
| 2975 | - * @throws InvalidArgumentException |
|
| 2976 | - * @throws InvalidDataTypeException |
|
| 2977 | - * @throws InvalidInterfaceException |
|
| 2978 | - */ |
|
| 2979 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2980 | - { |
|
| 2981 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2982 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2983 | - |
|
| 2984 | - $success = 1; |
|
| 2985 | - |
|
| 2986 | - //incoming GRP_IDs |
|
| 2987 | - if ($all) { |
|
| 2988 | - //Checkboxes |
|
| 2989 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2990 | - //if array has more than one element then success message should be plural. |
|
| 2991 | - //todo: what about nonce? |
|
| 2992 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2967 | + /** |
|
| 2968 | + * [_trash_or_restore_message_template] |
|
| 2969 | + * |
|
| 2970 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2971 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2972 | + * an individual context (FALSE). |
|
| 2973 | + * @return void |
|
| 2974 | + * @throws EE_Error |
|
| 2975 | + * @throws InvalidArgumentException |
|
| 2976 | + * @throws InvalidDataTypeException |
|
| 2977 | + * @throws InvalidInterfaceException |
|
| 2978 | + */ |
|
| 2979 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2980 | + { |
|
| 2981 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2982 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2983 | + |
|
| 2984 | + $success = 1; |
|
| 2985 | + |
|
| 2986 | + //incoming GRP_IDs |
|
| 2987 | + if ($all) { |
|
| 2988 | + //Checkboxes |
|
| 2989 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2990 | + //if array has more than one element then success message should be plural. |
|
| 2991 | + //todo: what about nonce? |
|
| 2992 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2993 | 2993 | |
| 2994 | - //cycle through checkboxes |
|
| 2995 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2996 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2997 | - if ( ! $trashed_or_restored) { |
|
| 2998 | - $success = 0; |
|
| 2999 | - } |
|
| 3000 | - } |
|
| 3001 | - } else { |
|
| 3002 | - //grab single GRP_ID and handle |
|
| 3003 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3004 | - if ( ! empty($GRP_ID)) { |
|
| 3005 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3006 | - if ( ! $trashed_or_restored) { |
|
| 3007 | - $success = 0; |
|
| 3008 | - } |
|
| 3009 | - } else { |
|
| 3010 | - $success = 0; |
|
| 3011 | - } |
|
| 3012 | - } |
|
| 2994 | + //cycle through checkboxes |
|
| 2995 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2996 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2997 | + if ( ! $trashed_or_restored) { |
|
| 2998 | + $success = 0; |
|
| 2999 | + } |
|
| 3000 | + } |
|
| 3001 | + } else { |
|
| 3002 | + //grab single GRP_ID and handle |
|
| 3003 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3004 | + if ( ! empty($GRP_ID)) { |
|
| 3005 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3006 | + if ( ! $trashed_or_restored) { |
|
| 3007 | + $success = 0; |
|
| 3008 | + } |
|
| 3009 | + } else { |
|
| 3010 | + $success = 0; |
|
| 3011 | + } |
|
| 3012 | + } |
|
| 3013 | 3013 | |
| 3014 | - } |
|
| 3014 | + } |
|
| 3015 | 3015 | |
| 3016 | - $action_desc = $trash |
|
| 3017 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3018 | - : esc_html__('restored', 'event_espresso'); |
|
| 3016 | + $action_desc = $trash |
|
| 3017 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3018 | + : esc_html__('restored', 'event_espresso'); |
|
| 3019 | 3019 | |
| 3020 | - $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3020 | + $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3021 | 3021 | |
| 3022 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3023 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3022 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3023 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3024 | 3024 | |
| 3025 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3026 | - 'event_espresso') : $item_desc; |
|
| 3025 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3026 | + 'event_espresso') : $item_desc; |
|
| 3027 | 3027 | |
| 3028 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3028 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3029 | 3029 | |
| 3030 | - } |
|
| 3030 | + } |
|
| 3031 | 3031 | |
| 3032 | 3032 | |
| 3033 | - /** |
|
| 3034 | - * [_delete_message_template] |
|
| 3035 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3036 | - * |
|
| 3037 | - * @return void |
|
| 3038 | - * @throws EE_Error |
|
| 3039 | - * @throws InvalidArgumentException |
|
| 3040 | - * @throws InvalidDataTypeException |
|
| 3041 | - * @throws InvalidInterfaceException |
|
| 3042 | - */ |
|
| 3043 | - protected function _delete_message_template() |
|
| 3044 | - { |
|
| 3045 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3046 | - |
|
| 3047 | - //checkboxes |
|
| 3048 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3049 | - //if array has more than one element then success message should be plural |
|
| 3050 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3033 | + /** |
|
| 3034 | + * [_delete_message_template] |
|
| 3035 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3036 | + * |
|
| 3037 | + * @return void |
|
| 3038 | + * @throws EE_Error |
|
| 3039 | + * @throws InvalidArgumentException |
|
| 3040 | + * @throws InvalidDataTypeException |
|
| 3041 | + * @throws InvalidInterfaceException |
|
| 3042 | + */ |
|
| 3043 | + protected function _delete_message_template() |
|
| 3044 | + { |
|
| 3045 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3046 | + |
|
| 3047 | + //checkboxes |
|
| 3048 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3049 | + //if array has more than one element then success message should be plural |
|
| 3050 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3051 | 3051 | |
| 3052 | - //cycle through bulk action checkboxes |
|
| 3053 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3054 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3055 | - } |
|
| 3056 | - } else { |
|
| 3057 | - //grab single grp_id and delete |
|
| 3058 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 3059 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3060 | - } |
|
| 3061 | - |
|
| 3062 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3063 | - |
|
| 3064 | - } |
|
| 3052 | + //cycle through bulk action checkboxes |
|
| 3053 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3054 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3055 | + } |
|
| 3056 | + } else { |
|
| 3057 | + //grab single grp_id and delete |
|
| 3058 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 3059 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3060 | + } |
|
| 3061 | + |
|
| 3062 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3063 | + |
|
| 3064 | + } |
|
| 3065 | 3065 | |
| 3066 | 3066 | |
| 3067 | - /** |
|
| 3068 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 3069 | - * |
|
| 3070 | - * @param int $GRP_ID The group being deleted |
|
| 3071 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3072 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3073 | - * @throws EE_Error |
|
| 3074 | - * @throws InvalidArgumentException |
|
| 3075 | - * @throws InvalidDataTypeException |
|
| 3076 | - * @throws InvalidInterfaceException |
|
| 3077 | - */ |
|
| 3078 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3079 | - { |
|
| 3080 | - $success = 1; |
|
| 3081 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3082 | - //first let's GET this group |
|
| 3083 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3084 | - //then delete permanently all the related Message Templates |
|
| 3085 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3086 | - |
|
| 3087 | - if ($deleted === 0) { |
|
| 3088 | - $success = 0; |
|
| 3089 | - } |
|
| 3090 | - |
|
| 3091 | - //now delete permanently this particular group |
|
| 3092 | - |
|
| 3093 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3094 | - $success = 0; |
|
| 3095 | - } |
|
| 3096 | - |
|
| 3097 | - return $success; |
|
| 3098 | - } |
|
| 3067 | + /** |
|
| 3068 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 3069 | + * |
|
| 3070 | + * @param int $GRP_ID The group being deleted |
|
| 3071 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3072 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 3073 | + * @throws EE_Error |
|
| 3074 | + * @throws InvalidArgumentException |
|
| 3075 | + * @throws InvalidDataTypeException |
|
| 3076 | + * @throws InvalidInterfaceException |
|
| 3077 | + */ |
|
| 3078 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3079 | + { |
|
| 3080 | + $success = 1; |
|
| 3081 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3082 | + //first let's GET this group |
|
| 3083 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3084 | + //then delete permanently all the related Message Templates |
|
| 3085 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3086 | + |
|
| 3087 | + if ($deleted === 0) { |
|
| 3088 | + $success = 0; |
|
| 3089 | + } |
|
| 3090 | + |
|
| 3091 | + //now delete permanently this particular group |
|
| 3092 | + |
|
| 3093 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3094 | + $success = 0; |
|
| 3095 | + } |
|
| 3096 | + |
|
| 3097 | + return $success; |
|
| 3098 | + } |
|
| 3099 | 3099 | |
| 3100 | 3100 | |
| 3101 | - /** |
|
| 3102 | - * _learn_more_about_message_templates_link |
|
| 3103 | - * @access protected |
|
| 3104 | - * @return string |
|
| 3105 | - */ |
|
| 3106 | - protected function _learn_more_about_message_templates_link() |
|
| 3107 | - { |
|
| 3108 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3109 | - . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3110 | - . '</a>'; |
|
| 3111 | - } |
|
| 3101 | + /** |
|
| 3102 | + * _learn_more_about_message_templates_link |
|
| 3103 | + * @access protected |
|
| 3104 | + * @return string |
|
| 3105 | + */ |
|
| 3106 | + protected function _learn_more_about_message_templates_link() |
|
| 3107 | + { |
|
| 3108 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3109 | + . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3110 | + . '</a>'; |
|
| 3111 | + } |
|
| 3112 | 3112 | |
| 3113 | 3113 | |
| 3114 | - /** |
|
| 3115 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3116 | - * ajax and other routes. |
|
| 3117 | - * |
|
| 3118 | - * @return void |
|
| 3119 | - * @throws DomainException |
|
| 3120 | - */ |
|
| 3121 | - protected function _settings() |
|
| 3122 | - { |
|
| 3123 | - |
|
| 3124 | - |
|
| 3125 | - $this->_set_m_mt_settings(); |
|
| 3126 | - |
|
| 3127 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3128 | - ? $this->_req_data['selected_messenger'] |
|
| 3129 | - : 'email'; |
|
| 3130 | - |
|
| 3131 | - //let's setup the messenger tabs |
|
| 3132 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3133 | - $this->_m_mt_settings['messenger_tabs'], |
|
| 3134 | - 'messenger_links', |
|
| 3135 | - '|', |
|
| 3136 | - $selected_messenger |
|
| 3137 | - ); |
|
| 3138 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3139 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3140 | - |
|
| 3141 | - $this->display_admin_page_with_sidebar(); |
|
| 3142 | - |
|
| 3143 | - } |
|
| 3114 | + /** |
|
| 3115 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3116 | + * ajax and other routes. |
|
| 3117 | + * |
|
| 3118 | + * @return void |
|
| 3119 | + * @throws DomainException |
|
| 3120 | + */ |
|
| 3121 | + protected function _settings() |
|
| 3122 | + { |
|
| 3123 | + |
|
| 3124 | + |
|
| 3125 | + $this->_set_m_mt_settings(); |
|
| 3126 | + |
|
| 3127 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3128 | + ? $this->_req_data['selected_messenger'] |
|
| 3129 | + : 'email'; |
|
| 3130 | + |
|
| 3131 | + //let's setup the messenger tabs |
|
| 3132 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3133 | + $this->_m_mt_settings['messenger_tabs'], |
|
| 3134 | + 'messenger_links', |
|
| 3135 | + '|', |
|
| 3136 | + $selected_messenger |
|
| 3137 | + ); |
|
| 3138 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3139 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3140 | + |
|
| 3141 | + $this->display_admin_page_with_sidebar(); |
|
| 3142 | + |
|
| 3143 | + } |
|
| 3144 | 3144 | |
| 3145 | 3145 | |
| 3146 | - /** |
|
| 3147 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3148 | - * |
|
| 3149 | - * @access protected |
|
| 3150 | - * @return void |
|
| 3151 | - * @throws DomainException |
|
| 3152 | - */ |
|
| 3153 | - protected function _set_m_mt_settings() |
|
| 3154 | - { |
|
| 3155 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 3156 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 3157 | - return; |
|
| 3158 | - } |
|
| 3159 | - |
|
| 3160 | - //get all installed messengers and message_types |
|
| 3161 | - /** @type EE_messenger[] $messengers */ |
|
| 3162 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3163 | - /** @type EE_message_type[] $message_types */ |
|
| 3164 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3165 | - |
|
| 3166 | - |
|
| 3167 | - //assemble the array for the _tab_text_links helper |
|
| 3168 | - |
|
| 3169 | - foreach ($messengers as $messenger) { |
|
| 3170 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3171 | - 'label' => ucwords($messenger->label['singular']), |
|
| 3172 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3173 | - ? 'messenger-active' |
|
| 3174 | - : '', |
|
| 3175 | - 'href' => $messenger->name, |
|
| 3176 | - 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3177 | - 'slug' => $messenger->name, |
|
| 3178 | - 'obj' => $messenger |
|
| 3179 | - ); |
|
| 3146 | + /** |
|
| 3147 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3148 | + * |
|
| 3149 | + * @access protected |
|
| 3150 | + * @return void |
|
| 3151 | + * @throws DomainException |
|
| 3152 | + */ |
|
| 3153 | + protected function _set_m_mt_settings() |
|
| 3154 | + { |
|
| 3155 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 3156 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 3157 | + return; |
|
| 3158 | + } |
|
| 3159 | + |
|
| 3160 | + //get all installed messengers and message_types |
|
| 3161 | + /** @type EE_messenger[] $messengers */ |
|
| 3162 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3163 | + /** @type EE_message_type[] $message_types */ |
|
| 3164 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3165 | + |
|
| 3166 | + |
|
| 3167 | + //assemble the array for the _tab_text_links helper |
|
| 3168 | + |
|
| 3169 | + foreach ($messengers as $messenger) { |
|
| 3170 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3171 | + 'label' => ucwords($messenger->label['singular']), |
|
| 3172 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3173 | + ? 'messenger-active' |
|
| 3174 | + : '', |
|
| 3175 | + 'href' => $messenger->name, |
|
| 3176 | + 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3177 | + 'slug' => $messenger->name, |
|
| 3178 | + 'obj' => $messenger |
|
| 3179 | + ); |
|
| 3180 | 3180 | |
| 3181 | 3181 | |
| 3182 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3182 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3183 | 3183 | |
| 3184 | - foreach ($message_types as $message_type) { |
|
| 3185 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3186 | - // it shouldn't show in either the inactive OR active metabox. |
|
| 3187 | - if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3188 | - continue; |
|
| 3189 | - } |
|
| 3184 | + foreach ($message_types as $message_type) { |
|
| 3185 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3186 | + // it shouldn't show in either the inactive OR active metabox. |
|
| 3187 | + if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3188 | + continue; |
|
| 3189 | + } |
|
| 3190 | 3190 | |
| 3191 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3192 | - $messenger->name, |
|
| 3193 | - $message_type->name |
|
| 3194 | - ) |
|
| 3195 | - ? 'active' |
|
| 3196 | - : 'inactive'; |
|
| 3191 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3192 | + $messenger->name, |
|
| 3193 | + $message_type->name |
|
| 3194 | + ) |
|
| 3195 | + ? 'active' |
|
| 3196 | + : 'inactive'; |
|
| 3197 | 3197 | |
| 3198 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3199 | - 'label' => ucwords($message_type->label['singular']), |
|
| 3200 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3201 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3202 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3203 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3204 | - 'title' => $a_or_i === 'active' |
|
| 3205 | - ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3206 | - : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3207 | - 'content' => $a_or_i === 'active' |
|
| 3208 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3209 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3210 | - 'slug' => $message_type->name, |
|
| 3211 | - 'active' => $a_or_i === 'active', |
|
| 3212 | - 'obj' => $message_type |
|
| 3213 | - ); |
|
| 3214 | - } |
|
| 3215 | - } |
|
| 3216 | - } |
|
| 3198 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3199 | + 'label' => ucwords($message_type->label['singular']), |
|
| 3200 | + 'class' => 'message-type-' . $a_or_i, |
|
| 3201 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3202 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3203 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3204 | + 'title' => $a_or_i === 'active' |
|
| 3205 | + ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3206 | + : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3207 | + 'content' => $a_or_i === 'active' |
|
| 3208 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3209 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3210 | + 'slug' => $message_type->name, |
|
| 3211 | + 'active' => $a_or_i === 'active', |
|
| 3212 | + 'obj' => $message_type |
|
| 3213 | + ); |
|
| 3214 | + } |
|
| 3215 | + } |
|
| 3216 | + } |
|
| 3217 | 3217 | |
| 3218 | 3218 | |
| 3219 | - /** |
|
| 3220 | - * This just prepares the content for the message type settings |
|
| 3221 | - * |
|
| 3222 | - * @param EE_message_type $message_type The message type object |
|
| 3223 | - * @param EE_messenger $messenger The messenger object |
|
| 3224 | - * @param boolean $active Whether the message type is active or not |
|
| 3225 | - * @return string html output for the content |
|
| 3226 | - * @throws DomainException |
|
| 3227 | - */ |
|
| 3228 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3229 | - { |
|
| 3230 | - //get message type fields |
|
| 3231 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 3232 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3233 | - |
|
| 3234 | - if ( ! empty($fields) && $active) { |
|
| 3219 | + /** |
|
| 3220 | + * This just prepares the content for the message type settings |
|
| 3221 | + * |
|
| 3222 | + * @param EE_message_type $message_type The message type object |
|
| 3223 | + * @param EE_messenger $messenger The messenger object |
|
| 3224 | + * @param boolean $active Whether the message type is active or not |
|
| 3225 | + * @return string html output for the content |
|
| 3226 | + * @throws DomainException |
|
| 3227 | + */ |
|
| 3228 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3229 | + { |
|
| 3230 | + //get message type fields |
|
| 3231 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 3232 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3233 | + |
|
| 3234 | + if ( ! empty($fields) && $active) { |
|
| 3235 | 3235 | |
| 3236 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3236 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3237 | 3237 | |
| 3238 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3239 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3240 | - $template_form_field[$field_id] = array( |
|
| 3241 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3242 | - 'label' => $fldprops['label'], |
|
| 3243 | - 'input' => $fldprops['field_type'], |
|
| 3244 | - 'type' => $fldprops['value_type'], |
|
| 3245 | - 'required' => $fldprops['required'], |
|
| 3246 | - 'validation' => $fldprops['validation'], |
|
| 3247 | - 'value' => isset($existing_settings[$fldname]) |
|
| 3248 | - ? $existing_settings[$fldname] |
|
| 3249 | - : $fldprops['default'], |
|
| 3250 | - 'options' => isset($fldprops['options']) |
|
| 3251 | - ? $fldprops['options'] |
|
| 3252 | - : array(), |
|
| 3253 | - 'default' => isset($existing_settings[$fldname]) |
|
| 3254 | - ? $existing_settings[$fldname] |
|
| 3255 | - : $fldprops['default'], |
|
| 3256 | - 'css_class' => 'no-drag', |
|
| 3257 | - 'format' => $fldprops['format'] |
|
| 3258 | - ); |
|
| 3259 | - } |
|
| 3238 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3239 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3240 | + $template_form_field[$field_id] = array( |
|
| 3241 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3242 | + 'label' => $fldprops['label'], |
|
| 3243 | + 'input' => $fldprops['field_type'], |
|
| 3244 | + 'type' => $fldprops['value_type'], |
|
| 3245 | + 'required' => $fldprops['required'], |
|
| 3246 | + 'validation' => $fldprops['validation'], |
|
| 3247 | + 'value' => isset($existing_settings[$fldname]) |
|
| 3248 | + ? $existing_settings[$fldname] |
|
| 3249 | + : $fldprops['default'], |
|
| 3250 | + 'options' => isset($fldprops['options']) |
|
| 3251 | + ? $fldprops['options'] |
|
| 3252 | + : array(), |
|
| 3253 | + 'default' => isset($existing_settings[$fldname]) |
|
| 3254 | + ? $existing_settings[$fldname] |
|
| 3255 | + : $fldprops['default'], |
|
| 3256 | + 'css_class' => 'no-drag', |
|
| 3257 | + 'format' => $fldprops['format'] |
|
| 3258 | + ); |
|
| 3259 | + } |
|
| 3260 | 3260 | |
| 3261 | 3261 | |
| 3262 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3263 | - ? $this->_generate_admin_form_fields( |
|
| 3264 | - $template_form_field, |
|
| 3265 | - 'string', |
|
| 3266 | - 'ee_mt_activate_form' |
|
| 3267 | - ) |
|
| 3268 | - : ''; |
|
| 3269 | - } |
|
| 3270 | - |
|
| 3271 | - $settings_template_args['description'] = $message_type->description; |
|
| 3272 | - //we also need some hidden fields |
|
| 3273 | - $settings_template_args['hidden_fields'] = array( |
|
| 3274 | - 'message_type_settings[messenger]' => array( |
|
| 3275 | - 'type' => 'hidden', |
|
| 3276 | - 'value' => $messenger->name |
|
| 3277 | - ), |
|
| 3278 | - 'message_type_settings[message_type]' => array( |
|
| 3279 | - 'type' => 'hidden', |
|
| 3280 | - 'value' => $message_type->name |
|
| 3281 | - ), |
|
| 3282 | - 'type' => array( |
|
| 3283 | - 'type' => 'hidden', |
|
| 3284 | - 'value' => 'message_type' |
|
| 3285 | - ) |
|
| 3286 | - ); |
|
| 3287 | - |
|
| 3288 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3289 | - $settings_template_args['hidden_fields'], |
|
| 3290 | - 'array' |
|
| 3291 | - ); |
|
| 3292 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3293 | - ? ' hidden' |
|
| 3294 | - : ''; |
|
| 3295 | - |
|
| 3296 | - |
|
| 3297 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3298 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3299 | - |
|
| 3300 | - return $content; |
|
| 3301 | - } |
|
| 3262 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3263 | + ? $this->_generate_admin_form_fields( |
|
| 3264 | + $template_form_field, |
|
| 3265 | + 'string', |
|
| 3266 | + 'ee_mt_activate_form' |
|
| 3267 | + ) |
|
| 3268 | + : ''; |
|
| 3269 | + } |
|
| 3270 | + |
|
| 3271 | + $settings_template_args['description'] = $message_type->description; |
|
| 3272 | + //we also need some hidden fields |
|
| 3273 | + $settings_template_args['hidden_fields'] = array( |
|
| 3274 | + 'message_type_settings[messenger]' => array( |
|
| 3275 | + 'type' => 'hidden', |
|
| 3276 | + 'value' => $messenger->name |
|
| 3277 | + ), |
|
| 3278 | + 'message_type_settings[message_type]' => array( |
|
| 3279 | + 'type' => 'hidden', |
|
| 3280 | + 'value' => $message_type->name |
|
| 3281 | + ), |
|
| 3282 | + 'type' => array( |
|
| 3283 | + 'type' => 'hidden', |
|
| 3284 | + 'value' => 'message_type' |
|
| 3285 | + ) |
|
| 3286 | + ); |
|
| 3287 | + |
|
| 3288 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3289 | + $settings_template_args['hidden_fields'], |
|
| 3290 | + 'array' |
|
| 3291 | + ); |
|
| 3292 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3293 | + ? ' hidden' |
|
| 3294 | + : ''; |
|
| 3295 | + |
|
| 3296 | + |
|
| 3297 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3298 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3299 | + |
|
| 3300 | + return $content; |
|
| 3301 | + } |
|
| 3302 | 3302 | |
| 3303 | 3303 | |
| 3304 | - /** |
|
| 3305 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3306 | - * |
|
| 3307 | - * @access protected |
|
| 3308 | - * @return void |
|
| 3309 | - * @throws DomainException |
|
| 3310 | - */ |
|
| 3311 | - protected function _messages_settings_metaboxes() |
|
| 3312 | - { |
|
| 3313 | - $this->_set_m_mt_settings(); |
|
| 3314 | - $m_boxes = $mt_boxes = array(); |
|
| 3315 | - $m_template_args = $mt_template_args = array(); |
|
| 3316 | - |
|
| 3317 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3318 | - ? $this->_req_data['selected_messenger'] |
|
| 3319 | - : 'email'; |
|
| 3320 | - |
|
| 3321 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3322 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3323 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3324 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3325 | - //messenger meta boxes |
|
| 3326 | - $active = $selected_messenger === $messenger; |
|
| 3327 | - $active_mt_tabs = isset( |
|
| 3328 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3329 | - ) |
|
| 3330 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3331 | - : ''; |
|
| 3332 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3333 | - esc_html__('%s Settings', 'event_espresso'), |
|
| 3334 | - $tab_array['label'] |
|
| 3335 | - ); |
|
| 3336 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 3337 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3338 | - 'inactive_message_types' => isset( |
|
| 3339 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3340 | - ) |
|
| 3341 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3342 | - : '', |
|
| 3343 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3344 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3345 | - 'hide_on_message' => $hide_on_message, |
|
| 3346 | - 'messenger' => $messenger, |
|
| 3347 | - 'active' => $active |
|
| 3348 | - ); |
|
| 3349 | - // message type meta boxes |
|
| 3350 | - // (which is really just the inactive container for each messenger |
|
| 3351 | - // showing inactive message types for that messenger) |
|
| 3352 | - $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3353 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3354 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3355 | - 'inactive_message_types' => isset( |
|
| 3356 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3357 | - ) |
|
| 3358 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3359 | - : '', |
|
| 3360 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3361 | - 'hide_on_message' => $hide_on_message, |
|
| 3362 | - 'hide_off_message' => $hide_off_message, |
|
| 3363 | - 'messenger' => $messenger, |
|
| 3364 | - 'active' => $active |
|
| 3365 | - ); |
|
| 3366 | - } |
|
| 3367 | - } |
|
| 3368 | - |
|
| 3369 | - |
|
| 3370 | - //register messenger metaboxes |
|
| 3371 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3372 | - foreach ($m_boxes as $box => $label) { |
|
| 3373 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3374 | - $msgr = str_replace('_a_box', '', $box); |
|
| 3375 | - add_meta_box( |
|
| 3376 | - 'espresso_' . $msgr . '_settings', |
|
| 3377 | - $label, |
|
| 3378 | - function ($post, $metabox) { |
|
| 3379 | - echo EEH_Template::display_template( |
|
| 3380 | - $metabox["args"]["template_path"], |
|
| 3381 | - $metabox["args"]["template_args"], |
|
| 3382 | - true |
|
| 3383 | - ); |
|
| 3384 | - }, |
|
| 3385 | - $this->_current_screen->id, |
|
| 3386 | - 'normal', |
|
| 3387 | - 'high', |
|
| 3388 | - $callback_args |
|
| 3389 | - ); |
|
| 3390 | - } |
|
| 3391 | - |
|
| 3392 | - //register message type metaboxes |
|
| 3393 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3394 | - foreach ($mt_boxes as $box => $label) { |
|
| 3395 | - $callback_args = array( |
|
| 3396 | - 'template_path' => $mt_template_path, |
|
| 3397 | - 'template_args' => $mt_template_args[$box] |
|
| 3398 | - ); |
|
| 3399 | - $mt = str_replace('_i_box', '', $box); |
|
| 3400 | - add_meta_box( |
|
| 3401 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3402 | - $label, |
|
| 3403 | - function ($post, $metabox) { |
|
| 3404 | - echo EEH_Template::display_template( |
|
| 3405 | - $metabox["args"]["template_path"], |
|
| 3406 | - $metabox["args"]["template_args"], |
|
| 3407 | - true |
|
| 3408 | - ); |
|
| 3409 | - }, |
|
| 3410 | - $this->_current_screen->id, |
|
| 3411 | - 'side', |
|
| 3412 | - 'high', |
|
| 3413 | - $callback_args |
|
| 3414 | - ); |
|
| 3415 | - } |
|
| 3416 | - |
|
| 3417 | - //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3418 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3419 | - if (is_main_site()) { |
|
| 3420 | - add_meta_box( |
|
| 3421 | - 'espresso_global_message_settings', |
|
| 3422 | - esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3423 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 3424 | - $this->_current_screen->id, |
|
| 3425 | - 'normal', |
|
| 3426 | - 'low', |
|
| 3427 | - array() |
|
| 3428 | - ); |
|
| 3429 | - } |
|
| 3430 | - |
|
| 3431 | - } |
|
| 3304 | + /** |
|
| 3305 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3306 | + * |
|
| 3307 | + * @access protected |
|
| 3308 | + * @return void |
|
| 3309 | + * @throws DomainException |
|
| 3310 | + */ |
|
| 3311 | + protected function _messages_settings_metaboxes() |
|
| 3312 | + { |
|
| 3313 | + $this->_set_m_mt_settings(); |
|
| 3314 | + $m_boxes = $mt_boxes = array(); |
|
| 3315 | + $m_template_args = $mt_template_args = array(); |
|
| 3316 | + |
|
| 3317 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3318 | + ? $this->_req_data['selected_messenger'] |
|
| 3319 | + : 'email'; |
|
| 3320 | + |
|
| 3321 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3322 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3323 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3324 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3325 | + //messenger meta boxes |
|
| 3326 | + $active = $selected_messenger === $messenger; |
|
| 3327 | + $active_mt_tabs = isset( |
|
| 3328 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3329 | + ) |
|
| 3330 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3331 | + : ''; |
|
| 3332 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3333 | + esc_html__('%s Settings', 'event_espresso'), |
|
| 3334 | + $tab_array['label'] |
|
| 3335 | + ); |
|
| 3336 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 3337 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3338 | + 'inactive_message_types' => isset( |
|
| 3339 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3340 | + ) |
|
| 3341 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3342 | + : '', |
|
| 3343 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3344 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3345 | + 'hide_on_message' => $hide_on_message, |
|
| 3346 | + 'messenger' => $messenger, |
|
| 3347 | + 'active' => $active |
|
| 3348 | + ); |
|
| 3349 | + // message type meta boxes |
|
| 3350 | + // (which is really just the inactive container for each messenger |
|
| 3351 | + // showing inactive message types for that messenger) |
|
| 3352 | + $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3353 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3354 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3355 | + 'inactive_message_types' => isset( |
|
| 3356 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3357 | + ) |
|
| 3358 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3359 | + : '', |
|
| 3360 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3361 | + 'hide_on_message' => $hide_on_message, |
|
| 3362 | + 'hide_off_message' => $hide_off_message, |
|
| 3363 | + 'messenger' => $messenger, |
|
| 3364 | + 'active' => $active |
|
| 3365 | + ); |
|
| 3366 | + } |
|
| 3367 | + } |
|
| 3368 | + |
|
| 3369 | + |
|
| 3370 | + //register messenger metaboxes |
|
| 3371 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3372 | + foreach ($m_boxes as $box => $label) { |
|
| 3373 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3374 | + $msgr = str_replace('_a_box', '', $box); |
|
| 3375 | + add_meta_box( |
|
| 3376 | + 'espresso_' . $msgr . '_settings', |
|
| 3377 | + $label, |
|
| 3378 | + function ($post, $metabox) { |
|
| 3379 | + echo EEH_Template::display_template( |
|
| 3380 | + $metabox["args"]["template_path"], |
|
| 3381 | + $metabox["args"]["template_args"], |
|
| 3382 | + true |
|
| 3383 | + ); |
|
| 3384 | + }, |
|
| 3385 | + $this->_current_screen->id, |
|
| 3386 | + 'normal', |
|
| 3387 | + 'high', |
|
| 3388 | + $callback_args |
|
| 3389 | + ); |
|
| 3390 | + } |
|
| 3391 | + |
|
| 3392 | + //register message type metaboxes |
|
| 3393 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3394 | + foreach ($mt_boxes as $box => $label) { |
|
| 3395 | + $callback_args = array( |
|
| 3396 | + 'template_path' => $mt_template_path, |
|
| 3397 | + 'template_args' => $mt_template_args[$box] |
|
| 3398 | + ); |
|
| 3399 | + $mt = str_replace('_i_box', '', $box); |
|
| 3400 | + add_meta_box( |
|
| 3401 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 3402 | + $label, |
|
| 3403 | + function ($post, $metabox) { |
|
| 3404 | + echo EEH_Template::display_template( |
|
| 3405 | + $metabox["args"]["template_path"], |
|
| 3406 | + $metabox["args"]["template_args"], |
|
| 3407 | + true |
|
| 3408 | + ); |
|
| 3409 | + }, |
|
| 3410 | + $this->_current_screen->id, |
|
| 3411 | + 'side', |
|
| 3412 | + 'high', |
|
| 3413 | + $callback_args |
|
| 3414 | + ); |
|
| 3415 | + } |
|
| 3416 | + |
|
| 3417 | + //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3418 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3419 | + if (is_main_site()) { |
|
| 3420 | + add_meta_box( |
|
| 3421 | + 'espresso_global_message_settings', |
|
| 3422 | + esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3423 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 3424 | + $this->_current_screen->id, |
|
| 3425 | + 'normal', |
|
| 3426 | + 'low', |
|
| 3427 | + array() |
|
| 3428 | + ); |
|
| 3429 | + } |
|
| 3430 | + |
|
| 3431 | + } |
|
| 3432 | 3432 | |
| 3433 | 3433 | |
| 3434 | - /** |
|
| 3435 | - * This generates the content for the global messages settings metabox. |
|
| 3436 | - * |
|
| 3437 | - * @return string |
|
| 3438 | - * @throws EE_Error |
|
| 3439 | - * @throws InvalidArgumentException |
|
| 3440 | - * @throws ReflectionException |
|
| 3441 | - * @throws InvalidDataTypeException |
|
| 3442 | - * @throws InvalidInterfaceException |
|
| 3443 | - */ |
|
| 3444 | - public function global_messages_settings_metabox_content() |
|
| 3445 | - { |
|
| 3446 | - $form = $this->_generate_global_settings_form(); |
|
| 3447 | - echo $form->form_open( |
|
| 3448 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3449 | - 'POST' |
|
| 3450 | - ) |
|
| 3451 | - . $form->get_html() |
|
| 3452 | - . $form->form_close(); |
|
| 3453 | - } |
|
| 3434 | + /** |
|
| 3435 | + * This generates the content for the global messages settings metabox. |
|
| 3436 | + * |
|
| 3437 | + * @return string |
|
| 3438 | + * @throws EE_Error |
|
| 3439 | + * @throws InvalidArgumentException |
|
| 3440 | + * @throws ReflectionException |
|
| 3441 | + * @throws InvalidDataTypeException |
|
| 3442 | + * @throws InvalidInterfaceException |
|
| 3443 | + */ |
|
| 3444 | + public function global_messages_settings_metabox_content() |
|
| 3445 | + { |
|
| 3446 | + $form = $this->_generate_global_settings_form(); |
|
| 3447 | + echo $form->form_open( |
|
| 3448 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3449 | + 'POST' |
|
| 3450 | + ) |
|
| 3451 | + . $form->get_html() |
|
| 3452 | + . $form->form_close(); |
|
| 3453 | + } |
|
| 3454 | 3454 | |
| 3455 | 3455 | |
| 3456 | - /** |
|
| 3457 | - * This generates and returns the form object for the global messages settings. |
|
| 3458 | - * |
|
| 3459 | - * @return EE_Form_Section_Proper |
|
| 3460 | - * @throws EE_Error |
|
| 3461 | - * @throws InvalidArgumentException |
|
| 3462 | - * @throws ReflectionException |
|
| 3463 | - * @throws InvalidDataTypeException |
|
| 3464 | - * @throws InvalidInterfaceException |
|
| 3465 | - */ |
|
| 3466 | - protected function _generate_global_settings_form() |
|
| 3467 | - { |
|
| 3468 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3469 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3470 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3471 | - |
|
| 3472 | - return new EE_Form_Section_Proper( |
|
| 3473 | - array( |
|
| 3474 | - 'name' => 'global_messages_settings', |
|
| 3475 | - 'html_id' => 'global_messages_settings', |
|
| 3476 | - 'html_class' => 'form-table', |
|
| 3477 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3478 | - 'subsections' => apply_filters( |
|
| 3479 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3480 | - array( |
|
| 3481 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3482 | - array( |
|
| 3483 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3484 | - false => esc_html__("On a separate request", "event_espresso") |
|
| 3485 | - ), |
|
| 3486 | - array( |
|
| 3487 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3488 | - 'html_label_text' => esc_html__( |
|
| 3489 | - 'Generate and send all messages:', |
|
| 3490 | - 'event_espresso' |
|
| 3491 | - ), |
|
| 3492 | - 'html_help_text' => esc_html__( |
|
| 3493 | - '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.', |
|
| 3494 | - 'event_espresso' |
|
| 3495 | - ), |
|
| 3496 | - ) |
|
| 3497 | - ), |
|
| 3498 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3499 | - array( |
|
| 3500 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3501 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3502 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3503 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3504 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3505 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3506 | - 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3507 | - ), |
|
| 3508 | - array( |
|
| 3509 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3510 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3511 | - 'html_help_text' => esc_html__( |
|
| 3512 | - 'You can control how long a record of processed messages is kept via this option.', |
|
| 3513 | - 'event_espresso' |
|
| 3514 | - ), |
|
| 3515 | - ) |
|
| 3516 | - ), |
|
| 3517 | - 'update_settings' => new EE_Submit_Input( |
|
| 3518 | - array( |
|
| 3519 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3520 | - 'html_label_text' => ' ' |
|
| 3521 | - ) |
|
| 3522 | - ) |
|
| 3523 | - ) |
|
| 3524 | - ) |
|
| 3525 | - ) |
|
| 3526 | - ); |
|
| 3527 | - } |
|
| 3456 | + /** |
|
| 3457 | + * This generates and returns the form object for the global messages settings. |
|
| 3458 | + * |
|
| 3459 | + * @return EE_Form_Section_Proper |
|
| 3460 | + * @throws EE_Error |
|
| 3461 | + * @throws InvalidArgumentException |
|
| 3462 | + * @throws ReflectionException |
|
| 3463 | + * @throws InvalidDataTypeException |
|
| 3464 | + * @throws InvalidInterfaceException |
|
| 3465 | + */ |
|
| 3466 | + protected function _generate_global_settings_form() |
|
| 3467 | + { |
|
| 3468 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3469 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3470 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3471 | + |
|
| 3472 | + return new EE_Form_Section_Proper( |
|
| 3473 | + array( |
|
| 3474 | + 'name' => 'global_messages_settings', |
|
| 3475 | + 'html_id' => 'global_messages_settings', |
|
| 3476 | + 'html_class' => 'form-table', |
|
| 3477 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3478 | + 'subsections' => apply_filters( |
|
| 3479 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3480 | + array( |
|
| 3481 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3482 | + array( |
|
| 3483 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3484 | + false => esc_html__("On a separate request", "event_espresso") |
|
| 3485 | + ), |
|
| 3486 | + array( |
|
| 3487 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3488 | + 'html_label_text' => esc_html__( |
|
| 3489 | + 'Generate and send all messages:', |
|
| 3490 | + 'event_espresso' |
|
| 3491 | + ), |
|
| 3492 | + 'html_help_text' => esc_html__( |
|
| 3493 | + '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.', |
|
| 3494 | + 'event_espresso' |
|
| 3495 | + ), |
|
| 3496 | + ) |
|
| 3497 | + ), |
|
| 3498 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3499 | + array( |
|
| 3500 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3501 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3502 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3503 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3504 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3505 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3506 | + 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3507 | + ), |
|
| 3508 | + array( |
|
| 3509 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3510 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3511 | + 'html_help_text' => esc_html__( |
|
| 3512 | + 'You can control how long a record of processed messages is kept via this option.', |
|
| 3513 | + 'event_espresso' |
|
| 3514 | + ), |
|
| 3515 | + ) |
|
| 3516 | + ), |
|
| 3517 | + 'update_settings' => new EE_Submit_Input( |
|
| 3518 | + array( |
|
| 3519 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3520 | + 'html_label_text' => ' ' |
|
| 3521 | + ) |
|
| 3522 | + ) |
|
| 3523 | + ) |
|
| 3524 | + ) |
|
| 3525 | + ) |
|
| 3526 | + ); |
|
| 3527 | + } |
|
| 3528 | 3528 | |
| 3529 | 3529 | |
| 3530 | - /** |
|
| 3531 | - * This handles updating the global settings set on the admin page. |
|
| 3532 | - * |
|
| 3533 | - * @throws EE_Error |
|
| 3534 | - * @throws InvalidDataTypeException |
|
| 3535 | - * @throws InvalidInterfaceException |
|
| 3536 | - * @throws InvalidArgumentException |
|
| 3537 | - * @throws ReflectionException |
|
| 3538 | - */ |
|
| 3539 | - protected function _update_global_settings() |
|
| 3540 | - { |
|
| 3541 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3542 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3543 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3544 | - $form = $this->_generate_global_settings_form(); |
|
| 3545 | - if ($form->was_submitted()) { |
|
| 3546 | - $form->receive_form_submission(); |
|
| 3547 | - if ($form->is_valid()) { |
|
| 3548 | - $valid_data = $form->valid_data(); |
|
| 3549 | - foreach ($valid_data as $property => $value) { |
|
| 3550 | - $setter = 'set_' . $property; |
|
| 3551 | - if (method_exists($network_config, $setter)) { |
|
| 3552 | - $network_config->{$setter}($value); |
|
| 3553 | - } else if ( |
|
| 3554 | - property_exists($network_config, $property) |
|
| 3555 | - && $network_config->{$property} !== $value |
|
| 3556 | - ) { |
|
| 3557 | - $network_config->{$property} = $value; |
|
| 3558 | - } else if ( |
|
| 3559 | - property_exists($messages_config, $property) |
|
| 3560 | - && $messages_config->{$property} !== $value |
|
| 3561 | - ) { |
|
| 3562 | - $messages_config->{$property} = $value; |
|
| 3563 | - } |
|
| 3564 | - } |
|
| 3565 | - //only update if the form submission was valid! |
|
| 3566 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3567 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3568 | - EE_Error::overwrite_success(); |
|
| 3569 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3570 | - } |
|
| 3571 | - } |
|
| 3572 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3573 | - } |
|
| 3530 | + /** |
|
| 3531 | + * This handles updating the global settings set on the admin page. |
|
| 3532 | + * |
|
| 3533 | + * @throws EE_Error |
|
| 3534 | + * @throws InvalidDataTypeException |
|
| 3535 | + * @throws InvalidInterfaceException |
|
| 3536 | + * @throws InvalidArgumentException |
|
| 3537 | + * @throws ReflectionException |
|
| 3538 | + */ |
|
| 3539 | + protected function _update_global_settings() |
|
| 3540 | + { |
|
| 3541 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3542 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3543 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3544 | + $form = $this->_generate_global_settings_form(); |
|
| 3545 | + if ($form->was_submitted()) { |
|
| 3546 | + $form->receive_form_submission(); |
|
| 3547 | + if ($form->is_valid()) { |
|
| 3548 | + $valid_data = $form->valid_data(); |
|
| 3549 | + foreach ($valid_data as $property => $value) { |
|
| 3550 | + $setter = 'set_' . $property; |
|
| 3551 | + if (method_exists($network_config, $setter)) { |
|
| 3552 | + $network_config->{$setter}($value); |
|
| 3553 | + } else if ( |
|
| 3554 | + property_exists($network_config, $property) |
|
| 3555 | + && $network_config->{$property} !== $value |
|
| 3556 | + ) { |
|
| 3557 | + $network_config->{$property} = $value; |
|
| 3558 | + } else if ( |
|
| 3559 | + property_exists($messages_config, $property) |
|
| 3560 | + && $messages_config->{$property} !== $value |
|
| 3561 | + ) { |
|
| 3562 | + $messages_config->{$property} = $value; |
|
| 3563 | + } |
|
| 3564 | + } |
|
| 3565 | + //only update if the form submission was valid! |
|
| 3566 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3567 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3568 | + EE_Error::overwrite_success(); |
|
| 3569 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3570 | + } |
|
| 3571 | + } |
|
| 3572 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3573 | + } |
|
| 3574 | 3574 | |
| 3575 | 3575 | |
| 3576 | - /** |
|
| 3577 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3578 | - * |
|
| 3579 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3580 | - * @return string html formatted tabs |
|
| 3581 | - * @throws DomainException |
|
| 3582 | - */ |
|
| 3583 | - protected function _get_mt_tabs($tab_array) |
|
| 3584 | - { |
|
| 3585 | - $tab_array = (array)$tab_array; |
|
| 3586 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3587 | - $tabs = ''; |
|
| 3588 | - |
|
| 3589 | - foreach ($tab_array as $tab) { |
|
| 3590 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3591 | - } |
|
| 3592 | - |
|
| 3593 | - return $tabs; |
|
| 3594 | - } |
|
| 3576 | + /** |
|
| 3577 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3578 | + * |
|
| 3579 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3580 | + * @return string html formatted tabs |
|
| 3581 | + * @throws DomainException |
|
| 3582 | + */ |
|
| 3583 | + protected function _get_mt_tabs($tab_array) |
|
| 3584 | + { |
|
| 3585 | + $tab_array = (array)$tab_array; |
|
| 3586 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3587 | + $tabs = ''; |
|
| 3588 | + |
|
| 3589 | + foreach ($tab_array as $tab) { |
|
| 3590 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3591 | + } |
|
| 3592 | + |
|
| 3593 | + return $tabs; |
|
| 3594 | + } |
|
| 3595 | 3595 | |
| 3596 | 3596 | |
| 3597 | - /** |
|
| 3598 | - * This prepares the content of the messenger meta box admin settings |
|
| 3599 | - * |
|
| 3600 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3601 | - * @return string html formatted content |
|
| 3602 | - * @throws DomainException |
|
| 3603 | - */ |
|
| 3604 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3605 | - { |
|
| 3597 | + /** |
|
| 3598 | + * This prepares the content of the messenger meta box admin settings |
|
| 3599 | + * |
|
| 3600 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3601 | + * @return string html formatted content |
|
| 3602 | + * @throws DomainException |
|
| 3603 | + */ |
|
| 3604 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3605 | + { |
|
| 3606 | 3606 | |
| 3607 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3608 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3607 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3608 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3609 | 3609 | |
| 3610 | - //is $messenger active? |
|
| 3611 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3610 | + //is $messenger active? |
|
| 3611 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3612 | 3612 | |
| 3613 | 3613 | |
| 3614 | - if ( ! empty($fields)) { |
|
| 3614 | + if ( ! empty($fields)) { |
|
| 3615 | 3615 | |
| 3616 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3616 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3617 | 3617 | |
| 3618 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3619 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3620 | - $template_form_field[$field_id] = array( |
|
| 3621 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3622 | - 'label' => $fldprops['label'], |
|
| 3623 | - 'input' => $fldprops['field_type'], |
|
| 3624 | - 'type' => $fldprops['value_type'], |
|
| 3625 | - 'required' => $fldprops['required'], |
|
| 3626 | - 'validation' => $fldprops['validation'], |
|
| 3627 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3628 | - ? $existing_settings[$field_id] |
|
| 3629 | - : $fldprops['default'], |
|
| 3630 | - 'css_class' => '', |
|
| 3631 | - 'format' => $fldprops['format'] |
|
| 3632 | - ); |
|
| 3633 | - } |
|
| 3618 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3619 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3620 | + $template_form_field[$field_id] = array( |
|
| 3621 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3622 | + 'label' => $fldprops['label'], |
|
| 3623 | + 'input' => $fldprops['field_type'], |
|
| 3624 | + 'type' => $fldprops['value_type'], |
|
| 3625 | + 'required' => $fldprops['required'], |
|
| 3626 | + 'validation' => $fldprops['validation'], |
|
| 3627 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3628 | + ? $existing_settings[$field_id] |
|
| 3629 | + : $fldprops['default'], |
|
| 3630 | + 'css_class' => '', |
|
| 3631 | + 'format' => $fldprops['format'] |
|
| 3632 | + ); |
|
| 3633 | + } |
|
| 3634 | 3634 | |
| 3635 | 3635 | |
| 3636 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3637 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3638 | - : ''; |
|
| 3639 | - } |
|
| 3640 | - |
|
| 3641 | - //we also need some hidden fields |
|
| 3642 | - $settings_template_args['hidden_fields'] = array( |
|
| 3643 | - 'messenger_settings[messenger]' => array( |
|
| 3644 | - 'type' => 'hidden', |
|
| 3645 | - 'value' => $messenger->name |
|
| 3646 | - ), |
|
| 3647 | - 'type' => array( |
|
| 3648 | - 'type' => 'hidden', |
|
| 3649 | - 'value' => 'messenger' |
|
| 3650 | - ) |
|
| 3651 | - ); |
|
| 3652 | - |
|
| 3653 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3654 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3655 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3656 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3657 | - 'type' => 'hidden', |
|
| 3658 | - 'value' => $mt |
|
| 3659 | - ); |
|
| 3660 | - } |
|
| 3661 | - } |
|
| 3662 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3663 | - $settings_template_args['hidden_fields'], |
|
| 3664 | - 'array' |
|
| 3665 | - ); |
|
| 3666 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3667 | - |
|
| 3668 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3669 | - $settings_template_args['description'] = $messenger->description; |
|
| 3670 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3671 | - |
|
| 3672 | - |
|
| 3673 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3674 | - $messenger->name |
|
| 3675 | - ) |
|
| 3676 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3677 | - : ' hidden'; |
|
| 3678 | - |
|
| 3679 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3680 | - ? ' hidden' |
|
| 3681 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3682 | - |
|
| 3683 | - |
|
| 3684 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3685 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3686 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3687 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3688 | - $content = EEH_Template::display_template( |
|
| 3689 | - $template, |
|
| 3690 | - $settings_template_args, |
|
| 3691 | - true |
|
| 3692 | - ); |
|
| 3693 | - |
|
| 3694 | - return $content; |
|
| 3695 | - } |
|
| 3636 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3637 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3638 | + : ''; |
|
| 3639 | + } |
|
| 3640 | + |
|
| 3641 | + //we also need some hidden fields |
|
| 3642 | + $settings_template_args['hidden_fields'] = array( |
|
| 3643 | + 'messenger_settings[messenger]' => array( |
|
| 3644 | + 'type' => 'hidden', |
|
| 3645 | + 'value' => $messenger->name |
|
| 3646 | + ), |
|
| 3647 | + 'type' => array( |
|
| 3648 | + 'type' => 'hidden', |
|
| 3649 | + 'value' => 'messenger' |
|
| 3650 | + ) |
|
| 3651 | + ); |
|
| 3652 | + |
|
| 3653 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3654 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3655 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3656 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3657 | + 'type' => 'hidden', |
|
| 3658 | + 'value' => $mt |
|
| 3659 | + ); |
|
| 3660 | + } |
|
| 3661 | + } |
|
| 3662 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3663 | + $settings_template_args['hidden_fields'], |
|
| 3664 | + 'array' |
|
| 3665 | + ); |
|
| 3666 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3667 | + |
|
| 3668 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3669 | + $settings_template_args['description'] = $messenger->description; |
|
| 3670 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3671 | + |
|
| 3672 | + |
|
| 3673 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3674 | + $messenger->name |
|
| 3675 | + ) |
|
| 3676 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3677 | + : ' hidden'; |
|
| 3678 | + |
|
| 3679 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3680 | + ? ' hidden' |
|
| 3681 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3682 | + |
|
| 3683 | + |
|
| 3684 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3685 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3686 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3687 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3688 | + $content = EEH_Template::display_template( |
|
| 3689 | + $template, |
|
| 3690 | + $settings_template_args, |
|
| 3691 | + true |
|
| 3692 | + ); |
|
| 3693 | + |
|
| 3694 | + return $content; |
|
| 3695 | + } |
|
| 3696 | 3696 | |
| 3697 | 3697 | |
| 3698 | - /** |
|
| 3699 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3700 | - * |
|
| 3701 | - * @throws DomainException |
|
| 3702 | - * @throws EE_Error |
|
| 3703 | - * @throws InvalidDataTypeException |
|
| 3704 | - * @throws InvalidInterfaceException |
|
| 3705 | - * @throws InvalidArgumentException |
|
| 3706 | - * @throws ReflectionException |
|
| 3707 | - */ |
|
| 3708 | - public function activate_messenger_toggle() |
|
| 3709 | - { |
|
| 3710 | - $success = true; |
|
| 3711 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3712 | - //let's check that we have required data |
|
| 3713 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3714 | - EE_Error::add_error( |
|
| 3715 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3716 | - __FILE__, |
|
| 3717 | - __FUNCTION__, |
|
| 3718 | - __LINE__ |
|
| 3719 | - ); |
|
| 3720 | - $success = false; |
|
| 3721 | - } |
|
| 3722 | - |
|
| 3723 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3724 | - $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3725 | - ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3726 | - : ''; |
|
| 3727 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3728 | - |
|
| 3729 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3730 | - |
|
| 3731 | - |
|
| 3732 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3733 | - EE_Error::add_error( |
|
| 3734 | - esc_html__( |
|
| 3735 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3736 | - 'event_espresso' |
|
| 3737 | - ), |
|
| 3738 | - __FILE__, |
|
| 3739 | - __FUNCTION__, |
|
| 3740 | - __LINE__ |
|
| 3741 | - ); |
|
| 3742 | - $success = false; |
|
| 3743 | - } |
|
| 3744 | - |
|
| 3745 | - //do check to verify we have a valid status. |
|
| 3746 | - $status = $this->_req_data['status']; |
|
| 3747 | - |
|
| 3748 | - if ($status !== 'off' && $status !== 'on') { |
|
| 3749 | - EE_Error::add_error( |
|
| 3750 | - sprintf( |
|
| 3751 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3752 | - $this->_req_data['status'] |
|
| 3753 | - ), |
|
| 3754 | - __FILE__, |
|
| 3755 | - __FUNCTION__, |
|
| 3756 | - __LINE__ |
|
| 3757 | - ); |
|
| 3758 | - $success = false; |
|
| 3759 | - } |
|
| 3760 | - |
|
| 3761 | - if ($success) { |
|
| 3762 | - //made it here? Stop dawdling then!! |
|
| 3763 | - $success = $status === 'off' |
|
| 3764 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3765 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3766 | - } |
|
| 3767 | - |
|
| 3768 | - $this->_template_args['success'] = $success; |
|
| 3769 | - |
|
| 3770 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3771 | - $this->_return_json(); |
|
| 3772 | - |
|
| 3773 | - } |
|
| 3698 | + /** |
|
| 3699 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3700 | + * |
|
| 3701 | + * @throws DomainException |
|
| 3702 | + * @throws EE_Error |
|
| 3703 | + * @throws InvalidDataTypeException |
|
| 3704 | + * @throws InvalidInterfaceException |
|
| 3705 | + * @throws InvalidArgumentException |
|
| 3706 | + * @throws ReflectionException |
|
| 3707 | + */ |
|
| 3708 | + public function activate_messenger_toggle() |
|
| 3709 | + { |
|
| 3710 | + $success = true; |
|
| 3711 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3712 | + //let's check that we have required data |
|
| 3713 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3714 | + EE_Error::add_error( |
|
| 3715 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3716 | + __FILE__, |
|
| 3717 | + __FUNCTION__, |
|
| 3718 | + __LINE__ |
|
| 3719 | + ); |
|
| 3720 | + $success = false; |
|
| 3721 | + } |
|
| 3722 | + |
|
| 3723 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3724 | + $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3725 | + ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3726 | + : ''; |
|
| 3727 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3728 | + |
|
| 3729 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3730 | + |
|
| 3731 | + |
|
| 3732 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3733 | + EE_Error::add_error( |
|
| 3734 | + esc_html__( |
|
| 3735 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3736 | + 'event_espresso' |
|
| 3737 | + ), |
|
| 3738 | + __FILE__, |
|
| 3739 | + __FUNCTION__, |
|
| 3740 | + __LINE__ |
|
| 3741 | + ); |
|
| 3742 | + $success = false; |
|
| 3743 | + } |
|
| 3744 | + |
|
| 3745 | + //do check to verify we have a valid status. |
|
| 3746 | + $status = $this->_req_data['status']; |
|
| 3747 | + |
|
| 3748 | + if ($status !== 'off' && $status !== 'on') { |
|
| 3749 | + EE_Error::add_error( |
|
| 3750 | + sprintf( |
|
| 3751 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3752 | + $this->_req_data['status'] |
|
| 3753 | + ), |
|
| 3754 | + __FILE__, |
|
| 3755 | + __FUNCTION__, |
|
| 3756 | + __LINE__ |
|
| 3757 | + ); |
|
| 3758 | + $success = false; |
|
| 3759 | + } |
|
| 3760 | + |
|
| 3761 | + if ($success) { |
|
| 3762 | + //made it here? Stop dawdling then!! |
|
| 3763 | + $success = $status === 'off' |
|
| 3764 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3765 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3766 | + } |
|
| 3767 | + |
|
| 3768 | + $this->_template_args['success'] = $success; |
|
| 3769 | + |
|
| 3770 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3771 | + $this->_return_json(); |
|
| 3772 | + |
|
| 3773 | + } |
|
| 3774 | 3774 | |
| 3775 | 3775 | |
| 3776 | - /** |
|
| 3777 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3778 | - * |
|
| 3779 | - * @throws DomainException |
|
| 3780 | - * @throws EE_Error |
|
| 3781 | - * @throws ReflectionException |
|
| 3782 | - * @throws InvalidDataTypeException |
|
| 3783 | - * @throws InvalidInterfaceException |
|
| 3784 | - * @throws InvalidArgumentException |
|
| 3785 | - */ |
|
| 3786 | - public function activate_mt_toggle() |
|
| 3787 | - { |
|
| 3788 | - $success = true; |
|
| 3789 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3790 | - |
|
| 3791 | - //let's make sure we have the necessary data |
|
| 3792 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3793 | - EE_Error::add_error( |
|
| 3794 | - esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3795 | - __FILE__, |
|
| 3796 | - __FUNCTION__, |
|
| 3797 | - __LINE__ |
|
| 3798 | - ); |
|
| 3799 | - $success = false; |
|
| 3800 | - } |
|
| 3801 | - |
|
| 3802 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3803 | - EE_Error::add_error( |
|
| 3804 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3805 | - __FILE__, |
|
| 3806 | - __FUNCTION__, |
|
| 3807 | - __LINE__ |
|
| 3808 | - ); |
|
| 3809 | - $success = false; |
|
| 3810 | - } |
|
| 3811 | - |
|
| 3812 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3813 | - EE_Error::add_error( |
|
| 3814 | - esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3815 | - 'event_espresso'), |
|
| 3816 | - __FILE__, |
|
| 3817 | - __FUNCTION__, |
|
| 3818 | - __LINE__ |
|
| 3819 | - ); |
|
| 3820 | - $success = false; |
|
| 3821 | - } |
|
| 3822 | - |
|
| 3823 | - |
|
| 3824 | - //do check to verify we have a valid status. |
|
| 3825 | - $status = $this->_req_data['status']; |
|
| 3826 | - |
|
| 3827 | - if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3828 | - EE_Error::add_error( |
|
| 3829 | - sprintf( |
|
| 3830 | - esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3831 | - $this->_req_data['status'] |
|
| 3832 | - ), |
|
| 3833 | - __FILE__, |
|
| 3834 | - __FUNCTION__, |
|
| 3835 | - __LINE__ |
|
| 3836 | - ); |
|
| 3837 | - $success = false; |
|
| 3838 | - } |
|
| 3839 | - |
|
| 3840 | - |
|
| 3841 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3842 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3843 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3844 | - |
|
| 3845 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3846 | - |
|
| 3847 | - if ($success) { |
|
| 3848 | - //made it here? um, what are you waiting for then? |
|
| 3849 | - $success = $status === 'deactivate' |
|
| 3850 | - ? $this->_deactivate_message_type_for_messenger( |
|
| 3851 | - $this->_req_data['messenger'], |
|
| 3852 | - $this->_req_data['message_type'] |
|
| 3853 | - ) |
|
| 3854 | - : $this->_activate_message_type_for_messenger( |
|
| 3855 | - $this->_req_data['messenger'], |
|
| 3856 | - $this->_req_data['message_type'] |
|
| 3857 | - ); |
|
| 3858 | - } |
|
| 3859 | - |
|
| 3860 | - $this->_template_args['success'] = $success; |
|
| 3861 | - $this->_return_json(); |
|
| 3862 | - } |
|
| 3776 | + /** |
|
| 3777 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3778 | + * |
|
| 3779 | + * @throws DomainException |
|
| 3780 | + * @throws EE_Error |
|
| 3781 | + * @throws ReflectionException |
|
| 3782 | + * @throws InvalidDataTypeException |
|
| 3783 | + * @throws InvalidInterfaceException |
|
| 3784 | + * @throws InvalidArgumentException |
|
| 3785 | + */ |
|
| 3786 | + public function activate_mt_toggle() |
|
| 3787 | + { |
|
| 3788 | + $success = true; |
|
| 3789 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3790 | + |
|
| 3791 | + //let's make sure we have the necessary data |
|
| 3792 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3793 | + EE_Error::add_error( |
|
| 3794 | + esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3795 | + __FILE__, |
|
| 3796 | + __FUNCTION__, |
|
| 3797 | + __LINE__ |
|
| 3798 | + ); |
|
| 3799 | + $success = false; |
|
| 3800 | + } |
|
| 3801 | + |
|
| 3802 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3803 | + EE_Error::add_error( |
|
| 3804 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3805 | + __FILE__, |
|
| 3806 | + __FUNCTION__, |
|
| 3807 | + __LINE__ |
|
| 3808 | + ); |
|
| 3809 | + $success = false; |
|
| 3810 | + } |
|
| 3811 | + |
|
| 3812 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3813 | + EE_Error::add_error( |
|
| 3814 | + esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3815 | + 'event_espresso'), |
|
| 3816 | + __FILE__, |
|
| 3817 | + __FUNCTION__, |
|
| 3818 | + __LINE__ |
|
| 3819 | + ); |
|
| 3820 | + $success = false; |
|
| 3821 | + } |
|
| 3822 | + |
|
| 3823 | + |
|
| 3824 | + //do check to verify we have a valid status. |
|
| 3825 | + $status = $this->_req_data['status']; |
|
| 3826 | + |
|
| 3827 | + if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3828 | + EE_Error::add_error( |
|
| 3829 | + sprintf( |
|
| 3830 | + esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3831 | + $this->_req_data['status'] |
|
| 3832 | + ), |
|
| 3833 | + __FILE__, |
|
| 3834 | + __FUNCTION__, |
|
| 3835 | + __LINE__ |
|
| 3836 | + ); |
|
| 3837 | + $success = false; |
|
| 3838 | + } |
|
| 3839 | + |
|
| 3840 | + |
|
| 3841 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3842 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3843 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3844 | + |
|
| 3845 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3846 | + |
|
| 3847 | + if ($success) { |
|
| 3848 | + //made it here? um, what are you waiting for then? |
|
| 3849 | + $success = $status === 'deactivate' |
|
| 3850 | + ? $this->_deactivate_message_type_for_messenger( |
|
| 3851 | + $this->_req_data['messenger'], |
|
| 3852 | + $this->_req_data['message_type'] |
|
| 3853 | + ) |
|
| 3854 | + : $this->_activate_message_type_for_messenger( |
|
| 3855 | + $this->_req_data['messenger'], |
|
| 3856 | + $this->_req_data['message_type'] |
|
| 3857 | + ); |
|
| 3858 | + } |
|
| 3859 | + |
|
| 3860 | + $this->_template_args['success'] = $success; |
|
| 3861 | + $this->_return_json(); |
|
| 3862 | + } |
|
| 3863 | 3863 | |
| 3864 | 3864 | |
| 3865 | - /** |
|
| 3866 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3867 | - * |
|
| 3868 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3869 | - * @return bool |
|
| 3870 | - * @throws DomainException |
|
| 3871 | - * @throws EE_Error |
|
| 3872 | - * @throws InvalidArgumentException |
|
| 3873 | - * @throws ReflectionException |
|
| 3874 | - * @throws InvalidDataTypeException |
|
| 3875 | - * @throws InvalidInterfaceException |
|
| 3876 | - */ |
|
| 3877 | - protected function _activate_messenger($messenger_name) |
|
| 3878 | - { |
|
| 3879 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3880 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3881 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3882 | - ? $active_messenger->get_default_message_types() |
|
| 3883 | - : array(); |
|
| 3884 | - |
|
| 3885 | - //ensure is active |
|
| 3886 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3887 | - |
|
| 3888 | - //set response_data for reload |
|
| 3889 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3890 | - /** @var EE_message_type $message_type */ |
|
| 3891 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3892 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3893 | - $messenger_name, |
|
| 3894 | - $message_type_name |
|
| 3895 | - ) |
|
| 3896 | - && $message_type instanceof EE_message_type |
|
| 3897 | - ) { |
|
| 3898 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3899 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3900 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3901 | - } |
|
| 3902 | - } |
|
| 3903 | - } |
|
| 3904 | - |
|
| 3905 | - //add success message for activating messenger |
|
| 3906 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3907 | - |
|
| 3908 | - } |
|
| 3865 | + /** |
|
| 3866 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3867 | + * |
|
| 3868 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3869 | + * @return bool |
|
| 3870 | + * @throws DomainException |
|
| 3871 | + * @throws EE_Error |
|
| 3872 | + * @throws InvalidArgumentException |
|
| 3873 | + * @throws ReflectionException |
|
| 3874 | + * @throws InvalidDataTypeException |
|
| 3875 | + * @throws InvalidInterfaceException |
|
| 3876 | + */ |
|
| 3877 | + protected function _activate_messenger($messenger_name) |
|
| 3878 | + { |
|
| 3879 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3880 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3881 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3882 | + ? $active_messenger->get_default_message_types() |
|
| 3883 | + : array(); |
|
| 3884 | + |
|
| 3885 | + //ensure is active |
|
| 3886 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3887 | + |
|
| 3888 | + //set response_data for reload |
|
| 3889 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3890 | + /** @var EE_message_type $message_type */ |
|
| 3891 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3892 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3893 | + $messenger_name, |
|
| 3894 | + $message_type_name |
|
| 3895 | + ) |
|
| 3896 | + && $message_type instanceof EE_message_type |
|
| 3897 | + ) { |
|
| 3898 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3899 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3900 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3901 | + } |
|
| 3902 | + } |
|
| 3903 | + } |
|
| 3904 | + |
|
| 3905 | + //add success message for activating messenger |
|
| 3906 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3907 | + |
|
| 3908 | + } |
|
| 3909 | 3909 | |
| 3910 | 3910 | |
| 3911 | - /** |
|
| 3912 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3913 | - * |
|
| 3914 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3915 | - * @return bool |
|
| 3916 | - * @throws DomainException |
|
| 3917 | - * @throws EE_Error |
|
| 3918 | - * @throws InvalidArgumentException |
|
| 3919 | - * @throws ReflectionException |
|
| 3920 | - * @throws InvalidDataTypeException |
|
| 3921 | - * @throws InvalidInterfaceException |
|
| 3922 | - */ |
|
| 3923 | - protected function _deactivate_messenger($messenger_name) |
|
| 3924 | - { |
|
| 3925 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3926 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3927 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3928 | - |
|
| 3929 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3930 | - } |
|
| 3911 | + /** |
|
| 3912 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3913 | + * |
|
| 3914 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3915 | + * @return bool |
|
| 3916 | + * @throws DomainException |
|
| 3917 | + * @throws EE_Error |
|
| 3918 | + * @throws InvalidArgumentException |
|
| 3919 | + * @throws ReflectionException |
|
| 3920 | + * @throws InvalidDataTypeException |
|
| 3921 | + * @throws InvalidInterfaceException |
|
| 3922 | + */ |
|
| 3923 | + protected function _deactivate_messenger($messenger_name) |
|
| 3924 | + { |
|
| 3925 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3926 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3927 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3928 | + |
|
| 3929 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3930 | + } |
|
| 3931 | 3931 | |
| 3932 | 3932 | |
| 3933 | - /** |
|
| 3934 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3935 | - * |
|
| 3936 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3937 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3938 | - * @return bool |
|
| 3939 | - * @throws DomainException |
|
| 3940 | - * @throws EE_Error |
|
| 3941 | - * @throws InvalidArgumentException |
|
| 3942 | - * @throws ReflectionException |
|
| 3943 | - * @throws InvalidDataTypeException |
|
| 3944 | - * @throws InvalidInterfaceException |
|
| 3945 | - */ |
|
| 3946 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3947 | - { |
|
| 3948 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3949 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3950 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3951 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3952 | - |
|
| 3953 | - //ensure is active |
|
| 3954 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3955 | - |
|
| 3956 | - //set response for load |
|
| 3957 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3958 | - $message_type_name) |
|
| 3959 | - ) { |
|
| 3960 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3961 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3962 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3963 | - } |
|
| 3964 | - } |
|
| 3965 | - |
|
| 3966 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3967 | - $message_type_to_activate); |
|
| 3968 | - } |
|
| 3933 | + /** |
|
| 3934 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3935 | + * |
|
| 3936 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3937 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3938 | + * @return bool |
|
| 3939 | + * @throws DomainException |
|
| 3940 | + * @throws EE_Error |
|
| 3941 | + * @throws InvalidArgumentException |
|
| 3942 | + * @throws ReflectionException |
|
| 3943 | + * @throws InvalidDataTypeException |
|
| 3944 | + * @throws InvalidInterfaceException |
|
| 3945 | + */ |
|
| 3946 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3947 | + { |
|
| 3948 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3949 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3950 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3951 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3952 | + |
|
| 3953 | + //ensure is active |
|
| 3954 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3955 | + |
|
| 3956 | + //set response for load |
|
| 3957 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3958 | + $message_type_name) |
|
| 3959 | + ) { |
|
| 3960 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3961 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3962 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3963 | + } |
|
| 3964 | + } |
|
| 3965 | + |
|
| 3966 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3967 | + $message_type_to_activate); |
|
| 3968 | + } |
|
| 3969 | 3969 | |
| 3970 | 3970 | |
| 3971 | - /** |
|
| 3972 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3973 | - * |
|
| 3974 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3975 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3976 | - * @return bool |
|
| 3977 | - * @throws DomainException |
|
| 3978 | - * @throws EE_Error |
|
| 3979 | - * @throws InvalidArgumentException |
|
| 3980 | - * @throws ReflectionException |
|
| 3981 | - * @throws InvalidDataTypeException |
|
| 3982 | - * @throws InvalidInterfaceException |
|
| 3983 | - */ |
|
| 3984 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3985 | - { |
|
| 3986 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3987 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3988 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3989 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3990 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3991 | - |
|
| 3992 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3993 | - $message_type_to_deactivate); |
|
| 3994 | - } |
|
| 3971 | + /** |
|
| 3972 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3973 | + * |
|
| 3974 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3975 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3976 | + * @return bool |
|
| 3977 | + * @throws DomainException |
|
| 3978 | + * @throws EE_Error |
|
| 3979 | + * @throws InvalidArgumentException |
|
| 3980 | + * @throws ReflectionException |
|
| 3981 | + * @throws InvalidDataTypeException |
|
| 3982 | + * @throws InvalidInterfaceException |
|
| 3983 | + */ |
|
| 3984 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3985 | + { |
|
| 3986 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3987 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3988 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3989 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3990 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3991 | + |
|
| 3992 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3993 | + $message_type_to_deactivate); |
|
| 3994 | + } |
|
| 3995 | 3995 | |
| 3996 | 3996 | |
| 3997 | - /** |
|
| 3998 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 3999 | - */ |
|
| 4000 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4001 | - { |
|
| 4002 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 4003 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 4004 | - } |
|
| 3997 | + /** |
|
| 3998 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 3999 | + */ |
|
| 4000 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4001 | + { |
|
| 4002 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 4003 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 4004 | + } |
|
| 4005 | 4005 | |
| 4006 | 4006 | |
| 4007 | - /** |
|
| 4008 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 4009 | - * |
|
| 4010 | - * @param EE_messenger $messenger |
|
| 4011 | - * @param EE_message_type|null $message_type |
|
| 4012 | - * @return bool |
|
| 4013 | - * @throws DomainException |
|
| 4014 | - * @throws EE_Error |
|
| 4015 | - * @throws InvalidArgumentException |
|
| 4016 | - * @throws ReflectionException |
|
| 4017 | - * @throws InvalidDataTypeException |
|
| 4018 | - * @throws InvalidInterfaceException |
|
| 4019 | - */ |
|
| 4020 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4021 | - $messenger, |
|
| 4022 | - EE_Message_Type $message_type = null |
|
| 4023 | - ) { |
|
| 4024 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4025 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4026 | - EE_Error::add_error( |
|
| 4027 | - esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4028 | - __FILE__, |
|
| 4029 | - __FUNCTION__, |
|
| 4030 | - __LINE__ |
|
| 4031 | - ); |
|
| 4007 | + /** |
|
| 4008 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 4009 | + * |
|
| 4010 | + * @param EE_messenger $messenger |
|
| 4011 | + * @param EE_message_type|null $message_type |
|
| 4012 | + * @return bool |
|
| 4013 | + * @throws DomainException |
|
| 4014 | + * @throws EE_Error |
|
| 4015 | + * @throws InvalidArgumentException |
|
| 4016 | + * @throws ReflectionException |
|
| 4017 | + * @throws InvalidDataTypeException |
|
| 4018 | + * @throws InvalidInterfaceException |
|
| 4019 | + */ |
|
| 4020 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4021 | + $messenger, |
|
| 4022 | + EE_Message_Type $message_type = null |
|
| 4023 | + ) { |
|
| 4024 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4025 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4026 | + EE_Error::add_error( |
|
| 4027 | + esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4028 | + __FILE__, |
|
| 4029 | + __FUNCTION__, |
|
| 4030 | + __LINE__ |
|
| 4031 | + ); |
|
| 4032 | 4032 | |
| 4033 | - return false; |
|
| 4034 | - } |
|
| 4035 | - //activated |
|
| 4036 | - if ($this->_template_args['data']['active_mts']) { |
|
| 4037 | - EE_Error::overwrite_success(); |
|
| 4038 | - //activated a message type with the messenger |
|
| 4039 | - if ($message_type instanceof EE_message_type) { |
|
| 4040 | - EE_Error::add_success( |
|
| 4041 | - sprintf( |
|
| 4042 | - esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4043 | - ucwords($message_type->label['singular']), |
|
| 4044 | - ucwords($messenger->label['singular']) |
|
| 4045 | - ) |
|
| 4046 | - ); |
|
| 4033 | + return false; |
|
| 4034 | + } |
|
| 4035 | + //activated |
|
| 4036 | + if ($this->_template_args['data']['active_mts']) { |
|
| 4037 | + EE_Error::overwrite_success(); |
|
| 4038 | + //activated a message type with the messenger |
|
| 4039 | + if ($message_type instanceof EE_message_type) { |
|
| 4040 | + EE_Error::add_success( |
|
| 4041 | + sprintf( |
|
| 4042 | + esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4043 | + ucwords($message_type->label['singular']), |
|
| 4044 | + ucwords($messenger->label['singular']) |
|
| 4045 | + ) |
|
| 4046 | + ); |
|
| 4047 | 4047 | |
| 4048 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4049 | - if ($message_type->name === 'invoice') { |
|
| 4050 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4051 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4052 | - if ($pm instanceof EE_Payment_Method) { |
|
| 4053 | - EE_Error::add_attention( |
|
| 4054 | - esc_html__( |
|
| 4055 | - '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.', |
|
| 4056 | - 'event_espresso' |
|
| 4057 | - ) |
|
| 4058 | - ); |
|
| 4059 | - } |
|
| 4060 | - } |
|
| 4061 | - //just toggles the entire messenger |
|
| 4062 | - } else { |
|
| 4063 | - EE_Error::add_success( |
|
| 4064 | - sprintf( |
|
| 4065 | - esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4066 | - ucwords($messenger->label['singular']) |
|
| 4067 | - ) |
|
| 4068 | - ); |
|
| 4069 | - } |
|
| 4048 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4049 | + if ($message_type->name === 'invoice') { |
|
| 4050 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4051 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4052 | + if ($pm instanceof EE_Payment_Method) { |
|
| 4053 | + EE_Error::add_attention( |
|
| 4054 | + esc_html__( |
|
| 4055 | + '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.', |
|
| 4056 | + 'event_espresso' |
|
| 4057 | + ) |
|
| 4058 | + ); |
|
| 4059 | + } |
|
| 4060 | + } |
|
| 4061 | + //just toggles the entire messenger |
|
| 4062 | + } else { |
|
| 4063 | + EE_Error::add_success( |
|
| 4064 | + sprintf( |
|
| 4065 | + esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4066 | + ucwords($messenger->label['singular']) |
|
| 4067 | + ) |
|
| 4068 | + ); |
|
| 4069 | + } |
|
| 4070 | 4070 | |
| 4071 | - return true; |
|
| 4071 | + return true; |
|
| 4072 | 4072 | |
| 4073 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4074 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4075 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 4076 | - } else { |
|
| 4077 | - if ( ! $messenger->get_default_message_types()) { |
|
| 4078 | - //messenger doesn't have any default message types so still a success. |
|
| 4079 | - EE_Error::add_success( |
|
| 4080 | - sprintf( |
|
| 4081 | - esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4082 | - ucwords($messenger->label['singular']) |
|
| 4083 | - ) |
|
| 4084 | - ); |
|
| 4073 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4074 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4075 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 4076 | + } else { |
|
| 4077 | + if ( ! $messenger->get_default_message_types()) { |
|
| 4078 | + //messenger doesn't have any default message types so still a success. |
|
| 4079 | + EE_Error::add_success( |
|
| 4080 | + sprintf( |
|
| 4081 | + esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4082 | + ucwords($messenger->label['singular']) |
|
| 4083 | + ) |
|
| 4084 | + ); |
|
| 4085 | 4085 | |
| 4086 | - return true; |
|
| 4087 | - } else { |
|
| 4088 | - EE_Error::add_error( |
|
| 4089 | - $message_type instanceof EE_message_type |
|
| 4090 | - ? sprintf( |
|
| 4091 | - esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4092 | - ucwords($message_type->label['singular']), |
|
| 4093 | - ucwords($messenger->label['singular']) |
|
| 4094 | - ) |
|
| 4095 | - : sprintf( |
|
| 4096 | - esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4097 | - ucwords($messenger->label['singular']) |
|
| 4098 | - ), |
|
| 4099 | - __FILE__, |
|
| 4100 | - __FUNCTION__, |
|
| 4101 | - __LINE__ |
|
| 4102 | - ); |
|
| 4086 | + return true; |
|
| 4087 | + } else { |
|
| 4088 | + EE_Error::add_error( |
|
| 4089 | + $message_type instanceof EE_message_type |
|
| 4090 | + ? sprintf( |
|
| 4091 | + esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4092 | + ucwords($message_type->label['singular']), |
|
| 4093 | + ucwords($messenger->label['singular']) |
|
| 4094 | + ) |
|
| 4095 | + : sprintf( |
|
| 4096 | + esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4097 | + ucwords($messenger->label['singular']) |
|
| 4098 | + ), |
|
| 4099 | + __FILE__, |
|
| 4100 | + __FUNCTION__, |
|
| 4101 | + __LINE__ |
|
| 4102 | + ); |
|
| 4103 | 4103 | |
| 4104 | - return false; |
|
| 4105 | - } |
|
| 4106 | - } |
|
| 4107 | - } |
|
| 4104 | + return false; |
|
| 4105 | + } |
|
| 4106 | + } |
|
| 4107 | + } |
|
| 4108 | 4108 | |
| 4109 | 4109 | |
| 4110 | - /** |
|
| 4111 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4112 | - * |
|
| 4113 | - * @param EE_messenger $messenger |
|
| 4114 | - * @param EE_message_type|null $message_type |
|
| 4115 | - * @return bool |
|
| 4116 | - * @throws DomainException |
|
| 4117 | - * @throws EE_Error |
|
| 4118 | - * @throws InvalidArgumentException |
|
| 4119 | - * @throws ReflectionException |
|
| 4120 | - * @throws InvalidDataTypeException |
|
| 4121 | - * @throws InvalidInterfaceException |
|
| 4122 | - */ |
|
| 4123 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4124 | - $messenger, |
|
| 4125 | - EE_message_type $message_type = null |
|
| 4126 | - ) { |
|
| 4127 | - EE_Error::overwrite_success(); |
|
| 4128 | - |
|
| 4129 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4130 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4131 | - EE_Error::add_error( |
|
| 4132 | - esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4133 | - __FILE__, |
|
| 4134 | - __FUNCTION__, |
|
| 4135 | - __LINE__ |
|
| 4136 | - ); |
|
| 4110 | + /** |
|
| 4111 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4112 | + * |
|
| 4113 | + * @param EE_messenger $messenger |
|
| 4114 | + * @param EE_message_type|null $message_type |
|
| 4115 | + * @return bool |
|
| 4116 | + * @throws DomainException |
|
| 4117 | + * @throws EE_Error |
|
| 4118 | + * @throws InvalidArgumentException |
|
| 4119 | + * @throws ReflectionException |
|
| 4120 | + * @throws InvalidDataTypeException |
|
| 4121 | + * @throws InvalidInterfaceException |
|
| 4122 | + */ |
|
| 4123 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4124 | + $messenger, |
|
| 4125 | + EE_message_type $message_type = null |
|
| 4126 | + ) { |
|
| 4127 | + EE_Error::overwrite_success(); |
|
| 4128 | + |
|
| 4129 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4130 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4131 | + EE_Error::add_error( |
|
| 4132 | + esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4133 | + __FILE__, |
|
| 4134 | + __FUNCTION__, |
|
| 4135 | + __LINE__ |
|
| 4136 | + ); |
|
| 4137 | 4137 | |
| 4138 | - return false; |
|
| 4139 | - } |
|
| 4140 | - |
|
| 4141 | - if ($message_type instanceof EE_message_type) { |
|
| 4142 | - $message_type_name = $message_type->name; |
|
| 4143 | - EE_Error::add_success( |
|
| 4144 | - sprintf( |
|
| 4145 | - esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4146 | - ucwords($message_type->label['singular']), |
|
| 4147 | - ucwords($messenger->label['singular']) |
|
| 4148 | - ) |
|
| 4149 | - ); |
|
| 4150 | - } else { |
|
| 4151 | - $message_type_name = ''; |
|
| 4152 | - EE_Error::add_success( |
|
| 4153 | - sprintf( |
|
| 4154 | - esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4155 | - ucwords($messenger->label['singular']) |
|
| 4156 | - ) |
|
| 4157 | - ); |
|
| 4158 | - } |
|
| 4159 | - |
|
| 4160 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4161 | - if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4162 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4163 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4164 | - if ($count_updated > 0) { |
|
| 4165 | - $msg = $message_type_name === 'invoice' |
|
| 4166 | - ? esc_html__( |
|
| 4167 | - '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.', |
|
| 4168 | - 'event_espresso' |
|
| 4169 | - ) |
|
| 4170 | - : esc_html__( |
|
| 4171 | - '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.', |
|
| 4172 | - 'event_espresso' |
|
| 4173 | - ); |
|
| 4174 | - EE_Error::add_attention($msg); |
|
| 4175 | - } |
|
| 4176 | - } |
|
| 4177 | - |
|
| 4178 | - return true; |
|
| 4179 | - } |
|
| 4138 | + return false; |
|
| 4139 | + } |
|
| 4140 | + |
|
| 4141 | + if ($message_type instanceof EE_message_type) { |
|
| 4142 | + $message_type_name = $message_type->name; |
|
| 4143 | + EE_Error::add_success( |
|
| 4144 | + sprintf( |
|
| 4145 | + esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4146 | + ucwords($message_type->label['singular']), |
|
| 4147 | + ucwords($messenger->label['singular']) |
|
| 4148 | + ) |
|
| 4149 | + ); |
|
| 4150 | + } else { |
|
| 4151 | + $message_type_name = ''; |
|
| 4152 | + EE_Error::add_success( |
|
| 4153 | + sprintf( |
|
| 4154 | + esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4155 | + ucwords($messenger->label['singular']) |
|
| 4156 | + ) |
|
| 4157 | + ); |
|
| 4158 | + } |
|
| 4159 | + |
|
| 4160 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4161 | + if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4162 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4163 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4164 | + if ($count_updated > 0) { |
|
| 4165 | + $msg = $message_type_name === 'invoice' |
|
| 4166 | + ? esc_html__( |
|
| 4167 | + '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.', |
|
| 4168 | + 'event_espresso' |
|
| 4169 | + ) |
|
| 4170 | + : esc_html__( |
|
| 4171 | + '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.', |
|
| 4172 | + 'event_espresso' |
|
| 4173 | + ); |
|
| 4174 | + EE_Error::add_attention($msg); |
|
| 4175 | + } |
|
| 4176 | + } |
|
| 4177 | + |
|
| 4178 | + return true; |
|
| 4179 | + } |
|
| 4180 | 4180 | |
| 4181 | 4181 | |
| 4182 | - /** |
|
| 4183 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4184 | - * |
|
| 4185 | - * @throws DomainException |
|
| 4186 | - */ |
|
| 4187 | - public function update_mt_form() |
|
| 4188 | - { |
|
| 4189 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4190 | - EE_Error::add_error( |
|
| 4191 | - esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4192 | - __FILE__, |
|
| 4193 | - __FUNCTION__, |
|
| 4194 | - __LINE__ |
|
| 4195 | - ); |
|
| 4196 | - $this->_return_json(); |
|
| 4197 | - } |
|
| 4198 | - |
|
| 4199 | - $message_types = $this->get_installed_message_types(); |
|
| 4200 | - |
|
| 4201 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4202 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4203 | - |
|
| 4204 | - $content = $this->_message_type_settings_content( |
|
| 4205 | - $message_type, |
|
| 4206 | - $messenger, |
|
| 4207 | - true |
|
| 4208 | - ); |
|
| 4209 | - $this->_template_args['success'] = true; |
|
| 4210 | - $this->_template_args['content'] = $content; |
|
| 4211 | - $this->_return_json(); |
|
| 4212 | - } |
|
| 4182 | + /** |
|
| 4183 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4184 | + * |
|
| 4185 | + * @throws DomainException |
|
| 4186 | + */ |
|
| 4187 | + public function update_mt_form() |
|
| 4188 | + { |
|
| 4189 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4190 | + EE_Error::add_error( |
|
| 4191 | + esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4192 | + __FILE__, |
|
| 4193 | + __FUNCTION__, |
|
| 4194 | + __LINE__ |
|
| 4195 | + ); |
|
| 4196 | + $this->_return_json(); |
|
| 4197 | + } |
|
| 4198 | + |
|
| 4199 | + $message_types = $this->get_installed_message_types(); |
|
| 4200 | + |
|
| 4201 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4202 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4203 | + |
|
| 4204 | + $content = $this->_message_type_settings_content( |
|
| 4205 | + $message_type, |
|
| 4206 | + $messenger, |
|
| 4207 | + true |
|
| 4208 | + ); |
|
| 4209 | + $this->_template_args['success'] = true; |
|
| 4210 | + $this->_template_args['content'] = $content; |
|
| 4211 | + $this->_return_json(); |
|
| 4212 | + } |
|
| 4213 | 4213 | |
| 4214 | 4214 | |
| 4215 | - /** |
|
| 4216 | - * this handles saving the settings for a messenger or message type |
|
| 4217 | - * |
|
| 4218 | - */ |
|
| 4219 | - public function save_settings() |
|
| 4220 | - { |
|
| 4221 | - if ( ! isset($this->_req_data['type'])) { |
|
| 4222 | - EE_Error::add_error( |
|
| 4223 | - esc_html__( |
|
| 4224 | - 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4225 | - 'event_espresso' |
|
| 4226 | - ), |
|
| 4227 | - __FILE__, |
|
| 4228 | - __FUNCTION__, |
|
| 4229 | - __LINE__ |
|
| 4230 | - ); |
|
| 4231 | - $this->_template_args['error'] = true; |
|
| 4232 | - $this->_return_json(); |
|
| 4233 | - } |
|
| 4234 | - |
|
| 4235 | - |
|
| 4236 | - if ($this->_req_data['type'] === 'messenger') { |
|
| 4237 | - //this should be an array. |
|
| 4238 | - $settings = $this->_req_data['messenger_settings']; |
|
| 4239 | - $messenger = $settings['messenger']; |
|
| 4240 | - //let's setup the settings data |
|
| 4241 | - foreach ($settings as $key => $value) { |
|
| 4242 | - switch ($key) { |
|
| 4243 | - case 'messenger' : |
|
| 4244 | - unset($settings['messenger']); |
|
| 4245 | - break; |
|
| 4246 | - case 'message_types' : |
|
| 4247 | - unset($settings['message_types']); |
|
| 4248 | - break; |
|
| 4249 | - default : |
|
| 4250 | - $settings[$key] = $value; |
|
| 4251 | - break; |
|
| 4252 | - } |
|
| 4253 | - } |
|
| 4254 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4255 | - } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4256 | - $settings = $this->_req_data['message_type_settings']; |
|
| 4257 | - $messenger = $settings['messenger']; |
|
| 4258 | - $message_type = $settings['message_type']; |
|
| 4215 | + /** |
|
| 4216 | + * this handles saving the settings for a messenger or message type |
|
| 4217 | + * |
|
| 4218 | + */ |
|
| 4219 | + public function save_settings() |
|
| 4220 | + { |
|
| 4221 | + if ( ! isset($this->_req_data['type'])) { |
|
| 4222 | + EE_Error::add_error( |
|
| 4223 | + esc_html__( |
|
| 4224 | + 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4225 | + 'event_espresso' |
|
| 4226 | + ), |
|
| 4227 | + __FILE__, |
|
| 4228 | + __FUNCTION__, |
|
| 4229 | + __LINE__ |
|
| 4230 | + ); |
|
| 4231 | + $this->_template_args['error'] = true; |
|
| 4232 | + $this->_return_json(); |
|
| 4233 | + } |
|
| 4234 | + |
|
| 4235 | + |
|
| 4236 | + if ($this->_req_data['type'] === 'messenger') { |
|
| 4237 | + //this should be an array. |
|
| 4238 | + $settings = $this->_req_data['messenger_settings']; |
|
| 4239 | + $messenger = $settings['messenger']; |
|
| 4240 | + //let's setup the settings data |
|
| 4241 | + foreach ($settings as $key => $value) { |
|
| 4242 | + switch ($key) { |
|
| 4243 | + case 'messenger' : |
|
| 4244 | + unset($settings['messenger']); |
|
| 4245 | + break; |
|
| 4246 | + case 'message_types' : |
|
| 4247 | + unset($settings['message_types']); |
|
| 4248 | + break; |
|
| 4249 | + default : |
|
| 4250 | + $settings[$key] = $value; |
|
| 4251 | + break; |
|
| 4252 | + } |
|
| 4253 | + } |
|
| 4254 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4255 | + } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4256 | + $settings = $this->_req_data['message_type_settings']; |
|
| 4257 | + $messenger = $settings['messenger']; |
|
| 4258 | + $message_type = $settings['message_type']; |
|
| 4259 | 4259 | |
| 4260 | - foreach ($settings as $key => $value) { |
|
| 4261 | - switch ($key) { |
|
| 4262 | - case 'messenger' : |
|
| 4263 | - unset($settings['messenger']); |
|
| 4264 | - break; |
|
| 4265 | - case 'message_type' : |
|
| 4266 | - unset($settings['message_type']); |
|
| 4267 | - break; |
|
| 4268 | - default : |
|
| 4269 | - $settings[$key] = $value; |
|
| 4270 | - break; |
|
| 4271 | - } |
|
| 4272 | - } |
|
| 4260 | + foreach ($settings as $key => $value) { |
|
| 4261 | + switch ($key) { |
|
| 4262 | + case 'messenger' : |
|
| 4263 | + unset($settings['messenger']); |
|
| 4264 | + break; |
|
| 4265 | + case 'message_type' : |
|
| 4266 | + unset($settings['message_type']); |
|
| 4267 | + break; |
|
| 4268 | + default : |
|
| 4269 | + $settings[$key] = $value; |
|
| 4270 | + break; |
|
| 4271 | + } |
|
| 4272 | + } |
|
| 4273 | 4273 | |
| 4274 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4275 | - } |
|
| 4276 | - |
|
| 4277 | - //okay we should have the data all setup. Now we just update! |
|
| 4278 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4279 | - |
|
| 4280 | - if ($success) { |
|
| 4281 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4282 | - } else { |
|
| 4283 | - EE_Error::add_error( |
|
| 4284 | - esc_html__( |
|
| 4285 | - 'Settings did not get updated', |
|
| 4286 | - 'event_espresso' |
|
| 4287 | - ), |
|
| 4288 | - __FILE__, |
|
| 4289 | - __FUNCTION__, |
|
| 4290 | - __LINE__ |
|
| 4291 | - ); |
|
| 4292 | - } |
|
| 4293 | - |
|
| 4294 | - $this->_template_args['success'] = $success; |
|
| 4295 | - $this->_return_json(); |
|
| 4296 | - } |
|
| 4274 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4275 | + } |
|
| 4276 | + |
|
| 4277 | + //okay we should have the data all setup. Now we just update! |
|
| 4278 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4279 | + |
|
| 4280 | + if ($success) { |
|
| 4281 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4282 | + } else { |
|
| 4283 | + EE_Error::add_error( |
|
| 4284 | + esc_html__( |
|
| 4285 | + 'Settings did not get updated', |
|
| 4286 | + 'event_espresso' |
|
| 4287 | + ), |
|
| 4288 | + __FILE__, |
|
| 4289 | + __FUNCTION__, |
|
| 4290 | + __LINE__ |
|
| 4291 | + ); |
|
| 4292 | + } |
|
| 4293 | + |
|
| 4294 | + $this->_template_args['success'] = $success; |
|
| 4295 | + $this->_return_json(); |
|
| 4296 | + } |
|
| 4297 | 4297 | |
| 4298 | 4298 | |
| 4299 | 4299 | |
| 4300 | 4300 | |
| 4301 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4301 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4302 | 4302 | |
| 4303 | 4303 | |
| 4304 | - /** |
|
| 4305 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4306 | - * However, this does not send immediately, it just queues for sending. |
|
| 4307 | - * |
|
| 4308 | - * @since 4.9.0 |
|
| 4309 | - */ |
|
| 4310 | - protected function _generate_now() |
|
| 4311 | - { |
|
| 4312 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4313 | - EED_Messages::generate_now($msg_ids); |
|
| 4314 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4315 | - } |
|
| 4304 | + /** |
|
| 4305 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4306 | + * However, this does not send immediately, it just queues for sending. |
|
| 4307 | + * |
|
| 4308 | + * @since 4.9.0 |
|
| 4309 | + */ |
|
| 4310 | + protected function _generate_now() |
|
| 4311 | + { |
|
| 4312 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4313 | + EED_Messages::generate_now($msg_ids); |
|
| 4314 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4315 | + } |
|
| 4316 | 4316 | |
| 4317 | 4317 | |
| 4318 | - /** |
|
| 4319 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4320 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4321 | - * |
|
| 4322 | - * @since 4.9.0 |
|
| 4323 | - * |
|
| 4324 | - */ |
|
| 4325 | - protected function _generate_and_send_now() |
|
| 4326 | - { |
|
| 4327 | - $this->_generate_now(); |
|
| 4328 | - $this->_send_now(); |
|
| 4329 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4330 | - } |
|
| 4318 | + /** |
|
| 4319 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4320 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4321 | + * |
|
| 4322 | + * @since 4.9.0 |
|
| 4323 | + * |
|
| 4324 | + */ |
|
| 4325 | + protected function _generate_and_send_now() |
|
| 4326 | + { |
|
| 4327 | + $this->_generate_now(); |
|
| 4328 | + $this->_send_now(); |
|
| 4329 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4330 | + } |
|
| 4331 | 4331 | |
| 4332 | 4332 | |
| 4333 | - /** |
|
| 4334 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4335 | - * |
|
| 4336 | - * @since 4.9.0 |
|
| 4337 | - */ |
|
| 4338 | - protected function _queue_for_resending() |
|
| 4339 | - { |
|
| 4340 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4341 | - EED_Messages::queue_for_resending($msg_ids); |
|
| 4342 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4343 | - } |
|
| 4333 | + /** |
|
| 4334 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4335 | + * |
|
| 4336 | + * @since 4.9.0 |
|
| 4337 | + */ |
|
| 4338 | + protected function _queue_for_resending() |
|
| 4339 | + { |
|
| 4340 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4341 | + EED_Messages::queue_for_resending($msg_ids); |
|
| 4342 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4343 | + } |
|
| 4344 | 4344 | |
| 4345 | 4345 | |
| 4346 | - /** |
|
| 4347 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4348 | - * |
|
| 4349 | - * @since 4.9.0 |
|
| 4350 | - */ |
|
| 4351 | - protected function _send_now() |
|
| 4352 | - { |
|
| 4353 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4354 | - EED_Messages::send_now($msg_ids); |
|
| 4355 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | - } |
|
| 4346 | + /** |
|
| 4347 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4348 | + * |
|
| 4349 | + * @since 4.9.0 |
|
| 4350 | + */ |
|
| 4351 | + protected function _send_now() |
|
| 4352 | + { |
|
| 4353 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4354 | + EED_Messages::send_now($msg_ids); |
|
| 4355 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | + } |
|
| 4357 | 4357 | |
| 4358 | 4358 | |
| 4359 | - /** |
|
| 4360 | - * Deletes EE_messages for IDs in the request. |
|
| 4361 | - * |
|
| 4362 | - * @since 4.9.0 |
|
| 4363 | - * @throws EE_Error |
|
| 4364 | - * @throws InvalidDataTypeException |
|
| 4365 | - * @throws InvalidInterfaceException |
|
| 4366 | - * @throws InvalidArgumentException |
|
| 4367 | - */ |
|
| 4368 | - protected function _delete_ee_messages() |
|
| 4369 | - { |
|
| 4370 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4371 | - $deleted_count = 0; |
|
| 4372 | - foreach ($msg_ids as $msg_id) { |
|
| 4373 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4374 | - $deleted_count++; |
|
| 4375 | - } |
|
| 4376 | - } |
|
| 4377 | - if ($deleted_count) { |
|
| 4378 | - $this->_redirect_after_action( |
|
| 4379 | - true, |
|
| 4380 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 4381 | - esc_html__('deleted', 'event_espresso') |
|
| 4382 | - ); |
|
| 4383 | - } else { |
|
| 4384 | - EE_Error::add_error( |
|
| 4385 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4386 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 4387 | - ); |
|
| 4388 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4389 | - } |
|
| 4390 | - } |
|
| 4359 | + /** |
|
| 4360 | + * Deletes EE_messages for IDs in the request. |
|
| 4361 | + * |
|
| 4362 | + * @since 4.9.0 |
|
| 4363 | + * @throws EE_Error |
|
| 4364 | + * @throws InvalidDataTypeException |
|
| 4365 | + * @throws InvalidInterfaceException |
|
| 4366 | + * @throws InvalidArgumentException |
|
| 4367 | + */ |
|
| 4368 | + protected function _delete_ee_messages() |
|
| 4369 | + { |
|
| 4370 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4371 | + $deleted_count = 0; |
|
| 4372 | + foreach ($msg_ids as $msg_id) { |
|
| 4373 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4374 | + $deleted_count++; |
|
| 4375 | + } |
|
| 4376 | + } |
|
| 4377 | + if ($deleted_count) { |
|
| 4378 | + $this->_redirect_after_action( |
|
| 4379 | + true, |
|
| 4380 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 4381 | + esc_html__('deleted', 'event_espresso') |
|
| 4382 | + ); |
|
| 4383 | + } else { |
|
| 4384 | + EE_Error::add_error( |
|
| 4385 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4386 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 4387 | + ); |
|
| 4388 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4389 | + } |
|
| 4390 | + } |
|
| 4391 | 4391 | |
| 4392 | 4392 | |
| 4393 | - /** |
|
| 4394 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4395 | - * @since 4.9.0 |
|
| 4396 | - * @return array |
|
| 4397 | - */ |
|
| 4398 | - protected function _get_msg_ids_from_request() |
|
| 4399 | - { |
|
| 4400 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4401 | - return array(); |
|
| 4402 | - } |
|
| 4403 | - |
|
| 4404 | - return is_array($this->_req_data['MSG_ID']) |
|
| 4405 | - ? array_keys($this->_req_data['MSG_ID']) |
|
| 4406 | - : array($this->_req_data['MSG_ID']); |
|
| 4407 | - } |
|
| 4393 | + /** |
|
| 4394 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4395 | + * @since 4.9.0 |
|
| 4396 | + * @return array |
|
| 4397 | + */ |
|
| 4398 | + protected function _get_msg_ids_from_request() |
|
| 4399 | + { |
|
| 4400 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4401 | + return array(); |
|
| 4402 | + } |
|
| 4403 | + |
|
| 4404 | + return is_array($this->_req_data['MSG_ID']) |
|
| 4405 | + ? array_keys($this->_req_data['MSG_ID']) |
|
| 4406 | + : array($this->_req_data['MSG_ID']); |
|
| 4407 | + } |
|
| 4408 | 4408 | } |
@@ -3,79 +3,79 @@ |
||
| 3 | 3 | </p> |
| 4 | 4 | <p> |
| 5 | 5 | <?php esc_html_e( |
| 6 | - 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
| 7 | - 'event_espresso' |
|
| 8 | - ); ?> |
|
| 6 | + 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
| 7 | + 'event_espresso' |
|
| 8 | + ); ?> |
|
| 9 | 9 | </p> |
| 10 | 10 | <p> |
| 11 | 11 | <?php esc_html_e( |
| 12 | - 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
| 13 | - 'event_espresso' |
|
| 14 | - ); ?> |
|
| 12 | + 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
| 13 | + 'event_espresso' |
|
| 14 | + ); ?> |
|
| 15 | 15 | </p> |
| 16 | 16 | <p> |
| 17 | 17 | <?php printf( |
| 18 | - esc_html__( |
|
| 19 | - 'The green colored gear %s indicates that this messenger is currently active.', |
|
| 20 | - 'event_espresso' |
|
| 21 | - ), |
|
| 22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
| 23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
| 24 | - ); |
|
| 25 | - printf( |
|
| 26 | - esc_html__( |
|
| 27 | - ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
| 28 | - 'event_espresso' |
|
| 29 | - ), |
|
| 30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
| 32 | - ); ?> |
|
| 18 | + esc_html__( |
|
| 19 | + 'The green colored gear %s indicates that this messenger is currently active.', |
|
| 20 | + 'event_espresso' |
|
| 21 | + ), |
|
| 22 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
| 23 | + . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
| 24 | + ); |
|
| 25 | + printf( |
|
| 26 | + esc_html__( |
|
| 27 | + ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
| 28 | + 'event_espresso' |
|
| 29 | + ), |
|
| 30 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 31 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
| 32 | + ); ?> |
|
| 33 | 33 | </p> |
| 34 | 34 | <p> |
| 35 | 35 | <?php esc_html_e( |
| 36 | - 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
| 37 | - 'event_espresso' |
|
| 38 | - ); ?> |
|
| 36 | + 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
| 37 | + 'event_espresso' |
|
| 38 | + ); ?> |
|
| 39 | 39 | </p> |
| 40 | 40 | <p> |
| 41 | 41 | <?php printf( |
| 42 | - esc_html__( |
|
| 43 | - '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
| 44 | - 'event_espresso' |
|
| 45 | - ), |
|
| 46 | - '<div class="switch">' |
|
| 47 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
| 48 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 49 | - . '</div>', |
|
| 50 | - '<div class="switch">' |
|
| 51 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
| 52 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 53 | - . '</div>' |
|
| 54 | - ); ?> |
|
| 42 | + esc_html__( |
|
| 43 | + '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
| 44 | + 'event_espresso' |
|
| 45 | + ), |
|
| 46 | + '<div class="switch">' |
|
| 47 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
| 48 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 49 | + . '</div>', |
|
| 50 | + '<div class="switch">' |
|
| 51 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
| 52 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 53 | + . '</div>' |
|
| 54 | + ); ?> |
|
| 55 | 55 | </p> |
| 56 | 56 | <p> |
| 57 | 57 | <?php |
| 58 | - esc_html_e( |
|
| 59 | - 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
| 60 | - 'event_espresso' |
|
| 61 | - ); ?> |
|
| 58 | + esc_html_e( |
|
| 59 | + 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
| 60 | + 'event_espresso' |
|
| 61 | + ); ?> |
|
| 62 | 62 | </p> |
| 63 | 63 | <p> |
| 64 | 64 | <?php esc_html_e( |
| 65 | - 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
| 66 | - 'event_espresso' |
|
| 67 | - ); ?> |
|
| 65 | + 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
| 66 | + 'event_espresso' |
|
| 67 | + ); ?> |
|
| 68 | 68 | </p> |
| 69 | 69 | <p> |
| 70 | 70 | <?php esc_html_e( |
| 71 | - 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
| 72 | - 'event_espresso' |
|
| 73 | - ); ?> |
|
| 71 | + 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
| 72 | + 'event_espresso' |
|
| 73 | + ); ?> |
|
| 74 | 74 | </p> |
| 75 | 75 | <p> |
| 76 | 76 | <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/> |
| 77 | 77 | <?php esc_html_e( |
| 78 | - 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
| 79 | - 'event_espresso' |
|
| 80 | - ); ?> |
|
| 78 | + 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
| 79 | + 'event_espresso' |
|
| 80 | + ); ?> |
|
| 81 | 81 | </p> |
@@ -19,16 +19,16 @@ |
||
| 19 | 19 | 'The green colored gear %s indicates that this messenger is currently active.', |
| 20 | 20 | 'event_espresso' |
| 21 | 21 | ), |
| 22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
| 23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
| 22 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"' |
|
| 23 | + . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />' |
|
| 24 | 24 | ); |
| 25 | 25 | printf( |
| 26 | 26 | esc_html__( |
| 27 | 27 | ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
| 28 | 28 | 'event_espresso' |
| 29 | 29 | ), |
| 30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
| 30 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png' |
|
| 31 | + . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />' |
|
| 32 | 32 | ); ?> |
| 33 | 33 | </p> |
| 34 | 34 | <p> |
@@ -176,7 +176,7 @@ |
||
| 176 | 176 | /** |
| 177 | 177 | * This retrieves the EE_Venue from the available data object. |
| 178 | 178 | * |
| 179 | - * @return EE_Venue|null |
|
| 179 | + * @return EE_Base_Class|null |
|
| 180 | 180 | * @throws EE_Error |
| 181 | 181 | * @throws EntityNotFoundException |
| 182 | 182 | */ |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | $this->_venue = $this->_get_venue(); |
| 92 | 92 | //If there is no venue object by now then get out. |
| 93 | - if (! $this->_venue instanceof EE_Venue) { |
|
| 93 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
| 94 | 94 | return ''; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
| 190 | 190 | // reg_obj instead. |
| 191 | - if (! $this->_event instanceof EE_Event) { |
|
| 191 | + if ( ! $this->_event instanceof EE_Event) { |
|
| 192 | 192 | $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
| 193 | 193 | $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
| 194 | 194 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
| 207 | 207 | // and use that. |
| 208 | - $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
| 208 | + $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
| 209 | 209 | ? reset($aee->events) |
| 210 | 210 | : $this->_event; |
| 211 | 211 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | private function _venue($field) |
| 230 | 230 | { |
| 231 | 231 | |
| 232 | - if (! $this->_venue instanceof EE_Venue) { |
|
| 232 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
| 233 | 233 | return ''; |
| 234 | 234 | } //no venue so get out. |
| 235 | 235 | |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | break; |
| 253 | 253 | |
| 254 | 254 | case 'image': |
| 255 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
| 256 | - . '" alt="' . sprintf( |
|
| 255 | + return '<img src="'.$this->_venue->feature_image_url(array(200, 200,)) |
|
| 256 | + . '" alt="'.sprintf( |
|
| 257 | 257 | esc_attr__('%s Feature Image', 'event_espresso'), |
| 258 | 258 | $this->_venue->get('VNU_name') |
| 259 | - ) . '" />'; |
|
| 259 | + ).'" />'; |
|
| 260 | 260 | break; |
| 261 | 261 | |
| 262 | 262 | case 'phone': |
@@ -19,317 +19,317 @@ |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Will hold the EE_Event if available |
|
| 24 | - * |
|
| 25 | - * @var EE_Event |
|
| 26 | - */ |
|
| 27 | - protected $_event; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Will hold the EE_Venue if available |
|
| 31 | - * |
|
| 32 | - * @var EE_Venue |
|
| 33 | - */ |
|
| 34 | - protected $_venue; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Initialize properties |
|
| 39 | - */ |
|
| 40 | - protected function _init_props() |
|
| 41 | - { |
|
| 42 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
| 43 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
| 44 | - $this->_shortcodes = array( |
|
| 45 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
| 46 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
| 47 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
| 48 | - '[VENUE_DETAILS_URL]' => sprintf( |
|
| 49 | - esc_html__( |
|
| 50 | - 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
| 51 | - 'event_espresso' |
|
| 52 | - ), |
|
| 53 | - '[VENUE_URL]' |
|
| 54 | - ), |
|
| 55 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
| 56 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
| 57 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
| 58 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
| 59 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
| 60 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
| 61 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
| 62 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
| 63 | - 'This just outputs the venue address in a semantic address format.', |
|
| 64 | - 'event_espresso' |
|
| 65 | - ), |
|
| 66 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
| 67 | - '[VENUE_META_*]' => esc_html__( |
|
| 68 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
| 69 | - 'event_espresso' |
|
| 70 | - ), |
|
| 71 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
| 72 | - 'URL for the google map associated with the venue.', |
|
| 73 | - 'event_espresso' |
|
| 74 | - ), |
|
| 75 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
| 76 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Parse incoming shortcode |
|
| 83 | - * |
|
| 84 | - * @param string $shortcode |
|
| 85 | - * @return string |
|
| 86 | - * @throws EE_Error |
|
| 87 | - * @throws EntityNotFoundException |
|
| 88 | - */ |
|
| 89 | - protected function _parser($shortcode) |
|
| 90 | - { |
|
| 91 | - $this->_venue = $this->_get_venue(); |
|
| 92 | - //If there is no venue object by now then get out. |
|
| 93 | - if (! $this->_venue instanceof EE_Venue) { |
|
| 94 | - return ''; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - switch ($shortcode) { |
|
| 98 | - case '[VENUE_TITLE]': |
|
| 99 | - return $this->_venue('title'); |
|
| 100 | - break; |
|
| 101 | - |
|
| 102 | - case '[VENUE_DESCRIPTION]': |
|
| 103 | - return $this->_venue('description'); |
|
| 104 | - break; |
|
| 105 | - |
|
| 106 | - case '[VENUE_URL]': |
|
| 107 | - return $this->_venue('url'); |
|
| 108 | - break; |
|
| 109 | - |
|
| 110 | - case '[VENUE_IMAGE]': |
|
| 111 | - return $this->_venue('image'); |
|
| 112 | - break; |
|
| 113 | - |
|
| 114 | - case '[VENUE_PHONE]': |
|
| 115 | - return $this->_venue('phone'); |
|
| 116 | - break; |
|
| 117 | - |
|
| 118 | - case '[VENUE_ADDRESS]': |
|
| 119 | - return $this->_venue('address'); |
|
| 120 | - break; |
|
| 121 | - |
|
| 122 | - case '[VENUE_ADDRESS2]': |
|
| 123 | - return $this->_venue('address2'); |
|
| 124 | - break; |
|
| 125 | - |
|
| 126 | - case '[VENUE_CITY]': |
|
| 127 | - return $this->_venue('city'); |
|
| 128 | - break; |
|
| 129 | - |
|
| 130 | - case '[VENUE_COUNTRY]': |
|
| 131 | - return $this->_venue('country'); |
|
| 132 | - break; |
|
| 133 | - |
|
| 134 | - case '[VENUE_STATE]': |
|
| 135 | - return $this->_venue('state'); |
|
| 136 | - break; |
|
| 137 | - |
|
| 138 | - case '[VENUE_ZIP]': |
|
| 139 | - return $this->_venue('zip'); |
|
| 140 | - break; |
|
| 141 | - |
|
| 142 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
| 143 | - return $this->_venue('formatted_address'); |
|
| 144 | - break; |
|
| 145 | - |
|
| 146 | - case '[GOOGLE_MAP_URL]': |
|
| 147 | - return $this->_venue('gmap_url'); |
|
| 148 | - break; |
|
| 149 | - |
|
| 150 | - case '[GOOGLE_MAP_LINK]': |
|
| 151 | - return $this->_venue('gmap_link'); |
|
| 152 | - break; |
|
| 153 | - |
|
| 154 | - case '[GOOGLE_MAP_IMAGE]': |
|
| 155 | - return $this->_venue('gmap_link_img'); |
|
| 156 | - break; |
|
| 157 | - |
|
| 158 | - case '[VENUE_DETAILS_URL]': |
|
| 159 | - return $this->_venue('permalink'); |
|
| 160 | - break; |
|
| 161 | - |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
| 165 | - $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
| 166 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
| 167 | - |
|
| 168 | - //pull the meta value from the venue post |
|
| 169 | - $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
| 170 | - |
|
| 171 | - return ! empty($venue_meta) ? $venue_meta : ''; |
|
| 172 | - |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * This retrieves the EE_Venue from the available data object. |
|
| 178 | - * |
|
| 179 | - * @return EE_Venue|null |
|
| 180 | - * @throws EE_Error |
|
| 181 | - * @throws EntityNotFoundException |
|
| 182 | - */ |
|
| 183 | - private function _get_venue() |
|
| 184 | - { |
|
| 185 | - |
|
| 186 | - //we need the EE_Event object to get the venue. |
|
| 187 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
| 188 | - |
|
| 189 | - //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
| 190 | - // reg_obj instead. |
|
| 191 | - if (! $this->_event instanceof EE_Event) { |
|
| 192 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 193 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
| 194 | - |
|
| 195 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
| 196 | - ? $aee->reg_obj->event() |
|
| 197 | - : null; |
|
| 198 | - |
|
| 199 | - //if still empty do we have a ticket data item? |
|
| 200 | - $this->_event = ! $this->_event instanceof EE_Event |
|
| 201 | - && $this->_data instanceof EE_Ticket |
|
| 202 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 203 | - ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
| 204 | - : $this->_event; |
|
| 205 | - |
|
| 206 | - //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
| 207 | - // and use that. |
|
| 208 | - $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
| 209 | - ? reset($aee->events) |
|
| 210 | - : $this->_event; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - //If we have an event object use it to pull the venue. |
|
| 214 | - if ($this->_event instanceof EE_Event) { |
|
| 215 | - return $this->_event->get_first_related('Venue'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - return null; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * This retrieves the specified venue information |
|
| 223 | - * |
|
| 224 | - * @param string $field What Venue field to retrieve |
|
| 225 | - * @return string What was retrieved! |
|
| 226 | - * @throws EE_Error |
|
| 227 | - * @throws EntityNotFoundException |
|
| 228 | - */ |
|
| 229 | - private function _venue($field) |
|
| 230 | - { |
|
| 231 | - |
|
| 232 | - if (! $this->_venue instanceof EE_Venue) { |
|
| 233 | - return ''; |
|
| 234 | - } //no venue so get out. |
|
| 235 | - |
|
| 236 | - switch ($field) { |
|
| 237 | - case 'title': |
|
| 238 | - return $this->_venue->get('VNU_name'); |
|
| 239 | - break; |
|
| 240 | - |
|
| 241 | - case 'description': |
|
| 242 | - return $this->_venue->get('VNU_desc'); |
|
| 243 | - break; |
|
| 244 | - |
|
| 245 | - case 'url': |
|
| 246 | - $url = $this->_venue->get('VNU_url'); |
|
| 247 | - return empty($url) ? $this->_venue->get_permalink() : $url; |
|
| 248 | - break; |
|
| 249 | - |
|
| 250 | - case 'permalink': |
|
| 251 | - return $this->_venue->get_permalink(); |
|
| 252 | - break; |
|
| 253 | - |
|
| 254 | - case 'image': |
|
| 255 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
| 256 | - . '" alt="' . sprintf( |
|
| 257 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
| 258 | - $this->_venue->get('VNU_name') |
|
| 259 | - ) . '" />'; |
|
| 260 | - break; |
|
| 261 | - |
|
| 262 | - case 'phone': |
|
| 263 | - return $this->_venue->get('VNU_phone'); |
|
| 264 | - break; |
|
| 265 | - |
|
| 266 | - case 'address': |
|
| 267 | - return $this->_venue->get('VNU_address'); |
|
| 268 | - break; |
|
| 269 | - |
|
| 270 | - case 'address2': |
|
| 271 | - return $this->_venue->get('VNU_address2'); |
|
| 272 | - break; |
|
| 273 | - |
|
| 274 | - case 'city': |
|
| 275 | - return $this->_venue->get('VNU_city'); |
|
| 276 | - break; |
|
| 277 | - |
|
| 278 | - case 'state': |
|
| 279 | - $state = $this->_venue->state_obj(); |
|
| 280 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
| 281 | - break; |
|
| 282 | - |
|
| 283 | - case 'country': |
|
| 284 | - $country = $this->_venue->country_obj(); |
|
| 285 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
| 286 | - break; |
|
| 287 | - |
|
| 288 | - case 'zip': |
|
| 289 | - return $this->_venue->get('VNU_zip'); |
|
| 290 | - break; |
|
| 291 | - |
|
| 292 | - case 'formatted_address': |
|
| 293 | - return EEH_Address::format($this->_venue); |
|
| 294 | - break; |
|
| 295 | - |
|
| 296 | - case 'gmap_link': |
|
| 297 | - case 'gmap_url': |
|
| 298 | - case 'gmap_link_img': |
|
| 299 | - $atts = $this->get_map_attributes($this->_venue, $field); |
|
| 300 | - return EEH_Maps::google_map_link($atts); |
|
| 301 | - break; |
|
| 302 | - } |
|
| 303 | - return ''; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Generates the attributes for retrieving a google_map artifact. |
|
| 309 | - * |
|
| 310 | - * @param EE_Venue $venue |
|
| 311 | - * @param string $field |
|
| 312 | - * @return array |
|
| 313 | - * @throws EE_Error |
|
| 314 | - */ |
|
| 315 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
| 316 | - { |
|
| 317 | - $state = $venue->state_obj(); |
|
| 318 | - $country = $venue->country_obj(); |
|
| 319 | - $atts = array( |
|
| 320 | - 'id' => $venue->ID(), |
|
| 321 | - 'address' => $venue->get('VNU_address'), |
|
| 322 | - 'city' => $venue->get('VNU_city'), |
|
| 323 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
| 324 | - 'zip' => $venue->get('VNU_zip'), |
|
| 325 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
| 326 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
| 327 | - 'map_w' => 200, |
|
| 328 | - 'map_h' => 200, |
|
| 329 | - ); |
|
| 330 | - if ($field === 'gmap_url') { |
|
| 331 | - $atts['type'] = 'url_only'; |
|
| 332 | - } |
|
| 333 | - return $atts; |
|
| 334 | - } |
|
| 22 | + /** |
|
| 23 | + * Will hold the EE_Event if available |
|
| 24 | + * |
|
| 25 | + * @var EE_Event |
|
| 26 | + */ |
|
| 27 | + protected $_event; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Will hold the EE_Venue if available |
|
| 31 | + * |
|
| 32 | + * @var EE_Venue |
|
| 33 | + */ |
|
| 34 | + protected $_venue; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Initialize properties |
|
| 39 | + */ |
|
| 40 | + protected function _init_props() |
|
| 41 | + { |
|
| 42 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
| 43 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
| 44 | + $this->_shortcodes = array( |
|
| 45 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
| 46 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
| 47 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
| 48 | + '[VENUE_DETAILS_URL]' => sprintf( |
|
| 49 | + esc_html__( |
|
| 50 | + 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
| 51 | + 'event_espresso' |
|
| 52 | + ), |
|
| 53 | + '[VENUE_URL]' |
|
| 54 | + ), |
|
| 55 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
| 56 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
| 57 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
| 58 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
| 59 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
| 60 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
| 61 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
| 62 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
| 63 | + 'This just outputs the venue address in a semantic address format.', |
|
| 64 | + 'event_espresso' |
|
| 65 | + ), |
|
| 66 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
| 67 | + '[VENUE_META_*]' => esc_html__( |
|
| 68 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
| 69 | + 'event_espresso' |
|
| 70 | + ), |
|
| 71 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
| 72 | + 'URL for the google map associated with the venue.', |
|
| 73 | + 'event_espresso' |
|
| 74 | + ), |
|
| 75 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
| 76 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Parse incoming shortcode |
|
| 83 | + * |
|
| 84 | + * @param string $shortcode |
|
| 85 | + * @return string |
|
| 86 | + * @throws EE_Error |
|
| 87 | + * @throws EntityNotFoundException |
|
| 88 | + */ |
|
| 89 | + protected function _parser($shortcode) |
|
| 90 | + { |
|
| 91 | + $this->_venue = $this->_get_venue(); |
|
| 92 | + //If there is no venue object by now then get out. |
|
| 93 | + if (! $this->_venue instanceof EE_Venue) { |
|
| 94 | + return ''; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + switch ($shortcode) { |
|
| 98 | + case '[VENUE_TITLE]': |
|
| 99 | + return $this->_venue('title'); |
|
| 100 | + break; |
|
| 101 | + |
|
| 102 | + case '[VENUE_DESCRIPTION]': |
|
| 103 | + return $this->_venue('description'); |
|
| 104 | + break; |
|
| 105 | + |
|
| 106 | + case '[VENUE_URL]': |
|
| 107 | + return $this->_venue('url'); |
|
| 108 | + break; |
|
| 109 | + |
|
| 110 | + case '[VENUE_IMAGE]': |
|
| 111 | + return $this->_venue('image'); |
|
| 112 | + break; |
|
| 113 | + |
|
| 114 | + case '[VENUE_PHONE]': |
|
| 115 | + return $this->_venue('phone'); |
|
| 116 | + break; |
|
| 117 | + |
|
| 118 | + case '[VENUE_ADDRESS]': |
|
| 119 | + return $this->_venue('address'); |
|
| 120 | + break; |
|
| 121 | + |
|
| 122 | + case '[VENUE_ADDRESS2]': |
|
| 123 | + return $this->_venue('address2'); |
|
| 124 | + break; |
|
| 125 | + |
|
| 126 | + case '[VENUE_CITY]': |
|
| 127 | + return $this->_venue('city'); |
|
| 128 | + break; |
|
| 129 | + |
|
| 130 | + case '[VENUE_COUNTRY]': |
|
| 131 | + return $this->_venue('country'); |
|
| 132 | + break; |
|
| 133 | + |
|
| 134 | + case '[VENUE_STATE]': |
|
| 135 | + return $this->_venue('state'); |
|
| 136 | + break; |
|
| 137 | + |
|
| 138 | + case '[VENUE_ZIP]': |
|
| 139 | + return $this->_venue('zip'); |
|
| 140 | + break; |
|
| 141 | + |
|
| 142 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
| 143 | + return $this->_venue('formatted_address'); |
|
| 144 | + break; |
|
| 145 | + |
|
| 146 | + case '[GOOGLE_MAP_URL]': |
|
| 147 | + return $this->_venue('gmap_url'); |
|
| 148 | + break; |
|
| 149 | + |
|
| 150 | + case '[GOOGLE_MAP_LINK]': |
|
| 151 | + return $this->_venue('gmap_link'); |
|
| 152 | + break; |
|
| 153 | + |
|
| 154 | + case '[GOOGLE_MAP_IMAGE]': |
|
| 155 | + return $this->_venue('gmap_link_img'); |
|
| 156 | + break; |
|
| 157 | + |
|
| 158 | + case '[VENUE_DETAILS_URL]': |
|
| 159 | + return $this->_venue('permalink'); |
|
| 160 | + break; |
|
| 161 | + |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
| 165 | + $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
| 166 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
| 167 | + |
|
| 168 | + //pull the meta value from the venue post |
|
| 169 | + $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
| 170 | + |
|
| 171 | + return ! empty($venue_meta) ? $venue_meta : ''; |
|
| 172 | + |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * This retrieves the EE_Venue from the available data object. |
|
| 178 | + * |
|
| 179 | + * @return EE_Venue|null |
|
| 180 | + * @throws EE_Error |
|
| 181 | + * @throws EntityNotFoundException |
|
| 182 | + */ |
|
| 183 | + private function _get_venue() |
|
| 184 | + { |
|
| 185 | + |
|
| 186 | + //we need the EE_Event object to get the venue. |
|
| 187 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
| 188 | + |
|
| 189 | + //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
| 190 | + // reg_obj instead. |
|
| 191 | + if (! $this->_event instanceof EE_Event) { |
|
| 192 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
| 193 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
| 194 | + |
|
| 195 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
| 196 | + ? $aee->reg_obj->event() |
|
| 197 | + : null; |
|
| 198 | + |
|
| 199 | + //if still empty do we have a ticket data item? |
|
| 200 | + $this->_event = ! $this->_event instanceof EE_Event |
|
| 201 | + && $this->_data instanceof EE_Ticket |
|
| 202 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
| 203 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
| 204 | + : $this->_event; |
|
| 205 | + |
|
| 206 | + //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
| 207 | + // and use that. |
|
| 208 | + $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
| 209 | + ? reset($aee->events) |
|
| 210 | + : $this->_event; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + //If we have an event object use it to pull the venue. |
|
| 214 | + if ($this->_event instanceof EE_Event) { |
|
| 215 | + return $this->_event->get_first_related('Venue'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + return null; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * This retrieves the specified venue information |
|
| 223 | + * |
|
| 224 | + * @param string $field What Venue field to retrieve |
|
| 225 | + * @return string What was retrieved! |
|
| 226 | + * @throws EE_Error |
|
| 227 | + * @throws EntityNotFoundException |
|
| 228 | + */ |
|
| 229 | + private function _venue($field) |
|
| 230 | + { |
|
| 231 | + |
|
| 232 | + if (! $this->_venue instanceof EE_Venue) { |
|
| 233 | + return ''; |
|
| 234 | + } //no venue so get out. |
|
| 235 | + |
|
| 236 | + switch ($field) { |
|
| 237 | + case 'title': |
|
| 238 | + return $this->_venue->get('VNU_name'); |
|
| 239 | + break; |
|
| 240 | + |
|
| 241 | + case 'description': |
|
| 242 | + return $this->_venue->get('VNU_desc'); |
|
| 243 | + break; |
|
| 244 | + |
|
| 245 | + case 'url': |
|
| 246 | + $url = $this->_venue->get('VNU_url'); |
|
| 247 | + return empty($url) ? $this->_venue->get_permalink() : $url; |
|
| 248 | + break; |
|
| 249 | + |
|
| 250 | + case 'permalink': |
|
| 251 | + return $this->_venue->get_permalink(); |
|
| 252 | + break; |
|
| 253 | + |
|
| 254 | + case 'image': |
|
| 255 | + return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
| 256 | + . '" alt="' . sprintf( |
|
| 257 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
| 258 | + $this->_venue->get('VNU_name') |
|
| 259 | + ) . '" />'; |
|
| 260 | + break; |
|
| 261 | + |
|
| 262 | + case 'phone': |
|
| 263 | + return $this->_venue->get('VNU_phone'); |
|
| 264 | + break; |
|
| 265 | + |
|
| 266 | + case 'address': |
|
| 267 | + return $this->_venue->get('VNU_address'); |
|
| 268 | + break; |
|
| 269 | + |
|
| 270 | + case 'address2': |
|
| 271 | + return $this->_venue->get('VNU_address2'); |
|
| 272 | + break; |
|
| 273 | + |
|
| 274 | + case 'city': |
|
| 275 | + return $this->_venue->get('VNU_city'); |
|
| 276 | + break; |
|
| 277 | + |
|
| 278 | + case 'state': |
|
| 279 | + $state = $this->_venue->state_obj(); |
|
| 280 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
| 281 | + break; |
|
| 282 | + |
|
| 283 | + case 'country': |
|
| 284 | + $country = $this->_venue->country_obj(); |
|
| 285 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
| 286 | + break; |
|
| 287 | + |
|
| 288 | + case 'zip': |
|
| 289 | + return $this->_venue->get('VNU_zip'); |
|
| 290 | + break; |
|
| 291 | + |
|
| 292 | + case 'formatted_address': |
|
| 293 | + return EEH_Address::format($this->_venue); |
|
| 294 | + break; |
|
| 295 | + |
|
| 296 | + case 'gmap_link': |
|
| 297 | + case 'gmap_url': |
|
| 298 | + case 'gmap_link_img': |
|
| 299 | + $atts = $this->get_map_attributes($this->_venue, $field); |
|
| 300 | + return EEH_Maps::google_map_link($atts); |
|
| 301 | + break; |
|
| 302 | + } |
|
| 303 | + return ''; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Generates the attributes for retrieving a google_map artifact. |
|
| 309 | + * |
|
| 310 | + * @param EE_Venue $venue |
|
| 311 | + * @param string $field |
|
| 312 | + * @return array |
|
| 313 | + * @throws EE_Error |
|
| 314 | + */ |
|
| 315 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
| 316 | + { |
|
| 317 | + $state = $venue->state_obj(); |
|
| 318 | + $country = $venue->country_obj(); |
|
| 319 | + $atts = array( |
|
| 320 | + 'id' => $venue->ID(), |
|
| 321 | + 'address' => $venue->get('VNU_address'), |
|
| 322 | + 'city' => $venue->get('VNU_city'), |
|
| 323 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
| 324 | + 'zip' => $venue->get('VNU_zip'), |
|
| 325 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
| 326 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
| 327 | + 'map_w' => 200, |
|
| 328 | + 'map_h' => 200, |
|
| 329 | + ); |
|
| 330 | + if ($field === 'gmap_url') { |
|
| 331 | + $atts['type'] = 'url_only'; |
|
| 332 | + } |
|
| 333 | + return $atts; |
|
| 334 | + } |
|
| 335 | 335 | } |
@@ -17,362 +17,362 @@ |
||
| 17 | 17 | class EE_Maintenance_Mode implements ResettableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
| 22 | - * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
| 23 | - */ |
|
| 24 | - const level_0_not_in_maintenance = 0; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
| 28 | - * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
| 29 | - */ |
|
| 30 | - const level_1_frontend_only_maintenance = 1; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
| 34 | - * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
| 35 | - * migration scripts before taking the site out of maintenance mode |
|
| 36 | - */ |
|
| 37 | - const level_2_complete_maintenance = 2; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * the name of the option which stores the current level of maintenance mode |
|
| 41 | - */ |
|
| 42 | - const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var EE_Maintenance_Mode $_instance |
|
| 47 | - */ |
|
| 48 | - private static $_instance; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var EE_Registry $EE |
|
| 52 | - */ |
|
| 53 | - protected $EE; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @singleton method used to instantiate class object |
|
| 59 | - * @return EE_Maintenance_Mode |
|
| 60 | - */ |
|
| 61 | - public static function instance() |
|
| 62 | - { |
|
| 63 | - // check if class object is instantiated |
|
| 64 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
| 65 | - self::$_instance = new self(); |
|
| 66 | - } |
|
| 67 | - return self::$_instance; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
| 74 | - * |
|
| 75 | - * @return EE_Maintenance_Mode |
|
| 76 | - */ |
|
| 77 | - public static function reset() |
|
| 78 | - { |
|
| 79 | - self::instance()->set_maintenance_mode_if_db_old(); |
|
| 80 | - return self::instance(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - *private constructor to prevent direct creation |
|
| 87 | - */ |
|
| 88 | - private function __construct() |
|
| 89 | - { |
|
| 90 | - // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
| 91 | - add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
| 92 | - // shut 'er down down for maintenance ? |
|
| 93 | - add_filter('the_content', array($this, 'the_content'), 2); |
|
| 94 | - // add powered by EE msg |
|
| 95 | - add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * retrieves the maintenance mode option value from the db |
|
| 102 | - * |
|
| 103 | - * @return int |
|
| 104 | - */ |
|
| 105 | - public function real_level() |
|
| 106 | - { |
|
| 107 | - return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Returns whether or not the models reportedly are able to run queries or not |
|
| 114 | - * (ie, if the system thinks their tables are present and up-to-date). |
|
| 115 | - * |
|
| 116 | - * @return boolean |
|
| 117 | - */ |
|
| 118 | - public function models_can_query() |
|
| 119 | - { |
|
| 120 | - return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
| 127 | - * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
| 128 | - * to them as if teh site isn't in maintenance mode. |
|
| 129 | - * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
| 130 | - * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
| 131 | - * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
| 132 | - * |
|
| 133 | - * @return int |
|
| 134 | - */ |
|
| 135 | - public function level() |
|
| 136 | - { |
|
| 137 | - $maintenance_mode_level = $this->real_level(); |
|
| 138 | - // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
| 139 | - if ( |
|
| 140 | - $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
| 141 | - && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
| 142 | - && current_user_can('administrator') // when the user is an admin |
|
| 143 | - ) { |
|
| 144 | - $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
| 145 | - } |
|
| 146 | - return $maintenance_mode_level; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Determines if we need to put EE in maintenance mode because the database needs updating |
|
| 153 | - * |
|
| 154 | - * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
| 155 | - */ |
|
| 156 | - public function set_maintenance_mode_if_db_old() |
|
| 157 | - { |
|
| 158 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 159 | - if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
| 160 | - update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
| 161 | - return true; |
|
| 162 | - } |
|
| 163 | - if ($this->level() === self::level_2_complete_maintenance) { |
|
| 164 | - //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
| 165 | - //then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
| 166 | - update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
| 167 | - return false; |
|
| 168 | - } |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Updates the maintenance level on the site |
|
| 176 | - * |
|
| 177 | - * @param int $level |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function set_maintenance_level($level) |
|
| 181 | - { |
|
| 182 | - do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
| 183 | - update_option(self::option_name_maintenance_mode, (int)$level); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
| 190 | - * |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public static function disable_frontend_for_maintenance() |
|
| 194 | - { |
|
| 195 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @return void |
|
| 202 | - */ |
|
| 203 | - public function load_assets_required_for_m_mode() |
|
| 204 | - { |
|
| 205 | - if ( |
|
| 206 | - $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 207 | - && ! wp_script_is('espresso_core') |
|
| 208 | - ) { |
|
| 209 | - wp_register_style( |
|
| 210 | - 'espresso_default', |
|
| 211 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 212 | - array('dashicons'), |
|
| 213 | - EVENT_ESPRESSO_VERSION |
|
| 214 | - ); |
|
| 215 | - wp_enqueue_style('espresso_default'); |
|
| 216 | - wp_register_script( |
|
| 217 | - 'espresso_core', |
|
| 218 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 219 | - array('jquery'), |
|
| 220 | - EVENT_ESPRESSO_VERSION, |
|
| 221 | - true |
|
| 222 | - ); |
|
| 223 | - wp_enqueue_script('espresso_core'); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * replacement EE CPT template that displays message notifying site visitors |
|
| 231 | - * that EE has been temporarily placed into maintenance mode |
|
| 232 | - * does NOT get called on non-EE-CPT requests |
|
| 233 | - * |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - public static function template_include() |
|
| 237 | - { |
|
| 238 | - // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
| 239 | - return get_template_directory() . '/index.php'; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * displays message notifying site visitors that EE has been temporarily |
|
| 246 | - * placed into maintenance mode when post_type != EE CPT |
|
| 247 | - * |
|
| 248 | - * @param string $the_content |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function the_content($the_content) |
|
| 252 | - { |
|
| 253 | - // check if M-mode is engaged and for EE shortcode |
|
| 254 | - if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
| 255 | - // this can eventually be moved to a template, or edited via admin. But for now... |
|
| 256 | - $the_content = sprintf( |
|
| 257 | - esc_html__( |
|
| 258 | - '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
| 259 | - 'event_espresso' |
|
| 260 | - ), |
|
| 261 | - '<h3>', |
|
| 262 | - '</h3><p>', |
|
| 263 | - '</p>' |
|
| 264 | - ); |
|
| 265 | - } |
|
| 266 | - return $the_content; |
|
| 267 | - } |
|
| 20 | + /** |
|
| 21 | + * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
| 22 | + * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
| 23 | + */ |
|
| 24 | + const level_0_not_in_maintenance = 0; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
| 28 | + * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
| 29 | + */ |
|
| 30 | + const level_1_frontend_only_maintenance = 1; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
| 34 | + * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
| 35 | + * migration scripts before taking the site out of maintenance mode |
|
| 36 | + */ |
|
| 37 | + const level_2_complete_maintenance = 2; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * the name of the option which stores the current level of maintenance mode |
|
| 41 | + */ |
|
| 42 | + const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var EE_Maintenance_Mode $_instance |
|
| 47 | + */ |
|
| 48 | + private static $_instance; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var EE_Registry $EE |
|
| 52 | + */ |
|
| 53 | + protected $EE; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @singleton method used to instantiate class object |
|
| 59 | + * @return EE_Maintenance_Mode |
|
| 60 | + */ |
|
| 61 | + public static function instance() |
|
| 62 | + { |
|
| 63 | + // check if class object is instantiated |
|
| 64 | + if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
| 65 | + self::$_instance = new self(); |
|
| 66 | + } |
|
| 67 | + return self::$_instance; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
| 74 | + * |
|
| 75 | + * @return EE_Maintenance_Mode |
|
| 76 | + */ |
|
| 77 | + public static function reset() |
|
| 78 | + { |
|
| 79 | + self::instance()->set_maintenance_mode_if_db_old(); |
|
| 80 | + return self::instance(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + *private constructor to prevent direct creation |
|
| 87 | + */ |
|
| 88 | + private function __construct() |
|
| 89 | + { |
|
| 90 | + // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
| 91 | + add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
| 92 | + // shut 'er down down for maintenance ? |
|
| 93 | + add_filter('the_content', array($this, 'the_content'), 2); |
|
| 94 | + // add powered by EE msg |
|
| 95 | + add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * retrieves the maintenance mode option value from the db |
|
| 102 | + * |
|
| 103 | + * @return int |
|
| 104 | + */ |
|
| 105 | + public function real_level() |
|
| 106 | + { |
|
| 107 | + return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Returns whether or not the models reportedly are able to run queries or not |
|
| 114 | + * (ie, if the system thinks their tables are present and up-to-date). |
|
| 115 | + * |
|
| 116 | + * @return boolean |
|
| 117 | + */ |
|
| 118 | + public function models_can_query() |
|
| 119 | + { |
|
| 120 | + return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
| 127 | + * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
| 128 | + * to them as if teh site isn't in maintenance mode. |
|
| 129 | + * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
| 130 | + * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
| 131 | + * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
| 132 | + * |
|
| 133 | + * @return int |
|
| 134 | + */ |
|
| 135 | + public function level() |
|
| 136 | + { |
|
| 137 | + $maintenance_mode_level = $this->real_level(); |
|
| 138 | + // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
| 139 | + if ( |
|
| 140 | + $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
| 141 | + && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
| 142 | + && current_user_can('administrator') // when the user is an admin |
|
| 143 | + ) { |
|
| 144 | + $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
| 145 | + } |
|
| 146 | + return $maintenance_mode_level; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Determines if we need to put EE in maintenance mode because the database needs updating |
|
| 153 | + * |
|
| 154 | + * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
| 155 | + */ |
|
| 156 | + public function set_maintenance_mode_if_db_old() |
|
| 157 | + { |
|
| 158 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 159 | + if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
| 160 | + update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
| 161 | + return true; |
|
| 162 | + } |
|
| 163 | + if ($this->level() === self::level_2_complete_maintenance) { |
|
| 164 | + //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
| 165 | + //then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
| 166 | + update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Updates the maintenance level on the site |
|
| 176 | + * |
|
| 177 | + * @param int $level |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function set_maintenance_level($level) |
|
| 181 | + { |
|
| 182 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
| 183 | + update_option(self::option_name_maintenance_mode, (int)$level); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
| 190 | + * |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public static function disable_frontend_for_maintenance() |
|
| 194 | + { |
|
| 195 | + return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @return void |
|
| 202 | + */ |
|
| 203 | + public function load_assets_required_for_m_mode() |
|
| 204 | + { |
|
| 205 | + if ( |
|
| 206 | + $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 207 | + && ! wp_script_is('espresso_core') |
|
| 208 | + ) { |
|
| 209 | + wp_register_style( |
|
| 210 | + 'espresso_default', |
|
| 211 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 212 | + array('dashicons'), |
|
| 213 | + EVENT_ESPRESSO_VERSION |
|
| 214 | + ); |
|
| 215 | + wp_enqueue_style('espresso_default'); |
|
| 216 | + wp_register_script( |
|
| 217 | + 'espresso_core', |
|
| 218 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 219 | + array('jquery'), |
|
| 220 | + EVENT_ESPRESSO_VERSION, |
|
| 221 | + true |
|
| 222 | + ); |
|
| 223 | + wp_enqueue_script('espresso_core'); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * replacement EE CPT template that displays message notifying site visitors |
|
| 231 | + * that EE has been temporarily placed into maintenance mode |
|
| 232 | + * does NOT get called on non-EE-CPT requests |
|
| 233 | + * |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + public static function template_include() |
|
| 237 | + { |
|
| 238 | + // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
| 239 | + return get_template_directory() . '/index.php'; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * displays message notifying site visitors that EE has been temporarily |
|
| 246 | + * placed into maintenance mode when post_type != EE CPT |
|
| 247 | + * |
|
| 248 | + * @param string $the_content |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function the_content($the_content) |
|
| 252 | + { |
|
| 253 | + // check if M-mode is engaged and for EE shortcode |
|
| 254 | + if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
| 255 | + // this can eventually be moved to a template, or edited via admin. But for now... |
|
| 256 | + $the_content = sprintf( |
|
| 257 | + esc_html__( |
|
| 258 | + '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
| 259 | + 'event_espresso' |
|
| 260 | + ), |
|
| 261 | + '<h3>', |
|
| 262 | + '</h3><p>', |
|
| 263 | + '</p>' |
|
| 264 | + ); |
|
| 265 | + } |
|
| 266 | + return $the_content; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | 269 | |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
| 273 | - */ |
|
| 274 | - public function display_maintenance_mode_notice() |
|
| 275 | - { |
|
| 276 | - // check if M-mode is engaged and for EE shortcode |
|
| 277 | - if ( |
|
| 278 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 279 | - && $this->real_level() |
|
| 280 | - && ! is_admin() |
|
| 281 | - && current_user_can('administrator') |
|
| 282 | - && EE_Registry::instance()->REQ->is_espresso_page() |
|
| 283 | - ) { |
|
| 284 | - printf( |
|
| 285 | - esc_html__( |
|
| 286 | - '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
| 287 | - 'event_espresso' |
|
| 288 | - ), |
|
| 289 | - '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
| 290 | - '"><span class="dashicons dashicons-no"></span></a><p>', |
|
| 291 | - ' » <a href="' . add_query_arg( |
|
| 292 | - array('page' => 'espresso_maintenance_settings'), admin_url('admin.php') |
|
| 293 | - ) . '">', |
|
| 294 | - '</a></p></div>' |
|
| 295 | - ); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - // espresso-notices important-notice ee-attention |
|
| 271 | + /** |
|
| 272 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
| 273 | + */ |
|
| 274 | + public function display_maintenance_mode_notice() |
|
| 275 | + { |
|
| 276 | + // check if M-mode is engaged and for EE shortcode |
|
| 277 | + if ( |
|
| 278 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 279 | + && $this->real_level() |
|
| 280 | + && ! is_admin() |
|
| 281 | + && current_user_can('administrator') |
|
| 282 | + && EE_Registry::instance()->REQ->is_espresso_page() |
|
| 283 | + ) { |
|
| 284 | + printf( |
|
| 285 | + esc_html__( |
|
| 286 | + '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
| 287 | + 'event_espresso' |
|
| 288 | + ), |
|
| 289 | + '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
| 290 | + '"><span class="dashicons dashicons-no"></span></a><p>', |
|
| 291 | + ' » <a href="' . add_query_arg( |
|
| 292 | + array('page' => 'espresso_maintenance_settings'), admin_url('admin.php') |
|
| 293 | + ) . '">', |
|
| 294 | + '</a></p></div>' |
|
| 295 | + ); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + // espresso-notices important-notice ee-attention |
|
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * override magic methods |
|
| 304 | - */ |
|
| 305 | - final public function __destruct() |
|
| 306 | - { |
|
| 307 | - } |
|
| 302 | + /** |
|
| 303 | + * override magic methods |
|
| 304 | + */ |
|
| 305 | + final public function __destruct() |
|
| 306 | + { |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | |
| 310 | 310 | |
| 311 | - final public function __call($a, $b) |
|
| 312 | - { |
|
| 313 | - } |
|
| 311 | + final public function __call($a, $b) |
|
| 312 | + { |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | |
| 316 | 316 | |
| 317 | - final public function __get($a) |
|
| 318 | - { |
|
| 319 | - } |
|
| 317 | + final public function __get($a) |
|
| 318 | + { |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | 321 | |
| 322 | 322 | |
| 323 | - final public function __set($a, $b) |
|
| 324 | - { |
|
| 325 | - } |
|
| 323 | + final public function __set($a, $b) |
|
| 324 | + { |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | 327 | |
| 328 | 328 | |
| 329 | - final public function __isset($a) |
|
| 330 | - { |
|
| 331 | - } |
|
| 329 | + final public function __isset($a) |
|
| 330 | + { |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | 333 | |
| 334 | 334 | |
| 335 | - final public function __unset($a) |
|
| 336 | - { |
|
| 337 | - } |
|
| 335 | + final public function __unset($a) |
|
| 336 | + { |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | 339 | |
| 340 | 340 | |
| 341 | - final public function __sleep() |
|
| 342 | - { |
|
| 343 | - return array(); |
|
| 344 | - } |
|
| 341 | + final public function __sleep() |
|
| 342 | + { |
|
| 343 | + return array(); |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | 346 | |
| 347 | 347 | |
| 348 | - final public function __wakeup() |
|
| 349 | - { |
|
| 350 | - } |
|
| 348 | + final public function __wakeup() |
|
| 349 | + { |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | 352 | |
| 353 | 353 | |
| 354 | - final public function __invoke() |
|
| 355 | - { |
|
| 356 | - } |
|
| 354 | + final public function __invoke() |
|
| 355 | + { |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | 358 | |
| 359 | 359 | |
| 360 | - final public static function __set_state($a = null) |
|
| 361 | - { |
|
| 362 | - return EE_Maintenance_Mode::instance(); |
|
| 363 | - } |
|
| 360 | + final public static function __set_state($a = null) |
|
| 361 | + { |
|
| 362 | + return EE_Maintenance_Mode::instance(); |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | 366 | |
| 367 | - final public function __clone() |
|
| 368 | - { |
|
| 369 | - } |
|
| 367 | + final public function __clone() |
|
| 368 | + { |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | 371 | |
| 372 | 372 | |
| 373 | - final public static function __callStatic($a, $b) |
|
| 374 | - { |
|
| 375 | - } |
|
| 373 | + final public static function __callStatic($a, $b) |
|
| 374 | + { |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | 377 | } |
| 378 | 378 | // End of file EE_Maintenance_Mode.core.php |
@@ -698,7 +698,7 @@ |
||
| 698 | 698 | |
| 699 | 699 | /** |
| 700 | 700 | * @param EE_State[] $state_options |
| 701 | - * @return array |
|
| 701 | + * @return EE_State[] |
|
| 702 | 702 | * @throws EE_Error |
| 703 | 703 | * @throws InvalidArgumentException |
| 704 | 704 | * @throws InvalidDataTypeException |
@@ -19,730 +19,730 @@ |
||
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @return EED_Module|EED_Add_New_State |
|
| 24 | - */ |
|
| 25 | - public static function instance() |
|
| 26 | - { |
|
| 27 | - return parent::get_instance(__CLASS__); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 34 | - * |
|
| 35 | - * @return void |
|
| 36 | - */ |
|
| 37 | - public static function set_hooks() |
|
| 38 | - { |
|
| 39 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 40 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 41 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 42 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 43 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 44 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 45 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 46 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 47 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 48 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 49 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 50 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 51 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 52 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 53 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 54 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 55 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 62 | - * |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public static function set_hooks_admin() |
|
| 66 | - { |
|
| 67 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 68 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 69 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 70 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 71 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 72 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 73 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 74 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 75 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 76 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 77 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 78 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 79 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 80 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 81 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 82 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 83 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 84 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 85 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 86 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 87 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 88 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 89 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - public static function set_definitions() |
|
| 98 | - { |
|
| 99 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 100 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
| 101 | - '\\', |
|
| 102 | - DS, |
|
| 103 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param WP $WP |
|
| 111 | - * @return void |
|
| 112 | - */ |
|
| 113 | - public function run($WP) |
|
| 114 | - { |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - public static function translate_js_strings() |
|
| 123 | - { |
|
| 124 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 125 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 126 | - 'event_espresso' |
|
| 127 | - ); |
|
| 128 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 129 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 130 | - 'event_espresso' |
|
| 131 | - ); |
|
| 132 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 133 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 134 | - 'event_espresso' |
|
| 135 | - ); |
|
| 136 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 137 | - 'The new state was successfully saved to the database.', |
|
| 138 | - 'event_espresso' |
|
| 139 | - ); |
|
| 140 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 141 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 142 | - 'event_espresso' |
|
| 143 | - ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public static function wp_enqueue_scripts() |
|
| 152 | - { |
|
| 153 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 154 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 155 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 156 | - wp_enqueue_script('add_new_state'); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * display_add_new_state_micro_form |
|
| 164 | - * |
|
| 165 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 166 | - * @return string |
|
| 167 | - * @throws EE_Error |
|
| 168 | - * @throws InvalidArgumentException |
|
| 169 | - * @throws InvalidDataTypeException |
|
| 170 | - * @throws InvalidInterfaceException |
|
| 171 | - */ |
|
| 172 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 173 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 174 | - { |
|
| 175 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 176 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 177 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 178 | - // is the "state" question in this form section? |
|
| 179 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 180 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 181 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 182 | - //by forcing it to set it now, like it did while getting the form for display |
|
| 183 | - if ($input instanceof EE_State_Select_Input) { |
|
| 184 | - $input->html_name(); |
|
| 185 | - } |
|
| 186 | - return $question_group_reg_form; |
|
| 187 | - } |
|
| 188 | - // we're only doing this for state select inputs |
|
| 189 | - if ($input instanceof EE_State_Select_Input) { |
|
| 190 | - // grab any set values from the request |
|
| 191 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 192 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 193 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 194 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 195 | - $country_options = array(); |
|
| 196 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 197 | - if (! empty($countries)) { |
|
| 198 | - foreach ($countries as $country) { |
|
| 199 | - if ($country instanceof EE_Country) { |
|
| 200 | - $country_options[$country->ID()] = $country->name(); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 205 | - array( |
|
| 206 | - 'name' => 'new_state_micro_form', |
|
| 207 | - 'html_id' => 'new_state_micro_form', |
|
| 208 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 209 | - 'subsections' => array( |
|
| 210 | - // add hidden input to indicate that a new state is being added |
|
| 211 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 212 | - array( |
|
| 213 | - 'html_name' => str_replace( |
|
| 214 | - 'state', |
|
| 215 | - 'nsmf_add_new_state', |
|
| 216 | - $input->html_name() |
|
| 217 | - ), |
|
| 218 | - 'html_id' => str_replace( |
|
| 219 | - 'state', |
|
| 220 | - 'nsmf_add_new_state', |
|
| 221 | - $input->html_id() |
|
| 222 | - ), |
|
| 223 | - 'default' => 0, |
|
| 224 | - ) |
|
| 225 | - ), |
|
| 226 | - // add link for displaying hidden container |
|
| 227 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 228 | - apply_filters( |
|
| 229 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 230 | - EEH_HTML::link( |
|
| 231 | - '', |
|
| 232 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 233 | - '', |
|
| 234 | - 'display-' . $input->html_id(), |
|
| 235 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 236 | - '', |
|
| 237 | - 'data-target="' . $input->html_id() . '"' |
|
| 238 | - ) |
|
| 239 | - ) |
|
| 240 | - ), |
|
| 241 | - // add initial html for hidden container |
|
| 242 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 243 | - apply_filters( |
|
| 244 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 245 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 246 | - 'display: none;') . |
|
| 247 | - EEH_HTML::h6( |
|
| 248 | - esc_html__( |
|
| 249 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 250 | - 'event_espresso' |
|
| 251 | - ) |
|
| 252 | - ) . |
|
| 253 | - EEH_HTML::ul() . |
|
| 254 | - EEH_HTML::li( |
|
| 255 | - esc_html__( |
|
| 256 | - 'first select the Country that your State/Province belongs to', |
|
| 257 | - 'event_espresso' |
|
| 258 | - ) |
|
| 259 | - ) . |
|
| 260 | - EEH_HTML::li( |
|
| 261 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 262 | - ) . |
|
| 263 | - EEH_HTML::li( |
|
| 264 | - esc_html__( |
|
| 265 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 266 | - 'event_espresso' |
|
| 267 | - ) |
|
| 268 | - ) . |
|
| 269 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 270 | - EEH_HTML::ulx() |
|
| 271 | - ) |
|
| 272 | - ), |
|
| 273 | - // NEW STATE COUNTRY |
|
| 274 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 275 | - $country_options, |
|
| 276 | - array( |
|
| 277 | - 'html_name' => $country_name, |
|
| 278 | - 'html_id' => str_replace( |
|
| 279 | - 'state', |
|
| 280 | - 'nsmf_new_state_country', $input->html_id() |
|
| 281 | - ), |
|
| 282 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 283 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 284 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 285 | - 'required' => false, |
|
| 286 | - ) |
|
| 287 | - ), |
|
| 288 | - // NEW STATE NAME |
|
| 289 | - 'new_state_name' => new EE_Text_Input( |
|
| 290 | - array( |
|
| 291 | - 'html_name' => $state_name, |
|
| 292 | - 'html_id' => str_replace( |
|
| 293 | - 'state', |
|
| 294 | - 'nsmf_new_state_name', $input->html_id() |
|
| 295 | - ), |
|
| 296 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 297 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
| 298 | - 'event_espresso'), |
|
| 299 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 300 | - 'required' => false, |
|
| 301 | - ) |
|
| 302 | - ), |
|
| 303 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 304 | - // NEW STATE NAME |
|
| 305 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 306 | - array( |
|
| 307 | - 'html_name' => $abbrv_name, |
|
| 308 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 309 | - $input->html_id()), |
|
| 310 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 311 | - 'html_label_text' => esc_html__( |
|
| 312 | - 'New State/Province Abbreviation', |
|
| 313 | - 'event_espresso' |
|
| 314 | - ) . ' *', |
|
| 315 | - 'html_other_attributes' => 'size="24"', |
|
| 316 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 317 | - 'required' => false, |
|
| 318 | - ) |
|
| 319 | - ), |
|
| 320 | - // "submit" button |
|
| 321 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 322 | - apply_filters( |
|
| 323 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 324 | - EEH_HTML::nbsp(3) . |
|
| 325 | - EEH_HTML::link( |
|
| 326 | - '', |
|
| 327 | - esc_html__('ADD', 'event_espresso'), |
|
| 328 | - '', |
|
| 329 | - 'submit-' . $new_state_submit_id, |
|
| 330 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 331 | - '', |
|
| 332 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 333 | - ) |
|
| 334 | - ) |
|
| 335 | - ), |
|
| 336 | - // extra info |
|
| 337 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 338 | - apply_filters( |
|
| 339 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 340 | - EEH_HTML::br(2) |
|
| 341 | - . |
|
| 342 | - EEH_HTML::div('', '', 'small-text') |
|
| 343 | - . |
|
| 344 | - EEH_HTML::strong( |
|
| 345 | - '* ' . |
|
| 346 | - esc_html__( |
|
| 347 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 348 | - 'event_espresso' |
|
| 349 | - ) |
|
| 350 | - ) |
|
| 351 | - . |
|
| 352 | - EEH_HTML::br() |
|
| 353 | - . |
|
| 354 | - sprintf( |
|
| 355 | - esc_html__( |
|
| 356 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 357 | - 'event_espresso' |
|
| 358 | - ), |
|
| 359 | - EEH_HTML::link( |
|
| 360 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 361 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 362 | - '', |
|
| 363 | - '', |
|
| 364 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 365 | - '', |
|
| 366 | - 'target="_blank"' |
|
| 367 | - ) |
|
| 368 | - ) |
|
| 369 | - . |
|
| 370 | - EEH_HTML::divx() |
|
| 371 | - . |
|
| 372 | - EEH_HTML::br() |
|
| 373 | - . |
|
| 374 | - EEH_HTML::link( |
|
| 375 | - '', |
|
| 376 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 377 | - '', |
|
| 378 | - 'hide-' . $input->html_id(), |
|
| 379 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 380 | - '', |
|
| 381 | - 'data-target="' . $input->html_id() . '"' |
|
| 382 | - ) |
|
| 383 | - . |
|
| 384 | - EEH_HTML::divx() |
|
| 385 | - . |
|
| 386 | - EEH_HTML::br() |
|
| 387 | - ) |
|
| 388 | - ), |
|
| 389 | - ), |
|
| 390 | - ) |
|
| 391 | - ); |
|
| 392 | - $question_group_reg_form->add_subsections( |
|
| 393 | - array('new_state_micro_form' => $new_state_micro_form), |
|
| 394 | - 'state', |
|
| 395 | - false |
|
| 396 | - ); |
|
| 397 | - } |
|
| 398 | - return $question_group_reg_form; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * set_new_state_input_width |
|
| 405 | - * |
|
| 406 | - * @return int|string |
|
| 407 | - * @throws EE_Error |
|
| 408 | - * @throws InvalidArgumentException |
|
| 409 | - * @throws InvalidDataTypeException |
|
| 410 | - * @throws InvalidInterfaceException |
|
| 411 | - * @throws ReflectionException |
|
| 412 | - */ |
|
| 413 | - public static function add_new_state() |
|
| 414 | - { |
|
| 415 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 416 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 417 | - EE_Registry::instance()->load_model('State'); |
|
| 418 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 419 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 420 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 421 | - : false; |
|
| 422 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 424 | - : false; |
|
| 425 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 427 | - : false; |
|
| 428 | - if ($state_country && $state_name && $state_abbr) { |
|
| 429 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 430 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 431 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 432 | - 'STA_name' => ucwords($state_name), |
|
| 433 | - 'STA_active' => false, |
|
| 434 | - )); |
|
| 435 | - if ($new_state instanceof EE_State) { |
|
| 436 | - // clean house |
|
| 437 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 438 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 439 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 440 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 441 | - // get any existing new states |
|
| 442 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 443 | - 'nsmf_new_states' |
|
| 444 | - ); |
|
| 445 | - $new_states[$new_state->ID()] = $new_state; |
|
| 446 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 447 | - array('nsmf_new_states' => $new_states) |
|
| 448 | - ); |
|
| 449 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 450 | - echo wp_json_encode(array( |
|
| 451 | - 'success' => true, |
|
| 452 | - 'id' => $new_state->ID(), |
|
| 453 | - 'name' => $new_state->name(), |
|
| 454 | - 'abbrev' => $new_state->abbrev(), |
|
| 455 | - 'country_iso' => $new_state->country_iso(), |
|
| 456 | - 'country_name' => $new_state->country()->name(), |
|
| 457 | - )); |
|
| 458 | - exit(); |
|
| 459 | - } |
|
| 460 | - return $new_state->ID(); |
|
| 461 | - } |
|
| 462 | - } else { |
|
| 463 | - $error = esc_html__( |
|
| 464 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 465 | - 'event_espresso' |
|
| 466 | - ); |
|
| 467 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 468 | - echo wp_json_encode(array('error' => $error)); |
|
| 469 | - exit(); |
|
| 470 | - } |
|
| 471 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - return false; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * recursively drills down through request params to remove any that were added by this module |
|
| 481 | - * |
|
| 482 | - * @param array $request_params |
|
| 483 | - * @return array |
|
| 484 | - */ |
|
| 485 | - public static function filter_checkout_request_params($request_params) |
|
| 486 | - { |
|
| 487 | - foreach ($request_params as $form_section) { |
|
| 488 | - if (is_array($form_section)) { |
|
| 489 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 490 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - return $request_params; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * @param array $request_params |
|
| 500 | - * @return array |
|
| 501 | - */ |
|
| 502 | - public static function unset_new_state_request_params($request_params) |
|
| 503 | - { |
|
| 504 | - unset( |
|
| 505 | - $request_params['new_state_micro_form'], |
|
| 506 | - $request_params['new_state_micro_add_new_state'], |
|
| 507 | - $request_params['new_state_micro_new_state_country'], |
|
| 508 | - $request_params['new_state_micro_new_state_name'], |
|
| 509 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 510 | - ); |
|
| 511 | - return $request_params; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * @param array $props_n_values |
|
| 518 | - * @return bool |
|
| 519 | - * @throws EE_Error |
|
| 520 | - * @throws InvalidArgumentException |
|
| 521 | - * @throws InvalidDataTypeException |
|
| 522 | - * @throws InvalidInterfaceException |
|
| 523 | - */ |
|
| 524 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 525 | - { |
|
| 526 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 527 | - if (! empty($existing_state)) { |
|
| 528 | - return array_pop($existing_state); |
|
| 529 | - } |
|
| 530 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 531 | - if ($new_state instanceof EE_State) { |
|
| 532 | - // if not non-ajax admin |
|
| 533 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 534 | - $new_state_notice = sprintf( |
|
| 535 | - esc_html__( |
|
| 536 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 537 | - 'event_espresso' |
|
| 538 | - ), |
|
| 539 | - '<b>' . $new_state->name() . '</b>', |
|
| 540 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 541 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 542 | - '<a href="' . add_query_arg(array( |
|
| 543 | - 'page' => 'espresso_general_settings', |
|
| 544 | - 'action' => 'country_settings', |
|
| 545 | - 'country' => $new_state->country_iso(), |
|
| 546 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 547 | - 'event_espresso') . '</a>', |
|
| 548 | - '<br />' |
|
| 549 | - ); |
|
| 550 | - EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
| 551 | - $new_state->save(); |
|
| 552 | - EEM_State::instance()->reset_cached_states(); |
|
| 553 | - return $new_state; |
|
| 554 | - } |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * @param string $CNT_ISO |
|
| 562 | - * @param string $STA_ID |
|
| 563 | - * @param array $cols_n_values |
|
| 564 | - * @return void |
|
| 565 | - * @throws EE_Error |
|
| 566 | - * @throws InvalidArgumentException |
|
| 567 | - * @throws InvalidDataTypeException |
|
| 568 | - * @throws InvalidInterfaceException |
|
| 569 | - */ |
|
| 570 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 571 | - { |
|
| 572 | - if (! $CNT_ISO) { |
|
| 573 | - EE_Error::add_error( |
|
| 574 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 575 | - __FILE__, |
|
| 576 | - __FUNCTION__, |
|
| 577 | - __LINE__ |
|
| 578 | - ); |
|
| 579 | - } |
|
| 580 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 581 | - : false; |
|
| 582 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 583 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 584 | - if ($state instanceof EE_State) { |
|
| 585 | - $STA_abbrev = $state->abbrev(); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - if (! $STA_abbrev) { |
|
| 589 | - EE_Error::add_error( |
|
| 590 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 591 | - __FILE__, |
|
| 592 | - __FUNCTION__, |
|
| 593 | - __LINE__ |
|
| 594 | - ); |
|
| 595 | - } |
|
| 596 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * @param EE_State[] $state_options |
|
| 603 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 604 | - * @param EE_Registration $registration |
|
| 605 | - * @param EE_Question $question |
|
| 606 | - * @param $answer |
|
| 607 | - * @return array |
|
| 608 | - * @throws EE_Error |
|
| 609 | - * @throws InvalidArgumentException |
|
| 610 | - * @throws InvalidDataTypeException |
|
| 611 | - * @throws InvalidInterfaceException |
|
| 612 | - */ |
|
| 613 | - public static function inject_new_reg_state_into_options( |
|
| 614 | - $state_options = array(), |
|
| 615 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 616 | - EE_Registration $registration, |
|
| 617 | - EE_Question $question, |
|
| 618 | - $answer |
|
| 619 | - ) { |
|
| 620 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 621 | - && $question->type() === EEM_Question::QST_type_state |
|
| 622 | - ) { |
|
| 623 | - $STA_ID = $answer->value(); |
|
| 624 | - if (! empty($STA_ID)) { |
|
| 625 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 626 | - if ($state instanceof EE_State) { |
|
| 627 | - $country = $state->country(); |
|
| 628 | - if ($country instanceof EE_Country) { |
|
| 629 | - if (! isset($state_options[$country->name()])) { |
|
| 630 | - $state_options[$country->name()] = array(); |
|
| 631 | - } |
|
| 632 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 633 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - return $state_options; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * @param EE_Country[] $country_options |
|
| 646 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 647 | - * @param EE_Registration $registration |
|
| 648 | - * @param EE_Question $question |
|
| 649 | - * @param $answer |
|
| 650 | - * @return array |
|
| 651 | - * @throws EE_Error |
|
| 652 | - * @throws InvalidArgumentException |
|
| 653 | - * @throws InvalidDataTypeException |
|
| 654 | - * @throws InvalidInterfaceException |
|
| 655 | - */ |
|
| 656 | - public static function inject_new_reg_country_into_options( |
|
| 657 | - $country_options = array(), |
|
| 658 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 659 | - EE_Registration $registration, |
|
| 660 | - EE_Question $question, |
|
| 661 | - $answer |
|
| 662 | - ) { |
|
| 663 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 664 | - && $question->type() |
|
| 665 | - === EEM_Question::QST_type_country |
|
| 666 | - ) { |
|
| 667 | - $CNT_ISO = $answer->value(); |
|
| 668 | - if (! empty($CNT_ISO)) { |
|
| 669 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 670 | - if ($country instanceof EE_Country) { |
|
| 671 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 672 | - $country_options[$CNT_ISO] = $country->name(); |
|
| 673 | - } |
|
| 674 | - } |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - return $country_options; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * @param EE_State[] $state_options |
|
| 684 | - * @return array |
|
| 685 | - * @throws EE_Error |
|
| 686 | - * @throws InvalidArgumentException |
|
| 687 | - * @throws InvalidDataTypeException |
|
| 688 | - * @throws InvalidInterfaceException |
|
| 689 | - */ |
|
| 690 | - public static function state_options($state_options = array()) |
|
| 691 | - { |
|
| 692 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 693 | - foreach ($new_states as $new_state) { |
|
| 694 | - if ( |
|
| 695 | - $new_state instanceof EE_State |
|
| 696 | - && $new_state->country() instanceof EE_Country |
|
| 697 | - ) { |
|
| 698 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - return $state_options; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * @return array |
|
| 708 | - * @throws InvalidArgumentException |
|
| 709 | - * @throws InvalidDataTypeException |
|
| 710 | - * @throws InvalidInterfaceException |
|
| 711 | - */ |
|
| 712 | - protected static function _get_new_states() |
|
| 713 | - { |
|
| 714 | - $new_states = array(); |
|
| 715 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 716 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 717 | - 'nsmf_new_states' |
|
| 718 | - ); |
|
| 719 | - } |
|
| 720 | - return is_array($new_states) ? $new_states : array(); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * @param EE_Country[] $country_options |
|
| 727 | - * @return array |
|
| 728 | - * @throws EE_Error |
|
| 729 | - * @throws InvalidArgumentException |
|
| 730 | - * @throws InvalidDataTypeException |
|
| 731 | - * @throws InvalidInterfaceException |
|
| 732 | - */ |
|
| 733 | - public static function country_options($country_options = array()) |
|
| 734 | - { |
|
| 735 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 736 | - foreach ($new_states as $new_state) { |
|
| 737 | - if ( |
|
| 738 | - $new_state instanceof EE_State |
|
| 739 | - && $new_state->country() instanceof EE_Country |
|
| 740 | - ) { |
|
| 741 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - return $country_options; |
|
| 745 | - } |
|
| 22 | + /** |
|
| 23 | + * @return EED_Module|EED_Add_New_State |
|
| 24 | + */ |
|
| 25 | + public static function instance() |
|
| 26 | + { |
|
| 27 | + return parent::get_instance(__CLASS__); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 34 | + * |
|
| 35 | + * @return void |
|
| 36 | + */ |
|
| 37 | + public static function set_hooks() |
|
| 38 | + { |
|
| 39 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 40 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 41 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 42 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 43 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 44 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 45 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 46 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 47 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 48 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 49 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 50 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 51 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 52 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 53 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 54 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 55 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 62 | + * |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public static function set_hooks_admin() |
|
| 66 | + { |
|
| 67 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 68 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 69 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 70 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 71 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 72 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 73 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 74 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 75 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 76 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 77 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 78 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 79 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 80 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 81 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 82 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 83 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 84 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 85 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 86 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 87 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 88 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 89 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + public static function set_definitions() |
|
| 98 | + { |
|
| 99 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 100 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
| 101 | + '\\', |
|
| 102 | + DS, |
|
| 103 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param WP $WP |
|
| 111 | + * @return void |
|
| 112 | + */ |
|
| 113 | + public function run($WP) |
|
| 114 | + { |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + public static function translate_js_strings() |
|
| 123 | + { |
|
| 124 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 125 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 126 | + 'event_espresso' |
|
| 127 | + ); |
|
| 128 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 129 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 130 | + 'event_espresso' |
|
| 131 | + ); |
|
| 132 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 133 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 134 | + 'event_espresso' |
|
| 135 | + ); |
|
| 136 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 137 | + 'The new state was successfully saved to the database.', |
|
| 138 | + 'event_espresso' |
|
| 139 | + ); |
|
| 140 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 141 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 142 | + 'event_espresso' |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public static function wp_enqueue_scripts() |
|
| 152 | + { |
|
| 153 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 154 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 155 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 156 | + wp_enqueue_script('add_new_state'); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * display_add_new_state_micro_form |
|
| 164 | + * |
|
| 165 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 166 | + * @return string |
|
| 167 | + * @throws EE_Error |
|
| 168 | + * @throws InvalidArgumentException |
|
| 169 | + * @throws InvalidDataTypeException |
|
| 170 | + * @throws InvalidInterfaceException |
|
| 171 | + */ |
|
| 172 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 173 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 174 | + { |
|
| 175 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 176 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 177 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 178 | + // is the "state" question in this form section? |
|
| 179 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 180 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 181 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 182 | + //by forcing it to set it now, like it did while getting the form for display |
|
| 183 | + if ($input instanceof EE_State_Select_Input) { |
|
| 184 | + $input->html_name(); |
|
| 185 | + } |
|
| 186 | + return $question_group_reg_form; |
|
| 187 | + } |
|
| 188 | + // we're only doing this for state select inputs |
|
| 189 | + if ($input instanceof EE_State_Select_Input) { |
|
| 190 | + // grab any set values from the request |
|
| 191 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 192 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 193 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 194 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 195 | + $country_options = array(); |
|
| 196 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 197 | + if (! empty($countries)) { |
|
| 198 | + foreach ($countries as $country) { |
|
| 199 | + if ($country instanceof EE_Country) { |
|
| 200 | + $country_options[$country->ID()] = $country->name(); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 205 | + array( |
|
| 206 | + 'name' => 'new_state_micro_form', |
|
| 207 | + 'html_id' => 'new_state_micro_form', |
|
| 208 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 209 | + 'subsections' => array( |
|
| 210 | + // add hidden input to indicate that a new state is being added |
|
| 211 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 212 | + array( |
|
| 213 | + 'html_name' => str_replace( |
|
| 214 | + 'state', |
|
| 215 | + 'nsmf_add_new_state', |
|
| 216 | + $input->html_name() |
|
| 217 | + ), |
|
| 218 | + 'html_id' => str_replace( |
|
| 219 | + 'state', |
|
| 220 | + 'nsmf_add_new_state', |
|
| 221 | + $input->html_id() |
|
| 222 | + ), |
|
| 223 | + 'default' => 0, |
|
| 224 | + ) |
|
| 225 | + ), |
|
| 226 | + // add link for displaying hidden container |
|
| 227 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 228 | + apply_filters( |
|
| 229 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 230 | + EEH_HTML::link( |
|
| 231 | + '', |
|
| 232 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 233 | + '', |
|
| 234 | + 'display-' . $input->html_id(), |
|
| 235 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 236 | + '', |
|
| 237 | + 'data-target="' . $input->html_id() . '"' |
|
| 238 | + ) |
|
| 239 | + ) |
|
| 240 | + ), |
|
| 241 | + // add initial html for hidden container |
|
| 242 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 243 | + apply_filters( |
|
| 244 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 245 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 246 | + 'display: none;') . |
|
| 247 | + EEH_HTML::h6( |
|
| 248 | + esc_html__( |
|
| 249 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 250 | + 'event_espresso' |
|
| 251 | + ) |
|
| 252 | + ) . |
|
| 253 | + EEH_HTML::ul() . |
|
| 254 | + EEH_HTML::li( |
|
| 255 | + esc_html__( |
|
| 256 | + 'first select the Country that your State/Province belongs to', |
|
| 257 | + 'event_espresso' |
|
| 258 | + ) |
|
| 259 | + ) . |
|
| 260 | + EEH_HTML::li( |
|
| 261 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 262 | + ) . |
|
| 263 | + EEH_HTML::li( |
|
| 264 | + esc_html__( |
|
| 265 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 266 | + 'event_espresso' |
|
| 267 | + ) |
|
| 268 | + ) . |
|
| 269 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 270 | + EEH_HTML::ulx() |
|
| 271 | + ) |
|
| 272 | + ), |
|
| 273 | + // NEW STATE COUNTRY |
|
| 274 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 275 | + $country_options, |
|
| 276 | + array( |
|
| 277 | + 'html_name' => $country_name, |
|
| 278 | + 'html_id' => str_replace( |
|
| 279 | + 'state', |
|
| 280 | + 'nsmf_new_state_country', $input->html_id() |
|
| 281 | + ), |
|
| 282 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 283 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 284 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 285 | + 'required' => false, |
|
| 286 | + ) |
|
| 287 | + ), |
|
| 288 | + // NEW STATE NAME |
|
| 289 | + 'new_state_name' => new EE_Text_Input( |
|
| 290 | + array( |
|
| 291 | + 'html_name' => $state_name, |
|
| 292 | + 'html_id' => str_replace( |
|
| 293 | + 'state', |
|
| 294 | + 'nsmf_new_state_name', $input->html_id() |
|
| 295 | + ), |
|
| 296 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 297 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
| 298 | + 'event_espresso'), |
|
| 299 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 300 | + 'required' => false, |
|
| 301 | + ) |
|
| 302 | + ), |
|
| 303 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 304 | + // NEW STATE NAME |
|
| 305 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 306 | + array( |
|
| 307 | + 'html_name' => $abbrv_name, |
|
| 308 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 309 | + $input->html_id()), |
|
| 310 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 311 | + 'html_label_text' => esc_html__( |
|
| 312 | + 'New State/Province Abbreviation', |
|
| 313 | + 'event_espresso' |
|
| 314 | + ) . ' *', |
|
| 315 | + 'html_other_attributes' => 'size="24"', |
|
| 316 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 317 | + 'required' => false, |
|
| 318 | + ) |
|
| 319 | + ), |
|
| 320 | + // "submit" button |
|
| 321 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 322 | + apply_filters( |
|
| 323 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 324 | + EEH_HTML::nbsp(3) . |
|
| 325 | + EEH_HTML::link( |
|
| 326 | + '', |
|
| 327 | + esc_html__('ADD', 'event_espresso'), |
|
| 328 | + '', |
|
| 329 | + 'submit-' . $new_state_submit_id, |
|
| 330 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 331 | + '', |
|
| 332 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 333 | + ) |
|
| 334 | + ) |
|
| 335 | + ), |
|
| 336 | + // extra info |
|
| 337 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 338 | + apply_filters( |
|
| 339 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 340 | + EEH_HTML::br(2) |
|
| 341 | + . |
|
| 342 | + EEH_HTML::div('', '', 'small-text') |
|
| 343 | + . |
|
| 344 | + EEH_HTML::strong( |
|
| 345 | + '* ' . |
|
| 346 | + esc_html__( |
|
| 347 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 348 | + 'event_espresso' |
|
| 349 | + ) |
|
| 350 | + ) |
|
| 351 | + . |
|
| 352 | + EEH_HTML::br() |
|
| 353 | + . |
|
| 354 | + sprintf( |
|
| 355 | + esc_html__( |
|
| 356 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 357 | + 'event_espresso' |
|
| 358 | + ), |
|
| 359 | + EEH_HTML::link( |
|
| 360 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 361 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 362 | + '', |
|
| 363 | + '', |
|
| 364 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 365 | + '', |
|
| 366 | + 'target="_blank"' |
|
| 367 | + ) |
|
| 368 | + ) |
|
| 369 | + . |
|
| 370 | + EEH_HTML::divx() |
|
| 371 | + . |
|
| 372 | + EEH_HTML::br() |
|
| 373 | + . |
|
| 374 | + EEH_HTML::link( |
|
| 375 | + '', |
|
| 376 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 377 | + '', |
|
| 378 | + 'hide-' . $input->html_id(), |
|
| 379 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 380 | + '', |
|
| 381 | + 'data-target="' . $input->html_id() . '"' |
|
| 382 | + ) |
|
| 383 | + . |
|
| 384 | + EEH_HTML::divx() |
|
| 385 | + . |
|
| 386 | + EEH_HTML::br() |
|
| 387 | + ) |
|
| 388 | + ), |
|
| 389 | + ), |
|
| 390 | + ) |
|
| 391 | + ); |
|
| 392 | + $question_group_reg_form->add_subsections( |
|
| 393 | + array('new_state_micro_form' => $new_state_micro_form), |
|
| 394 | + 'state', |
|
| 395 | + false |
|
| 396 | + ); |
|
| 397 | + } |
|
| 398 | + return $question_group_reg_form; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * set_new_state_input_width |
|
| 405 | + * |
|
| 406 | + * @return int|string |
|
| 407 | + * @throws EE_Error |
|
| 408 | + * @throws InvalidArgumentException |
|
| 409 | + * @throws InvalidDataTypeException |
|
| 410 | + * @throws InvalidInterfaceException |
|
| 411 | + * @throws ReflectionException |
|
| 412 | + */ |
|
| 413 | + public static function add_new_state() |
|
| 414 | + { |
|
| 415 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 416 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 417 | + EE_Registry::instance()->load_model('State'); |
|
| 418 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 419 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 420 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 421 | + : false; |
|
| 422 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 424 | + : false; |
|
| 425 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 427 | + : false; |
|
| 428 | + if ($state_country && $state_name && $state_abbr) { |
|
| 429 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 430 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 431 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 432 | + 'STA_name' => ucwords($state_name), |
|
| 433 | + 'STA_active' => false, |
|
| 434 | + )); |
|
| 435 | + if ($new_state instanceof EE_State) { |
|
| 436 | + // clean house |
|
| 437 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 438 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 439 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 440 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 441 | + // get any existing new states |
|
| 442 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 443 | + 'nsmf_new_states' |
|
| 444 | + ); |
|
| 445 | + $new_states[$new_state->ID()] = $new_state; |
|
| 446 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 447 | + array('nsmf_new_states' => $new_states) |
|
| 448 | + ); |
|
| 449 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 450 | + echo wp_json_encode(array( |
|
| 451 | + 'success' => true, |
|
| 452 | + 'id' => $new_state->ID(), |
|
| 453 | + 'name' => $new_state->name(), |
|
| 454 | + 'abbrev' => $new_state->abbrev(), |
|
| 455 | + 'country_iso' => $new_state->country_iso(), |
|
| 456 | + 'country_name' => $new_state->country()->name(), |
|
| 457 | + )); |
|
| 458 | + exit(); |
|
| 459 | + } |
|
| 460 | + return $new_state->ID(); |
|
| 461 | + } |
|
| 462 | + } else { |
|
| 463 | + $error = esc_html__( |
|
| 464 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 465 | + 'event_espresso' |
|
| 466 | + ); |
|
| 467 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 468 | + echo wp_json_encode(array('error' => $error)); |
|
| 469 | + exit(); |
|
| 470 | + } |
|
| 471 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + return false; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * recursively drills down through request params to remove any that were added by this module |
|
| 481 | + * |
|
| 482 | + * @param array $request_params |
|
| 483 | + * @return array |
|
| 484 | + */ |
|
| 485 | + public static function filter_checkout_request_params($request_params) |
|
| 486 | + { |
|
| 487 | + foreach ($request_params as $form_section) { |
|
| 488 | + if (is_array($form_section)) { |
|
| 489 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 490 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + return $request_params; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * @param array $request_params |
|
| 500 | + * @return array |
|
| 501 | + */ |
|
| 502 | + public static function unset_new_state_request_params($request_params) |
|
| 503 | + { |
|
| 504 | + unset( |
|
| 505 | + $request_params['new_state_micro_form'], |
|
| 506 | + $request_params['new_state_micro_add_new_state'], |
|
| 507 | + $request_params['new_state_micro_new_state_country'], |
|
| 508 | + $request_params['new_state_micro_new_state_name'], |
|
| 509 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 510 | + ); |
|
| 511 | + return $request_params; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * @param array $props_n_values |
|
| 518 | + * @return bool |
|
| 519 | + * @throws EE_Error |
|
| 520 | + * @throws InvalidArgumentException |
|
| 521 | + * @throws InvalidDataTypeException |
|
| 522 | + * @throws InvalidInterfaceException |
|
| 523 | + */ |
|
| 524 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 525 | + { |
|
| 526 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 527 | + if (! empty($existing_state)) { |
|
| 528 | + return array_pop($existing_state); |
|
| 529 | + } |
|
| 530 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 531 | + if ($new_state instanceof EE_State) { |
|
| 532 | + // if not non-ajax admin |
|
| 533 | + $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 534 | + $new_state_notice = sprintf( |
|
| 535 | + esc_html__( |
|
| 536 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 537 | + 'event_espresso' |
|
| 538 | + ), |
|
| 539 | + '<b>' . $new_state->name() . '</b>', |
|
| 540 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 541 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 542 | + '<a href="' . add_query_arg(array( |
|
| 543 | + 'page' => 'espresso_general_settings', |
|
| 544 | + 'action' => 'country_settings', |
|
| 545 | + 'country' => $new_state->country_iso(), |
|
| 546 | + ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 547 | + 'event_espresso') . '</a>', |
|
| 548 | + '<br />' |
|
| 549 | + ); |
|
| 550 | + EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
| 551 | + $new_state->save(); |
|
| 552 | + EEM_State::instance()->reset_cached_states(); |
|
| 553 | + return $new_state; |
|
| 554 | + } |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * @param string $CNT_ISO |
|
| 562 | + * @param string $STA_ID |
|
| 563 | + * @param array $cols_n_values |
|
| 564 | + * @return void |
|
| 565 | + * @throws EE_Error |
|
| 566 | + * @throws InvalidArgumentException |
|
| 567 | + * @throws InvalidDataTypeException |
|
| 568 | + * @throws InvalidInterfaceException |
|
| 569 | + */ |
|
| 570 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 571 | + { |
|
| 572 | + if (! $CNT_ISO) { |
|
| 573 | + EE_Error::add_error( |
|
| 574 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 575 | + __FILE__, |
|
| 576 | + __FUNCTION__, |
|
| 577 | + __LINE__ |
|
| 578 | + ); |
|
| 579 | + } |
|
| 580 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 581 | + : false; |
|
| 582 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 583 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 584 | + if ($state instanceof EE_State) { |
|
| 585 | + $STA_abbrev = $state->abbrev(); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + if (! $STA_abbrev) { |
|
| 589 | + EE_Error::add_error( |
|
| 590 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 591 | + __FILE__, |
|
| 592 | + __FUNCTION__, |
|
| 593 | + __LINE__ |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * @param EE_State[] $state_options |
|
| 603 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 604 | + * @param EE_Registration $registration |
|
| 605 | + * @param EE_Question $question |
|
| 606 | + * @param $answer |
|
| 607 | + * @return array |
|
| 608 | + * @throws EE_Error |
|
| 609 | + * @throws InvalidArgumentException |
|
| 610 | + * @throws InvalidDataTypeException |
|
| 611 | + * @throws InvalidInterfaceException |
|
| 612 | + */ |
|
| 613 | + public static function inject_new_reg_state_into_options( |
|
| 614 | + $state_options = array(), |
|
| 615 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 616 | + EE_Registration $registration, |
|
| 617 | + EE_Question $question, |
|
| 618 | + $answer |
|
| 619 | + ) { |
|
| 620 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 621 | + && $question->type() === EEM_Question::QST_type_state |
|
| 622 | + ) { |
|
| 623 | + $STA_ID = $answer->value(); |
|
| 624 | + if (! empty($STA_ID)) { |
|
| 625 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 626 | + if ($state instanceof EE_State) { |
|
| 627 | + $country = $state->country(); |
|
| 628 | + if ($country instanceof EE_Country) { |
|
| 629 | + if (! isset($state_options[$country->name()])) { |
|
| 630 | + $state_options[$country->name()] = array(); |
|
| 631 | + } |
|
| 632 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 633 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + return $state_options; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * @param EE_Country[] $country_options |
|
| 646 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 647 | + * @param EE_Registration $registration |
|
| 648 | + * @param EE_Question $question |
|
| 649 | + * @param $answer |
|
| 650 | + * @return array |
|
| 651 | + * @throws EE_Error |
|
| 652 | + * @throws InvalidArgumentException |
|
| 653 | + * @throws InvalidDataTypeException |
|
| 654 | + * @throws InvalidInterfaceException |
|
| 655 | + */ |
|
| 656 | + public static function inject_new_reg_country_into_options( |
|
| 657 | + $country_options = array(), |
|
| 658 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 659 | + EE_Registration $registration, |
|
| 660 | + EE_Question $question, |
|
| 661 | + $answer |
|
| 662 | + ) { |
|
| 663 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 664 | + && $question->type() |
|
| 665 | + === EEM_Question::QST_type_country |
|
| 666 | + ) { |
|
| 667 | + $CNT_ISO = $answer->value(); |
|
| 668 | + if (! empty($CNT_ISO)) { |
|
| 669 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 670 | + if ($country instanceof EE_Country) { |
|
| 671 | + if (! isset($country_options[$CNT_ISO])) { |
|
| 672 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + return $country_options; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * @param EE_State[] $state_options |
|
| 684 | + * @return array |
|
| 685 | + * @throws EE_Error |
|
| 686 | + * @throws InvalidArgumentException |
|
| 687 | + * @throws InvalidDataTypeException |
|
| 688 | + * @throws InvalidInterfaceException |
|
| 689 | + */ |
|
| 690 | + public static function state_options($state_options = array()) |
|
| 691 | + { |
|
| 692 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 693 | + foreach ($new_states as $new_state) { |
|
| 694 | + if ( |
|
| 695 | + $new_state instanceof EE_State |
|
| 696 | + && $new_state->country() instanceof EE_Country |
|
| 697 | + ) { |
|
| 698 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + return $state_options; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * @return array |
|
| 708 | + * @throws InvalidArgumentException |
|
| 709 | + * @throws InvalidDataTypeException |
|
| 710 | + * @throws InvalidInterfaceException |
|
| 711 | + */ |
|
| 712 | + protected static function _get_new_states() |
|
| 713 | + { |
|
| 714 | + $new_states = array(); |
|
| 715 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 716 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 717 | + 'nsmf_new_states' |
|
| 718 | + ); |
|
| 719 | + } |
|
| 720 | + return is_array($new_states) ? $new_states : array(); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * @param EE_Country[] $country_options |
|
| 727 | + * @return array |
|
| 728 | + * @throws EE_Error |
|
| 729 | + * @throws InvalidArgumentException |
|
| 730 | + * @throws InvalidDataTypeException |
|
| 731 | + * @throws InvalidInterfaceException |
|
| 732 | + */ |
|
| 733 | + public static function country_options($country_options = array()) |
|
| 734 | + { |
|
| 735 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 736 | + foreach ($new_states as $new_state) { |
|
| 737 | + if ( |
|
| 738 | + $new_state instanceof EE_State |
|
| 739 | + && $new_state->country() instanceof EE_Country |
|
| 740 | + ) { |
|
| 741 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + return $country_options; |
|
| 745 | + } |
|
| 746 | 746 | |
| 747 | 747 | |
| 748 | 748 | |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public static function set_definitions() |
| 98 | 98 | { |
| 99 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 99 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
| 100 | 100 | define('ANS_TEMPLATES_PATH', str_replace( |
| 101 | 101 | '\\', |
| 102 | 102 | DS, |
| 103 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 103 | + plugin_dir_path(__FILE__)).'templates'.DS |
|
| 104 | 104 | ); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -121,19 +121,19 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public static function translate_js_strings() |
| 123 | 123 | { |
| 124 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 124 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 125 | 125 | 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
| 126 | 126 | 'event_espresso' |
| 127 | 127 | ); |
| 128 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 128 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 129 | 129 | 'In order to proceed, you need to enter the name of your State/Province.', |
| 130 | 130 | 'event_espresso' |
| 131 | 131 | ); |
| 132 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 132 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 133 | 133 | 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
| 134 | 134 | 'event_espresso' |
| 135 | 135 | ); |
| 136 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 136 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 137 | 137 | 'The new state was successfully saved to the database.', |
| 138 | 138 | 'event_espresso' |
| 139 | 139 | ); |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public static function wp_enqueue_scripts() |
| 152 | 152 | { |
| 153 | 153 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
| 154 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 154 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', |
|
| 155 | 155 | array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
| 156 | 156 | wp_enqueue_script('add_new_state'); |
| 157 | 157 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
| 195 | 195 | $country_options = array(); |
| 196 | 196 | $countries = EEM_Country::instance()->get_all_countries(); |
| 197 | - if (! empty($countries)) { |
|
| 197 | + if ( ! empty($countries)) { |
|
| 198 | 198 | foreach ($countries as $country) { |
| 199 | 199 | if ($country instanceof EE_Country) { |
| 200 | 200 | $country_options[$country->ID()] = $country->name(); |
@@ -231,10 +231,10 @@ discard block |
||
| 231 | 231 | '', |
| 232 | 232 | esc_html__('click here to add a new state/province', 'event_espresso'), |
| 233 | 233 | '', |
| 234 | - 'display-' . $input->html_id(), |
|
| 234 | + 'display-'.$input->html_id(), |
|
| 235 | 235 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
| 236 | 236 | '', |
| 237 | - 'data-target="' . $input->html_id() . '"' |
|
| 237 | + 'data-target="'.$input->html_id().'"' |
|
| 238 | 238 | ) |
| 239 | 239 | ) |
| 240 | 240 | ), |
@@ -242,31 +242,31 @@ discard block |
||
| 242 | 242 | 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
| 243 | 243 | apply_filters( |
| 244 | 244 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
| 245 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 246 | - 'display: none;') . |
|
| 245 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', |
|
| 246 | + 'display: none;'). |
|
| 247 | 247 | EEH_HTML::h6( |
| 248 | 248 | esc_html__( |
| 249 | 249 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
| 250 | 250 | 'event_espresso' |
| 251 | 251 | ) |
| 252 | - ) . |
|
| 253 | - EEH_HTML::ul() . |
|
| 252 | + ). |
|
| 253 | + EEH_HTML::ul(). |
|
| 254 | 254 | EEH_HTML::li( |
| 255 | 255 | esc_html__( |
| 256 | 256 | 'first select the Country that your State/Province belongs to', |
| 257 | 257 | 'event_espresso' |
| 258 | 258 | ) |
| 259 | - ) . |
|
| 259 | + ). |
|
| 260 | 260 | EEH_HTML::li( |
| 261 | 261 | esc_html__('enter the name of your State/Province', 'event_espresso') |
| 262 | - ) . |
|
| 262 | + ). |
|
| 263 | 263 | EEH_HTML::li( |
| 264 | 264 | esc_html__( |
| 265 | 265 | 'enter a two to six letter abbreviation for the name of your State/Province', |
| 266 | 266 | 'event_espresso' |
| 267 | 267 | ) |
| 268 | - ) . |
|
| 269 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 268 | + ). |
|
| 269 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
| 270 | 270 | EEH_HTML::ulx() |
| 271 | 271 | ) |
| 272 | 272 | ), |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | 'state', |
| 280 | 280 | 'nsmf_new_state_country', $input->html_id() |
| 281 | 281 | ), |
| 282 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 282 | + 'html_class' => $input->html_class().' new-state-country', |
|
| 283 | 283 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
| 284 | 284 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
| 285 | 285 | 'required' => false, |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | 'state', |
| 294 | 294 | 'nsmf_new_state_name', $input->html_id() |
| 295 | 295 | ), |
| 296 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 296 | + 'html_class' => $input->html_class().' new-state-state', |
|
| 297 | 297 | 'html_label_text' => esc_html__('New State/Province Name', |
| 298 | 298 | 'event_espresso'), |
| 299 | 299 | 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
@@ -307,11 +307,11 @@ discard block |
||
| 307 | 307 | 'html_name' => $abbrv_name, |
| 308 | 308 | 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
| 309 | 309 | $input->html_id()), |
| 310 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 310 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
| 311 | 311 | 'html_label_text' => esc_html__( |
| 312 | 312 | 'New State/Province Abbreviation', |
| 313 | 313 | 'event_espresso' |
| 314 | - ) . ' *', |
|
| 314 | + ).' *', |
|
| 315 | 315 | 'html_other_attributes' => 'size="24"', |
| 316 | 316 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
| 317 | 317 | 'required' => false, |
@@ -321,15 +321,15 @@ discard block |
||
| 321 | 321 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
| 322 | 322 | apply_filters( |
| 323 | 323 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
| 324 | - EEH_HTML::nbsp(3) . |
|
| 324 | + EEH_HTML::nbsp(3). |
|
| 325 | 325 | EEH_HTML::link( |
| 326 | 326 | '', |
| 327 | 327 | esc_html__('ADD', 'event_espresso'), |
| 328 | 328 | '', |
| 329 | - 'submit-' . $new_state_submit_id, |
|
| 329 | + 'submit-'.$new_state_submit_id, |
|
| 330 | 330 | 'ee-form-add-new-state-submit button button-secondary', |
| 331 | 331 | '', |
| 332 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 332 | + 'data-target="'.$new_state_submit_id.'"' |
|
| 333 | 333 | ) |
| 334 | 334 | ) |
| 335 | 335 | ), |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | EEH_HTML::div('', '', 'small-text') |
| 343 | 343 | . |
| 344 | 344 | EEH_HTML::strong( |
| 345 | - '* ' . |
|
| 345 | + '* '. |
|
| 346 | 346 | esc_html__( |
| 347 | 347 | 'Don\'t know your State/Province Abbreviation?', |
| 348 | 348 | 'event_espresso' |
@@ -375,10 +375,10 @@ discard block |
||
| 375 | 375 | '', |
| 376 | 376 | esc_html__('cancel new State/Province', 'event_espresso'), |
| 377 | 377 | '', |
| 378 | - 'hide-' . $input->html_id(), |
|
| 378 | + 'hide-'.$input->html_id(), |
|
| 379 | 379 | 'ee-form-cancel-new-state-lnk smaller-text', |
| 380 | 380 | '', |
| 381 | - 'data-target="' . $input->html_id() . '"' |
|
| 381 | + 'data-target="'.$input->html_id().'"' |
|
| 382 | 382 | ) |
| 383 | 383 | . |
| 384 | 384 | EEH_HTML::divx() |
@@ -524,27 +524,27 @@ discard block |
||
| 524 | 524 | public static function save_new_state_to_db($props_n_values = array()) |
| 525 | 525 | { |
| 526 | 526 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
| 527 | - if (! empty($existing_state)) { |
|
| 527 | + if ( ! empty($existing_state)) { |
|
| 528 | 528 | return array_pop($existing_state); |
| 529 | 529 | } |
| 530 | 530 | $new_state = EE_State::new_instance($props_n_values); |
| 531 | 531 | if ($new_state instanceof EE_State) { |
| 532 | 532 | // if not non-ajax admin |
| 533 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 533 | + $new_state_key = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(); |
|
| 534 | 534 | $new_state_notice = sprintf( |
| 535 | 535 | esc_html__( |
| 536 | 536 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
| 537 | 537 | 'event_espresso' |
| 538 | 538 | ), |
| 539 | - '<b>' . $new_state->name() . '</b>', |
|
| 540 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 541 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 542 | - '<a href="' . add_query_arg(array( |
|
| 539 | + '<b>'.$new_state->name().'</b>', |
|
| 540 | + '<b>'.$new_state->abbrev().'</b>', |
|
| 541 | + '<b>'.$new_state->country()->name().'</b>', |
|
| 542 | + '<a href="'.add_query_arg(array( |
|
| 543 | 543 | 'page' => 'espresso_general_settings', |
| 544 | 544 | 'action' => 'country_settings', |
| 545 | 545 | 'country' => $new_state->country_iso(), |
| 546 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 547 | - 'event_espresso') . '</a>', |
|
| 546 | + ), admin_url('admin.php')).'">'.esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 547 | + 'event_espresso').'</a>', |
|
| 548 | 548 | '<br />' |
| 549 | 549 | ); |
| 550 | 550 | EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | */ |
| 570 | 570 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
| 571 | 571 | { |
| 572 | - if (! $CNT_ISO) { |
|
| 572 | + if ( ! $CNT_ISO) { |
|
| 573 | 573 | EE_Error::add_error( |
| 574 | 574 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
| 575 | 575 | __FILE__, |
@@ -579,13 +579,13 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
| 581 | 581 | : false; |
| 582 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 582 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
| 583 | 583 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 584 | 584 | if ($state instanceof EE_State) { |
| 585 | 585 | $STA_abbrev = $state->abbrev(); |
| 586 | 586 | } |
| 587 | 587 | } |
| 588 | - if (! $STA_abbrev) { |
|
| 588 | + if ( ! $STA_abbrev) { |
|
| 589 | 589 | EE_Error::add_error( |
| 590 | 590 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
| 591 | 591 | __FILE__, |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | __LINE__ |
| 594 | 594 | ); |
| 595 | 595 | } |
| 596 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 596 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | |
@@ -621,15 +621,15 @@ discard block |
||
| 621 | 621 | && $question->type() === EEM_Question::QST_type_state |
| 622 | 622 | ) { |
| 623 | 623 | $STA_ID = $answer->value(); |
| 624 | - if (! empty($STA_ID)) { |
|
| 624 | + if ( ! empty($STA_ID)) { |
|
| 625 | 625 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 626 | 626 | if ($state instanceof EE_State) { |
| 627 | 627 | $country = $state->country(); |
| 628 | 628 | if ($country instanceof EE_Country) { |
| 629 | - if (! isset($state_options[$country->name()])) { |
|
| 629 | + if ( ! isset($state_options[$country->name()])) { |
|
| 630 | 630 | $state_options[$country->name()] = array(); |
| 631 | 631 | } |
| 632 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 632 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
| 633 | 633 | $state_options[$country->name()][$STA_ID] = $state->name(); |
| 634 | 634 | } |
| 635 | 635 | } |
@@ -665,10 +665,10 @@ discard block |
||
| 665 | 665 | === EEM_Question::QST_type_country |
| 666 | 666 | ) { |
| 667 | 667 | $CNT_ISO = $answer->value(); |
| 668 | - if (! empty($CNT_ISO)) { |
|
| 668 | + if ( ! empty($CNT_ISO)) { |
|
| 669 | 669 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
| 670 | 670 | if ($country instanceof EE_Country) { |
| 671 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 671 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
| 672 | 672 | $country_options[$CNT_ISO] = $country->name(); |
| 673 | 673 | } |
| 674 | 674 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @since $VID:$ |
| 20 | 20 | */ |
| 21 | 21 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 22 | - exit('No direct script access allowed'); |
|
| 22 | + exit('No direct script access allowed'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -27,404 +27,404 @@ discard block |
||
| 27 | 27 | class Event extends Calculations_Base |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Calculates the total spaces on the event (not subtracting sales, but taking |
|
| 32 | - * sales into account; so this is the optimum sales that CAN still be achieved) |
|
| 33 | - * See EE_Event::total_available_spaces( true ); |
|
| 34 | - * |
|
| 35 | - * @param array $wpdb_row |
|
| 36 | - * @param \WP_REST_Request $request |
|
| 37 | - * @param Base $controller |
|
| 38 | - * @return int |
|
| 39 | - * @throws EE_Error |
|
| 40 | - */ |
|
| 41 | - public static function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
| 42 | - { |
|
| 43 | - $event_obj = null; |
|
| 44 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 45 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
| 46 | - } |
|
| 47 | - if ($event_obj instanceof EE_Event) { |
|
| 48 | - return $event_obj->total_available_spaces(); |
|
| 49 | - } |
|
| 50 | - throw new EE_Error( |
|
| 51 | - sprintf( |
|
| 52 | - __( |
|
| 53 | - // @codingStandardsIgnoreStart |
|
| 54 | - 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
| 55 | - // @codingStandardsIgnoreEnd |
|
| 56 | - 'event_espresso' |
|
| 57 | - ), |
|
| 58 | - $wpdb_row['Event_CPT.ID'], |
|
| 59 | - print_r($wpdb_row, true) |
|
| 60 | - ) |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
| 68 | - * sales that COULD have been achieved) |
|
| 69 | - * See EE_Event::total_available_spaces( true ); |
|
| 70 | - * |
|
| 71 | - * @param array $wpdb_row |
|
| 72 | - * @param \WP_REST_Request $request |
|
| 73 | - * @param Base $controller |
|
| 74 | - * @return int |
|
| 75 | - * @throws EE_Error |
|
| 76 | - */ |
|
| 77 | - public static function optimumSalesNow($wpdb_row, $request, $controller) |
|
| 78 | - { |
|
| 79 | - $event_obj = null; |
|
| 80 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 81 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
| 82 | - } |
|
| 83 | - if ($event_obj instanceof EE_Event) { |
|
| 84 | - return $event_obj->total_available_spaces(true); |
|
| 85 | - } |
|
| 86 | - throw new EE_Error( |
|
| 87 | - sprintf( |
|
| 88 | - __( |
|
| 89 | - // @codingStandardsIgnoreStart |
|
| 90 | - 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
| 91 | - // @codingStandardsIgnoreEnd |
|
| 92 | - 'event_espresso' |
|
| 93 | - ), |
|
| 94 | - $wpdb_row['Event_CPT.ID'], |
|
| 95 | - print_r($wpdb_row, true) |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Like optimum_sales_now, but minus total sales so far. |
|
| 104 | - * See EE_Event::spaces_remaining_for_sale( true ); |
|
| 105 | - * |
|
| 106 | - * @param array $wpdb_row |
|
| 107 | - * @param \WP_REST_Request $request |
|
| 108 | - * @param Base $controller |
|
| 109 | - * @return int |
|
| 110 | - * @throws EE_Error |
|
| 111 | - */ |
|
| 112 | - public static function spacesRemaining($wpdb_row, $request, $controller) |
|
| 113 | - { |
|
| 114 | - $event_obj = null; |
|
| 115 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 116 | - $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
| 117 | - } |
|
| 118 | - if ($event_obj instanceof EE_Event) { |
|
| 119 | - return $event_obj->spaces_remaining_for_sale(); |
|
| 120 | - } |
|
| 121 | - throw new EE_Error( |
|
| 122 | - sprintf( |
|
| 123 | - __( |
|
| 124 | - // @codingStandardsIgnoreStart |
|
| 125 | - 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
| 126 | - // @codingStandardsIgnoreEnd |
|
| 127 | - 'event_espresso' |
|
| 128 | - ), |
|
| 129 | - $wpdb_row['Event_CPT.ID'], |
|
| 130 | - print_r($wpdb_row, true) |
|
| 131 | - ) |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Counts the number of approved registrations for this event (regardless |
|
| 139 | - * of how many datetimes each registrations' ticket purchase is for) |
|
| 140 | - * |
|
| 141 | - * @param array $wpdb_row |
|
| 142 | - * @param \WP_REST_Request $request |
|
| 143 | - * @param Base $controller |
|
| 144 | - * @return int |
|
| 145 | - * @throws EE_Error |
|
| 146 | - */ |
|
| 147 | - public static function spotsTaken($wpdb_row, $request, $controller) |
|
| 148 | - { |
|
| 149 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 150 | - throw new EE_Error( |
|
| 151 | - sprintf( |
|
| 152 | - __( |
|
| 153 | - // @codingStandardsIgnoreStart |
|
| 154 | - 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
| 155 | - // @codingStandardsIgnoreEnd |
|
| 156 | - 'event_espresso' |
|
| 157 | - ), |
|
| 158 | - print_r($wpdb_row, true) |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - return EEM_Registration::instance()->count( |
|
| 163 | - array( |
|
| 164 | - array( |
|
| 165 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
| 166 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 167 | - ), |
|
| 168 | - ), |
|
| 169 | - 'REG_ID', |
|
| 170 | - true |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Counts the number of pending-payment registrations for this event (regardless |
|
| 178 | - * of how many datetimes each registrations' ticket purchase is for) |
|
| 179 | - * |
|
| 180 | - * @param array $wpdb_row |
|
| 181 | - * @param \WP_REST_Request $request |
|
| 182 | - * @param Base $controller |
|
| 183 | - * @return int |
|
| 184 | - * @throws EE_Error |
|
| 185 | - * @throws RestException |
|
| 186 | - */ |
|
| 187 | - public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
| 188 | - { |
|
| 189 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 190 | - throw new EE_Error( |
|
| 191 | - sprintf( |
|
| 192 | - __( |
|
| 193 | - // @codingStandardsIgnoreStart |
|
| 194 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 195 | - // @codingStandardsIgnoreEnd |
|
| 196 | - 'event_espresso' |
|
| 197 | - ), |
|
| 198 | - print_r($wpdb_row, true) |
|
| 199 | - ) |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
| 203 | - return EEM_Registration::instance()->count( |
|
| 204 | - array( |
|
| 205 | - array( |
|
| 206 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
| 207 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 208 | - ), |
|
| 209 | - ), |
|
| 210 | - 'REG_ID', |
|
| 211 | - true |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Counts all the registrations who have checked into one of this events' datetimes |
|
| 219 | - * See EE_Event::total_available_spaces( false ); |
|
| 220 | - * |
|
| 221 | - * @param array $wpdb_row |
|
| 222 | - * @param \WP_REST_Request $request |
|
| 223 | - * @param Base $controller |
|
| 224 | - * @return int|null if permission denied |
|
| 225 | - * @throws EE_Error |
|
| 226 | - * @throws RestException |
|
| 227 | - */ |
|
| 228 | - public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
| 229 | - { |
|
| 230 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 231 | - throw new EE_Error( |
|
| 232 | - sprintf( |
|
| 233 | - __( |
|
| 234 | - // @codingStandardsIgnoreStart |
|
| 235 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 236 | - // @codingStandardsIgnoreEnd |
|
| 237 | - 'event_espresso' |
|
| 238 | - ), |
|
| 239 | - print_r($wpdb_row, true) |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - } |
|
| 243 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
| 244 | - return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Counts all the registrations who have checked out of one of this events' datetimes |
|
| 251 | - * See EE_Event::total_available_spaces( false ); |
|
| 252 | - * |
|
| 253 | - * @param array $wpdb_row |
|
| 254 | - * @param \WP_REST_Request $request |
|
| 255 | - * @param Base $controller |
|
| 256 | - * @return int |
|
| 257 | - * @throws EE_Error |
|
| 258 | - * @throws RestException |
|
| 259 | - */ |
|
| 260 | - public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
| 261 | - { |
|
| 262 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 263 | - throw new EE_Error( |
|
| 264 | - sprintf( |
|
| 265 | - __( |
|
| 266 | - // @codingStandardsIgnoreStart |
|
| 267 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 268 | - // @codingStandardsIgnoreEnd |
|
| 269 | - 'event_espresso' |
|
| 270 | - ), |
|
| 271 | - print_r($wpdb_row, true) |
|
| 272 | - ) |
|
| 273 | - ); |
|
| 274 | - } |
|
| 275 | - self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
| 276 | - return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Gets the thumbnail image |
|
| 283 | - * |
|
| 284 | - * @param array $wpdb_row |
|
| 285 | - * @param \WP_REST_Request $request |
|
| 286 | - * @param Base $controller |
|
| 287 | - * @return array |
|
| 288 | - * @throws EE_Error |
|
| 289 | - */ |
|
| 290 | - public static function imageThumbnail($wpdb_row, $request, $controller) |
|
| 291 | - { |
|
| 292 | - return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Gets the medium image |
|
| 299 | - * |
|
| 300 | - * @param array $wpdb_row |
|
| 301 | - * @param \WP_REST_Request $request |
|
| 302 | - * @param Base $controller |
|
| 303 | - * @return array |
|
| 304 | - * @throws EE_Error |
|
| 305 | - */ |
|
| 306 | - public static function imageMedium($wpdb_row, $request, $controller) |
|
| 307 | - { |
|
| 308 | - return self::calculateImageData($wpdb_row, 'medium'); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Gets the medium-large image |
|
| 315 | - * |
|
| 316 | - * @param array $wpdb_row |
|
| 317 | - * @param \WP_REST_Request $request |
|
| 318 | - * @param Base $controller |
|
| 319 | - * @return array |
|
| 320 | - * @throws EE_Error |
|
| 321 | - */ |
|
| 322 | - public static function imageMediumLarge($wpdb_row, $request, $controller) |
|
| 323 | - { |
|
| 324 | - return self::calculateImageData($wpdb_row, 'medium_large'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Gets the large image |
|
| 331 | - * |
|
| 332 | - * @param array $wpdb_row |
|
| 333 | - * @param \WP_REST_Request $request |
|
| 334 | - * @param Base $controller |
|
| 335 | - * @return array |
|
| 336 | - * @throws EE_Error |
|
| 337 | - */ |
|
| 338 | - public static function imageLarge($wpdb_row, $request, $controller) |
|
| 339 | - { |
|
| 340 | - return self::calculateImageData($wpdb_row, 'large'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Gets the post-thumbnail image |
|
| 347 | - * |
|
| 348 | - * @param array $wpdb_row |
|
| 349 | - * @param \WP_REST_Request $request |
|
| 350 | - * @param Base $controller |
|
| 351 | - * @return array |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public static function imagePostThumbnail($wpdb_row, $request, $controller) |
|
| 355 | - { |
|
| 356 | - return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Gets the full size image |
|
| 363 | - * |
|
| 364 | - * @param array $wpdb_row |
|
| 365 | - * @param \WP_REST_Request $request |
|
| 366 | - * @param Base $controller |
|
| 367 | - * @return array |
|
| 368 | - * @throws EE_Error |
|
| 369 | - */ |
|
| 370 | - public static function imageFull($wpdb_row, $request, $controller) |
|
| 371 | - { |
|
| 372 | - return self::calculateImageData($wpdb_row, 'full'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Gets image specs and formats them for the display in the API, |
|
| 379 | - * according to the image size requested |
|
| 380 | - * |
|
| 381 | - * @param array $wpdb_row |
|
| 382 | - * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
| 383 | - * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
| 384 | - * @throws EE_Error |
|
| 385 | - */ |
|
| 386 | - protected static function calculateImageData($wpdb_row, $image_size) |
|
| 387 | - { |
|
| 388 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 389 | - throw new EE_Error( |
|
| 390 | - sprintf( |
|
| 391 | - __( |
|
| 392 | - // @codingStandardsIgnoreStart |
|
| 393 | - 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 394 | - // @codingStandardsIgnoreEnd |
|
| 395 | - 'event_espresso' |
|
| 396 | - ), |
|
| 397 | - print_r($wpdb_row, true) |
|
| 398 | - ) |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
| 402 | - $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
| 403 | - $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
| 404 | - if (! $data) { |
|
| 405 | - return null; |
|
| 406 | - } |
|
| 407 | - $generated = true; |
|
| 408 | - if (isset($data[3])) { |
|
| 409 | - $generated = $data[3]; |
|
| 410 | - } |
|
| 411 | - return array( |
|
| 412 | - 'url' => $data[0], |
|
| 413 | - 'width' => $data[1], |
|
| 414 | - 'height' => $data[2], |
|
| 415 | - 'generated' => $generated, |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
| 423 | - * @param array $wpdb_row |
|
| 424 | - * @return bool |
|
| 425 | - */ |
|
| 426 | - protected static function wpdbRowHasEventId($wpdb_row) |
|
| 427 | - { |
|
| 428 | - return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
| 429 | - } |
|
| 30 | + /** |
|
| 31 | + * Calculates the total spaces on the event (not subtracting sales, but taking |
|
| 32 | + * sales into account; so this is the optimum sales that CAN still be achieved) |
|
| 33 | + * See EE_Event::total_available_spaces( true ); |
|
| 34 | + * |
|
| 35 | + * @param array $wpdb_row |
|
| 36 | + * @param \WP_REST_Request $request |
|
| 37 | + * @param Base $controller |
|
| 38 | + * @return int |
|
| 39 | + * @throws EE_Error |
|
| 40 | + */ |
|
| 41 | + public static function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
| 42 | + { |
|
| 43 | + $event_obj = null; |
|
| 44 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 45 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
| 46 | + } |
|
| 47 | + if ($event_obj instanceof EE_Event) { |
|
| 48 | + return $event_obj->total_available_spaces(); |
|
| 49 | + } |
|
| 50 | + throw new EE_Error( |
|
| 51 | + sprintf( |
|
| 52 | + __( |
|
| 53 | + // @codingStandardsIgnoreStart |
|
| 54 | + 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
| 55 | + // @codingStandardsIgnoreEnd |
|
| 56 | + 'event_espresso' |
|
| 57 | + ), |
|
| 58 | + $wpdb_row['Event_CPT.ID'], |
|
| 59 | + print_r($wpdb_row, true) |
|
| 60 | + ) |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
| 68 | + * sales that COULD have been achieved) |
|
| 69 | + * See EE_Event::total_available_spaces( true ); |
|
| 70 | + * |
|
| 71 | + * @param array $wpdb_row |
|
| 72 | + * @param \WP_REST_Request $request |
|
| 73 | + * @param Base $controller |
|
| 74 | + * @return int |
|
| 75 | + * @throws EE_Error |
|
| 76 | + */ |
|
| 77 | + public static function optimumSalesNow($wpdb_row, $request, $controller) |
|
| 78 | + { |
|
| 79 | + $event_obj = null; |
|
| 80 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 81 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
| 82 | + } |
|
| 83 | + if ($event_obj instanceof EE_Event) { |
|
| 84 | + return $event_obj->total_available_spaces(true); |
|
| 85 | + } |
|
| 86 | + throw new EE_Error( |
|
| 87 | + sprintf( |
|
| 88 | + __( |
|
| 89 | + // @codingStandardsIgnoreStart |
|
| 90 | + 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
| 91 | + // @codingStandardsIgnoreEnd |
|
| 92 | + 'event_espresso' |
|
| 93 | + ), |
|
| 94 | + $wpdb_row['Event_CPT.ID'], |
|
| 95 | + print_r($wpdb_row, true) |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Like optimum_sales_now, but minus total sales so far. |
|
| 104 | + * See EE_Event::spaces_remaining_for_sale( true ); |
|
| 105 | + * |
|
| 106 | + * @param array $wpdb_row |
|
| 107 | + * @param \WP_REST_Request $request |
|
| 108 | + * @param Base $controller |
|
| 109 | + * @return int |
|
| 110 | + * @throws EE_Error |
|
| 111 | + */ |
|
| 112 | + public static function spacesRemaining($wpdb_row, $request, $controller) |
|
| 113 | + { |
|
| 114 | + $event_obj = null; |
|
| 115 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 116 | + $event_obj = EEM_Event::instance()->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
| 117 | + } |
|
| 118 | + if ($event_obj instanceof EE_Event) { |
|
| 119 | + return $event_obj->spaces_remaining_for_sale(); |
|
| 120 | + } |
|
| 121 | + throw new EE_Error( |
|
| 122 | + sprintf( |
|
| 123 | + __( |
|
| 124 | + // @codingStandardsIgnoreStart |
|
| 125 | + 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
| 126 | + // @codingStandardsIgnoreEnd |
|
| 127 | + 'event_espresso' |
|
| 128 | + ), |
|
| 129 | + $wpdb_row['Event_CPT.ID'], |
|
| 130 | + print_r($wpdb_row, true) |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Counts the number of approved registrations for this event (regardless |
|
| 139 | + * of how many datetimes each registrations' ticket purchase is for) |
|
| 140 | + * |
|
| 141 | + * @param array $wpdb_row |
|
| 142 | + * @param \WP_REST_Request $request |
|
| 143 | + * @param Base $controller |
|
| 144 | + * @return int |
|
| 145 | + * @throws EE_Error |
|
| 146 | + */ |
|
| 147 | + public static function spotsTaken($wpdb_row, $request, $controller) |
|
| 148 | + { |
|
| 149 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 150 | + throw new EE_Error( |
|
| 151 | + sprintf( |
|
| 152 | + __( |
|
| 153 | + // @codingStandardsIgnoreStart |
|
| 154 | + 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
| 155 | + // @codingStandardsIgnoreEnd |
|
| 156 | + 'event_espresso' |
|
| 157 | + ), |
|
| 158 | + print_r($wpdb_row, true) |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + return EEM_Registration::instance()->count( |
|
| 163 | + array( |
|
| 164 | + array( |
|
| 165 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
| 166 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 167 | + ), |
|
| 168 | + ), |
|
| 169 | + 'REG_ID', |
|
| 170 | + true |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Counts the number of pending-payment registrations for this event (regardless |
|
| 178 | + * of how many datetimes each registrations' ticket purchase is for) |
|
| 179 | + * |
|
| 180 | + * @param array $wpdb_row |
|
| 181 | + * @param \WP_REST_Request $request |
|
| 182 | + * @param Base $controller |
|
| 183 | + * @return int |
|
| 184 | + * @throws EE_Error |
|
| 185 | + * @throws RestException |
|
| 186 | + */ |
|
| 187 | + public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
| 188 | + { |
|
| 189 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 190 | + throw new EE_Error( |
|
| 191 | + sprintf( |
|
| 192 | + __( |
|
| 193 | + // @codingStandardsIgnoreStart |
|
| 194 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 195 | + // @codingStandardsIgnoreEnd |
|
| 196 | + 'event_espresso' |
|
| 197 | + ), |
|
| 198 | + print_r($wpdb_row, true) |
|
| 199 | + ) |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
| 203 | + return EEM_Registration::instance()->count( |
|
| 204 | + array( |
|
| 205 | + array( |
|
| 206 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
| 207 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 208 | + ), |
|
| 209 | + ), |
|
| 210 | + 'REG_ID', |
|
| 211 | + true |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Counts all the registrations who have checked into one of this events' datetimes |
|
| 219 | + * See EE_Event::total_available_spaces( false ); |
|
| 220 | + * |
|
| 221 | + * @param array $wpdb_row |
|
| 222 | + * @param \WP_REST_Request $request |
|
| 223 | + * @param Base $controller |
|
| 224 | + * @return int|null if permission denied |
|
| 225 | + * @throws EE_Error |
|
| 226 | + * @throws RestException |
|
| 227 | + */ |
|
| 228 | + public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
| 229 | + { |
|
| 230 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 231 | + throw new EE_Error( |
|
| 232 | + sprintf( |
|
| 233 | + __( |
|
| 234 | + // @codingStandardsIgnoreStart |
|
| 235 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 236 | + // @codingStandardsIgnoreEnd |
|
| 237 | + 'event_espresso' |
|
| 238 | + ), |
|
| 239 | + print_r($wpdb_row, true) |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
| 244 | + return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Counts all the registrations who have checked out of one of this events' datetimes |
|
| 251 | + * See EE_Event::total_available_spaces( false ); |
|
| 252 | + * |
|
| 253 | + * @param array $wpdb_row |
|
| 254 | + * @param \WP_REST_Request $request |
|
| 255 | + * @param Base $controller |
|
| 256 | + * @return int |
|
| 257 | + * @throws EE_Error |
|
| 258 | + * @throws RestException |
|
| 259 | + */ |
|
| 260 | + public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
| 261 | + { |
|
| 262 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 263 | + throw new EE_Error( |
|
| 264 | + sprintf( |
|
| 265 | + __( |
|
| 266 | + // @codingStandardsIgnoreStart |
|
| 267 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 268 | + // @codingStandardsIgnoreEnd |
|
| 269 | + 'event_espresso' |
|
| 270 | + ), |
|
| 271 | + print_r($wpdb_row, true) |
|
| 272 | + ) |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | + self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
| 276 | + return EEM_Registration::instance()->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Gets the thumbnail image |
|
| 283 | + * |
|
| 284 | + * @param array $wpdb_row |
|
| 285 | + * @param \WP_REST_Request $request |
|
| 286 | + * @param Base $controller |
|
| 287 | + * @return array |
|
| 288 | + * @throws EE_Error |
|
| 289 | + */ |
|
| 290 | + public static function imageThumbnail($wpdb_row, $request, $controller) |
|
| 291 | + { |
|
| 292 | + return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Gets the medium image |
|
| 299 | + * |
|
| 300 | + * @param array $wpdb_row |
|
| 301 | + * @param \WP_REST_Request $request |
|
| 302 | + * @param Base $controller |
|
| 303 | + * @return array |
|
| 304 | + * @throws EE_Error |
|
| 305 | + */ |
|
| 306 | + public static function imageMedium($wpdb_row, $request, $controller) |
|
| 307 | + { |
|
| 308 | + return self::calculateImageData($wpdb_row, 'medium'); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Gets the medium-large image |
|
| 315 | + * |
|
| 316 | + * @param array $wpdb_row |
|
| 317 | + * @param \WP_REST_Request $request |
|
| 318 | + * @param Base $controller |
|
| 319 | + * @return array |
|
| 320 | + * @throws EE_Error |
|
| 321 | + */ |
|
| 322 | + public static function imageMediumLarge($wpdb_row, $request, $controller) |
|
| 323 | + { |
|
| 324 | + return self::calculateImageData($wpdb_row, 'medium_large'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Gets the large image |
|
| 331 | + * |
|
| 332 | + * @param array $wpdb_row |
|
| 333 | + * @param \WP_REST_Request $request |
|
| 334 | + * @param Base $controller |
|
| 335 | + * @return array |
|
| 336 | + * @throws EE_Error |
|
| 337 | + */ |
|
| 338 | + public static function imageLarge($wpdb_row, $request, $controller) |
|
| 339 | + { |
|
| 340 | + return self::calculateImageData($wpdb_row, 'large'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Gets the post-thumbnail image |
|
| 347 | + * |
|
| 348 | + * @param array $wpdb_row |
|
| 349 | + * @param \WP_REST_Request $request |
|
| 350 | + * @param Base $controller |
|
| 351 | + * @return array |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public static function imagePostThumbnail($wpdb_row, $request, $controller) |
|
| 355 | + { |
|
| 356 | + return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Gets the full size image |
|
| 363 | + * |
|
| 364 | + * @param array $wpdb_row |
|
| 365 | + * @param \WP_REST_Request $request |
|
| 366 | + * @param Base $controller |
|
| 367 | + * @return array |
|
| 368 | + * @throws EE_Error |
|
| 369 | + */ |
|
| 370 | + public static function imageFull($wpdb_row, $request, $controller) |
|
| 371 | + { |
|
| 372 | + return self::calculateImageData($wpdb_row, 'full'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Gets image specs and formats them for the display in the API, |
|
| 379 | + * according to the image size requested |
|
| 380 | + * |
|
| 381 | + * @param array $wpdb_row |
|
| 382 | + * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
| 383 | + * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
| 384 | + * @throws EE_Error |
|
| 385 | + */ |
|
| 386 | + protected static function calculateImageData($wpdb_row, $image_size) |
|
| 387 | + { |
|
| 388 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 389 | + throw new EE_Error( |
|
| 390 | + sprintf( |
|
| 391 | + __( |
|
| 392 | + // @codingStandardsIgnoreStart |
|
| 393 | + 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
| 394 | + // @codingStandardsIgnoreEnd |
|
| 395 | + 'event_espresso' |
|
| 396 | + ), |
|
| 397 | + print_r($wpdb_row, true) |
|
| 398 | + ) |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
| 402 | + $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
| 403 | + $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
| 404 | + if (! $data) { |
|
| 405 | + return null; |
|
| 406 | + } |
|
| 407 | + $generated = true; |
|
| 408 | + if (isset($data[3])) { |
|
| 409 | + $generated = $data[3]; |
|
| 410 | + } |
|
| 411 | + return array( |
|
| 412 | + 'url' => $data[0], |
|
| 413 | + 'width' => $data[1], |
|
| 414 | + 'height' => $data[2], |
|
| 415 | + 'generated' => $generated, |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
| 423 | + * @param array $wpdb_row |
|
| 424 | + * @return bool |
|
| 425 | + */ |
|
| 426 | + protected static function wpdbRowHasEventId($wpdb_row) |
|
| 427 | + { |
|
| 428 | + return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
| 429 | + } |
|
| 430 | 430 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @author Mike Nelson |
| 19 | 19 | * @since $VID:$ |
| 20 | 20 | */ |
| 21 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 21 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 22 | 22 | exit('No direct script access allowed'); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public static function spotsTaken($wpdb_row, $request, $controller) |
| 148 | 148 | { |
| 149 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 149 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 150 | 150 | throw new EE_Error( |
| 151 | 151 | sprintf( |
| 152 | 152 | __( |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | public static function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
| 188 | 188 | { |
| 189 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 189 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 190 | 190 | throw new EE_Error( |
| 191 | 191 | sprintf( |
| 192 | 192 | __( |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | public static function registrationsCheckedInCount($wpdb_row, $request, $controller) |
| 229 | 229 | { |
| 230 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 230 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 231 | 231 | throw new EE_Error( |
| 232 | 232 | sprintf( |
| 233 | 233 | __( |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public static function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
| 261 | 261 | { |
| 262 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 262 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 263 | 263 | throw new EE_Error( |
| 264 | 264 | sprintf( |
| 265 | 265 | __( |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | protected static function calculateImageData($wpdb_row, $image_size) |
| 387 | 387 | { |
| 388 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 388 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
| 389 | 389 | throw new EE_Error( |
| 390 | 390 | sprintf( |
| 391 | 391 | __( |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | $EVT_ID = $wpdb_row['Event_CPT.ID']; |
| 402 | 402 | $attachment_id = get_post_thumbnail_id($EVT_ID); |
| 403 | 403 | $data = wp_get_attachment_image_src($attachment_id, $image_size); |
| 404 | - if (! $data) { |
|
| 404 | + if ( ! $data) { |
|
| 405 | 405 | return null; |
| 406 | 406 | } |
| 407 | 407 | $generated = true; |
@@ -140,7 +140,7 @@ |
||
| 140 | 140 | * Sets addon_name |
| 141 | 141 | * |
| 142 | 142 | * @param string $addon_name |
| 143 | - * @return boolean |
|
| 143 | + * @return string |
|
| 144 | 144 | */ |
| 145 | 145 | public function set_name($addon_name) |
| 146 | 146 | { |
@@ -18,287 +18,287 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * prefix to be added onto an addon's plugin slug to make a wp option name |
|
| 23 | - * which will be used to store the plugin's activation history |
|
| 24 | - */ |
|
| 25 | - const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var $_version |
|
| 29 | - * @type string |
|
| 30 | - */ |
|
| 31 | - protected $_version = ''; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var $_min_core_version |
|
| 35 | - * @type string |
|
| 36 | - */ |
|
| 37 | - protected $_min_core_version = ''; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * derived from plugin 'main_file_path using plugin_basename() |
|
| 41 | - * |
|
| 42 | - * @type string $_plugin_basename |
|
| 43 | - */ |
|
| 44 | - protected $_plugin_basename = ''; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * A non-internationalized name to identify this addon for use in URLs, etc |
|
| 48 | - * |
|
| 49 | - * @type string $_plugin_slug |
|
| 50 | - */ |
|
| 51 | - protected $_plugin_slug = ''; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
| 55 | - * |
|
| 56 | - * @type string _addon_name |
|
| 57 | - */ |
|
| 58 | - protected $_addon_name = ''; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * one of the EE_System::req_type_* constants |
|
| 62 | - * |
|
| 63 | - * @type int $_req_type |
|
| 64 | - */ |
|
| 65 | - protected $_req_type; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 69 | - * |
|
| 70 | - * @type string $_plugin_action_slug |
|
| 71 | - */ |
|
| 72 | - protected $_plugin_action_slug = ''; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 76 | - * that can be used for adding upgrading/marketing info |
|
| 77 | - * |
|
| 78 | - * @type array $_plugins_page_row |
|
| 79 | - */ |
|
| 80 | - protected $_plugins_page_row = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var ActivationHistory $activation_history |
|
| 84 | - */ |
|
| 85 | - private $activation_history; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @var RequestType $request_type |
|
| 89 | - */ |
|
| 90 | - private $request_type; |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * class constructor |
|
| 96 | - */ |
|
| 97 | - public function __construct() |
|
| 98 | - { |
|
| 99 | - add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param mixed $version |
|
| 105 | - */ |
|
| 106 | - public function set_version($version = null) |
|
| 107 | - { |
|
| 108 | - $this->_version = $version; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * get__version |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public function version() |
|
| 118 | - { |
|
| 119 | - return $this->_version; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param mixed $min_core_version |
|
| 125 | - */ |
|
| 126 | - public function set_min_core_version($min_core_version = null) |
|
| 127 | - { |
|
| 128 | - $this->_min_core_version = $min_core_version; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * get__min_core_version |
|
| 134 | - * |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - public function min_core_version() |
|
| 138 | - { |
|
| 139 | - return $this->_min_core_version; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Sets addon_name |
|
| 145 | - * |
|
| 146 | - * @param string $addon_name |
|
| 147 | - * @return boolean |
|
| 148 | - */ |
|
| 149 | - public function set_name($addon_name) |
|
| 150 | - { |
|
| 151 | - return $this->_addon_name = $addon_name; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Gets addon_name |
|
| 157 | - * |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function name() |
|
| 161 | - { |
|
| 162 | - return $this->_addon_name; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - public function plugin_basename() |
|
| 170 | - { |
|
| 171 | - |
|
| 172 | - return $this->_plugin_basename; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param string $plugin_basename |
|
| 178 | - */ |
|
| 179 | - public function set_plugin_basename($plugin_basename) |
|
| 180 | - { |
|
| 181 | - |
|
| 182 | - $this->_plugin_basename = $plugin_basename; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function plugin_slug() |
|
| 190 | - { |
|
| 191 | - |
|
| 192 | - return $this->_plugin_slug; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @param string $plugin_slug |
|
| 198 | - */ |
|
| 199 | - public function set_plugin_slug($plugin_slug) |
|
| 200 | - { |
|
| 201 | - |
|
| 202 | - $this->_plugin_slug = $plugin_slug; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - public function plugin_action_slug() |
|
| 210 | - { |
|
| 211 | - |
|
| 212 | - return $this->_plugin_action_slug; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @param string $plugin_action_slug |
|
| 218 | - */ |
|
| 219 | - public function set_plugin_action_slug($plugin_action_slug) |
|
| 220 | - { |
|
| 221 | - |
|
| 222 | - $this->_plugin_action_slug = $plugin_action_slug; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - public function get_plugins_page_row() |
|
| 230 | - { |
|
| 231 | - |
|
| 232 | - return $this->_plugins_page_row; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param array $plugins_page_row |
|
| 238 | - */ |
|
| 239 | - public function set_plugins_page_row($plugins_page_row = array()) |
|
| 240 | - { |
|
| 241 | - // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
| 242 | - if (! is_array($plugins_page_row) |
|
| 243 | - && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
| 244 | - ) { |
|
| 245 | - $plugins_page_row = array(); |
|
| 246 | - } |
|
| 247 | - $this->_plugins_page_row = (array) $plugins_page_row; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Called when EE core detects this addon has been activated for the first time. |
|
| 253 | - * If the site isn't in maintenance mode, should setup the addon's database |
|
| 254 | - * |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - public function new_install() |
|
| 258 | - { |
|
| 259 | - $classname = get_class($this); |
|
| 260 | - do_action("AHEE__{$classname}__new_install"); |
|
| 261 | - do_action('AHEE__EE_Addon__new_install', $this); |
|
| 262 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 263 | - add_action( |
|
| 264 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 265 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 266 | - ); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Called when EE core detects this addon has been reactivated. When this happens, |
|
| 272 | - * it's good to just check that your data is still intact |
|
| 273 | - * |
|
| 274 | - * @return void |
|
| 275 | - */ |
|
| 276 | - public function reactivation() |
|
| 277 | - { |
|
| 278 | - $classname = get_class($this); |
|
| 279 | - do_action("AHEE__{$classname}__reactivation"); |
|
| 280 | - do_action('AHEE__EE_Addon__reactivation', $this); |
|
| 281 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 282 | - add_action( |
|
| 283 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 284 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Called when the registered deactivation hook for this addon fires. |
|
| 291 | - * @throws EE_Error |
|
| 292 | - */ |
|
| 293 | - public function deactivation() |
|
| 294 | - { |
|
| 295 | - $classname = get_class($this); |
|
| 296 | - do_action("AHEE__{$classname}__deactivation"); |
|
| 297 | - do_action('AHEE__EE_Addon__deactivation', $this); |
|
| 298 | - //check if the site no longer needs to be in maintenance mode |
|
| 299 | - EE_Register_Addon::deregister($this->name()); |
|
| 300 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 301 | - } |
|
| 21 | + /** |
|
| 22 | + * prefix to be added onto an addon's plugin slug to make a wp option name |
|
| 23 | + * which will be used to store the plugin's activation history |
|
| 24 | + */ |
|
| 25 | + const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var $_version |
|
| 29 | + * @type string |
|
| 30 | + */ |
|
| 31 | + protected $_version = ''; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var $_min_core_version |
|
| 35 | + * @type string |
|
| 36 | + */ |
|
| 37 | + protected $_min_core_version = ''; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * derived from plugin 'main_file_path using plugin_basename() |
|
| 41 | + * |
|
| 42 | + * @type string $_plugin_basename |
|
| 43 | + */ |
|
| 44 | + protected $_plugin_basename = ''; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * A non-internationalized name to identify this addon for use in URLs, etc |
|
| 48 | + * |
|
| 49 | + * @type string $_plugin_slug |
|
| 50 | + */ |
|
| 51 | + protected $_plugin_slug = ''; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
| 55 | + * |
|
| 56 | + * @type string _addon_name |
|
| 57 | + */ |
|
| 58 | + protected $_addon_name = ''; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * one of the EE_System::req_type_* constants |
|
| 62 | + * |
|
| 63 | + * @type int $_req_type |
|
| 64 | + */ |
|
| 65 | + protected $_req_type; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 69 | + * |
|
| 70 | + * @type string $_plugin_action_slug |
|
| 71 | + */ |
|
| 72 | + protected $_plugin_action_slug = ''; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 76 | + * that can be used for adding upgrading/marketing info |
|
| 77 | + * |
|
| 78 | + * @type array $_plugins_page_row |
|
| 79 | + */ |
|
| 80 | + protected $_plugins_page_row = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @var ActivationHistory $activation_history |
|
| 84 | + */ |
|
| 85 | + private $activation_history; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @var RequestType $request_type |
|
| 89 | + */ |
|
| 90 | + private $request_type; |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * class constructor |
|
| 96 | + */ |
|
| 97 | + public function __construct() |
|
| 98 | + { |
|
| 99 | + add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param mixed $version |
|
| 105 | + */ |
|
| 106 | + public function set_version($version = null) |
|
| 107 | + { |
|
| 108 | + $this->_version = $version; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * get__version |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public function version() |
|
| 118 | + { |
|
| 119 | + return $this->_version; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param mixed $min_core_version |
|
| 125 | + */ |
|
| 126 | + public function set_min_core_version($min_core_version = null) |
|
| 127 | + { |
|
| 128 | + $this->_min_core_version = $min_core_version; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * get__min_core_version |
|
| 134 | + * |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + public function min_core_version() |
|
| 138 | + { |
|
| 139 | + return $this->_min_core_version; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Sets addon_name |
|
| 145 | + * |
|
| 146 | + * @param string $addon_name |
|
| 147 | + * @return boolean |
|
| 148 | + */ |
|
| 149 | + public function set_name($addon_name) |
|
| 150 | + { |
|
| 151 | + return $this->_addon_name = $addon_name; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Gets addon_name |
|
| 157 | + * |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function name() |
|
| 161 | + { |
|
| 162 | + return $this->_addon_name; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + public function plugin_basename() |
|
| 170 | + { |
|
| 171 | + |
|
| 172 | + return $this->_plugin_basename; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param string $plugin_basename |
|
| 178 | + */ |
|
| 179 | + public function set_plugin_basename($plugin_basename) |
|
| 180 | + { |
|
| 181 | + |
|
| 182 | + $this->_plugin_basename = $plugin_basename; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function plugin_slug() |
|
| 190 | + { |
|
| 191 | + |
|
| 192 | + return $this->_plugin_slug; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @param string $plugin_slug |
|
| 198 | + */ |
|
| 199 | + public function set_plugin_slug($plugin_slug) |
|
| 200 | + { |
|
| 201 | + |
|
| 202 | + $this->_plugin_slug = $plugin_slug; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + public function plugin_action_slug() |
|
| 210 | + { |
|
| 211 | + |
|
| 212 | + return $this->_plugin_action_slug; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @param string $plugin_action_slug |
|
| 218 | + */ |
|
| 219 | + public function set_plugin_action_slug($plugin_action_slug) |
|
| 220 | + { |
|
| 221 | + |
|
| 222 | + $this->_plugin_action_slug = $plugin_action_slug; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + public function get_plugins_page_row() |
|
| 230 | + { |
|
| 231 | + |
|
| 232 | + return $this->_plugins_page_row; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param array $plugins_page_row |
|
| 238 | + */ |
|
| 239 | + public function set_plugins_page_row($plugins_page_row = array()) |
|
| 240 | + { |
|
| 241 | + // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
| 242 | + if (! is_array($plugins_page_row) |
|
| 243 | + && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
| 244 | + ) { |
|
| 245 | + $plugins_page_row = array(); |
|
| 246 | + } |
|
| 247 | + $this->_plugins_page_row = (array) $plugins_page_row; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Called when EE core detects this addon has been activated for the first time. |
|
| 253 | + * If the site isn't in maintenance mode, should setup the addon's database |
|
| 254 | + * |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + public function new_install() |
|
| 258 | + { |
|
| 259 | + $classname = get_class($this); |
|
| 260 | + do_action("AHEE__{$classname}__new_install"); |
|
| 261 | + do_action('AHEE__EE_Addon__new_install', $this); |
|
| 262 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 263 | + add_action( |
|
| 264 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 265 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 266 | + ); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Called when EE core detects this addon has been reactivated. When this happens, |
|
| 272 | + * it's good to just check that your data is still intact |
|
| 273 | + * |
|
| 274 | + * @return void |
|
| 275 | + */ |
|
| 276 | + public function reactivation() |
|
| 277 | + { |
|
| 278 | + $classname = get_class($this); |
|
| 279 | + do_action("AHEE__{$classname}__reactivation"); |
|
| 280 | + do_action('AHEE__EE_Addon__reactivation', $this); |
|
| 281 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 282 | + add_action( |
|
| 283 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 284 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Called when the registered deactivation hook for this addon fires. |
|
| 291 | + * @throws EE_Error |
|
| 292 | + */ |
|
| 293 | + public function deactivation() |
|
| 294 | + { |
|
| 295 | + $classname = get_class($this); |
|
| 296 | + do_action("AHEE__{$classname}__deactivation"); |
|
| 297 | + do_action('AHEE__EE_Addon__deactivation', $this); |
|
| 298 | + //check if the site no longer needs to be in maintenance mode |
|
| 299 | + EE_Register_Addon::deregister($this->name()); |
|
| 300 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | 303 | |
| 304 | 304 | |
@@ -348,15 +348,15 @@ discard block |
||
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
| 351 | - /** |
|
| 352 | - * Gets the wp option which stores the activation history for this addon |
|
| 353 | - * |
|
| 354 | - * @return array |
|
| 355 | - */ |
|
| 356 | - public function get_activation_history() |
|
| 357 | - { |
|
| 358 | - return get_option($this->get_activation_history_option_name(), null); |
|
| 359 | - } |
|
| 351 | + /** |
|
| 352 | + * Gets the wp option which stores the activation history for this addon |
|
| 353 | + * |
|
| 354 | + * @return array |
|
| 355 | + */ |
|
| 356 | + public function get_activation_history() |
|
| 357 | + { |
|
| 358 | + return get_option($this->get_activation_history_option_name(), null); |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | 362 | * @param string $config_section |
@@ -370,64 +370,64 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | protected $_main_plugin_file; |
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * Gets the filename (no path) of the main file (the main file loaded |
|
| 375 | - * by WP) |
|
| 376 | - * |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_main_plugin_file_basename() |
|
| 380 | - { |
|
| 381 | - return plugin_basename($this->get_main_plugin_file()); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Gets the folder name which contains the main plugin file |
|
| 386 | - * |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function get_main_plugin_file_dirname() |
|
| 390 | - { |
|
| 391 | - return dirname($this->get_main_plugin_file()); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * sets hooks used in the admin |
|
| 397 | - * |
|
| 398 | - * @return void |
|
| 399 | - */ |
|
| 400 | - public function admin_init() |
|
| 401 | - { |
|
| 402 | - // is admin and not in M-Mode ? |
|
| 403 | - if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 404 | - add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
| 405 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * plugin_actions |
|
| 412 | - * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
| 413 | - * |
|
| 414 | - * @param $links |
|
| 415 | - * @param $file |
|
| 416 | - * @return array |
|
| 417 | - */ |
|
| 418 | - public function plugin_action_links($links, $file) |
|
| 419 | - { |
|
| 420 | - if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
| 421 | - // before other links |
|
| 422 | - array_unshift( |
|
| 423 | - $links, |
|
| 424 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
| 425 | - . esc_html__('Settings', 'event_espresso') |
|
| 426 | - . '</a>' |
|
| 427 | - ); |
|
| 428 | - } |
|
| 429 | - return $links; |
|
| 430 | - } |
|
| 373 | + /** |
|
| 374 | + * Gets the filename (no path) of the main file (the main file loaded |
|
| 375 | + * by WP) |
|
| 376 | + * |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_main_plugin_file_basename() |
|
| 380 | + { |
|
| 381 | + return plugin_basename($this->get_main_plugin_file()); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Gets the folder name which contains the main plugin file |
|
| 386 | + * |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function get_main_plugin_file_dirname() |
|
| 390 | + { |
|
| 391 | + return dirname($this->get_main_plugin_file()); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * sets hooks used in the admin |
|
| 397 | + * |
|
| 398 | + * @return void |
|
| 399 | + */ |
|
| 400 | + public function admin_init() |
|
| 401 | + { |
|
| 402 | + // is admin and not in M-Mode ? |
|
| 403 | + if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 404 | + add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
| 405 | + add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * plugin_actions |
|
| 412 | + * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
| 413 | + * |
|
| 414 | + * @param $links |
|
| 415 | + * @param $file |
|
| 416 | + * @return array |
|
| 417 | + */ |
|
| 418 | + public function plugin_action_links($links, $file) |
|
| 419 | + { |
|
| 420 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
| 421 | + // before other links |
|
| 422 | + array_unshift( |
|
| 423 | + $links, |
|
| 424 | + '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
| 425 | + . esc_html__('Settings', 'event_espresso') |
|
| 426 | + . '</a>' |
|
| 427 | + ); |
|
| 428 | + } |
|
| 429 | + return $links; |
|
| 430 | + } |
|
| 431 | 431 | |
| 432 | 432 | /** |
| 433 | 433 | * plugin_actions |
@@ -446,32 +446,32 @@ discard block |
||
| 446 | 446 | return $links; |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - /** |
|
| 450 | - * after_plugin_row |
|
| 451 | - * Add additional content to the plugins page plugin row |
|
| 452 | - * Inserts another row |
|
| 453 | - * |
|
| 454 | - * @param $plugin_file |
|
| 455 | - * @param $plugin_data |
|
| 456 | - * @param $status |
|
| 457 | - * @return void |
|
| 458 | - */ |
|
| 459 | - public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
| 460 | - { |
|
| 461 | - $after_plugin_row = ''; |
|
| 462 | - $plugins_page_row = $this->get_plugins_page_row(); |
|
| 463 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
| 464 | - $class = $status ? 'active' : 'inactive'; |
|
| 465 | - $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
| 466 | - $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
| 467 | - $description = isset($plugins_page_row['description']) |
|
| 468 | - ? $plugins_page_row['description'] |
|
| 469 | - : ''; |
|
| 470 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
| 471 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
| 472 | - $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
| 473 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
| 474 | - $after_plugin_row .= '<style> |
|
| 449 | + /** |
|
| 450 | + * after_plugin_row |
|
| 451 | + * Add additional content to the plugins page plugin row |
|
| 452 | + * Inserts another row |
|
| 453 | + * |
|
| 454 | + * @param $plugin_file |
|
| 455 | + * @param $plugin_data |
|
| 456 | + * @param $status |
|
| 457 | + * @return void |
|
| 458 | + */ |
|
| 459 | + public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
| 460 | + { |
|
| 461 | + $after_plugin_row = ''; |
|
| 462 | + $plugins_page_row = $this->get_plugins_page_row(); |
|
| 463 | + if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
| 464 | + $class = $status ? 'active' : 'inactive'; |
|
| 465 | + $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
| 466 | + $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
| 467 | + $description = isset($plugins_page_row['description']) |
|
| 468 | + ? $plugins_page_row['description'] |
|
| 469 | + : ''; |
|
| 470 | + if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
| 471 | + $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
| 472 | + $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
| 473 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
| 474 | + $after_plugin_row .= '<style> |
|
| 475 | 475 | .ee-button, |
| 476 | 476 | .ee-button:active, |
| 477 | 477 | .ee-button:visited { |
@@ -508,341 +508,341 @@ discard block |
||
| 508 | 508 | } |
| 509 | 509 | .ee-button:active { top:0; } |
| 510 | 510 | </style>'; |
| 511 | - $after_plugin_row .= ' |
|
| 511 | + $after_plugin_row .= ' |
|
| 512 | 512 | <p class="ee-addon-upsell-info-dv"> |
| 513 | 513 | <a class="ee-button" href="' . $link_url . '">' |
| 514 | - . $link_text |
|
| 515 | - . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
| 516 | - . '</a> |
|
| 514 | + . $link_text |
|
| 515 | + . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
| 516 | + . '</a> |
|
| 517 | 517 | </p>'; |
| 518 | - $after_plugin_row .= '</td>'; |
|
| 519 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
| 520 | - $after_plugin_row .= $description; |
|
| 521 | - $after_plugin_row .= '</td>'; |
|
| 522 | - $after_plugin_row .= '</tr>'; |
|
| 523 | - } else { |
|
| 524 | - $after_plugin_row .= $description; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - echo $after_plugin_row; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
| 534 | - * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
| 535 | - * for back compat reasons. |
|
| 536 | - * |
|
| 537 | - * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
| 538 | - * |
|
| 539 | - * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
| 540 | - * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
| 541 | - * callback does not get run/set in that request. |
|
| 542 | - * |
|
| 543 | - * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
| 544 | - * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
| 545 | - * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
| 546 | - * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
| 547 | - * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
| 548 | - * to call `parent::deactivation`. |
|
| 549 | - * |
|
| 550 | - * @since 4.9.26 |
|
| 551 | - */ |
|
| 552 | - public function after_registration() |
|
| 553 | - { |
|
| 554 | - // cricket chirp... cricket chirp... |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * ensures the activation history property is set |
|
| 561 | - * |
|
| 562 | - * @return void |
|
| 563 | - * @throws InvalidDataTypeException |
|
| 564 | - */ |
|
| 565 | - public function setup_activation_history() |
|
| 566 | - { |
|
| 567 | - if (! $this->activation_history instanceof ActivationHistory) { |
|
| 568 | - $this->setActivationHistory( |
|
| 569 | - new ActivationHistory( |
|
| 570 | - $this->get_activation_history_option_name(), |
|
| 571 | - $this->get_activation_indicator_option_name(), |
|
| 572 | - $this->version() |
|
| 573 | - ) |
|
| 574 | - ); |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Gets the ActivationHistory object for this addon |
|
| 582 | - * |
|
| 583 | - * @return ActivationHistory |
|
| 584 | - * @throws InvalidDataTypeException |
|
| 585 | - */ |
|
| 586 | - public function getActivationHistory() |
|
| 587 | - { |
|
| 588 | - $this->setup_activation_history(); |
|
| 589 | - return $this->activation_history; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * @param ActivationHistory $activation_history |
|
| 596 | - */ |
|
| 597 | - public function setActivationHistory(ActivationHistory $activation_history) |
|
| 598 | - { |
|
| 599 | - $this->activation_history = $activation_history; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * @return RequestType |
|
| 606 | - */ |
|
| 607 | - public function getRequestType() |
|
| 608 | - { |
|
| 609 | - return $this->request_type; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * @param RequestType $request_type |
|
| 616 | - */ |
|
| 617 | - public function setRequestType(RequestType $request_type) |
|
| 618 | - { |
|
| 619 | - $this->request_type = $request_type; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /******************************** DEPRECATED ***************************************/ |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * @deprecated 4.9.44 |
|
| 630 | - * @return array |
|
| 631 | - * @throws InvalidDataTypeException |
|
| 632 | - */ |
|
| 633 | - public function get_activation_history() |
|
| 634 | - { |
|
| 635 | - $this->setup_activation_history(); |
|
| 636 | - return $this->activation_history->getVersionHistory(); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * @deprecated 4.9.44 |
|
| 643 | - * @return void |
|
| 644 | - */ |
|
| 645 | - public function new_install() |
|
| 646 | - { |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * @deprecated 4.9.44 |
|
| 653 | - * @return void |
|
| 654 | - */ |
|
| 655 | - public function reactivation() |
|
| 656 | - { |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @deprecated 4.9.44 |
|
| 663 | - * @return void |
|
| 664 | - */ |
|
| 665 | - public function upgrade() |
|
| 666 | - { |
|
| 667 | - } |
|
| 518 | + $after_plugin_row .= '</td>'; |
|
| 519 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
| 520 | + $after_plugin_row .= $description; |
|
| 521 | + $after_plugin_row .= '</td>'; |
|
| 522 | + $after_plugin_row .= '</tr>'; |
|
| 523 | + } else { |
|
| 524 | + $after_plugin_row .= $description; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + echo $after_plugin_row; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
| 534 | + * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
| 535 | + * for back compat reasons. |
|
| 536 | + * |
|
| 537 | + * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
| 538 | + * |
|
| 539 | + * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
| 540 | + * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
| 541 | + * callback does not get run/set in that request. |
|
| 542 | + * |
|
| 543 | + * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
| 544 | + * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
| 545 | + * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
| 546 | + * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
| 547 | + * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
| 548 | + * to call `parent::deactivation`. |
|
| 549 | + * |
|
| 550 | + * @since 4.9.26 |
|
| 551 | + */ |
|
| 552 | + public function after_registration() |
|
| 553 | + { |
|
| 554 | + // cricket chirp... cricket chirp... |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * ensures the activation history property is set |
|
| 561 | + * |
|
| 562 | + * @return void |
|
| 563 | + * @throws InvalidDataTypeException |
|
| 564 | + */ |
|
| 565 | + public function setup_activation_history() |
|
| 566 | + { |
|
| 567 | + if (! $this->activation_history instanceof ActivationHistory) { |
|
| 568 | + $this->setActivationHistory( |
|
| 569 | + new ActivationHistory( |
|
| 570 | + $this->get_activation_history_option_name(), |
|
| 571 | + $this->get_activation_indicator_option_name(), |
|
| 572 | + $this->version() |
|
| 573 | + ) |
|
| 574 | + ); |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Gets the ActivationHistory object for this addon |
|
| 582 | + * |
|
| 583 | + * @return ActivationHistory |
|
| 584 | + * @throws InvalidDataTypeException |
|
| 585 | + */ |
|
| 586 | + public function getActivationHistory() |
|
| 587 | + { |
|
| 588 | + $this->setup_activation_history(); |
|
| 589 | + return $this->activation_history; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * @param ActivationHistory $activation_history |
|
| 596 | + */ |
|
| 597 | + public function setActivationHistory(ActivationHistory $activation_history) |
|
| 598 | + { |
|
| 599 | + $this->activation_history = $activation_history; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * @return RequestType |
|
| 606 | + */ |
|
| 607 | + public function getRequestType() |
|
| 608 | + { |
|
| 609 | + return $this->request_type; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * @param RequestType $request_type |
|
| 616 | + */ |
|
| 617 | + public function setRequestType(RequestType $request_type) |
|
| 618 | + { |
|
| 619 | + $this->request_type = $request_type; |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /******************************** DEPRECATED ***************************************/ |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * @deprecated 4.9.44 |
|
| 630 | + * @return array |
|
| 631 | + * @throws InvalidDataTypeException |
|
| 632 | + */ |
|
| 633 | + public function get_activation_history() |
|
| 634 | + { |
|
| 635 | + $this->setup_activation_history(); |
|
| 636 | + return $this->activation_history->getVersionHistory(); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * @deprecated 4.9.44 |
|
| 643 | + * @return void |
|
| 644 | + */ |
|
| 645 | + public function new_install() |
|
| 646 | + { |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * @deprecated 4.9.44 |
|
| 653 | + * @return void |
|
| 654 | + */ |
|
| 655 | + public function reactivation() |
|
| 656 | + { |
|
| 657 | + } |
|
| 668 | 658 | |
| 669 | 659 | |
| 670 | 660 | |
| 671 | - /** |
|
| 672 | - * @deprecated 4.9.44 |
|
| 673 | - */ |
|
| 674 | - public function downgrade() |
|
| 675 | - { |
|
| 676 | - } |
|
| 661 | + /** |
|
| 662 | + * @deprecated 4.9.44 |
|
| 663 | + * @return void |
|
| 664 | + */ |
|
| 665 | + public function upgrade() |
|
| 666 | + { |
|
| 667 | + } |
|
| 677 | 668 | |
| 678 | 669 | |
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * set_db_update_option_name |
|
| 682 | - * Until we do something better, we'll just check for migration scripts upon |
|
| 683 | - * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
| 684 | - * |
|
| 685 | - * @deprecated 4.3.0.alpha.016 |
|
| 686 | - * @return bool |
|
| 687 | - */ |
|
| 688 | - public function set_db_update_option_name() |
|
| 689 | - { |
|
| 690 | - EE_Error::doing_it_wrong( |
|
| 691 | - __FUNCTION__, |
|
| 692 | - esc_html__( |
|
| 693 | - 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
| 694 | - 'event_espresso' |
|
| 695 | - ), '4.3.0.alpha.016', |
|
| 696 | - '5.0.0' |
|
| 697 | - ); |
|
| 698 | - //let's just handle this on the next request, ok? right now we're just not really ready |
|
| 699 | - return $this->set_activation_indicator_option(); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * |
|
| 706 | - * Returns the name of the activation indicator option |
|
| 707 | - * (an option which is set temporarily to indicate that this addon was just activated) |
|
| 708 | - * |
|
| 709 | - * @deprecated 4.3.0.alpha.016 |
|
| 710 | - * @return string |
|
| 711 | - */ |
|
| 712 | - public function get_db_update_option_name() |
|
| 713 | - { |
|
| 714 | - EE_Error::doing_it_wrong( |
|
| 715 | - __FUNCTION__, |
|
| 716 | - esc_html__( |
|
| 717 | - 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
| 718 | - 'event_espresso' |
|
| 719 | - ), |
|
| 720 | - '4.3.0.alpha.016', |
|
| 721 | - '5.0.0' |
|
| 722 | - ); |
|
| 723 | - return $this->get_activation_indicator_option_name(); |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * @deprecated 4.9.44 |
|
| 730 | - * @return bool |
|
| 731 | - * @throws InvalidDataTypeException |
|
| 732 | - */ |
|
| 733 | - public function set_activation_indicator_option() |
|
| 734 | - { |
|
| 735 | - $this->setup_activation_history(); |
|
| 736 | - return $this->activation_history->setActivationIndicator(); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * @deprecated 4.9.44 |
|
| 743 | - * @param int $req_type |
|
| 744 | - */ |
|
| 745 | - public function set_req_type($req_type) |
|
| 746 | - { |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * @deprecated 4.9.44 |
|
| 753 | - */ |
|
| 754 | - public function detect_req_type() |
|
| 755 | - { |
|
| 756 | - return $this->getRequestType()->getRequestType(); |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * @deprecated 4.9.44 |
|
| 763 | - * @return void |
|
| 764 | - */ |
|
| 765 | - public function detect_activation_or_upgrade() |
|
| 766 | - { |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * @deprecated 4.9.44 |
|
| 773 | - * @param array $version_history |
|
| 774 | - * @param string $current_version |
|
| 775 | - * @return boolean success |
|
| 776 | - * @throws InvalidDataTypeException |
|
| 777 | - */ |
|
| 778 | - public function update_list_of_installed_versions($version_history = null, $current_version = null) |
|
| 779 | - { |
|
| 780 | - $this->setup_activation_history(); |
|
| 781 | - return $this->activation_history->updateActivationHistory( |
|
| 782 | - $version_history, |
|
| 783 | - $current_version |
|
| 784 | - ); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * @deprecated 4.9.44 |
|
| 791 | - * @param boolean $verify_schema |
|
| 792 | - * @return void |
|
| 793 | - * @throws EE_Error |
|
| 794 | - */ |
|
| 795 | - public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
| 796 | - { |
|
| 797 | - EE_Error::doing_it_wrong( |
|
| 798 | - __FUNCTION__, |
|
| 799 | - sprintf( |
|
| 800 | - esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
|
| 801 | - __METHOD__ . '()', |
|
| 802 | - 'EventEspresso\core\services\activation\InitializeAddon::initialize' |
|
| 803 | - ), |
|
| 804 | - '4.9.44', |
|
| 805 | - '5.0.0' |
|
| 806 | - ); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * @deprecated 4.9.44 |
|
| 813 | - */ |
|
| 814 | - public function initialize_db() |
|
| 815 | - { |
|
| 816 | - EE_Error::doing_it_wrong( |
|
| 817 | - __FUNCTION__, |
|
| 818 | - sprintf( |
|
| 819 | - esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
|
| 820 | - __METHOD__ . '()', |
|
| 821 | - 'EventEspresso\core\services\activation\InitializeAddon::initializeDatabase' |
|
| 822 | - ), |
|
| 823 | - '4.9.44', |
|
| 824 | - '5.0.0' |
|
| 825 | - ); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * @deprecated 4.9.44 |
|
| 832 | - */ |
|
| 833 | - public function initialize_default_data() |
|
| 834 | - { |
|
| 835 | - EE_Error::doing_it_wrong( |
|
| 836 | - __FUNCTION__, |
|
| 837 | - sprintf( |
|
| 838 | - esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
|
| 839 | - __METHOD__.'()', |
|
| 840 | - 'EventEspresso\core\services\activation\InitializeAddon::initializeDefaultData' |
|
| 841 | - ), |
|
| 842 | - '4.9.44', |
|
| 843 | - '5.0.0' |
|
| 844 | - ); |
|
| 845 | - } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * @deprecated 4.9.44 |
|
| 673 | + */ |
|
| 674 | + public function downgrade() |
|
| 675 | + { |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * set_db_update_option_name |
|
| 682 | + * Until we do something better, we'll just check for migration scripts upon |
|
| 683 | + * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
| 684 | + * |
|
| 685 | + * @deprecated 4.3.0.alpha.016 |
|
| 686 | + * @return bool |
|
| 687 | + */ |
|
| 688 | + public function set_db_update_option_name() |
|
| 689 | + { |
|
| 690 | + EE_Error::doing_it_wrong( |
|
| 691 | + __FUNCTION__, |
|
| 692 | + esc_html__( |
|
| 693 | + 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
| 694 | + 'event_espresso' |
|
| 695 | + ), '4.3.0.alpha.016', |
|
| 696 | + '5.0.0' |
|
| 697 | + ); |
|
| 698 | + //let's just handle this on the next request, ok? right now we're just not really ready |
|
| 699 | + return $this->set_activation_indicator_option(); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * |
|
| 706 | + * Returns the name of the activation indicator option |
|
| 707 | + * (an option which is set temporarily to indicate that this addon was just activated) |
|
| 708 | + * |
|
| 709 | + * @deprecated 4.3.0.alpha.016 |
|
| 710 | + * @return string |
|
| 711 | + */ |
|
| 712 | + public function get_db_update_option_name() |
|
| 713 | + { |
|
| 714 | + EE_Error::doing_it_wrong( |
|
| 715 | + __FUNCTION__, |
|
| 716 | + esc_html__( |
|
| 717 | + 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
| 718 | + 'event_espresso' |
|
| 719 | + ), |
|
| 720 | + '4.3.0.alpha.016', |
|
| 721 | + '5.0.0' |
|
| 722 | + ); |
|
| 723 | + return $this->get_activation_indicator_option_name(); |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * @deprecated 4.9.44 |
|
| 730 | + * @return bool |
|
| 731 | + * @throws InvalidDataTypeException |
|
| 732 | + */ |
|
| 733 | + public function set_activation_indicator_option() |
|
| 734 | + { |
|
| 735 | + $this->setup_activation_history(); |
|
| 736 | + return $this->activation_history->setActivationIndicator(); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * @deprecated 4.9.44 |
|
| 743 | + * @param int $req_type |
|
| 744 | + */ |
|
| 745 | + public function set_req_type($req_type) |
|
| 746 | + { |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * @deprecated 4.9.44 |
|
| 753 | + */ |
|
| 754 | + public function detect_req_type() |
|
| 755 | + { |
|
| 756 | + return $this->getRequestType()->getRequestType(); |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * @deprecated 4.9.44 |
|
| 763 | + * @return void |
|
| 764 | + */ |
|
| 765 | + public function detect_activation_or_upgrade() |
|
| 766 | + { |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * @deprecated 4.9.44 |
|
| 773 | + * @param array $version_history |
|
| 774 | + * @param string $current_version |
|
| 775 | + * @return boolean success |
|
| 776 | + * @throws InvalidDataTypeException |
|
| 777 | + */ |
|
| 778 | + public function update_list_of_installed_versions($version_history = null, $current_version = null) |
|
| 779 | + { |
|
| 780 | + $this->setup_activation_history(); |
|
| 781 | + return $this->activation_history->updateActivationHistory( |
|
| 782 | + $version_history, |
|
| 783 | + $current_version |
|
| 784 | + ); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * @deprecated 4.9.44 |
|
| 791 | + * @param boolean $verify_schema |
|
| 792 | + * @return void |
|
| 793 | + * @throws EE_Error |
|
| 794 | + */ |
|
| 795 | + public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
| 796 | + { |
|
| 797 | + EE_Error::doing_it_wrong( |
|
| 798 | + __FUNCTION__, |
|
| 799 | + sprintf( |
|
| 800 | + esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
|
| 801 | + __METHOD__ . '()', |
|
| 802 | + 'EventEspresso\core\services\activation\InitializeAddon::initialize' |
|
| 803 | + ), |
|
| 804 | + '4.9.44', |
|
| 805 | + '5.0.0' |
|
| 806 | + ); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * @deprecated 4.9.44 |
|
| 813 | + */ |
|
| 814 | + public function initialize_db() |
|
| 815 | + { |
|
| 816 | + EE_Error::doing_it_wrong( |
|
| 817 | + __FUNCTION__, |
|
| 818 | + sprintf( |
|
| 819 | + esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
|
| 820 | + __METHOD__ . '()', |
|
| 821 | + 'EventEspresso\core\services\activation\InitializeAddon::initializeDatabase' |
|
| 822 | + ), |
|
| 823 | + '4.9.44', |
|
| 824 | + '5.0.0' |
|
| 825 | + ); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * @deprecated 4.9.44 |
|
| 832 | + */ |
|
| 833 | + public function initialize_default_data() |
|
| 834 | + { |
|
| 835 | + EE_Error::doing_it_wrong( |
|
| 836 | + __FUNCTION__, |
|
| 837 | + sprintf( |
|
| 838 | + esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
|
| 839 | + __METHOD__.'()', |
|
| 840 | + 'EventEspresso\core\services\activation\InitializeAddon::initializeDefaultData' |
|
| 841 | + ), |
|
| 842 | + '4.9.44', |
|
| 843 | + '5.0.0' |
|
| 844 | + ); |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | 847 | |
| 848 | 848 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\services\activation\ActivatableInterface; |
| 5 | 5 | use EventEspresso\core\services\activation\RequestType; |
| 6 | 6 | |
| 7 | -defined('EVENT_ESPRESSO_VERSION' ) || exit( 'No direct script access allowed' ); |
|
| 7 | +defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Class EE_Addon |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | public function set_plugins_page_row($plugins_page_row = array()) |
| 240 | 240 | { |
| 241 | 241 | // sigh.... check for example content that I stupidly merged to master and remove it if found |
| 242 | - if (! is_array($plugins_page_row) |
|
| 242 | + if ( ! is_array($plugins_page_row) |
|
| 243 | 243 | && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
| 244 | 244 | ) { |
| 245 | 245 | $plugins_page_row = array(); |
@@ -306,9 +306,9 @@ discard block |
||
| 306 | 306 | /** |
| 307 | 307 | * @param array|string $plugins_page_row |
| 308 | 308 | */ |
| 309 | - public function set_plugins_page_row( $plugins_page_row = array() ) { |
|
| 309 | + public function set_plugins_page_row($plugins_page_row = array()) { |
|
| 310 | 310 | // sigh.... check for example content that I stupidly merged to master and remove it if found |
| 311 | - if ( ! is_array( $plugins_page_row ) && strpos( $plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>' ) !== false ) { |
|
| 311 | + if ( ! is_array($plugins_page_row) && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false) { |
|
| 312 | 312 | $plugins_page_row = ''; |
| 313 | 313 | } |
| 314 | 314 | $this->_plugins_page_row = $plugins_page_row; |
@@ -316,13 +316,13 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | |
| 318 | 318 | |
| 319 | - public function deactivation(){ |
|
| 319 | + public function deactivation() { |
|
| 320 | 320 | $classname = get_class($this); |
| 321 | 321 | // echo "Deactivating $classname";die; |
| 322 | 322 | do_action("AHEE__{$classname}__deactivation"); |
| 323 | 323 | do_action('AHEE__EE_Addon__deactivation', $this); |
| 324 | 324 | //check if the site no longer needs to be in maintenance mode |
| 325 | - EE_Register_Addon::deregister( $this->name() ); |
|
| 325 | + EE_Register_Addon::deregister($this->name()); |
|
| 326 | 326 | EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
| 327 | 327 | } |
| 328 | 328 | |
@@ -332,8 +332,8 @@ discard block |
||
| 332 | 332 | * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | - public function get_activation_indicator_option_name(){ |
|
| 336 | - return 'ee_activation_' . $this->name(); |
|
| 335 | + public function get_activation_indicator_option_name() { |
|
| 336 | + return 'ee_activation_'.$this->name(); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | * of this addon |
| 344 | 344 | * @return string |
| 345 | 345 | */ |
| 346 | - public function get_activation_history_option_name(){ |
|
| 347 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
| 346 | + public function get_activation_history_option_name() { |
|
| 347 | + return self::ee_addon_version_history_option_prefix.$this->name(); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -361,8 +361,8 @@ discard block |
||
| 361 | 361 | /** |
| 362 | 362 | * @param string $config_section |
| 363 | 363 | */ |
| 364 | - public function set_config_section( $config_section = '' ) { |
|
| 365 | - $this->_config_section = ! empty( $config_section ) ? $config_section : 'addons'; |
|
| 364 | + public function set_config_section($config_section = '') { |
|
| 365 | + $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
| 366 | 366 | } |
| 367 | 367 | /** |
| 368 | 368 | * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | // is admin and not in M-Mode ? |
| 403 | 403 | if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
| 404 | 404 | add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
| 405 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
| 405 | + add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | // before other links |
| 422 | 422 | array_unshift( |
| 423 | 423 | $links, |
| 424 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
| 424 | + '<a href="admin.php?page='.$this->plugin_action_slug().'">' |
|
| 425 | 425 | . esc_html__('Settings', 'event_espresso') |
| 426 | 426 | . '</a>' |
| 427 | 427 | ); |
@@ -438,10 +438,10 @@ discard block |
||
| 438 | 438 | * @param $file |
| 439 | 439 | * @return array |
| 440 | 440 | */ |
| 441 | - public function plugin_action_links( $links, $file ) { |
|
| 442 | - if ( $file === $this->plugin_basename() && $this->plugin_action_slug() !== '' ) { |
|
| 441 | + public function plugin_action_links($links, $file) { |
|
| 442 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
| 443 | 443 | // before other links |
| 444 | - array_unshift( $links, '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . esc_html__( 'Settings' ) . '</a>' ); |
|
| 444 | + array_unshift($links, '<a href="admin.php?page='.$this->plugin_action_slug().'">'.esc_html__('Settings').'</a>'); |
|
| 445 | 445 | } |
| 446 | 446 | return $links; |
| 447 | 447 | } |
@@ -460,15 +460,15 @@ discard block |
||
| 460 | 460 | { |
| 461 | 461 | $after_plugin_row = ''; |
| 462 | 462 | $plugins_page_row = $this->get_plugins_page_row(); |
| 463 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
| 463 | + if ( ! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
| 464 | 464 | $class = $status ? 'active' : 'inactive'; |
| 465 | 465 | $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
| 466 | 466 | $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
| 467 | 467 | $description = isset($plugins_page_row['description']) |
| 468 | 468 | ? $plugins_page_row['description'] |
| 469 | 469 | : ''; |
| 470 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
| 471 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
| 470 | + if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
| 471 | + $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">'; |
|
| 472 | 472 | $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
| 473 | 473 | $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
| 474 | 474 | $after_plugin_row .= '<style> |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | </style>'; |
| 511 | 511 | $after_plugin_row .= ' |
| 512 | 512 | <p class="ee-addon-upsell-info-dv"> |
| 513 | - <a class="ee-button" href="' . $link_url . '">' |
|
| 513 | + <a class="ee-button" href="' . $link_url.'">' |
|
| 514 | 514 | . $link_text |
| 515 | 515 | . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
| 516 | 516 | . '</a> |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | */ |
| 565 | 565 | public function setup_activation_history() |
| 566 | 566 | { |
| 567 | - if (! $this->activation_history instanceof ActivationHistory) { |
|
| 567 | + if ( ! $this->activation_history instanceof ActivationHistory) { |
|
| 568 | 568 | $this->setActivationHistory( |
| 569 | 569 | new ActivationHistory( |
| 570 | 570 | $this->get_activation_history_option_name(), |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | __FUNCTION__, |
| 799 | 799 | sprintf( |
| 800 | 800 | esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
| 801 | - __METHOD__ . '()', |
|
| 801 | + __METHOD__.'()', |
|
| 802 | 802 | 'EventEspresso\core\services\activation\InitializeAddon::initialize' |
| 803 | 803 | ), |
| 804 | 804 | '4.9.44', |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | __FUNCTION__, |
| 818 | 818 | sprintf( |
| 819 | 819 | esc_html__('The logic in "%1$s" was moved to "%2$s"', 'event_espresso'), |
| 820 | - __METHOD__ . '()', |
|
| 820 | + __METHOD__.'()', |
|
| 821 | 821 | 'EventEspresso\core\services\activation\InitializeAddon::initializeDatabase' |
| 822 | 822 | ), |
| 823 | 823 | '4.9.44', |
@@ -18,64 +18,64 @@ |
||
| 18 | 18 | class Context |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string $slug |
|
| 23 | - */ |
|
| 24 | - private $slug; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string $description |
|
| 28 | - */ |
|
| 29 | - private $description; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Context constructor. |
|
| 34 | - * |
|
| 35 | - * @param string $slug |
|
| 36 | - * @param string $description |
|
| 37 | - */ |
|
| 38 | - public function __construct($slug, $description) |
|
| 39 | - { |
|
| 40 | - $this->setSlug($slug); |
|
| 41 | - $this->setDescription($description); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - public function slug() |
|
| 49 | - { |
|
| 50 | - return $this->slug; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param string $slug |
|
| 56 | - */ |
|
| 57 | - private function setSlug($slug) |
|
| 58 | - { |
|
| 59 | - $this->slug = sanitize_key($slug); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function description() |
|
| 67 | - { |
|
| 68 | - return $this->description; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param string $description |
|
| 74 | - */ |
|
| 75 | - private function setDescription($description) |
|
| 76 | - { |
|
| 77 | - $this->description = sanitize_text_field($description); |
|
| 78 | - } |
|
| 21 | + /** |
|
| 22 | + * @var string $slug |
|
| 23 | + */ |
|
| 24 | + private $slug; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string $description |
|
| 28 | + */ |
|
| 29 | + private $description; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Context constructor. |
|
| 34 | + * |
|
| 35 | + * @param string $slug |
|
| 36 | + * @param string $description |
|
| 37 | + */ |
|
| 38 | + public function __construct($slug, $description) |
|
| 39 | + { |
|
| 40 | + $this->setSlug($slug); |
|
| 41 | + $this->setDescription($description); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + public function slug() |
|
| 49 | + { |
|
| 50 | + return $this->slug; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param string $slug |
|
| 56 | + */ |
|
| 57 | + private function setSlug($slug) |
|
| 58 | + { |
|
| 59 | + $this->slug = sanitize_key($slug); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function description() |
|
| 67 | + { |
|
| 68 | + return $this->description; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param string $description |
|
| 74 | + */ |
|
| 75 | + private function setDescription($description) |
|
| 76 | + { |
|
| 77 | + $this->description = sanitize_text_field($description); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | // Location: Context.php |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -27,1980 +27,1980 @@ discard block |
||
| 27 | 27 | class Transactions_Admin_Page extends EE_Admin_Page |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var EE_Transaction |
|
| 32 | - */ |
|
| 33 | - private $_transaction; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var EE_Session |
|
| 37 | - */ |
|
| 38 | - private $_session; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array $_txn_status |
|
| 42 | - */ |
|
| 43 | - private static $_txn_status; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var array $_pay_status |
|
| 47 | - */ |
|
| 48 | - private static $_pay_status; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 52 | - */ |
|
| 53 | - protected $_existing_reg_payment_REG_IDs = null; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @Constructor |
|
| 58 | - * @access public |
|
| 59 | - * |
|
| 60 | - * @param bool $routing |
|
| 61 | - * |
|
| 62 | - * @return Transactions_Admin_Page |
|
| 63 | - */ |
|
| 64 | - public function __construct($routing = true) |
|
| 65 | - { |
|
| 66 | - parent::__construct($routing); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * _init_page_props |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - protected function _init_page_props() |
|
| 75 | - { |
|
| 76 | - $this->page_slug = TXN_PG_SLUG; |
|
| 77 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 78 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 79 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * _ajax_hooks |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - protected function _ajax_hooks() |
|
| 88 | - { |
|
| 89 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 90 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 91 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * _define_page_props |
|
| 97 | - * @return void |
|
| 98 | - */ |
|
| 99 | - protected function _define_page_props() |
|
| 100 | - { |
|
| 101 | - $this->_admin_page_title = $this->page_label; |
|
| 102 | - $this->_labels = array( |
|
| 103 | - 'buttons' => array( |
|
| 104 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 105 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 106 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * grab url requests and route them |
|
| 114 | - * @access private |
|
| 115 | - * @return void |
|
| 116 | - */ |
|
| 117 | - public function _set_page_routes() |
|
| 118 | - { |
|
| 119 | - |
|
| 120 | - $this->_set_transaction_status_array(); |
|
| 121 | - |
|
| 122 | - $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
| 123 | - |
|
| 124 | - $this->_page_routes = array( |
|
| 125 | - |
|
| 126 | - 'default' => array( |
|
| 127 | - 'func' => '_transactions_overview_list_table', |
|
| 128 | - 'capability' => 'ee_read_transactions' |
|
| 129 | - ), |
|
| 130 | - |
|
| 131 | - 'view_transaction' => array( |
|
| 132 | - 'func' => '_transaction_details', |
|
| 133 | - 'capability' => 'ee_read_transaction', |
|
| 134 | - 'obj_id' => $txn_id |
|
| 135 | - ), |
|
| 136 | - |
|
| 137 | - 'send_payment_reminder' => array( |
|
| 138 | - 'func' => '_send_payment_reminder', |
|
| 139 | - 'noheader' => true, |
|
| 140 | - 'capability' => 'ee_send_message' |
|
| 141 | - ), |
|
| 142 | - |
|
| 143 | - 'espresso_apply_payment' => array( |
|
| 144 | - 'func' => 'apply_payments_or_refunds', |
|
| 145 | - 'noheader' => true, |
|
| 146 | - 'capability' => 'ee_edit_payments' |
|
| 147 | - ), |
|
| 148 | - |
|
| 149 | - 'espresso_apply_refund' => array( |
|
| 150 | - 'func' => 'apply_payments_or_refunds', |
|
| 151 | - 'noheader' => true, |
|
| 152 | - 'capability' => 'ee_edit_payments' |
|
| 153 | - ), |
|
| 154 | - |
|
| 155 | - 'espresso_delete_payment' => array( |
|
| 156 | - 'func' => 'delete_payment', |
|
| 157 | - 'noheader' => true, |
|
| 158 | - 'capability' => 'ee_delete_payments' |
|
| 159 | - ), |
|
| 160 | - |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - protected function _set_page_config() |
|
| 167 | - { |
|
| 168 | - $this->_page_config = array( |
|
| 169 | - 'default' => array( |
|
| 170 | - 'nav' => array( |
|
| 171 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 172 | - 'order' => 10 |
|
| 173 | - ), |
|
| 174 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 175 | - 'help_tabs' => array( |
|
| 176 | - 'transactions_overview_help_tab' => array( |
|
| 177 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 178 | - 'filename' => 'transactions_overview' |
|
| 179 | - ), |
|
| 180 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 181 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 182 | - 'filename' => 'transactions_overview_table_column_headings' |
|
| 183 | - ), |
|
| 184 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 185 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 186 | - 'filename' => 'transactions_overview_views_filters_search' |
|
| 187 | - ), |
|
| 188 | - ), |
|
| 189 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 190 | - /** |
|
| 191 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 192 | - * may change in a later iteration so want to keep the code for then. |
|
| 193 | - */ |
|
| 194 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 195 | - 'require_nonce' => false |
|
| 196 | - ), |
|
| 197 | - 'view_transaction' => array( |
|
| 198 | - 'nav' => array( |
|
| 199 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 200 | - 'order' => 5, |
|
| 201 | - 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
| 202 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 203 | - 'persistent' => false |
|
| 204 | - ), |
|
| 205 | - 'help_tabs' => array( |
|
| 206 | - 'transactions_view_transaction_help_tab' => array( |
|
| 207 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 208 | - 'filename' => 'transactions_view_transaction' |
|
| 209 | - ), |
|
| 210 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 211 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 212 | - 'filename' => 'transactions_view_transaction_transaction_details_table' |
|
| 213 | - ), |
|
| 214 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 215 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 216 | - 'filename' => 'transactions_view_transaction_attendees_registered' |
|
| 217 | - ), |
|
| 218 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 219 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 220 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
|
| 221 | - ), |
|
| 222 | - ), |
|
| 223 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 224 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 225 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 226 | - |
|
| 227 | - 'require_nonce' => false |
|
| 228 | - ) |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * The below methods aren't used by this class currently |
|
| 235 | - */ |
|
| 236 | - protected function _add_screen_options() |
|
| 237 | - { |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - protected function _add_feature_pointers() |
|
| 241 | - { |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function admin_init() |
|
| 245 | - { |
|
| 246 | - // IF a registration was JUST added via the admin... |
|
| 247 | - if ( |
|
| 248 | - isset( |
|
| 249 | - $this->_req_data['redirect_from'], |
|
| 250 | - $this->_req_data['EVT_ID'], |
|
| 251 | - $this->_req_data['event_name'] |
|
| 252 | - ) |
|
| 253 | - ) { |
|
| 254 | - // then set a cookie so that we can block any attempts to use |
|
| 255 | - // the back button as a way to enter another registration. |
|
| 256 | - setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
| 257 | - // and update the global |
|
| 258 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 259 | - } |
|
| 260 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 261 | - 'event_espresso'); |
|
| 262 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
| 263 | - 'event_espresso'); |
|
| 264 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
| 268 | - 'event_espresso'); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - public function admin_notices() |
|
| 272 | - { |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function admin_footer_scripts() |
|
| 276 | - { |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * _set_transaction_status_array |
|
| 282 | - * sets list of transaction statuses |
|
| 283 | - * |
|
| 284 | - * @access private |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 287 | - private function _set_transaction_status_array() |
|
| 288 | - { |
|
| 289 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * get_transaction_status_array |
|
| 295 | - * return the transaction status array for wp_list_table |
|
| 296 | - * |
|
| 297 | - * @access public |
|
| 298 | - * @return array |
|
| 299 | - */ |
|
| 300 | - public function get_transaction_status_array() |
|
| 301 | - { |
|
| 302 | - return self::$_txn_status; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * get list of payment statuses |
|
| 308 | - * |
|
| 309 | - * @access private |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - private function _get_payment_status_array() |
|
| 313 | - { |
|
| 314 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 315 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 316 | - |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * _add_screen_options_default |
|
| 322 | - * |
|
| 323 | - * @access protected |
|
| 324 | - * @return void |
|
| 325 | - */ |
|
| 326 | - protected function _add_screen_options_default() |
|
| 327 | - { |
|
| 328 | - $this->_per_page_screen_option(); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * load_scripts_styles |
|
| 334 | - * |
|
| 335 | - * @access public |
|
| 336 | - * @return void |
|
| 337 | - */ |
|
| 338 | - public function load_scripts_styles() |
|
| 339 | - { |
|
| 340 | - //enqueue style |
|
| 341 | - wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 342 | - EVENT_ESPRESSO_VERSION); |
|
| 343 | - wp_enqueue_style('espresso_txn'); |
|
| 344 | - //scripts |
|
| 345 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 346 | - 'ee_admin_js', |
|
| 347 | - 'ee-datepicker', |
|
| 348 | - 'jquery-ui-datepicker', |
|
| 349 | - 'jquery-ui-draggable', |
|
| 350 | - 'ee-dialog', |
|
| 351 | - 'ee-accounting', |
|
| 352 | - 'ee-serialize-full-array' |
|
| 353 | - ), EVENT_ESPRESSO_VERSION, true); |
|
| 354 | - wp_enqueue_script('espresso_txn'); |
|
| 355 | - |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * load_scripts_styles_view_transaction |
|
| 361 | - * |
|
| 362 | - * @access public |
|
| 363 | - * @return void |
|
| 364 | - */ |
|
| 365 | - public function load_scripts_styles_view_transaction() |
|
| 366 | - { |
|
| 367 | - //styles |
|
| 368 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * load_scripts_styles_default |
|
| 374 | - * |
|
| 375 | - * @access public |
|
| 376 | - * @return void |
|
| 377 | - */ |
|
| 378 | - public function load_scripts_styles_default() |
|
| 379 | - { |
|
| 380 | - //styles |
|
| 381 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * _set_list_table_views_default |
|
| 387 | - * |
|
| 388 | - * @access protected |
|
| 389 | - * @return void |
|
| 390 | - */ |
|
| 391 | - protected function _set_list_table_views_default() |
|
| 392 | - { |
|
| 393 | - $this->_views = array( |
|
| 394 | - 'all' => array( |
|
| 395 | - 'slug' => 'all', |
|
| 396 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 397 | - 'count' => 0 |
|
| 398 | - ), |
|
| 399 | - 'abandoned' => array( |
|
| 400 | - 'slug' => 'abandoned', |
|
| 401 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 402 | - 'count' => 0 |
|
| 403 | - ), |
|
| 404 | - 'failed' => array( |
|
| 405 | - 'slug' => 'failed', |
|
| 406 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 407 | - 'count' => 0 |
|
| 408 | - ) |
|
| 409 | - ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * _set_transaction_object |
|
| 415 | - * This sets the _transaction property for the transaction details screen |
|
| 416 | - * |
|
| 417 | - * @access private |
|
| 418 | - * @return void |
|
| 419 | - */ |
|
| 420 | - private function _set_transaction_object() |
|
| 421 | - { |
|
| 422 | - if (is_object($this->_transaction)) { |
|
| 423 | - return; |
|
| 424 | - } //get out we've already set the object |
|
| 425 | - |
|
| 426 | - $TXN = EEM_Transaction::instance(); |
|
| 427 | - |
|
| 428 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 429 | - |
|
| 430 | - //get transaction object |
|
| 431 | - $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
| 432 | - $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
| 433 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 434 | - |
|
| 435 | - if (empty($this->_transaction)) { |
|
| 436 | - $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
| 437 | - 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 438 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * _transaction_legend_items |
|
| 445 | - * |
|
| 446 | - * @access protected |
|
| 447 | - * @return array |
|
| 448 | - */ |
|
| 449 | - protected function _transaction_legend_items() |
|
| 450 | - { |
|
| 451 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 452 | - $items = array(); |
|
| 453 | - |
|
| 454 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 455 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 456 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 457 | - $items['view_related_messages'] = array( |
|
| 458 | - 'class' => $related_for_icon['css_class'], |
|
| 459 | - 'desc' => $related_for_icon['label'], |
|
| 460 | - ); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - $items = apply_filters( |
|
| 465 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 466 | - array_merge($items, |
|
| 467 | - array( |
|
| 468 | - 'view_details' => array( |
|
| 469 | - 'class' => 'dashicons dashicons-cart', |
|
| 470 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso') |
|
| 471 | - ), |
|
| 472 | - 'view_invoice' => array( |
|
| 473 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 474 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso') |
|
| 475 | - ), |
|
| 476 | - 'view_receipt' => array( |
|
| 477 | - 'class' => 'dashicons dashicons-media-default', |
|
| 478 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso') |
|
| 479 | - ), |
|
| 480 | - 'view_registration' => array( |
|
| 481 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 482 | - 'desc' => esc_html__('View Registration Details', 'event_espresso') |
|
| 483 | - ), |
|
| 484 | - 'payment_overview_link' => array( |
|
| 485 | - 'class' => 'dashicons dashicons-money', |
|
| 486 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso') |
|
| 487 | - ) |
|
| 488 | - ) |
|
| 489 | - ) |
|
| 490 | - ); |
|
| 491 | - |
|
| 492 | - if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 493 | - 'espresso_transactions_send_payment_reminder') |
|
| 494 | - ) { |
|
| 495 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 496 | - $items['send_payment_reminder'] = array( |
|
| 497 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 498 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso') |
|
| 499 | - ); |
|
| 500 | - } else { |
|
| 501 | - $items['blank*'] = array( |
|
| 502 | - 'class' => '', |
|
| 503 | - 'desc' => '' |
|
| 504 | - ); |
|
| 505 | - } |
|
| 506 | - } else { |
|
| 507 | - $items['blank*'] = array( |
|
| 508 | - 'class' => '', |
|
| 509 | - 'desc' => '' |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - $more_items = apply_filters( |
|
| 513 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 514 | - array( |
|
| 515 | - 'overpaid' => array( |
|
| 516 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 517 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
|
| 518 | - ), |
|
| 519 | - 'complete' => array( |
|
| 520 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 521 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
|
| 522 | - ), |
|
| 523 | - 'incomplete' => array( |
|
| 524 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 525 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
|
| 526 | - ), |
|
| 527 | - 'abandoned' => array( |
|
| 528 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 529 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
|
| 530 | - ), |
|
| 531 | - 'failed' => array( |
|
| 532 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 533 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
|
| 534 | - ) |
|
| 535 | - ) |
|
| 536 | - ); |
|
| 537 | - |
|
| 538 | - return array_merge($items, $more_items); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * _transactions_overview_list_table |
|
| 544 | - * |
|
| 545 | - * @access protected |
|
| 546 | - * @return void |
|
| 547 | - */ |
|
| 548 | - protected function _transactions_overview_list_table() |
|
| 549 | - { |
|
| 550 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 551 | - $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
| 552 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
| 553 | - 'event_espresso'), '<h3>', |
|
| 554 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 555 | - EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 556 | - 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 557 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 558 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * _transaction_details |
|
| 564 | - * generates HTML for the View Transaction Details Admin page |
|
| 565 | - * |
|
| 566 | - * @access protected |
|
| 567 | - * @return void |
|
| 568 | - */ |
|
| 569 | - protected function _transaction_details() |
|
| 570 | - { |
|
| 571 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 572 | - |
|
| 573 | - $this->_set_transaction_status_array(); |
|
| 574 | - |
|
| 575 | - $this->_template_args = array(); |
|
| 576 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 577 | - |
|
| 578 | - $this->_set_transaction_object(); |
|
| 579 | - |
|
| 580 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 581 | - $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
| 582 | - |
|
| 583 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 584 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 585 | - |
|
| 586 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 587 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 588 | - |
|
| 589 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 590 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 591 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 592 | - |
|
| 593 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 594 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 595 | - |
|
| 596 | - if ( |
|
| 597 | - $attendee instanceof EE_Attendee |
|
| 598 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 599 | - 'ee_send_message', |
|
| 600 | - 'espresso_transactions_send_payment_reminder' |
|
| 601 | - ) |
|
| 602 | - ) { |
|
| 603 | - $this->_template_args['send_payment_reminder_button'] = |
|
| 604 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 605 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
| 606 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
| 607 | - ? EEH_Template::get_button_or_link( |
|
| 608 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 609 | - array( |
|
| 610 | - 'action' => 'send_payment_reminder', |
|
| 611 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 612 | - 'redirect_to' => 'view_transaction' |
|
| 613 | - ), |
|
| 614 | - TXN_ADMIN_URL |
|
| 615 | - ), |
|
| 616 | - __(' Send Payment Reminder', 'event_espresso'), |
|
| 617 | - 'button secondary-button right', |
|
| 618 | - 'dashicons dashicons-email-alt' |
|
| 619 | - ) |
|
| 620 | - : ''; |
|
| 621 | - } else { |
|
| 622 | - $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 626 | - $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
| 627 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 628 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 629 | - } else { |
|
| 630 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 631 | - } |
|
| 632 | - $this->_template_args['amount_due_class'] = ''; |
|
| 633 | - |
|
| 634 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 635 | - // paid in full |
|
| 636 | - $this->_template_args['amount_due'] = false; |
|
| 637 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 638 | - // overpaid |
|
| 639 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 640 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
| 641 | - // monies owing |
|
| 642 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 643 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
| 644 | - // no payments made yet |
|
| 645 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 646 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 647 | - // free event |
|
| 648 | - $this->_template_args['amount_due'] = false; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - $payment_method = $this->_transaction->payment_method(); |
|
| 652 | - |
|
| 653 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 654 | - ? $payment_method->admin_name() |
|
| 655 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 656 | - |
|
| 657 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 658 | - // link back to overview |
|
| 659 | - $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
| 660 | - ? $_SERVER['HTTP_REFERER'] |
|
| 661 | - : TXN_ADMIN_URL; |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - // next link |
|
| 665 | - $next_txn = $this->_transaction->next( |
|
| 666 | - null, |
|
| 667 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 668 | - 'TXN_ID' |
|
| 669 | - ); |
|
| 670 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 671 | - ? $this->_next_link( |
|
| 672 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 673 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 674 | - TXN_ADMIN_URL |
|
| 675 | - ), |
|
| 676 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 677 | - ) |
|
| 678 | - : ''; |
|
| 679 | - // previous link |
|
| 680 | - $previous_txn = $this->_transaction->previous( |
|
| 681 | - null, |
|
| 682 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 683 | - 'TXN_ID' |
|
| 684 | - ); |
|
| 685 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 686 | - ? $this->_previous_link( |
|
| 687 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 688 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 689 | - TXN_ADMIN_URL |
|
| 690 | - ), |
|
| 691 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 692 | - ) |
|
| 693 | - : ''; |
|
| 694 | - |
|
| 695 | - // were we just redirected here after adding a new registration ??? |
|
| 696 | - if ( |
|
| 697 | - isset( |
|
| 698 | - $this->_req_data['redirect_from'], |
|
| 699 | - $this->_req_data['EVT_ID'], |
|
| 700 | - $this->_req_data['event_name'] |
|
| 701 | - ) |
|
| 702 | - ) { |
|
| 703 | - if ( |
|
| 704 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 705 | - 'ee_edit_registrations', |
|
| 706 | - 'espresso_registrations_new_registration', |
|
| 707 | - $this->_req_data['EVT_ID'] |
|
| 708 | - ) |
|
| 709 | - ) { |
|
| 710 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 711 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 712 | - array( |
|
| 713 | - 'page' => 'espresso_registrations', |
|
| 714 | - 'action' => 'new_registration', |
|
| 715 | - 'return' => 'default', |
|
| 716 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 717 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 718 | - ), |
|
| 719 | - REG_ADMIN_URL |
|
| 720 | - ); |
|
| 721 | - $this->_admin_page_title .= '">'; |
|
| 722 | - |
|
| 723 | - $this->_admin_page_title .= sprintf( |
|
| 724 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 725 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 726 | - ); |
|
| 727 | - $this->_admin_page_title .= '</a>'; |
|
| 728 | - } |
|
| 729 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 730 | - } |
|
| 731 | - // grab messages at the last second |
|
| 732 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 733 | - // path to template |
|
| 734 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 735 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 736 | - $this->_template_args, true); |
|
| 737 | - |
|
| 738 | - // the details template wrapper |
|
| 739 | - $this->display_admin_page_with_sidebar(); |
|
| 740 | - |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * _transaction_details_metaboxes |
|
| 746 | - * |
|
| 747 | - * @access protected |
|
| 748 | - * @return void |
|
| 749 | - */ |
|
| 750 | - protected function _transaction_details_metaboxes() |
|
| 751 | - { |
|
| 752 | - |
|
| 753 | - $this->_set_transaction_object(); |
|
| 754 | - |
|
| 755 | - add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
| 756 | - array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
| 757 | - add_meta_box( |
|
| 758 | - 'edit-txn-attendees-mbox', |
|
| 759 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 760 | - array($this, 'txn_attendees_meta_box'), |
|
| 761 | - $this->_wp_page_slug, |
|
| 762 | - 'normal', |
|
| 763 | - 'high', |
|
| 764 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 765 | - ); |
|
| 766 | - add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
| 767 | - array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 768 | - add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
| 769 | - array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 770 | - |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * txn_details_meta_box |
|
| 776 | - * generates HTML for the Transaction main meta box |
|
| 777 | - * |
|
| 778 | - * @access public |
|
| 779 | - * @return void |
|
| 780 | - */ |
|
| 781 | - public function txn_details_meta_box() |
|
| 782 | - { |
|
| 783 | - |
|
| 784 | - $this->_set_transaction_object(); |
|
| 785 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 786 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
| 787 | - |
|
| 788 | - //get line table |
|
| 789 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 790 | - $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
| 791 | - 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
| 792 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
| 793 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
| 794 | - |
|
| 795 | - // process taxes |
|
| 796 | - $taxes = $this->_transaction->get_many_related('Line_Item', |
|
| 797 | - array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 798 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 799 | - |
|
| 800 | - $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
| 801 | - false, false); |
|
| 802 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 803 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 30 | + /** |
|
| 31 | + * @var EE_Transaction |
|
| 32 | + */ |
|
| 33 | + private $_transaction; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var EE_Session |
|
| 37 | + */ |
|
| 38 | + private $_session; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array $_txn_status |
|
| 42 | + */ |
|
| 43 | + private static $_txn_status; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var array $_pay_status |
|
| 47 | + */ |
|
| 48 | + private static $_pay_status; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 52 | + */ |
|
| 53 | + protected $_existing_reg_payment_REG_IDs = null; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @Constructor |
|
| 58 | + * @access public |
|
| 59 | + * |
|
| 60 | + * @param bool $routing |
|
| 61 | + * |
|
| 62 | + * @return Transactions_Admin_Page |
|
| 63 | + */ |
|
| 64 | + public function __construct($routing = true) |
|
| 65 | + { |
|
| 66 | + parent::__construct($routing); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * _init_page_props |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + protected function _init_page_props() |
|
| 75 | + { |
|
| 76 | + $this->page_slug = TXN_PG_SLUG; |
|
| 77 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 78 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 79 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * _ajax_hooks |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + protected function _ajax_hooks() |
|
| 88 | + { |
|
| 89 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 90 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 91 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * _define_page_props |
|
| 97 | + * @return void |
|
| 98 | + */ |
|
| 99 | + protected function _define_page_props() |
|
| 100 | + { |
|
| 101 | + $this->_admin_page_title = $this->page_label; |
|
| 102 | + $this->_labels = array( |
|
| 103 | + 'buttons' => array( |
|
| 104 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 105 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 106 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * grab url requests and route them |
|
| 114 | + * @access private |
|
| 115 | + * @return void |
|
| 116 | + */ |
|
| 117 | + public function _set_page_routes() |
|
| 118 | + { |
|
| 119 | + |
|
| 120 | + $this->_set_transaction_status_array(); |
|
| 121 | + |
|
| 122 | + $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
| 123 | + |
|
| 124 | + $this->_page_routes = array( |
|
| 125 | + |
|
| 126 | + 'default' => array( |
|
| 127 | + 'func' => '_transactions_overview_list_table', |
|
| 128 | + 'capability' => 'ee_read_transactions' |
|
| 129 | + ), |
|
| 130 | + |
|
| 131 | + 'view_transaction' => array( |
|
| 132 | + 'func' => '_transaction_details', |
|
| 133 | + 'capability' => 'ee_read_transaction', |
|
| 134 | + 'obj_id' => $txn_id |
|
| 135 | + ), |
|
| 136 | + |
|
| 137 | + 'send_payment_reminder' => array( |
|
| 138 | + 'func' => '_send_payment_reminder', |
|
| 139 | + 'noheader' => true, |
|
| 140 | + 'capability' => 'ee_send_message' |
|
| 141 | + ), |
|
| 142 | + |
|
| 143 | + 'espresso_apply_payment' => array( |
|
| 144 | + 'func' => 'apply_payments_or_refunds', |
|
| 145 | + 'noheader' => true, |
|
| 146 | + 'capability' => 'ee_edit_payments' |
|
| 147 | + ), |
|
| 148 | + |
|
| 149 | + 'espresso_apply_refund' => array( |
|
| 150 | + 'func' => 'apply_payments_or_refunds', |
|
| 151 | + 'noheader' => true, |
|
| 152 | + 'capability' => 'ee_edit_payments' |
|
| 153 | + ), |
|
| 154 | + |
|
| 155 | + 'espresso_delete_payment' => array( |
|
| 156 | + 'func' => 'delete_payment', |
|
| 157 | + 'noheader' => true, |
|
| 158 | + 'capability' => 'ee_delete_payments' |
|
| 159 | + ), |
|
| 160 | + |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + protected function _set_page_config() |
|
| 167 | + { |
|
| 168 | + $this->_page_config = array( |
|
| 169 | + 'default' => array( |
|
| 170 | + 'nav' => array( |
|
| 171 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 172 | + 'order' => 10 |
|
| 173 | + ), |
|
| 174 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 175 | + 'help_tabs' => array( |
|
| 176 | + 'transactions_overview_help_tab' => array( |
|
| 177 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 178 | + 'filename' => 'transactions_overview' |
|
| 179 | + ), |
|
| 180 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 181 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 182 | + 'filename' => 'transactions_overview_table_column_headings' |
|
| 183 | + ), |
|
| 184 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 185 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 186 | + 'filename' => 'transactions_overview_views_filters_search' |
|
| 187 | + ), |
|
| 188 | + ), |
|
| 189 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 190 | + /** |
|
| 191 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 192 | + * may change in a later iteration so want to keep the code for then. |
|
| 193 | + */ |
|
| 194 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 195 | + 'require_nonce' => false |
|
| 196 | + ), |
|
| 197 | + 'view_transaction' => array( |
|
| 198 | + 'nav' => array( |
|
| 199 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 200 | + 'order' => 5, |
|
| 201 | + 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
| 202 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 203 | + 'persistent' => false |
|
| 204 | + ), |
|
| 205 | + 'help_tabs' => array( |
|
| 206 | + 'transactions_view_transaction_help_tab' => array( |
|
| 207 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 208 | + 'filename' => 'transactions_view_transaction' |
|
| 209 | + ), |
|
| 210 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 211 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 212 | + 'filename' => 'transactions_view_transaction_transaction_details_table' |
|
| 213 | + ), |
|
| 214 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 215 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 216 | + 'filename' => 'transactions_view_transaction_attendees_registered' |
|
| 217 | + ), |
|
| 218 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 219 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 220 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
|
| 221 | + ), |
|
| 222 | + ), |
|
| 223 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 224 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 225 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 226 | + |
|
| 227 | + 'require_nonce' => false |
|
| 228 | + ) |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * The below methods aren't used by this class currently |
|
| 235 | + */ |
|
| 236 | + protected function _add_screen_options() |
|
| 237 | + { |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + protected function _add_feature_pointers() |
|
| 241 | + { |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function admin_init() |
|
| 245 | + { |
|
| 246 | + // IF a registration was JUST added via the admin... |
|
| 247 | + if ( |
|
| 248 | + isset( |
|
| 249 | + $this->_req_data['redirect_from'], |
|
| 250 | + $this->_req_data['EVT_ID'], |
|
| 251 | + $this->_req_data['event_name'] |
|
| 252 | + ) |
|
| 253 | + ) { |
|
| 254 | + // then set a cookie so that we can block any attempts to use |
|
| 255 | + // the back button as a way to enter another registration. |
|
| 256 | + setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
| 257 | + // and update the global |
|
| 258 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 259 | + } |
|
| 260 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 261 | + 'event_espresso'); |
|
| 262 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
| 263 | + 'event_espresso'); |
|
| 264 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
| 268 | + 'event_espresso'); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + public function admin_notices() |
|
| 272 | + { |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function admin_footer_scripts() |
|
| 276 | + { |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * _set_transaction_status_array |
|
| 282 | + * sets list of transaction statuses |
|
| 283 | + * |
|
| 284 | + * @access private |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | + private function _set_transaction_status_array() |
|
| 288 | + { |
|
| 289 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * get_transaction_status_array |
|
| 295 | + * return the transaction status array for wp_list_table |
|
| 296 | + * |
|
| 297 | + * @access public |
|
| 298 | + * @return array |
|
| 299 | + */ |
|
| 300 | + public function get_transaction_status_array() |
|
| 301 | + { |
|
| 302 | + return self::$_txn_status; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * get list of payment statuses |
|
| 308 | + * |
|
| 309 | + * @access private |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + private function _get_payment_status_array() |
|
| 313 | + { |
|
| 314 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 315 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 316 | + |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * _add_screen_options_default |
|
| 322 | + * |
|
| 323 | + * @access protected |
|
| 324 | + * @return void |
|
| 325 | + */ |
|
| 326 | + protected function _add_screen_options_default() |
|
| 327 | + { |
|
| 328 | + $this->_per_page_screen_option(); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * load_scripts_styles |
|
| 334 | + * |
|
| 335 | + * @access public |
|
| 336 | + * @return void |
|
| 337 | + */ |
|
| 338 | + public function load_scripts_styles() |
|
| 339 | + { |
|
| 340 | + //enqueue style |
|
| 341 | + wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 342 | + EVENT_ESPRESSO_VERSION); |
|
| 343 | + wp_enqueue_style('espresso_txn'); |
|
| 344 | + //scripts |
|
| 345 | + wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 346 | + 'ee_admin_js', |
|
| 347 | + 'ee-datepicker', |
|
| 348 | + 'jquery-ui-datepicker', |
|
| 349 | + 'jquery-ui-draggable', |
|
| 350 | + 'ee-dialog', |
|
| 351 | + 'ee-accounting', |
|
| 352 | + 'ee-serialize-full-array' |
|
| 353 | + ), EVENT_ESPRESSO_VERSION, true); |
|
| 354 | + wp_enqueue_script('espresso_txn'); |
|
| 355 | + |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * load_scripts_styles_view_transaction |
|
| 361 | + * |
|
| 362 | + * @access public |
|
| 363 | + * @return void |
|
| 364 | + */ |
|
| 365 | + public function load_scripts_styles_view_transaction() |
|
| 366 | + { |
|
| 367 | + //styles |
|
| 368 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * load_scripts_styles_default |
|
| 374 | + * |
|
| 375 | + * @access public |
|
| 376 | + * @return void |
|
| 377 | + */ |
|
| 378 | + public function load_scripts_styles_default() |
|
| 379 | + { |
|
| 380 | + //styles |
|
| 381 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * _set_list_table_views_default |
|
| 387 | + * |
|
| 388 | + * @access protected |
|
| 389 | + * @return void |
|
| 390 | + */ |
|
| 391 | + protected function _set_list_table_views_default() |
|
| 392 | + { |
|
| 393 | + $this->_views = array( |
|
| 394 | + 'all' => array( |
|
| 395 | + 'slug' => 'all', |
|
| 396 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 397 | + 'count' => 0 |
|
| 398 | + ), |
|
| 399 | + 'abandoned' => array( |
|
| 400 | + 'slug' => 'abandoned', |
|
| 401 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 402 | + 'count' => 0 |
|
| 403 | + ), |
|
| 404 | + 'failed' => array( |
|
| 405 | + 'slug' => 'failed', |
|
| 406 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 407 | + 'count' => 0 |
|
| 408 | + ) |
|
| 409 | + ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * _set_transaction_object |
|
| 415 | + * This sets the _transaction property for the transaction details screen |
|
| 416 | + * |
|
| 417 | + * @access private |
|
| 418 | + * @return void |
|
| 419 | + */ |
|
| 420 | + private function _set_transaction_object() |
|
| 421 | + { |
|
| 422 | + if (is_object($this->_transaction)) { |
|
| 423 | + return; |
|
| 424 | + } //get out we've already set the object |
|
| 425 | + |
|
| 426 | + $TXN = EEM_Transaction::instance(); |
|
| 427 | + |
|
| 428 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 429 | + |
|
| 430 | + //get transaction object |
|
| 431 | + $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
| 432 | + $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
| 433 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 434 | + |
|
| 435 | + if (empty($this->_transaction)) { |
|
| 436 | + $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
| 437 | + 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 438 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * _transaction_legend_items |
|
| 445 | + * |
|
| 446 | + * @access protected |
|
| 447 | + * @return array |
|
| 448 | + */ |
|
| 449 | + protected function _transaction_legend_items() |
|
| 450 | + { |
|
| 451 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 452 | + $items = array(); |
|
| 453 | + |
|
| 454 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 455 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 456 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 457 | + $items['view_related_messages'] = array( |
|
| 458 | + 'class' => $related_for_icon['css_class'], |
|
| 459 | + 'desc' => $related_for_icon['label'], |
|
| 460 | + ); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + $items = apply_filters( |
|
| 465 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 466 | + array_merge($items, |
|
| 467 | + array( |
|
| 468 | + 'view_details' => array( |
|
| 469 | + 'class' => 'dashicons dashicons-cart', |
|
| 470 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso') |
|
| 471 | + ), |
|
| 472 | + 'view_invoice' => array( |
|
| 473 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 474 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso') |
|
| 475 | + ), |
|
| 476 | + 'view_receipt' => array( |
|
| 477 | + 'class' => 'dashicons dashicons-media-default', |
|
| 478 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso') |
|
| 479 | + ), |
|
| 480 | + 'view_registration' => array( |
|
| 481 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 482 | + 'desc' => esc_html__('View Registration Details', 'event_espresso') |
|
| 483 | + ), |
|
| 484 | + 'payment_overview_link' => array( |
|
| 485 | + 'class' => 'dashicons dashicons-money', |
|
| 486 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso') |
|
| 487 | + ) |
|
| 488 | + ) |
|
| 489 | + ) |
|
| 490 | + ); |
|
| 491 | + |
|
| 492 | + if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 493 | + 'espresso_transactions_send_payment_reminder') |
|
| 494 | + ) { |
|
| 495 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 496 | + $items['send_payment_reminder'] = array( |
|
| 497 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 498 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso') |
|
| 499 | + ); |
|
| 500 | + } else { |
|
| 501 | + $items['blank*'] = array( |
|
| 502 | + 'class' => '', |
|
| 503 | + 'desc' => '' |
|
| 504 | + ); |
|
| 505 | + } |
|
| 506 | + } else { |
|
| 507 | + $items['blank*'] = array( |
|
| 508 | + 'class' => '', |
|
| 509 | + 'desc' => '' |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + $more_items = apply_filters( |
|
| 513 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 514 | + array( |
|
| 515 | + 'overpaid' => array( |
|
| 516 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 517 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
|
| 518 | + ), |
|
| 519 | + 'complete' => array( |
|
| 520 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 521 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
|
| 522 | + ), |
|
| 523 | + 'incomplete' => array( |
|
| 524 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 525 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
|
| 526 | + ), |
|
| 527 | + 'abandoned' => array( |
|
| 528 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 529 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
|
| 530 | + ), |
|
| 531 | + 'failed' => array( |
|
| 532 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 533 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
|
| 534 | + ) |
|
| 535 | + ) |
|
| 536 | + ); |
|
| 537 | + |
|
| 538 | + return array_merge($items, $more_items); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * _transactions_overview_list_table |
|
| 544 | + * |
|
| 545 | + * @access protected |
|
| 546 | + * @return void |
|
| 547 | + */ |
|
| 548 | + protected function _transactions_overview_list_table() |
|
| 549 | + { |
|
| 550 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 551 | + $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
| 552 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
| 553 | + 'event_espresso'), '<h3>', |
|
| 554 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 555 | + EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 556 | + 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 557 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 558 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * _transaction_details |
|
| 564 | + * generates HTML for the View Transaction Details Admin page |
|
| 565 | + * |
|
| 566 | + * @access protected |
|
| 567 | + * @return void |
|
| 568 | + */ |
|
| 569 | + protected function _transaction_details() |
|
| 570 | + { |
|
| 571 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 572 | + |
|
| 573 | + $this->_set_transaction_status_array(); |
|
| 574 | + |
|
| 575 | + $this->_template_args = array(); |
|
| 576 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 577 | + |
|
| 578 | + $this->_set_transaction_object(); |
|
| 579 | + |
|
| 580 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 581 | + $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
| 582 | + |
|
| 583 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 584 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 585 | + |
|
| 586 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 587 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 588 | + |
|
| 589 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 590 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 591 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 592 | + |
|
| 593 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 594 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 595 | + |
|
| 596 | + if ( |
|
| 597 | + $attendee instanceof EE_Attendee |
|
| 598 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 599 | + 'ee_send_message', |
|
| 600 | + 'espresso_transactions_send_payment_reminder' |
|
| 601 | + ) |
|
| 602 | + ) { |
|
| 603 | + $this->_template_args['send_payment_reminder_button'] = |
|
| 604 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 605 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
| 606 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
| 607 | + ? EEH_Template::get_button_or_link( |
|
| 608 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 609 | + array( |
|
| 610 | + 'action' => 'send_payment_reminder', |
|
| 611 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 612 | + 'redirect_to' => 'view_transaction' |
|
| 613 | + ), |
|
| 614 | + TXN_ADMIN_URL |
|
| 615 | + ), |
|
| 616 | + __(' Send Payment Reminder', 'event_espresso'), |
|
| 617 | + 'button secondary-button right', |
|
| 618 | + 'dashicons dashicons-email-alt' |
|
| 619 | + ) |
|
| 620 | + : ''; |
|
| 621 | + } else { |
|
| 622 | + $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 626 | + $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
| 627 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 628 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 629 | + } else { |
|
| 630 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 631 | + } |
|
| 632 | + $this->_template_args['amount_due_class'] = ''; |
|
| 633 | + |
|
| 634 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 635 | + // paid in full |
|
| 636 | + $this->_template_args['amount_due'] = false; |
|
| 637 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 638 | + // overpaid |
|
| 639 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 640 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
| 641 | + // monies owing |
|
| 642 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 643 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
| 644 | + // no payments made yet |
|
| 645 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 646 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 647 | + // free event |
|
| 648 | + $this->_template_args['amount_due'] = false; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + $payment_method = $this->_transaction->payment_method(); |
|
| 652 | + |
|
| 653 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 654 | + ? $payment_method->admin_name() |
|
| 655 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 656 | + |
|
| 657 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 658 | + // link back to overview |
|
| 659 | + $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
| 660 | + ? $_SERVER['HTTP_REFERER'] |
|
| 661 | + : TXN_ADMIN_URL; |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + // next link |
|
| 665 | + $next_txn = $this->_transaction->next( |
|
| 666 | + null, |
|
| 667 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 668 | + 'TXN_ID' |
|
| 669 | + ); |
|
| 670 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 671 | + ? $this->_next_link( |
|
| 672 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 673 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 674 | + TXN_ADMIN_URL |
|
| 675 | + ), |
|
| 676 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 677 | + ) |
|
| 678 | + : ''; |
|
| 679 | + // previous link |
|
| 680 | + $previous_txn = $this->_transaction->previous( |
|
| 681 | + null, |
|
| 682 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 683 | + 'TXN_ID' |
|
| 684 | + ); |
|
| 685 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 686 | + ? $this->_previous_link( |
|
| 687 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 688 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 689 | + TXN_ADMIN_URL |
|
| 690 | + ), |
|
| 691 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 692 | + ) |
|
| 693 | + : ''; |
|
| 694 | + |
|
| 695 | + // were we just redirected here after adding a new registration ??? |
|
| 696 | + if ( |
|
| 697 | + isset( |
|
| 698 | + $this->_req_data['redirect_from'], |
|
| 699 | + $this->_req_data['EVT_ID'], |
|
| 700 | + $this->_req_data['event_name'] |
|
| 701 | + ) |
|
| 702 | + ) { |
|
| 703 | + if ( |
|
| 704 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 705 | + 'ee_edit_registrations', |
|
| 706 | + 'espresso_registrations_new_registration', |
|
| 707 | + $this->_req_data['EVT_ID'] |
|
| 708 | + ) |
|
| 709 | + ) { |
|
| 710 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 711 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 712 | + array( |
|
| 713 | + 'page' => 'espresso_registrations', |
|
| 714 | + 'action' => 'new_registration', |
|
| 715 | + 'return' => 'default', |
|
| 716 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 717 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 718 | + ), |
|
| 719 | + REG_ADMIN_URL |
|
| 720 | + ); |
|
| 721 | + $this->_admin_page_title .= '">'; |
|
| 722 | + |
|
| 723 | + $this->_admin_page_title .= sprintf( |
|
| 724 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 725 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 726 | + ); |
|
| 727 | + $this->_admin_page_title .= '</a>'; |
|
| 728 | + } |
|
| 729 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 730 | + } |
|
| 731 | + // grab messages at the last second |
|
| 732 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 733 | + // path to template |
|
| 734 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 735 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 736 | + $this->_template_args, true); |
|
| 737 | + |
|
| 738 | + // the details template wrapper |
|
| 739 | + $this->display_admin_page_with_sidebar(); |
|
| 740 | + |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * _transaction_details_metaboxes |
|
| 746 | + * |
|
| 747 | + * @access protected |
|
| 748 | + * @return void |
|
| 749 | + */ |
|
| 750 | + protected function _transaction_details_metaboxes() |
|
| 751 | + { |
|
| 752 | + |
|
| 753 | + $this->_set_transaction_object(); |
|
| 754 | + |
|
| 755 | + add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
| 756 | + array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
| 757 | + add_meta_box( |
|
| 758 | + 'edit-txn-attendees-mbox', |
|
| 759 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 760 | + array($this, 'txn_attendees_meta_box'), |
|
| 761 | + $this->_wp_page_slug, |
|
| 762 | + 'normal', |
|
| 763 | + 'high', |
|
| 764 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 765 | + ); |
|
| 766 | + add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
| 767 | + array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 768 | + add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
| 769 | + array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 770 | + |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * txn_details_meta_box |
|
| 776 | + * generates HTML for the Transaction main meta box |
|
| 777 | + * |
|
| 778 | + * @access public |
|
| 779 | + * @return void |
|
| 780 | + */ |
|
| 781 | + public function txn_details_meta_box() |
|
| 782 | + { |
|
| 783 | + |
|
| 784 | + $this->_set_transaction_object(); |
|
| 785 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 786 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
| 787 | + |
|
| 788 | + //get line table |
|
| 789 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 790 | + $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
| 791 | + 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
| 792 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
| 793 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
| 794 | + |
|
| 795 | + // process taxes |
|
| 796 | + $taxes = $this->_transaction->get_many_related('Line_Item', |
|
| 797 | + array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 798 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 799 | + |
|
| 800 | + $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
| 801 | + false, false); |
|
| 802 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 803 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 804 | 804 | |
| 805 | 805 | // $txn_status_class = 'status-' . $this->_transaction->get('STS_ID'); |
| 806 | 806 | |
| 807 | - // process payment details |
|
| 808 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
| 809 | - if ( ! empty($payments)) { |
|
| 810 | - $this->_template_args['payments'] = $payments; |
|
| 811 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 812 | - } else { |
|
| 813 | - $this->_template_args['payments'] = false; |
|
| 814 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 818 | - $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
| 819 | - TXN_ADMIN_URL); |
|
| 820 | - |
|
| 821 | - if (isset($txn_details['invoice_number'])) { |
|
| 822 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 823 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
| 824 | - 'event_espresso'); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
| 828 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
| 829 | - 'event_espresso'); |
|
| 830 | - |
|
| 831 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
| 832 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
| 833 | - 'event_espresso'); |
|
| 834 | - |
|
| 835 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
| 836 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 837 | - 'event_espresso'); |
|
| 838 | - |
|
| 839 | - $reg_steps = '<ul>'; |
|
| 840 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 841 | - if ($reg_step_status === true) { |
|
| 842 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 843 | - ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 844 | - } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 845 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 846 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 847 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 848 | - date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 849 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
| 850 | - ) . '</li>'; |
|
| 851 | - } else { |
|
| 852 | - $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 853 | - 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - $reg_steps .= '</ul>'; |
|
| 857 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 858 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
| 859 | - 'event_espresso'); |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 863 | - $this->_get_payment_methods($payments); |
|
| 864 | - $this->_get_payment_status_array(); |
|
| 865 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 866 | - |
|
| 867 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 868 | - 'action' => 'edit_transaction', |
|
| 869 | - 'process' => 'transaction' |
|
| 870 | - ), TXN_ADMIN_URL); |
|
| 871 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 872 | - 'page' => 'espresso_transactions', |
|
| 873 | - 'action' => 'espresso_apply_payment' |
|
| 874 | - ), WP_AJAX_URL); |
|
| 875 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 876 | - 'page' => 'espresso_transactions', |
|
| 877 | - 'action' => 'espresso_delete_payment' |
|
| 878 | - ), WP_AJAX_URL); |
|
| 879 | - |
|
| 880 | - // 'espresso_delete_payment_nonce' |
|
| 881 | - |
|
| 882 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 883 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 884 | - |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * _get_registration_payment_IDs |
|
| 890 | - * |
|
| 891 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 892 | - * |
|
| 893 | - * @access protected |
|
| 894 | - * |
|
| 895 | - * @param EE_Payment[] $payments |
|
| 896 | - * |
|
| 897 | - * @return array |
|
| 898 | - */ |
|
| 899 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 900 | - { |
|
| 901 | - $existing_reg_payments = array(); |
|
| 902 | - // get all reg payments for these payments |
|
| 903 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 904 | - array( |
|
| 905 | - 'PAY_ID' => array( |
|
| 906 | - 'IN', |
|
| 907 | - array_keys($payments) |
|
| 908 | - ) |
|
| 909 | - ) |
|
| 910 | - )); |
|
| 911 | - if ( ! empty($reg_payments)) { |
|
| 912 | - foreach ($payments as $payment) { |
|
| 913 | - if ( ! $payment instanceof EE_Payment) { |
|
| 914 | - continue; |
|
| 915 | - } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 916 | - $existing_reg_payments[$payment->ID()] = array(); |
|
| 917 | - } |
|
| 918 | - foreach ($reg_payments as $reg_payment) { |
|
| 919 | - if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
| 920 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - return $existing_reg_payments; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * _get_registrations_to_apply_payment_to |
|
| 932 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 933 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 934 | - * |
|
| 935 | - * @access protected |
|
| 936 | - * @return void |
|
| 937 | - * @throws \EE_Error |
|
| 938 | - */ |
|
| 939 | - protected function _get_registrations_to_apply_payment_to() |
|
| 940 | - { |
|
| 941 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 942 | - $query_params = array( |
|
| 943 | - array( |
|
| 944 | - 'STS_ID' => array( |
|
| 945 | - 'IN', |
|
| 946 | - array( |
|
| 947 | - EEM_Registration::status_id_approved, |
|
| 948 | - EEM_Registration::status_id_pending_payment, |
|
| 949 | - EEM_Registration::status_id_not_approved, |
|
| 950 | - ) |
|
| 951 | - ) |
|
| 952 | - ) |
|
| 953 | - ); |
|
| 954 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 955 | - '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 956 | - ); |
|
| 957 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 958 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 959 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 960 | - EEH_HTML::tr( |
|
| 961 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 962 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 963 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 964 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 965 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 966 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 967 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 968 | - ) |
|
| 969 | - ); |
|
| 970 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 971 | - // get registrations for TXN |
|
| 972 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 973 | - foreach ($registrations as $registration) { |
|
| 974 | - if ($registration instanceof EE_Registration) { |
|
| 975 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 976 | - ? $registration->attendee()->full_name() |
|
| 977 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 978 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 979 | - $taxable = $registration->ticket()->taxable() |
|
| 980 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 981 | - : ''; |
|
| 982 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 983 | - ? ' checked="checked"' |
|
| 984 | - : ''; |
|
| 985 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 986 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 987 | - EEH_HTML::td($registration->ID()) . |
|
| 988 | - EEH_HTML::td($attendee_name) . |
|
| 989 | - EEH_HTML::td( |
|
| 990 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 991 | - ) . |
|
| 992 | - EEH_HTML::td($registration->event_name()) . |
|
| 993 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 994 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 995 | - EEH_HTML::td( |
|
| 996 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 997 | - . '" name="txn_admin_payment[registrations]"' |
|
| 998 | - . $checked . $disabled . '>', |
|
| 999 | - '', 'jst-cntr' |
|
| 1000 | - ), |
|
| 1001 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1002 | - ); |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 1005 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1006 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1007 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1008 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1009 | - esc_html__( |
|
| 1010 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1011 | - 'event_espresso' |
|
| 1012 | - ), |
|
| 1013 | - '', 'clear description' |
|
| 1014 | - ); |
|
| 1015 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1016 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - |
|
| 1020 | - /** |
|
| 1021 | - * _get_reg_status_selection |
|
| 1022 | - * |
|
| 1023 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1024 | - * instead of events. |
|
| 1025 | - * @access protected |
|
| 1026 | - * @return void |
|
| 1027 | - */ |
|
| 1028 | - protected function _get_reg_status_selection() |
|
| 1029 | - { |
|
| 1030 | - //first get all possible statuses |
|
| 1031 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1032 | - //let's add a "don't change" option. |
|
| 1033 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1034 | - $status_array = array_merge($status_array, $statuses); |
|
| 1035 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
| 1036 | - $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
| 1037 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
| 1038 | - $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
| 1039 | - |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * _get_payment_methods |
|
| 1045 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1046 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1047 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1048 | - * @access private |
|
| 1049 | - * |
|
| 1050 | - * @param EE_Payment[] to show on this page |
|
| 1051 | - * |
|
| 1052 | - * @return void |
|
| 1053 | - */ |
|
| 1054 | - private function _get_payment_methods($payments = array()) |
|
| 1055 | - { |
|
| 1056 | - $payment_methods_of_payments = array(); |
|
| 1057 | - foreach ($payments as $payment) { |
|
| 1058 | - if ($payment instanceof EE_Payment) { |
|
| 1059 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1060 | - } |
|
| 1061 | - } |
|
| 1062 | - if ($payment_methods_of_payments) { |
|
| 1063 | - $query_args = array( |
|
| 1064 | - array( |
|
| 1065 | - 'OR*payment_method_for_payment' => array( |
|
| 1066 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1067 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1068 | - ) |
|
| 1069 | - ) |
|
| 1070 | - ); |
|
| 1071 | - } else { |
|
| 1072 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1073 | - } |
|
| 1074 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * txn_attendees_meta_box |
|
| 1080 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1081 | - * |
|
| 1082 | - * @access public |
|
| 1083 | - * |
|
| 1084 | - * @param WP_Post $post |
|
| 1085 | - * @param array $metabox |
|
| 1086 | - * |
|
| 1087 | - * @return void |
|
| 1088 | - */ |
|
| 1089 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1090 | - { |
|
| 1091 | - |
|
| 1092 | - extract($metabox['args']); |
|
| 1093 | - $this->_template_args['post'] = $post; |
|
| 1094 | - $this->_template_args['event_attendees'] = array(); |
|
| 1095 | - // process items in cart |
|
| 1096 | - $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
| 1097 | - if ( ! empty($line_items)) { |
|
| 1098 | - foreach ($line_items as $item) { |
|
| 1099 | - if ($item instanceof EE_Line_Item) { |
|
| 1100 | - switch ($item->OBJ_type()) { |
|
| 1101 | - |
|
| 1102 | - case 'Event' : |
|
| 1103 | - break; |
|
| 1104 | - |
|
| 1105 | - case 'Ticket' : |
|
| 1106 | - $ticket = $item->ticket(); |
|
| 1107 | - //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
| 1108 | - if ( ! $ticket instanceof EE_Ticket) { |
|
| 1109 | - continue; |
|
| 1110 | - } |
|
| 1111 | - try { |
|
| 1112 | - $event_name = $ticket->get_event_name(); |
|
| 1113 | - } catch (Exception $e) { |
|
| 1114 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1116 | - } |
|
| 1117 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1118 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1119 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1120 | - $registrations = $ticket->get_many_related('Registration', |
|
| 1121 | - array(array('TXN_ID' => $this->_transaction->ID()))); |
|
| 1122 | - foreach ($registrations as $registration) { |
|
| 1123 | - if ( ! $registration instanceof EE_Registration) { |
|
| 1124 | - continue; |
|
| 1125 | - } |
|
| 1126 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
| 1127 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
| 1128 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 1129 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 1130 | - // attendee info |
|
| 1131 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1132 | - if ($attendee instanceof EE_Attendee) { |
|
| 1133 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
| 1134 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
| 1135 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1136 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1137 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
| 1138 | - 'inline', false, false); |
|
| 1139 | - } else { |
|
| 1140 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1141 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1142 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1143 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - break; |
|
| 1147 | - |
|
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1153 | - 'action' => 'edit_transaction', |
|
| 1154 | - 'process' => 'attendees' |
|
| 1155 | - ), TXN_ADMIN_URL); |
|
| 1156 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1157 | - $this->_template_args, true); |
|
| 1158 | - |
|
| 1159 | - } else { |
|
| 1160 | - echo sprintf( |
|
| 1161 | - esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1162 | - 'event_espresso'), |
|
| 1163 | - '<p class="important-notice">', |
|
| 1164 | - '</p>' |
|
| 1165 | - ); |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * txn_registrant_side_meta_box |
|
| 1172 | - * generates HTML for the Edit Transaction side meta box |
|
| 1173 | - * |
|
| 1174 | - * @access public |
|
| 1175 | - * @throws \EE_Error |
|
| 1176 | - * @return void |
|
| 1177 | - */ |
|
| 1178 | - public function txn_registrant_side_meta_box() |
|
| 1179 | - { |
|
| 1180 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
| 1181 | - if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1182 | - $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1183 | - 'event_espresso'); |
|
| 1184 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1185 | - } |
|
| 1186 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1187 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1188 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1189 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1190 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1191 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1192 | - 'action' => 'edit_attendee', |
|
| 1193 | - 'post' => $primary_att->ID() |
|
| 1194 | - ), REG_ADMIN_URL); |
|
| 1195 | - // get formatted address for registrant |
|
| 1196 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1197 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1198 | - $this->_template_args, true); |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - |
|
| 1202 | - /** |
|
| 1203 | - * txn_billing_info_side_meta_box |
|
| 1204 | - * generates HTML for the Edit Transaction side meta box |
|
| 1205 | - * |
|
| 1206 | - * @access public |
|
| 1207 | - * @return void |
|
| 1208 | - */ |
|
| 1209 | - public function txn_billing_info_side_meta_box() |
|
| 1210 | - { |
|
| 1211 | - |
|
| 1212 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1213 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1214 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1215 | - TXN_ADMIN_URL |
|
| 1216 | - ); |
|
| 1217 | - |
|
| 1218 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1219 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * apply_payments_or_refunds |
|
| 1225 | - * registers a payment or refund made towards a transaction |
|
| 1226 | - * |
|
| 1227 | - * @access public |
|
| 1228 | - * @return void |
|
| 1229 | - */ |
|
| 1230 | - public function apply_payments_or_refunds() |
|
| 1231 | - { |
|
| 1232 | - $json_response_data = array('return_data' => false); |
|
| 1233 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1234 | - if ( ! empty($valid_data)) { |
|
| 1235 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1236 | - //save the new payment |
|
| 1237 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1238 | - // get the TXN for this payment |
|
| 1239 | - $transaction = $payment->transaction(); |
|
| 1240 | - // verify transaction |
|
| 1241 | - if ($transaction instanceof EE_Transaction) { |
|
| 1242 | - // calculate_total_payments_and_update_status |
|
| 1243 | - $this->_process_transaction_payments($transaction); |
|
| 1244 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1245 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1246 | - // apply payment to registrations (if applicable) |
|
| 1247 | - if ( ! empty($REG_IDs)) { |
|
| 1248 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1249 | - $this->_maybe_send_notifications(); |
|
| 1250 | - // now process status changes for the same registrations |
|
| 1251 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1252 | - } |
|
| 1253 | - $this->_maybe_send_notifications($payment); |
|
| 1254 | - //prepare to render page |
|
| 1255 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1256 | - do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
| 1257 | - $payment); |
|
| 1258 | - } else { |
|
| 1259 | - EE_Error::add_error( |
|
| 1260 | - esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
| 1261 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1262 | - ); |
|
| 1263 | - } |
|
| 1264 | - } else { |
|
| 1265 | - EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
| 1266 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1270 | - $this->_template_args = array( |
|
| 1271 | - 'data' => $json_response_data, |
|
| 1272 | - 'error' => $notices['errors'], |
|
| 1273 | - 'success' => $notices['success'] |
|
| 1274 | - ); |
|
| 1275 | - $this->_return_json(); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * _validate_payment_request_data |
|
| 1281 | - * |
|
| 1282 | - * @return array |
|
| 1283 | - */ |
|
| 1284 | - protected function _validate_payment_request_data() |
|
| 1285 | - { |
|
| 1286 | - if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1287 | - return false; |
|
| 1288 | - } |
|
| 1289 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1290 | - try { |
|
| 1291 | - if ($payment_form->was_submitted()) { |
|
| 1292 | - $payment_form->receive_form_submission(); |
|
| 1293 | - if ( ! $payment_form->is_valid()) { |
|
| 1294 | - $submission_error_messages = array(); |
|
| 1295 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1296 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1297 | - $submission_error_messages[] = sprintf( |
|
| 1298 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1299 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1300 | - $validation_error->getMessage() |
|
| 1301 | - ); |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1304 | - EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1305 | - |
|
| 1306 | - return array(); |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - } catch (EE_Error $e) { |
|
| 1310 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1311 | - |
|
| 1312 | - return array(); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - return $payment_form->valid_data(); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - /** |
|
| 1320 | - * _generate_payment_form_section |
|
| 1321 | - * |
|
| 1322 | - * @return EE_Form_Section_Proper |
|
| 1323 | - */ |
|
| 1324 | - protected function _generate_payment_form_section() |
|
| 1325 | - { |
|
| 1326 | - return new EE_Form_Section_Proper( |
|
| 1327 | - array( |
|
| 1328 | - 'name' => 'txn_admin_payment', |
|
| 1329 | - 'subsections' => array( |
|
| 1330 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1331 | - array( |
|
| 1332 | - 'default' => 0, |
|
| 1333 | - 'required' => false, |
|
| 1334 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1335 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1336 | - ) |
|
| 1337 | - ), |
|
| 1338 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1339 | - array( |
|
| 1340 | - 'default' => 0, |
|
| 1341 | - 'required' => true, |
|
| 1342 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1343 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1344 | - ) |
|
| 1345 | - ), |
|
| 1346 | - 'type' => new EE_Text_Input( |
|
| 1347 | - array( |
|
| 1348 | - 'default' => 1, |
|
| 1349 | - 'required' => true, |
|
| 1350 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1351 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1352 | - ) |
|
| 1353 | - ), |
|
| 1354 | - 'amount' => new EE_Text_Input( |
|
| 1355 | - array( |
|
| 1356 | - 'default' => 0, |
|
| 1357 | - 'required' => true, |
|
| 1358 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1359 | - 'validation_strategies' => array(new EE_Float_Normalization()) |
|
| 1360 | - ) |
|
| 1361 | - ), |
|
| 1362 | - 'status' => new EE_Text_Input( |
|
| 1363 | - array( |
|
| 1364 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1365 | - 'required' => true, |
|
| 1366 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1367 | - ) |
|
| 1368 | - ), |
|
| 1369 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1370 | - array( |
|
| 1371 | - 'default' => 2, |
|
| 1372 | - 'required' => true, |
|
| 1373 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1374 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1375 | - ) |
|
| 1376 | - ), |
|
| 1377 | - 'date' => new EE_Text_Input( |
|
| 1378 | - array( |
|
| 1379 | - 'default' => time(), |
|
| 1380 | - 'required' => true, |
|
| 1381 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1382 | - ) |
|
| 1383 | - ), |
|
| 1384 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1385 | - array( |
|
| 1386 | - 'default' => '', |
|
| 1387 | - 'required' => false, |
|
| 1388 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1389 | - 'validation_strategies' => array( |
|
| 1390 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1391 | - 100), |
|
| 1392 | - ) |
|
| 1393 | - ) |
|
| 1394 | - ), |
|
| 1395 | - 'po_number' => new EE_Text_Input( |
|
| 1396 | - array( |
|
| 1397 | - 'default' => '', |
|
| 1398 | - 'required' => false, |
|
| 1399 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1400 | - 'validation_strategies' => array( |
|
| 1401 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1402 | - 100), |
|
| 1403 | - ) |
|
| 1404 | - ) |
|
| 1405 | - ), |
|
| 1406 | - 'accounting' => new EE_Text_Input( |
|
| 1407 | - array( |
|
| 1408 | - 'default' => '', |
|
| 1409 | - 'required' => false, |
|
| 1410 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1411 | - 'validation_strategies' => array( |
|
| 1412 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1413 | - 100), |
|
| 1414 | - ) |
|
| 1415 | - ) |
|
| 1416 | - ), |
|
| 1417 | - ) |
|
| 1418 | - ) |
|
| 1419 | - ); |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - |
|
| 1423 | - /** |
|
| 1424 | - * _create_payment_from_request_data |
|
| 1425 | - * |
|
| 1426 | - * @param array $valid_data |
|
| 1427 | - * |
|
| 1428 | - * @return EE_Payment |
|
| 1429 | - */ |
|
| 1430 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1431 | - { |
|
| 1432 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1433 | - // get payment amount |
|
| 1434 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1435 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1436 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1437 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1438 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1439 | - $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
| 1440 | - current_time('timestamp')); |
|
| 1441 | - $payment = EE_Payment::new_instance( |
|
| 1442 | - array( |
|
| 1443 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1444 | - 'STS_ID' => $valid_data['status'], |
|
| 1445 | - 'PAY_timestamp' => $date, |
|
| 1446 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1447 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1448 | - 'PAY_amount' => $amount, |
|
| 1449 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1450 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1451 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1452 | - 'PAY_details' => $valid_data, |
|
| 1453 | - 'PAY_ID' => $PAY_ID |
|
| 1454 | - ), |
|
| 1455 | - '', |
|
| 1456 | - array('Y-m-d', 'g:i a') |
|
| 1457 | - ); |
|
| 1458 | - |
|
| 1459 | - if ( ! $payment->save()) { |
|
| 1460 | - EE_Error::add_error( |
|
| 1461 | - sprintf( |
|
| 1462 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1463 | - $payment->ID() |
|
| 1464 | - ), |
|
| 1465 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1466 | - ); |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - return $payment; |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * _process_transaction_payments |
|
| 1475 | - * |
|
| 1476 | - * @param \EE_Transaction $transaction |
|
| 1477 | - * |
|
| 1478 | - * @return array |
|
| 1479 | - */ |
|
| 1480 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1481 | - { |
|
| 1482 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1483 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1484 | - //update the transaction with this payment |
|
| 1485 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1486 | - EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
| 1487 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1488 | - } else { |
|
| 1489 | - EE_Error::add_error( |
|
| 1490 | - esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1491 | - 'event_espresso') |
|
| 1492 | - , __FILE__, __FUNCTION__, __LINE__ |
|
| 1493 | - ); |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1500 | - * |
|
| 1501 | - * returns a list of registration IDs that the payment will apply to |
|
| 1502 | - * |
|
| 1503 | - * @param \EE_Payment $payment |
|
| 1504 | - * |
|
| 1505 | - * @return array |
|
| 1506 | - */ |
|
| 1507 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1508 | - { |
|
| 1509 | - $REG_IDs = array(); |
|
| 1510 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1511 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1512 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1513 | - } |
|
| 1514 | - //nothing specified ? then get all reg IDs |
|
| 1515 | - if (empty($REG_IDs)) { |
|
| 1516 | - $registrations = $payment->transaction()->registrations(); |
|
| 1517 | - $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1521 | - return array_map('intval', $REG_IDs); |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - |
|
| 1525 | - /** |
|
| 1526 | - * @return array |
|
| 1527 | - */ |
|
| 1528 | - public function existing_reg_payment_REG_IDs() |
|
| 1529 | - { |
|
| 1530 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1531 | - } |
|
| 1532 | - |
|
| 1533 | - |
|
| 1534 | - /** |
|
| 1535 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1536 | - */ |
|
| 1537 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1538 | - { |
|
| 1539 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - /** |
|
| 1544 | - * _get_existing_reg_payment_REG_IDs |
|
| 1545 | - * |
|
| 1546 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1547 | - * as recorded in the database |
|
| 1548 | - * |
|
| 1549 | - * @param \EE_Payment $payment |
|
| 1550 | - * |
|
| 1551 | - * @return array |
|
| 1552 | - */ |
|
| 1553 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1554 | - { |
|
| 1555 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1556 | - // let's get any existing reg payment records for this payment |
|
| 1557 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1558 | - // but we only want the REG IDs, so grab the array keys |
|
| 1559 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
| 1560 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 1564 | - } |
|
| 1565 | - |
|
| 1566 | - |
|
| 1567 | - /** |
|
| 1568 | - * _remove_existing_registration_payments |
|
| 1569 | - * |
|
| 1570 | - * this calculates the difference between existing relations |
|
| 1571 | - * to the supplied payment and the new list registration IDs, |
|
| 1572 | - * removes any related registrations that no longer apply, |
|
| 1573 | - * and then updates the registration paid fields |
|
| 1574 | - * |
|
| 1575 | - * @param \EE_Payment $payment |
|
| 1576 | - * @param int $PAY_ID |
|
| 1577 | - * |
|
| 1578 | - * @return bool; |
|
| 1579 | - */ |
|
| 1580 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1581 | - { |
|
| 1582 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 1583 | - if ($PAY_ID == 0) { |
|
| 1584 | - return false; |
|
| 1585 | - } |
|
| 1586 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1587 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1588 | - return false; |
|
| 1589 | - } |
|
| 1590 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1591 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1592 | - |
|
| 1593 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1594 | - $payment, |
|
| 1595 | - array( |
|
| 1596 | - array( |
|
| 1597 | - 'PAY_ID' => $payment->ID(), |
|
| 1598 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1599 | - ) |
|
| 1600 | - ) |
|
| 1601 | - ); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - |
|
| 1605 | - /** |
|
| 1606 | - * _update_registration_payments |
|
| 1607 | - * |
|
| 1608 | - * this applies the payments to the selected registrations |
|
| 1609 | - * but only if they have not already been paid for |
|
| 1610 | - * |
|
| 1611 | - * @param EE_Transaction $transaction |
|
| 1612 | - * @param \EE_Payment $payment |
|
| 1613 | - * @param array $REG_IDs |
|
| 1614 | - * |
|
| 1615 | - * @return bool |
|
| 1616 | - */ |
|
| 1617 | - protected function _update_registration_payments( |
|
| 1618 | - EE_Transaction $transaction, |
|
| 1619 | - EE_Payment $payment, |
|
| 1620 | - $REG_IDs = array() |
|
| 1621 | - ) { |
|
| 1622 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1623 | - // so let's do that using our set of REG_IDs from the form |
|
| 1624 | - $registration_query_where_params = array( |
|
| 1625 | - 'REG_ID' => array('IN', $REG_IDs) |
|
| 1626 | - ); |
|
| 1627 | - // but add in some conditions regarding payment, |
|
| 1628 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1629 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1630 | - if ( ! $payment->is_a_refund()) { |
|
| 1631 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1632 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1633 | - } |
|
| 1634 | - //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
| 1635 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1636 | - if ( ! empty($registrations)) { |
|
| 1637 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 1638 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1639 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1640 | - } |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * _process_registration_status_change |
|
| 1646 | - * |
|
| 1647 | - * This processes requested registration status changes for all the registrations |
|
| 1648 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1649 | - * |
|
| 1650 | - * @param EE_Transaction $transaction |
|
| 1651 | - * @param array $REG_IDs |
|
| 1652 | - * |
|
| 1653 | - * @return bool |
|
| 1654 | - */ |
|
| 1655 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1656 | - { |
|
| 1657 | - // first if there is no change in status then we get out. |
|
| 1658 | - if ( |
|
| 1659 | - ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1660 | - || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
| 1661 | - ) { |
|
| 1662 | - //no error message, no change requested, just nothing to do man. |
|
| 1663 | - return false; |
|
| 1664 | - } |
|
| 1665 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1666 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1667 | - |
|
| 1668 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1669 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 1670 | - $transaction, |
|
| 1671 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1672 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1673 | - ); |
|
| 1674 | - } |
|
| 1675 | - |
|
| 1676 | - |
|
| 1677 | - /** |
|
| 1678 | - * _build_payment_json_response |
|
| 1679 | - * |
|
| 1680 | - * @access public |
|
| 1681 | - * |
|
| 1682 | - * @param \EE_Payment $payment |
|
| 1683 | - * @param array $REG_IDs |
|
| 1684 | - * @param bool | null $delete_txn_reg_status_change |
|
| 1685 | - * |
|
| 1686 | - * @return array |
|
| 1687 | - */ |
|
| 1688 | - protected function _build_payment_json_response( |
|
| 1689 | - EE_Payment $payment, |
|
| 1690 | - $REG_IDs = array(), |
|
| 1691 | - $delete_txn_reg_status_change = null |
|
| 1692 | - ) { |
|
| 1693 | - // was the payment deleted ? |
|
| 1694 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 1695 | - return array( |
|
| 1696 | - 'PAY_ID' => $payment->ID(), |
|
| 1697 | - 'amount' => $payment->amount(), |
|
| 1698 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 1699 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1700 | - 'pay_status' => $payment->STS_ID(), |
|
| 1701 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1702 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 1703 | - ); |
|
| 1704 | - } else { |
|
| 1705 | - $this->_get_payment_status_array(); |
|
| 1706 | - |
|
| 1707 | - return array( |
|
| 1708 | - 'amount' => $payment->amount(), |
|
| 1709 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 1710 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1711 | - 'pay_status' => $payment->STS_ID(), |
|
| 1712 | - 'PAY_ID' => $payment->ID(), |
|
| 1713 | - 'STS_ID' => $payment->STS_ID(), |
|
| 1714 | - 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 1715 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 1716 | - 'method' => strtoupper($payment->source()), |
|
| 1717 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 1718 | - 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
| 1719 | - 'event_espresso'), |
|
| 1720 | - 'gateway_response' => $payment->gateway_response(), |
|
| 1721 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 1722 | - 'po_number' => $payment->po_number(), |
|
| 1723 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 1724 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1725 | - ); |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * delete_payment |
|
| 1732 | - * delete a payment or refund made towards a transaction |
|
| 1733 | - * |
|
| 1734 | - * @access public |
|
| 1735 | - * @return void |
|
| 1736 | - */ |
|
| 1737 | - public function delete_payment() |
|
| 1738 | - { |
|
| 1739 | - $json_response_data = array('return_data' => false); |
|
| 1740 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
| 1741 | - if ($PAY_ID) { |
|
| 1742 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
| 1743 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 1744 | - if ($payment instanceof EE_Payment) { |
|
| 1745 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1746 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1747 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1748 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 1749 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
| 1750 | - $delete_txn_reg_status_change); |
|
| 1751 | - if ($delete_txn_reg_status_change) { |
|
| 1752 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1753 | - //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 1754 | - //$_REQUEST global because that's how messages will be looking for it. |
|
| 1755 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1756 | - $this->_maybe_send_notifications(); |
|
| 1757 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 1758 | - } |
|
| 1759 | - } |
|
| 1760 | - } else { |
|
| 1761 | - EE_Error::add_error( |
|
| 1762 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 1763 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1764 | - ); |
|
| 1765 | - } |
|
| 1766 | - } else { |
|
| 1767 | - EE_Error::add_error( |
|
| 1768 | - esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 1769 | - 'event_espresso'), |
|
| 1770 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1771 | - ); |
|
| 1772 | - } |
|
| 1773 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1774 | - $this->_template_args = array( |
|
| 1775 | - 'data' => $json_response_data, |
|
| 1776 | - 'success' => $notices['success'], |
|
| 1777 | - 'error' => $notices['errors'], |
|
| 1778 | - 'attention' => $notices['attention'] |
|
| 1779 | - ); |
|
| 1780 | - $this->_return_json(); |
|
| 1781 | - } |
|
| 1782 | - |
|
| 1783 | - |
|
| 1784 | - /** |
|
| 1785 | - * _registration_payment_data_array |
|
| 1786 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 1787 | - * |
|
| 1788 | - * @access protected |
|
| 1789 | - * |
|
| 1790 | - * @param array $REG_IDs |
|
| 1791 | - * |
|
| 1792 | - * @return array |
|
| 1793 | - */ |
|
| 1794 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 1795 | - { |
|
| 1796 | - $registration_payment_data = array(); |
|
| 1797 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 1798 | - if ( ! empty($REG_IDs)) { |
|
| 1799 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 1800 | - foreach ($registrations as $registration) { |
|
| 1801 | - if ($registration instanceof EE_Registration) { |
|
| 1802 | - $registration_payment_data[$registration->ID()] = array( |
|
| 1803 | - 'paid' => $registration->pretty_paid(), |
|
| 1804 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 1805 | - ); |
|
| 1806 | - } |
|
| 1807 | - } |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - return $registration_payment_data; |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - |
|
| 1814 | - /** |
|
| 1815 | - * _maybe_send_notifications |
|
| 1816 | - * |
|
| 1817 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 1818 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 1819 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 1820 | - * |
|
| 1821 | - * @access protected |
|
| 1822 | - * |
|
| 1823 | - * @param \EE_Payment | null $payment |
|
| 1824 | - */ |
|
| 1825 | - protected function _maybe_send_notifications($payment = null) |
|
| 1826 | - { |
|
| 1827 | - switch ($payment instanceof EE_Payment) { |
|
| 1828 | - // payment notifications |
|
| 1829 | - case true : |
|
| 1830 | - if ( |
|
| 1831 | - isset( |
|
| 1832 | - $this->_req_data['txn_payments'], |
|
| 1833 | - $this->_req_data['txn_payments']['send_notifications'] |
|
| 1834 | - ) && |
|
| 1835 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1836 | - ) { |
|
| 1837 | - $this->_process_payment_notification($payment); |
|
| 1838 | - } |
|
| 1839 | - break; |
|
| 1840 | - // registration notifications |
|
| 1841 | - case false : |
|
| 1842 | - if ( |
|
| 1843 | - isset( |
|
| 1844 | - $this->_req_data['txn_reg_status_change'], |
|
| 1845 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 1846 | - ) && |
|
| 1847 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1848 | - ) { |
|
| 1849 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 1850 | - } |
|
| 1851 | - break; |
|
| 1852 | - } |
|
| 1853 | - } |
|
| 1854 | - |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * _send_payment_reminder |
|
| 1858 | - * generates HTML for the View Transaction Details Admin page |
|
| 1859 | - * |
|
| 1860 | - * @access protected |
|
| 1861 | - * @return void |
|
| 1862 | - */ |
|
| 1863 | - protected function _send_payment_reminder() |
|
| 1864 | - { |
|
| 1865 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 1866 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 1867 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 1868 | - 'action' => $this->_req_data['redirect_to'], |
|
| 1869 | - 'TXN_ID' => $this->_req_data['TXN_ID'] |
|
| 1870 | - ) : array(); |
|
| 1871 | - do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 1872 | - $transaction); |
|
| 1873 | - $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
| 1874 | - esc_html__('sent', 'event_espresso'), $query_args, true); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - |
|
| 1878 | - /** |
|
| 1879 | - * get_transactions |
|
| 1880 | - * get transactions for given parameters (used by list table) |
|
| 1881 | - * |
|
| 1882 | - * @param int $perpage how many transactions displayed per page |
|
| 1883 | - * @param boolean $count return the count or objects |
|
| 1884 | - * @param string $view |
|
| 1885 | - * |
|
| 1886 | - * @return mixed int = count || array of transaction objects |
|
| 1887 | - */ |
|
| 1888 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 1889 | - { |
|
| 1890 | - |
|
| 1891 | - $TXN = EEM_Transaction::instance(); |
|
| 1892 | - |
|
| 1893 | - $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
| 1894 | - strtotime('-10 year')); |
|
| 1895 | - $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
| 1896 | - |
|
| 1897 | - //make sure our timestamps start and end right at the boundaries for each day |
|
| 1898 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1899 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - //convert to timestamps |
|
| 1903 | - $start_date = strtotime($start_date); |
|
| 1904 | - $end_date = strtotime($end_date); |
|
| 1905 | - |
|
| 1906 | - //makes sure start date is the lowest value and vice versa |
|
| 1907 | - $start_date = min($start_date, $end_date); |
|
| 1908 | - $end_date = max($start_date, $end_date); |
|
| 1909 | - |
|
| 1910 | - //convert to correct format for query |
|
| 1911 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1912 | - date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 1913 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1914 | - date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 1915 | - |
|
| 1916 | - |
|
| 1917 | - //set orderby |
|
| 1918 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 1919 | - |
|
| 1920 | - switch ($this->_req_data['orderby']) { |
|
| 1921 | - case 'TXN_ID': |
|
| 1922 | - $orderby = 'TXN_ID'; |
|
| 1923 | - break; |
|
| 1924 | - case 'ATT_fname': |
|
| 1925 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 1926 | - break; |
|
| 1927 | - case 'event_name': |
|
| 1928 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 1929 | - break; |
|
| 1930 | - default: //'TXN_timestamp' |
|
| 1931 | - $orderby = 'TXN_timestamp'; |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 1935 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1936 | - $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
| 1937 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 1938 | - |
|
| 1939 | - $offset = ($current_page - 1) * $per_page; |
|
| 1940 | - $limit = array($offset, $per_page); |
|
| 1941 | - |
|
| 1942 | - $_where = array( |
|
| 1943 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 1944 | - 'Registration.REG_count' => 1 |
|
| 1945 | - ); |
|
| 1946 | - |
|
| 1947 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 1948 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 1949 | - } |
|
| 1950 | - |
|
| 1951 | - if (isset($this->_req_data['s'])) { |
|
| 1952 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1953 | - $_where['OR'] = array( |
|
| 1954 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 1955 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1956 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1957 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1958 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1959 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1960 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1961 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1962 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1963 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1964 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1965 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 1966 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 1967 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 1968 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 1969 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1970 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1971 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 1972 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 1973 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 1974 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string) |
|
| 1975 | - ); |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - //failed transactions |
|
| 1979 | - $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
| 1980 | - $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
| 1981 | - |
|
| 1982 | - if ($failed) { |
|
| 1983 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 1984 | - } else if ($abandoned) { |
|
| 1985 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 1986 | - } else { |
|
| 1987 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 1988 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - $query_params = array( |
|
| 1992 | - $_where, |
|
| 1993 | - 'order_by' => array($orderby => $sort), |
|
| 1994 | - 'limit' => $limit, |
|
| 1995 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only |
|
| 1996 | - ); |
|
| 1997 | - |
|
| 1998 | - $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
| 1999 | - |
|
| 2000 | - |
|
| 2001 | - return $transactions; |
|
| 2002 | - |
|
| 2003 | - } |
|
| 807 | + // process payment details |
|
| 808 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
| 809 | + if ( ! empty($payments)) { |
|
| 810 | + $this->_template_args['payments'] = $payments; |
|
| 811 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 812 | + } else { |
|
| 813 | + $this->_template_args['payments'] = false; |
|
| 814 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 818 | + $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
| 819 | + TXN_ADMIN_URL); |
|
| 820 | + |
|
| 821 | + if (isset($txn_details['invoice_number'])) { |
|
| 822 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 823 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
| 824 | + 'event_espresso'); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
| 828 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
| 829 | + 'event_espresso'); |
|
| 830 | + |
|
| 831 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
| 832 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
| 833 | + 'event_espresso'); |
|
| 834 | + |
|
| 835 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
| 836 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 837 | + 'event_espresso'); |
|
| 838 | + |
|
| 839 | + $reg_steps = '<ul>'; |
|
| 840 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 841 | + if ($reg_step_status === true) { |
|
| 842 | + $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 843 | + ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 844 | + } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 845 | + $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 846 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 847 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 848 | + date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 849 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
| 850 | + ) . '</li>'; |
|
| 851 | + } else { |
|
| 852 | + $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 853 | + 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + $reg_steps .= '</ul>'; |
|
| 857 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 858 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
| 859 | + 'event_espresso'); |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 863 | + $this->_get_payment_methods($payments); |
|
| 864 | + $this->_get_payment_status_array(); |
|
| 865 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 866 | + |
|
| 867 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 868 | + 'action' => 'edit_transaction', |
|
| 869 | + 'process' => 'transaction' |
|
| 870 | + ), TXN_ADMIN_URL); |
|
| 871 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 872 | + 'page' => 'espresso_transactions', |
|
| 873 | + 'action' => 'espresso_apply_payment' |
|
| 874 | + ), WP_AJAX_URL); |
|
| 875 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 876 | + 'page' => 'espresso_transactions', |
|
| 877 | + 'action' => 'espresso_delete_payment' |
|
| 878 | + ), WP_AJAX_URL); |
|
| 879 | + |
|
| 880 | + // 'espresso_delete_payment_nonce' |
|
| 881 | + |
|
| 882 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 883 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 884 | + |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * _get_registration_payment_IDs |
|
| 890 | + * |
|
| 891 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 892 | + * |
|
| 893 | + * @access protected |
|
| 894 | + * |
|
| 895 | + * @param EE_Payment[] $payments |
|
| 896 | + * |
|
| 897 | + * @return array |
|
| 898 | + */ |
|
| 899 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 900 | + { |
|
| 901 | + $existing_reg_payments = array(); |
|
| 902 | + // get all reg payments for these payments |
|
| 903 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 904 | + array( |
|
| 905 | + 'PAY_ID' => array( |
|
| 906 | + 'IN', |
|
| 907 | + array_keys($payments) |
|
| 908 | + ) |
|
| 909 | + ) |
|
| 910 | + )); |
|
| 911 | + if ( ! empty($reg_payments)) { |
|
| 912 | + foreach ($payments as $payment) { |
|
| 913 | + if ( ! $payment instanceof EE_Payment) { |
|
| 914 | + continue; |
|
| 915 | + } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 916 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 917 | + } |
|
| 918 | + foreach ($reg_payments as $reg_payment) { |
|
| 919 | + if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
| 920 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + return $existing_reg_payments; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * _get_registrations_to_apply_payment_to |
|
| 932 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 933 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 934 | + * |
|
| 935 | + * @access protected |
|
| 936 | + * @return void |
|
| 937 | + * @throws \EE_Error |
|
| 938 | + */ |
|
| 939 | + protected function _get_registrations_to_apply_payment_to() |
|
| 940 | + { |
|
| 941 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 942 | + $query_params = array( |
|
| 943 | + array( |
|
| 944 | + 'STS_ID' => array( |
|
| 945 | + 'IN', |
|
| 946 | + array( |
|
| 947 | + EEM_Registration::status_id_approved, |
|
| 948 | + EEM_Registration::status_id_pending_payment, |
|
| 949 | + EEM_Registration::status_id_not_approved, |
|
| 950 | + ) |
|
| 951 | + ) |
|
| 952 | + ) |
|
| 953 | + ); |
|
| 954 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 955 | + '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 956 | + ); |
|
| 957 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 958 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 959 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 960 | + EEH_HTML::tr( |
|
| 961 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 962 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 963 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 964 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 965 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 966 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 967 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 968 | + ) |
|
| 969 | + ); |
|
| 970 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 971 | + // get registrations for TXN |
|
| 972 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 973 | + foreach ($registrations as $registration) { |
|
| 974 | + if ($registration instanceof EE_Registration) { |
|
| 975 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 976 | + ? $registration->attendee()->full_name() |
|
| 977 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 978 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 979 | + $taxable = $registration->ticket()->taxable() |
|
| 980 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 981 | + : ''; |
|
| 982 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 983 | + ? ' checked="checked"' |
|
| 984 | + : ''; |
|
| 985 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 986 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 987 | + EEH_HTML::td($registration->ID()) . |
|
| 988 | + EEH_HTML::td($attendee_name) . |
|
| 989 | + EEH_HTML::td( |
|
| 990 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 991 | + ) . |
|
| 992 | + EEH_HTML::td($registration->event_name()) . |
|
| 993 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 994 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 995 | + EEH_HTML::td( |
|
| 996 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 997 | + . '" name="txn_admin_payment[registrations]"' |
|
| 998 | + . $checked . $disabled . '>', |
|
| 999 | + '', 'jst-cntr' |
|
| 1000 | + ), |
|
| 1001 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1002 | + ); |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1006 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1007 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1008 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1009 | + esc_html__( |
|
| 1010 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1011 | + 'event_espresso' |
|
| 1012 | + ), |
|
| 1013 | + '', 'clear description' |
|
| 1014 | + ); |
|
| 1015 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1016 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + |
|
| 1020 | + /** |
|
| 1021 | + * _get_reg_status_selection |
|
| 1022 | + * |
|
| 1023 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1024 | + * instead of events. |
|
| 1025 | + * @access protected |
|
| 1026 | + * @return void |
|
| 1027 | + */ |
|
| 1028 | + protected function _get_reg_status_selection() |
|
| 1029 | + { |
|
| 1030 | + //first get all possible statuses |
|
| 1031 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1032 | + //let's add a "don't change" option. |
|
| 1033 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1034 | + $status_array = array_merge($status_array, $statuses); |
|
| 1035 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
| 1036 | + $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
| 1037 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
| 1038 | + $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
| 1039 | + |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * _get_payment_methods |
|
| 1045 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1046 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1047 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1048 | + * @access private |
|
| 1049 | + * |
|
| 1050 | + * @param EE_Payment[] to show on this page |
|
| 1051 | + * |
|
| 1052 | + * @return void |
|
| 1053 | + */ |
|
| 1054 | + private function _get_payment_methods($payments = array()) |
|
| 1055 | + { |
|
| 1056 | + $payment_methods_of_payments = array(); |
|
| 1057 | + foreach ($payments as $payment) { |
|
| 1058 | + if ($payment instanceof EE_Payment) { |
|
| 1059 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1060 | + } |
|
| 1061 | + } |
|
| 1062 | + if ($payment_methods_of_payments) { |
|
| 1063 | + $query_args = array( |
|
| 1064 | + array( |
|
| 1065 | + 'OR*payment_method_for_payment' => array( |
|
| 1066 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1067 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1068 | + ) |
|
| 1069 | + ) |
|
| 1070 | + ); |
|
| 1071 | + } else { |
|
| 1072 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1073 | + } |
|
| 1074 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * txn_attendees_meta_box |
|
| 1080 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1081 | + * |
|
| 1082 | + * @access public |
|
| 1083 | + * |
|
| 1084 | + * @param WP_Post $post |
|
| 1085 | + * @param array $metabox |
|
| 1086 | + * |
|
| 1087 | + * @return void |
|
| 1088 | + */ |
|
| 1089 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1090 | + { |
|
| 1091 | + |
|
| 1092 | + extract($metabox['args']); |
|
| 1093 | + $this->_template_args['post'] = $post; |
|
| 1094 | + $this->_template_args['event_attendees'] = array(); |
|
| 1095 | + // process items in cart |
|
| 1096 | + $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
| 1097 | + if ( ! empty($line_items)) { |
|
| 1098 | + foreach ($line_items as $item) { |
|
| 1099 | + if ($item instanceof EE_Line_Item) { |
|
| 1100 | + switch ($item->OBJ_type()) { |
|
| 1101 | + |
|
| 1102 | + case 'Event' : |
|
| 1103 | + break; |
|
| 1104 | + |
|
| 1105 | + case 'Ticket' : |
|
| 1106 | + $ticket = $item->ticket(); |
|
| 1107 | + //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
| 1108 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1109 | + continue; |
|
| 1110 | + } |
|
| 1111 | + try { |
|
| 1112 | + $event_name = $ticket->get_event_name(); |
|
| 1113 | + } catch (Exception $e) { |
|
| 1114 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1116 | + } |
|
| 1117 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1118 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1119 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1120 | + $registrations = $ticket->get_many_related('Registration', |
|
| 1121 | + array(array('TXN_ID' => $this->_transaction->ID()))); |
|
| 1122 | + foreach ($registrations as $registration) { |
|
| 1123 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1124 | + continue; |
|
| 1125 | + } |
|
| 1126 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
| 1127 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
| 1128 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 1129 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 1130 | + // attendee info |
|
| 1131 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1132 | + if ($attendee instanceof EE_Attendee) { |
|
| 1133 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
| 1134 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
| 1135 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1136 | + 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1137 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
| 1138 | + 'inline', false, false); |
|
| 1139 | + } else { |
|
| 1140 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1141 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1142 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1143 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + break; |
|
| 1147 | + |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1153 | + 'action' => 'edit_transaction', |
|
| 1154 | + 'process' => 'attendees' |
|
| 1155 | + ), TXN_ADMIN_URL); |
|
| 1156 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1157 | + $this->_template_args, true); |
|
| 1158 | + |
|
| 1159 | + } else { |
|
| 1160 | + echo sprintf( |
|
| 1161 | + esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1162 | + 'event_espresso'), |
|
| 1163 | + '<p class="important-notice">', |
|
| 1164 | + '</p>' |
|
| 1165 | + ); |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * txn_registrant_side_meta_box |
|
| 1172 | + * generates HTML for the Edit Transaction side meta box |
|
| 1173 | + * |
|
| 1174 | + * @access public |
|
| 1175 | + * @throws \EE_Error |
|
| 1176 | + * @return void |
|
| 1177 | + */ |
|
| 1178 | + public function txn_registrant_side_meta_box() |
|
| 1179 | + { |
|
| 1180 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
| 1181 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1182 | + $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1183 | + 'event_espresso'); |
|
| 1184 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1185 | + } |
|
| 1186 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1187 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1188 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1189 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1190 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1191 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1192 | + 'action' => 'edit_attendee', |
|
| 1193 | + 'post' => $primary_att->ID() |
|
| 1194 | + ), REG_ADMIN_URL); |
|
| 1195 | + // get formatted address for registrant |
|
| 1196 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1197 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1198 | + $this->_template_args, true); |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + |
|
| 1202 | + /** |
|
| 1203 | + * txn_billing_info_side_meta_box |
|
| 1204 | + * generates HTML for the Edit Transaction side meta box |
|
| 1205 | + * |
|
| 1206 | + * @access public |
|
| 1207 | + * @return void |
|
| 1208 | + */ |
|
| 1209 | + public function txn_billing_info_side_meta_box() |
|
| 1210 | + { |
|
| 1211 | + |
|
| 1212 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1213 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1214 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1215 | + TXN_ADMIN_URL |
|
| 1216 | + ); |
|
| 1217 | + |
|
| 1218 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1219 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * apply_payments_or_refunds |
|
| 1225 | + * registers a payment or refund made towards a transaction |
|
| 1226 | + * |
|
| 1227 | + * @access public |
|
| 1228 | + * @return void |
|
| 1229 | + */ |
|
| 1230 | + public function apply_payments_or_refunds() |
|
| 1231 | + { |
|
| 1232 | + $json_response_data = array('return_data' => false); |
|
| 1233 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1234 | + if ( ! empty($valid_data)) { |
|
| 1235 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1236 | + //save the new payment |
|
| 1237 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1238 | + // get the TXN for this payment |
|
| 1239 | + $transaction = $payment->transaction(); |
|
| 1240 | + // verify transaction |
|
| 1241 | + if ($transaction instanceof EE_Transaction) { |
|
| 1242 | + // calculate_total_payments_and_update_status |
|
| 1243 | + $this->_process_transaction_payments($transaction); |
|
| 1244 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1245 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1246 | + // apply payment to registrations (if applicable) |
|
| 1247 | + if ( ! empty($REG_IDs)) { |
|
| 1248 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1249 | + $this->_maybe_send_notifications(); |
|
| 1250 | + // now process status changes for the same registrations |
|
| 1251 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1252 | + } |
|
| 1253 | + $this->_maybe_send_notifications($payment); |
|
| 1254 | + //prepare to render page |
|
| 1255 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1256 | + do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
| 1257 | + $payment); |
|
| 1258 | + } else { |
|
| 1259 | + EE_Error::add_error( |
|
| 1260 | + esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
| 1261 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1262 | + ); |
|
| 1263 | + } |
|
| 1264 | + } else { |
|
| 1265 | + EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
| 1266 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1270 | + $this->_template_args = array( |
|
| 1271 | + 'data' => $json_response_data, |
|
| 1272 | + 'error' => $notices['errors'], |
|
| 1273 | + 'success' => $notices['success'] |
|
| 1274 | + ); |
|
| 1275 | + $this->_return_json(); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * _validate_payment_request_data |
|
| 1281 | + * |
|
| 1282 | + * @return array |
|
| 1283 | + */ |
|
| 1284 | + protected function _validate_payment_request_data() |
|
| 1285 | + { |
|
| 1286 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1287 | + return false; |
|
| 1288 | + } |
|
| 1289 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1290 | + try { |
|
| 1291 | + if ($payment_form->was_submitted()) { |
|
| 1292 | + $payment_form->receive_form_submission(); |
|
| 1293 | + if ( ! $payment_form->is_valid()) { |
|
| 1294 | + $submission_error_messages = array(); |
|
| 1295 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1296 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1297 | + $submission_error_messages[] = sprintf( |
|
| 1298 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1299 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1300 | + $validation_error->getMessage() |
|
| 1301 | + ); |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | + EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1305 | + |
|
| 1306 | + return array(); |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + } catch (EE_Error $e) { |
|
| 1310 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1311 | + |
|
| 1312 | + return array(); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + return $payment_form->valid_data(); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + /** |
|
| 1320 | + * _generate_payment_form_section |
|
| 1321 | + * |
|
| 1322 | + * @return EE_Form_Section_Proper |
|
| 1323 | + */ |
|
| 1324 | + protected function _generate_payment_form_section() |
|
| 1325 | + { |
|
| 1326 | + return new EE_Form_Section_Proper( |
|
| 1327 | + array( |
|
| 1328 | + 'name' => 'txn_admin_payment', |
|
| 1329 | + 'subsections' => array( |
|
| 1330 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1331 | + array( |
|
| 1332 | + 'default' => 0, |
|
| 1333 | + 'required' => false, |
|
| 1334 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1335 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1336 | + ) |
|
| 1337 | + ), |
|
| 1338 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1339 | + array( |
|
| 1340 | + 'default' => 0, |
|
| 1341 | + 'required' => true, |
|
| 1342 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1343 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1344 | + ) |
|
| 1345 | + ), |
|
| 1346 | + 'type' => new EE_Text_Input( |
|
| 1347 | + array( |
|
| 1348 | + 'default' => 1, |
|
| 1349 | + 'required' => true, |
|
| 1350 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1351 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1352 | + ) |
|
| 1353 | + ), |
|
| 1354 | + 'amount' => new EE_Text_Input( |
|
| 1355 | + array( |
|
| 1356 | + 'default' => 0, |
|
| 1357 | + 'required' => true, |
|
| 1358 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1359 | + 'validation_strategies' => array(new EE_Float_Normalization()) |
|
| 1360 | + ) |
|
| 1361 | + ), |
|
| 1362 | + 'status' => new EE_Text_Input( |
|
| 1363 | + array( |
|
| 1364 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1365 | + 'required' => true, |
|
| 1366 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1367 | + ) |
|
| 1368 | + ), |
|
| 1369 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1370 | + array( |
|
| 1371 | + 'default' => 2, |
|
| 1372 | + 'required' => true, |
|
| 1373 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1374 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1375 | + ) |
|
| 1376 | + ), |
|
| 1377 | + 'date' => new EE_Text_Input( |
|
| 1378 | + array( |
|
| 1379 | + 'default' => time(), |
|
| 1380 | + 'required' => true, |
|
| 1381 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1382 | + ) |
|
| 1383 | + ), |
|
| 1384 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1385 | + array( |
|
| 1386 | + 'default' => '', |
|
| 1387 | + 'required' => false, |
|
| 1388 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1389 | + 'validation_strategies' => array( |
|
| 1390 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1391 | + 100), |
|
| 1392 | + ) |
|
| 1393 | + ) |
|
| 1394 | + ), |
|
| 1395 | + 'po_number' => new EE_Text_Input( |
|
| 1396 | + array( |
|
| 1397 | + 'default' => '', |
|
| 1398 | + 'required' => false, |
|
| 1399 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1400 | + 'validation_strategies' => array( |
|
| 1401 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1402 | + 100), |
|
| 1403 | + ) |
|
| 1404 | + ) |
|
| 1405 | + ), |
|
| 1406 | + 'accounting' => new EE_Text_Input( |
|
| 1407 | + array( |
|
| 1408 | + 'default' => '', |
|
| 1409 | + 'required' => false, |
|
| 1410 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1411 | + 'validation_strategies' => array( |
|
| 1412 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1413 | + 100), |
|
| 1414 | + ) |
|
| 1415 | + ) |
|
| 1416 | + ), |
|
| 1417 | + ) |
|
| 1418 | + ) |
|
| 1419 | + ); |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + |
|
| 1423 | + /** |
|
| 1424 | + * _create_payment_from_request_data |
|
| 1425 | + * |
|
| 1426 | + * @param array $valid_data |
|
| 1427 | + * |
|
| 1428 | + * @return EE_Payment |
|
| 1429 | + */ |
|
| 1430 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1431 | + { |
|
| 1432 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1433 | + // get payment amount |
|
| 1434 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1435 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1436 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1437 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1438 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1439 | + $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
| 1440 | + current_time('timestamp')); |
|
| 1441 | + $payment = EE_Payment::new_instance( |
|
| 1442 | + array( |
|
| 1443 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1444 | + 'STS_ID' => $valid_data['status'], |
|
| 1445 | + 'PAY_timestamp' => $date, |
|
| 1446 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1447 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1448 | + 'PAY_amount' => $amount, |
|
| 1449 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1450 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1451 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1452 | + 'PAY_details' => $valid_data, |
|
| 1453 | + 'PAY_ID' => $PAY_ID |
|
| 1454 | + ), |
|
| 1455 | + '', |
|
| 1456 | + array('Y-m-d', 'g:i a') |
|
| 1457 | + ); |
|
| 1458 | + |
|
| 1459 | + if ( ! $payment->save()) { |
|
| 1460 | + EE_Error::add_error( |
|
| 1461 | + sprintf( |
|
| 1462 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1463 | + $payment->ID() |
|
| 1464 | + ), |
|
| 1465 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1466 | + ); |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + return $payment; |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * _process_transaction_payments |
|
| 1475 | + * |
|
| 1476 | + * @param \EE_Transaction $transaction |
|
| 1477 | + * |
|
| 1478 | + * @return array |
|
| 1479 | + */ |
|
| 1480 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1481 | + { |
|
| 1482 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1483 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1484 | + //update the transaction with this payment |
|
| 1485 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1486 | + EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
| 1487 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1488 | + } else { |
|
| 1489 | + EE_Error::add_error( |
|
| 1490 | + esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1491 | + 'event_espresso') |
|
| 1492 | + , __FILE__, __FUNCTION__, __LINE__ |
|
| 1493 | + ); |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1500 | + * |
|
| 1501 | + * returns a list of registration IDs that the payment will apply to |
|
| 1502 | + * |
|
| 1503 | + * @param \EE_Payment $payment |
|
| 1504 | + * |
|
| 1505 | + * @return array |
|
| 1506 | + */ |
|
| 1507 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1508 | + { |
|
| 1509 | + $REG_IDs = array(); |
|
| 1510 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1511 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1512 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1513 | + } |
|
| 1514 | + //nothing specified ? then get all reg IDs |
|
| 1515 | + if (empty($REG_IDs)) { |
|
| 1516 | + $registrations = $payment->transaction()->registrations(); |
|
| 1517 | + $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1521 | + return array_map('intval', $REG_IDs); |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + |
|
| 1525 | + /** |
|
| 1526 | + * @return array |
|
| 1527 | + */ |
|
| 1528 | + public function existing_reg_payment_REG_IDs() |
|
| 1529 | + { |
|
| 1530 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1531 | + } |
|
| 1532 | + |
|
| 1533 | + |
|
| 1534 | + /** |
|
| 1535 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1536 | + */ |
|
| 1537 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1538 | + { |
|
| 1539 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + |
|
| 1543 | + /** |
|
| 1544 | + * _get_existing_reg_payment_REG_IDs |
|
| 1545 | + * |
|
| 1546 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1547 | + * as recorded in the database |
|
| 1548 | + * |
|
| 1549 | + * @param \EE_Payment $payment |
|
| 1550 | + * |
|
| 1551 | + * @return array |
|
| 1552 | + */ |
|
| 1553 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1554 | + { |
|
| 1555 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1556 | + // let's get any existing reg payment records for this payment |
|
| 1557 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1558 | + // but we only want the REG IDs, so grab the array keys |
|
| 1559 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
| 1560 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 1564 | + } |
|
| 1565 | + |
|
| 1566 | + |
|
| 1567 | + /** |
|
| 1568 | + * _remove_existing_registration_payments |
|
| 1569 | + * |
|
| 1570 | + * this calculates the difference between existing relations |
|
| 1571 | + * to the supplied payment and the new list registration IDs, |
|
| 1572 | + * removes any related registrations that no longer apply, |
|
| 1573 | + * and then updates the registration paid fields |
|
| 1574 | + * |
|
| 1575 | + * @param \EE_Payment $payment |
|
| 1576 | + * @param int $PAY_ID |
|
| 1577 | + * |
|
| 1578 | + * @return bool; |
|
| 1579 | + */ |
|
| 1580 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1581 | + { |
|
| 1582 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 1583 | + if ($PAY_ID == 0) { |
|
| 1584 | + return false; |
|
| 1585 | + } |
|
| 1586 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1587 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1588 | + return false; |
|
| 1589 | + } |
|
| 1590 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1591 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1592 | + |
|
| 1593 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1594 | + $payment, |
|
| 1595 | + array( |
|
| 1596 | + array( |
|
| 1597 | + 'PAY_ID' => $payment->ID(), |
|
| 1598 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1599 | + ) |
|
| 1600 | + ) |
|
| 1601 | + ); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + |
|
| 1605 | + /** |
|
| 1606 | + * _update_registration_payments |
|
| 1607 | + * |
|
| 1608 | + * this applies the payments to the selected registrations |
|
| 1609 | + * but only if they have not already been paid for |
|
| 1610 | + * |
|
| 1611 | + * @param EE_Transaction $transaction |
|
| 1612 | + * @param \EE_Payment $payment |
|
| 1613 | + * @param array $REG_IDs |
|
| 1614 | + * |
|
| 1615 | + * @return bool |
|
| 1616 | + */ |
|
| 1617 | + protected function _update_registration_payments( |
|
| 1618 | + EE_Transaction $transaction, |
|
| 1619 | + EE_Payment $payment, |
|
| 1620 | + $REG_IDs = array() |
|
| 1621 | + ) { |
|
| 1622 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1623 | + // so let's do that using our set of REG_IDs from the form |
|
| 1624 | + $registration_query_where_params = array( |
|
| 1625 | + 'REG_ID' => array('IN', $REG_IDs) |
|
| 1626 | + ); |
|
| 1627 | + // but add in some conditions regarding payment, |
|
| 1628 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1629 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1630 | + if ( ! $payment->is_a_refund()) { |
|
| 1631 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1632 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1633 | + } |
|
| 1634 | + //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
| 1635 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1636 | + if ( ! empty($registrations)) { |
|
| 1637 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 1638 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1639 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1640 | + } |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * _process_registration_status_change |
|
| 1646 | + * |
|
| 1647 | + * This processes requested registration status changes for all the registrations |
|
| 1648 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1649 | + * |
|
| 1650 | + * @param EE_Transaction $transaction |
|
| 1651 | + * @param array $REG_IDs |
|
| 1652 | + * |
|
| 1653 | + * @return bool |
|
| 1654 | + */ |
|
| 1655 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1656 | + { |
|
| 1657 | + // first if there is no change in status then we get out. |
|
| 1658 | + if ( |
|
| 1659 | + ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1660 | + || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
| 1661 | + ) { |
|
| 1662 | + //no error message, no change requested, just nothing to do man. |
|
| 1663 | + return false; |
|
| 1664 | + } |
|
| 1665 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1666 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1667 | + |
|
| 1668 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1669 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 1670 | + $transaction, |
|
| 1671 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1672 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1673 | + ); |
|
| 1674 | + } |
|
| 1675 | + |
|
| 1676 | + |
|
| 1677 | + /** |
|
| 1678 | + * _build_payment_json_response |
|
| 1679 | + * |
|
| 1680 | + * @access public |
|
| 1681 | + * |
|
| 1682 | + * @param \EE_Payment $payment |
|
| 1683 | + * @param array $REG_IDs |
|
| 1684 | + * @param bool | null $delete_txn_reg_status_change |
|
| 1685 | + * |
|
| 1686 | + * @return array |
|
| 1687 | + */ |
|
| 1688 | + protected function _build_payment_json_response( |
|
| 1689 | + EE_Payment $payment, |
|
| 1690 | + $REG_IDs = array(), |
|
| 1691 | + $delete_txn_reg_status_change = null |
|
| 1692 | + ) { |
|
| 1693 | + // was the payment deleted ? |
|
| 1694 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 1695 | + return array( |
|
| 1696 | + 'PAY_ID' => $payment->ID(), |
|
| 1697 | + 'amount' => $payment->amount(), |
|
| 1698 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 1699 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1700 | + 'pay_status' => $payment->STS_ID(), |
|
| 1701 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1702 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 1703 | + ); |
|
| 1704 | + } else { |
|
| 1705 | + $this->_get_payment_status_array(); |
|
| 1706 | + |
|
| 1707 | + return array( |
|
| 1708 | + 'amount' => $payment->amount(), |
|
| 1709 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 1710 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1711 | + 'pay_status' => $payment->STS_ID(), |
|
| 1712 | + 'PAY_ID' => $payment->ID(), |
|
| 1713 | + 'STS_ID' => $payment->STS_ID(), |
|
| 1714 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 1715 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 1716 | + 'method' => strtoupper($payment->source()), |
|
| 1717 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 1718 | + 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
| 1719 | + 'event_espresso'), |
|
| 1720 | + 'gateway_response' => $payment->gateway_response(), |
|
| 1721 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 1722 | + 'po_number' => $payment->po_number(), |
|
| 1723 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 1724 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1725 | + ); |
|
| 1726 | + } |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * delete_payment |
|
| 1732 | + * delete a payment or refund made towards a transaction |
|
| 1733 | + * |
|
| 1734 | + * @access public |
|
| 1735 | + * @return void |
|
| 1736 | + */ |
|
| 1737 | + public function delete_payment() |
|
| 1738 | + { |
|
| 1739 | + $json_response_data = array('return_data' => false); |
|
| 1740 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
| 1741 | + if ($PAY_ID) { |
|
| 1742 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
| 1743 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 1744 | + if ($payment instanceof EE_Payment) { |
|
| 1745 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1746 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1747 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1748 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 1749 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
| 1750 | + $delete_txn_reg_status_change); |
|
| 1751 | + if ($delete_txn_reg_status_change) { |
|
| 1752 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1753 | + //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 1754 | + //$_REQUEST global because that's how messages will be looking for it. |
|
| 1755 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1756 | + $this->_maybe_send_notifications(); |
|
| 1757 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 1758 | + } |
|
| 1759 | + } |
|
| 1760 | + } else { |
|
| 1761 | + EE_Error::add_error( |
|
| 1762 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 1763 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1764 | + ); |
|
| 1765 | + } |
|
| 1766 | + } else { |
|
| 1767 | + EE_Error::add_error( |
|
| 1768 | + esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 1769 | + 'event_espresso'), |
|
| 1770 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1771 | + ); |
|
| 1772 | + } |
|
| 1773 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1774 | + $this->_template_args = array( |
|
| 1775 | + 'data' => $json_response_data, |
|
| 1776 | + 'success' => $notices['success'], |
|
| 1777 | + 'error' => $notices['errors'], |
|
| 1778 | + 'attention' => $notices['attention'] |
|
| 1779 | + ); |
|
| 1780 | + $this->_return_json(); |
|
| 1781 | + } |
|
| 1782 | + |
|
| 1783 | + |
|
| 1784 | + /** |
|
| 1785 | + * _registration_payment_data_array |
|
| 1786 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 1787 | + * |
|
| 1788 | + * @access protected |
|
| 1789 | + * |
|
| 1790 | + * @param array $REG_IDs |
|
| 1791 | + * |
|
| 1792 | + * @return array |
|
| 1793 | + */ |
|
| 1794 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 1795 | + { |
|
| 1796 | + $registration_payment_data = array(); |
|
| 1797 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 1798 | + if ( ! empty($REG_IDs)) { |
|
| 1799 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 1800 | + foreach ($registrations as $registration) { |
|
| 1801 | + if ($registration instanceof EE_Registration) { |
|
| 1802 | + $registration_payment_data[$registration->ID()] = array( |
|
| 1803 | + 'paid' => $registration->pretty_paid(), |
|
| 1804 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 1805 | + ); |
|
| 1806 | + } |
|
| 1807 | + } |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + return $registration_payment_data; |
|
| 1811 | + } |
|
| 1812 | + |
|
| 1813 | + |
|
| 1814 | + /** |
|
| 1815 | + * _maybe_send_notifications |
|
| 1816 | + * |
|
| 1817 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 1818 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 1819 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 1820 | + * |
|
| 1821 | + * @access protected |
|
| 1822 | + * |
|
| 1823 | + * @param \EE_Payment | null $payment |
|
| 1824 | + */ |
|
| 1825 | + protected function _maybe_send_notifications($payment = null) |
|
| 1826 | + { |
|
| 1827 | + switch ($payment instanceof EE_Payment) { |
|
| 1828 | + // payment notifications |
|
| 1829 | + case true : |
|
| 1830 | + if ( |
|
| 1831 | + isset( |
|
| 1832 | + $this->_req_data['txn_payments'], |
|
| 1833 | + $this->_req_data['txn_payments']['send_notifications'] |
|
| 1834 | + ) && |
|
| 1835 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1836 | + ) { |
|
| 1837 | + $this->_process_payment_notification($payment); |
|
| 1838 | + } |
|
| 1839 | + break; |
|
| 1840 | + // registration notifications |
|
| 1841 | + case false : |
|
| 1842 | + if ( |
|
| 1843 | + isset( |
|
| 1844 | + $this->_req_data['txn_reg_status_change'], |
|
| 1845 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 1846 | + ) && |
|
| 1847 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1848 | + ) { |
|
| 1849 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 1850 | + } |
|
| 1851 | + break; |
|
| 1852 | + } |
|
| 1853 | + } |
|
| 1854 | + |
|
| 1855 | + |
|
| 1856 | + /** |
|
| 1857 | + * _send_payment_reminder |
|
| 1858 | + * generates HTML for the View Transaction Details Admin page |
|
| 1859 | + * |
|
| 1860 | + * @access protected |
|
| 1861 | + * @return void |
|
| 1862 | + */ |
|
| 1863 | + protected function _send_payment_reminder() |
|
| 1864 | + { |
|
| 1865 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 1866 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 1867 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 1868 | + 'action' => $this->_req_data['redirect_to'], |
|
| 1869 | + 'TXN_ID' => $this->_req_data['TXN_ID'] |
|
| 1870 | + ) : array(); |
|
| 1871 | + do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 1872 | + $transaction); |
|
| 1873 | + $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
| 1874 | + esc_html__('sent', 'event_espresso'), $query_args, true); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * get_transactions |
|
| 1880 | + * get transactions for given parameters (used by list table) |
|
| 1881 | + * |
|
| 1882 | + * @param int $perpage how many transactions displayed per page |
|
| 1883 | + * @param boolean $count return the count or objects |
|
| 1884 | + * @param string $view |
|
| 1885 | + * |
|
| 1886 | + * @return mixed int = count || array of transaction objects |
|
| 1887 | + */ |
|
| 1888 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 1889 | + { |
|
| 1890 | + |
|
| 1891 | + $TXN = EEM_Transaction::instance(); |
|
| 1892 | + |
|
| 1893 | + $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
| 1894 | + strtotime('-10 year')); |
|
| 1895 | + $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
| 1896 | + |
|
| 1897 | + //make sure our timestamps start and end right at the boundaries for each day |
|
| 1898 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1899 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + //convert to timestamps |
|
| 1903 | + $start_date = strtotime($start_date); |
|
| 1904 | + $end_date = strtotime($end_date); |
|
| 1905 | + |
|
| 1906 | + //makes sure start date is the lowest value and vice versa |
|
| 1907 | + $start_date = min($start_date, $end_date); |
|
| 1908 | + $end_date = max($start_date, $end_date); |
|
| 1909 | + |
|
| 1910 | + //convert to correct format for query |
|
| 1911 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1912 | + date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 1913 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1914 | + date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 1915 | + |
|
| 1916 | + |
|
| 1917 | + //set orderby |
|
| 1918 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 1919 | + |
|
| 1920 | + switch ($this->_req_data['orderby']) { |
|
| 1921 | + case 'TXN_ID': |
|
| 1922 | + $orderby = 'TXN_ID'; |
|
| 1923 | + break; |
|
| 1924 | + case 'ATT_fname': |
|
| 1925 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 1926 | + break; |
|
| 1927 | + case 'event_name': |
|
| 1928 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 1929 | + break; |
|
| 1930 | + default: //'TXN_timestamp' |
|
| 1931 | + $orderby = 'TXN_timestamp'; |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 1935 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1936 | + $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
| 1937 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 1938 | + |
|
| 1939 | + $offset = ($current_page - 1) * $per_page; |
|
| 1940 | + $limit = array($offset, $per_page); |
|
| 1941 | + |
|
| 1942 | + $_where = array( |
|
| 1943 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 1944 | + 'Registration.REG_count' => 1 |
|
| 1945 | + ); |
|
| 1946 | + |
|
| 1947 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 1948 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 1949 | + } |
|
| 1950 | + |
|
| 1951 | + if (isset($this->_req_data['s'])) { |
|
| 1952 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1953 | + $_where['OR'] = array( |
|
| 1954 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 1955 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1956 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1957 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1958 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1959 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1960 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1961 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1962 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1963 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1964 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1965 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 1966 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 1967 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 1968 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 1969 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1970 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1971 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 1972 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 1973 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 1974 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string) |
|
| 1975 | + ); |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + //failed transactions |
|
| 1979 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
| 1980 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
| 1981 | + |
|
| 1982 | + if ($failed) { |
|
| 1983 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 1984 | + } else if ($abandoned) { |
|
| 1985 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 1986 | + } else { |
|
| 1987 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 1988 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + $query_params = array( |
|
| 1992 | + $_where, |
|
| 1993 | + 'order_by' => array($orderby => $sort), |
|
| 1994 | + 'limit' => $limit, |
|
| 1995 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only |
|
| 1996 | + ); |
|
| 1997 | + |
|
| 1998 | + $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
| 1999 | + |
|
| 2000 | + |
|
| 2001 | + return $transactions; |
|
| 2002 | + |
|
| 2003 | + } |
|
| 2004 | 2004 | |
| 2005 | 2005 | |
| 2006 | 2006 | } |