@@ -13,160 +13,160 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var SessionLifespan $session_lifespan |
|
| 18 | - */ |
|
| 19 | - private $session_lifespan; |
|
| 20 | - |
|
| 21 | - private $_status; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @param Transactions_Admin_Page $admin_page |
|
| 26 | - * @param SessionLifespan $lifespan |
|
| 27 | - */ |
|
| 28 | - public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
| 29 | - { |
|
| 30 | - parent::__construct($admin_page); |
|
| 31 | - $this->session_lifespan = $lifespan; |
|
| 32 | - $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - *_setup_data |
|
| 38 | - */ |
|
| 39 | - protected function _setup_data() |
|
| 40 | - { |
|
| 41 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
| 42 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
| 43 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - *_set_properties |
|
| 49 | - */ |
|
| 50 | - protected function _set_properties() |
|
| 51 | - { |
|
| 52 | - $this->_wp_list_args = array( |
|
| 53 | - 'singular' => esc_html__('transaction', 'event_espresso'), |
|
| 54 | - 'plural' => esc_html__('transactions', 'event_espresso'), |
|
| 55 | - 'ajax' => true, |
|
| 56 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 57 | - ); |
|
| 58 | - $ID_column_name = esc_html__('ID', 'event_espresso'); |
|
| 59 | - $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">'; |
|
| 60 | - $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso'); |
|
| 61 | - $ID_column_name .= '</span> '; |
|
| 62 | - $this->_columns = array( |
|
| 63 | - 'id' => $ID_column_name, |
|
| 64 | - 'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'), |
|
| 65 | - 'event_name' => esc_html__('Event', 'event_espresso'), |
|
| 66 | - 'ATT_fname' => esc_html__('Primary Registrant', 'event_espresso'), |
|
| 67 | - 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
| 68 | - 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
| 69 | - 'actions' => $this->actionsColumnHeader(), |
|
| 70 | - ); |
|
| 71 | - |
|
| 72 | - $this->_sortable_columns = array( |
|
| 73 | - 'id' => array('TXN_ID' => false), |
|
| 74 | - 'event_name' => array('event_name' => false), |
|
| 75 | - 'ATT_fname' => array('ATT_fname' => false), |
|
| 76 | - 'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - $this->_primary_column = 'TXN_ID'; |
|
| 80 | - |
|
| 81 | - $this->_hidden_columns = array(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * This simply sets up the row class for the table rows. |
|
| 87 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 88 | - * |
|
| 89 | - * @param EE_Transaction $transaction the current item |
|
| 90 | - * @return string |
|
| 91 | - * @throws EE_Error |
|
| 92 | - * @throws ReflectionException |
|
| 93 | - */ |
|
| 94 | - protected function _get_row_class($transaction) |
|
| 95 | - { |
|
| 96 | - $class = parent::_get_row_class($transaction); |
|
| 97 | - // add status class |
|
| 98 | - $class .= ' txn-status-' . $transaction->status_ID(); |
|
| 99 | - if ($this->_has_checkbox_column) { |
|
| 100 | - $class .= ' has-checkbox-column'; |
|
| 101 | - } |
|
| 102 | - return $class; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * _get_table_filters |
|
| 108 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 109 | - * gets shown in the table. |
|
| 110 | - * |
|
| 111 | - * @abstract |
|
| 112 | - * @return array |
|
| 113 | - */ |
|
| 114 | - protected function _get_table_filters() |
|
| 115 | - { |
|
| 116 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 117 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 118 | - : date('Y-m-d', strtotime('-10 year')); |
|
| 119 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 120 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 121 | - : date('Y-m-d', current_time('timestamp')); |
|
| 122 | - |
|
| 123 | - return [ |
|
| 124 | - EEH_Form_Fields::text( |
|
| 125 | - esc_html__('Display Transactions from', 'event_espresso'), |
|
| 126 | - esc_html($start_date), |
|
| 127 | - 'txn-filter-start-date', |
|
| 128 | - 'txn-filter-start-date', |
|
| 129 | - 'ee-datepicker' |
|
| 130 | - ), |
|
| 131 | - EEH_Form_Fields::text( |
|
| 132 | - esc_html__(' until ', 'event_espresso'), |
|
| 133 | - esc_html($end_date), |
|
| 134 | - 'txn-filter-end-date', |
|
| 135 | - 'txn-filter-end-date', |
|
| 136 | - 'ee-datepicker' |
|
| 137 | - ) |
|
| 138 | - ]; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - *_add_view_counts |
|
| 144 | - */ |
|
| 145 | - protected function _add_view_counts() |
|
| 146 | - { |
|
| 147 | - foreach ($this->_views as $view) { |
|
| 148 | - $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * column TXN_ID |
|
| 155 | - * |
|
| 156 | - * @param EE_Transaction $transaction |
|
| 157 | - * @return string |
|
| 158 | - * @throws EE_Error |
|
| 159 | - */ |
|
| 160 | - public function column_id(EE_Transaction $transaction) |
|
| 161 | - { |
|
| 162 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 163 | - array( |
|
| 164 | - 'action' => 'view_transaction', |
|
| 165 | - 'TXN_ID' => $transaction->ID(), |
|
| 166 | - ), |
|
| 167 | - TXN_ADMIN_URL |
|
| 168 | - ); |
|
| 169 | - $content = ' |
|
| 16 | + /** |
|
| 17 | + * @var SessionLifespan $session_lifespan |
|
| 18 | + */ |
|
| 19 | + private $session_lifespan; |
|
| 20 | + |
|
| 21 | + private $_status; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param Transactions_Admin_Page $admin_page |
|
| 26 | + * @param SessionLifespan $lifespan |
|
| 27 | + */ |
|
| 28 | + public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
| 29 | + { |
|
| 30 | + parent::__construct($admin_page); |
|
| 31 | + $this->session_lifespan = $lifespan; |
|
| 32 | + $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + *_setup_data |
|
| 38 | + */ |
|
| 39 | + protected function _setup_data() |
|
| 40 | + { |
|
| 41 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
| 42 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
| 43 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + *_set_properties |
|
| 49 | + */ |
|
| 50 | + protected function _set_properties() |
|
| 51 | + { |
|
| 52 | + $this->_wp_list_args = array( |
|
| 53 | + 'singular' => esc_html__('transaction', 'event_espresso'), |
|
| 54 | + 'plural' => esc_html__('transactions', 'event_espresso'), |
|
| 55 | + 'ajax' => true, |
|
| 56 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 57 | + ); |
|
| 58 | + $ID_column_name = esc_html__('ID', 'event_espresso'); |
|
| 59 | + $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">'; |
|
| 60 | + $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso'); |
|
| 61 | + $ID_column_name .= '</span> '; |
|
| 62 | + $this->_columns = array( |
|
| 63 | + 'id' => $ID_column_name, |
|
| 64 | + 'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'), |
|
| 65 | + 'event_name' => esc_html__('Event', 'event_espresso'), |
|
| 66 | + 'ATT_fname' => esc_html__('Primary Registrant', 'event_espresso'), |
|
| 67 | + 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
| 68 | + 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
| 69 | + 'actions' => $this->actionsColumnHeader(), |
|
| 70 | + ); |
|
| 71 | + |
|
| 72 | + $this->_sortable_columns = array( |
|
| 73 | + 'id' => array('TXN_ID' => false), |
|
| 74 | + 'event_name' => array('event_name' => false), |
|
| 75 | + 'ATT_fname' => array('ATT_fname' => false), |
|
| 76 | + 'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + $this->_primary_column = 'TXN_ID'; |
|
| 80 | + |
|
| 81 | + $this->_hidden_columns = array(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * This simply sets up the row class for the table rows. |
|
| 87 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 88 | + * |
|
| 89 | + * @param EE_Transaction $transaction the current item |
|
| 90 | + * @return string |
|
| 91 | + * @throws EE_Error |
|
| 92 | + * @throws ReflectionException |
|
| 93 | + */ |
|
| 94 | + protected function _get_row_class($transaction) |
|
| 95 | + { |
|
| 96 | + $class = parent::_get_row_class($transaction); |
|
| 97 | + // add status class |
|
| 98 | + $class .= ' txn-status-' . $transaction->status_ID(); |
|
| 99 | + if ($this->_has_checkbox_column) { |
|
| 100 | + $class .= ' has-checkbox-column'; |
|
| 101 | + } |
|
| 102 | + return $class; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * _get_table_filters |
|
| 108 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 109 | + * gets shown in the table. |
|
| 110 | + * |
|
| 111 | + * @abstract |
|
| 112 | + * @return array |
|
| 113 | + */ |
|
| 114 | + protected function _get_table_filters() |
|
| 115 | + { |
|
| 116 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 117 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 118 | + : date('Y-m-d', strtotime('-10 year')); |
|
| 119 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 120 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 121 | + : date('Y-m-d', current_time('timestamp')); |
|
| 122 | + |
|
| 123 | + return [ |
|
| 124 | + EEH_Form_Fields::text( |
|
| 125 | + esc_html__('Display Transactions from', 'event_espresso'), |
|
| 126 | + esc_html($start_date), |
|
| 127 | + 'txn-filter-start-date', |
|
| 128 | + 'txn-filter-start-date', |
|
| 129 | + 'ee-datepicker' |
|
| 130 | + ), |
|
| 131 | + EEH_Form_Fields::text( |
|
| 132 | + esc_html__(' until ', 'event_espresso'), |
|
| 133 | + esc_html($end_date), |
|
| 134 | + 'txn-filter-end-date', |
|
| 135 | + 'txn-filter-end-date', |
|
| 136 | + 'ee-datepicker' |
|
| 137 | + ) |
|
| 138 | + ]; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + *_add_view_counts |
|
| 144 | + */ |
|
| 145 | + protected function _add_view_counts() |
|
| 146 | + { |
|
| 147 | + foreach ($this->_views as $view) { |
|
| 148 | + $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * column TXN_ID |
|
| 155 | + * |
|
| 156 | + * @param EE_Transaction $transaction |
|
| 157 | + * @return string |
|
| 158 | + * @throws EE_Error |
|
| 159 | + */ |
|
| 160 | + public function column_id(EE_Transaction $transaction) |
|
| 161 | + { |
|
| 162 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 163 | + array( |
|
| 164 | + 'action' => 'view_transaction', |
|
| 165 | + 'TXN_ID' => $transaction->ID(), |
|
| 166 | + ), |
|
| 167 | + TXN_ADMIN_URL |
|
| 168 | + ); |
|
| 169 | + $content = ' |
|
| 170 | 170 | <span class="ee-entity-id"> |
| 171 | 171 | <a class="ee-aria-tooltip" |
| 172 | 172 | href="' . $view_lnk_url . '" |
@@ -175,539 +175,539 @@ discard block |
||
| 175 | 175 | ' . $transaction->ID() . ' |
| 176 | 176 | </a> |
| 177 | 177 | </span>'; |
| 178 | - // txn timestamp |
|
| 179 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
| 180 | - return $this->columnContent('id', $content, 'end'); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param EE_Transaction $transaction |
|
| 186 | - * @return string |
|
| 187 | - * @throws EE_Error |
|
| 188 | - * @throws InvalidArgumentException |
|
| 189 | - * @throws InvalidDataTypeException |
|
| 190 | - * @throws InvalidInterfaceException |
|
| 191 | - */ |
|
| 192 | - protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
| 193 | - { |
|
| 194 | - // is TXN less than 2 hours old ? |
|
| 195 | - if ( |
|
| 196 | - ($transaction->failed() || $transaction->is_abandoned()) |
|
| 197 | - && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
| 198 | - ) { |
|
| 199 | - $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
| 200 | - } else { |
|
| 201 | - $timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a'); |
|
| 202 | - } |
|
| 203 | - return $timestamp; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * column_cb |
|
| 209 | - * |
|
| 210 | - * @param EE_Transaction $transaction |
|
| 211 | - * @return string |
|
| 212 | - * @throws EE_Error |
|
| 213 | - */ |
|
| 214 | - public function column_cb($transaction) |
|
| 215 | - { |
|
| 216 | - return sprintf( |
|
| 217 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
| 218 | - $this->_wp_list_args['singular'], |
|
| 219 | - $transaction->ID() |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * column_TXN_timestamp |
|
| 226 | - * |
|
| 227 | - * @param EE_Transaction $transaction |
|
| 228 | - * @return string |
|
| 229 | - * @throws EE_Error |
|
| 230 | - * @throws ReflectionException |
|
| 231 | - */ |
|
| 232 | - public function column_TXN_timestamp(EE_Transaction $transaction) |
|
| 233 | - { |
|
| 234 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 235 | - array( |
|
| 236 | - 'action' => 'view_transaction', |
|
| 237 | - 'TXN_ID' => $transaction->ID(), |
|
| 238 | - ), |
|
| 239 | - TXN_ADMIN_URL |
|
| 240 | - ); |
|
| 241 | - $status = esc_attr($transaction->status_ID()); |
|
| 242 | - $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
|
| 243 | - return ' |
|
| 178 | + // txn timestamp |
|
| 179 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
| 180 | + return $this->columnContent('id', $content, 'end'); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param EE_Transaction $transaction |
|
| 186 | + * @return string |
|
| 187 | + * @throws EE_Error |
|
| 188 | + * @throws InvalidArgumentException |
|
| 189 | + * @throws InvalidDataTypeException |
|
| 190 | + * @throws InvalidInterfaceException |
|
| 191 | + */ |
|
| 192 | + protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
| 193 | + { |
|
| 194 | + // is TXN less than 2 hours old ? |
|
| 195 | + if ( |
|
| 196 | + ($transaction->failed() || $transaction->is_abandoned()) |
|
| 197 | + && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
| 198 | + ) { |
|
| 199 | + $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
| 200 | + } else { |
|
| 201 | + $timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a'); |
|
| 202 | + } |
|
| 203 | + return $timestamp; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * column_cb |
|
| 209 | + * |
|
| 210 | + * @param EE_Transaction $transaction |
|
| 211 | + * @return string |
|
| 212 | + * @throws EE_Error |
|
| 213 | + */ |
|
| 214 | + public function column_cb($transaction) |
|
| 215 | + { |
|
| 216 | + return sprintf( |
|
| 217 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
| 218 | + $this->_wp_list_args['singular'], |
|
| 219 | + $transaction->ID() |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * column_TXN_timestamp |
|
| 226 | + * |
|
| 227 | + * @param EE_Transaction $transaction |
|
| 228 | + * @return string |
|
| 229 | + * @throws EE_Error |
|
| 230 | + * @throws ReflectionException |
|
| 231 | + */ |
|
| 232 | + public function column_TXN_timestamp(EE_Transaction $transaction) |
|
| 233 | + { |
|
| 234 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 235 | + array( |
|
| 236 | + 'action' => 'view_transaction', |
|
| 237 | + 'TXN_ID' => $transaction->ID(), |
|
| 238 | + ), |
|
| 239 | + TXN_ADMIN_URL |
|
| 240 | + ); |
|
| 241 | + $status = esc_attr($transaction->status_ID()); |
|
| 242 | + $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
|
| 243 | + return ' |
|
| 244 | 244 | <div class="ee-layout-row"> |
| 245 | 245 | <span aria-label="' . $pretty_status . '" class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"></span> |
| 246 | 246 | <a href="' . $view_lnk_url . '" |
| 247 | 247 | class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" |
| 248 | 248 | aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID( |
| 249 | - ) . '"> |
|
| 249 | + ) . '"> |
|
| 250 | 250 | ' . $this->_get_txn_timestamp($transaction) . ' |
| 251 | 251 | </a> |
| 252 | 252 | </div>'; |
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * column_TXN_total |
|
| 258 | - * |
|
| 259 | - * @param EE_Transaction $transaction |
|
| 260 | - * @return string |
|
| 261 | - * @throws EE_Error |
|
| 262 | - */ |
|
| 263 | - public function column_TXN_total(EE_Transaction $transaction) |
|
| 264 | - { |
|
| 265 | - if ($transaction->get('TXN_total') > 0) { |
|
| 266 | - return '<span class="txn-pad-rght">' |
|
| 267 | - . apply_filters( |
|
| 268 | - 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
| 269 | - $transaction->get_pretty('TXN_total'), |
|
| 270 | - $transaction |
|
| 271 | - ) |
|
| 272 | - . '</span>'; |
|
| 273 | - } else { |
|
| 274 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * column_TXN_paid |
|
| 281 | - * |
|
| 282 | - * @param EE_Transaction $transaction |
|
| 283 | - * @return mixed|string |
|
| 284 | - * @throws EE_Error |
|
| 285 | - */ |
|
| 286 | - public function column_TXN_paid(EE_Transaction $transaction) |
|
| 287 | - { |
|
| 288 | - $transaction_total = $transaction->get('TXN_total'); |
|
| 289 | - $transaction_paid = $transaction->get('TXN_paid'); |
|
| 290 | - |
|
| 291 | - if (EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
| 292 | - // monies owing |
|
| 293 | - $span_class = 'txn-overview-part-payment-spn'; |
|
| 294 | - if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
| 295 | - // paid in full |
|
| 296 | - $span_class = 'txn-overview-full-payment-spn'; |
|
| 297 | - } elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
| 298 | - // no payments made |
|
| 299 | - $span_class = 'txn-overview-no-payment-spn'; |
|
| 300 | - } |
|
| 301 | - } else { |
|
| 302 | - // transaction_total == 0 so this is a free event |
|
| 303 | - $span_class = 'txn-overview-free-event-spn'; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $payment_method = $transaction->payment_method(); |
|
| 307 | - $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
| 308 | - ? $payment_method->admin_name() |
|
| 309 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 310 | - |
|
| 311 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
| 312 | - . $transaction->get_pretty('TXN_paid') |
|
| 313 | - . '</span>'; |
|
| 314 | - if ($transaction_paid > 0) { |
|
| 315 | - $content .= ' <span class="ee-status-text-small">' |
|
| 316 | - . sprintf( |
|
| 317 | - esc_html__('...via %s', 'event_espresso'), |
|
| 318 | - $payment_method_name |
|
| 319 | - ) |
|
| 320 | - . '</span>'; |
|
| 321 | - } |
|
| 322 | - return "<div>{$content}</div>"; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * column_ATT_fname |
|
| 328 | - * |
|
| 329 | - * @param EE_Transaction $transaction |
|
| 330 | - * @return string |
|
| 331 | - * @throws EE_Error |
|
| 332 | - * @throws InvalidArgumentException |
|
| 333 | - * @throws InvalidDataTypeException |
|
| 334 | - * @throws InvalidInterfaceException |
|
| 335 | - */ |
|
| 336 | - public function column_ATT_fname(EE_Transaction $transaction) |
|
| 337 | - { |
|
| 338 | - $primary_reg = $transaction->primary_registration(); |
|
| 339 | - $attendee = $primary_reg->attendee(); |
|
| 340 | - if ($attendee instanceof EE_Attendee) { |
|
| 341 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 342 | - array( |
|
| 343 | - 'action' => 'view_registration', |
|
| 344 | - '_REG_ID' => $primary_reg->ID(), |
|
| 345 | - ), |
|
| 346 | - REG_ADMIN_URL |
|
| 347 | - ); |
|
| 348 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 349 | - 'ee_read_registration', |
|
| 350 | - 'espresso_registrations_view_registration', |
|
| 351 | - $primary_reg->ID() |
|
| 352 | - ) |
|
| 353 | - ? '<a href="' . $edit_lnk_url . '"' |
|
| 354 | - . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
| 355 | - . $attendee->full_name() |
|
| 356 | - . '</a>' |
|
| 357 | - : $attendee->full_name(); |
|
| 358 | - $content .= '<br>' . $attendee->email(); |
|
| 359 | - return $content; |
|
| 360 | - } |
|
| 361 | - return $transaction->failed() || $transaction->is_abandoned() |
|
| 362 | - ? esc_html__('no contact record.', 'event_espresso') |
|
| 363 | - : esc_html__( |
|
| 364 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 365 | - 'event_espresso' |
|
| 366 | - ); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * column_ATT_email |
|
| 372 | - * |
|
| 373 | - * @param EE_Transaction $transaction |
|
| 374 | - * @return string |
|
| 375 | - * @throws EE_Error |
|
| 376 | - */ |
|
| 377 | - public function column_ATT_email(EE_Transaction $transaction) |
|
| 378 | - { |
|
| 379 | - $attendee = $transaction->primary_registration()->attendee(); |
|
| 380 | - if (! empty($attendee)) { |
|
| 381 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
| 382 | - . $attendee->get('ATT_email') |
|
| 383 | - . '</a>'; |
|
| 384 | - } else { |
|
| 385 | - return $transaction->failed() || $transaction->is_abandoned() |
|
| 386 | - ? esc_html__('no contact record.', 'event_espresso') |
|
| 387 | - : esc_html__( |
|
| 388 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 389 | - 'event_espresso' |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * column_event_name |
|
| 397 | - * |
|
| 398 | - * @param EE_Transaction $transaction |
|
| 399 | - * @return string |
|
| 400 | - * @throws EE_Error |
|
| 401 | - * @throws InvalidArgumentException |
|
| 402 | - * @throws InvalidDataTypeException |
|
| 403 | - * @throws InvalidInterfaceException |
|
| 404 | - */ |
|
| 405 | - public function column_event_name(EE_Transaction $transaction) |
|
| 406 | - { |
|
| 407 | - $actions = array(); |
|
| 408 | - $event = $transaction->primary_registration()->event(); |
|
| 409 | - if (! empty($event)) { |
|
| 410 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 411 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 412 | - EVENTS_ADMIN_URL |
|
| 413 | - ); |
|
| 414 | - $event_name = $event->get('EVT_name'); |
|
| 415 | - |
|
| 416 | - // filter this view by transactions for this event |
|
| 417 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce( |
|
| 418 | - array( |
|
| 419 | - 'action' => 'default', |
|
| 420 | - 'EVT_ID' => $event->ID(), |
|
| 421 | - ), |
|
| 422 | - TXN_ADMIN_URL |
|
| 423 | - ); |
|
| 424 | - if ( |
|
| 425 | - empty($this->_req_data['EVT_ID']) |
|
| 426 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 427 | - 'ee_edit_event', |
|
| 428 | - 'espresso_events_edit', |
|
| 429 | - $event->ID() |
|
| 430 | - ) |
|
| 431 | - ) { |
|
| 432 | - $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"' |
|
| 433 | - . ' aria-label="' . esc_attr__( |
|
| 434 | - 'Filter transactions by this event', |
|
| 435 | - 'event_espresso' |
|
| 436 | - ) . '">' |
|
| 437 | - . esc_html__('View Transactions for this event', 'event_espresso') |
|
| 438 | - . '</a>'; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - return sprintf( |
|
| 442 | - '%1$s %2$s', |
|
| 443 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 444 | - 'ee_edit_event', |
|
| 445 | - 'espresso_events_edit', |
|
| 446 | - $event->ID() |
|
| 447 | - ) |
|
| 448 | - ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"' |
|
| 449 | - . ' aria-label="' |
|
| 450 | - . sprintf( |
|
| 451 | - esc_attr__('Edit Event: %s', 'event_espresso'), |
|
| 452 | - $event->get('EVT_name') |
|
| 453 | - ) |
|
| 454 | - . '">' |
|
| 455 | - . wp_trim_words( |
|
| 456 | - $event_name, |
|
| 457 | - 30, |
|
| 458 | - '...' |
|
| 459 | - ) |
|
| 460 | - . '</a>' |
|
| 461 | - : wp_trim_words($event_name, 30, '...'), |
|
| 462 | - $this->row_actions($actions) |
|
| 463 | - ); |
|
| 464 | - } else { |
|
| 465 | - return esc_html__( |
|
| 466 | - 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
| 467 | - 'event_espresso' |
|
| 468 | - ); |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * column_actions |
|
| 475 | - * |
|
| 476 | - * @param EE_Transaction $transaction |
|
| 477 | - * @return string |
|
| 478 | - * @throws EE_Error |
|
| 479 | - */ |
|
| 480 | - public function column_actions(EE_Transaction $transaction) |
|
| 481 | - { |
|
| 482 | - return $this->actionsModalMenu( |
|
| 483 | - $this->_action_string( |
|
| 484 | - $this->get_transaction_details_link($transaction) |
|
| 485 | - . $this->get_invoice_link($transaction) |
|
| 486 | - . $this->get_receipt_link($transaction) |
|
| 487 | - . $this->get_primary_registration_details_link($transaction) |
|
| 488 | - . $this->get_send_payment_reminder_trigger_link($transaction) |
|
| 489 | - . $this->get_payment_overview_link($transaction) |
|
| 490 | - . $this->get_related_messages_link($transaction), |
|
| 491 | - $transaction, |
|
| 492 | - 'div', |
|
| 493 | - 'txn-overview-actions ee-list-table-actions' |
|
| 494 | - ) |
|
| 495 | - ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Get the transaction details link. |
|
| 501 | - * |
|
| 502 | - * @param EE_Transaction $transaction |
|
| 503 | - * @return string |
|
| 504 | - * @throws EE_Error |
|
| 505 | - */ |
|
| 506 | - protected function get_transaction_details_link(EE_Transaction $transaction) |
|
| 507 | - { |
|
| 508 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 509 | - array( |
|
| 510 | - 'action' => 'view_transaction', |
|
| 511 | - 'TXN_ID' => $transaction->ID(), |
|
| 512 | - ), |
|
| 513 | - TXN_ADMIN_URL |
|
| 514 | - ); |
|
| 515 | - return ' |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * column_TXN_total |
|
| 258 | + * |
|
| 259 | + * @param EE_Transaction $transaction |
|
| 260 | + * @return string |
|
| 261 | + * @throws EE_Error |
|
| 262 | + */ |
|
| 263 | + public function column_TXN_total(EE_Transaction $transaction) |
|
| 264 | + { |
|
| 265 | + if ($transaction->get('TXN_total') > 0) { |
|
| 266 | + return '<span class="txn-pad-rght">' |
|
| 267 | + . apply_filters( |
|
| 268 | + 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
| 269 | + $transaction->get_pretty('TXN_total'), |
|
| 270 | + $transaction |
|
| 271 | + ) |
|
| 272 | + . '</span>'; |
|
| 273 | + } else { |
|
| 274 | + return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * column_TXN_paid |
|
| 281 | + * |
|
| 282 | + * @param EE_Transaction $transaction |
|
| 283 | + * @return mixed|string |
|
| 284 | + * @throws EE_Error |
|
| 285 | + */ |
|
| 286 | + public function column_TXN_paid(EE_Transaction $transaction) |
|
| 287 | + { |
|
| 288 | + $transaction_total = $transaction->get('TXN_total'); |
|
| 289 | + $transaction_paid = $transaction->get('TXN_paid'); |
|
| 290 | + |
|
| 291 | + if (EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
| 292 | + // monies owing |
|
| 293 | + $span_class = 'txn-overview-part-payment-spn'; |
|
| 294 | + if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
| 295 | + // paid in full |
|
| 296 | + $span_class = 'txn-overview-full-payment-spn'; |
|
| 297 | + } elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
| 298 | + // no payments made |
|
| 299 | + $span_class = 'txn-overview-no-payment-spn'; |
|
| 300 | + } |
|
| 301 | + } else { |
|
| 302 | + // transaction_total == 0 so this is a free event |
|
| 303 | + $span_class = 'txn-overview-free-event-spn'; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $payment_method = $transaction->payment_method(); |
|
| 307 | + $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
| 308 | + ? $payment_method->admin_name() |
|
| 309 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 310 | + |
|
| 311 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
| 312 | + . $transaction->get_pretty('TXN_paid') |
|
| 313 | + . '</span>'; |
|
| 314 | + if ($transaction_paid > 0) { |
|
| 315 | + $content .= ' <span class="ee-status-text-small">' |
|
| 316 | + . sprintf( |
|
| 317 | + esc_html__('...via %s', 'event_espresso'), |
|
| 318 | + $payment_method_name |
|
| 319 | + ) |
|
| 320 | + . '</span>'; |
|
| 321 | + } |
|
| 322 | + return "<div>{$content}</div>"; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * column_ATT_fname |
|
| 328 | + * |
|
| 329 | + * @param EE_Transaction $transaction |
|
| 330 | + * @return string |
|
| 331 | + * @throws EE_Error |
|
| 332 | + * @throws InvalidArgumentException |
|
| 333 | + * @throws InvalidDataTypeException |
|
| 334 | + * @throws InvalidInterfaceException |
|
| 335 | + */ |
|
| 336 | + public function column_ATT_fname(EE_Transaction $transaction) |
|
| 337 | + { |
|
| 338 | + $primary_reg = $transaction->primary_registration(); |
|
| 339 | + $attendee = $primary_reg->attendee(); |
|
| 340 | + if ($attendee instanceof EE_Attendee) { |
|
| 341 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 342 | + array( |
|
| 343 | + 'action' => 'view_registration', |
|
| 344 | + '_REG_ID' => $primary_reg->ID(), |
|
| 345 | + ), |
|
| 346 | + REG_ADMIN_URL |
|
| 347 | + ); |
|
| 348 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 349 | + 'ee_read_registration', |
|
| 350 | + 'espresso_registrations_view_registration', |
|
| 351 | + $primary_reg->ID() |
|
| 352 | + ) |
|
| 353 | + ? '<a href="' . $edit_lnk_url . '"' |
|
| 354 | + . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
| 355 | + . $attendee->full_name() |
|
| 356 | + . '</a>' |
|
| 357 | + : $attendee->full_name(); |
|
| 358 | + $content .= '<br>' . $attendee->email(); |
|
| 359 | + return $content; |
|
| 360 | + } |
|
| 361 | + return $transaction->failed() || $transaction->is_abandoned() |
|
| 362 | + ? esc_html__('no contact record.', 'event_espresso') |
|
| 363 | + : esc_html__( |
|
| 364 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 365 | + 'event_espresso' |
|
| 366 | + ); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * column_ATT_email |
|
| 372 | + * |
|
| 373 | + * @param EE_Transaction $transaction |
|
| 374 | + * @return string |
|
| 375 | + * @throws EE_Error |
|
| 376 | + */ |
|
| 377 | + public function column_ATT_email(EE_Transaction $transaction) |
|
| 378 | + { |
|
| 379 | + $attendee = $transaction->primary_registration()->attendee(); |
|
| 380 | + if (! empty($attendee)) { |
|
| 381 | + return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
| 382 | + . $attendee->get('ATT_email') |
|
| 383 | + . '</a>'; |
|
| 384 | + } else { |
|
| 385 | + return $transaction->failed() || $transaction->is_abandoned() |
|
| 386 | + ? esc_html__('no contact record.', 'event_espresso') |
|
| 387 | + : esc_html__( |
|
| 388 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 389 | + 'event_espresso' |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * column_event_name |
|
| 397 | + * |
|
| 398 | + * @param EE_Transaction $transaction |
|
| 399 | + * @return string |
|
| 400 | + * @throws EE_Error |
|
| 401 | + * @throws InvalidArgumentException |
|
| 402 | + * @throws InvalidDataTypeException |
|
| 403 | + * @throws InvalidInterfaceException |
|
| 404 | + */ |
|
| 405 | + public function column_event_name(EE_Transaction $transaction) |
|
| 406 | + { |
|
| 407 | + $actions = array(); |
|
| 408 | + $event = $transaction->primary_registration()->event(); |
|
| 409 | + if (! empty($event)) { |
|
| 410 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 411 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 412 | + EVENTS_ADMIN_URL |
|
| 413 | + ); |
|
| 414 | + $event_name = $event->get('EVT_name'); |
|
| 415 | + |
|
| 416 | + // filter this view by transactions for this event |
|
| 417 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce( |
|
| 418 | + array( |
|
| 419 | + 'action' => 'default', |
|
| 420 | + 'EVT_ID' => $event->ID(), |
|
| 421 | + ), |
|
| 422 | + TXN_ADMIN_URL |
|
| 423 | + ); |
|
| 424 | + if ( |
|
| 425 | + empty($this->_req_data['EVT_ID']) |
|
| 426 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 427 | + 'ee_edit_event', |
|
| 428 | + 'espresso_events_edit', |
|
| 429 | + $event->ID() |
|
| 430 | + ) |
|
| 431 | + ) { |
|
| 432 | + $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"' |
|
| 433 | + . ' aria-label="' . esc_attr__( |
|
| 434 | + 'Filter transactions by this event', |
|
| 435 | + 'event_espresso' |
|
| 436 | + ) . '">' |
|
| 437 | + . esc_html__('View Transactions for this event', 'event_espresso') |
|
| 438 | + . '</a>'; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + return sprintf( |
|
| 442 | + '%1$s %2$s', |
|
| 443 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 444 | + 'ee_edit_event', |
|
| 445 | + 'espresso_events_edit', |
|
| 446 | + $event->ID() |
|
| 447 | + ) |
|
| 448 | + ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"' |
|
| 449 | + . ' aria-label="' |
|
| 450 | + . sprintf( |
|
| 451 | + esc_attr__('Edit Event: %s', 'event_espresso'), |
|
| 452 | + $event->get('EVT_name') |
|
| 453 | + ) |
|
| 454 | + . '">' |
|
| 455 | + . wp_trim_words( |
|
| 456 | + $event_name, |
|
| 457 | + 30, |
|
| 458 | + '...' |
|
| 459 | + ) |
|
| 460 | + . '</a>' |
|
| 461 | + : wp_trim_words($event_name, 30, '...'), |
|
| 462 | + $this->row_actions($actions) |
|
| 463 | + ); |
|
| 464 | + } else { |
|
| 465 | + return esc_html__( |
|
| 466 | + 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
| 467 | + 'event_espresso' |
|
| 468 | + ); |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * column_actions |
|
| 475 | + * |
|
| 476 | + * @param EE_Transaction $transaction |
|
| 477 | + * @return string |
|
| 478 | + * @throws EE_Error |
|
| 479 | + */ |
|
| 480 | + public function column_actions(EE_Transaction $transaction) |
|
| 481 | + { |
|
| 482 | + return $this->actionsModalMenu( |
|
| 483 | + $this->_action_string( |
|
| 484 | + $this->get_transaction_details_link($transaction) |
|
| 485 | + . $this->get_invoice_link($transaction) |
|
| 486 | + . $this->get_receipt_link($transaction) |
|
| 487 | + . $this->get_primary_registration_details_link($transaction) |
|
| 488 | + . $this->get_send_payment_reminder_trigger_link($transaction) |
|
| 489 | + . $this->get_payment_overview_link($transaction) |
|
| 490 | + . $this->get_related_messages_link($transaction), |
|
| 491 | + $transaction, |
|
| 492 | + 'div', |
|
| 493 | + 'txn-overview-actions ee-list-table-actions' |
|
| 494 | + ) |
|
| 495 | + ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Get the transaction details link. |
|
| 501 | + * |
|
| 502 | + * @param EE_Transaction $transaction |
|
| 503 | + * @return string |
|
| 504 | + * @throws EE_Error |
|
| 505 | + */ |
|
| 506 | + protected function get_transaction_details_link(EE_Transaction $transaction) |
|
| 507 | + { |
|
| 508 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 509 | + array( |
|
| 510 | + 'action' => 'view_transaction', |
|
| 511 | + 'TXN_ID' => $transaction->ID(), |
|
| 512 | + ), |
|
| 513 | + TXN_ADMIN_URL |
|
| 514 | + ); |
|
| 515 | + return ' |
|
| 516 | 516 | <a class="ee-aria-tooltip button button--icon-only" href="' . $url . '"' |
| 517 | - . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only"> |
|
| 517 | + . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only"> |
|
| 518 | 518 | <span class="dashicons dashicons-cart"></span> |
| 519 | 519 | </a>'; |
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Get the invoice link for the given registration. |
|
| 525 | - * |
|
| 526 | - * @param EE_Transaction $transaction |
|
| 527 | - * @return string |
|
| 528 | - * @throws EE_Error |
|
| 529 | - */ |
|
| 530 | - protected function get_invoice_link(EE_Transaction $transaction) |
|
| 531 | - { |
|
| 532 | - $registration = $transaction->primary_registration(); |
|
| 533 | - if ($registration instanceof EE_Registration) { |
|
| 534 | - $url = $registration->invoice_url(); |
|
| 535 | - // only show invoice link if message type is active. |
|
| 536 | - if ( |
|
| 537 | - $registration->attendee() instanceof EE_Attendee |
|
| 538 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 539 | - ) { |
|
| 540 | - return ' |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Get the invoice link for the given registration. |
|
| 525 | + * |
|
| 526 | + * @param EE_Transaction $transaction |
|
| 527 | + * @return string |
|
| 528 | + * @throws EE_Error |
|
| 529 | + */ |
|
| 530 | + protected function get_invoice_link(EE_Transaction $transaction) |
|
| 531 | + { |
|
| 532 | + $registration = $transaction->primary_registration(); |
|
| 533 | + if ($registration instanceof EE_Registration) { |
|
| 534 | + $url = $registration->invoice_url(); |
|
| 535 | + // only show invoice link if message type is active. |
|
| 536 | + if ( |
|
| 537 | + $registration->attendee() instanceof EE_Attendee |
|
| 538 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 539 | + ) { |
|
| 540 | + return ' |
|
| 541 | 541 | <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
| 542 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only"> |
|
| 542 | + . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only"> |
|
| 543 | 543 | <span class="dashicons dashicons-media-spreadsheet"></span> |
| 544 | 544 | </a>'; |
| 545 | - } |
|
| 546 | - } |
|
| 547 | - return ''; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Get the receipt link for the transaction. |
|
| 553 | - * |
|
| 554 | - * @param EE_Transaction $transaction |
|
| 555 | - * @return string |
|
| 556 | - * @throws EE_Error |
|
| 557 | - */ |
|
| 558 | - protected function get_receipt_link(EE_Transaction $transaction) |
|
| 559 | - { |
|
| 560 | - $registration = $transaction->primary_registration(); |
|
| 561 | - if ($registration instanceof EE_Registration) { |
|
| 562 | - $url = $registration->receipt_url(); |
|
| 563 | - // only show receipt link if message type is active. |
|
| 564 | - if ( |
|
| 565 | - $registration->attendee() instanceof EE_Attendee |
|
| 566 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
| 567 | - ) { |
|
| 568 | - return ' |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + return ''; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Get the receipt link for the transaction. |
|
| 553 | + * |
|
| 554 | + * @param EE_Transaction $transaction |
|
| 555 | + * @return string |
|
| 556 | + * @throws EE_Error |
|
| 557 | + */ |
|
| 558 | + protected function get_receipt_link(EE_Transaction $transaction) |
|
| 559 | + { |
|
| 560 | + $registration = $transaction->primary_registration(); |
|
| 561 | + if ($registration instanceof EE_Registration) { |
|
| 562 | + $url = $registration->receipt_url(); |
|
| 563 | + // only show receipt link if message type is active. |
|
| 564 | + if ( |
|
| 565 | + $registration->attendee() instanceof EE_Attendee |
|
| 566 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
| 567 | + ) { |
|
| 568 | + return ' |
|
| 569 | 569 | <a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
| 570 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only"> |
|
| 570 | + . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only"> |
|
| 571 | 571 | <span class="dashicons dashicons-text-page"></span> |
| 572 | 572 | </a>'; |
| 573 | - } |
|
| 574 | - } |
|
| 575 | - return ''; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Get the link to view the details for the primary registration. |
|
| 581 | - * |
|
| 582 | - * @param EE_Transaction $transaction |
|
| 583 | - * @return string |
|
| 584 | - * @throws EE_Error |
|
| 585 | - * @throws InvalidArgumentException |
|
| 586 | - * @throws InvalidDataTypeException |
|
| 587 | - * @throws InvalidInterfaceException |
|
| 588 | - */ |
|
| 589 | - protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
| 590 | - { |
|
| 591 | - $registration = $transaction->primary_registration(); |
|
| 592 | - if ($registration instanceof EE_Registration) { |
|
| 593 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 594 | - array( |
|
| 595 | - 'action' => 'view_registration', |
|
| 596 | - '_REG_ID' => $registration->ID(), |
|
| 597 | - ), |
|
| 598 | - REG_ADMIN_URL |
|
| 599 | - ); |
|
| 600 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 601 | - 'ee_read_registration', |
|
| 602 | - 'espresso_registrations_view_registration', |
|
| 603 | - $registration->ID() |
|
| 604 | - ) |
|
| 605 | - ? ' |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + return ''; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Get the link to view the details for the primary registration. |
|
| 581 | + * |
|
| 582 | + * @param EE_Transaction $transaction |
|
| 583 | + * @return string |
|
| 584 | + * @throws EE_Error |
|
| 585 | + * @throws InvalidArgumentException |
|
| 586 | + * @throws InvalidDataTypeException |
|
| 587 | + * @throws InvalidInterfaceException |
|
| 588 | + */ |
|
| 589 | + protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
| 590 | + { |
|
| 591 | + $registration = $transaction->primary_registration(); |
|
| 592 | + if ($registration instanceof EE_Registration) { |
|
| 593 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 594 | + array( |
|
| 595 | + 'action' => 'view_registration', |
|
| 596 | + '_REG_ID' => $registration->ID(), |
|
| 597 | + ), |
|
| 598 | + REG_ADMIN_URL |
|
| 599 | + ); |
|
| 600 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 601 | + 'ee_read_registration', |
|
| 602 | + 'espresso_registrations_view_registration', |
|
| 603 | + $registration->ID() |
|
| 604 | + ) |
|
| 605 | + ? ' |
|
| 606 | 606 | <a href="' . $url . '" |
| 607 | 607 | aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '" |
| 608 | 608 | class="ee-aria-tooltip button button--icon-only" |
| 609 | 609 | > |
| 610 | 610 | <span class="dashicons dashicons-clipboard"></span> |
| 611 | 611 | </a>' |
| 612 | - : ''; |
|
| 613 | - } |
|
| 614 | - return ''; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Get send payment reminder trigger link |
|
| 620 | - * |
|
| 621 | - * @param EE_Transaction $transaction |
|
| 622 | - * @return string |
|
| 623 | - * @throws EE_Error |
|
| 624 | - * @throws InvalidArgumentException |
|
| 625 | - * @throws InvalidDataTypeException |
|
| 626 | - * @throws InvalidInterfaceException |
|
| 627 | - */ |
|
| 628 | - protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
| 629 | - { |
|
| 630 | - $registration = $transaction->primary_registration(); |
|
| 631 | - if ( |
|
| 632 | - $registration instanceof EE_Registration |
|
| 633 | - && $registration->attendee() instanceof EE_Attendee |
|
| 634 | - && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 635 | - && ! in_array( |
|
| 636 | - $transaction->status_ID(), |
|
| 637 | - array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
| 638 | - true |
|
| 639 | - ) |
|
| 640 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 641 | - 'ee_send_message', |
|
| 642 | - 'espresso_transactions_send_payment_reminder' |
|
| 643 | - ) |
|
| 644 | - ) { |
|
| 645 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 646 | - array( |
|
| 647 | - 'action' => 'send_payment_reminder', |
|
| 648 | - 'TXN_ID' => $transaction->ID(), |
|
| 649 | - ), |
|
| 650 | - TXN_ADMIN_URL |
|
| 651 | - ); |
|
| 652 | - return ' |
|
| 612 | + : ''; |
|
| 613 | + } |
|
| 614 | + return ''; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Get send payment reminder trigger link |
|
| 620 | + * |
|
| 621 | + * @param EE_Transaction $transaction |
|
| 622 | + * @return string |
|
| 623 | + * @throws EE_Error |
|
| 624 | + * @throws InvalidArgumentException |
|
| 625 | + * @throws InvalidDataTypeException |
|
| 626 | + * @throws InvalidInterfaceException |
|
| 627 | + */ |
|
| 628 | + protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
| 629 | + { |
|
| 630 | + $registration = $transaction->primary_registration(); |
|
| 631 | + if ( |
|
| 632 | + $registration instanceof EE_Registration |
|
| 633 | + && $registration->attendee() instanceof EE_Attendee |
|
| 634 | + && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 635 | + && ! in_array( |
|
| 636 | + $transaction->status_ID(), |
|
| 637 | + array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
| 638 | + true |
|
| 639 | + ) |
|
| 640 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 641 | + 'ee_send_message', |
|
| 642 | + 'espresso_transactions_send_payment_reminder' |
|
| 643 | + ) |
|
| 644 | + ) { |
|
| 645 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 646 | + array( |
|
| 647 | + 'action' => 'send_payment_reminder', |
|
| 648 | + 'TXN_ID' => $transaction->ID(), |
|
| 649 | + ), |
|
| 650 | + TXN_ADMIN_URL |
|
| 651 | + ); |
|
| 652 | + return ' |
|
| 653 | 653 | <a href="' . $url . '" |
| 654 | 654 | aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" |
| 655 | 655 | class="ee-aria-tooltip button button--icon-only" |
| 656 | 656 | > |
| 657 | 657 | <span class="dashicons dashicons-email-alt"></span> |
| 658 | 658 | </a>'; |
| 659 | - } |
|
| 660 | - return ''; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Get link to filtered view in the message activity list table of messages for this transaction. |
|
| 666 | - * |
|
| 667 | - * @param EE_Transaction $transaction |
|
| 668 | - * @return string |
|
| 669 | - * @throws EE_Error |
|
| 670 | - * @throws InvalidArgumentException |
|
| 671 | - * @throws InvalidDataTypeException |
|
| 672 | - * @throws InvalidInterfaceException |
|
| 673 | - */ |
|
| 674 | - protected function get_related_messages_link(EE_Transaction $transaction) |
|
| 675 | - { |
|
| 676 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 677 | - 'ee_read_global_messages', |
|
| 678 | - 'view_filtered_messages' |
|
| 679 | - ) |
|
| 680 | - ? EEH_MSG_Template::get_message_action_link( |
|
| 681 | - 'see_notifications_for', |
|
| 682 | - null, |
|
| 683 | - array('TXN_ID' => $transaction->ID()) |
|
| 684 | - ) |
|
| 685 | - : ''; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Return the link to make a payment on the frontend |
|
| 691 | - * |
|
| 692 | - * @param EE_Transaction $transaction |
|
| 693 | - * @return string |
|
| 694 | - * @throws EE_Error |
|
| 695 | - */ |
|
| 696 | - protected function get_payment_overview_link(EE_Transaction $transaction) |
|
| 697 | - { |
|
| 698 | - $registration = $transaction->primary_registration(); |
|
| 699 | - if ( |
|
| 700 | - $registration instanceof EE_Registration |
|
| 701 | - && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 702 | - && $registration->owes_monies_and_can_pay() |
|
| 703 | - ) { |
|
| 704 | - return ' |
|
| 659 | + } |
|
| 660 | + return ''; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Get link to filtered view in the message activity list table of messages for this transaction. |
|
| 666 | + * |
|
| 667 | + * @param EE_Transaction $transaction |
|
| 668 | + * @return string |
|
| 669 | + * @throws EE_Error |
|
| 670 | + * @throws InvalidArgumentException |
|
| 671 | + * @throws InvalidDataTypeException |
|
| 672 | + * @throws InvalidInterfaceException |
|
| 673 | + */ |
|
| 674 | + protected function get_related_messages_link(EE_Transaction $transaction) |
|
| 675 | + { |
|
| 676 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 677 | + 'ee_read_global_messages', |
|
| 678 | + 'view_filtered_messages' |
|
| 679 | + ) |
|
| 680 | + ? EEH_MSG_Template::get_message_action_link( |
|
| 681 | + 'see_notifications_for', |
|
| 682 | + null, |
|
| 683 | + array('TXN_ID' => $transaction->ID()) |
|
| 684 | + ) |
|
| 685 | + : ''; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Return the link to make a payment on the frontend |
|
| 691 | + * |
|
| 692 | + * @param EE_Transaction $transaction |
|
| 693 | + * @return string |
|
| 694 | + * @throws EE_Error |
|
| 695 | + */ |
|
| 696 | + protected function get_payment_overview_link(EE_Transaction $transaction) |
|
| 697 | + { |
|
| 698 | + $registration = $transaction->primary_registration(); |
|
| 699 | + if ( |
|
| 700 | + $registration instanceof EE_Registration |
|
| 701 | + && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 702 | + && $registration->owes_monies_and_can_pay() |
|
| 703 | + ) { |
|
| 704 | + return ' |
|
| 705 | 705 | <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
| 706 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
| 707 | - . ' class="ee-aria-tooltip button button--icon-only"> |
|
| 706 | + . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
| 707 | + . ' class="ee-aria-tooltip button button--icon-only"> |
|
| 708 | 708 | <span class="dashicons dashicons-money"></span> |
| 709 | 709 | </a>'; |
| 710 | - } |
|
| 711 | - return ''; |
|
| 712 | - } |
|
| 710 | + } |
|
| 711 | + return ''; |
|
| 712 | + } |
|
| 713 | 713 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | ); |
| 58 | 58 | $ID_column_name = esc_html__('ID', 'event_espresso'); |
| 59 | 59 | $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">'; |
| 60 | - $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso'); |
|
| 60 | + $ID_column_name .= ' : '.esc_html__('Transaction Date', 'event_espresso'); |
|
| 61 | 61 | $ID_column_name .= '</span> '; |
| 62 | 62 | $this->_columns = array( |
| 63 | 63 | 'id' => $ID_column_name, |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | { |
| 96 | 96 | $class = parent::_get_row_class($transaction); |
| 97 | 97 | // add status class |
| 98 | - $class .= ' txn-status-' . $transaction->status_ID(); |
|
| 98 | + $class .= ' txn-status-'.$transaction->status_ID(); |
|
| 99 | 99 | if ($this->_has_checkbox_column) { |
| 100 | 100 | $class .= ' has-checkbox-column'; |
| 101 | 101 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | protected function _add_view_counts() |
| 146 | 146 | { |
| 147 | 147 | foreach ($this->_views as $view) { |
| 148 | - $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 148 | + $this->_views[$view['slug']]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -169,14 +169,14 @@ discard block |
||
| 169 | 169 | $content = ' |
| 170 | 170 | <span class="ee-entity-id"> |
| 171 | 171 | <a class="ee-aria-tooltip" |
| 172 | - href="' . $view_lnk_url . '" |
|
| 173 | - aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '" |
|
| 172 | + href="' . $view_lnk_url.'" |
|
| 173 | + aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso').'" |
|
| 174 | 174 | > |
| 175 | - ' . $transaction->ID() . ' |
|
| 175 | + ' . $transaction->ID().' |
|
| 176 | 176 | </a> |
| 177 | 177 | </span>'; |
| 178 | 178 | // txn timestamp |
| 179 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
| 179 | + $content .= ' <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>'; |
|
| 180 | 180 | return $this->columnContent('id', $content, 'end'); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
| 243 | 243 | return ' |
| 244 | 244 | <div class="ee-layout-row"> |
| 245 | - <span aria-label="' . $pretty_status . '" class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"></span> |
|
| 246 | - <a href="' . $view_lnk_url . '" |
|
| 247 | - class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" |
|
| 248 | - aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID( |
|
| 249 | - ) . '"> |
|
| 250 | - ' . $this->_get_txn_timestamp($transaction) . ' |
|
| 245 | + <span aria-label="' . $pretty_status.'" class="ee-status-dot ee-status-bg--'.$status.' ee-aria-tooltip"></span> |
|
| 246 | + <a href="' . $view_lnk_url.'" |
|
| 247 | + class="row-title ee-status-color--' . $status.' ee-aria-tooltip" |
|
| 248 | + aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID( |
|
| 249 | + ).'"> |
|
| 250 | + ' . $this->_get_txn_timestamp($transaction).' |
|
| 251 | 251 | </a> |
| 252 | 252 | </div>'; |
| 253 | 253 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | ) |
| 272 | 272 | . '</span>'; |
| 273 | 273 | } else { |
| 274 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
| 274 | + return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>'; |
|
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | ? $payment_method->admin_name() |
| 309 | 309 | : esc_html__('Unknown', 'event_espresso'); |
| 310 | 310 | |
| 311 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
| 311 | + $content = '<span class="'.$span_class.' txn-pad-rght">' |
|
| 312 | 312 | . $transaction->get_pretty('TXN_paid') |
| 313 | 313 | . '</span>'; |
| 314 | 314 | if ($transaction_paid > 0) { |
@@ -350,12 +350,12 @@ discard block |
||
| 350 | 350 | 'espresso_registrations_view_registration', |
| 351 | 351 | $primary_reg->ID() |
| 352 | 352 | ) |
| 353 | - ? '<a href="' . $edit_lnk_url . '"' |
|
| 354 | - . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
| 353 | + ? '<a href="'.$edit_lnk_url.'"' |
|
| 354 | + . ' aria-label="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
| 355 | 355 | . $attendee->full_name() |
| 356 | 356 | . '</a>' |
| 357 | 357 | : $attendee->full_name(); |
| 358 | - $content .= '<br>' . $attendee->email(); |
|
| 358 | + $content .= '<br>'.$attendee->email(); |
|
| 359 | 359 | return $content; |
| 360 | 360 | } |
| 361 | 361 | return $transaction->failed() || $transaction->is_abandoned() |
@@ -377,8 +377,8 @@ discard block |
||
| 377 | 377 | public function column_ATT_email(EE_Transaction $transaction) |
| 378 | 378 | { |
| 379 | 379 | $attendee = $transaction->primary_registration()->attendee(); |
| 380 | - if (! empty($attendee)) { |
|
| 381 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
| 380 | + if ( ! empty($attendee)) { |
|
| 381 | + return '<a href="mailto:'.$attendee->get('ATT_email').'">' |
|
| 382 | 382 | . $attendee->get('ATT_email') |
| 383 | 383 | . '</a>'; |
| 384 | 384 | } else { |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | { |
| 407 | 407 | $actions = array(); |
| 408 | 408 | $event = $transaction->primary_registration()->event(); |
| 409 | - if (! empty($event)) { |
|
| 409 | + if ( ! empty($event)) { |
|
| 410 | 410 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
| 411 | 411 | array('action' => 'edit', 'post' => $event->ID()), |
| 412 | 412 | EVENTS_ADMIN_URL |
@@ -429,11 +429,11 @@ discard block |
||
| 429 | 429 | $event->ID() |
| 430 | 430 | ) |
| 431 | 431 | ) { |
| 432 | - $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"' |
|
| 433 | - . ' aria-label="' . esc_attr__( |
|
| 432 | + $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="'.$txn_by_event_lnk.'"' |
|
| 433 | + . ' aria-label="'.esc_attr__( |
|
| 434 | 434 | 'Filter transactions by this event', |
| 435 | 435 | 'event_espresso' |
| 436 | - ) . '">' |
|
| 436 | + ).'">' |
|
| 437 | 437 | . esc_html__('View Transactions for this event', 'event_espresso') |
| 438 | 438 | . '</a>'; |
| 439 | 439 | } |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | 'espresso_events_edit', |
| 446 | 446 | $event->ID() |
| 447 | 447 | ) |
| 448 | - ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"' |
|
| 448 | + ? '<a class="ee-aria-tooltip" href="'.$edit_event_url.'"' |
|
| 449 | 449 | . ' aria-label="' |
| 450 | 450 | . sprintf( |
| 451 | 451 | esc_attr__('Edit Event: %s', 'event_espresso'), |
@@ -513,8 +513,8 @@ discard block |
||
| 513 | 513 | TXN_ADMIN_URL |
| 514 | 514 | ); |
| 515 | 515 | return ' |
| 516 | - <a class="ee-aria-tooltip button button--icon-only" href="' . $url . '"' |
|
| 517 | - . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only"> |
|
| 516 | + <a class="ee-aria-tooltip button button--icon-only" href="' . $url.'"' |
|
| 517 | + . ' aria-label="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="button button--icon-only"> |
|
| 518 | 518 | <span class="dashicons dashicons-cart"></span> |
| 519 | 519 | </a>'; |
| 520 | 520 | } |
@@ -538,8 +538,8 @@ discard block |
||
| 538 | 538 | && EEH_MSG_Template::is_mt_active('invoice') |
| 539 | 539 | ) { |
| 540 | 540 | return ' |
| 541 | - <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
|
| 542 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only"> |
|
| 541 | + <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"' |
|
| 542 | + . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--icon-only"> |
|
| 543 | 543 | <span class="dashicons dashicons-media-spreadsheet"></span> |
| 544 | 544 | </a>'; |
| 545 | 545 | } |
@@ -566,8 +566,8 @@ discard block |
||
| 566 | 566 | && EEH_MSG_Template::is_mt_active('receipt') |
| 567 | 567 | ) { |
| 568 | 568 | return ' |
| 569 | - <a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
|
| 570 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only"> |
|
| 569 | + <a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"' |
|
| 570 | + . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--icon-only"> |
|
| 571 | 571 | <span class="dashicons dashicons-text-page"></span> |
| 572 | 572 | </a>'; |
| 573 | 573 | } |
@@ -603,8 +603,8 @@ discard block |
||
| 603 | 603 | $registration->ID() |
| 604 | 604 | ) |
| 605 | 605 | ? ' |
| 606 | - <a href="' . $url . '" |
|
| 607 | - aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '" |
|
| 606 | + <a href="' . $url.'" |
|
| 607 | + aria-label="' . esc_attr__('View Registration Details', 'event_espresso').'" |
|
| 608 | 608 | class="ee-aria-tooltip button button--icon-only" |
| 609 | 609 | > |
| 610 | 610 | <span class="dashicons dashicons-clipboard"></span> |
@@ -650,8 +650,8 @@ discard block |
||
| 650 | 650 | TXN_ADMIN_URL |
| 651 | 651 | ); |
| 652 | 652 | return ' |
| 653 | - <a href="' . $url . '" |
|
| 654 | - aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" |
|
| 653 | + <a href="' . $url.'" |
|
| 654 | + aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso').'" |
|
| 655 | 655 | class="ee-aria-tooltip button button--icon-only" |
| 656 | 656 | > |
| 657 | 657 | <span class="dashicons dashicons-email-alt"></span> |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | && $registration->owes_monies_and_can_pay() |
| 703 | 703 | ) { |
| 704 | 704 | return ' |
| 705 | - <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
|
| 706 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
| 705 | + <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"' |
|
| 706 | + . ' target="_blank" href="'.$registration->payment_overview_url(true).'"' |
|
| 707 | 707 | . ' class="ee-aria-tooltip button button--icon-only"> |
| 708 | 708 | <span class="dashicons dashicons-money"></span> |
| 709 | 709 | </a>'; |
@@ -84,21 +84,21 @@ discard block |
||
| 84 | 84 | </div> |
| 85 | 85 | <br class="clear" /> |
| 86 | 86 | <?php |
| 87 | - $no_payments = $grand_raw_total > 0 |
|
| 88 | - || $TXN_status !== EEM_Transaction::complete_status_code |
|
| 89 | - || ! empty($payments); |
|
| 90 | - ?> |
|
| 87 | + $no_payments = $grand_raw_total > 0 |
|
| 88 | + || $TXN_status !== EEM_Transaction::complete_status_code |
|
| 89 | + || ! empty($payments); |
|
| 90 | + ?> |
|
| 91 | 91 | <?php if ($attendee instanceof EE_Attendee && $no_payments) : ?> |
| 92 | 92 | <?php $no_payment_text = $can_edit_payments |
| 93 | - ? esc_html__( |
|
| 94 | - 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 95 | - 'event_espresso' |
|
| 96 | - ) |
|
| 97 | - : esc_html__( |
|
| 98 | - 'No payments have been applied to this transaction yet.', |
|
| 99 | - 'event_espresso' |
|
| 100 | - ); |
|
| 101 | - ?> |
|
| 93 | + ? esc_html__( |
|
| 94 | + 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 95 | + 'event_espresso' |
|
| 96 | + ) |
|
| 97 | + : esc_html__( |
|
| 98 | + 'No payments have been applied to this transaction yet.', |
|
| 99 | + 'event_espresso' |
|
| 100 | + ); |
|
| 101 | + ?> |
|
| 102 | 102 | |
| 103 | 103 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
| 104 | 104 | <?php esc_html_e('Payment Details', 'event_espresso'); ?> |
@@ -141,92 +141,92 @@ discard block |
||
| 141 | 141 | </thead> |
| 142 | 142 | <tbody> |
| 143 | 143 | <?php if ($payments) : |
| 144 | - $payment_total = 0; |
|
| 145 | - foreach ($payments as $PAY_ID => $payment) : |
|
| 146 | - if (! $payment instanceof EE_Payment) { |
|
| 147 | - continue; |
|
| 148 | - } |
|
| 149 | - $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ]) |
|
| 150 | - ? wp_json_encode($existing_reg_payments[ $PAY_ID ]) |
|
| 151 | - : '{}'; |
|
| 152 | - ?> |
|
| 144 | + $payment_total = 0; |
|
| 145 | + foreach ($payments as $PAY_ID => $payment) : |
|
| 146 | + if (! $payment instanceof EE_Payment) { |
|
| 147 | + continue; |
|
| 148 | + } |
|
| 149 | + $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ]) |
|
| 150 | + ? wp_json_encode($existing_reg_payments[ $PAY_ID ]) |
|
| 151 | + : '{}'; |
|
| 152 | + ?> |
|
| 153 | 153 | <tr id="txn-admin-payment-tr-<?php echo absint($PAY_ID); ?>" class=' jst-cntr'> |
| 154 | 154 | <td class="jst-cntr no-pad"> |
| 155 | 155 | <span id="payment-status-<?php echo absint($PAY_ID); ?>" |
| 156 | 156 | class="ee-status-dot ee-status-bg--<?php echo esc_attr($payment->STS_ID()); ?>" ></span> |
| 157 | 157 | <div id="payment-STS_ID-<?php echo absint($PAY_ID); ?>" class="hidden"><?php |
| 158 | - echo esc_html($payment->STS_ID()); |
|
| 159 | - ?></div> |
|
| 158 | + echo esc_html($payment->STS_ID()); |
|
| 159 | + ?></div> |
|
| 160 | 160 | <div id="reg-payments-<?php echo absint($PAY_ID); ?>" class="hidden"><?php |
| 161 | - echo esc_html($existing_reg_payment_json); |
|
| 162 | - ?></div> |
|
| 161 | + echo esc_html($existing_reg_payment_json); |
|
| 162 | + ?></div> |
|
| 163 | 163 | </td> |
| 164 | 164 | <td class=" jst-rght"> |
| 165 | 165 | <div id="payment-id-<?php echo absint($PAY_ID); ?>"><?php |
| 166 | - echo esc_html($PAY_ID); |
|
| 167 | - ?></div> |
|
| 166 | + echo esc_html($PAY_ID); |
|
| 167 | + ?></div> |
|
| 168 | 168 | </td> |
| 169 | 169 | <td class=" jst-left"> |
| 170 | 170 | <div id="payment-date-<?php echo absint($PAY_ID); ?>" class="payment-date-dv"><?php |
| 171 | - echo esc_html($payment->timestamp('Y-m-d', 'g:i a')); |
|
| 172 | - ?></div> |
|
| 171 | + echo esc_html($payment->timestamp('Y-m-d', 'g:i a')); |
|
| 172 | + ?></div> |
|
| 173 | 173 | </td> |
| 174 | 174 | <td class='payment-method-gateway-td jst-left'> |
| 175 | 175 | <span id="payment-method-<?php echo absint($PAY_ID); ?>"><?php |
| 176 | - echo esc_html($payment->source()); |
|
| 177 | - ?></span> |
|
| 176 | + echo esc_html($payment->source()); |
|
| 177 | + ?></span> |
|
| 178 | 178 | <span class="ee-status--ignore">»</span> |
| 179 | 179 | <span id="payment-gateway-<?php echo absint($PAY_ID); ?>"><?php |
| 180 | - echo esc_html( |
|
| 181 | - $payment->payment_method() instanceof EE_Payment_Method |
|
| 182 | - ? $payment->payment_method()->admin_name() |
|
| 183 | - : __("Unknown", 'event_espresso') |
|
| 184 | - ); ?></span> |
|
| 180 | + echo esc_html( |
|
| 181 | + $payment->payment_method() instanceof EE_Payment_Method |
|
| 182 | + ? $payment->payment_method()->admin_name() |
|
| 183 | + : __("Unknown", 'event_espresso') |
|
| 184 | + ); ?></span> |
|
| 185 | 185 | <span id="payment-gateway-id-<?php echo absint($PAY_ID); ?>" class="hidden"><?php |
| 186 | - echo esc_html( |
|
| 187 | - $payment->payment_method() instanceof EE_Payment_Method |
|
| 188 | - ? $payment->payment_method()->ID() |
|
| 189 | - : 0 |
|
| 190 | - ); ?></span> |
|
| 186 | + echo esc_html( |
|
| 187 | + $payment->payment_method() instanceof EE_Payment_Method |
|
| 188 | + ? $payment->payment_method()->ID() |
|
| 189 | + : 0 |
|
| 190 | + ); ?></span> |
|
| 191 | 191 | </td> |
| 192 | 192 | <td class=' jst-rght'> |
| 193 | 193 | <?php |
| 194 | - $payment_class = $payment->amount() > 0 |
|
| 195 | - ? 'txn-admin-payment-status-' . $payment->STS_ID() |
|
| 196 | - : 'txn-admin-payment-status-PDC'; |
|
| 197 | - ?> |
|
| 194 | + $payment_class = $payment->amount() > 0 |
|
| 195 | + ? 'txn-admin-payment-status-' . $payment->STS_ID() |
|
| 196 | + : 'txn-admin-payment-status-PDC'; |
|
| 197 | + ?> |
|
| 198 | 198 | <span class="<?php echo esc_attr($payment_class); ?>"> |
| 199 | 199 | <span id="payment-amount-<?php echo absint($PAY_ID); ?>" |
| 200 | 200 | style="display:inline;" |
| 201 | 201 | ><?php echo wp_kses( |
| 202 | - EEH_Template::format_currency( |
|
| 203 | - $payment->amount(), |
|
| 204 | - false, |
|
| 205 | - false |
|
| 206 | - ), |
|
| 207 | - AllowedTags::getAllowedTags() |
|
| 208 | - ); ?></span> |
|
| 202 | + EEH_Template::format_currency( |
|
| 203 | + $payment->amount(), |
|
| 204 | + false, |
|
| 205 | + false |
|
| 206 | + ), |
|
| 207 | + AllowedTags::getAllowedTags() |
|
| 208 | + ); ?></span> |
|
| 209 | 209 | </span> |
| 210 | 210 | </td> |
| 211 | 211 | <td class=" jst-left"> |
| 212 | 212 | <div id="payment-response-<?php echo absint($PAY_ID); ?>"><?php |
| 213 | - echo esc_html($payment->gateway_response()); |
|
| 214 | - ?></div> |
|
| 213 | + echo esc_html($payment->gateway_response()); |
|
| 214 | + ?></div> |
|
| 215 | 215 | </td> |
| 216 | 216 | <td class=" jst-left payment-txn-id-chq-nmbr"> |
| 217 | 217 | <div id="payment-txn-id-chq-nmbr-<?php echo absint($PAY_ID); ?>"><?php |
| 218 | - echo esc_html($payment->txn_id_chq_nmbr()); |
|
| 219 | - ?></div> |
|
| 218 | + echo esc_html($payment->txn_id_chq_nmbr()); |
|
| 219 | + ?></div> |
|
| 220 | 220 | </td> |
| 221 | 221 | <td class=" jst-left"> |
| 222 | 222 | <div id="payment-po-nmbr-<?php echo absint($PAY_ID); ?>"><?php |
| 223 | - echo esc_html($payment->po_number()); |
|
| 224 | - ?></div> |
|
| 223 | + echo esc_html($payment->po_number()); |
|
| 224 | + ?></div> |
|
| 225 | 225 | </td> |
| 226 | 226 | <td class=" jst-left"> |
| 227 | 227 | <div id="payment-accntng-<?php echo absint($PAY_ID); ?>"><?php |
| 228 | - echo esc_html($payment->extra_accntng()); |
|
| 229 | - ?></div> |
|
| 228 | + echo esc_html($payment->extra_accntng()); |
|
| 229 | + ?></div> |
|
| 230 | 230 | </td> |
| 231 | 231 | <td class='jst-left'> |
| 232 | 232 | <div class='txn-overview-actions ee-list-table-actions'> |
@@ -256,14 +256,14 @@ discard block |
||
| 256 | 256 | <?php $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; ?> |
| 257 | 257 | <?php endforeach; ?> |
| 258 | 258 | <?php $pay_totals_class = $payment_total > $grand_raw_total |
| 259 | - ? ' important-notice' |
|
| 260 | - : ''; |
|
| 261 | - ?> |
|
| 259 | + ? ' important-notice' |
|
| 260 | + : ''; |
|
| 261 | + ?> |
|
| 262 | 262 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
| 263 | 263 | <td class=" jst-rght" colspan="10"> |
| 264 | 264 | <span class="important-notice"><?php |
| 265 | - echo wp_kses($no_payment_text, AllowedTags::getAllowedTags()); |
|
| 266 | - ?></span> |
|
| 265 | + echo wp_kses($no_payment_text, AllowedTags::getAllowedTags()); |
|
| 266 | + ?></span> |
|
| 267 | 267 | </td> |
| 268 | 268 | </tr> |
| 269 | 269 | <tr id="txn-admin-payments-total-tr" |
@@ -271,45 +271,45 @@ discard block |
||
| 271 | 271 | > |
| 272 | 272 | <th class=" jst-rght" colspan="9"> |
| 273 | 273 | <span id="payments-total-spn"><?php |
| 274 | - $overpaid = $payment_total > $grand_raw_total |
|
| 275 | - ? '<span id="overpaid">' |
|
| 276 | - . __('This transaction has been overpaid ! ', 'event_espresso') |
|
| 277 | - . '</span>' |
|
| 278 | - : ''; |
|
| 279 | - echo wp_kses( |
|
| 280 | - $overpaid |
|
| 281 | - . sprintf( |
|
| 282 | - __('Payments Total %s', 'event_espresso'), |
|
| 283 | - '(' . EE_Registry::instance()->CFG->currency->code . ')' |
|
| 284 | - ), |
|
| 285 | - AllowedTags::getAllowedTags() |
|
| 286 | - ); ?></span> |
|
| 274 | + $overpaid = $payment_total > $grand_raw_total |
|
| 275 | + ? '<span id="overpaid">' |
|
| 276 | + . __('This transaction has been overpaid ! ', 'event_espresso') |
|
| 277 | + . '</span>' |
|
| 278 | + : ''; |
|
| 279 | + echo wp_kses( |
|
| 280 | + $overpaid |
|
| 281 | + . sprintf( |
|
| 282 | + __('Payments Total %s', 'event_espresso'), |
|
| 283 | + '(' . EE_Registry::instance()->CFG->currency->code . ')' |
|
| 284 | + ), |
|
| 285 | + AllowedTags::getAllowedTags() |
|
| 286 | + ); ?></span> |
|
| 287 | 287 | </th> |
| 288 | 288 | <th class=" jst-rght"> |
| 289 | 289 | <span id="txn-admin-payment-total" data-total="<?php echo esc_attr($payment_total); ?>"><?php |
| 290 | - echo wp_kses( |
|
| 291 | - EEH_Template::format_currency( |
|
| 292 | - $payment_total, |
|
| 293 | - false, |
|
| 294 | - false |
|
| 295 | - ), |
|
| 296 | - AllowedTags::getAllowedTags() |
|
| 297 | - ); ?></span> |
|
| 290 | + echo wp_kses( |
|
| 291 | + EEH_Template::format_currency( |
|
| 292 | + $payment_total, |
|
| 293 | + false, |
|
| 294 | + false |
|
| 295 | + ), |
|
| 296 | + AllowedTags::getAllowedTags() |
|
| 297 | + ); ?></span> |
|
| 298 | 298 | </th> |
| 299 | 299 | </tr> |
| 300 | 300 | <?php else : ?> |
| 301 | 301 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
| 302 | 302 | <td class=" jst-rght" colspan="10"> |
| 303 | 303 | <span class="important-notice"><?php |
| 304 | - echo wp_kses($no_payment_text, AllowedTags::getAllowedTags()); |
|
| 305 | - ?></span> |
|
| 304 | + echo wp_kses($no_payment_text, AllowedTags::getAllowedTags()); |
|
| 305 | + ?></span> |
|
| 306 | 306 | </td> |
| 307 | 307 | </tr> |
| 308 | 308 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
| 309 | 309 | <th class=" jst-rght" colspan="9"> |
| 310 | 310 | <span id="payments-total-spn"><?php |
| 311 | - echo esc_html__('Payments Total', 'event_espresso'); |
|
| 312 | - ?></span> |
|
| 311 | + echo esc_html__('Payments Total', 'event_espresso'); |
|
| 312 | + ?></span> |
|
| 313 | 313 | </th> |
| 314 | 314 | <th class=" jst-rght"> |
| 315 | 315 | <span id="txn-admin-payment-total" data-total="0"></span> |
@@ -395,14 +395,14 @@ discard block |
||
| 395 | 395 | </span> |
| 396 | 396 | <?php endif; ?> |
| 397 | 397 | <?php |
| 398 | - // Allows extend the fields at actions area. |
|
| 399 | - ob_start(); |
|
| 400 | - do_action( |
|
| 401 | - 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
| 402 | - $can_edit_payments |
|
| 403 | - ); |
|
| 404 | - echo str_replace(['<li', '</li>'], ['<span', '</span>'], ob_get_clean()); |
|
| 405 | - ?> |
|
| 398 | + // Allows extend the fields at actions area. |
|
| 399 | + ob_start(); |
|
| 400 | + do_action( |
|
| 401 | + 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
| 402 | + $can_edit_payments |
|
| 403 | + ); |
|
| 404 | + echo str_replace(['<li', '</li>'], ['<span', '</span>'], ob_get_clean()); |
|
| 405 | + ?> |
|
| 406 | 406 | </div> |
| 407 | 407 | |
| 408 | 408 | <div id="txn-admin-apply-payment-dv" class="txn-admin-payment-option auto-hide" style="display: none;"> |
@@ -418,23 +418,23 @@ discard block |
||
| 418 | 418 | style="display:none;" |
| 419 | 419 | > |
| 420 | 420 | <?php |
| 421 | - printf( |
|
| 422 | - esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 423 | - '<span class="ee-admin-payment-id"></span>', |
|
| 424 | - $txn_nmbr['value'] |
|
| 425 | - ); |
|
| 426 | - ?> |
|
| 421 | + printf( |
|
| 422 | + esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 423 | + '<span class="ee-admin-payment-id"></span>', |
|
| 424 | + $txn_nmbr['value'] |
|
| 425 | + ); |
|
| 426 | + ?> |
|
| 427 | 427 | <span class='dashicons dashicons-money-alt'></span> |
| 428 | 428 | </h2> |
| 429 | 429 | |
| 430 | 430 | <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
| 431 | 431 | <?php |
| 432 | - printf( |
|
| 433 | - esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 434 | - '<span class="ee-admin-payment-id"></span>', |
|
| 435 | - $txn_nmbr['value'] |
|
| 436 | - ); |
|
| 437 | - ?> |
|
| 432 | + printf( |
|
| 433 | + esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 434 | + '<span class="ee-admin-payment-id"></span>', |
|
| 435 | + $txn_nmbr['value'] |
|
| 436 | + ); |
|
| 437 | + ?> |
|
| 438 | 438 | <span class='dashicons dashicons-money-alt'></span> |
| 439 | 439 | </h2> |
| 440 | 440 | |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | style="display:none;" |
| 443 | 443 | > |
| 444 | 444 | <?php |
| 445 | - echo esc_html__('Apply a Refund to Transaction #', 'event_espresso'); |
|
| 446 | - echo esc_html($txn_nmbr['value']); |
|
| 447 | - ?> |
|
| 445 | + echo esc_html__('Apply a Refund to Transaction #', 'event_espresso'); |
|
| 446 | + echo esc_html($txn_nmbr['value']); |
|
| 447 | + ?> |
|
| 448 | 448 | <span class='dashicons dashicons-money-alt'></span> |
| 449 | 449 | </h2> |
| 450 | 450 | |
@@ -558,20 +558,20 @@ discard block |
||
| 558 | 558 | <?php echo esc_attr($selected); ?> |
| 559 | 559 | > |
| 560 | 560 | <?php |
| 561 | - echo esc_html( |
|
| 562 | - sanitize_key($method->admin_desc()) |
|
| 563 | - ? substr($method->admin_desc(), 0, 128) |
|
| 564 | - : $method->admin_name() |
|
| 565 | - ); |
|
| 566 | - ?> |
|
| 561 | + echo esc_html( |
|
| 562 | + sanitize_key($method->admin_desc()) |
|
| 563 | + ? substr($method->admin_desc(), 0, 128) |
|
| 564 | + : $method->admin_name() |
|
| 565 | + ); |
|
| 566 | + ?> |
|
| 567 | 567 | </option> |
| 568 | 568 | <?php endforeach; ?> |
| 569 | 569 | </select> |
| 570 | 570 | <p class="description"> |
| 571 | 571 | <?php esc_html_e( |
| 572 | - 'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
|
| 573 | - 'event_espresso' |
|
| 574 | - ); ?> |
|
| 572 | + 'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
|
| 573 | + 'event_espresso' |
|
| 574 | + ); ?> |
|
| 575 | 575 | </p> |
| 576 | 576 | </div> |
| 577 | 577 | </div> |
@@ -580,9 +580,9 @@ discard block |
||
| 580 | 580 | admin-modal-dialog-row ee-layout-row"> |
| 581 | 581 | <label for="txn-admin-payment-txn-id-chq-nmbr-inp" class=""> |
| 582 | 582 | <?php esc_html_e( |
| 583 | - 'TXN ID / CHQ #', |
|
| 584 | - 'event_espresso' |
|
| 585 | - ); ?> |
|
| 583 | + 'TXN ID / CHQ #', |
|
| 584 | + 'event_espresso' |
|
| 585 | + ); ?> |
|
| 586 | 586 | </label> |
| 587 | 587 | <div class='ee-layout-stack'> |
| 588 | 588 | <input name="txn_admin_payment[txn_id_chq_nmbr]" |
@@ -592,9 +592,9 @@ discard block |
||
| 592 | 592 | /> |
| 593 | 593 | <p class="description"> |
| 594 | 594 | <?php esc_html_e( |
| 595 | - 'The Transaction ID sent back from the payment gateway, or the Cheque #', |
|
| 596 | - 'event_espresso' |
|
| 597 | - ); ?> |
|
| 595 | + 'The Transaction ID sent back from the payment gateway, or the Cheque #', |
|
| 596 | + 'event_espresso' |
|
| 597 | + ); ?> |
|
| 598 | 598 | </p> |
| 599 | 599 | </div> |
| 600 | 600 | </div> |
@@ -612,9 +612,9 @@ discard block |
||
| 612 | 612 | /> |
| 613 | 613 | <p class="description"> |
| 614 | 614 | <?php esc_html_e( |
| 615 | - 'The gateway response string (optional)', |
|
| 616 | - 'event_espresso' |
|
| 617 | - ); ?> |
|
| 615 | + 'The gateway response string (optional)', |
|
| 616 | + 'event_espresso' |
|
| 617 | + ); ?> |
|
| 618 | 618 | </p> |
| 619 | 619 | </div> |
| 620 | 620 | </div> |
@@ -623,9 +623,9 @@ discard block |
||
| 623 | 623 | ee-layout-row"> |
| 624 | 624 | <label for="txn-admin-payment-status-slct" class=""> |
| 625 | 625 | <?php esc_html_e( |
| 626 | - 'Payment Status', |
|
| 627 | - 'event_espresso' |
|
| 628 | - ); ?> |
|
| 626 | + 'Payment Status', |
|
| 627 | + 'event_espresso' |
|
| 628 | + ); ?> |
|
| 629 | 629 | </label> |
| 630 | 630 | <div class='ee-layout-stack'> |
| 631 | 631 | <select name="txn_admin_payment[status]" |
@@ -635,10 +635,10 @@ discard block |
||
| 635 | 635 | > |
| 636 | 636 | <?php foreach ($payment_status as $STS_ID => $STS_code) : ?> |
| 637 | 637 | <?php |
| 638 | - $selected = $STS_ID == 'PAP' |
|
| 639 | - ? 'selected' |
|
| 640 | - : ''; |
|
| 641 | - ?> |
|
| 638 | + $selected = $STS_ID == 'PAP' |
|
| 639 | + ? 'selected' |
|
| 640 | + : ''; |
|
| 641 | + ?> |
|
| 642 | 642 | <option id="payment-status-opt-<?php echo esc_attr($STS_ID); ?>" |
| 643 | 643 | value="<?php echo esc_attr($STS_ID); ?>" |
| 644 | 644 | <?php echo esc_attr($selected); ?> |
@@ -649,10 +649,10 @@ discard block |
||
| 649 | 649 | </select> |
| 650 | 650 | <p class="description"> |
| 651 | 651 | <?php |
| 652 | - esc_html_e( |
|
| 653 | - 'Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
|
| 654 | - 'event_espresso' |
|
| 655 | - ); ?> |
|
| 652 | + esc_html_e( |
|
| 653 | + 'Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
|
| 654 | + 'event_espresso' |
|
| 655 | + ); ?> |
|
| 656 | 656 | </p> |
| 657 | 657 | </div> |
| 658 | 658 | </div> |
@@ -670,9 +670,9 @@ discard block |
||
| 670 | 670 | /> |
| 671 | 671 | <p class="description"> |
| 672 | 672 | <?php esc_html_e( |
| 673 | - 'The Purchase or Sales Order Number if any (optional)', |
|
| 674 | - 'event_espresso' |
|
| 675 | - ); ?> |
|
| 673 | + 'The Purchase or Sales Order Number if any (optional)', |
|
| 674 | + 'event_espresso' |
|
| 675 | + ); ?> |
|
| 676 | 676 | </p> |
| 677 | 677 | </div> |
| 678 | 678 | </div> |
@@ -695,9 +695,9 @@ discard block |
||
| 695 | 695 | /> |
| 696 | 696 | <p class="description"> |
| 697 | 697 | <?php esc_html_e( |
| 698 | - 'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
|
| 699 | - 'event_espresso' |
|
| 700 | - ); ?> |
|
| 698 | + 'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
|
| 699 | + 'event_espresso' |
|
| 700 | + ); ?> |
|
| 701 | 701 | </p> |
| 702 | 702 | </div> |
| 703 | 703 | </div> |
@@ -736,9 +736,9 @@ discard block |
||
| 736 | 736 | <?php echo wp_kses($status_change_select, AllowedTags::getWithFormTags()); ?> |
| 737 | 737 | <p class="description"> |
| 738 | 738 | <?php esc_html_e( |
| 739 | - 'If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
|
| 740 | - 'event_espresso' |
|
| 741 | - ); ?> |
|
| 739 | + 'If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
|
| 740 | + 'event_espresso' |
|
| 741 | + ); ?> |
|
| 742 | 742 | </p> |
| 743 | 743 | </div> |
| 744 | 744 | </div> |
@@ -769,14 +769,14 @@ discard block |
||
| 769 | 769 | <br class="clear-float" /> |
| 770 | 770 | <p class="description"> |
| 771 | 771 | <?php printf( |
| 772 | - esc_html__( |
|
| 773 | - '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.', |
|
| 774 | - 'event_espresso' |
|
| 775 | - ), |
|
| 776 | - '<strong>', |
|
| 777 | - '</strong>', |
|
| 778 | - '<br />' |
|
| 779 | - ); ?> |
|
| 772 | + esc_html__( |
|
| 773 | + '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.', |
|
| 774 | + 'event_espresso' |
|
| 775 | + ), |
|
| 776 | + '<strong>', |
|
| 777 | + '</strong>', |
|
| 778 | + '<br />' |
|
| 779 | + ); ?> |
|
| 780 | 780 | </p> |
| 781 | 781 | </div> |
| 782 | 782 | </div> |
@@ -831,10 +831,10 @@ discard block |
||
| 831 | 831 | style="display:none;" |
| 832 | 832 | > |
| 833 | 833 | <?php printf( |
| 834 | - esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'), |
|
| 835 | - $txn_nmbr['value'] |
|
| 836 | - ); |
|
| 837 | - ?> |
|
| 834 | + esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'), |
|
| 835 | + $txn_nmbr['value'] |
|
| 836 | + ); |
|
| 837 | + ?> |
|
| 838 | 838 | <span class='dashicons dashicons-money-alt'></span> |
| 839 | 839 | </h2> |
| 840 | 840 | |
@@ -873,13 +873,13 @@ discard block |
||
| 873 | 873 | <?php echo wp_kses($delete_status_change_select, AllowedTags::getWithFormTags()); ?> |
| 874 | 874 | <p class="description"> |
| 875 | 875 | <?php printf( |
| 876 | - esc_html__( |
|
| 877 | - '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', |
|
| 878 | - 'event_espresso' |
|
| 879 | - ), |
|
| 880 | - '<strong>', |
|
| 881 | - '</strong>' |
|
| 882 | - ); ?> |
|
| 876 | + esc_html__( |
|
| 877 | + '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', |
|
| 878 | + 'event_espresso' |
|
| 879 | + ), |
|
| 880 | + '<strong>', |
|
| 881 | + '</strong>' |
|
| 882 | + ); ?> |
|
| 883 | 883 | </p> |
| 884 | 884 | </div> |
| 885 | 885 | </div> |
@@ -896,10 +896,10 @@ discard block |
||
| 896 | 896 | /> |
| 897 | 897 | <p class="description"> |
| 898 | 898 | <?php |
| 899 | - esc_html_e( |
|
| 900 | - '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.', |
|
| 901 | - 'event_espresso' |
|
| 902 | - ); ?> |
|
| 899 | + esc_html_e( |
|
| 900 | + '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.', |
|
| 901 | + 'event_espresso' |
|
| 902 | + ); ?> |
|
| 903 | 903 | </p> |
| 904 | 904 | </div> |
| 905 | 905 | </div> |
@@ -927,8 +927,8 @@ discard block |
||
| 927 | 927 | <?php endif; // $grand_raw_total > 0?> |
| 928 | 928 | |
| 929 | 929 | <?php if (WP_DEBUG) { |
| 930 | - $delivered_messages = get_option('EED_Messages__payment', []); |
|
| 931 | - if (isset($delivered_messages[ $TXN_ID ])) { ?> |
|
| 930 | + $delivered_messages = get_option('EED_Messages__payment', []); |
|
| 931 | + if (isset($delivered_messages[ $TXN_ID ])) { ?> |
|
| 932 | 932 | <h4 class="admin-primary-mbox-h4 hdr-has-icon"> |
| 933 | 933 | <?php esc_html_e('Messages Sent to Primary Registrant', 'event_espresso'); ?> |
| 934 | 934 | <span class="dashicons dashicons-email-alt"></span> |
@@ -940,39 +940,39 @@ discard block |
||
| 940 | 940 | <th class="jst-left"><?php esc_html_e('Date & Time', 'event_espresso'); ?></th> |
| 941 | 941 | <th class="jst-left"><?php esc_html_e('Message Type', 'event_espresso'); ?></th> |
| 942 | 942 | <th class="jst-left"><?php esc_html_e( |
| 943 | - 'Payment Status Upon Sending', |
|
| 944 | - 'event_espresso' |
|
| 945 | - ); ?></th> |
|
| 943 | + 'Payment Status Upon Sending', |
|
| 944 | + 'event_espresso' |
|
| 945 | + ); ?></th> |
|
| 946 | 946 | <th class="jst-left"><?php esc_html_e('TXN Status Upon Sending', 'event_espresso'); ?></th> |
| 947 | 947 | </tr> |
| 948 | 948 | </thead> |
| 949 | 949 | <tbody> |
| 950 | 950 | <?php |
| 951 | - foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) : |
|
| 952 | - ?> |
|
| 951 | + foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) : |
|
| 952 | + ?> |
|
| 953 | 953 | <tr> |
| 954 | 954 | <td class="jst-left"> |
| 955 | 955 | <?php echo esc_html( |
| 956 | - date( |
|
| 957 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 958 | - ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 959 | - ) |
|
| 960 | - ); ?> |
|
| 956 | + date( |
|
| 957 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 958 | + ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 959 | + ) |
|
| 960 | + ); ?> |
|
| 961 | 961 | </td> |
| 962 | 962 | <td class="jst-left"><?php |
| 963 | - echo isset($delivered_message['message_type']) |
|
| 964 | - ? esc_html($delivered_message['message_type']) |
|
| 965 | - : ''; ?> |
|
| 963 | + echo isset($delivered_message['message_type']) |
|
| 964 | + ? esc_html($delivered_message['message_type']) |
|
| 965 | + : ''; ?> |
|
| 966 | 966 | </td> |
| 967 | 967 | <td class="jst-left"><?php |
| 968 | - echo isset($delivered_message['pay_status']) |
|
| 969 | - ? esc_html($delivered_message['pay_status']) |
|
| 970 | - : ''; ?> |
|
| 968 | + echo isset($delivered_message['pay_status']) |
|
| 969 | + ? esc_html($delivered_message['pay_status']) |
|
| 970 | + : ''; ?> |
|
| 971 | 971 | </td> |
| 972 | 972 | <td class="jst-left"><?php |
| 973 | - echo isset($delivered_message['txn_status']) |
|
| 974 | - ? esc_html($delivered_message['txn_status']) |
|
| 975 | - : ''; ?> |
|
| 973 | + echo isset($delivered_message['txn_status']) |
|
| 974 | + ? esc_html($delivered_message['txn_status']) |
|
| 975 | + : ''; ?> |
|
| 976 | 976 | </td> |
| 977 | 977 | </tr> |
| 978 | 978 | <?php endforeach; // $delivered_messages?> |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | </table> |
| 981 | 981 | </div> |
| 982 | 982 | <?php |
| 983 | - } |
|
| 984 | - } |
|
| 985 | - ?> |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + ?> |
|
| 986 | 986 | </div> |
@@ -16,148 +16,148 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Payments_Admin_Page_Init extends EE_Admin_Page_Init |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var TableAnalysis $table_analysis |
|
| 21 | - */ |
|
| 22 | - protected $_table_analysis; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @throws EE_Error |
|
| 27 | - * @throws ReflectionException |
|
| 28 | - */ |
|
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - // define some page related constants |
|
| 32 | - if (! defined('EE_PAYMENTS_PG_SLUG')) { |
|
| 33 | - define('EE_PAYMENTS_PG_SLUG', 'espresso_payment_settings'); |
|
| 34 | - define('EE_PAYMENTS_ADMIN_URL', admin_url('admin.php?page=' . EE_PAYMENTS_PG_SLUG)); |
|
| 35 | - define('EE_PAYMENTS_ADMIN', EE_ADMIN_PAGES . 'payments/'); |
|
| 36 | - define('EE_PAYMENTS_TEMPLATE_PATH', EE_PAYMENTS_ADMIN . 'templates/'); |
|
| 37 | - define('EE_PAYMENTS_ASSETS_URL', EE_ADMIN_PAGES_URL . 'payments/assets/'); |
|
| 38 | - } |
|
| 39 | - $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
| 40 | - // check that there are active gateways on all admin page loads. but don't do it just yet |
|
| 41 | - add_action('admin_notices', [$this, 'check_payment_gateway_setup']); |
|
| 42 | - |
|
| 43 | - // Show/hide PP Standard alongside PP Express. |
|
| 44 | - add_filter( |
|
| 45 | - 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
| 46 | - [$this, 'unset_pp_standard'] |
|
| 47 | - ); |
|
| 48 | - |
|
| 49 | - parent::__construct(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - protected function _set_init_properties() |
|
| 54 | - { |
|
| 55 | - $this->label = esc_html__('Payment Methods', 'event_espresso'); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - public function getMenuProperties(): array |
|
| 60 | - { |
|
| 61 | - return [ |
|
| 62 | - 'menu_type' => AdminMenuItem::TYPE_MENU_SUB_ITEM, |
|
| 63 | - 'menu_group' => 'settings', |
|
| 64 | - 'menu_order' => 30, |
|
| 65 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 66 | - 'parent_slug' => 'espresso_events', |
|
| 67 | - 'menu_slug' => EE_PAYMENTS_PG_SLUG, |
|
| 68 | - 'menu_label' => esc_html__('Payment Methods', 'event_espresso'), |
|
| 69 | - 'capability' => 'ee_manage_gateways', |
|
| 70 | - ]; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Checks that there is at least one active gateway. If not, add a notice |
|
| 76 | - * |
|
| 77 | - * @throws EE_Error |
|
| 78 | - * @throws ReflectionException |
|
| 79 | - */ |
|
| 80 | - public function check_payment_gateway_setup() |
|
| 81 | - { |
|
| 82 | - // ONLY do this check if models can query |
|
| 83 | - // and avoid a bug where when we nuke EE4's data that this causes a fatal error |
|
| 84 | - // because the tables are deleted just before this request runs. |
|
| 85 | - // see https://events.codebasehq.com/projects/event-espresso/tickets/7539 |
|
| 86 | - if ( |
|
| 87 | - DbStatus::isOffline() |
|
| 88 | - || ! $this->_get_table_analysis()->tableExists(EEM_Payment_Method::instance()->table()) |
|
| 89 | - ) { |
|
| 90 | - return; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $actives = EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart); |
|
| 94 | - if ($actives < 1) { |
|
| 95 | - $url = EE_Admin_Page::add_query_args_and_nonce([], EE_PAYMENTS_ADMIN_URL); |
|
| 96 | - echo '<div class="error"> |
|
| 19 | + /** |
|
| 20 | + * @var TableAnalysis $table_analysis |
|
| 21 | + */ |
|
| 22 | + protected $_table_analysis; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @throws EE_Error |
|
| 27 | + * @throws ReflectionException |
|
| 28 | + */ |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + // define some page related constants |
|
| 32 | + if (! defined('EE_PAYMENTS_PG_SLUG')) { |
|
| 33 | + define('EE_PAYMENTS_PG_SLUG', 'espresso_payment_settings'); |
|
| 34 | + define('EE_PAYMENTS_ADMIN_URL', admin_url('admin.php?page=' . EE_PAYMENTS_PG_SLUG)); |
|
| 35 | + define('EE_PAYMENTS_ADMIN', EE_ADMIN_PAGES . 'payments/'); |
|
| 36 | + define('EE_PAYMENTS_TEMPLATE_PATH', EE_PAYMENTS_ADMIN . 'templates/'); |
|
| 37 | + define('EE_PAYMENTS_ASSETS_URL', EE_ADMIN_PAGES_URL . 'payments/assets/'); |
|
| 38 | + } |
|
| 39 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
| 40 | + // check that there are active gateways on all admin page loads. but don't do it just yet |
|
| 41 | + add_action('admin_notices', [$this, 'check_payment_gateway_setup']); |
|
| 42 | + |
|
| 43 | + // Show/hide PP Standard alongside PP Express. |
|
| 44 | + add_filter( |
|
| 45 | + 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
| 46 | + [$this, 'unset_pp_standard'] |
|
| 47 | + ); |
|
| 48 | + |
|
| 49 | + parent::__construct(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + protected function _set_init_properties() |
|
| 54 | + { |
|
| 55 | + $this->label = esc_html__('Payment Methods', 'event_espresso'); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + public function getMenuProperties(): array |
|
| 60 | + { |
|
| 61 | + return [ |
|
| 62 | + 'menu_type' => AdminMenuItem::TYPE_MENU_SUB_ITEM, |
|
| 63 | + 'menu_group' => 'settings', |
|
| 64 | + 'menu_order' => 30, |
|
| 65 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 66 | + 'parent_slug' => 'espresso_events', |
|
| 67 | + 'menu_slug' => EE_PAYMENTS_PG_SLUG, |
|
| 68 | + 'menu_label' => esc_html__('Payment Methods', 'event_espresso'), |
|
| 69 | + 'capability' => 'ee_manage_gateways', |
|
| 70 | + ]; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Checks that there is at least one active gateway. If not, add a notice |
|
| 76 | + * |
|
| 77 | + * @throws EE_Error |
|
| 78 | + * @throws ReflectionException |
|
| 79 | + */ |
|
| 80 | + public function check_payment_gateway_setup() |
|
| 81 | + { |
|
| 82 | + // ONLY do this check if models can query |
|
| 83 | + // and avoid a bug where when we nuke EE4's data that this causes a fatal error |
|
| 84 | + // because the tables are deleted just before this request runs. |
|
| 85 | + // see https://events.codebasehq.com/projects/event-espresso/tickets/7539 |
|
| 86 | + if ( |
|
| 87 | + DbStatus::isOffline() |
|
| 88 | + || ! $this->_get_table_analysis()->tableExists(EEM_Payment_Method::instance()->table()) |
|
| 89 | + ) { |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $actives = EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart); |
|
| 94 | + if ($actives < 1) { |
|
| 95 | + $url = EE_Admin_Page::add_query_args_and_nonce([], EE_PAYMENTS_ADMIN_URL); |
|
| 96 | + echo '<div class="error"> |
|
| 97 | 97 | <p>' |
| 98 | - . sprintf( |
|
| 99 | - esc_html__( |
|
| 100 | - "There are no Active Payment Methods setup for Event Espresso. Please %s activate at least one.%s", |
|
| 101 | - "event_espresso" |
|
| 102 | - ), |
|
| 103 | - "<a href='$url'>", |
|
| 104 | - "</a>" |
|
| 105 | - ) |
|
| 106 | - . '</p> |
|
| 98 | + . sprintf( |
|
| 99 | + esc_html__( |
|
| 100 | + "There are no Active Payment Methods setup for Event Espresso. Please %s activate at least one.%s", |
|
| 101 | + "event_espresso" |
|
| 102 | + ), |
|
| 103 | + "<a href='$url'>", |
|
| 104 | + "</a>" |
|
| 105 | + ) |
|
| 106 | + . '</p> |
|
| 107 | 107 | </div>'; |
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Gets the injected table analyzer, or throws an exception |
|
| 114 | - * |
|
| 115 | - * @return TableAnalysis |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - protected function _get_table_analysis() |
|
| 119 | - { |
|
| 120 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 121 | - return $this->_table_analysis; |
|
| 122 | - } else { |
|
| 123 | - throw new EE_Error( |
|
| 124 | - sprintf( |
|
| 125 | - esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 126 | - get_class($this) |
|
| 127 | - ) |
|
| 128 | - ); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Hide PayPal Standard for "new" users. |
|
| 135 | - * |
|
| 136 | - * @throws EE_Error |
|
| 137 | - * @throws ReflectionException |
|
| 138 | - */ |
|
| 139 | - public static function unset_pp_standard($payment_method_types) |
|
| 140 | - { |
|
| 141 | - $pps = EEM_Payment_Method::instance()->get_one_of_type('Paypal_Standard'); |
|
| 142 | - $paypal_standard_active = ! empty($pps) && $pps->active(); |
|
| 143 | - $paypal_standard_active_before = false; |
|
| 144 | - if ($pps) { |
|
| 145 | - // PP Standard used before ? |
|
| 146 | - $paypal_id = $pps->get_extra_meta('paypal_id', true); |
|
| 147 | - if ($paypal_id && ! empty($paypal_id)) { |
|
| 148 | - $paypal_standard_active_before = true; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Not using PP Standard? Then display only PayPal Express, do not show PayPal Standard. |
|
| 153 | - if ( |
|
| 154 | - apply_filters( |
|
| 155 | - 'FHEE__EE_PMT_Paypal_Express__register_payment_methods__hide_paypal_standard', |
|
| 156 | - ! $paypal_standard_active && ! $paypal_standard_active_before |
|
| 157 | - ) |
|
| 158 | - ) { |
|
| 159 | - unset($payment_method_types['paypal_standard']); |
|
| 160 | - } |
|
| 161 | - return $payment_method_types; |
|
| 162 | - } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Gets the injected table analyzer, or throws an exception |
|
| 114 | + * |
|
| 115 | + * @return TableAnalysis |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + protected function _get_table_analysis() |
|
| 119 | + { |
|
| 120 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 121 | + return $this->_table_analysis; |
|
| 122 | + } else { |
|
| 123 | + throw new EE_Error( |
|
| 124 | + sprintf( |
|
| 125 | + esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 126 | + get_class($this) |
|
| 127 | + ) |
|
| 128 | + ); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Hide PayPal Standard for "new" users. |
|
| 135 | + * |
|
| 136 | + * @throws EE_Error |
|
| 137 | + * @throws ReflectionException |
|
| 138 | + */ |
|
| 139 | + public static function unset_pp_standard($payment_method_types) |
|
| 140 | + { |
|
| 141 | + $pps = EEM_Payment_Method::instance()->get_one_of_type('Paypal_Standard'); |
|
| 142 | + $paypal_standard_active = ! empty($pps) && $pps->active(); |
|
| 143 | + $paypal_standard_active_before = false; |
|
| 144 | + if ($pps) { |
|
| 145 | + // PP Standard used before ? |
|
| 146 | + $paypal_id = $pps->get_extra_meta('paypal_id', true); |
|
| 147 | + if ($paypal_id && ! empty($paypal_id)) { |
|
| 148 | + $paypal_standard_active_before = true; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Not using PP Standard? Then display only PayPal Express, do not show PayPal Standard. |
|
| 153 | + if ( |
|
| 154 | + apply_filters( |
|
| 155 | + 'FHEE__EE_PMT_Paypal_Express__register_payment_methods__hide_paypal_standard', |
|
| 156 | + ! $paypal_standard_active && ! $paypal_standard_active_before |
|
| 157 | + ) |
|
| 158 | + ) { |
|
| 159 | + unset($payment_method_types['paypal_standard']); |
|
| 160 | + } |
|
| 161 | + return $payment_method_types; |
|
| 162 | + } |
|
| 163 | 163 | } |
@@ -11,115 +11,115 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class Payment_Log_Admin_List_Table extends EE_Admin_List_Table |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var Payments_Admin_Page $_admin_page |
|
| 16 | - */ |
|
| 17 | - protected EE_Admin_Page $_admin_page; |
|
| 14 | + /** |
|
| 15 | + * @var Payments_Admin_Page $_admin_page |
|
| 16 | + */ |
|
| 17 | + protected EE_Admin_Page $_admin_page; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param EE_Admin_Page $admin_page |
|
| 22 | - */ |
|
| 23 | - public function __construct($admin_page) |
|
| 24 | - { |
|
| 25 | - parent::__construct($admin_page); |
|
| 26 | - } |
|
| 20 | + /** |
|
| 21 | + * @param EE_Admin_Page $admin_page |
|
| 22 | + */ |
|
| 23 | + public function __construct($admin_page) |
|
| 24 | + { |
|
| 25 | + parent::__construct($admin_page); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * _setup_data |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - protected function _setup_data() |
|
| 35 | - { |
|
| 36 | - $this->_data = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page); |
|
| 37 | - // if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'trash') { |
|
| 38 | - // $this->_data = $this->_admin_page->get_trashed_questions($this->_per_page, $this->_current_page, false); |
|
| 39 | - // } else { |
|
| 40 | - // $this->_data = $this->_admin_page->get_questions($this->_per_page, $this->_current_page, false); |
|
| 41 | - // } |
|
| 42 | - $this->_all_data_count = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
| 43 | - add_action( |
|
| 44 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 45 | - [$this, 'add_download_logs_checkbox'] |
|
| 46 | - ); |
|
| 47 | - } |
|
| 29 | + /** |
|
| 30 | + * _setup_data |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + protected function _setup_data() |
|
| 35 | + { |
|
| 36 | + $this->_data = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page); |
|
| 37 | + // if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'trash') { |
|
| 38 | + // $this->_data = $this->_admin_page->get_trashed_questions($this->_per_page, $this->_current_page, false); |
|
| 39 | + // } else { |
|
| 40 | + // $this->_data = $this->_admin_page->get_questions($this->_per_page, $this->_current_page, false); |
|
| 41 | + // } |
|
| 42 | + $this->_all_data_count = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
| 43 | + add_action( |
|
| 44 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 45 | + [$this, 'add_download_logs_checkbox'] |
|
| 46 | + ); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * add_download_logs_checkbox |
|
| 52 | - * adds a checkbox to the bottom of the list table, instead of at the top with the rest of the filters |
|
| 53 | - * |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function add_download_logs_checkbox() |
|
| 57 | - { |
|
| 58 | - echo "<input type='submit' class='button--primary' id='download_results' name='download_results' value='" |
|
| 59 | - . esc_html__('Download Results', 'event_espresso') . "'>"; |
|
| 60 | - } |
|
| 50 | + /** |
|
| 51 | + * add_download_logs_checkbox |
|
| 52 | + * adds a checkbox to the bottom of the list table, instead of at the top with the rest of the filters |
|
| 53 | + * |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function add_download_logs_checkbox() |
|
| 57 | + { |
|
| 58 | + echo "<input type='submit' class='button--primary' id='download_results' name='download_results' value='" |
|
| 59 | + . esc_html__('Download Results', 'event_espresso') . "'>"; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * _set_properties |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - protected function _set_properties() |
|
| 69 | - { |
|
| 70 | - $this->_wp_list_args = [ |
|
| 71 | - 'singular' => esc_html__('payment log', 'event_espresso'), |
|
| 72 | - 'plural' => esc_html__('payment logs', 'event_espresso'), |
|
| 73 | - 'ajax' => true, // for now, |
|
| 74 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 75 | - ]; |
|
| 76 | - $this->_columns = [ |
|
| 77 | - 'cb' => '<input type="checkbox" />', |
|
| 78 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 79 | - 'LOG_time' => esc_html__('Time', 'event_espresso'), |
|
| 80 | - 'PMD_ID' => esc_html__('Payment Method', 'event_espresso'), |
|
| 81 | - 'TXN_ID' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 82 | - ]; |
|
| 83 | - $this->_sortable_columns = [ |
|
| 84 | - 'LOG_time' => ['LOG_time' => true], |
|
| 85 | - ]; |
|
| 86 | - $this->_hidden_columns = []; |
|
| 87 | - } |
|
| 63 | + /** |
|
| 64 | + * _set_properties |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + protected function _set_properties() |
|
| 69 | + { |
|
| 70 | + $this->_wp_list_args = [ |
|
| 71 | + 'singular' => esc_html__('payment log', 'event_espresso'), |
|
| 72 | + 'plural' => esc_html__('payment logs', 'event_espresso'), |
|
| 73 | + 'ajax' => true, // for now, |
|
| 74 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 75 | + ]; |
|
| 76 | + $this->_columns = [ |
|
| 77 | + 'cb' => '<input type="checkbox" />', |
|
| 78 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 79 | + 'LOG_time' => esc_html__('Time', 'event_espresso'), |
|
| 80 | + 'PMD_ID' => esc_html__('Payment Method', 'event_espresso'), |
|
| 81 | + 'TXN_ID' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 82 | + ]; |
|
| 83 | + $this->_sortable_columns = [ |
|
| 84 | + 'LOG_time' => ['LOG_time' => true], |
|
| 85 | + ]; |
|
| 86 | + $this->_hidden_columns = []; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * _get_table_filters |
|
| 92 | - * |
|
| 93 | - * @return array |
|
| 94 | - * @throws EE_Error |
|
| 95 | - * @throws ReflectionException |
|
| 96 | - */ |
|
| 97 | - protected function _get_table_filters() |
|
| 98 | - { |
|
| 99 | - $filters = []; |
|
| 100 | - // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
| 101 | - /** @var EE_Payment_Method[] $payment_methods */ |
|
| 102 | - $payment_methods = EEM_Payment_Method::instance()->get_all(); |
|
| 103 | - $payment_method_names = [ |
|
| 104 | - ['id' => 'all', 'text' => esc_html__("All", 'event_espresso')], |
|
| 105 | - ['id' => '0', 'text' => esc_html__("Unknown Payment Method", 'event_espresso')], |
|
| 106 | - ]; |
|
| 107 | - foreach ($payment_methods as $payment_method) { |
|
| 108 | - $payment_method_names[] = ['id' => $payment_method->ID(), 'text' => $payment_method->admin_name()]; |
|
| 109 | - } |
|
| 110 | - $filters[] = EEH_Form_Fields::select_input( |
|
| 111 | - '_payment_method', |
|
| 112 | - $payment_method_names, |
|
| 113 | - $this->_req_data['_payment_method'] ?? 'all' |
|
| 114 | - ); |
|
| 115 | - $start_date = isset($this->_req_data['payment-filter-start-date']) |
|
| 116 | - ? wp_strip_all_tags($this->_req_data['payment-filter-start-date']) |
|
| 117 | - : date('m/d/Y', strtotime('-6 months')); |
|
| 118 | - $end_date = isset($this->_req_data['payment-filter-end-date']) |
|
| 119 | - ? wp_strip_all_tags($this->_req_data['payment-filter-end-date']) |
|
| 120 | - : date('m/d/Y'); |
|
| 121 | - ob_start(); |
|
| 122 | - ?> |
|
| 90 | + /** |
|
| 91 | + * _get_table_filters |
|
| 92 | + * |
|
| 93 | + * @return array |
|
| 94 | + * @throws EE_Error |
|
| 95 | + * @throws ReflectionException |
|
| 96 | + */ |
|
| 97 | + protected function _get_table_filters() |
|
| 98 | + { |
|
| 99 | + $filters = []; |
|
| 100 | + // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
| 101 | + /** @var EE_Payment_Method[] $payment_methods */ |
|
| 102 | + $payment_methods = EEM_Payment_Method::instance()->get_all(); |
|
| 103 | + $payment_method_names = [ |
|
| 104 | + ['id' => 'all', 'text' => esc_html__("All", 'event_espresso')], |
|
| 105 | + ['id' => '0', 'text' => esc_html__("Unknown Payment Method", 'event_espresso')], |
|
| 106 | + ]; |
|
| 107 | + foreach ($payment_methods as $payment_method) { |
|
| 108 | + $payment_method_names[] = ['id' => $payment_method->ID(), 'text' => $payment_method->admin_name()]; |
|
| 109 | + } |
|
| 110 | + $filters[] = EEH_Form_Fields::select_input( |
|
| 111 | + '_payment_method', |
|
| 112 | + $payment_method_names, |
|
| 113 | + $this->_req_data['_payment_method'] ?? 'all' |
|
| 114 | + ); |
|
| 115 | + $start_date = isset($this->_req_data['payment-filter-start-date']) |
|
| 116 | + ? wp_strip_all_tags($this->_req_data['payment-filter-start-date']) |
|
| 117 | + : date('m/d/Y', strtotime('-6 months')); |
|
| 118 | + $end_date = isset($this->_req_data['payment-filter-end-date']) |
|
| 119 | + ? wp_strip_all_tags($this->_req_data['payment-filter-end-date']) |
|
| 120 | + : date('m/d/Y'); |
|
| 121 | + ob_start(); |
|
| 122 | + ?> |
|
| 123 | 123 | <label for="payment-filter-start-date"> |
| 124 | 124 | <?php esc_html_e('Display Transactions from ', 'event_espresso'); ?> |
| 125 | 125 | </label> |
@@ -141,157 +141,157 @@ discard block |
||
| 141 | 141 | size="15" |
| 142 | 142 | /> |
| 143 | 143 | <?php |
| 144 | - $filters[] = ob_get_clean(); |
|
| 145 | - return $filters; |
|
| 146 | - } |
|
| 144 | + $filters[] = ob_get_clean(); |
|
| 145 | + return $filters; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * _add_view_counts |
|
| 151 | - * |
|
| 152 | - * @return void |
|
| 153 | - */ |
|
| 154 | - protected function _add_view_counts() |
|
| 155 | - { |
|
| 156 | - $this->_views['all']['count'] = $this->_admin_page->get_payment_logs( |
|
| 157 | - $this->_per_page, |
|
| 158 | - $this->_current_page, |
|
| 159 | - true |
|
| 160 | - ); |
|
| 161 | - } |
|
| 149 | + /** |
|
| 150 | + * _add_view_counts |
|
| 151 | + * |
|
| 152 | + * @return void |
|
| 153 | + */ |
|
| 154 | + protected function _add_view_counts() |
|
| 155 | + { |
|
| 156 | + $this->_views['all']['count'] = $this->_admin_page->get_payment_logs( |
|
| 157 | + $this->_per_page, |
|
| 158 | + $this->_current_page, |
|
| 159 | + true |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * column_cb |
|
| 166 | - * |
|
| 167 | - * @param EE_Change_Log $item |
|
| 168 | - * @return string |
|
| 169 | - * @throws EE_Error |
|
| 170 | - * @throws ReflectionException |
|
| 171 | - */ |
|
| 172 | - public function column_cb($item) |
|
| 173 | - { |
|
| 174 | - return sprintf('<input type="checkbox" class="option_id" name="checkbox[%1$d]" value="%1$d" />', $item->ID()); |
|
| 175 | - } |
|
| 164 | + /** |
|
| 165 | + * column_cb |
|
| 166 | + * |
|
| 167 | + * @param EE_Change_Log $item |
|
| 168 | + * @return string |
|
| 169 | + * @throws EE_Error |
|
| 170 | + * @throws ReflectionException |
|
| 171 | + */ |
|
| 172 | + public function column_cb($item) |
|
| 173 | + { |
|
| 174 | + return sprintf('<input type="checkbox" class="option_id" name="checkbox[%1$d]" value="%1$d" />', $item->ID()); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * column_id |
|
| 180 | - * |
|
| 181 | - * @param EE_Change_Log $item |
|
| 182 | - * @return string |
|
| 183 | - * @throws EE_Error |
|
| 184 | - * @throws ReflectionException |
|
| 185 | - */ |
|
| 186 | - public function column_id(EE_Change_Log $item) |
|
| 187 | - { |
|
| 188 | - $ID = absint($item->ID()); |
|
| 189 | - $url = esc_url_raw( |
|
| 190 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 191 | - [ |
|
| 192 | - 'action' => 'payment_log_details', |
|
| 193 | - 'ID' => $ID, |
|
| 194 | - ], |
|
| 195 | - EE_PAYMENTS_ADMIN_URL |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - $label = esc_attr__('View Payment Log Details', 'event_espresso'); |
|
| 199 | - $payment_log = "<a class='ee-aria-tooltip' aria-label='{$label}' href='$url'>{$ID}</a>"; |
|
| 200 | - $content = ' |
|
| 178 | + /** |
|
| 179 | + * column_id |
|
| 180 | + * |
|
| 181 | + * @param EE_Change_Log $item |
|
| 182 | + * @return string |
|
| 183 | + * @throws EE_Error |
|
| 184 | + * @throws ReflectionException |
|
| 185 | + */ |
|
| 186 | + public function column_id(EE_Change_Log $item) |
|
| 187 | + { |
|
| 188 | + $ID = absint($item->ID()); |
|
| 189 | + $url = esc_url_raw( |
|
| 190 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 191 | + [ |
|
| 192 | + 'action' => 'payment_log_details', |
|
| 193 | + 'ID' => $ID, |
|
| 194 | + ], |
|
| 195 | + EE_PAYMENTS_ADMIN_URL |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + $label = esc_attr__('View Payment Log Details', 'event_espresso'); |
|
| 199 | + $payment_log = "<a class='ee-aria-tooltip' aria-label='{$label}' href='$url'>{$ID}</a>"; |
|
| 200 | + $content = ' |
|
| 201 | 201 | <span class="ee-entity-id">' . $payment_log . '</span> |
| 202 | 202 | <span class="show-on-mobile-view-only"> |
| 203 | 203 | <span>' . $this->column_LOG_time($item, false) . '</span> |
| 204 | 204 | |
| 205 | 205 | <span>' . $this->column_PMD_ID($item, false) . '</span> |
| 206 | 206 | </span>'; |
| 207 | - return $this->columnContent('id', $content, 'end'); |
|
| 208 | - } |
|
| 207 | + return $this->columnContent('id', $content, 'end'); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * column_LOG_time |
|
| 213 | - * |
|
| 214 | - * @param EE_Change_Log $item |
|
| 215 | - * @param bool $prep_content |
|
| 216 | - * @return string |
|
| 217 | - * @throws EE_Error |
|
| 218 | - * @throws ReflectionException |
|
| 219 | - */ |
|
| 220 | - public function column_LOG_time(EE_Change_Log $item, bool $prep_content = true): string |
|
| 221 | - { |
|
| 222 | - $content = $item->get_datetime('LOG_time'); |
|
| 223 | - return $prep_content ? $this->columnContent('LOG_time', $content) : $content; |
|
| 224 | - } |
|
| 211 | + /** |
|
| 212 | + * column_LOG_time |
|
| 213 | + * |
|
| 214 | + * @param EE_Change_Log $item |
|
| 215 | + * @param bool $prep_content |
|
| 216 | + * @return string |
|
| 217 | + * @throws EE_Error |
|
| 218 | + * @throws ReflectionException |
|
| 219 | + */ |
|
| 220 | + public function column_LOG_time(EE_Change_Log $item, bool $prep_content = true): string |
|
| 221 | + { |
|
| 222 | + $content = $item->get_datetime('LOG_time'); |
|
| 223 | + return $prep_content ? $this->columnContent('LOG_time', $content) : $content; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * column_PMD_ID |
|
| 229 | - * |
|
| 230 | - * @param EE_Change_Log $item |
|
| 231 | - * @param bool $prep_content |
|
| 232 | - * @return string |
|
| 233 | - * @throws EE_Error |
|
| 234 | - */ |
|
| 235 | - public function column_PMD_ID(EE_Change_Log $item, bool $prep_content = true): string |
|
| 236 | - { |
|
| 237 | - $object = $item->object(); |
|
| 238 | - if ($object instanceof EE_Payment_Method) { |
|
| 239 | - $content = $object->admin_name(); |
|
| 240 | - } elseif ( |
|
| 241 | - $object instanceof EE_Payment |
|
| 242 | - && $object->payment_method() instanceof EE_Payment_Method |
|
| 243 | - ) { |
|
| 244 | - $content = $object->payment_method()->admin_name(); |
|
| 245 | - } elseif ($object instanceof EE_Transaction) { |
|
| 246 | - $content = esc_html__('Unknown', 'event_espresso'); |
|
| 247 | - } else { |
|
| 248 | - $content = esc_html__('No longer exists', 'event_espresso'); |
|
| 249 | - } |
|
| 250 | - return $prep_content ? $this->columnContent('PMD_ID', $content) : $content; |
|
| 251 | - } |
|
| 227 | + /** |
|
| 228 | + * column_PMD_ID |
|
| 229 | + * |
|
| 230 | + * @param EE_Change_Log $item |
|
| 231 | + * @param bool $prep_content |
|
| 232 | + * @return string |
|
| 233 | + * @throws EE_Error |
|
| 234 | + */ |
|
| 235 | + public function column_PMD_ID(EE_Change_Log $item, bool $prep_content = true): string |
|
| 236 | + { |
|
| 237 | + $object = $item->object(); |
|
| 238 | + if ($object instanceof EE_Payment_Method) { |
|
| 239 | + $content = $object->admin_name(); |
|
| 240 | + } elseif ( |
|
| 241 | + $object instanceof EE_Payment |
|
| 242 | + && $object->payment_method() instanceof EE_Payment_Method |
|
| 243 | + ) { |
|
| 244 | + $content = $object->payment_method()->admin_name(); |
|
| 245 | + } elseif ($object instanceof EE_Transaction) { |
|
| 246 | + $content = esc_html__('Unknown', 'event_espresso'); |
|
| 247 | + } else { |
|
| 248 | + $content = esc_html__('No longer exists', 'event_espresso'); |
|
| 249 | + } |
|
| 250 | + return $prep_content ? $this->columnContent('PMD_ID', $content) : $content; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * column_TXN_ID |
|
| 256 | - * |
|
| 257 | - * @param EE_Change_Log $item |
|
| 258 | - * @return string |
|
| 259 | - * @throws EE_Error |
|
| 260 | - * @throws ReflectionException |
|
| 261 | - */ |
|
| 262 | - public function column_TXN_ID(EE_Change_Log $item): string |
|
| 263 | - { |
|
| 264 | - $object = $item->object(); |
|
| 265 | - if ($object instanceof EE_Payment) { |
|
| 266 | - $transaction_id = $object->TXN_ID(); |
|
| 267 | - } elseif ($object instanceof EE_Transaction) { |
|
| 268 | - $transaction_id = $object->ID(); |
|
| 269 | - } else { |
|
| 270 | - $transaction_id = null; |
|
| 271 | - } |
|
| 272 | - if ( |
|
| 273 | - $transaction_id |
|
| 274 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 275 | - 'ee_read_transaction', |
|
| 276 | - 'espresso_transactions_view_transaction', |
|
| 277 | - $transaction_id |
|
| 278 | - ) |
|
| 279 | - ) { |
|
| 280 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 281 | - ['action' => 'view_transaction', 'TXN_ID' => $transaction_id], |
|
| 282 | - TXN_ADMIN_URL |
|
| 283 | - ); |
|
| 284 | - $content = '<a href="' . esc_url_raw($view_txn_lnk_url) . '" ' |
|
| 285 | - . 'aria-label="' . sprintf( |
|
| 286 | - esc_attr__('click to view transaction #%s', 'event_espresso'), |
|
| 287 | - $transaction_id |
|
| 288 | - ) . '">' |
|
| 289 | - . sprintf(esc_html__('view txn %s', 'event_espresso'), $transaction_id) |
|
| 290 | - . '</a>'; |
|
| 291 | - } else { |
|
| 292 | - // No transaction id or use can not view the transaction. |
|
| 293 | - $content = esc_html__('Unable to find transaction', 'event_espresso'); |
|
| 294 | - } |
|
| 295 | - return $this->columnContent('TXN_ID', $content); |
|
| 296 | - } |
|
| 254 | + /** |
|
| 255 | + * column_TXN_ID |
|
| 256 | + * |
|
| 257 | + * @param EE_Change_Log $item |
|
| 258 | + * @return string |
|
| 259 | + * @throws EE_Error |
|
| 260 | + * @throws ReflectionException |
|
| 261 | + */ |
|
| 262 | + public function column_TXN_ID(EE_Change_Log $item): string |
|
| 263 | + { |
|
| 264 | + $object = $item->object(); |
|
| 265 | + if ($object instanceof EE_Payment) { |
|
| 266 | + $transaction_id = $object->TXN_ID(); |
|
| 267 | + } elseif ($object instanceof EE_Transaction) { |
|
| 268 | + $transaction_id = $object->ID(); |
|
| 269 | + } else { |
|
| 270 | + $transaction_id = null; |
|
| 271 | + } |
|
| 272 | + if ( |
|
| 273 | + $transaction_id |
|
| 274 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 275 | + 'ee_read_transaction', |
|
| 276 | + 'espresso_transactions_view_transaction', |
|
| 277 | + $transaction_id |
|
| 278 | + ) |
|
| 279 | + ) { |
|
| 280 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 281 | + ['action' => 'view_transaction', 'TXN_ID' => $transaction_id], |
|
| 282 | + TXN_ADMIN_URL |
|
| 283 | + ); |
|
| 284 | + $content = '<a href="' . esc_url_raw($view_txn_lnk_url) . '" ' |
|
| 285 | + . 'aria-label="' . sprintf( |
|
| 286 | + esc_attr__('click to view transaction #%s', 'event_espresso'), |
|
| 287 | + $transaction_id |
|
| 288 | + ) . '">' |
|
| 289 | + . sprintf(esc_html__('view txn %s', 'event_espresso'), $transaction_id) |
|
| 290 | + . '</a>'; |
|
| 291 | + } else { |
|
| 292 | + // No transaction id or use can not view the transaction. |
|
| 293 | + $content = esc_html__('Unable to find transaction', 'event_espresso'); |
|
| 294 | + } |
|
| 295 | + return $this->columnContent('TXN_ID', $content); |
|
| 296 | + } |
|
| 297 | 297 | } |
@@ -18,2950 +18,2950 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * primary key for the event model |
|
| 23 | - */ |
|
| 24 | - private int $EVT_ID = 0; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * This will hold the event object for event_details screen. |
|
| 28 | - * |
|
| 29 | - * @var EE_Event|null $_event |
|
| 30 | - */ |
|
| 31 | - protected ?EE_Event $_event = null; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This will hold the category object for category_details screen. |
|
| 35 | - */ |
|
| 36 | - protected ?stdClass $_category = null; |
|
| 37 | - |
|
| 38 | - protected ?EEM_Event $_event_model = null; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var EE_Event|EE_CPT_Base|null $_cpt_model_obj |
|
| 42 | - */ |
|
| 43 | - protected $_cpt_model_obj; |
|
| 44 | - |
|
| 45 | - protected ?NodeGroupDao $model_obj_node_group_persister = null; |
|
| 46 | - |
|
| 47 | - protected ?AdvancedEditorAdminFormSection $advanced_editor_admin_form = null; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Initialize page props for this admin page group. |
|
| 52 | - */ |
|
| 53 | - protected function _init_page_props() |
|
| 54 | - { |
|
| 55 | - // is there a evt_id in the request? |
|
| 56 | - $this->EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT); |
|
| 57 | - $this->EVT_ID = $this->request->getRequestParam('post', $this->EVT_ID, DataType::INT); |
|
| 58 | - $this->EVT_ID = $this->request->getRequestParam('post_ID', $this->EVT_ID, DataType::INT); |
|
| 59 | - |
|
| 60 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 61 | - $this->page_label = EVENTS_LABEL; |
|
| 62 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 63 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 64 | - $this->_cpt_model_names = [ |
|
| 65 | - 'create_new' => 'EEM_Event', |
|
| 66 | - 'edit' => 'EEM_Event', |
|
| 67 | - ]; |
|
| 68 | - $this->_cpt_edit_routes = [ |
|
| 69 | - 'espresso_events' => 'edit', |
|
| 70 | - ]; |
|
| 71 | - add_action( |
|
| 72 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 73 | - [$this, 'verify_event_edit'], |
|
| 74 | - 10, |
|
| 75 | - 2 |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Sets the ajax hooks used for this admin page group. |
|
| 82 | - */ |
|
| 83 | - protected function _ajax_hooks() |
|
| 84 | - { |
|
| 85 | - add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Sets the page properties for this admin page group. |
|
| 91 | - */ |
|
| 92 | - protected function _define_page_props() |
|
| 93 | - { |
|
| 94 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 95 | - $this->_labels = [ |
|
| 96 | - 'buttons' => [ |
|
| 97 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 98 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 99 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 100 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 101 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 102 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 103 | - ], |
|
| 104 | - 'editor_title' => [ |
|
| 105 | - 'espresso_events' => esc_html__('Edit Event', 'event_espresso'), |
|
| 106 | - ], |
|
| 107 | - 'publishbox' => [ |
|
| 108 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 109 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 110 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 111 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 112 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 113 | - ], |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Sets the page routes property for this admin page group. |
|
| 120 | - */ |
|
| 121 | - protected function _set_page_routes() |
|
| 122 | - { |
|
| 123 | - $this->_page_routes = [ |
|
| 124 | - 'default' => [ |
|
| 125 | - 'func' => [$this, '_events_overview_list_table'], |
|
| 126 | - 'capability' => 'ee_read_events', |
|
| 127 | - ], |
|
| 128 | - 'create_new' => [ |
|
| 129 | - 'func' => [$this, '_create_new_cpt_item'], |
|
| 130 | - 'capability' => 'ee_edit_events', |
|
| 131 | - ], |
|
| 132 | - 'edit' => [ |
|
| 133 | - 'func' => [$this, '_edit_cpt_item'], |
|
| 134 | - 'capability' => 'ee_edit_event', |
|
| 135 | - 'obj_id' => $this->EVT_ID, |
|
| 136 | - ], |
|
| 137 | - 'copy_event' => [ |
|
| 138 | - 'func' => [$this, '_copy_events'], |
|
| 139 | - 'capability' => 'ee_edit_event', |
|
| 140 | - 'obj_id' => $this->EVT_ID, |
|
| 141 | - 'noheader' => true, |
|
| 142 | - ], |
|
| 143 | - 'trash_event' => [ |
|
| 144 | - 'func' => [$this, '_trash_or_restore_event'], |
|
| 145 | - 'args' => ['event_status' => 'trash'], |
|
| 146 | - 'capability' => 'ee_delete_event', |
|
| 147 | - 'obj_id' => $this->EVT_ID, |
|
| 148 | - 'noheader' => true, |
|
| 149 | - ], |
|
| 150 | - 'trash_events' => [ |
|
| 151 | - 'func' => [$this, '_trash_or_restore_events'], |
|
| 152 | - 'args' => ['event_status' => 'trash'], |
|
| 153 | - 'capability' => 'ee_delete_events', |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ], |
|
| 156 | - 'restore_event' => [ |
|
| 157 | - 'func' => [$this, '_trash_or_restore_event'], |
|
| 158 | - 'args' => ['event_status' => 'draft'], |
|
| 159 | - 'capability' => 'ee_delete_event', |
|
| 160 | - 'obj_id' => $this->EVT_ID, |
|
| 161 | - 'noheader' => true, |
|
| 162 | - ], |
|
| 163 | - 'restore_events' => [ |
|
| 164 | - 'func' => [$this, '_trash_or_restore_events'], |
|
| 165 | - 'args' => ['event_status' => 'draft'], |
|
| 166 | - 'capability' => 'ee_delete_events', |
|
| 167 | - 'noheader' => true, |
|
| 168 | - ], |
|
| 169 | - 'delete_event' => [ |
|
| 170 | - 'func' => [$this, '_delete_event'], |
|
| 171 | - 'capability' => 'ee_delete_event', |
|
| 172 | - 'obj_id' => $this->EVT_ID, |
|
| 173 | - 'noheader' => true, |
|
| 174 | - ], |
|
| 175 | - 'delete_events' => [ |
|
| 176 | - 'func' => [$this, '_delete_events'], |
|
| 177 | - 'capability' => 'ee_delete_events', |
|
| 178 | - 'noheader' => true, |
|
| 179 | - ], |
|
| 180 | - 'view_report' => [ |
|
| 181 | - 'func' => [$this, '_view_report'], |
|
| 182 | - 'capability' => 'ee_edit_events', |
|
| 183 | - ], |
|
| 184 | - 'default_event_settings' => [ |
|
| 185 | - 'func' => [$this, '_default_event_settings'], |
|
| 186 | - 'capability' => 'manage_options', |
|
| 187 | - ], |
|
| 188 | - 'update_default_event_settings' => [ |
|
| 189 | - 'func' => [$this, '_update_default_event_settings'], |
|
| 190 | - 'capability' => 'manage_options', |
|
| 191 | - 'noheader' => true, |
|
| 192 | - ], |
|
| 193 | - 'template_settings' => [ |
|
| 194 | - 'func' => [$this, '_template_settings'], |
|
| 195 | - 'capability' => 'manage_options', |
|
| 196 | - ], |
|
| 197 | - // event category tab related |
|
| 198 | - 'add_category' => [ |
|
| 199 | - 'func' => [$this, '_category_details'], |
|
| 200 | - 'capability' => 'ee_edit_event_category', |
|
| 201 | - 'args' => ['view' => 'add'], |
|
| 202 | - ], |
|
| 203 | - 'edit_category' => [ |
|
| 204 | - 'func' => [$this, '_category_details'], |
|
| 205 | - 'capability' => 'ee_edit_event_category', |
|
| 206 | - 'args' => ['view' => 'edit'], |
|
| 207 | - ], |
|
| 208 | - 'delete_categories' => [ |
|
| 209 | - 'func' => [$this, '_delete_categories'], |
|
| 210 | - 'capability' => 'ee_delete_event_category', |
|
| 211 | - 'noheader' => true, |
|
| 212 | - ], |
|
| 213 | - 'delete_category' => [ |
|
| 214 | - 'func' => [$this, '_delete_categories'], |
|
| 215 | - 'capability' => 'ee_delete_event_category', |
|
| 216 | - 'noheader' => true, |
|
| 217 | - ], |
|
| 218 | - 'insert_category' => [ |
|
| 219 | - 'func' => [$this, '_insert_or_update_category'], |
|
| 220 | - 'args' => ['new_category' => true], |
|
| 221 | - 'capability' => 'ee_edit_event_category', |
|
| 222 | - 'noheader' => true, |
|
| 223 | - ], |
|
| 224 | - 'update_category' => [ |
|
| 225 | - 'func' => [$this, '_insert_or_update_category'], |
|
| 226 | - 'args' => ['new_category' => false], |
|
| 227 | - 'capability' => 'ee_edit_event_category', |
|
| 228 | - 'noheader' => true, |
|
| 229 | - ], |
|
| 230 | - 'category_list' => [ |
|
| 231 | - 'func' => [$this, '_category_list_table'], |
|
| 232 | - 'capability' => 'ee_manage_event_categories', |
|
| 233 | - ], |
|
| 234 | - 'preview_deletion' => [ |
|
| 235 | - 'func' => [$this, 'previewDeletion'], |
|
| 236 | - 'capability' => 'ee_delete_events', |
|
| 237 | - ], |
|
| 238 | - 'confirm_deletion' => [ |
|
| 239 | - 'func' => [$this, 'confirmDeletion'], |
|
| 240 | - 'capability' => 'ee_delete_events', |
|
| 241 | - 'noheader' => true, |
|
| 242 | - ], |
|
| 243 | - ]; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Set the _page_config property for this admin page group. |
|
| 249 | - */ |
|
| 250 | - protected function _set_page_config() |
|
| 251 | - { |
|
| 252 | - $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
| 253 | - $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
| 254 | - $this->_page_config = [ |
|
| 255 | - 'default' => [ |
|
| 256 | - 'nav' => [ |
|
| 257 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 258 | - 'icon' => 'dashicons-list-view', |
|
| 259 | - 'order' => 10, |
|
| 260 | - ], |
|
| 261 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 262 | - 'help_tabs' => [ |
|
| 263 | - 'events_overview_help_tab' => [ |
|
| 264 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 265 | - 'filename' => 'events_overview', |
|
| 266 | - ], |
|
| 267 | - 'events_overview_table_column_headings_help_tab' => [ |
|
| 268 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 269 | - 'filename' => 'events_overview_table_column_headings', |
|
| 270 | - ], |
|
| 271 | - 'events_overview_filters_help_tab' => [ |
|
| 272 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 273 | - 'filename' => 'events_overview_filters', |
|
| 274 | - ], |
|
| 275 | - 'events_overview_view_help_tab' => [ |
|
| 276 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 277 | - 'filename' => 'events_overview_views', |
|
| 278 | - ], |
|
| 279 | - 'events_overview_other_help_tab' => [ |
|
| 280 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 281 | - 'filename' => 'events_overview_other', |
|
| 282 | - ], |
|
| 283 | - ], |
|
| 284 | - 'require_nonce' => false, |
|
| 285 | - ], |
|
| 286 | - 'create_new' => [ |
|
| 287 | - 'nav' => [ |
|
| 288 | - 'label' => esc_html__('Add New Event', 'event_espresso'), |
|
| 289 | - 'icon' => 'dashicons-plus-alt', |
|
| 290 | - 'order' => 15, |
|
| 291 | - 'persistent' => false, |
|
| 292 | - ], |
|
| 293 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 294 | - 'help_tabs' => [ |
|
| 295 | - 'event_editor_help_tab' => [ |
|
| 296 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 297 | - 'filename' => 'event_editor', |
|
| 298 | - ], |
|
| 299 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 300 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 301 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 302 | - ], |
|
| 303 | - 'event_editor_venue_details_help_tab' => [ |
|
| 304 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 305 | - 'filename' => 'event_editor_venue_details', |
|
| 306 | - ], |
|
| 307 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 308 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 309 | - 'filename' => 'event_editor_event_datetimes', |
|
| 310 | - ], |
|
| 311 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 312 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 313 | - 'filename' => 'event_editor_event_tickets', |
|
| 314 | - ], |
|
| 315 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 316 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 317 | - 'filename' => 'event_editor_event_registration_options', |
|
| 318 | - ], |
|
| 319 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 320 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 321 | - 'filename' => 'event_editor_tags_categories', |
|
| 322 | - ], |
|
| 323 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 324 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 325 | - 'filename' => 'event_editor_questions_registrants', |
|
| 326 | - ], |
|
| 327 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 328 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 329 | - 'filename' => 'event_editor_save_new_event', |
|
| 330 | - ], |
|
| 331 | - 'event_editor_other_help_tab' => [ |
|
| 332 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 333 | - 'filename' => 'event_editor_other', |
|
| 334 | - ], |
|
| 335 | - ], |
|
| 336 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 337 | - 'require_nonce' => false, |
|
| 338 | - ], |
|
| 339 | - 'edit' => [ |
|
| 340 | - 'nav' => [ |
|
| 341 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 342 | - 'icon' => 'dashicons-edit', |
|
| 343 | - 'order' => 15, |
|
| 344 | - 'persistent' => false, |
|
| 345 | - 'url' => $post_id |
|
| 346 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 347 | - ['post' => $post_id, 'action' => 'edit'], |
|
| 348 | - $this->_current_page_view_url |
|
| 349 | - ) |
|
| 350 | - : $this->_admin_base_url, |
|
| 351 | - ], |
|
| 352 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 353 | - 'help_tabs' => [ |
|
| 354 | - 'event_editor_help_tab' => [ |
|
| 355 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 356 | - 'filename' => 'event_editor', |
|
| 357 | - ], |
|
| 358 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 359 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 360 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 361 | - ], |
|
| 362 | - 'event_editor_venue_details_help_tab' => [ |
|
| 363 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 364 | - 'filename' => 'event_editor_venue_details', |
|
| 365 | - ], |
|
| 366 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 367 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 368 | - 'filename' => 'event_editor_event_datetimes', |
|
| 369 | - ], |
|
| 370 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 371 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 372 | - 'filename' => 'event_editor_event_tickets', |
|
| 373 | - ], |
|
| 374 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 375 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 376 | - 'filename' => 'event_editor_event_registration_options', |
|
| 377 | - ], |
|
| 378 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 379 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 380 | - 'filename' => 'event_editor_tags_categories', |
|
| 381 | - ], |
|
| 382 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 383 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 384 | - 'filename' => 'event_editor_questions_registrants', |
|
| 385 | - ], |
|
| 386 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 387 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 388 | - 'filename' => 'event_editor_save_new_event', |
|
| 389 | - ], |
|
| 390 | - 'event_editor_other_help_tab' => [ |
|
| 391 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 392 | - 'filename' => 'event_editor_other', |
|
| 393 | - ], |
|
| 394 | - ], |
|
| 395 | - 'require_nonce' => false, |
|
| 396 | - ], |
|
| 397 | - 'default_event_settings' => [ |
|
| 398 | - 'nav' => [ |
|
| 399 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 400 | - 'icon' => 'dashicons-admin-generic', |
|
| 401 | - 'order' => 40, |
|
| 402 | - ], |
|
| 403 | - 'metaboxes' => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes), |
|
| 404 | - 'labels' => [ |
|
| 405 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 406 | - ], |
|
| 407 | - 'help_tabs' => [ |
|
| 408 | - 'default_settings_help_tab' => [ |
|
| 409 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 410 | - 'filename' => 'events_default_settings', |
|
| 411 | - ], |
|
| 412 | - 'default_settings_status_help_tab' => [ |
|
| 413 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 414 | - 'filename' => 'events_default_settings_status', |
|
| 415 | - ], |
|
| 416 | - 'default_maximum_tickets_help_tab' => [ |
|
| 417 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 418 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 419 | - ], |
|
| 420 | - ], |
|
| 421 | - 'require_nonce' => false, |
|
| 422 | - ], |
|
| 423 | - // template settings |
|
| 424 | - 'template_settings' => [ |
|
| 425 | - 'nav' => [ |
|
| 426 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 427 | - 'icon' => 'dashicons-layout', |
|
| 428 | - 'order' => 30, |
|
| 429 | - ], |
|
| 430 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 431 | - 'help_tabs' => [ |
|
| 432 | - 'general_settings_templates_help_tab' => [ |
|
| 433 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 434 | - 'filename' => 'general_settings_templates', |
|
| 435 | - ], |
|
| 436 | - ], |
|
| 437 | - 'require_nonce' => false, |
|
| 438 | - ], |
|
| 439 | - // event category stuff |
|
| 440 | - 'add_category' => [ |
|
| 441 | - 'nav' => [ |
|
| 442 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 443 | - 'icon' => 'dashicons-plus-alt', |
|
| 444 | - 'order' => 25, |
|
| 445 | - 'persistent' => false, |
|
| 446 | - ], |
|
| 447 | - 'help_tabs' => [ |
|
| 448 | - 'add_category_help_tab' => [ |
|
| 449 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 450 | - 'filename' => 'events_add_category', |
|
| 451 | - ], |
|
| 452 | - ], |
|
| 453 | - 'metaboxes' => ['_publish_post_box'], |
|
| 454 | - 'require_nonce' => false, |
|
| 455 | - ], |
|
| 456 | - 'edit_category' => [ |
|
| 457 | - 'nav' => [ |
|
| 458 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 459 | - 'icon' => 'dashicons-edit', |
|
| 460 | - 'order' => 25, |
|
| 461 | - 'persistent' => false, |
|
| 462 | - 'url' => $EVT_CAT_ID |
|
| 463 | - ? add_query_arg( |
|
| 464 | - ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
| 465 | - $this->_current_page_view_url |
|
| 466 | - ) |
|
| 467 | - : $this->_admin_base_url, |
|
| 468 | - ], |
|
| 469 | - 'help_tabs' => [ |
|
| 470 | - 'edit_category_help_tab' => [ |
|
| 471 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 472 | - 'filename' => 'events_edit_category', |
|
| 473 | - ], |
|
| 474 | - ], |
|
| 475 | - 'metaboxes' => ['_publish_post_box'], |
|
| 476 | - 'require_nonce' => false, |
|
| 477 | - ], |
|
| 478 | - 'category_list' => [ |
|
| 479 | - 'nav' => [ |
|
| 480 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 481 | - 'icon' => 'dashicons-networking', |
|
| 482 | - 'order' => 20, |
|
| 483 | - ], |
|
| 484 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 485 | - 'help_tabs' => [ |
|
| 486 | - 'events_categories_help_tab' => [ |
|
| 487 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 488 | - 'filename' => 'events_categories', |
|
| 489 | - ], |
|
| 490 | - 'events_categories_table_column_headings_help_tab' => [ |
|
| 491 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 492 | - 'filename' => 'events_categories_table_column_headings', |
|
| 493 | - ], |
|
| 494 | - 'events_categories_view_help_tab' => [ |
|
| 495 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 496 | - 'filename' => 'events_categories_views', |
|
| 497 | - ], |
|
| 498 | - 'events_categories_other_help_tab' => [ |
|
| 499 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 500 | - 'filename' => 'events_categories_other', |
|
| 501 | - ], |
|
| 502 | - ], |
|
| 503 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 504 | - 'require_nonce' => false, |
|
| 505 | - ], |
|
| 506 | - 'preview_deletion' => [ |
|
| 507 | - 'nav' => [ |
|
| 508 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 509 | - 'icon' => 'dashicons-remove', |
|
| 510 | - 'order' => 15, |
|
| 511 | - 'persistent' => false, |
|
| 512 | - 'url' => '', |
|
| 513 | - ], |
|
| 514 | - 'require_nonce' => false, |
|
| 515 | - ], |
|
| 516 | - ]; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 522 | - */ |
|
| 523 | - protected function _add_screen_options() |
|
| 524 | - { |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Implementing the screen options for the 'default' route. |
|
| 530 | - * |
|
| 531 | - * @throws InvalidArgumentException |
|
| 532 | - * @throws InvalidDataTypeException |
|
| 533 | - * @throws InvalidInterfaceException |
|
| 534 | - */ |
|
| 535 | - protected function _add_screen_options_default() |
|
| 536 | - { |
|
| 537 | - $this->_per_page_screen_option(); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Implementing screen options for the category list route. |
|
| 543 | - * |
|
| 544 | - * @throws InvalidArgumentException |
|
| 545 | - * @throws InvalidDataTypeException |
|
| 546 | - * @throws InvalidInterfaceException |
|
| 547 | - */ |
|
| 548 | - protected function _add_screen_options_category_list() |
|
| 549 | - { |
|
| 550 | - $page_title = $this->_admin_page_title; |
|
| 551 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 552 | - $this->_per_page_screen_option(); |
|
| 553 | - $this->_admin_page_title = $page_title; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Used to register any global feature pointers for the admin page group. |
|
| 559 | - */ |
|
| 560 | - protected function _add_feature_pointers() |
|
| 561 | - { |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 567 | - */ |
|
| 568 | - public function load_scripts_styles() |
|
| 569 | - { |
|
| 570 | - wp_register_style( |
|
| 571 | - 'events-admin-css', |
|
| 572 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 573 | - [], |
|
| 574 | - EVENT_ESPRESSO_VERSION |
|
| 575 | - ); |
|
| 576 | - wp_register_style( |
|
| 577 | - 'ee-cat-admin', |
|
| 578 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 579 | - [], |
|
| 580 | - EVENT_ESPRESSO_VERSION |
|
| 581 | - ); |
|
| 582 | - wp_enqueue_style('events-admin-css'); |
|
| 583 | - wp_enqueue_style('ee-cat-admin'); |
|
| 584 | - // scripts |
|
| 585 | - wp_register_script( |
|
| 586 | - 'event_editor_js', |
|
| 587 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 588 | - ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 589 | - EVENT_ESPRESSO_VERSION, |
|
| 590 | - true |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Enqueuing scripts and styles specific to this view |
|
| 597 | - */ |
|
| 598 | - public function load_scripts_styles_create_new() |
|
| 599 | - { |
|
| 600 | - $this->load_scripts_styles_edit(); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Enqueuing scripts and styles specific to this view |
|
| 606 | - */ |
|
| 607 | - public function load_scripts_styles_edit() |
|
| 608 | - { |
|
| 609 | - // styles |
|
| 610 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 611 | - wp_register_style( |
|
| 612 | - 'event-editor-css', |
|
| 613 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 614 | - ['ee-admin-css'], |
|
| 615 | - EVENT_ESPRESSO_VERSION |
|
| 616 | - ); |
|
| 617 | - wp_enqueue_style('event-editor-css'); |
|
| 618 | - // scripts |
|
| 619 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 620 | - wp_register_script( |
|
| 621 | - 'event-datetime-metabox', |
|
| 622 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 623 | - ['event_editor_js', 'ee-datepicker'], |
|
| 624 | - EVENT_ESPRESSO_VERSION |
|
| 625 | - ); |
|
| 626 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * Populating the _views property for the category list table view. |
|
| 633 | - */ |
|
| 634 | - protected function _set_list_table_views_category_list() |
|
| 635 | - { |
|
| 636 | - $this->_views = [ |
|
| 637 | - 'all' => [ |
|
| 638 | - 'slug' => 'all', |
|
| 639 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 640 | - 'count' => 0, |
|
| 641 | - 'bulk_action' => [ |
|
| 642 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 643 | - ], |
|
| 644 | - ], |
|
| 645 | - ]; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 651 | - */ |
|
| 652 | - public function admin_init() |
|
| 653 | - { |
|
| 654 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 655 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 656 | - 'event_espresso' |
|
| 657 | - ); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 663 | - * group. |
|
| 664 | - */ |
|
| 665 | - public function admin_notices() |
|
| 666 | - { |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 672 | - * this admin page group. |
|
| 673 | - */ |
|
| 674 | - public function admin_footer_scripts() |
|
| 675 | - { |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 681 | - * warning (via EE_Error::add_error()); |
|
| 682 | - * |
|
| 683 | - * @param EE_Event|null $event Event object |
|
| 684 | - * @param string $req_type |
|
| 685 | - * @return void |
|
| 686 | - * @throws EE_Error |
|
| 687 | - * @throws ReflectionException |
|
| 688 | - */ |
|
| 689 | - public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '') |
|
| 690 | - { |
|
| 691 | - // don't need to do this when processing |
|
| 692 | - if (! empty($req_type)) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - // no event? |
|
| 696 | - if (! $event instanceof EE_Event) { |
|
| 697 | - $event = $this->_cpt_model_obj; |
|
| 698 | - } |
|
| 699 | - // STILL no event? |
|
| 700 | - if (! $event instanceof EE_Event) { |
|
| 701 | - return; |
|
| 702 | - } |
|
| 703 | - // don't need to keep calling this |
|
| 704 | - remove_action( |
|
| 705 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 706 | - [$this, 'verify_event_edit'] |
|
| 707 | - ); |
|
| 708 | - $orig_status = $event->status(); |
|
| 709 | - // first check if event is active. |
|
| 710 | - if ( |
|
| 711 | - $orig_status === EEM_Event::cancelled |
|
| 712 | - || $orig_status === EEM_Event::postponed |
|
| 713 | - || $event->is_expired() |
|
| 714 | - || $event->is_inactive() |
|
| 715 | - ) { |
|
| 716 | - return; |
|
| 717 | - } |
|
| 718 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
| 719 | - if ($event->is_sold_out(true)) { |
|
| 720 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 721 | - EE_Error::add_attention( |
|
| 722 | - sprintf( |
|
| 723 | - esc_html__( |
|
| 724 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 725 | - 'event_espresso' |
|
| 726 | - ), |
|
| 727 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 728 | - ) |
|
| 729 | - ); |
|
| 730 | - } |
|
| 731 | - return; |
|
| 732 | - } |
|
| 733 | - if ($orig_status === EEM_Event::sold_out) { |
|
| 734 | - EE_Error::add_attention( |
|
| 735 | - sprintf( |
|
| 736 | - esc_html__( |
|
| 737 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 738 | - 'event_espresso' |
|
| 739 | - ), |
|
| 740 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 741 | - ) |
|
| 742 | - ); |
|
| 743 | - } |
|
| 744 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 745 | - if (! $event->tickets_on_sale()) { |
|
| 746 | - return; |
|
| 747 | - } |
|
| 748 | - // made it here so show warning |
|
| 749 | - $this->_edit_event_warning(); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 755 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 756 | - * |
|
| 757 | - * @access protected |
|
| 758 | - * @return void |
|
| 759 | - */ |
|
| 760 | - protected function _edit_event_warning() |
|
| 761 | - { |
|
| 762 | - // we don't want to add warnings during these requests |
|
| 763 | - if ($this->request->getRequestParam('action') === 'editpost') { |
|
| 764 | - return; |
|
| 765 | - } |
|
| 766 | - EE_Error::add_attention( |
|
| 767 | - sprintf( |
|
| 768 | - esc_html__( |
|
| 769 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 770 | - 'event_espresso' |
|
| 771 | - ), |
|
| 772 | - '<a class="espresso-help-tab-lnk ee-help-tab-link">', |
|
| 773 | - '</a>' |
|
| 774 | - ) |
|
| 775 | - ); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 781 | - * Otherwise, do the normal logic |
|
| 782 | - * |
|
| 783 | - * @return void |
|
| 784 | - * @throws EE_Error |
|
| 785 | - * @throws InvalidArgumentException |
|
| 786 | - * @throws InvalidDataTypeException |
|
| 787 | - * @throws InvalidInterfaceException |
|
| 788 | - * @throws ReflectionException |
|
| 789 | - */ |
|
| 790 | - protected function _create_new_cpt_item() |
|
| 791 | - { |
|
| 792 | - $has_timezone_string = get_option('timezone_string'); |
|
| 793 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 794 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 795 | - EE_Error::add_attention( |
|
| 796 | - sprintf( |
|
| 797 | - esc_html__( |
|
| 798 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 799 | - 'event_espresso' |
|
| 800 | - ), |
|
| 801 | - '<br>', |
|
| 802 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 803 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 804 | - . '</select>', |
|
| 805 | - '<button class="button button--secondary timezone-submit">', |
|
| 806 | - '</button><span class="spinner"></span>' |
|
| 807 | - ), |
|
| 808 | - __FILE__, |
|
| 809 | - __FUNCTION__, |
|
| 810 | - __LINE__ |
|
| 811 | - ); |
|
| 812 | - } |
|
| 813 | - parent::_create_new_cpt_item(); |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - /** |
|
| 818 | - * Sets the _views property for the default route in this admin page group. |
|
| 819 | - */ |
|
| 820 | - protected function _set_list_table_views_default() |
|
| 821 | - { |
|
| 822 | - $this->_views = [ |
|
| 823 | - 'all' => [ |
|
| 824 | - 'slug' => 'all', |
|
| 825 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 826 | - 'count' => 0, |
|
| 827 | - 'bulk_action' => [ |
|
| 828 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 829 | - ], |
|
| 830 | - ], |
|
| 831 | - 'draft' => [ |
|
| 832 | - 'slug' => 'draft', |
|
| 833 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 834 | - 'count' => 0, |
|
| 835 | - 'bulk_action' => [ |
|
| 836 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 837 | - ], |
|
| 838 | - ], |
|
| 839 | - ]; |
|
| 840 | - if ($this->capabilities->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 841 | - $this->_views['trash'] = [ |
|
| 842 | - 'slug' => 'trash', |
|
| 843 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 844 | - 'count' => 0, |
|
| 845 | - 'bulk_action' => [ |
|
| 846 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 847 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 848 | - ], |
|
| 849 | - ]; |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * Provides the legend item array for the default list table view. |
|
| 856 | - * |
|
| 857 | - * @return array |
|
| 858 | - * @throws EE_Error |
|
| 859 | - * @throws EE_Error |
|
| 860 | - */ |
|
| 861 | - protected function _event_legend_items(): array |
|
| 862 | - { |
|
| 863 | - $items = [ |
|
| 864 | - 'view_details' => [ |
|
| 865 | - 'class' => 'dashicons dashicons-visibility', |
|
| 866 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 867 | - ], |
|
| 868 | - 'edit_event' => [ |
|
| 869 | - 'class' => 'dashicons dashicons-calendar-alt', |
|
| 870 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 871 | - ], |
|
| 872 | - 'view_attendees' => [ |
|
| 873 | - 'class' => 'dashicons dashicons-groups', |
|
| 874 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 875 | - ], |
|
| 876 | - ]; |
|
| 877 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 878 | - $statuses = [ |
|
| 879 | - 'sold_out_status' => [ |
|
| 880 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out, |
|
| 881 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 882 | - ], |
|
| 883 | - 'active_status' => [ |
|
| 884 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active, |
|
| 885 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 886 | - ], |
|
| 887 | - 'upcoming_status' => [ |
|
| 888 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming, |
|
| 889 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 890 | - ], |
|
| 891 | - 'postponed_status' => [ |
|
| 892 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed, |
|
| 893 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 894 | - ], |
|
| 895 | - 'cancelled_status' => [ |
|
| 896 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled, |
|
| 897 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 898 | - ], |
|
| 899 | - 'expired_status' => [ |
|
| 900 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired, |
|
| 901 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 902 | - ], |
|
| 903 | - 'inactive_status' => [ |
|
| 904 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive, |
|
| 905 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 906 | - ], |
|
| 907 | - ]; |
|
| 908 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 909 | - return array_merge($items, $statuses); |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * @return EEM_Event |
|
| 915 | - * @throws EE_Error |
|
| 916 | - * @throws InvalidArgumentException |
|
| 917 | - * @throws InvalidDataTypeException |
|
| 918 | - * @throws InvalidInterfaceException |
|
| 919 | - * @throws ReflectionException |
|
| 920 | - */ |
|
| 921 | - private function _event_model(): EEM_Event |
|
| 922 | - { |
|
| 923 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 924 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 925 | - } |
|
| 926 | - return $this->_event_model; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 932 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 933 | - * |
|
| 934 | - * @param string $return the current html |
|
| 935 | - * @param int $id the post id for the page |
|
| 936 | - * @param string|null $new_title What the title is |
|
| 937 | - * @param string|null $new_slug what the slug is |
|
| 938 | - * @return string The new html string for the permalink area |
|
| 939 | - * @deprecated 5.0.0.p |
|
| 940 | - * @see TicketSelectorShortcodeButton::addButton |
|
| 941 | - */ |
|
| 942 | - public function extra_permalink_field_buttons( |
|
| 943 | - string $return, |
|
| 944 | - int $id, |
|
| 945 | - ?string $new_title, |
|
| 946 | - ?string $new_slug |
|
| 947 | - ): string { |
|
| 948 | - return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * _events_overview_list_table |
|
| 954 | - * This contains the logic for showing the events_overview list |
|
| 955 | - * |
|
| 956 | - * @access protected |
|
| 957 | - * @return void |
|
| 958 | - * @throws DomainException |
|
| 959 | - * @throws EE_Error |
|
| 960 | - * @throws InvalidArgumentException |
|
| 961 | - * @throws InvalidDataTypeException |
|
| 962 | - * @throws InvalidInterfaceException |
|
| 963 | - */ |
|
| 964 | - protected function _events_overview_list_table() |
|
| 965 | - { |
|
| 966 | - $after_list_table = []; |
|
| 967 | - $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack'); |
|
| 968 | - $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso')); |
|
| 969 | - $links_html .= EEH_HTML::div( |
|
| 970 | - EEH_Template::get_button_or_link( |
|
| 971 | - get_post_type_archive_link('espresso_events'), |
|
| 972 | - esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 973 | - 'button button--small button--secondary' |
|
| 974 | - ), |
|
| 975 | - '', |
|
| 976 | - 'ee-admin-button-row ee-admin-button-row--align-start' |
|
| 977 | - ); |
|
| 978 | - $links_html .= EEH_HTML::divx(); |
|
| 979 | - |
|
| 980 | - $after_list_table['view_event_list_button'] = $links_html; |
|
| 981 | - |
|
| 982 | - $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 983 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 984 | - 'create_new', |
|
| 985 | - 'add', |
|
| 986 | - [], |
|
| 987 | - 'add-new-h2' |
|
| 988 | - ); |
|
| 989 | - |
|
| 990 | - $this->_template_args['after_list_table'] = array_merge( |
|
| 991 | - (array) $this->_template_args['after_list_table'], |
|
| 992 | - $after_list_table |
|
| 993 | - ); |
|
| 994 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - |
|
| 998 | - /** |
|
| 999 | - * this allows for extra misc actions in the default WP publish box |
|
| 1000 | - * |
|
| 1001 | - * @return void |
|
| 1002 | - * @throws DomainException |
|
| 1003 | - * @throws EE_Error |
|
| 1004 | - * @throws InvalidArgumentException |
|
| 1005 | - * @throws InvalidDataTypeException |
|
| 1006 | - * @throws InvalidInterfaceException |
|
| 1007 | - * @throws ReflectionException |
|
| 1008 | - */ |
|
| 1009 | - public function extra_misc_actions_publish_box() |
|
| 1010 | - { |
|
| 1011 | - $this->_generate_publish_box_extra_content(); |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1017 | - * saved. |
|
| 1018 | - * Typically you would use this to save any additional data. |
|
| 1019 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1020 | - * ALSO very important. When a post transitions from scheduled to published, |
|
| 1021 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1022 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1023 | - * |
|
| 1024 | - * @access protected |
|
| 1025 | - * @abstract |
|
| 1026 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1027 | - * @param WP_Post $post The post object of the cpt that was saved. |
|
| 1028 | - * @return void |
|
| 1029 | - * @throws EE_Error |
|
| 1030 | - * @throws InvalidArgumentException |
|
| 1031 | - * @throws InvalidDataTypeException |
|
| 1032 | - * @throws InvalidInterfaceException |
|
| 1033 | - * @throws ReflectionException |
|
| 1034 | - */ |
|
| 1035 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 1036 | - { |
|
| 1037 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1038 | - // get out we're not processing an event save. |
|
| 1039 | - return; |
|
| 1040 | - } |
|
| 1041 | - $event_values = [ |
|
| 1042 | - 'EVT_member_only' => $this->request->getRequestParam('member_only', false, DataType::BOOL), |
|
| 1043 | - 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL), |
|
| 1044 | - 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
| 1045 | - ]; |
|
| 1046 | - // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1047 | - if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1048 | - $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
| 1049 | - 'display_ticket_selector', |
|
| 1050 | - false, |
|
| 1051 | - 'bool' |
|
| 1052 | - ); |
|
| 1053 | - $event_values['EVT_additional_limit'] = min( |
|
| 1054 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1055 | - $this->request->getRequestParam( |
|
| 1056 | - 'additional_limit', |
|
| 1057 | - EEM_Event::get_default_additional_limit(), |
|
| 1058 | - 'int' |
|
| 1059 | - ) |
|
| 1060 | - ); |
|
| 1061 | - $event_values['EVT_default_registration_status'] = $this->request->getRequestParam( |
|
| 1062 | - 'EVT_default_registration_status', |
|
| 1063 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 1064 | - ); |
|
| 1065 | - |
|
| 1066 | - $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL'); |
|
| 1067 | - $event_values['EVT_phone'] = $this->request->getRequestParam('event_phone'); |
|
| 1068 | - $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL); |
|
| 1069 | - } elseif ($post instanceof WP_Post) { |
|
| 1070 | - $event_values['EVT_name'] = $post->post_title; |
|
| 1071 | - $event_values['EVT_desc'] = $post->post_content; |
|
| 1072 | - } |
|
| 1073 | - // update event |
|
| 1074 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1075 | - // get event_object for other metaboxes... |
|
| 1076 | - // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1077 | - // i have to setup where conditions to override the filters in the model |
|
| 1078 | - // that filter out auto-draft and inherit statuses so we GET the inherit id! |
|
| 1079 | - /** @var EE_Event $event */ |
|
| 1080 | - $event = $this->_event_model()->get_one( |
|
| 1081 | - [ |
|
| 1082 | - [ |
|
| 1083 | - $this->_event_model()->primary_key_name() => $post_id, |
|
| 1084 | - 'OR' => [ |
|
| 1085 | - 'status' => $post->post_status, |
|
| 1086 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1087 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1088 | - 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
| 1089 | - ], |
|
| 1090 | - 'status' => ['NOT IN', ['auto-draft']], |
|
| 1091 | - ], |
|
| 1092 | - ] |
|
| 1093 | - ); |
|
| 1094 | - |
|
| 1095 | - // the following are default callbacks for event attachment updates |
|
| 1096 | - // that can be overridden by caffeinated functionality and/or addons. |
|
| 1097 | - $event_update_callbacks = []; |
|
| 1098 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 1099 | - $event_update_callbacks['_default_venue_update'] = [$this, '_default_venue_update']; |
|
| 1100 | - $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update']; |
|
| 1101 | - } |
|
| 1102 | - $event_update_callbacks = apply_filters( |
|
| 1103 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1104 | - $event_update_callbacks |
|
| 1105 | - ); |
|
| 1106 | - |
|
| 1107 | - $att_success = true; |
|
| 1108 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 1109 | - $_success = is_callable($e_callback) |
|
| 1110 | - ? $e_callback($event, $this->request->requestParams()) |
|
| 1111 | - : false; |
|
| 1112 | - // if ANY of these updates fail then we want the appropriate global error message |
|
| 1113 | - $att_success = $_success !== false ? $att_success : false; |
|
| 1114 | - } |
|
| 1115 | - // any errors? |
|
| 1116 | - if ($success && $att_success === false) { |
|
| 1117 | - EE_Error::add_error( |
|
| 1118 | - esc_html__( |
|
| 1119 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1120 | - 'event_espresso' |
|
| 1121 | - ), |
|
| 1122 | - __FILE__, |
|
| 1123 | - __FUNCTION__, |
|
| 1124 | - __LINE__ |
|
| 1125 | - ); |
|
| 1126 | - } elseif ($success === false) { |
|
| 1127 | - EE_Error::add_error( |
|
| 1128 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1129 | - __FILE__, |
|
| 1130 | - __FUNCTION__, |
|
| 1131 | - __LINE__ |
|
| 1132 | - ); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * @param int $post_id |
|
| 1139 | - * @param int $revision_id |
|
| 1140 | - * @throws EE_Error |
|
| 1141 | - * @throws EE_Error |
|
| 1142 | - * @throws ReflectionException |
|
| 1143 | - * @see parent::restore_item() |
|
| 1144 | - */ |
|
| 1145 | - protected function _restore_cpt_item(int $post_id, int $revision_id) |
|
| 1146 | - { |
|
| 1147 | - // copy existing event meta to new post |
|
| 1148 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1149 | - if ($post_evt instanceof EE_Event) { |
|
| 1150 | - // meta revision restore |
|
| 1151 | - $post_evt->restore_revision($revision_id); |
|
| 1152 | - // related objs restore |
|
| 1153 | - $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * Attach the venue to the Event |
|
| 1160 | - * |
|
| 1161 | - * @param EE_Event $event Event Object to add the venue to |
|
| 1162 | - * @param array $data The request data from the form |
|
| 1163 | - * @return bool Success or fail. |
|
| 1164 | - * @throws EE_Error |
|
| 1165 | - * @throws ReflectionException |
|
| 1166 | - */ |
|
| 1167 | - protected function _default_venue_update(EE_Event $event, array $data): bool |
|
| 1168 | - { |
|
| 1169 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1170 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1171 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1172 | - // very important. If we don't have a venue name... |
|
| 1173 | - // then we'll get out because not necessary to create empty venue |
|
| 1174 | - if (empty($data['venue_title'])) { |
|
| 1175 | - return false; |
|
| 1176 | - } |
|
| 1177 | - $venue_array = [ |
|
| 1178 | - 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
| 1179 | - 'VNU_name' => $data['venue_title'], |
|
| 1180 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1181 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1182 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
| 1183 | - ? $data['venue_short_description'] |
|
| 1184 | - : null, |
|
| 1185 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1186 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1187 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1188 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1189 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1190 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1191 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1192 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1193 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1194 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1195 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1196 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1197 | - 'status' => 'publish', |
|
| 1198 | - ]; |
|
| 1199 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1200 | - if (! empty($venue_id)) { |
|
| 1201 | - $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1202 | - $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1203 | - // we've gotta make sure that the venue is always attached to a revision.. |
|
| 1204 | - // add_relation_to should take care of making sure that the relation is already present. |
|
| 1205 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1206 | - return $rows_affected > 0; |
|
| 1207 | - } |
|
| 1208 | - // we insert the venue |
|
| 1209 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1210 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1211 | - return ! empty($venue_id); |
|
| 1212 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1218 | - * |
|
| 1219 | - * @param EE_Event $event The Event object we're attaching data to |
|
| 1220 | - * @param array $data The request data from the form |
|
| 1221 | - * @return array |
|
| 1222 | - * @throws EE_Error |
|
| 1223 | - * @throws ReflectionException |
|
| 1224 | - * @throws Exception |
|
| 1225 | - */ |
|
| 1226 | - protected function _default_tickets_update(EE_Event $event, array $data): array |
|
| 1227 | - { |
|
| 1228 | - if ($this->admin_config->useAdvancedEditor()) { |
|
| 1229 | - return []; |
|
| 1230 | - } |
|
| 1231 | - $datetime = null; |
|
| 1232 | - $saved_tickets = []; |
|
| 1233 | - $event_timezone = $event->get_timezone(); |
|
| 1234 | - $date_formats = ['Y-m-d', 'h:i a']; |
|
| 1235 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 1236 | - // trim all values to ensure any excess whitespace is removed. |
|
| 1237 | - $datetime_data = array_map('trim', $datetime_data); |
|
| 1238 | - $datetime_data['DTT_EVT_end'] = ! empty($datetime_data['DTT_EVT_end']) |
|
| 1239 | - ? $datetime_data['DTT_EVT_end'] |
|
| 1240 | - : $datetime_data['DTT_EVT_start']; |
|
| 1241 | - $datetime_values = [ |
|
| 1242 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
| 1243 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 1244 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 1245 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
| 1246 | - 'DTT_order' => $row, |
|
| 1247 | - ]; |
|
| 1248 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 1249 | - // Otherwise we instantiate a new object for save. |
|
| 1250 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 1251 | - $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 1252 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1253 | - throw new RuntimeException( |
|
| 1254 | - sprintf( |
|
| 1255 | - esc_html__( |
|
| 1256 | - 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1257 | - 'event_espresso' |
|
| 1258 | - ), |
|
| 1259 | - $datetime_data['DTT_ID'] |
|
| 1260 | - ) |
|
| 1261 | - ); |
|
| 1262 | - } |
|
| 1263 | - $datetime->set_date_format($date_formats[0]); |
|
| 1264 | - $datetime->set_time_format($date_formats[1]); |
|
| 1265 | - foreach ($datetime_values as $field => $value) { |
|
| 1266 | - $datetime->set($field, $value); |
|
| 1267 | - } |
|
| 1268 | - } else { |
|
| 1269 | - $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
| 1270 | - } |
|
| 1271 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1272 | - throw new RuntimeException( |
|
| 1273 | - sprintf( |
|
| 1274 | - esc_html__( |
|
| 1275 | - 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
| 1276 | - 'event_espresso' |
|
| 1277 | - ), |
|
| 1278 | - print_r($datetime_values, true) |
|
| 1279 | - ) |
|
| 1280 | - ); |
|
| 1281 | - } |
|
| 1282 | - // before going any further make sure our dates are setup correctly |
|
| 1283 | - // so that the end date is always equal or greater than the start date. |
|
| 1284 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 1285 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 1286 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 1287 | - } |
|
| 1288 | - $datetime->save(); |
|
| 1289 | - $event->_add_relation_to($datetime, 'Datetime'); |
|
| 1290 | - } |
|
| 1291 | - // no datetimes get deleted so we don't do any of that logic here. |
|
| 1292 | - // update tickets next |
|
| 1293 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1294 | - |
|
| 1295 | - // set up some default start and end dates in case those are not present in the incoming data |
|
| 1296 | - $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 1297 | - $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1298 | - // use the start date of the first datetime for the end date |
|
| 1299 | - $first_datetime = $event->first_datetime(); |
|
| 1300 | - $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
| 1301 | - |
|
| 1302 | - // now process the incoming data |
|
| 1303 | - foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
| 1304 | - $update_prices = false; |
|
| 1305 | - $ticket_price = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0; |
|
| 1306 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1307 | - $ticket_data = array_map('trim', $ticket_data); |
|
| 1308 | - $ticket_values = [ |
|
| 1309 | - 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
| 1310 | - 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
| 1311 | - 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
| 1312 | - 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
| 1313 | - 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
| 1314 | - ? $ticket_data['TKT_start_date'] |
|
| 1315 | - : $default_start_date, |
|
| 1316 | - 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
| 1317 | - ? $ticket_data['TKT_end_date'] |
|
| 1318 | - : $default_end_date, |
|
| 1319 | - 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
| 1320 | - || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
| 1321 | - ? $ticket_data['TKT_qty'] |
|
| 1322 | - : EE_INF, |
|
| 1323 | - 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
| 1324 | - || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
| 1325 | - ? $ticket_data['TKT_uses'] |
|
| 1326 | - : EE_INF, |
|
| 1327 | - 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
| 1328 | - 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
| 1329 | - 'TKT_order' => $ticket_data['TKT_order'] ?? $row, |
|
| 1330 | - 'TKT_price' => $ticket_price, |
|
| 1331 | - 'TKT_row' => $row, |
|
| 1332 | - ]; |
|
| 1333 | - // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1334 | - // which means in turn that the prices will become new prices as well. |
|
| 1335 | - if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
| 1336 | - $ticket_values['TKT_ID'] = 0; |
|
| 1337 | - $ticket_values['TKT_is_default'] = 0; |
|
| 1338 | - $update_prices = true; |
|
| 1339 | - } |
|
| 1340 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1341 | - // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
| 1342 | - // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
| 1343 | - // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
| 1344 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1345 | - if (! empty($ticket_data['TKT_ID'])) { |
|
| 1346 | - $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
| 1347 | - if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1348 | - throw new RuntimeException( |
|
| 1349 | - sprintf( |
|
| 1350 | - esc_html__( |
|
| 1351 | - 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1352 | - 'event_espresso' |
|
| 1353 | - ), |
|
| 1354 | - $ticket_data['TKT_ID'] |
|
| 1355 | - ) |
|
| 1356 | - ); |
|
| 1357 | - } |
|
| 1358 | - $ticket_sold = $existing_ticket->count_related( |
|
| 1359 | - 'Registration', |
|
| 1360 | - [ |
|
| 1361 | - [ |
|
| 1362 | - 'STS_ID' => [ |
|
| 1363 | - 'NOT IN', |
|
| 1364 | - [EEM_Registration::status_id_incomplete], |
|
| 1365 | - ], |
|
| 1366 | - ], |
|
| 1367 | - ] |
|
| 1368 | - ) > 0; |
|
| 1369 | - // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
| 1370 | - // if they are different then we create a new ticket (if $ticket_sold) |
|
| 1371 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 1372 | - $create_new_ticket = $ticket_sold |
|
| 1373 | - && $ticket_price !== $existing_ticket->price() |
|
| 1374 | - && ! $existing_ticket->deleted(); |
|
| 1375 | - $existing_ticket->set_date_format($date_formats[0]); |
|
| 1376 | - $existing_ticket->set_time_format($date_formats[1]); |
|
| 1377 | - // set new values |
|
| 1378 | - foreach ($ticket_values as $field => $value) { |
|
| 1379 | - if ($field == 'TKT_qty') { |
|
| 1380 | - $existing_ticket->set_qty($value); |
|
| 1381 | - } elseif ($field == 'TKT_price') { |
|
| 1382 | - $existing_ticket->set('TKT_price', $ticket_price); |
|
| 1383 | - } else { |
|
| 1384 | - $existing_ticket->set($field, $value); |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - $ticket = $existing_ticket; |
|
| 1388 | - // if $create_new_ticket is false then we can safely update the existing ticket. |
|
| 1389 | - // Otherwise we have to create a new ticket. |
|
| 1390 | - if ($create_new_ticket) { |
|
| 1391 | - // archive the old ticket first |
|
| 1392 | - $existing_ticket->set('TKT_deleted', 1); |
|
| 1393 | - $existing_ticket->save(); |
|
| 1394 | - // make sure this ticket is still recorded in our $saved_tickets |
|
| 1395 | - // so we don't run it through the regular trash routine. |
|
| 1396 | - $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1397 | - // create new ticket that's a copy of the existing except, |
|
| 1398 | - // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
| 1399 | - $new_ticket = clone $existing_ticket; |
|
| 1400 | - $new_ticket->set('TKT_ID', 0); |
|
| 1401 | - $new_ticket->set('TKT_deleted', 0); |
|
| 1402 | - $new_ticket->set('TKT_sold', 0); |
|
| 1403 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1404 | - $update_prices = true; |
|
| 1405 | - $ticket = $new_ticket; |
|
| 1406 | - } |
|
| 1407 | - } else { |
|
| 1408 | - // no TKT_id so a new ticket |
|
| 1409 | - $ticket_values['TKT_price'] = $ticket_price; |
|
| 1410 | - $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
| 1411 | - $update_prices = true; |
|
| 1412 | - } |
|
| 1413 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1414 | - throw new RuntimeException( |
|
| 1415 | - sprintf( |
|
| 1416 | - esc_html__( |
|
| 1417 | - 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
| 1418 | - 'event_espresso' |
|
| 1419 | - ), |
|
| 1420 | - print_r($ticket_values, true) |
|
| 1421 | - ) |
|
| 1422 | - ); |
|
| 1423 | - } |
|
| 1424 | - // cap ticket qty by datetime reg limits |
|
| 1425 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 1426 | - // update ticket. |
|
| 1427 | - $ticket->save(); |
|
| 1428 | - // before going any further make sure our dates are setup correctly |
|
| 1429 | - // so that the end date is always equal or greater than the start date. |
|
| 1430 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 1431 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 1432 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 1433 | - $ticket->save(); |
|
| 1434 | - } |
|
| 1435 | - // initially let's add the ticket to the datetime |
|
| 1436 | - $datetime->_add_relation_to($ticket, 'Ticket'); |
|
| 1437 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1438 | - // add prices to ticket |
|
| 1439 | - $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ]) |
|
| 1440 | - ? $data['edit_prices'][ $row ] |
|
| 1441 | - : []; |
|
| 1442 | - $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices); |
|
| 1443 | - } |
|
| 1444 | - // however now we need to handle permanently deleting tickets via the ui. |
|
| 1445 | - // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1446 | - // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1447 | - // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1448 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1449 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1450 | - foreach ($tickets_removed as $id) { |
|
| 1451 | - $id = absint($id); |
|
| 1452 | - // get the ticket for this id |
|
| 1453 | - $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
| 1454 | - if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1455 | - continue; |
|
| 1456 | - } |
|
| 1457 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1458 | - // (remember this process can ONLY kick off if there are NO tickets sold) |
|
| 1459 | - $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
| 1460 | - foreach ($related_datetimes as $related_datetime) { |
|
| 1461 | - $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
| 1462 | - } |
|
| 1463 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1464 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1465 | - $ticket_to_remove->delete_related_permanently('Price'); |
|
| 1466 | - // finally let's delete this ticket |
|
| 1467 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1468 | - $ticket_to_remove->delete_permanently(); |
|
| 1469 | - } |
|
| 1470 | - return [$datetime, $saved_tickets]; |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - |
|
| 1474 | - /** |
|
| 1475 | - * This attaches a list of given prices to a ticket. |
|
| 1476 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
| 1477 | - * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
| 1478 | - * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
| 1479 | - * |
|
| 1480 | - * @access private |
|
| 1481 | - * @param array $prices_data Array of prices from the form. |
|
| 1482 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1483 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1484 | - * @return void |
|
| 1485 | - * @throws EE_Error |
|
| 1486 | - * @throws ReflectionException |
|
| 1487 | - */ |
|
| 1488 | - private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false) |
|
| 1489 | - { |
|
| 1490 | - $timezone = $ticket->get_timezone(); |
|
| 1491 | - foreach ($prices_data as $row => $price_data) { |
|
| 1492 | - $price_values = [ |
|
| 1493 | - 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
| 1494 | - 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
| 1495 | - 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
| 1496 | - 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
| 1497 | - 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
| 1498 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1499 | - 'PRC_order' => $row, |
|
| 1500 | - ]; |
|
| 1501 | - if ($new_prices || empty($price_values['PRC_ID'])) { |
|
| 1502 | - $price_values['PRC_ID'] = 0; |
|
| 1503 | - $price = EE_Price::new_instance($price_values, $timezone); |
|
| 1504 | - } else { |
|
| 1505 | - $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
| 1506 | - // update this price with new values |
|
| 1507 | - foreach ($price_values as $field => $new_price) { |
|
| 1508 | - $price->set($field, $new_price); |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - if (! $price instanceof EE_Price) { |
|
| 1512 | - throw new RuntimeException( |
|
| 1513 | - sprintf( |
|
| 1514 | - esc_html__( |
|
| 1515 | - 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
| 1516 | - 'event_espresso' |
|
| 1517 | - ), |
|
| 1518 | - print_r($price_values, true) |
|
| 1519 | - ) |
|
| 1520 | - ); |
|
| 1521 | - } |
|
| 1522 | - $price->save(); |
|
| 1523 | - $ticket->_add_relation_to($price, 'Price'); |
|
| 1524 | - } |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - /** |
|
| 1529 | - * Add in our autosave ajax handlers |
|
| 1530 | - */ |
|
| 1531 | - protected function _ee_autosave_create_new() |
|
| 1532 | - { |
|
| 1533 | - } |
|
| 1534 | - |
|
| 1535 | - |
|
| 1536 | - /** |
|
| 1537 | - * More autosave handlers. |
|
| 1538 | - */ |
|
| 1539 | - protected function _ee_autosave_edit() |
|
| 1540 | - { |
|
| 1541 | - } |
|
| 1542 | - |
|
| 1543 | - |
|
| 1544 | - /** |
|
| 1545 | - * @throws EE_Error |
|
| 1546 | - * @throws ReflectionException |
|
| 1547 | - */ |
|
| 1548 | - private function _generate_publish_box_extra_content() |
|
| 1549 | - { |
|
| 1550 | - // load formatter helper |
|
| 1551 | - // args for getting related registrations |
|
| 1552 | - $approved_query_args = [ |
|
| 1553 | - [ |
|
| 1554 | - 'REG_deleted' => 0, |
|
| 1555 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1556 | - ], |
|
| 1557 | - ]; |
|
| 1558 | - $not_approved_query_args = [ |
|
| 1559 | - [ |
|
| 1560 | - 'REG_deleted' => 0, |
|
| 1561 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1562 | - ], |
|
| 1563 | - ]; |
|
| 1564 | - $pending_payment_query_args = [ |
|
| 1565 | - [ |
|
| 1566 | - 'REG_deleted' => 0, |
|
| 1567 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1568 | - ], |
|
| 1569 | - ]; |
|
| 1570 | - // publish box |
|
| 1571 | - $publish_box_extra_args = [ |
|
| 1572 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1573 | - [ |
|
| 1574 | - 'action' => 'default', |
|
| 1575 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1576 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1577 | - 'use_filters' => true, |
|
| 1578 | - ], |
|
| 1579 | - REG_ADMIN_URL |
|
| 1580 | - ), |
|
| 1581 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1582 | - [ |
|
| 1583 | - 'action' => 'default', |
|
| 1584 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1585 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1586 | - 'use_filters' => true, |
|
| 1587 | - ], |
|
| 1588 | - REG_ADMIN_URL |
|
| 1589 | - ), |
|
| 1590 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1591 | - [ |
|
| 1592 | - 'action' => 'default', |
|
| 1593 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1594 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1595 | - 'use_filters' => true, |
|
| 1596 | - ], |
|
| 1597 | - REG_ADMIN_URL |
|
| 1598 | - ), |
|
| 1599 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1600 | - 'Registration', |
|
| 1601 | - $approved_query_args |
|
| 1602 | - ), |
|
| 1603 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1604 | - 'Registration', |
|
| 1605 | - $not_approved_query_args |
|
| 1606 | - ), |
|
| 1607 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1608 | - 'Registration', |
|
| 1609 | - $pending_payment_query_args |
|
| 1610 | - ), |
|
| 1611 | - 'misc_pub_section_class' => apply_filters( |
|
| 1612 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1613 | - 'misc-pub-section' |
|
| 1614 | - ), |
|
| 1615 | - ]; |
|
| 1616 | - ob_start(); |
|
| 1617 | - do_action( |
|
| 1618 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1619 | - $this->_cpt_model_obj |
|
| 1620 | - ); |
|
| 1621 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1622 | - // load template |
|
| 1623 | - EEH_Template::display_template( |
|
| 1624 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1625 | - $publish_box_extra_args |
|
| 1626 | - ); |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * @return EE_Event |
|
| 1632 | - */ |
|
| 1633 | - public function get_event_object() |
|
| 1634 | - { |
|
| 1635 | - return $this->_cpt_model_obj; |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - |
|
| 1639 | - |
|
| 1640 | - |
|
| 1641 | - /** METABOXES * */ |
|
| 1642 | - /** |
|
| 1643 | - * _register_event_editor_meta_boxes |
|
| 1644 | - * add all metaboxes related to the event_editor |
|
| 1645 | - * |
|
| 1646 | - * @return void |
|
| 1647 | - * @throws EE_Error |
|
| 1648 | - * @throws ReflectionException |
|
| 1649 | - */ |
|
| 1650 | - protected function _register_event_editor_meta_boxes() |
|
| 1651 | - { |
|
| 1652 | - $this->verify_cpt_object(); |
|
| 1653 | - $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1654 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1655 | - if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1656 | - $this->addMetaBox( |
|
| 1657 | - 'espresso_event_editor_event_options', |
|
| 1658 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1659 | - [$this, 'registration_options_meta_box'], |
|
| 1660 | - $this->page_slug, |
|
| 1661 | - 'side' |
|
| 1662 | - ); |
|
| 1663 | - } |
|
| 1664 | - if (! $use_advanced_editor) { |
|
| 1665 | - $this->addMetaBox( |
|
| 1666 | - 'espresso_event_editor_tickets', |
|
| 1667 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1668 | - [$this, 'ticket_metabox'], |
|
| 1669 | - $this->page_slug, |
|
| 1670 | - 'normal', |
|
| 1671 | - 'high' |
|
| 1672 | - ); |
|
| 1673 | - } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1674 | - add_action( |
|
| 1675 | - 'add_meta_boxes_espresso_events', |
|
| 1676 | - function () { |
|
| 1677 | - global $current_screen; |
|
| 1678 | - remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1679 | - }, |
|
| 1680 | - 99 |
|
| 1681 | - ); |
|
| 1682 | - } |
|
| 1683 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1684 | - // where a metabox has a related management page in the admin |
|
| 1685 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1686 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1687 | - } |
|
| 1688 | - |
|
| 1689 | - |
|
| 1690 | - /** |
|
| 1691 | - * @throws DomainException |
|
| 1692 | - * @throws EE_Error |
|
| 1693 | - * @throws ReflectionException |
|
| 1694 | - */ |
|
| 1695 | - public function ticket_metabox() |
|
| 1696 | - { |
|
| 1697 | - $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1698 | - // defaults for template args |
|
| 1699 | - $template_args = [ |
|
| 1700 | - 'ticket_rows' => '', |
|
| 1701 | - 'total_ticket_rows' => 1, |
|
| 1702 | - 'trash_icon' => 'dashicons dashicons-lock', |
|
| 1703 | - 'disabled' => '', |
|
| 1704 | - ]; |
|
| 1705 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1706 | - /** |
|
| 1707 | - * 1. Start with retrieving Datetimes |
|
| 1708 | - * 2. Fore each datetime get related tickets |
|
| 1709 | - * 3. For each ticket get related prices |
|
| 1710 | - */ |
|
| 1711 | - /** @var EEM_Datetime $datetime_model */ |
|
| 1712 | - $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
| 1713 | - /** @var EEM_Ticket $datetime_model */ |
|
| 1714 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1715 | - $times = $datetime_model->get_all_event_dates($event_id); |
|
| 1716 | - /** @type EE_Datetime $first_datetime */ |
|
| 1717 | - $first_datetime = reset($times); |
|
| 1718 | - // do we get related tickets? |
|
| 1719 | - if ( |
|
| 1720 | - $first_datetime instanceof EE_Datetime |
|
| 1721 | - && $first_datetime->ID() !== 0 |
|
| 1722 | - ) { |
|
| 1723 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1724 | - $template_args['time'] = $first_datetime; |
|
| 1725 | - $related_tickets = $first_datetime->tickets( |
|
| 1726 | - [ |
|
| 1727 | - ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1728 | - 'default_where_conditions' => 'none', |
|
| 1729 | - ] |
|
| 1730 | - ); |
|
| 1731 | - if (! empty($related_tickets)) { |
|
| 1732 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1733 | - $row = 0; |
|
| 1734 | - foreach ($related_tickets as $ticket) { |
|
| 1735 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1736 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1737 | - $row++; |
|
| 1738 | - } |
|
| 1739 | - } else { |
|
| 1740 | - $template_args['total_ticket_rows'] = 1; |
|
| 1741 | - /** @type EE_Ticket $ticket */ |
|
| 1742 | - $ticket = $ticket_model->create_default_object(); |
|
| 1743 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1744 | - } |
|
| 1745 | - } else { |
|
| 1746 | - $template_args['time'] = $times[0]; |
|
| 1747 | - /** @type EE_Ticket[] $tickets */ |
|
| 1748 | - $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1749 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1750 | - // NOTE: we're just sending the first default row |
|
| 1751 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1752 | - } |
|
| 1753 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1754 | - 'event_editor_event_datetimes_help_tab' |
|
| 1755 | - ); |
|
| 1756 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1757 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1758 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1759 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1760 | - $ticket_model->create_default_object(), |
|
| 1761 | - true |
|
| 1762 | - ); |
|
| 1763 | - $template = apply_filters( |
|
| 1764 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1765 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1766 | - ); |
|
| 1767 | - EEH_Template::display_template($template, $template_args); |
|
| 1768 | - } |
|
| 1769 | - |
|
| 1770 | - |
|
| 1771 | - /** |
|
| 1772 | - * Setup an individual ticket form for the decaf event editor page |
|
| 21 | + /** |
|
| 22 | + * primary key for the event model |
|
| 23 | + */ |
|
| 24 | + private int $EVT_ID = 0; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * This will hold the event object for event_details screen. |
|
| 28 | + * |
|
| 29 | + * @var EE_Event|null $_event |
|
| 30 | + */ |
|
| 31 | + protected ?EE_Event $_event = null; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This will hold the category object for category_details screen. |
|
| 35 | + */ |
|
| 36 | + protected ?stdClass $_category = null; |
|
| 37 | + |
|
| 38 | + protected ?EEM_Event $_event_model = null; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var EE_Event|EE_CPT_Base|null $_cpt_model_obj |
|
| 42 | + */ |
|
| 43 | + protected $_cpt_model_obj; |
|
| 44 | + |
|
| 45 | + protected ?NodeGroupDao $model_obj_node_group_persister = null; |
|
| 46 | + |
|
| 47 | + protected ?AdvancedEditorAdminFormSection $advanced_editor_admin_form = null; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Initialize page props for this admin page group. |
|
| 52 | + */ |
|
| 53 | + protected function _init_page_props() |
|
| 54 | + { |
|
| 55 | + // is there a evt_id in the request? |
|
| 56 | + $this->EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT); |
|
| 57 | + $this->EVT_ID = $this->request->getRequestParam('post', $this->EVT_ID, DataType::INT); |
|
| 58 | + $this->EVT_ID = $this->request->getRequestParam('post_ID', $this->EVT_ID, DataType::INT); |
|
| 59 | + |
|
| 60 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 61 | + $this->page_label = EVENTS_LABEL; |
|
| 62 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 63 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 64 | + $this->_cpt_model_names = [ |
|
| 65 | + 'create_new' => 'EEM_Event', |
|
| 66 | + 'edit' => 'EEM_Event', |
|
| 67 | + ]; |
|
| 68 | + $this->_cpt_edit_routes = [ |
|
| 69 | + 'espresso_events' => 'edit', |
|
| 70 | + ]; |
|
| 71 | + add_action( |
|
| 72 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 73 | + [$this, 'verify_event_edit'], |
|
| 74 | + 10, |
|
| 75 | + 2 |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Sets the ajax hooks used for this admin page group. |
|
| 82 | + */ |
|
| 83 | + protected function _ajax_hooks() |
|
| 84 | + { |
|
| 85 | + add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Sets the page properties for this admin page group. |
|
| 91 | + */ |
|
| 92 | + protected function _define_page_props() |
|
| 93 | + { |
|
| 94 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 95 | + $this->_labels = [ |
|
| 96 | + 'buttons' => [ |
|
| 97 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 98 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 99 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 100 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 101 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 102 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 103 | + ], |
|
| 104 | + 'editor_title' => [ |
|
| 105 | + 'espresso_events' => esc_html__('Edit Event', 'event_espresso'), |
|
| 106 | + ], |
|
| 107 | + 'publishbox' => [ |
|
| 108 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 109 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 110 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 111 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 112 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 113 | + ], |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Sets the page routes property for this admin page group. |
|
| 120 | + */ |
|
| 121 | + protected function _set_page_routes() |
|
| 122 | + { |
|
| 123 | + $this->_page_routes = [ |
|
| 124 | + 'default' => [ |
|
| 125 | + 'func' => [$this, '_events_overview_list_table'], |
|
| 126 | + 'capability' => 'ee_read_events', |
|
| 127 | + ], |
|
| 128 | + 'create_new' => [ |
|
| 129 | + 'func' => [$this, '_create_new_cpt_item'], |
|
| 130 | + 'capability' => 'ee_edit_events', |
|
| 131 | + ], |
|
| 132 | + 'edit' => [ |
|
| 133 | + 'func' => [$this, '_edit_cpt_item'], |
|
| 134 | + 'capability' => 'ee_edit_event', |
|
| 135 | + 'obj_id' => $this->EVT_ID, |
|
| 136 | + ], |
|
| 137 | + 'copy_event' => [ |
|
| 138 | + 'func' => [$this, '_copy_events'], |
|
| 139 | + 'capability' => 'ee_edit_event', |
|
| 140 | + 'obj_id' => $this->EVT_ID, |
|
| 141 | + 'noheader' => true, |
|
| 142 | + ], |
|
| 143 | + 'trash_event' => [ |
|
| 144 | + 'func' => [$this, '_trash_or_restore_event'], |
|
| 145 | + 'args' => ['event_status' => 'trash'], |
|
| 146 | + 'capability' => 'ee_delete_event', |
|
| 147 | + 'obj_id' => $this->EVT_ID, |
|
| 148 | + 'noheader' => true, |
|
| 149 | + ], |
|
| 150 | + 'trash_events' => [ |
|
| 151 | + 'func' => [$this, '_trash_or_restore_events'], |
|
| 152 | + 'args' => ['event_status' => 'trash'], |
|
| 153 | + 'capability' => 'ee_delete_events', |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ], |
|
| 156 | + 'restore_event' => [ |
|
| 157 | + 'func' => [$this, '_trash_or_restore_event'], |
|
| 158 | + 'args' => ['event_status' => 'draft'], |
|
| 159 | + 'capability' => 'ee_delete_event', |
|
| 160 | + 'obj_id' => $this->EVT_ID, |
|
| 161 | + 'noheader' => true, |
|
| 162 | + ], |
|
| 163 | + 'restore_events' => [ |
|
| 164 | + 'func' => [$this, '_trash_or_restore_events'], |
|
| 165 | + 'args' => ['event_status' => 'draft'], |
|
| 166 | + 'capability' => 'ee_delete_events', |
|
| 167 | + 'noheader' => true, |
|
| 168 | + ], |
|
| 169 | + 'delete_event' => [ |
|
| 170 | + 'func' => [$this, '_delete_event'], |
|
| 171 | + 'capability' => 'ee_delete_event', |
|
| 172 | + 'obj_id' => $this->EVT_ID, |
|
| 173 | + 'noheader' => true, |
|
| 174 | + ], |
|
| 175 | + 'delete_events' => [ |
|
| 176 | + 'func' => [$this, '_delete_events'], |
|
| 177 | + 'capability' => 'ee_delete_events', |
|
| 178 | + 'noheader' => true, |
|
| 179 | + ], |
|
| 180 | + 'view_report' => [ |
|
| 181 | + 'func' => [$this, '_view_report'], |
|
| 182 | + 'capability' => 'ee_edit_events', |
|
| 183 | + ], |
|
| 184 | + 'default_event_settings' => [ |
|
| 185 | + 'func' => [$this, '_default_event_settings'], |
|
| 186 | + 'capability' => 'manage_options', |
|
| 187 | + ], |
|
| 188 | + 'update_default_event_settings' => [ |
|
| 189 | + 'func' => [$this, '_update_default_event_settings'], |
|
| 190 | + 'capability' => 'manage_options', |
|
| 191 | + 'noheader' => true, |
|
| 192 | + ], |
|
| 193 | + 'template_settings' => [ |
|
| 194 | + 'func' => [$this, '_template_settings'], |
|
| 195 | + 'capability' => 'manage_options', |
|
| 196 | + ], |
|
| 197 | + // event category tab related |
|
| 198 | + 'add_category' => [ |
|
| 199 | + 'func' => [$this, '_category_details'], |
|
| 200 | + 'capability' => 'ee_edit_event_category', |
|
| 201 | + 'args' => ['view' => 'add'], |
|
| 202 | + ], |
|
| 203 | + 'edit_category' => [ |
|
| 204 | + 'func' => [$this, '_category_details'], |
|
| 205 | + 'capability' => 'ee_edit_event_category', |
|
| 206 | + 'args' => ['view' => 'edit'], |
|
| 207 | + ], |
|
| 208 | + 'delete_categories' => [ |
|
| 209 | + 'func' => [$this, '_delete_categories'], |
|
| 210 | + 'capability' => 'ee_delete_event_category', |
|
| 211 | + 'noheader' => true, |
|
| 212 | + ], |
|
| 213 | + 'delete_category' => [ |
|
| 214 | + 'func' => [$this, '_delete_categories'], |
|
| 215 | + 'capability' => 'ee_delete_event_category', |
|
| 216 | + 'noheader' => true, |
|
| 217 | + ], |
|
| 218 | + 'insert_category' => [ |
|
| 219 | + 'func' => [$this, '_insert_or_update_category'], |
|
| 220 | + 'args' => ['new_category' => true], |
|
| 221 | + 'capability' => 'ee_edit_event_category', |
|
| 222 | + 'noheader' => true, |
|
| 223 | + ], |
|
| 224 | + 'update_category' => [ |
|
| 225 | + 'func' => [$this, '_insert_or_update_category'], |
|
| 226 | + 'args' => ['new_category' => false], |
|
| 227 | + 'capability' => 'ee_edit_event_category', |
|
| 228 | + 'noheader' => true, |
|
| 229 | + ], |
|
| 230 | + 'category_list' => [ |
|
| 231 | + 'func' => [$this, '_category_list_table'], |
|
| 232 | + 'capability' => 'ee_manage_event_categories', |
|
| 233 | + ], |
|
| 234 | + 'preview_deletion' => [ |
|
| 235 | + 'func' => [$this, 'previewDeletion'], |
|
| 236 | + 'capability' => 'ee_delete_events', |
|
| 237 | + ], |
|
| 238 | + 'confirm_deletion' => [ |
|
| 239 | + 'func' => [$this, 'confirmDeletion'], |
|
| 240 | + 'capability' => 'ee_delete_events', |
|
| 241 | + 'noheader' => true, |
|
| 242 | + ], |
|
| 243 | + ]; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Set the _page_config property for this admin page group. |
|
| 249 | + */ |
|
| 250 | + protected function _set_page_config() |
|
| 251 | + { |
|
| 252 | + $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
| 253 | + $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
| 254 | + $this->_page_config = [ |
|
| 255 | + 'default' => [ |
|
| 256 | + 'nav' => [ |
|
| 257 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 258 | + 'icon' => 'dashicons-list-view', |
|
| 259 | + 'order' => 10, |
|
| 260 | + ], |
|
| 261 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 262 | + 'help_tabs' => [ |
|
| 263 | + 'events_overview_help_tab' => [ |
|
| 264 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 265 | + 'filename' => 'events_overview', |
|
| 266 | + ], |
|
| 267 | + 'events_overview_table_column_headings_help_tab' => [ |
|
| 268 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 269 | + 'filename' => 'events_overview_table_column_headings', |
|
| 270 | + ], |
|
| 271 | + 'events_overview_filters_help_tab' => [ |
|
| 272 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 273 | + 'filename' => 'events_overview_filters', |
|
| 274 | + ], |
|
| 275 | + 'events_overview_view_help_tab' => [ |
|
| 276 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 277 | + 'filename' => 'events_overview_views', |
|
| 278 | + ], |
|
| 279 | + 'events_overview_other_help_tab' => [ |
|
| 280 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 281 | + 'filename' => 'events_overview_other', |
|
| 282 | + ], |
|
| 283 | + ], |
|
| 284 | + 'require_nonce' => false, |
|
| 285 | + ], |
|
| 286 | + 'create_new' => [ |
|
| 287 | + 'nav' => [ |
|
| 288 | + 'label' => esc_html__('Add New Event', 'event_espresso'), |
|
| 289 | + 'icon' => 'dashicons-plus-alt', |
|
| 290 | + 'order' => 15, |
|
| 291 | + 'persistent' => false, |
|
| 292 | + ], |
|
| 293 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 294 | + 'help_tabs' => [ |
|
| 295 | + 'event_editor_help_tab' => [ |
|
| 296 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 297 | + 'filename' => 'event_editor', |
|
| 298 | + ], |
|
| 299 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 300 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 301 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 302 | + ], |
|
| 303 | + 'event_editor_venue_details_help_tab' => [ |
|
| 304 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 305 | + 'filename' => 'event_editor_venue_details', |
|
| 306 | + ], |
|
| 307 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 308 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 309 | + 'filename' => 'event_editor_event_datetimes', |
|
| 310 | + ], |
|
| 311 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 312 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 313 | + 'filename' => 'event_editor_event_tickets', |
|
| 314 | + ], |
|
| 315 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 316 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 317 | + 'filename' => 'event_editor_event_registration_options', |
|
| 318 | + ], |
|
| 319 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 320 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 321 | + 'filename' => 'event_editor_tags_categories', |
|
| 322 | + ], |
|
| 323 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 324 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 325 | + 'filename' => 'event_editor_questions_registrants', |
|
| 326 | + ], |
|
| 327 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 328 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 329 | + 'filename' => 'event_editor_save_new_event', |
|
| 330 | + ], |
|
| 331 | + 'event_editor_other_help_tab' => [ |
|
| 332 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 333 | + 'filename' => 'event_editor_other', |
|
| 334 | + ], |
|
| 335 | + ], |
|
| 336 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 337 | + 'require_nonce' => false, |
|
| 338 | + ], |
|
| 339 | + 'edit' => [ |
|
| 340 | + 'nav' => [ |
|
| 341 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 342 | + 'icon' => 'dashicons-edit', |
|
| 343 | + 'order' => 15, |
|
| 344 | + 'persistent' => false, |
|
| 345 | + 'url' => $post_id |
|
| 346 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 347 | + ['post' => $post_id, 'action' => 'edit'], |
|
| 348 | + $this->_current_page_view_url |
|
| 349 | + ) |
|
| 350 | + : $this->_admin_base_url, |
|
| 351 | + ], |
|
| 352 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 353 | + 'help_tabs' => [ |
|
| 354 | + 'event_editor_help_tab' => [ |
|
| 355 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 356 | + 'filename' => 'event_editor', |
|
| 357 | + ], |
|
| 358 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 359 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 360 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 361 | + ], |
|
| 362 | + 'event_editor_venue_details_help_tab' => [ |
|
| 363 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 364 | + 'filename' => 'event_editor_venue_details', |
|
| 365 | + ], |
|
| 366 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 367 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 368 | + 'filename' => 'event_editor_event_datetimes', |
|
| 369 | + ], |
|
| 370 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 371 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 372 | + 'filename' => 'event_editor_event_tickets', |
|
| 373 | + ], |
|
| 374 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 375 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 376 | + 'filename' => 'event_editor_event_registration_options', |
|
| 377 | + ], |
|
| 378 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 379 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 380 | + 'filename' => 'event_editor_tags_categories', |
|
| 381 | + ], |
|
| 382 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 383 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 384 | + 'filename' => 'event_editor_questions_registrants', |
|
| 385 | + ], |
|
| 386 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 387 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 388 | + 'filename' => 'event_editor_save_new_event', |
|
| 389 | + ], |
|
| 390 | + 'event_editor_other_help_tab' => [ |
|
| 391 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 392 | + 'filename' => 'event_editor_other', |
|
| 393 | + ], |
|
| 394 | + ], |
|
| 395 | + 'require_nonce' => false, |
|
| 396 | + ], |
|
| 397 | + 'default_event_settings' => [ |
|
| 398 | + 'nav' => [ |
|
| 399 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 400 | + 'icon' => 'dashicons-admin-generic', |
|
| 401 | + 'order' => 40, |
|
| 402 | + ], |
|
| 403 | + 'metaboxes' => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes), |
|
| 404 | + 'labels' => [ |
|
| 405 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 406 | + ], |
|
| 407 | + 'help_tabs' => [ |
|
| 408 | + 'default_settings_help_tab' => [ |
|
| 409 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 410 | + 'filename' => 'events_default_settings', |
|
| 411 | + ], |
|
| 412 | + 'default_settings_status_help_tab' => [ |
|
| 413 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 414 | + 'filename' => 'events_default_settings_status', |
|
| 415 | + ], |
|
| 416 | + 'default_maximum_tickets_help_tab' => [ |
|
| 417 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 418 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 419 | + ], |
|
| 420 | + ], |
|
| 421 | + 'require_nonce' => false, |
|
| 422 | + ], |
|
| 423 | + // template settings |
|
| 424 | + 'template_settings' => [ |
|
| 425 | + 'nav' => [ |
|
| 426 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 427 | + 'icon' => 'dashicons-layout', |
|
| 428 | + 'order' => 30, |
|
| 429 | + ], |
|
| 430 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 431 | + 'help_tabs' => [ |
|
| 432 | + 'general_settings_templates_help_tab' => [ |
|
| 433 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 434 | + 'filename' => 'general_settings_templates', |
|
| 435 | + ], |
|
| 436 | + ], |
|
| 437 | + 'require_nonce' => false, |
|
| 438 | + ], |
|
| 439 | + // event category stuff |
|
| 440 | + 'add_category' => [ |
|
| 441 | + 'nav' => [ |
|
| 442 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 443 | + 'icon' => 'dashicons-plus-alt', |
|
| 444 | + 'order' => 25, |
|
| 445 | + 'persistent' => false, |
|
| 446 | + ], |
|
| 447 | + 'help_tabs' => [ |
|
| 448 | + 'add_category_help_tab' => [ |
|
| 449 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 450 | + 'filename' => 'events_add_category', |
|
| 451 | + ], |
|
| 452 | + ], |
|
| 453 | + 'metaboxes' => ['_publish_post_box'], |
|
| 454 | + 'require_nonce' => false, |
|
| 455 | + ], |
|
| 456 | + 'edit_category' => [ |
|
| 457 | + 'nav' => [ |
|
| 458 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 459 | + 'icon' => 'dashicons-edit', |
|
| 460 | + 'order' => 25, |
|
| 461 | + 'persistent' => false, |
|
| 462 | + 'url' => $EVT_CAT_ID |
|
| 463 | + ? add_query_arg( |
|
| 464 | + ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
| 465 | + $this->_current_page_view_url |
|
| 466 | + ) |
|
| 467 | + : $this->_admin_base_url, |
|
| 468 | + ], |
|
| 469 | + 'help_tabs' => [ |
|
| 470 | + 'edit_category_help_tab' => [ |
|
| 471 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 472 | + 'filename' => 'events_edit_category', |
|
| 473 | + ], |
|
| 474 | + ], |
|
| 475 | + 'metaboxes' => ['_publish_post_box'], |
|
| 476 | + 'require_nonce' => false, |
|
| 477 | + ], |
|
| 478 | + 'category_list' => [ |
|
| 479 | + 'nav' => [ |
|
| 480 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 481 | + 'icon' => 'dashicons-networking', |
|
| 482 | + 'order' => 20, |
|
| 483 | + ], |
|
| 484 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 485 | + 'help_tabs' => [ |
|
| 486 | + 'events_categories_help_tab' => [ |
|
| 487 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 488 | + 'filename' => 'events_categories', |
|
| 489 | + ], |
|
| 490 | + 'events_categories_table_column_headings_help_tab' => [ |
|
| 491 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 492 | + 'filename' => 'events_categories_table_column_headings', |
|
| 493 | + ], |
|
| 494 | + 'events_categories_view_help_tab' => [ |
|
| 495 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 496 | + 'filename' => 'events_categories_views', |
|
| 497 | + ], |
|
| 498 | + 'events_categories_other_help_tab' => [ |
|
| 499 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 500 | + 'filename' => 'events_categories_other', |
|
| 501 | + ], |
|
| 502 | + ], |
|
| 503 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 504 | + 'require_nonce' => false, |
|
| 505 | + ], |
|
| 506 | + 'preview_deletion' => [ |
|
| 507 | + 'nav' => [ |
|
| 508 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 509 | + 'icon' => 'dashicons-remove', |
|
| 510 | + 'order' => 15, |
|
| 511 | + 'persistent' => false, |
|
| 512 | + 'url' => '', |
|
| 513 | + ], |
|
| 514 | + 'require_nonce' => false, |
|
| 515 | + ], |
|
| 516 | + ]; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 522 | + */ |
|
| 523 | + protected function _add_screen_options() |
|
| 524 | + { |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Implementing the screen options for the 'default' route. |
|
| 530 | + * |
|
| 531 | + * @throws InvalidArgumentException |
|
| 532 | + * @throws InvalidDataTypeException |
|
| 533 | + * @throws InvalidInterfaceException |
|
| 534 | + */ |
|
| 535 | + protected function _add_screen_options_default() |
|
| 536 | + { |
|
| 537 | + $this->_per_page_screen_option(); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Implementing screen options for the category list route. |
|
| 543 | + * |
|
| 544 | + * @throws InvalidArgumentException |
|
| 545 | + * @throws InvalidDataTypeException |
|
| 546 | + * @throws InvalidInterfaceException |
|
| 547 | + */ |
|
| 548 | + protected function _add_screen_options_category_list() |
|
| 549 | + { |
|
| 550 | + $page_title = $this->_admin_page_title; |
|
| 551 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 552 | + $this->_per_page_screen_option(); |
|
| 553 | + $this->_admin_page_title = $page_title; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Used to register any global feature pointers for the admin page group. |
|
| 559 | + */ |
|
| 560 | + protected function _add_feature_pointers() |
|
| 561 | + { |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 567 | + */ |
|
| 568 | + public function load_scripts_styles() |
|
| 569 | + { |
|
| 570 | + wp_register_style( |
|
| 571 | + 'events-admin-css', |
|
| 572 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 573 | + [], |
|
| 574 | + EVENT_ESPRESSO_VERSION |
|
| 575 | + ); |
|
| 576 | + wp_register_style( |
|
| 577 | + 'ee-cat-admin', |
|
| 578 | + EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 579 | + [], |
|
| 580 | + EVENT_ESPRESSO_VERSION |
|
| 581 | + ); |
|
| 582 | + wp_enqueue_style('events-admin-css'); |
|
| 583 | + wp_enqueue_style('ee-cat-admin'); |
|
| 584 | + // scripts |
|
| 585 | + wp_register_script( |
|
| 586 | + 'event_editor_js', |
|
| 587 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 588 | + ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 589 | + EVENT_ESPRESSO_VERSION, |
|
| 590 | + true |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Enqueuing scripts and styles specific to this view |
|
| 597 | + */ |
|
| 598 | + public function load_scripts_styles_create_new() |
|
| 599 | + { |
|
| 600 | + $this->load_scripts_styles_edit(); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Enqueuing scripts and styles specific to this view |
|
| 606 | + */ |
|
| 607 | + public function load_scripts_styles_edit() |
|
| 608 | + { |
|
| 609 | + // styles |
|
| 610 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 611 | + wp_register_style( |
|
| 612 | + 'event-editor-css', |
|
| 613 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 614 | + ['ee-admin-css'], |
|
| 615 | + EVENT_ESPRESSO_VERSION |
|
| 616 | + ); |
|
| 617 | + wp_enqueue_style('event-editor-css'); |
|
| 618 | + // scripts |
|
| 619 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 620 | + wp_register_script( |
|
| 621 | + 'event-datetime-metabox', |
|
| 622 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 623 | + ['event_editor_js', 'ee-datepicker'], |
|
| 624 | + EVENT_ESPRESSO_VERSION |
|
| 625 | + ); |
|
| 626 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * Populating the _views property for the category list table view. |
|
| 633 | + */ |
|
| 634 | + protected function _set_list_table_views_category_list() |
|
| 635 | + { |
|
| 636 | + $this->_views = [ |
|
| 637 | + 'all' => [ |
|
| 638 | + 'slug' => 'all', |
|
| 639 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 640 | + 'count' => 0, |
|
| 641 | + 'bulk_action' => [ |
|
| 642 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 643 | + ], |
|
| 644 | + ], |
|
| 645 | + ]; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 651 | + */ |
|
| 652 | + public function admin_init() |
|
| 653 | + { |
|
| 654 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 655 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 656 | + 'event_espresso' |
|
| 657 | + ); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 663 | + * group. |
|
| 664 | + */ |
|
| 665 | + public function admin_notices() |
|
| 666 | + { |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 672 | + * this admin page group. |
|
| 673 | + */ |
|
| 674 | + public function admin_footer_scripts() |
|
| 675 | + { |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 681 | + * warning (via EE_Error::add_error()); |
|
| 682 | + * |
|
| 683 | + * @param EE_Event|null $event Event object |
|
| 684 | + * @param string $req_type |
|
| 685 | + * @return void |
|
| 686 | + * @throws EE_Error |
|
| 687 | + * @throws ReflectionException |
|
| 688 | + */ |
|
| 689 | + public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '') |
|
| 690 | + { |
|
| 691 | + // don't need to do this when processing |
|
| 692 | + if (! empty($req_type)) { |
|
| 693 | + return; |
|
| 694 | + } |
|
| 695 | + // no event? |
|
| 696 | + if (! $event instanceof EE_Event) { |
|
| 697 | + $event = $this->_cpt_model_obj; |
|
| 698 | + } |
|
| 699 | + // STILL no event? |
|
| 700 | + if (! $event instanceof EE_Event) { |
|
| 701 | + return; |
|
| 702 | + } |
|
| 703 | + // don't need to keep calling this |
|
| 704 | + remove_action( |
|
| 705 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 706 | + [$this, 'verify_event_edit'] |
|
| 707 | + ); |
|
| 708 | + $orig_status = $event->status(); |
|
| 709 | + // first check if event is active. |
|
| 710 | + if ( |
|
| 711 | + $orig_status === EEM_Event::cancelled |
|
| 712 | + || $orig_status === EEM_Event::postponed |
|
| 713 | + || $event->is_expired() |
|
| 714 | + || $event->is_inactive() |
|
| 715 | + ) { |
|
| 716 | + return; |
|
| 717 | + } |
|
| 718 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
| 719 | + if ($event->is_sold_out(true)) { |
|
| 720 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 721 | + EE_Error::add_attention( |
|
| 722 | + sprintf( |
|
| 723 | + esc_html__( |
|
| 724 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 725 | + 'event_espresso' |
|
| 726 | + ), |
|
| 727 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 728 | + ) |
|
| 729 | + ); |
|
| 730 | + } |
|
| 731 | + return; |
|
| 732 | + } |
|
| 733 | + if ($orig_status === EEM_Event::sold_out) { |
|
| 734 | + EE_Error::add_attention( |
|
| 735 | + sprintf( |
|
| 736 | + esc_html__( |
|
| 737 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 738 | + 'event_espresso' |
|
| 739 | + ), |
|
| 740 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 741 | + ) |
|
| 742 | + ); |
|
| 743 | + } |
|
| 744 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 745 | + if (! $event->tickets_on_sale()) { |
|
| 746 | + return; |
|
| 747 | + } |
|
| 748 | + // made it here so show warning |
|
| 749 | + $this->_edit_event_warning(); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 755 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 756 | + * |
|
| 757 | + * @access protected |
|
| 758 | + * @return void |
|
| 759 | + */ |
|
| 760 | + protected function _edit_event_warning() |
|
| 761 | + { |
|
| 762 | + // we don't want to add warnings during these requests |
|
| 763 | + if ($this->request->getRequestParam('action') === 'editpost') { |
|
| 764 | + return; |
|
| 765 | + } |
|
| 766 | + EE_Error::add_attention( |
|
| 767 | + sprintf( |
|
| 768 | + esc_html__( |
|
| 769 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 770 | + 'event_espresso' |
|
| 771 | + ), |
|
| 772 | + '<a class="espresso-help-tab-lnk ee-help-tab-link">', |
|
| 773 | + '</a>' |
|
| 774 | + ) |
|
| 775 | + ); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 781 | + * Otherwise, do the normal logic |
|
| 782 | + * |
|
| 783 | + * @return void |
|
| 784 | + * @throws EE_Error |
|
| 785 | + * @throws InvalidArgumentException |
|
| 786 | + * @throws InvalidDataTypeException |
|
| 787 | + * @throws InvalidInterfaceException |
|
| 788 | + * @throws ReflectionException |
|
| 789 | + */ |
|
| 790 | + protected function _create_new_cpt_item() |
|
| 791 | + { |
|
| 792 | + $has_timezone_string = get_option('timezone_string'); |
|
| 793 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 794 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 795 | + EE_Error::add_attention( |
|
| 796 | + sprintf( |
|
| 797 | + esc_html__( |
|
| 798 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 799 | + 'event_espresso' |
|
| 800 | + ), |
|
| 801 | + '<br>', |
|
| 802 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 803 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 804 | + . '</select>', |
|
| 805 | + '<button class="button button--secondary timezone-submit">', |
|
| 806 | + '</button><span class="spinner"></span>' |
|
| 807 | + ), |
|
| 808 | + __FILE__, |
|
| 809 | + __FUNCTION__, |
|
| 810 | + __LINE__ |
|
| 811 | + ); |
|
| 812 | + } |
|
| 813 | + parent::_create_new_cpt_item(); |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + /** |
|
| 818 | + * Sets the _views property for the default route in this admin page group. |
|
| 819 | + */ |
|
| 820 | + protected function _set_list_table_views_default() |
|
| 821 | + { |
|
| 822 | + $this->_views = [ |
|
| 823 | + 'all' => [ |
|
| 824 | + 'slug' => 'all', |
|
| 825 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 826 | + 'count' => 0, |
|
| 827 | + 'bulk_action' => [ |
|
| 828 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 829 | + ], |
|
| 830 | + ], |
|
| 831 | + 'draft' => [ |
|
| 832 | + 'slug' => 'draft', |
|
| 833 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 834 | + 'count' => 0, |
|
| 835 | + 'bulk_action' => [ |
|
| 836 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 837 | + ], |
|
| 838 | + ], |
|
| 839 | + ]; |
|
| 840 | + if ($this->capabilities->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 841 | + $this->_views['trash'] = [ |
|
| 842 | + 'slug' => 'trash', |
|
| 843 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 844 | + 'count' => 0, |
|
| 845 | + 'bulk_action' => [ |
|
| 846 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 847 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 848 | + ], |
|
| 849 | + ]; |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * Provides the legend item array for the default list table view. |
|
| 856 | + * |
|
| 857 | + * @return array |
|
| 858 | + * @throws EE_Error |
|
| 859 | + * @throws EE_Error |
|
| 860 | + */ |
|
| 861 | + protected function _event_legend_items(): array |
|
| 862 | + { |
|
| 863 | + $items = [ |
|
| 864 | + 'view_details' => [ |
|
| 865 | + 'class' => 'dashicons dashicons-visibility', |
|
| 866 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 867 | + ], |
|
| 868 | + 'edit_event' => [ |
|
| 869 | + 'class' => 'dashicons dashicons-calendar-alt', |
|
| 870 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 871 | + ], |
|
| 872 | + 'view_attendees' => [ |
|
| 873 | + 'class' => 'dashicons dashicons-groups', |
|
| 874 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 875 | + ], |
|
| 876 | + ]; |
|
| 877 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 878 | + $statuses = [ |
|
| 879 | + 'sold_out_status' => [ |
|
| 880 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out, |
|
| 881 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 882 | + ], |
|
| 883 | + 'active_status' => [ |
|
| 884 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active, |
|
| 885 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 886 | + ], |
|
| 887 | + 'upcoming_status' => [ |
|
| 888 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming, |
|
| 889 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 890 | + ], |
|
| 891 | + 'postponed_status' => [ |
|
| 892 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed, |
|
| 893 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 894 | + ], |
|
| 895 | + 'cancelled_status' => [ |
|
| 896 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled, |
|
| 897 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 898 | + ], |
|
| 899 | + 'expired_status' => [ |
|
| 900 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired, |
|
| 901 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 902 | + ], |
|
| 903 | + 'inactive_status' => [ |
|
| 904 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive, |
|
| 905 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 906 | + ], |
|
| 907 | + ]; |
|
| 908 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 909 | + return array_merge($items, $statuses); |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * @return EEM_Event |
|
| 915 | + * @throws EE_Error |
|
| 916 | + * @throws InvalidArgumentException |
|
| 917 | + * @throws InvalidDataTypeException |
|
| 918 | + * @throws InvalidInterfaceException |
|
| 919 | + * @throws ReflectionException |
|
| 920 | + */ |
|
| 921 | + private function _event_model(): EEM_Event |
|
| 922 | + { |
|
| 923 | + if (! $this->_event_model instanceof EEM_Event) { |
|
| 924 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 925 | + } |
|
| 926 | + return $this->_event_model; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 932 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 933 | + * |
|
| 934 | + * @param string $return the current html |
|
| 935 | + * @param int $id the post id for the page |
|
| 936 | + * @param string|null $new_title What the title is |
|
| 937 | + * @param string|null $new_slug what the slug is |
|
| 938 | + * @return string The new html string for the permalink area |
|
| 939 | + * @deprecated 5.0.0.p |
|
| 940 | + * @see TicketSelectorShortcodeButton::addButton |
|
| 941 | + */ |
|
| 942 | + public function extra_permalink_field_buttons( |
|
| 943 | + string $return, |
|
| 944 | + int $id, |
|
| 945 | + ?string $new_title, |
|
| 946 | + ?string $new_slug |
|
| 947 | + ): string { |
|
| 948 | + return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * _events_overview_list_table |
|
| 954 | + * This contains the logic for showing the events_overview list |
|
| 955 | + * |
|
| 956 | + * @access protected |
|
| 957 | + * @return void |
|
| 958 | + * @throws DomainException |
|
| 959 | + * @throws EE_Error |
|
| 960 | + * @throws InvalidArgumentException |
|
| 961 | + * @throws InvalidDataTypeException |
|
| 962 | + * @throws InvalidInterfaceException |
|
| 963 | + */ |
|
| 964 | + protected function _events_overview_list_table() |
|
| 965 | + { |
|
| 966 | + $after_list_table = []; |
|
| 967 | + $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack'); |
|
| 968 | + $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso')); |
|
| 969 | + $links_html .= EEH_HTML::div( |
|
| 970 | + EEH_Template::get_button_or_link( |
|
| 971 | + get_post_type_archive_link('espresso_events'), |
|
| 972 | + esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 973 | + 'button button--small button--secondary' |
|
| 974 | + ), |
|
| 975 | + '', |
|
| 976 | + 'ee-admin-button-row ee-admin-button-row--align-start' |
|
| 977 | + ); |
|
| 978 | + $links_html .= EEH_HTML::divx(); |
|
| 979 | + |
|
| 980 | + $after_list_table['view_event_list_button'] = $links_html; |
|
| 981 | + |
|
| 982 | + $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 983 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 984 | + 'create_new', |
|
| 985 | + 'add', |
|
| 986 | + [], |
|
| 987 | + 'add-new-h2' |
|
| 988 | + ); |
|
| 989 | + |
|
| 990 | + $this->_template_args['after_list_table'] = array_merge( |
|
| 991 | + (array) $this->_template_args['after_list_table'], |
|
| 992 | + $after_list_table |
|
| 993 | + ); |
|
| 994 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + |
|
| 998 | + /** |
|
| 999 | + * this allows for extra misc actions in the default WP publish box |
|
| 1000 | + * |
|
| 1001 | + * @return void |
|
| 1002 | + * @throws DomainException |
|
| 1003 | + * @throws EE_Error |
|
| 1004 | + * @throws InvalidArgumentException |
|
| 1005 | + * @throws InvalidDataTypeException |
|
| 1006 | + * @throws InvalidInterfaceException |
|
| 1007 | + * @throws ReflectionException |
|
| 1008 | + */ |
|
| 1009 | + public function extra_misc_actions_publish_box() |
|
| 1010 | + { |
|
| 1011 | + $this->_generate_publish_box_extra_content(); |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1017 | + * saved. |
|
| 1018 | + * Typically you would use this to save any additional data. |
|
| 1019 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1020 | + * ALSO very important. When a post transitions from scheduled to published, |
|
| 1021 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1022 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1023 | + * |
|
| 1024 | + * @access protected |
|
| 1025 | + * @abstract |
|
| 1026 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1027 | + * @param WP_Post $post The post object of the cpt that was saved. |
|
| 1028 | + * @return void |
|
| 1029 | + * @throws EE_Error |
|
| 1030 | + * @throws InvalidArgumentException |
|
| 1031 | + * @throws InvalidDataTypeException |
|
| 1032 | + * @throws InvalidInterfaceException |
|
| 1033 | + * @throws ReflectionException |
|
| 1034 | + */ |
|
| 1035 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 1036 | + { |
|
| 1037 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1038 | + // get out we're not processing an event save. |
|
| 1039 | + return; |
|
| 1040 | + } |
|
| 1041 | + $event_values = [ |
|
| 1042 | + 'EVT_member_only' => $this->request->getRequestParam('member_only', false, DataType::BOOL), |
|
| 1043 | + 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL), |
|
| 1044 | + 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
| 1045 | + ]; |
|
| 1046 | + // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1047 | + if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1048 | + $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
| 1049 | + 'display_ticket_selector', |
|
| 1050 | + false, |
|
| 1051 | + 'bool' |
|
| 1052 | + ); |
|
| 1053 | + $event_values['EVT_additional_limit'] = min( |
|
| 1054 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1055 | + $this->request->getRequestParam( |
|
| 1056 | + 'additional_limit', |
|
| 1057 | + EEM_Event::get_default_additional_limit(), |
|
| 1058 | + 'int' |
|
| 1059 | + ) |
|
| 1060 | + ); |
|
| 1061 | + $event_values['EVT_default_registration_status'] = $this->request->getRequestParam( |
|
| 1062 | + 'EVT_default_registration_status', |
|
| 1063 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 1064 | + ); |
|
| 1065 | + |
|
| 1066 | + $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL'); |
|
| 1067 | + $event_values['EVT_phone'] = $this->request->getRequestParam('event_phone'); |
|
| 1068 | + $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL); |
|
| 1069 | + } elseif ($post instanceof WP_Post) { |
|
| 1070 | + $event_values['EVT_name'] = $post->post_title; |
|
| 1071 | + $event_values['EVT_desc'] = $post->post_content; |
|
| 1072 | + } |
|
| 1073 | + // update event |
|
| 1074 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1075 | + // get event_object for other metaboxes... |
|
| 1076 | + // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1077 | + // i have to setup where conditions to override the filters in the model |
|
| 1078 | + // that filter out auto-draft and inherit statuses so we GET the inherit id! |
|
| 1079 | + /** @var EE_Event $event */ |
|
| 1080 | + $event = $this->_event_model()->get_one( |
|
| 1081 | + [ |
|
| 1082 | + [ |
|
| 1083 | + $this->_event_model()->primary_key_name() => $post_id, |
|
| 1084 | + 'OR' => [ |
|
| 1085 | + 'status' => $post->post_status, |
|
| 1086 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1087 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1088 | + 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
| 1089 | + ], |
|
| 1090 | + 'status' => ['NOT IN', ['auto-draft']], |
|
| 1091 | + ], |
|
| 1092 | + ] |
|
| 1093 | + ); |
|
| 1094 | + |
|
| 1095 | + // the following are default callbacks for event attachment updates |
|
| 1096 | + // that can be overridden by caffeinated functionality and/or addons. |
|
| 1097 | + $event_update_callbacks = []; |
|
| 1098 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 1099 | + $event_update_callbacks['_default_venue_update'] = [$this, '_default_venue_update']; |
|
| 1100 | + $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update']; |
|
| 1101 | + } |
|
| 1102 | + $event_update_callbacks = apply_filters( |
|
| 1103 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1104 | + $event_update_callbacks |
|
| 1105 | + ); |
|
| 1106 | + |
|
| 1107 | + $att_success = true; |
|
| 1108 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 1109 | + $_success = is_callable($e_callback) |
|
| 1110 | + ? $e_callback($event, $this->request->requestParams()) |
|
| 1111 | + : false; |
|
| 1112 | + // if ANY of these updates fail then we want the appropriate global error message |
|
| 1113 | + $att_success = $_success !== false ? $att_success : false; |
|
| 1114 | + } |
|
| 1115 | + // any errors? |
|
| 1116 | + if ($success && $att_success === false) { |
|
| 1117 | + EE_Error::add_error( |
|
| 1118 | + esc_html__( |
|
| 1119 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1120 | + 'event_espresso' |
|
| 1121 | + ), |
|
| 1122 | + __FILE__, |
|
| 1123 | + __FUNCTION__, |
|
| 1124 | + __LINE__ |
|
| 1125 | + ); |
|
| 1126 | + } elseif ($success === false) { |
|
| 1127 | + EE_Error::add_error( |
|
| 1128 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1129 | + __FILE__, |
|
| 1130 | + __FUNCTION__, |
|
| 1131 | + __LINE__ |
|
| 1132 | + ); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * @param int $post_id |
|
| 1139 | + * @param int $revision_id |
|
| 1140 | + * @throws EE_Error |
|
| 1141 | + * @throws EE_Error |
|
| 1142 | + * @throws ReflectionException |
|
| 1143 | + * @see parent::restore_item() |
|
| 1144 | + */ |
|
| 1145 | + protected function _restore_cpt_item(int $post_id, int $revision_id) |
|
| 1146 | + { |
|
| 1147 | + // copy existing event meta to new post |
|
| 1148 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1149 | + if ($post_evt instanceof EE_Event) { |
|
| 1150 | + // meta revision restore |
|
| 1151 | + $post_evt->restore_revision($revision_id); |
|
| 1152 | + // related objs restore |
|
| 1153 | + $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * Attach the venue to the Event |
|
| 1160 | + * |
|
| 1161 | + * @param EE_Event $event Event Object to add the venue to |
|
| 1162 | + * @param array $data The request data from the form |
|
| 1163 | + * @return bool Success or fail. |
|
| 1164 | + * @throws EE_Error |
|
| 1165 | + * @throws ReflectionException |
|
| 1166 | + */ |
|
| 1167 | + protected function _default_venue_update(EE_Event $event, array $data): bool |
|
| 1168 | + { |
|
| 1169 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1170 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1171 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1172 | + // very important. If we don't have a venue name... |
|
| 1173 | + // then we'll get out because not necessary to create empty venue |
|
| 1174 | + if (empty($data['venue_title'])) { |
|
| 1175 | + return false; |
|
| 1176 | + } |
|
| 1177 | + $venue_array = [ |
|
| 1178 | + 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
| 1179 | + 'VNU_name' => $data['venue_title'], |
|
| 1180 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1181 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1182 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
| 1183 | + ? $data['venue_short_description'] |
|
| 1184 | + : null, |
|
| 1185 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1186 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1187 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1188 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1189 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1190 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1191 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1192 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1193 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1194 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1195 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1196 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1197 | + 'status' => 'publish', |
|
| 1198 | + ]; |
|
| 1199 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1200 | + if (! empty($venue_id)) { |
|
| 1201 | + $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1202 | + $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1203 | + // we've gotta make sure that the venue is always attached to a revision.. |
|
| 1204 | + // add_relation_to should take care of making sure that the relation is already present. |
|
| 1205 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1206 | + return $rows_affected > 0; |
|
| 1207 | + } |
|
| 1208 | + // we insert the venue |
|
| 1209 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1210 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1211 | + return ! empty($venue_id); |
|
| 1212 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1218 | + * |
|
| 1219 | + * @param EE_Event $event The Event object we're attaching data to |
|
| 1220 | + * @param array $data The request data from the form |
|
| 1221 | + * @return array |
|
| 1222 | + * @throws EE_Error |
|
| 1223 | + * @throws ReflectionException |
|
| 1224 | + * @throws Exception |
|
| 1225 | + */ |
|
| 1226 | + protected function _default_tickets_update(EE_Event $event, array $data): array |
|
| 1227 | + { |
|
| 1228 | + if ($this->admin_config->useAdvancedEditor()) { |
|
| 1229 | + return []; |
|
| 1230 | + } |
|
| 1231 | + $datetime = null; |
|
| 1232 | + $saved_tickets = []; |
|
| 1233 | + $event_timezone = $event->get_timezone(); |
|
| 1234 | + $date_formats = ['Y-m-d', 'h:i a']; |
|
| 1235 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 1236 | + // trim all values to ensure any excess whitespace is removed. |
|
| 1237 | + $datetime_data = array_map('trim', $datetime_data); |
|
| 1238 | + $datetime_data['DTT_EVT_end'] = ! empty($datetime_data['DTT_EVT_end']) |
|
| 1239 | + ? $datetime_data['DTT_EVT_end'] |
|
| 1240 | + : $datetime_data['DTT_EVT_start']; |
|
| 1241 | + $datetime_values = [ |
|
| 1242 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
| 1243 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 1244 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 1245 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
| 1246 | + 'DTT_order' => $row, |
|
| 1247 | + ]; |
|
| 1248 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 1249 | + // Otherwise we instantiate a new object for save. |
|
| 1250 | + if (! empty($datetime_data['DTT_ID'])) { |
|
| 1251 | + $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 1252 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1253 | + throw new RuntimeException( |
|
| 1254 | + sprintf( |
|
| 1255 | + esc_html__( |
|
| 1256 | + 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1257 | + 'event_espresso' |
|
| 1258 | + ), |
|
| 1259 | + $datetime_data['DTT_ID'] |
|
| 1260 | + ) |
|
| 1261 | + ); |
|
| 1262 | + } |
|
| 1263 | + $datetime->set_date_format($date_formats[0]); |
|
| 1264 | + $datetime->set_time_format($date_formats[1]); |
|
| 1265 | + foreach ($datetime_values as $field => $value) { |
|
| 1266 | + $datetime->set($field, $value); |
|
| 1267 | + } |
|
| 1268 | + } else { |
|
| 1269 | + $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
| 1270 | + } |
|
| 1271 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1272 | + throw new RuntimeException( |
|
| 1273 | + sprintf( |
|
| 1274 | + esc_html__( |
|
| 1275 | + 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
| 1276 | + 'event_espresso' |
|
| 1277 | + ), |
|
| 1278 | + print_r($datetime_values, true) |
|
| 1279 | + ) |
|
| 1280 | + ); |
|
| 1281 | + } |
|
| 1282 | + // before going any further make sure our dates are setup correctly |
|
| 1283 | + // so that the end date is always equal or greater than the start date. |
|
| 1284 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 1285 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 1286 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 1287 | + } |
|
| 1288 | + $datetime->save(); |
|
| 1289 | + $event->_add_relation_to($datetime, 'Datetime'); |
|
| 1290 | + } |
|
| 1291 | + // no datetimes get deleted so we don't do any of that logic here. |
|
| 1292 | + // update tickets next |
|
| 1293 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1294 | + |
|
| 1295 | + // set up some default start and end dates in case those are not present in the incoming data |
|
| 1296 | + $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 1297 | + $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1298 | + // use the start date of the first datetime for the end date |
|
| 1299 | + $first_datetime = $event->first_datetime(); |
|
| 1300 | + $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
| 1301 | + |
|
| 1302 | + // now process the incoming data |
|
| 1303 | + foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
| 1304 | + $update_prices = false; |
|
| 1305 | + $ticket_price = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0; |
|
| 1306 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1307 | + $ticket_data = array_map('trim', $ticket_data); |
|
| 1308 | + $ticket_values = [ |
|
| 1309 | + 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
| 1310 | + 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
| 1311 | + 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
| 1312 | + 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
| 1313 | + 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
| 1314 | + ? $ticket_data['TKT_start_date'] |
|
| 1315 | + : $default_start_date, |
|
| 1316 | + 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
| 1317 | + ? $ticket_data['TKT_end_date'] |
|
| 1318 | + : $default_end_date, |
|
| 1319 | + 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
| 1320 | + || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
| 1321 | + ? $ticket_data['TKT_qty'] |
|
| 1322 | + : EE_INF, |
|
| 1323 | + 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
| 1324 | + || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
| 1325 | + ? $ticket_data['TKT_uses'] |
|
| 1326 | + : EE_INF, |
|
| 1327 | + 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
| 1328 | + 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
| 1329 | + 'TKT_order' => $ticket_data['TKT_order'] ?? $row, |
|
| 1330 | + 'TKT_price' => $ticket_price, |
|
| 1331 | + 'TKT_row' => $row, |
|
| 1332 | + ]; |
|
| 1333 | + // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1334 | + // which means in turn that the prices will become new prices as well. |
|
| 1335 | + if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
| 1336 | + $ticket_values['TKT_ID'] = 0; |
|
| 1337 | + $ticket_values['TKT_is_default'] = 0; |
|
| 1338 | + $update_prices = true; |
|
| 1339 | + } |
|
| 1340 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1341 | + // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
| 1342 | + // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
| 1343 | + // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
| 1344 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1345 | + if (! empty($ticket_data['TKT_ID'])) { |
|
| 1346 | + $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
| 1347 | + if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1348 | + throw new RuntimeException( |
|
| 1349 | + sprintf( |
|
| 1350 | + esc_html__( |
|
| 1351 | + 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1352 | + 'event_espresso' |
|
| 1353 | + ), |
|
| 1354 | + $ticket_data['TKT_ID'] |
|
| 1355 | + ) |
|
| 1356 | + ); |
|
| 1357 | + } |
|
| 1358 | + $ticket_sold = $existing_ticket->count_related( |
|
| 1359 | + 'Registration', |
|
| 1360 | + [ |
|
| 1361 | + [ |
|
| 1362 | + 'STS_ID' => [ |
|
| 1363 | + 'NOT IN', |
|
| 1364 | + [EEM_Registration::status_id_incomplete], |
|
| 1365 | + ], |
|
| 1366 | + ], |
|
| 1367 | + ] |
|
| 1368 | + ) > 0; |
|
| 1369 | + // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
| 1370 | + // if they are different then we create a new ticket (if $ticket_sold) |
|
| 1371 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 1372 | + $create_new_ticket = $ticket_sold |
|
| 1373 | + && $ticket_price !== $existing_ticket->price() |
|
| 1374 | + && ! $existing_ticket->deleted(); |
|
| 1375 | + $existing_ticket->set_date_format($date_formats[0]); |
|
| 1376 | + $existing_ticket->set_time_format($date_formats[1]); |
|
| 1377 | + // set new values |
|
| 1378 | + foreach ($ticket_values as $field => $value) { |
|
| 1379 | + if ($field == 'TKT_qty') { |
|
| 1380 | + $existing_ticket->set_qty($value); |
|
| 1381 | + } elseif ($field == 'TKT_price') { |
|
| 1382 | + $existing_ticket->set('TKT_price', $ticket_price); |
|
| 1383 | + } else { |
|
| 1384 | + $existing_ticket->set($field, $value); |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + $ticket = $existing_ticket; |
|
| 1388 | + // if $create_new_ticket is false then we can safely update the existing ticket. |
|
| 1389 | + // Otherwise we have to create a new ticket. |
|
| 1390 | + if ($create_new_ticket) { |
|
| 1391 | + // archive the old ticket first |
|
| 1392 | + $existing_ticket->set('TKT_deleted', 1); |
|
| 1393 | + $existing_ticket->save(); |
|
| 1394 | + // make sure this ticket is still recorded in our $saved_tickets |
|
| 1395 | + // so we don't run it through the regular trash routine. |
|
| 1396 | + $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1397 | + // create new ticket that's a copy of the existing except, |
|
| 1398 | + // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
| 1399 | + $new_ticket = clone $existing_ticket; |
|
| 1400 | + $new_ticket->set('TKT_ID', 0); |
|
| 1401 | + $new_ticket->set('TKT_deleted', 0); |
|
| 1402 | + $new_ticket->set('TKT_sold', 0); |
|
| 1403 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1404 | + $update_prices = true; |
|
| 1405 | + $ticket = $new_ticket; |
|
| 1406 | + } |
|
| 1407 | + } else { |
|
| 1408 | + // no TKT_id so a new ticket |
|
| 1409 | + $ticket_values['TKT_price'] = $ticket_price; |
|
| 1410 | + $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
| 1411 | + $update_prices = true; |
|
| 1412 | + } |
|
| 1413 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1414 | + throw new RuntimeException( |
|
| 1415 | + sprintf( |
|
| 1416 | + esc_html__( |
|
| 1417 | + 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
| 1418 | + 'event_espresso' |
|
| 1419 | + ), |
|
| 1420 | + print_r($ticket_values, true) |
|
| 1421 | + ) |
|
| 1422 | + ); |
|
| 1423 | + } |
|
| 1424 | + // cap ticket qty by datetime reg limits |
|
| 1425 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 1426 | + // update ticket. |
|
| 1427 | + $ticket->save(); |
|
| 1428 | + // before going any further make sure our dates are setup correctly |
|
| 1429 | + // so that the end date is always equal or greater than the start date. |
|
| 1430 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 1431 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 1432 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 1433 | + $ticket->save(); |
|
| 1434 | + } |
|
| 1435 | + // initially let's add the ticket to the datetime |
|
| 1436 | + $datetime->_add_relation_to($ticket, 'Ticket'); |
|
| 1437 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1438 | + // add prices to ticket |
|
| 1439 | + $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ]) |
|
| 1440 | + ? $data['edit_prices'][ $row ] |
|
| 1441 | + : []; |
|
| 1442 | + $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices); |
|
| 1443 | + } |
|
| 1444 | + // however now we need to handle permanently deleting tickets via the ui. |
|
| 1445 | + // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1446 | + // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1447 | + // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1448 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1449 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1450 | + foreach ($tickets_removed as $id) { |
|
| 1451 | + $id = absint($id); |
|
| 1452 | + // get the ticket for this id |
|
| 1453 | + $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
| 1454 | + if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1455 | + continue; |
|
| 1456 | + } |
|
| 1457 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1458 | + // (remember this process can ONLY kick off if there are NO tickets sold) |
|
| 1459 | + $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
| 1460 | + foreach ($related_datetimes as $related_datetime) { |
|
| 1461 | + $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
| 1462 | + } |
|
| 1463 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1464 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1465 | + $ticket_to_remove->delete_related_permanently('Price'); |
|
| 1466 | + // finally let's delete this ticket |
|
| 1467 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1468 | + $ticket_to_remove->delete_permanently(); |
|
| 1469 | + } |
|
| 1470 | + return [$datetime, $saved_tickets]; |
|
| 1471 | + } |
|
| 1472 | + |
|
| 1473 | + |
|
| 1474 | + /** |
|
| 1475 | + * This attaches a list of given prices to a ticket. |
|
| 1476 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
| 1477 | + * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
| 1478 | + * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
| 1479 | + * |
|
| 1480 | + * @access private |
|
| 1481 | + * @param array $prices_data Array of prices from the form. |
|
| 1482 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1483 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1484 | + * @return void |
|
| 1485 | + * @throws EE_Error |
|
| 1486 | + * @throws ReflectionException |
|
| 1487 | + */ |
|
| 1488 | + private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false) |
|
| 1489 | + { |
|
| 1490 | + $timezone = $ticket->get_timezone(); |
|
| 1491 | + foreach ($prices_data as $row => $price_data) { |
|
| 1492 | + $price_values = [ |
|
| 1493 | + 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
| 1494 | + 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
| 1495 | + 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
| 1496 | + 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
| 1497 | + 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
| 1498 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1499 | + 'PRC_order' => $row, |
|
| 1500 | + ]; |
|
| 1501 | + if ($new_prices || empty($price_values['PRC_ID'])) { |
|
| 1502 | + $price_values['PRC_ID'] = 0; |
|
| 1503 | + $price = EE_Price::new_instance($price_values, $timezone); |
|
| 1504 | + } else { |
|
| 1505 | + $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
| 1506 | + // update this price with new values |
|
| 1507 | + foreach ($price_values as $field => $new_price) { |
|
| 1508 | + $price->set($field, $new_price); |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + if (! $price instanceof EE_Price) { |
|
| 1512 | + throw new RuntimeException( |
|
| 1513 | + sprintf( |
|
| 1514 | + esc_html__( |
|
| 1515 | + 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
| 1516 | + 'event_espresso' |
|
| 1517 | + ), |
|
| 1518 | + print_r($price_values, true) |
|
| 1519 | + ) |
|
| 1520 | + ); |
|
| 1521 | + } |
|
| 1522 | + $price->save(); |
|
| 1523 | + $ticket->_add_relation_to($price, 'Price'); |
|
| 1524 | + } |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + /** |
|
| 1529 | + * Add in our autosave ajax handlers |
|
| 1530 | + */ |
|
| 1531 | + protected function _ee_autosave_create_new() |
|
| 1532 | + { |
|
| 1533 | + } |
|
| 1534 | + |
|
| 1535 | + |
|
| 1536 | + /** |
|
| 1537 | + * More autosave handlers. |
|
| 1538 | + */ |
|
| 1539 | + protected function _ee_autosave_edit() |
|
| 1540 | + { |
|
| 1541 | + } |
|
| 1542 | + |
|
| 1543 | + |
|
| 1544 | + /** |
|
| 1545 | + * @throws EE_Error |
|
| 1546 | + * @throws ReflectionException |
|
| 1547 | + */ |
|
| 1548 | + private function _generate_publish_box_extra_content() |
|
| 1549 | + { |
|
| 1550 | + // load formatter helper |
|
| 1551 | + // args for getting related registrations |
|
| 1552 | + $approved_query_args = [ |
|
| 1553 | + [ |
|
| 1554 | + 'REG_deleted' => 0, |
|
| 1555 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1556 | + ], |
|
| 1557 | + ]; |
|
| 1558 | + $not_approved_query_args = [ |
|
| 1559 | + [ |
|
| 1560 | + 'REG_deleted' => 0, |
|
| 1561 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1562 | + ], |
|
| 1563 | + ]; |
|
| 1564 | + $pending_payment_query_args = [ |
|
| 1565 | + [ |
|
| 1566 | + 'REG_deleted' => 0, |
|
| 1567 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1568 | + ], |
|
| 1569 | + ]; |
|
| 1570 | + // publish box |
|
| 1571 | + $publish_box_extra_args = [ |
|
| 1572 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1573 | + [ |
|
| 1574 | + 'action' => 'default', |
|
| 1575 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1576 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1577 | + 'use_filters' => true, |
|
| 1578 | + ], |
|
| 1579 | + REG_ADMIN_URL |
|
| 1580 | + ), |
|
| 1581 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1582 | + [ |
|
| 1583 | + 'action' => 'default', |
|
| 1584 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1585 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1586 | + 'use_filters' => true, |
|
| 1587 | + ], |
|
| 1588 | + REG_ADMIN_URL |
|
| 1589 | + ), |
|
| 1590 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1591 | + [ |
|
| 1592 | + 'action' => 'default', |
|
| 1593 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1594 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1595 | + 'use_filters' => true, |
|
| 1596 | + ], |
|
| 1597 | + REG_ADMIN_URL |
|
| 1598 | + ), |
|
| 1599 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1600 | + 'Registration', |
|
| 1601 | + $approved_query_args |
|
| 1602 | + ), |
|
| 1603 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1604 | + 'Registration', |
|
| 1605 | + $not_approved_query_args |
|
| 1606 | + ), |
|
| 1607 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1608 | + 'Registration', |
|
| 1609 | + $pending_payment_query_args |
|
| 1610 | + ), |
|
| 1611 | + 'misc_pub_section_class' => apply_filters( |
|
| 1612 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1613 | + 'misc-pub-section' |
|
| 1614 | + ), |
|
| 1615 | + ]; |
|
| 1616 | + ob_start(); |
|
| 1617 | + do_action( |
|
| 1618 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1619 | + $this->_cpt_model_obj |
|
| 1620 | + ); |
|
| 1621 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1622 | + // load template |
|
| 1623 | + EEH_Template::display_template( |
|
| 1624 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1625 | + $publish_box_extra_args |
|
| 1626 | + ); |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * @return EE_Event |
|
| 1632 | + */ |
|
| 1633 | + public function get_event_object() |
|
| 1634 | + { |
|
| 1635 | + return $this->_cpt_model_obj; |
|
| 1636 | + } |
|
| 1637 | + |
|
| 1638 | + |
|
| 1639 | + |
|
| 1640 | + |
|
| 1641 | + /** METABOXES * */ |
|
| 1642 | + /** |
|
| 1643 | + * _register_event_editor_meta_boxes |
|
| 1644 | + * add all metaboxes related to the event_editor |
|
| 1645 | + * |
|
| 1646 | + * @return void |
|
| 1647 | + * @throws EE_Error |
|
| 1648 | + * @throws ReflectionException |
|
| 1649 | + */ |
|
| 1650 | + protected function _register_event_editor_meta_boxes() |
|
| 1651 | + { |
|
| 1652 | + $this->verify_cpt_object(); |
|
| 1653 | + $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1654 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1655 | + if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1656 | + $this->addMetaBox( |
|
| 1657 | + 'espresso_event_editor_event_options', |
|
| 1658 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1659 | + [$this, 'registration_options_meta_box'], |
|
| 1660 | + $this->page_slug, |
|
| 1661 | + 'side' |
|
| 1662 | + ); |
|
| 1663 | + } |
|
| 1664 | + if (! $use_advanced_editor) { |
|
| 1665 | + $this->addMetaBox( |
|
| 1666 | + 'espresso_event_editor_tickets', |
|
| 1667 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1668 | + [$this, 'ticket_metabox'], |
|
| 1669 | + $this->page_slug, |
|
| 1670 | + 'normal', |
|
| 1671 | + 'high' |
|
| 1672 | + ); |
|
| 1673 | + } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1674 | + add_action( |
|
| 1675 | + 'add_meta_boxes_espresso_events', |
|
| 1676 | + function () { |
|
| 1677 | + global $current_screen; |
|
| 1678 | + remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1679 | + }, |
|
| 1680 | + 99 |
|
| 1681 | + ); |
|
| 1682 | + } |
|
| 1683 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1684 | + // where a metabox has a related management page in the admin |
|
| 1685 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1686 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1687 | + } |
|
| 1688 | + |
|
| 1689 | + |
|
| 1690 | + /** |
|
| 1691 | + * @throws DomainException |
|
| 1692 | + * @throws EE_Error |
|
| 1693 | + * @throws ReflectionException |
|
| 1694 | + */ |
|
| 1695 | + public function ticket_metabox() |
|
| 1696 | + { |
|
| 1697 | + $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1698 | + // defaults for template args |
|
| 1699 | + $template_args = [ |
|
| 1700 | + 'ticket_rows' => '', |
|
| 1701 | + 'total_ticket_rows' => 1, |
|
| 1702 | + 'trash_icon' => 'dashicons dashicons-lock', |
|
| 1703 | + 'disabled' => '', |
|
| 1704 | + ]; |
|
| 1705 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1706 | + /** |
|
| 1707 | + * 1. Start with retrieving Datetimes |
|
| 1708 | + * 2. Fore each datetime get related tickets |
|
| 1709 | + * 3. For each ticket get related prices |
|
| 1710 | + */ |
|
| 1711 | + /** @var EEM_Datetime $datetime_model */ |
|
| 1712 | + $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
| 1713 | + /** @var EEM_Ticket $datetime_model */ |
|
| 1714 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1715 | + $times = $datetime_model->get_all_event_dates($event_id); |
|
| 1716 | + /** @type EE_Datetime $first_datetime */ |
|
| 1717 | + $first_datetime = reset($times); |
|
| 1718 | + // do we get related tickets? |
|
| 1719 | + if ( |
|
| 1720 | + $first_datetime instanceof EE_Datetime |
|
| 1721 | + && $first_datetime->ID() !== 0 |
|
| 1722 | + ) { |
|
| 1723 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1724 | + $template_args['time'] = $first_datetime; |
|
| 1725 | + $related_tickets = $first_datetime->tickets( |
|
| 1726 | + [ |
|
| 1727 | + ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1728 | + 'default_where_conditions' => 'none', |
|
| 1729 | + ] |
|
| 1730 | + ); |
|
| 1731 | + if (! empty($related_tickets)) { |
|
| 1732 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1733 | + $row = 0; |
|
| 1734 | + foreach ($related_tickets as $ticket) { |
|
| 1735 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1736 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1737 | + $row++; |
|
| 1738 | + } |
|
| 1739 | + } else { |
|
| 1740 | + $template_args['total_ticket_rows'] = 1; |
|
| 1741 | + /** @type EE_Ticket $ticket */ |
|
| 1742 | + $ticket = $ticket_model->create_default_object(); |
|
| 1743 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1744 | + } |
|
| 1745 | + } else { |
|
| 1746 | + $template_args['time'] = $times[0]; |
|
| 1747 | + /** @type EE_Ticket[] $tickets */ |
|
| 1748 | + $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1749 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1750 | + // NOTE: we're just sending the first default row |
|
| 1751 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1752 | + } |
|
| 1753 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1754 | + 'event_editor_event_datetimes_help_tab' |
|
| 1755 | + ); |
|
| 1756 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1757 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1758 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1759 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1760 | + $ticket_model->create_default_object(), |
|
| 1761 | + true |
|
| 1762 | + ); |
|
| 1763 | + $template = apply_filters( |
|
| 1764 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1765 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1766 | + ); |
|
| 1767 | + EEH_Template::display_template($template, $template_args); |
|
| 1768 | + } |
|
| 1769 | + |
|
| 1770 | + |
|
| 1771 | + /** |
|
| 1772 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1773 | + * |
|
| 1774 | + * @access private |
|
| 1775 | + * @param EE_Ticket $ticket the ticket object |
|
| 1776 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1777 | + * @param int $row |
|
| 1778 | + * @return string generated html for the ticket row. |
|
| 1779 | + * @throws EE_Error |
|
| 1780 | + * @throws ReflectionException |
|
| 1781 | + */ |
|
| 1782 | + private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string |
|
| 1783 | + { |
|
| 1784 | + $template_args = [ |
|
| 1785 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1786 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1787 | + : '', |
|
| 1788 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1789 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1790 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1791 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1792 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1793 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1794 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1795 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1796 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1797 | + 'trash_icon' => ($skeleton || (! $ticket->get('TKT_deleted'))) |
|
| 1798 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1799 | + ? 'dashicons dashicons-post-trash clickable' |
|
| 1800 | + : 'dashicons dashicons-lock', |
|
| 1801 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1802 | + : ' disabled=disabled', |
|
| 1803 | + ]; |
|
| 1804 | + $price = $ticket->ID() !== 0 |
|
| 1805 | + ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1806 | + : null; |
|
| 1807 | + $price = $price instanceof EE_Price |
|
| 1808 | + ? $price |
|
| 1809 | + : EEM_Price::instance()->create_default_object(); |
|
| 1810 | + $price_args = [ |
|
| 1811 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1812 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1813 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1814 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1815 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1816 | + ]; |
|
| 1817 | + // make sure we have default start and end dates if skeleton |
|
| 1818 | + // handle rows that should NOT be empty |
|
| 1819 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1820 | + // if empty then the start date will be now. |
|
| 1821 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1822 | + } |
|
| 1823 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1824 | + // get the earliest datetime (if present); |
|
| 1825 | + $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1826 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1827 | + 'Datetime', |
|
| 1828 | + ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1829 | + ) |
|
| 1830 | + : null; |
|
| 1831 | + $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
| 1832 | + ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
| 1833 | + : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
| 1834 | + } |
|
| 1835 | + $template_args = array_merge($template_args, $price_args); |
|
| 1836 | + $template = apply_filters( |
|
| 1837 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1838 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1839 | + $ticket |
|
| 1840 | + ); |
|
| 1841 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * @throws EE_Error |
|
| 1847 | + * @throws ReflectionException |
|
| 1848 | + */ |
|
| 1849 | + public function registration_options_meta_box() |
|
| 1850 | + { |
|
| 1851 | + $yes_no_values = [ |
|
| 1852 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1853 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1854 | + ]; |
|
| 1855 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1856 | + [ |
|
| 1857 | + EEM_Registration::status_id_cancelled, |
|
| 1858 | + EEM_Registration::status_id_declined, |
|
| 1859 | + EEM_Registration::status_id_incomplete, |
|
| 1860 | + ], |
|
| 1861 | + true |
|
| 1862 | + ); |
|
| 1863 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1864 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1865 | + $template_args['event'] = $this->_cpt_model_obj; |
|
| 1866 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1867 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1868 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1869 | + 'default_reg_status', |
|
| 1870 | + $default_reg_status_values, |
|
| 1871 | + $this->_cpt_model_obj->default_registration_status(), |
|
| 1872 | + '', |
|
| 1873 | + 'ee-input-width--reg', |
|
| 1874 | + false |
|
| 1875 | + ); |
|
| 1876 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1877 | + 'display_desc', |
|
| 1878 | + $yes_no_values, |
|
| 1879 | + $this->_cpt_model_obj->display_description() |
|
| 1880 | + ); |
|
| 1881 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1882 | + 'display_ticket_selector', |
|
| 1883 | + $yes_no_values, |
|
| 1884 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1885 | + '', |
|
| 1886 | + 'ee-input-width--small', |
|
| 1887 | + false |
|
| 1888 | + ); |
|
| 1889 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1890 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1891 | + '', |
|
| 1892 | + $template_args, |
|
| 1893 | + $yes_no_values, |
|
| 1894 | + $default_reg_status_values |
|
| 1895 | + ); |
|
| 1896 | + EEH_Template::display_template( |
|
| 1897 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1898 | + $template_args |
|
| 1899 | + ); |
|
| 1900 | + } |
|
| 1901 | + |
|
| 1902 | + |
|
| 1903 | + /** |
|
| 1904 | + * _get_events() |
|
| 1905 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1906 | + * |
|
| 1907 | + * @access public |
|
| 1908 | + * @param int $per_page count of items per page (20 default); |
|
| 1909 | + * @param int $current_page what is the current page being viewed. |
|
| 1910 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1911 | + * If FALSE then we return an array of event objects |
|
| 1912 | + * that match the given _view and paging parameters. |
|
| 1913 | + * @return array|int an array of event objects or a count of them. |
|
| 1914 | + * @throws Exception |
|
| 1915 | + */ |
|
| 1916 | + public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
| 1917 | + { |
|
| 1918 | + $EEM_Event = $this->_event_model(); |
|
| 1919 | + $offset = ($current_page - 1) * $per_page; |
|
| 1920 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1921 | + $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
| 1922 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 1923 | + $month_range = $this->request->getRequestParam('month_range'); |
|
| 1924 | + if ($month_range) { |
|
| 1925 | + $pieces = explode(' ', $month_range, 3); |
|
| 1926 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1927 | + // where PHP doesn't know what to assume for date. |
|
| 1928 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1929 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1930 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1931 | + } |
|
| 1932 | + $where = []; |
|
| 1933 | + $status = $this->request->getRequestParam('status'); |
|
| 1934 | + // determine what post_status our condition will have for the query. |
|
| 1935 | + switch ($status) { |
|
| 1936 | + case 'month': |
|
| 1937 | + case 'today': |
|
| 1938 | + case null: |
|
| 1939 | + case 'all': |
|
| 1940 | + break; |
|
| 1941 | + case 'draft': |
|
| 1942 | + $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1943 | + break; |
|
| 1944 | + default: |
|
| 1945 | + $where['status'] = $status; |
|
| 1946 | + } |
|
| 1947 | + // categories? The default for all categories is -1 |
|
| 1948 | + $category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT); |
|
| 1949 | + if ($category !== -1) { |
|
| 1950 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1951 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1952 | + } |
|
| 1953 | + // date where conditions |
|
| 1954 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1955 | + if ($month_range) { |
|
| 1956 | + $DateTime = new DateTime( |
|
| 1957 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1958 | + new DateTimeZone('UTC') |
|
| 1959 | + ); |
|
| 1960 | + $start = $DateTime->getTimestamp(); |
|
| 1961 | + // set the datetime to be the end of the month |
|
| 1962 | + $DateTime->setDate( |
|
| 1963 | + $year_r, |
|
| 1964 | + $month_r, |
|
| 1965 | + $DateTime->format('t') |
|
| 1966 | + )->setTime(23, 59, 59); |
|
| 1967 | + $end = $DateTime->getTimestamp(); |
|
| 1968 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1969 | + } elseif ($status === 'today') { |
|
| 1970 | + $DateTime = new DateTime( |
|
| 1971 | + 'now', |
|
| 1972 | + new DateTimeZone(EEM_Event::instance()->get_timezone()) |
|
| 1973 | + ); |
|
| 1974 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1975 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1976 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1977 | + } elseif ($status === 'month') { |
|
| 1978 | + $now = date('Y-m-01'); |
|
| 1979 | + $DateTime = new DateTime( |
|
| 1980 | + $now, |
|
| 1981 | + new DateTimeZone(EEM_Event::instance()->get_timezone()) |
|
| 1982 | + ); |
|
| 1983 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1984 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1985 | + ->setTime(23, 59, 59) |
|
| 1986 | + ->format(implode(' ', $start_formats)); |
|
| 1987 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1988 | + } |
|
| 1989 | + if (! $this->capabilities->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1990 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1991 | + } else { |
|
| 1992 | + if (! isset($where['status'])) { |
|
| 1993 | + if (! $this->capabilities->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1994 | + $where['OR'] = [ |
|
| 1995 | + 'status*restrict_private' => ['!=', 'private'], |
|
| 1996 | + 'AND' => [ |
|
| 1997 | + 'status*inclusive' => ['=', 'private'], |
|
| 1998 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1999 | + ], |
|
| 2000 | + ]; |
|
| 2001 | + } |
|
| 2002 | + } |
|
| 2003 | + } |
|
| 2004 | + $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT); |
|
| 2005 | + if ( |
|
| 2006 | + $wp_user |
|
| 2007 | + && $wp_user !== get_current_user_id() |
|
| 2008 | + && $this->capabilities->current_user_can('ee_read_others_events', 'get_events') |
|
| 2009 | + ) { |
|
| 2010 | + $where['EVT_wp_user'] = $wp_user; |
|
| 2011 | + } |
|
| 2012 | + // search query handling |
|
| 2013 | + $search_term = $this->request->getRequestParam('s'); |
|
| 2014 | + if ($search_term) { |
|
| 2015 | + $search_term = '%' . $search_term . '%'; |
|
| 2016 | + $where['OR'] = [ |
|
| 2017 | + 'EVT_name' => ['LIKE', $search_term], |
|
| 2018 | + 'EVT_desc' => ['LIKE', $search_term], |
|
| 2019 | + 'EVT_short_desc' => ['LIKE', $search_term], |
|
| 2020 | + ]; |
|
| 2021 | + } |
|
| 2022 | + // filter events by venue. |
|
| 2023 | + $venue = $this->request->getRequestParam('venue', 0, DataType::INT); |
|
| 2024 | + if ($venue) { |
|
| 2025 | + $where['Venue.VNU_ID'] = $venue; |
|
| 2026 | + } |
|
| 2027 | + $request_params = $this->request->requestParams(); |
|
| 2028 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
| 2029 | + $query_params = apply_filters( |
|
| 2030 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2031 | + [ |
|
| 2032 | + $where, |
|
| 2033 | + 'limit' => $limit, |
|
| 2034 | + 'order_by' => $orderby, |
|
| 2035 | + 'order' => $order, |
|
| 2036 | + 'group_by' => 'EVT_ID', |
|
| 2037 | + ], |
|
| 2038 | + $request_params |
|
| 2039 | + ); |
|
| 2040 | + |
|
| 2041 | + // let's first check if we have special requests coming in. |
|
| 2042 | + $active_status = $this->request->getRequestParam('active_status'); |
|
| 2043 | + if ($active_status) { |
|
| 2044 | + switch ($active_status) { |
|
| 2045 | + case 'upcoming': |
|
| 2046 | + return $EEM_Event->get_upcoming_events($query_params, $count); |
|
| 2047 | + case 'expired': |
|
| 2048 | + return $EEM_Event->get_expired_events($query_params, $count); |
|
| 2049 | + case 'active': |
|
| 2050 | + return $EEM_Event->get_active_events($query_params, $count); |
|
| 2051 | + case 'inactive': |
|
| 2052 | + return $EEM_Event->get_inactive_events($query_params, $count); |
|
| 2053 | + } |
|
| 2054 | + } |
|
| 2055 | + |
|
| 2056 | + return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + |
|
| 2060 | + /** |
|
| 2061 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2062 | + * |
|
| 2063 | + * @param string $post_id |
|
| 2064 | + * @throws EE_Error |
|
| 2065 | + * @throws ReflectionException |
|
| 2066 | + */ |
|
| 2067 | + public function trash_cpt_item($post_id) |
|
| 2068 | + { |
|
| 2069 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2070 | + $this->_trash_or_restore_event('trash', false); |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * @param string $post_id |
|
| 2076 | + * @throws EE_Error |
|
| 2077 | + * @throws ReflectionException |
|
| 2078 | + */ |
|
| 2079 | + public function restore_cpt_item($post_id) |
|
| 2080 | + { |
|
| 2081 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2082 | + $this->_trash_or_restore_event('draft', false); |
|
| 2083 | + } |
|
| 2084 | + |
|
| 2085 | + |
|
| 2086 | + /** |
|
| 2087 | + * @param string $post_id |
|
| 2088 | + * @throws EE_Error |
|
| 2089 | + * @throws EE_Error |
|
| 2090 | + */ |
|
| 2091 | + public function delete_cpt_item($post_id) |
|
| 2092 | + { |
|
| 2093 | + throw new EE_Error( |
|
| 2094 | + esc_html__( |
|
| 2095 | + 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2096 | + 'event_espresso' |
|
| 2097 | + ) |
|
| 2098 | + ); |
|
| 2099 | + // $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2100 | + // $this->_delete_event(); |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * _trash_or_restore_event |
|
| 2106 | + * |
|
| 2107 | + * @access protected |
|
| 2108 | + * @param string $event_status |
|
| 2109 | + * @param bool $redirect_after |
|
| 2110 | + * @throws EE_Error |
|
| 2111 | + * @throws EE_Error |
|
| 2112 | + * @throws ReflectionException |
|
| 2113 | + */ |
|
| 2114 | + protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true) |
|
| 2115 | + { |
|
| 2116 | + // loop thru events |
|
| 2117 | + if ($this->EVT_ID) { |
|
| 2118 | + // clean status |
|
| 2119 | + $event_status = sanitize_key($event_status); |
|
| 2120 | + // grab status |
|
| 2121 | + if (! empty($event_status)) { |
|
| 2122 | + $success = $this->_change_event_status($this->EVT_ID, $event_status); |
|
| 2123 | + } else { |
|
| 2124 | + $success = false; |
|
| 2125 | + $msg = esc_html__( |
|
| 2126 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2127 | + 'event_espresso' |
|
| 2128 | + ); |
|
| 2129 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2130 | + } |
|
| 2131 | + } else { |
|
| 2132 | + $success = false; |
|
| 2133 | + $msg = esc_html__( |
|
| 2134 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2135 | + 'event_espresso' |
|
| 2136 | + ); |
|
| 2137 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2138 | + } |
|
| 2139 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2140 | + if ($redirect_after) { |
|
| 2141 | + $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2142 | + } |
|
| 2143 | + } |
|
| 2144 | + |
|
| 2145 | + |
|
| 2146 | + /** |
|
| 2147 | + * _trash_or_restore_events |
|
| 2148 | + * |
|
| 2149 | + * @access protected |
|
| 2150 | + * @param string $event_status |
|
| 2151 | + * @return void |
|
| 2152 | + * @throws EE_Error |
|
| 2153 | + * @throws EE_Error |
|
| 2154 | + * @throws ReflectionException |
|
| 2155 | + */ |
|
| 2156 | + protected function _trash_or_restore_events(string $event_status = 'trash') |
|
| 2157 | + { |
|
| 2158 | + // clean status |
|
| 2159 | + $event_status = sanitize_key($event_status); |
|
| 2160 | + // grab status |
|
| 2161 | + if (! empty($event_status)) { |
|
| 2162 | + $success = true; |
|
| 2163 | + // determine the event id and set to array. |
|
| 2164 | + $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2165 | + // loop thru events |
|
| 2166 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2167 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 2168 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2169 | + $success = $results !== false ? $success : false; |
|
| 2170 | + } else { |
|
| 2171 | + $msg = sprintf( |
|
| 2172 | + esc_html__( |
|
| 2173 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2174 | + 'event_espresso' |
|
| 2175 | + ), |
|
| 2176 | + $EVT_ID |
|
| 2177 | + ); |
|
| 2178 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2179 | + $success = false; |
|
| 2180 | + } |
|
| 2181 | + } |
|
| 2182 | + } else { |
|
| 2183 | + $success = false; |
|
| 2184 | + $msg = esc_html__( |
|
| 2185 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2186 | + 'event_espresso' |
|
| 2187 | + ); |
|
| 2188 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2189 | + } |
|
| 2190 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2191 | + $success = $success ? 2 : false; |
|
| 2192 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2193 | + $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2194 | + } |
|
| 2195 | + |
|
| 2196 | + |
|
| 2197 | + /** |
|
| 2198 | + * @param int $EVT_ID |
|
| 2199 | + * @param string $event_status |
|
| 2200 | + * @return bool |
|
| 2201 | + * @throws EE_Error |
|
| 2202 | + * @throws ReflectionException |
|
| 2203 | + */ |
|
| 2204 | + private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool |
|
| 2205 | + { |
|
| 2206 | + // grab event id |
|
| 2207 | + if (! $EVT_ID) { |
|
| 2208 | + $msg = esc_html__( |
|
| 2209 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2210 | + 'event_espresso' |
|
| 2211 | + ); |
|
| 2212 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2213 | + return false; |
|
| 2214 | + } |
|
| 2215 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2216 | + // clean status |
|
| 2217 | + $event_status = sanitize_key($event_status); |
|
| 2218 | + // grab status |
|
| 2219 | + if (empty($event_status)) { |
|
| 2220 | + $msg = esc_html__( |
|
| 2221 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2222 | + 'event_espresso' |
|
| 2223 | + ); |
|
| 2224 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2225 | + return false; |
|
| 2226 | + } |
|
| 2227 | + // was event trashed or restored ? |
|
| 2228 | + switch ($event_status) { |
|
| 2229 | + case 'draft': |
|
| 2230 | + $action = 'restored from the trash'; |
|
| 2231 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2232 | + break; |
|
| 2233 | + case 'trash': |
|
| 2234 | + $action = 'moved to the trash'; |
|
| 2235 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2236 | + break; |
|
| 2237 | + default: |
|
| 2238 | + $action = 'updated'; |
|
| 2239 | + $hook = false; |
|
| 2240 | + } |
|
| 2241 | + // use class to change status |
|
| 2242 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2243 | + $success = $this->_cpt_model_obj->save(); |
|
| 2244 | + if (! $success) { |
|
| 2245 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2246 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2247 | + return false; |
|
| 2248 | + } |
|
| 2249 | + if ($hook) { |
|
| 2250 | + do_action($hook); |
|
| 2251 | + // fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore() |
|
| 2252 | + // because events side step that and it otherwise won't get called |
|
| 2253 | + do_action( |
|
| 2254 | + 'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', |
|
| 2255 | + $this->_cpt_model_obj, |
|
| 2256 | + $hook === 'AHEE_event_moved_to_trash', |
|
| 2257 | + $success |
|
| 2258 | + ); |
|
| 2259 | + } |
|
| 2260 | + return true; |
|
| 2261 | + } |
|
| 2262 | + |
|
| 2263 | + |
|
| 2264 | + /** |
|
| 2265 | + * @param array $event_ids |
|
| 2266 | + * @return array |
|
| 2267 | + * @since 4.10.23.p |
|
| 2268 | + */ |
|
| 2269 | + private function cleanEventIds(array $event_ids): array |
|
| 2270 | + { |
|
| 2271 | + return array_map('absint', $event_ids); |
|
| 2272 | + } |
|
| 2273 | + |
|
| 2274 | + |
|
| 2275 | + /** |
|
| 2276 | + * @return array |
|
| 2277 | + * @since 4.10.23.p |
|
| 2278 | + */ |
|
| 2279 | + private function getEventIdsFromRequest(): array |
|
| 2280 | + { |
|
| 2281 | + if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
| 2282 | + return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2283 | + } else { |
|
| 2284 | + return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
| 2285 | + } |
|
| 2286 | + } |
|
| 2287 | + |
|
| 2288 | + |
|
| 2289 | + /** |
|
| 2290 | + * @param bool $preview_delete |
|
| 2291 | + * @throws EE_Error |
|
| 2292 | + * @throws ReflectionException |
|
| 2293 | + */ |
|
| 2294 | + protected function _delete_event(bool $preview_delete = true) |
|
| 2295 | + { |
|
| 2296 | + $this->_delete_events($preview_delete); |
|
| 2297 | + } |
|
| 2298 | + |
|
| 2299 | + |
|
| 2300 | + /** |
|
| 2301 | + * Gets the tree traversal batch persister. |
|
| 2302 | + * |
|
| 2303 | + * @return NodeGroupDao |
|
| 2304 | + * @throws InvalidArgumentException |
|
| 2305 | + * @throws InvalidDataTypeException |
|
| 2306 | + * @throws InvalidInterfaceException |
|
| 2307 | + * @since 4.10.12.p |
|
| 2308 | + */ |
|
| 2309 | + protected function getModelObjNodeGroupPersister(): NodeGroupDao |
|
| 2310 | + { |
|
| 2311 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2312 | + $this->model_obj_node_group_persister = |
|
| 2313 | + $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2314 | + } |
|
| 2315 | + return $this->model_obj_node_group_persister; |
|
| 2316 | + } |
|
| 2317 | + |
|
| 2318 | + |
|
| 2319 | + /** |
|
| 2320 | + * @param bool $preview_delete |
|
| 2321 | + * @return void |
|
| 2322 | + * @throws EE_Error |
|
| 2323 | + * @throws ReflectionException |
|
| 2324 | + */ |
|
| 2325 | + protected function _delete_events(bool $preview_delete = true) |
|
| 2326 | + { |
|
| 2327 | + $event_ids = $this->getEventIdsFromRequest(); |
|
| 2328 | + if ($preview_delete) { |
|
| 2329 | + $this->generateDeletionPreview($event_ids); |
|
| 2330 | + } else { |
|
| 2331 | + foreach ($event_ids as $event_id) { |
|
| 2332 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 2333 | + if ($event instanceof EE_Event) { |
|
| 2334 | + $event->delete_permanently(); |
|
| 2335 | + } |
|
| 2336 | + } |
|
| 2337 | + } |
|
| 2338 | + } |
|
| 2339 | + |
|
| 2340 | + |
|
| 2341 | + /** |
|
| 2342 | + * @param array $event_ids |
|
| 2343 | + */ |
|
| 2344 | + protected function generateDeletionPreview(array $event_ids) |
|
| 2345 | + { |
|
| 2346 | + $event_ids = $this->cleanEventIds($event_ids); |
|
| 2347 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2348 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2349 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2350 | + [ |
|
| 2351 | + 'action' => 'preview_deletion', |
|
| 2352 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2353 | + ], |
|
| 2354 | + $this->_admin_base_url |
|
| 2355 | + ); |
|
| 2356 | + EEH_URL::safeRedirectAndExit( |
|
| 2357 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2358 | + [ |
|
| 2359 | + 'page' => EED_Batch::PAGE_SLUG, |
|
| 2360 | + 'batch' => EED_Batch::batch_job, |
|
| 2361 | + 'EVT_IDs' => $event_ids, |
|
| 2362 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2363 | + 'job_handler' => urlencode('EventEspresso\core\libraries\batch\JobHandlers\PreviewEventDeletion'), |
|
| 2364 | + 'return_url' => urlencode($return_url), |
|
| 2365 | + ], |
|
| 2366 | + admin_url() |
|
| 2367 | + ) |
|
| 2368 | + ); |
|
| 2369 | + } |
|
| 2370 | + |
|
| 2371 | + |
|
| 2372 | + /** |
|
| 2373 | + * Checks for a POST submission |
|
| 2374 | + * |
|
| 2375 | + * @since 4.10.12.p |
|
| 2376 | + */ |
|
| 2377 | + protected function confirmDeletion() |
|
| 2378 | + { |
|
| 2379 | + $deletion_redirect_logic = $this->getLoader()->getShared( |
|
| 2380 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' |
|
| 2381 | + ); |
|
| 2382 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2383 | + } |
|
| 2384 | + |
|
| 2385 | + |
|
| 2386 | + /** |
|
| 2387 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2388 | + * |
|
| 2389 | + * @throws EE_Error |
|
| 2390 | + * @since 4.10.12.p |
|
| 2391 | + */ |
|
| 2392 | + protected function previewDeletion() |
|
| 2393 | + { |
|
| 2394 | + $preview_deletion_logic = $this->getLoader()->getShared( |
|
| 2395 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' |
|
| 2396 | + ); |
|
| 2397 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2398 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2399 | + } |
|
| 2400 | + |
|
| 2401 | + |
|
| 2402 | + /** |
|
| 2403 | + * get total number of events |
|
| 2404 | + * |
|
| 2405 | + * @access public |
|
| 2406 | + * @return int |
|
| 2407 | + * @throws EE_Error |
|
| 2408 | + * @throws EE_Error |
|
| 2409 | + * @throws ReflectionException |
|
| 2410 | + */ |
|
| 2411 | + public function total_events(): int |
|
| 2412 | + { |
|
| 2413 | + return EEM_Event::instance()->count( |
|
| 2414 | + ['caps' => 'read_admin'], |
|
| 2415 | + 'EVT_ID', |
|
| 2416 | + true |
|
| 2417 | + ); |
|
| 2418 | + } |
|
| 2419 | + |
|
| 2420 | + |
|
| 2421 | + /** |
|
| 2422 | + * get total number of draft events |
|
| 2423 | + * |
|
| 2424 | + * @access public |
|
| 2425 | + * @return int |
|
| 2426 | + * @throws EE_Error |
|
| 2427 | + * @throws EE_Error |
|
| 2428 | + * @throws ReflectionException |
|
| 2429 | + */ |
|
| 2430 | + public function total_events_draft(): int |
|
| 2431 | + { |
|
| 2432 | + return EEM_Event::instance()->count( |
|
| 2433 | + [ |
|
| 2434 | + ['status' => ['IN', ['draft', 'auto-draft']]], |
|
| 2435 | + 'caps' => 'read_admin', |
|
| 2436 | + ], |
|
| 2437 | + 'EVT_ID', |
|
| 2438 | + true |
|
| 2439 | + ); |
|
| 2440 | + } |
|
| 2441 | + |
|
| 2442 | + |
|
| 2443 | + /** |
|
| 2444 | + * get total number of trashed events |
|
| 2445 | + * |
|
| 2446 | + * @access public |
|
| 2447 | + * @return int |
|
| 2448 | + * @throws EE_Error |
|
| 2449 | + * @throws EE_Error |
|
| 2450 | + * @throws ReflectionException |
|
| 2451 | + */ |
|
| 2452 | + public function total_trashed_events(): int |
|
| 2453 | + { |
|
| 2454 | + return EEM_Event::instance()->count( |
|
| 2455 | + [ |
|
| 2456 | + ['status' => 'trash'], |
|
| 2457 | + 'caps' => 'read_admin', |
|
| 2458 | + ], |
|
| 2459 | + 'EVT_ID', |
|
| 2460 | + true |
|
| 2461 | + ); |
|
| 2462 | + } |
|
| 2463 | + |
|
| 2464 | + |
|
| 2465 | + /** |
|
| 2466 | + * _default_event_settings |
|
| 2467 | + * This generates the Default Settings Tab |
|
| 2468 | + * |
|
| 2469 | + * @return void |
|
| 2470 | + * @throws DomainException |
|
| 2471 | + * @throws EE_Error |
|
| 2472 | + * @throws InvalidArgumentException |
|
| 2473 | + * @throws InvalidDataTypeException |
|
| 2474 | + * @throws InvalidInterfaceException |
|
| 2475 | + * @throws ReflectionException |
|
| 2476 | + */ |
|
| 2477 | + protected function _default_event_settings() |
|
| 2478 | + { |
|
| 2479 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2480 | + $this->_set_publish_post_box_vars(); |
|
| 2481 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 2482 | + $this->_default_event_settings_form()->get_html(), |
|
| 2483 | + '', |
|
| 2484 | + 'padding' |
|
| 2485 | + ); |
|
| 2486 | + $this->display_admin_page_with_sidebar(); |
|
| 2487 | + } |
|
| 2488 | + |
|
| 2489 | + |
|
| 2490 | + /** |
|
| 2491 | + * Return the form for event settings. |
|
| 2492 | + * |
|
| 2493 | + * @return EE_Form_Section_Proper |
|
| 2494 | + * @throws EE_Error |
|
| 2495 | + * @throws ReflectionException |
|
| 2496 | + */ |
|
| 2497 | + protected function _default_event_settings_form(): EE_Form_Section_Proper |
|
| 2498 | + { |
|
| 2499 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2500 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2501 | + // exclude |
|
| 2502 | + [ |
|
| 2503 | + EEM_Registration::status_id_cancelled, |
|
| 2504 | + EEM_Registration::status_id_declined, |
|
| 2505 | + EEM_Registration::status_id_incomplete, |
|
| 2506 | + EEM_Registration::status_id_wait_list, |
|
| 2507 | + ], |
|
| 2508 | + true |
|
| 2509 | + ); |
|
| 2510 | + // setup Advanced Editor ??? |
|
| 2511 | + if ( |
|
| 2512 | + $this->raw_req_action === 'default_event_settings' |
|
| 2513 | + || $this->raw_req_action === 'update_default_event_settings' |
|
| 2514 | + ) { |
|
| 2515 | + $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class); |
|
| 2516 | + } |
|
| 2517 | + return new EE_Form_Section_Proper( |
|
| 2518 | + [ |
|
| 2519 | + 'name' => 'update_default_event_settings', |
|
| 2520 | + 'html_id' => 'update_default_event_settings', |
|
| 2521 | + 'html_class' => 'form-table', |
|
| 2522 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2523 | + 'subsections' => apply_filters( |
|
| 2524 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2525 | + [ |
|
| 2526 | + 'defaults_section_header' => new EE_Form_Section_HTML( |
|
| 2527 | + EEH_HTML::h2( |
|
| 2528 | + esc_html__('Default Settings', 'event_espresso'), |
|
| 2529 | + '', |
|
| 2530 | + 'ee-admin-settings-hdr' |
|
| 2531 | + ) |
|
| 2532 | + ), |
|
| 2533 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2534 | + $registration_stati_for_selection, |
|
| 2535 | + [ |
|
| 2536 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2537 | + && array_key_exists( |
|
| 2538 | + $registration_config->default_STS_ID, |
|
| 2539 | + $registration_stati_for_selection |
|
| 2540 | + ) |
|
| 2541 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2542 | + : EEM_Registration::status_id_pending_payment, |
|
| 2543 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2544 | + . EEH_Template::get_help_tab_link( |
|
| 2545 | + 'default_settings_status_help_tab' |
|
| 2546 | + ), |
|
| 2547 | + 'html_help_text' => esc_html__( |
|
| 2548 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2549 | + 'event_espresso' |
|
| 2550 | + ), |
|
| 2551 | + ] |
|
| 2552 | + ), |
|
| 2553 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2554 | + [ |
|
| 2555 | + 'default' => $registration_config->default_maximum_number_of_tickets |
|
| 2556 | + ?? EEM_Event::get_default_additional_limit(), |
|
| 2557 | + 'html_label_text' => esc_html__( |
|
| 2558 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2559 | + 'event_espresso' |
|
| 2560 | + ) |
|
| 2561 | + . EEH_Template::get_help_tab_link( |
|
| 2562 | + 'default_maximum_tickets_help_tab"' |
|
| 2563 | + ), |
|
| 2564 | + 'html_help_text' => esc_html__( |
|
| 2565 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2566 | + 'event_espresso' |
|
| 2567 | + ), |
|
| 2568 | + ] |
|
| 2569 | + ), |
|
| 2570 | + ] |
|
| 2571 | + ), |
|
| 2572 | + ] |
|
| 2573 | + ); |
|
| 2574 | + } |
|
| 2575 | + |
|
| 2576 | + |
|
| 2577 | + /** |
|
| 2578 | + * @return void |
|
| 2579 | + * @throws EE_Error |
|
| 2580 | + * @throws InvalidArgumentException |
|
| 2581 | + * @throws InvalidDataTypeException |
|
| 2582 | + * @throws InvalidInterfaceException |
|
| 2583 | + * @throws ReflectionException |
|
| 2584 | + */ |
|
| 2585 | + protected function _update_default_event_settings() |
|
| 2586 | + { |
|
| 2587 | + $form = $this->_default_event_settings_form(); |
|
| 2588 | + if ($form->was_submitted()) { |
|
| 2589 | + $form->receive_form_submission(); |
|
| 2590 | + if ($form->is_valid()) { |
|
| 2591 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2592 | + $valid_data = $form->valid_data(); |
|
| 2593 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2594 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2595 | + } |
|
| 2596 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2597 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2598 | + } |
|
| 2599 | + do_action( |
|
| 2600 | + 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2601 | + $valid_data, |
|
| 2602 | + EE_Registry::instance()->CFG, |
|
| 2603 | + $this |
|
| 2604 | + ); |
|
| 2605 | + // update because data was valid! |
|
| 2606 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2607 | + EE_Error::overwrite_success(); |
|
| 2608 | + EE_Error::add_success( |
|
| 2609 | + esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2610 | + ); |
|
| 2611 | + } |
|
| 2612 | + } |
|
| 2613 | + $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2614 | + } |
|
| 2615 | + |
|
| 2616 | + |
|
| 2617 | + /************* Templates ************* |
|
| 1773 | 2618 | * |
| 1774 | - * @access private |
|
| 1775 | - * @param EE_Ticket $ticket the ticket object |
|
| 1776 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1777 | - * @param int $row |
|
| 1778 | - * @return string generated html for the ticket row. |
|
| 1779 | - * @throws EE_Error |
|
| 1780 | - * @throws ReflectionException |
|
| 1781 | - */ |
|
| 1782 | - private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string |
|
| 1783 | - { |
|
| 1784 | - $template_args = [ |
|
| 1785 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1786 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1787 | - : '', |
|
| 1788 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1789 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1790 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1791 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1792 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1793 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1794 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1795 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1796 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1797 | - 'trash_icon' => ($skeleton || (! $ticket->get('TKT_deleted'))) |
|
| 1798 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1799 | - ? 'dashicons dashicons-post-trash clickable' |
|
| 1800 | - : 'dashicons dashicons-lock', |
|
| 1801 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1802 | - : ' disabled=disabled', |
|
| 1803 | - ]; |
|
| 1804 | - $price = $ticket->ID() !== 0 |
|
| 1805 | - ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1806 | - : null; |
|
| 1807 | - $price = $price instanceof EE_Price |
|
| 1808 | - ? $price |
|
| 1809 | - : EEM_Price::instance()->create_default_object(); |
|
| 1810 | - $price_args = [ |
|
| 1811 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1812 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1813 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1814 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1815 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1816 | - ]; |
|
| 1817 | - // make sure we have default start and end dates if skeleton |
|
| 1818 | - // handle rows that should NOT be empty |
|
| 1819 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1820 | - // if empty then the start date will be now. |
|
| 1821 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1822 | - } |
|
| 1823 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1824 | - // get the earliest datetime (if present); |
|
| 1825 | - $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1826 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1827 | - 'Datetime', |
|
| 1828 | - ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1829 | - ) |
|
| 1830 | - : null; |
|
| 1831 | - $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
| 1832 | - ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
| 1833 | - : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
| 1834 | - } |
|
| 1835 | - $template_args = array_merge($template_args, $price_args); |
|
| 1836 | - $template = apply_filters( |
|
| 1837 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1838 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1839 | - $ticket |
|
| 1840 | - ); |
|
| 1841 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * @throws EE_Error |
|
| 1847 | - * @throws ReflectionException |
|
| 1848 | - */ |
|
| 1849 | - public function registration_options_meta_box() |
|
| 1850 | - { |
|
| 1851 | - $yes_no_values = [ |
|
| 1852 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1853 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1854 | - ]; |
|
| 1855 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1856 | - [ |
|
| 1857 | - EEM_Registration::status_id_cancelled, |
|
| 1858 | - EEM_Registration::status_id_declined, |
|
| 1859 | - EEM_Registration::status_id_incomplete, |
|
| 1860 | - ], |
|
| 1861 | - true |
|
| 1862 | - ); |
|
| 1863 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1864 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1865 | - $template_args['event'] = $this->_cpt_model_obj; |
|
| 1866 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1867 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1868 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1869 | - 'default_reg_status', |
|
| 1870 | - $default_reg_status_values, |
|
| 1871 | - $this->_cpt_model_obj->default_registration_status(), |
|
| 1872 | - '', |
|
| 1873 | - 'ee-input-width--reg', |
|
| 1874 | - false |
|
| 1875 | - ); |
|
| 1876 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1877 | - 'display_desc', |
|
| 1878 | - $yes_no_values, |
|
| 1879 | - $this->_cpt_model_obj->display_description() |
|
| 1880 | - ); |
|
| 1881 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1882 | - 'display_ticket_selector', |
|
| 1883 | - $yes_no_values, |
|
| 1884 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1885 | - '', |
|
| 1886 | - 'ee-input-width--small', |
|
| 1887 | - false |
|
| 1888 | - ); |
|
| 1889 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1890 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1891 | - '', |
|
| 1892 | - $template_args, |
|
| 1893 | - $yes_no_values, |
|
| 1894 | - $default_reg_status_values |
|
| 1895 | - ); |
|
| 1896 | - EEH_Template::display_template( |
|
| 1897 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1898 | - $template_args |
|
| 1899 | - ); |
|
| 1900 | - } |
|
| 1901 | - |
|
| 1902 | - |
|
| 1903 | - /** |
|
| 1904 | - * _get_events() |
|
| 1905 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1906 | - * |
|
| 1907 | - * @access public |
|
| 1908 | - * @param int $per_page count of items per page (20 default); |
|
| 1909 | - * @param int $current_page what is the current page being viewed. |
|
| 1910 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1911 | - * If FALSE then we return an array of event objects |
|
| 1912 | - * that match the given _view and paging parameters. |
|
| 1913 | - * @return array|int an array of event objects or a count of them. |
|
| 1914 | - * @throws Exception |
|
| 1915 | - */ |
|
| 1916 | - public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
| 1917 | - { |
|
| 1918 | - $EEM_Event = $this->_event_model(); |
|
| 1919 | - $offset = ($current_page - 1) * $per_page; |
|
| 1920 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1921 | - $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
| 1922 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 1923 | - $month_range = $this->request->getRequestParam('month_range'); |
|
| 1924 | - if ($month_range) { |
|
| 1925 | - $pieces = explode(' ', $month_range, 3); |
|
| 1926 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1927 | - // where PHP doesn't know what to assume for date. |
|
| 1928 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1929 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1930 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1931 | - } |
|
| 1932 | - $where = []; |
|
| 1933 | - $status = $this->request->getRequestParam('status'); |
|
| 1934 | - // determine what post_status our condition will have for the query. |
|
| 1935 | - switch ($status) { |
|
| 1936 | - case 'month': |
|
| 1937 | - case 'today': |
|
| 1938 | - case null: |
|
| 1939 | - case 'all': |
|
| 1940 | - break; |
|
| 1941 | - case 'draft': |
|
| 1942 | - $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1943 | - break; |
|
| 1944 | - default: |
|
| 1945 | - $where['status'] = $status; |
|
| 1946 | - } |
|
| 1947 | - // categories? The default for all categories is -1 |
|
| 1948 | - $category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT); |
|
| 1949 | - if ($category !== -1) { |
|
| 1950 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1951 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1952 | - } |
|
| 1953 | - // date where conditions |
|
| 1954 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1955 | - if ($month_range) { |
|
| 1956 | - $DateTime = new DateTime( |
|
| 1957 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1958 | - new DateTimeZone('UTC') |
|
| 1959 | - ); |
|
| 1960 | - $start = $DateTime->getTimestamp(); |
|
| 1961 | - // set the datetime to be the end of the month |
|
| 1962 | - $DateTime->setDate( |
|
| 1963 | - $year_r, |
|
| 1964 | - $month_r, |
|
| 1965 | - $DateTime->format('t') |
|
| 1966 | - )->setTime(23, 59, 59); |
|
| 1967 | - $end = $DateTime->getTimestamp(); |
|
| 1968 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1969 | - } elseif ($status === 'today') { |
|
| 1970 | - $DateTime = new DateTime( |
|
| 1971 | - 'now', |
|
| 1972 | - new DateTimeZone(EEM_Event::instance()->get_timezone()) |
|
| 1973 | - ); |
|
| 1974 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1975 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1976 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1977 | - } elseif ($status === 'month') { |
|
| 1978 | - $now = date('Y-m-01'); |
|
| 1979 | - $DateTime = new DateTime( |
|
| 1980 | - $now, |
|
| 1981 | - new DateTimeZone(EEM_Event::instance()->get_timezone()) |
|
| 1982 | - ); |
|
| 1983 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1984 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1985 | - ->setTime(23, 59, 59) |
|
| 1986 | - ->format(implode(' ', $start_formats)); |
|
| 1987 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1988 | - } |
|
| 1989 | - if (! $this->capabilities->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1990 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1991 | - } else { |
|
| 1992 | - if (! isset($where['status'])) { |
|
| 1993 | - if (! $this->capabilities->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1994 | - $where['OR'] = [ |
|
| 1995 | - 'status*restrict_private' => ['!=', 'private'], |
|
| 1996 | - 'AND' => [ |
|
| 1997 | - 'status*inclusive' => ['=', 'private'], |
|
| 1998 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1999 | - ], |
|
| 2000 | - ]; |
|
| 2001 | - } |
|
| 2002 | - } |
|
| 2003 | - } |
|
| 2004 | - $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT); |
|
| 2005 | - if ( |
|
| 2006 | - $wp_user |
|
| 2007 | - && $wp_user !== get_current_user_id() |
|
| 2008 | - && $this->capabilities->current_user_can('ee_read_others_events', 'get_events') |
|
| 2009 | - ) { |
|
| 2010 | - $where['EVT_wp_user'] = $wp_user; |
|
| 2011 | - } |
|
| 2012 | - // search query handling |
|
| 2013 | - $search_term = $this->request->getRequestParam('s'); |
|
| 2014 | - if ($search_term) { |
|
| 2015 | - $search_term = '%' . $search_term . '%'; |
|
| 2016 | - $where['OR'] = [ |
|
| 2017 | - 'EVT_name' => ['LIKE', $search_term], |
|
| 2018 | - 'EVT_desc' => ['LIKE', $search_term], |
|
| 2019 | - 'EVT_short_desc' => ['LIKE', $search_term], |
|
| 2020 | - ]; |
|
| 2021 | - } |
|
| 2022 | - // filter events by venue. |
|
| 2023 | - $venue = $this->request->getRequestParam('venue', 0, DataType::INT); |
|
| 2024 | - if ($venue) { |
|
| 2025 | - $where['Venue.VNU_ID'] = $venue; |
|
| 2026 | - } |
|
| 2027 | - $request_params = $this->request->requestParams(); |
|
| 2028 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
| 2029 | - $query_params = apply_filters( |
|
| 2030 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2031 | - [ |
|
| 2032 | - $where, |
|
| 2033 | - 'limit' => $limit, |
|
| 2034 | - 'order_by' => $orderby, |
|
| 2035 | - 'order' => $order, |
|
| 2036 | - 'group_by' => 'EVT_ID', |
|
| 2037 | - ], |
|
| 2038 | - $request_params |
|
| 2039 | - ); |
|
| 2040 | - |
|
| 2041 | - // let's first check if we have special requests coming in. |
|
| 2042 | - $active_status = $this->request->getRequestParam('active_status'); |
|
| 2043 | - if ($active_status) { |
|
| 2044 | - switch ($active_status) { |
|
| 2045 | - case 'upcoming': |
|
| 2046 | - return $EEM_Event->get_upcoming_events($query_params, $count); |
|
| 2047 | - case 'expired': |
|
| 2048 | - return $EEM_Event->get_expired_events($query_params, $count); |
|
| 2049 | - case 'active': |
|
| 2050 | - return $EEM_Event->get_active_events($query_params, $count); |
|
| 2051 | - case 'inactive': |
|
| 2052 | - return $EEM_Event->get_inactive_events($query_params, $count); |
|
| 2053 | - } |
|
| 2054 | - } |
|
| 2055 | - |
|
| 2056 | - return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
| 2057 | - } |
|
| 2058 | - |
|
| 2059 | - |
|
| 2060 | - /** |
|
| 2061 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2062 | - * |
|
| 2063 | - * @param string $post_id |
|
| 2064 | - * @throws EE_Error |
|
| 2065 | - * @throws ReflectionException |
|
| 2066 | - */ |
|
| 2067 | - public function trash_cpt_item($post_id) |
|
| 2068 | - { |
|
| 2069 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2070 | - $this->_trash_or_restore_event('trash', false); |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * @param string $post_id |
|
| 2076 | - * @throws EE_Error |
|
| 2077 | - * @throws ReflectionException |
|
| 2078 | - */ |
|
| 2079 | - public function restore_cpt_item($post_id) |
|
| 2080 | - { |
|
| 2081 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2082 | - $this->_trash_or_restore_event('draft', false); |
|
| 2083 | - } |
|
| 2084 | - |
|
| 2085 | - |
|
| 2086 | - /** |
|
| 2087 | - * @param string $post_id |
|
| 2088 | - * @throws EE_Error |
|
| 2089 | - * @throws EE_Error |
|
| 2090 | - */ |
|
| 2091 | - public function delete_cpt_item($post_id) |
|
| 2092 | - { |
|
| 2093 | - throw new EE_Error( |
|
| 2094 | - esc_html__( |
|
| 2095 | - 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2096 | - 'event_espresso' |
|
| 2097 | - ) |
|
| 2098 | - ); |
|
| 2099 | - // $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2100 | - // $this->_delete_event(); |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * _trash_or_restore_event |
|
| 2106 | - * |
|
| 2107 | - * @access protected |
|
| 2108 | - * @param string $event_status |
|
| 2109 | - * @param bool $redirect_after |
|
| 2110 | - * @throws EE_Error |
|
| 2111 | - * @throws EE_Error |
|
| 2112 | - * @throws ReflectionException |
|
| 2113 | - */ |
|
| 2114 | - protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true) |
|
| 2115 | - { |
|
| 2116 | - // loop thru events |
|
| 2117 | - if ($this->EVT_ID) { |
|
| 2118 | - // clean status |
|
| 2119 | - $event_status = sanitize_key($event_status); |
|
| 2120 | - // grab status |
|
| 2121 | - if (! empty($event_status)) { |
|
| 2122 | - $success = $this->_change_event_status($this->EVT_ID, $event_status); |
|
| 2123 | - } else { |
|
| 2124 | - $success = false; |
|
| 2125 | - $msg = esc_html__( |
|
| 2126 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2127 | - 'event_espresso' |
|
| 2128 | - ); |
|
| 2129 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2130 | - } |
|
| 2131 | - } else { |
|
| 2132 | - $success = false; |
|
| 2133 | - $msg = esc_html__( |
|
| 2134 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2135 | - 'event_espresso' |
|
| 2136 | - ); |
|
| 2137 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2138 | - } |
|
| 2139 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2140 | - if ($redirect_after) { |
|
| 2141 | - $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2142 | - } |
|
| 2143 | - } |
|
| 2144 | - |
|
| 2145 | - |
|
| 2146 | - /** |
|
| 2147 | - * _trash_or_restore_events |
|
| 2148 | - * |
|
| 2149 | - * @access protected |
|
| 2150 | - * @param string $event_status |
|
| 2151 | - * @return void |
|
| 2152 | - * @throws EE_Error |
|
| 2153 | - * @throws EE_Error |
|
| 2154 | - * @throws ReflectionException |
|
| 2155 | - */ |
|
| 2156 | - protected function _trash_or_restore_events(string $event_status = 'trash') |
|
| 2157 | - { |
|
| 2158 | - // clean status |
|
| 2159 | - $event_status = sanitize_key($event_status); |
|
| 2160 | - // grab status |
|
| 2161 | - if (! empty($event_status)) { |
|
| 2162 | - $success = true; |
|
| 2163 | - // determine the event id and set to array. |
|
| 2164 | - $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2165 | - // loop thru events |
|
| 2166 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2167 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 2168 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2169 | - $success = $results !== false ? $success : false; |
|
| 2170 | - } else { |
|
| 2171 | - $msg = sprintf( |
|
| 2172 | - esc_html__( |
|
| 2173 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2174 | - 'event_espresso' |
|
| 2175 | - ), |
|
| 2176 | - $EVT_ID |
|
| 2177 | - ); |
|
| 2178 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2179 | - $success = false; |
|
| 2180 | - } |
|
| 2181 | - } |
|
| 2182 | - } else { |
|
| 2183 | - $success = false; |
|
| 2184 | - $msg = esc_html__( |
|
| 2185 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2186 | - 'event_espresso' |
|
| 2187 | - ); |
|
| 2188 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2189 | - } |
|
| 2190 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2191 | - $success = $success ? 2 : false; |
|
| 2192 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2193 | - $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2194 | - } |
|
| 2195 | - |
|
| 2196 | - |
|
| 2197 | - /** |
|
| 2198 | - * @param int $EVT_ID |
|
| 2199 | - * @param string $event_status |
|
| 2200 | - * @return bool |
|
| 2201 | - * @throws EE_Error |
|
| 2202 | - * @throws ReflectionException |
|
| 2203 | - */ |
|
| 2204 | - private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool |
|
| 2205 | - { |
|
| 2206 | - // grab event id |
|
| 2207 | - if (! $EVT_ID) { |
|
| 2208 | - $msg = esc_html__( |
|
| 2209 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2210 | - 'event_espresso' |
|
| 2211 | - ); |
|
| 2212 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2213 | - return false; |
|
| 2214 | - } |
|
| 2215 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2216 | - // clean status |
|
| 2217 | - $event_status = sanitize_key($event_status); |
|
| 2218 | - // grab status |
|
| 2219 | - if (empty($event_status)) { |
|
| 2220 | - $msg = esc_html__( |
|
| 2221 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2222 | - 'event_espresso' |
|
| 2223 | - ); |
|
| 2224 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2225 | - return false; |
|
| 2226 | - } |
|
| 2227 | - // was event trashed or restored ? |
|
| 2228 | - switch ($event_status) { |
|
| 2229 | - case 'draft': |
|
| 2230 | - $action = 'restored from the trash'; |
|
| 2231 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2232 | - break; |
|
| 2233 | - case 'trash': |
|
| 2234 | - $action = 'moved to the trash'; |
|
| 2235 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2236 | - break; |
|
| 2237 | - default: |
|
| 2238 | - $action = 'updated'; |
|
| 2239 | - $hook = false; |
|
| 2240 | - } |
|
| 2241 | - // use class to change status |
|
| 2242 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2243 | - $success = $this->_cpt_model_obj->save(); |
|
| 2244 | - if (! $success) { |
|
| 2245 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2246 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2247 | - return false; |
|
| 2248 | - } |
|
| 2249 | - if ($hook) { |
|
| 2250 | - do_action($hook); |
|
| 2251 | - // fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore() |
|
| 2252 | - // because events side step that and it otherwise won't get called |
|
| 2253 | - do_action( |
|
| 2254 | - 'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', |
|
| 2255 | - $this->_cpt_model_obj, |
|
| 2256 | - $hook === 'AHEE_event_moved_to_trash', |
|
| 2257 | - $success |
|
| 2258 | - ); |
|
| 2259 | - } |
|
| 2260 | - return true; |
|
| 2261 | - } |
|
| 2262 | - |
|
| 2263 | - |
|
| 2264 | - /** |
|
| 2265 | - * @param array $event_ids |
|
| 2266 | - * @return array |
|
| 2267 | - * @since 4.10.23.p |
|
| 2268 | - */ |
|
| 2269 | - private function cleanEventIds(array $event_ids): array |
|
| 2270 | - { |
|
| 2271 | - return array_map('absint', $event_ids); |
|
| 2272 | - } |
|
| 2273 | - |
|
| 2274 | - |
|
| 2275 | - /** |
|
| 2276 | - * @return array |
|
| 2277 | - * @since 4.10.23.p |
|
| 2278 | - */ |
|
| 2279 | - private function getEventIdsFromRequest(): array |
|
| 2280 | - { |
|
| 2281 | - if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
| 2282 | - return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2283 | - } else { |
|
| 2284 | - return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
| 2285 | - } |
|
| 2286 | - } |
|
| 2287 | - |
|
| 2288 | - |
|
| 2289 | - /** |
|
| 2290 | - * @param bool $preview_delete |
|
| 2291 | - * @throws EE_Error |
|
| 2292 | - * @throws ReflectionException |
|
| 2293 | - */ |
|
| 2294 | - protected function _delete_event(bool $preview_delete = true) |
|
| 2295 | - { |
|
| 2296 | - $this->_delete_events($preview_delete); |
|
| 2297 | - } |
|
| 2298 | - |
|
| 2299 | - |
|
| 2300 | - /** |
|
| 2301 | - * Gets the tree traversal batch persister. |
|
| 2302 | - * |
|
| 2303 | - * @return NodeGroupDao |
|
| 2304 | - * @throws InvalidArgumentException |
|
| 2305 | - * @throws InvalidDataTypeException |
|
| 2306 | - * @throws InvalidInterfaceException |
|
| 2307 | - * @since 4.10.12.p |
|
| 2308 | - */ |
|
| 2309 | - protected function getModelObjNodeGroupPersister(): NodeGroupDao |
|
| 2310 | - { |
|
| 2311 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2312 | - $this->model_obj_node_group_persister = |
|
| 2313 | - $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2314 | - } |
|
| 2315 | - return $this->model_obj_node_group_persister; |
|
| 2316 | - } |
|
| 2317 | - |
|
| 2318 | - |
|
| 2319 | - /** |
|
| 2320 | - * @param bool $preview_delete |
|
| 2321 | - * @return void |
|
| 2322 | - * @throws EE_Error |
|
| 2323 | - * @throws ReflectionException |
|
| 2324 | - */ |
|
| 2325 | - protected function _delete_events(bool $preview_delete = true) |
|
| 2326 | - { |
|
| 2327 | - $event_ids = $this->getEventIdsFromRequest(); |
|
| 2328 | - if ($preview_delete) { |
|
| 2329 | - $this->generateDeletionPreview($event_ids); |
|
| 2330 | - } else { |
|
| 2331 | - foreach ($event_ids as $event_id) { |
|
| 2332 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 2333 | - if ($event instanceof EE_Event) { |
|
| 2334 | - $event->delete_permanently(); |
|
| 2335 | - } |
|
| 2336 | - } |
|
| 2337 | - } |
|
| 2338 | - } |
|
| 2339 | - |
|
| 2340 | - |
|
| 2341 | - /** |
|
| 2342 | - * @param array $event_ids |
|
| 2343 | - */ |
|
| 2344 | - protected function generateDeletionPreview(array $event_ids) |
|
| 2345 | - { |
|
| 2346 | - $event_ids = $this->cleanEventIds($event_ids); |
|
| 2347 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2348 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2349 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2350 | - [ |
|
| 2351 | - 'action' => 'preview_deletion', |
|
| 2352 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2353 | - ], |
|
| 2354 | - $this->_admin_base_url |
|
| 2355 | - ); |
|
| 2356 | - EEH_URL::safeRedirectAndExit( |
|
| 2357 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2358 | - [ |
|
| 2359 | - 'page' => EED_Batch::PAGE_SLUG, |
|
| 2360 | - 'batch' => EED_Batch::batch_job, |
|
| 2361 | - 'EVT_IDs' => $event_ids, |
|
| 2362 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2363 | - 'job_handler' => urlencode('EventEspresso\core\libraries\batch\JobHandlers\PreviewEventDeletion'), |
|
| 2364 | - 'return_url' => urlencode($return_url), |
|
| 2365 | - ], |
|
| 2366 | - admin_url() |
|
| 2367 | - ) |
|
| 2368 | - ); |
|
| 2369 | - } |
|
| 2370 | - |
|
| 2371 | - |
|
| 2372 | - /** |
|
| 2373 | - * Checks for a POST submission |
|
| 2374 | - * |
|
| 2375 | - * @since 4.10.12.p |
|
| 2376 | - */ |
|
| 2377 | - protected function confirmDeletion() |
|
| 2378 | - { |
|
| 2379 | - $deletion_redirect_logic = $this->getLoader()->getShared( |
|
| 2380 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' |
|
| 2381 | - ); |
|
| 2382 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2383 | - } |
|
| 2384 | - |
|
| 2385 | - |
|
| 2386 | - /** |
|
| 2387 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2388 | - * |
|
| 2389 | - * @throws EE_Error |
|
| 2390 | - * @since 4.10.12.p |
|
| 2391 | - */ |
|
| 2392 | - protected function previewDeletion() |
|
| 2393 | - { |
|
| 2394 | - $preview_deletion_logic = $this->getLoader()->getShared( |
|
| 2395 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' |
|
| 2396 | - ); |
|
| 2397 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2398 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2399 | - } |
|
| 2400 | - |
|
| 2401 | - |
|
| 2402 | - /** |
|
| 2403 | - * get total number of events |
|
| 2404 | - * |
|
| 2405 | - * @access public |
|
| 2406 | - * @return int |
|
| 2407 | - * @throws EE_Error |
|
| 2408 | - * @throws EE_Error |
|
| 2409 | - * @throws ReflectionException |
|
| 2410 | - */ |
|
| 2411 | - public function total_events(): int |
|
| 2412 | - { |
|
| 2413 | - return EEM_Event::instance()->count( |
|
| 2414 | - ['caps' => 'read_admin'], |
|
| 2415 | - 'EVT_ID', |
|
| 2416 | - true |
|
| 2417 | - ); |
|
| 2418 | - } |
|
| 2419 | - |
|
| 2420 | - |
|
| 2421 | - /** |
|
| 2422 | - * get total number of draft events |
|
| 2423 | - * |
|
| 2424 | - * @access public |
|
| 2425 | - * @return int |
|
| 2426 | - * @throws EE_Error |
|
| 2427 | - * @throws EE_Error |
|
| 2428 | - * @throws ReflectionException |
|
| 2429 | - */ |
|
| 2430 | - public function total_events_draft(): int |
|
| 2431 | - { |
|
| 2432 | - return EEM_Event::instance()->count( |
|
| 2433 | - [ |
|
| 2434 | - ['status' => ['IN', ['draft', 'auto-draft']]], |
|
| 2435 | - 'caps' => 'read_admin', |
|
| 2436 | - ], |
|
| 2437 | - 'EVT_ID', |
|
| 2438 | - true |
|
| 2439 | - ); |
|
| 2440 | - } |
|
| 2441 | - |
|
| 2442 | - |
|
| 2443 | - /** |
|
| 2444 | - * get total number of trashed events |
|
| 2445 | - * |
|
| 2446 | - * @access public |
|
| 2447 | - * @return int |
|
| 2448 | - * @throws EE_Error |
|
| 2449 | - * @throws EE_Error |
|
| 2450 | - * @throws ReflectionException |
|
| 2451 | - */ |
|
| 2452 | - public function total_trashed_events(): int |
|
| 2453 | - { |
|
| 2454 | - return EEM_Event::instance()->count( |
|
| 2455 | - [ |
|
| 2456 | - ['status' => 'trash'], |
|
| 2457 | - 'caps' => 'read_admin', |
|
| 2458 | - ], |
|
| 2459 | - 'EVT_ID', |
|
| 2460 | - true |
|
| 2461 | - ); |
|
| 2462 | - } |
|
| 2463 | - |
|
| 2464 | - |
|
| 2465 | - /** |
|
| 2466 | - * _default_event_settings |
|
| 2467 | - * This generates the Default Settings Tab |
|
| 2468 | - * |
|
| 2469 | - * @return void |
|
| 2470 | - * @throws DomainException |
|
| 2471 | - * @throws EE_Error |
|
| 2472 | - * @throws InvalidArgumentException |
|
| 2473 | - * @throws InvalidDataTypeException |
|
| 2474 | - * @throws InvalidInterfaceException |
|
| 2475 | - * @throws ReflectionException |
|
| 2476 | - */ |
|
| 2477 | - protected function _default_event_settings() |
|
| 2478 | - { |
|
| 2479 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2480 | - $this->_set_publish_post_box_vars(); |
|
| 2481 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 2482 | - $this->_default_event_settings_form()->get_html(), |
|
| 2483 | - '', |
|
| 2484 | - 'padding' |
|
| 2485 | - ); |
|
| 2486 | - $this->display_admin_page_with_sidebar(); |
|
| 2487 | - } |
|
| 2488 | - |
|
| 2489 | - |
|
| 2490 | - /** |
|
| 2491 | - * Return the form for event settings. |
|
| 2492 | - * |
|
| 2493 | - * @return EE_Form_Section_Proper |
|
| 2494 | - * @throws EE_Error |
|
| 2495 | - * @throws ReflectionException |
|
| 2496 | - */ |
|
| 2497 | - protected function _default_event_settings_form(): EE_Form_Section_Proper |
|
| 2498 | - { |
|
| 2499 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2500 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2501 | - // exclude |
|
| 2502 | - [ |
|
| 2503 | - EEM_Registration::status_id_cancelled, |
|
| 2504 | - EEM_Registration::status_id_declined, |
|
| 2505 | - EEM_Registration::status_id_incomplete, |
|
| 2506 | - EEM_Registration::status_id_wait_list, |
|
| 2507 | - ], |
|
| 2508 | - true |
|
| 2509 | - ); |
|
| 2510 | - // setup Advanced Editor ??? |
|
| 2511 | - if ( |
|
| 2512 | - $this->raw_req_action === 'default_event_settings' |
|
| 2513 | - || $this->raw_req_action === 'update_default_event_settings' |
|
| 2514 | - ) { |
|
| 2515 | - $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class); |
|
| 2516 | - } |
|
| 2517 | - return new EE_Form_Section_Proper( |
|
| 2518 | - [ |
|
| 2519 | - 'name' => 'update_default_event_settings', |
|
| 2520 | - 'html_id' => 'update_default_event_settings', |
|
| 2521 | - 'html_class' => 'form-table', |
|
| 2522 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2523 | - 'subsections' => apply_filters( |
|
| 2524 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2525 | - [ |
|
| 2526 | - 'defaults_section_header' => new EE_Form_Section_HTML( |
|
| 2527 | - EEH_HTML::h2( |
|
| 2528 | - esc_html__('Default Settings', 'event_espresso'), |
|
| 2529 | - '', |
|
| 2530 | - 'ee-admin-settings-hdr' |
|
| 2531 | - ) |
|
| 2532 | - ), |
|
| 2533 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2534 | - $registration_stati_for_selection, |
|
| 2535 | - [ |
|
| 2536 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2537 | - && array_key_exists( |
|
| 2538 | - $registration_config->default_STS_ID, |
|
| 2539 | - $registration_stati_for_selection |
|
| 2540 | - ) |
|
| 2541 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2542 | - : EEM_Registration::status_id_pending_payment, |
|
| 2543 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2544 | - . EEH_Template::get_help_tab_link( |
|
| 2545 | - 'default_settings_status_help_tab' |
|
| 2546 | - ), |
|
| 2547 | - 'html_help_text' => esc_html__( |
|
| 2548 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2549 | - 'event_espresso' |
|
| 2550 | - ), |
|
| 2551 | - ] |
|
| 2552 | - ), |
|
| 2553 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2554 | - [ |
|
| 2555 | - 'default' => $registration_config->default_maximum_number_of_tickets |
|
| 2556 | - ?? EEM_Event::get_default_additional_limit(), |
|
| 2557 | - 'html_label_text' => esc_html__( |
|
| 2558 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2559 | - 'event_espresso' |
|
| 2560 | - ) |
|
| 2561 | - . EEH_Template::get_help_tab_link( |
|
| 2562 | - 'default_maximum_tickets_help_tab"' |
|
| 2563 | - ), |
|
| 2564 | - 'html_help_text' => esc_html__( |
|
| 2565 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2566 | - 'event_espresso' |
|
| 2567 | - ), |
|
| 2568 | - ] |
|
| 2569 | - ), |
|
| 2570 | - ] |
|
| 2571 | - ), |
|
| 2572 | - ] |
|
| 2573 | - ); |
|
| 2574 | - } |
|
| 2575 | - |
|
| 2576 | - |
|
| 2577 | - /** |
|
| 2578 | - * @return void |
|
| 2579 | - * @throws EE_Error |
|
| 2580 | - * @throws InvalidArgumentException |
|
| 2581 | - * @throws InvalidDataTypeException |
|
| 2582 | - * @throws InvalidInterfaceException |
|
| 2583 | - * @throws ReflectionException |
|
| 2584 | - */ |
|
| 2585 | - protected function _update_default_event_settings() |
|
| 2586 | - { |
|
| 2587 | - $form = $this->_default_event_settings_form(); |
|
| 2588 | - if ($form->was_submitted()) { |
|
| 2589 | - $form->receive_form_submission(); |
|
| 2590 | - if ($form->is_valid()) { |
|
| 2591 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2592 | - $valid_data = $form->valid_data(); |
|
| 2593 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2594 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2595 | - } |
|
| 2596 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2597 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2598 | - } |
|
| 2599 | - do_action( |
|
| 2600 | - 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2601 | - $valid_data, |
|
| 2602 | - EE_Registry::instance()->CFG, |
|
| 2603 | - $this |
|
| 2604 | - ); |
|
| 2605 | - // update because data was valid! |
|
| 2606 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2607 | - EE_Error::overwrite_success(); |
|
| 2608 | - EE_Error::add_success( |
|
| 2609 | - esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2610 | - ); |
|
| 2611 | - } |
|
| 2612 | - } |
|
| 2613 | - $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2614 | - } |
|
| 2615 | - |
|
| 2616 | - |
|
| 2617 | - /************* Templates ************* |
|
| 2618 | - * |
|
| 2619 | - * @throws EE_Error |
|
| 2620 | - */ |
|
| 2621 | - protected function _template_settings() |
|
| 2622 | - { |
|
| 2623 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2624 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2625 | - . EVENTS_ASSETS_URL |
|
| 2626 | - . '/images/' |
|
| 2627 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2628 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2629 | - . '" />'; |
|
| 2630 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 2631 | - . esc_html__( |
|
| 2632 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2633 | - 'event_espresso' |
|
| 2634 | - ) . '</strong>'; |
|
| 2635 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2636 | - } |
|
| 2637 | - |
|
| 2638 | - |
|
| 2639 | - /** Event Category Stuff **/ |
|
| 2640 | - /** |
|
| 2641 | - * set the _category property with the category object for the loaded page. |
|
| 2642 | - * |
|
| 2643 | - * @access private |
|
| 2644 | - * @return void |
|
| 2645 | - */ |
|
| 2646 | - private function _set_category_object() |
|
| 2647 | - { |
|
| 2648 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2649 | - return; |
|
| 2650 | - } //already have the category object so get out. |
|
| 2651 | - // set default category object |
|
| 2652 | - $this->_set_empty_category_object(); |
|
| 2653 | - // only set if we've got an id |
|
| 2654 | - $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
| 2655 | - if (! $category_ID) { |
|
| 2656 | - return; |
|
| 2657 | - } |
|
| 2658 | - $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2659 | - if (! empty($term)) { |
|
| 2660 | - $this->_category->category_name = $term->name; |
|
| 2661 | - $this->_category->category_identifier = $term->slug; |
|
| 2662 | - $this->_category->category_desc = $term->description; |
|
| 2663 | - $this->_category->id = $term->term_id; |
|
| 2664 | - $this->_category->parent = $term->parent; |
|
| 2665 | - } |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - |
|
| 2669 | - /** |
|
| 2670 | - * Clears out category properties. |
|
| 2671 | - */ |
|
| 2672 | - private function _set_empty_category_object() |
|
| 2673 | - { |
|
| 2674 | - $this->_category = new stdClass(); |
|
| 2675 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2676 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2677 | - } |
|
| 2678 | - |
|
| 2679 | - |
|
| 2680 | - /** |
|
| 2681 | - * @throws DomainException |
|
| 2682 | - * @throws EE_Error |
|
| 2683 | - * @throws InvalidArgumentException |
|
| 2684 | - * @throws InvalidDataTypeException |
|
| 2685 | - * @throws InvalidInterfaceException |
|
| 2686 | - */ |
|
| 2687 | - protected function _category_list_table() |
|
| 2688 | - { |
|
| 2689 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2690 | - $this->_admin_page_title .= ' '; |
|
| 2691 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 2692 | - 'add_category', |
|
| 2693 | - 'add_category', |
|
| 2694 | - [], |
|
| 2695 | - 'add-new-h2' |
|
| 2696 | - ); |
|
| 2697 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2698 | - } |
|
| 2699 | - |
|
| 2700 | - |
|
| 2701 | - /** |
|
| 2702 | - * Output category details view. |
|
| 2703 | - * |
|
| 2704 | - * @throws EE_Error |
|
| 2705 | - * @throws EE_Error |
|
| 2706 | - */ |
|
| 2707 | - protected function _category_details($view) |
|
| 2708 | - { |
|
| 2709 | - $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2710 | - $this->_set_add_edit_form_tags($route); |
|
| 2711 | - $this->_set_category_object(); |
|
| 2712 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2713 | - $delete_action = 'delete_category'; |
|
| 2714 | - // custom redirect |
|
| 2715 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2716 | - ['action' => 'category_list'], |
|
| 2717 | - $this->_admin_base_url |
|
| 2718 | - ); |
|
| 2719 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2720 | - // take care of contents |
|
| 2721 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2722 | - $this->display_admin_page_with_sidebar(); |
|
| 2723 | - } |
|
| 2724 | - |
|
| 2725 | - |
|
| 2726 | - /** |
|
| 2727 | - * Output category details content. |
|
| 2728 | - * |
|
| 2729 | - * @throws DomainException |
|
| 2730 | - */ |
|
| 2731 | - protected function _category_details_content(): string |
|
| 2732 | - { |
|
| 2733 | - $editor_args['category_desc'] = [ |
|
| 2734 | - 'type' => 'wp_editor', |
|
| 2735 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2736 | - 'class' => 'my_editor_custom', |
|
| 2737 | - 'wpeditor_args' => ['media_buttons' => false], |
|
| 2738 | - ]; |
|
| 2739 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2740 | - $all_terms = get_terms( |
|
| 2741 | - [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2742 | - ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2743 | - ); |
|
| 2744 | - // setup category select for term parents. |
|
| 2745 | - $category_select_values[] = [ |
|
| 2746 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2747 | - 'id' => 0, |
|
| 2748 | - ]; |
|
| 2749 | - foreach ($all_terms as $term) { |
|
| 2750 | - $category_select_values[] = [ |
|
| 2751 | - 'text' => $term->name, |
|
| 2752 | - 'id' => $term->term_id, |
|
| 2753 | - ]; |
|
| 2754 | - } |
|
| 2755 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2756 | - 'category_parent', |
|
| 2757 | - $category_select_values, |
|
| 2758 | - $this->_category->parent |
|
| 2759 | - ); |
|
| 2760 | - $template_args = [ |
|
| 2761 | - 'category' => $this->_category, |
|
| 2762 | - 'category_select' => $category_select, |
|
| 2763 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2764 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2765 | - 'disable' => '', |
|
| 2766 | - 'disabled_message' => false, |
|
| 2767 | - ]; |
|
| 2768 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2769 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2770 | - } |
|
| 2771 | - |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * Handles deleting categories. |
|
| 2775 | - * |
|
| 2776 | - * @throws EE_Error |
|
| 2777 | - */ |
|
| 2778 | - protected function _delete_categories() |
|
| 2779 | - { |
|
| 2780 | - $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
| 2781 | - foreach ($category_IDs as $category_ID) { |
|
| 2782 | - $this->_delete_category($category_ID); |
|
| 2783 | - } |
|
| 2784 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2785 | - $query_args = [ |
|
| 2786 | - 'action' => 'category_list', |
|
| 2787 | - ]; |
|
| 2788 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2789 | - } |
|
| 2790 | - |
|
| 2791 | - |
|
| 2792 | - /** |
|
| 2793 | - * Handles deleting specific category. |
|
| 2794 | - * |
|
| 2795 | - * @param int $cat_id |
|
| 2796 | - */ |
|
| 2797 | - protected function _delete_category(int $cat_id) |
|
| 2798 | - { |
|
| 2799 | - $cat_id = absint($cat_id); |
|
| 2800 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2801 | - } |
|
| 2802 | - |
|
| 2803 | - |
|
| 2804 | - /** |
|
| 2805 | - * Handles triggering the update or insertion of a new category. |
|
| 2806 | - * |
|
| 2807 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2808 | - * @throws EE_Error |
|
| 2809 | - * @throws EE_Error |
|
| 2810 | - */ |
|
| 2811 | - protected function _insert_or_update_category(bool $new_category) |
|
| 2812 | - { |
|
| 2813 | - $cat_id = $this->_insert_category($new_category); |
|
| 2814 | - $success = 0; // we already have a success message so lets not send another. |
|
| 2815 | - if ($cat_id) { |
|
| 2816 | - $query_args = [ |
|
| 2817 | - 'action' => 'edit_category', |
|
| 2818 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2819 | - ]; |
|
| 2820 | - } else { |
|
| 2821 | - $query_args = ['action' => 'add_category']; |
|
| 2822 | - } |
|
| 2823 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2824 | - } |
|
| 2825 | - |
|
| 2826 | - |
|
| 2827 | - /** |
|
| 2828 | - * Inserts or updates category |
|
| 2829 | - * |
|
| 2830 | - * @param bool $new_category (true indicates we're updating a category). |
|
| 2831 | - * @return bool|mixed|string |
|
| 2832 | - */ |
|
| 2833 | - private function _insert_category(bool $new_category) |
|
| 2834 | - { |
|
| 2835 | - $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
| 2836 | - $category_name = $this->request->getRequestParam('category_name', ''); |
|
| 2837 | - $category_desc = $this->request->getRequestParam('category_desc', '', DataType::HTML); |
|
| 2838 | - $category_parent = $this->request->getRequestParam('category_parent', 0, DataType::INT); |
|
| 2839 | - $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
| 2840 | - |
|
| 2841 | - if (empty($category_name)) { |
|
| 2842 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2843 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2844 | - return 0; |
|
| 2845 | - } |
|
| 2846 | - $term_args = [ |
|
| 2847 | - 'name' => $category_name, |
|
| 2848 | - 'description' => $category_desc, |
|
| 2849 | - 'parent' => $category_parent, |
|
| 2850 | - ]; |
|
| 2851 | - // was the category_identifier input disabled? |
|
| 2852 | - if ($category_identifier) { |
|
| 2853 | - $term_args['slug'] = $category_identifier; |
|
| 2854 | - } |
|
| 2855 | - $insert_ids = $new_category |
|
| 2856 | - ? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2857 | - : wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2858 | - |
|
| 2859 | - if ($insert_ids instanceof WP_Error) { |
|
| 2860 | - EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2861 | - return 0; |
|
| 2862 | - } |
|
| 2863 | - $category_ID = $insert_ids['term_id'] ?? 0; |
|
| 2864 | - if (! $category_ID) { |
|
| 2865 | - EE_Error::add_error( |
|
| 2866 | - esc_html__( |
|
| 2867 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2868 | - 'event_espresso' |
|
| 2869 | - ), |
|
| 2870 | - __FILE__, |
|
| 2871 | - __FUNCTION__, |
|
| 2872 | - __LINE__ |
|
| 2873 | - ); |
|
| 2874 | - return 0; |
|
| 2875 | - } |
|
| 2876 | - EE_Error::add_success( |
|
| 2877 | - sprintf( |
|
| 2878 | - esc_html__('The category %s was successfully saved', 'event_espresso'), |
|
| 2879 | - $category_name |
|
| 2880 | - ) |
|
| 2881 | - ); |
|
| 2882 | - return $category_ID; |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - |
|
| 2886 | - /** |
|
| 2887 | - * Gets categories or count of categories matching the arguments in the request. |
|
| 2888 | - * |
|
| 2889 | - * @param int $per_page |
|
| 2890 | - * @param int $current_page |
|
| 2891 | - * @param bool $count |
|
| 2892 | - * @return EE_Term_Taxonomy[]|int |
|
| 2893 | - * @throws EE_Error |
|
| 2894 | - * @throws ReflectionException |
|
| 2895 | - */ |
|
| 2896 | - public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
| 2897 | - { |
|
| 2898 | - // testing term stuff |
|
| 2899 | - $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
| 2900 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 2901 | - $limit = ($current_page - 1) * $per_page; |
|
| 2902 | - $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2903 | - $search_term = $this->request->getRequestParam('s'); |
|
| 2904 | - if ($search_term) { |
|
| 2905 | - $search_term = '%' . $search_term . '%'; |
|
| 2906 | - $where['OR'] = [ |
|
| 2907 | - 'Term.name' => ['LIKE', $search_term], |
|
| 2908 | - 'description' => ['LIKE', $search_term], |
|
| 2909 | - ]; |
|
| 2910 | - } |
|
| 2911 | - $query_params = [ |
|
| 2912 | - $where, |
|
| 2913 | - 'order_by' => [$orderby => $order], |
|
| 2914 | - 'limit' => $limit . ',' . $per_page, |
|
| 2915 | - 'force_join' => ['Term'], |
|
| 2916 | - ]; |
|
| 2917 | - return $count |
|
| 2918 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2919 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2920 | - } |
|
| 2921 | - |
|
| 2922 | - /* end category stuff */ |
|
| 2923 | - |
|
| 2924 | - |
|
| 2925 | - /**************/ |
|
| 2926 | - |
|
| 2927 | - |
|
| 2928 | - /** |
|
| 2929 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2930 | - * |
|
| 2931 | - * @throws EE_Error |
|
| 2932 | - * @throws InvalidArgumentException |
|
| 2933 | - * @throws InvalidDataTypeException |
|
| 2934 | - * @throws InvalidInterfaceException |
|
| 2935 | - */ |
|
| 2936 | - public function saveTimezoneString() |
|
| 2937 | - { |
|
| 2938 | - $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
| 2939 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2940 | - EE_Error::add_error( |
|
| 2941 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2942 | - __FILE__, |
|
| 2943 | - __FUNCTION__, |
|
| 2944 | - __LINE__ |
|
| 2945 | - ); |
|
| 2946 | - $this->_template_args['error'] = true; |
|
| 2947 | - $this->_return_json(); |
|
| 2948 | - } |
|
| 2949 | - |
|
| 2950 | - update_option('timezone_string', $timezone_string); |
|
| 2951 | - EE_Error::add_success( |
|
| 2952 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2953 | - ); |
|
| 2954 | - $this->_template_args['success'] = true; |
|
| 2955 | - $this->_return_json(true, ['action' => 'create_new']); |
|
| 2956 | - } |
|
| 2957 | - |
|
| 2958 | - |
|
| 2959 | - /** |
|
| 2960 | 2619 | * @throws EE_Error |
| 2961 | - * @deprecated 4.10.25.p |
|
| 2962 | 2620 | */ |
| 2963 | - public function save_timezonestring_setting() |
|
| 2964 | - { |
|
| 2965 | - $this->saveTimezoneString(); |
|
| 2966 | - } |
|
| 2621 | + protected function _template_settings() |
|
| 2622 | + { |
|
| 2623 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2624 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2625 | + . EVENTS_ASSETS_URL |
|
| 2626 | + . '/images/' |
|
| 2627 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2628 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2629 | + . '" />'; |
|
| 2630 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 2631 | + . esc_html__( |
|
| 2632 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2633 | + 'event_espresso' |
|
| 2634 | + ) . '</strong>'; |
|
| 2635 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2636 | + } |
|
| 2637 | + |
|
| 2638 | + |
|
| 2639 | + /** Event Category Stuff **/ |
|
| 2640 | + /** |
|
| 2641 | + * set the _category property with the category object for the loaded page. |
|
| 2642 | + * |
|
| 2643 | + * @access private |
|
| 2644 | + * @return void |
|
| 2645 | + */ |
|
| 2646 | + private function _set_category_object() |
|
| 2647 | + { |
|
| 2648 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2649 | + return; |
|
| 2650 | + } //already have the category object so get out. |
|
| 2651 | + // set default category object |
|
| 2652 | + $this->_set_empty_category_object(); |
|
| 2653 | + // only set if we've got an id |
|
| 2654 | + $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
| 2655 | + if (! $category_ID) { |
|
| 2656 | + return; |
|
| 2657 | + } |
|
| 2658 | + $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2659 | + if (! empty($term)) { |
|
| 2660 | + $this->_category->category_name = $term->name; |
|
| 2661 | + $this->_category->category_identifier = $term->slug; |
|
| 2662 | + $this->_category->category_desc = $term->description; |
|
| 2663 | + $this->_category->id = $term->term_id; |
|
| 2664 | + $this->_category->parent = $term->parent; |
|
| 2665 | + } |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + |
|
| 2669 | + /** |
|
| 2670 | + * Clears out category properties. |
|
| 2671 | + */ |
|
| 2672 | + private function _set_empty_category_object() |
|
| 2673 | + { |
|
| 2674 | + $this->_category = new stdClass(); |
|
| 2675 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2676 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2677 | + } |
|
| 2678 | + |
|
| 2679 | + |
|
| 2680 | + /** |
|
| 2681 | + * @throws DomainException |
|
| 2682 | + * @throws EE_Error |
|
| 2683 | + * @throws InvalidArgumentException |
|
| 2684 | + * @throws InvalidDataTypeException |
|
| 2685 | + * @throws InvalidInterfaceException |
|
| 2686 | + */ |
|
| 2687 | + protected function _category_list_table() |
|
| 2688 | + { |
|
| 2689 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2690 | + $this->_admin_page_title .= ' '; |
|
| 2691 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 2692 | + 'add_category', |
|
| 2693 | + 'add_category', |
|
| 2694 | + [], |
|
| 2695 | + 'add-new-h2' |
|
| 2696 | + ); |
|
| 2697 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2698 | + } |
|
| 2699 | + |
|
| 2700 | + |
|
| 2701 | + /** |
|
| 2702 | + * Output category details view. |
|
| 2703 | + * |
|
| 2704 | + * @throws EE_Error |
|
| 2705 | + * @throws EE_Error |
|
| 2706 | + */ |
|
| 2707 | + protected function _category_details($view) |
|
| 2708 | + { |
|
| 2709 | + $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2710 | + $this->_set_add_edit_form_tags($route); |
|
| 2711 | + $this->_set_category_object(); |
|
| 2712 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2713 | + $delete_action = 'delete_category'; |
|
| 2714 | + // custom redirect |
|
| 2715 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2716 | + ['action' => 'category_list'], |
|
| 2717 | + $this->_admin_base_url |
|
| 2718 | + ); |
|
| 2719 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2720 | + // take care of contents |
|
| 2721 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2722 | + $this->display_admin_page_with_sidebar(); |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + |
|
| 2726 | + /** |
|
| 2727 | + * Output category details content. |
|
| 2728 | + * |
|
| 2729 | + * @throws DomainException |
|
| 2730 | + */ |
|
| 2731 | + protected function _category_details_content(): string |
|
| 2732 | + { |
|
| 2733 | + $editor_args['category_desc'] = [ |
|
| 2734 | + 'type' => 'wp_editor', |
|
| 2735 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2736 | + 'class' => 'my_editor_custom', |
|
| 2737 | + 'wpeditor_args' => ['media_buttons' => false], |
|
| 2738 | + ]; |
|
| 2739 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2740 | + $all_terms = get_terms( |
|
| 2741 | + [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2742 | + ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2743 | + ); |
|
| 2744 | + // setup category select for term parents. |
|
| 2745 | + $category_select_values[] = [ |
|
| 2746 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2747 | + 'id' => 0, |
|
| 2748 | + ]; |
|
| 2749 | + foreach ($all_terms as $term) { |
|
| 2750 | + $category_select_values[] = [ |
|
| 2751 | + 'text' => $term->name, |
|
| 2752 | + 'id' => $term->term_id, |
|
| 2753 | + ]; |
|
| 2754 | + } |
|
| 2755 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2756 | + 'category_parent', |
|
| 2757 | + $category_select_values, |
|
| 2758 | + $this->_category->parent |
|
| 2759 | + ); |
|
| 2760 | + $template_args = [ |
|
| 2761 | + 'category' => $this->_category, |
|
| 2762 | + 'category_select' => $category_select, |
|
| 2763 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2764 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2765 | + 'disable' => '', |
|
| 2766 | + 'disabled_message' => false, |
|
| 2767 | + ]; |
|
| 2768 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2769 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2770 | + } |
|
| 2771 | + |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * Handles deleting categories. |
|
| 2775 | + * |
|
| 2776 | + * @throws EE_Error |
|
| 2777 | + */ |
|
| 2778 | + protected function _delete_categories() |
|
| 2779 | + { |
|
| 2780 | + $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
| 2781 | + foreach ($category_IDs as $category_ID) { |
|
| 2782 | + $this->_delete_category($category_ID); |
|
| 2783 | + } |
|
| 2784 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2785 | + $query_args = [ |
|
| 2786 | + 'action' => 'category_list', |
|
| 2787 | + ]; |
|
| 2788 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2789 | + } |
|
| 2790 | + |
|
| 2791 | + |
|
| 2792 | + /** |
|
| 2793 | + * Handles deleting specific category. |
|
| 2794 | + * |
|
| 2795 | + * @param int $cat_id |
|
| 2796 | + */ |
|
| 2797 | + protected function _delete_category(int $cat_id) |
|
| 2798 | + { |
|
| 2799 | + $cat_id = absint($cat_id); |
|
| 2800 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2801 | + } |
|
| 2802 | + |
|
| 2803 | + |
|
| 2804 | + /** |
|
| 2805 | + * Handles triggering the update or insertion of a new category. |
|
| 2806 | + * |
|
| 2807 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2808 | + * @throws EE_Error |
|
| 2809 | + * @throws EE_Error |
|
| 2810 | + */ |
|
| 2811 | + protected function _insert_or_update_category(bool $new_category) |
|
| 2812 | + { |
|
| 2813 | + $cat_id = $this->_insert_category($new_category); |
|
| 2814 | + $success = 0; // we already have a success message so lets not send another. |
|
| 2815 | + if ($cat_id) { |
|
| 2816 | + $query_args = [ |
|
| 2817 | + 'action' => 'edit_category', |
|
| 2818 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2819 | + ]; |
|
| 2820 | + } else { |
|
| 2821 | + $query_args = ['action' => 'add_category']; |
|
| 2822 | + } |
|
| 2823 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2824 | + } |
|
| 2825 | + |
|
| 2826 | + |
|
| 2827 | + /** |
|
| 2828 | + * Inserts or updates category |
|
| 2829 | + * |
|
| 2830 | + * @param bool $new_category (true indicates we're updating a category). |
|
| 2831 | + * @return bool|mixed|string |
|
| 2832 | + */ |
|
| 2833 | + private function _insert_category(bool $new_category) |
|
| 2834 | + { |
|
| 2835 | + $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
| 2836 | + $category_name = $this->request->getRequestParam('category_name', ''); |
|
| 2837 | + $category_desc = $this->request->getRequestParam('category_desc', '', DataType::HTML); |
|
| 2838 | + $category_parent = $this->request->getRequestParam('category_parent', 0, DataType::INT); |
|
| 2839 | + $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
| 2840 | + |
|
| 2841 | + if (empty($category_name)) { |
|
| 2842 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2843 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2844 | + return 0; |
|
| 2845 | + } |
|
| 2846 | + $term_args = [ |
|
| 2847 | + 'name' => $category_name, |
|
| 2848 | + 'description' => $category_desc, |
|
| 2849 | + 'parent' => $category_parent, |
|
| 2850 | + ]; |
|
| 2851 | + // was the category_identifier input disabled? |
|
| 2852 | + if ($category_identifier) { |
|
| 2853 | + $term_args['slug'] = $category_identifier; |
|
| 2854 | + } |
|
| 2855 | + $insert_ids = $new_category |
|
| 2856 | + ? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2857 | + : wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2858 | + |
|
| 2859 | + if ($insert_ids instanceof WP_Error) { |
|
| 2860 | + EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2861 | + return 0; |
|
| 2862 | + } |
|
| 2863 | + $category_ID = $insert_ids['term_id'] ?? 0; |
|
| 2864 | + if (! $category_ID) { |
|
| 2865 | + EE_Error::add_error( |
|
| 2866 | + esc_html__( |
|
| 2867 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2868 | + 'event_espresso' |
|
| 2869 | + ), |
|
| 2870 | + __FILE__, |
|
| 2871 | + __FUNCTION__, |
|
| 2872 | + __LINE__ |
|
| 2873 | + ); |
|
| 2874 | + return 0; |
|
| 2875 | + } |
|
| 2876 | + EE_Error::add_success( |
|
| 2877 | + sprintf( |
|
| 2878 | + esc_html__('The category %s was successfully saved', 'event_espresso'), |
|
| 2879 | + $category_name |
|
| 2880 | + ) |
|
| 2881 | + ); |
|
| 2882 | + return $category_ID; |
|
| 2883 | + } |
|
| 2884 | + |
|
| 2885 | + |
|
| 2886 | + /** |
|
| 2887 | + * Gets categories or count of categories matching the arguments in the request. |
|
| 2888 | + * |
|
| 2889 | + * @param int $per_page |
|
| 2890 | + * @param int $current_page |
|
| 2891 | + * @param bool $count |
|
| 2892 | + * @return EE_Term_Taxonomy[]|int |
|
| 2893 | + * @throws EE_Error |
|
| 2894 | + * @throws ReflectionException |
|
| 2895 | + */ |
|
| 2896 | + public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
| 2897 | + { |
|
| 2898 | + // testing term stuff |
|
| 2899 | + $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
| 2900 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 2901 | + $limit = ($current_page - 1) * $per_page; |
|
| 2902 | + $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2903 | + $search_term = $this->request->getRequestParam('s'); |
|
| 2904 | + if ($search_term) { |
|
| 2905 | + $search_term = '%' . $search_term . '%'; |
|
| 2906 | + $where['OR'] = [ |
|
| 2907 | + 'Term.name' => ['LIKE', $search_term], |
|
| 2908 | + 'description' => ['LIKE', $search_term], |
|
| 2909 | + ]; |
|
| 2910 | + } |
|
| 2911 | + $query_params = [ |
|
| 2912 | + $where, |
|
| 2913 | + 'order_by' => [$orderby => $order], |
|
| 2914 | + 'limit' => $limit . ',' . $per_page, |
|
| 2915 | + 'force_join' => ['Term'], |
|
| 2916 | + ]; |
|
| 2917 | + return $count |
|
| 2918 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2919 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2920 | + } |
|
| 2921 | + |
|
| 2922 | + /* end category stuff */ |
|
| 2923 | + |
|
| 2924 | + |
|
| 2925 | + /**************/ |
|
| 2926 | + |
|
| 2927 | + |
|
| 2928 | + /** |
|
| 2929 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2930 | + * |
|
| 2931 | + * @throws EE_Error |
|
| 2932 | + * @throws InvalidArgumentException |
|
| 2933 | + * @throws InvalidDataTypeException |
|
| 2934 | + * @throws InvalidInterfaceException |
|
| 2935 | + */ |
|
| 2936 | + public function saveTimezoneString() |
|
| 2937 | + { |
|
| 2938 | + $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
| 2939 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2940 | + EE_Error::add_error( |
|
| 2941 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2942 | + __FILE__, |
|
| 2943 | + __FUNCTION__, |
|
| 2944 | + __LINE__ |
|
| 2945 | + ); |
|
| 2946 | + $this->_template_args['error'] = true; |
|
| 2947 | + $this->_return_json(); |
|
| 2948 | + } |
|
| 2949 | + |
|
| 2950 | + update_option('timezone_string', $timezone_string); |
|
| 2951 | + EE_Error::add_success( |
|
| 2952 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2953 | + ); |
|
| 2954 | + $this->_template_args['success'] = true; |
|
| 2955 | + $this->_return_json(true, ['action' => 'create_new']); |
|
| 2956 | + } |
|
| 2957 | + |
|
| 2958 | + |
|
| 2959 | + /** |
|
| 2960 | + * @throws EE_Error |
|
| 2961 | + * @deprecated 4.10.25.p |
|
| 2962 | + */ |
|
| 2963 | + public function save_timezonestring_setting() |
|
| 2964 | + { |
|
| 2965 | + $this->saveTimezoneString(); |
|
| 2966 | + } |
|
| 2967 | 2967 | } |
@@ -11,176 +11,176 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Event_Categories_Admin_List_Table extends EE_Admin_List_Table |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var Events_Admin_Page $_admin_page |
|
| 16 | - */ |
|
| 17 | - protected EE_Admin_Page $_admin_page; |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @throws EE_Error |
|
| 22 | - * @throws ReflectionException |
|
| 23 | - */ |
|
| 24 | - protected function _setup_data() |
|
| 25 | - { |
|
| 26 | - $this->_data = $this->_admin_page->get_categories($this->_per_page, $this->_current_page); |
|
| 27 | - $this->_all_data_count = EEM_Term_Taxonomy::instance()->count( |
|
| 28 | - [['taxonomy' => 'espresso_event_categories']] |
|
| 29 | - ); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - protected function _set_properties() |
|
| 34 | - { |
|
| 35 | - $this->_wp_list_args = [ |
|
| 36 | - 'singular' => esc_html__('event category', 'event_espresso'), |
|
| 37 | - 'plural' => esc_html__('event categories', 'event_espresso'), |
|
| 38 | - 'ajax' => true, // for now, |
|
| 39 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 40 | - ]; |
|
| 41 | - |
|
| 42 | - $this->_columns = [ |
|
| 43 | - 'cb' => '<input type="checkbox" />', |
|
| 44 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 45 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 46 | - 'shortcode' => esc_html__('Shortcode', 'event_espresso'), |
|
| 47 | - 'count' => esc_html__('Events', 'event_espresso'), |
|
| 48 | - ]; |
|
| 49 | - |
|
| 50 | - $this->_sortable_columns = [ |
|
| 51 | - 'id' => ['Term.term_id' => true], |
|
| 52 | - 'name' => ['Term.slug' => false], |
|
| 53 | - 'count' => ['term_count' => false], |
|
| 54 | - ]; |
|
| 55 | - |
|
| 56 | - $this->_primary_column = 'id'; |
|
| 57 | - |
|
| 58 | - $this->_hidden_columns = []; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - protected function _get_table_filters() |
|
| 63 | - { |
|
| 64 | - return []; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - protected function _add_view_counts() |
|
| 69 | - { |
|
| 70 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - public function column_cb($item): string |
|
| 75 | - { |
|
| 76 | - return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id')); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param EE_Term_Taxonomy $item |
|
| 82 | - * @return string |
|
| 83 | - * @throws EE_Error |
|
| 84 | - * @throws ReflectionException |
|
| 85 | - */ |
|
| 86 | - public function column_id(EE_Term_Taxonomy $item): string |
|
| 87 | - { |
|
| 88 | - $content = ' |
|
| 14 | + /** |
|
| 15 | + * @var Events_Admin_Page $_admin_page |
|
| 16 | + */ |
|
| 17 | + protected EE_Admin_Page $_admin_page; |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @throws EE_Error |
|
| 22 | + * @throws ReflectionException |
|
| 23 | + */ |
|
| 24 | + protected function _setup_data() |
|
| 25 | + { |
|
| 26 | + $this->_data = $this->_admin_page->get_categories($this->_per_page, $this->_current_page); |
|
| 27 | + $this->_all_data_count = EEM_Term_Taxonomy::instance()->count( |
|
| 28 | + [['taxonomy' => 'espresso_event_categories']] |
|
| 29 | + ); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + protected function _set_properties() |
|
| 34 | + { |
|
| 35 | + $this->_wp_list_args = [ |
|
| 36 | + 'singular' => esc_html__('event category', 'event_espresso'), |
|
| 37 | + 'plural' => esc_html__('event categories', 'event_espresso'), |
|
| 38 | + 'ajax' => true, // for now, |
|
| 39 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 40 | + ]; |
|
| 41 | + |
|
| 42 | + $this->_columns = [ |
|
| 43 | + 'cb' => '<input type="checkbox" />', |
|
| 44 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 45 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 46 | + 'shortcode' => esc_html__('Shortcode', 'event_espresso'), |
|
| 47 | + 'count' => esc_html__('Events', 'event_espresso'), |
|
| 48 | + ]; |
|
| 49 | + |
|
| 50 | + $this->_sortable_columns = [ |
|
| 51 | + 'id' => ['Term.term_id' => true], |
|
| 52 | + 'name' => ['Term.slug' => false], |
|
| 53 | + 'count' => ['term_count' => false], |
|
| 54 | + ]; |
|
| 55 | + |
|
| 56 | + $this->_primary_column = 'id'; |
|
| 57 | + |
|
| 58 | + $this->_hidden_columns = []; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + protected function _get_table_filters() |
|
| 63 | + { |
|
| 64 | + return []; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + protected function _add_view_counts() |
|
| 69 | + { |
|
| 70 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + public function column_cb($item): string |
|
| 75 | + { |
|
| 76 | + return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id')); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param EE_Term_Taxonomy $item |
|
| 82 | + * @return string |
|
| 83 | + * @throws EE_Error |
|
| 84 | + * @throws ReflectionException |
|
| 85 | + */ |
|
| 86 | + public function column_id(EE_Term_Taxonomy $item): string |
|
| 87 | + { |
|
| 88 | + $content = ' |
|
| 89 | 89 | <span class="ee-entity-id">' . $item->get('term_id') . '</span> |
| 90 | 90 | <span class="show-on-mobile-view-only"> |
| 91 | 91 | ' . $item->get_first_related('Term')->get('name') . ' |
| 92 | 92 | </span>'; |
| 93 | - return $this->columnContent('id', $content, 'end'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param EE_Term_Taxonomy $item |
|
| 99 | - * @return string |
|
| 100 | - * @throws EE_Error |
|
| 101 | - * @throws ReflectionException |
|
| 102 | - */ |
|
| 103 | - public function column_name(EE_Term_Taxonomy $item): string |
|
| 104 | - { |
|
| 105 | - $edit_query_args = [ |
|
| 106 | - 'action' => 'edit_category', |
|
| 107 | - 'EVT_CAT_ID' => $item->get('term_id'), |
|
| 108 | - ]; |
|
| 109 | - |
|
| 110 | - $delete_query_args = [ |
|
| 111 | - 'action' => 'delete_category', |
|
| 112 | - 'EVT_CAT_ID' => $item->get('term_id'), |
|
| 113 | - ]; |
|
| 114 | - |
|
| 115 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 116 | - $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL); |
|
| 117 | - $view_link = get_term_link($item->get('term_id')); |
|
| 118 | - |
|
| 119 | - $term_name = $item->get_first_related('Term')->get('name'); |
|
| 120 | - |
|
| 121 | - $edit_category_label = sprintf( |
|
| 122 | - /* translators: The name of the event category */ |
|
| 123 | - esc_attr__( |
|
| 124 | - 'Edit Category (%s)', |
|
| 125 | - 'event_espresso' |
|
| 126 | - ), |
|
| 127 | - $term_name |
|
| 128 | - ); |
|
| 129 | - $actions['edit'] = ' |
|
| 93 | + return $this->columnContent('id', $content, 'end'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param EE_Term_Taxonomy $item |
|
| 99 | + * @return string |
|
| 100 | + * @throws EE_Error |
|
| 101 | + * @throws ReflectionException |
|
| 102 | + */ |
|
| 103 | + public function column_name(EE_Term_Taxonomy $item): string |
|
| 104 | + { |
|
| 105 | + $edit_query_args = [ |
|
| 106 | + 'action' => 'edit_category', |
|
| 107 | + 'EVT_CAT_ID' => $item->get('term_id'), |
|
| 108 | + ]; |
|
| 109 | + |
|
| 110 | + $delete_query_args = [ |
|
| 111 | + 'action' => 'delete_category', |
|
| 112 | + 'EVT_CAT_ID' => $item->get('term_id'), |
|
| 113 | + ]; |
|
| 114 | + |
|
| 115 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 116 | + $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL); |
|
| 117 | + $view_link = get_term_link($item->get('term_id')); |
|
| 118 | + |
|
| 119 | + $term_name = $item->get_first_related('Term')->get('name'); |
|
| 120 | + |
|
| 121 | + $edit_category_label = sprintf( |
|
| 122 | + /* translators: The name of the event category */ |
|
| 123 | + esc_attr__( |
|
| 124 | + 'Edit Category (%s)', |
|
| 125 | + 'event_espresso' |
|
| 126 | + ), |
|
| 127 | + $term_name |
|
| 128 | + ); |
|
| 129 | + $actions['edit'] = ' |
|
| 130 | 130 | <a href="' . $edit_link . '" aria-label="' . $edit_category_label . '"> |
| 131 | 131 | ' . esc_html__('Edit', 'event_espresso') . ' |
| 132 | 132 | </a>'; |
| 133 | 133 | |
| 134 | - $actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__( |
|
| 135 | - 'Delete Category', |
|
| 136 | - 'event_espresso' |
|
| 137 | - ) . '">' . esc_html__('Delete', 'event_espresso') . '</a>'; |
|
| 138 | - |
|
| 139 | - $view_category_label = sprintf( |
|
| 140 | - /* translators: %s: event category name */ |
|
| 141 | - esc_html__('View “%s” archive', 'event_espresso'), |
|
| 142 | - $item->get_first_related('Term')->get('name') |
|
| 143 | - ); |
|
| 144 | - $actions['view'] = ' |
|
| 134 | + $actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__( |
|
| 135 | + 'Delete Category', |
|
| 136 | + 'event_espresso' |
|
| 137 | + ) . '">' . esc_html__('Delete', 'event_espresso') . '</a>'; |
|
| 138 | + |
|
| 139 | + $view_category_label = sprintf( |
|
| 140 | + /* translators: %s: event category name */ |
|
| 141 | + esc_html__('View “%s” archive', 'event_espresso'), |
|
| 142 | + $item->get_first_related('Term')->get('name') |
|
| 143 | + ); |
|
| 144 | + $actions['view'] = ' |
|
| 145 | 145 | <a href="' . $view_link . '" aria-label="' . $view_category_label . '"> |
| 146 | 146 | ' . esc_html__('View', 'event_espresso') . ' |
| 147 | 147 | </a>'; |
| 148 | 148 | |
| 149 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $term_name . '</a></strong>'; |
|
| 150 | - $content .= $this->row_actions($actions); |
|
| 151 | - return $this->columnContent('name', $content); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param EE_Term_Taxonomy $item |
|
| 157 | - * @return string |
|
| 158 | - * @throws EE_Error |
|
| 159 | - * @throws ReflectionException |
|
| 160 | - */ |
|
| 161 | - public function column_shortcode(EE_Term_Taxonomy $item): string |
|
| 162 | - { |
|
| 163 | - $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']'; |
|
| 164 | - return $this->columnContent('shortcode', $content); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param EE_Term_Taxonomy $item |
|
| 170 | - * @return string |
|
| 171 | - * @throws EE_Error |
|
| 172 | - * @throws ReflectionException |
|
| 173 | - */ |
|
| 174 | - public function column_count(EE_Term_Taxonomy $item): string |
|
| 175 | - { |
|
| 176 | - $category_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 177 | - [ |
|
| 178 | - 'action' => 'default', |
|
| 179 | - 'EVT_CAT' => $item->get_first_related('Term')->ID(), |
|
| 180 | - ], |
|
| 181 | - EVENTS_ADMIN_URL |
|
| 182 | - ); |
|
| 183 | - $content = '<a href="' . $category_url . '">' . $item->get('term_count') . '</a>'; |
|
| 184 | - return $this->columnContent('count', $content); |
|
| 185 | - } |
|
| 149 | + $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $term_name . '</a></strong>'; |
|
| 150 | + $content .= $this->row_actions($actions); |
|
| 151 | + return $this->columnContent('name', $content); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param EE_Term_Taxonomy $item |
|
| 157 | + * @return string |
|
| 158 | + * @throws EE_Error |
|
| 159 | + * @throws ReflectionException |
|
| 160 | + */ |
|
| 161 | + public function column_shortcode(EE_Term_Taxonomy $item): string |
|
| 162 | + { |
|
| 163 | + $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']'; |
|
| 164 | + return $this->columnContent('shortcode', $content); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param EE_Term_Taxonomy $item |
|
| 170 | + * @return string |
|
| 171 | + * @throws EE_Error |
|
| 172 | + * @throws ReflectionException |
|
| 173 | + */ |
|
| 174 | + public function column_count(EE_Term_Taxonomy $item): string |
|
| 175 | + { |
|
| 176 | + $category_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 177 | + [ |
|
| 178 | + 'action' => 'default', |
|
| 179 | + 'EVT_CAT' => $item->get_first_related('Term')->ID(), |
|
| 180 | + ], |
|
| 181 | + EVENTS_ADMIN_URL |
|
| 182 | + ); |
|
| 183 | + $content = '<a href="' . $category_url . '">' . $item->get('term_count') . '</a>'; |
|
| 184 | + return $this->columnContent('count', $content); |
|
| 185 | + } |
|
| 186 | 186 | } |
@@ -14,177 +14,177 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var Events_Admin_Page |
|
| 19 | - */ |
|
| 20 | - protected EE_Admin_Page $_admin_page; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var EE_Datetime |
|
| 24 | - */ |
|
| 25 | - private $_dtt; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Initial setup of data properties for the list table. |
|
| 30 | - * |
|
| 31 | - * @throws Exception |
|
| 32 | - */ |
|
| 33 | - protected function _setup_data() |
|
| 34 | - { |
|
| 35 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 36 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Set up of additional properties for the list table. |
|
| 42 | - * |
|
| 43 | - * @throws EE_Error |
|
| 44 | - * @throws ReflectionException |
|
| 45 | - */ |
|
| 46 | - protected function _set_properties() |
|
| 47 | - { |
|
| 48 | - $this->_wp_list_args = [ |
|
| 49 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
| 50 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
| 51 | - 'ajax' => true, // for now |
|
| 52 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 53 | - ]; |
|
| 54 | - $approved_registrations = esc_html__('Approved Registrations', 'event_espresso'); |
|
| 55 | - $this->_columns = [ |
|
| 56 | - 'cb' => '<input type="checkbox" />', |
|
| 57 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 58 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 59 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
| 60 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 61 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 62 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 63 | - 'attendees' => ' |
|
| 17 | + /** |
|
| 18 | + * @var Events_Admin_Page |
|
| 19 | + */ |
|
| 20 | + protected EE_Admin_Page $_admin_page; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var EE_Datetime |
|
| 24 | + */ |
|
| 25 | + private $_dtt; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Initial setup of data properties for the list table. |
|
| 30 | + * |
|
| 31 | + * @throws Exception |
|
| 32 | + */ |
|
| 33 | + protected function _setup_data() |
|
| 34 | + { |
|
| 35 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 36 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Set up of additional properties for the list table. |
|
| 42 | + * |
|
| 43 | + * @throws EE_Error |
|
| 44 | + * @throws ReflectionException |
|
| 45 | + */ |
|
| 46 | + protected function _set_properties() |
|
| 47 | + { |
|
| 48 | + $this->_wp_list_args = [ |
|
| 49 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
| 50 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
| 51 | + 'ajax' => true, // for now |
|
| 52 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 53 | + ]; |
|
| 54 | + $approved_registrations = esc_html__('Approved Registrations', 'event_espresso'); |
|
| 55 | + $this->_columns = [ |
|
| 56 | + 'cb' => '<input type="checkbox" />', |
|
| 57 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 58 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 59 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
| 60 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 61 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 62 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 63 | + 'attendees' => ' |
|
| 64 | 64 | <span class="dashicons dashicons-groups ee-status-color--RAP ee-aria-tooltip" |
| 65 | 65 | aria-label="' . $approved_registrations . '"></span> |
| 66 | 66 | <span class="screen-reader-text">' . $approved_registrations . '</span>', |
| 67 | - 'actions' => $this->actionsColumnHeader(), |
|
| 68 | - ]; |
|
| 69 | - $this->addConditionalColumns(); |
|
| 70 | - $this->_sortable_columns = [ |
|
| 71 | - 'id' => ['EVT_ID' => true], |
|
| 72 | - 'name' => ['EVT_name' => false], |
|
| 73 | - 'author' => ['EVT_wp_user' => false], |
|
| 74 | - 'venue' => ['Venue.VNU_name' => false], |
|
| 75 | - 'start_date_time' => ['Datetime.DTT_EVT_start' => false], |
|
| 76 | - 'reg_begins' => ['Datetime.Ticket.TKT_start_date' => false], |
|
| 77 | - ]; |
|
| 78 | - |
|
| 79 | - $this->_primary_column = 'id'; |
|
| 80 | - $this->_hidden_columns = ['author', 'event_category']; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return array |
|
| 86 | - */ |
|
| 87 | - protected function _get_table_filters() |
|
| 88 | - { |
|
| 89 | - return []; // no filters with decaf |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Setup of views properties. |
|
| 95 | - * |
|
| 96 | - * @throws InvalidDataTypeException |
|
| 97 | - * @throws InvalidInterfaceException |
|
| 98 | - * @throws InvalidArgumentException |
|
| 99 | - * @throws EE_Error |
|
| 100 | - * @throws EE_Error |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function _add_view_counts() |
|
| 104 | - { |
|
| 105 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 106 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 107 | - if ( |
|
| 108 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 109 | - 'ee_delete_events', |
|
| 110 | - 'espresso_events_trash_events' |
|
| 111 | - ) |
|
| 112 | - ) { |
|
| 113 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param EE_Event $item |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - protected function _get_row_class($item): string |
|
| 123 | - { |
|
| 124 | - $class = parent::_get_row_class($item); |
|
| 125 | - if ($this->_has_checkbox_column) { |
|
| 126 | - $class .= ' has-checkbox-column'; |
|
| 127 | - } |
|
| 128 | - return $class; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param EE_Event $item |
|
| 134 | - * @return string |
|
| 135 | - * @throws EE_Error |
|
| 136 | - * @throws ReflectionException |
|
| 137 | - */ |
|
| 138 | - public function column_cb($item): string |
|
| 139 | - { |
|
| 140 | - if (! $item instanceof EE_Event) { |
|
| 141 | - return ''; |
|
| 142 | - } |
|
| 143 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 144 | - $content = sprintf( |
|
| 145 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 146 | - $item->ID() |
|
| 147 | - ); |
|
| 148 | - return $this->columnContent('cb', $content, 'center'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param EE_Event $event |
|
| 154 | - * @return string |
|
| 155 | - * @throws EE_Error |
|
| 156 | - * @throws ReflectionException |
|
| 157 | - */ |
|
| 158 | - public function column_id(EE_Event $event): string |
|
| 159 | - { |
|
| 160 | - $content = '<span class="ee-entity-id">' . $event->ID() . '</span>'; |
|
| 161 | - $content .= '<span class="show-on-mobile-view-only">'; |
|
| 162 | - $content .= $this->column_name($event, false); |
|
| 163 | - $content .= '</span>'; |
|
| 164 | - return $this->columnContent('id', $content, 'end'); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param EE_Event $event |
|
| 170 | - * @param bool $prep_content |
|
| 171 | - * @return string |
|
| 172 | - * @throws EE_Error |
|
| 173 | - * @throws ReflectionException |
|
| 174 | - */ |
|
| 175 | - public function column_name(EE_Event $event, bool $prep_content = true): string |
|
| 176 | - { |
|
| 177 | - $edit_query_args = [ |
|
| 178 | - 'action' => 'edit', |
|
| 179 | - 'post' => $event->ID(), |
|
| 180 | - ]; |
|
| 181 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 182 | - $actions = $this->_column_name_action_setup($event); |
|
| 183 | - $status = esc_attr($event->get_active_status()); |
|
| 184 | - $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
|
| 185 | - $status_dot = '<span class="ee-status-dot ee-status-bg--' . $status . '"></span>'; |
|
| 186 | - $visibility = $event->get_visibility_status(); |
|
| 187 | - $content = ' |
|
| 67 | + 'actions' => $this->actionsColumnHeader(), |
|
| 68 | + ]; |
|
| 69 | + $this->addConditionalColumns(); |
|
| 70 | + $this->_sortable_columns = [ |
|
| 71 | + 'id' => ['EVT_ID' => true], |
|
| 72 | + 'name' => ['EVT_name' => false], |
|
| 73 | + 'author' => ['EVT_wp_user' => false], |
|
| 74 | + 'venue' => ['Venue.VNU_name' => false], |
|
| 75 | + 'start_date_time' => ['Datetime.DTT_EVT_start' => false], |
|
| 76 | + 'reg_begins' => ['Datetime.Ticket.TKT_start_date' => false], |
|
| 77 | + ]; |
|
| 78 | + |
|
| 79 | + $this->_primary_column = 'id'; |
|
| 80 | + $this->_hidden_columns = ['author', 'event_category']; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return array |
|
| 86 | + */ |
|
| 87 | + protected function _get_table_filters() |
|
| 88 | + { |
|
| 89 | + return []; // no filters with decaf |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Setup of views properties. |
|
| 95 | + * |
|
| 96 | + * @throws InvalidDataTypeException |
|
| 97 | + * @throws InvalidInterfaceException |
|
| 98 | + * @throws InvalidArgumentException |
|
| 99 | + * @throws EE_Error |
|
| 100 | + * @throws EE_Error |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function _add_view_counts() |
|
| 104 | + { |
|
| 105 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 106 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 107 | + if ( |
|
| 108 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 109 | + 'ee_delete_events', |
|
| 110 | + 'espresso_events_trash_events' |
|
| 111 | + ) |
|
| 112 | + ) { |
|
| 113 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param EE_Event $item |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + protected function _get_row_class($item): string |
|
| 123 | + { |
|
| 124 | + $class = parent::_get_row_class($item); |
|
| 125 | + if ($this->_has_checkbox_column) { |
|
| 126 | + $class .= ' has-checkbox-column'; |
|
| 127 | + } |
|
| 128 | + return $class; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param EE_Event $item |
|
| 134 | + * @return string |
|
| 135 | + * @throws EE_Error |
|
| 136 | + * @throws ReflectionException |
|
| 137 | + */ |
|
| 138 | + public function column_cb($item): string |
|
| 139 | + { |
|
| 140 | + if (! $item instanceof EE_Event) { |
|
| 141 | + return ''; |
|
| 142 | + } |
|
| 143 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 144 | + $content = sprintf( |
|
| 145 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 146 | + $item->ID() |
|
| 147 | + ); |
|
| 148 | + return $this->columnContent('cb', $content, 'center'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param EE_Event $event |
|
| 154 | + * @return string |
|
| 155 | + * @throws EE_Error |
|
| 156 | + * @throws ReflectionException |
|
| 157 | + */ |
|
| 158 | + public function column_id(EE_Event $event): string |
|
| 159 | + { |
|
| 160 | + $content = '<span class="ee-entity-id">' . $event->ID() . '</span>'; |
|
| 161 | + $content .= '<span class="show-on-mobile-view-only">'; |
|
| 162 | + $content .= $this->column_name($event, false); |
|
| 163 | + $content .= '</span>'; |
|
| 164 | + return $this->columnContent('id', $content, 'end'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param EE_Event $event |
|
| 170 | + * @param bool $prep_content |
|
| 171 | + * @return string |
|
| 172 | + * @throws EE_Error |
|
| 173 | + * @throws ReflectionException |
|
| 174 | + */ |
|
| 175 | + public function column_name(EE_Event $event, bool $prep_content = true): string |
|
| 176 | + { |
|
| 177 | + $edit_query_args = [ |
|
| 178 | + 'action' => 'edit', |
|
| 179 | + 'post' => $event->ID(), |
|
| 180 | + ]; |
|
| 181 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 182 | + $actions = $this->_column_name_action_setup($event); |
|
| 183 | + $status = esc_attr($event->get_active_status()); |
|
| 184 | + $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
|
| 185 | + $status_dot = '<span class="ee-status-dot ee-status-bg--' . $status . '"></span>'; |
|
| 186 | + $visibility = $event->get_visibility_status(); |
|
| 187 | + $content = ' |
|
| 188 | 188 | <div class="ee-layout-row ee-layout-row--fixed"> |
| 189 | 189 | <a class="row-title ee-status-color--' . $status . ' ee-aria-tooltip" |
| 190 | 190 | aria-label="' . $pretty_status . '" |
@@ -193,415 +193,415 @@ discard block |
||
| 193 | 193 | ' . $status_dot . $event->name() . ' |
| 194 | 194 | </a> |
| 195 | 195 | ' . ( |
| 196 | - $visibility |
|
| 197 | - ? '<span class="ee-event-visibility-status ee-status-text-small">(' . esc_html($visibility) . ')</span>' |
|
| 198 | - : '' |
|
| 199 | - ) . ' |
|
| 196 | + $visibility |
|
| 197 | + ? '<span class="ee-event-visibility-status ee-status-text-small">(' . esc_html($visibility) . ')</span>' |
|
| 198 | + : '' |
|
| 199 | + ) . ' |
|
| 200 | 200 | </div>'; |
| 201 | 201 | |
| 202 | - $content .= $this->row_actions($actions); |
|
| 203 | - |
|
| 204 | - return $prep_content ? $this->columnContent('name', $content) : $content; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Just a method for setting up the actions for the name column |
|
| 210 | - * |
|
| 211 | - * @param EE_Event $event |
|
| 212 | - * @return array array of actions |
|
| 213 | - * @throws EE_Error |
|
| 214 | - * @throws InvalidArgumentException |
|
| 215 | - * @throws InvalidDataTypeException |
|
| 216 | - * @throws InvalidInterfaceException |
|
| 217 | - * @throws ReflectionException |
|
| 218 | - */ |
|
| 219 | - protected function _column_name_action_setup(EE_Event $event): array |
|
| 220 | - { |
|
| 221 | - // todo: remove when attendees is active |
|
| 222 | - if (! defined('REG_ADMIN_URL')) { |
|
| 223 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 224 | - } |
|
| 225 | - $actions = []; |
|
| 226 | - $restore_event_link = ''; |
|
| 227 | - $delete_event_link = ''; |
|
| 228 | - $trash_event_link = ''; |
|
| 229 | - if ( |
|
| 230 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 231 | - 'ee_edit_event', |
|
| 232 | - 'espresso_events_edit', |
|
| 233 | - $event->ID() |
|
| 234 | - ) |
|
| 235 | - ) { |
|
| 236 | - $edit_query_args = [ |
|
| 237 | - 'action' => 'edit', |
|
| 238 | - 'post' => $event->ID(), |
|
| 239 | - ]; |
|
| 240 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 241 | - $actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" ' |
|
| 242 | - . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 243 | - . esc_html__('Edit', 'event_espresso') |
|
| 244 | - . '</a>'; |
|
| 245 | - } |
|
| 246 | - if ( |
|
| 247 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 248 | - 'ee_read_registrations', |
|
| 249 | - 'espresso_registrations_view_registration' |
|
| 250 | - ) |
|
| 251 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 252 | - 'ee_read_event', |
|
| 253 | - 'espresso_registrations_view_registration', |
|
| 254 | - $event->ID() |
|
| 255 | - ) |
|
| 256 | - ) { |
|
| 257 | - $attendees_query_args = [ |
|
| 258 | - 'action' => 'default', |
|
| 259 | - 'event_id' => $event->ID(), |
|
| 260 | - ]; |
|
| 261 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 262 | - $actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"' |
|
| 263 | - . ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 264 | - . esc_html__('Registrations', 'event_espresso') |
|
| 265 | - . '</a>'; |
|
| 266 | - } |
|
| 267 | - if ( |
|
| 268 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 269 | - 'ee_delete_event', |
|
| 270 | - 'espresso_events_trash_event', |
|
| 271 | - $event->ID() |
|
| 272 | - ) |
|
| 273 | - ) { |
|
| 274 | - $trash_event_query_args = [ |
|
| 275 | - 'action' => 'trash_event', |
|
| 276 | - 'EVT_ID' => $event->ID(), |
|
| 277 | - ]; |
|
| 278 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 279 | - $trash_event_query_args, |
|
| 280 | - EVENTS_ADMIN_URL |
|
| 281 | - ); |
|
| 282 | - } |
|
| 283 | - if ( |
|
| 284 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 285 | - 'ee_delete_event', |
|
| 286 | - 'espresso_events_restore_event', |
|
| 287 | - $event->ID() |
|
| 288 | - ) |
|
| 289 | - ) { |
|
| 290 | - $restore_event_query_args = [ |
|
| 291 | - 'action' => 'restore_event', |
|
| 292 | - 'EVT_ID' => $event->ID(), |
|
| 293 | - ]; |
|
| 294 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 295 | - $restore_event_query_args, |
|
| 296 | - EVENTS_ADMIN_URL |
|
| 297 | - ); |
|
| 298 | - } |
|
| 299 | - if ( |
|
| 300 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 301 | - 'ee_delete_event', |
|
| 302 | - 'espresso_events_delete_event', |
|
| 303 | - $event->ID() |
|
| 304 | - ) |
|
| 305 | - ) { |
|
| 306 | - $delete_event_query_args = [ |
|
| 307 | - 'action' => 'delete_event', |
|
| 308 | - 'EVT_ID' => $event->ID(), |
|
| 309 | - ]; |
|
| 310 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 311 | - $delete_event_query_args, |
|
| 312 | - EVENTS_ADMIN_URL |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - $view_link = get_permalink($event->ID()); |
|
| 316 | - $actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"' |
|
| 317 | - . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 318 | - . esc_html__('View', 'event_espresso') |
|
| 319 | - . '</a>'; |
|
| 320 | - if ($event->get('status') === 'trash') { |
|
| 321 | - if ( |
|
| 322 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 323 | - 'ee_delete_event', |
|
| 324 | - 'espresso_events_restore_event', |
|
| 325 | - $event->ID() |
|
| 326 | - ) |
|
| 327 | - ) { |
|
| 328 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"' |
|
| 329 | - . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 330 | - . '">' |
|
| 331 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
| 332 | - . '</a>'; |
|
| 333 | - } |
|
| 334 | - if ( |
|
| 335 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 336 | - 'ee_delete_event', |
|
| 337 | - 'espresso_events_delete_event', |
|
| 338 | - $event->ID() |
|
| 339 | - ) |
|
| 340 | - ) { |
|
| 341 | - $actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"' |
|
| 342 | - . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 343 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
| 344 | - . '</a>'; |
|
| 345 | - } |
|
| 346 | - } else { |
|
| 347 | - if ( |
|
| 348 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 349 | - 'ee_delete_event', |
|
| 350 | - 'espresso_events_trash_event', |
|
| 351 | - $event->ID() |
|
| 352 | - ) |
|
| 353 | - ) { |
|
| 354 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"' |
|
| 355 | - . ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 356 | - . esc_html__('Trash', 'event_espresso') |
|
| 357 | - . '</a>'; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - return $actions; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * @param EE_Event $event |
|
| 366 | - * @return string |
|
| 367 | - * @throws EE_Error |
|
| 368 | - * @throws ReflectionException |
|
| 369 | - */ |
|
| 370 | - public function column_author(EE_Event $event): string |
|
| 371 | - { |
|
| 372 | - // user author info |
|
| 373 | - $event_author = get_userdata($event->wp_user()); |
|
| 374 | - $gravatar = get_avatar($event->wp_user(), '24'); |
|
| 375 | - // filter link |
|
| 376 | - $query_args = [ |
|
| 377 | - 'action' => 'default', |
|
| 378 | - 'EVT_wp_user' => $event->wp_user(), |
|
| 379 | - ]; |
|
| 380 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 381 | - $content = '<div class="ee-layout-row ee-layout-row--fixed">'; |
|
| 382 | - $content .= ' <a href="' . $filter_url . '" class="ee-event-author ee-aria-tooltip"' |
|
| 383 | - . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 384 | - . $gravatar . $event_author->display_name |
|
| 385 | - . '</a>'; |
|
| 386 | - $content .= '</div>'; |
|
| 387 | - return $this->columnContent('author', $content); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @param EE_Event $event |
|
| 393 | - * @return string |
|
| 394 | - * @throws EE_Error |
|
| 395 | - * @throws ReflectionException |
|
| 396 | - */ |
|
| 397 | - public function column_event_category(EE_Event $event): string |
|
| 398 | - { |
|
| 399 | - $event_categories = $event->get_all_event_categories(); |
|
| 400 | - $content = implode( |
|
| 401 | - ', ', |
|
| 402 | - array_map( |
|
| 403 | - function (EE_Term $category) { |
|
| 404 | - return $category->name(); |
|
| 405 | - }, |
|
| 406 | - $event_categories |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 409 | - return $this->columnContent('event_category', $content); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * @param EE_Event $event |
|
| 415 | - * @return string |
|
| 416 | - * @throws EE_Error |
|
| 417 | - * @throws ReflectionException |
|
| 418 | - */ |
|
| 419 | - public function column_venue(EE_Event $event): string |
|
| 420 | - { |
|
| 421 | - $venue = $event->get_first_related('Venue'); |
|
| 422 | - $content = ! empty($venue) |
|
| 423 | - ? $venue->name() |
|
| 424 | - : ''; |
|
| 425 | - return $this->columnContent('venue', $content); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * @param EE_Event $event |
|
| 431 | - * @return string |
|
| 432 | - * @throws EE_Error |
|
| 433 | - * @throws ReflectionException |
|
| 434 | - */ |
|
| 435 | - public function column_start_date_time(EE_Event $event): string |
|
| 436 | - { |
|
| 437 | - $content = $this->_dtt instanceof EE_Datetime |
|
| 438 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 439 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 440 | - return $this->columnContent('start_date_time', $content); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * @param EE_Event $event |
|
| 446 | - * @return string |
|
| 447 | - * @throws EE_Error |
|
| 448 | - * @throws ReflectionException |
|
| 449 | - */ |
|
| 450 | - public function column_reg_begins(EE_Event $event): string |
|
| 451 | - { |
|
| 452 | - $reg_start = $event->get_ticket_with_earliest_start_time(); |
|
| 453 | - $content = $reg_start instanceof EE_Ticket |
|
| 454 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 455 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 456 | - return $this->columnContent('reg_begins', $content); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @param EE_Event $event |
|
| 462 | - * @return string |
|
| 463 | - * @throws EE_Error |
|
| 464 | - * @throws InvalidArgumentException |
|
| 465 | - * @throws InvalidDataTypeException |
|
| 466 | - * @throws InvalidInterfaceException |
|
| 467 | - * @throws ReflectionException |
|
| 468 | - */ |
|
| 469 | - public function column_attendees(EE_Event $event): string |
|
| 470 | - { |
|
| 471 | - $attendees_query_args = [ |
|
| 472 | - 'action' => 'default', |
|
| 473 | - 'event_id' => $event->ID(), |
|
| 474 | - ]; |
|
| 475 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 476 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($event->ID()); |
|
| 477 | - |
|
| 478 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 479 | - 'ee_read_event', |
|
| 480 | - 'espresso_registrations_view_registration', |
|
| 481 | - $event->ID() |
|
| 482 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 483 | - 'ee_read_registrations', |
|
| 484 | - 'espresso_registrations_view_registration' |
|
| 485 | - ) |
|
| 486 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 487 | - : $registered_attendees; |
|
| 488 | - return $this->columnContent('attendees', $content, 'center'); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @param EE_Event $event |
|
| 494 | - * @return float |
|
| 495 | - * @throws EE_Error |
|
| 496 | - * @throws InvalidArgumentException |
|
| 497 | - * @throws InvalidDataTypeException |
|
| 498 | - * @throws InvalidInterfaceException |
|
| 499 | - * @throws ReflectionException |
|
| 500 | - */ |
|
| 501 | - public function column_tkts_sold(EE_Event $event): float |
|
| 502 | - { |
|
| 503 | - $content = EEM_Ticket::instance()->sum([['Datetime.EVT_ID' => $event->ID()]], 'TKT_sold'); |
|
| 504 | - return $this->columnContent('tkts_sold', $content); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * @param EE_Event $event |
|
| 510 | - * @return string |
|
| 511 | - * @throws EE_Error |
|
| 512 | - * @throws InvalidArgumentException |
|
| 513 | - * @throws InvalidDataTypeException |
|
| 514 | - * @throws InvalidInterfaceException |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - */ |
|
| 517 | - public function column_actions(EE_Event $event): string |
|
| 518 | - { |
|
| 519 | - // todo: remove when attendees is active |
|
| 520 | - if (! defined('REG_ADMIN_URL')) { |
|
| 521 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 522 | - } |
|
| 523 | - $action_links = []; |
|
| 524 | - $view_link = get_permalink($event->ID()); |
|
| 525 | - $action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--icon-only"' |
|
| 526 | - . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank"> |
|
| 202 | + $content .= $this->row_actions($actions); |
|
| 203 | + |
|
| 204 | + return $prep_content ? $this->columnContent('name', $content) : $content; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Just a method for setting up the actions for the name column |
|
| 210 | + * |
|
| 211 | + * @param EE_Event $event |
|
| 212 | + * @return array array of actions |
|
| 213 | + * @throws EE_Error |
|
| 214 | + * @throws InvalidArgumentException |
|
| 215 | + * @throws InvalidDataTypeException |
|
| 216 | + * @throws InvalidInterfaceException |
|
| 217 | + * @throws ReflectionException |
|
| 218 | + */ |
|
| 219 | + protected function _column_name_action_setup(EE_Event $event): array |
|
| 220 | + { |
|
| 221 | + // todo: remove when attendees is active |
|
| 222 | + if (! defined('REG_ADMIN_URL')) { |
|
| 223 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 224 | + } |
|
| 225 | + $actions = []; |
|
| 226 | + $restore_event_link = ''; |
|
| 227 | + $delete_event_link = ''; |
|
| 228 | + $trash_event_link = ''; |
|
| 229 | + if ( |
|
| 230 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 231 | + 'ee_edit_event', |
|
| 232 | + 'espresso_events_edit', |
|
| 233 | + $event->ID() |
|
| 234 | + ) |
|
| 235 | + ) { |
|
| 236 | + $edit_query_args = [ |
|
| 237 | + 'action' => 'edit', |
|
| 238 | + 'post' => $event->ID(), |
|
| 239 | + ]; |
|
| 240 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 241 | + $actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" ' |
|
| 242 | + . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 243 | + . esc_html__('Edit', 'event_espresso') |
|
| 244 | + . '</a>'; |
|
| 245 | + } |
|
| 246 | + if ( |
|
| 247 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 248 | + 'ee_read_registrations', |
|
| 249 | + 'espresso_registrations_view_registration' |
|
| 250 | + ) |
|
| 251 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 252 | + 'ee_read_event', |
|
| 253 | + 'espresso_registrations_view_registration', |
|
| 254 | + $event->ID() |
|
| 255 | + ) |
|
| 256 | + ) { |
|
| 257 | + $attendees_query_args = [ |
|
| 258 | + 'action' => 'default', |
|
| 259 | + 'event_id' => $event->ID(), |
|
| 260 | + ]; |
|
| 261 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 262 | + $actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"' |
|
| 263 | + . ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 264 | + . esc_html__('Registrations', 'event_espresso') |
|
| 265 | + . '</a>'; |
|
| 266 | + } |
|
| 267 | + if ( |
|
| 268 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 269 | + 'ee_delete_event', |
|
| 270 | + 'espresso_events_trash_event', |
|
| 271 | + $event->ID() |
|
| 272 | + ) |
|
| 273 | + ) { |
|
| 274 | + $trash_event_query_args = [ |
|
| 275 | + 'action' => 'trash_event', |
|
| 276 | + 'EVT_ID' => $event->ID(), |
|
| 277 | + ]; |
|
| 278 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 279 | + $trash_event_query_args, |
|
| 280 | + EVENTS_ADMIN_URL |
|
| 281 | + ); |
|
| 282 | + } |
|
| 283 | + if ( |
|
| 284 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 285 | + 'ee_delete_event', |
|
| 286 | + 'espresso_events_restore_event', |
|
| 287 | + $event->ID() |
|
| 288 | + ) |
|
| 289 | + ) { |
|
| 290 | + $restore_event_query_args = [ |
|
| 291 | + 'action' => 'restore_event', |
|
| 292 | + 'EVT_ID' => $event->ID(), |
|
| 293 | + ]; |
|
| 294 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 295 | + $restore_event_query_args, |
|
| 296 | + EVENTS_ADMIN_URL |
|
| 297 | + ); |
|
| 298 | + } |
|
| 299 | + if ( |
|
| 300 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 301 | + 'ee_delete_event', |
|
| 302 | + 'espresso_events_delete_event', |
|
| 303 | + $event->ID() |
|
| 304 | + ) |
|
| 305 | + ) { |
|
| 306 | + $delete_event_query_args = [ |
|
| 307 | + 'action' => 'delete_event', |
|
| 308 | + 'EVT_ID' => $event->ID(), |
|
| 309 | + ]; |
|
| 310 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 311 | + $delete_event_query_args, |
|
| 312 | + EVENTS_ADMIN_URL |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + $view_link = get_permalink($event->ID()); |
|
| 316 | + $actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"' |
|
| 317 | + . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 318 | + . esc_html__('View', 'event_espresso') |
|
| 319 | + . '</a>'; |
|
| 320 | + if ($event->get('status') === 'trash') { |
|
| 321 | + if ( |
|
| 322 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 323 | + 'ee_delete_event', |
|
| 324 | + 'espresso_events_restore_event', |
|
| 325 | + $event->ID() |
|
| 326 | + ) |
|
| 327 | + ) { |
|
| 328 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"' |
|
| 329 | + . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 330 | + . '">' |
|
| 331 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
| 332 | + . '</a>'; |
|
| 333 | + } |
|
| 334 | + if ( |
|
| 335 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 336 | + 'ee_delete_event', |
|
| 337 | + 'espresso_events_delete_event', |
|
| 338 | + $event->ID() |
|
| 339 | + ) |
|
| 340 | + ) { |
|
| 341 | + $actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"' |
|
| 342 | + . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 343 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
| 344 | + . '</a>'; |
|
| 345 | + } |
|
| 346 | + } else { |
|
| 347 | + if ( |
|
| 348 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 349 | + 'ee_delete_event', |
|
| 350 | + 'espresso_events_trash_event', |
|
| 351 | + $event->ID() |
|
| 352 | + ) |
|
| 353 | + ) { |
|
| 354 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"' |
|
| 355 | + . ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 356 | + . esc_html__('Trash', 'event_espresso') |
|
| 357 | + . '</a>'; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + return $actions; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * @param EE_Event $event |
|
| 366 | + * @return string |
|
| 367 | + * @throws EE_Error |
|
| 368 | + * @throws ReflectionException |
|
| 369 | + */ |
|
| 370 | + public function column_author(EE_Event $event): string |
|
| 371 | + { |
|
| 372 | + // user author info |
|
| 373 | + $event_author = get_userdata($event->wp_user()); |
|
| 374 | + $gravatar = get_avatar($event->wp_user(), '24'); |
|
| 375 | + // filter link |
|
| 376 | + $query_args = [ |
|
| 377 | + 'action' => 'default', |
|
| 378 | + 'EVT_wp_user' => $event->wp_user(), |
|
| 379 | + ]; |
|
| 380 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 381 | + $content = '<div class="ee-layout-row ee-layout-row--fixed">'; |
|
| 382 | + $content .= ' <a href="' . $filter_url . '" class="ee-event-author ee-aria-tooltip"' |
|
| 383 | + . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 384 | + . $gravatar . $event_author->display_name |
|
| 385 | + . '</a>'; |
|
| 386 | + $content .= '</div>'; |
|
| 387 | + return $this->columnContent('author', $content); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @param EE_Event $event |
|
| 393 | + * @return string |
|
| 394 | + * @throws EE_Error |
|
| 395 | + * @throws ReflectionException |
|
| 396 | + */ |
|
| 397 | + public function column_event_category(EE_Event $event): string |
|
| 398 | + { |
|
| 399 | + $event_categories = $event->get_all_event_categories(); |
|
| 400 | + $content = implode( |
|
| 401 | + ', ', |
|
| 402 | + array_map( |
|
| 403 | + function (EE_Term $category) { |
|
| 404 | + return $category->name(); |
|
| 405 | + }, |
|
| 406 | + $event_categories |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | + return $this->columnContent('event_category', $content); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * @param EE_Event $event |
|
| 415 | + * @return string |
|
| 416 | + * @throws EE_Error |
|
| 417 | + * @throws ReflectionException |
|
| 418 | + */ |
|
| 419 | + public function column_venue(EE_Event $event): string |
|
| 420 | + { |
|
| 421 | + $venue = $event->get_first_related('Venue'); |
|
| 422 | + $content = ! empty($venue) |
|
| 423 | + ? $venue->name() |
|
| 424 | + : ''; |
|
| 425 | + return $this->columnContent('venue', $content); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * @param EE_Event $event |
|
| 431 | + * @return string |
|
| 432 | + * @throws EE_Error |
|
| 433 | + * @throws ReflectionException |
|
| 434 | + */ |
|
| 435 | + public function column_start_date_time(EE_Event $event): string |
|
| 436 | + { |
|
| 437 | + $content = $this->_dtt instanceof EE_Datetime |
|
| 438 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 439 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 440 | + return $this->columnContent('start_date_time', $content); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * @param EE_Event $event |
|
| 446 | + * @return string |
|
| 447 | + * @throws EE_Error |
|
| 448 | + * @throws ReflectionException |
|
| 449 | + */ |
|
| 450 | + public function column_reg_begins(EE_Event $event): string |
|
| 451 | + { |
|
| 452 | + $reg_start = $event->get_ticket_with_earliest_start_time(); |
|
| 453 | + $content = $reg_start instanceof EE_Ticket |
|
| 454 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 455 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 456 | + return $this->columnContent('reg_begins', $content); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @param EE_Event $event |
|
| 462 | + * @return string |
|
| 463 | + * @throws EE_Error |
|
| 464 | + * @throws InvalidArgumentException |
|
| 465 | + * @throws InvalidDataTypeException |
|
| 466 | + * @throws InvalidInterfaceException |
|
| 467 | + * @throws ReflectionException |
|
| 468 | + */ |
|
| 469 | + public function column_attendees(EE_Event $event): string |
|
| 470 | + { |
|
| 471 | + $attendees_query_args = [ |
|
| 472 | + 'action' => 'default', |
|
| 473 | + 'event_id' => $event->ID(), |
|
| 474 | + ]; |
|
| 475 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 476 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($event->ID()); |
|
| 477 | + |
|
| 478 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 479 | + 'ee_read_event', |
|
| 480 | + 'espresso_registrations_view_registration', |
|
| 481 | + $event->ID() |
|
| 482 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 483 | + 'ee_read_registrations', |
|
| 484 | + 'espresso_registrations_view_registration' |
|
| 485 | + ) |
|
| 486 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 487 | + : $registered_attendees; |
|
| 488 | + return $this->columnContent('attendees', $content, 'center'); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @param EE_Event $event |
|
| 494 | + * @return float |
|
| 495 | + * @throws EE_Error |
|
| 496 | + * @throws InvalidArgumentException |
|
| 497 | + * @throws InvalidDataTypeException |
|
| 498 | + * @throws InvalidInterfaceException |
|
| 499 | + * @throws ReflectionException |
|
| 500 | + */ |
|
| 501 | + public function column_tkts_sold(EE_Event $event): float |
|
| 502 | + { |
|
| 503 | + $content = EEM_Ticket::instance()->sum([['Datetime.EVT_ID' => $event->ID()]], 'TKT_sold'); |
|
| 504 | + return $this->columnContent('tkts_sold', $content); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * @param EE_Event $event |
|
| 510 | + * @return string |
|
| 511 | + * @throws EE_Error |
|
| 512 | + * @throws InvalidArgumentException |
|
| 513 | + * @throws InvalidDataTypeException |
|
| 514 | + * @throws InvalidInterfaceException |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + */ |
|
| 517 | + public function column_actions(EE_Event $event): string |
|
| 518 | + { |
|
| 519 | + // todo: remove when attendees is active |
|
| 520 | + if (! defined('REG_ADMIN_URL')) { |
|
| 521 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 522 | + } |
|
| 523 | + $action_links = []; |
|
| 524 | + $view_link = get_permalink($event->ID()); |
|
| 525 | + $action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--icon-only"' |
|
| 526 | + . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank"> |
|
| 527 | 527 | <span class="dashicons dashicons-visibility"></span></a>'; |
| 528 | - if ( |
|
| 529 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 530 | - 'ee_edit_event', |
|
| 531 | - 'espresso_events_edit', |
|
| 532 | - $event->ID() |
|
| 533 | - ) |
|
| 534 | - ) { |
|
| 535 | - $edit_query_args = [ |
|
| 536 | - 'action' => 'edit', |
|
| 537 | - 'post' => $event->ID(), |
|
| 538 | - ]; |
|
| 539 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 540 | - $action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--icon-only"' |
|
| 541 | - . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 542 | - . '<span class="dashicons dashicons-calendar-alt"></span>' |
|
| 543 | - . '</a>'; |
|
| 544 | - } |
|
| 545 | - if ( |
|
| 546 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 547 | - 'ee_read_registrations', |
|
| 548 | - 'espresso_registrations_view_registration' |
|
| 549 | - ) |
|
| 550 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 551 | - 'ee_read_event', |
|
| 552 | - 'espresso_registrations_view_registration', |
|
| 553 | - $event->ID() |
|
| 554 | - ) |
|
| 555 | - ) { |
|
| 556 | - $attendees_query_args = [ |
|
| 557 | - 'action' => 'default', |
|
| 558 | - 'event_id' => $event->ID(), |
|
| 559 | - ]; |
|
| 560 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 561 | - $action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--icon-only"' |
|
| 562 | - . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 563 | - . '<span class="dashicons dashicons-groups"></span>' |
|
| 564 | - . '</a>'; |
|
| 565 | - } |
|
| 566 | - $action_links = apply_filters( |
|
| 567 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 568 | - $action_links, |
|
| 569 | - $event |
|
| 570 | - ); |
|
| 571 | - $content = $this->_action_string( |
|
| 572 | - implode("\n\t", $action_links), |
|
| 573 | - $event, |
|
| 574 | - 'div', |
|
| 575 | - 'event-overview-actions ee-list-table-actions' |
|
| 576 | - ); |
|
| 577 | - return $this->columnContent('actions', $this->actionsModalMenu($content)); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Helper for adding columns conditionally |
|
| 583 | - * |
|
| 584 | - * @throws EE_Error |
|
| 585 | - * @throws InvalidArgumentException |
|
| 586 | - * @throws InvalidDataTypeException |
|
| 587 | - * @throws InvalidInterfaceException |
|
| 588 | - * @throws ReflectionException |
|
| 589 | - */ |
|
| 590 | - private function addConditionalColumns() |
|
| 591 | - { |
|
| 592 | - $event_category_count = EEM_Term::instance()->count( |
|
| 593 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
| 594 | - ); |
|
| 595 | - if ($event_category_count === 0) { |
|
| 596 | - return; |
|
| 597 | - } |
|
| 598 | - $column_array = []; |
|
| 599 | - foreach ($this->_columns as $column => $column_label) { |
|
| 600 | - $column_array[ $column ] = $column_label; |
|
| 601 | - if ($column === 'venue') { |
|
| 602 | - $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - $this->_columns = $column_array; |
|
| 606 | - } |
|
| 528 | + if ( |
|
| 529 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 530 | + 'ee_edit_event', |
|
| 531 | + 'espresso_events_edit', |
|
| 532 | + $event->ID() |
|
| 533 | + ) |
|
| 534 | + ) { |
|
| 535 | + $edit_query_args = [ |
|
| 536 | + 'action' => 'edit', |
|
| 537 | + 'post' => $event->ID(), |
|
| 538 | + ]; |
|
| 539 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 540 | + $action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--icon-only"' |
|
| 541 | + . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 542 | + . '<span class="dashicons dashicons-calendar-alt"></span>' |
|
| 543 | + . '</a>'; |
|
| 544 | + } |
|
| 545 | + if ( |
|
| 546 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 547 | + 'ee_read_registrations', |
|
| 548 | + 'espresso_registrations_view_registration' |
|
| 549 | + ) |
|
| 550 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 551 | + 'ee_read_event', |
|
| 552 | + 'espresso_registrations_view_registration', |
|
| 553 | + $event->ID() |
|
| 554 | + ) |
|
| 555 | + ) { |
|
| 556 | + $attendees_query_args = [ |
|
| 557 | + 'action' => 'default', |
|
| 558 | + 'event_id' => $event->ID(), |
|
| 559 | + ]; |
|
| 560 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 561 | + $action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--icon-only"' |
|
| 562 | + . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 563 | + . '<span class="dashicons dashicons-groups"></span>' |
|
| 564 | + . '</a>'; |
|
| 565 | + } |
|
| 566 | + $action_links = apply_filters( |
|
| 567 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 568 | + $action_links, |
|
| 569 | + $event |
|
| 570 | + ); |
|
| 571 | + $content = $this->_action_string( |
|
| 572 | + implode("\n\t", $action_links), |
|
| 573 | + $event, |
|
| 574 | + 'div', |
|
| 575 | + 'event-overview-actions ee-list-table-actions' |
|
| 576 | + ); |
|
| 577 | + return $this->columnContent('actions', $this->actionsModalMenu($content)); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Helper for adding columns conditionally |
|
| 583 | + * |
|
| 584 | + * @throws EE_Error |
|
| 585 | + * @throws InvalidArgumentException |
|
| 586 | + * @throws InvalidDataTypeException |
|
| 587 | + * @throws InvalidInterfaceException |
|
| 588 | + * @throws ReflectionException |
|
| 589 | + */ |
|
| 590 | + private function addConditionalColumns() |
|
| 591 | + { |
|
| 592 | + $event_category_count = EEM_Term::instance()->count( |
|
| 593 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
| 594 | + ); |
|
| 595 | + if ($event_category_count === 0) { |
|
| 596 | + return; |
|
| 597 | + } |
|
| 598 | + $column_array = []; |
|
| 599 | + foreach ($this->_columns as $column => $column_label) { |
|
| 600 | + $column_array[ $column ] = $column_label; |
|
| 601 | + if ($column === 'venue') { |
|
| 602 | + $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + $this->_columns = $column_array; |
|
| 606 | + } |
|
| 607 | 607 | } |
@@ -15,956 +15,956 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Maintenance_Admin_Page extends EE_Admin_Page |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var EE_Data_Migration_Manager |
|
| 20 | - */ |
|
| 21 | - protected $migration_manager; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var EE_Maintenance_Mode |
|
| 25 | - */ |
|
| 26 | - protected $maintenance_mode; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var EE_Form_Section_Proper |
|
| 30 | - */ |
|
| 31 | - protected $datetime_fix_offset_form; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @param bool $routing |
|
| 36 | - * @throws EE_Error |
|
| 37 | - * @throws ReflectionException |
|
| 38 | - */ |
|
| 39 | - public function __construct($routing = true) |
|
| 40 | - { |
|
| 41 | - $this->migration_manager = EE_Data_Migration_Manager::instance(); |
|
| 42 | - $this->maintenance_mode = EE_Maintenance_Mode::instance(); |
|
| 43 | - parent::__construct($routing); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - protected function _init_page_props() |
|
| 48 | - { |
|
| 49 | - $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
| 50 | - $this->page_label = EE_MAINTENANCE_LABEL; |
|
| 51 | - $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
| 52 | - $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - protected function _ajax_hooks() |
|
| 57 | - { |
|
| 58 | - add_action('wp_ajax_migration_step', [$this, 'migration_step']); |
|
| 59 | - add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - protected function _define_page_props() |
|
| 64 | - { |
|
| 65 | - $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
| 66 | - $this->_labels = [ |
|
| 67 | - 'buttons' => [ |
|
| 68 | - 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
| 69 | - 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
| 70 | - ], |
|
| 71 | - ]; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - protected function _set_page_routes() |
|
| 76 | - { |
|
| 77 | - $this->_page_routes = [ |
|
| 78 | - 'default' => [ |
|
| 79 | - 'func' => [$this, '_maintenance'], |
|
| 80 | - 'capability' => 'manage_options', |
|
| 81 | - ], |
|
| 82 | - 'change_maintenance_level' => [ |
|
| 83 | - 'func' => [$this, '_change_maintenance_level'], |
|
| 84 | - 'capability' => 'manage_options', |
|
| 85 | - 'noheader' => true, |
|
| 86 | - ], |
|
| 87 | - 'system_status' => [ |
|
| 88 | - 'func' => [$this, '_system_status'], |
|
| 89 | - 'capability' => 'manage_options', |
|
| 90 | - ], |
|
| 91 | - 'download_system_status' => [ |
|
| 92 | - 'func' => [$this, '_download_system_status'], |
|
| 93 | - 'capability' => 'manage_options', |
|
| 94 | - 'noheader' => true, |
|
| 95 | - ], |
|
| 96 | - 'send_migration_crash_report' => [ |
|
| 97 | - 'func' => [$this, '_send_migration_crash_report'], |
|
| 98 | - 'capability' => 'manage_options', |
|
| 99 | - 'noheader' => true, |
|
| 100 | - ], |
|
| 101 | - 'confirm_migration_crash_report_sent' => [ |
|
| 102 | - 'func' => [$this, '_confirm_migration_crash_report_sent'], |
|
| 103 | - 'capability' => 'manage_options', |
|
| 104 | - ], |
|
| 105 | - 'data_reset' => [ |
|
| 106 | - 'func' => [$this, '_data_reset_and_delete'], |
|
| 107 | - 'capability' => 'manage_options', |
|
| 108 | - ], |
|
| 109 | - 'reset_db' => [ |
|
| 110 | - 'func' => [$this, '_reset_db'], |
|
| 111 | - 'capability' => 'manage_options', |
|
| 112 | - 'noheader' => true, |
|
| 113 | - 'args' => ['nuke_old_ee4_data' => true], |
|
| 114 | - ], |
|
| 115 | - 'start_with_fresh_ee4_db' => [ |
|
| 116 | - 'func' => [$this, '_reset_db'], |
|
| 117 | - 'capability' => 'manage_options', |
|
| 118 | - 'noheader' => true, |
|
| 119 | - 'args' => ['nuke_old_ee4_data' => false], |
|
| 120 | - ], |
|
| 121 | - 'delete_db' => [ |
|
| 122 | - 'func' => [$this, '_delete_db'], |
|
| 123 | - 'capability' => 'manage_options', |
|
| 124 | - 'noheader' => true, |
|
| 125 | - ], |
|
| 126 | - 'rerun_migration_from_ee3' => [ |
|
| 127 | - 'func' => [$this, '_rerun_migration_from_ee3'], |
|
| 128 | - 'capability' => 'manage_options', |
|
| 129 | - 'noheader' => true, |
|
| 130 | - ], |
|
| 131 | - 'reset_reservations' => [ |
|
| 132 | - 'func' => [$this, '_reset_reservations'], |
|
| 133 | - 'capability' => 'manage_options', |
|
| 134 | - 'noheader' => true, |
|
| 135 | - ], |
|
| 136 | - 'reset_capabilities' => [ |
|
| 137 | - 'func' => [$this, '_reset_capabilities'], |
|
| 138 | - 'capability' => 'manage_options', |
|
| 139 | - 'noheader' => true, |
|
| 140 | - ], |
|
| 141 | - 'reattempt_migration' => [ |
|
| 142 | - 'func' => [$this, '_reattempt_migration'], |
|
| 143 | - 'capability' => 'manage_options', |
|
| 144 | - 'noheader' => true, |
|
| 145 | - ], |
|
| 146 | - 'datetime_tools' => [ |
|
| 147 | - 'func' => [$this, '_datetime_tools'], |
|
| 148 | - 'capability' => 'manage_options', |
|
| 149 | - ], |
|
| 150 | - 'run_datetime_offset_fix' => [ |
|
| 151 | - 'func' => [$this, '_apply_datetime_offset'], |
|
| 152 | - 'noheader' => true, |
|
| 153 | - 'headers_sent_route' => 'datetime_tools', |
|
| 154 | - 'capability' => 'manage_options', |
|
| 155 | - ], |
|
| 156 | - ]; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - protected function _set_page_config() |
|
| 161 | - { |
|
| 162 | - $this->_page_config = [ |
|
| 163 | - 'default' => [ |
|
| 164 | - 'nav' => [ |
|
| 165 | - 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
| 166 | - 'icon' => 'dashicons-admin-tools', |
|
| 167 | - 'order' => 10, |
|
| 168 | - ], |
|
| 169 | - 'require_nonce' => false, |
|
| 170 | - ], |
|
| 171 | - 'data_reset' => [ |
|
| 172 | - 'nav' => [ |
|
| 173 | - 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
| 174 | - 'icon' => 'dashicons-trash', |
|
| 175 | - 'order' => 20, |
|
| 176 | - ], |
|
| 177 | - 'require_nonce' => false, |
|
| 178 | - ], |
|
| 179 | - 'datetime_tools' => [ |
|
| 180 | - 'nav' => [ |
|
| 181 | - 'label' => esc_html__('Datetime Utilities', 'event_espresso'), |
|
| 182 | - 'icon' => 'dashicons-calendar-alt', |
|
| 183 | - 'order' => 25, |
|
| 184 | - ], |
|
| 185 | - 'require_nonce' => false, |
|
| 186 | - ], |
|
| 187 | - 'system_status' => [ |
|
| 188 | - 'nav' => [ |
|
| 189 | - 'label' => esc_html__("System Information", "event_espresso"), |
|
| 190 | - 'icon' => 'dashicons-info', |
|
| 191 | - 'order' => 30, |
|
| 192 | - ], |
|
| 193 | - 'require_nonce' => false, |
|
| 194 | - ], |
|
| 195 | - ]; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * default maintenance page. |
|
| 201 | - * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI. |
|
| 202 | - * |
|
| 203 | - * @throws EE_Error |
|
| 204 | - */ |
|
| 205 | - public function _maintenance() |
|
| 206 | - { |
|
| 207 | - $show_maintenance_switch = true; |
|
| 208 | - $show_backup_db_text = false; |
|
| 209 | - $show_migration_progress = false; |
|
| 210 | - $script_names = []; |
|
| 211 | - $addons_should_be_upgraded_first = false; |
|
| 212 | - // it all depends on if we're in maintenance model level 1 (frontend-only) or |
|
| 213 | - // level 2 (everything except maintenance page) |
|
| 214 | - try { |
|
| 215 | - // get the current maintenance level and check if we are removed |
|
| 216 | - $was_full_site_maintenence_mode = MaintenanceStatus::isFullSite(); |
|
| 217 | - $no_longer_in_maintenence_mode = ! $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 218 | - if ($was_full_site_maintenence_mode && $no_longer_in_maintenence_mode) { |
|
| 219 | - // we just took the site out of maintenance mode, so notify the user. |
|
| 220 | - // unfortunately this message appears to be echoed on the NEXT page load... |
|
| 221 | - // oh well, we should really be checking for this on addon deactivation anyways |
|
| 222 | - EE_Error::add_attention( |
|
| 223 | - esc_html__( |
|
| 224 | - 'Site taken out of maintenance mode because no data migration scripts are required', |
|
| 225 | - 'event_espresso' |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - $this->_process_notices(['page' => 'espresso_maintenance_settings']); |
|
| 229 | - } |
|
| 230 | - // in case an exception is thrown while trying to handle migrations |
|
| 231 | - if (MaintenanceStatus::isFullSite()) { |
|
| 232 | - $show_maintenance_switch = false; |
|
| 233 | - $show_migration_progress = true; |
|
| 234 | - if (! isset($this->_req_data['continue_migration'])) { |
|
| 235 | - $show_backup_db_text = true; |
|
| 236 | - } |
|
| 237 | - $scripts_needing_to_run = |
|
| 238 | - $this->migration_manager->check_for_applicable_data_migration_scripts(); |
|
| 239 | - $addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating(); |
|
| 240 | - $script_names = []; |
|
| 241 | - $current_script = null; |
|
| 242 | - foreach ($scripts_needing_to_run as $script) { |
|
| 243 | - if ($script instanceof EE_Data_Migration_Script_Base) { |
|
| 244 | - if (! $current_script) { |
|
| 245 | - $current_script = $script; |
|
| 246 | - $current_script->migration_page_hooks(); |
|
| 247 | - } |
|
| 248 | - $script_names[] = $script->pretty_name(); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - $most_recent_migration = $this->migration_manager->get_last_ran_script(true); |
|
| 253 | - $exception_thrown = false; |
|
| 254 | - } catch (EE_Error $e) { |
|
| 255 | - $this->migration_manager->add_error_to_migrations_ran($e->getMessage()); |
|
| 256 | - // now, just so we can display the page correctly, make an error migration script stage object |
|
| 257 | - // and also put the error on it. It only persists for the duration of this request |
|
| 258 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 259 | - $most_recent_migration->add_error($e->getMessage()); |
|
| 260 | - $exception_thrown = true; |
|
| 261 | - } |
|
| 262 | - $current_db_state = $this->migration_manager->ensure_current_database_state_is_set(); |
|
| 263 | - $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
| 264 | - if ( |
|
| 265 | - $exception_thrown |
|
| 266 | - || ( |
|
| 267 | - $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 268 | - && $most_recent_migration->is_broken() |
|
| 269 | - ) |
|
| 270 | - ) { |
|
| 271 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
| 272 | - |
|
| 273 | - $this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/'; |
|
| 274 | - $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce( |
|
| 275 | - [ |
|
| 276 | - 'action' => 'confirm_migration_crash_report_sent', |
|
| 277 | - 'success' => '0', |
|
| 278 | - ], |
|
| 279 | - EE_MAINTENANCE_ADMIN_URL |
|
| 280 | - ); |
|
| 281 | - } elseif ($addons_should_be_upgraded_first) { |
|
| 282 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
| 283 | - } else { |
|
| 284 | - if ( |
|
| 285 | - $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 286 | - && $most_recent_migration->can_continue() |
|
| 287 | - ) { |
|
| 288 | - $show_backup_db_text = false; |
|
| 289 | - $show_continue_current_migration_script = true; |
|
| 290 | - $show_most_recent_migration = true; |
|
| 291 | - } elseif (isset($this->_req_data['continue_migration'])) { |
|
| 292 | - $show_most_recent_migration = true; |
|
| 293 | - $show_continue_current_migration_script = false; |
|
| 294 | - } else { |
|
| 295 | - $show_most_recent_migration = false; |
|
| 296 | - $show_continue_current_migration_script = false; |
|
| 297 | - } |
|
| 298 | - if (isset($current_script)) { |
|
| 299 | - $migrates_to = $current_script->migrates_to_version(); |
|
| 300 | - $plugin_slug = $migrates_to['slug']; |
|
| 301 | - $new_version = $migrates_to['version']; |
|
| 302 | - $this->_template_args = array_merge( |
|
| 303 | - $this->_template_args, |
|
| 304 | - [ |
|
| 305 | - 'current_db_state' => sprintf( |
|
| 306 | - esc_html__("EE%s (%s)", "event_espresso"), |
|
| 307 | - $current_db_state[ $plugin_slug ] ?? 3, |
|
| 308 | - $plugin_slug |
|
| 309 | - ), |
|
| 310 | - 'next_db_state' => sprintf( |
|
| 311 | - esc_html__("EE%s (%s)", 'event_espresso'), |
|
| 312 | - $new_version, |
|
| 313 | - $plugin_slug |
|
| 314 | - ), |
|
| 315 | - ] |
|
| 316 | - ); |
|
| 317 | - } else { |
|
| 318 | - $this->_template_args['current_db_state'] = ''; |
|
| 319 | - $this->_template_args['next_db_state'] = ''; |
|
| 320 | - } |
|
| 321 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
| 322 | - $this->_template_args = array_merge( |
|
| 323 | - $this->_template_args, |
|
| 324 | - [ |
|
| 325 | - 'show_most_recent_migration' => $show_most_recent_migration, |
|
| 326 | - // flag for showing the most recent migration's status and/or errors |
|
| 327 | - 'show_migration_progress' => $show_migration_progress, |
|
| 328 | - // flag for showing the option to run migrations and see their progress |
|
| 329 | - 'show_backup_db_text' => $show_backup_db_text, |
|
| 330 | - // flag for showing text telling the user to back up their DB |
|
| 331 | - 'show_maintenance_switch' => $show_maintenance_switch, |
|
| 332 | - // flag for showing the option to change maintenance mode between levels 0 and 1 |
|
| 333 | - 'script_names' => $script_names, |
|
| 334 | - // array of names of scripts that have run |
|
| 335 | - 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
| 336 | - // flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
| 337 | - 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce( |
|
| 338 | - ['action' => 'reset_db'], |
|
| 339 | - EE_MAINTENANCE_ADMIN_URL |
|
| 340 | - ), |
|
| 341 | - 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce( |
|
| 342 | - ['action' => 'data_reset'], |
|
| 343 | - EE_MAINTENANCE_ADMIN_URL |
|
| 344 | - ), |
|
| 345 | - 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce( |
|
| 346 | - ['action' => 'change_maintenance_level'], |
|
| 347 | - EE_MAINTENANCE_ADMIN_URL |
|
| 348 | - ), |
|
| 349 | - 'ultimate_db_state' => sprintf( |
|
| 350 | - esc_html__("EE%s", 'event_espresso'), |
|
| 351 | - espresso_version() |
|
| 352 | - ), |
|
| 353 | - ] |
|
| 354 | - ); |
|
| 355 | - } |
|
| 356 | - $this->_template_args['most_recent_migration'] = |
|
| 357 | - $most_recent_migration;// the actual most recently ran migration |
|
| 358 | - // now render the migration options part, and put it in a variable |
|
| 359 | - $migration_options_template_file = apply_filters( |
|
| 360 | - 'FHEE__ee_migration_page__migration_options_template', |
|
| 361 | - EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
| 362 | - ); |
|
| 363 | - $migration_options_html = EEH_Template::display_template( |
|
| 364 | - $migration_options_template_file, |
|
| 365 | - $this->_template_args, |
|
| 366 | - true |
|
| 367 | - ); |
|
| 368 | - $this->_template_args['migration_options_html'] = $migration_options_html; |
|
| 369 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 370 | - $this->_template_path, |
|
| 371 | - $this->_template_args, |
|
| 372 | - true |
|
| 373 | - ); |
|
| 374 | - $this->display_admin_page_with_sidebar(); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
| 380 | - * |
|
| 381 | - * @throws EE_Error |
|
| 382 | - */ |
|
| 383 | - public function migration_step() |
|
| 384 | - { |
|
| 385 | - $this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request(); |
|
| 386 | - $this->_return_json(); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Can be used by js when it notices a response with HTML in it in order |
|
| 392 | - * to log the malformed response |
|
| 393 | - * |
|
| 394 | - * @throws EE_Error |
|
| 395 | - */ |
|
| 396 | - public function add_error_to_migrations_ran() |
|
| 397 | - { |
|
| 398 | - $this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']); |
|
| 399 | - $this->_template_args['data'] = ['ok' => true]; |
|
| 400 | - $this->_return_json(); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * changes the maintenance level, provided there are still no migration scripts that should run |
|
| 406 | - * |
|
| 407 | - * @throws EE_Error |
|
| 408 | - */ |
|
| 409 | - public function _change_maintenance_level() |
|
| 410 | - { |
|
| 411 | - $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
| 412 | - if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) { |
|
| 413 | - $this->maintenance_mode->set_maintenance_level($new_level); |
|
| 414 | - $success = true; |
|
| 415 | - } else { |
|
| 416 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 417 | - $success = false; |
|
| 418 | - } |
|
| 419 | - $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * a tab with options for resetting and/or deleting EE data |
|
| 425 | - * |
|
| 426 | - * @throws EE_Error |
|
| 427 | - * @throws DomainException |
|
| 428 | - */ |
|
| 429 | - public function _data_reset_and_delete() |
|
| 430 | - { |
|
| 431 | - $this->_template_path = |
|
| 432 | - EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
| 433 | - $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
| 434 | - 'reset_reservations', |
|
| 435 | - 'reset_reservations', |
|
| 436 | - [], |
|
| 437 | - 'button button--caution ee-confirm' |
|
| 438 | - ); |
|
| 439 | - $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
| 440 | - 'reset_capabilities', |
|
| 441 | - 'reset_capabilities', |
|
| 442 | - [], |
|
| 443 | - 'button button--caution ee-confirm' |
|
| 444 | - ); |
|
| 445 | - $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 446 | - ['action' => 'delete_db'], |
|
| 447 | - EE_MAINTENANCE_ADMIN_URL |
|
| 448 | - ); |
|
| 449 | - $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 450 | - ['action' => 'reset_db'], |
|
| 451 | - EE_MAINTENANCE_ADMIN_URL |
|
| 452 | - ); |
|
| 453 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 454 | - $this->_template_path, |
|
| 455 | - $this->_template_args, |
|
| 456 | - true |
|
| 457 | - ); |
|
| 458 | - $this->display_admin_page_with_no_sidebar(); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * @throws EE_Error |
|
| 464 | - * @throws ReflectionException |
|
| 465 | - */ |
|
| 466 | - protected function _reset_reservations() |
|
| 467 | - { |
|
| 468 | - if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
| 469 | - EE_Error::add_success( |
|
| 470 | - esc_html__( |
|
| 471 | - 'Ticket and datetime reserved counts have been successfully reset.', |
|
| 472 | - 'event_espresso' |
|
| 473 | - ) |
|
| 474 | - ); |
|
| 475 | - } else { |
|
| 476 | - EE_Error::add_success( |
|
| 477 | - esc_html__( |
|
| 478 | - 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
| 479 | - 'event_espresso' |
|
| 480 | - ) |
|
| 481 | - ); |
|
| 482 | - } |
|
| 483 | - $this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @throws EE_Error |
|
| 489 | - */ |
|
| 490 | - protected function _reset_capabilities() |
|
| 491 | - { |
|
| 492 | - $this->capabilities->init_caps(true); |
|
| 493 | - EE_Error::add_success( |
|
| 494 | - esc_html__( |
|
| 495 | - 'Default Event Espresso capabilities have been restored for all current roles.', |
|
| 496 | - 'event_espresso' |
|
| 497 | - ) |
|
| 498 | - ); |
|
| 499 | - $this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * resets the DMSs, so we can attempt to continue migrating after a fatal error |
|
| 505 | - * (only a good idea when someone has somehow tried ot fix whatever caused |
|
| 506 | - * the fatal error in teh first place) |
|
| 507 | - * |
|
| 508 | - * @throws EE_Error |
|
| 509 | - */ |
|
| 510 | - protected function _reattempt_migration() |
|
| 511 | - { |
|
| 512 | - $this->migration_manager->reattempt(); |
|
| 513 | - $this->_redirect_after_action(false, '', '', ['action' => 'default'], true); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * shows the big ol' System Information page |
|
| 519 | - * |
|
| 520 | - * @throws EE_Error |
|
| 521 | - */ |
|
| 522 | - public function _system_status() |
|
| 523 | - { |
|
| 524 | - $this->_template_path = |
|
| 525 | - EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
| 526 | - $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
| 527 | - $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 528 | - [ |
|
| 529 | - 'action' => 'download_system_status', |
|
| 530 | - ], |
|
| 531 | - EE_MAINTENANCE_ADMIN_URL |
|
| 532 | - ); |
|
| 533 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 534 | - $this->_template_path, |
|
| 535 | - $this->_template_args, |
|
| 536 | - true |
|
| 537 | - ); |
|
| 538 | - $this->display_admin_page_with_no_sidebar(); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Downloads an HTML file of the system status that can be easily stored or emailed |
|
| 544 | - */ |
|
| 545 | - public function _download_system_status() |
|
| 546 | - { |
|
| 547 | - $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
| 548 | - header('Content-Disposition: attachment'); |
|
| 549 | - header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html"); |
|
| 550 | - $output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>'; |
|
| 551 | - $output .= '<h1>' . sprintf( |
|
| 552 | - __('System Information for %1$s', 'event_espresso'), |
|
| 553 | - esc_url_raw(site_url()) |
|
| 554 | - ) . '</h1>'; |
|
| 555 | - $output .= EEH_Template::layout_array_as_table($status_info); |
|
| 556 | - echo esc_html($output); |
|
| 557 | - die; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @throws EE_Error |
|
| 563 | - */ |
|
| 564 | - public function _send_migration_crash_report() |
|
| 565 | - { |
|
| 566 | - $from = $this->_req_data['from']; |
|
| 567 | - $from_name = $this->_req_data['from_name']; |
|
| 568 | - $body = $this->_req_data['body']; |
|
| 569 | - try { |
|
| 570 | - $success = wp_mail( |
|
| 571 | - EE_SUPPORT_EMAIL, |
|
| 572 | - 'Migration Crash Report', |
|
| 573 | - $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
| 574 | - [ |
|
| 575 | - "from:$from_name<$from>", |
|
| 576 | - ] |
|
| 577 | - ); |
|
| 578 | - } catch (Exception $e) { |
|
| 579 | - $success = false; |
|
| 580 | - } |
|
| 581 | - $this->_redirect_after_action( |
|
| 582 | - $success, |
|
| 583 | - esc_html__("Migration Crash Report", "event_espresso"), |
|
| 584 | - esc_html__("sent", "event_espresso"), |
|
| 585 | - ['success' => $success, 'action' => 'confirm_migration_crash_report_sent'] |
|
| 586 | - ); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * @throws EE_Error |
|
| 592 | - */ |
|
| 593 | - public function _confirm_migration_crash_report_sent() |
|
| 594 | - { |
|
| 595 | - try { |
|
| 596 | - $most_recent_migration = $this->migration_manager->get_last_ran_script(true); |
|
| 597 | - } catch (EE_Error $e) { |
|
| 598 | - $this->migration_manager->add_error_to_migrations_ran($e->getMessage()); |
|
| 599 | - // now, just so we can display the page correctly, make an error migration script stage object |
|
| 600 | - // and also put the error on it. It only persists for the duration of this request |
|
| 601 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 602 | - $most_recent_migration->add_error($e->getMessage()); |
|
| 603 | - } |
|
| 604 | - $success = $this->_req_data['success'] === '1'; |
|
| 605 | - $this->_template_args['success'] = $success; |
|
| 606 | - $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
| 607 | - $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 608 | - ['action' => 'reset_db'], |
|
| 609 | - EE_MAINTENANCE_ADMIN_URL |
|
| 610 | - ); |
|
| 611 | - $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 612 | - ['action' => 'data_reset'], |
|
| 613 | - EE_MAINTENANCE_ADMIN_URL |
|
| 614 | - ); |
|
| 615 | - $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 616 | - ['action' => 'reattempt_migration'], |
|
| 617 | - EE_MAINTENANCE_ADMIN_URL |
|
| 618 | - ); |
|
| 619 | - $this->_template_path = |
|
| 620 | - EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
| 621 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 622 | - $this->_template_path, |
|
| 623 | - $this->_template_args, |
|
| 624 | - true |
|
| 625 | - ); |
|
| 626 | - $this->display_admin_page_with_sidebar(); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Resets the entire EE4 database. |
|
| 632 | - * only sets up ee4 database for a fresh install- |
|
| 633 | - * doesn't actually clean out the old wp options, or cpts |
|
| 634 | - * (although it does erase old ee table data) |
|
| 635 | - * |
|
| 636 | - * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data, |
|
| 637 | - * or just try initializing ee4 default data |
|
| 638 | - * @throws EE_Error |
|
| 639 | - * @throws ReflectionException |
|
| 640 | - */ |
|
| 641 | - public function _reset_db($nuke_old_ee4_data = true) |
|
| 642 | - { |
|
| 643 | - $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_OFF); |
|
| 644 | - if ($nuke_old_ee4_data) { |
|
| 645 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 646 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 647 | - EEH_Activation::remove_cron_tasks(); |
|
| 648 | - } |
|
| 649 | - // make sure when we reset the registry's config that it |
|
| 650 | - // switches to using the new singleton |
|
| 651 | - EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
| 652 | - EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
| 653 | - EE_System::instance()->redirect_to_about_ee(); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Deletes ALL EE tables, Records, and Options from the database. |
|
| 659 | - * |
|
| 660 | - * @throws EE_Error |
|
| 661 | - * @throws ReflectionException |
|
| 662 | - */ |
|
| 663 | - public function _delete_db() |
|
| 664 | - { |
|
| 665 | - $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_OFF); |
|
| 666 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 667 | - EEH_Activation::delete_all_espresso_tables_and_data(); |
|
| 668 | - EEH_Activation::remove_cron_tasks(); |
|
| 669 | - EEH_Activation::deactivate_event_espresso(); |
|
| 670 | - wp_safe_redirect(admin_url('plugins.php')); |
|
| 671 | - exit; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
| 677 | - * |
|
| 678 | - * @throws EE_Error |
|
| 679 | - * @throws ReflectionException |
|
| 680 | - */ |
|
| 681 | - public function _rerun_migration_from_ee3() |
|
| 682 | - { |
|
| 683 | - $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_OFF); |
|
| 684 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 685 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 686 | - // set the db state to something that will require migrations |
|
| 687 | - update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
| 688 | - $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_FULL_SITE); |
|
| 689 | - $this->_redirect_after_action( |
|
| 690 | - true, |
|
| 691 | - esc_html__("Database", 'event_espresso'), |
|
| 692 | - esc_html__("reset", 'event_espresso') |
|
| 693 | - ); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - // none of the below group are currently used for Gateway Settings |
|
| 698 | - protected function _add_screen_options() |
|
| 699 | - { |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - protected function _add_feature_pointers() |
|
| 704 | - { |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - public function admin_init() |
|
| 709 | - { |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - public function admin_notices() |
|
| 714 | - { |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - public function admin_footer_scripts() |
|
| 719 | - { |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - public function load_scripts_styles() |
|
| 724 | - { |
|
| 725 | - wp_enqueue_script('ee_admin_js'); |
|
| 726 | - wp_enqueue_script( |
|
| 727 | - 'ee-maintenance', |
|
| 728 | - EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js', |
|
| 729 | - ['jquery'], |
|
| 730 | - EVENT_ESPRESSO_VERSION, |
|
| 731 | - true |
|
| 732 | - ); |
|
| 733 | - wp_register_style( |
|
| 734 | - 'espresso_maintenance', |
|
| 735 | - EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', |
|
| 736 | - [], |
|
| 737 | - EVENT_ESPRESSO_VERSION |
|
| 738 | - ); |
|
| 739 | - wp_enqueue_style('espresso_maintenance'); |
|
| 740 | - // localize script stuff |
|
| 741 | - wp_localize_script( |
|
| 742 | - 'ee-maintenance', |
|
| 743 | - 'ee_maintenance', |
|
| 744 | - [ |
|
| 745 | - 'migrating' => wp_strip_all_tags(__("Updating Database...", "event_espresso")), |
|
| 746 | - 'next' => wp_strip_all_tags(__("Next", "event_espresso")), |
|
| 747 | - 'fatal_error' => wp_strip_all_tags( |
|
| 748 | - __( |
|
| 749 | - "A Fatal Error Has Occurred", |
|
| 750 | - "event_espresso" |
|
| 751 | - ) |
|
| 752 | - ), |
|
| 753 | - 'click_next_when_ready' => wp_strip_all_tags( |
|
| 754 | - __( |
|
| 755 | - "The current Database Update has ended. Click 'next' when ready to proceed", |
|
| 756 | - "event_espresso" |
|
| 757 | - ) |
|
| 758 | - ), |
|
| 759 | - 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
| 760 | - 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
| 761 | - 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
| 762 | - 'confirm' => wp_strip_all_tags( |
|
| 763 | - __( |
|
| 764 | - 'Are you sure you want to do this? It CANNOT be undone!', |
|
| 765 | - 'event_espresso' |
|
| 766 | - ) |
|
| 767 | - ), |
|
| 768 | - 'confirm_skip_migration' => wp_strip_all_tags( |
|
| 769 | - __( |
|
| 770 | - 'You have chosen to NOT migrate your existing data. Are you sure you want to continue?', |
|
| 771 | - 'event_espresso' |
|
| 772 | - ) |
|
| 773 | - ), |
|
| 774 | - ] |
|
| 775 | - ); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - public function load_scripts_styles_default() |
|
| 780 | - { |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * Enqueue scripts and styles for the datetime tools page. |
|
| 786 | - */ |
|
| 787 | - public function load_scripts_styles_datetime_tools() |
|
| 788 | - { |
|
| 789 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * @throws EE_Error |
|
| 795 | - */ |
|
| 796 | - protected function _datetime_tools() |
|
| 797 | - { |
|
| 798 | - $form_action = EE_Admin_Page::add_query_args_and_nonce( |
|
| 799 | - [ |
|
| 800 | - 'action' => 'run_datetime_offset_fix', |
|
| 801 | - 'return_action' => $this->_req_action, |
|
| 802 | - ], |
|
| 803 | - EE_MAINTENANCE_ADMIN_URL |
|
| 804 | - ); |
|
| 805 | - $form = $this->_get_datetime_offset_fix_form(); |
|
| 806 | - $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso'); |
|
| 807 | - $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post') |
|
| 808 | - . $form->get_html_and_js() |
|
| 809 | - . $form->form_close(); |
|
| 810 | - $this->display_admin_page_with_sidebar(); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * @throws EE_Error |
|
| 816 | - */ |
|
| 817 | - protected function _get_datetime_offset_fix_form() |
|
| 818 | - { |
|
| 819 | - if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) { |
|
| 820 | - $this->datetime_fix_offset_form = new EE_Form_Section_Proper( |
|
| 821 | - [ |
|
| 822 | - 'name' => 'datetime_offset_fix_option', |
|
| 823 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 824 | - 'subsections' => [ |
|
| 825 | - 'title' => new EE_Form_Section_HTML( |
|
| 826 | - EEH_HTML::h2( |
|
| 827 | - esc_html__('Datetime Offset Tool', 'event_espresso') |
|
| 828 | - ) |
|
| 829 | - ), |
|
| 830 | - 'explanation' => new EE_Form_Section_HTML( |
|
| 831 | - EEH_HTML::p( |
|
| 832 | - esc_html__( |
|
| 833 | - 'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.', |
|
| 834 | - 'event_espresso' |
|
| 835 | - ) |
|
| 836 | - ) |
|
| 837 | - . EEH_HTML::p( |
|
| 838 | - esc_html__( |
|
| 839 | - 'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied. Decimals represent the fraction of hours, not minutes.', |
|
| 840 | - 'event_espresso' |
|
| 841 | - ) |
|
| 842 | - ) |
|
| 843 | - ), |
|
| 844 | - 'offset_input' => new EE_Float_Input( |
|
| 845 | - [ |
|
| 846 | - 'html_name' => 'offset_for_datetimes', |
|
| 847 | - 'html_label_text' => esc_html__( |
|
| 848 | - 'Offset to apply (in hours):', |
|
| 849 | - 'event_espresso' |
|
| 850 | - ), |
|
| 851 | - 'min_value' => '-12', |
|
| 852 | - 'max_value' => '14', |
|
| 853 | - 'step_value' => '.25', |
|
| 854 | - 'default' => DatetimeOffsetFix::getOffset(), |
|
| 855 | - ] |
|
| 856 | - ), |
|
| 857 | - 'date_range_explanation' => new EE_Form_Section_HTML( |
|
| 858 | - EEH_HTML::p( |
|
| 859 | - esc_html__( |
|
| 860 | - 'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.', |
|
| 861 | - 'event_espresso' |
|
| 862 | - ) |
|
| 863 | - ) |
|
| 864 | - . EEH_HTML::p( |
|
| 865 | - EEH_HTML::strong( |
|
| 866 | - sprintf( |
|
| 867 | - esc_html__( |
|
| 868 | - 'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).', |
|
| 869 | - 'event_espresso' |
|
| 870 | - ), |
|
| 871 | - '<a href="https://www.timeanddate.com/worldclock/converter.html">', |
|
| 872 | - '</a>' |
|
| 873 | - ) |
|
| 874 | - ) |
|
| 875 | - ) |
|
| 876 | - ), |
|
| 877 | - 'date_range_start_date' => new EE_Datepicker_Input( |
|
| 878 | - [ |
|
| 879 | - 'html_name' => 'offset_date_start_range', |
|
| 880 | - 'html_label_text' => esc_html__( |
|
| 881 | - 'Start Date for dates the offset applied to:', |
|
| 882 | - 'event_espresso' |
|
| 883 | - ), |
|
| 884 | - ] |
|
| 885 | - ), |
|
| 886 | - 'date_range_end_date' => new EE_Datepicker_Input( |
|
| 887 | - [ |
|
| 888 | - 'html_name' => 'offset_date_end_range', |
|
| 889 | - 'html_label_text' => esc_html__( |
|
| 890 | - 'End Date for dates the offset is applied to:', |
|
| 891 | - 'event_espresso' |
|
| 892 | - ), |
|
| 893 | - ] |
|
| 894 | - ), |
|
| 895 | - 'submit' => new EE_Submit_Input( |
|
| 896 | - [ |
|
| 897 | - 'html_label_text' => '', |
|
| 898 | - 'default' => esc_html__('Apply Offset', 'event_espresso'), |
|
| 899 | - ] |
|
| 900 | - ), |
|
| 901 | - ], |
|
| 902 | - ] |
|
| 903 | - ); |
|
| 904 | - } |
|
| 905 | - return $this->datetime_fix_offset_form; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Callback for the run_datetime_offset_fix route. |
|
| 911 | - * |
|
| 912 | - * @throws EE_Error |
|
| 913 | - */ |
|
| 914 | - protected function _apply_datetime_offset() |
|
| 915 | - { |
|
| 916 | - if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 917 | - $form = $this->_get_datetime_offset_fix_form(); |
|
| 918 | - $form->receive_form_submission($this->_req_data); |
|
| 919 | - if ($form->is_valid()) { |
|
| 920 | - // save offset data so batch processor can get it. |
|
| 921 | - DatetimeOffsetFix::updateOffset((float) $form->get_input_value('offset_input')); |
|
| 922 | - $utc_timezone = new DateTimeZone('UTC'); |
|
| 923 | - $date_range_start_date = DateTime::createFromFormat( |
|
| 924 | - 'm/d/Y H:i:s', |
|
| 925 | - $form->get_input_value('date_range_start_date') . ' 00:00:00', |
|
| 926 | - $utc_timezone |
|
| 927 | - ); |
|
| 928 | - $date_range_end_date = DateTime::createFromFormat( |
|
| 929 | - 'm/d/Y H:i:s', |
|
| 930 | - $form->get_input_value('date_range_end_date') . ' 23:59:59', |
|
| 931 | - $utc_timezone |
|
| 932 | - ); |
|
| 933 | - if ($date_range_start_date instanceof DateTime) { |
|
| 934 | - DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date)); |
|
| 935 | - } |
|
| 936 | - if ($date_range_end_date instanceof DateTime) { |
|
| 937 | - DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date)); |
|
| 938 | - } |
|
| 939 | - // redirect to batch tool |
|
| 940 | - wp_redirect( |
|
| 941 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 942 | - [ |
|
| 943 | - 'page' => EED_Batch::PAGE_SLUG, |
|
| 944 | - 'batch' => EED_Batch::batch_job, |
|
| 945 | - 'label' => esc_html__('Applying Offset', 'event_espresso'), |
|
| 946 | - 'job_handler' => urlencode('EventEspresso\core\libraries\batch\JobHandlers\DatetimeOffsetFix'), |
|
| 947 | - 'return_url' => urlencode( |
|
| 948 | - add_query_arg( |
|
| 949 | - [ |
|
| 950 | - 'action' => 'datetime_tools', |
|
| 951 | - ], |
|
| 952 | - EEH_URL::current_url_without_query_paramaters( |
|
| 953 | - [ |
|
| 954 | - 'return_action', |
|
| 955 | - 'run_datetime_offset_fix_nonce', |
|
| 956 | - 'return', |
|
| 957 | - 'datetime_tools_nonce', |
|
| 958 | - ] |
|
| 959 | - ) |
|
| 960 | - ) |
|
| 961 | - ), |
|
| 962 | - ], |
|
| 963 | - admin_url() |
|
| 964 | - ) |
|
| 965 | - ); |
|
| 966 | - exit; |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - } |
|
| 18 | + /** |
|
| 19 | + * @var EE_Data_Migration_Manager |
|
| 20 | + */ |
|
| 21 | + protected $migration_manager; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var EE_Maintenance_Mode |
|
| 25 | + */ |
|
| 26 | + protected $maintenance_mode; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var EE_Form_Section_Proper |
|
| 30 | + */ |
|
| 31 | + protected $datetime_fix_offset_form; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @param bool $routing |
|
| 36 | + * @throws EE_Error |
|
| 37 | + * @throws ReflectionException |
|
| 38 | + */ |
|
| 39 | + public function __construct($routing = true) |
|
| 40 | + { |
|
| 41 | + $this->migration_manager = EE_Data_Migration_Manager::instance(); |
|
| 42 | + $this->maintenance_mode = EE_Maintenance_Mode::instance(); |
|
| 43 | + parent::__construct($routing); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + protected function _init_page_props() |
|
| 48 | + { |
|
| 49 | + $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
| 50 | + $this->page_label = EE_MAINTENANCE_LABEL; |
|
| 51 | + $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
| 52 | + $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + protected function _ajax_hooks() |
|
| 57 | + { |
|
| 58 | + add_action('wp_ajax_migration_step', [$this, 'migration_step']); |
|
| 59 | + add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + protected function _define_page_props() |
|
| 64 | + { |
|
| 65 | + $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
| 66 | + $this->_labels = [ |
|
| 67 | + 'buttons' => [ |
|
| 68 | + 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
| 69 | + 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
| 70 | + ], |
|
| 71 | + ]; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + protected function _set_page_routes() |
|
| 76 | + { |
|
| 77 | + $this->_page_routes = [ |
|
| 78 | + 'default' => [ |
|
| 79 | + 'func' => [$this, '_maintenance'], |
|
| 80 | + 'capability' => 'manage_options', |
|
| 81 | + ], |
|
| 82 | + 'change_maintenance_level' => [ |
|
| 83 | + 'func' => [$this, '_change_maintenance_level'], |
|
| 84 | + 'capability' => 'manage_options', |
|
| 85 | + 'noheader' => true, |
|
| 86 | + ], |
|
| 87 | + 'system_status' => [ |
|
| 88 | + 'func' => [$this, '_system_status'], |
|
| 89 | + 'capability' => 'manage_options', |
|
| 90 | + ], |
|
| 91 | + 'download_system_status' => [ |
|
| 92 | + 'func' => [$this, '_download_system_status'], |
|
| 93 | + 'capability' => 'manage_options', |
|
| 94 | + 'noheader' => true, |
|
| 95 | + ], |
|
| 96 | + 'send_migration_crash_report' => [ |
|
| 97 | + 'func' => [$this, '_send_migration_crash_report'], |
|
| 98 | + 'capability' => 'manage_options', |
|
| 99 | + 'noheader' => true, |
|
| 100 | + ], |
|
| 101 | + 'confirm_migration_crash_report_sent' => [ |
|
| 102 | + 'func' => [$this, '_confirm_migration_crash_report_sent'], |
|
| 103 | + 'capability' => 'manage_options', |
|
| 104 | + ], |
|
| 105 | + 'data_reset' => [ |
|
| 106 | + 'func' => [$this, '_data_reset_and_delete'], |
|
| 107 | + 'capability' => 'manage_options', |
|
| 108 | + ], |
|
| 109 | + 'reset_db' => [ |
|
| 110 | + 'func' => [$this, '_reset_db'], |
|
| 111 | + 'capability' => 'manage_options', |
|
| 112 | + 'noheader' => true, |
|
| 113 | + 'args' => ['nuke_old_ee4_data' => true], |
|
| 114 | + ], |
|
| 115 | + 'start_with_fresh_ee4_db' => [ |
|
| 116 | + 'func' => [$this, '_reset_db'], |
|
| 117 | + 'capability' => 'manage_options', |
|
| 118 | + 'noheader' => true, |
|
| 119 | + 'args' => ['nuke_old_ee4_data' => false], |
|
| 120 | + ], |
|
| 121 | + 'delete_db' => [ |
|
| 122 | + 'func' => [$this, '_delete_db'], |
|
| 123 | + 'capability' => 'manage_options', |
|
| 124 | + 'noheader' => true, |
|
| 125 | + ], |
|
| 126 | + 'rerun_migration_from_ee3' => [ |
|
| 127 | + 'func' => [$this, '_rerun_migration_from_ee3'], |
|
| 128 | + 'capability' => 'manage_options', |
|
| 129 | + 'noheader' => true, |
|
| 130 | + ], |
|
| 131 | + 'reset_reservations' => [ |
|
| 132 | + 'func' => [$this, '_reset_reservations'], |
|
| 133 | + 'capability' => 'manage_options', |
|
| 134 | + 'noheader' => true, |
|
| 135 | + ], |
|
| 136 | + 'reset_capabilities' => [ |
|
| 137 | + 'func' => [$this, '_reset_capabilities'], |
|
| 138 | + 'capability' => 'manage_options', |
|
| 139 | + 'noheader' => true, |
|
| 140 | + ], |
|
| 141 | + 'reattempt_migration' => [ |
|
| 142 | + 'func' => [$this, '_reattempt_migration'], |
|
| 143 | + 'capability' => 'manage_options', |
|
| 144 | + 'noheader' => true, |
|
| 145 | + ], |
|
| 146 | + 'datetime_tools' => [ |
|
| 147 | + 'func' => [$this, '_datetime_tools'], |
|
| 148 | + 'capability' => 'manage_options', |
|
| 149 | + ], |
|
| 150 | + 'run_datetime_offset_fix' => [ |
|
| 151 | + 'func' => [$this, '_apply_datetime_offset'], |
|
| 152 | + 'noheader' => true, |
|
| 153 | + 'headers_sent_route' => 'datetime_tools', |
|
| 154 | + 'capability' => 'manage_options', |
|
| 155 | + ], |
|
| 156 | + ]; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + protected function _set_page_config() |
|
| 161 | + { |
|
| 162 | + $this->_page_config = [ |
|
| 163 | + 'default' => [ |
|
| 164 | + 'nav' => [ |
|
| 165 | + 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
| 166 | + 'icon' => 'dashicons-admin-tools', |
|
| 167 | + 'order' => 10, |
|
| 168 | + ], |
|
| 169 | + 'require_nonce' => false, |
|
| 170 | + ], |
|
| 171 | + 'data_reset' => [ |
|
| 172 | + 'nav' => [ |
|
| 173 | + 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
| 174 | + 'icon' => 'dashicons-trash', |
|
| 175 | + 'order' => 20, |
|
| 176 | + ], |
|
| 177 | + 'require_nonce' => false, |
|
| 178 | + ], |
|
| 179 | + 'datetime_tools' => [ |
|
| 180 | + 'nav' => [ |
|
| 181 | + 'label' => esc_html__('Datetime Utilities', 'event_espresso'), |
|
| 182 | + 'icon' => 'dashicons-calendar-alt', |
|
| 183 | + 'order' => 25, |
|
| 184 | + ], |
|
| 185 | + 'require_nonce' => false, |
|
| 186 | + ], |
|
| 187 | + 'system_status' => [ |
|
| 188 | + 'nav' => [ |
|
| 189 | + 'label' => esc_html__("System Information", "event_espresso"), |
|
| 190 | + 'icon' => 'dashicons-info', |
|
| 191 | + 'order' => 30, |
|
| 192 | + ], |
|
| 193 | + 'require_nonce' => false, |
|
| 194 | + ], |
|
| 195 | + ]; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * default maintenance page. |
|
| 201 | + * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI. |
|
| 202 | + * |
|
| 203 | + * @throws EE_Error |
|
| 204 | + */ |
|
| 205 | + public function _maintenance() |
|
| 206 | + { |
|
| 207 | + $show_maintenance_switch = true; |
|
| 208 | + $show_backup_db_text = false; |
|
| 209 | + $show_migration_progress = false; |
|
| 210 | + $script_names = []; |
|
| 211 | + $addons_should_be_upgraded_first = false; |
|
| 212 | + // it all depends on if we're in maintenance model level 1 (frontend-only) or |
|
| 213 | + // level 2 (everything except maintenance page) |
|
| 214 | + try { |
|
| 215 | + // get the current maintenance level and check if we are removed |
|
| 216 | + $was_full_site_maintenence_mode = MaintenanceStatus::isFullSite(); |
|
| 217 | + $no_longer_in_maintenence_mode = ! $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 218 | + if ($was_full_site_maintenence_mode && $no_longer_in_maintenence_mode) { |
|
| 219 | + // we just took the site out of maintenance mode, so notify the user. |
|
| 220 | + // unfortunately this message appears to be echoed on the NEXT page load... |
|
| 221 | + // oh well, we should really be checking for this on addon deactivation anyways |
|
| 222 | + EE_Error::add_attention( |
|
| 223 | + esc_html__( |
|
| 224 | + 'Site taken out of maintenance mode because no data migration scripts are required', |
|
| 225 | + 'event_espresso' |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + $this->_process_notices(['page' => 'espresso_maintenance_settings']); |
|
| 229 | + } |
|
| 230 | + // in case an exception is thrown while trying to handle migrations |
|
| 231 | + if (MaintenanceStatus::isFullSite()) { |
|
| 232 | + $show_maintenance_switch = false; |
|
| 233 | + $show_migration_progress = true; |
|
| 234 | + if (! isset($this->_req_data['continue_migration'])) { |
|
| 235 | + $show_backup_db_text = true; |
|
| 236 | + } |
|
| 237 | + $scripts_needing_to_run = |
|
| 238 | + $this->migration_manager->check_for_applicable_data_migration_scripts(); |
|
| 239 | + $addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating(); |
|
| 240 | + $script_names = []; |
|
| 241 | + $current_script = null; |
|
| 242 | + foreach ($scripts_needing_to_run as $script) { |
|
| 243 | + if ($script instanceof EE_Data_Migration_Script_Base) { |
|
| 244 | + if (! $current_script) { |
|
| 245 | + $current_script = $script; |
|
| 246 | + $current_script->migration_page_hooks(); |
|
| 247 | + } |
|
| 248 | + $script_names[] = $script->pretty_name(); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + $most_recent_migration = $this->migration_manager->get_last_ran_script(true); |
|
| 253 | + $exception_thrown = false; |
|
| 254 | + } catch (EE_Error $e) { |
|
| 255 | + $this->migration_manager->add_error_to_migrations_ran($e->getMessage()); |
|
| 256 | + // now, just so we can display the page correctly, make an error migration script stage object |
|
| 257 | + // and also put the error on it. It only persists for the duration of this request |
|
| 258 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 259 | + $most_recent_migration->add_error($e->getMessage()); |
|
| 260 | + $exception_thrown = true; |
|
| 261 | + } |
|
| 262 | + $current_db_state = $this->migration_manager->ensure_current_database_state_is_set(); |
|
| 263 | + $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
| 264 | + if ( |
|
| 265 | + $exception_thrown |
|
| 266 | + || ( |
|
| 267 | + $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 268 | + && $most_recent_migration->is_broken() |
|
| 269 | + ) |
|
| 270 | + ) { |
|
| 271 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
| 272 | + |
|
| 273 | + $this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/'; |
|
| 274 | + $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce( |
|
| 275 | + [ |
|
| 276 | + 'action' => 'confirm_migration_crash_report_sent', |
|
| 277 | + 'success' => '0', |
|
| 278 | + ], |
|
| 279 | + EE_MAINTENANCE_ADMIN_URL |
|
| 280 | + ); |
|
| 281 | + } elseif ($addons_should_be_upgraded_first) { |
|
| 282 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
| 283 | + } else { |
|
| 284 | + if ( |
|
| 285 | + $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 286 | + && $most_recent_migration->can_continue() |
|
| 287 | + ) { |
|
| 288 | + $show_backup_db_text = false; |
|
| 289 | + $show_continue_current_migration_script = true; |
|
| 290 | + $show_most_recent_migration = true; |
|
| 291 | + } elseif (isset($this->_req_data['continue_migration'])) { |
|
| 292 | + $show_most_recent_migration = true; |
|
| 293 | + $show_continue_current_migration_script = false; |
|
| 294 | + } else { |
|
| 295 | + $show_most_recent_migration = false; |
|
| 296 | + $show_continue_current_migration_script = false; |
|
| 297 | + } |
|
| 298 | + if (isset($current_script)) { |
|
| 299 | + $migrates_to = $current_script->migrates_to_version(); |
|
| 300 | + $plugin_slug = $migrates_to['slug']; |
|
| 301 | + $new_version = $migrates_to['version']; |
|
| 302 | + $this->_template_args = array_merge( |
|
| 303 | + $this->_template_args, |
|
| 304 | + [ |
|
| 305 | + 'current_db_state' => sprintf( |
|
| 306 | + esc_html__("EE%s (%s)", "event_espresso"), |
|
| 307 | + $current_db_state[ $plugin_slug ] ?? 3, |
|
| 308 | + $plugin_slug |
|
| 309 | + ), |
|
| 310 | + 'next_db_state' => sprintf( |
|
| 311 | + esc_html__("EE%s (%s)", 'event_espresso'), |
|
| 312 | + $new_version, |
|
| 313 | + $plugin_slug |
|
| 314 | + ), |
|
| 315 | + ] |
|
| 316 | + ); |
|
| 317 | + } else { |
|
| 318 | + $this->_template_args['current_db_state'] = ''; |
|
| 319 | + $this->_template_args['next_db_state'] = ''; |
|
| 320 | + } |
|
| 321 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
| 322 | + $this->_template_args = array_merge( |
|
| 323 | + $this->_template_args, |
|
| 324 | + [ |
|
| 325 | + 'show_most_recent_migration' => $show_most_recent_migration, |
|
| 326 | + // flag for showing the most recent migration's status and/or errors |
|
| 327 | + 'show_migration_progress' => $show_migration_progress, |
|
| 328 | + // flag for showing the option to run migrations and see their progress |
|
| 329 | + 'show_backup_db_text' => $show_backup_db_text, |
|
| 330 | + // flag for showing text telling the user to back up their DB |
|
| 331 | + 'show_maintenance_switch' => $show_maintenance_switch, |
|
| 332 | + // flag for showing the option to change maintenance mode between levels 0 and 1 |
|
| 333 | + 'script_names' => $script_names, |
|
| 334 | + // array of names of scripts that have run |
|
| 335 | + 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
| 336 | + // flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
| 337 | + 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce( |
|
| 338 | + ['action' => 'reset_db'], |
|
| 339 | + EE_MAINTENANCE_ADMIN_URL |
|
| 340 | + ), |
|
| 341 | + 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce( |
|
| 342 | + ['action' => 'data_reset'], |
|
| 343 | + EE_MAINTENANCE_ADMIN_URL |
|
| 344 | + ), |
|
| 345 | + 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce( |
|
| 346 | + ['action' => 'change_maintenance_level'], |
|
| 347 | + EE_MAINTENANCE_ADMIN_URL |
|
| 348 | + ), |
|
| 349 | + 'ultimate_db_state' => sprintf( |
|
| 350 | + esc_html__("EE%s", 'event_espresso'), |
|
| 351 | + espresso_version() |
|
| 352 | + ), |
|
| 353 | + ] |
|
| 354 | + ); |
|
| 355 | + } |
|
| 356 | + $this->_template_args['most_recent_migration'] = |
|
| 357 | + $most_recent_migration;// the actual most recently ran migration |
|
| 358 | + // now render the migration options part, and put it in a variable |
|
| 359 | + $migration_options_template_file = apply_filters( |
|
| 360 | + 'FHEE__ee_migration_page__migration_options_template', |
|
| 361 | + EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
| 362 | + ); |
|
| 363 | + $migration_options_html = EEH_Template::display_template( |
|
| 364 | + $migration_options_template_file, |
|
| 365 | + $this->_template_args, |
|
| 366 | + true |
|
| 367 | + ); |
|
| 368 | + $this->_template_args['migration_options_html'] = $migration_options_html; |
|
| 369 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 370 | + $this->_template_path, |
|
| 371 | + $this->_template_args, |
|
| 372 | + true |
|
| 373 | + ); |
|
| 374 | + $this->display_admin_page_with_sidebar(); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
| 380 | + * |
|
| 381 | + * @throws EE_Error |
|
| 382 | + */ |
|
| 383 | + public function migration_step() |
|
| 384 | + { |
|
| 385 | + $this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request(); |
|
| 386 | + $this->_return_json(); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Can be used by js when it notices a response with HTML in it in order |
|
| 392 | + * to log the malformed response |
|
| 393 | + * |
|
| 394 | + * @throws EE_Error |
|
| 395 | + */ |
|
| 396 | + public function add_error_to_migrations_ran() |
|
| 397 | + { |
|
| 398 | + $this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']); |
|
| 399 | + $this->_template_args['data'] = ['ok' => true]; |
|
| 400 | + $this->_return_json(); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * changes the maintenance level, provided there are still no migration scripts that should run |
|
| 406 | + * |
|
| 407 | + * @throws EE_Error |
|
| 408 | + */ |
|
| 409 | + public function _change_maintenance_level() |
|
| 410 | + { |
|
| 411 | + $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
| 412 | + if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) { |
|
| 413 | + $this->maintenance_mode->set_maintenance_level($new_level); |
|
| 414 | + $success = true; |
|
| 415 | + } else { |
|
| 416 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 417 | + $success = false; |
|
| 418 | + } |
|
| 419 | + $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * a tab with options for resetting and/or deleting EE data |
|
| 425 | + * |
|
| 426 | + * @throws EE_Error |
|
| 427 | + * @throws DomainException |
|
| 428 | + */ |
|
| 429 | + public function _data_reset_and_delete() |
|
| 430 | + { |
|
| 431 | + $this->_template_path = |
|
| 432 | + EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
| 433 | + $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
| 434 | + 'reset_reservations', |
|
| 435 | + 'reset_reservations', |
|
| 436 | + [], |
|
| 437 | + 'button button--caution ee-confirm' |
|
| 438 | + ); |
|
| 439 | + $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
| 440 | + 'reset_capabilities', |
|
| 441 | + 'reset_capabilities', |
|
| 442 | + [], |
|
| 443 | + 'button button--caution ee-confirm' |
|
| 444 | + ); |
|
| 445 | + $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 446 | + ['action' => 'delete_db'], |
|
| 447 | + EE_MAINTENANCE_ADMIN_URL |
|
| 448 | + ); |
|
| 449 | + $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 450 | + ['action' => 'reset_db'], |
|
| 451 | + EE_MAINTENANCE_ADMIN_URL |
|
| 452 | + ); |
|
| 453 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 454 | + $this->_template_path, |
|
| 455 | + $this->_template_args, |
|
| 456 | + true |
|
| 457 | + ); |
|
| 458 | + $this->display_admin_page_with_no_sidebar(); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * @throws EE_Error |
|
| 464 | + * @throws ReflectionException |
|
| 465 | + */ |
|
| 466 | + protected function _reset_reservations() |
|
| 467 | + { |
|
| 468 | + if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
| 469 | + EE_Error::add_success( |
|
| 470 | + esc_html__( |
|
| 471 | + 'Ticket and datetime reserved counts have been successfully reset.', |
|
| 472 | + 'event_espresso' |
|
| 473 | + ) |
|
| 474 | + ); |
|
| 475 | + } else { |
|
| 476 | + EE_Error::add_success( |
|
| 477 | + esc_html__( |
|
| 478 | + 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
| 479 | + 'event_espresso' |
|
| 480 | + ) |
|
| 481 | + ); |
|
| 482 | + } |
|
| 483 | + $this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @throws EE_Error |
|
| 489 | + */ |
|
| 490 | + protected function _reset_capabilities() |
|
| 491 | + { |
|
| 492 | + $this->capabilities->init_caps(true); |
|
| 493 | + EE_Error::add_success( |
|
| 494 | + esc_html__( |
|
| 495 | + 'Default Event Espresso capabilities have been restored for all current roles.', |
|
| 496 | + 'event_espresso' |
|
| 497 | + ) |
|
| 498 | + ); |
|
| 499 | + $this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * resets the DMSs, so we can attempt to continue migrating after a fatal error |
|
| 505 | + * (only a good idea when someone has somehow tried ot fix whatever caused |
|
| 506 | + * the fatal error in teh first place) |
|
| 507 | + * |
|
| 508 | + * @throws EE_Error |
|
| 509 | + */ |
|
| 510 | + protected function _reattempt_migration() |
|
| 511 | + { |
|
| 512 | + $this->migration_manager->reattempt(); |
|
| 513 | + $this->_redirect_after_action(false, '', '', ['action' => 'default'], true); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * shows the big ol' System Information page |
|
| 519 | + * |
|
| 520 | + * @throws EE_Error |
|
| 521 | + */ |
|
| 522 | + public function _system_status() |
|
| 523 | + { |
|
| 524 | + $this->_template_path = |
|
| 525 | + EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
| 526 | + $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
| 527 | + $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 528 | + [ |
|
| 529 | + 'action' => 'download_system_status', |
|
| 530 | + ], |
|
| 531 | + EE_MAINTENANCE_ADMIN_URL |
|
| 532 | + ); |
|
| 533 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 534 | + $this->_template_path, |
|
| 535 | + $this->_template_args, |
|
| 536 | + true |
|
| 537 | + ); |
|
| 538 | + $this->display_admin_page_with_no_sidebar(); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Downloads an HTML file of the system status that can be easily stored or emailed |
|
| 544 | + */ |
|
| 545 | + public function _download_system_status() |
|
| 546 | + { |
|
| 547 | + $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
| 548 | + header('Content-Disposition: attachment'); |
|
| 549 | + header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html"); |
|
| 550 | + $output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>'; |
|
| 551 | + $output .= '<h1>' . sprintf( |
|
| 552 | + __('System Information for %1$s', 'event_espresso'), |
|
| 553 | + esc_url_raw(site_url()) |
|
| 554 | + ) . '</h1>'; |
|
| 555 | + $output .= EEH_Template::layout_array_as_table($status_info); |
|
| 556 | + echo esc_html($output); |
|
| 557 | + die; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @throws EE_Error |
|
| 563 | + */ |
|
| 564 | + public function _send_migration_crash_report() |
|
| 565 | + { |
|
| 566 | + $from = $this->_req_data['from']; |
|
| 567 | + $from_name = $this->_req_data['from_name']; |
|
| 568 | + $body = $this->_req_data['body']; |
|
| 569 | + try { |
|
| 570 | + $success = wp_mail( |
|
| 571 | + EE_SUPPORT_EMAIL, |
|
| 572 | + 'Migration Crash Report', |
|
| 573 | + $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
| 574 | + [ |
|
| 575 | + "from:$from_name<$from>", |
|
| 576 | + ] |
|
| 577 | + ); |
|
| 578 | + } catch (Exception $e) { |
|
| 579 | + $success = false; |
|
| 580 | + } |
|
| 581 | + $this->_redirect_after_action( |
|
| 582 | + $success, |
|
| 583 | + esc_html__("Migration Crash Report", "event_espresso"), |
|
| 584 | + esc_html__("sent", "event_espresso"), |
|
| 585 | + ['success' => $success, 'action' => 'confirm_migration_crash_report_sent'] |
|
| 586 | + ); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * @throws EE_Error |
|
| 592 | + */ |
|
| 593 | + public function _confirm_migration_crash_report_sent() |
|
| 594 | + { |
|
| 595 | + try { |
|
| 596 | + $most_recent_migration = $this->migration_manager->get_last_ran_script(true); |
|
| 597 | + } catch (EE_Error $e) { |
|
| 598 | + $this->migration_manager->add_error_to_migrations_ran($e->getMessage()); |
|
| 599 | + // now, just so we can display the page correctly, make an error migration script stage object |
|
| 600 | + // and also put the error on it. It only persists for the duration of this request |
|
| 601 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 602 | + $most_recent_migration->add_error($e->getMessage()); |
|
| 603 | + } |
|
| 604 | + $success = $this->_req_data['success'] === '1'; |
|
| 605 | + $this->_template_args['success'] = $success; |
|
| 606 | + $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
| 607 | + $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 608 | + ['action' => 'reset_db'], |
|
| 609 | + EE_MAINTENANCE_ADMIN_URL |
|
| 610 | + ); |
|
| 611 | + $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 612 | + ['action' => 'data_reset'], |
|
| 613 | + EE_MAINTENANCE_ADMIN_URL |
|
| 614 | + ); |
|
| 615 | + $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 616 | + ['action' => 'reattempt_migration'], |
|
| 617 | + EE_MAINTENANCE_ADMIN_URL |
|
| 618 | + ); |
|
| 619 | + $this->_template_path = |
|
| 620 | + EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
| 621 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 622 | + $this->_template_path, |
|
| 623 | + $this->_template_args, |
|
| 624 | + true |
|
| 625 | + ); |
|
| 626 | + $this->display_admin_page_with_sidebar(); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Resets the entire EE4 database. |
|
| 632 | + * only sets up ee4 database for a fresh install- |
|
| 633 | + * doesn't actually clean out the old wp options, or cpts |
|
| 634 | + * (although it does erase old ee table data) |
|
| 635 | + * |
|
| 636 | + * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data, |
|
| 637 | + * or just try initializing ee4 default data |
|
| 638 | + * @throws EE_Error |
|
| 639 | + * @throws ReflectionException |
|
| 640 | + */ |
|
| 641 | + public function _reset_db($nuke_old_ee4_data = true) |
|
| 642 | + { |
|
| 643 | + $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_OFF); |
|
| 644 | + if ($nuke_old_ee4_data) { |
|
| 645 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 646 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 647 | + EEH_Activation::remove_cron_tasks(); |
|
| 648 | + } |
|
| 649 | + // make sure when we reset the registry's config that it |
|
| 650 | + // switches to using the new singleton |
|
| 651 | + EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
| 652 | + EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
| 653 | + EE_System::instance()->redirect_to_about_ee(); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Deletes ALL EE tables, Records, and Options from the database. |
|
| 659 | + * |
|
| 660 | + * @throws EE_Error |
|
| 661 | + * @throws ReflectionException |
|
| 662 | + */ |
|
| 663 | + public function _delete_db() |
|
| 664 | + { |
|
| 665 | + $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_OFF); |
|
| 666 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 667 | + EEH_Activation::delete_all_espresso_tables_and_data(); |
|
| 668 | + EEH_Activation::remove_cron_tasks(); |
|
| 669 | + EEH_Activation::deactivate_event_espresso(); |
|
| 670 | + wp_safe_redirect(admin_url('plugins.php')); |
|
| 671 | + exit; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
| 677 | + * |
|
| 678 | + * @throws EE_Error |
|
| 679 | + * @throws ReflectionException |
|
| 680 | + */ |
|
| 681 | + public function _rerun_migration_from_ee3() |
|
| 682 | + { |
|
| 683 | + $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_OFF); |
|
| 684 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 685 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 686 | + // set the db state to something that will require migrations |
|
| 687 | + update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
| 688 | + $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::STATUS_FULL_SITE); |
|
| 689 | + $this->_redirect_after_action( |
|
| 690 | + true, |
|
| 691 | + esc_html__("Database", 'event_espresso'), |
|
| 692 | + esc_html__("reset", 'event_espresso') |
|
| 693 | + ); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + // none of the below group are currently used for Gateway Settings |
|
| 698 | + protected function _add_screen_options() |
|
| 699 | + { |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + protected function _add_feature_pointers() |
|
| 704 | + { |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + public function admin_init() |
|
| 709 | + { |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + public function admin_notices() |
|
| 714 | + { |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + public function admin_footer_scripts() |
|
| 719 | + { |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + public function load_scripts_styles() |
|
| 724 | + { |
|
| 725 | + wp_enqueue_script('ee_admin_js'); |
|
| 726 | + wp_enqueue_script( |
|
| 727 | + 'ee-maintenance', |
|
| 728 | + EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js', |
|
| 729 | + ['jquery'], |
|
| 730 | + EVENT_ESPRESSO_VERSION, |
|
| 731 | + true |
|
| 732 | + ); |
|
| 733 | + wp_register_style( |
|
| 734 | + 'espresso_maintenance', |
|
| 735 | + EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', |
|
| 736 | + [], |
|
| 737 | + EVENT_ESPRESSO_VERSION |
|
| 738 | + ); |
|
| 739 | + wp_enqueue_style('espresso_maintenance'); |
|
| 740 | + // localize script stuff |
|
| 741 | + wp_localize_script( |
|
| 742 | + 'ee-maintenance', |
|
| 743 | + 'ee_maintenance', |
|
| 744 | + [ |
|
| 745 | + 'migrating' => wp_strip_all_tags(__("Updating Database...", "event_espresso")), |
|
| 746 | + 'next' => wp_strip_all_tags(__("Next", "event_espresso")), |
|
| 747 | + 'fatal_error' => wp_strip_all_tags( |
|
| 748 | + __( |
|
| 749 | + "A Fatal Error Has Occurred", |
|
| 750 | + "event_espresso" |
|
| 751 | + ) |
|
| 752 | + ), |
|
| 753 | + 'click_next_when_ready' => wp_strip_all_tags( |
|
| 754 | + __( |
|
| 755 | + "The current Database Update has ended. Click 'next' when ready to proceed", |
|
| 756 | + "event_espresso" |
|
| 757 | + ) |
|
| 758 | + ), |
|
| 759 | + 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
| 760 | + 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
| 761 | + 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
| 762 | + 'confirm' => wp_strip_all_tags( |
|
| 763 | + __( |
|
| 764 | + 'Are you sure you want to do this? It CANNOT be undone!', |
|
| 765 | + 'event_espresso' |
|
| 766 | + ) |
|
| 767 | + ), |
|
| 768 | + 'confirm_skip_migration' => wp_strip_all_tags( |
|
| 769 | + __( |
|
| 770 | + 'You have chosen to NOT migrate your existing data. Are you sure you want to continue?', |
|
| 771 | + 'event_espresso' |
|
| 772 | + ) |
|
| 773 | + ), |
|
| 774 | + ] |
|
| 775 | + ); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + public function load_scripts_styles_default() |
|
| 780 | + { |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + |
|
| 784 | + /** |
|
| 785 | + * Enqueue scripts and styles for the datetime tools page. |
|
| 786 | + */ |
|
| 787 | + public function load_scripts_styles_datetime_tools() |
|
| 788 | + { |
|
| 789 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * @throws EE_Error |
|
| 795 | + */ |
|
| 796 | + protected function _datetime_tools() |
|
| 797 | + { |
|
| 798 | + $form_action = EE_Admin_Page::add_query_args_and_nonce( |
|
| 799 | + [ |
|
| 800 | + 'action' => 'run_datetime_offset_fix', |
|
| 801 | + 'return_action' => $this->_req_action, |
|
| 802 | + ], |
|
| 803 | + EE_MAINTENANCE_ADMIN_URL |
|
| 804 | + ); |
|
| 805 | + $form = $this->_get_datetime_offset_fix_form(); |
|
| 806 | + $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso'); |
|
| 807 | + $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post') |
|
| 808 | + . $form->get_html_and_js() |
|
| 809 | + . $form->form_close(); |
|
| 810 | + $this->display_admin_page_with_sidebar(); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * @throws EE_Error |
|
| 816 | + */ |
|
| 817 | + protected function _get_datetime_offset_fix_form() |
|
| 818 | + { |
|
| 819 | + if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) { |
|
| 820 | + $this->datetime_fix_offset_form = new EE_Form_Section_Proper( |
|
| 821 | + [ |
|
| 822 | + 'name' => 'datetime_offset_fix_option', |
|
| 823 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 824 | + 'subsections' => [ |
|
| 825 | + 'title' => new EE_Form_Section_HTML( |
|
| 826 | + EEH_HTML::h2( |
|
| 827 | + esc_html__('Datetime Offset Tool', 'event_espresso') |
|
| 828 | + ) |
|
| 829 | + ), |
|
| 830 | + 'explanation' => new EE_Form_Section_HTML( |
|
| 831 | + EEH_HTML::p( |
|
| 832 | + esc_html__( |
|
| 833 | + 'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.', |
|
| 834 | + 'event_espresso' |
|
| 835 | + ) |
|
| 836 | + ) |
|
| 837 | + . EEH_HTML::p( |
|
| 838 | + esc_html__( |
|
| 839 | + 'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied. Decimals represent the fraction of hours, not minutes.', |
|
| 840 | + 'event_espresso' |
|
| 841 | + ) |
|
| 842 | + ) |
|
| 843 | + ), |
|
| 844 | + 'offset_input' => new EE_Float_Input( |
|
| 845 | + [ |
|
| 846 | + 'html_name' => 'offset_for_datetimes', |
|
| 847 | + 'html_label_text' => esc_html__( |
|
| 848 | + 'Offset to apply (in hours):', |
|
| 849 | + 'event_espresso' |
|
| 850 | + ), |
|
| 851 | + 'min_value' => '-12', |
|
| 852 | + 'max_value' => '14', |
|
| 853 | + 'step_value' => '.25', |
|
| 854 | + 'default' => DatetimeOffsetFix::getOffset(), |
|
| 855 | + ] |
|
| 856 | + ), |
|
| 857 | + 'date_range_explanation' => new EE_Form_Section_HTML( |
|
| 858 | + EEH_HTML::p( |
|
| 859 | + esc_html__( |
|
| 860 | + 'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.', |
|
| 861 | + 'event_espresso' |
|
| 862 | + ) |
|
| 863 | + ) |
|
| 864 | + . EEH_HTML::p( |
|
| 865 | + EEH_HTML::strong( |
|
| 866 | + sprintf( |
|
| 867 | + esc_html__( |
|
| 868 | + 'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).', |
|
| 869 | + 'event_espresso' |
|
| 870 | + ), |
|
| 871 | + '<a href="https://www.timeanddate.com/worldclock/converter.html">', |
|
| 872 | + '</a>' |
|
| 873 | + ) |
|
| 874 | + ) |
|
| 875 | + ) |
|
| 876 | + ), |
|
| 877 | + 'date_range_start_date' => new EE_Datepicker_Input( |
|
| 878 | + [ |
|
| 879 | + 'html_name' => 'offset_date_start_range', |
|
| 880 | + 'html_label_text' => esc_html__( |
|
| 881 | + 'Start Date for dates the offset applied to:', |
|
| 882 | + 'event_espresso' |
|
| 883 | + ), |
|
| 884 | + ] |
|
| 885 | + ), |
|
| 886 | + 'date_range_end_date' => new EE_Datepicker_Input( |
|
| 887 | + [ |
|
| 888 | + 'html_name' => 'offset_date_end_range', |
|
| 889 | + 'html_label_text' => esc_html__( |
|
| 890 | + 'End Date for dates the offset is applied to:', |
|
| 891 | + 'event_espresso' |
|
| 892 | + ), |
|
| 893 | + ] |
|
| 894 | + ), |
|
| 895 | + 'submit' => new EE_Submit_Input( |
|
| 896 | + [ |
|
| 897 | + 'html_label_text' => '', |
|
| 898 | + 'default' => esc_html__('Apply Offset', 'event_espresso'), |
|
| 899 | + ] |
|
| 900 | + ), |
|
| 901 | + ], |
|
| 902 | + ] |
|
| 903 | + ); |
|
| 904 | + } |
|
| 905 | + return $this->datetime_fix_offset_form; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Callback for the run_datetime_offset_fix route. |
|
| 911 | + * |
|
| 912 | + * @throws EE_Error |
|
| 913 | + */ |
|
| 914 | + protected function _apply_datetime_offset() |
|
| 915 | + { |
|
| 916 | + if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 917 | + $form = $this->_get_datetime_offset_fix_form(); |
|
| 918 | + $form->receive_form_submission($this->_req_data); |
|
| 919 | + if ($form->is_valid()) { |
|
| 920 | + // save offset data so batch processor can get it. |
|
| 921 | + DatetimeOffsetFix::updateOffset((float) $form->get_input_value('offset_input')); |
|
| 922 | + $utc_timezone = new DateTimeZone('UTC'); |
|
| 923 | + $date_range_start_date = DateTime::createFromFormat( |
|
| 924 | + 'm/d/Y H:i:s', |
|
| 925 | + $form->get_input_value('date_range_start_date') . ' 00:00:00', |
|
| 926 | + $utc_timezone |
|
| 927 | + ); |
|
| 928 | + $date_range_end_date = DateTime::createFromFormat( |
|
| 929 | + 'm/d/Y H:i:s', |
|
| 930 | + $form->get_input_value('date_range_end_date') . ' 23:59:59', |
|
| 931 | + $utc_timezone |
|
| 932 | + ); |
|
| 933 | + if ($date_range_start_date instanceof DateTime) { |
|
| 934 | + DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date)); |
|
| 935 | + } |
|
| 936 | + if ($date_range_end_date instanceof DateTime) { |
|
| 937 | + DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date)); |
|
| 938 | + } |
|
| 939 | + // redirect to batch tool |
|
| 940 | + wp_redirect( |
|
| 941 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 942 | + [ |
|
| 943 | + 'page' => EED_Batch::PAGE_SLUG, |
|
| 944 | + 'batch' => EED_Batch::batch_job, |
|
| 945 | + 'label' => esc_html__('Applying Offset', 'event_espresso'), |
|
| 946 | + 'job_handler' => urlencode('EventEspresso\core\libraries\batch\JobHandlers\DatetimeOffsetFix'), |
|
| 947 | + 'return_url' => urlencode( |
|
| 948 | + add_query_arg( |
|
| 949 | + [ |
|
| 950 | + 'action' => 'datetime_tools', |
|
| 951 | + ], |
|
| 952 | + EEH_URL::current_url_without_query_paramaters( |
|
| 953 | + [ |
|
| 954 | + 'return_action', |
|
| 955 | + 'run_datetime_offset_fix_nonce', |
|
| 956 | + 'return', |
|
| 957 | + 'datetime_tools_nonce', |
|
| 958 | + ] |
|
| 959 | + ) |
|
| 960 | + ) |
|
| 961 | + ), |
|
| 962 | + ], |
|
| 963 | + admin_url() |
|
| 964 | + ) |
|
| 965 | + ); |
|
| 966 | + exit; |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + } |
|
| 970 | 970 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | if (MaintenanceStatus::isFullSite()) { |
| 232 | 232 | $show_maintenance_switch = false; |
| 233 | 233 | $show_migration_progress = true; |
| 234 | - if (! isset($this->_req_data['continue_migration'])) { |
|
| 234 | + if ( ! isset($this->_req_data['continue_migration'])) { |
|
| 235 | 235 | $show_backup_db_text = true; |
| 236 | 236 | } |
| 237 | 237 | $scripts_needing_to_run = |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $current_script = null; |
| 242 | 242 | foreach ($scripts_needing_to_run as $script) { |
| 243 | 243 | if ($script instanceof EE_Data_Migration_Script_Base) { |
| 244 | - if (! $current_script) { |
|
| 244 | + if ( ! $current_script) { |
|
| 245 | 245 | $current_script = $script; |
| 246 | 246 | $current_script->migration_page_hooks(); |
| 247 | 247 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | && $most_recent_migration->is_broken() |
| 269 | 269 | ) |
| 270 | 270 | ) { |
| 271 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
| 271 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php'; |
|
| 272 | 272 | |
| 273 | 273 | $this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/'; |
| 274 | 274 | $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce( |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | EE_MAINTENANCE_ADMIN_URL |
| 280 | 280 | ); |
| 281 | 281 | } elseif ($addons_should_be_upgraded_first) { |
| 282 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
| 282 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php'; |
|
| 283 | 283 | } else { |
| 284 | 284 | if ( |
| 285 | 285 | $most_recent_migration instanceof EE_Data_Migration_Script_Base |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | [ |
| 305 | 305 | 'current_db_state' => sprintf( |
| 306 | 306 | esc_html__("EE%s (%s)", "event_espresso"), |
| 307 | - $current_db_state[ $plugin_slug ] ?? 3, |
|
| 307 | + $current_db_state[$plugin_slug] ?? 3, |
|
| 308 | 308 | $plugin_slug |
| 309 | 309 | ), |
| 310 | 310 | 'next_db_state' => sprintf( |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | $this->_template_args['current_db_state'] = ''; |
| 319 | 319 | $this->_template_args['next_db_state'] = ''; |
| 320 | 320 | } |
| 321 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
| 321 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php'; |
|
| 322 | 322 | $this->_template_args = array_merge( |
| 323 | 323 | $this->_template_args, |
| 324 | 324 | [ |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | ); |
| 355 | 355 | } |
| 356 | 356 | $this->_template_args['most_recent_migration'] = |
| 357 | - $most_recent_migration;// the actual most recently ran migration |
|
| 357 | + $most_recent_migration; // the actual most recently ran migration |
|
| 358 | 358 | // now render the migration options part, and put it in a variable |
| 359 | - $migration_options_template_file = apply_filters( |
|
| 359 | + $migration_options_template_file = apply_filters( |
|
| 360 | 360 | 'FHEE__ee_migration_page__migration_options_template', |
| 361 | - EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
| 361 | + EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php' |
|
| 362 | 362 | ); |
| 363 | - $migration_options_html = EEH_Template::display_template( |
|
| 363 | + $migration_options_html = EEH_Template::display_template( |
|
| 364 | 364 | $migration_options_template_file, |
| 365 | 365 | $this->_template_args, |
| 366 | 366 | true |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | public function _change_maintenance_level() |
| 410 | 410 | { |
| 411 | 411 | $new_level = absint($this->_req_data['maintenance_mode_level']); |
| 412 | - if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) { |
|
| 412 | + if ( ! $this->migration_manager->check_for_applicable_data_migration_scripts()) { |
|
| 413 | 413 | $this->maintenance_mode->set_maintenance_level($new_level); |
| 414 | 414 | $success = true; |
| 415 | 415 | } else { |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | public function _data_reset_and_delete() |
| 430 | 430 | { |
| 431 | 431 | $this->_template_path = |
| 432 | - EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
| 432 | + EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php'; |
|
| 433 | 433 | $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
| 434 | 434 | 'reset_reservations', |
| 435 | 435 | 'reset_reservations', |
@@ -442,15 +442,15 @@ discard block |
||
| 442 | 442 | [], |
| 443 | 443 | 'button button--caution ee-confirm' |
| 444 | 444 | ); |
| 445 | - $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 445 | + $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 446 | 446 | ['action' => 'delete_db'], |
| 447 | 447 | EE_MAINTENANCE_ADMIN_URL |
| 448 | 448 | ); |
| 449 | - $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 449 | + $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 450 | 450 | ['action' => 'reset_db'], |
| 451 | 451 | EE_MAINTENANCE_ADMIN_URL |
| 452 | 452 | ); |
| 453 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 453 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 454 | 454 | $this->_template_path, |
| 455 | 455 | $this->_template_args, |
| 456 | 456 | true |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | public function _system_status() |
| 523 | 523 | { |
| 524 | 524 | $this->_template_path = |
| 525 | - EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
| 525 | + EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php'; |
|
| 526 | 526 | $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
| 527 | 527 | $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
| 528 | 528 | [ |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | ], |
| 531 | 531 | EE_MAINTENANCE_ADMIN_URL |
| 532 | 532 | ); |
| 533 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 533 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 534 | 534 | $this->_template_path, |
| 535 | 535 | $this->_template_args, |
| 536 | 536 | true |
@@ -546,12 +546,12 @@ discard block |
||
| 546 | 546 | { |
| 547 | 547 | $status_info = EEM_System_Status::instance()->get_system_stati(); |
| 548 | 548 | header('Content-Disposition: attachment'); |
| 549 | - header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html"); |
|
| 549 | + header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html"); |
|
| 550 | 550 | $output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>'; |
| 551 | - $output .= '<h1>' . sprintf( |
|
| 551 | + $output .= '<h1>'.sprintf( |
|
| 552 | 552 | __('System Information for %1$s', 'event_espresso'), |
| 553 | 553 | esc_url_raw(site_url()) |
| 554 | - ) . '</h1>'; |
|
| 554 | + ).'</h1>'; |
|
| 555 | 555 | $output .= EEH_Template::layout_array_as_table($status_info); |
| 556 | 556 | echo esc_html($output); |
| 557 | 557 | die; |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | $success = wp_mail( |
| 571 | 571 | EE_SUPPORT_EMAIL, |
| 572 | 572 | 'Migration Crash Report', |
| 573 | - $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
| 573 | + $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
| 574 | 574 | [ |
| 575 | 575 | "from:$from_name<$from>", |
| 576 | 576 | ] |
@@ -608,16 +608,16 @@ discard block |
||
| 608 | 608 | ['action' => 'reset_db'], |
| 609 | 609 | EE_MAINTENANCE_ADMIN_URL |
| 610 | 610 | ); |
| 611 | - $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 611 | + $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 612 | 612 | ['action' => 'data_reset'], |
| 613 | 613 | EE_MAINTENANCE_ADMIN_URL |
| 614 | 614 | ); |
| 615 | - $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 615 | + $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 616 | 616 | ['action' => 'reattempt_migration'], |
| 617 | 617 | EE_MAINTENANCE_ADMIN_URL |
| 618 | 618 | ); |
| 619 | 619 | $this->_template_path = |
| 620 | - EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
| 620 | + EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php'; |
|
| 621 | 621 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 622 | 622 | $this->_template_path, |
| 623 | 623 | $this->_template_args, |
@@ -725,14 +725,14 @@ discard block |
||
| 725 | 725 | wp_enqueue_script('ee_admin_js'); |
| 726 | 726 | wp_enqueue_script( |
| 727 | 727 | 'ee-maintenance', |
| 728 | - EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js', |
|
| 728 | + EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.js', |
|
| 729 | 729 | ['jquery'], |
| 730 | 730 | EVENT_ESPRESSO_VERSION, |
| 731 | 731 | true |
| 732 | 732 | ); |
| 733 | 733 | wp_register_style( |
| 734 | 734 | 'espresso_maintenance', |
| 735 | - EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', |
|
| 735 | + EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', |
|
| 736 | 736 | [], |
| 737 | 737 | EVENT_ESPRESSO_VERSION |
| 738 | 738 | ); |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | */ |
| 796 | 796 | protected function _datetime_tools() |
| 797 | 797 | { |
| 798 | - $form_action = EE_Admin_Page::add_query_args_and_nonce( |
|
| 798 | + $form_action = EE_Admin_Page::add_query_args_and_nonce( |
|
| 799 | 799 | [ |
| 800 | 800 | 'action' => 'run_datetime_offset_fix', |
| 801 | 801 | 'return_action' => $this->_req_action, |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | */ |
| 817 | 817 | protected function _get_datetime_offset_fix_form() |
| 818 | 818 | { |
| 819 | - if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) { |
|
| 819 | + if ( ! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) { |
|
| 820 | 820 | $this->datetime_fix_offset_form = new EE_Form_Section_Proper( |
| 821 | 821 | [ |
| 822 | 822 | 'name' => 'datetime_offset_fix_option', |
@@ -922,12 +922,12 @@ discard block |
||
| 922 | 922 | $utc_timezone = new DateTimeZone('UTC'); |
| 923 | 923 | $date_range_start_date = DateTime::createFromFormat( |
| 924 | 924 | 'm/d/Y H:i:s', |
| 925 | - $form->get_input_value('date_range_start_date') . ' 00:00:00', |
|
| 925 | + $form->get_input_value('date_range_start_date').' 00:00:00', |
|
| 926 | 926 | $utc_timezone |
| 927 | 927 | ); |
| 928 | - $date_range_end_date = DateTime::createFromFormat( |
|
| 928 | + $date_range_end_date = DateTime::createFromFormat( |
|
| 929 | 929 | 'm/d/Y H:i:s', |
| 930 | - $form->get_input_value('date_range_end_date') . ' 23:59:59', |
|
| 930 | + $form->get_input_value('date_range_end_date').' 23:59:59', |
|
| 931 | 931 | $utc_timezone |
| 932 | 932 | ); |
| 933 | 933 | if ($date_range_start_date instanceof DateTime) { |
@@ -18,96 +18,96 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Maintenance_Admin_Page_Init extends EE_Admin_Page_Init |
| 20 | 20 | { |
| 21 | - protected int $m_mode_level; |
|
| 21 | + protected int $m_mode_level; |
|
| 22 | 22 | |
| 23 | - protected bool $is_full_m_mode; |
|
| 23 | + protected bool $is_full_m_mode; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - public function __construct() |
|
| 27 | - { |
|
| 28 | - $this->m_mode_level = EE_Maintenance_Mode::instance()->level(); |
|
| 29 | - $this->is_full_m_mode = MaintenanceStatus::isNotDisabled(); |
|
| 30 | - // define some page related constants |
|
| 31 | - if (! defined('EE_MAINTENANCE_PG_SLUG')) { |
|
| 32 | - define('EE_MAINTENANCE_LABEL', esc_html__('Maintenance', 'event_espresso')); |
|
| 33 | - define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
|
| 34 | - define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
| 35 | - define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance/'); |
|
| 36 | - define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates/'); |
|
| 37 | - define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
| 38 | - } |
|
| 39 | - // check that if we're in maintenance mode that we tell the admin that |
|
| 40 | - add_action('admin_notices', [$this, 'check_maintenance_mode']); |
|
| 41 | - parent::__construct(); |
|
| 42 | - } |
|
| 26 | + public function __construct() |
|
| 27 | + { |
|
| 28 | + $this->m_mode_level = EE_Maintenance_Mode::instance()->level(); |
|
| 29 | + $this->is_full_m_mode = MaintenanceStatus::isNotDisabled(); |
|
| 30 | + // define some page related constants |
|
| 31 | + if (! defined('EE_MAINTENANCE_PG_SLUG')) { |
|
| 32 | + define('EE_MAINTENANCE_LABEL', esc_html__('Maintenance', 'event_espresso')); |
|
| 33 | + define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
|
| 34 | + define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
| 35 | + define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance/'); |
|
| 36 | + define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates/'); |
|
| 37 | + define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
| 38 | + } |
|
| 39 | + // check that if we're in maintenance mode that we tell the admin that |
|
| 40 | + add_action('admin_notices', [$this, 'check_maintenance_mode']); |
|
| 41 | + parent::__construct(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - protected function _set_init_properties() |
|
| 46 | - { |
|
| 47 | - $this->label = EE_MAINTENANCE_LABEL; |
|
| 48 | - } |
|
| 45 | + protected function _set_init_properties() |
|
| 46 | + { |
|
| 47 | + $this->label = EE_MAINTENANCE_LABEL; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - public function getMenuProperties(): array |
|
| 52 | - { |
|
| 53 | - return [ |
|
| 54 | - 'menu_type' => AdminMenuItem::TYPE_MENU_SUB_ITEM, |
|
| 55 | - 'menu_group' => $this->is_full_m_mode ? 'main' : 'extras', |
|
| 56 | - 'menu_order' => 30, |
|
| 57 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 58 | - 'parent_slug' => 'espresso_events', |
|
| 59 | - 'menu_slug' => EE_MAINTENANCE_PG_SLUG, |
|
| 60 | - 'menu_label' => EE_MAINTENANCE_LABEL, |
|
| 61 | - 'capability' => 'manage_options', |
|
| 62 | - 'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG, |
|
| 63 | - ]; |
|
| 64 | - } |
|
| 51 | + public function getMenuProperties(): array |
|
| 52 | + { |
|
| 53 | + return [ |
|
| 54 | + 'menu_type' => AdminMenuItem::TYPE_MENU_SUB_ITEM, |
|
| 55 | + 'menu_group' => $this->is_full_m_mode ? 'main' : 'extras', |
|
| 56 | + 'menu_order' => 30, |
|
| 57 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 58 | + 'parent_slug' => 'espresso_events', |
|
| 59 | + 'menu_slug' => EE_MAINTENANCE_PG_SLUG, |
|
| 60 | + 'menu_label' => EE_MAINTENANCE_LABEL, |
|
| 61 | + 'capability' => 'manage_options', |
|
| 62 | + 'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG, |
|
| 63 | + ]; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of |
|
| 69 | - * maintenance mode |
|
| 70 | - */ |
|
| 71 | - public function check_maintenance_mode() |
|
| 72 | - { |
|
| 73 | - $notice = ''; |
|
| 74 | - $maintenance_page_url = ''; |
|
| 75 | - if ($this->m_mode_level) { |
|
| 76 | - $maintenance_page_url = esc_url_raw( |
|
| 77 | - EE_Admin_Page::add_query_args_and_nonce([], EE_MAINTENANCE_ADMIN_URL) |
|
| 78 | - ); |
|
| 79 | - switch ($this->m_mode_level) { |
|
| 80 | - case EE_Maintenance_Mode::STATUS_PUBLIC_ONLY: |
|
| 81 | - $notice = '<div class="notice ee-nag-notice ee-status-outline ee-status-outline--warning ee-status-bg--warning">'; |
|
| 82 | - $notice .= sprintf( |
|
| 83 | - esc_html__( |
|
| 84 | - "Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.", |
|
| 85 | - "event_espresso" |
|
| 86 | - ), |
|
| 87 | - "<a href='$maintenance_page_url'>", |
|
| 88 | - "</a>" |
|
| 89 | - ); |
|
| 90 | - $notice .= '</div>'; |
|
| 91 | - break; |
|
| 92 | - case EE_Maintenance_Mode::STATUS_FULL_SITE: |
|
| 93 | - $notice = '<div class="error"><p>'; |
|
| 94 | - $notice .= sprintf( |
|
| 95 | - esc_html__( |
|
| 96 | - "As part of the process for updating Event Espresso, your database also |
|
| 67 | + /** |
|
| 68 | + * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of |
|
| 69 | + * maintenance mode |
|
| 70 | + */ |
|
| 71 | + public function check_maintenance_mode() |
|
| 72 | + { |
|
| 73 | + $notice = ''; |
|
| 74 | + $maintenance_page_url = ''; |
|
| 75 | + if ($this->m_mode_level) { |
|
| 76 | + $maintenance_page_url = esc_url_raw( |
|
| 77 | + EE_Admin_Page::add_query_args_and_nonce([], EE_MAINTENANCE_ADMIN_URL) |
|
| 78 | + ); |
|
| 79 | + switch ($this->m_mode_level) { |
|
| 80 | + case EE_Maintenance_Mode::STATUS_PUBLIC_ONLY: |
|
| 81 | + $notice = '<div class="notice ee-nag-notice ee-status-outline ee-status-outline--warning ee-status-bg--warning">'; |
|
| 82 | + $notice .= sprintf( |
|
| 83 | + esc_html__( |
|
| 84 | + "Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.", |
|
| 85 | + "event_espresso" |
|
| 86 | + ), |
|
| 87 | + "<a href='$maintenance_page_url'>", |
|
| 88 | + "</a>" |
|
| 89 | + ); |
|
| 90 | + $notice .= '</div>'; |
|
| 91 | + break; |
|
| 92 | + case EE_Maintenance_Mode::STATUS_FULL_SITE: |
|
| 93 | + $notice = '<div class="error"><p>'; |
|
| 94 | + $notice .= sprintf( |
|
| 95 | + esc_html__( |
|
| 96 | + "As part of the process for updating Event Espresso, your database also |
|
| 97 | 97 | needs to be updated. Event Espresso is in COMPLETE MAINTENANCE MODE (both WordPress admin pages and front-end event registration pages are disabled) until you run the database update script. %s Visit the Maintenance Page to get started,%s it only takes a moment.", |
| 98 | - "event_espresso" |
|
| 99 | - ), |
|
| 100 | - "<a href='$maintenance_page_url'>", |
|
| 101 | - "</a>" |
|
| 102 | - ); |
|
| 103 | - $notice .= '</p></div>'; |
|
| 104 | - break; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - echo apply_filters( |
|
| 108 | - 'FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', |
|
| 109 | - $notice, // already escaped |
|
| 110 | - $maintenance_page_url // already escaped |
|
| 111 | - ); |
|
| 112 | - } |
|
| 98 | + "event_espresso" |
|
| 99 | + ), |
|
| 100 | + "<a href='$maintenance_page_url'>", |
|
| 101 | + "</a>" |
|
| 102 | + ); |
|
| 103 | + $notice .= '</p></div>'; |
|
| 104 | + break; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + echo apply_filters( |
|
| 108 | + 'FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', |
|
| 109 | + $notice, // already escaped |
|
| 110 | + $maintenance_page_url // already escaped |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -28,13 +28,13 @@ |
||
| 28 | 28 | $this->m_mode_level = EE_Maintenance_Mode::instance()->level(); |
| 29 | 29 | $this->is_full_m_mode = MaintenanceStatus::isNotDisabled(); |
| 30 | 30 | // define some page related constants |
| 31 | - if (! defined('EE_MAINTENANCE_PG_SLUG')) { |
|
| 31 | + if ( ! defined('EE_MAINTENANCE_PG_SLUG')) { |
|
| 32 | 32 | define('EE_MAINTENANCE_LABEL', esc_html__('Maintenance', 'event_espresso')); |
| 33 | 33 | define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
| 34 | - define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
| 35 | - define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance/'); |
|
| 36 | - define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates/'); |
|
| 37 | - define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
| 34 | + define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page='.EE_MAINTENANCE_PG_SLUG)); |
|
| 35 | + define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES.'maintenance/'); |
|
| 36 | + define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN.'templates/'); |
|
| 37 | + define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL.'maintenance/assets/'); |
|
| 38 | 38 | } |
| 39 | 39 | // check that if we're in maintenance mode that we tell the admin that |
| 40 | 40 | add_action('admin_notices', [$this, 'check_maintenance_mode']); |