@@ -2166,6 +2166,7 @@ |
||
| 2166 | 2166 | * |
| 2167 | 2167 | * @access protected |
| 2168 | 2168 | * @param \EE_Payment | null $payment |
| 2169 | + * @param EE_Payment $payment |
|
| 2169 | 2170 | */ |
| 2170 | 2171 | protected function _maybe_send_notifications($payment = null) |
| 2171 | 2172 | { |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | '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.', |
| 267 | 267 | 'event_espresso' |
| 268 | 268 | ); |
| 269 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 269 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 270 | 270 | 'An error occurred! Please refresh the page and try again.', |
| 271 | 271 | 'event_espresso' |
| 272 | 272 | ); |
@@ -364,13 +364,13 @@ discard block |
||
| 364 | 364 | //enqueue style |
| 365 | 365 | wp_register_style( |
| 366 | 366 | 'espresso_txn', |
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 367 | + TXN_ASSETS_URL.'espresso_transactions_admin.css', |
|
| 368 | 368 | array(), |
| 369 | 369 | EVENT_ESPRESSO_VERSION |
| 370 | 370 | ); |
| 371 | 371 | wp_enqueue_style('espresso_txn'); |
| 372 | 372 | //scripts |
| 373 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 373 | + wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array( |
|
| 374 | 374 | 'ee_admin_js', |
| 375 | 375 | 'ee-datepicker', |
| 376 | 376 | 'jquery-ui-datepicker', |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | : null; |
| 467 | 467 | $this->_transaction->verify_abandoned_transaction_status(); |
| 468 | 468 | |
| 469 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 469 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 470 | 470 | $error_msg = sprintf( |
| 471 | 471 | esc_html__( |
| 472 | 472 | 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
| 565 | 565 | array( |
| 566 | 566 | 'overpaid' => array( |
| 567 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 567 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
| 568 | 568 | 'desc' => EEH_Template::pretty_status( |
| 569 | 569 | EEM_Transaction::overpaid_status_code, |
| 570 | 570 | false, |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | ), |
| 573 | 573 | ), |
| 574 | 574 | 'complete' => array( |
| 575 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 575 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
| 576 | 576 | 'desc' => EEH_Template::pretty_status( |
| 577 | 577 | EEM_Transaction::complete_status_code, |
| 578 | 578 | false, |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | ), |
| 581 | 581 | ), |
| 582 | 582 | 'incomplete' => array( |
| 583 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 583 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
| 584 | 584 | 'desc' => EEH_Template::pretty_status( |
| 585 | 585 | EEM_Transaction::incomplete_status_code, |
| 586 | 586 | false, |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | ), |
| 589 | 589 | ), |
| 590 | 590 | 'abandoned' => array( |
| 591 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 591 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
| 592 | 592 | 'desc' => EEH_Template::pretty_status( |
| 593 | 593 | EEM_Transaction::abandoned_status_code, |
| 594 | 594 | false, |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | ), |
| 597 | 597 | ), |
| 598 | 598 | 'failed' => array( |
| 599 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 599 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
| 600 | 600 | 'desc' => EEH_Template::pretty_status( |
| 601 | 601 | EEM_Transaction::failed_status_code, |
| 602 | 602 | false, |
@@ -645,11 +645,11 @@ discard block |
||
| 645 | 645 | 'Click to Edit event', |
| 646 | 646 | 'event_espresso' |
| 647 | 647 | ) |
| 648 | - . '">' . $event->get('EVT_name') . '</a>', |
|
| 648 | + . '">'.$event->get('EVT_name').'</a>', |
|
| 649 | 649 | '</h3>' |
| 650 | 650 | ) |
| 651 | 651 | : ''; |
| 652 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 652 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 653 | 653 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 654 | 654 | } |
| 655 | 655 | |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | |
| 692 | 692 | $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
| 693 | 693 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
| 694 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 694 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID'); |
|
| 695 | 695 | |
| 696 | 696 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
| 697 | 697 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | |
| 773 | 773 | |
| 774 | 774 | // next link |
| 775 | - $next_txn = $this->_transaction->next( |
|
| 775 | + $next_txn = $this->_transaction->next( |
|
| 776 | 776 | null, |
| 777 | 777 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 778 | 778 | 'TXN_ID' |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | ) |
| 788 | 788 | : ''; |
| 789 | 789 | // previous link |
| 790 | - $previous_txn = $this->_transaction->previous( |
|
| 790 | + $previous_txn = $this->_transaction->previous( |
|
| 791 | 791 | null, |
| 792 | 792 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 793 | 793 | 'TXN_ID' |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | // grab messages at the last second |
| 838 | 838 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 839 | 839 | // path to template |
| 840 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 840 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
| 841 | 841 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
| 842 | 842 | $template_path, |
| 843 | 843 | $this->_template_args, |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | |
| 927 | 927 | //get line table |
| 928 | 928 | EEH_Autoloader::register_line_item_display_autoloaders(); |
| 929 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 929 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 930 | 930 | 'admin_table', |
| 931 | 931 | 'EE_Admin_Table_Line_Item_Display_Strategy' |
| 932 | 932 | ); |
@@ -937,13 +937,13 @@ discard block |
||
| 937 | 937 | ->get('REG_code'); |
| 938 | 938 | |
| 939 | 939 | // process taxes |
| 940 | - $taxes = $this->_transaction->get_many_related( |
|
| 940 | + $taxes = $this->_transaction->get_many_related( |
|
| 941 | 941 | 'Line_Item', |
| 942 | 942 | array(array('LIN_type' => EEM_Line_Item::type_tax)) |
| 943 | 943 | ); |
| 944 | 944 | $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
| 945 | 945 | |
| 946 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 946 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 947 | 947 | $this->_transaction->get('TXN_total'), |
| 948 | 948 | false, |
| 949 | 949 | false |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | |
| 954 | 954 | // process payment details |
| 955 | 955 | $payments = $this->_transaction->get_many_related('Payment'); |
| 956 | - if (! empty($payments)) { |
|
| 956 | + if ( ! empty($payments)) { |
|
| 957 | 957 | $this->_template_args['payments'] = $payments; |
| 958 | 958 | $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
| 959 | 959 | } else { |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
| 1015 | 1015 | ucwords(str_replace('_', ' ', $reg_step)), |
| 1016 | 1016 | date( |
| 1017 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1017 | + get_option('date_format').' '.get_option('time_format'), |
|
| 1018 | 1018 | ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
| 1019 | 1019 | ) |
| 1020 | 1020 | ) |
@@ -1028,7 +1028,7 @@ discard block |
||
| 1028 | 1028 | . '</li>'; |
| 1029 | 1029 | } |
| 1030 | 1030 | } |
| 1031 | - $reg_steps .= '</ul>'; |
|
| 1031 | + $reg_steps .= '</ul>'; |
|
| 1032 | 1032 | $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
| 1033 | 1033 | $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
| 1034 | 1034 | 'Registration Step Progress', |
@@ -1041,11 +1041,11 @@ discard block |
||
| 1041 | 1041 | $this->_get_payment_status_array(); |
| 1042 | 1042 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
| 1043 | 1043 | |
| 1044 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1044 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1045 | 1045 | 'action' => 'edit_transaction', |
| 1046 | 1046 | 'process' => 'transaction', |
| 1047 | 1047 | ), TXN_ADMIN_URL); |
| 1048 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1048 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1049 | 1049 | 'page' => 'espresso_transactions', |
| 1050 | 1050 | 'action' => 'espresso_apply_payment', |
| 1051 | 1051 | ), WP_AJAX_URL); |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | |
| 1057 | 1057 | // 'espresso_delete_payment_nonce' |
| 1058 | 1058 | |
| 1059 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1059 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1060 | 1060 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1061 | 1061 | } |
| 1062 | 1062 | |
@@ -1085,11 +1085,11 @@ discard block |
||
| 1085 | 1085 | ), |
| 1086 | 1086 | ), |
| 1087 | 1087 | )); |
| 1088 | - if (! empty($reg_payments)) { |
|
| 1088 | + if ( ! empty($reg_payments)) { |
|
| 1089 | 1089 | foreach ($payments as $payment) { |
| 1090 | - if (! $payment instanceof EE_Payment) { |
|
| 1090 | + if ( ! $payment instanceof EE_Payment) { |
|
| 1091 | 1091 | continue; |
| 1092 | - } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1092 | + } elseif ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1093 | 1093 | $existing_reg_payments[$payment->ID()] = array(); |
| 1094 | 1094 | } |
| 1095 | 1095 | foreach ($reg_payments as $reg_payment) { |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | protected function _get_registrations_to_apply_payment_to() |
| 1119 | 1119 | { |
| 1120 | 1120 | // we want any registration with an active status (ie: not deleted or cancelled) |
| 1121 | - $query_params = array( |
|
| 1121 | + $query_params = array( |
|
| 1122 | 1122 | array( |
| 1123 | 1123 | 'STS_ID' => array( |
| 1124 | 1124 | 'IN', |
@@ -1137,16 +1137,16 @@ discard block |
||
| 1137 | 1137 | '', |
| 1138 | 1138 | 'clear: both; margin: 1.5em 0 0; display: none;' |
| 1139 | 1139 | ); |
| 1140 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1140 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1141 | 1141 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
| 1142 | 1142 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
| 1143 | 1143 | EEH_HTML::tr( |
| 1144 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1145 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1146 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1147 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1148 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1149 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1144 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
| 1145 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
| 1146 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
| 1147 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
| 1148 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1149 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 1150 | 1150 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
| 1151 | 1151 | ) |
| 1152 | 1152 | ); |
@@ -1161,29 +1161,29 @@ discard block |
||
| 1161 | 1161 | : esc_html__('Unknown Attendee', 'event_espresso'); |
| 1162 | 1162 | $owing = $registration->final_price() - $registration->paid(); |
| 1163 | 1163 | $taxable = $registration->ticket()->taxable() |
| 1164 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1164 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
| 1165 | 1165 | : ''; |
| 1166 | 1166 | $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
| 1167 | 1167 | ? ' checked="checked"' |
| 1168 | 1168 | : ''; |
| 1169 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1169 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1170 | 1170 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
| 1171 | - EEH_HTML::td($registration->ID()) . |
|
| 1172 | - EEH_HTML::td($attendee_name) . |
|
| 1171 | + EEH_HTML::td($registration->ID()). |
|
| 1172 | + EEH_HTML::td($attendee_name). |
|
| 1173 | 1173 | EEH_HTML::td( |
| 1174 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1175 | - ) . |
|
| 1176 | - EEH_HTML::td($registration->event_name()) . |
|
| 1177 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1178 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1174 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
| 1175 | + ). |
|
| 1176 | + EEH_HTML::td($registration->event_name()). |
|
| 1177 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1178 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 1179 | 1179 | EEH_HTML::td( |
| 1180 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1180 | + '<input type="checkbox" value="'.$registration->ID() |
|
| 1181 | 1181 | . '" name="txn_admin_payment[registrations]"' |
| 1182 | - . $checked . $disabled . '>', |
|
| 1182 | + . $checked.$disabled.'>', |
|
| 1183 | 1183 | '', |
| 1184 | 1184 | 'jst-cntr' |
| 1185 | 1185 | ), |
| 1186 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1186 | + 'apply-payment-registration-row-'.$registration->ID() |
|
| 1187 | 1187 | ); |
| 1188 | 1188 | } |
| 1189 | 1189 | } |
@@ -1198,7 +1198,7 @@ discard block |
||
| 1198 | 1198 | '', |
| 1199 | 1199 | 'clear description' |
| 1200 | 1200 | ); |
| 1201 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1201 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1202 | 1202 | $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
@@ -1263,12 +1263,12 @@ discard block |
||
| 1263 | 1263 | array( |
| 1264 | 1264 | 'OR*payment_method_for_payment' => array( |
| 1265 | 1265 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
| 1266 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1266 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'), |
|
| 1267 | 1267 | ), |
| 1268 | 1268 | ), |
| 1269 | 1269 | ); |
| 1270 | 1270 | } else { |
| 1271 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1271 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
| 1272 | 1272 | } |
| 1273 | 1273 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
| 1274 | 1274 | } |
@@ -1297,7 +1297,7 @@ discard block |
||
| 1297 | 1297 | 'Line_Item', |
| 1298 | 1298 | array(array('LIN_type' => 'line-item')) |
| 1299 | 1299 | ); |
| 1300 | - if (! empty($line_items)) { |
|
| 1300 | + if ( ! empty($line_items)) { |
|
| 1301 | 1301 | foreach ($line_items as $item) { |
| 1302 | 1302 | if ($item instanceof EE_Line_Item) { |
| 1303 | 1303 | switch ($item->OBJ_type()) { |
@@ -1307,7 +1307,7 @@ discard block |
||
| 1307 | 1307 | $ticket = $item->ticket(); |
| 1308 | 1308 | //right now we're only handling tickets here. |
| 1309 | 1309 | //Cause its expected that only tickets will have attendees right? |
| 1310 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1310 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1311 | 1311 | continue; |
| 1312 | 1312 | } |
| 1313 | 1313 | try { |
@@ -1316,7 +1316,7 @@ discard block |
||
| 1316 | 1316 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1317 | 1317 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
| 1318 | 1318 | } |
| 1319 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1319 | + $event_name .= ' - '.$item->get('LIN_name'); |
|
| 1320 | 1320 | $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
| 1321 | 1321 | // now get all of the registrations for this transaction that use this ticket |
| 1322 | 1322 | $registrations = $ticket->get_many_related( |
@@ -1324,7 +1324,7 @@ discard block |
||
| 1324 | 1324 | array(array('TXN_ID' => $this->_transaction->ID())) |
| 1325 | 1325 | ); |
| 1326 | 1326 | foreach ($registrations as $registration) { |
| 1327 | - if (! $registration instanceof EE_Registration) { |
|
| 1327 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1328 | 1328 | continue; |
| 1329 | 1329 | } |
| 1330 | 1330 | $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
@@ -1343,12 +1343,12 @@ discard block |
||
| 1343 | 1343 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
| 1344 | 1344 | = $attendee->full_name(); |
| 1345 | 1345 | $this->_template_args['event_attendees'][$registration->ID()]['email'] |
| 1346 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1346 | + = '<a href="mailto:'.$attendee->email().'?subject='.$event_name |
|
| 1347 | 1347 | . esc_html__( |
| 1348 | 1348 | ' Event', |
| 1349 | 1349 | 'event_espresso' |
| 1350 | 1350 | ) |
| 1351 | - . '">' . $attendee->email() . '</a>'; |
|
| 1351 | + . '">'.$attendee->email().'</a>'; |
|
| 1352 | 1352 | $this->_template_args['event_attendees'][$registration->ID()]['address'] |
| 1353 | 1353 | = EEH_Address::format($attendee, 'inline', false, false); |
| 1354 | 1354 | } else { |
@@ -1372,7 +1372,7 @@ discard block |
||
| 1372 | 1372 | TXN_ADMIN_URL |
| 1373 | 1373 | ); |
| 1374 | 1374 | echo EEH_Template::display_template( |
| 1375 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1375 | + TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1376 | 1376 | $this->_template_args, |
| 1377 | 1377 | true |
| 1378 | 1378 | ); |
@@ -1407,12 +1407,12 @@ discard block |
||
| 1407 | 1407 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
| 1408 | 1408 | ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
| 1409 | 1409 | : null; |
| 1410 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1410 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1411 | 1411 | $this->_template_args['no_attendee_message'] = esc_html__( |
| 1412 | 1412 | 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
| 1413 | 1413 | 'event_espresso' |
| 1414 | 1414 | ); |
| 1415 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1415 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1416 | 1416 | } |
| 1417 | 1417 | $this->_template_args['ATT_ID'] = $primary_att->ID(); |
| 1418 | 1418 | $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
@@ -1426,7 +1426,7 @@ discard block |
||
| 1426 | 1426 | // get formatted address for registrant |
| 1427 | 1427 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
| 1428 | 1428 | echo EEH_Template::display_template( |
| 1429 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1429 | + TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1430 | 1430 | $this->_template_args, |
| 1431 | 1431 | true |
| 1432 | 1432 | ); |
@@ -1451,8 +1451,8 @@ discard block |
||
| 1451 | 1451 | TXN_ADMIN_URL |
| 1452 | 1452 | ); |
| 1453 | 1453 | |
| 1454 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1455 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1454 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1455 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/ |
|
| 1456 | 1456 | } |
| 1457 | 1457 | |
| 1458 | 1458 | |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | 'ee_edit_payments', |
| 1478 | 1478 | 'apply_payment_or_refund_from_registration_details' |
| 1479 | 1479 | ); |
| 1480 | - if (! empty($valid_data) && $has_access) { |
|
| 1480 | + if ( ! empty($valid_data) && $has_access) { |
|
| 1481 | 1481 | $PAY_ID = $valid_data['PAY_ID']; |
| 1482 | 1482 | //save the new payment |
| 1483 | 1483 | $payment = $this->_create_payment_from_request_data($valid_data); |
@@ -1490,7 +1490,7 @@ discard block |
||
| 1490 | 1490 | $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
| 1491 | 1491 | $this->_remove_existing_registration_payments($payment, $PAY_ID); |
| 1492 | 1492 | // apply payment to registrations (if applicable) |
| 1493 | - if (! empty($REG_IDs)) { |
|
| 1493 | + if ( ! empty($REG_IDs)) { |
|
| 1494 | 1494 | $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
| 1495 | 1495 | $this->_maybe_send_notifications(); |
| 1496 | 1496 | // now process status changes for the same registrations |
@@ -1538,7 +1538,7 @@ discard block |
||
| 1538 | 1538 | ); |
| 1539 | 1539 | } |
| 1540 | 1540 | } |
| 1541 | - $notices = EE_Error::get_notices( |
|
| 1541 | + $notices = EE_Error::get_notices( |
|
| 1542 | 1542 | false, |
| 1543 | 1543 | false, |
| 1544 | 1544 | false |
@@ -1559,14 +1559,14 @@ discard block |
||
| 1559 | 1559 | */ |
| 1560 | 1560 | protected function _validate_payment_request_data() |
| 1561 | 1561 | { |
| 1562 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1562 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1563 | 1563 | return false; |
| 1564 | 1564 | } |
| 1565 | 1565 | $payment_form = $this->_generate_payment_form_section(); |
| 1566 | 1566 | try { |
| 1567 | 1567 | if ($payment_form->was_submitted()) { |
| 1568 | 1568 | $payment_form->receive_form_submission(); |
| 1569 | - if (! $payment_form->is_valid()) { |
|
| 1569 | + if ( ! $payment_form->is_valid()) { |
|
| 1570 | 1570 | $submission_error_messages = array(); |
| 1571 | 1571 | foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
| 1572 | 1572 | if ($validation_error instanceof EE_Validation_Error) { |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | array('Y-m-d', 'g:i a') |
| 1745 | 1745 | ); |
| 1746 | 1746 | |
| 1747 | - if (! $payment->save()) { |
|
| 1747 | + if ( ! $payment->save()) { |
|
| 1748 | 1748 | EE_Error::add_error( |
| 1749 | 1749 | sprintf( |
| 1750 | 1750 | esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
@@ -1809,7 +1809,7 @@ discard block |
||
| 1809 | 1809 | $REG_IDs = array(); |
| 1810 | 1810 | // grab array of IDs for specific registrations to apply changes to |
| 1811 | 1811 | if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
| 1812 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1812 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1813 | 1813 | } |
| 1814 | 1814 | //nothing specified ? then get all reg IDs |
| 1815 | 1815 | if (empty($REG_IDs)) { |
@@ -1937,12 +1937,12 @@ discard block |
||
| 1937 | 1937 | // but add in some conditions regarding payment, |
| 1938 | 1938 | // so that we don't apply payments to registrations that are free or have already been paid for |
| 1939 | 1939 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
| 1940 | - if (! $payment->is_a_refund()) { |
|
| 1940 | + if ( ! $payment->is_a_refund()) { |
|
| 1941 | 1941 | $registration_query_where_params['REG_final_price'] = array('!=', 0); |
| 1942 | 1942 | $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
| 1943 | 1943 | } |
| 1944 | 1944 | $registrations = $transaction->registrations(array($registration_query_where_params)); |
| 1945 | - if (! empty($registrations)) { |
|
| 1945 | + if ( ! empty($registrations)) { |
|
| 1946 | 1946 | /** @type EE_Payment_Processor $payment_processor */ |
| 1947 | 1947 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
| 1948 | 1948 | $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
@@ -2142,7 +2142,7 @@ discard block |
||
| 2142 | 2142 | { |
| 2143 | 2143 | $registration_payment_data = array(); |
| 2144 | 2144 | //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
| 2145 | - if (! empty($REG_IDs)) { |
|
| 2145 | + if ( ! empty($REG_IDs)) { |
|
| 2146 | 2146 | $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
| 2147 | 2147 | foreach ($registrations as $registration) { |
| 2148 | 2148 | if ($registration instanceof EE_Registration) { |
@@ -2255,13 +2255,13 @@ discard block |
||
| 2255 | 2255 | 'm/d/Y', |
| 2256 | 2256 | strtotime('-10 year') |
| 2257 | 2257 | ); |
| 2258 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2258 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2259 | 2259 | ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
| 2260 | 2260 | : date('m/d/Y'); |
| 2261 | 2261 | |
| 2262 | 2262 | //make sure our timestamps start and end right at the boundaries for each day |
| 2263 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2264 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2263 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 2264 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 2265 | 2265 | |
| 2266 | 2266 | |
| 2267 | 2267 | //convert to timestamps |
@@ -2278,7 +2278,7 @@ discard block |
||
| 2278 | 2278 | date('Y-m-d H:i:s', $start_date), |
| 2279 | 2279 | 'Y-m-d H:i:s' |
| 2280 | 2280 | ); |
| 2281 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2281 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2282 | 2282 | 'TXN_timestamp', |
| 2283 | 2283 | date('Y-m-d H:i:s', $end_date), |
| 2284 | 2284 | 'Y-m-d H:i:s' |
@@ -2320,7 +2320,7 @@ discard block |
||
| 2320 | 2320 | } |
| 2321 | 2321 | |
| 2322 | 2322 | if (isset($this->_req_data['s'])) { |
| 2323 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2323 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 2324 | 2324 | $_where['OR'] = array( |
| 2325 | 2325 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
| 2326 | 2326 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
@@ -2347,9 +2347,9 @@ discard block |
||
| 2347 | 2347 | } |
| 2348 | 2348 | |
| 2349 | 2349 | //failed transactions |
| 2350 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2350 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2351 | 2351 | || ($count && $view === 'failed'); |
| 2352 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2352 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2353 | 2353 | || ($count && $view === 'abandoned'); |
| 2354 | 2354 | |
| 2355 | 2355 | if ($failed) { |
@@ -16,2370 +16,2370 @@ |
||
| 16 | 16 | class Transactions_Admin_Page extends EE_Admin_Page |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var EE_Transaction |
|
| 21 | - */ |
|
| 22 | - private $_transaction; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var EE_Session |
|
| 26 | - */ |
|
| 27 | - private $_session; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var array $_txn_status |
|
| 31 | - */ |
|
| 32 | - private static $_txn_status; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var array $_pay_status |
|
| 36 | - */ |
|
| 37 | - private static $_pay_status; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 41 | - */ |
|
| 42 | - protected $_existing_reg_payment_REG_IDs = null; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @Constructor |
|
| 47 | - * @access public |
|
| 48 | - * @param bool $routing |
|
| 49 | - * @throws EE_Error |
|
| 50 | - * @throws InvalidArgumentException |
|
| 51 | - * @throws ReflectionException |
|
| 52 | - * @throws InvalidDataTypeException |
|
| 53 | - * @throws InvalidInterfaceException |
|
| 54 | - */ |
|
| 55 | - public function __construct($routing = true) |
|
| 56 | - { |
|
| 57 | - parent::__construct($routing); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * _init_page_props |
|
| 63 | - * |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - protected function _init_page_props() |
|
| 67 | - { |
|
| 68 | - $this->page_slug = TXN_PG_SLUG; |
|
| 69 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 70 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 71 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * _ajax_hooks |
|
| 77 | - * |
|
| 78 | - * @return void |
|
| 79 | - */ |
|
| 80 | - protected function _ajax_hooks() |
|
| 81 | - { |
|
| 82 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 83 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 84 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * _define_page_props |
|
| 90 | - * |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - protected function _define_page_props() |
|
| 94 | - { |
|
| 95 | - $this->_admin_page_title = $this->page_label; |
|
| 96 | - $this->_labels = array( |
|
| 97 | - 'buttons' => array( |
|
| 98 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 99 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 100 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 101 | - ), |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * grab url requests and route them |
|
| 108 | - * |
|
| 109 | - * @access private |
|
| 110 | - * @return void |
|
| 111 | - * @throws EE_Error |
|
| 112 | - * @throws InvalidArgumentException |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - */ |
|
| 116 | - public function _set_page_routes() |
|
| 117 | - { |
|
| 118 | - |
|
| 119 | - $this->_set_transaction_status_array(); |
|
| 120 | - |
|
| 121 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 122 | - && ! is_array($this->_req_data['TXN_ID']) |
|
| 123 | - ? $this->_req_data['TXN_ID'] |
|
| 124 | - : 0; |
|
| 125 | - |
|
| 126 | - $this->_page_routes = array( |
|
| 127 | - |
|
| 128 | - 'default' => array( |
|
| 129 | - 'func' => '_transactions_overview_list_table', |
|
| 130 | - 'capability' => 'ee_read_transactions', |
|
| 131 | - ), |
|
| 132 | - |
|
| 133 | - 'view_transaction' => array( |
|
| 134 | - 'func' => '_transaction_details', |
|
| 135 | - 'capability' => 'ee_read_transaction', |
|
| 136 | - 'obj_id' => $txn_id, |
|
| 137 | - ), |
|
| 138 | - |
|
| 139 | - 'send_payment_reminder' => array( |
|
| 140 | - 'func' => '_send_payment_reminder', |
|
| 141 | - 'noheader' => true, |
|
| 142 | - 'capability' => 'ee_send_message', |
|
| 143 | - ), |
|
| 144 | - |
|
| 145 | - 'espresso_apply_payment' => array( |
|
| 146 | - 'func' => 'apply_payments_or_refunds', |
|
| 147 | - 'noheader' => true, |
|
| 148 | - 'capability' => 'ee_edit_payments', |
|
| 149 | - ), |
|
| 150 | - |
|
| 151 | - 'espresso_apply_refund' => array( |
|
| 152 | - 'func' => 'apply_payments_or_refunds', |
|
| 153 | - 'noheader' => true, |
|
| 154 | - 'capability' => 'ee_edit_payments', |
|
| 155 | - ), |
|
| 156 | - |
|
| 157 | - 'espresso_delete_payment' => array( |
|
| 158 | - 'func' => 'delete_payment', |
|
| 159 | - 'noheader' => true, |
|
| 160 | - 'capability' => 'ee_delete_payments', |
|
| 161 | - ), |
|
| 162 | - |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - protected function _set_page_config() |
|
| 168 | - { |
|
| 169 | - $this->_page_config = array( |
|
| 170 | - 'default' => array( |
|
| 171 | - 'nav' => array( |
|
| 172 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 173 | - 'order' => 10, |
|
| 174 | - ), |
|
| 175 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 176 | - 'help_tabs' => array( |
|
| 177 | - 'transactions_overview_help_tab' => array( |
|
| 178 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 179 | - 'filename' => 'transactions_overview', |
|
| 180 | - ), |
|
| 181 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 182 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 183 | - 'filename' => 'transactions_overview_table_column_headings', |
|
| 184 | - ), |
|
| 185 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 186 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 187 | - 'filename' => 'transactions_overview_views_filters_search', |
|
| 188 | - ), |
|
| 189 | - ), |
|
| 190 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 191 | - /** |
|
| 192 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 193 | - * may change in a later iteration so want to keep the code for then. |
|
| 194 | - */ |
|
| 195 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 196 | - 'require_nonce' => false, |
|
| 197 | - ), |
|
| 198 | - 'view_transaction' => array( |
|
| 199 | - 'nav' => array( |
|
| 200 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 201 | - 'order' => 5, |
|
| 202 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
| 203 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 204 | - : $this->_admin_base_url, |
|
| 205 | - 'persistent' => false, |
|
| 206 | - ), |
|
| 207 | - 'help_tabs' => array( |
|
| 208 | - 'transactions_view_transaction_help_tab' => array( |
|
| 209 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 210 | - 'filename' => 'transactions_view_transaction', |
|
| 211 | - ), |
|
| 212 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 213 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 214 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 215 | - ), |
|
| 216 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 217 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 218 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 219 | - ), |
|
| 220 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 221 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 222 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 223 | - ), |
|
| 224 | - ), |
|
| 225 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 226 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 227 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 228 | - |
|
| 229 | - 'require_nonce' => false, |
|
| 230 | - ), |
|
| 231 | - ); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * The below methods aren't used by this class currently |
|
| 237 | - */ |
|
| 238 | - protected function _add_screen_options() |
|
| 239 | - { |
|
| 240 | - //noop |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - protected function _add_feature_pointers() |
|
| 244 | - { |
|
| 245 | - //noop |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - public function admin_init() |
|
| 249 | - { |
|
| 250 | - // IF a registration was JUST added via the admin... |
|
| 251 | - if (isset( |
|
| 252 | - $this->_req_data['redirect_from'], |
|
| 253 | - $this->_req_data['EVT_ID'], |
|
| 254 | - $this->_req_data['event_name'] |
|
| 255 | - )) { |
|
| 256 | - // then set a cookie so that we can block any attempts to use |
|
| 257 | - // the back button as a way to enter another registration. |
|
| 258 | - setcookie( |
|
| 259 | - 'ee_registration_added', |
|
| 260 | - $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/' |
|
| 261 | - ); |
|
| 262 | - // and update the global |
|
| 263 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 264 | - } |
|
| 265 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 266 | - '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.', |
|
| 267 | - 'event_espresso' |
|
| 268 | - ); |
|
| 269 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 270 | - 'An error occurred! Please refresh the page and try again.', |
|
| 271 | - 'event_espresso' |
|
| 272 | - ); |
|
| 273 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 274 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 275 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 276 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 277 | - 'This transaction has been overpaid ! Payments Total', |
|
| 278 | - 'event_espresso' |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - public function admin_notices() |
|
| 283 | - { |
|
| 284 | - //noop |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - public function admin_footer_scripts() |
|
| 288 | - { |
|
| 289 | - //noop |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * _set_transaction_status_array |
|
| 295 | - * sets list of transaction statuses |
|
| 296 | - * |
|
| 297 | - * @access private |
|
| 298 | - * @return void |
|
| 299 | - * @throws EE_Error |
|
| 300 | - * @throws InvalidArgumentException |
|
| 301 | - * @throws InvalidDataTypeException |
|
| 302 | - * @throws InvalidInterfaceException |
|
| 303 | - */ |
|
| 304 | - private function _set_transaction_status_array() |
|
| 305 | - { |
|
| 306 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * get_transaction_status_array |
|
| 312 | - * return the transaction status array for wp_list_table |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @return array |
|
| 316 | - */ |
|
| 317 | - public function get_transaction_status_array() |
|
| 318 | - { |
|
| 319 | - return self::$_txn_status; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * get list of payment statuses |
|
| 325 | - * |
|
| 326 | - * @access private |
|
| 327 | - * @return void |
|
| 328 | - * @throws EE_Error |
|
| 329 | - * @throws InvalidArgumentException |
|
| 330 | - * @throws InvalidDataTypeException |
|
| 331 | - * @throws InvalidInterfaceException |
|
| 332 | - */ |
|
| 333 | - private function _get_payment_status_array() |
|
| 334 | - { |
|
| 335 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 336 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 337 | - |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * _add_screen_options_default |
|
| 343 | - * |
|
| 344 | - * @access protected |
|
| 345 | - * @return void |
|
| 346 | - * @throws InvalidArgumentException |
|
| 347 | - * @throws InvalidDataTypeException |
|
| 348 | - * @throws InvalidInterfaceException |
|
| 349 | - */ |
|
| 350 | - protected function _add_screen_options_default() |
|
| 351 | - { |
|
| 352 | - $this->_per_page_screen_option(); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * load_scripts_styles |
|
| 358 | - * |
|
| 359 | - * @access public |
|
| 360 | - * @return void |
|
| 361 | - */ |
|
| 362 | - public function load_scripts_styles() |
|
| 363 | - { |
|
| 364 | - //enqueue style |
|
| 365 | - wp_register_style( |
|
| 366 | - 'espresso_txn', |
|
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 368 | - array(), |
|
| 369 | - EVENT_ESPRESSO_VERSION |
|
| 370 | - ); |
|
| 371 | - wp_enqueue_style('espresso_txn'); |
|
| 372 | - //scripts |
|
| 373 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 374 | - 'ee_admin_js', |
|
| 375 | - 'ee-datepicker', |
|
| 376 | - 'jquery-ui-datepicker', |
|
| 377 | - 'jquery-ui-draggable', |
|
| 378 | - 'ee-dialog', |
|
| 379 | - 'ee-accounting', |
|
| 380 | - 'ee-serialize-full-array', |
|
| 381 | - ), EVENT_ESPRESSO_VERSION, true); |
|
| 382 | - wp_enqueue_script('espresso_txn'); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * load_scripts_styles_view_transaction |
|
| 388 | - * |
|
| 389 | - * @access public |
|
| 390 | - * @return void |
|
| 391 | - */ |
|
| 392 | - public function load_scripts_styles_view_transaction() |
|
| 393 | - { |
|
| 394 | - //styles |
|
| 395 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * load_scripts_styles_default |
|
| 401 | - * |
|
| 402 | - * @access public |
|
| 403 | - * @return void |
|
| 404 | - */ |
|
| 405 | - public function load_scripts_styles_default() |
|
| 406 | - { |
|
| 407 | - //styles |
|
| 408 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * _set_list_table_views_default |
|
| 414 | - * |
|
| 415 | - * @access protected |
|
| 416 | - * @return void |
|
| 417 | - */ |
|
| 418 | - protected function _set_list_table_views_default() |
|
| 419 | - { |
|
| 420 | - $this->_views = array( |
|
| 421 | - 'all' => array( |
|
| 422 | - 'slug' => 'all', |
|
| 423 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 424 | - 'count' => 0, |
|
| 425 | - ), |
|
| 426 | - 'abandoned' => array( |
|
| 427 | - 'slug' => 'abandoned', |
|
| 428 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 429 | - 'count' => 0, |
|
| 430 | - ), |
|
| 431 | - 'failed' => array( |
|
| 432 | - 'slug' => 'failed', |
|
| 433 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 434 | - 'count' => 0, |
|
| 435 | - ), |
|
| 436 | - ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * _set_transaction_object |
|
| 442 | - * This sets the _transaction property for the transaction details screen |
|
| 443 | - * |
|
| 444 | - * @access private |
|
| 445 | - * @return void |
|
| 446 | - * @throws EE_Error |
|
| 447 | - * @throws InvalidArgumentException |
|
| 448 | - * @throws RuntimeException |
|
| 449 | - * @throws InvalidDataTypeException |
|
| 450 | - * @throws InvalidInterfaceException |
|
| 451 | - */ |
|
| 452 | - private function _set_transaction_object() |
|
| 453 | - { |
|
| 454 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 455 | - return; |
|
| 456 | - } //get out we've already set the object |
|
| 457 | - |
|
| 458 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 459 | - ? absint($this->_req_data['TXN_ID']) |
|
| 460 | - : false; |
|
| 461 | - |
|
| 462 | - //get transaction object |
|
| 463 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 464 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 465 | - ? $this->_transaction->get('TXN_session_data') |
|
| 466 | - : null; |
|
| 467 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 468 | - |
|
| 469 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 470 | - $error_msg = sprintf( |
|
| 471 | - esc_html__( |
|
| 472 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 473 | - 'event_espresso' |
|
| 474 | - ), |
|
| 475 | - $TXN_ID |
|
| 476 | - ); |
|
| 477 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * _transaction_legend_items |
|
| 484 | - * |
|
| 485 | - * @access protected |
|
| 486 | - * @return array |
|
| 487 | - * @throws EE_Error |
|
| 488 | - * @throws InvalidArgumentException |
|
| 489 | - * @throws ReflectionException |
|
| 490 | - * @throws InvalidDataTypeException |
|
| 491 | - * @throws InvalidInterfaceException |
|
| 492 | - */ |
|
| 493 | - protected function _transaction_legend_items() |
|
| 494 | - { |
|
| 495 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 496 | - $items = array(); |
|
| 497 | - |
|
| 498 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 499 | - 'ee_read_global_messages', |
|
| 500 | - 'view_filtered_messages' |
|
| 501 | - )) { |
|
| 502 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 503 | - if (is_array($related_for_icon) |
|
| 504 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 505 | - ) { |
|
| 506 | - $items['view_related_messages'] = array( |
|
| 507 | - 'class' => $related_for_icon['css_class'], |
|
| 508 | - 'desc' => $related_for_icon['label'], |
|
| 509 | - ); |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - $items = apply_filters( |
|
| 514 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 515 | - array_merge( |
|
| 516 | - $items, |
|
| 517 | - array( |
|
| 518 | - 'view_details' => array( |
|
| 519 | - 'class' => 'dashicons dashicons-cart', |
|
| 520 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 521 | - ), |
|
| 522 | - 'view_invoice' => array( |
|
| 523 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 524 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 525 | - ), |
|
| 526 | - 'view_receipt' => array( |
|
| 527 | - 'class' => 'dashicons dashicons-media-default', |
|
| 528 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 529 | - ), |
|
| 530 | - 'view_registration' => array( |
|
| 531 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 532 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 533 | - ), |
|
| 534 | - 'payment_overview_link' => array( |
|
| 535 | - 'class' => 'dashicons dashicons-money', |
|
| 536 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 537 | - ), |
|
| 538 | - ) |
|
| 539 | - ) |
|
| 540 | - ); |
|
| 541 | - |
|
| 542 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 543 | - 'ee_send_message', |
|
| 544 | - 'espresso_transactions_send_payment_reminder' |
|
| 545 | - )) { |
|
| 546 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 547 | - $items['send_payment_reminder'] = array( |
|
| 548 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 549 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 550 | - ); |
|
| 551 | - } else { |
|
| 552 | - $items['blank*'] = array( |
|
| 553 | - 'class' => '', |
|
| 554 | - 'desc' => '', |
|
| 555 | - ); |
|
| 556 | - } |
|
| 557 | - } else { |
|
| 558 | - $items['blank*'] = array( |
|
| 559 | - 'class' => '', |
|
| 560 | - 'desc' => '', |
|
| 561 | - ); |
|
| 562 | - } |
|
| 563 | - $more_items = apply_filters( |
|
| 564 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 565 | - array( |
|
| 566 | - 'overpaid' => array( |
|
| 567 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 568 | - 'desc' => EEH_Template::pretty_status( |
|
| 569 | - EEM_Transaction::overpaid_status_code, |
|
| 570 | - false, |
|
| 571 | - 'sentence' |
|
| 572 | - ), |
|
| 573 | - ), |
|
| 574 | - 'complete' => array( |
|
| 575 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 576 | - 'desc' => EEH_Template::pretty_status( |
|
| 577 | - EEM_Transaction::complete_status_code, |
|
| 578 | - false, |
|
| 579 | - 'sentence' |
|
| 580 | - ), |
|
| 581 | - ), |
|
| 582 | - 'incomplete' => array( |
|
| 583 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 584 | - 'desc' => EEH_Template::pretty_status( |
|
| 585 | - EEM_Transaction::incomplete_status_code, |
|
| 586 | - false, |
|
| 587 | - 'sentence' |
|
| 588 | - ), |
|
| 589 | - ), |
|
| 590 | - 'abandoned' => array( |
|
| 591 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 592 | - 'desc' => EEH_Template::pretty_status( |
|
| 593 | - EEM_Transaction::abandoned_status_code, |
|
| 594 | - false, |
|
| 595 | - 'sentence' |
|
| 596 | - ), |
|
| 597 | - ), |
|
| 598 | - 'failed' => array( |
|
| 599 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 600 | - 'desc' => EEH_Template::pretty_status( |
|
| 601 | - EEM_Transaction::failed_status_code, |
|
| 602 | - false, |
|
| 603 | - 'sentence' |
|
| 604 | - ), |
|
| 605 | - ), |
|
| 606 | - ) |
|
| 607 | - ); |
|
| 608 | - |
|
| 609 | - return array_merge($items, $more_items); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * _transactions_overview_list_table |
|
| 615 | - * |
|
| 616 | - * @access protected |
|
| 617 | - * @return void |
|
| 618 | - * @throws DomainException |
|
| 619 | - * @throws EE_Error |
|
| 620 | - * @throws InvalidArgumentException |
|
| 621 | - * @throws InvalidDataTypeException |
|
| 622 | - * @throws InvalidInterfaceException |
|
| 623 | - * @throws ReflectionException |
|
| 624 | - */ |
|
| 625 | - protected function _transactions_overview_list_table() |
|
| 626 | - { |
|
| 627 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 628 | - $event = isset($this->_req_data['EVT_ID']) |
|
| 629 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 630 | - : null; |
|
| 631 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 632 | - ? sprintf( |
|
| 633 | - esc_html__( |
|
| 634 | - '%sViewing Transactions for the Event: %s%s', |
|
| 635 | - 'event_espresso' |
|
| 636 | - ), |
|
| 637 | - '<h3>', |
|
| 638 | - '<a href="' |
|
| 639 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 640 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 641 | - EVENTS_ADMIN_URL |
|
| 642 | - ) |
|
| 643 | - . '" title="' |
|
| 644 | - . esc_attr__( |
|
| 645 | - 'Click to Edit event', |
|
| 646 | - 'event_espresso' |
|
| 647 | - ) |
|
| 648 | - . '">' . $event->get('EVT_name') . '</a>', |
|
| 649 | - '</h3>' |
|
| 650 | - ) |
|
| 651 | - : ''; |
|
| 652 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 653 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * _transaction_details |
|
| 659 | - * generates HTML for the View Transaction Details Admin page |
|
| 660 | - * |
|
| 661 | - * @access protected |
|
| 662 | - * @return void |
|
| 663 | - * @throws DomainException |
|
| 664 | - * @throws EE_Error |
|
| 665 | - * @throws InvalidArgumentException |
|
| 666 | - * @throws InvalidDataTypeException |
|
| 667 | - * @throws InvalidInterfaceException |
|
| 668 | - * @throws RuntimeException |
|
| 669 | - */ |
|
| 670 | - protected function _transaction_details() |
|
| 671 | - { |
|
| 672 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 673 | - |
|
| 674 | - $this->_set_transaction_status_array(); |
|
| 675 | - |
|
| 676 | - $this->_template_args = array(); |
|
| 677 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 678 | - |
|
| 679 | - $this->_set_transaction_object(); |
|
| 680 | - |
|
| 681 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 682 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 683 | - ? $primary_registration->attendee() |
|
| 684 | - : null; |
|
| 685 | - |
|
| 686 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 687 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 688 | - |
|
| 689 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 690 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 691 | - |
|
| 692 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 693 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 694 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 695 | - |
|
| 696 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 697 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 698 | - |
|
| 699 | - if ($attendee instanceof EE_Attendee |
|
| 700 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 701 | - 'ee_send_message', |
|
| 702 | - 'espresso_transactions_send_payment_reminder' |
|
| 703 | - ) |
|
| 704 | - ) { |
|
| 705 | - $this->_template_args['send_payment_reminder_button'] = |
|
| 706 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 707 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
| 708 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
| 709 | - ? EEH_Template::get_button_or_link( |
|
| 710 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 711 | - array( |
|
| 712 | - 'action' => 'send_payment_reminder', |
|
| 713 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 714 | - 'redirect_to' => 'view_transaction', |
|
| 715 | - ), |
|
| 716 | - TXN_ADMIN_URL |
|
| 717 | - ), |
|
| 718 | - __(' Send Payment Reminder', 'event_espresso'), |
|
| 719 | - 'button secondary-button right', |
|
| 720 | - 'dashicons dashicons-email-alt' |
|
| 721 | - ) |
|
| 722 | - : ''; |
|
| 723 | - } else { |
|
| 724 | - $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 728 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 729 | - $amount_due, |
|
| 730 | - true |
|
| 731 | - ); |
|
| 732 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 733 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 734 | - . $this->_template_args['amount_due']; |
|
| 735 | - } else { |
|
| 736 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 737 | - } |
|
| 738 | - $this->_template_args['amount_due_class'] = ''; |
|
| 739 | - |
|
| 740 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 741 | - // paid in full |
|
| 742 | - $this->_template_args['amount_due'] = false; |
|
| 743 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 744 | - // overpaid |
|
| 745 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 746 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 747 | - && $this->_transaction->get('TXN_paid') > 0 |
|
| 748 | - ) { |
|
| 749 | - // monies owing |
|
| 750 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 751 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 752 | - && $this->_transaction->get('TXN_paid') == 0 |
|
| 753 | - ) { |
|
| 754 | - // no payments made yet |
|
| 755 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 756 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 757 | - // free event |
|
| 758 | - $this->_template_args['amount_due'] = false; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - $payment_method = $this->_transaction->payment_method(); |
|
| 762 | - |
|
| 763 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 764 | - ? $payment_method->admin_name() |
|
| 765 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 766 | - |
|
| 767 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 768 | - // link back to overview |
|
| 769 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 770 | - ? $_SERVER['HTTP_REFERER'] |
|
| 771 | - : TXN_ADMIN_URL; |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - // next link |
|
| 775 | - $next_txn = $this->_transaction->next( |
|
| 776 | - null, |
|
| 777 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 778 | - 'TXN_ID' |
|
| 779 | - ); |
|
| 780 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 781 | - ? $this->_next_link( |
|
| 782 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 783 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 784 | - TXN_ADMIN_URL |
|
| 785 | - ), |
|
| 786 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 787 | - ) |
|
| 788 | - : ''; |
|
| 789 | - // previous link |
|
| 790 | - $previous_txn = $this->_transaction->previous( |
|
| 791 | - null, |
|
| 792 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 793 | - 'TXN_ID' |
|
| 794 | - ); |
|
| 795 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 796 | - ? $this->_previous_link( |
|
| 797 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 798 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 799 | - TXN_ADMIN_URL |
|
| 800 | - ), |
|
| 801 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 802 | - ) |
|
| 803 | - : ''; |
|
| 804 | - |
|
| 805 | - // were we just redirected here after adding a new registration ??? |
|
| 806 | - if (isset( |
|
| 807 | - $this->_req_data['redirect_from'], |
|
| 808 | - $this->_req_data['EVT_ID'], |
|
| 809 | - $this->_req_data['event_name'] |
|
| 810 | - )) { |
|
| 811 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 812 | - 'ee_edit_registrations', |
|
| 813 | - 'espresso_registrations_new_registration', |
|
| 814 | - $this->_req_data['EVT_ID'] |
|
| 815 | - )) { |
|
| 816 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 817 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 818 | - array( |
|
| 819 | - 'page' => 'espresso_registrations', |
|
| 820 | - 'action' => 'new_registration', |
|
| 821 | - 'return' => 'default', |
|
| 822 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 823 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 824 | - ), |
|
| 825 | - REG_ADMIN_URL |
|
| 826 | - ); |
|
| 827 | - $this->_admin_page_title .= '">'; |
|
| 828 | - |
|
| 829 | - $this->_admin_page_title .= sprintf( |
|
| 830 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 831 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 832 | - ); |
|
| 833 | - $this->_admin_page_title .= '</a>'; |
|
| 834 | - } |
|
| 835 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 836 | - } |
|
| 837 | - // grab messages at the last second |
|
| 838 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 839 | - // path to template |
|
| 840 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 841 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 842 | - $template_path, |
|
| 843 | - $this->_template_args, |
|
| 844 | - true |
|
| 845 | - ); |
|
| 846 | - |
|
| 847 | - // the details template wrapper |
|
| 848 | - $this->display_admin_page_with_sidebar(); |
|
| 849 | - |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * _transaction_details_metaboxes |
|
| 855 | - * |
|
| 856 | - * @access protected |
|
| 857 | - * @return void |
|
| 858 | - * @throws EE_Error |
|
| 859 | - * @throws InvalidArgumentException |
|
| 860 | - * @throws InvalidDataTypeException |
|
| 861 | - * @throws InvalidInterfaceException |
|
| 862 | - * @throws RuntimeException |
|
| 863 | - */ |
|
| 864 | - protected function _transaction_details_metaboxes() |
|
| 865 | - { |
|
| 866 | - |
|
| 867 | - $this->_set_transaction_object(); |
|
| 868 | - |
|
| 869 | - add_meta_box( |
|
| 870 | - 'edit-txn-details-mbox', |
|
| 871 | - esc_html__('Transaction Details', 'event_espresso'), |
|
| 872 | - array($this, 'txn_details_meta_box'), |
|
| 873 | - $this->_wp_page_slug, |
|
| 874 | - 'normal', |
|
| 875 | - 'high' |
|
| 876 | - ); |
|
| 877 | - add_meta_box( |
|
| 878 | - 'edit-txn-attendees-mbox', |
|
| 879 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 880 | - array($this, 'txn_attendees_meta_box'), |
|
| 881 | - $this->_wp_page_slug, |
|
| 882 | - 'normal', |
|
| 883 | - 'high', |
|
| 884 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 885 | - ); |
|
| 886 | - add_meta_box( |
|
| 887 | - 'edit-txn-registrant-mbox', |
|
| 888 | - esc_html__('Primary Contact', 'event_espresso'), |
|
| 889 | - array($this, 'txn_registrant_side_meta_box'), |
|
| 890 | - $this->_wp_page_slug, |
|
| 891 | - 'side', |
|
| 892 | - 'high' |
|
| 893 | - ); |
|
| 894 | - add_meta_box( |
|
| 895 | - 'edit-txn-billing-info-mbox', |
|
| 896 | - esc_html__('Billing Information', 'event_espresso'), |
|
| 897 | - array($this, 'txn_billing_info_side_meta_box'), |
|
| 898 | - $this->_wp_page_slug, |
|
| 899 | - 'side', |
|
| 900 | - 'high' |
|
| 901 | - ); |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * txn_details_meta_box |
|
| 907 | - * generates HTML for the Transaction main meta box |
|
| 908 | - * |
|
| 909 | - * @access public |
|
| 910 | - * @return void |
|
| 911 | - * @throws DomainException |
|
| 912 | - * @throws EE_Error |
|
| 913 | - * @throws InvalidArgumentException |
|
| 914 | - * @throws InvalidDataTypeException |
|
| 915 | - * @throws InvalidInterfaceException |
|
| 916 | - * @throws RuntimeException |
|
| 917 | - */ |
|
| 918 | - public function txn_details_meta_box() |
|
| 919 | - { |
|
| 920 | - |
|
| 921 | - $this->_set_transaction_object(); |
|
| 922 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 923 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 924 | - ? $this->_transaction->primary_registration()->attendee() |
|
| 925 | - : null; |
|
| 926 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 927 | - 'ee_edit_payments', |
|
| 928 | - 'apply_payment_or_refund_from_registration_details' |
|
| 929 | - ); |
|
| 930 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | - 'ee_delete_payments', |
|
| 932 | - 'delete_payment_from_registration_details' |
|
| 933 | - ); |
|
| 934 | - |
|
| 935 | - //get line table |
|
| 936 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 937 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 938 | - 'admin_table', |
|
| 939 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 940 | - ); |
|
| 941 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 942 | - $this->_transaction->total_line_item() |
|
| 943 | - ); |
|
| 944 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
| 945 | - ->get('REG_code'); |
|
| 946 | - |
|
| 947 | - // process taxes |
|
| 948 | - $taxes = $this->_transaction->get_many_related( |
|
| 949 | - 'Line_Item', |
|
| 950 | - array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
| 951 | - ); |
|
| 952 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 953 | - |
|
| 954 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 955 | - $this->_transaction->get('TXN_total'), |
|
| 956 | - false, |
|
| 957 | - false |
|
| 958 | - ); |
|
| 959 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 960 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 961 | - |
|
| 962 | - // process payment details |
|
| 963 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
| 964 | - if (! empty($payments)) { |
|
| 965 | - $this->_template_args['payments'] = $payments; |
|
| 966 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 967 | - } else { |
|
| 968 | - $this->_template_args['payments'] = false; |
|
| 969 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 973 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 974 | - array('action' => 'espresso_delete_payment'), |
|
| 975 | - TXN_ADMIN_URL |
|
| 976 | - ); |
|
| 977 | - |
|
| 978 | - if (isset($txn_details['invoice_number'])) { |
|
| 979 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 980 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 981 | - 'Invoice Number', |
|
| 982 | - 'event_espresso' |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 987 | - ->get_first_related('Registration') |
|
| 988 | - ->get('REG_session'); |
|
| 989 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 990 | - 'Registration Session', |
|
| 991 | - 'event_espresso' |
|
| 992 | - ); |
|
| 993 | - |
|
| 994 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 995 | - ? $this->_session['ip_address'] |
|
| 996 | - : ''; |
|
| 997 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 998 | - 'Transaction placed from IP', |
|
| 999 | - 'event_espresso' |
|
| 1000 | - ); |
|
| 1001 | - |
|
| 1002 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1003 | - ? $this->_session['user_agent'] |
|
| 1004 | - : ''; |
|
| 1005 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1006 | - 'Registrant User Agent', |
|
| 1007 | - 'event_espresso' |
|
| 1008 | - ); |
|
| 1009 | - |
|
| 1010 | - $reg_steps = '<ul>'; |
|
| 1011 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1012 | - if ($reg_step_status === true) { |
|
| 1013 | - $reg_steps .= '<li style="color:#70cc50">' |
|
| 1014 | - . sprintf( |
|
| 1015 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1016 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1017 | - ) |
|
| 1018 | - . '</li>'; |
|
| 1019 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1020 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1021 | - . sprintf( |
|
| 1022 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1023 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1024 | - date( |
|
| 1025 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1026 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 1027 | - ) |
|
| 1028 | - ) |
|
| 1029 | - . '</li>'; |
|
| 1030 | - } else { |
|
| 1031 | - $reg_steps .= '<li style="color:#E76700">' |
|
| 1032 | - . sprintf( |
|
| 1033 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1034 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1035 | - ) |
|
| 1036 | - . '</li>'; |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - $reg_steps .= '</ul>'; |
|
| 1040 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1041 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1042 | - 'Registration Step Progress', |
|
| 1043 | - 'event_espresso' |
|
| 1044 | - ); |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 1048 | - $this->_get_payment_methods($payments); |
|
| 1049 | - $this->_get_payment_status_array(); |
|
| 1050 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 1051 | - |
|
| 1052 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1053 | - 'action' => 'edit_transaction', |
|
| 1054 | - 'process' => 'transaction', |
|
| 1055 | - ), TXN_ADMIN_URL); |
|
| 1056 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1057 | - 'page' => 'espresso_transactions', |
|
| 1058 | - 'action' => 'espresso_apply_payment', |
|
| 1059 | - ), WP_AJAX_URL); |
|
| 1060 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 1061 | - 'page' => 'espresso_transactions', |
|
| 1062 | - 'action' => 'espresso_delete_payment', |
|
| 1063 | - ), WP_AJAX_URL); |
|
| 1064 | - |
|
| 1065 | - // 'espresso_delete_payment_nonce' |
|
| 1066 | - |
|
| 1067 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1068 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * _get_registration_payment_IDs |
|
| 1074 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1075 | - * |
|
| 1076 | - * @access protected |
|
| 1077 | - * @param EE_Payment[] $payments |
|
| 1078 | - * @return array |
|
| 1079 | - * @throws EE_Error |
|
| 1080 | - * @throws InvalidArgumentException |
|
| 1081 | - * @throws InvalidDataTypeException |
|
| 1082 | - * @throws InvalidInterfaceException |
|
| 1083 | - */ |
|
| 1084 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 1085 | - { |
|
| 1086 | - $existing_reg_payments = array(); |
|
| 1087 | - // get all reg payments for these payments |
|
| 1088 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 1089 | - array( |
|
| 1090 | - 'PAY_ID' => array( |
|
| 1091 | - 'IN', |
|
| 1092 | - array_keys($payments), |
|
| 1093 | - ), |
|
| 1094 | - ), |
|
| 1095 | - )); |
|
| 1096 | - if (! empty($reg_payments)) { |
|
| 1097 | - foreach ($payments as $payment) { |
|
| 1098 | - if (! $payment instanceof EE_Payment) { |
|
| 1099 | - continue; |
|
| 1100 | - } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1101 | - $existing_reg_payments[$payment->ID()] = array(); |
|
| 1102 | - } |
|
| 1103 | - foreach ($reg_payments as $reg_payment) { |
|
| 1104 | - if ($reg_payment instanceof EE_Registration_Payment |
|
| 1105 | - && $reg_payment->payment_ID() === $payment->ID() |
|
| 1106 | - ) { |
|
| 1107 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - return $existing_reg_payments; |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - |
|
| 1117 | - /** |
|
| 1118 | - * _get_registrations_to_apply_payment_to |
|
| 1119 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1120 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 1121 | - * |
|
| 1122 | - * @access protected |
|
| 1123 | - * @return void |
|
| 1124 | - * @throws \EE_Error |
|
| 1125 | - */ |
|
| 1126 | - protected function _get_registrations_to_apply_payment_to() |
|
| 1127 | - { |
|
| 1128 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1129 | - $query_params = array( |
|
| 1130 | - array( |
|
| 1131 | - 'STS_ID' => array( |
|
| 1132 | - 'IN', |
|
| 1133 | - array( |
|
| 1134 | - EEM_Registration::status_id_approved, |
|
| 1135 | - EEM_Registration::status_id_pending_payment, |
|
| 1136 | - EEM_Registration::status_id_not_approved, |
|
| 1137 | - ), |
|
| 1138 | - ), |
|
| 1139 | - ), |
|
| 1140 | - ); |
|
| 1141 | - $registrations_to_apply_payment_to = EEH_HTML::br() |
|
| 1142 | - . EEH_HTML::div( |
|
| 1143 | - '', |
|
| 1144 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1145 | - '', |
|
| 1146 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1147 | - ); |
|
| 1148 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1149 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1150 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1151 | - EEH_HTML::tr( |
|
| 1152 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1153 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1154 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1155 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1156 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1157 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1158 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1159 | - ) |
|
| 1160 | - ); |
|
| 1161 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1162 | - // get registrations for TXN |
|
| 1163 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 1164 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1165 | - foreach ($registrations as $registration) { |
|
| 1166 | - if ($registration instanceof EE_Registration) { |
|
| 1167 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1168 | - ? $registration->attendee()->full_name() |
|
| 1169 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1170 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 1171 | - $taxable = $registration->ticket()->taxable() |
|
| 1172 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1173 | - : ''; |
|
| 1174 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 1175 | - ? ' checked="checked"' |
|
| 1176 | - : ''; |
|
| 1177 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1178 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1179 | - EEH_HTML::td($registration->ID()) . |
|
| 1180 | - EEH_HTML::td($attendee_name) . |
|
| 1181 | - EEH_HTML::td( |
|
| 1182 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1183 | - ) . |
|
| 1184 | - EEH_HTML::td($registration->event_name()) . |
|
| 1185 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1186 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1187 | - EEH_HTML::td( |
|
| 1188 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1189 | - . '" name="txn_admin_payment[registrations]"' |
|
| 1190 | - . $checked . $disabled . '>', |
|
| 1191 | - '', |
|
| 1192 | - 'jst-cntr' |
|
| 1193 | - ), |
|
| 1194 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1195 | - ); |
|
| 1196 | - } |
|
| 1197 | - } |
|
| 1198 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1199 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1200 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1201 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1202 | - esc_html__( |
|
| 1203 | - '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.', |
|
| 1204 | - 'event_espresso' |
|
| 1205 | - ), |
|
| 1206 | - '', |
|
| 1207 | - 'clear description' |
|
| 1208 | - ); |
|
| 1209 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1210 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * _get_reg_status_selection |
|
| 1216 | - * |
|
| 1217 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1218 | - * instead of events. |
|
| 1219 | - * @access protected |
|
| 1220 | - * @return void |
|
| 1221 | - * @throws EE_Error |
|
| 1222 | - */ |
|
| 1223 | - protected function _get_reg_status_selection() |
|
| 1224 | - { |
|
| 1225 | - //first get all possible statuses |
|
| 1226 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1227 | - //let's add a "don't change" option. |
|
| 1228 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1229 | - $status_array = array_merge($status_array, $statuses); |
|
| 1230 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1231 | - 'txn_reg_status_change[reg_status]', |
|
| 1232 | - $status_array, |
|
| 1233 | - 'NAN', |
|
| 1234 | - 'id="txn-admin-payment-reg-status-inp"', |
|
| 1235 | - 'txn-reg-status-change-reg-status' |
|
| 1236 | - ); |
|
| 1237 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1238 | - 'delete_txn_reg_status_change[reg_status]', |
|
| 1239 | - $status_array, |
|
| 1240 | - 'NAN', |
|
| 1241 | - 'delete-txn-admin-payment-reg-status-inp', |
|
| 1242 | - 'delete-txn-reg-status-change-reg-status' |
|
| 1243 | - ); |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * _get_payment_methods |
|
| 1249 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1250 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1251 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1252 | - * |
|
| 1253 | - * @access private |
|
| 1254 | - * @param EE_Payment[] to show on this page |
|
| 1255 | - * @return void |
|
| 1256 | - * @throws EE_Error |
|
| 1257 | - * @throws InvalidArgumentException |
|
| 1258 | - * @throws InvalidDataTypeException |
|
| 1259 | - * @throws InvalidInterfaceException |
|
| 1260 | - */ |
|
| 1261 | - private function _get_payment_methods($payments = array()) |
|
| 1262 | - { |
|
| 1263 | - $payment_methods_of_payments = array(); |
|
| 1264 | - foreach ($payments as $payment) { |
|
| 1265 | - if ($payment instanceof EE_Payment) { |
|
| 1266 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - if ($payment_methods_of_payments) { |
|
| 1270 | - $query_args = array( |
|
| 1271 | - array( |
|
| 1272 | - 'OR*payment_method_for_payment' => array( |
|
| 1273 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1274 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1275 | - ), |
|
| 1276 | - ), |
|
| 1277 | - ); |
|
| 1278 | - } else { |
|
| 1279 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1280 | - } |
|
| 1281 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * txn_attendees_meta_box |
|
| 1287 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1288 | - * |
|
| 1289 | - * @access public |
|
| 1290 | - * @param WP_Post $post |
|
| 1291 | - * @param array $metabox |
|
| 1292 | - * @return void |
|
| 1293 | - * @throws DomainException |
|
| 1294 | - * @throws EE_Error |
|
| 1295 | - */ |
|
| 1296 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1297 | - { |
|
| 1298 | - |
|
| 1299 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1300 | - extract($metabox['args']); |
|
| 1301 | - $this->_template_args['post'] = $post; |
|
| 1302 | - $this->_template_args['event_attendees'] = array(); |
|
| 1303 | - // process items in cart |
|
| 1304 | - $line_items = $this->_transaction->get_many_related( |
|
| 1305 | - 'Line_Item', |
|
| 1306 | - array(array('LIN_type' => 'line-item')) |
|
| 1307 | - ); |
|
| 1308 | - if (! empty($line_items)) { |
|
| 1309 | - foreach ($line_items as $item) { |
|
| 1310 | - if ($item instanceof EE_Line_Item) { |
|
| 1311 | - switch ($item->OBJ_type()) { |
|
| 1312 | - case 'Event': |
|
| 1313 | - break; |
|
| 1314 | - case 'Ticket': |
|
| 1315 | - $ticket = $item->ticket(); |
|
| 1316 | - //right now we're only handling tickets here. |
|
| 1317 | - //Cause its expected that only tickets will have attendees right? |
|
| 1318 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1319 | - continue; |
|
| 1320 | - } |
|
| 1321 | - try { |
|
| 1322 | - $event_name = $ticket->get_event_name(); |
|
| 1323 | - } catch (Exception $e) { |
|
| 1324 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1325 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1326 | - } |
|
| 1327 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1328 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1329 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1330 | - $registrations = $ticket->get_many_related( |
|
| 1331 | - 'Registration', |
|
| 1332 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1333 | - ); |
|
| 1334 | - foreach ($registrations as $registration) { |
|
| 1335 | - if (! $registration instanceof EE_Registration) { |
|
| 1336 | - continue; |
|
| 1337 | - } |
|
| 1338 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
| 1339 | - = $registration->status_ID(); |
|
| 1340 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
| 1341 | - = $registration->count(); |
|
| 1342 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
| 1343 | - = $event_name; |
|
| 1344 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
| 1345 | - = $ticket_price; |
|
| 1346 | - // attendee info |
|
| 1347 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1348 | - if ($attendee instanceof EE_Attendee) { |
|
| 1349 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
| 1350 | - = $attendee->ID(); |
|
| 1351 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
| 1352 | - = $attendee->full_name(); |
|
| 1353 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
| 1354 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1355 | - . esc_html__( |
|
| 1356 | - ' Event', |
|
| 1357 | - 'event_espresso' |
|
| 1358 | - ) |
|
| 1359 | - . '">' . $attendee->email() . '</a>'; |
|
| 1360 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
| 1361 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1362 | - } else { |
|
| 1363 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1364 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1365 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1366 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - break; |
|
| 1370 | - |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1376 | - array( |
|
| 1377 | - 'action' => 'edit_transaction', |
|
| 1378 | - 'process' => 'attendees', |
|
| 1379 | - ), |
|
| 1380 | - TXN_ADMIN_URL |
|
| 1381 | - ); |
|
| 1382 | - echo EEH_Template::display_template( |
|
| 1383 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1384 | - $this->_template_args, |
|
| 1385 | - true |
|
| 1386 | - ); |
|
| 1387 | - |
|
| 1388 | - } else { |
|
| 1389 | - echo sprintf( |
|
| 1390 | - esc_html__( |
|
| 1391 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1392 | - 'event_espresso' |
|
| 1393 | - ), |
|
| 1394 | - '<p class="important-notice">', |
|
| 1395 | - '</p>' |
|
| 1396 | - ); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * txn_registrant_side_meta_box |
|
| 1403 | - * generates HTML for the Edit Transaction side meta box |
|
| 1404 | - * |
|
| 1405 | - * @access public |
|
| 1406 | - * @return void |
|
| 1407 | - * @throws DomainException |
|
| 1408 | - * @throws EE_Error |
|
| 1409 | - * @throws InvalidArgumentException |
|
| 1410 | - * @throws InvalidDataTypeException |
|
| 1411 | - * @throws InvalidInterfaceException |
|
| 1412 | - */ |
|
| 1413 | - public function txn_registrant_side_meta_box() |
|
| 1414 | - { |
|
| 1415 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1416 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1417 | - : null; |
|
| 1418 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1419 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1420 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1421 | - 'event_espresso' |
|
| 1422 | - ); |
|
| 1423 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1424 | - } |
|
| 1425 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1426 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1427 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1428 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1429 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1430 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1431 | - 'action' => 'edit_attendee', |
|
| 1432 | - 'post' => $primary_att->ID(), |
|
| 1433 | - ), REG_ADMIN_URL); |
|
| 1434 | - // get formatted address for registrant |
|
| 1435 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1436 | - echo EEH_Template::display_template( |
|
| 1437 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1438 | - $this->_template_args, |
|
| 1439 | - true |
|
| 1440 | - ); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - |
|
| 1444 | - /** |
|
| 1445 | - * txn_billing_info_side_meta_box |
|
| 1446 | - * generates HTML for the Edit Transaction side meta box |
|
| 1447 | - * |
|
| 1448 | - * @access public |
|
| 1449 | - * @return void |
|
| 1450 | - * @throws DomainException |
|
| 1451 | - * @throws EE_Error |
|
| 1452 | - */ |
|
| 1453 | - public function txn_billing_info_side_meta_box() |
|
| 1454 | - { |
|
| 1455 | - |
|
| 1456 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1457 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1458 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1459 | - TXN_ADMIN_URL |
|
| 1460 | - ); |
|
| 1461 | - |
|
| 1462 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1463 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * apply_payments_or_refunds |
|
| 1469 | - * registers a payment or refund made towards a transaction |
|
| 1470 | - * |
|
| 1471 | - * @access public |
|
| 1472 | - * @return void |
|
| 1473 | - * @throws EE_Error |
|
| 1474 | - * @throws InvalidArgumentException |
|
| 1475 | - * @throws ReflectionException |
|
| 1476 | - * @throws RuntimeException |
|
| 1477 | - * @throws InvalidDataTypeException |
|
| 1478 | - * @throws InvalidInterfaceException |
|
| 1479 | - */ |
|
| 1480 | - public function apply_payments_or_refunds() |
|
| 1481 | - { |
|
| 1482 | - $json_response_data = array('return_data' => false); |
|
| 1483 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1484 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1485 | - 'ee_edit_payments', |
|
| 1486 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1487 | - ); |
|
| 1488 | - if (! empty($valid_data) && $has_access) { |
|
| 1489 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1490 | - //save the new payment |
|
| 1491 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1492 | - // get the TXN for this payment |
|
| 1493 | - $transaction = $payment->transaction(); |
|
| 1494 | - // verify transaction |
|
| 1495 | - if ($transaction instanceof EE_Transaction) { |
|
| 1496 | - // calculate_total_payments_and_update_status |
|
| 1497 | - $this->_process_transaction_payments($transaction); |
|
| 1498 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1499 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1500 | - // apply payment to registrations (if applicable) |
|
| 1501 | - if (! empty($REG_IDs)) { |
|
| 1502 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1503 | - $this->_maybe_send_notifications(); |
|
| 1504 | - // now process status changes for the same registrations |
|
| 1505 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1506 | - } |
|
| 1507 | - $this->_maybe_send_notifications($payment); |
|
| 1508 | - //prepare to render page |
|
| 1509 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1510 | - do_action( |
|
| 1511 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1512 | - $transaction, |
|
| 1513 | - $payment |
|
| 1514 | - ); |
|
| 1515 | - } else { |
|
| 1516 | - EE_Error::add_error( |
|
| 1517 | - esc_html__( |
|
| 1518 | - 'A valid Transaction for this payment could not be retrieved.', |
|
| 1519 | - 'event_espresso' |
|
| 1520 | - ), |
|
| 1521 | - __FILE__, |
|
| 1522 | - __FUNCTION__, |
|
| 1523 | - __LINE__ |
|
| 1524 | - ); |
|
| 1525 | - } |
|
| 1526 | - } else { |
|
| 1527 | - if ($has_access) { |
|
| 1528 | - EE_Error::add_error( |
|
| 1529 | - esc_html__( |
|
| 1530 | - 'The payment form data could not be processed. Please try again.', |
|
| 1531 | - 'event_espresso' |
|
| 1532 | - ), |
|
| 1533 | - __FILE__, |
|
| 1534 | - __FUNCTION__, |
|
| 1535 | - __LINE__ |
|
| 1536 | - ); |
|
| 1537 | - } else { |
|
| 1538 | - EE_Error::add_error( |
|
| 1539 | - esc_html__( |
|
| 1540 | - 'You do not have access to apply payments or refunds to a registration.', |
|
| 1541 | - 'event_espresso' |
|
| 1542 | - ), |
|
| 1543 | - __FILE__, |
|
| 1544 | - __FUNCTION__, |
|
| 1545 | - __LINE__ |
|
| 1546 | - ); |
|
| 1547 | - } |
|
| 1548 | - } |
|
| 1549 | - $notices = EE_Error::get_notices( |
|
| 1550 | - false, |
|
| 1551 | - false, |
|
| 1552 | - false |
|
| 1553 | - ); |
|
| 1554 | - $this->_template_args = array( |
|
| 1555 | - 'data' => $json_response_data, |
|
| 1556 | - 'error' => $notices['errors'], |
|
| 1557 | - 'success' => $notices['success'], |
|
| 1558 | - ); |
|
| 1559 | - $this->_return_json(); |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - |
|
| 1563 | - /** |
|
| 1564 | - * _validate_payment_request_data |
|
| 1565 | - * |
|
| 1566 | - * @return array |
|
| 1567 | - */ |
|
| 1568 | - protected function _validate_payment_request_data() |
|
| 1569 | - { |
|
| 1570 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1571 | - return false; |
|
| 1572 | - } |
|
| 1573 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1574 | - try { |
|
| 1575 | - if ($payment_form->was_submitted()) { |
|
| 1576 | - $payment_form->receive_form_submission(); |
|
| 1577 | - if (! $payment_form->is_valid()) { |
|
| 1578 | - $submission_error_messages = array(); |
|
| 1579 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1580 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1581 | - $submission_error_messages[] = sprintf( |
|
| 1582 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1583 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1584 | - $validation_error->getMessage() |
|
| 1585 | - ); |
|
| 1586 | - } |
|
| 1587 | - } |
|
| 1588 | - EE_Error::add_error( |
|
| 1589 | - implode('<br />', $submission_error_messages), |
|
| 1590 | - __FILE__, |
|
| 1591 | - __FUNCTION__, |
|
| 1592 | - __LINE__ |
|
| 1593 | - ); |
|
| 1594 | - |
|
| 1595 | - return array(); |
|
| 1596 | - } |
|
| 1597 | - } |
|
| 1598 | - } catch (EE_Error $e) { |
|
| 1599 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1600 | - |
|
| 1601 | - return array(); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - return $payment_form->valid_data(); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * _generate_payment_form_section |
|
| 1610 | - * |
|
| 1611 | - * @return EE_Form_Section_Proper |
|
| 1612 | - */ |
|
| 1613 | - protected function _generate_payment_form_section() |
|
| 1614 | - { |
|
| 1615 | - return new EE_Form_Section_Proper( |
|
| 1616 | - array( |
|
| 1617 | - 'name' => 'txn_admin_payment', |
|
| 1618 | - 'subsections' => array( |
|
| 1619 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1620 | - array( |
|
| 1621 | - 'default' => 0, |
|
| 1622 | - 'required' => false, |
|
| 1623 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1624 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1625 | - ) |
|
| 1626 | - ), |
|
| 1627 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1628 | - array( |
|
| 1629 | - 'default' => 0, |
|
| 1630 | - 'required' => true, |
|
| 1631 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1632 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1633 | - ) |
|
| 1634 | - ), |
|
| 1635 | - 'type' => new EE_Text_Input( |
|
| 1636 | - array( |
|
| 1637 | - 'default' => 1, |
|
| 1638 | - 'required' => true, |
|
| 1639 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1640 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1641 | - ) |
|
| 1642 | - ), |
|
| 1643 | - 'amount' => new EE_Text_Input( |
|
| 1644 | - array( |
|
| 1645 | - 'default' => 0, |
|
| 1646 | - 'required' => true, |
|
| 1647 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1648 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1649 | - ) |
|
| 1650 | - ), |
|
| 1651 | - 'status' => new EE_Text_Input( |
|
| 1652 | - array( |
|
| 1653 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1654 | - 'required' => true, |
|
| 1655 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1656 | - ) |
|
| 1657 | - ), |
|
| 1658 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1659 | - array( |
|
| 1660 | - 'default' => 2, |
|
| 1661 | - 'required' => true, |
|
| 1662 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1663 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1664 | - ) |
|
| 1665 | - ), |
|
| 1666 | - 'date' => new EE_Text_Input( |
|
| 1667 | - array( |
|
| 1668 | - 'default' => time(), |
|
| 1669 | - 'required' => true, |
|
| 1670 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1671 | - ) |
|
| 1672 | - ), |
|
| 1673 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1674 | - array( |
|
| 1675 | - 'default' => '', |
|
| 1676 | - 'required' => false, |
|
| 1677 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1678 | - 'validation_strategies' => array( |
|
| 1679 | - new EE_Max_Length_Validation_Strategy( |
|
| 1680 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1681 | - 100 |
|
| 1682 | - ), |
|
| 1683 | - ), |
|
| 1684 | - ) |
|
| 1685 | - ), |
|
| 1686 | - 'po_number' => new EE_Text_Input( |
|
| 1687 | - array( |
|
| 1688 | - 'default' => '', |
|
| 1689 | - 'required' => false, |
|
| 1690 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1691 | - 'validation_strategies' => array( |
|
| 1692 | - new EE_Max_Length_Validation_Strategy( |
|
| 1693 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1694 | - 100 |
|
| 1695 | - ), |
|
| 1696 | - ), |
|
| 1697 | - ) |
|
| 1698 | - ), |
|
| 1699 | - 'accounting' => new EE_Text_Input( |
|
| 1700 | - array( |
|
| 1701 | - 'default' => '', |
|
| 1702 | - 'required' => false, |
|
| 1703 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1704 | - 'validation_strategies' => array( |
|
| 1705 | - new EE_Max_Length_Validation_Strategy( |
|
| 1706 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1707 | - 100 |
|
| 1708 | - ), |
|
| 1709 | - ), |
|
| 1710 | - ) |
|
| 1711 | - ), |
|
| 1712 | - ), |
|
| 1713 | - ) |
|
| 1714 | - ); |
|
| 1715 | - } |
|
| 1716 | - |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * _create_payment_from_request_data |
|
| 1720 | - * |
|
| 1721 | - * @param array $valid_data |
|
| 1722 | - * @return EE_Payment |
|
| 1723 | - * @throws EE_Error |
|
| 1724 | - */ |
|
| 1725 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1726 | - { |
|
| 1727 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1728 | - // get payment amount |
|
| 1729 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1730 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1731 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1732 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1733 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1734 | - $date = $valid_data['date'] |
|
| 1735 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1736 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1737 | - $payment = EE_Payment::new_instance( |
|
| 1738 | - array( |
|
| 1739 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1740 | - 'STS_ID' => $valid_data['status'], |
|
| 1741 | - 'PAY_timestamp' => $date, |
|
| 1742 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1743 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1744 | - 'PAY_amount' => $amount, |
|
| 1745 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1746 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1747 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1748 | - 'PAY_details' => $valid_data, |
|
| 1749 | - 'PAY_ID' => $PAY_ID, |
|
| 1750 | - ), |
|
| 1751 | - '', |
|
| 1752 | - array('Y-m-d', 'g:i a') |
|
| 1753 | - ); |
|
| 1754 | - |
|
| 1755 | - if (! $payment->save()) { |
|
| 1756 | - EE_Error::add_error( |
|
| 1757 | - sprintf( |
|
| 1758 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1759 | - $payment->ID() |
|
| 1760 | - ), |
|
| 1761 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1762 | - ); |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - return $payment; |
|
| 1766 | - } |
|
| 1767 | - |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * _process_transaction_payments |
|
| 1771 | - * |
|
| 1772 | - * @param \EE_Transaction $transaction |
|
| 1773 | - * @return void |
|
| 1774 | - * @throws EE_Error |
|
| 1775 | - * @throws InvalidArgumentException |
|
| 1776 | - * @throws ReflectionException |
|
| 1777 | - * @throws InvalidDataTypeException |
|
| 1778 | - * @throws InvalidInterfaceException |
|
| 1779 | - */ |
|
| 1780 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1781 | - { |
|
| 1782 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1783 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1784 | - //update the transaction with this payment |
|
| 1785 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1786 | - EE_Error::add_success(esc_html__( |
|
| 1787 | - 'The payment has been processed successfully.', 'event_espresso'), |
|
| 1788 | - __FILE__, |
|
| 1789 | - __FUNCTION__, |
|
| 1790 | - __LINE__ |
|
| 1791 | - ); |
|
| 1792 | - } else { |
|
| 1793 | - EE_Error::add_error( |
|
| 1794 | - esc_html__( |
|
| 1795 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1796 | - 'event_espresso' |
|
| 1797 | - ) |
|
| 1798 | - , |
|
| 1799 | - __FILE__, |
|
| 1800 | - __FUNCTION__, |
|
| 1801 | - __LINE__ |
|
| 1802 | - ); |
|
| 1803 | - } |
|
| 1804 | - } |
|
| 1805 | - |
|
| 1806 | - |
|
| 1807 | - /** |
|
| 1808 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1809 | - * returns a list of registration IDs that the payment will apply to |
|
| 1810 | - * |
|
| 1811 | - * @param \EE_Payment $payment |
|
| 1812 | - * @return array |
|
| 1813 | - * @throws EE_Error |
|
| 1814 | - */ |
|
| 1815 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1816 | - { |
|
| 1817 | - $REG_IDs = array(); |
|
| 1818 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1819 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1820 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1821 | - } |
|
| 1822 | - //nothing specified ? then get all reg IDs |
|
| 1823 | - if (empty($REG_IDs)) { |
|
| 1824 | - $registrations = $payment->transaction()->registrations(); |
|
| 1825 | - $REG_IDs = ! empty($registrations) |
|
| 1826 | - ? array_keys($registrations) |
|
| 1827 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1831 | - return array_map('intval', $REG_IDs); |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - |
|
| 1835 | - /** |
|
| 1836 | - * @return array |
|
| 1837 | - */ |
|
| 1838 | - public function existing_reg_payment_REG_IDs() |
|
| 1839 | - { |
|
| 1840 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - |
|
| 1844 | - /** |
|
| 1845 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1846 | - */ |
|
| 1847 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1848 | - { |
|
| 1849 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - |
|
| 1853 | - /** |
|
| 1854 | - * _get_existing_reg_payment_REG_IDs |
|
| 1855 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1856 | - * as recorded in the database |
|
| 1857 | - * |
|
| 1858 | - * @param \EE_Payment $payment |
|
| 1859 | - * @return array |
|
| 1860 | - * @throws EE_Error |
|
| 1861 | - */ |
|
| 1862 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1863 | - { |
|
| 1864 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1865 | - // let's get any existing reg payment records for this payment |
|
| 1866 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1867 | - // but we only want the REG IDs, so grab the array keys |
|
| 1868 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 1869 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
| 1870 | - : array(); |
|
| 1871 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - |
|
| 1878 | - /** |
|
| 1879 | - * _remove_existing_registration_payments |
|
| 1880 | - * this calculates the difference between existing relations |
|
| 1881 | - * to the supplied payment and the new list registration IDs, |
|
| 1882 | - * removes any related registrations that no longer apply, |
|
| 1883 | - * and then updates the registration paid fields |
|
| 1884 | - * |
|
| 1885 | - * @param \EE_Payment $payment |
|
| 1886 | - * @param int $PAY_ID |
|
| 1887 | - * @return bool; |
|
| 1888 | - * @throws EE_Error |
|
| 1889 | - * @throws InvalidArgumentException |
|
| 1890 | - * @throws ReflectionException |
|
| 1891 | - * @throws InvalidDataTypeException |
|
| 1892 | - * @throws InvalidInterfaceException |
|
| 1893 | - */ |
|
| 1894 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1895 | - { |
|
| 1896 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 1897 | - if ($PAY_ID == 0) { |
|
| 1898 | - return false; |
|
| 1899 | - } |
|
| 1900 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1901 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1902 | - return false; |
|
| 1903 | - } |
|
| 1904 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1905 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1906 | - |
|
| 1907 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1908 | - $payment, |
|
| 1909 | - array( |
|
| 1910 | - array( |
|
| 1911 | - 'PAY_ID' => $payment->ID(), |
|
| 1912 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1913 | - ), |
|
| 1914 | - ) |
|
| 1915 | - ); |
|
| 1916 | - } |
|
| 1917 | - |
|
| 1918 | - |
|
| 1919 | - /** |
|
| 1920 | - * _update_registration_payments |
|
| 1921 | - * this applies the payments to the selected registrations |
|
| 1922 | - * but only if they have not already been paid for |
|
| 1923 | - * |
|
| 1924 | - * @param EE_Transaction $transaction |
|
| 1925 | - * @param \EE_Payment $payment |
|
| 1926 | - * @param array $REG_IDs |
|
| 1927 | - * @return void |
|
| 1928 | - * @throws EE_Error |
|
| 1929 | - * @throws InvalidArgumentException |
|
| 1930 | - * @throws ReflectionException |
|
| 1931 | - * @throws RuntimeException |
|
| 1932 | - * @throws InvalidDataTypeException |
|
| 1933 | - * @throws InvalidInterfaceException |
|
| 1934 | - */ |
|
| 1935 | - protected function _update_registration_payments( |
|
| 1936 | - EE_Transaction $transaction, |
|
| 1937 | - EE_Payment $payment, |
|
| 1938 | - $REG_IDs = array() |
|
| 1939 | - ) { |
|
| 1940 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1941 | - // so let's do that using our set of REG_IDs from the form |
|
| 1942 | - $registration_query_where_params = array( |
|
| 1943 | - 'REG_ID' => array('IN', $REG_IDs), |
|
| 1944 | - ); |
|
| 1945 | - // but add in some conditions regarding payment, |
|
| 1946 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1947 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1948 | - if (! $payment->is_a_refund()) { |
|
| 1949 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1950 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1951 | - } |
|
| 1952 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1953 | - if (! empty($registrations)) { |
|
| 1954 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 1955 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1956 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1957 | - } |
|
| 1958 | - } |
|
| 1959 | - |
|
| 1960 | - |
|
| 1961 | - /** |
|
| 1962 | - * _process_registration_status_change |
|
| 1963 | - * This processes requested registration status changes for all the registrations |
|
| 1964 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1965 | - * |
|
| 1966 | - * @param EE_Transaction $transaction |
|
| 1967 | - * @param array $REG_IDs |
|
| 1968 | - * @return bool |
|
| 1969 | - * @throws EE_Error |
|
| 1970 | - * @throws InvalidArgumentException |
|
| 1971 | - * @throws ReflectionException |
|
| 1972 | - * @throws InvalidDataTypeException |
|
| 1973 | - * @throws InvalidInterfaceException |
|
| 1974 | - */ |
|
| 1975 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1976 | - { |
|
| 1977 | - // first if there is no change in status then we get out. |
|
| 1978 | - if ( |
|
| 1979 | - ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1980 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 1981 | - ) { |
|
| 1982 | - //no error message, no change requested, just nothing to do man. |
|
| 1983 | - return false; |
|
| 1984 | - } |
|
| 1985 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1986 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1987 | - |
|
| 1988 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1989 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 1990 | - $transaction, |
|
| 1991 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1992 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1993 | - ); |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - |
|
| 1997 | - /** |
|
| 1998 | - * _build_payment_json_response |
|
| 1999 | - * |
|
| 2000 | - * @access public |
|
| 2001 | - * @param \EE_Payment $payment |
|
| 2002 | - * @param array $REG_IDs |
|
| 2003 | - * @param bool | null $delete_txn_reg_status_change |
|
| 2004 | - * @return array |
|
| 2005 | - * @throws EE_Error |
|
| 2006 | - * @throws InvalidArgumentException |
|
| 2007 | - * @throws InvalidDataTypeException |
|
| 2008 | - * @throws InvalidInterfaceException |
|
| 2009 | - */ |
|
| 2010 | - protected function _build_payment_json_response( |
|
| 2011 | - EE_Payment $payment, |
|
| 2012 | - $REG_IDs = array(), |
|
| 2013 | - $delete_txn_reg_status_change = null |
|
| 2014 | - ) { |
|
| 2015 | - // was the payment deleted ? |
|
| 2016 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 2017 | - return array( |
|
| 2018 | - 'PAY_ID' => $payment->ID(), |
|
| 2019 | - 'amount' => $payment->amount(), |
|
| 2020 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2021 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2022 | - 'pay_status' => $payment->STS_ID(), |
|
| 2023 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2024 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2025 | - ); |
|
| 2026 | - } else { |
|
| 2027 | - $this->_get_payment_status_array(); |
|
| 2028 | - |
|
| 2029 | - return array( |
|
| 2030 | - 'amount' => $payment->amount(), |
|
| 2031 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2032 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2033 | - 'pay_status' => $payment->STS_ID(), |
|
| 2034 | - 'PAY_ID' => $payment->ID(), |
|
| 2035 | - 'STS_ID' => $payment->STS_ID(), |
|
| 2036 | - 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 2037 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2038 | - 'method' => strtoupper($payment->source()), |
|
| 2039 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2040 | - 'gateway' => $payment->payment_method() |
|
| 2041 | - ? $payment->payment_method()->admin_name() |
|
| 2042 | - : esc_html__("Unknown", 'event_espresso'), |
|
| 2043 | - 'gateway_response' => $payment->gateway_response(), |
|
| 2044 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2045 | - 'po_number' => $payment->po_number(), |
|
| 2046 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 2047 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2048 | - ); |
|
| 2049 | - } |
|
| 2050 | - } |
|
| 2051 | - |
|
| 2052 | - |
|
| 2053 | - /** |
|
| 2054 | - * delete_payment |
|
| 2055 | - * delete a payment or refund made towards a transaction |
|
| 2056 | - * |
|
| 2057 | - * @access public |
|
| 2058 | - * @return void |
|
| 2059 | - * @throws EE_Error |
|
| 2060 | - * @throws InvalidArgumentException |
|
| 2061 | - * @throws ReflectionException |
|
| 2062 | - * @throws InvalidDataTypeException |
|
| 2063 | - * @throws InvalidInterfaceException |
|
| 2064 | - */ |
|
| 2065 | - public function delete_payment() |
|
| 2066 | - { |
|
| 2067 | - $json_response_data = array('return_data' => false); |
|
| 2068 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2069 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2070 | - : 0; |
|
| 2071 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2072 | - 'ee_delete_payments', |
|
| 2073 | - 'delete_payment_from_registration_details' |
|
| 2074 | - ); |
|
| 2075 | - if ($PAY_ID && $can_delete) { |
|
| 2076 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2077 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2078 | - : false; |
|
| 2079 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2080 | - if ($payment instanceof EE_Payment) { |
|
| 2081 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2082 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2083 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2084 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2085 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2086 | - $payment, |
|
| 2087 | - $REG_IDs, |
|
| 2088 | - $delete_txn_reg_status_change |
|
| 2089 | - ); |
|
| 2090 | - if ($delete_txn_reg_status_change) { |
|
| 2091 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2092 | - //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2093 | - //$_REQUEST global because that's how messages will be looking for it. |
|
| 2094 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2095 | - $this->_maybe_send_notifications(); |
|
| 2096 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2097 | - } |
|
| 2098 | - } |
|
| 2099 | - } else { |
|
| 2100 | - EE_Error::add_error( |
|
| 2101 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2102 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2103 | - ); |
|
| 2104 | - } |
|
| 2105 | - } else { |
|
| 2106 | - if ($can_delete) { |
|
| 2107 | - EE_Error::add_error( |
|
| 2108 | - esc_html__( |
|
| 2109 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2110 | - 'event_espresso' |
|
| 2111 | - ), |
|
| 2112 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | - ); |
|
| 2114 | - } else { |
|
| 2115 | - EE_Error::add_error( |
|
| 2116 | - esc_html__( |
|
| 2117 | - 'You do not have access to delete a payment.', |
|
| 2118 | - 'event_espresso' |
|
| 2119 | - ), |
|
| 2120 | - __FILE__, |
|
| 2121 | - __FUNCTION__, |
|
| 2122 | - __LINE__ |
|
| 2123 | - ); |
|
| 2124 | - } |
|
| 2125 | - } |
|
| 2126 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 2127 | - $this->_template_args = array( |
|
| 2128 | - 'data' => $json_response_data, |
|
| 2129 | - 'success' => $notices['success'], |
|
| 2130 | - 'error' => $notices['errors'], |
|
| 2131 | - 'attention' => $notices['attention'], |
|
| 2132 | - ); |
|
| 2133 | - $this->_return_json(); |
|
| 2134 | - } |
|
| 2135 | - |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * _registration_payment_data_array |
|
| 2139 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2140 | - * |
|
| 2141 | - * @access protected |
|
| 2142 | - * @param array $REG_IDs |
|
| 2143 | - * @return array |
|
| 2144 | - * @throws EE_Error |
|
| 2145 | - * @throws InvalidArgumentException |
|
| 2146 | - * @throws InvalidDataTypeException |
|
| 2147 | - * @throws InvalidInterfaceException |
|
| 2148 | - */ |
|
| 2149 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 2150 | - { |
|
| 2151 | - $registration_payment_data = array(); |
|
| 2152 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2153 | - if (! empty($REG_IDs)) { |
|
| 2154 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2155 | - foreach ($registrations as $registration) { |
|
| 2156 | - if ($registration instanceof EE_Registration) { |
|
| 2157 | - $registration_payment_data[$registration->ID()] = array( |
|
| 2158 | - 'paid' => $registration->pretty_paid(), |
|
| 2159 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2160 | - ); |
|
| 2161 | - } |
|
| 2162 | - } |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - return $registration_payment_data; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * _maybe_send_notifications |
|
| 2171 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2172 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 2173 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2174 | - * |
|
| 2175 | - * @access protected |
|
| 2176 | - * @param \EE_Payment | null $payment |
|
| 2177 | - */ |
|
| 2178 | - protected function _maybe_send_notifications($payment = null) |
|
| 2179 | - { |
|
| 2180 | - switch ($payment instanceof EE_Payment) { |
|
| 2181 | - // payment notifications |
|
| 2182 | - case true : |
|
| 2183 | - if ( |
|
| 2184 | - isset( |
|
| 2185 | - $this->_req_data['txn_payments'], |
|
| 2186 | - $this->_req_data['txn_payments']['send_notifications'] |
|
| 2187 | - ) && |
|
| 2188 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2189 | - ) { |
|
| 2190 | - $this->_process_payment_notification($payment); |
|
| 2191 | - } |
|
| 2192 | - break; |
|
| 2193 | - // registration notifications |
|
| 2194 | - case false : |
|
| 2195 | - if ( |
|
| 2196 | - isset( |
|
| 2197 | - $this->_req_data['txn_reg_status_change'], |
|
| 2198 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 2199 | - ) && |
|
| 2200 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2201 | - ) { |
|
| 2202 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2203 | - } |
|
| 2204 | - break; |
|
| 2205 | - } |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - |
|
| 2209 | - /** |
|
| 2210 | - * _send_payment_reminder |
|
| 2211 | - * generates HTML for the View Transaction Details Admin page |
|
| 2212 | - * |
|
| 2213 | - * @access protected |
|
| 2214 | - * @return void |
|
| 2215 | - * @throws EE_Error |
|
| 2216 | - * @throws InvalidArgumentException |
|
| 2217 | - * @throws InvalidDataTypeException |
|
| 2218 | - * @throws InvalidInterfaceException |
|
| 2219 | - */ |
|
| 2220 | - protected function _send_payment_reminder() |
|
| 2221 | - { |
|
| 2222 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2223 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2224 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2225 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2226 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2227 | - ) : array(); |
|
| 2228 | - do_action( |
|
| 2229 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2230 | - $transaction |
|
| 2231 | - ); |
|
| 2232 | - $this->_redirect_after_action( |
|
| 2233 | - false, |
|
| 2234 | - esc_html__('payment reminder', 'event_espresso'), |
|
| 2235 | - esc_html__('sent', 'event_espresso'), |
|
| 2236 | - $query_args, |
|
| 2237 | - true |
|
| 2238 | - ); |
|
| 2239 | - } |
|
| 2240 | - |
|
| 2241 | - |
|
| 2242 | - /** |
|
| 2243 | - * get_transactions |
|
| 2244 | - * get transactions for given parameters (used by list table) |
|
| 2245 | - * |
|
| 2246 | - * @param int $perpage how many transactions displayed per page |
|
| 2247 | - * @param boolean $count return the count or objects |
|
| 2248 | - * @param string $view |
|
| 2249 | - * @return mixed int = count || array of transaction objects |
|
| 2250 | - * @throws EE_Error |
|
| 2251 | - * @throws InvalidArgumentException |
|
| 2252 | - * @throws InvalidDataTypeException |
|
| 2253 | - * @throws InvalidInterfaceException |
|
| 2254 | - */ |
|
| 2255 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 2256 | - { |
|
| 2257 | - |
|
| 2258 | - $TXN = EEM_Transaction::instance(); |
|
| 2259 | - |
|
| 2260 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2261 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2262 | - : date( |
|
| 2263 | - 'm/d/Y', |
|
| 2264 | - strtotime('-10 year') |
|
| 2265 | - ); |
|
| 2266 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2267 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2268 | - : date('m/d/Y'); |
|
| 2269 | - |
|
| 2270 | - //make sure our timestamps start and end right at the boundaries for each day |
|
| 2271 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2272 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2273 | - |
|
| 2274 | - |
|
| 2275 | - //convert to timestamps |
|
| 2276 | - $start_date = strtotime($start_date); |
|
| 2277 | - $end_date = strtotime($end_date); |
|
| 2278 | - |
|
| 2279 | - //makes sure start date is the lowest value and vice versa |
|
| 2280 | - $start_date = min($start_date, $end_date); |
|
| 2281 | - $end_date = max($start_date, $end_date); |
|
| 2282 | - |
|
| 2283 | - //convert to correct format for query |
|
| 2284 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2285 | - 'TXN_timestamp', |
|
| 2286 | - date('Y-m-d H:i:s', $start_date), |
|
| 2287 | - 'Y-m-d H:i:s' |
|
| 2288 | - ); |
|
| 2289 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2290 | - 'TXN_timestamp', |
|
| 2291 | - date('Y-m-d H:i:s', $end_date), |
|
| 2292 | - 'Y-m-d H:i:s' |
|
| 2293 | - ); |
|
| 2294 | - |
|
| 2295 | - |
|
| 2296 | - //set orderby |
|
| 2297 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2298 | - |
|
| 2299 | - switch ($this->_req_data['orderby']) { |
|
| 2300 | - case 'TXN_ID': |
|
| 2301 | - $orderby = 'TXN_ID'; |
|
| 2302 | - break; |
|
| 2303 | - case 'ATT_fname': |
|
| 2304 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2305 | - break; |
|
| 2306 | - case 'event_name': |
|
| 2307 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 2308 | - break; |
|
| 2309 | - default: //'TXN_timestamp' |
|
| 2310 | - $orderby = 'TXN_timestamp'; |
|
| 2311 | - } |
|
| 2312 | - |
|
| 2313 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2314 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2315 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2316 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2317 | - |
|
| 2318 | - $offset = ($current_page - 1) * $per_page; |
|
| 2319 | - $limit = array($offset, $per_page); |
|
| 2320 | - |
|
| 2321 | - $_where = array( |
|
| 2322 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2323 | - 'Registration.REG_count' => 1, |
|
| 2324 | - ); |
|
| 2325 | - |
|
| 2326 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 2327 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2328 | - } |
|
| 2329 | - |
|
| 2330 | - if (isset($this->_req_data['s'])) { |
|
| 2331 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2332 | - $_where['OR'] = array( |
|
| 2333 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2334 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2335 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2336 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2337 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2338 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2339 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2340 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2341 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2342 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2343 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2344 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2345 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2346 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2347 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2348 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2349 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2350 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2351 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2352 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2353 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2354 | - ); |
|
| 2355 | - } |
|
| 2356 | - |
|
| 2357 | - //failed transactions |
|
| 2358 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2359 | - || ($count && $view === 'failed'); |
|
| 2360 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2361 | - || ($count && $view === 'abandoned'); |
|
| 2362 | - |
|
| 2363 | - if ($failed) { |
|
| 2364 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2365 | - } else if ($abandoned) { |
|
| 2366 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2367 | - } else { |
|
| 2368 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2369 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - $query_params = array( |
|
| 2373 | - $_where, |
|
| 2374 | - 'order_by' => array($orderby => $sort), |
|
| 2375 | - 'limit' => $limit, |
|
| 2376 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2377 | - ); |
|
| 2378 | - |
|
| 2379 | - $transactions = $count |
|
| 2380 | - ? $TXN->count(array($_where), 'TXN_ID', true) |
|
| 2381 | - : $TXN->get_all($query_params); |
|
| 2382 | - |
|
| 2383 | - return $transactions; |
|
| 2384 | - } |
|
| 19 | + /** |
|
| 20 | + * @var EE_Transaction |
|
| 21 | + */ |
|
| 22 | + private $_transaction; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var EE_Session |
|
| 26 | + */ |
|
| 27 | + private $_session; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var array $_txn_status |
|
| 31 | + */ |
|
| 32 | + private static $_txn_status; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var array $_pay_status |
|
| 36 | + */ |
|
| 37 | + private static $_pay_status; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 41 | + */ |
|
| 42 | + protected $_existing_reg_payment_REG_IDs = null; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @Constructor |
|
| 47 | + * @access public |
|
| 48 | + * @param bool $routing |
|
| 49 | + * @throws EE_Error |
|
| 50 | + * @throws InvalidArgumentException |
|
| 51 | + * @throws ReflectionException |
|
| 52 | + * @throws InvalidDataTypeException |
|
| 53 | + * @throws InvalidInterfaceException |
|
| 54 | + */ |
|
| 55 | + public function __construct($routing = true) |
|
| 56 | + { |
|
| 57 | + parent::__construct($routing); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * _init_page_props |
|
| 63 | + * |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + protected function _init_page_props() |
|
| 67 | + { |
|
| 68 | + $this->page_slug = TXN_PG_SLUG; |
|
| 69 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 70 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 71 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * _ajax_hooks |
|
| 77 | + * |
|
| 78 | + * @return void |
|
| 79 | + */ |
|
| 80 | + protected function _ajax_hooks() |
|
| 81 | + { |
|
| 82 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 83 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 84 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * _define_page_props |
|
| 90 | + * |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + protected function _define_page_props() |
|
| 94 | + { |
|
| 95 | + $this->_admin_page_title = $this->page_label; |
|
| 96 | + $this->_labels = array( |
|
| 97 | + 'buttons' => array( |
|
| 98 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 99 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 100 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 101 | + ), |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * grab url requests and route them |
|
| 108 | + * |
|
| 109 | + * @access private |
|
| 110 | + * @return void |
|
| 111 | + * @throws EE_Error |
|
| 112 | + * @throws InvalidArgumentException |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + */ |
|
| 116 | + public function _set_page_routes() |
|
| 117 | + { |
|
| 118 | + |
|
| 119 | + $this->_set_transaction_status_array(); |
|
| 120 | + |
|
| 121 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 122 | + && ! is_array($this->_req_data['TXN_ID']) |
|
| 123 | + ? $this->_req_data['TXN_ID'] |
|
| 124 | + : 0; |
|
| 125 | + |
|
| 126 | + $this->_page_routes = array( |
|
| 127 | + |
|
| 128 | + 'default' => array( |
|
| 129 | + 'func' => '_transactions_overview_list_table', |
|
| 130 | + 'capability' => 'ee_read_transactions', |
|
| 131 | + ), |
|
| 132 | + |
|
| 133 | + 'view_transaction' => array( |
|
| 134 | + 'func' => '_transaction_details', |
|
| 135 | + 'capability' => 'ee_read_transaction', |
|
| 136 | + 'obj_id' => $txn_id, |
|
| 137 | + ), |
|
| 138 | + |
|
| 139 | + 'send_payment_reminder' => array( |
|
| 140 | + 'func' => '_send_payment_reminder', |
|
| 141 | + 'noheader' => true, |
|
| 142 | + 'capability' => 'ee_send_message', |
|
| 143 | + ), |
|
| 144 | + |
|
| 145 | + 'espresso_apply_payment' => array( |
|
| 146 | + 'func' => 'apply_payments_or_refunds', |
|
| 147 | + 'noheader' => true, |
|
| 148 | + 'capability' => 'ee_edit_payments', |
|
| 149 | + ), |
|
| 150 | + |
|
| 151 | + 'espresso_apply_refund' => array( |
|
| 152 | + 'func' => 'apply_payments_or_refunds', |
|
| 153 | + 'noheader' => true, |
|
| 154 | + 'capability' => 'ee_edit_payments', |
|
| 155 | + ), |
|
| 156 | + |
|
| 157 | + 'espresso_delete_payment' => array( |
|
| 158 | + 'func' => 'delete_payment', |
|
| 159 | + 'noheader' => true, |
|
| 160 | + 'capability' => 'ee_delete_payments', |
|
| 161 | + ), |
|
| 162 | + |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + protected function _set_page_config() |
|
| 168 | + { |
|
| 169 | + $this->_page_config = array( |
|
| 170 | + 'default' => array( |
|
| 171 | + 'nav' => array( |
|
| 172 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 173 | + 'order' => 10, |
|
| 174 | + ), |
|
| 175 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 176 | + 'help_tabs' => array( |
|
| 177 | + 'transactions_overview_help_tab' => array( |
|
| 178 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 179 | + 'filename' => 'transactions_overview', |
|
| 180 | + ), |
|
| 181 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 182 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 183 | + 'filename' => 'transactions_overview_table_column_headings', |
|
| 184 | + ), |
|
| 185 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 186 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 187 | + 'filename' => 'transactions_overview_views_filters_search', |
|
| 188 | + ), |
|
| 189 | + ), |
|
| 190 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 191 | + /** |
|
| 192 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 193 | + * may change in a later iteration so want to keep the code for then. |
|
| 194 | + */ |
|
| 195 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 196 | + 'require_nonce' => false, |
|
| 197 | + ), |
|
| 198 | + 'view_transaction' => array( |
|
| 199 | + 'nav' => array( |
|
| 200 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 201 | + 'order' => 5, |
|
| 202 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
| 203 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 204 | + : $this->_admin_base_url, |
|
| 205 | + 'persistent' => false, |
|
| 206 | + ), |
|
| 207 | + 'help_tabs' => array( |
|
| 208 | + 'transactions_view_transaction_help_tab' => array( |
|
| 209 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 210 | + 'filename' => 'transactions_view_transaction', |
|
| 211 | + ), |
|
| 212 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 213 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 214 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 215 | + ), |
|
| 216 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 217 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 218 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 219 | + ), |
|
| 220 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 221 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 222 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 223 | + ), |
|
| 224 | + ), |
|
| 225 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 226 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 227 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 228 | + |
|
| 229 | + 'require_nonce' => false, |
|
| 230 | + ), |
|
| 231 | + ); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * The below methods aren't used by this class currently |
|
| 237 | + */ |
|
| 238 | + protected function _add_screen_options() |
|
| 239 | + { |
|
| 240 | + //noop |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + protected function _add_feature_pointers() |
|
| 244 | + { |
|
| 245 | + //noop |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + public function admin_init() |
|
| 249 | + { |
|
| 250 | + // IF a registration was JUST added via the admin... |
|
| 251 | + if (isset( |
|
| 252 | + $this->_req_data['redirect_from'], |
|
| 253 | + $this->_req_data['EVT_ID'], |
|
| 254 | + $this->_req_data['event_name'] |
|
| 255 | + )) { |
|
| 256 | + // then set a cookie so that we can block any attempts to use |
|
| 257 | + // the back button as a way to enter another registration. |
|
| 258 | + setcookie( |
|
| 259 | + 'ee_registration_added', |
|
| 260 | + $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/' |
|
| 261 | + ); |
|
| 262 | + // and update the global |
|
| 263 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 264 | + } |
|
| 265 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 266 | + '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.', |
|
| 267 | + 'event_espresso' |
|
| 268 | + ); |
|
| 269 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 270 | + 'An error occurred! Please refresh the page and try again.', |
|
| 271 | + 'event_espresso' |
|
| 272 | + ); |
|
| 273 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 274 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 275 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 276 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 277 | + 'This transaction has been overpaid ! Payments Total', |
|
| 278 | + 'event_espresso' |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + public function admin_notices() |
|
| 283 | + { |
|
| 284 | + //noop |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + public function admin_footer_scripts() |
|
| 288 | + { |
|
| 289 | + //noop |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * _set_transaction_status_array |
|
| 295 | + * sets list of transaction statuses |
|
| 296 | + * |
|
| 297 | + * @access private |
|
| 298 | + * @return void |
|
| 299 | + * @throws EE_Error |
|
| 300 | + * @throws InvalidArgumentException |
|
| 301 | + * @throws InvalidDataTypeException |
|
| 302 | + * @throws InvalidInterfaceException |
|
| 303 | + */ |
|
| 304 | + private function _set_transaction_status_array() |
|
| 305 | + { |
|
| 306 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * get_transaction_status_array |
|
| 312 | + * return the transaction status array for wp_list_table |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @return array |
|
| 316 | + */ |
|
| 317 | + public function get_transaction_status_array() |
|
| 318 | + { |
|
| 319 | + return self::$_txn_status; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * get list of payment statuses |
|
| 325 | + * |
|
| 326 | + * @access private |
|
| 327 | + * @return void |
|
| 328 | + * @throws EE_Error |
|
| 329 | + * @throws InvalidArgumentException |
|
| 330 | + * @throws InvalidDataTypeException |
|
| 331 | + * @throws InvalidInterfaceException |
|
| 332 | + */ |
|
| 333 | + private function _get_payment_status_array() |
|
| 334 | + { |
|
| 335 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 336 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 337 | + |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * _add_screen_options_default |
|
| 343 | + * |
|
| 344 | + * @access protected |
|
| 345 | + * @return void |
|
| 346 | + * @throws InvalidArgumentException |
|
| 347 | + * @throws InvalidDataTypeException |
|
| 348 | + * @throws InvalidInterfaceException |
|
| 349 | + */ |
|
| 350 | + protected function _add_screen_options_default() |
|
| 351 | + { |
|
| 352 | + $this->_per_page_screen_option(); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * load_scripts_styles |
|
| 358 | + * |
|
| 359 | + * @access public |
|
| 360 | + * @return void |
|
| 361 | + */ |
|
| 362 | + public function load_scripts_styles() |
|
| 363 | + { |
|
| 364 | + //enqueue style |
|
| 365 | + wp_register_style( |
|
| 366 | + 'espresso_txn', |
|
| 367 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 368 | + array(), |
|
| 369 | + EVENT_ESPRESSO_VERSION |
|
| 370 | + ); |
|
| 371 | + wp_enqueue_style('espresso_txn'); |
|
| 372 | + //scripts |
|
| 373 | + wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 374 | + 'ee_admin_js', |
|
| 375 | + 'ee-datepicker', |
|
| 376 | + 'jquery-ui-datepicker', |
|
| 377 | + 'jquery-ui-draggable', |
|
| 378 | + 'ee-dialog', |
|
| 379 | + 'ee-accounting', |
|
| 380 | + 'ee-serialize-full-array', |
|
| 381 | + ), EVENT_ESPRESSO_VERSION, true); |
|
| 382 | + wp_enqueue_script('espresso_txn'); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * load_scripts_styles_view_transaction |
|
| 388 | + * |
|
| 389 | + * @access public |
|
| 390 | + * @return void |
|
| 391 | + */ |
|
| 392 | + public function load_scripts_styles_view_transaction() |
|
| 393 | + { |
|
| 394 | + //styles |
|
| 395 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * load_scripts_styles_default |
|
| 401 | + * |
|
| 402 | + * @access public |
|
| 403 | + * @return void |
|
| 404 | + */ |
|
| 405 | + public function load_scripts_styles_default() |
|
| 406 | + { |
|
| 407 | + //styles |
|
| 408 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * _set_list_table_views_default |
|
| 414 | + * |
|
| 415 | + * @access protected |
|
| 416 | + * @return void |
|
| 417 | + */ |
|
| 418 | + protected function _set_list_table_views_default() |
|
| 419 | + { |
|
| 420 | + $this->_views = array( |
|
| 421 | + 'all' => array( |
|
| 422 | + 'slug' => 'all', |
|
| 423 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 424 | + 'count' => 0, |
|
| 425 | + ), |
|
| 426 | + 'abandoned' => array( |
|
| 427 | + 'slug' => 'abandoned', |
|
| 428 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 429 | + 'count' => 0, |
|
| 430 | + ), |
|
| 431 | + 'failed' => array( |
|
| 432 | + 'slug' => 'failed', |
|
| 433 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 434 | + 'count' => 0, |
|
| 435 | + ), |
|
| 436 | + ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * _set_transaction_object |
|
| 442 | + * This sets the _transaction property for the transaction details screen |
|
| 443 | + * |
|
| 444 | + * @access private |
|
| 445 | + * @return void |
|
| 446 | + * @throws EE_Error |
|
| 447 | + * @throws InvalidArgumentException |
|
| 448 | + * @throws RuntimeException |
|
| 449 | + * @throws InvalidDataTypeException |
|
| 450 | + * @throws InvalidInterfaceException |
|
| 451 | + */ |
|
| 452 | + private function _set_transaction_object() |
|
| 453 | + { |
|
| 454 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 455 | + return; |
|
| 456 | + } //get out we've already set the object |
|
| 457 | + |
|
| 458 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 459 | + ? absint($this->_req_data['TXN_ID']) |
|
| 460 | + : false; |
|
| 461 | + |
|
| 462 | + //get transaction object |
|
| 463 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 464 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 465 | + ? $this->_transaction->get('TXN_session_data') |
|
| 466 | + : null; |
|
| 467 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 468 | + |
|
| 469 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 470 | + $error_msg = sprintf( |
|
| 471 | + esc_html__( |
|
| 472 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 473 | + 'event_espresso' |
|
| 474 | + ), |
|
| 475 | + $TXN_ID |
|
| 476 | + ); |
|
| 477 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * _transaction_legend_items |
|
| 484 | + * |
|
| 485 | + * @access protected |
|
| 486 | + * @return array |
|
| 487 | + * @throws EE_Error |
|
| 488 | + * @throws InvalidArgumentException |
|
| 489 | + * @throws ReflectionException |
|
| 490 | + * @throws InvalidDataTypeException |
|
| 491 | + * @throws InvalidInterfaceException |
|
| 492 | + */ |
|
| 493 | + protected function _transaction_legend_items() |
|
| 494 | + { |
|
| 495 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 496 | + $items = array(); |
|
| 497 | + |
|
| 498 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 499 | + 'ee_read_global_messages', |
|
| 500 | + 'view_filtered_messages' |
|
| 501 | + )) { |
|
| 502 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 503 | + if (is_array($related_for_icon) |
|
| 504 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 505 | + ) { |
|
| 506 | + $items['view_related_messages'] = array( |
|
| 507 | + 'class' => $related_for_icon['css_class'], |
|
| 508 | + 'desc' => $related_for_icon['label'], |
|
| 509 | + ); |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + $items = apply_filters( |
|
| 514 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 515 | + array_merge( |
|
| 516 | + $items, |
|
| 517 | + array( |
|
| 518 | + 'view_details' => array( |
|
| 519 | + 'class' => 'dashicons dashicons-cart', |
|
| 520 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 521 | + ), |
|
| 522 | + 'view_invoice' => array( |
|
| 523 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 524 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 525 | + ), |
|
| 526 | + 'view_receipt' => array( |
|
| 527 | + 'class' => 'dashicons dashicons-media-default', |
|
| 528 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 529 | + ), |
|
| 530 | + 'view_registration' => array( |
|
| 531 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 532 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 533 | + ), |
|
| 534 | + 'payment_overview_link' => array( |
|
| 535 | + 'class' => 'dashicons dashicons-money', |
|
| 536 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 537 | + ), |
|
| 538 | + ) |
|
| 539 | + ) |
|
| 540 | + ); |
|
| 541 | + |
|
| 542 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 543 | + 'ee_send_message', |
|
| 544 | + 'espresso_transactions_send_payment_reminder' |
|
| 545 | + )) { |
|
| 546 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 547 | + $items['send_payment_reminder'] = array( |
|
| 548 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 549 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 550 | + ); |
|
| 551 | + } else { |
|
| 552 | + $items['blank*'] = array( |
|
| 553 | + 'class' => '', |
|
| 554 | + 'desc' => '', |
|
| 555 | + ); |
|
| 556 | + } |
|
| 557 | + } else { |
|
| 558 | + $items['blank*'] = array( |
|
| 559 | + 'class' => '', |
|
| 560 | + 'desc' => '', |
|
| 561 | + ); |
|
| 562 | + } |
|
| 563 | + $more_items = apply_filters( |
|
| 564 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 565 | + array( |
|
| 566 | + 'overpaid' => array( |
|
| 567 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 568 | + 'desc' => EEH_Template::pretty_status( |
|
| 569 | + EEM_Transaction::overpaid_status_code, |
|
| 570 | + false, |
|
| 571 | + 'sentence' |
|
| 572 | + ), |
|
| 573 | + ), |
|
| 574 | + 'complete' => array( |
|
| 575 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 576 | + 'desc' => EEH_Template::pretty_status( |
|
| 577 | + EEM_Transaction::complete_status_code, |
|
| 578 | + false, |
|
| 579 | + 'sentence' |
|
| 580 | + ), |
|
| 581 | + ), |
|
| 582 | + 'incomplete' => array( |
|
| 583 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 584 | + 'desc' => EEH_Template::pretty_status( |
|
| 585 | + EEM_Transaction::incomplete_status_code, |
|
| 586 | + false, |
|
| 587 | + 'sentence' |
|
| 588 | + ), |
|
| 589 | + ), |
|
| 590 | + 'abandoned' => array( |
|
| 591 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 592 | + 'desc' => EEH_Template::pretty_status( |
|
| 593 | + EEM_Transaction::abandoned_status_code, |
|
| 594 | + false, |
|
| 595 | + 'sentence' |
|
| 596 | + ), |
|
| 597 | + ), |
|
| 598 | + 'failed' => array( |
|
| 599 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 600 | + 'desc' => EEH_Template::pretty_status( |
|
| 601 | + EEM_Transaction::failed_status_code, |
|
| 602 | + false, |
|
| 603 | + 'sentence' |
|
| 604 | + ), |
|
| 605 | + ), |
|
| 606 | + ) |
|
| 607 | + ); |
|
| 608 | + |
|
| 609 | + return array_merge($items, $more_items); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * _transactions_overview_list_table |
|
| 615 | + * |
|
| 616 | + * @access protected |
|
| 617 | + * @return void |
|
| 618 | + * @throws DomainException |
|
| 619 | + * @throws EE_Error |
|
| 620 | + * @throws InvalidArgumentException |
|
| 621 | + * @throws InvalidDataTypeException |
|
| 622 | + * @throws InvalidInterfaceException |
|
| 623 | + * @throws ReflectionException |
|
| 624 | + */ |
|
| 625 | + protected function _transactions_overview_list_table() |
|
| 626 | + { |
|
| 627 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 628 | + $event = isset($this->_req_data['EVT_ID']) |
|
| 629 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 630 | + : null; |
|
| 631 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 632 | + ? sprintf( |
|
| 633 | + esc_html__( |
|
| 634 | + '%sViewing Transactions for the Event: %s%s', |
|
| 635 | + 'event_espresso' |
|
| 636 | + ), |
|
| 637 | + '<h3>', |
|
| 638 | + '<a href="' |
|
| 639 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 640 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 641 | + EVENTS_ADMIN_URL |
|
| 642 | + ) |
|
| 643 | + . '" title="' |
|
| 644 | + . esc_attr__( |
|
| 645 | + 'Click to Edit event', |
|
| 646 | + 'event_espresso' |
|
| 647 | + ) |
|
| 648 | + . '">' . $event->get('EVT_name') . '</a>', |
|
| 649 | + '</h3>' |
|
| 650 | + ) |
|
| 651 | + : ''; |
|
| 652 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 653 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * _transaction_details |
|
| 659 | + * generates HTML for the View Transaction Details Admin page |
|
| 660 | + * |
|
| 661 | + * @access protected |
|
| 662 | + * @return void |
|
| 663 | + * @throws DomainException |
|
| 664 | + * @throws EE_Error |
|
| 665 | + * @throws InvalidArgumentException |
|
| 666 | + * @throws InvalidDataTypeException |
|
| 667 | + * @throws InvalidInterfaceException |
|
| 668 | + * @throws RuntimeException |
|
| 669 | + */ |
|
| 670 | + protected function _transaction_details() |
|
| 671 | + { |
|
| 672 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 673 | + |
|
| 674 | + $this->_set_transaction_status_array(); |
|
| 675 | + |
|
| 676 | + $this->_template_args = array(); |
|
| 677 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 678 | + |
|
| 679 | + $this->_set_transaction_object(); |
|
| 680 | + |
|
| 681 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 682 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 683 | + ? $primary_registration->attendee() |
|
| 684 | + : null; |
|
| 685 | + |
|
| 686 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 687 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 688 | + |
|
| 689 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 690 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 691 | + |
|
| 692 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 693 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 694 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 695 | + |
|
| 696 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 697 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 698 | + |
|
| 699 | + if ($attendee instanceof EE_Attendee |
|
| 700 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 701 | + 'ee_send_message', |
|
| 702 | + 'espresso_transactions_send_payment_reminder' |
|
| 703 | + ) |
|
| 704 | + ) { |
|
| 705 | + $this->_template_args['send_payment_reminder_button'] = |
|
| 706 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 707 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
| 708 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
| 709 | + ? EEH_Template::get_button_or_link( |
|
| 710 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 711 | + array( |
|
| 712 | + 'action' => 'send_payment_reminder', |
|
| 713 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 714 | + 'redirect_to' => 'view_transaction', |
|
| 715 | + ), |
|
| 716 | + TXN_ADMIN_URL |
|
| 717 | + ), |
|
| 718 | + __(' Send Payment Reminder', 'event_espresso'), |
|
| 719 | + 'button secondary-button right', |
|
| 720 | + 'dashicons dashicons-email-alt' |
|
| 721 | + ) |
|
| 722 | + : ''; |
|
| 723 | + } else { |
|
| 724 | + $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 728 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 729 | + $amount_due, |
|
| 730 | + true |
|
| 731 | + ); |
|
| 732 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 733 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 734 | + . $this->_template_args['amount_due']; |
|
| 735 | + } else { |
|
| 736 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 737 | + } |
|
| 738 | + $this->_template_args['amount_due_class'] = ''; |
|
| 739 | + |
|
| 740 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 741 | + // paid in full |
|
| 742 | + $this->_template_args['amount_due'] = false; |
|
| 743 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 744 | + // overpaid |
|
| 745 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 746 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 747 | + && $this->_transaction->get('TXN_paid') > 0 |
|
| 748 | + ) { |
|
| 749 | + // monies owing |
|
| 750 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 751 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 752 | + && $this->_transaction->get('TXN_paid') == 0 |
|
| 753 | + ) { |
|
| 754 | + // no payments made yet |
|
| 755 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 756 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 757 | + // free event |
|
| 758 | + $this->_template_args['amount_due'] = false; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + $payment_method = $this->_transaction->payment_method(); |
|
| 762 | + |
|
| 763 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 764 | + ? $payment_method->admin_name() |
|
| 765 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 766 | + |
|
| 767 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 768 | + // link back to overview |
|
| 769 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 770 | + ? $_SERVER['HTTP_REFERER'] |
|
| 771 | + : TXN_ADMIN_URL; |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + // next link |
|
| 775 | + $next_txn = $this->_transaction->next( |
|
| 776 | + null, |
|
| 777 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 778 | + 'TXN_ID' |
|
| 779 | + ); |
|
| 780 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 781 | + ? $this->_next_link( |
|
| 782 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 783 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 784 | + TXN_ADMIN_URL |
|
| 785 | + ), |
|
| 786 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 787 | + ) |
|
| 788 | + : ''; |
|
| 789 | + // previous link |
|
| 790 | + $previous_txn = $this->_transaction->previous( |
|
| 791 | + null, |
|
| 792 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 793 | + 'TXN_ID' |
|
| 794 | + ); |
|
| 795 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 796 | + ? $this->_previous_link( |
|
| 797 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 798 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 799 | + TXN_ADMIN_URL |
|
| 800 | + ), |
|
| 801 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 802 | + ) |
|
| 803 | + : ''; |
|
| 804 | + |
|
| 805 | + // were we just redirected here after adding a new registration ??? |
|
| 806 | + if (isset( |
|
| 807 | + $this->_req_data['redirect_from'], |
|
| 808 | + $this->_req_data['EVT_ID'], |
|
| 809 | + $this->_req_data['event_name'] |
|
| 810 | + )) { |
|
| 811 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 812 | + 'ee_edit_registrations', |
|
| 813 | + 'espresso_registrations_new_registration', |
|
| 814 | + $this->_req_data['EVT_ID'] |
|
| 815 | + )) { |
|
| 816 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 817 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 818 | + array( |
|
| 819 | + 'page' => 'espresso_registrations', |
|
| 820 | + 'action' => 'new_registration', |
|
| 821 | + 'return' => 'default', |
|
| 822 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 823 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 824 | + ), |
|
| 825 | + REG_ADMIN_URL |
|
| 826 | + ); |
|
| 827 | + $this->_admin_page_title .= '">'; |
|
| 828 | + |
|
| 829 | + $this->_admin_page_title .= sprintf( |
|
| 830 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 831 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 832 | + ); |
|
| 833 | + $this->_admin_page_title .= '</a>'; |
|
| 834 | + } |
|
| 835 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 836 | + } |
|
| 837 | + // grab messages at the last second |
|
| 838 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 839 | + // path to template |
|
| 840 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 841 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 842 | + $template_path, |
|
| 843 | + $this->_template_args, |
|
| 844 | + true |
|
| 845 | + ); |
|
| 846 | + |
|
| 847 | + // the details template wrapper |
|
| 848 | + $this->display_admin_page_with_sidebar(); |
|
| 849 | + |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * _transaction_details_metaboxes |
|
| 855 | + * |
|
| 856 | + * @access protected |
|
| 857 | + * @return void |
|
| 858 | + * @throws EE_Error |
|
| 859 | + * @throws InvalidArgumentException |
|
| 860 | + * @throws InvalidDataTypeException |
|
| 861 | + * @throws InvalidInterfaceException |
|
| 862 | + * @throws RuntimeException |
|
| 863 | + */ |
|
| 864 | + protected function _transaction_details_metaboxes() |
|
| 865 | + { |
|
| 866 | + |
|
| 867 | + $this->_set_transaction_object(); |
|
| 868 | + |
|
| 869 | + add_meta_box( |
|
| 870 | + 'edit-txn-details-mbox', |
|
| 871 | + esc_html__('Transaction Details', 'event_espresso'), |
|
| 872 | + array($this, 'txn_details_meta_box'), |
|
| 873 | + $this->_wp_page_slug, |
|
| 874 | + 'normal', |
|
| 875 | + 'high' |
|
| 876 | + ); |
|
| 877 | + add_meta_box( |
|
| 878 | + 'edit-txn-attendees-mbox', |
|
| 879 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 880 | + array($this, 'txn_attendees_meta_box'), |
|
| 881 | + $this->_wp_page_slug, |
|
| 882 | + 'normal', |
|
| 883 | + 'high', |
|
| 884 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 885 | + ); |
|
| 886 | + add_meta_box( |
|
| 887 | + 'edit-txn-registrant-mbox', |
|
| 888 | + esc_html__('Primary Contact', 'event_espresso'), |
|
| 889 | + array($this, 'txn_registrant_side_meta_box'), |
|
| 890 | + $this->_wp_page_slug, |
|
| 891 | + 'side', |
|
| 892 | + 'high' |
|
| 893 | + ); |
|
| 894 | + add_meta_box( |
|
| 895 | + 'edit-txn-billing-info-mbox', |
|
| 896 | + esc_html__('Billing Information', 'event_espresso'), |
|
| 897 | + array($this, 'txn_billing_info_side_meta_box'), |
|
| 898 | + $this->_wp_page_slug, |
|
| 899 | + 'side', |
|
| 900 | + 'high' |
|
| 901 | + ); |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * txn_details_meta_box |
|
| 907 | + * generates HTML for the Transaction main meta box |
|
| 908 | + * |
|
| 909 | + * @access public |
|
| 910 | + * @return void |
|
| 911 | + * @throws DomainException |
|
| 912 | + * @throws EE_Error |
|
| 913 | + * @throws InvalidArgumentException |
|
| 914 | + * @throws InvalidDataTypeException |
|
| 915 | + * @throws InvalidInterfaceException |
|
| 916 | + * @throws RuntimeException |
|
| 917 | + */ |
|
| 918 | + public function txn_details_meta_box() |
|
| 919 | + { |
|
| 920 | + |
|
| 921 | + $this->_set_transaction_object(); |
|
| 922 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 923 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 924 | + ? $this->_transaction->primary_registration()->attendee() |
|
| 925 | + : null; |
|
| 926 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 927 | + 'ee_edit_payments', |
|
| 928 | + 'apply_payment_or_refund_from_registration_details' |
|
| 929 | + ); |
|
| 930 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | + 'ee_delete_payments', |
|
| 932 | + 'delete_payment_from_registration_details' |
|
| 933 | + ); |
|
| 934 | + |
|
| 935 | + //get line table |
|
| 936 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 937 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 938 | + 'admin_table', |
|
| 939 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 940 | + ); |
|
| 941 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 942 | + $this->_transaction->total_line_item() |
|
| 943 | + ); |
|
| 944 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
| 945 | + ->get('REG_code'); |
|
| 946 | + |
|
| 947 | + // process taxes |
|
| 948 | + $taxes = $this->_transaction->get_many_related( |
|
| 949 | + 'Line_Item', |
|
| 950 | + array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
| 951 | + ); |
|
| 952 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 953 | + |
|
| 954 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 955 | + $this->_transaction->get('TXN_total'), |
|
| 956 | + false, |
|
| 957 | + false |
|
| 958 | + ); |
|
| 959 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 960 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 961 | + |
|
| 962 | + // process payment details |
|
| 963 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
| 964 | + if (! empty($payments)) { |
|
| 965 | + $this->_template_args['payments'] = $payments; |
|
| 966 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 967 | + } else { |
|
| 968 | + $this->_template_args['payments'] = false; |
|
| 969 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 973 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 974 | + array('action' => 'espresso_delete_payment'), |
|
| 975 | + TXN_ADMIN_URL |
|
| 976 | + ); |
|
| 977 | + |
|
| 978 | + if (isset($txn_details['invoice_number'])) { |
|
| 979 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 980 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 981 | + 'Invoice Number', |
|
| 982 | + 'event_espresso' |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 987 | + ->get_first_related('Registration') |
|
| 988 | + ->get('REG_session'); |
|
| 989 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 990 | + 'Registration Session', |
|
| 991 | + 'event_espresso' |
|
| 992 | + ); |
|
| 993 | + |
|
| 994 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 995 | + ? $this->_session['ip_address'] |
|
| 996 | + : ''; |
|
| 997 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 998 | + 'Transaction placed from IP', |
|
| 999 | + 'event_espresso' |
|
| 1000 | + ); |
|
| 1001 | + |
|
| 1002 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1003 | + ? $this->_session['user_agent'] |
|
| 1004 | + : ''; |
|
| 1005 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1006 | + 'Registrant User Agent', |
|
| 1007 | + 'event_espresso' |
|
| 1008 | + ); |
|
| 1009 | + |
|
| 1010 | + $reg_steps = '<ul>'; |
|
| 1011 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1012 | + if ($reg_step_status === true) { |
|
| 1013 | + $reg_steps .= '<li style="color:#70cc50">' |
|
| 1014 | + . sprintf( |
|
| 1015 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1016 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1017 | + ) |
|
| 1018 | + . '</li>'; |
|
| 1019 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1020 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1021 | + . sprintf( |
|
| 1022 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1023 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1024 | + date( |
|
| 1025 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1026 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 1027 | + ) |
|
| 1028 | + ) |
|
| 1029 | + . '</li>'; |
|
| 1030 | + } else { |
|
| 1031 | + $reg_steps .= '<li style="color:#E76700">' |
|
| 1032 | + . sprintf( |
|
| 1033 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1034 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1035 | + ) |
|
| 1036 | + . '</li>'; |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + $reg_steps .= '</ul>'; |
|
| 1040 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1041 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1042 | + 'Registration Step Progress', |
|
| 1043 | + 'event_espresso' |
|
| 1044 | + ); |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 1048 | + $this->_get_payment_methods($payments); |
|
| 1049 | + $this->_get_payment_status_array(); |
|
| 1050 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 1051 | + |
|
| 1052 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1053 | + 'action' => 'edit_transaction', |
|
| 1054 | + 'process' => 'transaction', |
|
| 1055 | + ), TXN_ADMIN_URL); |
|
| 1056 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1057 | + 'page' => 'espresso_transactions', |
|
| 1058 | + 'action' => 'espresso_apply_payment', |
|
| 1059 | + ), WP_AJAX_URL); |
|
| 1060 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 1061 | + 'page' => 'espresso_transactions', |
|
| 1062 | + 'action' => 'espresso_delete_payment', |
|
| 1063 | + ), WP_AJAX_URL); |
|
| 1064 | + |
|
| 1065 | + // 'espresso_delete_payment_nonce' |
|
| 1066 | + |
|
| 1067 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1068 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * _get_registration_payment_IDs |
|
| 1074 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1075 | + * |
|
| 1076 | + * @access protected |
|
| 1077 | + * @param EE_Payment[] $payments |
|
| 1078 | + * @return array |
|
| 1079 | + * @throws EE_Error |
|
| 1080 | + * @throws InvalidArgumentException |
|
| 1081 | + * @throws InvalidDataTypeException |
|
| 1082 | + * @throws InvalidInterfaceException |
|
| 1083 | + */ |
|
| 1084 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 1085 | + { |
|
| 1086 | + $existing_reg_payments = array(); |
|
| 1087 | + // get all reg payments for these payments |
|
| 1088 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 1089 | + array( |
|
| 1090 | + 'PAY_ID' => array( |
|
| 1091 | + 'IN', |
|
| 1092 | + array_keys($payments), |
|
| 1093 | + ), |
|
| 1094 | + ), |
|
| 1095 | + )); |
|
| 1096 | + if (! empty($reg_payments)) { |
|
| 1097 | + foreach ($payments as $payment) { |
|
| 1098 | + if (! $payment instanceof EE_Payment) { |
|
| 1099 | + continue; |
|
| 1100 | + } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1101 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 1102 | + } |
|
| 1103 | + foreach ($reg_payments as $reg_payment) { |
|
| 1104 | + if ($reg_payment instanceof EE_Registration_Payment |
|
| 1105 | + && $reg_payment->payment_ID() === $payment->ID() |
|
| 1106 | + ) { |
|
| 1107 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + return $existing_reg_payments; |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + |
|
| 1117 | + /** |
|
| 1118 | + * _get_registrations_to_apply_payment_to |
|
| 1119 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1120 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 1121 | + * |
|
| 1122 | + * @access protected |
|
| 1123 | + * @return void |
|
| 1124 | + * @throws \EE_Error |
|
| 1125 | + */ |
|
| 1126 | + protected function _get_registrations_to_apply_payment_to() |
|
| 1127 | + { |
|
| 1128 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1129 | + $query_params = array( |
|
| 1130 | + array( |
|
| 1131 | + 'STS_ID' => array( |
|
| 1132 | + 'IN', |
|
| 1133 | + array( |
|
| 1134 | + EEM_Registration::status_id_approved, |
|
| 1135 | + EEM_Registration::status_id_pending_payment, |
|
| 1136 | + EEM_Registration::status_id_not_approved, |
|
| 1137 | + ), |
|
| 1138 | + ), |
|
| 1139 | + ), |
|
| 1140 | + ); |
|
| 1141 | + $registrations_to_apply_payment_to = EEH_HTML::br() |
|
| 1142 | + . EEH_HTML::div( |
|
| 1143 | + '', |
|
| 1144 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1145 | + '', |
|
| 1146 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1147 | + ); |
|
| 1148 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1149 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1150 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1151 | + EEH_HTML::tr( |
|
| 1152 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1153 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1154 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1155 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1156 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1157 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1158 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1159 | + ) |
|
| 1160 | + ); |
|
| 1161 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1162 | + // get registrations for TXN |
|
| 1163 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 1164 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1165 | + foreach ($registrations as $registration) { |
|
| 1166 | + if ($registration instanceof EE_Registration) { |
|
| 1167 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1168 | + ? $registration->attendee()->full_name() |
|
| 1169 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1170 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 1171 | + $taxable = $registration->ticket()->taxable() |
|
| 1172 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1173 | + : ''; |
|
| 1174 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 1175 | + ? ' checked="checked"' |
|
| 1176 | + : ''; |
|
| 1177 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1178 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1179 | + EEH_HTML::td($registration->ID()) . |
|
| 1180 | + EEH_HTML::td($attendee_name) . |
|
| 1181 | + EEH_HTML::td( |
|
| 1182 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1183 | + ) . |
|
| 1184 | + EEH_HTML::td($registration->event_name()) . |
|
| 1185 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1186 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1187 | + EEH_HTML::td( |
|
| 1188 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 1189 | + . '" name="txn_admin_payment[registrations]"' |
|
| 1190 | + . $checked . $disabled . '>', |
|
| 1191 | + '', |
|
| 1192 | + 'jst-cntr' |
|
| 1193 | + ), |
|
| 1194 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1195 | + ); |
|
| 1196 | + } |
|
| 1197 | + } |
|
| 1198 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1199 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1200 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1201 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1202 | + esc_html__( |
|
| 1203 | + '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.', |
|
| 1204 | + 'event_espresso' |
|
| 1205 | + ), |
|
| 1206 | + '', |
|
| 1207 | + 'clear description' |
|
| 1208 | + ); |
|
| 1209 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1210 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * _get_reg_status_selection |
|
| 1216 | + * |
|
| 1217 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1218 | + * instead of events. |
|
| 1219 | + * @access protected |
|
| 1220 | + * @return void |
|
| 1221 | + * @throws EE_Error |
|
| 1222 | + */ |
|
| 1223 | + protected function _get_reg_status_selection() |
|
| 1224 | + { |
|
| 1225 | + //first get all possible statuses |
|
| 1226 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1227 | + //let's add a "don't change" option. |
|
| 1228 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1229 | + $status_array = array_merge($status_array, $statuses); |
|
| 1230 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1231 | + 'txn_reg_status_change[reg_status]', |
|
| 1232 | + $status_array, |
|
| 1233 | + 'NAN', |
|
| 1234 | + 'id="txn-admin-payment-reg-status-inp"', |
|
| 1235 | + 'txn-reg-status-change-reg-status' |
|
| 1236 | + ); |
|
| 1237 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1238 | + 'delete_txn_reg_status_change[reg_status]', |
|
| 1239 | + $status_array, |
|
| 1240 | + 'NAN', |
|
| 1241 | + 'delete-txn-admin-payment-reg-status-inp', |
|
| 1242 | + 'delete-txn-reg-status-change-reg-status' |
|
| 1243 | + ); |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * _get_payment_methods |
|
| 1249 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1250 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1251 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1252 | + * |
|
| 1253 | + * @access private |
|
| 1254 | + * @param EE_Payment[] to show on this page |
|
| 1255 | + * @return void |
|
| 1256 | + * @throws EE_Error |
|
| 1257 | + * @throws InvalidArgumentException |
|
| 1258 | + * @throws InvalidDataTypeException |
|
| 1259 | + * @throws InvalidInterfaceException |
|
| 1260 | + */ |
|
| 1261 | + private function _get_payment_methods($payments = array()) |
|
| 1262 | + { |
|
| 1263 | + $payment_methods_of_payments = array(); |
|
| 1264 | + foreach ($payments as $payment) { |
|
| 1265 | + if ($payment instanceof EE_Payment) { |
|
| 1266 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + if ($payment_methods_of_payments) { |
|
| 1270 | + $query_args = array( |
|
| 1271 | + array( |
|
| 1272 | + 'OR*payment_method_for_payment' => array( |
|
| 1273 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1274 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1275 | + ), |
|
| 1276 | + ), |
|
| 1277 | + ); |
|
| 1278 | + } else { |
|
| 1279 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1280 | + } |
|
| 1281 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * txn_attendees_meta_box |
|
| 1287 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1288 | + * |
|
| 1289 | + * @access public |
|
| 1290 | + * @param WP_Post $post |
|
| 1291 | + * @param array $metabox |
|
| 1292 | + * @return void |
|
| 1293 | + * @throws DomainException |
|
| 1294 | + * @throws EE_Error |
|
| 1295 | + */ |
|
| 1296 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1297 | + { |
|
| 1298 | + |
|
| 1299 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1300 | + extract($metabox['args']); |
|
| 1301 | + $this->_template_args['post'] = $post; |
|
| 1302 | + $this->_template_args['event_attendees'] = array(); |
|
| 1303 | + // process items in cart |
|
| 1304 | + $line_items = $this->_transaction->get_many_related( |
|
| 1305 | + 'Line_Item', |
|
| 1306 | + array(array('LIN_type' => 'line-item')) |
|
| 1307 | + ); |
|
| 1308 | + if (! empty($line_items)) { |
|
| 1309 | + foreach ($line_items as $item) { |
|
| 1310 | + if ($item instanceof EE_Line_Item) { |
|
| 1311 | + switch ($item->OBJ_type()) { |
|
| 1312 | + case 'Event': |
|
| 1313 | + break; |
|
| 1314 | + case 'Ticket': |
|
| 1315 | + $ticket = $item->ticket(); |
|
| 1316 | + //right now we're only handling tickets here. |
|
| 1317 | + //Cause its expected that only tickets will have attendees right? |
|
| 1318 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1319 | + continue; |
|
| 1320 | + } |
|
| 1321 | + try { |
|
| 1322 | + $event_name = $ticket->get_event_name(); |
|
| 1323 | + } catch (Exception $e) { |
|
| 1324 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1325 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1326 | + } |
|
| 1327 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1328 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1329 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1330 | + $registrations = $ticket->get_many_related( |
|
| 1331 | + 'Registration', |
|
| 1332 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1333 | + ); |
|
| 1334 | + foreach ($registrations as $registration) { |
|
| 1335 | + if (! $registration instanceof EE_Registration) { |
|
| 1336 | + continue; |
|
| 1337 | + } |
|
| 1338 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
| 1339 | + = $registration->status_ID(); |
|
| 1340 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
| 1341 | + = $registration->count(); |
|
| 1342 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
| 1343 | + = $event_name; |
|
| 1344 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
| 1345 | + = $ticket_price; |
|
| 1346 | + // attendee info |
|
| 1347 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1348 | + if ($attendee instanceof EE_Attendee) { |
|
| 1349 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
| 1350 | + = $attendee->ID(); |
|
| 1351 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
| 1352 | + = $attendee->full_name(); |
|
| 1353 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
| 1354 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1355 | + . esc_html__( |
|
| 1356 | + ' Event', |
|
| 1357 | + 'event_espresso' |
|
| 1358 | + ) |
|
| 1359 | + . '">' . $attendee->email() . '</a>'; |
|
| 1360 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
| 1361 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1362 | + } else { |
|
| 1363 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1364 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1365 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1366 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + break; |
|
| 1370 | + |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1376 | + array( |
|
| 1377 | + 'action' => 'edit_transaction', |
|
| 1378 | + 'process' => 'attendees', |
|
| 1379 | + ), |
|
| 1380 | + TXN_ADMIN_URL |
|
| 1381 | + ); |
|
| 1382 | + echo EEH_Template::display_template( |
|
| 1383 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1384 | + $this->_template_args, |
|
| 1385 | + true |
|
| 1386 | + ); |
|
| 1387 | + |
|
| 1388 | + } else { |
|
| 1389 | + echo sprintf( |
|
| 1390 | + esc_html__( |
|
| 1391 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1392 | + 'event_espresso' |
|
| 1393 | + ), |
|
| 1394 | + '<p class="important-notice">', |
|
| 1395 | + '</p>' |
|
| 1396 | + ); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * txn_registrant_side_meta_box |
|
| 1403 | + * generates HTML for the Edit Transaction side meta box |
|
| 1404 | + * |
|
| 1405 | + * @access public |
|
| 1406 | + * @return void |
|
| 1407 | + * @throws DomainException |
|
| 1408 | + * @throws EE_Error |
|
| 1409 | + * @throws InvalidArgumentException |
|
| 1410 | + * @throws InvalidDataTypeException |
|
| 1411 | + * @throws InvalidInterfaceException |
|
| 1412 | + */ |
|
| 1413 | + public function txn_registrant_side_meta_box() |
|
| 1414 | + { |
|
| 1415 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1416 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1417 | + : null; |
|
| 1418 | + if (! $primary_att instanceof EE_Attendee) { |
|
| 1419 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1420 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1421 | + 'event_espresso' |
|
| 1422 | + ); |
|
| 1423 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1424 | + } |
|
| 1425 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1426 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1427 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1428 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1429 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1430 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1431 | + 'action' => 'edit_attendee', |
|
| 1432 | + 'post' => $primary_att->ID(), |
|
| 1433 | + ), REG_ADMIN_URL); |
|
| 1434 | + // get formatted address for registrant |
|
| 1435 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1436 | + echo EEH_Template::display_template( |
|
| 1437 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1438 | + $this->_template_args, |
|
| 1439 | + true |
|
| 1440 | + ); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + |
|
| 1444 | + /** |
|
| 1445 | + * txn_billing_info_side_meta_box |
|
| 1446 | + * generates HTML for the Edit Transaction side meta box |
|
| 1447 | + * |
|
| 1448 | + * @access public |
|
| 1449 | + * @return void |
|
| 1450 | + * @throws DomainException |
|
| 1451 | + * @throws EE_Error |
|
| 1452 | + */ |
|
| 1453 | + public function txn_billing_info_side_meta_box() |
|
| 1454 | + { |
|
| 1455 | + |
|
| 1456 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1457 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1458 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1459 | + TXN_ADMIN_URL |
|
| 1460 | + ); |
|
| 1461 | + |
|
| 1462 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1463 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * apply_payments_or_refunds |
|
| 1469 | + * registers a payment or refund made towards a transaction |
|
| 1470 | + * |
|
| 1471 | + * @access public |
|
| 1472 | + * @return void |
|
| 1473 | + * @throws EE_Error |
|
| 1474 | + * @throws InvalidArgumentException |
|
| 1475 | + * @throws ReflectionException |
|
| 1476 | + * @throws RuntimeException |
|
| 1477 | + * @throws InvalidDataTypeException |
|
| 1478 | + * @throws InvalidInterfaceException |
|
| 1479 | + */ |
|
| 1480 | + public function apply_payments_or_refunds() |
|
| 1481 | + { |
|
| 1482 | + $json_response_data = array('return_data' => false); |
|
| 1483 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1484 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1485 | + 'ee_edit_payments', |
|
| 1486 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1487 | + ); |
|
| 1488 | + if (! empty($valid_data) && $has_access) { |
|
| 1489 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1490 | + //save the new payment |
|
| 1491 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1492 | + // get the TXN for this payment |
|
| 1493 | + $transaction = $payment->transaction(); |
|
| 1494 | + // verify transaction |
|
| 1495 | + if ($transaction instanceof EE_Transaction) { |
|
| 1496 | + // calculate_total_payments_and_update_status |
|
| 1497 | + $this->_process_transaction_payments($transaction); |
|
| 1498 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1499 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1500 | + // apply payment to registrations (if applicable) |
|
| 1501 | + if (! empty($REG_IDs)) { |
|
| 1502 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1503 | + $this->_maybe_send_notifications(); |
|
| 1504 | + // now process status changes for the same registrations |
|
| 1505 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1506 | + } |
|
| 1507 | + $this->_maybe_send_notifications($payment); |
|
| 1508 | + //prepare to render page |
|
| 1509 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1510 | + do_action( |
|
| 1511 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1512 | + $transaction, |
|
| 1513 | + $payment |
|
| 1514 | + ); |
|
| 1515 | + } else { |
|
| 1516 | + EE_Error::add_error( |
|
| 1517 | + esc_html__( |
|
| 1518 | + 'A valid Transaction for this payment could not be retrieved.', |
|
| 1519 | + 'event_espresso' |
|
| 1520 | + ), |
|
| 1521 | + __FILE__, |
|
| 1522 | + __FUNCTION__, |
|
| 1523 | + __LINE__ |
|
| 1524 | + ); |
|
| 1525 | + } |
|
| 1526 | + } else { |
|
| 1527 | + if ($has_access) { |
|
| 1528 | + EE_Error::add_error( |
|
| 1529 | + esc_html__( |
|
| 1530 | + 'The payment form data could not be processed. Please try again.', |
|
| 1531 | + 'event_espresso' |
|
| 1532 | + ), |
|
| 1533 | + __FILE__, |
|
| 1534 | + __FUNCTION__, |
|
| 1535 | + __LINE__ |
|
| 1536 | + ); |
|
| 1537 | + } else { |
|
| 1538 | + EE_Error::add_error( |
|
| 1539 | + esc_html__( |
|
| 1540 | + 'You do not have access to apply payments or refunds to a registration.', |
|
| 1541 | + 'event_espresso' |
|
| 1542 | + ), |
|
| 1543 | + __FILE__, |
|
| 1544 | + __FUNCTION__, |
|
| 1545 | + __LINE__ |
|
| 1546 | + ); |
|
| 1547 | + } |
|
| 1548 | + } |
|
| 1549 | + $notices = EE_Error::get_notices( |
|
| 1550 | + false, |
|
| 1551 | + false, |
|
| 1552 | + false |
|
| 1553 | + ); |
|
| 1554 | + $this->_template_args = array( |
|
| 1555 | + 'data' => $json_response_data, |
|
| 1556 | + 'error' => $notices['errors'], |
|
| 1557 | + 'success' => $notices['success'], |
|
| 1558 | + ); |
|
| 1559 | + $this->_return_json(); |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + |
|
| 1563 | + /** |
|
| 1564 | + * _validate_payment_request_data |
|
| 1565 | + * |
|
| 1566 | + * @return array |
|
| 1567 | + */ |
|
| 1568 | + protected function _validate_payment_request_data() |
|
| 1569 | + { |
|
| 1570 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1571 | + return false; |
|
| 1572 | + } |
|
| 1573 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1574 | + try { |
|
| 1575 | + if ($payment_form->was_submitted()) { |
|
| 1576 | + $payment_form->receive_form_submission(); |
|
| 1577 | + if (! $payment_form->is_valid()) { |
|
| 1578 | + $submission_error_messages = array(); |
|
| 1579 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1580 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1581 | + $submission_error_messages[] = sprintf( |
|
| 1582 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1583 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1584 | + $validation_error->getMessage() |
|
| 1585 | + ); |
|
| 1586 | + } |
|
| 1587 | + } |
|
| 1588 | + EE_Error::add_error( |
|
| 1589 | + implode('<br />', $submission_error_messages), |
|
| 1590 | + __FILE__, |
|
| 1591 | + __FUNCTION__, |
|
| 1592 | + __LINE__ |
|
| 1593 | + ); |
|
| 1594 | + |
|
| 1595 | + return array(); |
|
| 1596 | + } |
|
| 1597 | + } |
|
| 1598 | + } catch (EE_Error $e) { |
|
| 1599 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1600 | + |
|
| 1601 | + return array(); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + return $payment_form->valid_data(); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * _generate_payment_form_section |
|
| 1610 | + * |
|
| 1611 | + * @return EE_Form_Section_Proper |
|
| 1612 | + */ |
|
| 1613 | + protected function _generate_payment_form_section() |
|
| 1614 | + { |
|
| 1615 | + return new EE_Form_Section_Proper( |
|
| 1616 | + array( |
|
| 1617 | + 'name' => 'txn_admin_payment', |
|
| 1618 | + 'subsections' => array( |
|
| 1619 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1620 | + array( |
|
| 1621 | + 'default' => 0, |
|
| 1622 | + 'required' => false, |
|
| 1623 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1624 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1625 | + ) |
|
| 1626 | + ), |
|
| 1627 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1628 | + array( |
|
| 1629 | + 'default' => 0, |
|
| 1630 | + 'required' => true, |
|
| 1631 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1632 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1633 | + ) |
|
| 1634 | + ), |
|
| 1635 | + 'type' => new EE_Text_Input( |
|
| 1636 | + array( |
|
| 1637 | + 'default' => 1, |
|
| 1638 | + 'required' => true, |
|
| 1639 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1640 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1641 | + ) |
|
| 1642 | + ), |
|
| 1643 | + 'amount' => new EE_Text_Input( |
|
| 1644 | + array( |
|
| 1645 | + 'default' => 0, |
|
| 1646 | + 'required' => true, |
|
| 1647 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1648 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1649 | + ) |
|
| 1650 | + ), |
|
| 1651 | + 'status' => new EE_Text_Input( |
|
| 1652 | + array( |
|
| 1653 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1654 | + 'required' => true, |
|
| 1655 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1656 | + ) |
|
| 1657 | + ), |
|
| 1658 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1659 | + array( |
|
| 1660 | + 'default' => 2, |
|
| 1661 | + 'required' => true, |
|
| 1662 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1663 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1664 | + ) |
|
| 1665 | + ), |
|
| 1666 | + 'date' => new EE_Text_Input( |
|
| 1667 | + array( |
|
| 1668 | + 'default' => time(), |
|
| 1669 | + 'required' => true, |
|
| 1670 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1671 | + ) |
|
| 1672 | + ), |
|
| 1673 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1674 | + array( |
|
| 1675 | + 'default' => '', |
|
| 1676 | + 'required' => false, |
|
| 1677 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1678 | + 'validation_strategies' => array( |
|
| 1679 | + new EE_Max_Length_Validation_Strategy( |
|
| 1680 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1681 | + 100 |
|
| 1682 | + ), |
|
| 1683 | + ), |
|
| 1684 | + ) |
|
| 1685 | + ), |
|
| 1686 | + 'po_number' => new EE_Text_Input( |
|
| 1687 | + array( |
|
| 1688 | + 'default' => '', |
|
| 1689 | + 'required' => false, |
|
| 1690 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1691 | + 'validation_strategies' => array( |
|
| 1692 | + new EE_Max_Length_Validation_Strategy( |
|
| 1693 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1694 | + 100 |
|
| 1695 | + ), |
|
| 1696 | + ), |
|
| 1697 | + ) |
|
| 1698 | + ), |
|
| 1699 | + 'accounting' => new EE_Text_Input( |
|
| 1700 | + array( |
|
| 1701 | + 'default' => '', |
|
| 1702 | + 'required' => false, |
|
| 1703 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1704 | + 'validation_strategies' => array( |
|
| 1705 | + new EE_Max_Length_Validation_Strategy( |
|
| 1706 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1707 | + 100 |
|
| 1708 | + ), |
|
| 1709 | + ), |
|
| 1710 | + ) |
|
| 1711 | + ), |
|
| 1712 | + ), |
|
| 1713 | + ) |
|
| 1714 | + ); |
|
| 1715 | + } |
|
| 1716 | + |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * _create_payment_from_request_data |
|
| 1720 | + * |
|
| 1721 | + * @param array $valid_data |
|
| 1722 | + * @return EE_Payment |
|
| 1723 | + * @throws EE_Error |
|
| 1724 | + */ |
|
| 1725 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1726 | + { |
|
| 1727 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1728 | + // get payment amount |
|
| 1729 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1730 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1731 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1732 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1733 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1734 | + $date = $valid_data['date'] |
|
| 1735 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1736 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1737 | + $payment = EE_Payment::new_instance( |
|
| 1738 | + array( |
|
| 1739 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1740 | + 'STS_ID' => $valid_data['status'], |
|
| 1741 | + 'PAY_timestamp' => $date, |
|
| 1742 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1743 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1744 | + 'PAY_amount' => $amount, |
|
| 1745 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1746 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1747 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1748 | + 'PAY_details' => $valid_data, |
|
| 1749 | + 'PAY_ID' => $PAY_ID, |
|
| 1750 | + ), |
|
| 1751 | + '', |
|
| 1752 | + array('Y-m-d', 'g:i a') |
|
| 1753 | + ); |
|
| 1754 | + |
|
| 1755 | + if (! $payment->save()) { |
|
| 1756 | + EE_Error::add_error( |
|
| 1757 | + sprintf( |
|
| 1758 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1759 | + $payment->ID() |
|
| 1760 | + ), |
|
| 1761 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1762 | + ); |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + return $payment; |
|
| 1766 | + } |
|
| 1767 | + |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * _process_transaction_payments |
|
| 1771 | + * |
|
| 1772 | + * @param \EE_Transaction $transaction |
|
| 1773 | + * @return void |
|
| 1774 | + * @throws EE_Error |
|
| 1775 | + * @throws InvalidArgumentException |
|
| 1776 | + * @throws ReflectionException |
|
| 1777 | + * @throws InvalidDataTypeException |
|
| 1778 | + * @throws InvalidInterfaceException |
|
| 1779 | + */ |
|
| 1780 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1781 | + { |
|
| 1782 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1783 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1784 | + //update the transaction with this payment |
|
| 1785 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1786 | + EE_Error::add_success(esc_html__( |
|
| 1787 | + 'The payment has been processed successfully.', 'event_espresso'), |
|
| 1788 | + __FILE__, |
|
| 1789 | + __FUNCTION__, |
|
| 1790 | + __LINE__ |
|
| 1791 | + ); |
|
| 1792 | + } else { |
|
| 1793 | + EE_Error::add_error( |
|
| 1794 | + esc_html__( |
|
| 1795 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1796 | + 'event_espresso' |
|
| 1797 | + ) |
|
| 1798 | + , |
|
| 1799 | + __FILE__, |
|
| 1800 | + __FUNCTION__, |
|
| 1801 | + __LINE__ |
|
| 1802 | + ); |
|
| 1803 | + } |
|
| 1804 | + } |
|
| 1805 | + |
|
| 1806 | + |
|
| 1807 | + /** |
|
| 1808 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1809 | + * returns a list of registration IDs that the payment will apply to |
|
| 1810 | + * |
|
| 1811 | + * @param \EE_Payment $payment |
|
| 1812 | + * @return array |
|
| 1813 | + * @throws EE_Error |
|
| 1814 | + */ |
|
| 1815 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1816 | + { |
|
| 1817 | + $REG_IDs = array(); |
|
| 1818 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1819 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1820 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1821 | + } |
|
| 1822 | + //nothing specified ? then get all reg IDs |
|
| 1823 | + if (empty($REG_IDs)) { |
|
| 1824 | + $registrations = $payment->transaction()->registrations(); |
|
| 1825 | + $REG_IDs = ! empty($registrations) |
|
| 1826 | + ? array_keys($registrations) |
|
| 1827 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1831 | + return array_map('intval', $REG_IDs); |
|
| 1832 | + } |
|
| 1833 | + |
|
| 1834 | + |
|
| 1835 | + /** |
|
| 1836 | + * @return array |
|
| 1837 | + */ |
|
| 1838 | + public function existing_reg_payment_REG_IDs() |
|
| 1839 | + { |
|
| 1840 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + |
|
| 1844 | + /** |
|
| 1845 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1846 | + */ |
|
| 1847 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1848 | + { |
|
| 1849 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + |
|
| 1853 | + /** |
|
| 1854 | + * _get_existing_reg_payment_REG_IDs |
|
| 1855 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1856 | + * as recorded in the database |
|
| 1857 | + * |
|
| 1858 | + * @param \EE_Payment $payment |
|
| 1859 | + * @return array |
|
| 1860 | + * @throws EE_Error |
|
| 1861 | + */ |
|
| 1862 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1863 | + { |
|
| 1864 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1865 | + // let's get any existing reg payment records for this payment |
|
| 1866 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1867 | + // but we only want the REG IDs, so grab the array keys |
|
| 1868 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 1869 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
| 1870 | + : array(); |
|
| 1871 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * _remove_existing_registration_payments |
|
| 1880 | + * this calculates the difference between existing relations |
|
| 1881 | + * to the supplied payment and the new list registration IDs, |
|
| 1882 | + * removes any related registrations that no longer apply, |
|
| 1883 | + * and then updates the registration paid fields |
|
| 1884 | + * |
|
| 1885 | + * @param \EE_Payment $payment |
|
| 1886 | + * @param int $PAY_ID |
|
| 1887 | + * @return bool; |
|
| 1888 | + * @throws EE_Error |
|
| 1889 | + * @throws InvalidArgumentException |
|
| 1890 | + * @throws ReflectionException |
|
| 1891 | + * @throws InvalidDataTypeException |
|
| 1892 | + * @throws InvalidInterfaceException |
|
| 1893 | + */ |
|
| 1894 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1895 | + { |
|
| 1896 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 1897 | + if ($PAY_ID == 0) { |
|
| 1898 | + return false; |
|
| 1899 | + } |
|
| 1900 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1901 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1902 | + return false; |
|
| 1903 | + } |
|
| 1904 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1905 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1906 | + |
|
| 1907 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1908 | + $payment, |
|
| 1909 | + array( |
|
| 1910 | + array( |
|
| 1911 | + 'PAY_ID' => $payment->ID(), |
|
| 1912 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1913 | + ), |
|
| 1914 | + ) |
|
| 1915 | + ); |
|
| 1916 | + } |
|
| 1917 | + |
|
| 1918 | + |
|
| 1919 | + /** |
|
| 1920 | + * _update_registration_payments |
|
| 1921 | + * this applies the payments to the selected registrations |
|
| 1922 | + * but only if they have not already been paid for |
|
| 1923 | + * |
|
| 1924 | + * @param EE_Transaction $transaction |
|
| 1925 | + * @param \EE_Payment $payment |
|
| 1926 | + * @param array $REG_IDs |
|
| 1927 | + * @return void |
|
| 1928 | + * @throws EE_Error |
|
| 1929 | + * @throws InvalidArgumentException |
|
| 1930 | + * @throws ReflectionException |
|
| 1931 | + * @throws RuntimeException |
|
| 1932 | + * @throws InvalidDataTypeException |
|
| 1933 | + * @throws InvalidInterfaceException |
|
| 1934 | + */ |
|
| 1935 | + protected function _update_registration_payments( |
|
| 1936 | + EE_Transaction $transaction, |
|
| 1937 | + EE_Payment $payment, |
|
| 1938 | + $REG_IDs = array() |
|
| 1939 | + ) { |
|
| 1940 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1941 | + // so let's do that using our set of REG_IDs from the form |
|
| 1942 | + $registration_query_where_params = array( |
|
| 1943 | + 'REG_ID' => array('IN', $REG_IDs), |
|
| 1944 | + ); |
|
| 1945 | + // but add in some conditions regarding payment, |
|
| 1946 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1947 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1948 | + if (! $payment->is_a_refund()) { |
|
| 1949 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1950 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1951 | + } |
|
| 1952 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1953 | + if (! empty($registrations)) { |
|
| 1954 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 1955 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1956 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1957 | + } |
|
| 1958 | + } |
|
| 1959 | + |
|
| 1960 | + |
|
| 1961 | + /** |
|
| 1962 | + * _process_registration_status_change |
|
| 1963 | + * This processes requested registration status changes for all the registrations |
|
| 1964 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1965 | + * |
|
| 1966 | + * @param EE_Transaction $transaction |
|
| 1967 | + * @param array $REG_IDs |
|
| 1968 | + * @return bool |
|
| 1969 | + * @throws EE_Error |
|
| 1970 | + * @throws InvalidArgumentException |
|
| 1971 | + * @throws ReflectionException |
|
| 1972 | + * @throws InvalidDataTypeException |
|
| 1973 | + * @throws InvalidInterfaceException |
|
| 1974 | + */ |
|
| 1975 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1976 | + { |
|
| 1977 | + // first if there is no change in status then we get out. |
|
| 1978 | + if ( |
|
| 1979 | + ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1980 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 1981 | + ) { |
|
| 1982 | + //no error message, no change requested, just nothing to do man. |
|
| 1983 | + return false; |
|
| 1984 | + } |
|
| 1985 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1986 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1987 | + |
|
| 1988 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1989 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 1990 | + $transaction, |
|
| 1991 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1992 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1993 | + ); |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + |
|
| 1997 | + /** |
|
| 1998 | + * _build_payment_json_response |
|
| 1999 | + * |
|
| 2000 | + * @access public |
|
| 2001 | + * @param \EE_Payment $payment |
|
| 2002 | + * @param array $REG_IDs |
|
| 2003 | + * @param bool | null $delete_txn_reg_status_change |
|
| 2004 | + * @return array |
|
| 2005 | + * @throws EE_Error |
|
| 2006 | + * @throws InvalidArgumentException |
|
| 2007 | + * @throws InvalidDataTypeException |
|
| 2008 | + * @throws InvalidInterfaceException |
|
| 2009 | + */ |
|
| 2010 | + protected function _build_payment_json_response( |
|
| 2011 | + EE_Payment $payment, |
|
| 2012 | + $REG_IDs = array(), |
|
| 2013 | + $delete_txn_reg_status_change = null |
|
| 2014 | + ) { |
|
| 2015 | + // was the payment deleted ? |
|
| 2016 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 2017 | + return array( |
|
| 2018 | + 'PAY_ID' => $payment->ID(), |
|
| 2019 | + 'amount' => $payment->amount(), |
|
| 2020 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2021 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2022 | + 'pay_status' => $payment->STS_ID(), |
|
| 2023 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2024 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2025 | + ); |
|
| 2026 | + } else { |
|
| 2027 | + $this->_get_payment_status_array(); |
|
| 2028 | + |
|
| 2029 | + return array( |
|
| 2030 | + 'amount' => $payment->amount(), |
|
| 2031 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2032 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2033 | + 'pay_status' => $payment->STS_ID(), |
|
| 2034 | + 'PAY_ID' => $payment->ID(), |
|
| 2035 | + 'STS_ID' => $payment->STS_ID(), |
|
| 2036 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 2037 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2038 | + 'method' => strtoupper($payment->source()), |
|
| 2039 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2040 | + 'gateway' => $payment->payment_method() |
|
| 2041 | + ? $payment->payment_method()->admin_name() |
|
| 2042 | + : esc_html__("Unknown", 'event_espresso'), |
|
| 2043 | + 'gateway_response' => $payment->gateway_response(), |
|
| 2044 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2045 | + 'po_number' => $payment->po_number(), |
|
| 2046 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 2047 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2048 | + ); |
|
| 2049 | + } |
|
| 2050 | + } |
|
| 2051 | + |
|
| 2052 | + |
|
| 2053 | + /** |
|
| 2054 | + * delete_payment |
|
| 2055 | + * delete a payment or refund made towards a transaction |
|
| 2056 | + * |
|
| 2057 | + * @access public |
|
| 2058 | + * @return void |
|
| 2059 | + * @throws EE_Error |
|
| 2060 | + * @throws InvalidArgumentException |
|
| 2061 | + * @throws ReflectionException |
|
| 2062 | + * @throws InvalidDataTypeException |
|
| 2063 | + * @throws InvalidInterfaceException |
|
| 2064 | + */ |
|
| 2065 | + public function delete_payment() |
|
| 2066 | + { |
|
| 2067 | + $json_response_data = array('return_data' => false); |
|
| 2068 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2069 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2070 | + : 0; |
|
| 2071 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2072 | + 'ee_delete_payments', |
|
| 2073 | + 'delete_payment_from_registration_details' |
|
| 2074 | + ); |
|
| 2075 | + if ($PAY_ID && $can_delete) { |
|
| 2076 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2077 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2078 | + : false; |
|
| 2079 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2080 | + if ($payment instanceof EE_Payment) { |
|
| 2081 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2082 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2083 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2084 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2085 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2086 | + $payment, |
|
| 2087 | + $REG_IDs, |
|
| 2088 | + $delete_txn_reg_status_change |
|
| 2089 | + ); |
|
| 2090 | + if ($delete_txn_reg_status_change) { |
|
| 2091 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2092 | + //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2093 | + //$_REQUEST global because that's how messages will be looking for it. |
|
| 2094 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2095 | + $this->_maybe_send_notifications(); |
|
| 2096 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2097 | + } |
|
| 2098 | + } |
|
| 2099 | + } else { |
|
| 2100 | + EE_Error::add_error( |
|
| 2101 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2102 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2103 | + ); |
|
| 2104 | + } |
|
| 2105 | + } else { |
|
| 2106 | + if ($can_delete) { |
|
| 2107 | + EE_Error::add_error( |
|
| 2108 | + esc_html__( |
|
| 2109 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2110 | + 'event_espresso' |
|
| 2111 | + ), |
|
| 2112 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | + ); |
|
| 2114 | + } else { |
|
| 2115 | + EE_Error::add_error( |
|
| 2116 | + esc_html__( |
|
| 2117 | + 'You do not have access to delete a payment.', |
|
| 2118 | + 'event_espresso' |
|
| 2119 | + ), |
|
| 2120 | + __FILE__, |
|
| 2121 | + __FUNCTION__, |
|
| 2122 | + __LINE__ |
|
| 2123 | + ); |
|
| 2124 | + } |
|
| 2125 | + } |
|
| 2126 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 2127 | + $this->_template_args = array( |
|
| 2128 | + 'data' => $json_response_data, |
|
| 2129 | + 'success' => $notices['success'], |
|
| 2130 | + 'error' => $notices['errors'], |
|
| 2131 | + 'attention' => $notices['attention'], |
|
| 2132 | + ); |
|
| 2133 | + $this->_return_json(); |
|
| 2134 | + } |
|
| 2135 | + |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * _registration_payment_data_array |
|
| 2139 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2140 | + * |
|
| 2141 | + * @access protected |
|
| 2142 | + * @param array $REG_IDs |
|
| 2143 | + * @return array |
|
| 2144 | + * @throws EE_Error |
|
| 2145 | + * @throws InvalidArgumentException |
|
| 2146 | + * @throws InvalidDataTypeException |
|
| 2147 | + * @throws InvalidInterfaceException |
|
| 2148 | + */ |
|
| 2149 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 2150 | + { |
|
| 2151 | + $registration_payment_data = array(); |
|
| 2152 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2153 | + if (! empty($REG_IDs)) { |
|
| 2154 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2155 | + foreach ($registrations as $registration) { |
|
| 2156 | + if ($registration instanceof EE_Registration) { |
|
| 2157 | + $registration_payment_data[$registration->ID()] = array( |
|
| 2158 | + 'paid' => $registration->pretty_paid(), |
|
| 2159 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2160 | + ); |
|
| 2161 | + } |
|
| 2162 | + } |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + return $registration_payment_data; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + |
|
| 2169 | + /** |
|
| 2170 | + * _maybe_send_notifications |
|
| 2171 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2172 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 2173 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2174 | + * |
|
| 2175 | + * @access protected |
|
| 2176 | + * @param \EE_Payment | null $payment |
|
| 2177 | + */ |
|
| 2178 | + protected function _maybe_send_notifications($payment = null) |
|
| 2179 | + { |
|
| 2180 | + switch ($payment instanceof EE_Payment) { |
|
| 2181 | + // payment notifications |
|
| 2182 | + case true : |
|
| 2183 | + if ( |
|
| 2184 | + isset( |
|
| 2185 | + $this->_req_data['txn_payments'], |
|
| 2186 | + $this->_req_data['txn_payments']['send_notifications'] |
|
| 2187 | + ) && |
|
| 2188 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2189 | + ) { |
|
| 2190 | + $this->_process_payment_notification($payment); |
|
| 2191 | + } |
|
| 2192 | + break; |
|
| 2193 | + // registration notifications |
|
| 2194 | + case false : |
|
| 2195 | + if ( |
|
| 2196 | + isset( |
|
| 2197 | + $this->_req_data['txn_reg_status_change'], |
|
| 2198 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 2199 | + ) && |
|
| 2200 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2201 | + ) { |
|
| 2202 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2203 | + } |
|
| 2204 | + break; |
|
| 2205 | + } |
|
| 2206 | + } |
|
| 2207 | + |
|
| 2208 | + |
|
| 2209 | + /** |
|
| 2210 | + * _send_payment_reminder |
|
| 2211 | + * generates HTML for the View Transaction Details Admin page |
|
| 2212 | + * |
|
| 2213 | + * @access protected |
|
| 2214 | + * @return void |
|
| 2215 | + * @throws EE_Error |
|
| 2216 | + * @throws InvalidArgumentException |
|
| 2217 | + * @throws InvalidDataTypeException |
|
| 2218 | + * @throws InvalidInterfaceException |
|
| 2219 | + */ |
|
| 2220 | + protected function _send_payment_reminder() |
|
| 2221 | + { |
|
| 2222 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2223 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2224 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2225 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2226 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2227 | + ) : array(); |
|
| 2228 | + do_action( |
|
| 2229 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2230 | + $transaction |
|
| 2231 | + ); |
|
| 2232 | + $this->_redirect_after_action( |
|
| 2233 | + false, |
|
| 2234 | + esc_html__('payment reminder', 'event_espresso'), |
|
| 2235 | + esc_html__('sent', 'event_espresso'), |
|
| 2236 | + $query_args, |
|
| 2237 | + true |
|
| 2238 | + ); |
|
| 2239 | + } |
|
| 2240 | + |
|
| 2241 | + |
|
| 2242 | + /** |
|
| 2243 | + * get_transactions |
|
| 2244 | + * get transactions for given parameters (used by list table) |
|
| 2245 | + * |
|
| 2246 | + * @param int $perpage how many transactions displayed per page |
|
| 2247 | + * @param boolean $count return the count or objects |
|
| 2248 | + * @param string $view |
|
| 2249 | + * @return mixed int = count || array of transaction objects |
|
| 2250 | + * @throws EE_Error |
|
| 2251 | + * @throws InvalidArgumentException |
|
| 2252 | + * @throws InvalidDataTypeException |
|
| 2253 | + * @throws InvalidInterfaceException |
|
| 2254 | + */ |
|
| 2255 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 2256 | + { |
|
| 2257 | + |
|
| 2258 | + $TXN = EEM_Transaction::instance(); |
|
| 2259 | + |
|
| 2260 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2261 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2262 | + : date( |
|
| 2263 | + 'm/d/Y', |
|
| 2264 | + strtotime('-10 year') |
|
| 2265 | + ); |
|
| 2266 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2267 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2268 | + : date('m/d/Y'); |
|
| 2269 | + |
|
| 2270 | + //make sure our timestamps start and end right at the boundaries for each day |
|
| 2271 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2272 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2273 | + |
|
| 2274 | + |
|
| 2275 | + //convert to timestamps |
|
| 2276 | + $start_date = strtotime($start_date); |
|
| 2277 | + $end_date = strtotime($end_date); |
|
| 2278 | + |
|
| 2279 | + //makes sure start date is the lowest value and vice versa |
|
| 2280 | + $start_date = min($start_date, $end_date); |
|
| 2281 | + $end_date = max($start_date, $end_date); |
|
| 2282 | + |
|
| 2283 | + //convert to correct format for query |
|
| 2284 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2285 | + 'TXN_timestamp', |
|
| 2286 | + date('Y-m-d H:i:s', $start_date), |
|
| 2287 | + 'Y-m-d H:i:s' |
|
| 2288 | + ); |
|
| 2289 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2290 | + 'TXN_timestamp', |
|
| 2291 | + date('Y-m-d H:i:s', $end_date), |
|
| 2292 | + 'Y-m-d H:i:s' |
|
| 2293 | + ); |
|
| 2294 | + |
|
| 2295 | + |
|
| 2296 | + //set orderby |
|
| 2297 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2298 | + |
|
| 2299 | + switch ($this->_req_data['orderby']) { |
|
| 2300 | + case 'TXN_ID': |
|
| 2301 | + $orderby = 'TXN_ID'; |
|
| 2302 | + break; |
|
| 2303 | + case 'ATT_fname': |
|
| 2304 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2305 | + break; |
|
| 2306 | + case 'event_name': |
|
| 2307 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 2308 | + break; |
|
| 2309 | + default: //'TXN_timestamp' |
|
| 2310 | + $orderby = 'TXN_timestamp'; |
|
| 2311 | + } |
|
| 2312 | + |
|
| 2313 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2314 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2315 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2316 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2317 | + |
|
| 2318 | + $offset = ($current_page - 1) * $per_page; |
|
| 2319 | + $limit = array($offset, $per_page); |
|
| 2320 | + |
|
| 2321 | + $_where = array( |
|
| 2322 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2323 | + 'Registration.REG_count' => 1, |
|
| 2324 | + ); |
|
| 2325 | + |
|
| 2326 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 2327 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2328 | + } |
|
| 2329 | + |
|
| 2330 | + if (isset($this->_req_data['s'])) { |
|
| 2331 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2332 | + $_where['OR'] = array( |
|
| 2333 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2334 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2335 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2336 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2337 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2338 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2339 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2340 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2341 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2342 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2343 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2344 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2345 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2346 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2347 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2348 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2349 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2350 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2351 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2352 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2353 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2354 | + ); |
|
| 2355 | + } |
|
| 2356 | + |
|
| 2357 | + //failed transactions |
|
| 2358 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2359 | + || ($count && $view === 'failed'); |
|
| 2360 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2361 | + || ($count && $view === 'abandoned'); |
|
| 2362 | + |
|
| 2363 | + if ($failed) { |
|
| 2364 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2365 | + } else if ($abandoned) { |
|
| 2366 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2367 | + } else { |
|
| 2368 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2369 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + $query_params = array( |
|
| 2373 | + $_where, |
|
| 2374 | + 'order_by' => array($orderby => $sort), |
|
| 2375 | + 'limit' => $limit, |
|
| 2376 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2377 | + ); |
|
| 2378 | + |
|
| 2379 | + $transactions = $count |
|
| 2380 | + ? $TXN->count(array($_where), 'TXN_ID', true) |
|
| 2381 | + : $TXN->get_all($query_params); |
|
| 2382 | + |
|
| 2383 | + return $transactions; |
|
| 2384 | + } |
|
| 2385 | 2385 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | <div id="payment-accntng-<?php echo $PAY_ID; ?>"><?php echo $payment->extra_accntng(); ?></div> |
| 160 | 160 | </td> |
| 161 | 161 | <td class=" jst-rght"> |
| 162 | - <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-' . $payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
| 162 | + <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-'.$payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
| 163 | 163 | <span class="<?php echo $payment_class; ?>"> |
| 164 | 164 | <div id="payment-amount-<?php echo $PAY_ID; ?>" |
| 165 | 165 | style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | <?php endforeach; // $payment?> |
| 174 | 174 | <?php |
| 175 | 175 | $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
| 176 | - $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
| 177 | - 'event_espresso') . '</span>' : ''; |
|
| 176 | + $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">'.esc_html__('This transaction has been overpaid ! ', |
|
| 177 | + 'event_espresso').'</span>' : ''; |
|
| 178 | 178 | ?> |
| 179 | 179 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
| 180 | 180 | <td class=" jst-rght" colspan="11"> |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | <tr id="txn-admin-payments-total-tr" |
| 185 | 185 | class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>"> |
| 186 | 186 | <th class=" jst-rght" colspan="10"><span |
| 187 | - id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s', |
|
| 187 | + id="payments-total-spn"><?php echo $overpaid.sprintf(esc_html__('Payments Total %s', |
|
| 188 | 188 | 'event_espresso'), |
| 189 | - '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
| 189 | + '('.EE_Registry::instance()->CFG->currency->code.')'); ?></span></th> |
|
| 190 | 190 | <th class=" jst-rght"><span |
| 191 | 191 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
| 192 | 192 | false, false); ?></span></th> |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | <h2 id="admin-modal-dialog-apply-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
| 300 | 300 | style="display:none;"> |
| 301 | 301 | <div class="ee-icon ee-icon-cash-add float-left"></div> |
| 302 | - <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 302 | + <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
| 303 | 303 | </h2> |
| 304 | 304 | |
| 305 | 305 | <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
| 329 | 329 | style="display:none;"> |
| 330 | 330 | <div class="ee-icon ee-icon-cash-remove float-left"></div> |
| 331 | - <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 331 | + <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
| 332 | 332 | </h2> |
| 333 | 333 | |
| 334 | 334 | <form name="txn-admin-apply-payment-frm" id="txn-admin-apply-payment-frm" |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | style="display:none;"> |
| 558 | 558 | <span class="ee-icon ee-icon-cash-add"></span> |
| 559 | 559 | <?php echo esc_html__('Delete Payment/Refund for Transaction #', |
| 560 | - 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 560 | + 'event_espresso').$txn_nmbr['value']; ?> |
|
| 561 | 561 | </h2> |
| 562 | 562 | |
| 563 | 563 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
| 644 | 644 | ?> |
| 645 | 645 | <tr> |
| 646 | - <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 646 | + <td class="jst-left"><?php echo date(get_option('date_format').' '.get_option('time_format'), |
|
| 647 | 647 | ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
| 648 | 648 | <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td> |
| 649 | 649 | <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td> |
@@ -191,10 +191,13 @@ discard block |
||
| 191 | 191 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
| 192 | 192 | false, false); ?></span></th> |
| 193 | 193 | </tr> |
| 194 | - <?php else : ?> |
|
| 194 | + <?php else { |
|
| 195 | + : ?> |
|
| 195 | 196 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
| 196 | 197 | <td class=" jst-rght" colspan="11"> |
| 197 | - <span class="important-notice"><?php echo $no_payment_text; ?></span> |
|
| 198 | + <span class="important-notice"><?php echo $no_payment_text; |
|
| 199 | +} |
|
| 200 | +?></span> |
|
| 198 | 201 | </td> |
| 199 | 202 | </tr> |
| 200 | 203 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
@@ -285,10 +288,13 @@ discard block |
||
| 285 | 288 | <?php esc_html_e('Apply Refund', 'event_espresso'); ?> |
| 286 | 289 | </a> |
| 287 | 290 | </li> |
| 288 | - <?php else : ?> |
|
| 291 | + <?php else { |
|
| 292 | + : ?> |
|
| 289 | 293 | <li> |
| 290 | 294 | <p><?php esc_html__('You do not have access to apply payments or refunds.', |
| 291 | - 'event_espresso'); ?></p> |
|
| 295 | + 'event_espresso'); |
|
| 296 | +} |
|
| 297 | +?></p> |
|
| 292 | 298 | </li> |
| 293 | 299 | <?php endif; ?> |
| 294 | 300 | </ul> |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | <a id="display-additional-transaction-session-info" class="display-the-hidden smaller-text" |
| 13 | 13 | rel="additional-transaction-session-info"> |
| 14 | 14 | <span class="dashicons dashicons-plus-alt"></span><?php esc_html_e('view additional transaction session details', |
| 15 | - 'event_espresso'); ?> |
|
| 15 | + 'event_espresso'); ?> |
|
| 16 | 16 | </a> |
| 17 | 17 | |
| 18 | 18 | <div id="additional-transaction-session-info-dv" class="hidden"> |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | <a id="hide-additional-transaction-session-info" class="hide-the-displayed hidden smaller-text" |
| 21 | 21 | rel="additional-transaction-session-info"> |
| 22 | 22 | <span class="dashicons dashicons-dismiss"></span><?php esc_html_e('hide additional transaction session details', |
| 23 | - 'event_espresso'); ?> |
|
| 23 | + 'event_espresso'); ?> |
|
| 24 | 24 | </a> |
| 25 | 25 | <br class="clear"/> |
| 26 | 26 | |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | <?php if ($attendee instanceof EE_Attendee && ($grand_raw_total > 0 || $TXN_status !== EEM_Transaction::complete_status_code || ! empty($payments))) : |
| 48 | - $no_payment_text = $can_edit_payments |
|
| 49 | - ? esc_html__( |
|
| 50 | - 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 51 | - 'event_espresso' |
|
| 52 | - ) |
|
| 53 | - : esc_html__( |
|
| 54 | - 'No payments have been applied to this transaction yet.', |
|
| 55 | - 'event_espresso' |
|
| 56 | - ); |
|
| 57 | - ?> |
|
| 48 | + $no_payment_text = $can_edit_payments |
|
| 49 | + ? esc_html__( |
|
| 50 | + 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 51 | + 'event_espresso' |
|
| 52 | + ) |
|
| 53 | + : esc_html__( |
|
| 54 | + 'No payments have been applied to this transaction yet.', |
|
| 55 | + 'event_espresso' |
|
| 56 | + ); |
|
| 57 | + ?> |
|
| 58 | 58 | |
| 59 | 59 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
| 60 | 60 | <span class="ee-icon ee-icon-cash"></span><?php esc_html_e('Payment Details', 'event_espresso'); ?> |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | <?php if ($payments) : ?> |
| 83 | 83 | <?php $payment_total = 0; ?> |
| 84 | 84 | <?php foreach ($payments as $PAY_ID => $payment) : |
| 85 | - $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID]) |
|
| 86 | - ? wp_json_encode($existing_reg_payments[$PAY_ID]) |
|
| 87 | - : '{}'; |
|
| 88 | - ?> |
|
| 85 | + $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID]) |
|
| 86 | + ? wp_json_encode($existing_reg_payments[$PAY_ID]) |
|
| 87 | + : '{}'; |
|
| 88 | + ?> |
|
| 89 | 89 | <tr id="txn-admin-payment-tr-<?php echo $PAY_ID; ?>"> |
| 90 | 90 | <td> |
| 91 | 91 | <span id="payment-status-<?php echo $PAY_ID; ?>" |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | <td class=" jst-left"> |
| 133 | 133 | <div id="payment-gateway-<?php echo $PAY_ID; ?>"> |
| 134 | 134 | <?php echo $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
| 135 | - 'event_espresso'); ?> |
|
| 135 | + 'event_espresso'); ?> |
|
| 136 | 136 | </div> |
| 137 | 137 | <div id="payment-gateway-id-<?php echo $PAY_ID; ?>" |
| 138 | 138 | class="hidden"><?php echo $payment->payment_method() ? $payment->payment_method()->ID() : 0; ?></div> |
@@ -154,19 +154,19 @@ discard block |
||
| 154 | 154 | <span class="<?php echo $payment_class; ?>"> |
| 155 | 155 | <div id="payment-amount-<?php echo $PAY_ID; ?>" |
| 156 | 156 | style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), |
| 157 | - false, false); ?></div> |
|
| 157 | + false, false); ?></div> |
|
| 158 | 158 | </span> |
| 159 | 159 | </td> |
| 160 | 160 | </tr> |
| 161 | 161 | <?php |
| 162 | - $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
| 163 | - ?> |
|
| 162 | + $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
| 163 | + ?> |
|
| 164 | 164 | <?php endforeach; // $payment?> |
| 165 | 165 | <?php |
| 166 | - $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
| 167 | - $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
| 168 | - 'event_espresso') . '</span>' : ''; |
|
| 169 | - ?> |
|
| 166 | + $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
| 167 | + $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
| 168 | + 'event_espresso') . '</span>' : ''; |
|
| 169 | + ?> |
|
| 170 | 170 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
| 171 | 171 | <td class=" jst-rght" colspan="11"> |
| 172 | 172 | <span class="important-notice"><?php echo $no_payment_text; ?></span> |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>"> |
| 177 | 177 | <th class=" jst-rght" colspan="10"><span |
| 178 | 178 | id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s', |
| 179 | - 'event_espresso'), |
|
| 180 | - '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
| 179 | + 'event_espresso'), |
|
| 180 | + '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
| 181 | 181 | <th class=" jst-rght"><span |
| 182 | 182 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
| 183 | - false, false); ?></span></th> |
|
| 183 | + false, false); ?></span></th> |
|
| 184 | 184 | </tr> |
| 185 | 185 | <?php else : ?> |
| 186 | 186 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
| 192 | 192 | <th class=" jst-rght" colspan="10"><span |
| 193 | 193 | id="payments-total-spn"><?php echo esc_html__('Payments Total', |
| 194 | - 'event_espresso'); ?></span></th> |
|
| 194 | + 'event_espresso'); ?></span></th> |
|
| 195 | 195 | <th class=" jst-rght"><span id="txn-admin-payment-total"></span></th> |
| 196 | 196 | </tr> |
| 197 | 197 | <?php endif; // $payments |
| 198 | - ?> |
|
| 198 | + ?> |
|
| 199 | 199 | |
| 200 | 200 | <tr id="txn-admin-payment-empty-row-tr" class="hidden"> |
| 201 | 201 | <td> |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | <ul id="txn-admin-payment-options-ul"> |
| 262 | 262 | <?php if ($can_edit_payments) : |
| 263 | - ?> |
|
| 263 | + ?> |
|
| 264 | 264 | <li> |
| 265 | 265 | <a id="display-txn-admin-apply-payment" class="button-primary no-icon no-hide" |
| 266 | 266 | rel="txn-admin-apply-payment"> <!--display-the-hidden --> |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | <?php else : ?> |
| 277 | 277 | <li> |
| 278 | 278 | <p><?php esc_html__('You do not have access to apply payments or refunds.', |
| 279 | - 'event_espresso'); ?></p> |
|
| 279 | + 'event_espresso'); ?></p> |
|
| 280 | 280 | </li> |
| 281 | 281 | <?php endif; ?> |
| 282 | 282 | </ul> |
@@ -294,23 +294,23 @@ discard block |
||
| 294 | 294 | style="display:none;"> |
| 295 | 295 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
| 296 | 296 | <?php |
| 297 | - echo sprintf( |
|
| 298 | - __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 299 | - '<span></span>', |
|
| 300 | - $txn_nmbr['value'] |
|
| 301 | - ); |
|
| 302 | - ?> |
|
| 297 | + echo sprintf( |
|
| 298 | + __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 299 | + '<span></span>', |
|
| 300 | + $txn_nmbr['value'] |
|
| 301 | + ); |
|
| 302 | + ?> |
|
| 303 | 303 | </h2> |
| 304 | 304 | |
| 305 | 305 | <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
| 306 | 306 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
| 307 | 307 | <?php |
| 308 | - echo sprintf( |
|
| 309 | - __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 310 | - '<span></span>', |
|
| 311 | - $txn_nmbr['value'] |
|
| 312 | - ); |
|
| 313 | - ?> |
|
| 308 | + echo sprintf( |
|
| 309 | + __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 310 | + '<span></span>', |
|
| 311 | + $txn_nmbr['value'] |
|
| 312 | + ); |
|
| 313 | + ?> |
|
| 314 | 314 | </h2> |
| 315 | 315 | |
| 316 | 316 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -343,55 +343,55 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | <div class="txn-admin-apply-payment-date-dv admin-modal-dialog-row"> |
| 345 | 345 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
| 346 | - 'event_espresso'); ?></div> |
|
| 346 | + 'event_espresso'); ?></div> |
|
| 347 | 347 | <label for="txn-admin-payment-date-inp" class=""><?php esc_html_e('Payment Date', |
| 348 | - 'event_espresso'); ?></label> |
|
| 348 | + 'event_espresso'); ?></label> |
|
| 349 | 349 | <input name="txn_admin_payment[date]" id="txn-admin-payment-date-inp" |
| 350 | 350 | class="txn-admin-apply-payment-inp required" type="text" |
| 351 | 351 | value="<?php echo date('Y-m-d g:i a', current_time('timestamp')); ?>"/> |
| 352 | 352 | <p class="description"><?php esc_html_e('The date the payment was actually made on', |
| 353 | - 'event_espresso'); ?></p> |
|
| 353 | + 'event_espresso'); ?></p> |
|
| 354 | 354 | </div> |
| 355 | 355 | |
| 356 | 356 | <div class="txn-admin-apply-payment-amount-dv admin-modal-dialog-row"> |
| 357 | 357 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
| 358 | - 'event_espresso'); ?></div> |
|
| 358 | + 'event_espresso'); ?></div> |
|
| 359 | 359 | <label for="txn-admin-payment-amount-inp" class=""><?php esc_html_e('Amount', |
| 360 | - 'event_espresso'); ?></label> |
|
| 360 | + 'event_espresso'); ?></label> |
|
| 361 | 361 | <input name="txn_admin_payment[amount]" id="txn-admin-payment-amount-inp" |
| 362 | 362 | class="txn-admin-apply-payment-inp required" type="text" value=""/> |
| 363 | 363 | <p class="description"><?php esc_html_e('The amount of the payment', |
| 364 | - 'event_espresso'); ?></p> |
|
| 364 | + 'event_espresso'); ?></p> |
|
| 365 | 365 | </div> |
| 366 | 366 | |
| 367 | 367 | <div class="txn-admin-apply-payment-method-dv admin-modal-dialog-row"> |
| 368 | 368 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
| 369 | - 'event_espresso'); ?></div> |
|
| 369 | + 'event_espresso'); ?></div> |
|
| 370 | 370 | <label for="txn-admin-payment-method-inp" class=""><?php esc_html_e('Method of Payment', |
| 371 | - 'event_espresso'); ?></label> |
|
| 371 | + 'event_espresso'); ?></label> |
|
| 372 | 372 | <select name="txn_admin_payment[PMD_ID]" id="txn-admin-payment-method-slct" |
| 373 | 373 | class="txn-admin-apply-payment-slct required" type="text"> |
| 374 | 374 | <?php foreach ($payment_methods as $method) : ?> |
| 375 | 375 | <?php $selected = $method->slug() == 'cash' ? ' selected="selected"' : ''; ?> |
| 376 | 376 | <option id="payment-method-opt-<?php echo $method->slug(); ?>" |
| 377 | 377 | value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>><?php echo sanitize_key($method->admin_desc()) ? substr($method->admin_desc(), |
| 378 | - 0, 128) : $method->admin_name(); ?> |
|
| 378 | + 0, 128) : $method->admin_name(); ?> |
|
| 379 | 379 | </option> |
| 380 | 380 | <?php endforeach; ?> |
| 381 | 381 | </select> |
| 382 | 382 | <p class="description"><?php esc_html_e('Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
| 383 | - 'event_espresso'); ?></p> |
|
| 383 | + 'event_espresso'); ?></p> |
|
| 384 | 384 | </div> |
| 385 | 385 | |
| 386 | 386 | <div class="mop-PP mop-CC mop-CHQ mop"> |
| 387 | 387 | <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row"> |
| 388 | 388 | <label for="txn-admin-payment-txn-id-inp" class=""><?php esc_html_e('TXN ID / CHQ #', |
| 389 | - 'event_espresso'); ?></label> |
|
| 389 | + 'event_espresso'); ?></label> |
|
| 390 | 390 | <input name="txn_admin_payment[txn_id_chq_nmbr]" |
| 391 | 391 | id="txn-admin-payment-txn-id-chq-nmbr-inp" class="txn-admin-apply-payment-inp" |
| 392 | 392 | type="text" maxlength="100"/> |
| 393 | 393 | <p class="description"><?php esc_html_e('The Transaction ID sent back from the payment gateway, or the Cheque #', |
| 394 | - 'event_espresso'); ?></p> |
|
| 394 | + 'event_espresso'); ?></p> |
|
| 395 | 395 | </div> |
| 396 | 396 | </div> |
| 397 | 397 | |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | id="txn-admin-payment-gateway-response-inp" class="txn-admin-apply-payment-inp" |
| 404 | 404 | type="text"/> |
| 405 | 405 | <p class="description"><?php esc_html_e('The gateway response string (optional)', |
| 406 | - 'event_espresso'); ?></p> |
|
| 406 | + 'event_espresso'); ?></p> |
|
| 407 | 407 | </div> |
| 408 | 408 | </div> |
| 409 | 409 | |
| 410 | 410 | <div class="mop-PP mop-CC mop"> |
| 411 | 411 | <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row"> |
| 412 | 412 | <label for="txn-admin-payment-status-inp" class=""><?php esc_html_e('Payment Status', |
| 413 | - 'event_espresso'); ?></label> |
|
| 413 | + 'event_espresso'); ?></label> |
|
| 414 | 414 | <select name="txn_admin_payment[status]" id="txn-admin-payment-status-slct" |
| 415 | 415 | class="txn-admin-apply-payment-slct" type="text"> |
| 416 | 416 | <?php foreach ($payment_status as $STS_ID => $STS_code) : ?> |
@@ -422,35 +422,35 @@ discard block |
||
| 422 | 422 | <?php endforeach; ?> |
| 423 | 423 | </select> |
| 424 | 424 | <p class="description"><?php esc_html_e('Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
| 425 | - 'event_espresso'); ?></p> |
|
| 425 | + 'event_espresso'); ?></p> |
|
| 426 | 426 | </div> |
| 427 | 427 | </div> |
| 428 | 428 | |
| 429 | 429 | <div class="txn-admin-apply-payment-po-nmbr-dv admin-modal-dialog-row"> |
| 430 | 430 | <label for="txn-admin-payment-po-nmbr-inp" class=""><?php esc_html_e('P.O. / S.O. #', |
| 431 | - 'event_espresso'); ?></label> |
|
| 431 | + 'event_espresso'); ?></label> |
|
| 432 | 432 | <input name="txn_admin_payment[po_number]" id="txn-admin-payment-po-nmbr-inp" |
| 433 | 433 | class="txn-admin-apply-payment-inp" type="text" maxlength="100"/> |
| 434 | 434 | <p class="description"><?php esc_html_e('The Purchase or Sales Order Number if any (optional)', |
| 435 | - 'event_espresso'); ?></p> |
|
| 435 | + 'event_espresso'); ?></p> |
|
| 436 | 436 | </div> |
| 437 | 437 | |
| 438 | 438 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
| 439 | 439 | <label for="txn-admin-payment-accounting-inp" |
| 440 | 440 | class="last"><?php esc_html_e('Notes / Extra Accounting', |
| 441 | - 'event_espresso'); ?></label> |
|
| 441 | + 'event_espresso'); ?></label> |
|
| 442 | 442 | <input name="txn_admin_payment[accounting]" id="txn-admin-payment-accounting-inp" |
| 443 | 443 | class="txn-admin-apply-payment-inp" type="text" value="<?php echo $REG_code; ?>" |
| 444 | 444 | maxlength="100"/> <input type="hidden" id="txn-admin-reg-code-inp" |
| 445 | 445 | value="<?php echo $REG_code; ?>"/> |
| 446 | 446 | <p class="description"><?php esc_html_e('An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
| 447 | - 'event_espresso'); ?></p> |
|
| 447 | + 'event_espresso'); ?></p> |
|
| 448 | 448 | </div> |
| 449 | 449 | |
| 450 | 450 | <div class="txn-admin-apply-payment-registrations-dv admin-modal-dialog-row"> |
| 451 | 451 | <label for="txn-admin-payment-registrations-inp" |
| 452 | 452 | class="last"><?php esc_html_e('Registrations to Apply Payment to:', |
| 453 | - 'event_espresso'); ?></label> |
|
| 453 | + 'event_espresso'); ?></label> |
|
| 454 | 454 | <label class="txn-admin-apply-payment-to-registrations-lbl"> |
| 455 | 455 | <input type="radio" value="1" id="txn-admin-apply-payment-to-all-registrations-inp" |
| 456 | 456 | name="txn_admin_payment[apply_to_all_registrations]" checked="checked"/> |
@@ -467,10 +467,10 @@ discard block |
||
| 467 | 467 | <div class="txn-admin-payment-reg-status-dv admin-modal-dialog-row"> |
| 468 | 468 | <label for="txn-admin-payment-reg-status-inp" |
| 469 | 469 | class="last"><?php esc_html_e('Change Registration Status?', |
| 470 | - 'event_espresso'); ?></label> |
|
| 470 | + 'event_espresso'); ?></label> |
|
| 471 | 471 | <?php echo $status_change_select; ?> |
| 472 | 472 | <p class="description"><?php esc_html_e('If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
| 473 | - 'event_espresso'); ?></p> |
|
| 473 | + 'event_espresso'); ?></p> |
|
| 474 | 474 | <br/> |
| 475 | 475 | </div> |
| 476 | 476 | |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | </label> |
| 491 | 491 | <br class="clear-float"/> |
| 492 | 492 | <p class="description"><?php printf(esc_html__('By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', |
| 493 | - 'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p> |
|
| 493 | + 'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p> |
|
| 494 | 494 | <label></label> |
| 495 | 495 | </div> |
| 496 | 496 | <div class="clear"></div> |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | </li> |
| 531 | 531 | <li> |
| 532 | 532 | <span id="ee-ajax-processing-text" style="display:none;"><?php esc_html_e('Processing...', |
| 533 | - 'event_espresso'); ?></span> |
|
| 533 | + 'event_espresso'); ?></span> |
|
| 534 | 534 | </li> |
| 535 | 535 | </ul> |
| 536 | 536 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | style="display:none;"> |
| 546 | 546 | <span class="ee-icon ee-icon-cash-add"></span> |
| 547 | 547 | <?php echo esc_html__('Delete Payment/Refund for Transaction #', |
| 548 | - 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 548 | + 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 549 | 549 | </h2> |
| 550 | 550 | |
| 551 | 551 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" |
@@ -566,10 +566,10 @@ discard block |
||
| 566 | 566 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
| 567 | 567 | <label for="delete-txn-admin-payment-reg-status-inp" |
| 568 | 568 | class="last"><?php esc_html_e('Change Registration Status?', |
| 569 | - 'event_espresso'); ?></label> |
|
| 569 | + 'event_espresso'); ?></label> |
|
| 570 | 570 | <?php echo $delete_status_change_select; ?> |
| 571 | 571 | <p class="description"><?php printf(esc_html__('If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', |
| 572 | - 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
| 572 | + 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
| 573 | 573 | </div> |
| 574 | 574 | |
| 575 | 575 | <div class="ee-attention txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | class="last"><?php esc_html_e('Send Related Messages?', 'event_espresso'); ?></label> |
| 578 | 578 | <input type="checkbox" value="1" name="delete_txn_reg_status_change[send_notifications]"> |
| 579 | 579 | <p class="description"><?php esc_html_e('If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', |
| 580 | - 'event_espresso'); ?></p> |
|
| 580 | + 'event_espresso'); ?></p> |
|
| 581 | 581 | </div> |
| 582 | 582 | <div class="clear"></div> |
| 583 | 583 | |
@@ -609,13 +609,13 @@ discard block |
||
| 609 | 609 | <?php endif; // $grand_raw_total > 0?> |
| 610 | 610 | |
| 611 | 611 | <?php |
| 612 | - if (WP_DEBUG) { |
|
| 613 | - $delivered_messages = get_option('EED_Messages__payment', array()); |
|
| 614 | - if (isset($delivered_messages[$TXN_ID])) { |
|
| 615 | - ?> |
|
| 612 | + if (WP_DEBUG) { |
|
| 613 | + $delivered_messages = get_option('EED_Messages__payment', array()); |
|
| 614 | + if (isset($delivered_messages[$TXN_ID])) { |
|
| 615 | + ?> |
|
| 616 | 616 | <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span |
| 617 | 617 | class="dashicons dashicons-email-alt"></span><?php esc_html_e('Messages Sent to Primary Registrant', |
| 618 | - 'event_espresso'); ?></h4> |
|
| 618 | + 'event_espresso'); ?></h4> |
|
| 619 | 619 | |
| 620 | 620 | <div class="admin-primary-mbox-tbl-wrap"> |
| 621 | 621 | <table class="admin-primary-mbox-tbl"> |
@@ -629,10 +629,10 @@ discard block |
||
| 629 | 629 | </thead> |
| 630 | 630 | <tbody> |
| 631 | 631 | <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
| 632 | - ?> |
|
| 632 | + ?> |
|
| 633 | 633 | <tr> |
| 634 | 634 | <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'), |
| 635 | - ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
|
| 635 | + ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
|
| 636 | 636 | <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td> |
| 637 | 637 | <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td> |
| 638 | 638 | <td class="jst-left"><?php echo isset($delivered_message['txn_status']) ? $delivered_message['txn_status'] : ''; ?></td> |
@@ -642,9 +642,9 @@ discard block |
||
| 642 | 642 | </table> |
| 643 | 643 | </div> |
| 644 | 644 | <?php |
| 645 | - } |
|
| 646 | - } |
|
| 647 | - ?> |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + ?> |
|
| 648 | 648 | |
| 649 | 649 | |
| 650 | 650 | </div> |
@@ -22,744 +22,744 @@ |
||
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return EED_Module|EED_Add_New_State |
|
| 27 | - */ |
|
| 28 | - public static function instance() |
|
| 29 | - { |
|
| 30 | - return parent::get_instance(__CLASS__); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public static function set_hooks() |
|
| 41 | - { |
|
| 42 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public static function set_hooks_admin() |
|
| 69 | - { |
|
| 70 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public static function set_definitions() |
|
| 101 | - { |
|
| 102 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | - '\\', |
|
| 105 | - DS, |
|
| 106 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @param WP $WP |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function run($WP) |
|
| 117 | - { |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public static function translate_js_strings() |
|
| 126 | - { |
|
| 127 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | - 'event_espresso' |
|
| 130 | - ); |
|
| 131 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | - 'event_espresso' |
|
| 134 | - ); |
|
| 135 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | - 'event_espresso' |
|
| 138 | - ); |
|
| 139 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | - 'The new state was successfully saved to the database.', |
|
| 141 | - 'event_espresso' |
|
| 142 | - ); |
|
| 143 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | - 'event_espresso' |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return void |
|
| 153 | - */ |
|
| 154 | - public static function wp_enqueue_scripts() |
|
| 155 | - { |
|
| 156 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | - wp_enqueue_script('add_new_state'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * display_add_new_state_micro_form |
|
| 167 | - * |
|
| 168 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | - * @return string |
|
| 170 | - * @throws EE_Error |
|
| 171 | - * @throws InvalidArgumentException |
|
| 172 | - * @throws InvalidDataTypeException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - */ |
|
| 175 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | - { |
|
| 178 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | - // is the "state" question in this form section? |
|
| 182 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | - //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | - if ($input instanceof EE_State_Select_Input) { |
|
| 187 | - $input->html_name(); |
|
| 188 | - } |
|
| 189 | - return $question_group_reg_form; |
|
| 190 | - } |
|
| 191 | - // we're only doing this for state select inputs |
|
| 192 | - if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | - // grab any set values from the request |
|
| 194 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | - $country_options = array(); |
|
| 199 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | - if (! empty($countries)) { |
|
| 201 | - foreach ($countries as $country) { |
|
| 202 | - if ($country instanceof EE_Country) { |
|
| 203 | - $country_options[$country->ID()] = $country->name(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | - array( |
|
| 209 | - 'name' => 'new_state_micro_form', |
|
| 210 | - 'html_id' => 'new_state_micro_form', |
|
| 211 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | - 'subsections' => array( |
|
| 213 | - // add hidden input to indicate that a new state is being added |
|
| 214 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | - array( |
|
| 216 | - 'html_name' => str_replace( |
|
| 217 | - 'state', |
|
| 218 | - 'nsmf_add_new_state', |
|
| 219 | - $input->html_name() |
|
| 220 | - ), |
|
| 221 | - 'html_id' => str_replace( |
|
| 222 | - 'state', |
|
| 223 | - 'nsmf_add_new_state', |
|
| 224 | - $input->html_id() |
|
| 225 | - ), |
|
| 226 | - 'default' => 0, |
|
| 227 | - ) |
|
| 228 | - ), |
|
| 229 | - // add link for displaying hidden container |
|
| 230 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | - apply_filters( |
|
| 232 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | - EEH_HTML::link( |
|
| 234 | - '', |
|
| 235 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | - '', |
|
| 237 | - 'display-' . $input->html_id(), |
|
| 238 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | - '', |
|
| 240 | - 'data-target="' . $input->html_id() . '"' |
|
| 241 | - ) |
|
| 242 | - ) |
|
| 243 | - ), |
|
| 244 | - // add initial html for hidden container |
|
| 245 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | - apply_filters( |
|
| 247 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | - 'display: none;') . |
|
| 250 | - EEH_HTML::h6( |
|
| 251 | - esc_html__( |
|
| 252 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | - 'event_espresso' |
|
| 254 | - ) |
|
| 255 | - ) . |
|
| 256 | - EEH_HTML::ul() . |
|
| 257 | - EEH_HTML::li( |
|
| 258 | - esc_html__( |
|
| 259 | - 'first select the Country that your State/Province belongs to', |
|
| 260 | - 'event_espresso' |
|
| 261 | - ) |
|
| 262 | - ) . |
|
| 263 | - EEH_HTML::li( |
|
| 264 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | - ) . |
|
| 266 | - EEH_HTML::li( |
|
| 267 | - esc_html__( |
|
| 268 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ) |
|
| 271 | - ) . |
|
| 272 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | - EEH_HTML::ulx() |
|
| 274 | - ) |
|
| 275 | - ), |
|
| 276 | - // NEW STATE COUNTRY |
|
| 277 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | - $country_options, |
|
| 279 | - array( |
|
| 280 | - 'html_name' => $country_name, |
|
| 281 | - 'html_id' => str_replace( |
|
| 282 | - 'state', |
|
| 283 | - 'nsmf_new_state_country', $input->html_id() |
|
| 284 | - ), |
|
| 285 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | - 'required' => false, |
|
| 289 | - ) |
|
| 290 | - ), |
|
| 291 | - // NEW STATE NAME |
|
| 292 | - 'new_state_name' => new EE_Text_Input( |
|
| 293 | - array( |
|
| 294 | - 'html_name' => $state_name, |
|
| 295 | - 'html_id' => str_replace( |
|
| 296 | - 'state', |
|
| 297 | - 'nsmf_new_state_name', $input->html_id() |
|
| 298 | - ), |
|
| 299 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | - 'event_espresso'), |
|
| 302 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | - 'required' => false, |
|
| 304 | - ) |
|
| 305 | - ), |
|
| 306 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | - // NEW STATE NAME |
|
| 308 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | - array( |
|
| 310 | - 'html_name' => $abbrv_name, |
|
| 311 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | - $input->html_id()), |
|
| 313 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | - 'html_label_text' => esc_html__( |
|
| 315 | - 'New State/Province Abbreviation', |
|
| 316 | - 'event_espresso' |
|
| 317 | - ) . ' *', |
|
| 318 | - 'html_other_attributes' => 'size="24"', |
|
| 319 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | - 'required' => false, |
|
| 321 | - ) |
|
| 322 | - ), |
|
| 323 | - // "submit" button |
|
| 324 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | - apply_filters( |
|
| 326 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | - EEH_HTML::nbsp(3) . |
|
| 328 | - EEH_HTML::link( |
|
| 329 | - '', |
|
| 330 | - esc_html__('ADD', 'event_espresso'), |
|
| 331 | - '', |
|
| 332 | - 'submit-' . $new_state_submit_id, |
|
| 333 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | - '', |
|
| 335 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | - ) |
|
| 337 | - ) |
|
| 338 | - ), |
|
| 339 | - // extra info |
|
| 340 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | - apply_filters( |
|
| 342 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | - EEH_HTML::br(2) |
|
| 344 | - . |
|
| 345 | - EEH_HTML::div('', '', 'small-text') |
|
| 346 | - . |
|
| 347 | - EEH_HTML::strong( |
|
| 348 | - '* ' . |
|
| 349 | - esc_html__( |
|
| 350 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | - 'event_espresso' |
|
| 352 | - ) |
|
| 353 | - ) |
|
| 354 | - . |
|
| 355 | - EEH_HTML::br() |
|
| 356 | - . |
|
| 357 | - sprintf( |
|
| 358 | - esc_html__( |
|
| 359 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | - 'event_espresso' |
|
| 361 | - ), |
|
| 362 | - EEH_HTML::link( |
|
| 363 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | - '', |
|
| 366 | - '', |
|
| 367 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | - '', |
|
| 369 | - 'target="_blank"' |
|
| 370 | - ) |
|
| 371 | - ) |
|
| 372 | - . |
|
| 373 | - EEH_HTML::divx() |
|
| 374 | - . |
|
| 375 | - EEH_HTML::br() |
|
| 376 | - . |
|
| 377 | - EEH_HTML::link( |
|
| 378 | - '', |
|
| 379 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | - '', |
|
| 381 | - 'hide-' . $input->html_id(), |
|
| 382 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | - '', |
|
| 384 | - 'data-target="' . $input->html_id() . '"' |
|
| 385 | - ) |
|
| 386 | - . |
|
| 387 | - EEH_HTML::divx() |
|
| 388 | - . |
|
| 389 | - EEH_HTML::br() |
|
| 390 | - ) |
|
| 391 | - ), |
|
| 392 | - ), |
|
| 393 | - ) |
|
| 394 | - ); |
|
| 395 | - $question_group_reg_form->add_subsections( |
|
| 396 | - array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | - 'state', |
|
| 398 | - false |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - return $question_group_reg_form; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * set_new_state_input_width |
|
| 408 | - * |
|
| 409 | - * @return int|string |
|
| 410 | - * @throws EE_Error |
|
| 411 | - * @throws InvalidArgumentException |
|
| 412 | - * @throws InvalidDataTypeException |
|
| 413 | - * @throws InvalidInterfaceException |
|
| 414 | - * @throws ReflectionException |
|
| 415 | - */ |
|
| 416 | - public static function add_new_state() |
|
| 417 | - { |
|
| 418 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | - EE_Registry::instance()->load_model('State'); |
|
| 421 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | - : false; |
|
| 425 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | - : false; |
|
| 428 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | - : false; |
|
| 431 | - if ($state_country && $state_name && $state_abbr) { |
|
| 432 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | - 'STA_name' => ucwords($state_name), |
|
| 436 | - 'STA_active' => false, |
|
| 437 | - )); |
|
| 438 | - if ($new_state instanceof EE_State) { |
|
| 439 | - // clean house |
|
| 440 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | - // get any existing new states |
|
| 445 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | - 'nsmf_new_states' |
|
| 447 | - ); |
|
| 448 | - $new_states[$new_state->ID()] = $new_state; |
|
| 449 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | - array('nsmf_new_states' => $new_states) |
|
| 451 | - ); |
|
| 452 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | - echo wp_json_encode(array( |
|
| 454 | - 'success' => true, |
|
| 455 | - 'id' => $new_state->ID(), |
|
| 456 | - 'name' => $new_state->name(), |
|
| 457 | - 'abbrev' => $new_state->abbrev(), |
|
| 458 | - 'country_iso' => $new_state->country_iso(), |
|
| 459 | - 'country_name' => $new_state->country()->name(), |
|
| 460 | - )); |
|
| 461 | - exit(); |
|
| 462 | - } |
|
| 463 | - return $new_state->ID(); |
|
| 464 | - } |
|
| 465 | - } else { |
|
| 466 | - $error = esc_html__( |
|
| 467 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | - 'event_espresso' |
|
| 469 | - ); |
|
| 470 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | - echo wp_json_encode(array('error' => $error)); |
|
| 472 | - exit(); |
|
| 473 | - } |
|
| 474 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - return false; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * recursively drills down through request params to remove any that were added by this module |
|
| 484 | - * |
|
| 485 | - * @param array $request_params |
|
| 486 | - * @return array |
|
| 487 | - */ |
|
| 488 | - public static function filter_checkout_request_params($request_params) |
|
| 489 | - { |
|
| 490 | - foreach ($request_params as $form_section) { |
|
| 491 | - if (is_array($form_section)) { |
|
| 492 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $request_params; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param array $request_params |
|
| 503 | - * @return array |
|
| 504 | - */ |
|
| 505 | - public static function unset_new_state_request_params($request_params) |
|
| 506 | - { |
|
| 507 | - unset( |
|
| 508 | - $request_params['new_state_micro_form'], |
|
| 509 | - $request_params['new_state_micro_add_new_state'], |
|
| 510 | - $request_params['new_state_micro_new_state_country'], |
|
| 511 | - $request_params['new_state_micro_new_state_name'], |
|
| 512 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | - ); |
|
| 514 | - return $request_params; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * @param array $props_n_values |
|
| 521 | - * @return bool |
|
| 522 | - * @throws EE_Error |
|
| 523 | - * @throws InvalidArgumentException |
|
| 524 | - * @throws InvalidDataTypeException |
|
| 525 | - * @throws InvalidInterfaceException |
|
| 526 | - */ |
|
| 527 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | - { |
|
| 529 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | - if (! empty($existing_state)) { |
|
| 531 | - return array_pop($existing_state); |
|
| 532 | - } |
|
| 533 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | - if ($new_state instanceof EE_State) { |
|
| 535 | - $country_settings_url = add_query_arg( |
|
| 536 | - array( |
|
| 537 | - 'page' => 'espresso_general_settings', |
|
| 538 | - 'action' => 'country_settings', |
|
| 539 | - 'country' => $new_state->country_iso(), |
|
| 540 | - ), |
|
| 541 | - admin_url('admin.php') |
|
| 542 | - ); |
|
| 543 | - // if not non-ajax admin |
|
| 544 | - new PersistentAdminNotice( |
|
| 545 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | - sprintf( |
|
| 547 | - esc_html__( |
|
| 548 | - '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.', |
|
| 549 | - 'event_espresso' |
|
| 550 | - ), |
|
| 551 | - '<b>' . $new_state->name() . '</b>', |
|
| 552 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | - '<a href="' |
|
| 555 | - . $country_settings_url |
|
| 556 | - . '">' |
|
| 557 | - . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | - 'event_espresso') |
|
| 559 | - . '</a>', |
|
| 560 | - '<br />' |
|
| 561 | - ) |
|
| 562 | - ); |
|
| 563 | - $new_state->save(); |
|
| 564 | - EEM_State::instance()->reset_cached_states(); |
|
| 565 | - return $new_state; |
|
| 566 | - } |
|
| 567 | - return false; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @param string $CNT_ISO |
|
| 574 | - * @param string $STA_ID |
|
| 575 | - * @param array $cols_n_values |
|
| 576 | - * @return void |
|
| 577 | - * @throws DomainException |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws InvalidArgumentException |
|
| 580 | - * @throws InvalidDataTypeException |
|
| 581 | - * @throws InvalidInterfaceException |
|
| 582 | - */ |
|
| 583 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | - { |
|
| 585 | - if (! $CNT_ISO) { |
|
| 586 | - EE_Error::add_error( |
|
| 587 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | - __FILE__, |
|
| 589 | - __FUNCTION__, |
|
| 590 | - __LINE__ |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | - : false; |
|
| 595 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | - if ($state instanceof EE_State) { |
|
| 598 | - $STA_abbrev = $state->abbrev(); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - if (! $STA_abbrev) { |
|
| 602 | - EE_Error::add_error( |
|
| 603 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | - __FILE__, |
|
| 605 | - __FUNCTION__, |
|
| 606 | - __LINE__ |
|
| 607 | - ); |
|
| 608 | - } |
|
| 609 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | - ); |
|
| 613 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @param EE_State[] $state_options |
|
| 620 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | - * @param EE_Registration $registration |
|
| 622 | - * @param EE_Question $question |
|
| 623 | - * @param $answer |
|
| 624 | - * @return array |
|
| 625 | - * @throws EE_Error |
|
| 626 | - * @throws InvalidArgumentException |
|
| 627 | - * @throws InvalidDataTypeException |
|
| 628 | - * @throws InvalidInterfaceException |
|
| 629 | - */ |
|
| 630 | - public static function inject_new_reg_state_into_options( |
|
| 631 | - $state_options = array(), |
|
| 632 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | - EE_Registration $registration, |
|
| 634 | - EE_Question $question, |
|
| 635 | - $answer |
|
| 636 | - ) { |
|
| 637 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | - && $question->type() === EEM_Question::QST_type_state |
|
| 639 | - ) { |
|
| 640 | - $STA_ID = $answer->value(); |
|
| 641 | - if (! empty($STA_ID)) { |
|
| 642 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | - if ($state instanceof EE_State) { |
|
| 644 | - $country = $state->country(); |
|
| 645 | - if ($country instanceof EE_Country) { |
|
| 646 | - if (! isset($state_options[$country->name()])) { |
|
| 647 | - $state_options[$country->name()] = array(); |
|
| 648 | - } |
|
| 649 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - return $state_options; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param EE_Country[] $country_options |
|
| 663 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | - * @param EE_Registration $registration |
|
| 665 | - * @param EE_Question $question |
|
| 666 | - * @param $answer |
|
| 667 | - * @return array |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws InvalidArgumentException |
|
| 670 | - * @throws InvalidDataTypeException |
|
| 671 | - * @throws InvalidInterfaceException |
|
| 672 | - */ |
|
| 673 | - public static function inject_new_reg_country_into_options( |
|
| 674 | - $country_options = array(), |
|
| 675 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | - EE_Registration $registration, |
|
| 677 | - EE_Question $question, |
|
| 678 | - $answer |
|
| 679 | - ) { |
|
| 680 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | - && $question->type() |
|
| 682 | - === EEM_Question::QST_type_country |
|
| 683 | - ) { |
|
| 684 | - $CNT_ISO = $answer->value(); |
|
| 685 | - if (! empty($CNT_ISO)) { |
|
| 686 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | - if ($country instanceof EE_Country) { |
|
| 688 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | - $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - return $country_options; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * @param EE_State[] $state_options |
|
| 701 | - * @return array |
|
| 702 | - * @throws EE_Error |
|
| 703 | - * @throws InvalidArgumentException |
|
| 704 | - * @throws InvalidDataTypeException |
|
| 705 | - * @throws InvalidInterfaceException |
|
| 706 | - */ |
|
| 707 | - public static function state_options($state_options = array()) |
|
| 708 | - { |
|
| 709 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | - foreach ($new_states as $new_state) { |
|
| 711 | - if ( |
|
| 712 | - $new_state instanceof EE_State |
|
| 713 | - && $new_state->country() instanceof EE_Country |
|
| 714 | - ) { |
|
| 715 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - return $state_options; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * @return array |
|
| 725 | - * @throws InvalidArgumentException |
|
| 726 | - * @throws InvalidDataTypeException |
|
| 727 | - * @throws InvalidInterfaceException |
|
| 728 | - */ |
|
| 729 | - protected static function _get_new_states() |
|
| 730 | - { |
|
| 731 | - $new_states = array(); |
|
| 732 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | - 'nsmf_new_states' |
|
| 735 | - ); |
|
| 736 | - } |
|
| 737 | - return is_array($new_states) ? $new_states : array(); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * @param EE_Country[] $country_options |
|
| 744 | - * @return array |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @throws InvalidArgumentException |
|
| 747 | - * @throws InvalidDataTypeException |
|
| 748 | - * @throws InvalidInterfaceException |
|
| 749 | - */ |
|
| 750 | - public static function country_options($country_options = array()) |
|
| 751 | - { |
|
| 752 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | - foreach ($new_states as $new_state) { |
|
| 754 | - if ( |
|
| 755 | - $new_state instanceof EE_State |
|
| 756 | - && $new_state->country() instanceof EE_Country |
|
| 757 | - ) { |
|
| 758 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - return $country_options; |
|
| 762 | - } |
|
| 25 | + /** |
|
| 26 | + * @return EED_Module|EED_Add_New_State |
|
| 27 | + */ |
|
| 28 | + public static function instance() |
|
| 29 | + { |
|
| 30 | + return parent::get_instance(__CLASS__); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public static function set_hooks() |
|
| 41 | + { |
|
| 42 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public static function set_hooks_admin() |
|
| 69 | + { |
|
| 70 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public static function set_definitions() |
|
| 101 | + { |
|
| 102 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | + '\\', |
|
| 105 | + DS, |
|
| 106 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @param WP $WP |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function run($WP) |
|
| 117 | + { |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public static function translate_js_strings() |
|
| 126 | + { |
|
| 127 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | + 'event_espresso' |
|
| 130 | + ); |
|
| 131 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | + 'event_espresso' |
|
| 134 | + ); |
|
| 135 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | + 'event_espresso' |
|
| 138 | + ); |
|
| 139 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | + 'The new state was successfully saved to the database.', |
|
| 141 | + 'event_espresso' |
|
| 142 | + ); |
|
| 143 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | + 'event_espresso' |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return void |
|
| 153 | + */ |
|
| 154 | + public static function wp_enqueue_scripts() |
|
| 155 | + { |
|
| 156 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | + wp_enqueue_script('add_new_state'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * display_add_new_state_micro_form |
|
| 167 | + * |
|
| 168 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | + * @return string |
|
| 170 | + * @throws EE_Error |
|
| 171 | + * @throws InvalidArgumentException |
|
| 172 | + * @throws InvalidDataTypeException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + */ |
|
| 175 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | + { |
|
| 178 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | + // is the "state" question in this form section? |
|
| 182 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | + //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | + if ($input instanceof EE_State_Select_Input) { |
|
| 187 | + $input->html_name(); |
|
| 188 | + } |
|
| 189 | + return $question_group_reg_form; |
|
| 190 | + } |
|
| 191 | + // we're only doing this for state select inputs |
|
| 192 | + if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | + // grab any set values from the request |
|
| 194 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | + $country_options = array(); |
|
| 199 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | + if (! empty($countries)) { |
|
| 201 | + foreach ($countries as $country) { |
|
| 202 | + if ($country instanceof EE_Country) { |
|
| 203 | + $country_options[$country->ID()] = $country->name(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | + array( |
|
| 209 | + 'name' => 'new_state_micro_form', |
|
| 210 | + 'html_id' => 'new_state_micro_form', |
|
| 211 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | + 'subsections' => array( |
|
| 213 | + // add hidden input to indicate that a new state is being added |
|
| 214 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | + array( |
|
| 216 | + 'html_name' => str_replace( |
|
| 217 | + 'state', |
|
| 218 | + 'nsmf_add_new_state', |
|
| 219 | + $input->html_name() |
|
| 220 | + ), |
|
| 221 | + 'html_id' => str_replace( |
|
| 222 | + 'state', |
|
| 223 | + 'nsmf_add_new_state', |
|
| 224 | + $input->html_id() |
|
| 225 | + ), |
|
| 226 | + 'default' => 0, |
|
| 227 | + ) |
|
| 228 | + ), |
|
| 229 | + // add link for displaying hidden container |
|
| 230 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | + apply_filters( |
|
| 232 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | + EEH_HTML::link( |
|
| 234 | + '', |
|
| 235 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | + '', |
|
| 237 | + 'display-' . $input->html_id(), |
|
| 238 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | + '', |
|
| 240 | + 'data-target="' . $input->html_id() . '"' |
|
| 241 | + ) |
|
| 242 | + ) |
|
| 243 | + ), |
|
| 244 | + // add initial html for hidden container |
|
| 245 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | + apply_filters( |
|
| 247 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | + 'display: none;') . |
|
| 250 | + EEH_HTML::h6( |
|
| 251 | + esc_html__( |
|
| 252 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | + 'event_espresso' |
|
| 254 | + ) |
|
| 255 | + ) . |
|
| 256 | + EEH_HTML::ul() . |
|
| 257 | + EEH_HTML::li( |
|
| 258 | + esc_html__( |
|
| 259 | + 'first select the Country that your State/Province belongs to', |
|
| 260 | + 'event_espresso' |
|
| 261 | + ) |
|
| 262 | + ) . |
|
| 263 | + EEH_HTML::li( |
|
| 264 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | + ) . |
|
| 266 | + EEH_HTML::li( |
|
| 267 | + esc_html__( |
|
| 268 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ) |
|
| 271 | + ) . |
|
| 272 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | + EEH_HTML::ulx() |
|
| 274 | + ) |
|
| 275 | + ), |
|
| 276 | + // NEW STATE COUNTRY |
|
| 277 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | + $country_options, |
|
| 279 | + array( |
|
| 280 | + 'html_name' => $country_name, |
|
| 281 | + 'html_id' => str_replace( |
|
| 282 | + 'state', |
|
| 283 | + 'nsmf_new_state_country', $input->html_id() |
|
| 284 | + ), |
|
| 285 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | + 'required' => false, |
|
| 289 | + ) |
|
| 290 | + ), |
|
| 291 | + // NEW STATE NAME |
|
| 292 | + 'new_state_name' => new EE_Text_Input( |
|
| 293 | + array( |
|
| 294 | + 'html_name' => $state_name, |
|
| 295 | + 'html_id' => str_replace( |
|
| 296 | + 'state', |
|
| 297 | + 'nsmf_new_state_name', $input->html_id() |
|
| 298 | + ), |
|
| 299 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | + 'event_espresso'), |
|
| 302 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | + 'required' => false, |
|
| 304 | + ) |
|
| 305 | + ), |
|
| 306 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | + // NEW STATE NAME |
|
| 308 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | + array( |
|
| 310 | + 'html_name' => $abbrv_name, |
|
| 311 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | + $input->html_id()), |
|
| 313 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | + 'html_label_text' => esc_html__( |
|
| 315 | + 'New State/Province Abbreviation', |
|
| 316 | + 'event_espresso' |
|
| 317 | + ) . ' *', |
|
| 318 | + 'html_other_attributes' => 'size="24"', |
|
| 319 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | + 'required' => false, |
|
| 321 | + ) |
|
| 322 | + ), |
|
| 323 | + // "submit" button |
|
| 324 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | + apply_filters( |
|
| 326 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | + EEH_HTML::nbsp(3) . |
|
| 328 | + EEH_HTML::link( |
|
| 329 | + '', |
|
| 330 | + esc_html__('ADD', 'event_espresso'), |
|
| 331 | + '', |
|
| 332 | + 'submit-' . $new_state_submit_id, |
|
| 333 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | + '', |
|
| 335 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | + ) |
|
| 337 | + ) |
|
| 338 | + ), |
|
| 339 | + // extra info |
|
| 340 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | + apply_filters( |
|
| 342 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | + EEH_HTML::br(2) |
|
| 344 | + . |
|
| 345 | + EEH_HTML::div('', '', 'small-text') |
|
| 346 | + . |
|
| 347 | + EEH_HTML::strong( |
|
| 348 | + '* ' . |
|
| 349 | + esc_html__( |
|
| 350 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | + 'event_espresso' |
|
| 352 | + ) |
|
| 353 | + ) |
|
| 354 | + . |
|
| 355 | + EEH_HTML::br() |
|
| 356 | + . |
|
| 357 | + sprintf( |
|
| 358 | + esc_html__( |
|
| 359 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | + 'event_espresso' |
|
| 361 | + ), |
|
| 362 | + EEH_HTML::link( |
|
| 363 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | + '', |
|
| 366 | + '', |
|
| 367 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | + '', |
|
| 369 | + 'target="_blank"' |
|
| 370 | + ) |
|
| 371 | + ) |
|
| 372 | + . |
|
| 373 | + EEH_HTML::divx() |
|
| 374 | + . |
|
| 375 | + EEH_HTML::br() |
|
| 376 | + . |
|
| 377 | + EEH_HTML::link( |
|
| 378 | + '', |
|
| 379 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | + '', |
|
| 381 | + 'hide-' . $input->html_id(), |
|
| 382 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | + '', |
|
| 384 | + 'data-target="' . $input->html_id() . '"' |
|
| 385 | + ) |
|
| 386 | + . |
|
| 387 | + EEH_HTML::divx() |
|
| 388 | + . |
|
| 389 | + EEH_HTML::br() |
|
| 390 | + ) |
|
| 391 | + ), |
|
| 392 | + ), |
|
| 393 | + ) |
|
| 394 | + ); |
|
| 395 | + $question_group_reg_form->add_subsections( |
|
| 396 | + array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | + 'state', |
|
| 398 | + false |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + return $question_group_reg_form; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * set_new_state_input_width |
|
| 408 | + * |
|
| 409 | + * @return int|string |
|
| 410 | + * @throws EE_Error |
|
| 411 | + * @throws InvalidArgumentException |
|
| 412 | + * @throws InvalidDataTypeException |
|
| 413 | + * @throws InvalidInterfaceException |
|
| 414 | + * @throws ReflectionException |
|
| 415 | + */ |
|
| 416 | + public static function add_new_state() |
|
| 417 | + { |
|
| 418 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | + EE_Registry::instance()->load_model('State'); |
|
| 421 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | + : false; |
|
| 425 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | + : false; |
|
| 428 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | + : false; |
|
| 431 | + if ($state_country && $state_name && $state_abbr) { |
|
| 432 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | + 'STA_name' => ucwords($state_name), |
|
| 436 | + 'STA_active' => false, |
|
| 437 | + )); |
|
| 438 | + if ($new_state instanceof EE_State) { |
|
| 439 | + // clean house |
|
| 440 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | + // get any existing new states |
|
| 445 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | + 'nsmf_new_states' |
|
| 447 | + ); |
|
| 448 | + $new_states[$new_state->ID()] = $new_state; |
|
| 449 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | + array('nsmf_new_states' => $new_states) |
|
| 451 | + ); |
|
| 452 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | + echo wp_json_encode(array( |
|
| 454 | + 'success' => true, |
|
| 455 | + 'id' => $new_state->ID(), |
|
| 456 | + 'name' => $new_state->name(), |
|
| 457 | + 'abbrev' => $new_state->abbrev(), |
|
| 458 | + 'country_iso' => $new_state->country_iso(), |
|
| 459 | + 'country_name' => $new_state->country()->name(), |
|
| 460 | + )); |
|
| 461 | + exit(); |
|
| 462 | + } |
|
| 463 | + return $new_state->ID(); |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + $error = esc_html__( |
|
| 467 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | + 'event_espresso' |
|
| 469 | + ); |
|
| 470 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | + echo wp_json_encode(array('error' => $error)); |
|
| 472 | + exit(); |
|
| 473 | + } |
|
| 474 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + return false; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * recursively drills down through request params to remove any that were added by this module |
|
| 484 | + * |
|
| 485 | + * @param array $request_params |
|
| 486 | + * @return array |
|
| 487 | + */ |
|
| 488 | + public static function filter_checkout_request_params($request_params) |
|
| 489 | + { |
|
| 490 | + foreach ($request_params as $form_section) { |
|
| 491 | + if (is_array($form_section)) { |
|
| 492 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $request_params; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param array $request_params |
|
| 503 | + * @return array |
|
| 504 | + */ |
|
| 505 | + public static function unset_new_state_request_params($request_params) |
|
| 506 | + { |
|
| 507 | + unset( |
|
| 508 | + $request_params['new_state_micro_form'], |
|
| 509 | + $request_params['new_state_micro_add_new_state'], |
|
| 510 | + $request_params['new_state_micro_new_state_country'], |
|
| 511 | + $request_params['new_state_micro_new_state_name'], |
|
| 512 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | + ); |
|
| 514 | + return $request_params; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * @param array $props_n_values |
|
| 521 | + * @return bool |
|
| 522 | + * @throws EE_Error |
|
| 523 | + * @throws InvalidArgumentException |
|
| 524 | + * @throws InvalidDataTypeException |
|
| 525 | + * @throws InvalidInterfaceException |
|
| 526 | + */ |
|
| 527 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | + { |
|
| 529 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | + if (! empty($existing_state)) { |
|
| 531 | + return array_pop($existing_state); |
|
| 532 | + } |
|
| 533 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | + if ($new_state instanceof EE_State) { |
|
| 535 | + $country_settings_url = add_query_arg( |
|
| 536 | + array( |
|
| 537 | + 'page' => 'espresso_general_settings', |
|
| 538 | + 'action' => 'country_settings', |
|
| 539 | + 'country' => $new_state->country_iso(), |
|
| 540 | + ), |
|
| 541 | + admin_url('admin.php') |
|
| 542 | + ); |
|
| 543 | + // if not non-ajax admin |
|
| 544 | + new PersistentAdminNotice( |
|
| 545 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | + sprintf( |
|
| 547 | + esc_html__( |
|
| 548 | + '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.', |
|
| 549 | + 'event_espresso' |
|
| 550 | + ), |
|
| 551 | + '<b>' . $new_state->name() . '</b>', |
|
| 552 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | + '<a href="' |
|
| 555 | + . $country_settings_url |
|
| 556 | + . '">' |
|
| 557 | + . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | + 'event_espresso') |
|
| 559 | + . '</a>', |
|
| 560 | + '<br />' |
|
| 561 | + ) |
|
| 562 | + ); |
|
| 563 | + $new_state->save(); |
|
| 564 | + EEM_State::instance()->reset_cached_states(); |
|
| 565 | + return $new_state; |
|
| 566 | + } |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @param string $CNT_ISO |
|
| 574 | + * @param string $STA_ID |
|
| 575 | + * @param array $cols_n_values |
|
| 576 | + * @return void |
|
| 577 | + * @throws DomainException |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws InvalidArgumentException |
|
| 580 | + * @throws InvalidDataTypeException |
|
| 581 | + * @throws InvalidInterfaceException |
|
| 582 | + */ |
|
| 583 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | + { |
|
| 585 | + if (! $CNT_ISO) { |
|
| 586 | + EE_Error::add_error( |
|
| 587 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | + __FILE__, |
|
| 589 | + __FUNCTION__, |
|
| 590 | + __LINE__ |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | + : false; |
|
| 595 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | + if ($state instanceof EE_State) { |
|
| 598 | + $STA_abbrev = $state->abbrev(); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + if (! $STA_abbrev) { |
|
| 602 | + EE_Error::add_error( |
|
| 603 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | + __FILE__, |
|
| 605 | + __FUNCTION__, |
|
| 606 | + __LINE__ |
|
| 607 | + ); |
|
| 608 | + } |
|
| 609 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | + ); |
|
| 613 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @param EE_State[] $state_options |
|
| 620 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | + * @param EE_Registration $registration |
|
| 622 | + * @param EE_Question $question |
|
| 623 | + * @param $answer |
|
| 624 | + * @return array |
|
| 625 | + * @throws EE_Error |
|
| 626 | + * @throws InvalidArgumentException |
|
| 627 | + * @throws InvalidDataTypeException |
|
| 628 | + * @throws InvalidInterfaceException |
|
| 629 | + */ |
|
| 630 | + public static function inject_new_reg_state_into_options( |
|
| 631 | + $state_options = array(), |
|
| 632 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | + EE_Registration $registration, |
|
| 634 | + EE_Question $question, |
|
| 635 | + $answer |
|
| 636 | + ) { |
|
| 637 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | + && $question->type() === EEM_Question::QST_type_state |
|
| 639 | + ) { |
|
| 640 | + $STA_ID = $answer->value(); |
|
| 641 | + if (! empty($STA_ID)) { |
|
| 642 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | + if ($state instanceof EE_State) { |
|
| 644 | + $country = $state->country(); |
|
| 645 | + if ($country instanceof EE_Country) { |
|
| 646 | + if (! isset($state_options[$country->name()])) { |
|
| 647 | + $state_options[$country->name()] = array(); |
|
| 648 | + } |
|
| 649 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + return $state_options; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param EE_Country[] $country_options |
|
| 663 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | + * @param EE_Registration $registration |
|
| 665 | + * @param EE_Question $question |
|
| 666 | + * @param $answer |
|
| 667 | + * @return array |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws InvalidArgumentException |
|
| 670 | + * @throws InvalidDataTypeException |
|
| 671 | + * @throws InvalidInterfaceException |
|
| 672 | + */ |
|
| 673 | + public static function inject_new_reg_country_into_options( |
|
| 674 | + $country_options = array(), |
|
| 675 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | + EE_Registration $registration, |
|
| 677 | + EE_Question $question, |
|
| 678 | + $answer |
|
| 679 | + ) { |
|
| 680 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | + && $question->type() |
|
| 682 | + === EEM_Question::QST_type_country |
|
| 683 | + ) { |
|
| 684 | + $CNT_ISO = $answer->value(); |
|
| 685 | + if (! empty($CNT_ISO)) { |
|
| 686 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | + if ($country instanceof EE_Country) { |
|
| 688 | + if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + return $country_options; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * @param EE_State[] $state_options |
|
| 701 | + * @return array |
|
| 702 | + * @throws EE_Error |
|
| 703 | + * @throws InvalidArgumentException |
|
| 704 | + * @throws InvalidDataTypeException |
|
| 705 | + * @throws InvalidInterfaceException |
|
| 706 | + */ |
|
| 707 | + public static function state_options($state_options = array()) |
|
| 708 | + { |
|
| 709 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | + foreach ($new_states as $new_state) { |
|
| 711 | + if ( |
|
| 712 | + $new_state instanceof EE_State |
|
| 713 | + && $new_state->country() instanceof EE_Country |
|
| 714 | + ) { |
|
| 715 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + return $state_options; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * @return array |
|
| 725 | + * @throws InvalidArgumentException |
|
| 726 | + * @throws InvalidDataTypeException |
|
| 727 | + * @throws InvalidInterfaceException |
|
| 728 | + */ |
|
| 729 | + protected static function _get_new_states() |
|
| 730 | + { |
|
| 731 | + $new_states = array(); |
|
| 732 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | + 'nsmf_new_states' |
|
| 735 | + ); |
|
| 736 | + } |
|
| 737 | + return is_array($new_states) ? $new_states : array(); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * @param EE_Country[] $country_options |
|
| 744 | + * @return array |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @throws InvalidArgumentException |
|
| 747 | + * @throws InvalidDataTypeException |
|
| 748 | + * @throws InvalidInterfaceException |
|
| 749 | + */ |
|
| 750 | + public static function country_options($country_options = array()) |
|
| 751 | + { |
|
| 752 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | + foreach ($new_states as $new_state) { |
|
| 754 | + if ( |
|
| 755 | + $new_state instanceof EE_State |
|
| 756 | + && $new_state->country() instanceof EE_Country |
|
| 757 | + ) { |
|
| 758 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + return $country_options; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | 764 | |
| 765 | 765 | |
@@ -27,746 +27,746 @@ |
||
| 27 | 27 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Sets some dynamic defaults |
|
| 32 | - * |
|
| 33 | - * @param array $fieldValues |
|
| 34 | - * @param bool $bydb |
|
| 35 | - * @param string $timezone |
|
| 36 | - * @param array $date_formats |
|
| 37 | - * @throws EE_Error |
|
| 38 | - */ |
|
| 39 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | - { |
|
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | - } |
|
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | - } |
|
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | - } |
|
| 53 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param array $props_n_values incoming values |
|
| 59 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | - * used.) |
|
| 61 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | - * date_format and the second value is the time format |
|
| 63 | - * @return EE_Attendee |
|
| 64 | - * @throws EE_Error |
|
| 65 | - */ |
|
| 66 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | - { |
|
| 68 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param array $props_n_values incoming values from the database |
|
| 75 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | - * the website will be used. |
|
| 77 | - * @return EE_Attendee |
|
| 78 | - */ |
|
| 79 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | - { |
|
| 81 | - return new self($props_n_values, true, $timezone); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Set Attendee First Name |
|
| 87 | - * |
|
| 88 | - * @access public |
|
| 89 | - * @param string $fname |
|
| 90 | - * @throws EE_Error |
|
| 91 | - */ |
|
| 92 | - public function set_fname($fname = '') |
|
| 93 | - { |
|
| 94 | - $this->set('ATT_fname', $fname); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Set Attendee Last Name |
|
| 100 | - * |
|
| 101 | - * @access public |
|
| 102 | - * @param string $lname |
|
| 103 | - * @throws EE_Error |
|
| 104 | - */ |
|
| 105 | - public function set_lname($lname = '') |
|
| 106 | - { |
|
| 107 | - $this->set('ATT_lname', $lname); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Set Attendee Address |
|
| 113 | - * |
|
| 114 | - * @access public |
|
| 115 | - * @param string $address |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_address($address = '') |
|
| 119 | - { |
|
| 120 | - $this->set('ATT_address', $address); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Set Attendee Address2 |
|
| 126 | - * |
|
| 127 | - * @access public |
|
| 128 | - * @param string $address2 |
|
| 129 | - * @throws EE_Error |
|
| 130 | - */ |
|
| 131 | - public function set_address2($address2 = '') |
|
| 132 | - { |
|
| 133 | - $this->set('ATT_address2', $address2); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Set Attendee City |
|
| 139 | - * |
|
| 140 | - * @access public |
|
| 141 | - * @param string $city |
|
| 142 | - * @throws EE_Error |
|
| 143 | - */ |
|
| 144 | - public function set_city($city = '') |
|
| 145 | - { |
|
| 146 | - $this->set('ATT_city', $city); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set Attendee State ID |
|
| 152 | - * |
|
| 153 | - * @access public |
|
| 154 | - * @param int $STA_ID |
|
| 155 | - * @throws EE_Error |
|
| 156 | - */ |
|
| 157 | - public function set_state($STA_ID = 0) |
|
| 158 | - { |
|
| 159 | - $this->set('STA_ID', $STA_ID); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Set Attendee Country ISO Code |
|
| 165 | - * |
|
| 166 | - * @access public |
|
| 167 | - * @param string $CNT_ISO |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function set_country($CNT_ISO = '') |
|
| 171 | - { |
|
| 172 | - $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Set Attendee Zip/Postal Code |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @param string $zip |
|
| 181 | - * @throws EE_Error |
|
| 182 | - */ |
|
| 183 | - public function set_zip($zip = '') |
|
| 184 | - { |
|
| 185 | - $this->set('ATT_zip', $zip); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Set Attendee Email Address |
|
| 191 | - * |
|
| 192 | - * @access public |
|
| 193 | - * @param string $email |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - public function set_email($email = '') |
|
| 197 | - { |
|
| 198 | - $this->set('ATT_email', $email); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Set Attendee Phone |
|
| 204 | - * |
|
| 205 | - * @access public |
|
| 206 | - * @param string $phone |
|
| 207 | - * @throws EE_Error |
|
| 208 | - */ |
|
| 209 | - public function set_phone($phone = '') |
|
| 210 | - { |
|
| 211 | - $this->set('ATT_phone', $phone); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * set deleted |
|
| 217 | - * |
|
| 218 | - * @access public |
|
| 219 | - * @param bool $ATT_deleted |
|
| 220 | - * @throws EE_Error |
|
| 221 | - */ |
|
| 222 | - public function set_deleted($ATT_deleted = false) |
|
| 223 | - { |
|
| 224 | - $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Returns the value for the post_author id saved with the cpt |
|
| 230 | - * |
|
| 231 | - * @since 4.5.0 |
|
| 232 | - * @return int |
|
| 233 | - * @throws EE_Error |
|
| 234 | - */ |
|
| 235 | - public function wp_user() |
|
| 236 | - { |
|
| 237 | - return $this->get('ATT_author'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * get Attendee First Name |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return string |
|
| 246 | - * @throws EE_Error |
|
| 247 | - */ |
|
| 248 | - public function fname() |
|
| 249 | - { |
|
| 250 | - return $this->get('ATT_fname'); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * echoes out the attendee's first name |
|
| 256 | - * |
|
| 257 | - * @return void |
|
| 258 | - * @throws EE_Error |
|
| 259 | - */ |
|
| 260 | - public function e_full_name() |
|
| 261 | - { |
|
| 262 | - echo $this->full_name(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns the first and last name concatenated together with a space. |
|
| 268 | - * |
|
| 269 | - * @param bool $apply_html_entities |
|
| 270 | - * @return string |
|
| 271 | - * @throws EE_Error |
|
| 272 | - */ |
|
| 273 | - public function full_name($apply_html_entities = false) |
|
| 274 | - { |
|
| 275 | - $full_name = array( |
|
| 276 | - $this->fname(), |
|
| 277 | - $this->lname(), |
|
| 278 | - ); |
|
| 279 | - $full_name = array_filter($full_name); |
|
| 280 | - $full_name = implode(' ', $full_name); |
|
| 281 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | - * attendee. |
|
| 289 | - * |
|
| 290 | - * @param bool $apply_html_entities |
|
| 291 | - * @return string |
|
| 292 | - * @throws EE_Error |
|
| 293 | - */ |
|
| 294 | - public function ATT_full_name($apply_html_entities = false) |
|
| 295 | - { |
|
| 296 | - return $apply_html_entities |
|
| 297 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | - : $this->get('ATT_full_name'); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * get Attendee Last Name |
|
| 304 | - * |
|
| 305 | - * @access public |
|
| 306 | - * @return string |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - public function lname() |
|
| 310 | - { |
|
| 311 | - return $this->get('ATT_lname'); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | - * |
|
| 318 | - * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | - * Eg, if the user only responded to state and country, |
|
| 320 | - * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | - * @return array |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function full_address_as_array() |
|
| 325 | - { |
|
| 326 | - $full_address_array = array(); |
|
| 327 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | - foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | - $address_fields_value = $this->get($address_field_name); |
|
| 330 | - if (! empty($address_fields_value)) { |
|
| 331 | - $full_address_array[] = $address_fields_value; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - //now handle state and country |
|
| 335 | - $state_obj = $this->state_obj(); |
|
| 336 | - if ($state_obj instanceof EE_State) { |
|
| 337 | - $full_address_array[] = $state_obj->name(); |
|
| 338 | - } |
|
| 339 | - $country_obj = $this->country_obj(); |
|
| 340 | - if ($country_obj instanceof EE_Country) { |
|
| 341 | - $full_address_array[] = $country_obj->name(); |
|
| 342 | - } |
|
| 343 | - //lastly get the xip |
|
| 344 | - $zip_value = $this->zip(); |
|
| 345 | - if (! empty($zip_value)) { |
|
| 346 | - $full_address_array[] = $zip_value; |
|
| 347 | - } |
|
| 348 | - return $full_address_array; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get Attendee Address |
|
| 354 | - * |
|
| 355 | - * @return string |
|
| 356 | - * @throws EE_Error |
|
| 357 | - */ |
|
| 358 | - public function address() |
|
| 359 | - { |
|
| 360 | - return $this->get('ATT_address'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * get Attendee Address2 |
|
| 366 | - * |
|
| 367 | - * @return string |
|
| 368 | - * @throws EE_Error |
|
| 369 | - */ |
|
| 370 | - public function address2() |
|
| 371 | - { |
|
| 372 | - return $this->get('ATT_address2'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * get Attendee City |
|
| 378 | - * |
|
| 379 | - * @return string |
|
| 380 | - * @throws EE_Error |
|
| 381 | - */ |
|
| 382 | - public function city() |
|
| 383 | - { |
|
| 384 | - return $this->get('ATT_city'); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * get Attendee State ID |
|
| 390 | - * |
|
| 391 | - * @return string |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function state_ID() |
|
| 395 | - { |
|
| 396 | - return $this->get('STA_ID'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @return string |
|
| 402 | - * @throws EE_Error |
|
| 403 | - */ |
|
| 404 | - public function state_abbrev() |
|
| 405 | - { |
|
| 406 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Gets the state set to this attendee |
|
| 412 | - * |
|
| 413 | - * @return EE_State |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public function state_obj() |
|
| 417 | - { |
|
| 418 | - return $this->get_first_related('State'); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns the state's name, otherwise 'Unknown' |
|
| 424 | - * |
|
| 425 | - * @return string |
|
| 426 | - * @throws EE_Error |
|
| 427 | - */ |
|
| 428 | - public function state_name() |
|
| 429 | - { |
|
| 430 | - if ($this->state_obj()) { |
|
| 431 | - return $this->state_obj()->name(); |
|
| 432 | - } else { |
|
| 433 | - return ''; |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * either displays the state abbreviation or the state name, as determined |
|
| 440 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | - * defaults to abbreviation |
|
| 442 | - * |
|
| 443 | - * @return string |
|
| 444 | - * @throws EE_Error |
|
| 445 | - */ |
|
| 446 | - public function state() |
|
| 447 | - { |
|
| 448 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | - return $this->state_abbrev(); |
|
| 450 | - } |
|
| 451 | - return $this->state_name(); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * get Attendee Country ISO Code |
|
| 457 | - * |
|
| 458 | - * @return string |
|
| 459 | - * @throws EE_Error |
|
| 460 | - */ |
|
| 461 | - public function country_ID() |
|
| 462 | - { |
|
| 463 | - return $this->get('CNT_ISO'); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Gets country set for this attendee |
|
| 469 | - * |
|
| 470 | - * @return EE_Country |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function country_obj() |
|
| 474 | - { |
|
| 475 | - return $this->get_first_related('Country'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | - * |
|
| 482 | - * @return string |
|
| 483 | - * @throws EE_Error |
|
| 484 | - */ |
|
| 485 | - public function country_name() |
|
| 486 | - { |
|
| 487 | - if ($this->country_obj()) { |
|
| 488 | - return $this->country_obj()->name(); |
|
| 489 | - } |
|
| 490 | - return ''; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * either displays the country ISO2 code or the country name, as determined |
|
| 496 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | - * defaults to abbreviation |
|
| 498 | - * |
|
| 499 | - * @return string |
|
| 500 | - * @throws EE_Error |
|
| 501 | - */ |
|
| 502 | - public function country() |
|
| 503 | - { |
|
| 504 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | - return $this->country_ID(); |
|
| 506 | - } |
|
| 507 | - return $this->country_name(); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get Attendee Zip/Postal Code |
|
| 513 | - * |
|
| 514 | - * @return string |
|
| 515 | - * @throws EE_Error |
|
| 516 | - */ |
|
| 517 | - public function zip() |
|
| 518 | - { |
|
| 519 | - return $this->get('ATT_zip'); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * get Attendee Email Address |
|
| 525 | - * |
|
| 526 | - * @return string |
|
| 527 | - * @throws EE_Error |
|
| 528 | - */ |
|
| 529 | - public function email() |
|
| 530 | - { |
|
| 531 | - return $this->get('ATT_email'); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * get Attendee Phone # |
|
| 537 | - * |
|
| 538 | - * @return string |
|
| 539 | - * @throws EE_Error |
|
| 540 | - */ |
|
| 541 | - public function phone() |
|
| 542 | - { |
|
| 543 | - return $this->get('ATT_phone'); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * get deleted |
|
| 549 | - * |
|
| 550 | - * @return bool |
|
| 551 | - * @throws EE_Error |
|
| 552 | - */ |
|
| 553 | - public function deleted() |
|
| 554 | - { |
|
| 555 | - return $this->get('ATT_deleted'); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Gets registrations of this attendee |
|
| 561 | - * |
|
| 562 | - * @param array $query_params |
|
| 563 | - * @return EE_Registration[] |
|
| 564 | - * @throws EE_Error |
|
| 565 | - */ |
|
| 566 | - public function get_registrations($query_params = array()) |
|
| 567 | - { |
|
| 568 | - return $this->get_many_related('Registration', $query_params); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Gets the most recent registration of this attendee |
|
| 574 | - * |
|
| 575 | - * @return EE_Registration |
|
| 576 | - * @throws EE_Error |
|
| 577 | - */ |
|
| 578 | - public function get_most_recent_registration() |
|
| 579 | - { |
|
| 580 | - return $this->get_first_related( |
|
| 581 | - 'Registration', |
|
| 582 | - array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | - ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Gets the most recent registration for this attend at this event |
|
| 589 | - * |
|
| 590 | - * @param int $event_id |
|
| 591 | - * @return EE_Registration |
|
| 592 | - * @throws EE_Error |
|
| 593 | - */ |
|
| 594 | - public function get_most_recent_registration_for_event($event_id) |
|
| 595 | - { |
|
| 596 | - return $this->get_first_related( |
|
| 597 | - 'Registration', |
|
| 598 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * returns any events attached to this attendee ($_Event property); |
|
| 605 | - * |
|
| 606 | - * @return array |
|
| 607 | - * @throws EE_Error |
|
| 608 | - */ |
|
| 609 | - public function events() |
|
| 610 | - { |
|
| 611 | - return $this->get_many_related('Event'); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | - * used to save the billing info |
|
| 619 | - * |
|
| 620 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | - * @return EE_Form_Section_Proper|null |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - public function billing_info_for_payment_method($payment_method) |
|
| 625 | - { |
|
| 626 | - $pm_type = $payment_method->type_obj(); |
|
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | - return null; |
|
| 629 | - } |
|
| 630 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | - if (! $billing_info) { |
|
| 632 | - return null; |
|
| 633 | - } |
|
| 634 | - $billing_form = $pm_type->billing_form(); |
|
| 635 | - //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | - $form_totally_hidden = true; |
|
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | - $form_totally_hidden = false; |
|
| 640 | - break; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - if($form_totally_hidden) { |
|
| 644 | - return null; |
|
| 645 | - } |
|
| 646 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $billing_form; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | - * specified payment method |
|
| 657 | - * |
|
| 658 | - * @param EE_Payment_Method $payment_method |
|
| 659 | - * @return string |
|
| 660 | - * @throws EE_Error |
|
| 661 | - */ |
|
| 662 | - public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | - { |
|
| 664 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | - } |
|
| 667 | - return null; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | - * retrieve it |
|
| 674 | - * |
|
| 675 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | - * @param EE_Payment_Method $payment_method |
|
| 677 | - * @return boolean |
|
| 678 | - * @throws EE_Error |
|
| 679 | - */ |
|
| 680 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | - { |
|
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | - return false; |
|
| 685 | - } |
|
| 686 | - $billing_form->clean_sensitive_data(); |
|
| 687 | - return update_post_meta( |
|
| 688 | - $this->ID(), |
|
| 689 | - $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | - $billing_form->input_values(true) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Return the link to the admin details for the object. |
|
| 697 | - * |
|
| 698 | - * @return string |
|
| 699 | - * @throws EE_Error |
|
| 700 | - * @throws InvalidArgumentException |
|
| 701 | - * @throws InvalidDataTypeException |
|
| 702 | - * @throws InvalidInterfaceException |
|
| 703 | - * @throws ReflectionException |
|
| 704 | - */ |
|
| 705 | - public function get_admin_details_link() |
|
| 706 | - { |
|
| 707 | - return $this->get_admin_edit_link(); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | - * |
|
| 714 | - * @return string |
|
| 715 | - * @throws EE_Error |
|
| 716 | - * @throws InvalidArgumentException |
|
| 717 | - * @throws ReflectionException |
|
| 718 | - * @throws InvalidDataTypeException |
|
| 719 | - * @throws InvalidInterfaceException |
|
| 720 | - */ |
|
| 721 | - public function get_admin_edit_link() |
|
| 722 | - { |
|
| 723 | - EE_Registry::instance()->load_helper('URL'); |
|
| 724 | - return EEH_URL::add_query_args_and_nonce( |
|
| 725 | - array( |
|
| 726 | - 'page' => 'espresso_registrations', |
|
| 727 | - 'action' => 'edit_attendee', |
|
| 728 | - 'post' => $this->ID(), |
|
| 729 | - ), |
|
| 730 | - admin_url('admin.php') |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * Returns the link to a settings page for the object. |
|
| 737 | - * |
|
| 738 | - * @return string |
|
| 739 | - * @throws EE_Error |
|
| 740 | - * @throws InvalidArgumentException |
|
| 741 | - * @throws InvalidDataTypeException |
|
| 742 | - * @throws InvalidInterfaceException |
|
| 743 | - * @throws ReflectionException |
|
| 744 | - */ |
|
| 745 | - public function get_admin_settings_link() |
|
| 746 | - { |
|
| 747 | - return $this->get_admin_edit_link(); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | - * |
|
| 754 | - * @return string |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws InvalidArgumentException |
|
| 757 | - * @throws ReflectionException |
|
| 758 | - * @throws InvalidDataTypeException |
|
| 759 | - * @throws InvalidInterfaceException |
|
| 760 | - */ |
|
| 761 | - public function get_admin_overview_link() |
|
| 762 | - { |
|
| 763 | - EE_Registry::instance()->load_helper('URL'); |
|
| 764 | - return EEH_URL::add_query_args_and_nonce( |
|
| 765 | - array( |
|
| 766 | - 'page' => 'espresso_registrations', |
|
| 767 | - 'action' => 'contact_list', |
|
| 768 | - ), |
|
| 769 | - admin_url('admin.php') |
|
| 770 | - ); |
|
| 771 | - } |
|
| 30 | + /** |
|
| 31 | + * Sets some dynamic defaults |
|
| 32 | + * |
|
| 33 | + * @param array $fieldValues |
|
| 34 | + * @param bool $bydb |
|
| 35 | + * @param string $timezone |
|
| 36 | + * @param array $date_formats |
|
| 37 | + * @throws EE_Error |
|
| 38 | + */ |
|
| 39 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | + { |
|
| 41 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | + } |
|
| 46 | + if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | + } |
|
| 50 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | + } |
|
| 53 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param array $props_n_values incoming values |
|
| 59 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | + * used.) |
|
| 61 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | + * date_format and the second value is the time format |
|
| 63 | + * @return EE_Attendee |
|
| 64 | + * @throws EE_Error |
|
| 65 | + */ |
|
| 66 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | + { |
|
| 68 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param array $props_n_values incoming values from the database |
|
| 75 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | + * the website will be used. |
|
| 77 | + * @return EE_Attendee |
|
| 78 | + */ |
|
| 79 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | + { |
|
| 81 | + return new self($props_n_values, true, $timezone); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Set Attendee First Name |
|
| 87 | + * |
|
| 88 | + * @access public |
|
| 89 | + * @param string $fname |
|
| 90 | + * @throws EE_Error |
|
| 91 | + */ |
|
| 92 | + public function set_fname($fname = '') |
|
| 93 | + { |
|
| 94 | + $this->set('ATT_fname', $fname); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Set Attendee Last Name |
|
| 100 | + * |
|
| 101 | + * @access public |
|
| 102 | + * @param string $lname |
|
| 103 | + * @throws EE_Error |
|
| 104 | + */ |
|
| 105 | + public function set_lname($lname = '') |
|
| 106 | + { |
|
| 107 | + $this->set('ATT_lname', $lname); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Set Attendee Address |
|
| 113 | + * |
|
| 114 | + * @access public |
|
| 115 | + * @param string $address |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_address($address = '') |
|
| 119 | + { |
|
| 120 | + $this->set('ATT_address', $address); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Set Attendee Address2 |
|
| 126 | + * |
|
| 127 | + * @access public |
|
| 128 | + * @param string $address2 |
|
| 129 | + * @throws EE_Error |
|
| 130 | + */ |
|
| 131 | + public function set_address2($address2 = '') |
|
| 132 | + { |
|
| 133 | + $this->set('ATT_address2', $address2); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Set Attendee City |
|
| 139 | + * |
|
| 140 | + * @access public |
|
| 141 | + * @param string $city |
|
| 142 | + * @throws EE_Error |
|
| 143 | + */ |
|
| 144 | + public function set_city($city = '') |
|
| 145 | + { |
|
| 146 | + $this->set('ATT_city', $city); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set Attendee State ID |
|
| 152 | + * |
|
| 153 | + * @access public |
|
| 154 | + * @param int $STA_ID |
|
| 155 | + * @throws EE_Error |
|
| 156 | + */ |
|
| 157 | + public function set_state($STA_ID = 0) |
|
| 158 | + { |
|
| 159 | + $this->set('STA_ID', $STA_ID); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Set Attendee Country ISO Code |
|
| 165 | + * |
|
| 166 | + * @access public |
|
| 167 | + * @param string $CNT_ISO |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function set_country($CNT_ISO = '') |
|
| 171 | + { |
|
| 172 | + $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Set Attendee Zip/Postal Code |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @param string $zip |
|
| 181 | + * @throws EE_Error |
|
| 182 | + */ |
|
| 183 | + public function set_zip($zip = '') |
|
| 184 | + { |
|
| 185 | + $this->set('ATT_zip', $zip); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Set Attendee Email Address |
|
| 191 | + * |
|
| 192 | + * @access public |
|
| 193 | + * @param string $email |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + public function set_email($email = '') |
|
| 197 | + { |
|
| 198 | + $this->set('ATT_email', $email); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Set Attendee Phone |
|
| 204 | + * |
|
| 205 | + * @access public |
|
| 206 | + * @param string $phone |
|
| 207 | + * @throws EE_Error |
|
| 208 | + */ |
|
| 209 | + public function set_phone($phone = '') |
|
| 210 | + { |
|
| 211 | + $this->set('ATT_phone', $phone); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * set deleted |
|
| 217 | + * |
|
| 218 | + * @access public |
|
| 219 | + * @param bool $ATT_deleted |
|
| 220 | + * @throws EE_Error |
|
| 221 | + */ |
|
| 222 | + public function set_deleted($ATT_deleted = false) |
|
| 223 | + { |
|
| 224 | + $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Returns the value for the post_author id saved with the cpt |
|
| 230 | + * |
|
| 231 | + * @since 4.5.0 |
|
| 232 | + * @return int |
|
| 233 | + * @throws EE_Error |
|
| 234 | + */ |
|
| 235 | + public function wp_user() |
|
| 236 | + { |
|
| 237 | + return $this->get('ATT_author'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * get Attendee First Name |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return string |
|
| 246 | + * @throws EE_Error |
|
| 247 | + */ |
|
| 248 | + public function fname() |
|
| 249 | + { |
|
| 250 | + return $this->get('ATT_fname'); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * echoes out the attendee's first name |
|
| 256 | + * |
|
| 257 | + * @return void |
|
| 258 | + * @throws EE_Error |
|
| 259 | + */ |
|
| 260 | + public function e_full_name() |
|
| 261 | + { |
|
| 262 | + echo $this->full_name(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns the first and last name concatenated together with a space. |
|
| 268 | + * |
|
| 269 | + * @param bool $apply_html_entities |
|
| 270 | + * @return string |
|
| 271 | + * @throws EE_Error |
|
| 272 | + */ |
|
| 273 | + public function full_name($apply_html_entities = false) |
|
| 274 | + { |
|
| 275 | + $full_name = array( |
|
| 276 | + $this->fname(), |
|
| 277 | + $this->lname(), |
|
| 278 | + ); |
|
| 279 | + $full_name = array_filter($full_name); |
|
| 280 | + $full_name = implode(' ', $full_name); |
|
| 281 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | + * attendee. |
|
| 289 | + * |
|
| 290 | + * @param bool $apply_html_entities |
|
| 291 | + * @return string |
|
| 292 | + * @throws EE_Error |
|
| 293 | + */ |
|
| 294 | + public function ATT_full_name($apply_html_entities = false) |
|
| 295 | + { |
|
| 296 | + return $apply_html_entities |
|
| 297 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | + : $this->get('ATT_full_name'); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * get Attendee Last Name |
|
| 304 | + * |
|
| 305 | + * @access public |
|
| 306 | + * @return string |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + public function lname() |
|
| 310 | + { |
|
| 311 | + return $this->get('ATT_lname'); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | + * |
|
| 318 | + * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | + * Eg, if the user only responded to state and country, |
|
| 320 | + * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | + * @return array |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function full_address_as_array() |
|
| 325 | + { |
|
| 326 | + $full_address_array = array(); |
|
| 327 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | + foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | + $address_fields_value = $this->get($address_field_name); |
|
| 330 | + if (! empty($address_fields_value)) { |
|
| 331 | + $full_address_array[] = $address_fields_value; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + //now handle state and country |
|
| 335 | + $state_obj = $this->state_obj(); |
|
| 336 | + if ($state_obj instanceof EE_State) { |
|
| 337 | + $full_address_array[] = $state_obj->name(); |
|
| 338 | + } |
|
| 339 | + $country_obj = $this->country_obj(); |
|
| 340 | + if ($country_obj instanceof EE_Country) { |
|
| 341 | + $full_address_array[] = $country_obj->name(); |
|
| 342 | + } |
|
| 343 | + //lastly get the xip |
|
| 344 | + $zip_value = $this->zip(); |
|
| 345 | + if (! empty($zip_value)) { |
|
| 346 | + $full_address_array[] = $zip_value; |
|
| 347 | + } |
|
| 348 | + return $full_address_array; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get Attendee Address |
|
| 354 | + * |
|
| 355 | + * @return string |
|
| 356 | + * @throws EE_Error |
|
| 357 | + */ |
|
| 358 | + public function address() |
|
| 359 | + { |
|
| 360 | + return $this->get('ATT_address'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * get Attendee Address2 |
|
| 366 | + * |
|
| 367 | + * @return string |
|
| 368 | + * @throws EE_Error |
|
| 369 | + */ |
|
| 370 | + public function address2() |
|
| 371 | + { |
|
| 372 | + return $this->get('ATT_address2'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * get Attendee City |
|
| 378 | + * |
|
| 379 | + * @return string |
|
| 380 | + * @throws EE_Error |
|
| 381 | + */ |
|
| 382 | + public function city() |
|
| 383 | + { |
|
| 384 | + return $this->get('ATT_city'); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * get Attendee State ID |
|
| 390 | + * |
|
| 391 | + * @return string |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function state_ID() |
|
| 395 | + { |
|
| 396 | + return $this->get('STA_ID'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @return string |
|
| 402 | + * @throws EE_Error |
|
| 403 | + */ |
|
| 404 | + public function state_abbrev() |
|
| 405 | + { |
|
| 406 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Gets the state set to this attendee |
|
| 412 | + * |
|
| 413 | + * @return EE_State |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public function state_obj() |
|
| 417 | + { |
|
| 418 | + return $this->get_first_related('State'); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns the state's name, otherwise 'Unknown' |
|
| 424 | + * |
|
| 425 | + * @return string |
|
| 426 | + * @throws EE_Error |
|
| 427 | + */ |
|
| 428 | + public function state_name() |
|
| 429 | + { |
|
| 430 | + if ($this->state_obj()) { |
|
| 431 | + return $this->state_obj()->name(); |
|
| 432 | + } else { |
|
| 433 | + return ''; |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * either displays the state abbreviation or the state name, as determined |
|
| 440 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | + * defaults to abbreviation |
|
| 442 | + * |
|
| 443 | + * @return string |
|
| 444 | + * @throws EE_Error |
|
| 445 | + */ |
|
| 446 | + public function state() |
|
| 447 | + { |
|
| 448 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | + return $this->state_abbrev(); |
|
| 450 | + } |
|
| 451 | + return $this->state_name(); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * get Attendee Country ISO Code |
|
| 457 | + * |
|
| 458 | + * @return string |
|
| 459 | + * @throws EE_Error |
|
| 460 | + */ |
|
| 461 | + public function country_ID() |
|
| 462 | + { |
|
| 463 | + return $this->get('CNT_ISO'); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Gets country set for this attendee |
|
| 469 | + * |
|
| 470 | + * @return EE_Country |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function country_obj() |
|
| 474 | + { |
|
| 475 | + return $this->get_first_related('Country'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | + * |
|
| 482 | + * @return string |
|
| 483 | + * @throws EE_Error |
|
| 484 | + */ |
|
| 485 | + public function country_name() |
|
| 486 | + { |
|
| 487 | + if ($this->country_obj()) { |
|
| 488 | + return $this->country_obj()->name(); |
|
| 489 | + } |
|
| 490 | + return ''; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * either displays the country ISO2 code or the country name, as determined |
|
| 496 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | + * defaults to abbreviation |
|
| 498 | + * |
|
| 499 | + * @return string |
|
| 500 | + * @throws EE_Error |
|
| 501 | + */ |
|
| 502 | + public function country() |
|
| 503 | + { |
|
| 504 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | + return $this->country_ID(); |
|
| 506 | + } |
|
| 507 | + return $this->country_name(); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get Attendee Zip/Postal Code |
|
| 513 | + * |
|
| 514 | + * @return string |
|
| 515 | + * @throws EE_Error |
|
| 516 | + */ |
|
| 517 | + public function zip() |
|
| 518 | + { |
|
| 519 | + return $this->get('ATT_zip'); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * get Attendee Email Address |
|
| 525 | + * |
|
| 526 | + * @return string |
|
| 527 | + * @throws EE_Error |
|
| 528 | + */ |
|
| 529 | + public function email() |
|
| 530 | + { |
|
| 531 | + return $this->get('ATT_email'); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * get Attendee Phone # |
|
| 537 | + * |
|
| 538 | + * @return string |
|
| 539 | + * @throws EE_Error |
|
| 540 | + */ |
|
| 541 | + public function phone() |
|
| 542 | + { |
|
| 543 | + return $this->get('ATT_phone'); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * get deleted |
|
| 549 | + * |
|
| 550 | + * @return bool |
|
| 551 | + * @throws EE_Error |
|
| 552 | + */ |
|
| 553 | + public function deleted() |
|
| 554 | + { |
|
| 555 | + return $this->get('ATT_deleted'); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Gets registrations of this attendee |
|
| 561 | + * |
|
| 562 | + * @param array $query_params |
|
| 563 | + * @return EE_Registration[] |
|
| 564 | + * @throws EE_Error |
|
| 565 | + */ |
|
| 566 | + public function get_registrations($query_params = array()) |
|
| 567 | + { |
|
| 568 | + return $this->get_many_related('Registration', $query_params); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Gets the most recent registration of this attendee |
|
| 574 | + * |
|
| 575 | + * @return EE_Registration |
|
| 576 | + * @throws EE_Error |
|
| 577 | + */ |
|
| 578 | + public function get_most_recent_registration() |
|
| 579 | + { |
|
| 580 | + return $this->get_first_related( |
|
| 581 | + 'Registration', |
|
| 582 | + array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | + ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Gets the most recent registration for this attend at this event |
|
| 589 | + * |
|
| 590 | + * @param int $event_id |
|
| 591 | + * @return EE_Registration |
|
| 592 | + * @throws EE_Error |
|
| 593 | + */ |
|
| 594 | + public function get_most_recent_registration_for_event($event_id) |
|
| 595 | + { |
|
| 596 | + return $this->get_first_related( |
|
| 597 | + 'Registration', |
|
| 598 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * returns any events attached to this attendee ($_Event property); |
|
| 605 | + * |
|
| 606 | + * @return array |
|
| 607 | + * @throws EE_Error |
|
| 608 | + */ |
|
| 609 | + public function events() |
|
| 610 | + { |
|
| 611 | + return $this->get_many_related('Event'); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | + * used to save the billing info |
|
| 619 | + * |
|
| 620 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | + * @return EE_Form_Section_Proper|null |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + public function billing_info_for_payment_method($payment_method) |
|
| 625 | + { |
|
| 626 | + $pm_type = $payment_method->type_obj(); |
|
| 627 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | + return null; |
|
| 629 | + } |
|
| 630 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | + if (! $billing_info) { |
|
| 632 | + return null; |
|
| 633 | + } |
|
| 634 | + $billing_form = $pm_type->billing_form(); |
|
| 635 | + //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | + $form_totally_hidden = true; |
|
| 637 | + foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | + if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | + $form_totally_hidden = false; |
|
| 640 | + break; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + if($form_totally_hidden) { |
|
| 644 | + return null; |
|
| 645 | + } |
|
| 646 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $billing_form; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | + * specified payment method |
|
| 657 | + * |
|
| 658 | + * @param EE_Payment_Method $payment_method |
|
| 659 | + * @return string |
|
| 660 | + * @throws EE_Error |
|
| 661 | + */ |
|
| 662 | + public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | + { |
|
| 664 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | + } |
|
| 667 | + return null; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | + * retrieve it |
|
| 674 | + * |
|
| 675 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | + * @param EE_Payment_Method $payment_method |
|
| 677 | + * @return boolean |
|
| 678 | + * @throws EE_Error |
|
| 679 | + */ |
|
| 680 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | + { |
|
| 682 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | + return false; |
|
| 685 | + } |
|
| 686 | + $billing_form->clean_sensitive_data(); |
|
| 687 | + return update_post_meta( |
|
| 688 | + $this->ID(), |
|
| 689 | + $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | + $billing_form->input_values(true) |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Return the link to the admin details for the object. |
|
| 697 | + * |
|
| 698 | + * @return string |
|
| 699 | + * @throws EE_Error |
|
| 700 | + * @throws InvalidArgumentException |
|
| 701 | + * @throws InvalidDataTypeException |
|
| 702 | + * @throws InvalidInterfaceException |
|
| 703 | + * @throws ReflectionException |
|
| 704 | + */ |
|
| 705 | + public function get_admin_details_link() |
|
| 706 | + { |
|
| 707 | + return $this->get_admin_edit_link(); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | + * |
|
| 714 | + * @return string |
|
| 715 | + * @throws EE_Error |
|
| 716 | + * @throws InvalidArgumentException |
|
| 717 | + * @throws ReflectionException |
|
| 718 | + * @throws InvalidDataTypeException |
|
| 719 | + * @throws InvalidInterfaceException |
|
| 720 | + */ |
|
| 721 | + public function get_admin_edit_link() |
|
| 722 | + { |
|
| 723 | + EE_Registry::instance()->load_helper('URL'); |
|
| 724 | + return EEH_URL::add_query_args_and_nonce( |
|
| 725 | + array( |
|
| 726 | + 'page' => 'espresso_registrations', |
|
| 727 | + 'action' => 'edit_attendee', |
|
| 728 | + 'post' => $this->ID(), |
|
| 729 | + ), |
|
| 730 | + admin_url('admin.php') |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * Returns the link to a settings page for the object. |
|
| 737 | + * |
|
| 738 | + * @return string |
|
| 739 | + * @throws EE_Error |
|
| 740 | + * @throws InvalidArgumentException |
|
| 741 | + * @throws InvalidDataTypeException |
|
| 742 | + * @throws InvalidInterfaceException |
|
| 743 | + * @throws ReflectionException |
|
| 744 | + */ |
|
| 745 | + public function get_admin_settings_link() |
|
| 746 | + { |
|
| 747 | + return $this->get_admin_edit_link(); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | + * |
|
| 754 | + * @return string |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws InvalidArgumentException |
|
| 757 | + * @throws ReflectionException |
|
| 758 | + * @throws InvalidDataTypeException |
|
| 759 | + * @throws InvalidInterfaceException |
|
| 760 | + */ |
|
| 761 | + public function get_admin_overview_link() |
|
| 762 | + { |
|
| 763 | + EE_Registry::instance()->load_helper('URL'); |
|
| 764 | + return EEH_URL::add_query_args_and_nonce( |
|
| 765 | + array( |
|
| 766 | + 'page' => 'espresso_registrations', |
|
| 767 | + 'action' => 'contact_list', |
|
| 768 | + ), |
|
| 769 | + admin_url('admin.php') |
|
| 770 | + ); |
|
| 771 | + } |
|
| 772 | 772 | } |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
| 40 | 40 | { |
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 41 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
| 43 | 43 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
| 45 | 45 | } |
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 46 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
| 47 | 47 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
| 48 | 48 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
| 49 | 49 | } |
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 50 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | 51 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
| 52 | 52 | } |
| 53 | 53 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
| 328 | 328 | foreach ($initial_address_fields as $address_field_name) { |
| 329 | 329 | $address_fields_value = $this->get($address_field_name); |
| 330 | - if (! empty($address_fields_value)) { |
|
| 330 | + if ( ! empty($address_fields_value)) { |
|
| 331 | 331 | $full_address_array[] = $address_fields_value; |
| 332 | 332 | } |
| 333 | 333 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | //lastly get the xip |
| 344 | 344 | $zip_value = $this->zip(); |
| 345 | - if (! empty($zip_value)) { |
|
| 345 | + if ( ! empty($zip_value)) { |
|
| 346 | 346 | $full_address_array[] = $zip_value; |
| 347 | 347 | } |
| 348 | 348 | return $full_address_array; |
@@ -624,23 +624,23 @@ discard block |
||
| 624 | 624 | public function billing_info_for_payment_method($payment_method) |
| 625 | 625 | { |
| 626 | 626 | $pm_type = $payment_method->type_obj(); |
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 627 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | 628 | return null; |
| 629 | 629 | } |
| 630 | 630 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
| 631 | - if (! $billing_info) { |
|
| 631 | + if ( ! $billing_info) { |
|
| 632 | 632 | return null; |
| 633 | 633 | } |
| 634 | 634 | $billing_form = $pm_type->billing_form(); |
| 635 | 635 | //double-check the form isn't totally hidden, in which case pretend there is no form |
| 636 | 636 | $form_totally_hidden = true; |
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 637 | + foreach ($billing_form->inputs_in_subsections() as $input) { |
|
| 638 | + if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | 639 | $form_totally_hidden = false; |
| 640 | 640 | break; |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | - if($form_totally_hidden) { |
|
| 643 | + if ($form_totally_hidden) { |
|
| 644 | 644 | return null; |
| 645 | 645 | } |
| 646 | 646 | if ($billing_form instanceof EE_Form_Section_Proper) { |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | public function get_billing_info_postmeta_name($payment_method) |
| 663 | 663 | { |
| 664 | 664 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 665 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
| 666 | 666 | } |
| 667 | 667 | return null; |
| 668 | 668 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | */ |
| 680 | 680 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
| 681 | 681 | { |
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 682 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | 683 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
| 684 | 684 | return false; |
| 685 | 685 | } |
@@ -15,288 +15,288 @@ |
||
| 15 | 15 | abstract class EE_Form_Section_Layout_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Form form section to lay out |
|
| 20 | - * |
|
| 21 | - * @var EE_Form_Section_Proper |
|
| 22 | - */ |
|
| 23 | - protected $_form_section; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * __construct |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The form section on which this strategy is to perform |
|
| 38 | - * |
|
| 39 | - * @param EE_Form_Section_Proper $form |
|
| 40 | - */ |
|
| 41 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | - { |
|
| 43 | - $this->_form_section = $form; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return EE_Form_Section_Proper |
|
| 50 | - */ |
|
| 51 | - public function form_section() |
|
| 52 | - { |
|
| 53 | - return $this->_form_section; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | - * this form. |
|
| 61 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | - * proper subsections. |
|
| 63 | - * Returns the HTML |
|
| 64 | - * |
|
| 65 | - * @return string HTML for displaying |
|
| 66 | - * @throws EE_Error |
|
| 67 | - */ |
|
| 68 | - public function layout_form() |
|
| 69 | - { |
|
| 70 | - $html = ''; |
|
| 71 | - // layout_form_begin |
|
| 72 | - $html .= apply_filters( |
|
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | - $this->layout_form_begin(), |
|
| 75 | - $this->_form_section |
|
| 76 | - ); |
|
| 77 | - // layout_form_loop |
|
| 78 | - $html .= apply_filters( |
|
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | - $this->layout_form_loop(), |
|
| 81 | - $this->_form_section |
|
| 82 | - ); |
|
| 83 | - // layout_form_end |
|
| 84 | - $html .= apply_filters( |
|
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | - $this->layout_form_end(), |
|
| 87 | - $this->_form_section |
|
| 88 | - ); |
|
| 89 | - $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | - return $html; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - * @throws EE_Error |
|
| 98 | - */ |
|
| 99 | - public function layout_form_loop() |
|
| 100 | - { |
|
| 101 | - $html = ''; |
|
| 102 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | - $html .= apply_filters( |
|
| 105 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | - $this->layout_input($subsection), |
|
| 108 | - $this->_form_section, |
|
| 109 | - $subsection |
|
| 110 | - ); |
|
| 111 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | - $html .= apply_filters( |
|
| 113 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | - $this->layout_subsection($subsection), |
|
| 116 | - $this->_form_section, |
|
| 117 | - $subsection |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - return $html; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | - * |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - abstract public function layout_form_begin(); |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | - * |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - abstract public function layout_form_end(); |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | - * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | - * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | - * 'easy-to-layout' inputs |
|
| 151 | - * |
|
| 152 | - * @param EE_Form_Input_Base $input |
|
| 153 | - * @return string html |
|
| 154 | - */ |
|
| 155 | - abstract public function layout_input($input); |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | - * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | - * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | - * |
|
| 164 | - * @param EE_Form_Section_Base $subsection |
|
| 165 | - * @return string html |
|
| 166 | - */ |
|
| 167 | - abstract public function layout_subsection($subsection); |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Gets the HTML for the label tag and its contents for the input |
|
| 173 | - * |
|
| 174 | - * @param EE_Form_Input_Base $input |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public function display_label($input) |
|
| 178 | - { |
|
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | - return ''; |
|
| 181 | - } |
|
| 182 | - $class = $input->required() |
|
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | - : $input->html_label_class(); |
|
| 185 | - $label_text = $input->required() |
|
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | - : $input->html_label_text(); |
|
| 188 | - return '<label id="' |
|
| 189 | - . $input->html_label_id() |
|
| 190 | - . '" class="' |
|
| 191 | - . $class |
|
| 192 | - . '" style="' |
|
| 193 | - . $input->html_label_style() |
|
| 194 | - . '" for="' . $input->html_name() |
|
| 195 | - . '">' |
|
| 196 | - . $label_text |
|
| 197 | - . '</label>'; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | - * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | - * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function display_form_wide_errors() |
|
| 209 | - { |
|
| 210 | - $html = ''; |
|
| 211 | - if ($this->_form_section->get_validation_errors()) { |
|
| 212 | - $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | - //get all the errors on THIS form section (errors which aren't |
|
| 214 | - //for specific inputs, but instead for the entire form section) |
|
| 215 | - foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 217 | - } |
|
| 218 | - $html .= '</div>'; |
|
| 219 | - } |
|
| 220 | - return apply_filters( |
|
| 221 | - 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | - $html, |
|
| 223 | - $this |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | - * Note that if JS is enabled, it should remove these and instead |
|
| 232 | - * populate the form's errors in the jquery validate fashion |
|
| 233 | - * using the localized data provided to the JS |
|
| 234 | - * |
|
| 235 | - * @param EE_Form_Input_Base $input |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function display_errors($input) |
|
| 239 | - { |
|
| 240 | - if ($input->get_validation_errors()) { |
|
| 241 | - return "<label id='" |
|
| 242 | - . $input->html_id() |
|
| 243 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | - . $input->get_validation_error_string() |
|
| 245 | - . '</label>'; |
|
| 246 | - } |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Displays the help span for the specified input |
|
| 254 | - * |
|
| 255 | - * @param EE_Form_Input_Base $input |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function display_help_text($input) |
|
| 259 | - { |
|
| 260 | - $help_text = $input->html_help_text(); |
|
| 261 | - if ($help_text !== '' && $help_text !== null) { |
|
| 262 | - $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | - return '<' |
|
| 264 | - . $tag |
|
| 265 | - . ' id="' |
|
| 266 | - . $input->html_id() |
|
| 267 | - . '-help" class="' |
|
| 268 | - . $input->html_help_class() |
|
| 269 | - . '" style="' |
|
| 270 | - . $input->html_help_style() |
|
| 271 | - . '">' |
|
| 272 | - . $help_text |
|
| 273 | - . '</' |
|
| 274 | - . $tag |
|
| 275 | - . '>'; |
|
| 276 | - } |
|
| 277 | - return ''; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Does an action and hook onto the end of teh form |
|
| 284 | - * |
|
| 285 | - * @param string $html |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function add_form_section_hooks_and_filters($html) |
|
| 289 | - { |
|
| 290 | - // replace dashes and spaces with underscores |
|
| 291 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | - $html = (string) apply_filters( |
|
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | - $html, |
|
| 296 | - $this->_form_section |
|
| 297 | - ); |
|
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | - return $html; |
|
| 301 | - } |
|
| 18 | + /** |
|
| 19 | + * Form form section to lay out |
|
| 20 | + * |
|
| 21 | + * @var EE_Form_Section_Proper |
|
| 22 | + */ |
|
| 23 | + protected $_form_section; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * __construct |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The form section on which this strategy is to perform |
|
| 38 | + * |
|
| 39 | + * @param EE_Form_Section_Proper $form |
|
| 40 | + */ |
|
| 41 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | + { |
|
| 43 | + $this->_form_section = $form; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return EE_Form_Section_Proper |
|
| 50 | + */ |
|
| 51 | + public function form_section() |
|
| 52 | + { |
|
| 53 | + return $this->_form_section; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | + * this form. |
|
| 61 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | + * proper subsections. |
|
| 63 | + * Returns the HTML |
|
| 64 | + * |
|
| 65 | + * @return string HTML for displaying |
|
| 66 | + * @throws EE_Error |
|
| 67 | + */ |
|
| 68 | + public function layout_form() |
|
| 69 | + { |
|
| 70 | + $html = ''; |
|
| 71 | + // layout_form_begin |
|
| 72 | + $html .= apply_filters( |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | + $this->layout_form_begin(), |
|
| 75 | + $this->_form_section |
|
| 76 | + ); |
|
| 77 | + // layout_form_loop |
|
| 78 | + $html .= apply_filters( |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | + $this->layout_form_loop(), |
|
| 81 | + $this->_form_section |
|
| 82 | + ); |
|
| 83 | + // layout_form_end |
|
| 84 | + $html .= apply_filters( |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | + $this->layout_form_end(), |
|
| 87 | + $this->_form_section |
|
| 88 | + ); |
|
| 89 | + $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | + return $html; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + * @throws EE_Error |
|
| 98 | + */ |
|
| 99 | + public function layout_form_loop() |
|
| 100 | + { |
|
| 101 | + $html = ''; |
|
| 102 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | + $html .= apply_filters( |
|
| 105 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | + $this->layout_input($subsection), |
|
| 108 | + $this->_form_section, |
|
| 109 | + $subsection |
|
| 110 | + ); |
|
| 111 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | + $html .= apply_filters( |
|
| 113 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | + $this->layout_subsection($subsection), |
|
| 116 | + $this->_form_section, |
|
| 117 | + $subsection |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + return $html; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | + * |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + abstract public function layout_form_begin(); |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | + * |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + abstract public function layout_form_end(); |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | + * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | + * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | + * 'easy-to-layout' inputs |
|
| 151 | + * |
|
| 152 | + * @param EE_Form_Input_Base $input |
|
| 153 | + * @return string html |
|
| 154 | + */ |
|
| 155 | + abstract public function layout_input($input); |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | + * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | + * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | + * |
|
| 164 | + * @param EE_Form_Section_Base $subsection |
|
| 165 | + * @return string html |
|
| 166 | + */ |
|
| 167 | + abstract public function layout_subsection($subsection); |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Gets the HTML for the label tag and its contents for the input |
|
| 173 | + * |
|
| 174 | + * @param EE_Form_Input_Base $input |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public function display_label($input) |
|
| 178 | + { |
|
| 179 | + if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | + return ''; |
|
| 181 | + } |
|
| 182 | + $class = $input->required() |
|
| 183 | + ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | + : $input->html_label_class(); |
|
| 185 | + $label_text = $input->required() |
|
| 186 | + ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | + : $input->html_label_text(); |
|
| 188 | + return '<label id="' |
|
| 189 | + . $input->html_label_id() |
|
| 190 | + . '" class="' |
|
| 191 | + . $class |
|
| 192 | + . '" style="' |
|
| 193 | + . $input->html_label_style() |
|
| 194 | + . '" for="' . $input->html_name() |
|
| 195 | + . '">' |
|
| 196 | + . $label_text |
|
| 197 | + . '</label>'; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | + * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | + * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function display_form_wide_errors() |
|
| 209 | + { |
|
| 210 | + $html = ''; |
|
| 211 | + if ($this->_form_section->get_validation_errors()) { |
|
| 212 | + $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | + //get all the errors on THIS form section (errors which aren't |
|
| 214 | + //for specific inputs, but instead for the entire form section) |
|
| 215 | + foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | + $html .= $error->getMessage() . '<br>'; |
|
| 217 | + } |
|
| 218 | + $html .= '</div>'; |
|
| 219 | + } |
|
| 220 | + return apply_filters( |
|
| 221 | + 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | + $html, |
|
| 223 | + $this |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | + * Note that if JS is enabled, it should remove these and instead |
|
| 232 | + * populate the form's errors in the jquery validate fashion |
|
| 233 | + * using the localized data provided to the JS |
|
| 234 | + * |
|
| 235 | + * @param EE_Form_Input_Base $input |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function display_errors($input) |
|
| 239 | + { |
|
| 240 | + if ($input->get_validation_errors()) { |
|
| 241 | + return "<label id='" |
|
| 242 | + . $input->html_id() |
|
| 243 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | + . $input->get_validation_error_string() |
|
| 245 | + . '</label>'; |
|
| 246 | + } |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Displays the help span for the specified input |
|
| 254 | + * |
|
| 255 | + * @param EE_Form_Input_Base $input |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function display_help_text($input) |
|
| 259 | + { |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | + if ($help_text !== '' && $help_text !== null) { |
|
| 262 | + $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | + return '<' |
|
| 264 | + . $tag |
|
| 265 | + . ' id="' |
|
| 266 | + . $input->html_id() |
|
| 267 | + . '-help" class="' |
|
| 268 | + . $input->html_help_class() |
|
| 269 | + . '" style="' |
|
| 270 | + . $input->html_help_style() |
|
| 271 | + . '">' |
|
| 272 | + . $help_text |
|
| 273 | + . '</' |
|
| 274 | + . $tag |
|
| 275 | + . '>'; |
|
| 276 | + } |
|
| 277 | + return ''; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Does an action and hook onto the end of teh form |
|
| 284 | + * |
|
| 285 | + * @param string $html |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function add_form_section_hooks_and_filters($html) |
|
| 289 | + { |
|
| 290 | + // replace dashes and spaces with underscores |
|
| 291 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | + $html = (string) apply_filters( |
|
| 294 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | + $html, |
|
| 296 | + $this->_form_section |
|
| 297 | + ); |
|
| 298 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | + return $html; |
|
| 301 | + } |
|
| 302 | 302 | } |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | $html = ''; |
| 71 | 71 | // layout_form_begin |
| 72 | 72 | $html .= apply_filters( |
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
| 74 | 74 | $this->layout_form_begin(), |
| 75 | 75 | $this->_form_section |
| 76 | 76 | ); |
| 77 | 77 | // layout_form_loop |
| 78 | 78 | $html .= apply_filters( |
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
| 80 | 80 | $this->layout_form_loop(), |
| 81 | 81 | $this->_form_section |
| 82 | 82 | ); |
| 83 | 83 | // layout_form_end |
| 84 | 84 | $html .= apply_filters( |
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
| 86 | 86 | $this->layout_form_end(), |
| 87 | 87 | $this->_form_section |
| 88 | 88 | ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | if ($subsection instanceof EE_Form_Input_Base) { |
| 104 | 104 | $html .= apply_filters( |
| 105 | 105 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 106 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 107 | 107 | $this->layout_input($subsection), |
| 108 | 108 | $this->_form_section, |
| 109 | 109 | $subsection |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
| 112 | 112 | $html .= apply_filters( |
| 113 | 113 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 114 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 115 | 115 | $this->layout_subsection($subsection), |
| 116 | 116 | $this->_form_section, |
| 117 | 117 | $subsection |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function display_label($input) |
| 178 | 178 | { |
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 179 | + if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 180 | 180 | return ''; |
| 181 | 181 | } |
| 182 | 182 | $class = $input->required() |
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 183 | + ? 'ee-required-label '.$input->html_label_class() |
|
| 184 | 184 | : $input->html_label_class(); |
| 185 | 185 | $label_text = $input->required() |
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 186 | + ? $input->html_label_text().'<span class="ee-asterisk">*</span>' |
|
| 187 | 187 | : $input->html_label_text(); |
| 188 | 188 | return '<label id="' |
| 189 | 189 | . $input->html_label_id() |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | . $class |
| 192 | 192 | . '" style="' |
| 193 | 193 | . $input->html_label_style() |
| 194 | - . '" for="' . $input->html_name() |
|
| 194 | + . '" for="'.$input->html_name() |
|
| 195 | 195 | . '">' |
| 196 | 196 | . $label_text |
| 197 | 197 | . '</label>'; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | //get all the errors on THIS form section (errors which aren't |
| 214 | 214 | //for specific inputs, but instead for the entire form section) |
| 215 | 215 | foreach ($this->_form_section->get_validation_errors() as $error) { |
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 216 | + $html .= $error->getMessage().'<br>'; |
|
| 217 | 217 | } |
| 218 | 218 | $html .= '</div>'; |
| 219 | 219 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function display_help_text($input) |
| 259 | 259 | { |
| 260 | - $help_text = $input->html_help_text(); |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | 261 | if ($help_text !== '' && $help_text !== null) { |
| 262 | 262 | $tag = is_admin() ? 'p' : 'span'; |
| 263 | 263 | return '<' |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | { |
| 290 | 290 | // replace dashes and spaces with underscores |
| 291 | 291 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
| 293 | 293 | $html = (string) apply_filters( |
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 294 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
| 295 | 295 | $html, |
| 296 | 296 | $this->_form_section |
| 297 | 297 | ); |
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 298 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
| 300 | 300 | return $html; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -20,4205 +20,4205 @@ |
||
| 20 | 20 | { |
| 21 | 21 | |
| 22 | 22 | |
| 23 | - //set in _init_page_props() |
|
| 24 | - public $page_slug; |
|
| 23 | + //set in _init_page_props() |
|
| 24 | + public $page_slug; |
|
| 25 | 25 | |
| 26 | - public $page_label; |
|
| 26 | + public $page_label; |
|
| 27 | 27 | |
| 28 | - public $page_folder; |
|
| 28 | + public $page_folder; |
|
| 29 | 29 | |
| 30 | - //set in define_page_props() |
|
| 31 | - protected $_admin_base_url; |
|
| 30 | + //set in define_page_props() |
|
| 31 | + protected $_admin_base_url; |
|
| 32 | 32 | |
| 33 | - protected $_admin_base_path; |
|
| 33 | + protected $_admin_base_path; |
|
| 34 | 34 | |
| 35 | - protected $_admin_page_title; |
|
| 35 | + protected $_admin_page_title; |
|
| 36 | 36 | |
| 37 | - protected $_labels; |
|
| 37 | + protected $_labels; |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - //set early within EE_Admin_Init |
|
| 41 | - protected $_wp_page_slug; |
|
| 40 | + //set early within EE_Admin_Init |
|
| 41 | + protected $_wp_page_slug; |
|
| 42 | 42 | |
| 43 | - //navtabs |
|
| 44 | - protected $_nav_tabs; |
|
| 43 | + //navtabs |
|
| 44 | + protected $_nav_tabs; |
|
| 45 | 45 | |
| 46 | - protected $_default_nav_tab_name; |
|
| 46 | + protected $_default_nav_tab_name; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var array $_help_tour |
|
| 50 | - */ |
|
| 51 | - protected $_help_tour = array(); |
|
| 48 | + /** |
|
| 49 | + * @var array $_help_tour |
|
| 50 | + */ |
|
| 51 | + protected $_help_tour = array(); |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - //template variables (used by templates) |
|
| 55 | - protected $_template_path; |
|
| 54 | + //template variables (used by templates) |
|
| 55 | + protected $_template_path; |
|
| 56 | 56 | |
| 57 | - protected $_column_template_path; |
|
| 57 | + protected $_column_template_path; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var array $_template_args |
|
| 61 | - */ |
|
| 62 | - protected $_template_args = array(); |
|
| 59 | + /** |
|
| 60 | + * @var array $_template_args |
|
| 61 | + */ |
|
| 62 | + protected $_template_args = array(); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * this will hold the list table object for a given view. |
|
| 66 | - * |
|
| 67 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 68 | - */ |
|
| 69 | - protected $_list_table_object; |
|
| 64 | + /** |
|
| 65 | + * this will hold the list table object for a given view. |
|
| 66 | + * |
|
| 67 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 68 | + */ |
|
| 69 | + protected $_list_table_object; |
|
| 70 | 70 | |
| 71 | - //bools |
|
| 72 | - protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 71 | + //bools |
|
| 72 | + protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 73 | 73 | |
| 74 | - protected $_routing; |
|
| 74 | + protected $_routing; |
|
| 75 | 75 | |
| 76 | - //list table args |
|
| 77 | - protected $_view; |
|
| 76 | + //list table args |
|
| 77 | + protected $_view; |
|
| 78 | 78 | |
| 79 | - protected $_views; |
|
| 79 | + protected $_views; |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - //action => method pairs used for routing incoming requests |
|
| 83 | - protected $_page_routes; |
|
| 82 | + //action => method pairs used for routing incoming requests |
|
| 83 | + protected $_page_routes; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @var array $_page_config |
|
| 87 | - */ |
|
| 88 | - protected $_page_config; |
|
| 85 | + /** |
|
| 86 | + * @var array $_page_config |
|
| 87 | + */ |
|
| 88 | + protected $_page_config; |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * the current page route and route config |
|
| 92 | - * |
|
| 93 | - * @var string $_route |
|
| 94 | - */ |
|
| 95 | - protected $_route; |
|
| 90 | + /** |
|
| 91 | + * the current page route and route config |
|
| 92 | + * |
|
| 93 | + * @var string $_route |
|
| 94 | + */ |
|
| 95 | + protected $_route; |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @var string $_cpt_route |
|
| 99 | - */ |
|
| 100 | - protected $_cpt_route; |
|
| 97 | + /** |
|
| 98 | + * @var string $_cpt_route |
|
| 99 | + */ |
|
| 100 | + protected $_cpt_route; |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @var array $_route_config |
|
| 104 | - */ |
|
| 105 | - protected $_route_config; |
|
| 102 | + /** |
|
| 103 | + * @var array $_route_config |
|
| 104 | + */ |
|
| 105 | + protected $_route_config; |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 109 | - * actions. |
|
| 110 | - * |
|
| 111 | - * @since 4.6.x |
|
| 112 | - * @var array. |
|
| 113 | - */ |
|
| 114 | - protected $_default_route_query_args; |
|
| 115 | - |
|
| 116 | - //set via request page and action args. |
|
| 117 | - protected $_current_page; |
|
| 107 | + /** |
|
| 108 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 109 | + * actions. |
|
| 110 | + * |
|
| 111 | + * @since 4.6.x |
|
| 112 | + * @var array. |
|
| 113 | + */ |
|
| 114 | + protected $_default_route_query_args; |
|
| 115 | + |
|
| 116 | + //set via request page and action args. |
|
| 117 | + protected $_current_page; |
|
| 118 | 118 | |
| 119 | - protected $_current_view; |
|
| 119 | + protected $_current_view; |
|
| 120 | 120 | |
| 121 | - protected $_current_page_view_url; |
|
| 121 | + protected $_current_page_view_url; |
|
| 122 | 122 | |
| 123 | - //sanitized request action (and nonce) |
|
| 123 | + //sanitized request action (and nonce) |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @var string $_req_action |
|
| 127 | - */ |
|
| 128 | - protected $_req_action; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var string $_req_nonce |
|
| 132 | - */ |
|
| 133 | - protected $_req_nonce; |
|
| 134 | - |
|
| 135 | - //search related |
|
| 136 | - protected $_search_btn_label; |
|
| 137 | - |
|
| 138 | - protected $_search_box_callback; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * WP Current Screen object |
|
| 142 | - * |
|
| 143 | - * @var WP_Screen |
|
| 144 | - */ |
|
| 145 | - protected $_current_screen; |
|
| 146 | - |
|
| 147 | - //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 148 | - protected $_hook_obj; |
|
| 149 | - |
|
| 150 | - //for holding incoming request data |
|
| 151 | - protected $_req_data; |
|
| 152 | - |
|
| 153 | - // yes / no array for admin form fields |
|
| 154 | - protected $_yes_no_values = array(); |
|
| 155 | - |
|
| 156 | - //some default things shared by all child classes |
|
| 157 | - protected $_default_espresso_metaboxes; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * EE_Registry Object |
|
| 161 | - * |
|
| 162 | - * @var EE_Registry |
|
| 163 | - */ |
|
| 164 | - protected $EE = null; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 170 | - * |
|
| 171 | - * @var boolean |
|
| 172 | - */ |
|
| 173 | - protected $_is_caf = false; |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @Constructor |
|
| 179 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 180 | - * @throws EE_Error |
|
| 181 | - * @throws InvalidArgumentException |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - * @throws InvalidDataTypeException |
|
| 184 | - * @throws InvalidInterfaceException |
|
| 185 | - */ |
|
| 186 | - public function __construct($routing = true) |
|
| 187 | - { |
|
| 188 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 189 | - $this->_is_caf = true; |
|
| 190 | - } |
|
| 191 | - $this->_yes_no_values = array( |
|
| 192 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 193 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 194 | - ); |
|
| 195 | - //set the _req_data property. |
|
| 196 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 197 | - //routing enabled? |
|
| 198 | - $this->_routing = $routing; |
|
| 199 | - //set initial page props (child method) |
|
| 200 | - $this->_init_page_props(); |
|
| 201 | - //set global defaults |
|
| 202 | - $this->_set_defaults(); |
|
| 203 | - //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 204 | - $this->_global_ajax_hooks(); |
|
| 205 | - $this->_ajax_hooks(); |
|
| 206 | - //other_page_hooks have to be early too. |
|
| 207 | - $this->_do_other_page_hooks(); |
|
| 208 | - //This just allows us to have extending classes do something specific |
|
| 209 | - // before the parent constructor runs _page_setup(). |
|
| 210 | - if (method_exists($this, '_before_page_setup')) { |
|
| 211 | - $this->_before_page_setup(); |
|
| 212 | - } |
|
| 213 | - //set up page dependencies |
|
| 214 | - $this->_page_setup(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * _init_page_props |
|
| 221 | - * Child classes use to set at least the following properties: |
|
| 222 | - * $page_slug. |
|
| 223 | - * $page_label. |
|
| 224 | - * |
|
| 225 | - * @abstract |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - abstract protected function _init_page_props(); |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * _ajax_hooks |
|
| 234 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 235 | - * Note: within the ajax callback methods. |
|
| 236 | - * |
|
| 237 | - * @abstract |
|
| 238 | - * @return void |
|
| 239 | - */ |
|
| 240 | - abstract protected function _ajax_hooks(); |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * _define_page_props |
|
| 246 | - * child classes define page properties in here. Must include at least: |
|
| 247 | - * $_admin_base_url = base_url for all admin pages |
|
| 248 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 249 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 250 | - * array( |
|
| 251 | - * 'buttons' => array( |
|
| 252 | - * 'add' => esc_html__('label for add new button'), |
|
| 253 | - * 'edit' => esc_html__('label for edit button'), |
|
| 254 | - * 'delete' => esc_html__('label for delete button') |
|
| 255 | - * ) |
|
| 256 | - * ) |
|
| 257 | - * |
|
| 258 | - * @abstract |
|
| 259 | - * @return void |
|
| 260 | - */ |
|
| 261 | - abstract protected function _define_page_props(); |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * _set_page_routes |
|
| 267 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 268 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 269 | - * have a 'default' route. Here's the format |
|
| 270 | - * $this->_page_routes = array( |
|
| 271 | - * 'default' => array( |
|
| 272 | - * 'func' => '_default_method_handling_route', |
|
| 273 | - * 'args' => array('array','of','args'), |
|
| 274 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 275 | - * ajax request, backend processing) |
|
| 276 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 277 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 278 | - * headers sent route. |
|
| 279 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 280 | - * this route. |
|
| 281 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 282 | - * checks). |
|
| 283 | - * ), |
|
| 284 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 285 | - * handling method. |
|
| 286 | - * ) |
|
| 287 | - * ) |
|
| 288 | - * |
|
| 289 | - * @abstract |
|
| 290 | - * @return void |
|
| 291 | - */ |
|
| 292 | - abstract protected function _set_page_routes(); |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * _set_page_config |
|
| 298 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 299 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 300 | - * $this->_page_config = array( |
|
| 301 | - * 'default' => array( |
|
| 302 | - * 'labels' => array( |
|
| 303 | - * 'buttons' => array( |
|
| 304 | - * 'add' => esc_html__('label for adding item'), |
|
| 305 | - * 'edit' => esc_html__('label for editing item'), |
|
| 306 | - * 'delete' => esc_html__('label for deleting item') |
|
| 307 | - * ), |
|
| 308 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 309 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 310 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 311 | - * _define_page_props() method |
|
| 312 | - * 'nav' => array( |
|
| 313 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 314 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 315 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 316 | - * 'order' => 10, //required to indicate tab position. |
|
| 317 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 318 | - * displayed then add this parameter. |
|
| 319 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 320 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 321 | - * metaboxes set for eventespresso admin pages. |
|
| 322 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 323 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 324 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 325 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 326 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 327 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 328 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 329 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 330 | - * want to display. |
|
| 331 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 332 | - * 'tab_id' => array( |
|
| 333 | - * 'title' => 'tab_title', |
|
| 334 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 335 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 336 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 337 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 338 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 339 | - * attempt to use the callback which should match the name of a method in the class |
|
| 340 | - * ), |
|
| 341 | - * 'tab2_id' => array( |
|
| 342 | - * 'title' => 'tab2 title', |
|
| 343 | - * 'filename' => 'file_name_2' |
|
| 344 | - * 'callback' => 'callback_method_for_content', |
|
| 345 | - * ), |
|
| 346 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 347 | - * help tab area on an admin page. @link |
|
| 348 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 349 | - * 'help_tour' => array( |
|
| 350 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 351 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 352 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 353 | - * ), |
|
| 354 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 355 | - * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 356 | - * just set |
|
| 357 | - * 'require_nonce' to FALSE |
|
| 358 | - * ) |
|
| 359 | - * ) |
|
| 360 | - * |
|
| 361 | - * @abstract |
|
| 362 | - * @return void |
|
| 363 | - */ |
|
| 364 | - abstract protected function _set_page_config(); |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** end sample help_tour methods **/ |
|
| 371 | - /** |
|
| 372 | - * _add_screen_options |
|
| 373 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 374 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 375 | - * to a particular view. |
|
| 376 | - * |
|
| 377 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 378 | - * see also WP_Screen object documents... |
|
| 379 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 380 | - * @abstract |
|
| 381 | - * @return void |
|
| 382 | - */ |
|
| 383 | - abstract protected function _add_screen_options(); |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * _add_feature_pointers |
|
| 389 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 390 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 391 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 392 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 393 | - * extended) also see: |
|
| 394 | - * |
|
| 395 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 396 | - * @abstract |
|
| 397 | - * @return void |
|
| 398 | - */ |
|
| 399 | - abstract protected function _add_feature_pointers(); |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * load_scripts_styles |
|
| 405 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 406 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 407 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 408 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 409 | - * |
|
| 410 | - * @abstract |
|
| 411 | - * @return void |
|
| 412 | - */ |
|
| 413 | - abstract public function load_scripts_styles(); |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * admin_init |
|
| 419 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 420 | - * all pages/views loaded by child class. |
|
| 421 | - * |
|
| 422 | - * @abstract |
|
| 423 | - * @return void |
|
| 424 | - */ |
|
| 425 | - abstract public function admin_init(); |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * admin_notices |
|
| 431 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 432 | - * all pages/views loaded by child class. |
|
| 433 | - * |
|
| 434 | - * @abstract |
|
| 435 | - * @return void |
|
| 436 | - */ |
|
| 437 | - abstract public function admin_notices(); |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * admin_footer_scripts |
|
| 443 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 444 | - * will apply to all pages/views loaded by child class. |
|
| 445 | - * |
|
| 446 | - * @return void |
|
| 447 | - */ |
|
| 448 | - abstract public function admin_footer_scripts(); |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * admin_footer |
|
| 454 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 455 | - * apply to all pages/views loaded by child class. |
|
| 456 | - * |
|
| 457 | - * @return void |
|
| 458 | - */ |
|
| 459 | - public function admin_footer() |
|
| 460 | - { |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * _global_ajax_hooks |
|
| 467 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 468 | - * Note: within the ajax callback methods. |
|
| 469 | - * |
|
| 470 | - * @abstract |
|
| 471 | - * @return void |
|
| 472 | - */ |
|
| 473 | - protected function _global_ajax_hooks() |
|
| 474 | - { |
|
| 475 | - //for lazy loading of metabox content |
|
| 476 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - public function ajax_metabox_content() |
|
| 482 | - { |
|
| 483 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 484 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 485 | - self::cached_rss_display($contentid, $url); |
|
| 486 | - wp_die(); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * _page_setup |
|
| 493 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 494 | - * doesn't match the object. |
|
| 495 | - * |
|
| 496 | - * @final |
|
| 497 | - * @return void |
|
| 498 | - * @throws EE_Error |
|
| 499 | - * @throws InvalidArgumentException |
|
| 500 | - * @throws ReflectionException |
|
| 501 | - * @throws InvalidDataTypeException |
|
| 502 | - * @throws InvalidInterfaceException |
|
| 503 | - */ |
|
| 504 | - final protected function _page_setup() |
|
| 505 | - { |
|
| 506 | - //requires? |
|
| 507 | - //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 508 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 509 | - //next verify if we need to load anything... |
|
| 510 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 511 | - $this->page_folder = strtolower( |
|
| 512 | - str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 513 | - ); |
|
| 514 | - global $ee_menu_slugs; |
|
| 515 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 516 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 517 | - return; |
|
| 518 | - } |
|
| 519 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 520 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 521 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 522 | - ? $this->_req_data['action2'] |
|
| 523 | - : $this->_req_data['action']; |
|
| 524 | - } |
|
| 525 | - // then set blank or -1 action values to 'default' |
|
| 526 | - $this->_req_action = isset($this->_req_data['action']) |
|
| 527 | - && ! empty($this->_req_data['action']) |
|
| 528 | - && $this->_req_data['action'] !== '-1' |
|
| 529 | - ? sanitize_key($this->_req_data['action']) |
|
| 530 | - : 'default'; |
|
| 531 | - // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 532 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 533 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 534 | - ? $this->_req_data['route'] : $this->_req_action; |
|
| 535 | - //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 536 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 537 | - ? $this->_req_data['route'] |
|
| 538 | - : $this->_req_action; |
|
| 539 | - $this->_current_view = $this->_req_action; |
|
| 540 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 541 | - $this->_define_page_props(); |
|
| 542 | - $this->_current_page_view_url = add_query_arg( |
|
| 543 | - array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 544 | - $this->_admin_base_url |
|
| 545 | - ); |
|
| 546 | - //default things |
|
| 547 | - $this->_default_espresso_metaboxes = array( |
|
| 548 | - '_espresso_news_post_box', |
|
| 549 | - '_espresso_links_post_box', |
|
| 550 | - '_espresso_ratings_request', |
|
| 551 | - '_espresso_sponsors_post_box', |
|
| 552 | - ); |
|
| 553 | - //set page configs |
|
| 554 | - $this->_set_page_routes(); |
|
| 555 | - $this->_set_page_config(); |
|
| 556 | - //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 557 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 558 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 559 | - } |
|
| 560 | - //for caffeinated and other extended functionality. |
|
| 561 | - // If there is a _extend_page_config method |
|
| 562 | - // then let's run that to modify the all the various page configuration arrays |
|
| 563 | - if (method_exists($this, '_extend_page_config')) { |
|
| 564 | - $this->_extend_page_config(); |
|
| 565 | - } |
|
| 566 | - //for CPT and other extended functionality. |
|
| 567 | - // If there is an _extend_page_config_for_cpt |
|
| 568 | - // then let's run that to modify all the various page configuration arrays. |
|
| 569 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | - $this->_extend_page_config_for_cpt(); |
|
| 571 | - } |
|
| 572 | - //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | - $this->_page_routes = apply_filters( |
|
| 574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | - $this->_page_routes, |
|
| 576 | - $this |
|
| 577 | - ); |
|
| 578 | - $this->_page_config = apply_filters( |
|
| 579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | - $this->_page_config, |
|
| 581 | - $this |
|
| 582 | - ); |
|
| 583 | - //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | - if ( |
|
| 586 | - method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view) |
|
| 587 | - ) { |
|
| 588 | - add_action( |
|
| 589 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 590 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 591 | - 10, |
|
| 592 | - 2 |
|
| 593 | - ); |
|
| 594 | - } |
|
| 595 | - //next route only if routing enabled |
|
| 596 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 597 | - $this->_verify_routes(); |
|
| 598 | - //next let's just check user_access and kill if no access |
|
| 599 | - $this->check_user_access(); |
|
| 600 | - if ($this->_is_UI_request) { |
|
| 601 | - //admin_init stuff - global, all views for this page class, specific view |
|
| 602 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 603 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 604 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 605 | - } |
|
| 606 | - } else { |
|
| 607 | - //hijack regular WP loading and route admin request immediately |
|
| 608 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 609 | - $this->route_admin_request(); |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 618 | - * |
|
| 619 | - * @return void |
|
| 620 | - * @throws ReflectionException |
|
| 621 | - * @throws EE_Error |
|
| 622 | - */ |
|
| 623 | - private function _do_other_page_hooks() |
|
| 624 | - { |
|
| 625 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 626 | - foreach ($registered_pages as $page) { |
|
| 627 | - //now let's setup the file name and class that should be present |
|
| 628 | - $classname = str_replace('.class.php', '', $page); |
|
| 629 | - //autoloaders should take care of loading file |
|
| 630 | - if (! class_exists($classname)) { |
|
| 631 | - $error_msg[] = sprintf( |
|
| 632 | - esc_html__( |
|
| 633 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 634 | - 'event_espresso' |
|
| 635 | - ), |
|
| 636 | - $page |
|
| 637 | - ); |
|
| 638 | - $error_msg[] = $error_msg[0] |
|
| 639 | - . "\r\n" |
|
| 640 | - . sprintf( |
|
| 641 | - esc_html__( |
|
| 642 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 643 | - 'event_espresso' |
|
| 644 | - ), |
|
| 645 | - $page, |
|
| 646 | - '<br />', |
|
| 647 | - '<strong>' . $classname . '</strong>' |
|
| 648 | - ); |
|
| 649 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 650 | - } |
|
| 651 | - $a = new ReflectionClass($classname); |
|
| 652 | - //notice we are passing the instance of this class to the hook object. |
|
| 653 | - $hookobj[] = $a->newInstance($this); |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - public function load_page_dependencies() |
|
| 660 | - { |
|
| 661 | - try { |
|
| 662 | - $this->_load_page_dependencies(); |
|
| 663 | - } catch (EE_Error $e) { |
|
| 664 | - $e->get_error(); |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * load_page_dependencies |
|
| 672 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 673 | - * |
|
| 674 | - * @return void |
|
| 675 | - * @throws DomainException |
|
| 676 | - * @throws EE_Error |
|
| 677 | - * @throws InvalidArgumentException |
|
| 678 | - * @throws InvalidDataTypeException |
|
| 679 | - * @throws InvalidInterfaceException |
|
| 680 | - * @throws ReflectionException |
|
| 681 | - */ |
|
| 682 | - protected function _load_page_dependencies() |
|
| 683 | - { |
|
| 684 | - //let's set the current_screen and screen options to override what WP set |
|
| 685 | - $this->_current_screen = get_current_screen(); |
|
| 686 | - //load admin_notices - global, page class, and view specific |
|
| 687 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 688 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 689 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 690 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 691 | - } |
|
| 692 | - //load network admin_notices - global, page class, and view specific |
|
| 693 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 694 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 695 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 696 | - } |
|
| 697 | - //this will save any per_page screen options if they are present |
|
| 698 | - $this->_set_per_page_screen_options(); |
|
| 699 | - //setup list table properties |
|
| 700 | - $this->_set_list_table(); |
|
| 701 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 702 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 703 | - $this->_add_registered_meta_boxes(); |
|
| 704 | - $this->_add_screen_columns(); |
|
| 705 | - //add screen options - global, page child class, and view specific |
|
| 706 | - $this->_add_global_screen_options(); |
|
| 707 | - $this->_add_screen_options(); |
|
| 708 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 709 | - if (method_exists($this, $add_screen_options )) { |
|
| 710 | - $this->{$add_screen_options}(); |
|
| 711 | - } |
|
| 712 | - //add help tab(s) and tours- set via page_config and qtips. |
|
| 713 | - $this->_add_help_tour(); |
|
| 714 | - $this->_add_help_tabs(); |
|
| 715 | - $this->_add_qtips(); |
|
| 716 | - //add feature_pointers - global, page child class, and view specific |
|
| 717 | - $this->_add_feature_pointers(); |
|
| 718 | - $this->_add_global_feature_pointers(); |
|
| 719 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 720 | - if (method_exists($this, $add_feature_pointer )) { |
|
| 721 | - $this->{$add_feature_pointer}(); |
|
| 722 | - } |
|
| 723 | - //enqueue scripts/styles - global, page class, and view specific |
|
| 724 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 725 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 726 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 727 | - add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 728 | - } |
|
| 729 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 730 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 731 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 732 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 733 | - // is a good use case. Notice the late priority we're giving these |
|
| 734 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 735 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 736 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 737 | - add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 738 | - } |
|
| 739 | - //admin footer scripts |
|
| 740 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 741 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 742 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 743 | - add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 744 | - } |
|
| 745 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 746 | - //targeted hook |
|
| 747 | - do_action( |
|
| 748 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 749 | - |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * _set_defaults |
|
| 757 | - * This sets some global defaults for class properties. |
|
| 758 | - */ |
|
| 759 | - private function _set_defaults() |
|
| 760 | - { |
|
| 761 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 762 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 763 | - $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 764 | - $this->_page_config = $this->_default_route_query_args = array(); |
|
| 765 | - $this->_default_nav_tab_name = 'overview'; |
|
| 766 | - //init template args |
|
| 767 | - $this->_template_args = array( |
|
| 768 | - 'admin_page_header' => '', |
|
| 769 | - 'admin_page_content' => '', |
|
| 770 | - 'post_body_content' => '', |
|
| 771 | - 'before_list_table' => '', |
|
| 772 | - 'after_list_table' => '', |
|
| 773 | - ); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * route_admin_request |
|
| 780 | - * |
|
| 781 | - * @see _route_admin_request() |
|
| 782 | - * @return exception|void error |
|
| 783 | - * @throws InvalidArgumentException |
|
| 784 | - * @throws InvalidInterfaceException |
|
| 785 | - * @throws InvalidDataTypeException |
|
| 786 | - * @throws EE_Error |
|
| 787 | - * @throws ReflectionException |
|
| 788 | - */ |
|
| 789 | - public function route_admin_request() |
|
| 790 | - { |
|
| 791 | - try { |
|
| 792 | - $this->_route_admin_request(); |
|
| 793 | - } catch (EE_Error $e) { |
|
| 794 | - $e->get_error(); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - public function set_wp_page_slug($wp_page_slug) |
|
| 801 | - { |
|
| 802 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 803 | - //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 804 | - if (is_network_admin()) { |
|
| 805 | - $this->_wp_page_slug .= '-network'; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * _verify_routes |
|
| 813 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 814 | - * we know if we need to drop out. |
|
| 815 | - * |
|
| 816 | - * @return bool |
|
| 817 | - * @throws EE_Error |
|
| 818 | - */ |
|
| 819 | - protected function _verify_routes() |
|
| 820 | - { |
|
| 821 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 822 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - $this->_route = false; |
|
| 826 | - // check that the page_routes array is not empty |
|
| 827 | - if (empty($this->_page_routes)) { |
|
| 828 | - // user error msg |
|
| 829 | - $error_msg = sprintf( |
|
| 830 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 831 | - $this->_admin_page_title |
|
| 832 | - ); |
|
| 833 | - // developer error msg |
|
| 834 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 835 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 836 | - 'event_espresso' |
|
| 837 | - ); |
|
| 838 | - throw new EE_Error($error_msg); |
|
| 839 | - } |
|
| 840 | - // and that the requested page route exists |
|
| 841 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 842 | - $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 843 | - $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 844 | - ? $this->_page_config[$this->_req_action] : array(); |
|
| 845 | - } else { |
|
| 846 | - // user error msg |
|
| 847 | - $error_msg = sprintf( |
|
| 848 | - esc_html__( |
|
| 849 | - 'The requested page route does not exist for the %s admin page.', |
|
| 850 | - 'event_espresso' |
|
| 851 | - ), |
|
| 852 | - $this->_admin_page_title |
|
| 853 | - ); |
|
| 854 | - // developer error msg |
|
| 855 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 856 | - esc_html__( |
|
| 857 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 858 | - 'event_espresso' |
|
| 859 | - ), |
|
| 860 | - $this->_req_action |
|
| 861 | - ); |
|
| 862 | - throw new EE_Error($error_msg); |
|
| 863 | - } |
|
| 864 | - // and that a default route exists |
|
| 865 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 866 | - // user error msg |
|
| 867 | - $error_msg = sprintf( |
|
| 868 | - esc_html__( |
|
| 869 | - 'A default page route has not been set for the % admin page.', |
|
| 870 | - 'event_espresso' |
|
| 871 | - ), |
|
| 872 | - $this->_admin_page_title |
|
| 873 | - ); |
|
| 874 | - // developer error msg |
|
| 875 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 876 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 877 | - 'event_espresso' |
|
| 878 | - ); |
|
| 879 | - throw new EE_Error($error_msg); |
|
| 880 | - } |
|
| 881 | - //first lets' catch if the UI request has EVER been set. |
|
| 882 | - if ($this->_is_UI_request === null) { |
|
| 883 | - //lets set if this is a UI request or not. |
|
| 884 | - $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 885 | - //wait a minute... we might have a noheader in the route array |
|
| 886 | - $this->_is_UI_request = is_array($this->_route) |
|
| 887 | - && isset($this->_route['noheader']) |
|
| 888 | - && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 889 | - } |
|
| 890 | - $this->_set_current_labels(); |
|
| 891 | - return true; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - /** |
|
| 897 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 898 | - * |
|
| 899 | - * @param string $route the route name we're verifying |
|
| 900 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 901 | - * @throws EE_Error |
|
| 902 | - */ |
|
| 903 | - protected function _verify_route($route) |
|
| 904 | - { |
|
| 905 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 906 | - return true; |
|
| 907 | - } |
|
| 908 | - // user error msg |
|
| 909 | - $error_msg = sprintf( |
|
| 910 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 911 | - $this->_admin_page_title |
|
| 912 | - ); |
|
| 913 | - // developer error msg |
|
| 914 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 915 | - esc_html__( |
|
| 916 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 917 | - 'event_espresso' |
|
| 918 | - ), |
|
| 919 | - $route |
|
| 920 | - ); |
|
| 921 | - throw new EE_Error($error_msg); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * perform nonce verification |
|
| 928 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 929 | - * using this method (and save retyping!) |
|
| 930 | - * |
|
| 931 | - * @param string $nonce The nonce sent |
|
| 932 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 933 | - * @return void |
|
| 934 | - * @throws EE_Error |
|
| 935 | - */ |
|
| 936 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 937 | - { |
|
| 938 | - // verify nonce against expected value |
|
| 939 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 940 | - // these are not the droids you are looking for !!! |
|
| 941 | - $msg = sprintf( |
|
| 942 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 943 | - '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 944 | - '</a>' |
|
| 945 | - ); |
|
| 946 | - if (WP_DEBUG) { |
|
| 947 | - $msg .= "\n " . sprintf( |
|
| 948 | - esc_html__( |
|
| 949 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 950 | - 'event_espresso' |
|
| 951 | - ), |
|
| 952 | - __CLASS__ |
|
| 953 | - ); |
|
| 954 | - } |
|
| 955 | - if (! defined('DOING_AJAX')) { |
|
| 956 | - wp_die($msg); |
|
| 957 | - } else { |
|
| 958 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 959 | - $this->_return_json(); |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * _route_admin_request() |
|
| 968 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 969 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 970 | - * in the page routes and then will try to load the corresponding method. |
|
| 971 | - * |
|
| 972 | - * @return void |
|
| 973 | - * @throws EE_Error |
|
| 974 | - * @throws InvalidArgumentException |
|
| 975 | - * @throws InvalidDataTypeException |
|
| 976 | - * @throws InvalidInterfaceException |
|
| 977 | - * @throws ReflectionException |
|
| 978 | - */ |
|
| 979 | - protected function _route_admin_request() |
|
| 980 | - { |
|
| 981 | - if (! $this->_is_UI_request) { |
|
| 982 | - $this->_verify_routes(); |
|
| 983 | - } |
|
| 984 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 985 | - ? $this->_route_config['require_nonce'] |
|
| 986 | - : true; |
|
| 987 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 988 | - // set nonce from post data |
|
| 989 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 990 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 991 | - : ''; |
|
| 992 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 993 | - } |
|
| 994 | - //set the nav_tabs array but ONLY if this is UI_request |
|
| 995 | - if ($this->_is_UI_request) { |
|
| 996 | - $this->_set_nav_tabs(); |
|
| 997 | - } |
|
| 998 | - // grab callback function |
|
| 999 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1000 | - // check if callback has args |
|
| 1001 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1002 | - $error_msg = ''; |
|
| 1003 | - // action right before calling route |
|
| 1004 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1005 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1006 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1007 | - } |
|
| 1008 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 1009 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1010 | - $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1011 | - '_wp_http_referer', |
|
| 1012 | - wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1013 | - ); |
|
| 1014 | - if (! empty($func)) { |
|
| 1015 | - if (is_array($func)) { |
|
| 1016 | - list($class, $method) = $func; |
|
| 1017 | - } elseif (strpos($func, '::') !== false) { |
|
| 1018 | - list($class, $method) = explode('::', $func); |
|
| 1019 | - } else { |
|
| 1020 | - $class = $this; |
|
| 1021 | - $method = $func; |
|
| 1022 | - } |
|
| 1023 | - if (! (is_object($class) && $class === $this)) { |
|
| 1024 | - // send along this admin page object for access by addons. |
|
| 1025 | - $args['admin_page_object'] = $this; |
|
| 1026 | - } |
|
| 1027 | - if ( |
|
| 1028 | - //is it a method on a class that doesn't work? |
|
| 1029 | - ( |
|
| 1030 | - ( |
|
| 1031 | - method_exists($class, $method) |
|
| 1032 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 1033 | - ) |
|
| 1034 | - && ( |
|
| 1035 | - //is it a standalone function that doesn't work? |
|
| 1036 | - function_exists($method) |
|
| 1037 | - && call_user_func_array( |
|
| 1038 | - $func, |
|
| 1039 | - array_merge(array('admin_page_object' => $this), $args) |
|
| 1040 | - ) === false |
|
| 1041 | - ) |
|
| 1042 | - ) |
|
| 1043 | - || ( |
|
| 1044 | - //is it neither a class method NOR a standalone function? |
|
| 1045 | - ! method_exists($class, $method) |
|
| 1046 | - && ! function_exists($method) |
|
| 1047 | - ) |
|
| 1048 | - ) { |
|
| 1049 | - // user error msg |
|
| 1050 | - $error_msg = esc_html__( |
|
| 1051 | - 'An error occurred. The requested page route could not be found.', |
|
| 1052 | - 'event_espresso' |
|
| 1053 | - ); |
|
| 1054 | - // developer error msg |
|
| 1055 | - $error_msg .= '||'; |
|
| 1056 | - $error_msg .= sprintf( |
|
| 1057 | - esc_html__( |
|
| 1058 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1059 | - 'event_espresso' |
|
| 1060 | - ), |
|
| 1061 | - $method |
|
| 1062 | - ); |
|
| 1063 | - } |
|
| 1064 | - if (! empty($error_msg)) { |
|
| 1065 | - throw new EE_Error($error_msg); |
|
| 1066 | - } |
|
| 1067 | - } |
|
| 1068 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1069 | - // then we need to reset the routing properties to the new route. |
|
| 1070 | - //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1071 | - if ($this->_is_UI_request === false |
|
| 1072 | - && is_array($this->_route) |
|
| 1073 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1074 | - ) { |
|
| 1075 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1083 | - * route redirects to a headers route in its route config. |
|
| 1084 | - * |
|
| 1085 | - * @since 4.3.0 |
|
| 1086 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1087 | - * @return void |
|
| 1088 | - * @throws ReflectionException |
|
| 1089 | - * @throws InvalidArgumentException |
|
| 1090 | - * @throws InvalidInterfaceException |
|
| 1091 | - * @throws InvalidDataTypeException |
|
| 1092 | - * @throws EE_Error |
|
| 1093 | - */ |
|
| 1094 | - protected function _reset_routing_properties($new_route) |
|
| 1095 | - { |
|
| 1096 | - $this->_is_UI_request = true; |
|
| 1097 | - //now we set the current route to whatever the headers_sent_route is set at |
|
| 1098 | - $this->_req_data['action'] = $new_route; |
|
| 1099 | - //rerun page setup |
|
| 1100 | - $this->_page_setup(); |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * _add_query_arg |
|
| 1107 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1108 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1109 | - * |
|
| 1110 | - * @param array $args |
|
| 1111 | - * @param string $url |
|
| 1112 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1113 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1114 | - * Example usage: If the current page is: |
|
| 1115 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1116 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1117 | - * &_wpnonce=5467821 |
|
| 1118 | - * and you call: |
|
| 1119 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1120 | - * array( |
|
| 1121 | - * 'action' => 'resend_something', |
|
| 1122 | - * 'page=>espresso_registrations' |
|
| 1123 | - * ), |
|
| 1124 | - * $some_url, |
|
| 1125 | - * true |
|
| 1126 | - * ); |
|
| 1127 | - * It will produce a url in this structure: |
|
| 1128 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1129 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1130 | - * month_range]=March%202015 |
|
| 1131 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1132 | - * @return string |
|
| 1133 | - */ |
|
| 1134 | - public static function add_query_args_and_nonce( |
|
| 1135 | - $args = array(), |
|
| 1136 | - $url = false, |
|
| 1137 | - $sticky = false, |
|
| 1138 | - $exclude_nonce = false |
|
| 1139 | - ) { |
|
| 1140 | - //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1141 | - if ($sticky) { |
|
| 1142 | - $request = $_REQUEST; |
|
| 1143 | - unset($request['_wp_http_referer']); |
|
| 1144 | - unset($request['wp_referer']); |
|
| 1145 | - foreach ($request as $key => $value) { |
|
| 1146 | - //do not add nonces |
|
| 1147 | - if (strpos($key, 'nonce') !== false) { |
|
| 1148 | - continue; |
|
| 1149 | - } |
|
| 1150 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 1151 | - } |
|
| 1152 | - } |
|
| 1153 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * This returns a generated link that will load the related help tab. |
|
| 1160 | - * |
|
| 1161 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1162 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1163 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1164 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1165 | - * @return string generated link |
|
| 1166 | - */ |
|
| 1167 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1168 | - { |
|
| 1169 | - return EEH_Template::get_help_tab_link( |
|
| 1170 | - $help_tab_id, |
|
| 1171 | - $this->page_slug, |
|
| 1172 | - $this->_req_action, |
|
| 1173 | - $icon_style, |
|
| 1174 | - $help_text |
|
| 1175 | - ); |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * _add_help_tabs |
|
| 1182 | - * Note child classes define their help tabs within the page_config array. |
|
| 1183 | - * |
|
| 1184 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1185 | - * @return void |
|
| 1186 | - * @throws DomainException |
|
| 1187 | - * @throws EE_Error |
|
| 1188 | - */ |
|
| 1189 | - protected function _add_help_tabs() |
|
| 1190 | - { |
|
| 1191 | - $tour_buttons = ''; |
|
| 1192 | - if (isset($this->_page_config[$this->_req_action])) { |
|
| 1193 | - $config = $this->_page_config[$this->_req_action]; |
|
| 1194 | - //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1195 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1196 | - $tb = array(); |
|
| 1197 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1198 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1199 | - //if this is the end tour then we don't need to setup a button |
|
| 1200 | - if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1201 | - continue; |
|
| 1202 | - } |
|
| 1203 | - $tb[] = '<button id="trigger-tour-' |
|
| 1204 | - . $tour->get_slug() |
|
| 1205 | - . '" class="button-primary trigger-ee-help-tour">' |
|
| 1206 | - . $tour->get_label() |
|
| 1207 | - . '</button>'; |
|
| 1208 | - } |
|
| 1209 | - $tour_buttons .= implode('<br />', $tb); |
|
| 1210 | - $tour_buttons .= '</div></div>'; |
|
| 1211 | - } |
|
| 1212 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1213 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1214 | - //check that the callback given is valid |
|
| 1215 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1216 | - throw new EE_Error( |
|
| 1217 | - sprintf( |
|
| 1218 | - esc_html__( |
|
| 1219 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1220 | - 'event_espresso' |
|
| 1221 | - ), |
|
| 1222 | - $config['help_sidebar'], |
|
| 1223 | - get_class($this) |
|
| 1224 | - ) |
|
| 1225 | - ); |
|
| 1226 | - } |
|
| 1227 | - $content = apply_filters( |
|
| 1228 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1229 | - $this->{$config['help_sidebar']}() |
|
| 1230 | - ); |
|
| 1231 | - $content .= $tour_buttons; //add help tour buttons. |
|
| 1232 | - //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1233 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1234 | - } |
|
| 1235 | - //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1236 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1237 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1238 | - } |
|
| 1239 | - //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1240 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1241 | - $_ht['id'] = $this->page_slug; |
|
| 1242 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1243 | - $_ht['content'] = '<p>' . esc_html__( |
|
| 1244 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1245 | - 'event_espresso' |
|
| 1246 | - ) . '</p>'; |
|
| 1247 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1248 | - } |
|
| 1249 | - if (! isset($config['help_tabs'])) { |
|
| 1250 | - return; |
|
| 1251 | - } //no help tabs for this route |
|
| 1252 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1253 | - //we're here so there ARE help tabs! |
|
| 1254 | - //make sure we've got what we need |
|
| 1255 | - if (! isset($cfg['title'])) { |
|
| 1256 | - throw new EE_Error( |
|
| 1257 | - esc_html__( |
|
| 1258 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1259 | - 'event_espresso' |
|
| 1260 | - ) |
|
| 1261 | - ); |
|
| 1262 | - } |
|
| 1263 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1264 | - throw new EE_Error( |
|
| 1265 | - esc_html__( |
|
| 1266 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1267 | - 'event_espresso' |
|
| 1268 | - ) |
|
| 1269 | - ); |
|
| 1270 | - } |
|
| 1271 | - //first priority goes to content. |
|
| 1272 | - if (! empty($cfg['content'])) { |
|
| 1273 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1274 | - //second priority goes to filename |
|
| 1275 | - } elseif (! empty($cfg['filename'])) { |
|
| 1276 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1277 | - //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1278 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1279 | - . basename($this->_get_dir()) |
|
| 1280 | - . '/help_tabs/' |
|
| 1281 | - . $cfg['filename'] |
|
| 1282 | - . '.help_tab.php' : $file_path; |
|
| 1283 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1284 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1285 | - EE_Error::add_error( |
|
| 1286 | - sprintf( |
|
| 1287 | - esc_html__( |
|
| 1288 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1289 | - 'event_espresso' |
|
| 1290 | - ), |
|
| 1291 | - $tab_id, |
|
| 1292 | - key($config), |
|
| 1293 | - $file_path |
|
| 1294 | - ), |
|
| 1295 | - __FILE__, |
|
| 1296 | - __FUNCTION__, |
|
| 1297 | - __LINE__ |
|
| 1298 | - ); |
|
| 1299 | - return; |
|
| 1300 | - } |
|
| 1301 | - $template_args['admin_page_obj'] = $this; |
|
| 1302 | - $content = EEH_Template::display_template( |
|
| 1303 | - $file_path, |
|
| 1304 | - $template_args, |
|
| 1305 | - true |
|
| 1306 | - ); |
|
| 1307 | - } else { |
|
| 1308 | - $content = ''; |
|
| 1309 | - } |
|
| 1310 | - //check if callback is valid |
|
| 1311 | - if ( |
|
| 1312 | - empty($content) && ( |
|
| 1313 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1314 | - ) |
|
| 1315 | - ) { |
|
| 1316 | - EE_Error::add_error( |
|
| 1317 | - sprintf( |
|
| 1318 | - esc_html__( |
|
| 1319 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1320 | - 'event_espresso' |
|
| 1321 | - ), |
|
| 1322 | - $cfg['title'] |
|
| 1323 | - ), |
|
| 1324 | - __FILE__, |
|
| 1325 | - __FUNCTION__, |
|
| 1326 | - __LINE__ |
|
| 1327 | - ); |
|
| 1328 | - return; |
|
| 1329 | - } |
|
| 1330 | - //setup config array for help tab method |
|
| 1331 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1332 | - $_ht = array( |
|
| 1333 | - 'id' => $id, |
|
| 1334 | - 'title' => $cfg['title'], |
|
| 1335 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1336 | - 'content' => $content, |
|
| 1337 | - ); |
|
| 1338 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1339 | - } |
|
| 1340 | - } |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - |
|
| 1344 | - |
|
| 1345 | - /** |
|
| 1346 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1347 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1348 | - * |
|
| 1349 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1350 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1351 | - * _set_page_config() comments |
|
| 1352 | - * @return void |
|
| 1353 | - * @throws EE_Error |
|
| 1354 | - * @throws InvalidArgumentException |
|
| 1355 | - * @throws InvalidDataTypeException |
|
| 1356 | - * @throws InvalidInterfaceException |
|
| 1357 | - */ |
|
| 1358 | - protected function _add_help_tour() |
|
| 1359 | - { |
|
| 1360 | - $tours = array(); |
|
| 1361 | - $this->_help_tour = array(); |
|
| 1362 | - //exit early if help tours are turned off globally |
|
| 1363 | - if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1364 | - || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1365 | - ) { |
|
| 1366 | - return; |
|
| 1367 | - } |
|
| 1368 | - //loop through _page_config to find any help_tour defined |
|
| 1369 | - foreach ($this->_page_config as $route => $config) { |
|
| 1370 | - //we're only going to set things up for this route |
|
| 1371 | - if ($route !== $this->_req_action) { |
|
| 1372 | - continue; |
|
| 1373 | - } |
|
| 1374 | - if (isset($config['help_tour'])) { |
|
| 1375 | - foreach ($config['help_tour'] as $tour) { |
|
| 1376 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1377 | - // let's see if we can get that file... |
|
| 1378 | - // if not its possible this is a decaf route not set in caffeinated |
|
| 1379 | - // so lets try and get the caffeinated equivalent |
|
| 1380 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1381 | - . basename($this->_get_dir()) |
|
| 1382 | - . '/help_tours/' |
|
| 1383 | - . $tour |
|
| 1384 | - . '.class.php' : $file_path; |
|
| 1385 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1386 | - if (! is_readable($file_path)) { |
|
| 1387 | - EE_Error::add_error( |
|
| 1388 | - sprintf( |
|
| 1389 | - esc_html__( |
|
| 1390 | - 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1391 | - 'event_espresso' |
|
| 1392 | - ), |
|
| 1393 | - $file_path, |
|
| 1394 | - $tour |
|
| 1395 | - ), |
|
| 1396 | - __FILE__, |
|
| 1397 | - __FUNCTION__, |
|
| 1398 | - __LINE__ |
|
| 1399 | - ); |
|
| 1400 | - return; |
|
| 1401 | - } |
|
| 1402 | - require_once $file_path; |
|
| 1403 | - if (! class_exists($tour)) { |
|
| 1404 | - $error_msg[] = sprintf( |
|
| 1405 | - esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1406 | - $tour |
|
| 1407 | - ); |
|
| 1408 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 1409 | - esc_html__( |
|
| 1410 | - 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1411 | - 'event_espresso' |
|
| 1412 | - ), |
|
| 1413 | - $tour, |
|
| 1414 | - '<br />', |
|
| 1415 | - $tour, |
|
| 1416 | - $this->_req_action, |
|
| 1417 | - get_class($this) |
|
| 1418 | - ); |
|
| 1419 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 1420 | - } |
|
| 1421 | - $tour_obj = new $tour($this->_is_caf); |
|
| 1422 | - $tours[] = $tour_obj; |
|
| 1423 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1424 | - } |
|
| 1425 | - //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1426 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1427 | - $tours[] = $end_stop_tour; |
|
| 1428 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1429 | - } |
|
| 1430 | - } |
|
| 1431 | - if (! empty($tours)) { |
|
| 1432 | - $this->_help_tour['tours'] = $tours; |
|
| 1433 | - } |
|
| 1434 | - // that's it! Now that the $_help_tours property is set (or not) |
|
| 1435 | - // the scripts and html should be taken care of automatically. |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - |
|
| 1439 | - |
|
| 1440 | - /** |
|
| 1441 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1442 | - * |
|
| 1443 | - * @return void |
|
| 1444 | - */ |
|
| 1445 | - protected function _add_qtips() |
|
| 1446 | - { |
|
| 1447 | - if (isset($this->_route_config['qtips'])) { |
|
| 1448 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1449 | - //load qtip loader |
|
| 1450 | - $path = array( |
|
| 1451 | - $this->_get_dir() . '/qtips/', |
|
| 1452 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1453 | - ); |
|
| 1454 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1455 | - } |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - /** |
|
| 1461 | - * _set_nav_tabs |
|
| 1462 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1463 | - * wish to add additional tabs or modify accordingly. |
|
| 1464 | - * |
|
| 1465 | - * @return void |
|
| 1466 | - * @throws InvalidArgumentException |
|
| 1467 | - * @throws InvalidInterfaceException |
|
| 1468 | - * @throws InvalidDataTypeException |
|
| 1469 | - */ |
|
| 1470 | - protected function _set_nav_tabs() |
|
| 1471 | - { |
|
| 1472 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1473 | - $i = 0; |
|
| 1474 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1475 | - if ( |
|
| 1476 | - ! is_array($config) |
|
| 1477 | - || ( |
|
| 1478 | - is_array($config) |
|
| 1479 | - && ( |
|
| 1480 | - (isset($config['nav']) && ! $config['nav']) |
|
| 1481 | - || ! isset($config['nav']) |
|
| 1482 | - ) |
|
| 1483 | - ) |
|
| 1484 | - ) { |
|
| 1485 | - continue; |
|
| 1486 | - } |
|
| 1487 | - //no nav tab for this config |
|
| 1488 | - //check for persistent flag |
|
| 1489 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1490 | - // nav tab is only to appear when route requested. |
|
| 1491 | - continue; |
|
| 1492 | - } |
|
| 1493 | - if (! $this->check_user_access($slug, true)) { |
|
| 1494 | - // no nav tab because current user does not have access. |
|
| 1495 | - continue; |
|
| 1496 | - } |
|
| 1497 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1498 | - $this->_nav_tabs[$slug] = array( |
|
| 1499 | - 'url' => isset($config['nav']['url']) |
|
| 1500 | - ? $config['nav']['url'] |
|
| 1501 | - : self::add_query_args_and_nonce( |
|
| 1502 | - array('action' => $slug), |
|
| 1503 | - $this->_admin_base_url |
|
| 1504 | - ), |
|
| 1505 | - 'link_text' => isset($config['nav']['label']) |
|
| 1506 | - ? $config['nav']['label'] |
|
| 1507 | - : ucwords( |
|
| 1508 | - str_replace('_', ' ', $slug) |
|
| 1509 | - ), |
|
| 1510 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1511 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1512 | - ); |
|
| 1513 | - $i++; |
|
| 1514 | - } |
|
| 1515 | - //if $this->_nav_tabs is empty then lets set the default |
|
| 1516 | - if (empty($this->_nav_tabs)) { |
|
| 1517 | - $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1518 | - 'url' => $this->_admin_base_url, |
|
| 1519 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1520 | - 'css_class' => 'nav-tab-active', |
|
| 1521 | - 'order' => 10, |
|
| 1522 | - ); |
|
| 1523 | - } |
|
| 1524 | - //now let's sort the tabs according to order |
|
| 1525 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * _set_current_labels |
|
| 1532 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1533 | - * property array |
|
| 1534 | - * |
|
| 1535 | - * @return void |
|
| 1536 | - */ |
|
| 1537 | - private function _set_current_labels() |
|
| 1538 | - { |
|
| 1539 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1540 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1541 | - if (is_array($text)) { |
|
| 1542 | - foreach ($text as $sublabel => $subtext) { |
|
| 1543 | - $this->_labels[$label][$sublabel] = $subtext; |
|
| 1544 | - } |
|
| 1545 | - } else { |
|
| 1546 | - $this->_labels[$label] = $text; |
|
| 1547 | - } |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - |
|
| 1552 | - |
|
| 1553 | - |
|
| 1554 | - /** |
|
| 1555 | - * verifies user access for this admin page |
|
| 1556 | - * |
|
| 1557 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1558 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1559 | - * return false if verify fail. |
|
| 1560 | - * @return bool |
|
| 1561 | - * @throws InvalidArgumentException |
|
| 1562 | - * @throws InvalidDataTypeException |
|
| 1563 | - * @throws InvalidInterfaceException |
|
| 1564 | - */ |
|
| 1565 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1566 | - { |
|
| 1567 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1568 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1569 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1570 | - && is_array( |
|
| 1571 | - $this->_page_routes[$route_to_check] |
|
| 1572 | - ) |
|
| 1573 | - && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1574 | - ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1575 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1576 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1577 | - : $this->_route['capability']; |
|
| 1578 | - } else { |
|
| 1579 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1580 | - } |
|
| 1581 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1582 | - if ( |
|
| 1583 | - ! defined('DOING_AJAX') |
|
| 1584 | - && ( |
|
| 1585 | - ! function_exists('is_admin') |
|
| 1586 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1587 | - $capability, |
|
| 1588 | - $this->page_slug |
|
| 1589 | - . '_' |
|
| 1590 | - . $route_to_check, |
|
| 1591 | - $id |
|
| 1592 | - ) |
|
| 1593 | - ) |
|
| 1594 | - ) { |
|
| 1595 | - if ($verify_only) { |
|
| 1596 | - return false; |
|
| 1597 | - } |
|
| 1598 | - if (is_user_logged_in()) { |
|
| 1599 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1600 | - } else { |
|
| 1601 | - return false; |
|
| 1602 | - } |
|
| 1603 | - } |
|
| 1604 | - return true; |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** |
|
| 1610 | - * admin_init_global |
|
| 1611 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1612 | - * This method executes for ALL EE Admin pages. |
|
| 1613 | - * |
|
| 1614 | - * @return void |
|
| 1615 | - */ |
|
| 1616 | - public function admin_init_global() |
|
| 1617 | - { |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * wp_loaded_global |
|
| 1624 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1625 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1626 | - * |
|
| 1627 | - * @return void |
|
| 1628 | - */ |
|
| 1629 | - public function wp_loaded() |
|
| 1630 | - { |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * admin_notices |
|
| 1637 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1638 | - * ALL EE_Admin pages. |
|
| 1639 | - * |
|
| 1640 | - * @return void |
|
| 1641 | - */ |
|
| 1642 | - public function admin_notices_global() |
|
| 1643 | - { |
|
| 1644 | - $this->_display_no_javascript_warning(); |
|
| 1645 | - $this->_display_espresso_notices(); |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - |
|
| 1649 | - |
|
| 1650 | - public function network_admin_notices_global() |
|
| 1651 | - { |
|
| 1652 | - $this->_display_no_javascript_warning(); |
|
| 1653 | - $this->_display_espresso_notices(); |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | - /** |
|
| 1659 | - * admin_footer_scripts_global |
|
| 1660 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1661 | - * will apply on ALL EE_Admin pages. |
|
| 1662 | - * |
|
| 1663 | - * @return void |
|
| 1664 | - */ |
|
| 1665 | - public function admin_footer_scripts_global() |
|
| 1666 | - { |
|
| 1667 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1668 | - $this->_add_admin_page_overlay(); |
|
| 1669 | - //if metaboxes are present we need to add the nonce field |
|
| 1670 | - if ( |
|
| 1671 | - isset($this->_route_config['metaboxes']) |
|
| 1672 | - || isset($this->_route_config['list_table']) |
|
| 1673 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1674 | - ) { |
|
| 1675 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1676 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1677 | - } |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - |
|
| 1681 | - |
|
| 1682 | - /** |
|
| 1683 | - * admin_footer_global |
|
| 1684 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1685 | - * ALL EE_Admin Pages. |
|
| 1686 | - * |
|
| 1687 | - * @return void |
|
| 1688 | - * @throws EE_Error |
|
| 1689 | - */ |
|
| 1690 | - public function admin_footer_global() |
|
| 1691 | - { |
|
| 1692 | - //dialog container for dialog helper |
|
| 1693 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1694 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1695 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1696 | - $d_cont .= '</div>'; |
|
| 1697 | - echo $d_cont; |
|
| 1698 | - //help tour stuff? |
|
| 1699 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1700 | - echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1701 | - } |
|
| 1702 | - //current set timezone for timezone js |
|
| 1703 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1704 | - } |
|
| 1705 | - |
|
| 1706 | - |
|
| 1707 | - |
|
| 1708 | - /** |
|
| 1709 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1710 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1711 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1712 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1713 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1714 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1715 | - * for the |
|
| 1716 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1717 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1718 | - * 'help_trigger_id' => array( |
|
| 1719 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1720 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1721 | - * ) |
|
| 1722 | - * ); |
|
| 1723 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1724 | - * |
|
| 1725 | - * @param array $help_array |
|
| 1726 | - * @param bool $display |
|
| 1727 | - * @return string content |
|
| 1728 | - * @throws DomainException |
|
| 1729 | - * @throws EE_Error |
|
| 1730 | - */ |
|
| 1731 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1732 | - { |
|
| 1733 | - $content = ''; |
|
| 1734 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1735 | - //loop through the array and setup content |
|
| 1736 | - foreach ($help_array as $trigger => $help) { |
|
| 1737 | - //make sure the array is setup properly |
|
| 1738 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1739 | - throw new EE_Error( |
|
| 1740 | - esc_html__( |
|
| 1741 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1742 | - 'event_espresso' |
|
| 1743 | - ) |
|
| 1744 | - ); |
|
| 1745 | - } |
|
| 1746 | - //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1747 | - $template_args = array( |
|
| 1748 | - 'help_popup_id' => $trigger, |
|
| 1749 | - 'help_popup_title' => $help['title'], |
|
| 1750 | - 'help_popup_content' => $help['content'], |
|
| 1751 | - ); |
|
| 1752 | - $content .= EEH_Template::display_template( |
|
| 1753 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1754 | - $template_args, |
|
| 1755 | - true |
|
| 1756 | - ); |
|
| 1757 | - } |
|
| 1758 | - if ($display) { |
|
| 1759 | - echo $content; |
|
| 1760 | - return ''; |
|
| 1761 | - } |
|
| 1762 | - return $content; |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - |
|
| 1767 | - /** |
|
| 1768 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1769 | - * |
|
| 1770 | - * @return array properly formatted array for help popup content |
|
| 1771 | - * @throws EE_Error |
|
| 1772 | - */ |
|
| 1773 | - private function _get_help_content() |
|
| 1774 | - { |
|
| 1775 | - //what is the method we're looking for? |
|
| 1776 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1777 | - //if method doesn't exist let's get out. |
|
| 1778 | - if (! method_exists($this, $method_name)) { |
|
| 1779 | - return array(); |
|
| 1780 | - } |
|
| 1781 | - //k we're good to go let's retrieve the help array |
|
| 1782 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1783 | - //make sure we've got an array! |
|
| 1784 | - if (! is_array($help_array)) { |
|
| 1785 | - throw new EE_Error( |
|
| 1786 | - esc_html__( |
|
| 1787 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1788 | - 'event_espresso' |
|
| 1789 | - ) |
|
| 1790 | - ); |
|
| 1791 | - } |
|
| 1792 | - return $help_array; |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - |
|
| 1797 | - /** |
|
| 1798 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1799 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1800 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1801 | - * |
|
| 1802 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1803 | - * @param boolean $display if false then we return the trigger string |
|
| 1804 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1805 | - * @return string |
|
| 1806 | - * @throws DomainException |
|
| 1807 | - * @throws EE_Error |
|
| 1808 | - */ |
|
| 1809 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1810 | - { |
|
| 1811 | - if (defined('DOING_AJAX')) { |
|
| 1812 | - return ''; |
|
| 1813 | - } |
|
| 1814 | - //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1815 | - $help_array = $this->_get_help_content(); |
|
| 1816 | - $help_content = ''; |
|
| 1817 | - if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1818 | - $help_array[$trigger_id] = array( |
|
| 1819 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1820 | - 'content' => esc_html__( |
|
| 1821 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1822 | - 'event_espresso' |
|
| 1823 | - ), |
|
| 1824 | - ); |
|
| 1825 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1826 | - } |
|
| 1827 | - //let's setup the trigger |
|
| 1828 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1829 | - . $dimensions[0] |
|
| 1830 | - . '&width=' |
|
| 1831 | - . $dimensions[1] |
|
| 1832 | - . '&inlineId=' |
|
| 1833 | - . $trigger_id |
|
| 1834 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1835 | - $content .= $help_content; |
|
| 1836 | - if ($display) { |
|
| 1837 | - echo $content; |
|
| 1838 | - return ''; |
|
| 1839 | - } |
|
| 1840 | - return $content; |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * _add_global_screen_options |
|
| 1847 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1848 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1849 | - * |
|
| 1850 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1851 | - * see also WP_Screen object documents... |
|
| 1852 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1853 | - * @abstract |
|
| 1854 | - * @return void |
|
| 1855 | - */ |
|
| 1856 | - private function _add_global_screen_options() |
|
| 1857 | - { |
|
| 1858 | - } |
|
| 1859 | - |
|
| 1860 | - |
|
| 1861 | - |
|
| 1862 | - /** |
|
| 1863 | - * _add_global_feature_pointers |
|
| 1864 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1865 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1866 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1867 | - * |
|
| 1868 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1869 | - * extended) also see: |
|
| 1870 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1871 | - * @abstract |
|
| 1872 | - * @return void |
|
| 1873 | - */ |
|
| 1874 | - private function _add_global_feature_pointers() |
|
| 1875 | - { |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * load_global_scripts_styles |
|
| 1882 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1883 | - * |
|
| 1884 | - * @return void |
|
| 1885 | - * @throws EE_Error |
|
| 1886 | - */ |
|
| 1887 | - public function load_global_scripts_styles() |
|
| 1888 | - { |
|
| 1889 | - /** STYLES **/ |
|
| 1890 | - // add debugging styles |
|
| 1891 | - if (WP_DEBUG) { |
|
| 1892 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1893 | - } |
|
| 1894 | - // register all styles |
|
| 1895 | - wp_register_style( |
|
| 1896 | - 'espresso-ui-theme', |
|
| 1897 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1898 | - array(), |
|
| 1899 | - EVENT_ESPRESSO_VERSION |
|
| 1900 | - ); |
|
| 1901 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1902 | - //helpers styles |
|
| 1903 | - wp_register_style( |
|
| 1904 | - 'ee-text-links', |
|
| 1905 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1906 | - array(), |
|
| 1907 | - EVENT_ESPRESSO_VERSION |
|
| 1908 | - ); |
|
| 1909 | - /** SCRIPTS **/ |
|
| 1910 | - //register all scripts |
|
| 1911 | - wp_register_script( |
|
| 1912 | - 'ee-dialog', |
|
| 1913 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1914 | - array('jquery', 'jquery-ui-draggable'), |
|
| 1915 | - EVENT_ESPRESSO_VERSION, |
|
| 1916 | - true |
|
| 1917 | - ); |
|
| 1918 | - wp_register_script( |
|
| 1919 | - 'ee_admin_js', |
|
| 1920 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1921 | - array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1922 | - EVENT_ESPRESSO_VERSION, |
|
| 1923 | - true |
|
| 1924 | - ); |
|
| 1925 | - wp_register_script( |
|
| 1926 | - 'jquery-ui-timepicker-addon', |
|
| 1927 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1928 | - array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1929 | - EVENT_ESPRESSO_VERSION, |
|
| 1930 | - true |
|
| 1931 | - ); |
|
| 1932 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1933 | - //script for sorting tables |
|
| 1934 | - wp_register_script( |
|
| 1935 | - 'espresso_ajax_table_sorting', |
|
| 1936 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1937 | - array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1938 | - EVENT_ESPRESSO_VERSION, |
|
| 1939 | - true |
|
| 1940 | - ); |
|
| 1941 | - //script for parsing uri's |
|
| 1942 | - wp_register_script( |
|
| 1943 | - 'ee-parse-uri', |
|
| 1944 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1945 | - array(), |
|
| 1946 | - EVENT_ESPRESSO_VERSION, |
|
| 1947 | - true |
|
| 1948 | - ); |
|
| 1949 | - //and parsing associative serialized form elements |
|
| 1950 | - wp_register_script( |
|
| 1951 | - 'ee-serialize-full-array', |
|
| 1952 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1953 | - array('jquery'), |
|
| 1954 | - EVENT_ESPRESSO_VERSION, |
|
| 1955 | - true |
|
| 1956 | - ); |
|
| 1957 | - //helpers scripts |
|
| 1958 | - wp_register_script( |
|
| 1959 | - 'ee-text-links', |
|
| 1960 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1961 | - array('jquery'), |
|
| 1962 | - EVENT_ESPRESSO_VERSION, |
|
| 1963 | - true |
|
| 1964 | - ); |
|
| 1965 | - wp_register_script( |
|
| 1966 | - 'ee-moment-core', |
|
| 1967 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1968 | - array(), |
|
| 1969 | - EVENT_ESPRESSO_VERSION, |
|
| 1970 | - true |
|
| 1971 | - ); |
|
| 1972 | - wp_register_script( |
|
| 1973 | - 'ee-moment', |
|
| 1974 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1975 | - array('ee-moment-core'), |
|
| 1976 | - EVENT_ESPRESSO_VERSION, |
|
| 1977 | - true |
|
| 1978 | - ); |
|
| 1979 | - wp_register_script( |
|
| 1980 | - 'ee-datepicker', |
|
| 1981 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1982 | - array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1983 | - EVENT_ESPRESSO_VERSION, |
|
| 1984 | - true |
|
| 1985 | - ); |
|
| 1986 | - //google charts |
|
| 1987 | - wp_register_script( |
|
| 1988 | - 'google-charts', |
|
| 1989 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1990 | - array(), |
|
| 1991 | - EVENT_ESPRESSO_VERSION, |
|
| 1992 | - false |
|
| 1993 | - ); |
|
| 1994 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1995 | - wp_enqueue_style('ee-admin-css'); |
|
| 1996 | - wp_enqueue_script('ee_admin_js'); |
|
| 1997 | - wp_enqueue_script('ee-accounting'); |
|
| 1998 | - wp_enqueue_script('jquery-validate'); |
|
| 1999 | - //taking care of metaboxes |
|
| 2000 | - if ( |
|
| 2001 | - empty($this->_cpt_route) |
|
| 2002 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2003 | - ) { |
|
| 2004 | - wp_enqueue_script('dashboard'); |
|
| 2005 | - } |
|
| 2006 | - // LOCALIZED DATA |
|
| 2007 | - //localize script for ajax lazy loading |
|
| 2008 | - $lazy_loader_container_ids = apply_filters( |
|
| 2009 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2010 | - array('espresso_news_post_box_content') |
|
| 2011 | - ); |
|
| 2012 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2013 | - /** |
|
| 2014 | - * help tour stuff |
|
| 2015 | - */ |
|
| 2016 | - if (! empty($this->_help_tour)) { |
|
| 2017 | - //register the js for kicking things off |
|
| 2018 | - wp_enqueue_script( |
|
| 2019 | - 'ee-help-tour', |
|
| 2020 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2021 | - array('jquery-joyride'), |
|
| 2022 | - EVENT_ESPRESSO_VERSION, |
|
| 2023 | - true |
|
| 2024 | - ); |
|
| 2025 | - $tours = array(); |
|
| 2026 | - //setup tours for the js tour object |
|
| 2027 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2028 | - if ($tour instanceof EE_Help_Tour) { |
|
| 2029 | - $tours[] = array( |
|
| 2030 | - 'id' => $tour->get_slug(), |
|
| 2031 | - 'options' => $tour->get_options(), |
|
| 2032 | - ); |
|
| 2033 | - } |
|
| 2034 | - } |
|
| 2035 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2036 | - //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2037 | - } |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * admin_footer_scripts_eei18n_js_strings |
|
| 2044 | - * |
|
| 2045 | - * @return void |
|
| 2046 | - */ |
|
| 2047 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 2048 | - { |
|
| 2049 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2050 | - EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2051 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2052 | - 'event_espresso' |
|
| 2053 | - ); |
|
| 2054 | - EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2055 | - EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2056 | - EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2057 | - EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2058 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2059 | - EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2060 | - EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2061 | - EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2062 | - EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2063 | - EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2064 | - EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2065 | - EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2066 | - EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2067 | - EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2068 | - EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2069 | - EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2070 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2071 | - EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2072 | - EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2073 | - EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2074 | - EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2075 | - EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2076 | - EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2077 | - EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2078 | - EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2079 | - EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2080 | - EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2081 | - EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2082 | - EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2083 | - EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2084 | - EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2085 | - EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2086 | - EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2087 | - EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2088 | - EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2089 | - EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2090 | - EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2091 | - EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2092 | - } |
|
| 2093 | - |
|
| 2094 | - |
|
| 2095 | - |
|
| 2096 | - /** |
|
| 2097 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2098 | - * |
|
| 2099 | - * @return void |
|
| 2100 | - */ |
|
| 2101 | - public function add_xdebug_style() |
|
| 2102 | - { |
|
| 2103 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - |
|
| 2107 | - /************************/ |
|
| 2108 | - /** LIST TABLE METHODS **/ |
|
| 2109 | - /************************/ |
|
| 2110 | - /** |
|
| 2111 | - * this sets up the list table if the current view requires it. |
|
| 2112 | - * |
|
| 2113 | - * @return void |
|
| 2114 | - * @throws EE_Error |
|
| 2115 | - */ |
|
| 2116 | - protected function _set_list_table() |
|
| 2117 | - { |
|
| 2118 | - //first is this a list_table view? |
|
| 2119 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2120 | - return; |
|
| 2121 | - } //not a list_table view so get out. |
|
| 2122 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2123 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2124 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2125 | - //user error msg |
|
| 2126 | - $error_msg = esc_html__( |
|
| 2127 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2128 | - 'event_espresso' |
|
| 2129 | - ); |
|
| 2130 | - //developer error msg |
|
| 2131 | - $error_msg .= '||' . sprintf( |
|
| 2132 | - esc_html__( |
|
| 2133 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2134 | - 'event_espresso' |
|
| 2135 | - ), |
|
| 2136 | - $this->_req_action, |
|
| 2137 | - $list_table_view |
|
| 2138 | - ); |
|
| 2139 | - throw new EE_Error($error_msg); |
|
| 2140 | - } |
|
| 2141 | - //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2142 | - $this->_views = apply_filters( |
|
| 2143 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2144 | - $this->_views |
|
| 2145 | - ); |
|
| 2146 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2147 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2148 | - $this->_set_list_table_view(); |
|
| 2149 | - $this->_set_list_table_object(); |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - |
|
| 2153 | - |
|
| 2154 | - /** |
|
| 2155 | - * set current view for List Table |
|
| 2156 | - * |
|
| 2157 | - * @return void |
|
| 2158 | - */ |
|
| 2159 | - protected function _set_list_table_view() |
|
| 2160 | - { |
|
| 2161 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2162 | - // looking at active items or dumpster diving ? |
|
| 2163 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2164 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2165 | - } else { |
|
| 2166 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2167 | - } |
|
| 2168 | - } |
|
| 2169 | - |
|
| 2170 | - |
|
| 2171 | - |
|
| 2172 | - /** |
|
| 2173 | - * _set_list_table_object |
|
| 2174 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2175 | - * |
|
| 2176 | - * @throws EE_Error |
|
| 2177 | - */ |
|
| 2178 | - protected function _set_list_table_object() |
|
| 2179 | - { |
|
| 2180 | - if (isset($this->_route_config['list_table'])) { |
|
| 2181 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2182 | - throw new EE_Error( |
|
| 2183 | - sprintf( |
|
| 2184 | - esc_html__( |
|
| 2185 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2186 | - 'event_espresso' |
|
| 2187 | - ), |
|
| 2188 | - $this->_route_config['list_table'], |
|
| 2189 | - get_class($this) |
|
| 2190 | - ) |
|
| 2191 | - ); |
|
| 2192 | - } |
|
| 2193 | - $list_table = $this->_route_config['list_table']; |
|
| 2194 | - $this->_list_table_object = new $list_table($this); |
|
| 2195 | - } |
|
| 2196 | - } |
|
| 2197 | - |
|
| 2198 | - |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2202 | - * |
|
| 2203 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2204 | - * urls. The array should be indexed by the view it is being |
|
| 2205 | - * added to. |
|
| 2206 | - * @return array |
|
| 2207 | - */ |
|
| 2208 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2209 | - { |
|
| 2210 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2211 | - if (empty($this->_views)) { |
|
| 2212 | - $this->_views = array(); |
|
| 2213 | - } |
|
| 2214 | - // cycle thru views |
|
| 2215 | - foreach ($this->_views as $key => $view) { |
|
| 2216 | - $query_args = array(); |
|
| 2217 | - // check for current view |
|
| 2218 | - $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2219 | - $query_args['action'] = $this->_req_action; |
|
| 2220 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2221 | - $query_args['status'] = $view['slug']; |
|
| 2222 | - //merge any other arguments sent in. |
|
| 2223 | - if (isset($extra_query_args[$view['slug']])) { |
|
| 2224 | - $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2225 | - } |
|
| 2226 | - $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2227 | - } |
|
| 2228 | - return $this->_views; |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * _entries_per_page_dropdown |
|
| 2235 | - * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2236 | - * |
|
| 2237 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2238 | - * WP does it. |
|
| 2239 | - * @param int $max_entries total number of rows in the table |
|
| 2240 | - * @return string |
|
| 2241 | - */ |
|
| 2242 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2243 | - { |
|
| 2244 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2245 | - $values = array(10, 25, 50, 100); |
|
| 2246 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2247 | - if ($max_entries) { |
|
| 2248 | - $values[] = $max_entries; |
|
| 2249 | - sort($values); |
|
| 2250 | - } |
|
| 2251 | - $entries_per_page_dropdown = ' |
|
| 125 | + /** |
|
| 126 | + * @var string $_req_action |
|
| 127 | + */ |
|
| 128 | + protected $_req_action; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var string $_req_nonce |
|
| 132 | + */ |
|
| 133 | + protected $_req_nonce; |
|
| 134 | + |
|
| 135 | + //search related |
|
| 136 | + protected $_search_btn_label; |
|
| 137 | + |
|
| 138 | + protected $_search_box_callback; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * WP Current Screen object |
|
| 142 | + * |
|
| 143 | + * @var WP_Screen |
|
| 144 | + */ |
|
| 145 | + protected $_current_screen; |
|
| 146 | + |
|
| 147 | + //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 148 | + protected $_hook_obj; |
|
| 149 | + |
|
| 150 | + //for holding incoming request data |
|
| 151 | + protected $_req_data; |
|
| 152 | + |
|
| 153 | + // yes / no array for admin form fields |
|
| 154 | + protected $_yes_no_values = array(); |
|
| 155 | + |
|
| 156 | + //some default things shared by all child classes |
|
| 157 | + protected $_default_espresso_metaboxes; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * EE_Registry Object |
|
| 161 | + * |
|
| 162 | + * @var EE_Registry |
|
| 163 | + */ |
|
| 164 | + protected $EE = null; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 170 | + * |
|
| 171 | + * @var boolean |
|
| 172 | + */ |
|
| 173 | + protected $_is_caf = false; |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @Constructor |
|
| 179 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 180 | + * @throws EE_Error |
|
| 181 | + * @throws InvalidArgumentException |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + * @throws InvalidDataTypeException |
|
| 184 | + * @throws InvalidInterfaceException |
|
| 185 | + */ |
|
| 186 | + public function __construct($routing = true) |
|
| 187 | + { |
|
| 188 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 189 | + $this->_is_caf = true; |
|
| 190 | + } |
|
| 191 | + $this->_yes_no_values = array( |
|
| 192 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 193 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 194 | + ); |
|
| 195 | + //set the _req_data property. |
|
| 196 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 197 | + //routing enabled? |
|
| 198 | + $this->_routing = $routing; |
|
| 199 | + //set initial page props (child method) |
|
| 200 | + $this->_init_page_props(); |
|
| 201 | + //set global defaults |
|
| 202 | + $this->_set_defaults(); |
|
| 203 | + //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 204 | + $this->_global_ajax_hooks(); |
|
| 205 | + $this->_ajax_hooks(); |
|
| 206 | + //other_page_hooks have to be early too. |
|
| 207 | + $this->_do_other_page_hooks(); |
|
| 208 | + //This just allows us to have extending classes do something specific |
|
| 209 | + // before the parent constructor runs _page_setup(). |
|
| 210 | + if (method_exists($this, '_before_page_setup')) { |
|
| 211 | + $this->_before_page_setup(); |
|
| 212 | + } |
|
| 213 | + //set up page dependencies |
|
| 214 | + $this->_page_setup(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * _init_page_props |
|
| 221 | + * Child classes use to set at least the following properties: |
|
| 222 | + * $page_slug. |
|
| 223 | + * $page_label. |
|
| 224 | + * |
|
| 225 | + * @abstract |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + abstract protected function _init_page_props(); |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * _ajax_hooks |
|
| 234 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 235 | + * Note: within the ajax callback methods. |
|
| 236 | + * |
|
| 237 | + * @abstract |
|
| 238 | + * @return void |
|
| 239 | + */ |
|
| 240 | + abstract protected function _ajax_hooks(); |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * _define_page_props |
|
| 246 | + * child classes define page properties in here. Must include at least: |
|
| 247 | + * $_admin_base_url = base_url for all admin pages |
|
| 248 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 249 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 250 | + * array( |
|
| 251 | + * 'buttons' => array( |
|
| 252 | + * 'add' => esc_html__('label for add new button'), |
|
| 253 | + * 'edit' => esc_html__('label for edit button'), |
|
| 254 | + * 'delete' => esc_html__('label for delete button') |
|
| 255 | + * ) |
|
| 256 | + * ) |
|
| 257 | + * |
|
| 258 | + * @abstract |
|
| 259 | + * @return void |
|
| 260 | + */ |
|
| 261 | + abstract protected function _define_page_props(); |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * _set_page_routes |
|
| 267 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 268 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 269 | + * have a 'default' route. Here's the format |
|
| 270 | + * $this->_page_routes = array( |
|
| 271 | + * 'default' => array( |
|
| 272 | + * 'func' => '_default_method_handling_route', |
|
| 273 | + * 'args' => array('array','of','args'), |
|
| 274 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 275 | + * ajax request, backend processing) |
|
| 276 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 277 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 278 | + * headers sent route. |
|
| 279 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 280 | + * this route. |
|
| 281 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 282 | + * checks). |
|
| 283 | + * ), |
|
| 284 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 285 | + * handling method. |
|
| 286 | + * ) |
|
| 287 | + * ) |
|
| 288 | + * |
|
| 289 | + * @abstract |
|
| 290 | + * @return void |
|
| 291 | + */ |
|
| 292 | + abstract protected function _set_page_routes(); |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * _set_page_config |
|
| 298 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 299 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 300 | + * $this->_page_config = array( |
|
| 301 | + * 'default' => array( |
|
| 302 | + * 'labels' => array( |
|
| 303 | + * 'buttons' => array( |
|
| 304 | + * 'add' => esc_html__('label for adding item'), |
|
| 305 | + * 'edit' => esc_html__('label for editing item'), |
|
| 306 | + * 'delete' => esc_html__('label for deleting item') |
|
| 307 | + * ), |
|
| 308 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 309 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 310 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 311 | + * _define_page_props() method |
|
| 312 | + * 'nav' => array( |
|
| 313 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 314 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 315 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 316 | + * 'order' => 10, //required to indicate tab position. |
|
| 317 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 318 | + * displayed then add this parameter. |
|
| 319 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 320 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 321 | + * metaboxes set for eventespresso admin pages. |
|
| 322 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 323 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 324 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 325 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 326 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 327 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 328 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 329 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 330 | + * want to display. |
|
| 331 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 332 | + * 'tab_id' => array( |
|
| 333 | + * 'title' => 'tab_title', |
|
| 334 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 335 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 336 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 337 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 338 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 339 | + * attempt to use the callback which should match the name of a method in the class |
|
| 340 | + * ), |
|
| 341 | + * 'tab2_id' => array( |
|
| 342 | + * 'title' => 'tab2 title', |
|
| 343 | + * 'filename' => 'file_name_2' |
|
| 344 | + * 'callback' => 'callback_method_for_content', |
|
| 345 | + * ), |
|
| 346 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 347 | + * help tab area on an admin page. @link |
|
| 348 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 349 | + * 'help_tour' => array( |
|
| 350 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 351 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 352 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 353 | + * ), |
|
| 354 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 355 | + * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 356 | + * just set |
|
| 357 | + * 'require_nonce' to FALSE |
|
| 358 | + * ) |
|
| 359 | + * ) |
|
| 360 | + * |
|
| 361 | + * @abstract |
|
| 362 | + * @return void |
|
| 363 | + */ |
|
| 364 | + abstract protected function _set_page_config(); |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** end sample help_tour methods **/ |
|
| 371 | + /** |
|
| 372 | + * _add_screen_options |
|
| 373 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 374 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 375 | + * to a particular view. |
|
| 376 | + * |
|
| 377 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 378 | + * see also WP_Screen object documents... |
|
| 379 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 380 | + * @abstract |
|
| 381 | + * @return void |
|
| 382 | + */ |
|
| 383 | + abstract protected function _add_screen_options(); |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * _add_feature_pointers |
|
| 389 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 390 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 391 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 392 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 393 | + * extended) also see: |
|
| 394 | + * |
|
| 395 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 396 | + * @abstract |
|
| 397 | + * @return void |
|
| 398 | + */ |
|
| 399 | + abstract protected function _add_feature_pointers(); |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * load_scripts_styles |
|
| 405 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 406 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 407 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 408 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 409 | + * |
|
| 410 | + * @abstract |
|
| 411 | + * @return void |
|
| 412 | + */ |
|
| 413 | + abstract public function load_scripts_styles(); |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * admin_init |
|
| 419 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 420 | + * all pages/views loaded by child class. |
|
| 421 | + * |
|
| 422 | + * @abstract |
|
| 423 | + * @return void |
|
| 424 | + */ |
|
| 425 | + abstract public function admin_init(); |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * admin_notices |
|
| 431 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 432 | + * all pages/views loaded by child class. |
|
| 433 | + * |
|
| 434 | + * @abstract |
|
| 435 | + * @return void |
|
| 436 | + */ |
|
| 437 | + abstract public function admin_notices(); |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * admin_footer_scripts |
|
| 443 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 444 | + * will apply to all pages/views loaded by child class. |
|
| 445 | + * |
|
| 446 | + * @return void |
|
| 447 | + */ |
|
| 448 | + abstract public function admin_footer_scripts(); |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * admin_footer |
|
| 454 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 455 | + * apply to all pages/views loaded by child class. |
|
| 456 | + * |
|
| 457 | + * @return void |
|
| 458 | + */ |
|
| 459 | + public function admin_footer() |
|
| 460 | + { |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * _global_ajax_hooks |
|
| 467 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 468 | + * Note: within the ajax callback methods. |
|
| 469 | + * |
|
| 470 | + * @abstract |
|
| 471 | + * @return void |
|
| 472 | + */ |
|
| 473 | + protected function _global_ajax_hooks() |
|
| 474 | + { |
|
| 475 | + //for lazy loading of metabox content |
|
| 476 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + public function ajax_metabox_content() |
|
| 482 | + { |
|
| 483 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 484 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 485 | + self::cached_rss_display($contentid, $url); |
|
| 486 | + wp_die(); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * _page_setup |
|
| 493 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 494 | + * doesn't match the object. |
|
| 495 | + * |
|
| 496 | + * @final |
|
| 497 | + * @return void |
|
| 498 | + * @throws EE_Error |
|
| 499 | + * @throws InvalidArgumentException |
|
| 500 | + * @throws ReflectionException |
|
| 501 | + * @throws InvalidDataTypeException |
|
| 502 | + * @throws InvalidInterfaceException |
|
| 503 | + */ |
|
| 504 | + final protected function _page_setup() |
|
| 505 | + { |
|
| 506 | + //requires? |
|
| 507 | + //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 508 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 509 | + //next verify if we need to load anything... |
|
| 510 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 511 | + $this->page_folder = strtolower( |
|
| 512 | + str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 513 | + ); |
|
| 514 | + global $ee_menu_slugs; |
|
| 515 | + $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 516 | + if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 517 | + return; |
|
| 518 | + } |
|
| 519 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 520 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 521 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 522 | + ? $this->_req_data['action2'] |
|
| 523 | + : $this->_req_data['action']; |
|
| 524 | + } |
|
| 525 | + // then set blank or -1 action values to 'default' |
|
| 526 | + $this->_req_action = isset($this->_req_data['action']) |
|
| 527 | + && ! empty($this->_req_data['action']) |
|
| 528 | + && $this->_req_data['action'] !== '-1' |
|
| 529 | + ? sanitize_key($this->_req_data['action']) |
|
| 530 | + : 'default'; |
|
| 531 | + // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 532 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 533 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 534 | + ? $this->_req_data['route'] : $this->_req_action; |
|
| 535 | + //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 536 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 537 | + ? $this->_req_data['route'] |
|
| 538 | + : $this->_req_action; |
|
| 539 | + $this->_current_view = $this->_req_action; |
|
| 540 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 541 | + $this->_define_page_props(); |
|
| 542 | + $this->_current_page_view_url = add_query_arg( |
|
| 543 | + array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 544 | + $this->_admin_base_url |
|
| 545 | + ); |
|
| 546 | + //default things |
|
| 547 | + $this->_default_espresso_metaboxes = array( |
|
| 548 | + '_espresso_news_post_box', |
|
| 549 | + '_espresso_links_post_box', |
|
| 550 | + '_espresso_ratings_request', |
|
| 551 | + '_espresso_sponsors_post_box', |
|
| 552 | + ); |
|
| 553 | + //set page configs |
|
| 554 | + $this->_set_page_routes(); |
|
| 555 | + $this->_set_page_config(); |
|
| 556 | + //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 557 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 558 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 559 | + } |
|
| 560 | + //for caffeinated and other extended functionality. |
|
| 561 | + // If there is a _extend_page_config method |
|
| 562 | + // then let's run that to modify the all the various page configuration arrays |
|
| 563 | + if (method_exists($this, '_extend_page_config')) { |
|
| 564 | + $this->_extend_page_config(); |
|
| 565 | + } |
|
| 566 | + //for CPT and other extended functionality. |
|
| 567 | + // If there is an _extend_page_config_for_cpt |
|
| 568 | + // then let's run that to modify all the various page configuration arrays. |
|
| 569 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | + $this->_extend_page_config_for_cpt(); |
|
| 571 | + } |
|
| 572 | + //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | + $this->_page_routes = apply_filters( |
|
| 574 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | + $this->_page_routes, |
|
| 576 | + $this |
|
| 577 | + ); |
|
| 578 | + $this->_page_config = apply_filters( |
|
| 579 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | + $this->_page_config, |
|
| 581 | + $this |
|
| 582 | + ); |
|
| 583 | + //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | + if ( |
|
| 586 | + method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view) |
|
| 587 | + ) { |
|
| 588 | + add_action( |
|
| 589 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 590 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 591 | + 10, |
|
| 592 | + 2 |
|
| 593 | + ); |
|
| 594 | + } |
|
| 595 | + //next route only if routing enabled |
|
| 596 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 597 | + $this->_verify_routes(); |
|
| 598 | + //next let's just check user_access and kill if no access |
|
| 599 | + $this->check_user_access(); |
|
| 600 | + if ($this->_is_UI_request) { |
|
| 601 | + //admin_init stuff - global, all views for this page class, specific view |
|
| 602 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 603 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 604 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 605 | + } |
|
| 606 | + } else { |
|
| 607 | + //hijack regular WP loading and route admin request immediately |
|
| 608 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 609 | + $this->route_admin_request(); |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 618 | + * |
|
| 619 | + * @return void |
|
| 620 | + * @throws ReflectionException |
|
| 621 | + * @throws EE_Error |
|
| 622 | + */ |
|
| 623 | + private function _do_other_page_hooks() |
|
| 624 | + { |
|
| 625 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 626 | + foreach ($registered_pages as $page) { |
|
| 627 | + //now let's setup the file name and class that should be present |
|
| 628 | + $classname = str_replace('.class.php', '', $page); |
|
| 629 | + //autoloaders should take care of loading file |
|
| 630 | + if (! class_exists($classname)) { |
|
| 631 | + $error_msg[] = sprintf( |
|
| 632 | + esc_html__( |
|
| 633 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 634 | + 'event_espresso' |
|
| 635 | + ), |
|
| 636 | + $page |
|
| 637 | + ); |
|
| 638 | + $error_msg[] = $error_msg[0] |
|
| 639 | + . "\r\n" |
|
| 640 | + . sprintf( |
|
| 641 | + esc_html__( |
|
| 642 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 643 | + 'event_espresso' |
|
| 644 | + ), |
|
| 645 | + $page, |
|
| 646 | + '<br />', |
|
| 647 | + '<strong>' . $classname . '</strong>' |
|
| 648 | + ); |
|
| 649 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 650 | + } |
|
| 651 | + $a = new ReflectionClass($classname); |
|
| 652 | + //notice we are passing the instance of this class to the hook object. |
|
| 653 | + $hookobj[] = $a->newInstance($this); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + public function load_page_dependencies() |
|
| 660 | + { |
|
| 661 | + try { |
|
| 662 | + $this->_load_page_dependencies(); |
|
| 663 | + } catch (EE_Error $e) { |
|
| 664 | + $e->get_error(); |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * load_page_dependencies |
|
| 672 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 673 | + * |
|
| 674 | + * @return void |
|
| 675 | + * @throws DomainException |
|
| 676 | + * @throws EE_Error |
|
| 677 | + * @throws InvalidArgumentException |
|
| 678 | + * @throws InvalidDataTypeException |
|
| 679 | + * @throws InvalidInterfaceException |
|
| 680 | + * @throws ReflectionException |
|
| 681 | + */ |
|
| 682 | + protected function _load_page_dependencies() |
|
| 683 | + { |
|
| 684 | + //let's set the current_screen and screen options to override what WP set |
|
| 685 | + $this->_current_screen = get_current_screen(); |
|
| 686 | + //load admin_notices - global, page class, and view specific |
|
| 687 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 688 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 689 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 690 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 691 | + } |
|
| 692 | + //load network admin_notices - global, page class, and view specific |
|
| 693 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 694 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 695 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 696 | + } |
|
| 697 | + //this will save any per_page screen options if they are present |
|
| 698 | + $this->_set_per_page_screen_options(); |
|
| 699 | + //setup list table properties |
|
| 700 | + $this->_set_list_table(); |
|
| 701 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 702 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 703 | + $this->_add_registered_meta_boxes(); |
|
| 704 | + $this->_add_screen_columns(); |
|
| 705 | + //add screen options - global, page child class, and view specific |
|
| 706 | + $this->_add_global_screen_options(); |
|
| 707 | + $this->_add_screen_options(); |
|
| 708 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 709 | + if (method_exists($this, $add_screen_options )) { |
|
| 710 | + $this->{$add_screen_options}(); |
|
| 711 | + } |
|
| 712 | + //add help tab(s) and tours- set via page_config and qtips. |
|
| 713 | + $this->_add_help_tour(); |
|
| 714 | + $this->_add_help_tabs(); |
|
| 715 | + $this->_add_qtips(); |
|
| 716 | + //add feature_pointers - global, page child class, and view specific |
|
| 717 | + $this->_add_feature_pointers(); |
|
| 718 | + $this->_add_global_feature_pointers(); |
|
| 719 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 720 | + if (method_exists($this, $add_feature_pointer )) { |
|
| 721 | + $this->{$add_feature_pointer}(); |
|
| 722 | + } |
|
| 723 | + //enqueue scripts/styles - global, page class, and view specific |
|
| 724 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 725 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 726 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 727 | + add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 728 | + } |
|
| 729 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 730 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 731 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 732 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 733 | + // is a good use case. Notice the late priority we're giving these |
|
| 734 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 735 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 736 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 737 | + add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 738 | + } |
|
| 739 | + //admin footer scripts |
|
| 740 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 741 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 742 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 743 | + add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 744 | + } |
|
| 745 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 746 | + //targeted hook |
|
| 747 | + do_action( |
|
| 748 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 749 | + |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * _set_defaults |
|
| 757 | + * This sets some global defaults for class properties. |
|
| 758 | + */ |
|
| 759 | + private function _set_defaults() |
|
| 760 | + { |
|
| 761 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 762 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 763 | + $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 764 | + $this->_page_config = $this->_default_route_query_args = array(); |
|
| 765 | + $this->_default_nav_tab_name = 'overview'; |
|
| 766 | + //init template args |
|
| 767 | + $this->_template_args = array( |
|
| 768 | + 'admin_page_header' => '', |
|
| 769 | + 'admin_page_content' => '', |
|
| 770 | + 'post_body_content' => '', |
|
| 771 | + 'before_list_table' => '', |
|
| 772 | + 'after_list_table' => '', |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * route_admin_request |
|
| 780 | + * |
|
| 781 | + * @see _route_admin_request() |
|
| 782 | + * @return exception|void error |
|
| 783 | + * @throws InvalidArgumentException |
|
| 784 | + * @throws InvalidInterfaceException |
|
| 785 | + * @throws InvalidDataTypeException |
|
| 786 | + * @throws EE_Error |
|
| 787 | + * @throws ReflectionException |
|
| 788 | + */ |
|
| 789 | + public function route_admin_request() |
|
| 790 | + { |
|
| 791 | + try { |
|
| 792 | + $this->_route_admin_request(); |
|
| 793 | + } catch (EE_Error $e) { |
|
| 794 | + $e->get_error(); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + public function set_wp_page_slug($wp_page_slug) |
|
| 801 | + { |
|
| 802 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 803 | + //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 804 | + if (is_network_admin()) { |
|
| 805 | + $this->_wp_page_slug .= '-network'; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * _verify_routes |
|
| 813 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 814 | + * we know if we need to drop out. |
|
| 815 | + * |
|
| 816 | + * @return bool |
|
| 817 | + * @throws EE_Error |
|
| 818 | + */ |
|
| 819 | + protected function _verify_routes() |
|
| 820 | + { |
|
| 821 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 822 | + if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + $this->_route = false; |
|
| 826 | + // check that the page_routes array is not empty |
|
| 827 | + if (empty($this->_page_routes)) { |
|
| 828 | + // user error msg |
|
| 829 | + $error_msg = sprintf( |
|
| 830 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 831 | + $this->_admin_page_title |
|
| 832 | + ); |
|
| 833 | + // developer error msg |
|
| 834 | + $error_msg .= '||' . $error_msg . esc_html__( |
|
| 835 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 836 | + 'event_espresso' |
|
| 837 | + ); |
|
| 838 | + throw new EE_Error($error_msg); |
|
| 839 | + } |
|
| 840 | + // and that the requested page route exists |
|
| 841 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 842 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 843 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 844 | + ? $this->_page_config[$this->_req_action] : array(); |
|
| 845 | + } else { |
|
| 846 | + // user error msg |
|
| 847 | + $error_msg = sprintf( |
|
| 848 | + esc_html__( |
|
| 849 | + 'The requested page route does not exist for the %s admin page.', |
|
| 850 | + 'event_espresso' |
|
| 851 | + ), |
|
| 852 | + $this->_admin_page_title |
|
| 853 | + ); |
|
| 854 | + // developer error msg |
|
| 855 | + $error_msg .= '||' . $error_msg . sprintf( |
|
| 856 | + esc_html__( |
|
| 857 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 858 | + 'event_espresso' |
|
| 859 | + ), |
|
| 860 | + $this->_req_action |
|
| 861 | + ); |
|
| 862 | + throw new EE_Error($error_msg); |
|
| 863 | + } |
|
| 864 | + // and that a default route exists |
|
| 865 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 866 | + // user error msg |
|
| 867 | + $error_msg = sprintf( |
|
| 868 | + esc_html__( |
|
| 869 | + 'A default page route has not been set for the % admin page.', |
|
| 870 | + 'event_espresso' |
|
| 871 | + ), |
|
| 872 | + $this->_admin_page_title |
|
| 873 | + ); |
|
| 874 | + // developer error msg |
|
| 875 | + $error_msg .= '||' . $error_msg . esc_html__( |
|
| 876 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 877 | + 'event_espresso' |
|
| 878 | + ); |
|
| 879 | + throw new EE_Error($error_msg); |
|
| 880 | + } |
|
| 881 | + //first lets' catch if the UI request has EVER been set. |
|
| 882 | + if ($this->_is_UI_request === null) { |
|
| 883 | + //lets set if this is a UI request or not. |
|
| 884 | + $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 885 | + //wait a minute... we might have a noheader in the route array |
|
| 886 | + $this->_is_UI_request = is_array($this->_route) |
|
| 887 | + && isset($this->_route['noheader']) |
|
| 888 | + && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 889 | + } |
|
| 890 | + $this->_set_current_labels(); |
|
| 891 | + return true; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + /** |
|
| 897 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 898 | + * |
|
| 899 | + * @param string $route the route name we're verifying |
|
| 900 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 901 | + * @throws EE_Error |
|
| 902 | + */ |
|
| 903 | + protected function _verify_route($route) |
|
| 904 | + { |
|
| 905 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 906 | + return true; |
|
| 907 | + } |
|
| 908 | + // user error msg |
|
| 909 | + $error_msg = sprintf( |
|
| 910 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 911 | + $this->_admin_page_title |
|
| 912 | + ); |
|
| 913 | + // developer error msg |
|
| 914 | + $error_msg .= '||' . $error_msg . sprintf( |
|
| 915 | + esc_html__( |
|
| 916 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 917 | + 'event_espresso' |
|
| 918 | + ), |
|
| 919 | + $route |
|
| 920 | + ); |
|
| 921 | + throw new EE_Error($error_msg); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * perform nonce verification |
|
| 928 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 929 | + * using this method (and save retyping!) |
|
| 930 | + * |
|
| 931 | + * @param string $nonce The nonce sent |
|
| 932 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 933 | + * @return void |
|
| 934 | + * @throws EE_Error |
|
| 935 | + */ |
|
| 936 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 937 | + { |
|
| 938 | + // verify nonce against expected value |
|
| 939 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 940 | + // these are not the droids you are looking for !!! |
|
| 941 | + $msg = sprintf( |
|
| 942 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 943 | + '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 944 | + '</a>' |
|
| 945 | + ); |
|
| 946 | + if (WP_DEBUG) { |
|
| 947 | + $msg .= "\n " . sprintf( |
|
| 948 | + esc_html__( |
|
| 949 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 950 | + 'event_espresso' |
|
| 951 | + ), |
|
| 952 | + __CLASS__ |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | + if (! defined('DOING_AJAX')) { |
|
| 956 | + wp_die($msg); |
|
| 957 | + } else { |
|
| 958 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 959 | + $this->_return_json(); |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * _route_admin_request() |
|
| 968 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 969 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 970 | + * in the page routes and then will try to load the corresponding method. |
|
| 971 | + * |
|
| 972 | + * @return void |
|
| 973 | + * @throws EE_Error |
|
| 974 | + * @throws InvalidArgumentException |
|
| 975 | + * @throws InvalidDataTypeException |
|
| 976 | + * @throws InvalidInterfaceException |
|
| 977 | + * @throws ReflectionException |
|
| 978 | + */ |
|
| 979 | + protected function _route_admin_request() |
|
| 980 | + { |
|
| 981 | + if (! $this->_is_UI_request) { |
|
| 982 | + $this->_verify_routes(); |
|
| 983 | + } |
|
| 984 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 985 | + ? $this->_route_config['require_nonce'] |
|
| 986 | + : true; |
|
| 987 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 988 | + // set nonce from post data |
|
| 989 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 990 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 991 | + : ''; |
|
| 992 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 993 | + } |
|
| 994 | + //set the nav_tabs array but ONLY if this is UI_request |
|
| 995 | + if ($this->_is_UI_request) { |
|
| 996 | + $this->_set_nav_tabs(); |
|
| 997 | + } |
|
| 998 | + // grab callback function |
|
| 999 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1000 | + // check if callback has args |
|
| 1001 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1002 | + $error_msg = ''; |
|
| 1003 | + // action right before calling route |
|
| 1004 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1005 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1006 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1007 | + } |
|
| 1008 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 1009 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1010 | + $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1011 | + '_wp_http_referer', |
|
| 1012 | + wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1013 | + ); |
|
| 1014 | + if (! empty($func)) { |
|
| 1015 | + if (is_array($func)) { |
|
| 1016 | + list($class, $method) = $func; |
|
| 1017 | + } elseif (strpos($func, '::') !== false) { |
|
| 1018 | + list($class, $method) = explode('::', $func); |
|
| 1019 | + } else { |
|
| 1020 | + $class = $this; |
|
| 1021 | + $method = $func; |
|
| 1022 | + } |
|
| 1023 | + if (! (is_object($class) && $class === $this)) { |
|
| 1024 | + // send along this admin page object for access by addons. |
|
| 1025 | + $args['admin_page_object'] = $this; |
|
| 1026 | + } |
|
| 1027 | + if ( |
|
| 1028 | + //is it a method on a class that doesn't work? |
|
| 1029 | + ( |
|
| 1030 | + ( |
|
| 1031 | + method_exists($class, $method) |
|
| 1032 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 1033 | + ) |
|
| 1034 | + && ( |
|
| 1035 | + //is it a standalone function that doesn't work? |
|
| 1036 | + function_exists($method) |
|
| 1037 | + && call_user_func_array( |
|
| 1038 | + $func, |
|
| 1039 | + array_merge(array('admin_page_object' => $this), $args) |
|
| 1040 | + ) === false |
|
| 1041 | + ) |
|
| 1042 | + ) |
|
| 1043 | + || ( |
|
| 1044 | + //is it neither a class method NOR a standalone function? |
|
| 1045 | + ! method_exists($class, $method) |
|
| 1046 | + && ! function_exists($method) |
|
| 1047 | + ) |
|
| 1048 | + ) { |
|
| 1049 | + // user error msg |
|
| 1050 | + $error_msg = esc_html__( |
|
| 1051 | + 'An error occurred. The requested page route could not be found.', |
|
| 1052 | + 'event_espresso' |
|
| 1053 | + ); |
|
| 1054 | + // developer error msg |
|
| 1055 | + $error_msg .= '||'; |
|
| 1056 | + $error_msg .= sprintf( |
|
| 1057 | + esc_html__( |
|
| 1058 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1059 | + 'event_espresso' |
|
| 1060 | + ), |
|
| 1061 | + $method |
|
| 1062 | + ); |
|
| 1063 | + } |
|
| 1064 | + if (! empty($error_msg)) { |
|
| 1065 | + throw new EE_Error($error_msg); |
|
| 1066 | + } |
|
| 1067 | + } |
|
| 1068 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1069 | + // then we need to reset the routing properties to the new route. |
|
| 1070 | + //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1071 | + if ($this->_is_UI_request === false |
|
| 1072 | + && is_array($this->_route) |
|
| 1073 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1074 | + ) { |
|
| 1075 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1083 | + * route redirects to a headers route in its route config. |
|
| 1084 | + * |
|
| 1085 | + * @since 4.3.0 |
|
| 1086 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1087 | + * @return void |
|
| 1088 | + * @throws ReflectionException |
|
| 1089 | + * @throws InvalidArgumentException |
|
| 1090 | + * @throws InvalidInterfaceException |
|
| 1091 | + * @throws InvalidDataTypeException |
|
| 1092 | + * @throws EE_Error |
|
| 1093 | + */ |
|
| 1094 | + protected function _reset_routing_properties($new_route) |
|
| 1095 | + { |
|
| 1096 | + $this->_is_UI_request = true; |
|
| 1097 | + //now we set the current route to whatever the headers_sent_route is set at |
|
| 1098 | + $this->_req_data['action'] = $new_route; |
|
| 1099 | + //rerun page setup |
|
| 1100 | + $this->_page_setup(); |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * _add_query_arg |
|
| 1107 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1108 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1109 | + * |
|
| 1110 | + * @param array $args |
|
| 1111 | + * @param string $url |
|
| 1112 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1113 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1114 | + * Example usage: If the current page is: |
|
| 1115 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1116 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1117 | + * &_wpnonce=5467821 |
|
| 1118 | + * and you call: |
|
| 1119 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1120 | + * array( |
|
| 1121 | + * 'action' => 'resend_something', |
|
| 1122 | + * 'page=>espresso_registrations' |
|
| 1123 | + * ), |
|
| 1124 | + * $some_url, |
|
| 1125 | + * true |
|
| 1126 | + * ); |
|
| 1127 | + * It will produce a url in this structure: |
|
| 1128 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1129 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1130 | + * month_range]=March%202015 |
|
| 1131 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1132 | + * @return string |
|
| 1133 | + */ |
|
| 1134 | + public static function add_query_args_and_nonce( |
|
| 1135 | + $args = array(), |
|
| 1136 | + $url = false, |
|
| 1137 | + $sticky = false, |
|
| 1138 | + $exclude_nonce = false |
|
| 1139 | + ) { |
|
| 1140 | + //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1141 | + if ($sticky) { |
|
| 1142 | + $request = $_REQUEST; |
|
| 1143 | + unset($request['_wp_http_referer']); |
|
| 1144 | + unset($request['wp_referer']); |
|
| 1145 | + foreach ($request as $key => $value) { |
|
| 1146 | + //do not add nonces |
|
| 1147 | + if (strpos($key, 'nonce') !== false) { |
|
| 1148 | + continue; |
|
| 1149 | + } |
|
| 1150 | + $args['wp_referer[' . $key . ']'] = $value; |
|
| 1151 | + } |
|
| 1152 | + } |
|
| 1153 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * This returns a generated link that will load the related help tab. |
|
| 1160 | + * |
|
| 1161 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1162 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1163 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1164 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1165 | + * @return string generated link |
|
| 1166 | + */ |
|
| 1167 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1168 | + { |
|
| 1169 | + return EEH_Template::get_help_tab_link( |
|
| 1170 | + $help_tab_id, |
|
| 1171 | + $this->page_slug, |
|
| 1172 | + $this->_req_action, |
|
| 1173 | + $icon_style, |
|
| 1174 | + $help_text |
|
| 1175 | + ); |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * _add_help_tabs |
|
| 1182 | + * Note child classes define their help tabs within the page_config array. |
|
| 1183 | + * |
|
| 1184 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1185 | + * @return void |
|
| 1186 | + * @throws DomainException |
|
| 1187 | + * @throws EE_Error |
|
| 1188 | + */ |
|
| 1189 | + protected function _add_help_tabs() |
|
| 1190 | + { |
|
| 1191 | + $tour_buttons = ''; |
|
| 1192 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1193 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1194 | + //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1195 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1196 | + $tb = array(); |
|
| 1197 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1198 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1199 | + //if this is the end tour then we don't need to setup a button |
|
| 1200 | + if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1201 | + continue; |
|
| 1202 | + } |
|
| 1203 | + $tb[] = '<button id="trigger-tour-' |
|
| 1204 | + . $tour->get_slug() |
|
| 1205 | + . '" class="button-primary trigger-ee-help-tour">' |
|
| 1206 | + . $tour->get_label() |
|
| 1207 | + . '</button>'; |
|
| 1208 | + } |
|
| 1209 | + $tour_buttons .= implode('<br />', $tb); |
|
| 1210 | + $tour_buttons .= '</div></div>'; |
|
| 1211 | + } |
|
| 1212 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1213 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1214 | + //check that the callback given is valid |
|
| 1215 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1216 | + throw new EE_Error( |
|
| 1217 | + sprintf( |
|
| 1218 | + esc_html__( |
|
| 1219 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1220 | + 'event_espresso' |
|
| 1221 | + ), |
|
| 1222 | + $config['help_sidebar'], |
|
| 1223 | + get_class($this) |
|
| 1224 | + ) |
|
| 1225 | + ); |
|
| 1226 | + } |
|
| 1227 | + $content = apply_filters( |
|
| 1228 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1229 | + $this->{$config['help_sidebar']}() |
|
| 1230 | + ); |
|
| 1231 | + $content .= $tour_buttons; //add help tour buttons. |
|
| 1232 | + //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1233 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1234 | + } |
|
| 1235 | + //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1236 | + if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1237 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1238 | + } |
|
| 1239 | + //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1240 | + if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1241 | + $_ht['id'] = $this->page_slug; |
|
| 1242 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1243 | + $_ht['content'] = '<p>' . esc_html__( |
|
| 1244 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1245 | + 'event_espresso' |
|
| 1246 | + ) . '</p>'; |
|
| 1247 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1248 | + } |
|
| 1249 | + if (! isset($config['help_tabs'])) { |
|
| 1250 | + return; |
|
| 1251 | + } //no help tabs for this route |
|
| 1252 | + foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1253 | + //we're here so there ARE help tabs! |
|
| 1254 | + //make sure we've got what we need |
|
| 1255 | + if (! isset($cfg['title'])) { |
|
| 1256 | + throw new EE_Error( |
|
| 1257 | + esc_html__( |
|
| 1258 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1259 | + 'event_espresso' |
|
| 1260 | + ) |
|
| 1261 | + ); |
|
| 1262 | + } |
|
| 1263 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1264 | + throw new EE_Error( |
|
| 1265 | + esc_html__( |
|
| 1266 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1267 | + 'event_espresso' |
|
| 1268 | + ) |
|
| 1269 | + ); |
|
| 1270 | + } |
|
| 1271 | + //first priority goes to content. |
|
| 1272 | + if (! empty($cfg['content'])) { |
|
| 1273 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1274 | + //second priority goes to filename |
|
| 1275 | + } elseif (! empty($cfg['filename'])) { |
|
| 1276 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1277 | + //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1278 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1279 | + . basename($this->_get_dir()) |
|
| 1280 | + . '/help_tabs/' |
|
| 1281 | + . $cfg['filename'] |
|
| 1282 | + . '.help_tab.php' : $file_path; |
|
| 1283 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1284 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1285 | + EE_Error::add_error( |
|
| 1286 | + sprintf( |
|
| 1287 | + esc_html__( |
|
| 1288 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1289 | + 'event_espresso' |
|
| 1290 | + ), |
|
| 1291 | + $tab_id, |
|
| 1292 | + key($config), |
|
| 1293 | + $file_path |
|
| 1294 | + ), |
|
| 1295 | + __FILE__, |
|
| 1296 | + __FUNCTION__, |
|
| 1297 | + __LINE__ |
|
| 1298 | + ); |
|
| 1299 | + return; |
|
| 1300 | + } |
|
| 1301 | + $template_args['admin_page_obj'] = $this; |
|
| 1302 | + $content = EEH_Template::display_template( |
|
| 1303 | + $file_path, |
|
| 1304 | + $template_args, |
|
| 1305 | + true |
|
| 1306 | + ); |
|
| 1307 | + } else { |
|
| 1308 | + $content = ''; |
|
| 1309 | + } |
|
| 1310 | + //check if callback is valid |
|
| 1311 | + if ( |
|
| 1312 | + empty($content) && ( |
|
| 1313 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1314 | + ) |
|
| 1315 | + ) { |
|
| 1316 | + EE_Error::add_error( |
|
| 1317 | + sprintf( |
|
| 1318 | + esc_html__( |
|
| 1319 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1320 | + 'event_espresso' |
|
| 1321 | + ), |
|
| 1322 | + $cfg['title'] |
|
| 1323 | + ), |
|
| 1324 | + __FILE__, |
|
| 1325 | + __FUNCTION__, |
|
| 1326 | + __LINE__ |
|
| 1327 | + ); |
|
| 1328 | + return; |
|
| 1329 | + } |
|
| 1330 | + //setup config array for help tab method |
|
| 1331 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1332 | + $_ht = array( |
|
| 1333 | + 'id' => $id, |
|
| 1334 | + 'title' => $cfg['title'], |
|
| 1335 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1336 | + 'content' => $content, |
|
| 1337 | + ); |
|
| 1338 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1339 | + } |
|
| 1340 | + } |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + |
|
| 1344 | + |
|
| 1345 | + /** |
|
| 1346 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1347 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1348 | + * |
|
| 1349 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1350 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1351 | + * _set_page_config() comments |
|
| 1352 | + * @return void |
|
| 1353 | + * @throws EE_Error |
|
| 1354 | + * @throws InvalidArgumentException |
|
| 1355 | + * @throws InvalidDataTypeException |
|
| 1356 | + * @throws InvalidInterfaceException |
|
| 1357 | + */ |
|
| 1358 | + protected function _add_help_tour() |
|
| 1359 | + { |
|
| 1360 | + $tours = array(); |
|
| 1361 | + $this->_help_tour = array(); |
|
| 1362 | + //exit early if help tours are turned off globally |
|
| 1363 | + if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1364 | + || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1365 | + ) { |
|
| 1366 | + return; |
|
| 1367 | + } |
|
| 1368 | + //loop through _page_config to find any help_tour defined |
|
| 1369 | + foreach ($this->_page_config as $route => $config) { |
|
| 1370 | + //we're only going to set things up for this route |
|
| 1371 | + if ($route !== $this->_req_action) { |
|
| 1372 | + continue; |
|
| 1373 | + } |
|
| 1374 | + if (isset($config['help_tour'])) { |
|
| 1375 | + foreach ($config['help_tour'] as $tour) { |
|
| 1376 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1377 | + // let's see if we can get that file... |
|
| 1378 | + // if not its possible this is a decaf route not set in caffeinated |
|
| 1379 | + // so lets try and get the caffeinated equivalent |
|
| 1380 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1381 | + . basename($this->_get_dir()) |
|
| 1382 | + . '/help_tours/' |
|
| 1383 | + . $tour |
|
| 1384 | + . '.class.php' : $file_path; |
|
| 1385 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1386 | + if (! is_readable($file_path)) { |
|
| 1387 | + EE_Error::add_error( |
|
| 1388 | + sprintf( |
|
| 1389 | + esc_html__( |
|
| 1390 | + 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1391 | + 'event_espresso' |
|
| 1392 | + ), |
|
| 1393 | + $file_path, |
|
| 1394 | + $tour |
|
| 1395 | + ), |
|
| 1396 | + __FILE__, |
|
| 1397 | + __FUNCTION__, |
|
| 1398 | + __LINE__ |
|
| 1399 | + ); |
|
| 1400 | + return; |
|
| 1401 | + } |
|
| 1402 | + require_once $file_path; |
|
| 1403 | + if (! class_exists($tour)) { |
|
| 1404 | + $error_msg[] = sprintf( |
|
| 1405 | + esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1406 | + $tour |
|
| 1407 | + ); |
|
| 1408 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 1409 | + esc_html__( |
|
| 1410 | + 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1411 | + 'event_espresso' |
|
| 1412 | + ), |
|
| 1413 | + $tour, |
|
| 1414 | + '<br />', |
|
| 1415 | + $tour, |
|
| 1416 | + $this->_req_action, |
|
| 1417 | + get_class($this) |
|
| 1418 | + ); |
|
| 1419 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 1420 | + } |
|
| 1421 | + $tour_obj = new $tour($this->_is_caf); |
|
| 1422 | + $tours[] = $tour_obj; |
|
| 1423 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1424 | + } |
|
| 1425 | + //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1426 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1427 | + $tours[] = $end_stop_tour; |
|
| 1428 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1429 | + } |
|
| 1430 | + } |
|
| 1431 | + if (! empty($tours)) { |
|
| 1432 | + $this->_help_tour['tours'] = $tours; |
|
| 1433 | + } |
|
| 1434 | + // that's it! Now that the $_help_tours property is set (or not) |
|
| 1435 | + // the scripts and html should be taken care of automatically. |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + |
|
| 1439 | + |
|
| 1440 | + /** |
|
| 1441 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1442 | + * |
|
| 1443 | + * @return void |
|
| 1444 | + */ |
|
| 1445 | + protected function _add_qtips() |
|
| 1446 | + { |
|
| 1447 | + if (isset($this->_route_config['qtips'])) { |
|
| 1448 | + $qtips = (array)$this->_route_config['qtips']; |
|
| 1449 | + //load qtip loader |
|
| 1450 | + $path = array( |
|
| 1451 | + $this->_get_dir() . '/qtips/', |
|
| 1452 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1453 | + ); |
|
| 1454 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1455 | + } |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + /** |
|
| 1461 | + * _set_nav_tabs |
|
| 1462 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1463 | + * wish to add additional tabs or modify accordingly. |
|
| 1464 | + * |
|
| 1465 | + * @return void |
|
| 1466 | + * @throws InvalidArgumentException |
|
| 1467 | + * @throws InvalidInterfaceException |
|
| 1468 | + * @throws InvalidDataTypeException |
|
| 1469 | + */ |
|
| 1470 | + protected function _set_nav_tabs() |
|
| 1471 | + { |
|
| 1472 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1473 | + $i = 0; |
|
| 1474 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1475 | + if ( |
|
| 1476 | + ! is_array($config) |
|
| 1477 | + || ( |
|
| 1478 | + is_array($config) |
|
| 1479 | + && ( |
|
| 1480 | + (isset($config['nav']) && ! $config['nav']) |
|
| 1481 | + || ! isset($config['nav']) |
|
| 1482 | + ) |
|
| 1483 | + ) |
|
| 1484 | + ) { |
|
| 1485 | + continue; |
|
| 1486 | + } |
|
| 1487 | + //no nav tab for this config |
|
| 1488 | + //check for persistent flag |
|
| 1489 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1490 | + // nav tab is only to appear when route requested. |
|
| 1491 | + continue; |
|
| 1492 | + } |
|
| 1493 | + if (! $this->check_user_access($slug, true)) { |
|
| 1494 | + // no nav tab because current user does not have access. |
|
| 1495 | + continue; |
|
| 1496 | + } |
|
| 1497 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1498 | + $this->_nav_tabs[$slug] = array( |
|
| 1499 | + 'url' => isset($config['nav']['url']) |
|
| 1500 | + ? $config['nav']['url'] |
|
| 1501 | + : self::add_query_args_and_nonce( |
|
| 1502 | + array('action' => $slug), |
|
| 1503 | + $this->_admin_base_url |
|
| 1504 | + ), |
|
| 1505 | + 'link_text' => isset($config['nav']['label']) |
|
| 1506 | + ? $config['nav']['label'] |
|
| 1507 | + : ucwords( |
|
| 1508 | + str_replace('_', ' ', $slug) |
|
| 1509 | + ), |
|
| 1510 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1511 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1512 | + ); |
|
| 1513 | + $i++; |
|
| 1514 | + } |
|
| 1515 | + //if $this->_nav_tabs is empty then lets set the default |
|
| 1516 | + if (empty($this->_nav_tabs)) { |
|
| 1517 | + $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1518 | + 'url' => $this->_admin_base_url, |
|
| 1519 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1520 | + 'css_class' => 'nav-tab-active', |
|
| 1521 | + 'order' => 10, |
|
| 1522 | + ); |
|
| 1523 | + } |
|
| 1524 | + //now let's sort the tabs according to order |
|
| 1525 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1526 | + } |
|
| 1527 | + |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * _set_current_labels |
|
| 1532 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1533 | + * property array |
|
| 1534 | + * |
|
| 1535 | + * @return void |
|
| 1536 | + */ |
|
| 1537 | + private function _set_current_labels() |
|
| 1538 | + { |
|
| 1539 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1540 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1541 | + if (is_array($text)) { |
|
| 1542 | + foreach ($text as $sublabel => $subtext) { |
|
| 1543 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1544 | + } |
|
| 1545 | + } else { |
|
| 1546 | + $this->_labels[$label] = $text; |
|
| 1547 | + } |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + |
|
| 1552 | + |
|
| 1553 | + |
|
| 1554 | + /** |
|
| 1555 | + * verifies user access for this admin page |
|
| 1556 | + * |
|
| 1557 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1558 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1559 | + * return false if verify fail. |
|
| 1560 | + * @return bool |
|
| 1561 | + * @throws InvalidArgumentException |
|
| 1562 | + * @throws InvalidDataTypeException |
|
| 1563 | + * @throws InvalidInterfaceException |
|
| 1564 | + */ |
|
| 1565 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1566 | + { |
|
| 1567 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1568 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1569 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1570 | + && is_array( |
|
| 1571 | + $this->_page_routes[$route_to_check] |
|
| 1572 | + ) |
|
| 1573 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1574 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1575 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1576 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1577 | + : $this->_route['capability']; |
|
| 1578 | + } else { |
|
| 1579 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1580 | + } |
|
| 1581 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1582 | + if ( |
|
| 1583 | + ! defined('DOING_AJAX') |
|
| 1584 | + && ( |
|
| 1585 | + ! function_exists('is_admin') |
|
| 1586 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1587 | + $capability, |
|
| 1588 | + $this->page_slug |
|
| 1589 | + . '_' |
|
| 1590 | + . $route_to_check, |
|
| 1591 | + $id |
|
| 1592 | + ) |
|
| 1593 | + ) |
|
| 1594 | + ) { |
|
| 1595 | + if ($verify_only) { |
|
| 1596 | + return false; |
|
| 1597 | + } |
|
| 1598 | + if (is_user_logged_in()) { |
|
| 1599 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1600 | + } else { |
|
| 1601 | + return false; |
|
| 1602 | + } |
|
| 1603 | + } |
|
| 1604 | + return true; |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** |
|
| 1610 | + * admin_init_global |
|
| 1611 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1612 | + * This method executes for ALL EE Admin pages. |
|
| 1613 | + * |
|
| 1614 | + * @return void |
|
| 1615 | + */ |
|
| 1616 | + public function admin_init_global() |
|
| 1617 | + { |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * wp_loaded_global |
|
| 1624 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1625 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1626 | + * |
|
| 1627 | + * @return void |
|
| 1628 | + */ |
|
| 1629 | + public function wp_loaded() |
|
| 1630 | + { |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * admin_notices |
|
| 1637 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1638 | + * ALL EE_Admin pages. |
|
| 1639 | + * |
|
| 1640 | + * @return void |
|
| 1641 | + */ |
|
| 1642 | + public function admin_notices_global() |
|
| 1643 | + { |
|
| 1644 | + $this->_display_no_javascript_warning(); |
|
| 1645 | + $this->_display_espresso_notices(); |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + |
|
| 1649 | + |
|
| 1650 | + public function network_admin_notices_global() |
|
| 1651 | + { |
|
| 1652 | + $this->_display_no_javascript_warning(); |
|
| 1653 | + $this->_display_espresso_notices(); |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + |
|
| 1657 | + |
|
| 1658 | + /** |
|
| 1659 | + * admin_footer_scripts_global |
|
| 1660 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1661 | + * will apply on ALL EE_Admin pages. |
|
| 1662 | + * |
|
| 1663 | + * @return void |
|
| 1664 | + */ |
|
| 1665 | + public function admin_footer_scripts_global() |
|
| 1666 | + { |
|
| 1667 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1668 | + $this->_add_admin_page_overlay(); |
|
| 1669 | + //if metaboxes are present we need to add the nonce field |
|
| 1670 | + if ( |
|
| 1671 | + isset($this->_route_config['metaboxes']) |
|
| 1672 | + || isset($this->_route_config['list_table']) |
|
| 1673 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1674 | + ) { |
|
| 1675 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1676 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1677 | + } |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + |
|
| 1681 | + |
|
| 1682 | + /** |
|
| 1683 | + * admin_footer_global |
|
| 1684 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1685 | + * ALL EE_Admin Pages. |
|
| 1686 | + * |
|
| 1687 | + * @return void |
|
| 1688 | + * @throws EE_Error |
|
| 1689 | + */ |
|
| 1690 | + public function admin_footer_global() |
|
| 1691 | + { |
|
| 1692 | + //dialog container for dialog helper |
|
| 1693 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1694 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1695 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1696 | + $d_cont .= '</div>'; |
|
| 1697 | + echo $d_cont; |
|
| 1698 | + //help tour stuff? |
|
| 1699 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1700 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1701 | + } |
|
| 1702 | + //current set timezone for timezone js |
|
| 1703 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1704 | + } |
|
| 1705 | + |
|
| 1706 | + |
|
| 1707 | + |
|
| 1708 | + /** |
|
| 1709 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1710 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1711 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1712 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1713 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1714 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1715 | + * for the |
|
| 1716 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1717 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1718 | + * 'help_trigger_id' => array( |
|
| 1719 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1720 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1721 | + * ) |
|
| 1722 | + * ); |
|
| 1723 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1724 | + * |
|
| 1725 | + * @param array $help_array |
|
| 1726 | + * @param bool $display |
|
| 1727 | + * @return string content |
|
| 1728 | + * @throws DomainException |
|
| 1729 | + * @throws EE_Error |
|
| 1730 | + */ |
|
| 1731 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1732 | + { |
|
| 1733 | + $content = ''; |
|
| 1734 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1735 | + //loop through the array and setup content |
|
| 1736 | + foreach ($help_array as $trigger => $help) { |
|
| 1737 | + //make sure the array is setup properly |
|
| 1738 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1739 | + throw new EE_Error( |
|
| 1740 | + esc_html__( |
|
| 1741 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1742 | + 'event_espresso' |
|
| 1743 | + ) |
|
| 1744 | + ); |
|
| 1745 | + } |
|
| 1746 | + //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1747 | + $template_args = array( |
|
| 1748 | + 'help_popup_id' => $trigger, |
|
| 1749 | + 'help_popup_title' => $help['title'], |
|
| 1750 | + 'help_popup_content' => $help['content'], |
|
| 1751 | + ); |
|
| 1752 | + $content .= EEH_Template::display_template( |
|
| 1753 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1754 | + $template_args, |
|
| 1755 | + true |
|
| 1756 | + ); |
|
| 1757 | + } |
|
| 1758 | + if ($display) { |
|
| 1759 | + echo $content; |
|
| 1760 | + return ''; |
|
| 1761 | + } |
|
| 1762 | + return $content; |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + |
|
| 1767 | + /** |
|
| 1768 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1769 | + * |
|
| 1770 | + * @return array properly formatted array for help popup content |
|
| 1771 | + * @throws EE_Error |
|
| 1772 | + */ |
|
| 1773 | + private function _get_help_content() |
|
| 1774 | + { |
|
| 1775 | + //what is the method we're looking for? |
|
| 1776 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1777 | + //if method doesn't exist let's get out. |
|
| 1778 | + if (! method_exists($this, $method_name)) { |
|
| 1779 | + return array(); |
|
| 1780 | + } |
|
| 1781 | + //k we're good to go let's retrieve the help array |
|
| 1782 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1783 | + //make sure we've got an array! |
|
| 1784 | + if (! is_array($help_array)) { |
|
| 1785 | + throw new EE_Error( |
|
| 1786 | + esc_html__( |
|
| 1787 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1788 | + 'event_espresso' |
|
| 1789 | + ) |
|
| 1790 | + ); |
|
| 1791 | + } |
|
| 1792 | + return $help_array; |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + |
|
| 1797 | + /** |
|
| 1798 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1799 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1800 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1801 | + * |
|
| 1802 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1803 | + * @param boolean $display if false then we return the trigger string |
|
| 1804 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1805 | + * @return string |
|
| 1806 | + * @throws DomainException |
|
| 1807 | + * @throws EE_Error |
|
| 1808 | + */ |
|
| 1809 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1810 | + { |
|
| 1811 | + if (defined('DOING_AJAX')) { |
|
| 1812 | + return ''; |
|
| 1813 | + } |
|
| 1814 | + //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1815 | + $help_array = $this->_get_help_content(); |
|
| 1816 | + $help_content = ''; |
|
| 1817 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1818 | + $help_array[$trigger_id] = array( |
|
| 1819 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1820 | + 'content' => esc_html__( |
|
| 1821 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1822 | + 'event_espresso' |
|
| 1823 | + ), |
|
| 1824 | + ); |
|
| 1825 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1826 | + } |
|
| 1827 | + //let's setup the trigger |
|
| 1828 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1829 | + . $dimensions[0] |
|
| 1830 | + . '&width=' |
|
| 1831 | + . $dimensions[1] |
|
| 1832 | + . '&inlineId=' |
|
| 1833 | + . $trigger_id |
|
| 1834 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1835 | + $content .= $help_content; |
|
| 1836 | + if ($display) { |
|
| 1837 | + echo $content; |
|
| 1838 | + return ''; |
|
| 1839 | + } |
|
| 1840 | + return $content; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * _add_global_screen_options |
|
| 1847 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1848 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1849 | + * |
|
| 1850 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1851 | + * see also WP_Screen object documents... |
|
| 1852 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1853 | + * @abstract |
|
| 1854 | + * @return void |
|
| 1855 | + */ |
|
| 1856 | + private function _add_global_screen_options() |
|
| 1857 | + { |
|
| 1858 | + } |
|
| 1859 | + |
|
| 1860 | + |
|
| 1861 | + |
|
| 1862 | + /** |
|
| 1863 | + * _add_global_feature_pointers |
|
| 1864 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1865 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1866 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1867 | + * |
|
| 1868 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1869 | + * extended) also see: |
|
| 1870 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1871 | + * @abstract |
|
| 1872 | + * @return void |
|
| 1873 | + */ |
|
| 1874 | + private function _add_global_feature_pointers() |
|
| 1875 | + { |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * load_global_scripts_styles |
|
| 1882 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1883 | + * |
|
| 1884 | + * @return void |
|
| 1885 | + * @throws EE_Error |
|
| 1886 | + */ |
|
| 1887 | + public function load_global_scripts_styles() |
|
| 1888 | + { |
|
| 1889 | + /** STYLES **/ |
|
| 1890 | + // add debugging styles |
|
| 1891 | + if (WP_DEBUG) { |
|
| 1892 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1893 | + } |
|
| 1894 | + // register all styles |
|
| 1895 | + wp_register_style( |
|
| 1896 | + 'espresso-ui-theme', |
|
| 1897 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1898 | + array(), |
|
| 1899 | + EVENT_ESPRESSO_VERSION |
|
| 1900 | + ); |
|
| 1901 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1902 | + //helpers styles |
|
| 1903 | + wp_register_style( |
|
| 1904 | + 'ee-text-links', |
|
| 1905 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1906 | + array(), |
|
| 1907 | + EVENT_ESPRESSO_VERSION |
|
| 1908 | + ); |
|
| 1909 | + /** SCRIPTS **/ |
|
| 1910 | + //register all scripts |
|
| 1911 | + wp_register_script( |
|
| 1912 | + 'ee-dialog', |
|
| 1913 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1914 | + array('jquery', 'jquery-ui-draggable'), |
|
| 1915 | + EVENT_ESPRESSO_VERSION, |
|
| 1916 | + true |
|
| 1917 | + ); |
|
| 1918 | + wp_register_script( |
|
| 1919 | + 'ee_admin_js', |
|
| 1920 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1921 | + array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1922 | + EVENT_ESPRESSO_VERSION, |
|
| 1923 | + true |
|
| 1924 | + ); |
|
| 1925 | + wp_register_script( |
|
| 1926 | + 'jquery-ui-timepicker-addon', |
|
| 1927 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1928 | + array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1929 | + EVENT_ESPRESSO_VERSION, |
|
| 1930 | + true |
|
| 1931 | + ); |
|
| 1932 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1933 | + //script for sorting tables |
|
| 1934 | + wp_register_script( |
|
| 1935 | + 'espresso_ajax_table_sorting', |
|
| 1936 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1937 | + array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1938 | + EVENT_ESPRESSO_VERSION, |
|
| 1939 | + true |
|
| 1940 | + ); |
|
| 1941 | + //script for parsing uri's |
|
| 1942 | + wp_register_script( |
|
| 1943 | + 'ee-parse-uri', |
|
| 1944 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1945 | + array(), |
|
| 1946 | + EVENT_ESPRESSO_VERSION, |
|
| 1947 | + true |
|
| 1948 | + ); |
|
| 1949 | + //and parsing associative serialized form elements |
|
| 1950 | + wp_register_script( |
|
| 1951 | + 'ee-serialize-full-array', |
|
| 1952 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1953 | + array('jquery'), |
|
| 1954 | + EVENT_ESPRESSO_VERSION, |
|
| 1955 | + true |
|
| 1956 | + ); |
|
| 1957 | + //helpers scripts |
|
| 1958 | + wp_register_script( |
|
| 1959 | + 'ee-text-links', |
|
| 1960 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1961 | + array('jquery'), |
|
| 1962 | + EVENT_ESPRESSO_VERSION, |
|
| 1963 | + true |
|
| 1964 | + ); |
|
| 1965 | + wp_register_script( |
|
| 1966 | + 'ee-moment-core', |
|
| 1967 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1968 | + array(), |
|
| 1969 | + EVENT_ESPRESSO_VERSION, |
|
| 1970 | + true |
|
| 1971 | + ); |
|
| 1972 | + wp_register_script( |
|
| 1973 | + 'ee-moment', |
|
| 1974 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1975 | + array('ee-moment-core'), |
|
| 1976 | + EVENT_ESPRESSO_VERSION, |
|
| 1977 | + true |
|
| 1978 | + ); |
|
| 1979 | + wp_register_script( |
|
| 1980 | + 'ee-datepicker', |
|
| 1981 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1982 | + array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1983 | + EVENT_ESPRESSO_VERSION, |
|
| 1984 | + true |
|
| 1985 | + ); |
|
| 1986 | + //google charts |
|
| 1987 | + wp_register_script( |
|
| 1988 | + 'google-charts', |
|
| 1989 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1990 | + array(), |
|
| 1991 | + EVENT_ESPRESSO_VERSION, |
|
| 1992 | + false |
|
| 1993 | + ); |
|
| 1994 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1995 | + wp_enqueue_style('ee-admin-css'); |
|
| 1996 | + wp_enqueue_script('ee_admin_js'); |
|
| 1997 | + wp_enqueue_script('ee-accounting'); |
|
| 1998 | + wp_enqueue_script('jquery-validate'); |
|
| 1999 | + //taking care of metaboxes |
|
| 2000 | + if ( |
|
| 2001 | + empty($this->_cpt_route) |
|
| 2002 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2003 | + ) { |
|
| 2004 | + wp_enqueue_script('dashboard'); |
|
| 2005 | + } |
|
| 2006 | + // LOCALIZED DATA |
|
| 2007 | + //localize script for ajax lazy loading |
|
| 2008 | + $lazy_loader_container_ids = apply_filters( |
|
| 2009 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2010 | + array('espresso_news_post_box_content') |
|
| 2011 | + ); |
|
| 2012 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2013 | + /** |
|
| 2014 | + * help tour stuff |
|
| 2015 | + */ |
|
| 2016 | + if (! empty($this->_help_tour)) { |
|
| 2017 | + //register the js for kicking things off |
|
| 2018 | + wp_enqueue_script( |
|
| 2019 | + 'ee-help-tour', |
|
| 2020 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2021 | + array('jquery-joyride'), |
|
| 2022 | + EVENT_ESPRESSO_VERSION, |
|
| 2023 | + true |
|
| 2024 | + ); |
|
| 2025 | + $tours = array(); |
|
| 2026 | + //setup tours for the js tour object |
|
| 2027 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2028 | + if ($tour instanceof EE_Help_Tour) { |
|
| 2029 | + $tours[] = array( |
|
| 2030 | + 'id' => $tour->get_slug(), |
|
| 2031 | + 'options' => $tour->get_options(), |
|
| 2032 | + ); |
|
| 2033 | + } |
|
| 2034 | + } |
|
| 2035 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2036 | + //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2037 | + } |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + |
|
| 2041 | + |
|
| 2042 | + /** |
|
| 2043 | + * admin_footer_scripts_eei18n_js_strings |
|
| 2044 | + * |
|
| 2045 | + * @return void |
|
| 2046 | + */ |
|
| 2047 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 2048 | + { |
|
| 2049 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2050 | + EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2051 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2052 | + 'event_espresso' |
|
| 2053 | + ); |
|
| 2054 | + EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2055 | + EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2056 | + EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2057 | + EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2058 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2059 | + EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2060 | + EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2061 | + EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2062 | + EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2063 | + EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2064 | + EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2065 | + EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2066 | + EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2067 | + EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2068 | + EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2069 | + EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2070 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2071 | + EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2072 | + EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2073 | + EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2074 | + EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2075 | + EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2076 | + EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2077 | + EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2078 | + EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2079 | + EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2080 | + EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2081 | + EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2082 | + EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2083 | + EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2084 | + EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2085 | + EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2086 | + EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2087 | + EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2088 | + EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2089 | + EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2090 | + EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2091 | + EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + |
|
| 2095 | + |
|
| 2096 | + /** |
|
| 2097 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2098 | + * |
|
| 2099 | + * @return void |
|
| 2100 | + */ |
|
| 2101 | + public function add_xdebug_style() |
|
| 2102 | + { |
|
| 2103 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + |
|
| 2107 | + /************************/ |
|
| 2108 | + /** LIST TABLE METHODS **/ |
|
| 2109 | + /************************/ |
|
| 2110 | + /** |
|
| 2111 | + * this sets up the list table if the current view requires it. |
|
| 2112 | + * |
|
| 2113 | + * @return void |
|
| 2114 | + * @throws EE_Error |
|
| 2115 | + */ |
|
| 2116 | + protected function _set_list_table() |
|
| 2117 | + { |
|
| 2118 | + //first is this a list_table view? |
|
| 2119 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2120 | + return; |
|
| 2121 | + } //not a list_table view so get out. |
|
| 2122 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2123 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2124 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2125 | + //user error msg |
|
| 2126 | + $error_msg = esc_html__( |
|
| 2127 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2128 | + 'event_espresso' |
|
| 2129 | + ); |
|
| 2130 | + //developer error msg |
|
| 2131 | + $error_msg .= '||' . sprintf( |
|
| 2132 | + esc_html__( |
|
| 2133 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2134 | + 'event_espresso' |
|
| 2135 | + ), |
|
| 2136 | + $this->_req_action, |
|
| 2137 | + $list_table_view |
|
| 2138 | + ); |
|
| 2139 | + throw new EE_Error($error_msg); |
|
| 2140 | + } |
|
| 2141 | + //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2142 | + $this->_views = apply_filters( |
|
| 2143 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2144 | + $this->_views |
|
| 2145 | + ); |
|
| 2146 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2147 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2148 | + $this->_set_list_table_view(); |
|
| 2149 | + $this->_set_list_table_object(); |
|
| 2150 | + } |
|
| 2151 | + |
|
| 2152 | + |
|
| 2153 | + |
|
| 2154 | + /** |
|
| 2155 | + * set current view for List Table |
|
| 2156 | + * |
|
| 2157 | + * @return void |
|
| 2158 | + */ |
|
| 2159 | + protected function _set_list_table_view() |
|
| 2160 | + { |
|
| 2161 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2162 | + // looking at active items or dumpster diving ? |
|
| 2163 | + if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2164 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2165 | + } else { |
|
| 2166 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2167 | + } |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + |
|
| 2171 | + |
|
| 2172 | + /** |
|
| 2173 | + * _set_list_table_object |
|
| 2174 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2175 | + * |
|
| 2176 | + * @throws EE_Error |
|
| 2177 | + */ |
|
| 2178 | + protected function _set_list_table_object() |
|
| 2179 | + { |
|
| 2180 | + if (isset($this->_route_config['list_table'])) { |
|
| 2181 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2182 | + throw new EE_Error( |
|
| 2183 | + sprintf( |
|
| 2184 | + esc_html__( |
|
| 2185 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2186 | + 'event_espresso' |
|
| 2187 | + ), |
|
| 2188 | + $this->_route_config['list_table'], |
|
| 2189 | + get_class($this) |
|
| 2190 | + ) |
|
| 2191 | + ); |
|
| 2192 | + } |
|
| 2193 | + $list_table = $this->_route_config['list_table']; |
|
| 2194 | + $this->_list_table_object = new $list_table($this); |
|
| 2195 | + } |
|
| 2196 | + } |
|
| 2197 | + |
|
| 2198 | + |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2202 | + * |
|
| 2203 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2204 | + * urls. The array should be indexed by the view it is being |
|
| 2205 | + * added to. |
|
| 2206 | + * @return array |
|
| 2207 | + */ |
|
| 2208 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2209 | + { |
|
| 2210 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2211 | + if (empty($this->_views)) { |
|
| 2212 | + $this->_views = array(); |
|
| 2213 | + } |
|
| 2214 | + // cycle thru views |
|
| 2215 | + foreach ($this->_views as $key => $view) { |
|
| 2216 | + $query_args = array(); |
|
| 2217 | + // check for current view |
|
| 2218 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2219 | + $query_args['action'] = $this->_req_action; |
|
| 2220 | + $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2221 | + $query_args['status'] = $view['slug']; |
|
| 2222 | + //merge any other arguments sent in. |
|
| 2223 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2224 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2225 | + } |
|
| 2226 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2227 | + } |
|
| 2228 | + return $this->_views; |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * _entries_per_page_dropdown |
|
| 2235 | + * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2236 | + * |
|
| 2237 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2238 | + * WP does it. |
|
| 2239 | + * @param int $max_entries total number of rows in the table |
|
| 2240 | + * @return string |
|
| 2241 | + */ |
|
| 2242 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2243 | + { |
|
| 2244 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2245 | + $values = array(10, 25, 50, 100); |
|
| 2246 | + $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2247 | + if ($max_entries) { |
|
| 2248 | + $values[] = $max_entries; |
|
| 2249 | + sort($values); |
|
| 2250 | + } |
|
| 2251 | + $entries_per_page_dropdown = ' |
|
| 2252 | 2252 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2253 | 2253 | <label class="hide-if-no-js"> |
| 2254 | 2254 | Show |
| 2255 | 2255 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2256 | - foreach ($values as $value) { |
|
| 2257 | - if ($value < $max_entries) { |
|
| 2258 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2259 | - $entries_per_page_dropdown .= ' |
|
| 2256 | + foreach ($values as $value) { |
|
| 2257 | + if ($value < $max_entries) { |
|
| 2258 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2259 | + $entries_per_page_dropdown .= ' |
|
| 2260 | 2260 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2261 | - } |
|
| 2262 | - } |
|
| 2263 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2264 | - $entries_per_page_dropdown .= ' |
|
| 2261 | + } |
|
| 2262 | + } |
|
| 2263 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2264 | + $entries_per_page_dropdown .= ' |
|
| 2265 | 2265 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2266 | - $entries_per_page_dropdown .= ' |
|
| 2266 | + $entries_per_page_dropdown .= ' |
|
| 2267 | 2267 | </select> |
| 2268 | 2268 | entries |
| 2269 | 2269 | </label> |
| 2270 | 2270 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2271 | 2271 | </div> |
| 2272 | 2272 | '; |
| 2273 | - return $entries_per_page_dropdown; |
|
| 2274 | - } |
|
| 2275 | - |
|
| 2276 | - |
|
| 2277 | - |
|
| 2278 | - /** |
|
| 2279 | - * _set_search_attributes |
|
| 2280 | - * |
|
| 2281 | - * @return void |
|
| 2282 | - */ |
|
| 2283 | - public function _set_search_attributes() |
|
| 2284 | - { |
|
| 2285 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2286 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2287 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2288 | - : $this->_search_btn_label |
|
| 2289 | - ); |
|
| 2290 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2291 | - } |
|
| 2292 | - |
|
| 2293 | - |
|
| 2294 | - |
|
| 2295 | - /*** END LIST TABLE METHODS **/ |
|
| 2296 | - |
|
| 2297 | - |
|
| 2298 | - |
|
| 2299 | - /** |
|
| 2300 | - * _add_registered_metaboxes |
|
| 2301 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2302 | - * |
|
| 2303 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2304 | - * @return void |
|
| 2305 | - * @throws EE_Error |
|
| 2306 | - */ |
|
| 2307 | - private function _add_registered_meta_boxes() |
|
| 2308 | - { |
|
| 2309 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2310 | - //we only add meta boxes if the page_route calls for it |
|
| 2311 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2312 | - && is_array( |
|
| 2313 | - $this->_route_config['metaboxes'] |
|
| 2314 | - ) |
|
| 2315 | - ) { |
|
| 2316 | - // this simply loops through the callbacks provided |
|
| 2317 | - // and checks if there is a corresponding callback registered by the child |
|
| 2318 | - // if there is then we go ahead and process the metabox loader. |
|
| 2319 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2320 | - // first check for Closures |
|
| 2321 | - if ($metabox_callback instanceof Closure) { |
|
| 2322 | - $result = $metabox_callback(); |
|
| 2323 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2324 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2325 | - } else { |
|
| 2326 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2327 | - } |
|
| 2328 | - if ($result === false) { |
|
| 2329 | - // user error msg |
|
| 2330 | - $error_msg = esc_html__( |
|
| 2331 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2332 | - 'event_espresso' |
|
| 2333 | - ); |
|
| 2334 | - // developer error msg |
|
| 2335 | - $error_msg .= '||' . sprintf( |
|
| 2336 | - esc_html__( |
|
| 2337 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2338 | - 'event_espresso' |
|
| 2339 | - ), |
|
| 2340 | - $metabox_callback |
|
| 2341 | - ); |
|
| 2342 | - throw new EE_Error($error_msg); |
|
| 2343 | - } |
|
| 2344 | - } |
|
| 2345 | - } |
|
| 2346 | - } |
|
| 2347 | - |
|
| 2348 | - |
|
| 2349 | - |
|
| 2350 | - /** |
|
| 2351 | - * _add_screen_columns |
|
| 2352 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2353 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2354 | - * |
|
| 2355 | - * @return void |
|
| 2356 | - */ |
|
| 2357 | - private function _add_screen_columns() |
|
| 2358 | - { |
|
| 2359 | - if ( |
|
| 2360 | - is_array($this->_route_config) |
|
| 2361 | - && isset($this->_route_config['columns']) |
|
| 2362 | - && is_array($this->_route_config['columns']) |
|
| 2363 | - && count($this->_route_config['columns']) === 2 |
|
| 2364 | - ) { |
|
| 2365 | - add_screen_option( |
|
| 2366 | - 'layout_columns', |
|
| 2367 | - array( |
|
| 2368 | - 'max' => (int)$this->_route_config['columns'][0], |
|
| 2369 | - 'default' => (int)$this->_route_config['columns'][1], |
|
| 2370 | - ) |
|
| 2371 | - ); |
|
| 2372 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2373 | - $screen_id = $this->_current_screen->id; |
|
| 2374 | - $screen_columns = (int)get_user_option("screen_layout_{$screen_id}"); |
|
| 2375 | - $total_columns = ! empty($screen_columns) |
|
| 2376 | - ? $screen_columns |
|
| 2377 | - : $this->_route_config['columns'][1]; |
|
| 2378 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2379 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2380 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2381 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2382 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2383 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2384 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2385 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2386 | - } |
|
| 2387 | - } |
|
| 2388 | - |
|
| 2389 | - |
|
| 2390 | - |
|
| 2391 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - /** |
|
| 2395 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2396 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2397 | - * these get loaded on. |
|
| 2398 | - */ |
|
| 2399 | - private function _espresso_news_post_box() |
|
| 2400 | - { |
|
| 2401 | - $news_box_title = apply_filters( |
|
| 2402 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2403 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2404 | - ); |
|
| 2405 | - add_meta_box( |
|
| 2406 | - 'espresso_news_post_box', |
|
| 2407 | - $news_box_title, |
|
| 2408 | - array( |
|
| 2409 | - $this, |
|
| 2410 | - 'espresso_news_post_box', |
|
| 2411 | - ), |
|
| 2412 | - $this->_wp_page_slug, |
|
| 2413 | - 'side' |
|
| 2414 | - ); |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - /** |
|
| 2420 | - * Code for setting up espresso ratings request metabox. |
|
| 2421 | - */ |
|
| 2422 | - protected function _espresso_ratings_request() |
|
| 2423 | - { |
|
| 2424 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2425 | - return; |
|
| 2426 | - } |
|
| 2427 | - $ratings_box_title = apply_filters( |
|
| 2428 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2429 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2430 | - ); |
|
| 2431 | - add_meta_box( |
|
| 2432 | - 'espresso_ratings_request', |
|
| 2433 | - $ratings_box_title, |
|
| 2434 | - array( |
|
| 2435 | - $this, |
|
| 2436 | - 'espresso_ratings_request', |
|
| 2437 | - ), |
|
| 2438 | - $this->_wp_page_slug, |
|
| 2439 | - 'side' |
|
| 2440 | - ); |
|
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - |
|
| 2444 | - |
|
| 2445 | - /** |
|
| 2446 | - * Code for setting up espresso ratings request metabox content. |
|
| 2447 | - * |
|
| 2448 | - * @throws DomainException |
|
| 2449 | - */ |
|
| 2450 | - public function espresso_ratings_request() |
|
| 2451 | - { |
|
| 2452 | - EEH_Template::display_template( |
|
| 2453 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2454 | - array() |
|
| 2455 | - ); |
|
| 2456 | - } |
|
| 2457 | - |
|
| 2458 | - |
|
| 2459 | - |
|
| 2460 | - public static function cached_rss_display($rss_id, $url) |
|
| 2461 | - { |
|
| 2462 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2463 | - . __('Loading…') |
|
| 2464 | - . '</p><p class="hide-if-js">' |
|
| 2465 | - . esc_html__('This widget requires JavaScript.') |
|
| 2466 | - . '</p>'; |
|
| 2467 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2468 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2469 | - $post = '</div>' . "\n"; |
|
| 2470 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2471 | - $output = get_transient($cache_key); |
|
| 2472 | - if ($output !== false) { |
|
| 2473 | - echo $pre . $output . $post; |
|
| 2474 | - return true; |
|
| 2475 | - } |
|
| 2476 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2477 | - echo $pre . $loading . $post; |
|
| 2478 | - return false; |
|
| 2479 | - } |
|
| 2480 | - ob_start(); |
|
| 2481 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2482 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2483 | - return true; |
|
| 2484 | - } |
|
| 2485 | - |
|
| 2486 | - |
|
| 2487 | - |
|
| 2488 | - public function espresso_news_post_box() |
|
| 2489 | - { |
|
| 2490 | - ?> |
|
| 2273 | + return $entries_per_page_dropdown; |
|
| 2274 | + } |
|
| 2275 | + |
|
| 2276 | + |
|
| 2277 | + |
|
| 2278 | + /** |
|
| 2279 | + * _set_search_attributes |
|
| 2280 | + * |
|
| 2281 | + * @return void |
|
| 2282 | + */ |
|
| 2283 | + public function _set_search_attributes() |
|
| 2284 | + { |
|
| 2285 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2286 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2287 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2288 | + : $this->_search_btn_label |
|
| 2289 | + ); |
|
| 2290 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2291 | + } |
|
| 2292 | + |
|
| 2293 | + |
|
| 2294 | + |
|
| 2295 | + /*** END LIST TABLE METHODS **/ |
|
| 2296 | + |
|
| 2297 | + |
|
| 2298 | + |
|
| 2299 | + /** |
|
| 2300 | + * _add_registered_metaboxes |
|
| 2301 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2302 | + * |
|
| 2303 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2304 | + * @return void |
|
| 2305 | + * @throws EE_Error |
|
| 2306 | + */ |
|
| 2307 | + private function _add_registered_meta_boxes() |
|
| 2308 | + { |
|
| 2309 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2310 | + //we only add meta boxes if the page_route calls for it |
|
| 2311 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2312 | + && is_array( |
|
| 2313 | + $this->_route_config['metaboxes'] |
|
| 2314 | + ) |
|
| 2315 | + ) { |
|
| 2316 | + // this simply loops through the callbacks provided |
|
| 2317 | + // and checks if there is a corresponding callback registered by the child |
|
| 2318 | + // if there is then we go ahead and process the metabox loader. |
|
| 2319 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2320 | + // first check for Closures |
|
| 2321 | + if ($metabox_callback instanceof Closure) { |
|
| 2322 | + $result = $metabox_callback(); |
|
| 2323 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2324 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2325 | + } else { |
|
| 2326 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2327 | + } |
|
| 2328 | + if ($result === false) { |
|
| 2329 | + // user error msg |
|
| 2330 | + $error_msg = esc_html__( |
|
| 2331 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2332 | + 'event_espresso' |
|
| 2333 | + ); |
|
| 2334 | + // developer error msg |
|
| 2335 | + $error_msg .= '||' . sprintf( |
|
| 2336 | + esc_html__( |
|
| 2337 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2338 | + 'event_espresso' |
|
| 2339 | + ), |
|
| 2340 | + $metabox_callback |
|
| 2341 | + ); |
|
| 2342 | + throw new EE_Error($error_msg); |
|
| 2343 | + } |
|
| 2344 | + } |
|
| 2345 | + } |
|
| 2346 | + } |
|
| 2347 | + |
|
| 2348 | + |
|
| 2349 | + |
|
| 2350 | + /** |
|
| 2351 | + * _add_screen_columns |
|
| 2352 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2353 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2354 | + * |
|
| 2355 | + * @return void |
|
| 2356 | + */ |
|
| 2357 | + private function _add_screen_columns() |
|
| 2358 | + { |
|
| 2359 | + if ( |
|
| 2360 | + is_array($this->_route_config) |
|
| 2361 | + && isset($this->_route_config['columns']) |
|
| 2362 | + && is_array($this->_route_config['columns']) |
|
| 2363 | + && count($this->_route_config['columns']) === 2 |
|
| 2364 | + ) { |
|
| 2365 | + add_screen_option( |
|
| 2366 | + 'layout_columns', |
|
| 2367 | + array( |
|
| 2368 | + 'max' => (int)$this->_route_config['columns'][0], |
|
| 2369 | + 'default' => (int)$this->_route_config['columns'][1], |
|
| 2370 | + ) |
|
| 2371 | + ); |
|
| 2372 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2373 | + $screen_id = $this->_current_screen->id; |
|
| 2374 | + $screen_columns = (int)get_user_option("screen_layout_{$screen_id}"); |
|
| 2375 | + $total_columns = ! empty($screen_columns) |
|
| 2376 | + ? $screen_columns |
|
| 2377 | + : $this->_route_config['columns'][1]; |
|
| 2378 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2379 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2380 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2381 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2382 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2383 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2384 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2385 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2386 | + } |
|
| 2387 | + } |
|
| 2388 | + |
|
| 2389 | + |
|
| 2390 | + |
|
| 2391 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2396 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2397 | + * these get loaded on. |
|
| 2398 | + */ |
|
| 2399 | + private function _espresso_news_post_box() |
|
| 2400 | + { |
|
| 2401 | + $news_box_title = apply_filters( |
|
| 2402 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2403 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2404 | + ); |
|
| 2405 | + add_meta_box( |
|
| 2406 | + 'espresso_news_post_box', |
|
| 2407 | + $news_box_title, |
|
| 2408 | + array( |
|
| 2409 | + $this, |
|
| 2410 | + 'espresso_news_post_box', |
|
| 2411 | + ), |
|
| 2412 | + $this->_wp_page_slug, |
|
| 2413 | + 'side' |
|
| 2414 | + ); |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + /** |
|
| 2420 | + * Code for setting up espresso ratings request metabox. |
|
| 2421 | + */ |
|
| 2422 | + protected function _espresso_ratings_request() |
|
| 2423 | + { |
|
| 2424 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2425 | + return; |
|
| 2426 | + } |
|
| 2427 | + $ratings_box_title = apply_filters( |
|
| 2428 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2429 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2430 | + ); |
|
| 2431 | + add_meta_box( |
|
| 2432 | + 'espresso_ratings_request', |
|
| 2433 | + $ratings_box_title, |
|
| 2434 | + array( |
|
| 2435 | + $this, |
|
| 2436 | + 'espresso_ratings_request', |
|
| 2437 | + ), |
|
| 2438 | + $this->_wp_page_slug, |
|
| 2439 | + 'side' |
|
| 2440 | + ); |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + |
|
| 2444 | + |
|
| 2445 | + /** |
|
| 2446 | + * Code for setting up espresso ratings request metabox content. |
|
| 2447 | + * |
|
| 2448 | + * @throws DomainException |
|
| 2449 | + */ |
|
| 2450 | + public function espresso_ratings_request() |
|
| 2451 | + { |
|
| 2452 | + EEH_Template::display_template( |
|
| 2453 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2454 | + array() |
|
| 2455 | + ); |
|
| 2456 | + } |
|
| 2457 | + |
|
| 2458 | + |
|
| 2459 | + |
|
| 2460 | + public static function cached_rss_display($rss_id, $url) |
|
| 2461 | + { |
|
| 2462 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2463 | + . __('Loading…') |
|
| 2464 | + . '</p><p class="hide-if-js">' |
|
| 2465 | + . esc_html__('This widget requires JavaScript.') |
|
| 2466 | + . '</p>'; |
|
| 2467 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2468 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2469 | + $post = '</div>' . "\n"; |
|
| 2470 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2471 | + $output = get_transient($cache_key); |
|
| 2472 | + if ($output !== false) { |
|
| 2473 | + echo $pre . $output . $post; |
|
| 2474 | + return true; |
|
| 2475 | + } |
|
| 2476 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2477 | + echo $pre . $loading . $post; |
|
| 2478 | + return false; |
|
| 2479 | + } |
|
| 2480 | + ob_start(); |
|
| 2481 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2482 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2483 | + return true; |
|
| 2484 | + } |
|
| 2485 | + |
|
| 2486 | + |
|
| 2487 | + |
|
| 2488 | + public function espresso_news_post_box() |
|
| 2489 | + { |
|
| 2490 | + ?> |
|
| 2491 | 2491 | <div class="padding"> |
| 2492 | 2492 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2493 | 2493 | <?php |
| 2494 | - // Get RSS Feed(s) |
|
| 2495 | - self::cached_rss_display( |
|
| 2496 | - 'espresso_news_post_box_content', |
|
| 2497 | - urlencode( |
|
| 2498 | - apply_filters( |
|
| 2499 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2500 | - 'http://eventespresso.com/feed/' |
|
| 2501 | - ) |
|
| 2502 | - ) |
|
| 2503 | - ); |
|
| 2504 | - ?> |
|
| 2494 | + // Get RSS Feed(s) |
|
| 2495 | + self::cached_rss_display( |
|
| 2496 | + 'espresso_news_post_box_content', |
|
| 2497 | + urlencode( |
|
| 2498 | + apply_filters( |
|
| 2499 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2500 | + 'http://eventespresso.com/feed/' |
|
| 2501 | + ) |
|
| 2502 | + ) |
|
| 2503 | + ); |
|
| 2504 | + ?> |
|
| 2505 | 2505 | </div> |
| 2506 | 2506 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2507 | 2507 | </div> |
| 2508 | 2508 | <?php |
| 2509 | - } |
|
| 2510 | - |
|
| 2511 | - |
|
| 2512 | - |
|
| 2513 | - private function _espresso_links_post_box() |
|
| 2514 | - { |
|
| 2515 | - //Hiding until we actually have content to put in here... |
|
| 2516 | - //add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2517 | - } |
|
| 2518 | - |
|
| 2519 | - |
|
| 2520 | - |
|
| 2521 | - public function espresso_links_post_box() |
|
| 2522 | - { |
|
| 2523 | - //Hiding until we actually have content to put in here... |
|
| 2524 | - // EEH_Template::display_template( |
|
| 2525 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2526 | - // ); |
|
| 2527 | - } |
|
| 2528 | - |
|
| 2529 | - |
|
| 2530 | - |
|
| 2531 | - protected function _espresso_sponsors_post_box() |
|
| 2532 | - { |
|
| 2533 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2534 | - add_meta_box( |
|
| 2535 | - 'espresso_sponsors_post_box', |
|
| 2536 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2537 | - array($this, 'espresso_sponsors_post_box'), |
|
| 2538 | - $this->_wp_page_slug, |
|
| 2539 | - 'side' |
|
| 2540 | - ); |
|
| 2541 | - } |
|
| 2542 | - } |
|
| 2543 | - |
|
| 2544 | - |
|
| 2545 | - |
|
| 2546 | - public function espresso_sponsors_post_box() |
|
| 2547 | - { |
|
| 2548 | - EEH_Template::display_template( |
|
| 2549 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2550 | - ); |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - |
|
| 2554 | - |
|
| 2555 | - private function _publish_post_box() |
|
| 2556 | - { |
|
| 2557 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2558 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2559 | - // then we'll use that for the metabox label. |
|
| 2560 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2561 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2562 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2563 | - : $this->_labels['publishbox']; |
|
| 2564 | - } else { |
|
| 2565 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2566 | - } |
|
| 2567 | - $box_label = apply_filters( |
|
| 2568 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2569 | - $box_label, |
|
| 2570 | - $this->_req_action, |
|
| 2571 | - $this |
|
| 2572 | - ); |
|
| 2573 | - add_meta_box( |
|
| 2574 | - $meta_box_ref, |
|
| 2575 | - $box_label, |
|
| 2576 | - array($this, 'editor_overview'), |
|
| 2577 | - $this->_current_screen->id, |
|
| 2578 | - 'side', |
|
| 2579 | - 'high' |
|
| 2580 | - ); |
|
| 2581 | - } |
|
| 2582 | - |
|
| 2583 | - |
|
| 2584 | - |
|
| 2585 | - public function editor_overview() |
|
| 2586 | - { |
|
| 2587 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2588 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2589 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2590 | - : ''; |
|
| 2591 | - echo EEH_Template::display_template( |
|
| 2592 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2593 | - $this->_template_args, |
|
| 2594 | - true |
|
| 2595 | - ); |
|
| 2596 | - } |
|
| 2597 | - |
|
| 2598 | - |
|
| 2599 | - /** end of globally available metaboxes section **/ |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - |
|
| 2603 | - /** |
|
| 2604 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2605 | - * protected method. |
|
| 2606 | - * |
|
| 2607 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2608 | - * @since 4.6.0 |
|
| 2609 | - * @param string $name |
|
| 2610 | - * @param int $id |
|
| 2611 | - * @param bool $delete |
|
| 2612 | - * @param string $save_close_redirect_URL |
|
| 2613 | - * @param bool $both_btns |
|
| 2614 | - * @throws EE_Error |
|
| 2615 | - * @throws InvalidArgumentException |
|
| 2616 | - * @throws InvalidDataTypeException |
|
| 2617 | - * @throws InvalidInterfaceException |
|
| 2618 | - */ |
|
| 2619 | - public function set_publish_post_box_vars( |
|
| 2620 | - $name = '', |
|
| 2621 | - $id = 0, |
|
| 2622 | - $delete = false, |
|
| 2623 | - $save_close_redirect_URL = '', |
|
| 2624 | - $both_btns = true |
|
| 2625 | - ) { |
|
| 2626 | - $this->_set_publish_post_box_vars( |
|
| 2627 | - $name, |
|
| 2628 | - $id, |
|
| 2629 | - $delete, |
|
| 2630 | - $save_close_redirect_URL, |
|
| 2631 | - $both_btns |
|
| 2632 | - ); |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - |
|
| 2636 | - |
|
| 2637 | - /** |
|
| 2638 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2639 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2640 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2641 | - * values for the name and id arguments. |
|
| 2642 | - * |
|
| 2643 | - * @todo Add in validation for name/id arguments. |
|
| 2644 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2645 | - * @param int $id id attached to the item published |
|
| 2646 | - * @param string $delete page route callback for the delete action |
|
| 2647 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2648 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2649 | - * the Save button |
|
| 2650 | - * @throws EE_Error |
|
| 2651 | - * @throws InvalidArgumentException |
|
| 2652 | - * @throws InvalidDataTypeException |
|
| 2653 | - * @throws InvalidInterfaceException |
|
| 2654 | - */ |
|
| 2655 | - protected function _set_publish_post_box_vars( |
|
| 2656 | - $name = '', |
|
| 2657 | - $id = 0, |
|
| 2658 | - $delete = '', |
|
| 2659 | - $save_close_redirect_URL = '', |
|
| 2660 | - $both_btns = true |
|
| 2661 | - ) { |
|
| 2662 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2663 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2664 | - ? $save_close_redirect_URL |
|
| 2665 | - : $this->_admin_base_url; |
|
| 2666 | - // create the Save & Close and Save buttons |
|
| 2667 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2668 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2669 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2670 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2671 | - : ''; |
|
| 2672 | - if ($delete && ! empty($id)) { |
|
| 2673 | - //make sure we have a default if just true is sent. |
|
| 2674 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2675 | - $delete_link_args = array($name => $id); |
|
| 2676 | - $delete = $this->get_action_link_or_button( |
|
| 2677 | - $delete, |
|
| 2678 | - $delete, |
|
| 2679 | - $delete_link_args, |
|
| 2680 | - 'submitdelete deletion', |
|
| 2681 | - '', |
|
| 2682 | - false |
|
| 2683 | - ); |
|
| 2684 | - } |
|
| 2685 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2686 | - if (! empty($name) && ! empty($id)) { |
|
| 2687 | - $hidden_field_arr[$name] = array( |
|
| 2688 | - 'type' => 'hidden', |
|
| 2689 | - 'value' => $id, |
|
| 2690 | - ); |
|
| 2691 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2692 | - } else { |
|
| 2693 | - $hf = ''; |
|
| 2694 | - } |
|
| 2695 | - // add hidden field |
|
| 2696 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2697 | - ? $hf[$name]['field'] |
|
| 2698 | - : $hf; |
|
| 2699 | - } |
|
| 2700 | - |
|
| 2701 | - |
|
| 2702 | - |
|
| 2703 | - /** |
|
| 2704 | - * displays an error message to ppl who have javascript disabled |
|
| 2705 | - * |
|
| 2706 | - * @return void |
|
| 2707 | - */ |
|
| 2708 | - private function _display_no_javascript_warning() |
|
| 2709 | - { |
|
| 2710 | - ?> |
|
| 2509 | + } |
|
| 2510 | + |
|
| 2511 | + |
|
| 2512 | + |
|
| 2513 | + private function _espresso_links_post_box() |
|
| 2514 | + { |
|
| 2515 | + //Hiding until we actually have content to put in here... |
|
| 2516 | + //add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2517 | + } |
|
| 2518 | + |
|
| 2519 | + |
|
| 2520 | + |
|
| 2521 | + public function espresso_links_post_box() |
|
| 2522 | + { |
|
| 2523 | + //Hiding until we actually have content to put in here... |
|
| 2524 | + // EEH_Template::display_template( |
|
| 2525 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2526 | + // ); |
|
| 2527 | + } |
|
| 2528 | + |
|
| 2529 | + |
|
| 2530 | + |
|
| 2531 | + protected function _espresso_sponsors_post_box() |
|
| 2532 | + { |
|
| 2533 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2534 | + add_meta_box( |
|
| 2535 | + 'espresso_sponsors_post_box', |
|
| 2536 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2537 | + array($this, 'espresso_sponsors_post_box'), |
|
| 2538 | + $this->_wp_page_slug, |
|
| 2539 | + 'side' |
|
| 2540 | + ); |
|
| 2541 | + } |
|
| 2542 | + } |
|
| 2543 | + |
|
| 2544 | + |
|
| 2545 | + |
|
| 2546 | + public function espresso_sponsors_post_box() |
|
| 2547 | + { |
|
| 2548 | + EEH_Template::display_template( |
|
| 2549 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2550 | + ); |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + |
|
| 2554 | + |
|
| 2555 | + private function _publish_post_box() |
|
| 2556 | + { |
|
| 2557 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2558 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2559 | + // then we'll use that for the metabox label. |
|
| 2560 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2561 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2562 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2563 | + : $this->_labels['publishbox']; |
|
| 2564 | + } else { |
|
| 2565 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2566 | + } |
|
| 2567 | + $box_label = apply_filters( |
|
| 2568 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2569 | + $box_label, |
|
| 2570 | + $this->_req_action, |
|
| 2571 | + $this |
|
| 2572 | + ); |
|
| 2573 | + add_meta_box( |
|
| 2574 | + $meta_box_ref, |
|
| 2575 | + $box_label, |
|
| 2576 | + array($this, 'editor_overview'), |
|
| 2577 | + $this->_current_screen->id, |
|
| 2578 | + 'side', |
|
| 2579 | + 'high' |
|
| 2580 | + ); |
|
| 2581 | + } |
|
| 2582 | + |
|
| 2583 | + |
|
| 2584 | + |
|
| 2585 | + public function editor_overview() |
|
| 2586 | + { |
|
| 2587 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2588 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2589 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2590 | + : ''; |
|
| 2591 | + echo EEH_Template::display_template( |
|
| 2592 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2593 | + $this->_template_args, |
|
| 2594 | + true |
|
| 2595 | + ); |
|
| 2596 | + } |
|
| 2597 | + |
|
| 2598 | + |
|
| 2599 | + /** end of globally available metaboxes section **/ |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + |
|
| 2603 | + /** |
|
| 2604 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2605 | + * protected method. |
|
| 2606 | + * |
|
| 2607 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2608 | + * @since 4.6.0 |
|
| 2609 | + * @param string $name |
|
| 2610 | + * @param int $id |
|
| 2611 | + * @param bool $delete |
|
| 2612 | + * @param string $save_close_redirect_URL |
|
| 2613 | + * @param bool $both_btns |
|
| 2614 | + * @throws EE_Error |
|
| 2615 | + * @throws InvalidArgumentException |
|
| 2616 | + * @throws InvalidDataTypeException |
|
| 2617 | + * @throws InvalidInterfaceException |
|
| 2618 | + */ |
|
| 2619 | + public function set_publish_post_box_vars( |
|
| 2620 | + $name = '', |
|
| 2621 | + $id = 0, |
|
| 2622 | + $delete = false, |
|
| 2623 | + $save_close_redirect_URL = '', |
|
| 2624 | + $both_btns = true |
|
| 2625 | + ) { |
|
| 2626 | + $this->_set_publish_post_box_vars( |
|
| 2627 | + $name, |
|
| 2628 | + $id, |
|
| 2629 | + $delete, |
|
| 2630 | + $save_close_redirect_URL, |
|
| 2631 | + $both_btns |
|
| 2632 | + ); |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + |
|
| 2636 | + |
|
| 2637 | + /** |
|
| 2638 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2639 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2640 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2641 | + * values for the name and id arguments. |
|
| 2642 | + * |
|
| 2643 | + * @todo Add in validation for name/id arguments. |
|
| 2644 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2645 | + * @param int $id id attached to the item published |
|
| 2646 | + * @param string $delete page route callback for the delete action |
|
| 2647 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2648 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2649 | + * the Save button |
|
| 2650 | + * @throws EE_Error |
|
| 2651 | + * @throws InvalidArgumentException |
|
| 2652 | + * @throws InvalidDataTypeException |
|
| 2653 | + * @throws InvalidInterfaceException |
|
| 2654 | + */ |
|
| 2655 | + protected function _set_publish_post_box_vars( |
|
| 2656 | + $name = '', |
|
| 2657 | + $id = 0, |
|
| 2658 | + $delete = '', |
|
| 2659 | + $save_close_redirect_URL = '', |
|
| 2660 | + $both_btns = true |
|
| 2661 | + ) { |
|
| 2662 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2663 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2664 | + ? $save_close_redirect_URL |
|
| 2665 | + : $this->_admin_base_url; |
|
| 2666 | + // create the Save & Close and Save buttons |
|
| 2667 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2668 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2669 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2670 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2671 | + : ''; |
|
| 2672 | + if ($delete && ! empty($id)) { |
|
| 2673 | + //make sure we have a default if just true is sent. |
|
| 2674 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2675 | + $delete_link_args = array($name => $id); |
|
| 2676 | + $delete = $this->get_action_link_or_button( |
|
| 2677 | + $delete, |
|
| 2678 | + $delete, |
|
| 2679 | + $delete_link_args, |
|
| 2680 | + 'submitdelete deletion', |
|
| 2681 | + '', |
|
| 2682 | + false |
|
| 2683 | + ); |
|
| 2684 | + } |
|
| 2685 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2686 | + if (! empty($name) && ! empty($id)) { |
|
| 2687 | + $hidden_field_arr[$name] = array( |
|
| 2688 | + 'type' => 'hidden', |
|
| 2689 | + 'value' => $id, |
|
| 2690 | + ); |
|
| 2691 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2692 | + } else { |
|
| 2693 | + $hf = ''; |
|
| 2694 | + } |
|
| 2695 | + // add hidden field |
|
| 2696 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2697 | + ? $hf[$name]['field'] |
|
| 2698 | + : $hf; |
|
| 2699 | + } |
|
| 2700 | + |
|
| 2701 | + |
|
| 2702 | + |
|
| 2703 | + /** |
|
| 2704 | + * displays an error message to ppl who have javascript disabled |
|
| 2705 | + * |
|
| 2706 | + * @return void |
|
| 2707 | + */ |
|
| 2708 | + private function _display_no_javascript_warning() |
|
| 2709 | + { |
|
| 2710 | + ?> |
|
| 2711 | 2711 | <noscript> |
| 2712 | 2712 | <div id="no-js-message" class="error"> |
| 2713 | 2713 | <p style="font-size:1.3em;"> |
| 2714 | 2714 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2715 | 2715 | <?php esc_html_e( |
| 2716 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2717 | - 'event_espresso' |
|
| 2718 | - ); ?> |
|
| 2716 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2717 | + 'event_espresso' |
|
| 2718 | + ); ?> |
|
| 2719 | 2719 | </p> |
| 2720 | 2720 | </div> |
| 2721 | 2721 | </noscript> |
| 2722 | 2722 | <?php |
| 2723 | - } |
|
| 2723 | + } |
|
| 2724 | 2724 | |
| 2725 | 2725 | |
| 2726 | 2726 | |
| 2727 | - /** |
|
| 2728 | - * displays espresso success and/or error notices |
|
| 2729 | - * |
|
| 2730 | - * @return void |
|
| 2731 | - */ |
|
| 2732 | - private function _display_espresso_notices() |
|
| 2733 | - { |
|
| 2734 | - $notices = $this->_get_transient(true); |
|
| 2735 | - echo stripslashes($notices); |
|
| 2736 | - } |
|
| 2727 | + /** |
|
| 2728 | + * displays espresso success and/or error notices |
|
| 2729 | + * |
|
| 2730 | + * @return void |
|
| 2731 | + */ |
|
| 2732 | + private function _display_espresso_notices() |
|
| 2733 | + { |
|
| 2734 | + $notices = $this->_get_transient(true); |
|
| 2735 | + echo stripslashes($notices); |
|
| 2736 | + } |
|
| 2737 | 2737 | |
| 2738 | 2738 | |
| 2739 | 2739 | |
| 2740 | - /** |
|
| 2741 | - * spinny things pacify the masses |
|
| 2742 | - * |
|
| 2743 | - * @return void |
|
| 2744 | - */ |
|
| 2745 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2746 | - { |
|
| 2747 | - ?> |
|
| 2740 | + /** |
|
| 2741 | + * spinny things pacify the masses |
|
| 2742 | + * |
|
| 2743 | + * @return void |
|
| 2744 | + */ |
|
| 2745 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2746 | + { |
|
| 2747 | + ?> |
|
| 2748 | 2748 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2749 | 2749 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e( |
| 2750 | - 'loading...', |
|
| 2751 | - 'event_espresso' |
|
| 2752 | - ); ?></span> |
|
| 2750 | + 'loading...', |
|
| 2751 | + 'event_espresso' |
|
| 2752 | + ); ?></span> |
|
| 2753 | 2753 | </div> |
| 2754 | 2754 | <?php |
| 2755 | - } |
|
| 2755 | + } |
|
| 2756 | 2756 | |
| 2757 | 2757 | |
| 2758 | 2758 | |
| 2759 | - /** |
|
| 2760 | - * add admin page overlay for modal boxes |
|
| 2761 | - * |
|
| 2762 | - * @return void |
|
| 2763 | - */ |
|
| 2764 | - protected function _add_admin_page_overlay() |
|
| 2765 | - { |
|
| 2766 | - ?> |
|
| 2759 | + /** |
|
| 2760 | + * add admin page overlay for modal boxes |
|
| 2761 | + * |
|
| 2762 | + * @return void |
|
| 2763 | + */ |
|
| 2764 | + protected function _add_admin_page_overlay() |
|
| 2765 | + { |
|
| 2766 | + ?> |
|
| 2767 | 2767 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2768 | 2768 | <?php |
| 2769 | - } |
|
| 2770 | - |
|
| 2771 | - |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * facade for add_meta_box |
|
| 2775 | - * |
|
| 2776 | - * @param string $action where the metabox get's displayed |
|
| 2777 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2778 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2779 | - * instead of the one created in here. |
|
| 2780 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2781 | - * @param string $column what metabox column |
|
| 2782 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2783 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2784 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2785 | - * @throws \DomainException |
|
| 2786 | - */ |
|
| 2787 | - public function _add_admin_page_meta_box( |
|
| 2788 | - $action, |
|
| 2789 | - $title, |
|
| 2790 | - $callback, |
|
| 2791 | - $callback_args, |
|
| 2792 | - $column = 'normal', |
|
| 2793 | - $priority = 'high', |
|
| 2794 | - $create_func = true |
|
| 2795 | - ) { |
|
| 2796 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2797 | - //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2798 | - if (empty($callback_args) && $create_func) { |
|
| 2799 | - $callback_args = array( |
|
| 2800 | - 'template_path' => $this->_template_path, |
|
| 2801 | - 'template_args' => $this->_template_args, |
|
| 2802 | - ); |
|
| 2803 | - } |
|
| 2804 | - //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2805 | - $call_back_func = $create_func |
|
| 2806 | - ? function ($post, $metabox) |
|
| 2807 | - { |
|
| 2808 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2809 | - echo EEH_Template::display_template( |
|
| 2810 | - $metabox['args']['template_path'], |
|
| 2811 | - $metabox['args']['template_args'], |
|
| 2812 | - true |
|
| 2813 | - ); |
|
| 2814 | - } |
|
| 2815 | - : $callback; |
|
| 2816 | - add_meta_box( |
|
| 2817 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2818 | - $title, |
|
| 2819 | - $call_back_func, |
|
| 2820 | - $this->_wp_page_slug, |
|
| 2821 | - $column, |
|
| 2822 | - $priority, |
|
| 2823 | - $callback_args |
|
| 2824 | - ); |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - |
|
| 2828 | - |
|
| 2829 | - /** |
|
| 2830 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2831 | - * |
|
| 2832 | - * @throws DomainException |
|
| 2833 | - * @throws EE_Error |
|
| 2834 | - */ |
|
| 2835 | - public function display_admin_page_with_metabox_columns() |
|
| 2836 | - { |
|
| 2837 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2838 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2839 | - $this->_column_template_path, |
|
| 2840 | - $this->_template_args, |
|
| 2841 | - true |
|
| 2842 | - ); |
|
| 2843 | - //the final wrapper |
|
| 2844 | - $this->admin_page_wrapper(); |
|
| 2845 | - } |
|
| 2846 | - |
|
| 2847 | - |
|
| 2848 | - |
|
| 2849 | - /** |
|
| 2850 | - * generates HTML wrapper for an admin details page |
|
| 2851 | - * |
|
| 2852 | - * @return void |
|
| 2853 | - * @throws EE_Error |
|
| 2854 | - * @throws DomainException |
|
| 2855 | - */ |
|
| 2856 | - public function display_admin_page_with_sidebar() |
|
| 2857 | - { |
|
| 2858 | - $this->_display_admin_page(true); |
|
| 2859 | - } |
|
| 2860 | - |
|
| 2861 | - |
|
| 2862 | - |
|
| 2863 | - /** |
|
| 2864 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2865 | - * |
|
| 2866 | - * @return void |
|
| 2867 | - * @throws EE_Error |
|
| 2868 | - * @throws DomainException |
|
| 2869 | - */ |
|
| 2870 | - public function display_admin_page_with_no_sidebar() |
|
| 2871 | - { |
|
| 2872 | - $this->_display_admin_page(); |
|
| 2873 | - } |
|
| 2874 | - |
|
| 2875 | - |
|
| 2876 | - |
|
| 2877 | - /** |
|
| 2878 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2879 | - * |
|
| 2880 | - * @return void |
|
| 2881 | - * @throws EE_Error |
|
| 2882 | - * @throws DomainException |
|
| 2883 | - */ |
|
| 2884 | - public function display_about_admin_page() |
|
| 2885 | - { |
|
| 2886 | - $this->_display_admin_page(false, true); |
|
| 2887 | - } |
|
| 2888 | - |
|
| 2889 | - |
|
| 2890 | - |
|
| 2891 | - /** |
|
| 2892 | - * display_admin_page |
|
| 2893 | - * contains the code for actually displaying an admin page |
|
| 2894 | - * |
|
| 2895 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2896 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2897 | - * @return void |
|
| 2898 | - * @throws DomainException |
|
| 2899 | - * @throws EE_Error |
|
| 2900 | - */ |
|
| 2901 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2902 | - { |
|
| 2903 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2904 | - //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2905 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2906 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2907 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2908 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2909 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2910 | - ? 'poststuff' |
|
| 2911 | - : 'espresso-default-admin'; |
|
| 2912 | - $template_path = $sidebar |
|
| 2913 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2914 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2915 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2916 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2917 | - } |
|
| 2918 | - $template_path = ! empty($this->_column_template_path) |
|
| 2919 | - ? $this->_column_template_path : $template_path; |
|
| 2920 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2921 | - ? $this->_template_args['admin_page_content'] |
|
| 2922 | - : ''; |
|
| 2923 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2924 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2925 | - : ''; |
|
| 2926 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2927 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2928 | - : ''; |
|
| 2929 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2930 | - $template_path, |
|
| 2931 | - $this->_template_args, |
|
| 2932 | - true |
|
| 2933 | - ); |
|
| 2934 | - // the final template wrapper |
|
| 2935 | - $this->admin_page_wrapper($about); |
|
| 2936 | - } |
|
| 2937 | - |
|
| 2938 | - |
|
| 2939 | - |
|
| 2940 | - /** |
|
| 2941 | - * This is used to display caf preview pages. |
|
| 2942 | - * |
|
| 2943 | - * @since 4.3.2 |
|
| 2944 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2945 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2946 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2947 | - * @return void |
|
| 2948 | - * @throws DomainException |
|
| 2949 | - * @throws EE_Error |
|
| 2950 | - * @throws InvalidArgumentException |
|
| 2951 | - * @throws InvalidDataTypeException |
|
| 2952 | - * @throws InvalidInterfaceException |
|
| 2953 | - */ |
|
| 2954 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2955 | - { |
|
| 2956 | - //let's generate a default preview action button if there isn't one already present. |
|
| 2957 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2958 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2959 | - 'event_espresso' |
|
| 2960 | - ); |
|
| 2961 | - $buy_now_url = add_query_arg( |
|
| 2962 | - array( |
|
| 2963 | - 'ee_ver' => 'ee4', |
|
| 2964 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2965 | - 'utm_medium' => 'link', |
|
| 2966 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2967 | - 'utm_content' => 'buy_now_button', |
|
| 2968 | - ), |
|
| 2969 | - 'http://eventespresso.com/pricing/' |
|
| 2970 | - ); |
|
| 2971 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2972 | - ? $this->get_action_link_or_button( |
|
| 2973 | - '', |
|
| 2974 | - 'buy_now', |
|
| 2975 | - array(), |
|
| 2976 | - 'button-primary button-large', |
|
| 2977 | - $buy_now_url, |
|
| 2978 | - true |
|
| 2979 | - ) |
|
| 2980 | - : $this->_template_args['preview_action_button']; |
|
| 2981 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2982 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2983 | - $this->_template_args, |
|
| 2984 | - true |
|
| 2985 | - ); |
|
| 2986 | - $this->_display_admin_page($display_sidebar); |
|
| 2987 | - } |
|
| 2988 | - |
|
| 2989 | - |
|
| 2990 | - |
|
| 2991 | - /** |
|
| 2992 | - * display_admin_list_table_page_with_sidebar |
|
| 2993 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2994 | - * |
|
| 2995 | - * @return void |
|
| 2996 | - * @throws EE_Error |
|
| 2997 | - * @throws DomainException |
|
| 2998 | - */ |
|
| 2999 | - public function display_admin_list_table_page_with_sidebar() |
|
| 3000 | - { |
|
| 3001 | - $this->_display_admin_list_table_page(true); |
|
| 3002 | - } |
|
| 3003 | - |
|
| 3004 | - |
|
| 3005 | - |
|
| 3006 | - /** |
|
| 3007 | - * display_admin_list_table_page_with_no_sidebar |
|
| 3008 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3009 | - * |
|
| 3010 | - * @return void |
|
| 3011 | - * @throws EE_Error |
|
| 3012 | - * @throws DomainException |
|
| 3013 | - */ |
|
| 3014 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 3015 | - { |
|
| 3016 | - $this->_display_admin_list_table_page(); |
|
| 3017 | - } |
|
| 3018 | - |
|
| 3019 | - |
|
| 3020 | - |
|
| 3021 | - /** |
|
| 3022 | - * generates html wrapper for an admin_list_table page |
|
| 3023 | - * |
|
| 3024 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3025 | - * @return void |
|
| 3026 | - * @throws DomainException |
|
| 3027 | - * @throws EE_Error |
|
| 3028 | - */ |
|
| 3029 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 3030 | - { |
|
| 3031 | - //setup search attributes |
|
| 3032 | - $this->_set_search_attributes(); |
|
| 3033 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3034 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3035 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 3036 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 3037 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 3038 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3039 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 3040 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3041 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3042 | - if (! empty($ajax_sorting_callback)) { |
|
| 3043 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3044 | - $ajax_sorting_callback . '_nonce', |
|
| 3045 | - $ajax_sorting_callback . '_nonce', |
|
| 3046 | - false, |
|
| 3047 | - false |
|
| 3048 | - ); |
|
| 3049 | - // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 3050 | - // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 3051 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3052 | - . $this->page_slug |
|
| 3053 | - . '" />'; |
|
| 3054 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3055 | - . $ajax_sorting_callback |
|
| 3056 | - . '" />'; |
|
| 3057 | - } else { |
|
| 3058 | - $sortable_list_table_form_fields = ''; |
|
| 3059 | - } |
|
| 3060 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3061 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3062 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 3063 | - : ''; |
|
| 3064 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3065 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3066 | - . $nonce_ref |
|
| 3067 | - . '" value="' |
|
| 3068 | - . wp_create_nonce($nonce_ref) |
|
| 3069 | - . '">'; |
|
| 3070 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3071 | - //display message about search results? |
|
| 3072 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3073 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3074 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3075 | - trim($this->_req_data['s'], '%') |
|
| 3076 | - ) . '</p>' |
|
| 3077 | - : ''; |
|
| 3078 | - // filter before_list_table template arg |
|
| 3079 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 3080 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3081 | - $this->_template_args['before_list_table'], |
|
| 3082 | - $this->page_slug, |
|
| 3083 | - $this->_req_data, |
|
| 3084 | - $this->_req_action |
|
| 3085 | - ); |
|
| 3086 | - // convert to array and filter again |
|
| 3087 | - // arrays are easier to inject new items in a specific location, |
|
| 3088 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3089 | - $this->_template_args['before_list_table'] = implode( |
|
| 3090 | - " \n", |
|
| 3091 | - (array)apply_filters( |
|
| 3092 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3093 | - (array)$this->_template_args['before_list_table'], |
|
| 3094 | - $this->page_slug, |
|
| 3095 | - $this->_req_data, |
|
| 3096 | - $this->_req_action |
|
| 3097 | - ) |
|
| 3098 | - ); |
|
| 3099 | - // filter after_list_table template arg |
|
| 3100 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3101 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3102 | - $this->_template_args['after_list_table'], |
|
| 3103 | - $this->page_slug, |
|
| 3104 | - $this->_req_data, |
|
| 3105 | - $this->_req_action |
|
| 3106 | - ); |
|
| 3107 | - // convert to array and filter again |
|
| 3108 | - // arrays are easier to inject new items in a specific location, |
|
| 3109 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3110 | - $this->_template_args['after_list_table'] = implode( |
|
| 3111 | - " \n", |
|
| 3112 | - (array)apply_filters( |
|
| 3113 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3114 | - (array)$this->_template_args['after_list_table'], |
|
| 3115 | - $this->page_slug, |
|
| 3116 | - $this->_req_data, |
|
| 3117 | - $this->_req_action |
|
| 3118 | - ) |
|
| 3119 | - ); |
|
| 3120 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3121 | - $template_path, |
|
| 3122 | - $this->_template_args, |
|
| 3123 | - true |
|
| 3124 | - ); |
|
| 3125 | - // the final template wrapper |
|
| 3126 | - if ($sidebar) { |
|
| 3127 | - $this->display_admin_page_with_sidebar(); |
|
| 3128 | - } else { |
|
| 3129 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3130 | - } |
|
| 3131 | - } |
|
| 3132 | - |
|
| 3133 | - |
|
| 3134 | - |
|
| 3135 | - /** |
|
| 3136 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3137 | - * html string for the legend. |
|
| 3138 | - * $items are expected in an array in the following format: |
|
| 3139 | - * $legend_items = array( |
|
| 3140 | - * 'item_id' => array( |
|
| 3141 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3142 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3143 | - * ) |
|
| 3144 | - * ); |
|
| 3145 | - * |
|
| 3146 | - * @param array $items see above for format of array |
|
| 3147 | - * @return string html string of legend |
|
| 3148 | - * @throws DomainException |
|
| 3149 | - */ |
|
| 3150 | - protected function _display_legend($items) |
|
| 3151 | - { |
|
| 3152 | - $this->_template_args['items'] = apply_filters( |
|
| 3153 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3154 | - (array)$items, |
|
| 3155 | - $this |
|
| 3156 | - ); |
|
| 3157 | - return EEH_Template::display_template( |
|
| 3158 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3159 | - $this->_template_args, |
|
| 3160 | - true |
|
| 3161 | - ); |
|
| 3162 | - } |
|
| 3163 | - |
|
| 3164 | - |
|
| 3165 | - /** |
|
| 3166 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3167 | - * The returned json object is created from an array in the following format: |
|
| 3168 | - * array( |
|
| 3169 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3170 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3171 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3172 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3173 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3174 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3175 | - * that might be included in here) |
|
| 3176 | - * ) |
|
| 3177 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3178 | - * |
|
| 3179 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3180 | - * instead of displayed. |
|
| 3181 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3182 | - * @return void |
|
| 3183 | - * @throws EE_Error |
|
| 3184 | - */ |
|
| 3185 | - protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3186 | - { |
|
| 3187 | - //make sure any EE_Error notices have been handled. |
|
| 3188 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3189 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3190 | - unset($this->_template_args['data']); |
|
| 3191 | - $json = array( |
|
| 3192 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3193 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3194 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3195 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3196 | - 'notices' => EE_Error::get_notices(), |
|
| 3197 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3198 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3199 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3200 | - 'isEEajax' => true |
|
| 3201 | - //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3202 | - ); |
|
| 3203 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3204 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3205 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3206 | - } |
|
| 3207 | - echo wp_json_encode($json); |
|
| 3208 | - exit(); |
|
| 3209 | - } |
|
| 3210 | - |
|
| 3211 | - |
|
| 3212 | - |
|
| 3213 | - /** |
|
| 3214 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3215 | - * |
|
| 3216 | - * @return void |
|
| 3217 | - * @throws EE_Error |
|
| 3218 | - */ |
|
| 3219 | - public function return_json() |
|
| 3220 | - { |
|
| 3221 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3222 | - $this->_return_json(); |
|
| 3223 | - } else { |
|
| 3224 | - throw new EE_Error( |
|
| 3225 | - sprintf( |
|
| 3226 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3227 | - __FUNCTION__ |
|
| 3228 | - ) |
|
| 3229 | - ); |
|
| 3230 | - } |
|
| 3231 | - } |
|
| 3232 | - |
|
| 3233 | - |
|
| 3234 | - |
|
| 3235 | - /** |
|
| 3236 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3237 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3238 | - * |
|
| 3239 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3240 | - */ |
|
| 3241 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3242 | - { |
|
| 3243 | - $this->_hook_obj = $hook_obj; |
|
| 3244 | - } |
|
| 3245 | - |
|
| 3246 | - |
|
| 3247 | - |
|
| 3248 | - /** |
|
| 3249 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3250 | - * |
|
| 3251 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3252 | - * @return void |
|
| 3253 | - * @throws DomainException |
|
| 3254 | - * @throws EE_Error |
|
| 3255 | - */ |
|
| 3256 | - public function admin_page_wrapper($about = false) |
|
| 3257 | - { |
|
| 3258 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3259 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3260 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3261 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3262 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3263 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3264 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3265 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3266 | - : '' |
|
| 3267 | - ); |
|
| 3268 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3269 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3270 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3271 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3272 | - : '' |
|
| 3273 | - ); |
|
| 3274 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3275 | - // load settings page wrapper template |
|
| 3276 | - $template_path = ! defined('DOING_AJAX') |
|
| 3277 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3278 | - : EE_ADMIN_TEMPLATE |
|
| 3279 | - . 'admin_wrapper_ajax.template.php'; |
|
| 3280 | - //about page? |
|
| 3281 | - $template_path = $about |
|
| 3282 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3283 | - : $template_path; |
|
| 3284 | - if (defined('DOING_AJAX')) { |
|
| 3285 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3286 | - $template_path, |
|
| 3287 | - $this->_template_args, |
|
| 3288 | - true |
|
| 3289 | - ); |
|
| 3290 | - $this->_return_json(); |
|
| 3291 | - } else { |
|
| 3292 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3293 | - } |
|
| 3294 | - } |
|
| 3295 | - |
|
| 3296 | - |
|
| 3297 | - |
|
| 3298 | - /** |
|
| 3299 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3300 | - * |
|
| 3301 | - * @return string html |
|
| 3302 | - * @throws EE_Error |
|
| 3303 | - */ |
|
| 3304 | - protected function _get_main_nav_tabs() |
|
| 3305 | - { |
|
| 3306 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3307 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3308 | - // (rather than setting in the page_routes array) |
|
| 3309 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3310 | - } |
|
| 3311 | - |
|
| 3312 | - |
|
| 3313 | - |
|
| 3314 | - /** |
|
| 3315 | - * sort nav tabs |
|
| 3316 | - * |
|
| 3317 | - * @param $a |
|
| 3318 | - * @param $b |
|
| 3319 | - * @return int |
|
| 3320 | - */ |
|
| 3321 | - private function _sort_nav_tabs($a, $b) |
|
| 3322 | - { |
|
| 3323 | - if ($a['order'] === $b['order']) { |
|
| 3324 | - return 0; |
|
| 3325 | - } |
|
| 3326 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3327 | - } |
|
| 3328 | - |
|
| 3329 | - |
|
| 3330 | - |
|
| 3331 | - /** |
|
| 3332 | - * generates HTML for the forms used on admin pages |
|
| 3333 | - * |
|
| 3334 | - * @param array $input_vars - array of input field details |
|
| 3335 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3336 | - * use) |
|
| 3337 | - * @param bool $id |
|
| 3338 | - * @return string |
|
| 3339 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3340 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3341 | - */ |
|
| 3342 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3343 | - { |
|
| 3344 | - $content = $generator === 'string' |
|
| 3345 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3346 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3347 | - return $content; |
|
| 3348 | - } |
|
| 3349 | - |
|
| 3350 | - |
|
| 3351 | - |
|
| 3352 | - /** |
|
| 3353 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3354 | - * |
|
| 3355 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3356 | - * Close" button. |
|
| 3357 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3358 | - * 'Save', [1] => 'save & close') |
|
| 3359 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3360 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3361 | - * default actions by submitting some other value. |
|
| 3362 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3363 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3364 | - * close (normal form handling). |
|
| 3365 | - */ |
|
| 3366 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3367 | - { |
|
| 3368 | - //make sure $text and $actions are in an array |
|
| 3369 | - $text = (array)$text; |
|
| 3370 | - $actions = (array)$actions; |
|
| 3371 | - $referrer_url = empty($referrer) |
|
| 3372 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3373 | - . $_SERVER['REQUEST_URI'] |
|
| 3374 | - . '" />' |
|
| 3375 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3376 | - . $referrer |
|
| 3377 | - . '" />'; |
|
| 3378 | - $button_text = ! empty($text) |
|
| 3379 | - ? $text |
|
| 3380 | - : array( |
|
| 3381 | - esc_html__('Save', 'event_espresso'), |
|
| 3382 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3383 | - ); |
|
| 3384 | - $default_names = array('save', 'save_and_close'); |
|
| 3385 | - //add in a hidden index for the current page (so save and close redirects properly) |
|
| 3386 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3387 | - foreach ($button_text as $key => $button) { |
|
| 3388 | - $ref = $default_names[$key]; |
|
| 3389 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3390 | - . $ref |
|
| 3391 | - . '" value="' |
|
| 3392 | - . $button |
|
| 3393 | - . '" name="' |
|
| 3394 | - . (! empty($actions) ? $actions[$key] : $ref) |
|
| 3395 | - . '" id="' |
|
| 3396 | - . $this->_current_view . '_' . $ref |
|
| 3397 | - . '" />'; |
|
| 3398 | - if (! $both) { |
|
| 3399 | - break; |
|
| 3400 | - } |
|
| 3401 | - } |
|
| 3402 | - } |
|
| 3403 | - |
|
| 3404 | - |
|
| 3405 | - |
|
| 3406 | - /** |
|
| 3407 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3408 | - * |
|
| 3409 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3410 | - * @since 4.6.0 |
|
| 3411 | - * @param string $route |
|
| 3412 | - * @param array $additional_hidden_fields |
|
| 3413 | - */ |
|
| 3414 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3415 | - { |
|
| 3416 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3417 | - } |
|
| 3418 | - |
|
| 3419 | - |
|
| 3420 | - |
|
| 3421 | - /** |
|
| 3422 | - * set form open and close tags on add/edit pages. |
|
| 3423 | - * |
|
| 3424 | - * @param string $route the route you want the form to direct to |
|
| 3425 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3426 | - * @return void |
|
| 3427 | - */ |
|
| 3428 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3429 | - { |
|
| 3430 | - if (empty($route)) { |
|
| 3431 | - $user_msg = esc_html__( |
|
| 3432 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3433 | - 'event_espresso' |
|
| 3434 | - ); |
|
| 3435 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
| 3436 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3437 | - __FUNCTION__, |
|
| 3438 | - __CLASS__ |
|
| 3439 | - ); |
|
| 3440 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3441 | - } |
|
| 3442 | - // open form |
|
| 3443 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3444 | - . $this->_admin_base_url |
|
| 3445 | - . '" id="' |
|
| 3446 | - . $route |
|
| 3447 | - . '_event_form" >'; |
|
| 3448 | - // add nonce |
|
| 3449 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3450 | - // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 3451 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3452 | - // add REQUIRED form action |
|
| 3453 | - $hidden_fields = array( |
|
| 3454 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3455 | - ); |
|
| 3456 | - // merge arrays |
|
| 3457 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3458 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3459 | - : $hidden_fields; |
|
| 3460 | - // generate form fields |
|
| 3461 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3462 | - // add fields to form |
|
| 3463 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 3464 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3465 | - } |
|
| 3466 | - // close form |
|
| 3467 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3468 | - } |
|
| 3469 | - |
|
| 3470 | - |
|
| 3471 | - |
|
| 3472 | - /** |
|
| 3473 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3474 | - * discovered it would be useful for external code to have access. |
|
| 3475 | - * |
|
| 3476 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3477 | - * @since 4.5.0 |
|
| 3478 | - * @param bool $success |
|
| 3479 | - * @param string $what |
|
| 3480 | - * @param string $action_desc |
|
| 3481 | - * @param array $query_args |
|
| 3482 | - * @param bool $override_overwrite |
|
| 3483 | - * @throws EE_Error |
|
| 3484 | - */ |
|
| 3485 | - public function redirect_after_action( |
|
| 3486 | - $success = false, |
|
| 3487 | - $what = 'item', |
|
| 3488 | - $action_desc = 'processed', |
|
| 3489 | - $query_args = array(), |
|
| 3490 | - $override_overwrite = false |
|
| 3491 | - ) { |
|
| 3492 | - $this->_redirect_after_action( |
|
| 3493 | - $success, |
|
| 3494 | - $what, |
|
| 3495 | - $action_desc, |
|
| 3496 | - $query_args, |
|
| 3497 | - $override_overwrite |
|
| 3498 | - ); |
|
| 3499 | - } |
|
| 3500 | - |
|
| 3501 | - |
|
| 3502 | - |
|
| 3503 | - /** |
|
| 3504 | - * _redirect_after_action |
|
| 3505 | - * |
|
| 3506 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3507 | - * @param string $what - what the action was performed on |
|
| 3508 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3509 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3510 | - * action is completed |
|
| 3511 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3512 | - * override this so that they show. |
|
| 3513 | - * @return void |
|
| 3514 | - * @throws EE_Error |
|
| 3515 | - */ |
|
| 3516 | - protected function _redirect_after_action( |
|
| 3517 | - $success = 0, |
|
| 3518 | - $what = 'item', |
|
| 3519 | - $action_desc = 'processed', |
|
| 3520 | - $query_args = array(), |
|
| 3521 | - $override_overwrite = false |
|
| 3522 | - ) { |
|
| 3523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3524 | - //class name for actions/filters. |
|
| 3525 | - $classname = get_class($this); |
|
| 3526 | - // set redirect url. |
|
| 3527 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3528 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3529 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3530 | - $notices = EE_Error::get_notices(false); |
|
| 3531 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3532 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3533 | - EE_Error::overwrite_success(); |
|
| 3534 | - } |
|
| 3535 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3536 | - // how many records affected ? more than one record ? or just one ? |
|
| 3537 | - if ($success > 1) { |
|
| 3538 | - // set plural msg |
|
| 3539 | - EE_Error::add_success( |
|
| 3540 | - sprintf( |
|
| 3541 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3542 | - $what, |
|
| 3543 | - $action_desc |
|
| 3544 | - ), |
|
| 3545 | - __FILE__, |
|
| 3546 | - __FUNCTION__, |
|
| 3547 | - __LINE__ |
|
| 3548 | - ); |
|
| 3549 | - } elseif ($success === 1) { |
|
| 3550 | - // set singular msg |
|
| 3551 | - EE_Error::add_success( |
|
| 3552 | - sprintf( |
|
| 3553 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3554 | - $what, |
|
| 3555 | - $action_desc |
|
| 3556 | - ), |
|
| 3557 | - __FILE__, |
|
| 3558 | - __FUNCTION__, |
|
| 3559 | - __LINE__ |
|
| 3560 | - ); |
|
| 3561 | - } |
|
| 3562 | - } |
|
| 3563 | - // check that $query_args isn't something crazy |
|
| 3564 | - if (! is_array($query_args)) { |
|
| 3565 | - $query_args = array(); |
|
| 3566 | - } |
|
| 3567 | - /** |
|
| 3568 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3569 | - * redirections on save and close actions |
|
| 3570 | - * |
|
| 3571 | - * @since 4.2.0 |
|
| 3572 | - * @param array $query_args The original query_args array coming into the |
|
| 3573 | - * method. |
|
| 3574 | - */ |
|
| 3575 | - do_action( |
|
| 3576 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3577 | - $query_args |
|
| 3578 | - ); |
|
| 3579 | - //calculate where we're going (if we have a "save and close" button pushed) |
|
| 3580 | - if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3581 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3582 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3583 | - // regenerate query args array from referrer URL |
|
| 3584 | - parse_str($parsed_url['query'], $query_args); |
|
| 3585 | - // correct page and action will be in the query args now |
|
| 3586 | - $redirect_url = admin_url('admin.php'); |
|
| 3587 | - } |
|
| 3588 | - //merge any default query_args set in _default_route_query_args property |
|
| 3589 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3590 | - $args_to_merge = array(); |
|
| 3591 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3592 | - //is there a wp_referer array in our _default_route_query_args property? |
|
| 3593 | - if ($query_param === 'wp_referer') { |
|
| 3594 | - $query_value = (array)$query_value; |
|
| 3595 | - foreach ($query_value as $reference => $value) { |
|
| 3596 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3597 | - continue; |
|
| 3598 | - } |
|
| 3599 | - //finally we will override any arguments in the referer with |
|
| 3600 | - //what might be set on the _default_route_query_args array. |
|
| 3601 | - if (isset($this->_default_route_query_args[$reference])) { |
|
| 3602 | - $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3603 | - } else { |
|
| 3604 | - $args_to_merge[$reference] = urlencode($value); |
|
| 3605 | - } |
|
| 3606 | - } |
|
| 3607 | - continue; |
|
| 3608 | - } |
|
| 3609 | - $args_to_merge[$query_param] = $query_value; |
|
| 3610 | - } |
|
| 3611 | - //now let's merge these arguments but override with what was specifically sent in to the |
|
| 3612 | - //redirect. |
|
| 3613 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3614 | - } |
|
| 3615 | - $this->_process_notices($query_args); |
|
| 3616 | - // generate redirect url |
|
| 3617 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3618 | - if (isset($query_args['action'])) { |
|
| 3619 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3620 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3621 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3622 | - } |
|
| 3623 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3624 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3625 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3626 | - $redirect_url = apply_filters( |
|
| 3627 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3628 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3629 | - $query_args |
|
| 3630 | - ); |
|
| 3631 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3632 | - if (defined('DOING_AJAX')) { |
|
| 3633 | - $default_data = array( |
|
| 3634 | - 'close' => true, |
|
| 3635 | - 'redirect_url' => $redirect_url, |
|
| 3636 | - 'where' => 'main', |
|
| 3637 | - 'what' => 'append', |
|
| 3638 | - ); |
|
| 3639 | - $this->_template_args['success'] = $success; |
|
| 3640 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3641 | - $default_data, |
|
| 3642 | - $this->_template_args['data'] |
|
| 3643 | - ) : $default_data; |
|
| 3644 | - $this->_return_json(); |
|
| 3645 | - } |
|
| 3646 | - wp_safe_redirect($redirect_url); |
|
| 3647 | - exit(); |
|
| 3648 | - } |
|
| 3649 | - |
|
| 3650 | - |
|
| 3651 | - |
|
| 3652 | - /** |
|
| 3653 | - * process any notices before redirecting (or returning ajax request) |
|
| 3654 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3655 | - * |
|
| 3656 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3657 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3658 | - * page_routes haven't been defined yet. |
|
| 3659 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3660 | - * still save a transient for the notice. |
|
| 3661 | - * @return void |
|
| 3662 | - * @throws EE_Error |
|
| 3663 | - */ |
|
| 3664 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3665 | - { |
|
| 3666 | - //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3667 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3668 | - $notices = EE_Error::get_notices(false); |
|
| 3669 | - if (empty($this->_template_args['success'])) { |
|
| 3670 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3671 | - } |
|
| 3672 | - if (empty($this->_template_args['errors'])) { |
|
| 3673 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3674 | - } |
|
| 3675 | - if (empty($this->_template_args['attention'])) { |
|
| 3676 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3677 | - } |
|
| 3678 | - } |
|
| 3679 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3680 | - //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3681 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3682 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3683 | - $this->_add_transient( |
|
| 3684 | - $route, |
|
| 3685 | - $this->_template_args['notices'], |
|
| 3686 | - true, |
|
| 3687 | - $skip_route_verify |
|
| 3688 | - ); |
|
| 3689 | - } |
|
| 3690 | - } |
|
| 3691 | - |
|
| 3692 | - |
|
| 3693 | - |
|
| 3694 | - /** |
|
| 3695 | - * get_action_link_or_button |
|
| 3696 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3697 | - * |
|
| 3698 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3699 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3700 | - * property. |
|
| 3701 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3702 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3703 | - * @param string $base_url If this is not provided |
|
| 3704 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3705 | - * Otherwise this value will be used. |
|
| 3706 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3707 | - * @return string |
|
| 3708 | - * @throws InvalidArgumentException |
|
| 3709 | - * @throws InvalidInterfaceException |
|
| 3710 | - * @throws InvalidDataTypeException |
|
| 3711 | - * @throws EE_Error |
|
| 3712 | - */ |
|
| 3713 | - public function get_action_link_or_button( |
|
| 3714 | - $action, |
|
| 3715 | - $type = 'add', |
|
| 3716 | - $extra_request = array(), |
|
| 3717 | - $class = 'button-primary', |
|
| 3718 | - $base_url = '', |
|
| 3719 | - $exclude_nonce = false |
|
| 3720 | - ) { |
|
| 3721 | - //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3722 | - if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3723 | - throw new EE_Error( |
|
| 3724 | - sprintf( |
|
| 3725 | - esc_html__( |
|
| 3726 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3727 | - 'event_espresso' |
|
| 3728 | - ), |
|
| 3729 | - $action |
|
| 3730 | - ) |
|
| 3731 | - ); |
|
| 3732 | - } |
|
| 3733 | - if (! isset($this->_labels['buttons'][$type])) { |
|
| 3734 | - throw new EE_Error( |
|
| 3735 | - sprintf( |
|
| 3736 | - __( |
|
| 3737 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3738 | - 'event_espresso' |
|
| 3739 | - ), |
|
| 3740 | - $type |
|
| 3741 | - ) |
|
| 3742 | - ); |
|
| 3743 | - } |
|
| 3744 | - //finally check user access for this button. |
|
| 3745 | - $has_access = $this->check_user_access($action, true); |
|
| 3746 | - if (! $has_access) { |
|
| 3747 | - return ''; |
|
| 3748 | - } |
|
| 3749 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3750 | - $query_args = array( |
|
| 3751 | - 'action' => $action, |
|
| 3752 | - ); |
|
| 3753 | - //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3754 | - if (! empty($extra_request)) { |
|
| 3755 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3756 | - } |
|
| 3757 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3758 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3759 | - } |
|
| 3760 | - |
|
| 3761 | - |
|
| 3762 | - |
|
| 3763 | - /** |
|
| 3764 | - * _per_page_screen_option |
|
| 3765 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3766 | - * |
|
| 3767 | - * @return void |
|
| 3768 | - * @throws InvalidArgumentException |
|
| 3769 | - * @throws InvalidInterfaceException |
|
| 3770 | - * @throws InvalidDataTypeException |
|
| 3771 | - */ |
|
| 3772 | - protected function _per_page_screen_option() |
|
| 3773 | - { |
|
| 3774 | - $option = 'per_page'; |
|
| 3775 | - $args = array( |
|
| 3776 | - 'label' => esc_html__( |
|
| 3777 | - apply_filters( |
|
| 3778 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3779 | - $this->_admin_page_title, |
|
| 3780 | - $this |
|
| 3781 | - ) |
|
| 3782 | - ), |
|
| 3783 | - 'default' => (int) apply_filters( |
|
| 3784 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3785 | - 10 |
|
| 3786 | - ), |
|
| 3787 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3788 | - ); |
|
| 3789 | - //ONLY add the screen option if the user has access to it. |
|
| 3790 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3791 | - add_screen_option($option, $args); |
|
| 3792 | - } |
|
| 3793 | - } |
|
| 3794 | - |
|
| 3795 | - |
|
| 3796 | - |
|
| 3797 | - /** |
|
| 3798 | - * set_per_page_screen_option |
|
| 3799 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3800 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3801 | - * admin_menu. |
|
| 3802 | - * |
|
| 3803 | - * @return void |
|
| 3804 | - */ |
|
| 3805 | - private function _set_per_page_screen_options() |
|
| 3806 | - { |
|
| 3807 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3808 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3809 | - if (! $user = wp_get_current_user()) { |
|
| 3810 | - return; |
|
| 3811 | - } |
|
| 3812 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3813 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3814 | - if ($option != sanitize_key($option)) { |
|
| 3815 | - return; |
|
| 3816 | - } |
|
| 3817 | - $map_option = $option; |
|
| 3818 | - $option = str_replace('-', '_', $option); |
|
| 3819 | - switch ($map_option) { |
|
| 3820 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3821 | - $value = (int)$value; |
|
| 3822 | - $max_value = apply_filters( |
|
| 3823 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3824 | - 999, |
|
| 3825 | - $this->_current_page, |
|
| 3826 | - $this->_current_view |
|
| 3827 | - ); |
|
| 3828 | - if ($value < 1) { |
|
| 3829 | - return; |
|
| 3830 | - } |
|
| 3831 | - $value = min($value, $max_value); |
|
| 3832 | - break; |
|
| 3833 | - default: |
|
| 3834 | - $value = apply_filters( |
|
| 3835 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3836 | - false, |
|
| 3837 | - $option, |
|
| 3838 | - $value |
|
| 3839 | - ); |
|
| 3840 | - if (false === $value) { |
|
| 3841 | - return; |
|
| 3842 | - } |
|
| 3843 | - break; |
|
| 3844 | - } |
|
| 3845 | - update_user_meta($user->ID, $option, $value); |
|
| 3846 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3847 | - exit; |
|
| 3848 | - } |
|
| 3849 | - } |
|
| 3850 | - |
|
| 3851 | - |
|
| 3852 | - |
|
| 3853 | - /** |
|
| 3854 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3855 | - * |
|
| 3856 | - * @param array $data array that will be assigned to template args. |
|
| 3857 | - */ |
|
| 3858 | - public function set_template_args($data) |
|
| 3859 | - { |
|
| 3860 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3861 | - } |
|
| 3862 | - |
|
| 3863 | - |
|
| 3864 | - |
|
| 3865 | - /** |
|
| 3866 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3867 | - * |
|
| 3868 | - * @param string $route the route that should receive the transient |
|
| 3869 | - * @param array $data the data that gets sent |
|
| 3870 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3871 | - * normal route transient. |
|
| 3872 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3873 | - * when we are adding a transient before page_routes have been defined. |
|
| 3874 | - * @return void |
|
| 3875 | - * @throws EE_Error |
|
| 3876 | - */ |
|
| 3877 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3878 | - { |
|
| 3879 | - $user_id = get_current_user_id(); |
|
| 3880 | - if (! $skip_route_verify) { |
|
| 3881 | - $this->_verify_route($route); |
|
| 3882 | - } |
|
| 3883 | - //now let's set the string for what kind of transient we're setting |
|
| 3884 | - $transient = $notices |
|
| 3885 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3886 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3887 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3888 | - //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3889 | - $existing = is_multisite() && is_network_admin() |
|
| 3890 | - ? get_site_transient($transient) |
|
| 3891 | - : get_transient($transient); |
|
| 3892 | - if ($existing) { |
|
| 3893 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3894 | - } |
|
| 3895 | - if (is_multisite() && is_network_admin()) { |
|
| 3896 | - set_site_transient($transient, $data, 8); |
|
| 3897 | - } else { |
|
| 3898 | - set_transient($transient, $data, 8); |
|
| 3899 | - } |
|
| 3900 | - } |
|
| 3901 | - |
|
| 3902 | - |
|
| 3903 | - |
|
| 3904 | - /** |
|
| 3905 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3906 | - * |
|
| 3907 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3908 | - * @param string $route |
|
| 3909 | - * @return mixed data |
|
| 3910 | - */ |
|
| 3911 | - protected function _get_transient($notices = false, $route = '') |
|
| 3912 | - { |
|
| 3913 | - $user_id = get_current_user_id(); |
|
| 3914 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3915 | - $transient = $notices |
|
| 3916 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3917 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3918 | - $data = is_multisite() && is_network_admin() |
|
| 3919 | - ? get_site_transient($transient) |
|
| 3920 | - : get_transient($transient); |
|
| 3921 | - //delete transient after retrieval (just in case it hasn't expired); |
|
| 3922 | - if (is_multisite() && is_network_admin()) { |
|
| 3923 | - delete_site_transient($transient); |
|
| 3924 | - } else { |
|
| 3925 | - delete_transient($transient); |
|
| 3926 | - } |
|
| 3927 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3928 | - } |
|
| 3929 | - |
|
| 3930 | - |
|
| 3931 | - |
|
| 3932 | - /** |
|
| 3933 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3934 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3935 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3936 | - * |
|
| 3937 | - * @return void |
|
| 3938 | - */ |
|
| 3939 | - protected function _transient_garbage_collection() |
|
| 3940 | - { |
|
| 3941 | - global $wpdb; |
|
| 3942 | - //retrieve all existing transients |
|
| 3943 | - $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3944 | - if ($results = $wpdb->get_results($query)) { |
|
| 3945 | - foreach ($results as $result) { |
|
| 3946 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3947 | - get_transient($transient); |
|
| 3948 | - if (is_multisite() && is_network_admin()) { |
|
| 3949 | - get_site_transient($transient); |
|
| 3950 | - } |
|
| 3951 | - } |
|
| 3952 | - } |
|
| 3953 | - } |
|
| 3954 | - |
|
| 3955 | - |
|
| 3956 | - |
|
| 3957 | - /** |
|
| 3958 | - * get_view |
|
| 3959 | - * |
|
| 3960 | - * @return string content of _view property |
|
| 3961 | - */ |
|
| 3962 | - public function get_view() |
|
| 3963 | - { |
|
| 3964 | - return $this->_view; |
|
| 3965 | - } |
|
| 3966 | - |
|
| 3967 | - |
|
| 3968 | - |
|
| 3969 | - /** |
|
| 3970 | - * getter for the protected $_views property |
|
| 3971 | - * |
|
| 3972 | - * @return array |
|
| 3973 | - */ |
|
| 3974 | - public function get_views() |
|
| 3975 | - { |
|
| 3976 | - return $this->_views; |
|
| 3977 | - } |
|
| 3978 | - |
|
| 3979 | - |
|
| 3980 | - |
|
| 3981 | - /** |
|
| 3982 | - * get_current_page |
|
| 3983 | - * |
|
| 3984 | - * @return string _current_page property value |
|
| 3985 | - */ |
|
| 3986 | - public function get_current_page() |
|
| 3987 | - { |
|
| 3988 | - return $this->_current_page; |
|
| 3989 | - } |
|
| 3990 | - |
|
| 3991 | - |
|
| 3992 | - |
|
| 3993 | - /** |
|
| 3994 | - * get_current_view |
|
| 3995 | - * |
|
| 3996 | - * @return string _current_view property value |
|
| 3997 | - */ |
|
| 3998 | - public function get_current_view() |
|
| 3999 | - { |
|
| 4000 | - return $this->_current_view; |
|
| 4001 | - } |
|
| 4002 | - |
|
| 4003 | - |
|
| 4004 | - |
|
| 4005 | - /** |
|
| 4006 | - * get_current_screen |
|
| 4007 | - * |
|
| 4008 | - * @return object The current WP_Screen object |
|
| 4009 | - */ |
|
| 4010 | - public function get_current_screen() |
|
| 4011 | - { |
|
| 4012 | - return $this->_current_screen; |
|
| 4013 | - } |
|
| 4014 | - |
|
| 4015 | - |
|
| 4016 | - |
|
| 4017 | - /** |
|
| 4018 | - * get_current_page_view_url |
|
| 4019 | - * |
|
| 4020 | - * @return string This returns the url for the current_page_view. |
|
| 4021 | - */ |
|
| 4022 | - public function get_current_page_view_url() |
|
| 4023 | - { |
|
| 4024 | - return $this->_current_page_view_url; |
|
| 4025 | - } |
|
| 4026 | - |
|
| 4027 | - |
|
| 4028 | - |
|
| 4029 | - /** |
|
| 4030 | - * just returns the _req_data property |
|
| 4031 | - * |
|
| 4032 | - * @return array |
|
| 4033 | - */ |
|
| 4034 | - public function get_request_data() |
|
| 4035 | - { |
|
| 4036 | - return $this->_req_data; |
|
| 4037 | - } |
|
| 4038 | - |
|
| 4039 | - |
|
| 4040 | - |
|
| 4041 | - /** |
|
| 4042 | - * returns the _req_data protected property |
|
| 4043 | - * |
|
| 4044 | - * @return string |
|
| 4045 | - */ |
|
| 4046 | - public function get_req_action() |
|
| 4047 | - { |
|
| 4048 | - return $this->_req_action; |
|
| 4049 | - } |
|
| 4050 | - |
|
| 4051 | - |
|
| 4052 | - |
|
| 4053 | - /** |
|
| 4054 | - * @return bool value of $_is_caf property |
|
| 4055 | - */ |
|
| 4056 | - public function is_caf() |
|
| 4057 | - { |
|
| 4058 | - return $this->_is_caf; |
|
| 4059 | - } |
|
| 4060 | - |
|
| 4061 | - |
|
| 4062 | - |
|
| 4063 | - /** |
|
| 4064 | - * @return mixed |
|
| 4065 | - */ |
|
| 4066 | - public function default_espresso_metaboxes() |
|
| 4067 | - { |
|
| 4068 | - return $this->_default_espresso_metaboxes; |
|
| 4069 | - } |
|
| 4070 | - |
|
| 4071 | - |
|
| 4072 | - |
|
| 4073 | - /** |
|
| 4074 | - * @return mixed |
|
| 4075 | - */ |
|
| 4076 | - public function admin_base_url() |
|
| 4077 | - { |
|
| 4078 | - return $this->_admin_base_url; |
|
| 4079 | - } |
|
| 2769 | + } |
|
| 2770 | + |
|
| 2771 | + |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * facade for add_meta_box |
|
| 2775 | + * |
|
| 2776 | + * @param string $action where the metabox get's displayed |
|
| 2777 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2778 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2779 | + * instead of the one created in here. |
|
| 2780 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2781 | + * @param string $column what metabox column |
|
| 2782 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2783 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2784 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2785 | + * @throws \DomainException |
|
| 2786 | + */ |
|
| 2787 | + public function _add_admin_page_meta_box( |
|
| 2788 | + $action, |
|
| 2789 | + $title, |
|
| 2790 | + $callback, |
|
| 2791 | + $callback_args, |
|
| 2792 | + $column = 'normal', |
|
| 2793 | + $priority = 'high', |
|
| 2794 | + $create_func = true |
|
| 2795 | + ) { |
|
| 2796 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2797 | + //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2798 | + if (empty($callback_args) && $create_func) { |
|
| 2799 | + $callback_args = array( |
|
| 2800 | + 'template_path' => $this->_template_path, |
|
| 2801 | + 'template_args' => $this->_template_args, |
|
| 2802 | + ); |
|
| 2803 | + } |
|
| 2804 | + //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2805 | + $call_back_func = $create_func |
|
| 2806 | + ? function ($post, $metabox) |
|
| 2807 | + { |
|
| 2808 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2809 | + echo EEH_Template::display_template( |
|
| 2810 | + $metabox['args']['template_path'], |
|
| 2811 | + $metabox['args']['template_args'], |
|
| 2812 | + true |
|
| 2813 | + ); |
|
| 2814 | + } |
|
| 2815 | + : $callback; |
|
| 2816 | + add_meta_box( |
|
| 2817 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2818 | + $title, |
|
| 2819 | + $call_back_func, |
|
| 2820 | + $this->_wp_page_slug, |
|
| 2821 | + $column, |
|
| 2822 | + $priority, |
|
| 2823 | + $callback_args |
|
| 2824 | + ); |
|
| 2825 | + } |
|
| 2826 | + |
|
| 2827 | + |
|
| 2828 | + |
|
| 2829 | + /** |
|
| 2830 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2831 | + * |
|
| 2832 | + * @throws DomainException |
|
| 2833 | + * @throws EE_Error |
|
| 2834 | + */ |
|
| 2835 | + public function display_admin_page_with_metabox_columns() |
|
| 2836 | + { |
|
| 2837 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2838 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2839 | + $this->_column_template_path, |
|
| 2840 | + $this->_template_args, |
|
| 2841 | + true |
|
| 2842 | + ); |
|
| 2843 | + //the final wrapper |
|
| 2844 | + $this->admin_page_wrapper(); |
|
| 2845 | + } |
|
| 2846 | + |
|
| 2847 | + |
|
| 2848 | + |
|
| 2849 | + /** |
|
| 2850 | + * generates HTML wrapper for an admin details page |
|
| 2851 | + * |
|
| 2852 | + * @return void |
|
| 2853 | + * @throws EE_Error |
|
| 2854 | + * @throws DomainException |
|
| 2855 | + */ |
|
| 2856 | + public function display_admin_page_with_sidebar() |
|
| 2857 | + { |
|
| 2858 | + $this->_display_admin_page(true); |
|
| 2859 | + } |
|
| 2860 | + |
|
| 2861 | + |
|
| 2862 | + |
|
| 2863 | + /** |
|
| 2864 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2865 | + * |
|
| 2866 | + * @return void |
|
| 2867 | + * @throws EE_Error |
|
| 2868 | + * @throws DomainException |
|
| 2869 | + */ |
|
| 2870 | + public function display_admin_page_with_no_sidebar() |
|
| 2871 | + { |
|
| 2872 | + $this->_display_admin_page(); |
|
| 2873 | + } |
|
| 2874 | + |
|
| 2875 | + |
|
| 2876 | + |
|
| 2877 | + /** |
|
| 2878 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2879 | + * |
|
| 2880 | + * @return void |
|
| 2881 | + * @throws EE_Error |
|
| 2882 | + * @throws DomainException |
|
| 2883 | + */ |
|
| 2884 | + public function display_about_admin_page() |
|
| 2885 | + { |
|
| 2886 | + $this->_display_admin_page(false, true); |
|
| 2887 | + } |
|
| 2888 | + |
|
| 2889 | + |
|
| 2890 | + |
|
| 2891 | + /** |
|
| 2892 | + * display_admin_page |
|
| 2893 | + * contains the code for actually displaying an admin page |
|
| 2894 | + * |
|
| 2895 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2896 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2897 | + * @return void |
|
| 2898 | + * @throws DomainException |
|
| 2899 | + * @throws EE_Error |
|
| 2900 | + */ |
|
| 2901 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2902 | + { |
|
| 2903 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2904 | + //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2905 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2906 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2907 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2908 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2909 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2910 | + ? 'poststuff' |
|
| 2911 | + : 'espresso-default-admin'; |
|
| 2912 | + $template_path = $sidebar |
|
| 2913 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2914 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2915 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2916 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2917 | + } |
|
| 2918 | + $template_path = ! empty($this->_column_template_path) |
|
| 2919 | + ? $this->_column_template_path : $template_path; |
|
| 2920 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2921 | + ? $this->_template_args['admin_page_content'] |
|
| 2922 | + : ''; |
|
| 2923 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2924 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2925 | + : ''; |
|
| 2926 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2927 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2928 | + : ''; |
|
| 2929 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2930 | + $template_path, |
|
| 2931 | + $this->_template_args, |
|
| 2932 | + true |
|
| 2933 | + ); |
|
| 2934 | + // the final template wrapper |
|
| 2935 | + $this->admin_page_wrapper($about); |
|
| 2936 | + } |
|
| 2937 | + |
|
| 2938 | + |
|
| 2939 | + |
|
| 2940 | + /** |
|
| 2941 | + * This is used to display caf preview pages. |
|
| 2942 | + * |
|
| 2943 | + * @since 4.3.2 |
|
| 2944 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2945 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2946 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2947 | + * @return void |
|
| 2948 | + * @throws DomainException |
|
| 2949 | + * @throws EE_Error |
|
| 2950 | + * @throws InvalidArgumentException |
|
| 2951 | + * @throws InvalidDataTypeException |
|
| 2952 | + * @throws InvalidInterfaceException |
|
| 2953 | + */ |
|
| 2954 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2955 | + { |
|
| 2956 | + //let's generate a default preview action button if there isn't one already present. |
|
| 2957 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2958 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2959 | + 'event_espresso' |
|
| 2960 | + ); |
|
| 2961 | + $buy_now_url = add_query_arg( |
|
| 2962 | + array( |
|
| 2963 | + 'ee_ver' => 'ee4', |
|
| 2964 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2965 | + 'utm_medium' => 'link', |
|
| 2966 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2967 | + 'utm_content' => 'buy_now_button', |
|
| 2968 | + ), |
|
| 2969 | + 'http://eventespresso.com/pricing/' |
|
| 2970 | + ); |
|
| 2971 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2972 | + ? $this->get_action_link_or_button( |
|
| 2973 | + '', |
|
| 2974 | + 'buy_now', |
|
| 2975 | + array(), |
|
| 2976 | + 'button-primary button-large', |
|
| 2977 | + $buy_now_url, |
|
| 2978 | + true |
|
| 2979 | + ) |
|
| 2980 | + : $this->_template_args['preview_action_button']; |
|
| 2981 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2982 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2983 | + $this->_template_args, |
|
| 2984 | + true |
|
| 2985 | + ); |
|
| 2986 | + $this->_display_admin_page($display_sidebar); |
|
| 2987 | + } |
|
| 2988 | + |
|
| 2989 | + |
|
| 2990 | + |
|
| 2991 | + /** |
|
| 2992 | + * display_admin_list_table_page_with_sidebar |
|
| 2993 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2994 | + * |
|
| 2995 | + * @return void |
|
| 2996 | + * @throws EE_Error |
|
| 2997 | + * @throws DomainException |
|
| 2998 | + */ |
|
| 2999 | + public function display_admin_list_table_page_with_sidebar() |
|
| 3000 | + { |
|
| 3001 | + $this->_display_admin_list_table_page(true); |
|
| 3002 | + } |
|
| 3003 | + |
|
| 3004 | + |
|
| 3005 | + |
|
| 3006 | + /** |
|
| 3007 | + * display_admin_list_table_page_with_no_sidebar |
|
| 3008 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3009 | + * |
|
| 3010 | + * @return void |
|
| 3011 | + * @throws EE_Error |
|
| 3012 | + * @throws DomainException |
|
| 3013 | + */ |
|
| 3014 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 3015 | + { |
|
| 3016 | + $this->_display_admin_list_table_page(); |
|
| 3017 | + } |
|
| 3018 | + |
|
| 3019 | + |
|
| 3020 | + |
|
| 3021 | + /** |
|
| 3022 | + * generates html wrapper for an admin_list_table page |
|
| 3023 | + * |
|
| 3024 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3025 | + * @return void |
|
| 3026 | + * @throws DomainException |
|
| 3027 | + * @throws EE_Error |
|
| 3028 | + */ |
|
| 3029 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 3030 | + { |
|
| 3031 | + //setup search attributes |
|
| 3032 | + $this->_set_search_attributes(); |
|
| 3033 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3034 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3035 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 3036 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 3037 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 3038 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3039 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 3040 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3041 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3042 | + if (! empty($ajax_sorting_callback)) { |
|
| 3043 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3044 | + $ajax_sorting_callback . '_nonce', |
|
| 3045 | + $ajax_sorting_callback . '_nonce', |
|
| 3046 | + false, |
|
| 3047 | + false |
|
| 3048 | + ); |
|
| 3049 | + // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 3050 | + // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 3051 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3052 | + . $this->page_slug |
|
| 3053 | + . '" />'; |
|
| 3054 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3055 | + . $ajax_sorting_callback |
|
| 3056 | + . '" />'; |
|
| 3057 | + } else { |
|
| 3058 | + $sortable_list_table_form_fields = ''; |
|
| 3059 | + } |
|
| 3060 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3061 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3062 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 3063 | + : ''; |
|
| 3064 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3065 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3066 | + . $nonce_ref |
|
| 3067 | + . '" value="' |
|
| 3068 | + . wp_create_nonce($nonce_ref) |
|
| 3069 | + . '">'; |
|
| 3070 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3071 | + //display message about search results? |
|
| 3072 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3073 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 3074 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3075 | + trim($this->_req_data['s'], '%') |
|
| 3076 | + ) . '</p>' |
|
| 3077 | + : ''; |
|
| 3078 | + // filter before_list_table template arg |
|
| 3079 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 3080 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3081 | + $this->_template_args['before_list_table'], |
|
| 3082 | + $this->page_slug, |
|
| 3083 | + $this->_req_data, |
|
| 3084 | + $this->_req_action |
|
| 3085 | + ); |
|
| 3086 | + // convert to array and filter again |
|
| 3087 | + // arrays are easier to inject new items in a specific location, |
|
| 3088 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3089 | + $this->_template_args['before_list_table'] = implode( |
|
| 3090 | + " \n", |
|
| 3091 | + (array)apply_filters( |
|
| 3092 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3093 | + (array)$this->_template_args['before_list_table'], |
|
| 3094 | + $this->page_slug, |
|
| 3095 | + $this->_req_data, |
|
| 3096 | + $this->_req_action |
|
| 3097 | + ) |
|
| 3098 | + ); |
|
| 3099 | + // filter after_list_table template arg |
|
| 3100 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3101 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3102 | + $this->_template_args['after_list_table'], |
|
| 3103 | + $this->page_slug, |
|
| 3104 | + $this->_req_data, |
|
| 3105 | + $this->_req_action |
|
| 3106 | + ); |
|
| 3107 | + // convert to array and filter again |
|
| 3108 | + // arrays are easier to inject new items in a specific location, |
|
| 3109 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3110 | + $this->_template_args['after_list_table'] = implode( |
|
| 3111 | + " \n", |
|
| 3112 | + (array)apply_filters( |
|
| 3113 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3114 | + (array)$this->_template_args['after_list_table'], |
|
| 3115 | + $this->page_slug, |
|
| 3116 | + $this->_req_data, |
|
| 3117 | + $this->_req_action |
|
| 3118 | + ) |
|
| 3119 | + ); |
|
| 3120 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3121 | + $template_path, |
|
| 3122 | + $this->_template_args, |
|
| 3123 | + true |
|
| 3124 | + ); |
|
| 3125 | + // the final template wrapper |
|
| 3126 | + if ($sidebar) { |
|
| 3127 | + $this->display_admin_page_with_sidebar(); |
|
| 3128 | + } else { |
|
| 3129 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3130 | + } |
|
| 3131 | + } |
|
| 3132 | + |
|
| 3133 | + |
|
| 3134 | + |
|
| 3135 | + /** |
|
| 3136 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3137 | + * html string for the legend. |
|
| 3138 | + * $items are expected in an array in the following format: |
|
| 3139 | + * $legend_items = array( |
|
| 3140 | + * 'item_id' => array( |
|
| 3141 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3142 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3143 | + * ) |
|
| 3144 | + * ); |
|
| 3145 | + * |
|
| 3146 | + * @param array $items see above for format of array |
|
| 3147 | + * @return string html string of legend |
|
| 3148 | + * @throws DomainException |
|
| 3149 | + */ |
|
| 3150 | + protected function _display_legend($items) |
|
| 3151 | + { |
|
| 3152 | + $this->_template_args['items'] = apply_filters( |
|
| 3153 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3154 | + (array)$items, |
|
| 3155 | + $this |
|
| 3156 | + ); |
|
| 3157 | + return EEH_Template::display_template( |
|
| 3158 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3159 | + $this->_template_args, |
|
| 3160 | + true |
|
| 3161 | + ); |
|
| 3162 | + } |
|
| 3163 | + |
|
| 3164 | + |
|
| 3165 | + /** |
|
| 3166 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3167 | + * The returned json object is created from an array in the following format: |
|
| 3168 | + * array( |
|
| 3169 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3170 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3171 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3172 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3173 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3174 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3175 | + * that might be included in here) |
|
| 3176 | + * ) |
|
| 3177 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3178 | + * |
|
| 3179 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3180 | + * instead of displayed. |
|
| 3181 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3182 | + * @return void |
|
| 3183 | + * @throws EE_Error |
|
| 3184 | + */ |
|
| 3185 | + protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3186 | + { |
|
| 3187 | + //make sure any EE_Error notices have been handled. |
|
| 3188 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3189 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3190 | + unset($this->_template_args['data']); |
|
| 3191 | + $json = array( |
|
| 3192 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3193 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3194 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3195 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3196 | + 'notices' => EE_Error::get_notices(), |
|
| 3197 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3198 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3199 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3200 | + 'isEEajax' => true |
|
| 3201 | + //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3202 | + ); |
|
| 3203 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3204 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3205 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3206 | + } |
|
| 3207 | + echo wp_json_encode($json); |
|
| 3208 | + exit(); |
|
| 3209 | + } |
|
| 3210 | + |
|
| 3211 | + |
|
| 3212 | + |
|
| 3213 | + /** |
|
| 3214 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3215 | + * |
|
| 3216 | + * @return void |
|
| 3217 | + * @throws EE_Error |
|
| 3218 | + */ |
|
| 3219 | + public function return_json() |
|
| 3220 | + { |
|
| 3221 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3222 | + $this->_return_json(); |
|
| 3223 | + } else { |
|
| 3224 | + throw new EE_Error( |
|
| 3225 | + sprintf( |
|
| 3226 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3227 | + __FUNCTION__ |
|
| 3228 | + ) |
|
| 3229 | + ); |
|
| 3230 | + } |
|
| 3231 | + } |
|
| 3232 | + |
|
| 3233 | + |
|
| 3234 | + |
|
| 3235 | + /** |
|
| 3236 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3237 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3238 | + * |
|
| 3239 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3240 | + */ |
|
| 3241 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3242 | + { |
|
| 3243 | + $this->_hook_obj = $hook_obj; |
|
| 3244 | + } |
|
| 3245 | + |
|
| 3246 | + |
|
| 3247 | + |
|
| 3248 | + /** |
|
| 3249 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3250 | + * |
|
| 3251 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3252 | + * @return void |
|
| 3253 | + * @throws DomainException |
|
| 3254 | + * @throws EE_Error |
|
| 3255 | + */ |
|
| 3256 | + public function admin_page_wrapper($about = false) |
|
| 3257 | + { |
|
| 3258 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3259 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3260 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3261 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3262 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3263 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3264 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3265 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3266 | + : '' |
|
| 3267 | + ); |
|
| 3268 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3269 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3270 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3271 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3272 | + : '' |
|
| 3273 | + ); |
|
| 3274 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3275 | + // load settings page wrapper template |
|
| 3276 | + $template_path = ! defined('DOING_AJAX') |
|
| 3277 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3278 | + : EE_ADMIN_TEMPLATE |
|
| 3279 | + . 'admin_wrapper_ajax.template.php'; |
|
| 3280 | + //about page? |
|
| 3281 | + $template_path = $about |
|
| 3282 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3283 | + : $template_path; |
|
| 3284 | + if (defined('DOING_AJAX')) { |
|
| 3285 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3286 | + $template_path, |
|
| 3287 | + $this->_template_args, |
|
| 3288 | + true |
|
| 3289 | + ); |
|
| 3290 | + $this->_return_json(); |
|
| 3291 | + } else { |
|
| 3292 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3293 | + } |
|
| 3294 | + } |
|
| 3295 | + |
|
| 3296 | + |
|
| 3297 | + |
|
| 3298 | + /** |
|
| 3299 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3300 | + * |
|
| 3301 | + * @return string html |
|
| 3302 | + * @throws EE_Error |
|
| 3303 | + */ |
|
| 3304 | + protected function _get_main_nav_tabs() |
|
| 3305 | + { |
|
| 3306 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3307 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3308 | + // (rather than setting in the page_routes array) |
|
| 3309 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3310 | + } |
|
| 3311 | + |
|
| 3312 | + |
|
| 3313 | + |
|
| 3314 | + /** |
|
| 3315 | + * sort nav tabs |
|
| 3316 | + * |
|
| 3317 | + * @param $a |
|
| 3318 | + * @param $b |
|
| 3319 | + * @return int |
|
| 3320 | + */ |
|
| 3321 | + private function _sort_nav_tabs($a, $b) |
|
| 3322 | + { |
|
| 3323 | + if ($a['order'] === $b['order']) { |
|
| 3324 | + return 0; |
|
| 3325 | + } |
|
| 3326 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3327 | + } |
|
| 3328 | + |
|
| 3329 | + |
|
| 3330 | + |
|
| 3331 | + /** |
|
| 3332 | + * generates HTML for the forms used on admin pages |
|
| 3333 | + * |
|
| 3334 | + * @param array $input_vars - array of input field details |
|
| 3335 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3336 | + * use) |
|
| 3337 | + * @param bool $id |
|
| 3338 | + * @return string |
|
| 3339 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3340 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3341 | + */ |
|
| 3342 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3343 | + { |
|
| 3344 | + $content = $generator === 'string' |
|
| 3345 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3346 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3347 | + return $content; |
|
| 3348 | + } |
|
| 3349 | + |
|
| 3350 | + |
|
| 3351 | + |
|
| 3352 | + /** |
|
| 3353 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3354 | + * |
|
| 3355 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3356 | + * Close" button. |
|
| 3357 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3358 | + * 'Save', [1] => 'save & close') |
|
| 3359 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3360 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3361 | + * default actions by submitting some other value. |
|
| 3362 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3363 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3364 | + * close (normal form handling). |
|
| 3365 | + */ |
|
| 3366 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3367 | + { |
|
| 3368 | + //make sure $text and $actions are in an array |
|
| 3369 | + $text = (array)$text; |
|
| 3370 | + $actions = (array)$actions; |
|
| 3371 | + $referrer_url = empty($referrer) |
|
| 3372 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3373 | + . $_SERVER['REQUEST_URI'] |
|
| 3374 | + . '" />' |
|
| 3375 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3376 | + . $referrer |
|
| 3377 | + . '" />'; |
|
| 3378 | + $button_text = ! empty($text) |
|
| 3379 | + ? $text |
|
| 3380 | + : array( |
|
| 3381 | + esc_html__('Save', 'event_espresso'), |
|
| 3382 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3383 | + ); |
|
| 3384 | + $default_names = array('save', 'save_and_close'); |
|
| 3385 | + //add in a hidden index for the current page (so save and close redirects properly) |
|
| 3386 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3387 | + foreach ($button_text as $key => $button) { |
|
| 3388 | + $ref = $default_names[$key]; |
|
| 3389 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3390 | + . $ref |
|
| 3391 | + . '" value="' |
|
| 3392 | + . $button |
|
| 3393 | + . '" name="' |
|
| 3394 | + . (! empty($actions) ? $actions[$key] : $ref) |
|
| 3395 | + . '" id="' |
|
| 3396 | + . $this->_current_view . '_' . $ref |
|
| 3397 | + . '" />'; |
|
| 3398 | + if (! $both) { |
|
| 3399 | + break; |
|
| 3400 | + } |
|
| 3401 | + } |
|
| 3402 | + } |
|
| 3403 | + |
|
| 3404 | + |
|
| 3405 | + |
|
| 3406 | + /** |
|
| 3407 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3408 | + * |
|
| 3409 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3410 | + * @since 4.6.0 |
|
| 3411 | + * @param string $route |
|
| 3412 | + * @param array $additional_hidden_fields |
|
| 3413 | + */ |
|
| 3414 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3415 | + { |
|
| 3416 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3417 | + } |
|
| 3418 | + |
|
| 3419 | + |
|
| 3420 | + |
|
| 3421 | + /** |
|
| 3422 | + * set form open and close tags on add/edit pages. |
|
| 3423 | + * |
|
| 3424 | + * @param string $route the route you want the form to direct to |
|
| 3425 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3426 | + * @return void |
|
| 3427 | + */ |
|
| 3428 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3429 | + { |
|
| 3430 | + if (empty($route)) { |
|
| 3431 | + $user_msg = esc_html__( |
|
| 3432 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3433 | + 'event_espresso' |
|
| 3434 | + ); |
|
| 3435 | + $dev_msg = $user_msg . "\n" . sprintf( |
|
| 3436 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3437 | + __FUNCTION__, |
|
| 3438 | + __CLASS__ |
|
| 3439 | + ); |
|
| 3440 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3441 | + } |
|
| 3442 | + // open form |
|
| 3443 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3444 | + . $this->_admin_base_url |
|
| 3445 | + . '" id="' |
|
| 3446 | + . $route |
|
| 3447 | + . '_event_form" >'; |
|
| 3448 | + // add nonce |
|
| 3449 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3450 | + // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 3451 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3452 | + // add REQUIRED form action |
|
| 3453 | + $hidden_fields = array( |
|
| 3454 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3455 | + ); |
|
| 3456 | + // merge arrays |
|
| 3457 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3458 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3459 | + : $hidden_fields; |
|
| 3460 | + // generate form fields |
|
| 3461 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3462 | + // add fields to form |
|
| 3463 | + foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 3464 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3465 | + } |
|
| 3466 | + // close form |
|
| 3467 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3468 | + } |
|
| 3469 | + |
|
| 3470 | + |
|
| 3471 | + |
|
| 3472 | + /** |
|
| 3473 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3474 | + * discovered it would be useful for external code to have access. |
|
| 3475 | + * |
|
| 3476 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3477 | + * @since 4.5.0 |
|
| 3478 | + * @param bool $success |
|
| 3479 | + * @param string $what |
|
| 3480 | + * @param string $action_desc |
|
| 3481 | + * @param array $query_args |
|
| 3482 | + * @param bool $override_overwrite |
|
| 3483 | + * @throws EE_Error |
|
| 3484 | + */ |
|
| 3485 | + public function redirect_after_action( |
|
| 3486 | + $success = false, |
|
| 3487 | + $what = 'item', |
|
| 3488 | + $action_desc = 'processed', |
|
| 3489 | + $query_args = array(), |
|
| 3490 | + $override_overwrite = false |
|
| 3491 | + ) { |
|
| 3492 | + $this->_redirect_after_action( |
|
| 3493 | + $success, |
|
| 3494 | + $what, |
|
| 3495 | + $action_desc, |
|
| 3496 | + $query_args, |
|
| 3497 | + $override_overwrite |
|
| 3498 | + ); |
|
| 3499 | + } |
|
| 3500 | + |
|
| 3501 | + |
|
| 3502 | + |
|
| 3503 | + /** |
|
| 3504 | + * _redirect_after_action |
|
| 3505 | + * |
|
| 3506 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3507 | + * @param string $what - what the action was performed on |
|
| 3508 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3509 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3510 | + * action is completed |
|
| 3511 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3512 | + * override this so that they show. |
|
| 3513 | + * @return void |
|
| 3514 | + * @throws EE_Error |
|
| 3515 | + */ |
|
| 3516 | + protected function _redirect_after_action( |
|
| 3517 | + $success = 0, |
|
| 3518 | + $what = 'item', |
|
| 3519 | + $action_desc = 'processed', |
|
| 3520 | + $query_args = array(), |
|
| 3521 | + $override_overwrite = false |
|
| 3522 | + ) { |
|
| 3523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3524 | + //class name for actions/filters. |
|
| 3525 | + $classname = get_class($this); |
|
| 3526 | + // set redirect url. |
|
| 3527 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3528 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3529 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3530 | + $notices = EE_Error::get_notices(false); |
|
| 3531 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3532 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3533 | + EE_Error::overwrite_success(); |
|
| 3534 | + } |
|
| 3535 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3536 | + // how many records affected ? more than one record ? or just one ? |
|
| 3537 | + if ($success > 1) { |
|
| 3538 | + // set plural msg |
|
| 3539 | + EE_Error::add_success( |
|
| 3540 | + sprintf( |
|
| 3541 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3542 | + $what, |
|
| 3543 | + $action_desc |
|
| 3544 | + ), |
|
| 3545 | + __FILE__, |
|
| 3546 | + __FUNCTION__, |
|
| 3547 | + __LINE__ |
|
| 3548 | + ); |
|
| 3549 | + } elseif ($success === 1) { |
|
| 3550 | + // set singular msg |
|
| 3551 | + EE_Error::add_success( |
|
| 3552 | + sprintf( |
|
| 3553 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3554 | + $what, |
|
| 3555 | + $action_desc |
|
| 3556 | + ), |
|
| 3557 | + __FILE__, |
|
| 3558 | + __FUNCTION__, |
|
| 3559 | + __LINE__ |
|
| 3560 | + ); |
|
| 3561 | + } |
|
| 3562 | + } |
|
| 3563 | + // check that $query_args isn't something crazy |
|
| 3564 | + if (! is_array($query_args)) { |
|
| 3565 | + $query_args = array(); |
|
| 3566 | + } |
|
| 3567 | + /** |
|
| 3568 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3569 | + * redirections on save and close actions |
|
| 3570 | + * |
|
| 3571 | + * @since 4.2.0 |
|
| 3572 | + * @param array $query_args The original query_args array coming into the |
|
| 3573 | + * method. |
|
| 3574 | + */ |
|
| 3575 | + do_action( |
|
| 3576 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3577 | + $query_args |
|
| 3578 | + ); |
|
| 3579 | + //calculate where we're going (if we have a "save and close" button pushed) |
|
| 3580 | + if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3581 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3582 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3583 | + // regenerate query args array from referrer URL |
|
| 3584 | + parse_str($parsed_url['query'], $query_args); |
|
| 3585 | + // correct page and action will be in the query args now |
|
| 3586 | + $redirect_url = admin_url('admin.php'); |
|
| 3587 | + } |
|
| 3588 | + //merge any default query_args set in _default_route_query_args property |
|
| 3589 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3590 | + $args_to_merge = array(); |
|
| 3591 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3592 | + //is there a wp_referer array in our _default_route_query_args property? |
|
| 3593 | + if ($query_param === 'wp_referer') { |
|
| 3594 | + $query_value = (array)$query_value; |
|
| 3595 | + foreach ($query_value as $reference => $value) { |
|
| 3596 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3597 | + continue; |
|
| 3598 | + } |
|
| 3599 | + //finally we will override any arguments in the referer with |
|
| 3600 | + //what might be set on the _default_route_query_args array. |
|
| 3601 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3602 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3603 | + } else { |
|
| 3604 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3605 | + } |
|
| 3606 | + } |
|
| 3607 | + continue; |
|
| 3608 | + } |
|
| 3609 | + $args_to_merge[$query_param] = $query_value; |
|
| 3610 | + } |
|
| 3611 | + //now let's merge these arguments but override with what was specifically sent in to the |
|
| 3612 | + //redirect. |
|
| 3613 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3614 | + } |
|
| 3615 | + $this->_process_notices($query_args); |
|
| 3616 | + // generate redirect url |
|
| 3617 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3618 | + if (isset($query_args['action'])) { |
|
| 3619 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3620 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3621 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3622 | + } |
|
| 3623 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3624 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3625 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3626 | + $redirect_url = apply_filters( |
|
| 3627 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3628 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3629 | + $query_args |
|
| 3630 | + ); |
|
| 3631 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3632 | + if (defined('DOING_AJAX')) { |
|
| 3633 | + $default_data = array( |
|
| 3634 | + 'close' => true, |
|
| 3635 | + 'redirect_url' => $redirect_url, |
|
| 3636 | + 'where' => 'main', |
|
| 3637 | + 'what' => 'append', |
|
| 3638 | + ); |
|
| 3639 | + $this->_template_args['success'] = $success; |
|
| 3640 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3641 | + $default_data, |
|
| 3642 | + $this->_template_args['data'] |
|
| 3643 | + ) : $default_data; |
|
| 3644 | + $this->_return_json(); |
|
| 3645 | + } |
|
| 3646 | + wp_safe_redirect($redirect_url); |
|
| 3647 | + exit(); |
|
| 3648 | + } |
|
| 3649 | + |
|
| 3650 | + |
|
| 3651 | + |
|
| 3652 | + /** |
|
| 3653 | + * process any notices before redirecting (or returning ajax request) |
|
| 3654 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3655 | + * |
|
| 3656 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3657 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3658 | + * page_routes haven't been defined yet. |
|
| 3659 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3660 | + * still save a transient for the notice. |
|
| 3661 | + * @return void |
|
| 3662 | + * @throws EE_Error |
|
| 3663 | + */ |
|
| 3664 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3665 | + { |
|
| 3666 | + //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3667 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3668 | + $notices = EE_Error::get_notices(false); |
|
| 3669 | + if (empty($this->_template_args['success'])) { |
|
| 3670 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3671 | + } |
|
| 3672 | + if (empty($this->_template_args['errors'])) { |
|
| 3673 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3674 | + } |
|
| 3675 | + if (empty($this->_template_args['attention'])) { |
|
| 3676 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3677 | + } |
|
| 3678 | + } |
|
| 3679 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3680 | + //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3681 | + if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3682 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3683 | + $this->_add_transient( |
|
| 3684 | + $route, |
|
| 3685 | + $this->_template_args['notices'], |
|
| 3686 | + true, |
|
| 3687 | + $skip_route_verify |
|
| 3688 | + ); |
|
| 3689 | + } |
|
| 3690 | + } |
|
| 3691 | + |
|
| 3692 | + |
|
| 3693 | + |
|
| 3694 | + /** |
|
| 3695 | + * get_action_link_or_button |
|
| 3696 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3697 | + * |
|
| 3698 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3699 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3700 | + * property. |
|
| 3701 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3702 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3703 | + * @param string $base_url If this is not provided |
|
| 3704 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3705 | + * Otherwise this value will be used. |
|
| 3706 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3707 | + * @return string |
|
| 3708 | + * @throws InvalidArgumentException |
|
| 3709 | + * @throws InvalidInterfaceException |
|
| 3710 | + * @throws InvalidDataTypeException |
|
| 3711 | + * @throws EE_Error |
|
| 3712 | + */ |
|
| 3713 | + public function get_action_link_or_button( |
|
| 3714 | + $action, |
|
| 3715 | + $type = 'add', |
|
| 3716 | + $extra_request = array(), |
|
| 3717 | + $class = 'button-primary', |
|
| 3718 | + $base_url = '', |
|
| 3719 | + $exclude_nonce = false |
|
| 3720 | + ) { |
|
| 3721 | + //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3722 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3723 | + throw new EE_Error( |
|
| 3724 | + sprintf( |
|
| 3725 | + esc_html__( |
|
| 3726 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3727 | + 'event_espresso' |
|
| 3728 | + ), |
|
| 3729 | + $action |
|
| 3730 | + ) |
|
| 3731 | + ); |
|
| 3732 | + } |
|
| 3733 | + if (! isset($this->_labels['buttons'][$type])) { |
|
| 3734 | + throw new EE_Error( |
|
| 3735 | + sprintf( |
|
| 3736 | + __( |
|
| 3737 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3738 | + 'event_espresso' |
|
| 3739 | + ), |
|
| 3740 | + $type |
|
| 3741 | + ) |
|
| 3742 | + ); |
|
| 3743 | + } |
|
| 3744 | + //finally check user access for this button. |
|
| 3745 | + $has_access = $this->check_user_access($action, true); |
|
| 3746 | + if (! $has_access) { |
|
| 3747 | + return ''; |
|
| 3748 | + } |
|
| 3749 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3750 | + $query_args = array( |
|
| 3751 | + 'action' => $action, |
|
| 3752 | + ); |
|
| 3753 | + //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3754 | + if (! empty($extra_request)) { |
|
| 3755 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3756 | + } |
|
| 3757 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3758 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3759 | + } |
|
| 3760 | + |
|
| 3761 | + |
|
| 3762 | + |
|
| 3763 | + /** |
|
| 3764 | + * _per_page_screen_option |
|
| 3765 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3766 | + * |
|
| 3767 | + * @return void |
|
| 3768 | + * @throws InvalidArgumentException |
|
| 3769 | + * @throws InvalidInterfaceException |
|
| 3770 | + * @throws InvalidDataTypeException |
|
| 3771 | + */ |
|
| 3772 | + protected function _per_page_screen_option() |
|
| 3773 | + { |
|
| 3774 | + $option = 'per_page'; |
|
| 3775 | + $args = array( |
|
| 3776 | + 'label' => esc_html__( |
|
| 3777 | + apply_filters( |
|
| 3778 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3779 | + $this->_admin_page_title, |
|
| 3780 | + $this |
|
| 3781 | + ) |
|
| 3782 | + ), |
|
| 3783 | + 'default' => (int) apply_filters( |
|
| 3784 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3785 | + 10 |
|
| 3786 | + ), |
|
| 3787 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3788 | + ); |
|
| 3789 | + //ONLY add the screen option if the user has access to it. |
|
| 3790 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3791 | + add_screen_option($option, $args); |
|
| 3792 | + } |
|
| 3793 | + } |
|
| 3794 | + |
|
| 3795 | + |
|
| 3796 | + |
|
| 3797 | + /** |
|
| 3798 | + * set_per_page_screen_option |
|
| 3799 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3800 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3801 | + * admin_menu. |
|
| 3802 | + * |
|
| 3803 | + * @return void |
|
| 3804 | + */ |
|
| 3805 | + private function _set_per_page_screen_options() |
|
| 3806 | + { |
|
| 3807 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3808 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3809 | + if (! $user = wp_get_current_user()) { |
|
| 3810 | + return; |
|
| 3811 | + } |
|
| 3812 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3813 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3814 | + if ($option != sanitize_key($option)) { |
|
| 3815 | + return; |
|
| 3816 | + } |
|
| 3817 | + $map_option = $option; |
|
| 3818 | + $option = str_replace('-', '_', $option); |
|
| 3819 | + switch ($map_option) { |
|
| 3820 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3821 | + $value = (int)$value; |
|
| 3822 | + $max_value = apply_filters( |
|
| 3823 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3824 | + 999, |
|
| 3825 | + $this->_current_page, |
|
| 3826 | + $this->_current_view |
|
| 3827 | + ); |
|
| 3828 | + if ($value < 1) { |
|
| 3829 | + return; |
|
| 3830 | + } |
|
| 3831 | + $value = min($value, $max_value); |
|
| 3832 | + break; |
|
| 3833 | + default: |
|
| 3834 | + $value = apply_filters( |
|
| 3835 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3836 | + false, |
|
| 3837 | + $option, |
|
| 3838 | + $value |
|
| 3839 | + ); |
|
| 3840 | + if (false === $value) { |
|
| 3841 | + return; |
|
| 3842 | + } |
|
| 3843 | + break; |
|
| 3844 | + } |
|
| 3845 | + update_user_meta($user->ID, $option, $value); |
|
| 3846 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3847 | + exit; |
|
| 3848 | + } |
|
| 3849 | + } |
|
| 3850 | + |
|
| 3851 | + |
|
| 3852 | + |
|
| 3853 | + /** |
|
| 3854 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3855 | + * |
|
| 3856 | + * @param array $data array that will be assigned to template args. |
|
| 3857 | + */ |
|
| 3858 | + public function set_template_args($data) |
|
| 3859 | + { |
|
| 3860 | + $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3861 | + } |
|
| 3862 | + |
|
| 3863 | + |
|
| 3864 | + |
|
| 3865 | + /** |
|
| 3866 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3867 | + * |
|
| 3868 | + * @param string $route the route that should receive the transient |
|
| 3869 | + * @param array $data the data that gets sent |
|
| 3870 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3871 | + * normal route transient. |
|
| 3872 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3873 | + * when we are adding a transient before page_routes have been defined. |
|
| 3874 | + * @return void |
|
| 3875 | + * @throws EE_Error |
|
| 3876 | + */ |
|
| 3877 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3878 | + { |
|
| 3879 | + $user_id = get_current_user_id(); |
|
| 3880 | + if (! $skip_route_verify) { |
|
| 3881 | + $this->_verify_route($route); |
|
| 3882 | + } |
|
| 3883 | + //now let's set the string for what kind of transient we're setting |
|
| 3884 | + $transient = $notices |
|
| 3885 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3886 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3887 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3888 | + //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3889 | + $existing = is_multisite() && is_network_admin() |
|
| 3890 | + ? get_site_transient($transient) |
|
| 3891 | + : get_transient($transient); |
|
| 3892 | + if ($existing) { |
|
| 3893 | + $data = array_merge((array)$data, (array)$existing); |
|
| 3894 | + } |
|
| 3895 | + if (is_multisite() && is_network_admin()) { |
|
| 3896 | + set_site_transient($transient, $data, 8); |
|
| 3897 | + } else { |
|
| 3898 | + set_transient($transient, $data, 8); |
|
| 3899 | + } |
|
| 3900 | + } |
|
| 3901 | + |
|
| 3902 | + |
|
| 3903 | + |
|
| 3904 | + /** |
|
| 3905 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3906 | + * |
|
| 3907 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3908 | + * @param string $route |
|
| 3909 | + * @return mixed data |
|
| 3910 | + */ |
|
| 3911 | + protected function _get_transient($notices = false, $route = '') |
|
| 3912 | + { |
|
| 3913 | + $user_id = get_current_user_id(); |
|
| 3914 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3915 | + $transient = $notices |
|
| 3916 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3917 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3918 | + $data = is_multisite() && is_network_admin() |
|
| 3919 | + ? get_site_transient($transient) |
|
| 3920 | + : get_transient($transient); |
|
| 3921 | + //delete transient after retrieval (just in case it hasn't expired); |
|
| 3922 | + if (is_multisite() && is_network_admin()) { |
|
| 3923 | + delete_site_transient($transient); |
|
| 3924 | + } else { |
|
| 3925 | + delete_transient($transient); |
|
| 3926 | + } |
|
| 3927 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3928 | + } |
|
| 3929 | + |
|
| 3930 | + |
|
| 3931 | + |
|
| 3932 | + /** |
|
| 3933 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3934 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3935 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3936 | + * |
|
| 3937 | + * @return void |
|
| 3938 | + */ |
|
| 3939 | + protected function _transient_garbage_collection() |
|
| 3940 | + { |
|
| 3941 | + global $wpdb; |
|
| 3942 | + //retrieve all existing transients |
|
| 3943 | + $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3944 | + if ($results = $wpdb->get_results($query)) { |
|
| 3945 | + foreach ($results as $result) { |
|
| 3946 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3947 | + get_transient($transient); |
|
| 3948 | + if (is_multisite() && is_network_admin()) { |
|
| 3949 | + get_site_transient($transient); |
|
| 3950 | + } |
|
| 3951 | + } |
|
| 3952 | + } |
|
| 3953 | + } |
|
| 3954 | + |
|
| 3955 | + |
|
| 3956 | + |
|
| 3957 | + /** |
|
| 3958 | + * get_view |
|
| 3959 | + * |
|
| 3960 | + * @return string content of _view property |
|
| 3961 | + */ |
|
| 3962 | + public function get_view() |
|
| 3963 | + { |
|
| 3964 | + return $this->_view; |
|
| 3965 | + } |
|
| 3966 | + |
|
| 3967 | + |
|
| 3968 | + |
|
| 3969 | + /** |
|
| 3970 | + * getter for the protected $_views property |
|
| 3971 | + * |
|
| 3972 | + * @return array |
|
| 3973 | + */ |
|
| 3974 | + public function get_views() |
|
| 3975 | + { |
|
| 3976 | + return $this->_views; |
|
| 3977 | + } |
|
| 3978 | + |
|
| 3979 | + |
|
| 3980 | + |
|
| 3981 | + /** |
|
| 3982 | + * get_current_page |
|
| 3983 | + * |
|
| 3984 | + * @return string _current_page property value |
|
| 3985 | + */ |
|
| 3986 | + public function get_current_page() |
|
| 3987 | + { |
|
| 3988 | + return $this->_current_page; |
|
| 3989 | + } |
|
| 3990 | + |
|
| 3991 | + |
|
| 3992 | + |
|
| 3993 | + /** |
|
| 3994 | + * get_current_view |
|
| 3995 | + * |
|
| 3996 | + * @return string _current_view property value |
|
| 3997 | + */ |
|
| 3998 | + public function get_current_view() |
|
| 3999 | + { |
|
| 4000 | + return $this->_current_view; |
|
| 4001 | + } |
|
| 4002 | + |
|
| 4003 | + |
|
| 4004 | + |
|
| 4005 | + /** |
|
| 4006 | + * get_current_screen |
|
| 4007 | + * |
|
| 4008 | + * @return object The current WP_Screen object |
|
| 4009 | + */ |
|
| 4010 | + public function get_current_screen() |
|
| 4011 | + { |
|
| 4012 | + return $this->_current_screen; |
|
| 4013 | + } |
|
| 4014 | + |
|
| 4015 | + |
|
| 4016 | + |
|
| 4017 | + /** |
|
| 4018 | + * get_current_page_view_url |
|
| 4019 | + * |
|
| 4020 | + * @return string This returns the url for the current_page_view. |
|
| 4021 | + */ |
|
| 4022 | + public function get_current_page_view_url() |
|
| 4023 | + { |
|
| 4024 | + return $this->_current_page_view_url; |
|
| 4025 | + } |
|
| 4026 | + |
|
| 4027 | + |
|
| 4028 | + |
|
| 4029 | + /** |
|
| 4030 | + * just returns the _req_data property |
|
| 4031 | + * |
|
| 4032 | + * @return array |
|
| 4033 | + */ |
|
| 4034 | + public function get_request_data() |
|
| 4035 | + { |
|
| 4036 | + return $this->_req_data; |
|
| 4037 | + } |
|
| 4038 | + |
|
| 4039 | + |
|
| 4040 | + |
|
| 4041 | + /** |
|
| 4042 | + * returns the _req_data protected property |
|
| 4043 | + * |
|
| 4044 | + * @return string |
|
| 4045 | + */ |
|
| 4046 | + public function get_req_action() |
|
| 4047 | + { |
|
| 4048 | + return $this->_req_action; |
|
| 4049 | + } |
|
| 4050 | + |
|
| 4051 | + |
|
| 4052 | + |
|
| 4053 | + /** |
|
| 4054 | + * @return bool value of $_is_caf property |
|
| 4055 | + */ |
|
| 4056 | + public function is_caf() |
|
| 4057 | + { |
|
| 4058 | + return $this->_is_caf; |
|
| 4059 | + } |
|
| 4060 | + |
|
| 4061 | + |
|
| 4062 | + |
|
| 4063 | + /** |
|
| 4064 | + * @return mixed |
|
| 4065 | + */ |
|
| 4066 | + public function default_espresso_metaboxes() |
|
| 4067 | + { |
|
| 4068 | + return $this->_default_espresso_metaboxes; |
|
| 4069 | + } |
|
| 4070 | + |
|
| 4071 | + |
|
| 4072 | + |
|
| 4073 | + /** |
|
| 4074 | + * @return mixed |
|
| 4075 | + */ |
|
| 4076 | + public function admin_base_url() |
|
| 4077 | + { |
|
| 4078 | + return $this->_admin_base_url; |
|
| 4079 | + } |
|
| 4080 | 4080 | |
| 4081 | 4081 | |
| 4082 | 4082 | |
| 4083 | - /** |
|
| 4084 | - * @return mixed |
|
| 4085 | - */ |
|
| 4086 | - public function wp_page_slug() |
|
| 4087 | - { |
|
| 4088 | - return $this->_wp_page_slug; |
|
| 4089 | - } |
|
| 4083 | + /** |
|
| 4084 | + * @return mixed |
|
| 4085 | + */ |
|
| 4086 | + public function wp_page_slug() |
|
| 4087 | + { |
|
| 4088 | + return $this->_wp_page_slug; |
|
| 4089 | + } |
|
| 4090 | 4090 | |
| 4091 | 4091 | |
| 4092 | - |
|
| 4093 | - /** |
|
| 4094 | - * updates espresso configuration settings |
|
| 4095 | - * |
|
| 4096 | - * @param string $tab |
|
| 4097 | - * @param EE_Config_Base|EE_Config $config |
|
| 4098 | - * @param string $file file where error occurred |
|
| 4099 | - * @param string $func function where error occurred |
|
| 4100 | - * @param string $line line no where error occurred |
|
| 4101 | - * @return boolean |
|
| 4102 | - */ |
|
| 4103 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4104 | - { |
|
| 4105 | - //remove any options that are NOT going to be saved with the config settings. |
|
| 4106 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4107 | - $config->core->ee_ueip_has_notified = true; |
|
| 4108 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4109 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4110 | - update_option('ee_ueip_has_notified', true); |
|
| 4111 | - } |
|
| 4112 | - // and save it (note we're also doing the network save here) |
|
| 4113 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4114 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4115 | - if ($config_saved && $net_saved) { |
|
| 4116 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4117 | - return true; |
|
| 4118 | - } |
|
| 4119 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4120 | - return false; |
|
| 4121 | - } |
|
| 4122 | - |
|
| 4123 | - |
|
| 4124 | - |
|
| 4125 | - /** |
|
| 4126 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4127 | - * |
|
| 4128 | - * @return array |
|
| 4129 | - */ |
|
| 4130 | - public function get_yes_no_values() |
|
| 4131 | - { |
|
| 4132 | - return $this->_yes_no_values; |
|
| 4133 | - } |
|
| 4134 | - |
|
| 4135 | - |
|
| 4136 | - |
|
| 4137 | - protected function _get_dir() |
|
| 4138 | - { |
|
| 4139 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4140 | - return dirname($reflector->getFileName()); |
|
| 4141 | - } |
|
| 4142 | - |
|
| 4143 | - |
|
| 4144 | - |
|
| 4145 | - /** |
|
| 4146 | - * A helper for getting a "next link". |
|
| 4147 | - * |
|
| 4148 | - * @param string $url The url to link to |
|
| 4149 | - * @param string $class The class to use. |
|
| 4150 | - * @return string |
|
| 4151 | - */ |
|
| 4152 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4153 | - { |
|
| 4154 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4155 | - } |
|
| 4156 | - |
|
| 4157 | - |
|
| 4158 | - |
|
| 4159 | - /** |
|
| 4160 | - * A helper for getting a "previous link". |
|
| 4161 | - * |
|
| 4162 | - * @param string $url The url to link to |
|
| 4163 | - * @param string $class The class to use. |
|
| 4164 | - * @return string |
|
| 4165 | - */ |
|
| 4166 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4167 | - { |
|
| 4168 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4169 | - } |
|
| 4170 | - |
|
| 4171 | - |
|
| 4172 | - |
|
| 4173 | - |
|
| 4174 | - |
|
| 4175 | - |
|
| 4176 | - |
|
| 4177 | - //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4178 | - |
|
| 4179 | - |
|
| 4180 | - /** |
|
| 4181 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4182 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4183 | - * _req_data array. |
|
| 4184 | - * |
|
| 4185 | - * @return bool success/fail |
|
| 4186 | - * @throws EE_Error |
|
| 4187 | - * @throws InvalidArgumentException |
|
| 4188 | - * @throws ReflectionException |
|
| 4189 | - * @throws InvalidDataTypeException |
|
| 4190 | - * @throws InvalidInterfaceException |
|
| 4191 | - */ |
|
| 4192 | - protected function _process_resend_registration() |
|
| 4193 | - { |
|
| 4194 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4195 | - do_action( |
|
| 4196 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4197 | - $this->_template_args['success'], |
|
| 4198 | - $this->_req_data |
|
| 4199 | - ); |
|
| 4200 | - return $this->_template_args['success']; |
|
| 4201 | - } |
|
| 4202 | - |
|
| 4203 | - |
|
| 4204 | - |
|
| 4205 | - /** |
|
| 4206 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4207 | - * |
|
| 4208 | - * @param \EE_Payment $payment |
|
| 4209 | - * @return bool success/fail |
|
| 4210 | - */ |
|
| 4211 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4212 | - { |
|
| 4213 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4214 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4215 | - $this->_template_args['success'] = apply_filters( |
|
| 4216 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4217 | - false, |
|
| 4218 | - $payment |
|
| 4219 | - ); |
|
| 4220 | - return $this->_template_args['success']; |
|
| 4221 | - } |
|
| 4092 | + |
|
| 4093 | + /** |
|
| 4094 | + * updates espresso configuration settings |
|
| 4095 | + * |
|
| 4096 | + * @param string $tab |
|
| 4097 | + * @param EE_Config_Base|EE_Config $config |
|
| 4098 | + * @param string $file file where error occurred |
|
| 4099 | + * @param string $func function where error occurred |
|
| 4100 | + * @param string $line line no where error occurred |
|
| 4101 | + * @return boolean |
|
| 4102 | + */ |
|
| 4103 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4104 | + { |
|
| 4105 | + //remove any options that are NOT going to be saved with the config settings. |
|
| 4106 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4107 | + $config->core->ee_ueip_has_notified = true; |
|
| 4108 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4109 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4110 | + update_option('ee_ueip_has_notified', true); |
|
| 4111 | + } |
|
| 4112 | + // and save it (note we're also doing the network save here) |
|
| 4113 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4114 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4115 | + if ($config_saved && $net_saved) { |
|
| 4116 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4117 | + return true; |
|
| 4118 | + } |
|
| 4119 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4120 | + return false; |
|
| 4121 | + } |
|
| 4122 | + |
|
| 4123 | + |
|
| 4124 | + |
|
| 4125 | + /** |
|
| 4126 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4127 | + * |
|
| 4128 | + * @return array |
|
| 4129 | + */ |
|
| 4130 | + public function get_yes_no_values() |
|
| 4131 | + { |
|
| 4132 | + return $this->_yes_no_values; |
|
| 4133 | + } |
|
| 4134 | + |
|
| 4135 | + |
|
| 4136 | + |
|
| 4137 | + protected function _get_dir() |
|
| 4138 | + { |
|
| 4139 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4140 | + return dirname($reflector->getFileName()); |
|
| 4141 | + } |
|
| 4142 | + |
|
| 4143 | + |
|
| 4144 | + |
|
| 4145 | + /** |
|
| 4146 | + * A helper for getting a "next link". |
|
| 4147 | + * |
|
| 4148 | + * @param string $url The url to link to |
|
| 4149 | + * @param string $class The class to use. |
|
| 4150 | + * @return string |
|
| 4151 | + */ |
|
| 4152 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4153 | + { |
|
| 4154 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4155 | + } |
|
| 4156 | + |
|
| 4157 | + |
|
| 4158 | + |
|
| 4159 | + /** |
|
| 4160 | + * A helper for getting a "previous link". |
|
| 4161 | + * |
|
| 4162 | + * @param string $url The url to link to |
|
| 4163 | + * @param string $class The class to use. |
|
| 4164 | + * @return string |
|
| 4165 | + */ |
|
| 4166 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4167 | + { |
|
| 4168 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4169 | + } |
|
| 4170 | + |
|
| 4171 | + |
|
| 4172 | + |
|
| 4173 | + |
|
| 4174 | + |
|
| 4175 | + |
|
| 4176 | + |
|
| 4177 | + //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4178 | + |
|
| 4179 | + |
|
| 4180 | + /** |
|
| 4181 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4182 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4183 | + * _req_data array. |
|
| 4184 | + * |
|
| 4185 | + * @return bool success/fail |
|
| 4186 | + * @throws EE_Error |
|
| 4187 | + * @throws InvalidArgumentException |
|
| 4188 | + * @throws ReflectionException |
|
| 4189 | + * @throws InvalidDataTypeException |
|
| 4190 | + * @throws InvalidInterfaceException |
|
| 4191 | + */ |
|
| 4192 | + protected function _process_resend_registration() |
|
| 4193 | + { |
|
| 4194 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4195 | + do_action( |
|
| 4196 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4197 | + $this->_template_args['success'], |
|
| 4198 | + $this->_req_data |
|
| 4199 | + ); |
|
| 4200 | + return $this->_template_args['success']; |
|
| 4201 | + } |
|
| 4202 | + |
|
| 4203 | + |
|
| 4204 | + |
|
| 4205 | + /** |
|
| 4206 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4207 | + * |
|
| 4208 | + * @param \EE_Payment $payment |
|
| 4209 | + * @return bool success/fail |
|
| 4210 | + */ |
|
| 4211 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4212 | + { |
|
| 4213 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4214 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4215 | + $this->_template_args['success'] = apply_filters( |
|
| 4216 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4217 | + false, |
|
| 4218 | + $payment |
|
| 4219 | + ); |
|
| 4220 | + return $this->_template_args['success']; |
|
| 4221 | + } |
|
| 4222 | 4222 | |
| 4223 | 4223 | |
| 4224 | 4224 | } |
@@ -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 | |
@@ -16,680 +16,680 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | //Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 18 | 18 | if (! function_exists('mb_strcut')) { |
| 19 | - /** |
|
| 20 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 21 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 22 | - * @param $string |
|
| 23 | - * @param $start |
|
| 24 | - * @param $length |
|
| 25 | - * @return bool|string |
|
| 26 | - */ |
|
| 27 | - function mb_strcut($string, $start, $length = null) |
|
| 28 | - { |
|
| 29 | - return mb_substr($string, $start, $length); |
|
| 30 | - } |
|
| 19 | + /** |
|
| 20 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 21 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 22 | + * @param $string |
|
| 23 | + * @param $start |
|
| 24 | + * @param $length |
|
| 25 | + * @return bool|string |
|
| 26 | + */ |
|
| 27 | + function mb_strcut($string, $start, $length = null) |
|
| 28 | + { |
|
| 29 | + return mb_substr($string, $start, $length); |
|
| 30 | + } |
|
| 31 | 31 | } |
| 32 | 32 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Merchant API Username. |
|
| 37 | - * |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - protected $_api_username; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Merchant API Password. |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $_api_password; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * API Signature. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - protected $_api_signature; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Request Shipping address on PP checkout page. |
|
| 58 | - * |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - protected $_request_shipping_addr; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Business/personal logo. |
|
| 65 | - * |
|
| 66 | - * @var string |
|
| 67 | - */ |
|
| 68 | - protected $_image_url; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * gateway URL variable |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - protected $_base_gateway_url = ''; |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * EEG_Paypal_Express constructor. |
|
| 81 | - */ |
|
| 82 | - public function __construct() |
|
| 83 | - { |
|
| 84 | - $this->_currencies_supported = array( |
|
| 85 | - 'USD', |
|
| 86 | - 'AUD', |
|
| 87 | - 'BRL', |
|
| 88 | - 'CAD', |
|
| 89 | - 'CZK', |
|
| 90 | - 'DKK', |
|
| 91 | - 'EUR', |
|
| 92 | - 'HKD', |
|
| 93 | - 'HUF', |
|
| 94 | - 'ILS', |
|
| 95 | - 'JPY', |
|
| 96 | - 'MYR', |
|
| 97 | - 'MXN', |
|
| 98 | - 'NOK', |
|
| 99 | - 'NZD', |
|
| 100 | - 'PHP', |
|
| 101 | - 'PLN', |
|
| 102 | - 'GBP', |
|
| 103 | - 'RUB', |
|
| 104 | - 'SGD', |
|
| 105 | - 'SEK', |
|
| 106 | - 'CHF', |
|
| 107 | - 'TWD', |
|
| 108 | - 'THB', |
|
| 109 | - 'TRY', |
|
| 110 | - ); |
|
| 111 | - parent::__construct(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 118 | - * |
|
| 119 | - * @param array $settings_array |
|
| 120 | - */ |
|
| 121 | - public function set_settings($settings_array) |
|
| 122 | - { |
|
| 123 | - parent::set_settings($settings_array); |
|
| 124 | - // Redirect URL. |
|
| 125 | - $this->_base_gateway_url = $this->_debug_mode |
|
| 126 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 127 | - : 'https://api-3t.paypal.com/nvp'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param EEI_Payment $payment |
|
| 134 | - * @param array $billing_info |
|
| 135 | - * @param string $return_url |
|
| 136 | - * @param string $notify_url |
|
| 137 | - * @param string $cancel_url |
|
| 138 | - * @return \EE_Payment|\EEI_Payment |
|
| 139 | - * @throws \EE_Error |
|
| 140 | - */ |
|
| 141 | - public function set_redirection_info( |
|
| 142 | - $payment, |
|
| 143 | - $billing_info = array(), |
|
| 144 | - $return_url = null, |
|
| 145 | - $notify_url = null, |
|
| 146 | - $cancel_url = null |
|
| 147 | - ) { |
|
| 148 | - if (! $payment instanceof EEI_Payment) { |
|
| 149 | - $payment->set_gateway_response( |
|
| 150 | - esc_html__( |
|
| 151 | - 'Error. No associated payment was found.', |
|
| 152 | - 'event_espresso' |
|
| 153 | - ) |
|
| 154 | - ); |
|
| 155 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 156 | - return $payment; |
|
| 157 | - } |
|
| 158 | - $transaction = $payment->transaction(); |
|
| 159 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 160 | - $payment->set_gateway_response( |
|
| 161 | - esc_html__( |
|
| 162 | - 'Could not process this payment because it has no associated transaction.', |
|
| 163 | - 'event_espresso' |
|
| 164 | - ) |
|
| 165 | - ); |
|
| 166 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 167 | - return $payment; |
|
| 168 | - } |
|
| 169 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 170 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 171 | - $primary_registration = $transaction->primary_registration(); |
|
| 172 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 173 | - ? $primary_registration->attendee() |
|
| 174 | - : false; |
|
| 175 | - $locale = explode('-', get_bloginfo('language')); |
|
| 176 | - // Gather request parameters. |
|
| 177 | - $token_request_dtls = array( |
|
| 178 | - 'METHOD' => 'SetExpressCheckout', |
|
| 179 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 180 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 181 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 182 | - 'RETURNURL' => $return_url, |
|
| 183 | - 'CANCELURL' => $cancel_url, |
|
| 184 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 185 | - // Buyer does not need to create a PayPal account to check out. |
|
| 186 | - // This is referred to as PayPal Account Optional. |
|
| 187 | - 'SOLUTIONTYPE' => 'Sole', |
|
| 188 | - //EE will blow up if you change this |
|
| 189 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 190 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 191 | - 'LOCALECODE' => $locale[1] |
|
| 192 | - ); |
|
| 193 | - // Show itemized list. |
|
| 194 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 195 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 196 | - // Automatically filling out shipping and contact information. |
|
| 197 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 198 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 199 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 200 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 202 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 203 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 204 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 205 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 206 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 207 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 208 | - } elseif (! $this->_request_shipping_addr) { |
|
| 209 | - // Do not request shipping details on the PP Checkout page. |
|
| 210 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 211 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 212 | - } |
|
| 213 | - // Used a business/personal logo on the PayPal page. |
|
| 214 | - if (! empty($this->_image_url)) { |
|
| 215 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 216 | - } |
|
| 217 | - $token_request_dtls = apply_filters( |
|
| 218 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 219 | - $token_request_dtls, |
|
| 220 | - $this |
|
| 221 | - ); |
|
| 222 | - // Request PayPal token. |
|
| 223 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 224 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 225 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 226 | - ? $token_rstatus['args'] |
|
| 227 | - : array(); |
|
| 228 | - if ($token_rstatus['status']) { |
|
| 229 | - // We got the Token so we may continue with the payment and redirect the client. |
|
| 230 | - $payment->set_details($response_args); |
|
| 231 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 232 | - $payment->set_redirect_url( |
|
| 233 | - $gateway_url |
|
| 234 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 235 | - . $response_args['TOKEN'] |
|
| 236 | - ); |
|
| 237 | - } else { |
|
| 238 | - if (isset($response_args['L_ERRORCODE'])) { |
|
| 239 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 240 | - } else { |
|
| 241 | - $payment->set_gateway_response( |
|
| 242 | - esc_html__( |
|
| 243 | - 'Error occurred while trying to setup the Express Checkout.', |
|
| 244 | - 'event_espresso' |
|
| 245 | - ) |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - $payment->set_details($response_args); |
|
| 249 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 250 | - } |
|
| 251 | - return $payment; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param array $update_info { |
|
| 258 | - * @type string $gateway_txn_id |
|
| 259 | - * @type string status an EEMI_Payment status |
|
| 260 | - * } |
|
| 261 | - * @param EEI_Transaction $transaction |
|
| 262 | - * @return EEI_Payment |
|
| 263 | - */ |
|
| 264 | - public function handle_payment_update($update_info, $transaction) |
|
| 265 | - { |
|
| 266 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 267 | - if ($payment instanceof EEI_Payment) { |
|
| 268 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 269 | - $transaction = $payment->transaction(); |
|
| 270 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 271 | - $payment->set_gateway_response( |
|
| 272 | - esc_html__( |
|
| 273 | - 'Could not process this payment because it has no associated transaction.', |
|
| 274 | - 'event_espresso' |
|
| 275 | - ) |
|
| 276 | - ); |
|
| 277 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 278 | - return $payment; |
|
| 279 | - } |
|
| 280 | - $primary_registrant = $transaction->primary_registration(); |
|
| 281 | - $payment_details = $payment->details(); |
|
| 282 | - // Check if we still have the token. |
|
| 283 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 284 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 285 | - return $payment; |
|
| 286 | - } |
|
| 287 | - $cdetails_request_dtls = array( |
|
| 288 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 289 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 290 | - ); |
|
| 291 | - // Request Customer Details. |
|
| 292 | - $cdetails_request_response = $this->_ppExpress_request( |
|
| 293 | - $cdetails_request_dtls, |
|
| 294 | - 'Customer Details', |
|
| 295 | - $payment |
|
| 296 | - ); |
|
| 297 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 298 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 299 | - ? $cdetails_rstatus['args'] |
|
| 300 | - : array(); |
|
| 301 | - if ($cdetails_rstatus['status']) { |
|
| 302 | - // We got the PayerID so now we can Complete the transaction. |
|
| 303 | - $docheckout_request_dtls = array( |
|
| 304 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 305 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 306 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 307 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 308 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 309 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 310 | - //EE will blow up if you change this |
|
| 311 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 312 | - ); |
|
| 313 | - // Include itemized list. |
|
| 314 | - $itemized_list = $this->itemize_list( |
|
| 315 | - $payment, |
|
| 316 | - $transaction, |
|
| 317 | - $cdata_response_args |
|
| 318 | - ); |
|
| 319 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 320 | - // Payment Checkout/Capture. |
|
| 321 | - $docheckout_request_response = $this->_ppExpress_request( |
|
| 322 | - $docheckout_request_dtls, |
|
| 323 | - 'Do Payment', |
|
| 324 | - $payment |
|
| 325 | - ); |
|
| 326 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 327 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 328 | - ? $docheckout_rstatus['args'] |
|
| 329 | - : array(); |
|
| 330 | - if ($docheckout_rstatus['status']) { |
|
| 331 | - // All is well, payment approved. |
|
| 332 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 333 | - $primary_registrant->reg_code() |
|
| 334 | - : ''; |
|
| 335 | - $payment->set_extra_accntng($primary_registration_code); |
|
| 336 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 337 | - ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 338 | - : 0); |
|
| 339 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 340 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 341 | - : null); |
|
| 342 | - $payment->set_details($cdata_response_args); |
|
| 343 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 344 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 345 | - : ''); |
|
| 346 | - $payment->set_status($this->_pay_model->approved_status()); |
|
| 347 | - } else { |
|
| 348 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 349 | - $payment->set_gateway_response( |
|
| 350 | - $docheckout_response_args['L_ERRORCODE'] |
|
| 351 | - . '; ' |
|
| 352 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 353 | - ); |
|
| 354 | - } else { |
|
| 355 | - $payment->set_gateway_response( |
|
| 356 | - esc_html__( |
|
| 357 | - 'Error occurred while trying to Capture the funds.', |
|
| 358 | - 'event_espresso' |
|
| 359 | - ) |
|
| 360 | - ); |
|
| 361 | - } |
|
| 362 | - $payment->set_details($docheckout_response_args); |
|
| 363 | - $payment->set_status($this->_pay_model->declined_status()); |
|
| 364 | - } |
|
| 365 | - } else { |
|
| 366 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 367 | - $payment->set_gateway_response( |
|
| 368 | - $cdata_response_args['L_ERRORCODE'] |
|
| 369 | - . '; ' |
|
| 370 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 371 | - ); |
|
| 372 | - } else { |
|
| 373 | - $payment->set_gateway_response( |
|
| 374 | - esc_html__( |
|
| 375 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
| 376 | - 'event_espresso' |
|
| 377 | - ) |
|
| 378 | - ); |
|
| 379 | - } |
|
| 380 | - $payment->set_details($cdata_response_args); |
|
| 381 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 382 | - } |
|
| 383 | - } else { |
|
| 384 | - $payment->set_gateway_response( |
|
| 385 | - esc_html__( |
|
| 386 | - 'Error occurred while trying to process the payment.', |
|
| 387 | - 'event_espresso' |
|
| 388 | - ) |
|
| 389 | - ); |
|
| 390 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 391 | - } |
|
| 392 | - return $payment; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Make a list of items that are in the giver transaction. |
|
| 399 | - * |
|
| 400 | - * @param EEI_Payment $payment |
|
| 401 | - * @param EEI_Transaction $transaction |
|
| 402 | - * @param array $request_response_args Data from a previous communication with PP. |
|
| 403 | - * @return array |
|
| 404 | - */ |
|
| 405 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 406 | - { |
|
| 407 | - $itemized_list = array(); |
|
| 408 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 409 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 410 | - if ( |
|
| 411 | - ! empty($request_response_args) |
|
| 412 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 413 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 414 | - ) { |
|
| 415 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 416 | - if ( |
|
| 417 | - strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 418 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
| 419 | - ) { |
|
| 420 | - $itemized_list[$arg_key] = $arg_val; |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - // If we got only a few Items then something is not right. |
|
| 424 | - if (count($itemized_list) > 2) { |
|
| 425 | - return $itemized_list; |
|
| 426 | - } else { |
|
| 427 | - if (WP_DEBUG) { |
|
| 428 | - throw new EE_Error( |
|
| 429 | - sprintf( |
|
| 430 | - esc_html__( |
|
| 431 | - // @codingStandardsIgnoreStart |
|
| 432 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 433 | - // @codingStandardsIgnoreEnd |
|
| 434 | - 'event_espresso' |
|
| 435 | - ), |
|
| 436 | - wp_json_encode($itemized_list) |
|
| 437 | - ) |
|
| 438 | - ); |
|
| 439 | - } |
|
| 440 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 441 | - $itemized_list = array(); |
|
| 442 | - $this->log( |
|
| 443 | - array( |
|
| 444 | - esc_html__( |
|
| 445 | - 'Could not generate a proper item list with:', |
|
| 446 | - 'event_espresso' |
|
| 447 | - ) => $request_response_args |
|
| 448 | - ), |
|
| 449 | - $payment |
|
| 450 | - ); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - // ...otherwise we generate a new list for this transaction. |
|
| 454 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 455 | - $item_num = 0; |
|
| 456 | - $itemized_sum = 0; |
|
| 457 | - $total_line_items = $transaction->total_line_item(); |
|
| 458 | - // Go through each item in the list. |
|
| 459 | - foreach ($total_line_items->get_items() as $line_item) { |
|
| 460 | - if ($line_item instanceof EE_Line_Item) { |
|
| 461 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 462 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 463 | - continue; |
|
| 464 | - } |
|
| 465 | - $unit_price = $line_item->unit_price(); |
|
| 466 | - $line_item_quantity = $line_item->quantity(); |
|
| 467 | - // This is a discount. |
|
| 468 | - if ($line_item->is_percent()) { |
|
| 469 | - $unit_price = $line_item->total(); |
|
| 470 | - $line_item_quantity = 1; |
|
| 471 | - } |
|
| 472 | - // Item Name. |
|
| 473 | - $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut( |
|
| 474 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 475 | - 0, |
|
| 476 | - 127 |
|
| 477 | - ); |
|
| 478 | - // Item description. |
|
| 479 | - $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut( |
|
| 480 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 481 | - 0, |
|
| 482 | - 127 |
|
| 483 | - ); |
|
| 484 | - // Cost of individual item. |
|
| 485 | - $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency($unit_price); |
|
| 486 | - // Item Number. |
|
| 487 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
| 488 | - // Item quantity. |
|
| 489 | - $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
| 490 | - // Digital item is sold. |
|
| 491 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
| 492 | - $itemized_sum += $line_item->total(); |
|
| 493 | - ++$item_num; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - // Item's sales S/H and tax amount. |
|
| 497 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 498 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 499 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 500 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 501 | - $itemized_sum_diff_from_txn_total = round( |
|
| 502 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 503 | - 2 |
|
| 504 | - ); |
|
| 505 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 506 | - // add the difference as an extra line item. |
|
| 507 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 508 | - // Item Name. |
|
| 509 | - $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut( |
|
| 510 | - esc_html__( |
|
| 511 | - 'Other (promotion/surcharge/cancellation)', |
|
| 512 | - 'event_espresso' |
|
| 513 | - ), |
|
| 514 | - 0, |
|
| 515 | - 127 |
|
| 516 | - ); |
|
| 517 | - // Item description. |
|
| 518 | - $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
| 519 | - // Cost of individual item. |
|
| 520 | - $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency( |
|
| 521 | - $itemized_sum_diff_from_txn_total |
|
| 522 | - ); |
|
| 523 | - // Item Number. |
|
| 524 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
| 525 | - // Item quantity. |
|
| 526 | - $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
| 527 | - // Digital item is sold. |
|
| 528 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
| 529 | - $item_num++; |
|
| 530 | - } |
|
| 531 | - } else { |
|
| 532 | - // Just one Item. |
|
| 533 | - // Item Name. |
|
| 534 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 535 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 536 | - 0, |
|
| 537 | - 127 |
|
| 538 | - ); |
|
| 539 | - // Item description. |
|
| 540 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 541 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 542 | - 0, |
|
| 543 | - 127 |
|
| 544 | - ); |
|
| 545 | - // Cost of individual item. |
|
| 546 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 547 | - // Item Number. |
|
| 548 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 549 | - // Item quantity. |
|
| 550 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 551 | - // Digital item is sold. |
|
| 552 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 553 | - // Item's sales S/H and tax amount. |
|
| 554 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 555 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 556 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 557 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 558 | - } |
|
| 559 | - return $itemized_list; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Make the Express checkout request. |
|
| 566 | - * |
|
| 567 | - * @param array $request_params |
|
| 568 | - * @param string $request_text |
|
| 569 | - * @param EEI_Payment $payment |
|
| 570 | - * @return mixed |
|
| 571 | - */ |
|
| 572 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 573 | - { |
|
| 574 | - $request_dtls = array( |
|
| 575 | - 'VERSION' => '204.0', |
|
| 576 | - 'USER' => urlencode($this->_api_username), |
|
| 577 | - 'PWD' => urlencode($this->_api_password), |
|
| 578 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 579 | - ); |
|
| 580 | - $dtls = array_merge($request_dtls, $request_params); |
|
| 581 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 582 | - // Request Customer Details. |
|
| 583 | - $request_response = wp_remote_post( |
|
| 584 | - $this->_base_gateway_url, |
|
| 585 | - array( |
|
| 586 | - 'method' => 'POST', |
|
| 587 | - 'timeout' => 45, |
|
| 588 | - 'httpversion' => '1.1', |
|
| 589 | - 'cookies' => array(), |
|
| 590 | - 'headers' => array(), |
|
| 591 | - 'body' => http_build_query($dtls, '', '&'), |
|
| 592 | - ) |
|
| 593 | - ); |
|
| 594 | - // Log the response. |
|
| 595 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 596 | - return $request_response; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * Check the response status. |
|
| 603 | - * |
|
| 604 | - * @param mixed $request_response |
|
| 605 | - * @return array |
|
| 606 | - */ |
|
| 607 | - public function _ppExpress_check_response($request_response) |
|
| 608 | - { |
|
| 609 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 610 | - // If we got here then there was an error in this request. |
|
| 611 | - return array('status' => false, 'args' => $request_response); |
|
| 612 | - } |
|
| 613 | - $response_args = array(); |
|
| 614 | - parse_str(urldecode($request_response['body']), $response_args); |
|
| 615 | - if (! isset($response_args['ACK'])) { |
|
| 616 | - return array('status' => false, 'args' => $request_response); |
|
| 617 | - } |
|
| 618 | - if ( |
|
| 619 | - ( |
|
| 620 | - isset($response_args['PAYERID']) |
|
| 621 | - || isset($response_args['TOKEN']) |
|
| 622 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 623 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 624 | - ) |
|
| 625 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 626 | - ) { |
|
| 627 | - // Response status OK, return response parameters for further processing. |
|
| 628 | - return array('status' => true, 'args' => $response_args); |
|
| 629 | - } |
|
| 630 | - $errors = $this->_get_errors($response_args); |
|
| 631 | - return array('status' => false, 'args' => $errors); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Log a "Cleared" request. |
|
| 638 | - * |
|
| 639 | - * @param array $request |
|
| 640 | - * @param EEI_Payment $payment |
|
| 641 | - * @param string $info |
|
| 642 | - * @return void |
|
| 643 | - */ |
|
| 644 | - private function _log_clean_request($request, $payment, $info) |
|
| 645 | - { |
|
| 646 | - $cleaned_request_data = $request; |
|
| 647 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 648 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Get error from the response data. |
|
| 655 | - * |
|
| 656 | - * @param array $data_array |
|
| 657 | - * @return array |
|
| 658 | - */ |
|
| 659 | - private function _get_errors($data_array) |
|
| 660 | - { |
|
| 661 | - $errors = array(); |
|
| 662 | - $n = 0; |
|
| 663 | - while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
| 664 | - $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
| 665 | - ? $data_array["L_ERRORCODE{$n}"] |
|
| 666 | - : ''; |
|
| 667 | - $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
| 668 | - ? $data_array["L_SEVERITYCODE{$n}"] |
|
| 669 | - : ''; |
|
| 670 | - $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
| 671 | - ? $data_array["L_SHORTMESSAGE{$n}"] |
|
| 672 | - : ''; |
|
| 673 | - $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
| 674 | - ? $data_array["L_LONGMESSAGE{$n}"] |
|
| 675 | - : ''; |
|
| 676 | - if ($n === 0) { |
|
| 677 | - $errors = array( |
|
| 678 | - 'L_ERRORCODE' => $l_error_code, |
|
| 679 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
| 680 | - 'L_LONGMESSAGE' => $l_long_message, |
|
| 681 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
| 682 | - ); |
|
| 683 | - } else { |
|
| 684 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 685 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 686 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 687 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 688 | - } |
|
| 689 | - $n++; |
|
| 690 | - } |
|
| 691 | - return $errors; |
|
| 692 | - } |
|
| 35 | + /** |
|
| 36 | + * Merchant API Username. |
|
| 37 | + * |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + protected $_api_username; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Merchant API Password. |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $_api_password; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * API Signature. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + protected $_api_signature; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Request Shipping address on PP checkout page. |
|
| 58 | + * |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + protected $_request_shipping_addr; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Business/personal logo. |
|
| 65 | + * |
|
| 66 | + * @var string |
|
| 67 | + */ |
|
| 68 | + protected $_image_url; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * gateway URL variable |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + protected $_base_gateway_url = ''; |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * EEG_Paypal_Express constructor. |
|
| 81 | + */ |
|
| 82 | + public function __construct() |
|
| 83 | + { |
|
| 84 | + $this->_currencies_supported = array( |
|
| 85 | + 'USD', |
|
| 86 | + 'AUD', |
|
| 87 | + 'BRL', |
|
| 88 | + 'CAD', |
|
| 89 | + 'CZK', |
|
| 90 | + 'DKK', |
|
| 91 | + 'EUR', |
|
| 92 | + 'HKD', |
|
| 93 | + 'HUF', |
|
| 94 | + 'ILS', |
|
| 95 | + 'JPY', |
|
| 96 | + 'MYR', |
|
| 97 | + 'MXN', |
|
| 98 | + 'NOK', |
|
| 99 | + 'NZD', |
|
| 100 | + 'PHP', |
|
| 101 | + 'PLN', |
|
| 102 | + 'GBP', |
|
| 103 | + 'RUB', |
|
| 104 | + 'SGD', |
|
| 105 | + 'SEK', |
|
| 106 | + 'CHF', |
|
| 107 | + 'TWD', |
|
| 108 | + 'THB', |
|
| 109 | + 'TRY', |
|
| 110 | + ); |
|
| 111 | + parent::__construct(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 118 | + * |
|
| 119 | + * @param array $settings_array |
|
| 120 | + */ |
|
| 121 | + public function set_settings($settings_array) |
|
| 122 | + { |
|
| 123 | + parent::set_settings($settings_array); |
|
| 124 | + // Redirect URL. |
|
| 125 | + $this->_base_gateway_url = $this->_debug_mode |
|
| 126 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 127 | + : 'https://api-3t.paypal.com/nvp'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param EEI_Payment $payment |
|
| 134 | + * @param array $billing_info |
|
| 135 | + * @param string $return_url |
|
| 136 | + * @param string $notify_url |
|
| 137 | + * @param string $cancel_url |
|
| 138 | + * @return \EE_Payment|\EEI_Payment |
|
| 139 | + * @throws \EE_Error |
|
| 140 | + */ |
|
| 141 | + public function set_redirection_info( |
|
| 142 | + $payment, |
|
| 143 | + $billing_info = array(), |
|
| 144 | + $return_url = null, |
|
| 145 | + $notify_url = null, |
|
| 146 | + $cancel_url = null |
|
| 147 | + ) { |
|
| 148 | + if (! $payment instanceof EEI_Payment) { |
|
| 149 | + $payment->set_gateway_response( |
|
| 150 | + esc_html__( |
|
| 151 | + 'Error. No associated payment was found.', |
|
| 152 | + 'event_espresso' |
|
| 153 | + ) |
|
| 154 | + ); |
|
| 155 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 156 | + return $payment; |
|
| 157 | + } |
|
| 158 | + $transaction = $payment->transaction(); |
|
| 159 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 160 | + $payment->set_gateway_response( |
|
| 161 | + esc_html__( |
|
| 162 | + 'Could not process this payment because it has no associated transaction.', |
|
| 163 | + 'event_espresso' |
|
| 164 | + ) |
|
| 165 | + ); |
|
| 166 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 167 | + return $payment; |
|
| 168 | + } |
|
| 169 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 170 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 171 | + $primary_registration = $transaction->primary_registration(); |
|
| 172 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 173 | + ? $primary_registration->attendee() |
|
| 174 | + : false; |
|
| 175 | + $locale = explode('-', get_bloginfo('language')); |
|
| 176 | + // Gather request parameters. |
|
| 177 | + $token_request_dtls = array( |
|
| 178 | + 'METHOD' => 'SetExpressCheckout', |
|
| 179 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 180 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 181 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 182 | + 'RETURNURL' => $return_url, |
|
| 183 | + 'CANCELURL' => $cancel_url, |
|
| 184 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 185 | + // Buyer does not need to create a PayPal account to check out. |
|
| 186 | + // This is referred to as PayPal Account Optional. |
|
| 187 | + 'SOLUTIONTYPE' => 'Sole', |
|
| 188 | + //EE will blow up if you change this |
|
| 189 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 190 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 191 | + 'LOCALECODE' => $locale[1] |
|
| 192 | + ); |
|
| 193 | + // Show itemized list. |
|
| 194 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 195 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 196 | + // Automatically filling out shipping and contact information. |
|
| 197 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 198 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 199 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 200 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 202 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 203 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 204 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 205 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 206 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 207 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 208 | + } elseif (! $this->_request_shipping_addr) { |
|
| 209 | + // Do not request shipping details on the PP Checkout page. |
|
| 210 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 211 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 212 | + } |
|
| 213 | + // Used a business/personal logo on the PayPal page. |
|
| 214 | + if (! empty($this->_image_url)) { |
|
| 215 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 216 | + } |
|
| 217 | + $token_request_dtls = apply_filters( |
|
| 218 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 219 | + $token_request_dtls, |
|
| 220 | + $this |
|
| 221 | + ); |
|
| 222 | + // Request PayPal token. |
|
| 223 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 224 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 225 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 226 | + ? $token_rstatus['args'] |
|
| 227 | + : array(); |
|
| 228 | + if ($token_rstatus['status']) { |
|
| 229 | + // We got the Token so we may continue with the payment and redirect the client. |
|
| 230 | + $payment->set_details($response_args); |
|
| 231 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 232 | + $payment->set_redirect_url( |
|
| 233 | + $gateway_url |
|
| 234 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 235 | + . $response_args['TOKEN'] |
|
| 236 | + ); |
|
| 237 | + } else { |
|
| 238 | + if (isset($response_args['L_ERRORCODE'])) { |
|
| 239 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 240 | + } else { |
|
| 241 | + $payment->set_gateway_response( |
|
| 242 | + esc_html__( |
|
| 243 | + 'Error occurred while trying to setup the Express Checkout.', |
|
| 244 | + 'event_espresso' |
|
| 245 | + ) |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + $payment->set_details($response_args); |
|
| 249 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 250 | + } |
|
| 251 | + return $payment; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param array $update_info { |
|
| 258 | + * @type string $gateway_txn_id |
|
| 259 | + * @type string status an EEMI_Payment status |
|
| 260 | + * } |
|
| 261 | + * @param EEI_Transaction $transaction |
|
| 262 | + * @return EEI_Payment |
|
| 263 | + */ |
|
| 264 | + public function handle_payment_update($update_info, $transaction) |
|
| 265 | + { |
|
| 266 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 267 | + if ($payment instanceof EEI_Payment) { |
|
| 268 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 269 | + $transaction = $payment->transaction(); |
|
| 270 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 271 | + $payment->set_gateway_response( |
|
| 272 | + esc_html__( |
|
| 273 | + 'Could not process this payment because it has no associated transaction.', |
|
| 274 | + 'event_espresso' |
|
| 275 | + ) |
|
| 276 | + ); |
|
| 277 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 278 | + return $payment; |
|
| 279 | + } |
|
| 280 | + $primary_registrant = $transaction->primary_registration(); |
|
| 281 | + $payment_details = $payment->details(); |
|
| 282 | + // Check if we still have the token. |
|
| 283 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 284 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 285 | + return $payment; |
|
| 286 | + } |
|
| 287 | + $cdetails_request_dtls = array( |
|
| 288 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 289 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 290 | + ); |
|
| 291 | + // Request Customer Details. |
|
| 292 | + $cdetails_request_response = $this->_ppExpress_request( |
|
| 293 | + $cdetails_request_dtls, |
|
| 294 | + 'Customer Details', |
|
| 295 | + $payment |
|
| 296 | + ); |
|
| 297 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 298 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 299 | + ? $cdetails_rstatus['args'] |
|
| 300 | + : array(); |
|
| 301 | + if ($cdetails_rstatus['status']) { |
|
| 302 | + // We got the PayerID so now we can Complete the transaction. |
|
| 303 | + $docheckout_request_dtls = array( |
|
| 304 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 305 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 306 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 307 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 308 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 309 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 310 | + //EE will blow up if you change this |
|
| 311 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 312 | + ); |
|
| 313 | + // Include itemized list. |
|
| 314 | + $itemized_list = $this->itemize_list( |
|
| 315 | + $payment, |
|
| 316 | + $transaction, |
|
| 317 | + $cdata_response_args |
|
| 318 | + ); |
|
| 319 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 320 | + // Payment Checkout/Capture. |
|
| 321 | + $docheckout_request_response = $this->_ppExpress_request( |
|
| 322 | + $docheckout_request_dtls, |
|
| 323 | + 'Do Payment', |
|
| 324 | + $payment |
|
| 325 | + ); |
|
| 326 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 327 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 328 | + ? $docheckout_rstatus['args'] |
|
| 329 | + : array(); |
|
| 330 | + if ($docheckout_rstatus['status']) { |
|
| 331 | + // All is well, payment approved. |
|
| 332 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 333 | + $primary_registrant->reg_code() |
|
| 334 | + : ''; |
|
| 335 | + $payment->set_extra_accntng($primary_registration_code); |
|
| 336 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 337 | + ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 338 | + : 0); |
|
| 339 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 340 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 341 | + : null); |
|
| 342 | + $payment->set_details($cdata_response_args); |
|
| 343 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 344 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 345 | + : ''); |
|
| 346 | + $payment->set_status($this->_pay_model->approved_status()); |
|
| 347 | + } else { |
|
| 348 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 349 | + $payment->set_gateway_response( |
|
| 350 | + $docheckout_response_args['L_ERRORCODE'] |
|
| 351 | + . '; ' |
|
| 352 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 353 | + ); |
|
| 354 | + } else { |
|
| 355 | + $payment->set_gateway_response( |
|
| 356 | + esc_html__( |
|
| 357 | + 'Error occurred while trying to Capture the funds.', |
|
| 358 | + 'event_espresso' |
|
| 359 | + ) |
|
| 360 | + ); |
|
| 361 | + } |
|
| 362 | + $payment->set_details($docheckout_response_args); |
|
| 363 | + $payment->set_status($this->_pay_model->declined_status()); |
|
| 364 | + } |
|
| 365 | + } else { |
|
| 366 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 367 | + $payment->set_gateway_response( |
|
| 368 | + $cdata_response_args['L_ERRORCODE'] |
|
| 369 | + . '; ' |
|
| 370 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 371 | + ); |
|
| 372 | + } else { |
|
| 373 | + $payment->set_gateway_response( |
|
| 374 | + esc_html__( |
|
| 375 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
| 376 | + 'event_espresso' |
|
| 377 | + ) |
|
| 378 | + ); |
|
| 379 | + } |
|
| 380 | + $payment->set_details($cdata_response_args); |
|
| 381 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 382 | + } |
|
| 383 | + } else { |
|
| 384 | + $payment->set_gateway_response( |
|
| 385 | + esc_html__( |
|
| 386 | + 'Error occurred while trying to process the payment.', |
|
| 387 | + 'event_espresso' |
|
| 388 | + ) |
|
| 389 | + ); |
|
| 390 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 391 | + } |
|
| 392 | + return $payment; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Make a list of items that are in the giver transaction. |
|
| 399 | + * |
|
| 400 | + * @param EEI_Payment $payment |
|
| 401 | + * @param EEI_Transaction $transaction |
|
| 402 | + * @param array $request_response_args Data from a previous communication with PP. |
|
| 403 | + * @return array |
|
| 404 | + */ |
|
| 405 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 406 | + { |
|
| 407 | + $itemized_list = array(); |
|
| 408 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 409 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 410 | + if ( |
|
| 411 | + ! empty($request_response_args) |
|
| 412 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 413 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 414 | + ) { |
|
| 415 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 416 | + if ( |
|
| 417 | + strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 418 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
| 419 | + ) { |
|
| 420 | + $itemized_list[$arg_key] = $arg_val; |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + // If we got only a few Items then something is not right. |
|
| 424 | + if (count($itemized_list) > 2) { |
|
| 425 | + return $itemized_list; |
|
| 426 | + } else { |
|
| 427 | + if (WP_DEBUG) { |
|
| 428 | + throw new EE_Error( |
|
| 429 | + sprintf( |
|
| 430 | + esc_html__( |
|
| 431 | + // @codingStandardsIgnoreStart |
|
| 432 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 433 | + // @codingStandardsIgnoreEnd |
|
| 434 | + 'event_espresso' |
|
| 435 | + ), |
|
| 436 | + wp_json_encode($itemized_list) |
|
| 437 | + ) |
|
| 438 | + ); |
|
| 439 | + } |
|
| 440 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 441 | + $itemized_list = array(); |
|
| 442 | + $this->log( |
|
| 443 | + array( |
|
| 444 | + esc_html__( |
|
| 445 | + 'Could not generate a proper item list with:', |
|
| 446 | + 'event_espresso' |
|
| 447 | + ) => $request_response_args |
|
| 448 | + ), |
|
| 449 | + $payment |
|
| 450 | + ); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + // ...otherwise we generate a new list for this transaction. |
|
| 454 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 455 | + $item_num = 0; |
|
| 456 | + $itemized_sum = 0; |
|
| 457 | + $total_line_items = $transaction->total_line_item(); |
|
| 458 | + // Go through each item in the list. |
|
| 459 | + foreach ($total_line_items->get_items() as $line_item) { |
|
| 460 | + if ($line_item instanceof EE_Line_Item) { |
|
| 461 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 462 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 463 | + continue; |
|
| 464 | + } |
|
| 465 | + $unit_price = $line_item->unit_price(); |
|
| 466 | + $line_item_quantity = $line_item->quantity(); |
|
| 467 | + // This is a discount. |
|
| 468 | + if ($line_item->is_percent()) { |
|
| 469 | + $unit_price = $line_item->total(); |
|
| 470 | + $line_item_quantity = 1; |
|
| 471 | + } |
|
| 472 | + // Item Name. |
|
| 473 | + $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut( |
|
| 474 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 475 | + 0, |
|
| 476 | + 127 |
|
| 477 | + ); |
|
| 478 | + // Item description. |
|
| 479 | + $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = mb_strcut( |
|
| 480 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 481 | + 0, |
|
| 482 | + 127 |
|
| 483 | + ); |
|
| 484 | + // Cost of individual item. |
|
| 485 | + $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency($unit_price); |
|
| 486 | + // Item Number. |
|
| 487 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
| 488 | + // Item quantity. |
|
| 489 | + $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
| 490 | + // Digital item is sold. |
|
| 491 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
| 492 | + $itemized_sum += $line_item->total(); |
|
| 493 | + ++$item_num; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + // Item's sales S/H and tax amount. |
|
| 497 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 498 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 499 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 500 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 501 | + $itemized_sum_diff_from_txn_total = round( |
|
| 502 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 503 | + 2 |
|
| 504 | + ); |
|
| 505 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 506 | + // add the difference as an extra line item. |
|
| 507 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 508 | + // Item Name. |
|
| 509 | + $itemized_list['L_PAYMENTREQUEST_0_NAME' . $item_num] = mb_strcut( |
|
| 510 | + esc_html__( |
|
| 511 | + 'Other (promotion/surcharge/cancellation)', |
|
| 512 | + 'event_espresso' |
|
| 513 | + ), |
|
| 514 | + 0, |
|
| 515 | + 127 |
|
| 516 | + ); |
|
| 517 | + // Item description. |
|
| 518 | + $itemized_list['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
| 519 | + // Cost of individual item. |
|
| 520 | + $itemized_list['L_PAYMENTREQUEST_0_AMT' . $item_num] = $gateway_formatter->formatCurrency( |
|
| 521 | + $itemized_sum_diff_from_txn_total |
|
| 522 | + ); |
|
| 523 | + // Item Number. |
|
| 524 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
| 525 | + // Item quantity. |
|
| 526 | + $itemized_list['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
| 527 | + // Digital item is sold. |
|
| 528 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
| 529 | + $item_num++; |
|
| 530 | + } |
|
| 531 | + } else { |
|
| 532 | + // Just one Item. |
|
| 533 | + // Item Name. |
|
| 534 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 535 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 536 | + 0, |
|
| 537 | + 127 |
|
| 538 | + ); |
|
| 539 | + // Item description. |
|
| 540 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 541 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 542 | + 0, |
|
| 543 | + 127 |
|
| 544 | + ); |
|
| 545 | + // Cost of individual item. |
|
| 546 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 547 | + // Item Number. |
|
| 548 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 549 | + // Item quantity. |
|
| 550 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 551 | + // Digital item is sold. |
|
| 552 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 553 | + // Item's sales S/H and tax amount. |
|
| 554 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 555 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 556 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 557 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 558 | + } |
|
| 559 | + return $itemized_list; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Make the Express checkout request. |
|
| 566 | + * |
|
| 567 | + * @param array $request_params |
|
| 568 | + * @param string $request_text |
|
| 569 | + * @param EEI_Payment $payment |
|
| 570 | + * @return mixed |
|
| 571 | + */ |
|
| 572 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 573 | + { |
|
| 574 | + $request_dtls = array( |
|
| 575 | + 'VERSION' => '204.0', |
|
| 576 | + 'USER' => urlencode($this->_api_username), |
|
| 577 | + 'PWD' => urlencode($this->_api_password), |
|
| 578 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 579 | + ); |
|
| 580 | + $dtls = array_merge($request_dtls, $request_params); |
|
| 581 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 582 | + // Request Customer Details. |
|
| 583 | + $request_response = wp_remote_post( |
|
| 584 | + $this->_base_gateway_url, |
|
| 585 | + array( |
|
| 586 | + 'method' => 'POST', |
|
| 587 | + 'timeout' => 45, |
|
| 588 | + 'httpversion' => '1.1', |
|
| 589 | + 'cookies' => array(), |
|
| 590 | + 'headers' => array(), |
|
| 591 | + 'body' => http_build_query($dtls, '', '&'), |
|
| 592 | + ) |
|
| 593 | + ); |
|
| 594 | + // Log the response. |
|
| 595 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 596 | + return $request_response; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * Check the response status. |
|
| 603 | + * |
|
| 604 | + * @param mixed $request_response |
|
| 605 | + * @return array |
|
| 606 | + */ |
|
| 607 | + public function _ppExpress_check_response($request_response) |
|
| 608 | + { |
|
| 609 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 610 | + // If we got here then there was an error in this request. |
|
| 611 | + return array('status' => false, 'args' => $request_response); |
|
| 612 | + } |
|
| 613 | + $response_args = array(); |
|
| 614 | + parse_str(urldecode($request_response['body']), $response_args); |
|
| 615 | + if (! isset($response_args['ACK'])) { |
|
| 616 | + return array('status' => false, 'args' => $request_response); |
|
| 617 | + } |
|
| 618 | + if ( |
|
| 619 | + ( |
|
| 620 | + isset($response_args['PAYERID']) |
|
| 621 | + || isset($response_args['TOKEN']) |
|
| 622 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 623 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 624 | + ) |
|
| 625 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 626 | + ) { |
|
| 627 | + // Response status OK, return response parameters for further processing. |
|
| 628 | + return array('status' => true, 'args' => $response_args); |
|
| 629 | + } |
|
| 630 | + $errors = $this->_get_errors($response_args); |
|
| 631 | + return array('status' => false, 'args' => $errors); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Log a "Cleared" request. |
|
| 638 | + * |
|
| 639 | + * @param array $request |
|
| 640 | + * @param EEI_Payment $payment |
|
| 641 | + * @param string $info |
|
| 642 | + * @return void |
|
| 643 | + */ |
|
| 644 | + private function _log_clean_request($request, $payment, $info) |
|
| 645 | + { |
|
| 646 | + $cleaned_request_data = $request; |
|
| 647 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 648 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Get error from the response data. |
|
| 655 | + * |
|
| 656 | + * @param array $data_array |
|
| 657 | + * @return array |
|
| 658 | + */ |
|
| 659 | + private function _get_errors($data_array) |
|
| 660 | + { |
|
| 661 | + $errors = array(); |
|
| 662 | + $n = 0; |
|
| 663 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
| 664 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
| 665 | + ? $data_array["L_ERRORCODE{$n}"] |
|
| 666 | + : ''; |
|
| 667 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
| 668 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
| 669 | + : ''; |
|
| 670 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
| 671 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
| 672 | + : ''; |
|
| 673 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
| 674 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
| 675 | + : ''; |
|
| 676 | + if ($n === 0) { |
|
| 677 | + $errors = array( |
|
| 678 | + 'L_ERRORCODE' => $l_error_code, |
|
| 679 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
| 680 | + 'L_LONGMESSAGE' => $l_long_message, |
|
| 681 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
| 682 | + ); |
|
| 683 | + } else { |
|
| 684 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 685 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 686 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 687 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 688 | + } |
|
| 689 | + $n++; |
|
| 690 | + } |
|
| 691 | + return $errors; |
|
| 692 | + } |
|
| 693 | 693 | |
| 694 | 694 | } |
| 695 | 695 | // End of file EEG_Paypal_Express.gateway.php |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function instance() { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) { |
|
| 35 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EEH_Qtip_Loader)) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private function __construct() { |
| 50 | 50 | //let's just make sure this is instantiated in the right place. |
| 51 | - if ( did_action( 'wp_print_styles' ) || did_action( 'admin_head' )) { |
|
| 52 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso' ), '4.1' ); |
|
| 51 | + if (did_action('wp_print_styles') || did_action('admin_head')) { |
|
| 52 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso'), '4.1'); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
@@ -61,25 +61,25 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | public function register_and_enqueue() { |
| 64 | - $qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js'; |
|
| 65 | - $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map'; |
|
| 66 | - $qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css'; |
|
| 64 | + $qtips_js = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js'; |
|
| 65 | + $qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map'; |
|
| 66 | + $qtipcss = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css'; |
|
| 67 | 67 | |
| 68 | - wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE ); |
|
| 69 | - wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE ); |
|
| 70 | - wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 68 | + wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE); |
|
| 69 | + wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', TRUE); |
|
| 70 | + wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS.'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 71 | 71 | |
| 72 | - wp_register_style('qtip-css', $qtipcss, array(), '2.2' ); |
|
| 72 | + wp_register_style('qtip-css', $qtipcss, array(), '2.2'); |
|
| 73 | 73 | |
| 74 | 74 | //k now let's see if there are any registered qtips. If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!) |
| 75 | - if ( !empty( $this->_qtips ) ) { |
|
| 75 | + if ( ! empty($this->_qtips)) { |
|
| 76 | 76 | wp_enqueue_script('ee-qtip-helper'); |
| 77 | 77 | wp_enqueue_style('qtip-css'); |
| 78 | 78 | $qtips = array(); |
| 79 | - foreach ( $this->_qtips as $qtip ) { |
|
| 79 | + foreach ($this->_qtips as $qtip) { |
|
| 80 | 80 | $qts = $qtip->get_tips(); |
| 81 | - foreach ( $qts as $qt ) { |
|
| 82 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 81 | + foreach ($qts as $qt) { |
|
| 82 | + if ( ! $qt instanceof EE_Qtip) |
|
| 83 | 83 | continue; |
| 84 | 84 | $qtips[] = array( |
| 85 | 85 | 'content_id' => $qt->content_id, |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | - if ( !empty($qtips) ) |
|
| 92 | - wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ) ); |
|
| 91 | + if ( ! empty($qtips)) |
|
| 92 | + wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips)); |
|
| 93 | 93 | |
| 94 | 94 | } else { |
| 95 | 95 | //qtips has been requested without any registration (so assuming its just directly used in the admin). |
@@ -111,24 +111,24 @@ discard block |
||
| 111 | 111 | * @param string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips] |
| 112 | 112 | * @return void |
| 113 | 113 | */ |
| 114 | - public function register( $configname, $paths = array() ) { |
|
| 114 | + public function register($configname, $paths = array()) { |
|
| 115 | 115 | |
| 116 | 116 | //let's just make sure this is instantiated in the right place. |
| 117 | - if ( did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts') ) { |
|
| 118 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso' ), '4.1' ); |
|
| 117 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 118 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso'), '4.1'); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $configname = (array) $configname; //typecast to array |
| 122 | - foreach ( $configname as $config ) { |
|
| 123 | - $this->_register( $config, $paths ); |
|
| 122 | + foreach ($configname as $config) { |
|
| 123 | + $this->_register($config, $paths); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | //hook into appropriate footer |
| 127 | 127 | $footer_action = is_admin() ? 'admin_footer' : 'wp_footer'; |
| 128 | - add_action($footer_action, array($this, 'setup_qtip'), 10 ); |
|
| 128 | + add_action($footer_action, array($this, 'setup_qtip'), 10); |
|
| 129 | 129 | |
| 130 | 130 | //make sure we "turn on" qtip js. |
| 131 | - add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 131 | + add_filter('FHEE_load_qtip', '__return_true'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | * @throws EE_Error |
| 143 | 143 | * @return void |
| 144 | 144 | */ |
| 145 | - private function _register( $config, $paths ) { |
|
| 145 | + private function _register($config, $paths) { |
|
| 146 | 146 | //before doing anything we have to make sure that EE_Qtip_Config parent is required. |
| 147 | - EE_Registry::instance()->load_lib( 'Qtip_Config', array(), TRUE ); |
|
| 147 | + EE_Registry::instance()->load_lib('Qtip_Config', array(), TRUE); |
|
| 148 | 148 | |
| 149 | - if ( !empty( $paths ) ) { |
|
| 149 | + if ( ! empty($paths)) { |
|
| 150 | 150 | $paths = (array) $paths; |
| 151 | - foreach ( $paths as $path ) { |
|
| 152 | - $path = $path . $config . '.lib.php'; |
|
| 153 | - if ( !is_readable($path ) ) { |
|
| 151 | + foreach ($paths as $path) { |
|
| 152 | + $path = $path.$config.'.lib.php'; |
|
| 153 | + if ( ! is_readable($path)) { |
|
| 154 | 154 | continue; |
| 155 | 155 | } else { |
| 156 | 156 | require_once $path; |
@@ -159,26 +159,26 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | //does class exist at this point? If it does then let's instantiate. If it doesn't then let's continue with other paths. |
| 162 | - if ( !class_exists($config) ) { |
|
| 163 | - $path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php'; |
|
| 164 | - if ( !is_readable($path ) ) { |
|
| 165 | - throw new EE_Error( sprintf( __('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config ) ); |
|
| 162 | + if ( ! class_exists($config)) { |
|
| 163 | + $path = EE_LIBRARIES.'qtips/'.$config.'.lib.php'; |
|
| 164 | + if ( ! is_readable($path)) { |
|
| 165 | + throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config)); |
|
| 166 | 166 | } else { |
| 167 | 167 | require_once $path; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | //now we attempt a class_exists one more time. |
| 172 | - if ( !class_exists( $config ) ) |
|
| 173 | - throw new EE_Error( sprintf( __('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config ) ); |
|
| 172 | + if ( ! class_exists($config)) |
|
| 173 | + throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config)); |
|
| 174 | 174 | |
| 175 | 175 | //made it HERE? FINALLY, let's get things setup. |
| 176 | 176 | $a = new ReflectionClass($config); |
| 177 | 177 | $qtip = $a->newInstance(); |
| 178 | 178 | |
| 179 | 179 | //verify that $qtip is a valid object |
| 180 | - if ( ! $qtip instanceof EE_Qtip_Config ) |
|
| 181 | - throw new EE_Error( sprintf( esc_html__( 'The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>' ) ); |
|
| 180 | + if ( ! $qtip instanceof EE_Qtip_Config) |
|
| 181 | + throw new EE_Error(sprintf(esc_html__('The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config, '<strong>', '</strong>')); |
|
| 182 | 182 | |
| 183 | 183 | $this->_qtips[] = $a->newInstance(); |
| 184 | 184 | |
@@ -194,12 +194,12 @@ discard block |
||
| 194 | 194 | * @return void |
| 195 | 195 | */ |
| 196 | 196 | public function setup_qtip() { |
| 197 | - if ( empty( $this->_qtips ) ) |
|
| 197 | + if (empty($this->_qtips)) |
|
| 198 | 198 | return; //no qtips! |
| 199 | 199 | |
| 200 | 200 | $content = array(); |
| 201 | 201 | |
| 202 | - foreach ( $this->_qtips as $qtip ) { |
|
| 202 | + foreach ($this->_qtips as $qtip) { |
|
| 203 | 203 | $content[] = $this->_generate_content_container($qtip); |
| 204 | 204 | } |
| 205 | 205 | |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | private function _generate_content_container($qtip) { |
| 217 | 217 | $qts = $qtip->get_tips(); |
| 218 | 218 | $content = array(); |
| 219 | - foreach ( $qts as $qt ) { |
|
| 220 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 219 | + foreach ($qts as $qt) { |
|
| 220 | + if ( ! $qt instanceof EE_Qtip) |
|
| 221 | 221 | continue; |
| 222 | - $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>'; |
|
| 222 | + $content[] = '<div class="ee-qtip-helper-content hidden" id="'.$qt->content_id.'">'.$qt->content.'</div>'; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | return implode('<br />', $content); |
@@ -19,126 +19,126 @@ |
||
| 19 | 19 | abstract class DomainBase implements DomainInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | - * |
|
| 25 | - * @var FilePath |
|
| 26 | - */ |
|
| 27 | - private $plugin_file; |
|
| 22 | + /** |
|
| 23 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | + * |
|
| 25 | + * @var FilePath |
|
| 26 | + */ |
|
| 27 | + private $plugin_file; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * String indicating version for plugin |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private $version; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string $plugin_basename |
|
| 38 | - */ |
|
| 39 | - private $plugin_basename; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string $plugin_path |
|
| 43 | - */ |
|
| 44 | - private $plugin_path; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $plugin_url |
|
| 48 | - */ |
|
| 49 | - private $plugin_url; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Initializes internal properties. |
|
| 55 | - * |
|
| 56 | - * @param FilePath $plugin_file |
|
| 57 | - * @param Version $version |
|
| 58 | - */ |
|
| 59 | - public function __construct(FilePath $plugin_file, Version $version) |
|
| 60 | - { |
|
| 61 | - $this->plugin_file = $plugin_file; |
|
| 62 | - $this->version = $version; |
|
| 63 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 64 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 65 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function pluginFile() |
|
| 73 | - { |
|
| 74 | - return (string) $this->plugin_file; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function pluginBasename() |
|
| 83 | - { |
|
| 84 | - return $this->plugin_basename; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function pluginPath() |
|
| 93 | - { |
|
| 94 | - return $this->plugin_path; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function pluginUrl() |
|
| 103 | - { |
|
| 104 | - return $this->plugin_url; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function version() |
|
| 113 | - { |
|
| 114 | - return (string) $this->version; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return Version |
|
| 121 | - */ |
|
| 122 | - public function versionValueObject() |
|
| 123 | - { |
|
| 124 | - return $this->version; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function distributionAssetsPath() |
|
| 132 | - { |
|
| 133 | - return $this->pluginPath() . 'assets/dist/'; |
|
| 134 | - } |
|
| 29 | + /** |
|
| 30 | + * String indicating version for plugin |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private $version; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string $plugin_basename |
|
| 38 | + */ |
|
| 39 | + private $plugin_basename; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string $plugin_path |
|
| 43 | + */ |
|
| 44 | + private $plugin_path; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $plugin_url |
|
| 48 | + */ |
|
| 49 | + private $plugin_url; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Initializes internal properties. |
|
| 55 | + * |
|
| 56 | + * @param FilePath $plugin_file |
|
| 57 | + * @param Version $version |
|
| 58 | + */ |
|
| 59 | + public function __construct(FilePath $plugin_file, Version $version) |
|
| 60 | + { |
|
| 61 | + $this->plugin_file = $plugin_file; |
|
| 62 | + $this->version = $version; |
|
| 63 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 64 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 65 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function pluginFile() |
|
| 73 | + { |
|
| 74 | + return (string) $this->plugin_file; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function pluginBasename() |
|
| 83 | + { |
|
| 84 | + return $this->plugin_basename; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function pluginPath() |
|
| 93 | + { |
|
| 94 | + return $this->plugin_path; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function pluginUrl() |
|
| 103 | + { |
|
| 104 | + return $this->plugin_url; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function version() |
|
| 113 | + { |
|
| 114 | + return (string) $this->version; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return Version |
|
| 121 | + */ |
|
| 122 | + public function versionValueObject() |
|
| 123 | + { |
|
| 124 | + return $this->version; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function distributionAssetsPath() |
|
| 132 | + { |
|
| 133 | + return $this->pluginPath() . 'assets/dist/'; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function distributionAssetsUrl() |
|
| 141 | - { |
|
| 142 | - return $this->pluginUrl() . 'assets/dist/'; |
|
| 143 | - } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function distributionAssetsUrl() |
|
| 141 | + { |
|
| 142 | + return $this->pluginUrl() . 'assets/dist/'; |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function distributionAssetsPath() |
| 132 | 132 | { |
| 133 | - return $this->pluginPath() . 'assets/dist/'; |
|
| 133 | + return $this->pluginPath().'assets/dist/'; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -139,6 +139,6 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function distributionAssetsUrl() |
| 141 | 141 | { |
| 142 | - return $this->pluginUrl() . 'assets/dist/'; |
|
| 142 | + return $this->pluginUrl().'assets/dist/'; |
|
| 143 | 143 | } |
| 144 | 144 | } |