@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 4 | 4 | |
| 5 | 5 | if (! class_exists('WP_List_Table')) { |
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 6 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
@@ -22,873 +22,873 @@ discard block |
||
| 22 | 22 | abstract class EE_Admin_List_Table extends WP_List_Table |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * holds the data that will be processed for the table |
|
| 27 | - * |
|
| 28 | - * @var array $_data |
|
| 29 | - */ |
|
| 30 | - protected $_data; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This holds the value of all the data available for the given view (for all pages). |
|
| 35 | - * |
|
| 36 | - * @var int $_all_data_count |
|
| 37 | - */ |
|
| 38 | - protected $_all_data_count; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Will contain the count of trashed items for the view label. |
|
| 43 | - * |
|
| 44 | - * @var int $_trashed_count |
|
| 45 | - */ |
|
| 46 | - protected $_trashed_count; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * This is what will be referenced as the slug for the current screen |
|
| 51 | - * |
|
| 52 | - * @var string $_screen |
|
| 53 | - */ |
|
| 54 | - protected $_screen; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * this is the EE_Admin_Page object |
|
| 59 | - * |
|
| 60 | - * @var EE_Admin_Page $_admin_page |
|
| 61 | - */ |
|
| 62 | - protected $_admin_page; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * The current view |
|
| 67 | - * |
|
| 68 | - * @var string $_view |
|
| 69 | - */ |
|
| 70 | - protected $_view; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * array of possible views for this table |
|
| 75 | - * |
|
| 76 | - * @var array $_views |
|
| 77 | - */ |
|
| 78 | - protected $_views; |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * An array of key => value pairs containing information about the current table |
|
| 83 | - * array( |
|
| 84 | - * 'plural' => 'plural label', |
|
| 85 | - * 'singular' => 'singular label', |
|
| 86 | - * 'ajax' => false, //whether to use ajax or not |
|
| 87 | - * 'screen' => null, //string used to reference what screen this is |
|
| 88 | - * (WP_List_table converts to screen object) |
|
| 89 | - * ) |
|
| 90 | - * |
|
| 91 | - * @var array $_wp_list_args |
|
| 92 | - */ |
|
| 93 | - protected $_wp_list_args; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * an array of column names |
|
| 97 | - * array( |
|
| 98 | - * 'internal-name' => 'Title' |
|
| 99 | - * ) |
|
| 100 | - * |
|
| 101 | - * @var array $_columns |
|
| 102 | - */ |
|
| 103 | - protected $_columns; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of sortable columns |
|
| 107 | - * array( |
|
| 108 | - * 'internal-name' => 'orderby' //or |
|
| 109 | - * 'internal-name' => array( 'orderby', true ) |
|
| 110 | - * ) |
|
| 111 | - * |
|
| 112 | - * @var array $_sortable_columns |
|
| 113 | - */ |
|
| 114 | - protected $_sortable_columns; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * callback method used to perform AJAX row reordering |
|
| 118 | - * |
|
| 119 | - * @var string $_ajax_sorting_callback |
|
| 120 | - */ |
|
| 121 | - protected $_ajax_sorting_callback; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * An array of hidden columns (if needed) |
|
| 125 | - * array('internal-name', 'internal-name') |
|
| 126 | - * |
|
| 127 | - * @var array $_hidden_columns |
|
| 128 | - */ |
|
| 129 | - protected $_hidden_columns; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * holds the per_page value |
|
| 133 | - * |
|
| 134 | - * @var int $_per_page |
|
| 135 | - */ |
|
| 136 | - protected $_per_page; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * holds what page number is currently being viewed |
|
| 140 | - * |
|
| 141 | - * @var int $_current_page |
|
| 142 | - */ |
|
| 143 | - protected $_current_page; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * the reference string for the nonce_action |
|
| 147 | - * |
|
| 148 | - * @var string $_nonce_action_ref |
|
| 149 | - */ |
|
| 150 | - protected $_nonce_action_ref; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * property to hold incoming request data (as set by the admin_page_core) |
|
| 154 | - * |
|
| 155 | - * @var array $_req_data |
|
| 156 | - */ |
|
| 157 | - protected $_req_data; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * yes / no array for admin form fields |
|
| 162 | - * |
|
| 163 | - * @var array $_yes_no |
|
| 164 | - */ |
|
| 165 | - protected $_yes_no = []; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Array describing buttons that should appear at the bottom of the page |
|
| 169 | - * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 170 | - * and the values are another array with the following keys |
|
| 171 | - * array( |
|
| 172 | - * 'route' => 'page_route', |
|
| 173 | - * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 174 | - * ) |
|
| 175 | - * |
|
| 176 | - * @var array $_bottom_buttons |
|
| 177 | - */ |
|
| 178 | - protected $_bottom_buttons = []; |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Used to indicate what should be the primary column for the list table. |
|
| 183 | - * If not present then falls back to what WP calculates |
|
| 184 | - * as the primary column. |
|
| 185 | - * |
|
| 186 | - * @type string $_primary_column |
|
| 187 | - */ |
|
| 188 | - protected $_primary_column = ''; |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Used to indicate whether the table has a checkbox column or not. |
|
| 193 | - * |
|
| 194 | - * @type bool $_has_checkbox_column |
|
| 195 | - */ |
|
| 196 | - protected $_has_checkbox_column = false; |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 201 | - */ |
|
| 202 | - public function __construct(EE_Admin_Page $admin_page) |
|
| 203 | - { |
|
| 204 | - $this->_admin_page = $admin_page; |
|
| 205 | - $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 206 | - $this->_view = $this->_admin_page->get_view(); |
|
| 207 | - $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 208 | - $this->_current_page = $this->get_pagenum(); |
|
| 209 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 210 | - $this->_yes_no = [ |
|
| 211 | - esc_html__('No', 'event_espresso'), |
|
| 212 | - esc_html__('Yes', 'event_espresso') |
|
| 213 | - ]; |
|
| 214 | - |
|
| 215 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 216 | - |
|
| 217 | - $this->_setup_data(); |
|
| 218 | - $this->_add_view_counts(); |
|
| 219 | - |
|
| 220 | - $this->_nonce_action_ref = $this->_view; |
|
| 221 | - |
|
| 222 | - $this->_set_properties(); |
|
| 223 | - |
|
| 224 | - // set primary column |
|
| 225 | - add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 226 | - |
|
| 227 | - // set parent defaults |
|
| 228 | - parent::__construct($this->_wp_list_args); |
|
| 229 | - |
|
| 230 | - $this->prepare_items(); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * _setup_data |
|
| 236 | - * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 237 | - * |
|
| 238 | - * @return void |
|
| 239 | - * @uses $this->_admin_page |
|
| 240 | - */ |
|
| 241 | - abstract protected function _setup_data(); |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 246 | - * properties set: |
|
| 247 | - * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 248 | - * _columns = set the columns in an array. |
|
| 249 | - * _sortable_columns = columns that are sortable (array). |
|
| 250 | - * _hidden_columns = columns that are hidden (array) |
|
| 251 | - * _default_orderby = the default orderby for sorting. |
|
| 252 | - * |
|
| 253 | - * @abstract |
|
| 254 | - * @access protected |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - abstract protected function _set_properties(); |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * _get_table_filters |
|
| 262 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 263 | - * gets shown in the table. |
|
| 264 | - * |
|
| 265 | - * @abstract |
|
| 266 | - * @access protected |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - abstract protected function _get_table_filters(); |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 274 | - * counts of the views is accurate. |
|
| 275 | - * |
|
| 276 | - * @abstract |
|
| 277 | - * @access protected |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - abstract protected function _add_view_counts(); |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * _get_hidden_fields |
|
| 285 | - * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 286 | - * |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - protected function _get_hidden_fields() |
|
| 290 | - { |
|
| 291 | - $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 292 | - $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 293 | - // if action is STILL empty, then we set it to default |
|
| 294 | - $action = empty($action) ? 'default' : $action; |
|
| 295 | - $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 296 | - $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 297 | - $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 298 | - |
|
| 299 | - $bulk_actions = $this->_get_bulk_actions(); |
|
| 300 | - foreach ($bulk_actions as $bulk_action => $label) { |
|
| 301 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 302 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - return $field; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * _set_column_info |
|
| 311 | - * we're using this to set the column headers property. |
|
| 312 | - * |
|
| 313 | - * @access protected |
|
| 314 | - * @return void |
|
| 315 | - */ |
|
| 316 | - protected function _set_column_info() |
|
| 317 | - { |
|
| 318 | - $columns = $this->get_columns(); |
|
| 319 | - $hidden = $this->get_hidden_columns(); |
|
| 320 | - $_sortable = $this->get_sortable_columns(); |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 324 | - * Note that $this->screen->id is in the format |
|
| 325 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 326 | - * table it is: event-espresso_page_espresso_messages. |
|
| 327 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 328 | - * hook prefix ("event-espresso") will be different. |
|
| 329 | - * |
|
| 330 | - * @var array |
|
| 331 | - */ |
|
| 332 | - $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 333 | - |
|
| 334 | - $sortable = []; |
|
| 335 | - foreach ($_sortable as $id => $data) { |
|
| 336 | - if (empty($data)) { |
|
| 337 | - continue; |
|
| 338 | - } |
|
| 339 | - // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 340 | - if (is_array($data)) { |
|
| 341 | - $_data[0] = key($data); |
|
| 342 | - $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 343 | - } else { |
|
| 344 | - $_data[0] = $data; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $data = (array) $data; |
|
| 348 | - |
|
| 349 | - if (! isset($data[1])) { |
|
| 350 | - $_data[1] = false; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $sortable[ $id ] = $_data; |
|
| 354 | - } |
|
| 355 | - $primary = $this->get_primary_column_name(); |
|
| 356 | - $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 362 | - * |
|
| 363 | - * @return string |
|
| 364 | - */ |
|
| 365 | - protected function get_primary_column_name() |
|
| 366 | - { |
|
| 367 | - foreach (class_parents($this) as $parent) { |
|
| 368 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 369 | - return parent::get_primary_column_name(); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - return $this->_primary_column; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 378 | - * |
|
| 379 | - * @param EE_Base_Class $item |
|
| 380 | - * @param string $column_name |
|
| 381 | - * @param string $primary |
|
| 382 | - * @return string |
|
| 383 | - */ |
|
| 384 | - protected function handle_row_actions($item, $column_name, $primary) |
|
| 385 | - { |
|
| 386 | - foreach (class_parents($this) as $parent) { |
|
| 387 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 388 | - return parent::handle_row_actions($item, $column_name, $primary); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - return ''; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * _get_bulk_actions |
|
| 397 | - * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 398 | - * |
|
| 399 | - * @access protected |
|
| 400 | - * @return array bulk_actions |
|
| 401 | - */ |
|
| 402 | - protected function _get_bulk_actions() |
|
| 403 | - { |
|
| 404 | - $actions = []; |
|
| 405 | - // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 406 | - // formatted array for the wp_list_table(); |
|
| 407 | - foreach ($this->_views as $view => $args) { |
|
| 408 | - if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 409 | - // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 410 | - // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 411 | - foreach ($args['bulk_action'] as $route => $label) { |
|
| 412 | - if ($this->_admin_page->check_user_access($route, true)) { |
|
| 413 | - $actions[ $route ] = $label; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - return $actions; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Generate the table navigation above or below the table. |
|
| 424 | - * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 425 | - * |
|
| 426 | - * @throws EE_Error |
|
| 427 | - * @since 4.9.44.rc.001 |
|
| 428 | - */ |
|
| 429 | - public function display_tablenav($which) |
|
| 430 | - { |
|
| 431 | - if ('top' === $which) { |
|
| 432 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 433 | - } |
|
| 434 | - ?> |
|
| 25 | + /** |
|
| 26 | + * holds the data that will be processed for the table |
|
| 27 | + * |
|
| 28 | + * @var array $_data |
|
| 29 | + */ |
|
| 30 | + protected $_data; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This holds the value of all the data available for the given view (for all pages). |
|
| 35 | + * |
|
| 36 | + * @var int $_all_data_count |
|
| 37 | + */ |
|
| 38 | + protected $_all_data_count; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Will contain the count of trashed items for the view label. |
|
| 43 | + * |
|
| 44 | + * @var int $_trashed_count |
|
| 45 | + */ |
|
| 46 | + protected $_trashed_count; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * This is what will be referenced as the slug for the current screen |
|
| 51 | + * |
|
| 52 | + * @var string $_screen |
|
| 53 | + */ |
|
| 54 | + protected $_screen; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * this is the EE_Admin_Page object |
|
| 59 | + * |
|
| 60 | + * @var EE_Admin_Page $_admin_page |
|
| 61 | + */ |
|
| 62 | + protected $_admin_page; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * The current view |
|
| 67 | + * |
|
| 68 | + * @var string $_view |
|
| 69 | + */ |
|
| 70 | + protected $_view; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * array of possible views for this table |
|
| 75 | + * |
|
| 76 | + * @var array $_views |
|
| 77 | + */ |
|
| 78 | + protected $_views; |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * An array of key => value pairs containing information about the current table |
|
| 83 | + * array( |
|
| 84 | + * 'plural' => 'plural label', |
|
| 85 | + * 'singular' => 'singular label', |
|
| 86 | + * 'ajax' => false, //whether to use ajax or not |
|
| 87 | + * 'screen' => null, //string used to reference what screen this is |
|
| 88 | + * (WP_List_table converts to screen object) |
|
| 89 | + * ) |
|
| 90 | + * |
|
| 91 | + * @var array $_wp_list_args |
|
| 92 | + */ |
|
| 93 | + protected $_wp_list_args; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * an array of column names |
|
| 97 | + * array( |
|
| 98 | + * 'internal-name' => 'Title' |
|
| 99 | + * ) |
|
| 100 | + * |
|
| 101 | + * @var array $_columns |
|
| 102 | + */ |
|
| 103 | + protected $_columns; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of sortable columns |
|
| 107 | + * array( |
|
| 108 | + * 'internal-name' => 'orderby' //or |
|
| 109 | + * 'internal-name' => array( 'orderby', true ) |
|
| 110 | + * ) |
|
| 111 | + * |
|
| 112 | + * @var array $_sortable_columns |
|
| 113 | + */ |
|
| 114 | + protected $_sortable_columns; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * callback method used to perform AJAX row reordering |
|
| 118 | + * |
|
| 119 | + * @var string $_ajax_sorting_callback |
|
| 120 | + */ |
|
| 121 | + protected $_ajax_sorting_callback; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * An array of hidden columns (if needed) |
|
| 125 | + * array('internal-name', 'internal-name') |
|
| 126 | + * |
|
| 127 | + * @var array $_hidden_columns |
|
| 128 | + */ |
|
| 129 | + protected $_hidden_columns; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * holds the per_page value |
|
| 133 | + * |
|
| 134 | + * @var int $_per_page |
|
| 135 | + */ |
|
| 136 | + protected $_per_page; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * holds what page number is currently being viewed |
|
| 140 | + * |
|
| 141 | + * @var int $_current_page |
|
| 142 | + */ |
|
| 143 | + protected $_current_page; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * the reference string for the nonce_action |
|
| 147 | + * |
|
| 148 | + * @var string $_nonce_action_ref |
|
| 149 | + */ |
|
| 150 | + protected $_nonce_action_ref; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * property to hold incoming request data (as set by the admin_page_core) |
|
| 154 | + * |
|
| 155 | + * @var array $_req_data |
|
| 156 | + */ |
|
| 157 | + protected $_req_data; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * yes / no array for admin form fields |
|
| 162 | + * |
|
| 163 | + * @var array $_yes_no |
|
| 164 | + */ |
|
| 165 | + protected $_yes_no = []; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Array describing buttons that should appear at the bottom of the page |
|
| 169 | + * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 170 | + * and the values are another array with the following keys |
|
| 171 | + * array( |
|
| 172 | + * 'route' => 'page_route', |
|
| 173 | + * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 174 | + * ) |
|
| 175 | + * |
|
| 176 | + * @var array $_bottom_buttons |
|
| 177 | + */ |
|
| 178 | + protected $_bottom_buttons = []; |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Used to indicate what should be the primary column for the list table. |
|
| 183 | + * If not present then falls back to what WP calculates |
|
| 184 | + * as the primary column. |
|
| 185 | + * |
|
| 186 | + * @type string $_primary_column |
|
| 187 | + */ |
|
| 188 | + protected $_primary_column = ''; |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Used to indicate whether the table has a checkbox column or not. |
|
| 193 | + * |
|
| 194 | + * @type bool $_has_checkbox_column |
|
| 195 | + */ |
|
| 196 | + protected $_has_checkbox_column = false; |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 201 | + */ |
|
| 202 | + public function __construct(EE_Admin_Page $admin_page) |
|
| 203 | + { |
|
| 204 | + $this->_admin_page = $admin_page; |
|
| 205 | + $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 206 | + $this->_view = $this->_admin_page->get_view(); |
|
| 207 | + $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 208 | + $this->_current_page = $this->get_pagenum(); |
|
| 209 | + $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 210 | + $this->_yes_no = [ |
|
| 211 | + esc_html__('No', 'event_espresso'), |
|
| 212 | + esc_html__('Yes', 'event_espresso') |
|
| 213 | + ]; |
|
| 214 | + |
|
| 215 | + $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 216 | + |
|
| 217 | + $this->_setup_data(); |
|
| 218 | + $this->_add_view_counts(); |
|
| 219 | + |
|
| 220 | + $this->_nonce_action_ref = $this->_view; |
|
| 221 | + |
|
| 222 | + $this->_set_properties(); |
|
| 223 | + |
|
| 224 | + // set primary column |
|
| 225 | + add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 226 | + |
|
| 227 | + // set parent defaults |
|
| 228 | + parent::__construct($this->_wp_list_args); |
|
| 229 | + |
|
| 230 | + $this->prepare_items(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * _setup_data |
|
| 236 | + * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 237 | + * |
|
| 238 | + * @return void |
|
| 239 | + * @uses $this->_admin_page |
|
| 240 | + */ |
|
| 241 | + abstract protected function _setup_data(); |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 246 | + * properties set: |
|
| 247 | + * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 248 | + * _columns = set the columns in an array. |
|
| 249 | + * _sortable_columns = columns that are sortable (array). |
|
| 250 | + * _hidden_columns = columns that are hidden (array) |
|
| 251 | + * _default_orderby = the default orderby for sorting. |
|
| 252 | + * |
|
| 253 | + * @abstract |
|
| 254 | + * @access protected |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + abstract protected function _set_properties(); |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * _get_table_filters |
|
| 262 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 263 | + * gets shown in the table. |
|
| 264 | + * |
|
| 265 | + * @abstract |
|
| 266 | + * @access protected |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + abstract protected function _get_table_filters(); |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 274 | + * counts of the views is accurate. |
|
| 275 | + * |
|
| 276 | + * @abstract |
|
| 277 | + * @access protected |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + abstract protected function _add_view_counts(); |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * _get_hidden_fields |
|
| 285 | + * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 286 | + * |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + protected function _get_hidden_fields() |
|
| 290 | + { |
|
| 291 | + $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 292 | + $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 293 | + // if action is STILL empty, then we set it to default |
|
| 294 | + $action = empty($action) ? 'default' : $action; |
|
| 295 | + $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 296 | + $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 297 | + $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 298 | + |
|
| 299 | + $bulk_actions = $this->_get_bulk_actions(); |
|
| 300 | + foreach ($bulk_actions as $bulk_action => $label) { |
|
| 301 | + $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 302 | + . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + return $field; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * _set_column_info |
|
| 311 | + * we're using this to set the column headers property. |
|
| 312 | + * |
|
| 313 | + * @access protected |
|
| 314 | + * @return void |
|
| 315 | + */ |
|
| 316 | + protected function _set_column_info() |
|
| 317 | + { |
|
| 318 | + $columns = $this->get_columns(); |
|
| 319 | + $hidden = $this->get_hidden_columns(); |
|
| 320 | + $_sortable = $this->get_sortable_columns(); |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 324 | + * Note that $this->screen->id is in the format |
|
| 325 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 326 | + * table it is: event-espresso_page_espresso_messages. |
|
| 327 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 328 | + * hook prefix ("event-espresso") will be different. |
|
| 329 | + * |
|
| 330 | + * @var array |
|
| 331 | + */ |
|
| 332 | + $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 333 | + |
|
| 334 | + $sortable = []; |
|
| 335 | + foreach ($_sortable as $id => $data) { |
|
| 336 | + if (empty($data)) { |
|
| 337 | + continue; |
|
| 338 | + } |
|
| 339 | + // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 340 | + if (is_array($data)) { |
|
| 341 | + $_data[0] = key($data); |
|
| 342 | + $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 343 | + } else { |
|
| 344 | + $_data[0] = $data; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $data = (array) $data; |
|
| 348 | + |
|
| 349 | + if (! isset($data[1])) { |
|
| 350 | + $_data[1] = false; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $sortable[ $id ] = $_data; |
|
| 354 | + } |
|
| 355 | + $primary = $this->get_primary_column_name(); |
|
| 356 | + $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 362 | + * |
|
| 363 | + * @return string |
|
| 364 | + */ |
|
| 365 | + protected function get_primary_column_name() |
|
| 366 | + { |
|
| 367 | + foreach (class_parents($this) as $parent) { |
|
| 368 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 369 | + return parent::get_primary_column_name(); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + return $this->_primary_column; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 378 | + * |
|
| 379 | + * @param EE_Base_Class $item |
|
| 380 | + * @param string $column_name |
|
| 381 | + * @param string $primary |
|
| 382 | + * @return string |
|
| 383 | + */ |
|
| 384 | + protected function handle_row_actions($item, $column_name, $primary) |
|
| 385 | + { |
|
| 386 | + foreach (class_parents($this) as $parent) { |
|
| 387 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 388 | + return parent::handle_row_actions($item, $column_name, $primary); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + return ''; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * _get_bulk_actions |
|
| 397 | + * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 398 | + * |
|
| 399 | + * @access protected |
|
| 400 | + * @return array bulk_actions |
|
| 401 | + */ |
|
| 402 | + protected function _get_bulk_actions() |
|
| 403 | + { |
|
| 404 | + $actions = []; |
|
| 405 | + // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 406 | + // formatted array for the wp_list_table(); |
|
| 407 | + foreach ($this->_views as $view => $args) { |
|
| 408 | + if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 409 | + // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 410 | + // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 411 | + foreach ($args['bulk_action'] as $route => $label) { |
|
| 412 | + if ($this->_admin_page->check_user_access($route, true)) { |
|
| 413 | + $actions[ $route ] = $label; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + return $actions; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Generate the table navigation above or below the table. |
|
| 424 | + * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 425 | + * |
|
| 426 | + * @throws EE_Error |
|
| 427 | + * @since 4.9.44.rc.001 |
|
| 428 | + */ |
|
| 429 | + public function display_tablenav($which) |
|
| 430 | + { |
|
| 431 | + if ('top' === $which) { |
|
| 432 | + wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 433 | + } |
|
| 434 | + ?> |
|
| 435 | 435 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
| 436 | 436 | <?php if ($this->_get_bulk_actions()) { ?> |
| 437 | 437 | <div class="alignleft actions bulkactions"> |
| 438 | 438 | <?php $this->bulk_actions(); ?> |
| 439 | 439 | </div> |
| 440 | 440 | <?php } |
| 441 | - $this->extra_tablenav($which); |
|
| 442 | - $this->pagination($which); |
|
| 443 | - ?> |
|
| 441 | + $this->extra_tablenav($which); |
|
| 442 | + $this->pagination($which); |
|
| 443 | + ?> |
|
| 444 | 444 | |
| 445 | 445 | <br class="clear" /> |
| 446 | 446 | </div> |
| 447 | 447 | <?php |
| 448 | - } |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * _filters |
|
| 453 | - * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 454 | - * button. |
|
| 455 | - * |
|
| 456 | - * @access private |
|
| 457 | - * @return void echos html showing filters |
|
| 458 | - */ |
|
| 459 | - private function _filters() |
|
| 460 | - { |
|
| 461 | - $classname = get_class($this); |
|
| 462 | - $filters = apply_filters( |
|
| 463 | - "FHEE__{$classname}__filters", |
|
| 464 | - (array) $this->_get_table_filters(), |
|
| 465 | - $this, |
|
| 466 | - $this->_screen |
|
| 467 | - ); |
|
| 468 | - |
|
| 469 | - if (empty($filters)) { |
|
| 470 | - return; |
|
| 471 | - } |
|
| 472 | - foreach ($filters as $filter) { |
|
| 473 | - echo wp_kses($filter, AllowedTags::getWithFormTags()); |
|
| 474 | - } |
|
| 475 | - // add filter button at end |
|
| 476 | - echo '<input type="submit" class="button-secondary" value="' |
|
| 477 | - . esc_html__('Filter', 'event_espresso') |
|
| 478 | - . '" id="post-query-submit" />'; |
|
| 479 | - // add reset filters button at end |
|
| 480 | - echo '<a class="button button-secondary" href="' |
|
| 481 | - . esc_url_raw($this->_admin_page->get_current_page_view_url()) |
|
| 482 | - . '" style="display:inline-block">' |
|
| 483 | - . esc_html__('Reset Filters', 'event_espresso') |
|
| 484 | - . '</a>'; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * Callback for 'list_table_primary_column' WordPress filter |
|
| 490 | - * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 491 | - * column when class is instantiated. |
|
| 492 | - * |
|
| 493 | - * @param string $column_name |
|
| 494 | - * @return string |
|
| 495 | - * @see WP_List_Table::get_primary_column_name |
|
| 496 | - */ |
|
| 497 | - public function set_primary_column($column_name) |
|
| 498 | - { |
|
| 499 | - return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * |
|
| 505 | - */ |
|
| 506 | - public function prepare_items() |
|
| 507 | - { |
|
| 508 | - |
|
| 509 | - $this->_set_column_info(); |
|
| 510 | - // $this->_column_headers = $this->get_column_info(); |
|
| 511 | - $total_items = $this->_all_data_count; |
|
| 512 | - $this->process_bulk_action(); |
|
| 513 | - |
|
| 514 | - $this->items = $this->_data; |
|
| 515 | - $this->set_pagination_args( |
|
| 516 | - [ |
|
| 517 | - 'total_items' => $total_items, |
|
| 518 | - 'per_page' => $this->_per_page, |
|
| 519 | - 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 520 | - ] |
|
| 521 | - ); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * @param object|array $item |
|
| 527 | - * @return string html content for the column |
|
| 528 | - */ |
|
| 529 | - protected function column_cb($item) |
|
| 530 | - { |
|
| 531 | - return ''; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * This column is the default for when there is no defined column method for a registered column. |
|
| 537 | - * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 538 | - * |
|
| 539 | - * @param EE_Base_Class $item |
|
| 540 | - * @param string $column_name The column being called. |
|
| 541 | - * @return string html content for the column |
|
| 542 | - */ |
|
| 543 | - public function column_default($item, $column_name) |
|
| 544 | - { |
|
| 545 | - /** |
|
| 546 | - * Dynamic hook allowing for adding additional column content in this list table. |
|
| 547 | - * Note that $this->screen->id is in the format |
|
| 548 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 549 | - * table it is: event-espresso_page_espresso_messages. |
|
| 550 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 551 | - * hook prefix ("event-espresso") will be different. |
|
| 552 | - */ |
|
| 553 | - ob_start(); |
|
| 554 | - do_action( |
|
| 555 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 556 | - $item, |
|
| 557 | - $this->_screen |
|
| 558 | - ); |
|
| 559 | - return ob_get_clean(); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Get a list of columns. The format is: |
|
| 565 | - * 'internal-name' => 'Title' |
|
| 566 | - * |
|
| 567 | - * @return array |
|
| 568 | - * @since 3.1.0 |
|
| 569 | - * @access public |
|
| 570 | - * @abstract |
|
| 571 | - */ |
|
| 572 | - public function get_columns() |
|
| 573 | - { |
|
| 574 | - /** |
|
| 575 | - * Dynamic hook allowing for adding additional columns in this list table. |
|
| 576 | - * Note that $this->screen->id is in the format |
|
| 577 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 578 | - * table it is: event-espresso_page_espresso_messages. |
|
| 579 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 580 | - * hook prefix ("event-espresso") will be different. |
|
| 581 | - * |
|
| 582 | - * @var array |
|
| 583 | - */ |
|
| 584 | - return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Get an associative array ( id => link ) with the list |
|
| 590 | - * of views available on this table. |
|
| 591 | - * |
|
| 592 | - * @return array |
|
| 593 | - * @since 3.1.0 |
|
| 594 | - * @access protected |
|
| 595 | - */ |
|
| 596 | - public function get_views() |
|
| 597 | - { |
|
| 598 | - return $this->_views; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Generate the views html. |
|
| 604 | - */ |
|
| 605 | - public function display_views() |
|
| 606 | - { |
|
| 607 | - $views = $this->get_views(); |
|
| 608 | - $assembled_views = []; |
|
| 609 | - |
|
| 610 | - if (empty($views)) { |
|
| 611 | - return; |
|
| 612 | - } |
|
| 613 | - echo "<ul class='subsubsub'>\n"; |
|
| 614 | - foreach ($views as $view) { |
|
| 615 | - $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 616 | - if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 617 | - $filter = "<li"; |
|
| 618 | - $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 619 | - $filter .= ">"; |
|
| 620 | - $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 621 | - $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 622 | - $filter .= '</li>'; |
|
| 623 | - $assembled_views[ $view['slug'] ] = $filter; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - echo ! empty($assembled_views) |
|
| 628 | - ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 629 | - : ''; |
|
| 630 | - echo "</ul>"; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * Generates content for a single row of the table |
|
| 636 | - * |
|
| 637 | - * @param EE_Base_Class $item The current item |
|
| 638 | - * @since 4.1 |
|
| 639 | - * @access public |
|
| 640 | - */ |
|
| 641 | - public function single_row($item) |
|
| 642 | - { |
|
| 643 | - $row_class = $this->_get_row_class($item); |
|
| 644 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 645 | - $this->single_row_columns($item); // already escaped |
|
| 646 | - echo '</tr>'; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * This simply sets up the row class for the table rows. |
|
| 652 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 653 | - * |
|
| 654 | - * @param EE_Base_Class $item the current item |
|
| 655 | - * @return string |
|
| 656 | - */ |
|
| 657 | - protected function _get_row_class($item) |
|
| 658 | - { |
|
| 659 | - static $row_class = ''; |
|
| 660 | - $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 661 | - |
|
| 662 | - $new_row_class = $row_class; |
|
| 663 | - |
|
| 664 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 665 | - $new_row_class .= ' rowsortable'; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - return $new_row_class; |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * @return array |
|
| 674 | - */ |
|
| 675 | - public function get_sortable_columns() |
|
| 676 | - { |
|
| 677 | - return (array) $this->_sortable_columns; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * @return string |
|
| 683 | - */ |
|
| 684 | - public function get_ajax_sorting_callback() |
|
| 685 | - { |
|
| 686 | - return $this->_ajax_sorting_callback; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * @return array |
|
| 692 | - */ |
|
| 693 | - public function get_hidden_columns() |
|
| 694 | - { |
|
| 695 | - $user_id = get_current_user_id(); |
|
| 696 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 697 | - if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 698 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 699 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 700 | - } |
|
| 701 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 702 | - return (array) get_user_option($ref, $user_id); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Generates the columns for a single row of the table. |
|
| 708 | - * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 709 | - * column. |
|
| 710 | - * |
|
| 711 | - * @param EE_Base_Class $item The current item |
|
| 712 | - * @since 3.1.0 |
|
| 713 | - */ |
|
| 714 | - public function single_row_columns($item) |
|
| 715 | - { |
|
| 716 | - list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
| 717 | - |
|
| 718 | - foreach ($columns as $column_name => $column_display_name) { |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 722 | - * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 723 | - */ |
|
| 724 | - $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 725 | - |
|
| 726 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 727 | - if ($primary === $column_name) { |
|
| 728 | - $classes .= ' has-row-actions column-primary'; |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 732 | - |
|
| 733 | - $class = 'class="' . esc_attr($classes) . '"'; |
|
| 734 | - |
|
| 735 | - $attributes = "{$class}{$data}"; |
|
| 736 | - |
|
| 737 | - if ($column_name === 'cb') { |
|
| 738 | - echo '<th scope="row" class="check-column">'; |
|
| 739 | - echo apply_filters( |
|
| 740 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 741 | - $this->column_cb($item), // already escaped |
|
| 742 | - $item, |
|
| 743 | - $this |
|
| 744 | - ); |
|
| 745 | - echo '</th>'; |
|
| 746 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 747 | - echo "<td $attributes>"; // already escaped |
|
| 748 | - echo apply_filters( |
|
| 749 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 750 | - call_user_func([$this, 'column_' . $column_name], $item), |
|
| 751 | - $item, |
|
| 752 | - $this |
|
| 753 | - ); |
|
| 754 | - echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 755 | - echo "</td>"; |
|
| 756 | - } else { |
|
| 757 | - echo "<td $attributes>"; // already escaped |
|
| 758 | - echo apply_filters( |
|
| 759 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 760 | - $this->column_default($item, $column_name), |
|
| 761 | - $item, |
|
| 762 | - $column_name, |
|
| 763 | - $this |
|
| 764 | - ); |
|
| 765 | - echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 766 | - echo "</td>"; |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Extra controls to be displayed between bulk actions and pagination |
|
| 774 | - * |
|
| 775 | - * @access public |
|
| 776 | - * @param string $which |
|
| 777 | - * @throws EE_Error |
|
| 778 | - */ |
|
| 779 | - public function extra_tablenav($which) |
|
| 780 | - { |
|
| 781 | - if ($which === 'top') { |
|
| 782 | - $this->_filters(); |
|
| 783 | - echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags()); |
|
| 784 | - } else { |
|
| 785 | - echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 786 | - foreach ($this->_bottom_buttons as $type => $action) { |
|
| 787 | - $route = isset($action['route']) ? $action['route'] : ''; |
|
| 788 | - $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
| 789 | - // already escaped |
|
| 790 | - echo wp_kses($this->_admin_page->get_action_link_or_button( |
|
| 791 | - $route, |
|
| 792 | - $type, |
|
| 793 | - $extra_request, |
|
| 794 | - 'button button-secondary' |
|
| 795 | - ), AllowedTags::getWithFormTags()); |
|
| 796 | - } |
|
| 797 | - do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 798 | - echo '</div>'; |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * Get an associative array ( option_name => option_title ) with the list |
|
| 805 | - * of bulk actions available on this table. |
|
| 806 | - * |
|
| 807 | - * @return array |
|
| 808 | - * @since 3.1.0 |
|
| 809 | - * @access protected |
|
| 810 | - */ |
|
| 811 | - public function get_bulk_actions() |
|
| 812 | - { |
|
| 813 | - return (array) $this->_get_bulk_actions(); |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - /** |
|
| 818 | - * Processing bulk actions. |
|
| 819 | - */ |
|
| 820 | - public function process_bulk_action() |
|
| 821 | - { |
|
| 822 | - // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 823 | - // reference in case there is a case where it gets used. |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * returns the EE admin page this list table is associated with |
|
| 829 | - * |
|
| 830 | - * @return EE_Admin_Page |
|
| 831 | - */ |
|
| 832 | - public function get_admin_page() |
|
| 833 | - { |
|
| 834 | - return $this->_admin_page; |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * A "helper" function for all children to provide an html string of |
|
| 840 | - * actions to output in their content. It is preferable for child classes |
|
| 841 | - * to use this method for generating their actions content so that it's |
|
| 842 | - * filterable by plugins |
|
| 843 | - * |
|
| 844 | - * @param string $action_container what are the html container |
|
| 845 | - * elements for this actions string? |
|
| 846 | - * @param string $action_class What class is for the container |
|
| 847 | - * element. |
|
| 848 | - * @param string $action_items The contents for the action items |
|
| 849 | - * container. This is filtered before |
|
| 850 | - * returned. |
|
| 851 | - * @param string $action_id What id (optional) is used for the |
|
| 852 | - * container element. |
|
| 853 | - * @param EE_Base_Class $item The object for the column displaying |
|
| 854 | - * the actions. |
|
| 855 | - * @return string The assembled action elements container. |
|
| 856 | - */ |
|
| 857 | - protected function _action_string( |
|
| 858 | - $action_items, |
|
| 859 | - $item, |
|
| 860 | - $action_container = 'ul', |
|
| 861 | - $action_class = '', |
|
| 862 | - $action_id = '' |
|
| 863 | - ) { |
|
| 864 | - $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 865 | - $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 866 | - $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 867 | - $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 868 | - try { |
|
| 869 | - $content = apply_filters( |
|
| 870 | - 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 871 | - $action_items, |
|
| 872 | - $item, |
|
| 873 | - $this |
|
| 874 | - ); |
|
| 875 | - } catch (Exception $e) { |
|
| 876 | - if (WP_DEBUG) { |
|
| 877 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 878 | - } |
|
| 879 | - $content = $action_items; |
|
| 880 | - } |
|
| 881 | - return "{$open_tag}{$content}{$close_tag}"; |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * @return string |
|
| 887 | - */ |
|
| 888 | - protected function getReturnUrl() |
|
| 889 | - { |
|
| 890 | - $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 891 | - $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 892 | - return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 893 | - } |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * _filters |
|
| 453 | + * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 454 | + * button. |
|
| 455 | + * |
|
| 456 | + * @access private |
|
| 457 | + * @return void echos html showing filters |
|
| 458 | + */ |
|
| 459 | + private function _filters() |
|
| 460 | + { |
|
| 461 | + $classname = get_class($this); |
|
| 462 | + $filters = apply_filters( |
|
| 463 | + "FHEE__{$classname}__filters", |
|
| 464 | + (array) $this->_get_table_filters(), |
|
| 465 | + $this, |
|
| 466 | + $this->_screen |
|
| 467 | + ); |
|
| 468 | + |
|
| 469 | + if (empty($filters)) { |
|
| 470 | + return; |
|
| 471 | + } |
|
| 472 | + foreach ($filters as $filter) { |
|
| 473 | + echo wp_kses($filter, AllowedTags::getWithFormTags()); |
|
| 474 | + } |
|
| 475 | + // add filter button at end |
|
| 476 | + echo '<input type="submit" class="button-secondary" value="' |
|
| 477 | + . esc_html__('Filter', 'event_espresso') |
|
| 478 | + . '" id="post-query-submit" />'; |
|
| 479 | + // add reset filters button at end |
|
| 480 | + echo '<a class="button button-secondary" href="' |
|
| 481 | + . esc_url_raw($this->_admin_page->get_current_page_view_url()) |
|
| 482 | + . '" style="display:inline-block">' |
|
| 483 | + . esc_html__('Reset Filters', 'event_espresso') |
|
| 484 | + . '</a>'; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * Callback for 'list_table_primary_column' WordPress filter |
|
| 490 | + * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 491 | + * column when class is instantiated. |
|
| 492 | + * |
|
| 493 | + * @param string $column_name |
|
| 494 | + * @return string |
|
| 495 | + * @see WP_List_Table::get_primary_column_name |
|
| 496 | + */ |
|
| 497 | + public function set_primary_column($column_name) |
|
| 498 | + { |
|
| 499 | + return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * |
|
| 505 | + */ |
|
| 506 | + public function prepare_items() |
|
| 507 | + { |
|
| 508 | + |
|
| 509 | + $this->_set_column_info(); |
|
| 510 | + // $this->_column_headers = $this->get_column_info(); |
|
| 511 | + $total_items = $this->_all_data_count; |
|
| 512 | + $this->process_bulk_action(); |
|
| 513 | + |
|
| 514 | + $this->items = $this->_data; |
|
| 515 | + $this->set_pagination_args( |
|
| 516 | + [ |
|
| 517 | + 'total_items' => $total_items, |
|
| 518 | + 'per_page' => $this->_per_page, |
|
| 519 | + 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 520 | + ] |
|
| 521 | + ); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * @param object|array $item |
|
| 527 | + * @return string html content for the column |
|
| 528 | + */ |
|
| 529 | + protected function column_cb($item) |
|
| 530 | + { |
|
| 531 | + return ''; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * This column is the default for when there is no defined column method for a registered column. |
|
| 537 | + * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 538 | + * |
|
| 539 | + * @param EE_Base_Class $item |
|
| 540 | + * @param string $column_name The column being called. |
|
| 541 | + * @return string html content for the column |
|
| 542 | + */ |
|
| 543 | + public function column_default($item, $column_name) |
|
| 544 | + { |
|
| 545 | + /** |
|
| 546 | + * Dynamic hook allowing for adding additional column content in this list table. |
|
| 547 | + * Note that $this->screen->id is in the format |
|
| 548 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 549 | + * table it is: event-espresso_page_espresso_messages. |
|
| 550 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 551 | + * hook prefix ("event-espresso") will be different. |
|
| 552 | + */ |
|
| 553 | + ob_start(); |
|
| 554 | + do_action( |
|
| 555 | + 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 556 | + $item, |
|
| 557 | + $this->_screen |
|
| 558 | + ); |
|
| 559 | + return ob_get_clean(); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Get a list of columns. The format is: |
|
| 565 | + * 'internal-name' => 'Title' |
|
| 566 | + * |
|
| 567 | + * @return array |
|
| 568 | + * @since 3.1.0 |
|
| 569 | + * @access public |
|
| 570 | + * @abstract |
|
| 571 | + */ |
|
| 572 | + public function get_columns() |
|
| 573 | + { |
|
| 574 | + /** |
|
| 575 | + * Dynamic hook allowing for adding additional columns in this list table. |
|
| 576 | + * Note that $this->screen->id is in the format |
|
| 577 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 578 | + * table it is: event-espresso_page_espresso_messages. |
|
| 579 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 580 | + * hook prefix ("event-espresso") will be different. |
|
| 581 | + * |
|
| 582 | + * @var array |
|
| 583 | + */ |
|
| 584 | + return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Get an associative array ( id => link ) with the list |
|
| 590 | + * of views available on this table. |
|
| 591 | + * |
|
| 592 | + * @return array |
|
| 593 | + * @since 3.1.0 |
|
| 594 | + * @access protected |
|
| 595 | + */ |
|
| 596 | + public function get_views() |
|
| 597 | + { |
|
| 598 | + return $this->_views; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Generate the views html. |
|
| 604 | + */ |
|
| 605 | + public function display_views() |
|
| 606 | + { |
|
| 607 | + $views = $this->get_views(); |
|
| 608 | + $assembled_views = []; |
|
| 609 | + |
|
| 610 | + if (empty($views)) { |
|
| 611 | + return; |
|
| 612 | + } |
|
| 613 | + echo "<ul class='subsubsub'>\n"; |
|
| 614 | + foreach ($views as $view) { |
|
| 615 | + $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 616 | + if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 617 | + $filter = "<li"; |
|
| 618 | + $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 619 | + $filter .= ">"; |
|
| 620 | + $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 621 | + $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 622 | + $filter .= '</li>'; |
|
| 623 | + $assembled_views[ $view['slug'] ] = $filter; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + echo ! empty($assembled_views) |
|
| 628 | + ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 629 | + : ''; |
|
| 630 | + echo "</ul>"; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * Generates content for a single row of the table |
|
| 636 | + * |
|
| 637 | + * @param EE_Base_Class $item The current item |
|
| 638 | + * @since 4.1 |
|
| 639 | + * @access public |
|
| 640 | + */ |
|
| 641 | + public function single_row($item) |
|
| 642 | + { |
|
| 643 | + $row_class = $this->_get_row_class($item); |
|
| 644 | + echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 645 | + $this->single_row_columns($item); // already escaped |
|
| 646 | + echo '</tr>'; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * This simply sets up the row class for the table rows. |
|
| 652 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 653 | + * |
|
| 654 | + * @param EE_Base_Class $item the current item |
|
| 655 | + * @return string |
|
| 656 | + */ |
|
| 657 | + protected function _get_row_class($item) |
|
| 658 | + { |
|
| 659 | + static $row_class = ''; |
|
| 660 | + $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 661 | + |
|
| 662 | + $new_row_class = $row_class; |
|
| 663 | + |
|
| 664 | + if (! empty($this->_ajax_sorting_callback)) { |
|
| 665 | + $new_row_class .= ' rowsortable'; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + return $new_row_class; |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * @return array |
|
| 674 | + */ |
|
| 675 | + public function get_sortable_columns() |
|
| 676 | + { |
|
| 677 | + return (array) $this->_sortable_columns; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * @return string |
|
| 683 | + */ |
|
| 684 | + public function get_ajax_sorting_callback() |
|
| 685 | + { |
|
| 686 | + return $this->_ajax_sorting_callback; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * @return array |
|
| 692 | + */ |
|
| 693 | + public function get_hidden_columns() |
|
| 694 | + { |
|
| 695 | + $user_id = get_current_user_id(); |
|
| 696 | + $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 697 | + if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 698 | + update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 699 | + update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 700 | + } |
|
| 701 | + $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 702 | + return (array) get_user_option($ref, $user_id); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Generates the columns for a single row of the table. |
|
| 708 | + * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 709 | + * column. |
|
| 710 | + * |
|
| 711 | + * @param EE_Base_Class $item The current item |
|
| 712 | + * @since 3.1.0 |
|
| 713 | + */ |
|
| 714 | + public function single_row_columns($item) |
|
| 715 | + { |
|
| 716 | + list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
| 717 | + |
|
| 718 | + foreach ($columns as $column_name => $column_display_name) { |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 722 | + * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 723 | + */ |
|
| 724 | + $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 725 | + |
|
| 726 | + $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 727 | + if ($primary === $column_name) { |
|
| 728 | + $classes .= ' has-row-actions column-primary'; |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 732 | + |
|
| 733 | + $class = 'class="' . esc_attr($classes) . '"'; |
|
| 734 | + |
|
| 735 | + $attributes = "{$class}{$data}"; |
|
| 736 | + |
|
| 737 | + if ($column_name === 'cb') { |
|
| 738 | + echo '<th scope="row" class="check-column">'; |
|
| 739 | + echo apply_filters( |
|
| 740 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 741 | + $this->column_cb($item), // already escaped |
|
| 742 | + $item, |
|
| 743 | + $this |
|
| 744 | + ); |
|
| 745 | + echo '</th>'; |
|
| 746 | + } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 747 | + echo "<td $attributes>"; // already escaped |
|
| 748 | + echo apply_filters( |
|
| 749 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 750 | + call_user_func([$this, 'column_' . $column_name], $item), |
|
| 751 | + $item, |
|
| 752 | + $this |
|
| 753 | + ); |
|
| 754 | + echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 755 | + echo "</td>"; |
|
| 756 | + } else { |
|
| 757 | + echo "<td $attributes>"; // already escaped |
|
| 758 | + echo apply_filters( |
|
| 759 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 760 | + $this->column_default($item, $column_name), |
|
| 761 | + $item, |
|
| 762 | + $column_name, |
|
| 763 | + $this |
|
| 764 | + ); |
|
| 765 | + echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 766 | + echo "</td>"; |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Extra controls to be displayed between bulk actions and pagination |
|
| 774 | + * |
|
| 775 | + * @access public |
|
| 776 | + * @param string $which |
|
| 777 | + * @throws EE_Error |
|
| 778 | + */ |
|
| 779 | + public function extra_tablenav($which) |
|
| 780 | + { |
|
| 781 | + if ($which === 'top') { |
|
| 782 | + $this->_filters(); |
|
| 783 | + echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags()); |
|
| 784 | + } else { |
|
| 785 | + echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 786 | + foreach ($this->_bottom_buttons as $type => $action) { |
|
| 787 | + $route = isset($action['route']) ? $action['route'] : ''; |
|
| 788 | + $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
| 789 | + // already escaped |
|
| 790 | + echo wp_kses($this->_admin_page->get_action_link_or_button( |
|
| 791 | + $route, |
|
| 792 | + $type, |
|
| 793 | + $extra_request, |
|
| 794 | + 'button button-secondary' |
|
| 795 | + ), AllowedTags::getWithFormTags()); |
|
| 796 | + } |
|
| 797 | + do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 798 | + echo '</div>'; |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * Get an associative array ( option_name => option_title ) with the list |
|
| 805 | + * of bulk actions available on this table. |
|
| 806 | + * |
|
| 807 | + * @return array |
|
| 808 | + * @since 3.1.0 |
|
| 809 | + * @access protected |
|
| 810 | + */ |
|
| 811 | + public function get_bulk_actions() |
|
| 812 | + { |
|
| 813 | + return (array) $this->_get_bulk_actions(); |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + /** |
|
| 818 | + * Processing bulk actions. |
|
| 819 | + */ |
|
| 820 | + public function process_bulk_action() |
|
| 821 | + { |
|
| 822 | + // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 823 | + // reference in case there is a case where it gets used. |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * returns the EE admin page this list table is associated with |
|
| 829 | + * |
|
| 830 | + * @return EE_Admin_Page |
|
| 831 | + */ |
|
| 832 | + public function get_admin_page() |
|
| 833 | + { |
|
| 834 | + return $this->_admin_page; |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * A "helper" function for all children to provide an html string of |
|
| 840 | + * actions to output in their content. It is preferable for child classes |
|
| 841 | + * to use this method for generating their actions content so that it's |
|
| 842 | + * filterable by plugins |
|
| 843 | + * |
|
| 844 | + * @param string $action_container what are the html container |
|
| 845 | + * elements for this actions string? |
|
| 846 | + * @param string $action_class What class is for the container |
|
| 847 | + * element. |
|
| 848 | + * @param string $action_items The contents for the action items |
|
| 849 | + * container. This is filtered before |
|
| 850 | + * returned. |
|
| 851 | + * @param string $action_id What id (optional) is used for the |
|
| 852 | + * container element. |
|
| 853 | + * @param EE_Base_Class $item The object for the column displaying |
|
| 854 | + * the actions. |
|
| 855 | + * @return string The assembled action elements container. |
|
| 856 | + */ |
|
| 857 | + protected function _action_string( |
|
| 858 | + $action_items, |
|
| 859 | + $item, |
|
| 860 | + $action_container = 'ul', |
|
| 861 | + $action_class = '', |
|
| 862 | + $action_id = '' |
|
| 863 | + ) { |
|
| 864 | + $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 865 | + $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 866 | + $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 867 | + $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 868 | + try { |
|
| 869 | + $content = apply_filters( |
|
| 870 | + 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 871 | + $action_items, |
|
| 872 | + $item, |
|
| 873 | + $this |
|
| 874 | + ); |
|
| 875 | + } catch (Exception $e) { |
|
| 876 | + if (WP_DEBUG) { |
|
| 877 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 878 | + } |
|
| 879 | + $content = $action_items; |
|
| 880 | + } |
|
| 881 | + return "{$open_tag}{$content}{$close_tag}"; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * @return string |
|
| 887 | + */ |
|
| 888 | + protected function getReturnUrl() |
|
| 889 | + { |
|
| 890 | + $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 891 | + $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 892 | + return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 893 | + } |
|
| 894 | 894 | } |
@@ -2,8 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 4 | 4 | |
| 5 | -if (! class_exists('WP_List_Table')) { |
|
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 5 | +if ( ! class_exists('WP_List_Table')) { |
|
| 6 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
@@ -206,13 +206,13 @@ discard block |
||
| 206 | 206 | $this->_view = $this->_admin_page->get_view(); |
| 207 | 207 | $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
| 208 | 208 | $this->_current_page = $this->get_pagenum(); |
| 209 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 209 | + $this->_screen = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view(); |
|
| 210 | 210 | $this->_yes_no = [ |
| 211 | 211 | esc_html__('No', 'event_espresso'), |
| 212 | 212 | esc_html__('Yes', 'event_espresso') |
| 213 | 213 | ]; |
| 214 | 214 | |
| 215 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 215 | + $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page'); |
|
| 216 | 216 | |
| 217 | 217 | $this->_setup_data(); |
| 218 | 218 | $this->_add_view_counts(); |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
| 293 | 293 | // if action is STILL empty, then we set it to default |
| 294 | 294 | $action = empty($action) ? 'default' : $action; |
| 295 | - $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 296 | - $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 297 | - $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 295 | + $field = '<input type="hidden" name="page" value="'.esc_attr($this->_req_data['page']).'" />'."\n"; |
|
| 296 | + $field .= '<input type="hidden" name="route" value="'.esc_attr($action).'" />'."\n"; |
|
| 297 | + $field .= '<input type="hidden" name="perpage" value="'.esc_attr($this->_per_page).'" />'."\n"; |
|
| 298 | 298 | |
| 299 | 299 | $bulk_actions = $this->_get_bulk_actions(); |
| 300 | 300 | foreach ($bulk_actions as $bulk_action => $label) { |
| 301 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 302 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 301 | + $field .= '<input type="hidden" name="'.$bulk_action.'_nonce"' |
|
| 302 | + . ' value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n"; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | return $field; |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | |
| 347 | 347 | $data = (array) $data; |
| 348 | 348 | |
| 349 | - if (! isset($data[1])) { |
|
| 349 | + if ( ! isset($data[1])) { |
|
| 350 | 350 | $_data[1] = false; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - $sortable[ $id ] = $_data; |
|
| 353 | + $sortable[$id] = $_data; |
|
| 354 | 354 | } |
| 355 | 355 | $primary = $this->get_primary_column_name(); |
| 356 | 356 | $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | // for that page route and skip adding the bulk action if no access for the current logged in user. |
| 411 | 411 | foreach ($args['bulk_action'] as $route => $label) { |
| 412 | 412 | if ($this->_admin_page->check_user_access($route, true)) { |
| 413 | - $actions[ $route ] = $label; |
|
| 413 | + $actions[$route] = $label; |
|
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | public function display_tablenav($which) |
| 430 | 430 | { |
| 431 | 431 | if ('top' === $which) { |
| 432 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 432 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
| 433 | 433 | } |
| 434 | 434 | ?> |
| 435 | 435 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | */ |
| 553 | 553 | ob_start(); |
| 554 | 554 | do_action( |
| 555 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 555 | + 'AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id, |
|
| 556 | 556 | $item, |
| 557 | 557 | $this->_screen |
| 558 | 558 | ); |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | * |
| 582 | 582 | * @var array |
| 583 | 583 | */ |
| 584 | - return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 584 | + return apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | |
@@ -615,12 +615,12 @@ discard block |
||
| 615 | 615 | $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
| 616 | 616 | if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
| 617 | 617 | $filter = "<li"; |
| 618 | - $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 618 | + $filter .= $view['class'] ? " class='".esc_attr($view['class'])."'" : ''; |
|
| 619 | 619 | $filter .= ">"; |
| 620 | - $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 621 | - $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 620 | + $filter .= '<a href="'.esc_url_raw($view['url']).'">'.esc_html($view['label']).'</a>'; |
|
| 621 | + $filter .= '<span class="count">('.$count.')</span>'; |
|
| 622 | 622 | $filter .= '</li>'; |
| 623 | - $assembled_views[ $view['slug'] ] = $filter; |
|
| 623 | + $assembled_views[$view['slug']] = $filter; |
|
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | public function single_row($item) |
| 642 | 642 | { |
| 643 | 643 | $row_class = $this->_get_row_class($item); |
| 644 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 644 | + echo '<tr class="'.esc_attr($row_class).'">'; |
|
| 645 | 645 | $this->single_row_columns($item); // already escaped |
| 646 | 646 | echo '</tr>'; |
| 647 | 647 | } |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | |
| 662 | 662 | $new_row_class = $row_class; |
| 663 | 663 | |
| 664 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 664 | + if ( ! empty($this->_ajax_sorting_callback)) { |
|
| 665 | 665 | $new_row_class .= ' rowsortable'; |
| 666 | 666 | } |
| 667 | 667 | |
@@ -693,12 +693,12 @@ discard block |
||
| 693 | 693 | public function get_hidden_columns() |
| 694 | 694 | { |
| 695 | 695 | $user_id = get_current_user_id(); |
| 696 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 696 | + $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id); |
|
| 697 | 697 | if (empty($has_default) && ! empty($this->_hidden_columns)) { |
| 698 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 699 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 698 | + update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true); |
|
| 699 | + update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true); |
|
| 700 | 700 | } |
| 701 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 701 | + $ref = 'manage'.$this->screen->id.'columnshidden'; |
|
| 702 | 702 | return (array) get_user_option($ref, $user_id); |
| 703 | 703 | } |
| 704 | 704 | |
@@ -723,14 +723,14 @@ discard block |
||
| 723 | 723 | */ |
| 724 | 724 | $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
| 725 | 725 | |
| 726 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 726 | + $classes = $column_name.' column-'.$column_name.$hidden_class; |
|
| 727 | 727 | if ($primary === $column_name) { |
| 728 | 728 | $classes .= ' has-row-actions column-primary'; |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 731 | + $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"'; |
|
| 732 | 732 | |
| 733 | - $class = 'class="' . esc_attr($classes) . '"'; |
|
| 733 | + $class = 'class="'.esc_attr($classes).'"'; |
|
| 734 | 734 | |
| 735 | 735 | $attributes = "{$class}{$data}"; |
| 736 | 736 | |
@@ -743,11 +743,11 @@ discard block |
||
| 743 | 743 | $this |
| 744 | 744 | ); |
| 745 | 745 | echo '</th>'; |
| 746 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 746 | + } elseif (method_exists($this, 'column_'.$column_name)) { |
|
| 747 | 747 | echo "<td $attributes>"; // already escaped |
| 748 | 748 | echo apply_filters( |
| 749 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 750 | - call_user_func([$this, 'column_' . $column_name], $item), |
|
| 749 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content', |
|
| 750 | + call_user_func([$this, 'column_'.$column_name], $item), |
|
| 751 | 751 | $item, |
| 752 | 752 | $this |
| 753 | 753 | ); |
@@ -861,10 +861,10 @@ discard block |
||
| 861 | 861 | $action_class = '', |
| 862 | 862 | $action_id = '' |
| 863 | 863 | ) { |
| 864 | - $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 865 | - $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 866 | - $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 867 | - $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 864 | + $action_class = ! empty($action_class) ? ' class="'.esc_attr($action_class).'"' : ''; |
|
| 865 | + $action_id = ! empty($action_id) ? ' id="'.esc_attr($action_id).'"' : ''; |
|
| 866 | + $open_tag = ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : ''; |
|
| 867 | + $close_tag = ! empty($action_container) ? '</'.$action_container.'>' : ''; |
|
| 868 | 868 | try { |
| 869 | 869 | $content = apply_filters( |
| 870 | 870 | 'FHEE__EE_Admin_List_Table___action_string__action_items', |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | protected function getLoader() |
| 166 | 166 | { |
| 167 | - if (! $this->loader instanceof LoaderInterface) { |
|
| 167 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
| 168 | 168 | $this->loader = LoaderFactory::getLoader(); |
| 169 | 169 | } |
| 170 | 170 | return $this->loader; |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | ], |
| 189 | 189 | $this->_cpt_routes |
| 190 | 190 | ); |
| 191 | - $cpt_route_action = isset($this->_cpt_routes[ $this->raw_req_action ]) |
|
| 192 | - ? $this->_cpt_routes[ $this->raw_req_action ] |
|
| 191 | + $cpt_route_action = isset($this->_cpt_routes[$this->raw_req_action]) |
|
| 192 | + ? $this->_cpt_routes[$this->raw_req_action] |
|
| 193 | 193 | : null; |
| 194 | 194 | // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page |
| 195 | 195 | $page = $this->raw_req_page ?: $this->page_slug; |
| 196 | 196 | $page = $cpt_route_action ?: $page; |
| 197 | 197 | $this->_cpt_object = get_post_type_object($page); |
| 198 | 198 | // tweak pagenow for page loading. |
| 199 | - if (! $this->_pagenow_map) { |
|
| 199 | + if ( ! $this->_pagenow_map) { |
|
| 200 | 200 | $this->_pagenow_map = [ |
| 201 | 201 | 'create_new' => 'post-new.php', |
| 202 | 202 | 'edit' => 'post.php', |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | // possibly reset pagenow. |
| 223 | 223 | if ( |
| 224 | 224 | $this->page_slug === $this->raw_req_page |
| 225 | - && isset($this->_pagenow_map[ $this->raw_req_action ]) |
|
| 225 | + && isset($this->_pagenow_map[$this->raw_req_action]) |
|
| 226 | 226 | ) { |
| 227 | 227 | global $pagenow, $hook_suffix; |
| 228 | - $pagenow = $this->_pagenow_map[ $this->raw_req_action ]; |
|
| 228 | + $pagenow = $this->_pagenow_map[$this->raw_req_action]; |
|
| 229 | 229 | $hook_suffix = $pagenow; |
| 230 | 230 | } |
| 231 | 231 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | if (empty($wp_meta_boxes)) { |
| 258 | 258 | return; |
| 259 | 259 | } |
| 260 | - $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : []; |
|
| 260 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : []; |
|
| 261 | 261 | foreach ($current_metaboxes as $box_context) { |
| 262 | 262 | foreach ($box_context as $box_details) { |
| 263 | 263 | foreach ($box_details as $box) { |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | $this |
| 292 | 292 | ); |
| 293 | 293 | $containers = apply_filters( |
| 294 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 294 | + 'FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
| 295 | 295 | $containers, |
| 296 | 296 | $this |
| 297 | 297 | ); |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | protected function _load_page_dependencies() |
| 337 | 337 | { |
| 338 | 338 | // we only add stuff if this is a cpt_route! |
| 339 | - if (! $this->_cpt_route) { |
|
| 339 | + if ( ! $this->_cpt_route) { |
|
| 340 | 340 | parent::_load_page_dependencies(); |
| 341 | 341 | return; |
| 342 | 342 | } |
@@ -360,16 +360,16 @@ discard block |
||
| 360 | 360 | add_filter('pre_get_shortlink', [$this, 'add_shortlink_button_to_editor'], 10, 4); |
| 361 | 361 | // This basically allows us to change the title of the "publish" metabox area |
| 362 | 362 | // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
| 363 | - if (! empty($this->_labels['publishbox'])) { |
|
| 363 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 364 | 364 | $box_label = is_array($this->_labels['publishbox']) |
| 365 | - && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
| 366 | - ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 365 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
| 366 | + ? $this->_labels['publishbox'][$this->_req_action] |
|
| 367 | 367 | : $this->_labels['publishbox']; |
| 368 | 368 | add_meta_box( |
| 369 | 369 | 'submitdiv', |
| 370 | 370 | $box_label, |
| 371 | 371 | 'post_submit_meta_box', |
| 372 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 372 | + $this->_cpt_routes[$this->_req_action], |
|
| 373 | 373 | 'side', |
| 374 | 374 | 'core' |
| 375 | 375 | ); |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | 'page_templates', |
| 381 | 381 | esc_html__('Page Template', 'event_espresso'), |
| 382 | 382 | [$this, 'page_template_meta_box'], |
| 383 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 383 | + $this->_cpt_routes[$this->_req_action], |
|
| 384 | 384 | 'side', |
| 385 | 385 | 'default' |
| 386 | 386 | ); |
@@ -412,8 +412,8 @@ discard block |
||
| 412 | 412 | // This is for any plugins that are doing things properly |
| 413 | 413 | // and hooking into the load page hook for core wp cpt routes. |
| 414 | 414 | global $pagenow; |
| 415 | - add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20); |
|
| 416 | - do_action('load-' . $pagenow); |
|
| 415 | + add_action('load-'.$pagenow, [$this, 'modify_current_screen'], 20); |
|
| 416 | + do_action('load-'.$pagenow); |
|
| 417 | 417 | add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30); |
| 418 | 418 | // we route REALLY early. |
| 419 | 419 | try { |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | 'admin.php?page=espresso_registrations&action=contact_list', |
| 443 | 443 | ], |
| 444 | 444 | 1 => [ |
| 445 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 446 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
| 445 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
| 446 | + 'admin.php?page='.$this->_cpt_object->name, |
|
| 447 | 447 | ], |
| 448 | 448 | ]; |
| 449 | 449 | foreach ($routes_to_match as $route_matches) { |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
| 473 | 473 | ); |
| 474 | 474 | $cpt_args = $custom_post_types->getDefinitions(); |
| 475 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : []; |
|
| 475 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : []; |
|
| 476 | 476 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
| 477 | 477 | |
| 478 | 478 | // if the installed version of WP is > 4.7 we do some additional checks. |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | // if there are $post_templates for this cpt, then we return false for this method because |
| 482 | 482 | // that means we aren't going to load our page template manager and leave that up to the native |
| 483 | 483 | // cpt template manager. |
| 484 | - $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
| 484 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | return $cpt_has_support; |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | |
| 561 | 561 | $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
| 562 | 562 | $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
| 563 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
| 563 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
| 564 | 564 | : ''; |
| 565 | 565 | $template_args = [ |
| 566 | 566 | 'cur_status' => $this->_cpt_model_obj->status(), |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | $template_args['statuses'] = $statuses; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 578 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
| 579 | 579 | EEH_Template::display_template($template, $template_args); |
| 580 | 580 | } |
| 581 | 581 | |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | $nonce = $this->request->getRequestParam('autosavenonce'); |
| 616 | 616 | $this->_verify_nonce($nonce, 'autosave'); |
| 617 | 617 | // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
| 618 | - if (! defined('DOING_AUTOSAVE')) { |
|
| 618 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
| 619 | 619 | define('DOING_AUTOSAVE', true); |
| 620 | 620 | } |
| 621 | 621 | // if we made it here then the nonce checked out. Let's run our methods and actions |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | $this->_template_args['success'] = true; |
| 627 | 627 | } |
| 628 | 628 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
| 629 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 629 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
| 630 | 630 | // now let's return json |
| 631 | 631 | $this->_return_json(); |
| 632 | 632 | } |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | return; |
| 649 | 649 | } |
| 650 | 650 | // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
| 651 | - if (! empty($this->_cpt_object)) { |
|
| 651 | + if ( ! empty($this->_cpt_object)) { |
|
| 652 | 652 | $this->_page_routes = array_merge( |
| 653 | 653 | [ |
| 654 | 654 | 'create_new' => '_create_new_cpt_item', |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | ); |
| 680 | 680 | } |
| 681 | 681 | // load the next section only if this is a matching cpt route as set in the cpt routes array. |
| 682 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
| 682 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
| 683 | 683 | return; |
| 684 | 684 | } |
| 685 | 685 | $this->_cpt_route = true; |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | empty($this->_cpt_model_names) |
| 721 | 721 | || ( |
| 722 | 722 | ! $ignore_route_check |
| 723 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
| 723 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
| 724 | 724 | ) |
| 725 | 725 | || ( |
| 726 | 726 | $this->_cpt_model_obj instanceof EE_CPT_Base |
@@ -738,11 +738,11 @@ discard block |
||
| 738 | 738 | 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
| 739 | 739 | ); |
| 740 | 740 | $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
| 741 | - if (isset($model_names[ $post_type ])) { |
|
| 742 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
| 741 | + if (isset($model_names[$post_type])) { |
|
| 742 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
| 743 | 743 | } |
| 744 | 744 | } else { |
| 745 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
| 745 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
| 746 | 746 | } |
| 747 | 747 | if ($model instanceof EEM_Base) { |
| 748 | 748 | $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
@@ -771,8 +771,8 @@ discard block |
||
| 771 | 771 | $current_route = isset($this->_req_data['current_route']) |
| 772 | 772 | ? $this->_req_data['current_route'] |
| 773 | 773 | : 'shouldneverwork'; |
| 774 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
| 775 | - ? $this->_cpt_routes[ $current_route ] |
|
| 774 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
| 775 | + ? $this->_cpt_routes[$current_route] |
|
| 776 | 776 | : ''; |
| 777 | 777 | add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 3); |
| 778 | 778 | add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 3); |
@@ -781,10 +781,10 @@ discard block |
||
| 781 | 781 | } |
| 782 | 782 | // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
| 783 | 783 | $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
| 784 | - if (! empty($revision)) { |
|
| 784 | + if ( ! empty($revision)) { |
|
| 785 | 785 | $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
| 786 | 786 | // doing a restore? |
| 787 | - if (! empty($action) && $action === 'restore') { |
|
| 787 | + if ( ! empty($action) && $action === 'restore') { |
|
| 788 | 788 | // get post for revision |
| 789 | 789 | $rev_post = get_post($revision); |
| 790 | 790 | $rev_parent = get_post($rev_post->post_parent); |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | { |
| 822 | 822 | $this->_set_model_object($post_id, true, 'trash'); |
| 823 | 823 | // if our cpt object isn't existent then get out immediately. |
| 824 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 824 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 825 | 825 | return; |
| 826 | 826 | } |
| 827 | 827 | $this->trash_cpt_item($post_id); |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | { |
| 841 | 841 | $this->_set_model_object($post_id, true, 'restore'); |
| 842 | 842 | // if our cpt object isn't existent then get out immediately. |
| 843 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 843 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 844 | 844 | return; |
| 845 | 845 | } |
| 846 | 846 | $this->restore_cpt_item($post_id); |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | { |
| 860 | 860 | $this->_set_model_object($post_id, true, 'delete'); |
| 861 | 861 | // if our cpt object isn't existent then get out immediately. |
| 862 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 862 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 863 | 863 | return; |
| 864 | 864 | } |
| 865 | 865 | $this->delete_cpt_item($post_id); |
@@ -878,7 +878,7 @@ discard block |
||
| 878 | 878 | { |
| 879 | 879 | $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
| 880 | 880 | // verify event object |
| 881 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 881 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 882 | 882 | throw new EE_Error( |
| 883 | 883 | sprintf( |
| 884 | 884 | esc_html__( |
@@ -933,13 +933,13 @@ discard block |
||
| 933 | 933 | if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
| 934 | 934 | // setup custom post status object for localize script but only if we've got a cpt object |
| 935 | 935 | $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
| 936 | - if (! empty($statuses)) { |
|
| 936 | + if ( ! empty($statuses)) { |
|
| 937 | 937 | // get ALL statuses! |
| 938 | 938 | $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
| 939 | 939 | // setup object |
| 940 | 940 | $ee_cpt_statuses = []; |
| 941 | 941 | foreach ($statuses as $status => $label) { |
| 942 | - $ee_cpt_statuses[ $status ] = [ |
|
| 942 | + $ee_cpt_statuses[$status] = [ |
|
| 943 | 943 | 'label' => $label, |
| 944 | 944 | 'save_label' => sprintf( |
| 945 | 945 | wp_strip_all_tags(__('Save as %s', 'event_espresso')), |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | } |
| 1010 | 1010 | if ( |
| 1011 | 1011 | 'default' != $this->_req_data['page_template'] |
| 1012 | - && ! isset($page_templates[ $this->_req_data['page_template'] ]) |
|
| 1012 | + && ! isset($page_templates[$this->_req_data['page_template']]) |
|
| 1013 | 1013 | ) { |
| 1014 | 1014 | EE_Error::add_error( |
| 1015 | 1015 | esc_html__('Invalid Page Template.', 'event_espresso'), |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | { |
| 1041 | 1041 | // only do this if we're actually processing one of our CPTs |
| 1042 | 1042 | // if our cpt object isn't existent then get out immediately. |
| 1043 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 1043 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 1044 | 1044 | return; |
| 1045 | 1045 | } |
| 1046 | 1046 | delete_post_meta($post_id, '_wp_trash_meta_status'); |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | // global action |
| 1066 | 1066 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
| 1067 | 1067 | // class specific action so you can limit hooking into a specific page. |
| 1068 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 1068 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | |
@@ -1094,11 +1094,11 @@ discard block |
||
| 1094 | 1094 | public function modify_current_screen() |
| 1095 | 1095 | { |
| 1096 | 1096 | // ONLY do this if the current page_route IS a cpt route |
| 1097 | - if (! $this->_cpt_route) { |
|
| 1097 | + if ( ! $this->_cpt_route) { |
|
| 1098 | 1098 | return; |
| 1099 | 1099 | } |
| 1100 | 1100 | // routing things REALLY early b/c this is a cpt admin page |
| 1101 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
| 1101 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
| 1102 | 1102 | $this->_current_screen = get_current_screen(); |
| 1103 | 1103 | $this->_current_screen->base = 'event-espresso'; |
| 1104 | 1104 | $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
@@ -1121,8 +1121,8 @@ discard block |
||
| 1121 | 1121 | */ |
| 1122 | 1122 | public function add_custom_editor_default_title($title) |
| 1123 | 1123 | { |
| 1124 | - return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
| 1125 | - ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
| 1124 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
| 1125 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
| 1126 | 1126 | : $title; |
| 1127 | 1127 | } |
| 1128 | 1128 | |
@@ -1138,10 +1138,10 @@ discard block |
||
| 1138 | 1138 | */ |
| 1139 | 1139 | public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
| 1140 | 1140 | { |
| 1141 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
| 1141 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
| 1142 | 1142 | $post = get_post($id); |
| 1143 | 1143 | if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
| 1144 | - $shortlink = home_url('?p=' . $post->ID); |
|
| 1144 | + $shortlink = home_url('?p='.$post->ID); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | } |
| 1147 | 1147 | return $shortlink; |
@@ -1176,10 +1176,10 @@ discard block |
||
| 1176 | 1176 | { |
| 1177 | 1177 | // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
| 1178 | 1178 | echo ' |
| 1179 | - <input type="hidden" name="ee_cpt_item_redirect_url" value="' . esc_url_raw($this->_admin_base_url) . '"/> |
|
| 1179 | + <input type="hidden" name="ee_cpt_item_redirect_url" value="' . esc_url_raw($this->_admin_base_url).'"/> |
|
| 1180 | 1180 | <div id="ee-cpt-hidden-inputs"> |
| 1181 | - <input type="hidden" id="current_route" name="current_route" value="' . esc_attr($this->_current_view) . '"/> |
|
| 1182 | - <input type="hidden" id="current_page" name="current_page" value="' . esc_attr($this->page_slug) . '"/> |
|
| 1181 | + <input type="hidden" id="current_route" name="current_route" value="' . esc_attr($this->_current_view).'"/> |
|
| 1182 | + <input type="hidden" id="current_page" name="current_page" value="' . esc_attr($this->page_slug).'"/> |
|
| 1183 | 1183 | </div>'; |
| 1184 | 1184 | } |
| 1185 | 1185 | |
@@ -1228,14 +1228,14 @@ discard block |
||
| 1228 | 1228 | $post = get_post($id); |
| 1229 | 1229 | if ( |
| 1230 | 1230 | ! isset($this->_req_data['action']) |
| 1231 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1232 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
| 1231 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1232 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
| 1233 | 1233 | ) { |
| 1234 | 1234 | return $link; |
| 1235 | 1235 | } |
| 1236 | 1236 | $query_args = [ |
| 1237 | - 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
| 1238 | - ? $this->_cpt_edit_routes[ $post->post_type ] |
|
| 1237 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
| 1238 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
| 1239 | 1239 | : 'edit', |
| 1240 | 1240 | 'post' => $id, |
| 1241 | 1241 | ]; |
@@ -1260,16 +1260,16 @@ discard block |
||
| 1260 | 1260 | |
| 1261 | 1261 | if ( |
| 1262 | 1262 | empty($this->_req_data['action']) |
| 1263 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1263 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1264 | 1264 | || ! $post instanceof WP_Post |
| 1265 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
| 1265 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
| 1266 | 1266 | ) { |
| 1267 | 1267 | return $delete_link; |
| 1268 | 1268 | } |
| 1269 | 1269 | $this->_set_model_object($post->ID, true); |
| 1270 | 1270 | |
| 1271 | 1271 | // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
| 1272 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1272 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1273 | 1273 | |
| 1274 | 1274 | return EE_Admin_Page::add_query_args_and_nonce( |
| 1275 | 1275 | [ |
@@ -1299,7 +1299,7 @@ discard block |
||
| 1299 | 1299 | // we DO have a match so let's setup the url |
| 1300 | 1300 | // we have to get the post to determine our route |
| 1301 | 1301 | $post = get_post($post_id); |
| 1302 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
| 1302 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
| 1303 | 1303 | // shared query_args |
| 1304 | 1304 | $query_args = ['action' => $edit_route, 'post' => $post_id]; |
| 1305 | 1305 | $admin_url = $this->_admin_base_url; |
@@ -1370,12 +1370,12 @@ discard block |
||
| 1370 | 1370 | $id = empty($id) && is_object($post) ? $post->ID : null; |
| 1371 | 1371 | $revision = $this->request->getRequestParam('revision', 0, 'int'); |
| 1372 | 1372 | |
| 1373 | - $messages[ $post->post_type ] = [ |
|
| 1373 | + $messages[$post->post_type] = [ |
|
| 1374 | 1374 | 0 => '', // Unused. Messages start at index 1. |
| 1375 | 1375 | 1 => sprintf( |
| 1376 | 1376 | esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
| 1377 | 1377 | $this->_cpt_object->labels->singular_name, |
| 1378 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1378 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
| 1379 | 1379 | '</a>' |
| 1380 | 1380 | ), |
| 1381 | 1381 | 2 => esc_html__('Custom field updated', 'event_espresso'), |
@@ -1391,27 +1391,27 @@ discard block |
||
| 1391 | 1391 | 6 => sprintf( |
| 1392 | 1392 | esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
| 1393 | 1393 | $this->_cpt_object->labels->singular_name, |
| 1394 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1394 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
| 1395 | 1395 | '</a>' |
| 1396 | 1396 | ), |
| 1397 | 1397 | 7 => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
| 1398 | 1398 | 8 => sprintf( |
| 1399 | 1399 | esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
| 1400 | 1400 | $this->_cpt_object->labels->singular_name, |
| 1401 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1401 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
| 1402 | 1402 | '</a>' |
| 1403 | 1403 | ), |
| 1404 | 1404 | 9 => sprintf( |
| 1405 | 1405 | esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
| 1406 | 1406 | $this->_cpt_object->labels->singular_name, |
| 1407 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
| 1408 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1407 | + '<strong>'.date_i18n('M j, Y @ G:i', strtotime($post->post_date)).'</strong>', |
|
| 1408 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
| 1409 | 1409 | '</a>' |
| 1410 | 1410 | ), |
| 1411 | 1411 | 10 => sprintf( |
| 1412 | 1412 | esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
| 1413 | 1413 | $this->_cpt_object->labels->singular_name, |
| 1414 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1414 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1415 | 1415 | '</a>' |
| 1416 | 1416 | ), |
| 1417 | 1417 | ]; |
@@ -1429,10 +1429,10 @@ discard block |
||
| 1429 | 1429 | { |
| 1430 | 1430 | // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
| 1431 | 1431 | global $post, $title, $is_IE, $post_type, $post_type_object; |
| 1432 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1432 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
| 1433 | 1433 | $post_type_object = $this->_cpt_object; |
| 1434 | 1434 | $title = $post_type_object->labels->add_new_item; |
| 1435 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
| 1435 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
| 1436 | 1436 | add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
| 1437 | 1437 | // modify the default editor title field with default title. |
| 1438 | 1438 | add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10); |
@@ -1458,15 +1458,15 @@ discard block |
||
| 1458 | 1458 | wp_enqueue_script('autosave'); |
| 1459 | 1459 | } else { |
| 1460 | 1460 | if ( |
| 1461 | - isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1462 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
| 1461 | + isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1462 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
| 1463 | 1463 | ) { |
| 1464 | 1464 | $create_new_action = apply_filters( |
| 1465 | 1465 | 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
| 1466 | 1466 | 'create_new', |
| 1467 | 1467 | $this |
| 1468 | 1468 | ); |
| 1469 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1469 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1470 | 1470 | [ |
| 1471 | 1471 | 'action' => $create_new_action, |
| 1472 | 1472 | 'page' => $this->page_slug, |
@@ -1475,7 +1475,7 @@ discard block |
||
| 1475 | 1475 | ); |
| 1476 | 1476 | } |
| 1477 | 1477 | } |
| 1478 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1478 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
| 1479 | 1479 | } |
| 1480 | 1480 | } |
| 1481 | 1481 | |
@@ -1517,14 +1517,14 @@ discard block |
||
| 1517 | 1517 | } |
| 1518 | 1518 | |
| 1519 | 1519 | // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
| 1520 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1520 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
| 1521 | 1521 | $post_type_object = $this->_cpt_object; |
| 1522 | 1522 | |
| 1523 | - if (! wp_check_post_lock($post->ID)) { |
|
| 1523 | + if ( ! wp_check_post_lock($post->ID)) { |
|
| 1524 | 1524 | wp_set_post_lock($post->ID); |
| 1525 | 1525 | } |
| 1526 | 1526 | add_action('admin_footer', '_admin_notice_post_locked'); |
| 1527 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
| 1527 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
| 1528 | 1528 | wp_enqueue_script('admin-comments'); |
| 1529 | 1529 | enqueue_comment_hotkeys_js(); |
| 1530 | 1530 | } |
@@ -29,492 +29,492 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * This gets set in _setup_cpt |
|
| 34 | - * It will contain the object for the custom post type. |
|
| 35 | - * |
|
| 36 | - * @var EE_CPT_Base |
|
| 37 | - */ |
|
| 38 | - protected $_cpt_object; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
| 43 | - * |
|
| 44 | - * @var bool |
|
| 45 | - */ |
|
| 46 | - protected $_cpt_route = false; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
| 51 | - * //in this array we define what the custom post type for this route is. |
|
| 52 | - * array( |
|
| 53 | - * 'route_name' => 'custom_post_type_slug' |
|
| 54 | - * ) |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - protected $_cpt_routes = []; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
| 63 | - * in this format: |
|
| 64 | - * array( |
|
| 65 | - * 'post_type_slug' => 'edit_route' |
|
| 66 | - * ) |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $_cpt_edit_routes = []; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
| 75 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
| 76 | - * _cpt_model_names property should be in the following format: array( |
|
| 77 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
| 78 | - * |
|
| 79 | - * @var array $_cpt_model_names |
|
| 80 | - */ |
|
| 81 | - protected $_cpt_model_names = []; |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var EE_CPT_Base |
|
| 86 | - */ |
|
| 87 | - protected $_cpt_model_obj = false; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @var LoaderInterface $loader ; |
|
| 91 | - */ |
|
| 92 | - protected $loader; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
| 96 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
| 97 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
| 98 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
| 99 | - * |
|
| 100 | - * @var array() |
|
| 101 | - */ |
|
| 102 | - protected $_autosave_containers = []; |
|
| 103 | - |
|
| 104 | - protected $_autosave_fields = []; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
| 108 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
| 109 | - * |
|
| 110 | - * @var array |
|
| 111 | - */ |
|
| 112 | - protected $_pagenow_map; |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 117 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 118 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
| 119 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
| 120 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
| 121 | - * |
|
| 122 | - * @abstract |
|
| 123 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 124 | - * @param WP_Post $post The post object of the cpt that was saved. |
|
| 125 | - * @return void |
|
| 126 | - */ |
|
| 127 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
| 132 | - * |
|
| 133 | - * @abstract |
|
| 134 | - * @param string $post_id The ID of the cpt that was trashed |
|
| 135 | - * @return void |
|
| 136 | - */ |
|
| 137 | - abstract public function trash_cpt_item($post_id); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
| 142 | - * |
|
| 143 | - * @param string $post_id theID of the cpt that was untrashed |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - abstract public function restore_cpt_item($post_id); |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
| 151 | - * from the db |
|
| 152 | - * |
|
| 153 | - * @param string $post_id the ID of the cpt that was deleted |
|
| 154 | - * @return void |
|
| 155 | - */ |
|
| 156 | - abstract public function delete_cpt_item($post_id); |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return LoaderInterface |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - */ |
|
| 165 | - protected function getLoader() |
|
| 166 | - { |
|
| 167 | - if (! $this->loader instanceof LoaderInterface) { |
|
| 168 | - $this->loader = LoaderFactory::getLoader(); |
|
| 169 | - } |
|
| 170 | - return $this->loader; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
| 176 | - * |
|
| 177 | - * @return void |
|
| 178 | - */ |
|
| 179 | - protected function _before_page_setup() |
|
| 180 | - { |
|
| 181 | - $this->raw_req_action = $this->request->getRequestParam('action'); |
|
| 182 | - $this->raw_req_page = $this->request->getRequestParam('page'); |
|
| 183 | - $this->_cpt_routes = array_merge( |
|
| 184 | - [ |
|
| 185 | - 'create_new' => $this->page_slug, |
|
| 186 | - 'edit' => $this->page_slug, |
|
| 187 | - 'trash' => $this->page_slug, |
|
| 188 | - ], |
|
| 189 | - $this->_cpt_routes |
|
| 190 | - ); |
|
| 191 | - $cpt_route_action = isset($this->_cpt_routes[ $this->raw_req_action ]) |
|
| 192 | - ? $this->_cpt_routes[ $this->raw_req_action ] |
|
| 193 | - : null; |
|
| 194 | - // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page |
|
| 195 | - $page = $this->raw_req_page ?: $this->page_slug; |
|
| 196 | - $page = $cpt_route_action ?: $page; |
|
| 197 | - $this->_cpt_object = get_post_type_object($page); |
|
| 198 | - // tweak pagenow for page loading. |
|
| 199 | - if (! $this->_pagenow_map) { |
|
| 200 | - $this->_pagenow_map = [ |
|
| 201 | - 'create_new' => 'post-new.php', |
|
| 202 | - 'edit' => 'post.php', |
|
| 203 | - 'trash' => 'post.php', |
|
| 204 | - ]; |
|
| 205 | - } |
|
| 206 | - add_action('current_screen', [$this, 'modify_pagenow']); |
|
| 207 | - // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
| 208 | - // get current page from autosave |
|
| 209 | - $current_page = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]'); |
|
| 210 | - $this->_current_page = $this->request->getRequestParam('current_page', $current_page); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
| 216 | - * |
|
| 217 | - * @param WP_Screen $current_screen |
|
| 218 | - * @return void |
|
| 219 | - */ |
|
| 220 | - public function modify_pagenow($current_screen) |
|
| 221 | - { |
|
| 222 | - // possibly reset pagenow. |
|
| 223 | - if ( |
|
| 224 | - $this->page_slug === $this->raw_req_page |
|
| 225 | - && isset($this->_pagenow_map[ $this->raw_req_action ]) |
|
| 226 | - ) { |
|
| 227 | - global $pagenow, $hook_suffix; |
|
| 228 | - $pagenow = $this->_pagenow_map[ $this->raw_req_action ]; |
|
| 229 | - $hook_suffix = $pagenow; |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
| 236 | - * |
|
| 237 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
| 238 | - * you would send along the id of a metabox container. |
|
| 239 | - * @return void |
|
| 240 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
| 241 | - * automatically register the id for the post metabox as a container. |
|
| 242 | - */ |
|
| 243 | - protected function _register_autosave_containers($ids) |
|
| 244 | - { |
|
| 245 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
| 251 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
| 252 | - */ |
|
| 253 | - protected function _set_autosave_containers() |
|
| 254 | - { |
|
| 255 | - global $wp_meta_boxes; |
|
| 256 | - $containers = []; |
|
| 257 | - if (empty($wp_meta_boxes)) { |
|
| 258 | - return; |
|
| 259 | - } |
|
| 260 | - $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : []; |
|
| 261 | - foreach ($current_metaboxes as $box_context) { |
|
| 262 | - foreach ($box_context as $box_details) { |
|
| 263 | - foreach ($box_details as $box) { |
|
| 264 | - if ( |
|
| 265 | - is_array($box) && is_array($box['callback']) |
|
| 266 | - && ( |
|
| 267 | - $box['callback'][0] instanceof EE_Admin_Page |
|
| 268 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
| 269 | - ) |
|
| 270 | - ) { |
|
| 271 | - $containers[] = $box['id']; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
| 277 | - // add hidden inputs container |
|
| 278 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - protected function _load_autosave_scripts_styles() |
|
| 283 | - { |
|
| 284 | - /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 32 | + /** |
|
| 33 | + * This gets set in _setup_cpt |
|
| 34 | + * It will contain the object for the custom post type. |
|
| 35 | + * |
|
| 36 | + * @var EE_CPT_Base |
|
| 37 | + */ |
|
| 38 | + protected $_cpt_object; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
| 43 | + * |
|
| 44 | + * @var bool |
|
| 45 | + */ |
|
| 46 | + protected $_cpt_route = false; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
| 51 | + * //in this array we define what the custom post type for this route is. |
|
| 52 | + * array( |
|
| 53 | + * 'route_name' => 'custom_post_type_slug' |
|
| 54 | + * ) |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + protected $_cpt_routes = []; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
| 63 | + * in this format: |
|
| 64 | + * array( |
|
| 65 | + * 'post_type_slug' => 'edit_route' |
|
| 66 | + * ) |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $_cpt_edit_routes = []; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
| 75 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
| 76 | + * _cpt_model_names property should be in the following format: array( |
|
| 77 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
| 78 | + * |
|
| 79 | + * @var array $_cpt_model_names |
|
| 80 | + */ |
|
| 81 | + protected $_cpt_model_names = []; |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var EE_CPT_Base |
|
| 86 | + */ |
|
| 87 | + protected $_cpt_model_obj = false; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @var LoaderInterface $loader ; |
|
| 91 | + */ |
|
| 92 | + protected $loader; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
| 96 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
| 97 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
| 98 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
| 99 | + * |
|
| 100 | + * @var array() |
|
| 101 | + */ |
|
| 102 | + protected $_autosave_containers = []; |
|
| 103 | + |
|
| 104 | + protected $_autosave_fields = []; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
| 108 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
| 109 | + * |
|
| 110 | + * @var array |
|
| 111 | + */ |
|
| 112 | + protected $_pagenow_map; |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 117 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 118 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
| 119 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
| 120 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
| 121 | + * |
|
| 122 | + * @abstract |
|
| 123 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 124 | + * @param WP_Post $post The post object of the cpt that was saved. |
|
| 125 | + * @return void |
|
| 126 | + */ |
|
| 127 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
| 132 | + * |
|
| 133 | + * @abstract |
|
| 134 | + * @param string $post_id The ID of the cpt that was trashed |
|
| 135 | + * @return void |
|
| 136 | + */ |
|
| 137 | + abstract public function trash_cpt_item($post_id); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
| 142 | + * |
|
| 143 | + * @param string $post_id theID of the cpt that was untrashed |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + abstract public function restore_cpt_item($post_id); |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
| 151 | + * from the db |
|
| 152 | + * |
|
| 153 | + * @param string $post_id the ID of the cpt that was deleted |
|
| 154 | + * @return void |
|
| 155 | + */ |
|
| 156 | + abstract public function delete_cpt_item($post_id); |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return LoaderInterface |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + */ |
|
| 165 | + protected function getLoader() |
|
| 166 | + { |
|
| 167 | + if (! $this->loader instanceof LoaderInterface) { |
|
| 168 | + $this->loader = LoaderFactory::getLoader(); |
|
| 169 | + } |
|
| 170 | + return $this->loader; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
| 176 | + * |
|
| 177 | + * @return void |
|
| 178 | + */ |
|
| 179 | + protected function _before_page_setup() |
|
| 180 | + { |
|
| 181 | + $this->raw_req_action = $this->request->getRequestParam('action'); |
|
| 182 | + $this->raw_req_page = $this->request->getRequestParam('page'); |
|
| 183 | + $this->_cpt_routes = array_merge( |
|
| 184 | + [ |
|
| 185 | + 'create_new' => $this->page_slug, |
|
| 186 | + 'edit' => $this->page_slug, |
|
| 187 | + 'trash' => $this->page_slug, |
|
| 188 | + ], |
|
| 189 | + $this->_cpt_routes |
|
| 190 | + ); |
|
| 191 | + $cpt_route_action = isset($this->_cpt_routes[ $this->raw_req_action ]) |
|
| 192 | + ? $this->_cpt_routes[ $this->raw_req_action ] |
|
| 193 | + : null; |
|
| 194 | + // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page |
|
| 195 | + $page = $this->raw_req_page ?: $this->page_slug; |
|
| 196 | + $page = $cpt_route_action ?: $page; |
|
| 197 | + $this->_cpt_object = get_post_type_object($page); |
|
| 198 | + // tweak pagenow for page loading. |
|
| 199 | + if (! $this->_pagenow_map) { |
|
| 200 | + $this->_pagenow_map = [ |
|
| 201 | + 'create_new' => 'post-new.php', |
|
| 202 | + 'edit' => 'post.php', |
|
| 203 | + 'trash' => 'post.php', |
|
| 204 | + ]; |
|
| 205 | + } |
|
| 206 | + add_action('current_screen', [$this, 'modify_pagenow']); |
|
| 207 | + // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
| 208 | + // get current page from autosave |
|
| 209 | + $current_page = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]'); |
|
| 210 | + $this->_current_page = $this->request->getRequestParam('current_page', $current_page); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
| 216 | + * |
|
| 217 | + * @param WP_Screen $current_screen |
|
| 218 | + * @return void |
|
| 219 | + */ |
|
| 220 | + public function modify_pagenow($current_screen) |
|
| 221 | + { |
|
| 222 | + // possibly reset pagenow. |
|
| 223 | + if ( |
|
| 224 | + $this->page_slug === $this->raw_req_page |
|
| 225 | + && isset($this->_pagenow_map[ $this->raw_req_action ]) |
|
| 226 | + ) { |
|
| 227 | + global $pagenow, $hook_suffix; |
|
| 228 | + $pagenow = $this->_pagenow_map[ $this->raw_req_action ]; |
|
| 229 | + $hook_suffix = $pagenow; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
| 236 | + * |
|
| 237 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
| 238 | + * you would send along the id of a metabox container. |
|
| 239 | + * @return void |
|
| 240 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
| 241 | + * automatically register the id for the post metabox as a container. |
|
| 242 | + */ |
|
| 243 | + protected function _register_autosave_containers($ids) |
|
| 244 | + { |
|
| 245 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
| 251 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
| 252 | + */ |
|
| 253 | + protected function _set_autosave_containers() |
|
| 254 | + { |
|
| 255 | + global $wp_meta_boxes; |
|
| 256 | + $containers = []; |
|
| 257 | + if (empty($wp_meta_boxes)) { |
|
| 258 | + return; |
|
| 259 | + } |
|
| 260 | + $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : []; |
|
| 261 | + foreach ($current_metaboxes as $box_context) { |
|
| 262 | + foreach ($box_context as $box_details) { |
|
| 263 | + foreach ($box_details as $box) { |
|
| 264 | + if ( |
|
| 265 | + is_array($box) && is_array($box['callback']) |
|
| 266 | + && ( |
|
| 267 | + $box['callback'][0] instanceof EE_Admin_Page |
|
| 268 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
| 269 | + ) |
|
| 270 | + ) { |
|
| 271 | + $containers[] = $box['id']; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
| 277 | + // add hidden inputs container |
|
| 278 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + protected function _load_autosave_scripts_styles() |
|
| 283 | + { |
|
| 284 | + /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 285 | 285 | wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2 |
| 286 | 286 | |
| 287 | - // filter _autosave_containers |
|
| 288 | - $containers = apply_filters( |
|
| 289 | - 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
| 290 | - $this->_autosave_containers, |
|
| 291 | - $this |
|
| 292 | - ); |
|
| 293 | - $containers = apply_filters( |
|
| 294 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 295 | - $containers, |
|
| 296 | - $this |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - wp_localize_script( |
|
| 300 | - 'event_editor_js', |
|
| 301 | - 'EE_AUTOSAVE_IDS', |
|
| 302 | - $containers |
|
| 303 | - ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
| 304 | - |
|
| 305 | - $unsaved_data_msg = [ |
|
| 306 | - 'eventmsg' => sprintf( |
|
| 307 | - wp_strip_all_tags( |
|
| 308 | - __( |
|
| 309 | - "The changes you made to this %s will be lost if you navigate away from this page.", |
|
| 310 | - 'event_espresso' |
|
| 311 | - ) |
|
| 312 | - ), |
|
| 313 | - $this->_cpt_object->labels->singular_name |
|
| 314 | - ), |
|
| 315 | - 'inputChanged' => 0, |
|
| 316 | - ]; |
|
| 317 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - public function load_page_dependencies() |
|
| 322 | - { |
|
| 323 | - try { |
|
| 324 | - $this->_load_page_dependencies(); |
|
| 325 | - } catch (EE_Error $e) { |
|
| 326 | - $e->get_error(); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
| 333 | - * |
|
| 334 | - * @return void |
|
| 335 | - */ |
|
| 336 | - protected function _load_page_dependencies() |
|
| 337 | - { |
|
| 338 | - // we only add stuff if this is a cpt_route! |
|
| 339 | - if (! $this->_cpt_route) { |
|
| 340 | - parent::_load_page_dependencies(); |
|
| 341 | - return; |
|
| 342 | - } |
|
| 343 | - // now let's do some automatic filters into the wp_system |
|
| 344 | - // and we'll check to make sure the CHILD class |
|
| 345 | - // automatically has the required methods in place. |
|
| 346 | - // the following filters are for setting all the redirects |
|
| 347 | - // on DEFAULT WP custom post type actions |
|
| 348 | - // let's add a hidden input to the post-edit form |
|
| 349 | - // so we know when we have to trigger our custom redirects! |
|
| 350 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
| 351 | - add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']); |
|
| 352 | - // inject our Admin page nav tabs... |
|
| 353 | - // let's make sure the nav tabs are set if they aren't already |
|
| 354 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
| 355 | - add_action('edit_form_top', [$this, 'inject_nav_tabs']); |
|
| 356 | - // modify the post_updated messages array |
|
| 357 | - add_action('post_updated_messages', [$this, 'post_update_messages'], 10); |
|
| 358 | - // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
| 359 | - // cpts use the same format for shortlinks as posts! |
|
| 360 | - add_filter('pre_get_shortlink', [$this, 'add_shortlink_button_to_editor'], 10, 4); |
|
| 361 | - // This basically allows us to change the title of the "publish" metabox area |
|
| 362 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
| 363 | - if (! empty($this->_labels['publishbox'])) { |
|
| 364 | - $box_label = is_array($this->_labels['publishbox']) |
|
| 365 | - && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
| 366 | - ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 367 | - : $this->_labels['publishbox']; |
|
| 368 | - add_meta_box( |
|
| 369 | - 'submitdiv', |
|
| 370 | - $box_label, |
|
| 371 | - 'post_submit_meta_box', |
|
| 372 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 373 | - 'side', |
|
| 374 | - 'core' |
|
| 375 | - ); |
|
| 376 | - } |
|
| 377 | - // let's add page_templates metabox if this cpt added support for it. |
|
| 378 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
| 379 | - add_meta_box( |
|
| 380 | - 'page_templates', |
|
| 381 | - esc_html__('Page Template', 'event_espresso'), |
|
| 382 | - [$this, 'page_template_meta_box'], |
|
| 383 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 384 | - 'side', |
|
| 385 | - 'default' |
|
| 386 | - ); |
|
| 387 | - } |
|
| 388 | - // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 389 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
| 390 | - add_filter('get_sample_permalink_html', [$this, 'extra_permalink_field_buttons'], 10, 4); |
|
| 391 | - } |
|
| 392 | - // add preview button |
|
| 393 | - add_filter('get_sample_permalink_html', [$this, 'preview_button_html'], 5, 4); |
|
| 394 | - // insert our own post_stati dropdown |
|
| 395 | - add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10); |
|
| 396 | - // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
| 397 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
| 398 | - add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10); |
|
| 399 | - } |
|
| 400 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
| 401 | - // This is also before the wp_editor for post description field. |
|
| 402 | - if (method_exists($this, 'edit_form_after_title')) { |
|
| 403 | - add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10); |
|
| 404 | - } |
|
| 405 | - /** |
|
| 406 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
| 407 | - */ |
|
| 408 | - add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10, 3); |
|
| 409 | - parent::_load_page_dependencies(); |
|
| 410 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
| 411 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
| 412 | - // This is for any plugins that are doing things properly |
|
| 413 | - // and hooking into the load page hook for core wp cpt routes. |
|
| 414 | - global $pagenow; |
|
| 415 | - add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20); |
|
| 416 | - do_action('load-' . $pagenow); |
|
| 417 | - add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30); |
|
| 418 | - // we route REALLY early. |
|
| 419 | - try { |
|
| 420 | - $this->_route_admin_request(); |
|
| 421 | - } catch (EE_Error $e) { |
|
| 422 | - $e->get_error(); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
| 429 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
| 430 | - * route instead. |
|
| 431 | - * |
|
| 432 | - * @param string $good_protocol_url The escaped url. |
|
| 433 | - * @param string $original_url The original url. |
|
| 434 | - * @param string $_context The context sent to the esc_url method. |
|
| 435 | - * @return string possibly a new url for our route. |
|
| 436 | - */ |
|
| 437 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
| 438 | - { |
|
| 439 | - $routes_to_match = [ |
|
| 440 | - 0 => [ |
|
| 441 | - 'edit.php?post_type=espresso_attendees', |
|
| 442 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
| 443 | - ], |
|
| 444 | - 1 => [ |
|
| 445 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 446 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
| 447 | - ], |
|
| 448 | - ]; |
|
| 449 | - foreach ($routes_to_match as $route_matches) { |
|
| 450 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
| 451 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - return $good_protocol_url; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Determine whether the current cpt supports page templates or not. |
|
| 460 | - * |
|
| 461 | - * @param string $cpt_name The cpt slug we're checking on. |
|
| 462 | - * @return bool True supported, false not. |
|
| 463 | - * @throws InvalidArgumentException |
|
| 464 | - * @throws InvalidDataTypeException |
|
| 465 | - * @throws InvalidInterfaceException |
|
| 466 | - * @since %VER% |
|
| 467 | - */ |
|
| 468 | - private function _supports_page_templates($cpt_name) |
|
| 469 | - { |
|
| 470 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 471 | - $custom_post_types = $this->getLoader()->getShared( |
|
| 472 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 473 | - ); |
|
| 474 | - $cpt_args = $custom_post_types->getDefinitions(); |
|
| 475 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : []; |
|
| 476 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
| 477 | - |
|
| 478 | - // if the installed version of WP is > 4.7 we do some additional checks. |
|
| 479 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
| 480 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
| 481 | - // if there are $post_templates for this cpt, then we return false for this method because |
|
| 482 | - // that means we aren't going to load our page template manager and leave that up to the native |
|
| 483 | - // cpt template manager. |
|
| 484 | - $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $cpt_has_support; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Callback for the page_templates metabox selector. |
|
| 493 | - * |
|
| 494 | - * @return void |
|
| 495 | - * @since %VER% |
|
| 496 | - */ |
|
| 497 | - public function page_template_meta_box() |
|
| 498 | - { |
|
| 499 | - global $post; |
|
| 500 | - $template = ''; |
|
| 501 | - |
|
| 502 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
| 503 | - $page_template_count = count(get_page_templates()); |
|
| 504 | - } else { |
|
| 505 | - $page_template_count = count(get_page_templates($post)); |
|
| 506 | - }; |
|
| 507 | - |
|
| 508 | - if ($page_template_count) { |
|
| 509 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
| 510 | - $template = ! empty($page_template) ? $page_template : ''; |
|
| 511 | - } |
|
| 512 | - ?> |
|
| 287 | + // filter _autosave_containers |
|
| 288 | + $containers = apply_filters( |
|
| 289 | + 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
| 290 | + $this->_autosave_containers, |
|
| 291 | + $this |
|
| 292 | + ); |
|
| 293 | + $containers = apply_filters( |
|
| 294 | + 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 295 | + $containers, |
|
| 296 | + $this |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + wp_localize_script( |
|
| 300 | + 'event_editor_js', |
|
| 301 | + 'EE_AUTOSAVE_IDS', |
|
| 302 | + $containers |
|
| 303 | + ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
| 304 | + |
|
| 305 | + $unsaved_data_msg = [ |
|
| 306 | + 'eventmsg' => sprintf( |
|
| 307 | + wp_strip_all_tags( |
|
| 308 | + __( |
|
| 309 | + "The changes you made to this %s will be lost if you navigate away from this page.", |
|
| 310 | + 'event_espresso' |
|
| 311 | + ) |
|
| 312 | + ), |
|
| 313 | + $this->_cpt_object->labels->singular_name |
|
| 314 | + ), |
|
| 315 | + 'inputChanged' => 0, |
|
| 316 | + ]; |
|
| 317 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + public function load_page_dependencies() |
|
| 322 | + { |
|
| 323 | + try { |
|
| 324 | + $this->_load_page_dependencies(); |
|
| 325 | + } catch (EE_Error $e) { |
|
| 326 | + $e->get_error(); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
| 333 | + * |
|
| 334 | + * @return void |
|
| 335 | + */ |
|
| 336 | + protected function _load_page_dependencies() |
|
| 337 | + { |
|
| 338 | + // we only add stuff if this is a cpt_route! |
|
| 339 | + if (! $this->_cpt_route) { |
|
| 340 | + parent::_load_page_dependencies(); |
|
| 341 | + return; |
|
| 342 | + } |
|
| 343 | + // now let's do some automatic filters into the wp_system |
|
| 344 | + // and we'll check to make sure the CHILD class |
|
| 345 | + // automatically has the required methods in place. |
|
| 346 | + // the following filters are for setting all the redirects |
|
| 347 | + // on DEFAULT WP custom post type actions |
|
| 348 | + // let's add a hidden input to the post-edit form |
|
| 349 | + // so we know when we have to trigger our custom redirects! |
|
| 350 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
| 351 | + add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']); |
|
| 352 | + // inject our Admin page nav tabs... |
|
| 353 | + // let's make sure the nav tabs are set if they aren't already |
|
| 354 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
| 355 | + add_action('edit_form_top', [$this, 'inject_nav_tabs']); |
|
| 356 | + // modify the post_updated messages array |
|
| 357 | + add_action('post_updated_messages', [$this, 'post_update_messages'], 10); |
|
| 358 | + // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
| 359 | + // cpts use the same format for shortlinks as posts! |
|
| 360 | + add_filter('pre_get_shortlink', [$this, 'add_shortlink_button_to_editor'], 10, 4); |
|
| 361 | + // This basically allows us to change the title of the "publish" metabox area |
|
| 362 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
| 363 | + if (! empty($this->_labels['publishbox'])) { |
|
| 364 | + $box_label = is_array($this->_labels['publishbox']) |
|
| 365 | + && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
| 366 | + ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 367 | + : $this->_labels['publishbox']; |
|
| 368 | + add_meta_box( |
|
| 369 | + 'submitdiv', |
|
| 370 | + $box_label, |
|
| 371 | + 'post_submit_meta_box', |
|
| 372 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 373 | + 'side', |
|
| 374 | + 'core' |
|
| 375 | + ); |
|
| 376 | + } |
|
| 377 | + // let's add page_templates metabox if this cpt added support for it. |
|
| 378 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
| 379 | + add_meta_box( |
|
| 380 | + 'page_templates', |
|
| 381 | + esc_html__('Page Template', 'event_espresso'), |
|
| 382 | + [$this, 'page_template_meta_box'], |
|
| 383 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 384 | + 'side', |
|
| 385 | + 'default' |
|
| 386 | + ); |
|
| 387 | + } |
|
| 388 | + // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 389 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
| 390 | + add_filter('get_sample_permalink_html', [$this, 'extra_permalink_field_buttons'], 10, 4); |
|
| 391 | + } |
|
| 392 | + // add preview button |
|
| 393 | + add_filter('get_sample_permalink_html', [$this, 'preview_button_html'], 5, 4); |
|
| 394 | + // insert our own post_stati dropdown |
|
| 395 | + add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10); |
|
| 396 | + // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
| 397 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
| 398 | + add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10); |
|
| 399 | + } |
|
| 400 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
| 401 | + // This is also before the wp_editor for post description field. |
|
| 402 | + if (method_exists($this, 'edit_form_after_title')) { |
|
| 403 | + add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10); |
|
| 404 | + } |
|
| 405 | + /** |
|
| 406 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
| 407 | + */ |
|
| 408 | + add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10, 3); |
|
| 409 | + parent::_load_page_dependencies(); |
|
| 410 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
| 411 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
| 412 | + // This is for any plugins that are doing things properly |
|
| 413 | + // and hooking into the load page hook for core wp cpt routes. |
|
| 414 | + global $pagenow; |
|
| 415 | + add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20); |
|
| 416 | + do_action('load-' . $pagenow); |
|
| 417 | + add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30); |
|
| 418 | + // we route REALLY early. |
|
| 419 | + try { |
|
| 420 | + $this->_route_admin_request(); |
|
| 421 | + } catch (EE_Error $e) { |
|
| 422 | + $e->get_error(); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
| 429 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
| 430 | + * route instead. |
|
| 431 | + * |
|
| 432 | + * @param string $good_protocol_url The escaped url. |
|
| 433 | + * @param string $original_url The original url. |
|
| 434 | + * @param string $_context The context sent to the esc_url method. |
|
| 435 | + * @return string possibly a new url for our route. |
|
| 436 | + */ |
|
| 437 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
| 438 | + { |
|
| 439 | + $routes_to_match = [ |
|
| 440 | + 0 => [ |
|
| 441 | + 'edit.php?post_type=espresso_attendees', |
|
| 442 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
| 443 | + ], |
|
| 444 | + 1 => [ |
|
| 445 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 446 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
| 447 | + ], |
|
| 448 | + ]; |
|
| 449 | + foreach ($routes_to_match as $route_matches) { |
|
| 450 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
| 451 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + return $good_protocol_url; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Determine whether the current cpt supports page templates or not. |
|
| 460 | + * |
|
| 461 | + * @param string $cpt_name The cpt slug we're checking on. |
|
| 462 | + * @return bool True supported, false not. |
|
| 463 | + * @throws InvalidArgumentException |
|
| 464 | + * @throws InvalidDataTypeException |
|
| 465 | + * @throws InvalidInterfaceException |
|
| 466 | + * @since %VER% |
|
| 467 | + */ |
|
| 468 | + private function _supports_page_templates($cpt_name) |
|
| 469 | + { |
|
| 470 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 471 | + $custom_post_types = $this->getLoader()->getShared( |
|
| 472 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 473 | + ); |
|
| 474 | + $cpt_args = $custom_post_types->getDefinitions(); |
|
| 475 | + $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : []; |
|
| 476 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
| 477 | + |
|
| 478 | + // if the installed version of WP is > 4.7 we do some additional checks. |
|
| 479 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
| 480 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
| 481 | + // if there are $post_templates for this cpt, then we return false for this method because |
|
| 482 | + // that means we aren't going to load our page template manager and leave that up to the native |
|
| 483 | + // cpt template manager. |
|
| 484 | + $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $cpt_has_support; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Callback for the page_templates metabox selector. |
|
| 493 | + * |
|
| 494 | + * @return void |
|
| 495 | + * @since %VER% |
|
| 496 | + */ |
|
| 497 | + public function page_template_meta_box() |
|
| 498 | + { |
|
| 499 | + global $post; |
|
| 500 | + $template = ''; |
|
| 501 | + |
|
| 502 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
| 503 | + $page_template_count = count(get_page_templates()); |
|
| 504 | + } else { |
|
| 505 | + $page_template_count = count(get_page_templates($post)); |
|
| 506 | + }; |
|
| 507 | + |
|
| 508 | + if ($page_template_count) { |
|
| 509 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
| 510 | + $template = ! empty($page_template) ? $page_template : ''; |
|
| 511 | + } |
|
| 512 | + ?> |
|
| 513 | 513 | <p><strong><?php esc_html_e('Template', 'event_espresso') ?></strong></p> |
| 514 | 514 | <label class="screen-reader-text" for="page_template"><?php esc_html_e( |
| 515 | - 'Page Template', |
|
| 516 | - 'event_espresso' |
|
| 517 | - ) ?></label> |
|
| 515 | + 'Page Template', |
|
| 516 | + 'event_espresso' |
|
| 517 | + ) ?></label> |
|
| 518 | 518 | <select |
| 519 | 519 | name="page_template" id="page_template" |
| 520 | 520 | > |
@@ -522,473 +522,473 @@ discard block |
||
| 522 | 522 | <?php page_template_dropdown($template); ?> |
| 523 | 523 | </select> |
| 524 | 524 | <?php |
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
| 530 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 531 | - * |
|
| 532 | - * @param string $return the current html |
|
| 533 | - * @param int $id the post id for the page |
|
| 534 | - * @param string $new_title What the title is |
|
| 535 | - * @param string $new_slug what the slug is |
|
| 536 | - * @return string The new html string for the permalink area |
|
| 537 | - */ |
|
| 538 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
| 539 | - { |
|
| 540 | - $post = get_post($id); |
|
| 541 | - if ('publish' !== get_post_status($post)) { |
|
| 542 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
| 543 | - . get_preview_post_link($id) |
|
| 544 | - . '" class="button button-small">' |
|
| 545 | - . esc_html__('Preview', 'event_espresso') |
|
| 546 | - . '</a></span>' |
|
| 547 | - . "\n"; |
|
| 548 | - } |
|
| 549 | - return $return; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
| 555 | - * |
|
| 556 | - * @return void |
|
| 557 | - */ |
|
| 558 | - public function custom_post_stati_dropdown() |
|
| 559 | - { |
|
| 560 | - |
|
| 561 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 562 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
| 563 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
| 564 | - : ''; |
|
| 565 | - $template_args = [ |
|
| 566 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
| 567 | - 'statuses' => $statuses, |
|
| 568 | - 'cur_status_label' => $cur_status_label, |
|
| 569 | - 'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label), |
|
| 570 | - ]; |
|
| 571 | - // we'll add a trash post status (WP doesn't add one for some reason) |
|
| 572 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
| 573 | - $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso'); |
|
| 574 | - $statuses['trash'] = esc_html__('Trashed', 'event_espresso'); |
|
| 575 | - $template_args['statuses'] = $statuses; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 579 | - EEH_Template::display_template($template, $template_args); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - public function setup_autosave_hooks() |
|
| 584 | - { |
|
| 585 | - $this->_set_autosave_containers(); |
|
| 586 | - $this->_load_autosave_scripts_styles(); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available |
|
| 592 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
| 593 | - * for the nonce in here, but then this method looks for two things: |
|
| 594 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
| 595 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
| 596 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
| 597 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
| 598 | - * template args. |
|
| 599 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
| 600 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
| 601 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
| 602 | - * $this->_template_args['data']['items'] = array( |
|
| 603 | - * 'event-datetime-ids' => '1,2,3'; |
|
| 604 | - * ); |
|
| 605 | - * Keep in mind the following things: |
|
| 606 | - * - "where" index is for the input with the id as that string. |
|
| 607 | - * - "what" index is what will be used for the value of that input. |
|
| 608 | - * |
|
| 609 | - * @return void |
|
| 610 | - * @throws EE_Error |
|
| 611 | - */ |
|
| 612 | - public function do_extra_autosave_stuff() |
|
| 613 | - { |
|
| 614 | - // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
| 615 | - $nonce = $this->request->getRequestParam('autosavenonce'); |
|
| 616 | - $this->_verify_nonce($nonce, 'autosave'); |
|
| 617 | - // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
| 618 | - if (! defined('DOING_AUTOSAVE')) { |
|
| 619 | - define('DOING_AUTOSAVE', true); |
|
| 620 | - } |
|
| 621 | - // if we made it here then the nonce checked out. Let's run our methods and actions |
|
| 622 | - $autosave = "_ee_autosave_{$this->_current_view}"; |
|
| 623 | - if (method_exists($this, $autosave)) { |
|
| 624 | - $this->$autosave(); |
|
| 625 | - } else { |
|
| 626 | - $this->_template_args['success'] = true; |
|
| 627 | - } |
|
| 628 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
| 629 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 630 | - // now let's return json |
|
| 631 | - $this->_return_json(); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
| 637 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
| 638 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
| 639 | - * |
|
| 640 | - * @return void |
|
| 641 | - * @throws EE_Error |
|
| 642 | - * @throws ReflectionException |
|
| 643 | - */ |
|
| 644 | - protected function _extend_page_config_for_cpt() |
|
| 645 | - { |
|
| 646 | - // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
| 647 | - if ($this->raw_req_page !== $this->page_slug) { |
|
| 648 | - return; |
|
| 649 | - } |
|
| 650 | - // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
| 651 | - if (! empty($this->_cpt_object)) { |
|
| 652 | - $this->_page_routes = array_merge( |
|
| 653 | - [ |
|
| 654 | - 'create_new' => '_create_new_cpt_item', |
|
| 655 | - 'edit' => '_edit_cpt_item', |
|
| 656 | - ], |
|
| 657 | - $this->_page_routes |
|
| 658 | - ); |
|
| 659 | - $this->_page_config = array_merge( |
|
| 660 | - [ |
|
| 661 | - 'create_new' => [ |
|
| 662 | - 'nav' => [ |
|
| 663 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
| 664 | - 'order' => 5, |
|
| 665 | - ], |
|
| 666 | - 'require_nonce' => false, |
|
| 667 | - ], |
|
| 668 | - 'edit' => [ |
|
| 669 | - 'nav' => [ |
|
| 670 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
| 671 | - 'order' => 5, |
|
| 672 | - 'persistent' => false, |
|
| 673 | - 'url' => '', |
|
| 674 | - ], |
|
| 675 | - 'require_nonce' => false, |
|
| 676 | - ], |
|
| 677 | - ], |
|
| 678 | - $this->_page_config |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
| 682 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
| 683 | - return; |
|
| 684 | - } |
|
| 685 | - $this->_cpt_route = true; |
|
| 686 | - // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]); |
|
| 687 | - // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
| 688 | - if (empty($this->_cpt_object)) { |
|
| 689 | - $msg = sprintf( |
|
| 690 | - esc_html__( |
|
| 691 | - 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
| 692 | - 'event_espresso' |
|
| 693 | - ), |
|
| 694 | - $this->page_slug, |
|
| 695 | - $this->_req_action, |
|
| 696 | - get_class($this) |
|
| 697 | - ); |
|
| 698 | - throw new EE_Error($msg); |
|
| 699 | - } |
|
| 700 | - $this->_set_model_object($this->request->getRequestParam('post')); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
| 706 | - * |
|
| 707 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
| 708 | - * @param bool $ignore_route_check |
|
| 709 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
| 710 | - * @throws EE_Error |
|
| 711 | - * @throws InvalidArgumentException |
|
| 712 | - * @throws InvalidDataTypeException |
|
| 713 | - * @throws InvalidInterfaceException |
|
| 714 | - * @throws ReflectionException |
|
| 715 | - */ |
|
| 716 | - protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
| 717 | - { |
|
| 718 | - $model = null; |
|
| 719 | - if ( |
|
| 720 | - empty($this->_cpt_model_names) |
|
| 721 | - || ( |
|
| 722 | - ! $ignore_route_check |
|
| 723 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
| 724 | - ) |
|
| 725 | - || ( |
|
| 726 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 727 | - && $this->_cpt_model_obj->ID() === $id |
|
| 728 | - ) |
|
| 729 | - ) { |
|
| 730 | - // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
| 731 | - return; |
|
| 732 | - } |
|
| 733 | - // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
| 734 | - if ($ignore_route_check) { |
|
| 735 | - $post_type = get_post_type($id); |
|
| 736 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 737 | - $custom_post_types = $this->getLoader()->getShared( |
|
| 738 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 739 | - ); |
|
| 740 | - $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
| 741 | - if (isset($model_names[ $post_type ])) { |
|
| 742 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
| 743 | - } |
|
| 744 | - } else { |
|
| 745 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
| 746 | - } |
|
| 747 | - if ($model instanceof EEM_Base) { |
|
| 748 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
| 749 | - } |
|
| 750 | - do_action( |
|
| 751 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 752 | - $this->_cpt_model_obj, |
|
| 753 | - $req_type |
|
| 754 | - ); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * admin_init_global |
|
| 760 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 761 | - * This method executes for ALL EE Admin pages. |
|
| 762 | - * |
|
| 763 | - * @return void |
|
| 764 | - */ |
|
| 765 | - public function admin_init_global() |
|
| 766 | - { |
|
| 767 | - $post = $this->request->getRequestParam('post'); |
|
| 768 | - // its possible this is a new save so let's catch that instead |
|
| 769 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
| 770 | - $post_type = $post instanceof WP_Post ? $post->post_type : false; |
|
| 771 | - $current_route = isset($this->_req_data['current_route']) |
|
| 772 | - ? $this->_req_data['current_route'] |
|
| 773 | - : 'shouldneverwork'; |
|
| 774 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
| 775 | - ? $this->_cpt_routes[ $current_route ] |
|
| 776 | - : ''; |
|
| 777 | - add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 3); |
|
| 778 | - add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 3); |
|
| 779 | - if ($post_type === $route_to_check) { |
|
| 780 | - add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2); |
|
| 781 | - } |
|
| 782 | - // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
| 783 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 784 | - if (! empty($revision)) { |
|
| 785 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
| 786 | - // doing a restore? |
|
| 787 | - if (! empty($action) && $action === 'restore') { |
|
| 788 | - // get post for revision |
|
| 789 | - $rev_post = get_post($revision); |
|
| 790 | - $rev_parent = get_post($rev_post->post_parent); |
|
| 791 | - // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
| 792 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
| 793 | - add_filter('wp_redirect', [$this, 'revision_redirect'], 10, 2); |
|
| 794 | - // restores of revisions |
|
| 795 | - add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2); |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
| 800 | - if ($post_type && $post_type === $route_to_check) { |
|
| 801 | - // $post_id, $post |
|
| 802 | - add_action('save_post', [$this, 'insert_update'], 10, 3); |
|
| 803 | - // $post_id |
|
| 804 | - add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10); |
|
| 805 | - add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10); |
|
| 806 | - add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10); |
|
| 807 | - add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10); |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * Callback for the WordPress trashed_post hook. |
|
| 814 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
| 815 | - * |
|
| 816 | - * @param int $post_id |
|
| 817 | - * @throws \EE_Error |
|
| 818 | - * @throws ReflectionException |
|
| 819 | - */ |
|
| 820 | - public function before_trash_cpt_item($post_id) |
|
| 821 | - { |
|
| 822 | - $this->_set_model_object($post_id, true, 'trash'); |
|
| 823 | - // if our cpt object isn't existent then get out immediately. |
|
| 824 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 825 | - return; |
|
| 826 | - } |
|
| 827 | - $this->trash_cpt_item($post_id); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * Callback for the WordPress untrashed_post hook. |
|
| 833 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
| 834 | - * |
|
| 835 | - * @param $post_id |
|
| 836 | - * @throws \EE_Error |
|
| 837 | - * @throws ReflectionException |
|
| 838 | - */ |
|
| 839 | - public function before_restore_cpt_item($post_id) |
|
| 840 | - { |
|
| 841 | - $this->_set_model_object($post_id, true, 'restore'); |
|
| 842 | - // if our cpt object isn't existent then get out immediately. |
|
| 843 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 844 | - return; |
|
| 845 | - } |
|
| 846 | - $this->restore_cpt_item($post_id); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * Callback for the WordPress after_delete_post hook. |
|
| 852 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
| 853 | - * |
|
| 854 | - * @param $post_id |
|
| 855 | - * @throws \EE_Error |
|
| 856 | - * @throws ReflectionException |
|
| 857 | - */ |
|
| 858 | - public function before_delete_cpt_item($post_id) |
|
| 859 | - { |
|
| 860 | - $this->_set_model_object($post_id, true, 'delete'); |
|
| 861 | - // if our cpt object isn't existent then get out immediately. |
|
| 862 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 863 | - return; |
|
| 864 | - } |
|
| 865 | - $this->delete_cpt_item($post_id); |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
| 871 | - * accordingly. |
|
| 872 | - * |
|
| 873 | - * @return void |
|
| 874 | - * @throws EE_Error |
|
| 875 | - * @throws ReflectionException |
|
| 876 | - */ |
|
| 877 | - public function verify_cpt_object() |
|
| 878 | - { |
|
| 879 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
| 880 | - // verify event object |
|
| 881 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 882 | - throw new EE_Error( |
|
| 883 | - sprintf( |
|
| 884 | - esc_html__( |
|
| 885 | - 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
| 886 | - 'event_espresso' |
|
| 887 | - ), |
|
| 888 | - $label |
|
| 889 | - ) |
|
| 890 | - ); |
|
| 891 | - } |
|
| 892 | - // if auto-draft then throw an error |
|
| 893 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
| 894 | - EE_Error::overwrite_errors(); |
|
| 895 | - EE_Error::add_error( |
|
| 896 | - sprintf( |
|
| 897 | - esc_html__( |
|
| 898 | - 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
| 899 | - 'event_espresso' |
|
| 900 | - ), |
|
| 901 | - $label |
|
| 902 | - ), |
|
| 903 | - __FILE__, |
|
| 904 | - __FUNCTION__, |
|
| 905 | - __LINE__ |
|
| 906 | - ); |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - /** |
|
| 912 | - * admin_footer_scripts_global |
|
| 913 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 914 | - * will apply on ALL EE_Admin pages. |
|
| 915 | - * |
|
| 916 | - * @return void |
|
| 917 | - */ |
|
| 918 | - public function admin_footer_scripts_global() |
|
| 919 | - { |
|
| 920 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 921 | - $this->_add_admin_page_overlay(); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * add in any global scripts for cpt routes |
|
| 927 | - * |
|
| 928 | - * @return void |
|
| 929 | - */ |
|
| 930 | - public function load_global_scripts_styles() |
|
| 931 | - { |
|
| 932 | - parent::load_global_scripts_styles(); |
|
| 933 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 934 | - // setup custom post status object for localize script but only if we've got a cpt object |
|
| 935 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 936 | - if (! empty($statuses)) { |
|
| 937 | - // get ALL statuses! |
|
| 938 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
| 939 | - // setup object |
|
| 940 | - $ee_cpt_statuses = []; |
|
| 941 | - foreach ($statuses as $status => $label) { |
|
| 942 | - $ee_cpt_statuses[ $status ] = [ |
|
| 943 | - 'label' => $label, |
|
| 944 | - 'save_label' => sprintf( |
|
| 945 | - wp_strip_all_tags(__('Save as %s', 'event_espresso')), |
|
| 946 | - $label |
|
| 947 | - ), |
|
| 948 | - ]; |
|
| 949 | - } |
|
| 950 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
| 951 | - } |
|
| 952 | - } |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - |
|
| 956 | - /** |
|
| 957 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
| 958 | - * insert/updates |
|
| 959 | - * |
|
| 960 | - * @param int $post_id ID of post being updated |
|
| 961 | - * @param WP_Post $post Post object from WP |
|
| 962 | - * @param bool $update Whether this is an update or a new save. |
|
| 963 | - * @return void |
|
| 964 | - * @throws \EE_Error |
|
| 965 | - * @throws ReflectionException |
|
| 966 | - */ |
|
| 967 | - public function insert_update($post_id, $post, $update) |
|
| 968 | - { |
|
| 969 | - // make sure that if this is a revision OR trash action that we don't do any updates! |
|
| 970 | - if ( |
|
| 971 | - isset($this->_req_data['action']) |
|
| 972 | - && ( |
|
| 973 | - $this->_req_data['action'] === 'restore' |
|
| 974 | - || $this->_req_data['action'] === 'trash' |
|
| 975 | - ) |
|
| 976 | - ) { |
|
| 977 | - return; |
|
| 978 | - } |
|
| 979 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
| 980 | - // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
| 981 | - if ( |
|
| 982 | - $update |
|
| 983 | - && ( |
|
| 984 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 985 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
| 986 | - ) |
|
| 987 | - ) { |
|
| 988 | - return; |
|
| 989 | - } |
|
| 990 | - // check for autosave and update our req_data property accordingly. |
|
| 991 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
| 530 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 531 | + * |
|
| 532 | + * @param string $return the current html |
|
| 533 | + * @param int $id the post id for the page |
|
| 534 | + * @param string $new_title What the title is |
|
| 535 | + * @param string $new_slug what the slug is |
|
| 536 | + * @return string The new html string for the permalink area |
|
| 537 | + */ |
|
| 538 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
| 539 | + { |
|
| 540 | + $post = get_post($id); |
|
| 541 | + if ('publish' !== get_post_status($post)) { |
|
| 542 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
| 543 | + . get_preview_post_link($id) |
|
| 544 | + . '" class="button button-small">' |
|
| 545 | + . esc_html__('Preview', 'event_espresso') |
|
| 546 | + . '</a></span>' |
|
| 547 | + . "\n"; |
|
| 548 | + } |
|
| 549 | + return $return; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
| 555 | + * |
|
| 556 | + * @return void |
|
| 557 | + */ |
|
| 558 | + public function custom_post_stati_dropdown() |
|
| 559 | + { |
|
| 560 | + |
|
| 561 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 562 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
| 563 | + ? $statuses[ $this->_cpt_model_obj->status() ] |
|
| 564 | + : ''; |
|
| 565 | + $template_args = [ |
|
| 566 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
| 567 | + 'statuses' => $statuses, |
|
| 568 | + 'cur_status_label' => $cur_status_label, |
|
| 569 | + 'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label), |
|
| 570 | + ]; |
|
| 571 | + // we'll add a trash post status (WP doesn't add one for some reason) |
|
| 572 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
| 573 | + $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso'); |
|
| 574 | + $statuses['trash'] = esc_html__('Trashed', 'event_espresso'); |
|
| 575 | + $template_args['statuses'] = $statuses; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 579 | + EEH_Template::display_template($template, $template_args); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + public function setup_autosave_hooks() |
|
| 584 | + { |
|
| 585 | + $this->_set_autosave_containers(); |
|
| 586 | + $this->_load_autosave_scripts_styles(); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available |
|
| 592 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
| 593 | + * for the nonce in here, but then this method looks for two things: |
|
| 594 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
| 595 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
| 596 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
| 597 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
| 598 | + * template args. |
|
| 599 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
| 600 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
| 601 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
| 602 | + * $this->_template_args['data']['items'] = array( |
|
| 603 | + * 'event-datetime-ids' => '1,2,3'; |
|
| 604 | + * ); |
|
| 605 | + * Keep in mind the following things: |
|
| 606 | + * - "where" index is for the input with the id as that string. |
|
| 607 | + * - "what" index is what will be used for the value of that input. |
|
| 608 | + * |
|
| 609 | + * @return void |
|
| 610 | + * @throws EE_Error |
|
| 611 | + */ |
|
| 612 | + public function do_extra_autosave_stuff() |
|
| 613 | + { |
|
| 614 | + // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
| 615 | + $nonce = $this->request->getRequestParam('autosavenonce'); |
|
| 616 | + $this->_verify_nonce($nonce, 'autosave'); |
|
| 617 | + // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
| 618 | + if (! defined('DOING_AUTOSAVE')) { |
|
| 619 | + define('DOING_AUTOSAVE', true); |
|
| 620 | + } |
|
| 621 | + // if we made it here then the nonce checked out. Let's run our methods and actions |
|
| 622 | + $autosave = "_ee_autosave_{$this->_current_view}"; |
|
| 623 | + if (method_exists($this, $autosave)) { |
|
| 624 | + $this->$autosave(); |
|
| 625 | + } else { |
|
| 626 | + $this->_template_args['success'] = true; |
|
| 627 | + } |
|
| 628 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
| 629 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 630 | + // now let's return json |
|
| 631 | + $this->_return_json(); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
| 637 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
| 638 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
| 639 | + * |
|
| 640 | + * @return void |
|
| 641 | + * @throws EE_Error |
|
| 642 | + * @throws ReflectionException |
|
| 643 | + */ |
|
| 644 | + protected function _extend_page_config_for_cpt() |
|
| 645 | + { |
|
| 646 | + // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
| 647 | + if ($this->raw_req_page !== $this->page_slug) { |
|
| 648 | + return; |
|
| 649 | + } |
|
| 650 | + // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
| 651 | + if (! empty($this->_cpt_object)) { |
|
| 652 | + $this->_page_routes = array_merge( |
|
| 653 | + [ |
|
| 654 | + 'create_new' => '_create_new_cpt_item', |
|
| 655 | + 'edit' => '_edit_cpt_item', |
|
| 656 | + ], |
|
| 657 | + $this->_page_routes |
|
| 658 | + ); |
|
| 659 | + $this->_page_config = array_merge( |
|
| 660 | + [ |
|
| 661 | + 'create_new' => [ |
|
| 662 | + 'nav' => [ |
|
| 663 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
| 664 | + 'order' => 5, |
|
| 665 | + ], |
|
| 666 | + 'require_nonce' => false, |
|
| 667 | + ], |
|
| 668 | + 'edit' => [ |
|
| 669 | + 'nav' => [ |
|
| 670 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
| 671 | + 'order' => 5, |
|
| 672 | + 'persistent' => false, |
|
| 673 | + 'url' => '', |
|
| 674 | + ], |
|
| 675 | + 'require_nonce' => false, |
|
| 676 | + ], |
|
| 677 | + ], |
|
| 678 | + $this->_page_config |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | + // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
| 682 | + if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
| 683 | + return; |
|
| 684 | + } |
|
| 685 | + $this->_cpt_route = true; |
|
| 686 | + // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]); |
|
| 687 | + // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
| 688 | + if (empty($this->_cpt_object)) { |
|
| 689 | + $msg = sprintf( |
|
| 690 | + esc_html__( |
|
| 691 | + 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
| 692 | + 'event_espresso' |
|
| 693 | + ), |
|
| 694 | + $this->page_slug, |
|
| 695 | + $this->_req_action, |
|
| 696 | + get_class($this) |
|
| 697 | + ); |
|
| 698 | + throw new EE_Error($msg); |
|
| 699 | + } |
|
| 700 | + $this->_set_model_object($this->request->getRequestParam('post')); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
| 706 | + * |
|
| 707 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
| 708 | + * @param bool $ignore_route_check |
|
| 709 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
| 710 | + * @throws EE_Error |
|
| 711 | + * @throws InvalidArgumentException |
|
| 712 | + * @throws InvalidDataTypeException |
|
| 713 | + * @throws InvalidInterfaceException |
|
| 714 | + * @throws ReflectionException |
|
| 715 | + */ |
|
| 716 | + protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
| 717 | + { |
|
| 718 | + $model = null; |
|
| 719 | + if ( |
|
| 720 | + empty($this->_cpt_model_names) |
|
| 721 | + || ( |
|
| 722 | + ! $ignore_route_check |
|
| 723 | + && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
| 724 | + ) |
|
| 725 | + || ( |
|
| 726 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 727 | + && $this->_cpt_model_obj->ID() === $id |
|
| 728 | + ) |
|
| 729 | + ) { |
|
| 730 | + // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
| 731 | + return; |
|
| 732 | + } |
|
| 733 | + // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
| 734 | + if ($ignore_route_check) { |
|
| 735 | + $post_type = get_post_type($id); |
|
| 736 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 737 | + $custom_post_types = $this->getLoader()->getShared( |
|
| 738 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 739 | + ); |
|
| 740 | + $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
| 741 | + if (isset($model_names[ $post_type ])) { |
|
| 742 | + $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
| 743 | + } |
|
| 744 | + } else { |
|
| 745 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
| 746 | + } |
|
| 747 | + if ($model instanceof EEM_Base) { |
|
| 748 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
| 749 | + } |
|
| 750 | + do_action( |
|
| 751 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 752 | + $this->_cpt_model_obj, |
|
| 753 | + $req_type |
|
| 754 | + ); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * admin_init_global |
|
| 760 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 761 | + * This method executes for ALL EE Admin pages. |
|
| 762 | + * |
|
| 763 | + * @return void |
|
| 764 | + */ |
|
| 765 | + public function admin_init_global() |
|
| 766 | + { |
|
| 767 | + $post = $this->request->getRequestParam('post'); |
|
| 768 | + // its possible this is a new save so let's catch that instead |
|
| 769 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
| 770 | + $post_type = $post instanceof WP_Post ? $post->post_type : false; |
|
| 771 | + $current_route = isset($this->_req_data['current_route']) |
|
| 772 | + ? $this->_req_data['current_route'] |
|
| 773 | + : 'shouldneverwork'; |
|
| 774 | + $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
| 775 | + ? $this->_cpt_routes[ $current_route ] |
|
| 776 | + : ''; |
|
| 777 | + add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 3); |
|
| 778 | + add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 3); |
|
| 779 | + if ($post_type === $route_to_check) { |
|
| 780 | + add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2); |
|
| 781 | + } |
|
| 782 | + // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
| 783 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 784 | + if (! empty($revision)) { |
|
| 785 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
| 786 | + // doing a restore? |
|
| 787 | + if (! empty($action) && $action === 'restore') { |
|
| 788 | + // get post for revision |
|
| 789 | + $rev_post = get_post($revision); |
|
| 790 | + $rev_parent = get_post($rev_post->post_parent); |
|
| 791 | + // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
| 792 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
| 793 | + add_filter('wp_redirect', [$this, 'revision_redirect'], 10, 2); |
|
| 794 | + // restores of revisions |
|
| 795 | + add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
| 800 | + if ($post_type && $post_type === $route_to_check) { |
|
| 801 | + // $post_id, $post |
|
| 802 | + add_action('save_post', [$this, 'insert_update'], 10, 3); |
|
| 803 | + // $post_id |
|
| 804 | + add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10); |
|
| 805 | + add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10); |
|
| 806 | + add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10); |
|
| 807 | + add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10); |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * Callback for the WordPress trashed_post hook. |
|
| 814 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
| 815 | + * |
|
| 816 | + * @param int $post_id |
|
| 817 | + * @throws \EE_Error |
|
| 818 | + * @throws ReflectionException |
|
| 819 | + */ |
|
| 820 | + public function before_trash_cpt_item($post_id) |
|
| 821 | + { |
|
| 822 | + $this->_set_model_object($post_id, true, 'trash'); |
|
| 823 | + // if our cpt object isn't existent then get out immediately. |
|
| 824 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 825 | + return; |
|
| 826 | + } |
|
| 827 | + $this->trash_cpt_item($post_id); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * Callback for the WordPress untrashed_post hook. |
|
| 833 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
| 834 | + * |
|
| 835 | + * @param $post_id |
|
| 836 | + * @throws \EE_Error |
|
| 837 | + * @throws ReflectionException |
|
| 838 | + */ |
|
| 839 | + public function before_restore_cpt_item($post_id) |
|
| 840 | + { |
|
| 841 | + $this->_set_model_object($post_id, true, 'restore'); |
|
| 842 | + // if our cpt object isn't existent then get out immediately. |
|
| 843 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 844 | + return; |
|
| 845 | + } |
|
| 846 | + $this->restore_cpt_item($post_id); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * Callback for the WordPress after_delete_post hook. |
|
| 852 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
| 853 | + * |
|
| 854 | + * @param $post_id |
|
| 855 | + * @throws \EE_Error |
|
| 856 | + * @throws ReflectionException |
|
| 857 | + */ |
|
| 858 | + public function before_delete_cpt_item($post_id) |
|
| 859 | + { |
|
| 860 | + $this->_set_model_object($post_id, true, 'delete'); |
|
| 861 | + // if our cpt object isn't existent then get out immediately. |
|
| 862 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 863 | + return; |
|
| 864 | + } |
|
| 865 | + $this->delete_cpt_item($post_id); |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
| 871 | + * accordingly. |
|
| 872 | + * |
|
| 873 | + * @return void |
|
| 874 | + * @throws EE_Error |
|
| 875 | + * @throws ReflectionException |
|
| 876 | + */ |
|
| 877 | + public function verify_cpt_object() |
|
| 878 | + { |
|
| 879 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
| 880 | + // verify event object |
|
| 881 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 882 | + throw new EE_Error( |
|
| 883 | + sprintf( |
|
| 884 | + esc_html__( |
|
| 885 | + 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
| 886 | + 'event_espresso' |
|
| 887 | + ), |
|
| 888 | + $label |
|
| 889 | + ) |
|
| 890 | + ); |
|
| 891 | + } |
|
| 892 | + // if auto-draft then throw an error |
|
| 893 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
| 894 | + EE_Error::overwrite_errors(); |
|
| 895 | + EE_Error::add_error( |
|
| 896 | + sprintf( |
|
| 897 | + esc_html__( |
|
| 898 | + 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
| 899 | + 'event_espresso' |
|
| 900 | + ), |
|
| 901 | + $label |
|
| 902 | + ), |
|
| 903 | + __FILE__, |
|
| 904 | + __FUNCTION__, |
|
| 905 | + __LINE__ |
|
| 906 | + ); |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + /** |
|
| 912 | + * admin_footer_scripts_global |
|
| 913 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 914 | + * will apply on ALL EE_Admin pages. |
|
| 915 | + * |
|
| 916 | + * @return void |
|
| 917 | + */ |
|
| 918 | + public function admin_footer_scripts_global() |
|
| 919 | + { |
|
| 920 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 921 | + $this->_add_admin_page_overlay(); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * add in any global scripts for cpt routes |
|
| 927 | + * |
|
| 928 | + * @return void |
|
| 929 | + */ |
|
| 930 | + public function load_global_scripts_styles() |
|
| 931 | + { |
|
| 932 | + parent::load_global_scripts_styles(); |
|
| 933 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 934 | + // setup custom post status object for localize script but only if we've got a cpt object |
|
| 935 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 936 | + if (! empty($statuses)) { |
|
| 937 | + // get ALL statuses! |
|
| 938 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
| 939 | + // setup object |
|
| 940 | + $ee_cpt_statuses = []; |
|
| 941 | + foreach ($statuses as $status => $label) { |
|
| 942 | + $ee_cpt_statuses[ $status ] = [ |
|
| 943 | + 'label' => $label, |
|
| 944 | + 'save_label' => sprintf( |
|
| 945 | + wp_strip_all_tags(__('Save as %s', 'event_espresso')), |
|
| 946 | + $label |
|
| 947 | + ), |
|
| 948 | + ]; |
|
| 949 | + } |
|
| 950 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
| 951 | + } |
|
| 952 | + } |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + |
|
| 956 | + /** |
|
| 957 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
| 958 | + * insert/updates |
|
| 959 | + * |
|
| 960 | + * @param int $post_id ID of post being updated |
|
| 961 | + * @param WP_Post $post Post object from WP |
|
| 962 | + * @param bool $update Whether this is an update or a new save. |
|
| 963 | + * @return void |
|
| 964 | + * @throws \EE_Error |
|
| 965 | + * @throws ReflectionException |
|
| 966 | + */ |
|
| 967 | + public function insert_update($post_id, $post, $update) |
|
| 968 | + { |
|
| 969 | + // make sure that if this is a revision OR trash action that we don't do any updates! |
|
| 970 | + if ( |
|
| 971 | + isset($this->_req_data['action']) |
|
| 972 | + && ( |
|
| 973 | + $this->_req_data['action'] === 'restore' |
|
| 974 | + || $this->_req_data['action'] === 'trash' |
|
| 975 | + ) |
|
| 976 | + ) { |
|
| 977 | + return; |
|
| 978 | + } |
|
| 979 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
| 980 | + // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
| 981 | + if ( |
|
| 982 | + $update |
|
| 983 | + && ( |
|
| 984 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 985 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
| 986 | + ) |
|
| 987 | + ) { |
|
| 988 | + return; |
|
| 989 | + } |
|
| 990 | + // check for autosave and update our req_data property accordingly. |
|
| 991 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
| 992 | 992 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
| 993 | 993 | |
| 994 | 994 | foreach ( (array) $values as $key => $value ) { |
@@ -998,547 +998,547 @@ discard block |
||
| 998 | 998 | |
| 999 | 999 | }/**/ // TODO reactivate after autosave is implemented in 4.2 |
| 1000 | 1000 | |
| 1001 | - // take care of updating any selected page_template IF this cpt supports it. |
|
| 1002 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
| 1003 | - // wp version aware. |
|
| 1004 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
| 1005 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
| 1006 | - } else { |
|
| 1007 | - $post->page_template = $this->_req_data['page_template']; |
|
| 1008 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
| 1009 | - } |
|
| 1010 | - if ( |
|
| 1011 | - 'default' != $this->_req_data['page_template'] |
|
| 1012 | - && ! isset($page_templates[ $this->_req_data['page_template'] ]) |
|
| 1013 | - ) { |
|
| 1014 | - EE_Error::add_error( |
|
| 1015 | - esc_html__('Invalid Page Template.', 'event_espresso'), |
|
| 1016 | - __FILE__, |
|
| 1017 | - __FUNCTION__, |
|
| 1018 | - __LINE__ |
|
| 1019 | - ); |
|
| 1020 | - } else { |
|
| 1021 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
| 1022 | - } |
|
| 1023 | - } |
|
| 1024 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 1025 | - return; |
|
| 1026 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
| 1027 | - $this->_insert_update_cpt_item($post_id, $post); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
| 1033 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
| 1034 | - * so we don't have to check for our CPT. |
|
| 1035 | - * |
|
| 1036 | - * @param int $post_id ID of the post |
|
| 1037 | - * @return void |
|
| 1038 | - */ |
|
| 1039 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
| 1040 | - { |
|
| 1041 | - // only do this if we're actually processing one of our CPTs |
|
| 1042 | - // if our cpt object isn't existent then get out immediately. |
|
| 1043 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 1044 | - return; |
|
| 1045 | - } |
|
| 1046 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
| 1047 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
| 1048 | - // our cpts may have comments so let's take care of that too |
|
| 1049 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - |
|
| 1053 | - /** |
|
| 1054 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
| 1055 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
| 1056 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
| 1057 | - * |
|
| 1058 | - * @param int $post_id ID of cpt item |
|
| 1059 | - * @param int $revision_id ID of revision being restored |
|
| 1060 | - * @return void |
|
| 1061 | - */ |
|
| 1062 | - public function restore_revision($post_id, $revision_id) |
|
| 1063 | - { |
|
| 1064 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
| 1065 | - // global action |
|
| 1066 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
| 1067 | - // class specific action so you can limit hooking into a specific page. |
|
| 1068 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * @param int $post_id ID of cpt item |
|
| 1074 | - * @param int $revision_id ID of revision for item |
|
| 1075 | - * @return void |
|
| 1076 | - * @see restore_revision() for details |
|
| 1077 | - */ |
|
| 1078 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
| 1083 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
| 1084 | - * To fix we have to reset the current_screen using the page_slug |
|
| 1085 | - * (which is identical - or should be - to our registered_post_type id.) |
|
| 1086 | - * Also, since the core WP file loads the admin_header.php for WP |
|
| 1087 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
| 1088 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
| 1089 | - * |
|
| 1090 | - * @return void |
|
| 1091 | - * @throws EE_Error |
|
| 1092 | - * @throws EE_Error |
|
| 1093 | - */ |
|
| 1094 | - public function modify_current_screen() |
|
| 1095 | - { |
|
| 1096 | - // ONLY do this if the current page_route IS a cpt route |
|
| 1097 | - if (! $this->_cpt_route) { |
|
| 1098 | - return; |
|
| 1099 | - } |
|
| 1100 | - // routing things REALLY early b/c this is a cpt admin page |
|
| 1101 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
| 1102 | - $this->_current_screen = get_current_screen(); |
|
| 1103 | - $this->_current_screen->base = 'event-espresso'; |
|
| 1104 | - $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
| 1105 | - /*try { |
|
| 1001 | + // take care of updating any selected page_template IF this cpt supports it. |
|
| 1002 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
| 1003 | + // wp version aware. |
|
| 1004 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
| 1005 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
| 1006 | + } else { |
|
| 1007 | + $post->page_template = $this->_req_data['page_template']; |
|
| 1008 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
| 1009 | + } |
|
| 1010 | + if ( |
|
| 1011 | + 'default' != $this->_req_data['page_template'] |
|
| 1012 | + && ! isset($page_templates[ $this->_req_data['page_template'] ]) |
|
| 1013 | + ) { |
|
| 1014 | + EE_Error::add_error( |
|
| 1015 | + esc_html__('Invalid Page Template.', 'event_espresso'), |
|
| 1016 | + __FILE__, |
|
| 1017 | + __FUNCTION__, |
|
| 1018 | + __LINE__ |
|
| 1019 | + ); |
|
| 1020 | + } else { |
|
| 1021 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
| 1022 | + } |
|
| 1023 | + } |
|
| 1024 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 1025 | + return; |
|
| 1026 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
| 1027 | + $this->_insert_update_cpt_item($post_id, $post); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
| 1033 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
| 1034 | + * so we don't have to check for our CPT. |
|
| 1035 | + * |
|
| 1036 | + * @param int $post_id ID of the post |
|
| 1037 | + * @return void |
|
| 1038 | + */ |
|
| 1039 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
| 1040 | + { |
|
| 1041 | + // only do this if we're actually processing one of our CPTs |
|
| 1042 | + // if our cpt object isn't existent then get out immediately. |
|
| 1043 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 1044 | + return; |
|
| 1045 | + } |
|
| 1046 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
| 1047 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
| 1048 | + // our cpts may have comments so let's take care of that too |
|
| 1049 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + |
|
| 1053 | + /** |
|
| 1054 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
| 1055 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
| 1056 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
| 1057 | + * |
|
| 1058 | + * @param int $post_id ID of cpt item |
|
| 1059 | + * @param int $revision_id ID of revision being restored |
|
| 1060 | + * @return void |
|
| 1061 | + */ |
|
| 1062 | + public function restore_revision($post_id, $revision_id) |
|
| 1063 | + { |
|
| 1064 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
| 1065 | + // global action |
|
| 1066 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
| 1067 | + // class specific action so you can limit hooking into a specific page. |
|
| 1068 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * @param int $post_id ID of cpt item |
|
| 1074 | + * @param int $revision_id ID of revision for item |
|
| 1075 | + * @return void |
|
| 1076 | + * @see restore_revision() for details |
|
| 1077 | + */ |
|
| 1078 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
| 1083 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
| 1084 | + * To fix we have to reset the current_screen using the page_slug |
|
| 1085 | + * (which is identical - or should be - to our registered_post_type id.) |
|
| 1086 | + * Also, since the core WP file loads the admin_header.php for WP |
|
| 1087 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
| 1088 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
| 1089 | + * |
|
| 1090 | + * @return void |
|
| 1091 | + * @throws EE_Error |
|
| 1092 | + * @throws EE_Error |
|
| 1093 | + */ |
|
| 1094 | + public function modify_current_screen() |
|
| 1095 | + { |
|
| 1096 | + // ONLY do this if the current page_route IS a cpt route |
|
| 1097 | + if (! $this->_cpt_route) { |
|
| 1098 | + return; |
|
| 1099 | + } |
|
| 1100 | + // routing things REALLY early b/c this is a cpt admin page |
|
| 1101 | + set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
| 1102 | + $this->_current_screen = get_current_screen(); |
|
| 1103 | + $this->_current_screen->base = 'event-espresso'; |
|
| 1104 | + $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
| 1105 | + /*try { |
|
| 1106 | 1106 | $this->_route_admin_request(); |
| 1107 | 1107 | } catch ( EE_Error $e ) { |
| 1108 | 1108 | $e->get_error(); |
| 1109 | 1109 | }/**/ |
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
| 1115 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
| 1116 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
| 1117 | - * default to be. |
|
| 1118 | - * |
|
| 1119 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
| 1120 | - * @return string |
|
| 1121 | - */ |
|
| 1122 | - public function add_custom_editor_default_title($title) |
|
| 1123 | - { |
|
| 1124 | - return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
| 1125 | - ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
| 1126 | - : $title; |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
| 1132 | - * |
|
| 1133 | - * @param string $shortlink The already generated shortlink |
|
| 1134 | - * @param int $id Post ID for this item |
|
| 1135 | - * @param string $context The context for the link |
|
| 1136 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
| 1137 | - * @return string |
|
| 1138 | - */ |
|
| 1139 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
| 1140 | - { |
|
| 1141 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
| 1142 | - $post = get_post($id); |
|
| 1143 | - if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
| 1144 | - $shortlink = home_url('?p=' . $post->ID); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - return $shortlink; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
| 1153 | - * already run in modify_current_screen()) |
|
| 1154 | - * |
|
| 1155 | - * @return void |
|
| 1156 | - */ |
|
| 1157 | - public function route_admin_request() |
|
| 1158 | - { |
|
| 1159 | - if ($this->_cpt_route) { |
|
| 1160 | - return; |
|
| 1161 | - } |
|
| 1162 | - try { |
|
| 1163 | - $this->_route_admin_request(); |
|
| 1164 | - } catch (EE_Error $e) { |
|
| 1165 | - $e->get_error(); |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
| 1172 | - * |
|
| 1173 | - * @return void |
|
| 1174 | - */ |
|
| 1175 | - public function cpt_post_form_hidden_input() |
|
| 1176 | - { |
|
| 1177 | - // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
| 1178 | - echo ' |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
| 1115 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
| 1116 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
| 1117 | + * default to be. |
|
| 1118 | + * |
|
| 1119 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
| 1120 | + * @return string |
|
| 1121 | + */ |
|
| 1122 | + public function add_custom_editor_default_title($title) |
|
| 1123 | + { |
|
| 1124 | + return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
| 1125 | + ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
| 1126 | + : $title; |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
| 1132 | + * |
|
| 1133 | + * @param string $shortlink The already generated shortlink |
|
| 1134 | + * @param int $id Post ID for this item |
|
| 1135 | + * @param string $context The context for the link |
|
| 1136 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
| 1137 | + * @return string |
|
| 1138 | + */ |
|
| 1139 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
| 1140 | + { |
|
| 1141 | + if (! empty($id) && get_option('permalink_structure') !== '') { |
|
| 1142 | + $post = get_post($id); |
|
| 1143 | + if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
| 1144 | + $shortlink = home_url('?p=' . $post->ID); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + return $shortlink; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
| 1153 | + * already run in modify_current_screen()) |
|
| 1154 | + * |
|
| 1155 | + * @return void |
|
| 1156 | + */ |
|
| 1157 | + public function route_admin_request() |
|
| 1158 | + { |
|
| 1159 | + if ($this->_cpt_route) { |
|
| 1160 | + return; |
|
| 1161 | + } |
|
| 1162 | + try { |
|
| 1163 | + $this->_route_admin_request(); |
|
| 1164 | + } catch (EE_Error $e) { |
|
| 1165 | + $e->get_error(); |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
| 1172 | + * |
|
| 1173 | + * @return void |
|
| 1174 | + */ |
|
| 1175 | + public function cpt_post_form_hidden_input() |
|
| 1176 | + { |
|
| 1177 | + // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
| 1178 | + echo ' |
|
| 1179 | 1179 | <input type="hidden" name="ee_cpt_item_redirect_url" value="' . esc_url_raw($this->_admin_base_url) . '"/> |
| 1180 | 1180 | <div id="ee-cpt-hidden-inputs"> |
| 1181 | 1181 | <input type="hidden" id="current_route" name="current_route" value="' . esc_attr($this->_current_view) . '"/> |
| 1182 | 1182 | <input type="hidden" id="current_page" name="current_page" value="' . esc_attr($this->page_slug) . '"/> |
| 1183 | 1183 | </div>'; |
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - |
|
| 1187 | - /** |
|
| 1188 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
| 1189 | - * |
|
| 1190 | - * @param string $location Original location url |
|
| 1191 | - * @param int $status Status for http header |
|
| 1192 | - * @return string new (or original) url to redirect to. |
|
| 1193 | - * @throws EE_Error |
|
| 1194 | - * @throws EE_Error |
|
| 1195 | - */ |
|
| 1196 | - public function revision_redirect($location, $status) |
|
| 1197 | - { |
|
| 1198 | - // get revision |
|
| 1199 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 1200 | - // can't do anything without revision so let's get out if not present |
|
| 1201 | - if (empty($rev_id)) { |
|
| 1202 | - return $location; |
|
| 1203 | - } |
|
| 1204 | - // get rev_post_data |
|
| 1205 | - $rev = get_post($rev_id); |
|
| 1206 | - $admin_url = $this->_admin_base_url; |
|
| 1207 | - $query_args = [ |
|
| 1208 | - 'action' => 'edit', |
|
| 1209 | - 'post' => $rev->post_parent, |
|
| 1210 | - 'revision' => $rev_id, |
|
| 1211 | - 'message' => 5, |
|
| 1212 | - ]; |
|
| 1213 | - $this->_process_notices($query_args, true); |
|
| 1214 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
| 1220 | - * |
|
| 1221 | - * @param string $link the original generated link |
|
| 1222 | - * @param int $id post id |
|
| 1223 | - * @param string $context optional, defaults to display. How to write the '&' |
|
| 1224 | - * @return string the link |
|
| 1225 | - */ |
|
| 1226 | - public function modify_edit_post_link($link, $id, $context) |
|
| 1227 | - { |
|
| 1228 | - $post = get_post($id); |
|
| 1229 | - if ( |
|
| 1230 | - ! isset($this->_req_data['action']) |
|
| 1231 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1232 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
| 1233 | - ) { |
|
| 1234 | - return $link; |
|
| 1235 | - } |
|
| 1236 | - $query_args = [ |
|
| 1237 | - 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
| 1238 | - ? $this->_cpt_edit_routes[ $post->post_type ] |
|
| 1239 | - : 'edit', |
|
| 1240 | - 'post' => $id, |
|
| 1241 | - ]; |
|
| 1242 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - /** |
|
| 1247 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
| 1248 | - * our routes. |
|
| 1249 | - * |
|
| 1250 | - * @param string $delete_link original delete link |
|
| 1251 | - * @param int $post_id id of cpt object |
|
| 1252 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
| 1253 | - * @return string new delete link |
|
| 1254 | - * @throws EE_Error |
|
| 1255 | - * @throws ReflectionException |
|
| 1256 | - */ |
|
| 1257 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
| 1258 | - { |
|
| 1259 | - $post = get_post($post_id); |
|
| 1260 | - |
|
| 1261 | - if ( |
|
| 1262 | - empty($this->_req_data['action']) |
|
| 1263 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1264 | - || ! $post instanceof WP_Post |
|
| 1265 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
| 1266 | - ) { |
|
| 1267 | - return $delete_link; |
|
| 1268 | - } |
|
| 1269 | - $this->_set_model_object($post->ID, true); |
|
| 1270 | - |
|
| 1271 | - // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
| 1272 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1273 | - |
|
| 1274 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
| 1275 | - [ |
|
| 1276 | - 'page' => $this->_req_data['page'], |
|
| 1277 | - 'action' => $action, |
|
| 1278 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
| 1279 | - => $post->ID, |
|
| 1280 | - ], |
|
| 1281 | - admin_url() |
|
| 1282 | - ); |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - |
|
| 1286 | - /** |
|
| 1287 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
| 1288 | - * so that we can hijack the default redirect locations for wp custom post types |
|
| 1289 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
| 1290 | - * |
|
| 1291 | - * @param string $location This is the incoming currently set redirect location |
|
| 1292 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
| 1293 | - * @return string the new location to redirect to |
|
| 1294 | - * @throws EE_Error |
|
| 1295 | - * @throws EE_Error |
|
| 1296 | - */ |
|
| 1297 | - public function cpt_post_location_redirect($location, $post_id) |
|
| 1298 | - { |
|
| 1299 | - // we DO have a match so let's setup the url |
|
| 1300 | - // we have to get the post to determine our route |
|
| 1301 | - $post = get_post($post_id); |
|
| 1302 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
| 1303 | - // shared query_args |
|
| 1304 | - $query_args = ['action' => $edit_route, 'post' => $post_id]; |
|
| 1305 | - $admin_url = $this->_admin_base_url; |
|
| 1306 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
| 1307 | - $status = get_post_status($post_id); |
|
| 1308 | - if (isset($this->_req_data['publish'])) { |
|
| 1309 | - switch ($status) { |
|
| 1310 | - case 'pending': |
|
| 1311 | - $message = 8; |
|
| 1312 | - break; |
|
| 1313 | - case 'future': |
|
| 1314 | - $message = 9; |
|
| 1315 | - break; |
|
| 1316 | - default: |
|
| 1317 | - $message = 6; |
|
| 1318 | - } |
|
| 1319 | - } else { |
|
| 1320 | - $message = 'draft' === $status ? 10 : 1; |
|
| 1321 | - } |
|
| 1322 | - } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
| 1323 | - $message = 2; |
|
| 1324 | - } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
| 1325 | - $message = 3; |
|
| 1326 | - } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
| 1327 | - $message = 7; |
|
| 1328 | - } else { |
|
| 1329 | - $message = 4; |
|
| 1330 | - } |
|
| 1331 | - // change the message if the post type is not viewable on the frontend |
|
| 1332 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
| 1333 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
| 1334 | - $query_args = array_merge(['message' => $message], $query_args); |
|
| 1335 | - $this->_process_notices($query_args, true); |
|
| 1336 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - |
|
| 1340 | - /** |
|
| 1341 | - * This method is called to inject nav tabs on core WP cpt pages |
|
| 1342 | - * |
|
| 1343 | - * @return void |
|
| 1344 | - * @throws EE_Error |
|
| 1345 | - * @throws EE_Error |
|
| 1346 | - */ |
|
| 1347 | - public function inject_nav_tabs() |
|
| 1348 | - { |
|
| 1349 | - echo wp_kses($this->_get_main_nav_tabs(), AllowedTags::getWithFormTags()); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * This just sets up the post update messages when an update form is loaded |
|
| 1355 | - * |
|
| 1356 | - * @param array $messages the original messages array |
|
| 1357 | - * @return array the new messages array |
|
| 1358 | - */ |
|
| 1359 | - public function post_update_messages($messages) |
|
| 1360 | - { |
|
| 1361 | - global $post; |
|
| 1362 | - $id = $this->request->getRequestParam('post'); |
|
| 1363 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
| 1364 | - $revision = $this->request->getRequestParam('revision', 0, 'int'); |
|
| 1365 | - |
|
| 1366 | - $messages[ $post->post_type ] = [ |
|
| 1367 | - 0 => '', // Unused. Messages start at index 1. |
|
| 1368 | - 1 => sprintf( |
|
| 1369 | - esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1370 | - $this->_cpt_object->labels->singular_name, |
|
| 1371 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1372 | - '</a>' |
|
| 1373 | - ), |
|
| 1374 | - 2 => esc_html__('Custom field updated', 'event_espresso'), |
|
| 1375 | - 3 => esc_html__('Custom field deleted.', 'event_espresso'), |
|
| 1376 | - 4 => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1377 | - 5 => $revision |
|
| 1378 | - ? sprintf( |
|
| 1379 | - esc_html__('%s restored to revision from %s', 'event_espresso'), |
|
| 1380 | - $this->_cpt_object->labels->singular_name, |
|
| 1381 | - wp_post_revision_title($revision, false) |
|
| 1382 | - ) |
|
| 1383 | - : false, |
|
| 1384 | - 6 => sprintf( |
|
| 1385 | - esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1386 | - $this->_cpt_object->labels->singular_name, |
|
| 1387 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1388 | - '</a>' |
|
| 1389 | - ), |
|
| 1390 | - 7 => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1391 | - 8 => sprintf( |
|
| 1392 | - esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
| 1393 | - $this->_cpt_object->labels->singular_name, |
|
| 1394 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1395 | - '</a>' |
|
| 1396 | - ), |
|
| 1397 | - 9 => sprintf( |
|
| 1398 | - esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
| 1399 | - $this->_cpt_object->labels->singular_name, |
|
| 1400 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
| 1401 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1402 | - '</a>' |
|
| 1403 | - ), |
|
| 1404 | - 10 => sprintf( |
|
| 1405 | - esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
| 1406 | - $this->_cpt_object->labels->singular_name, |
|
| 1407 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1408 | - '</a>' |
|
| 1409 | - ), |
|
| 1410 | - ]; |
|
| 1411 | - return $messages; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - |
|
| 1415 | - /** |
|
| 1416 | - * default method for the 'create_new' route for cpt admin pages. |
|
| 1417 | - * For reference what to include in here, see wp-admin/post-new.php |
|
| 1418 | - * |
|
| 1419 | - * @return void |
|
| 1420 | - */ |
|
| 1421 | - protected function _create_new_cpt_item() |
|
| 1422 | - { |
|
| 1423 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1424 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1425 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1426 | - $post_type_object = $this->_cpt_object; |
|
| 1427 | - $title = $post_type_object->labels->add_new_item; |
|
| 1428 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
| 1429 | - add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1430 | - // modify the default editor title field with default title. |
|
| 1431 | - add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10); |
|
| 1432 | - $this->loadEditorTemplate(true); |
|
| 1433 | - } |
|
| 1434 | - |
|
| 1435 | - |
|
| 1436 | - /** |
|
| 1437 | - * Enqueues auto-save and loads the editor template |
|
| 1438 | - * |
|
| 1439 | - * @param bool $creating |
|
| 1440 | - */ |
|
| 1441 | - private function loadEditorTemplate($creating = true) |
|
| 1442 | - { |
|
| 1443 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1444 | - // these vars are used by the template |
|
| 1445 | - $editing = true; |
|
| 1446 | - $post_ID = $post->ID; |
|
| 1447 | - if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
| 1448 | - // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
| 1449 | - // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
| 1450 | - if ($creating) { |
|
| 1451 | - wp_enqueue_script('autosave'); |
|
| 1452 | - } else { |
|
| 1453 | - if ( |
|
| 1454 | - isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1455 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
| 1456 | - ) { |
|
| 1457 | - $create_new_action = apply_filters( |
|
| 1458 | - 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
| 1459 | - 'create_new', |
|
| 1460 | - $this |
|
| 1461 | - ); |
|
| 1462 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1463 | - [ |
|
| 1464 | - 'action' => $create_new_action, |
|
| 1465 | - 'page' => $this->page_slug, |
|
| 1466 | - ], |
|
| 1467 | - 'admin.php' |
|
| 1468 | - ); |
|
| 1469 | - } |
|
| 1470 | - } |
|
| 1471 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1472 | - } |
|
| 1473 | - } |
|
| 1474 | - |
|
| 1475 | - |
|
| 1476 | - public function add_new_admin_page_global() |
|
| 1477 | - { |
|
| 1478 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
| 1479 | - ?> |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + |
|
| 1187 | + /** |
|
| 1188 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
| 1189 | + * |
|
| 1190 | + * @param string $location Original location url |
|
| 1191 | + * @param int $status Status for http header |
|
| 1192 | + * @return string new (or original) url to redirect to. |
|
| 1193 | + * @throws EE_Error |
|
| 1194 | + * @throws EE_Error |
|
| 1195 | + */ |
|
| 1196 | + public function revision_redirect($location, $status) |
|
| 1197 | + { |
|
| 1198 | + // get revision |
|
| 1199 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 1200 | + // can't do anything without revision so let's get out if not present |
|
| 1201 | + if (empty($rev_id)) { |
|
| 1202 | + return $location; |
|
| 1203 | + } |
|
| 1204 | + // get rev_post_data |
|
| 1205 | + $rev = get_post($rev_id); |
|
| 1206 | + $admin_url = $this->_admin_base_url; |
|
| 1207 | + $query_args = [ |
|
| 1208 | + 'action' => 'edit', |
|
| 1209 | + 'post' => $rev->post_parent, |
|
| 1210 | + 'revision' => $rev_id, |
|
| 1211 | + 'message' => 5, |
|
| 1212 | + ]; |
|
| 1213 | + $this->_process_notices($query_args, true); |
|
| 1214 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
| 1220 | + * |
|
| 1221 | + * @param string $link the original generated link |
|
| 1222 | + * @param int $id post id |
|
| 1223 | + * @param string $context optional, defaults to display. How to write the '&' |
|
| 1224 | + * @return string the link |
|
| 1225 | + */ |
|
| 1226 | + public function modify_edit_post_link($link, $id, $context) |
|
| 1227 | + { |
|
| 1228 | + $post = get_post($id); |
|
| 1229 | + if ( |
|
| 1230 | + ! isset($this->_req_data['action']) |
|
| 1231 | + || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1232 | + || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
| 1233 | + ) { |
|
| 1234 | + return $link; |
|
| 1235 | + } |
|
| 1236 | + $query_args = [ |
|
| 1237 | + 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
| 1238 | + ? $this->_cpt_edit_routes[ $post->post_type ] |
|
| 1239 | + : 'edit', |
|
| 1240 | + 'post' => $id, |
|
| 1241 | + ]; |
|
| 1242 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + /** |
|
| 1247 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
| 1248 | + * our routes. |
|
| 1249 | + * |
|
| 1250 | + * @param string $delete_link original delete link |
|
| 1251 | + * @param int $post_id id of cpt object |
|
| 1252 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
| 1253 | + * @return string new delete link |
|
| 1254 | + * @throws EE_Error |
|
| 1255 | + * @throws ReflectionException |
|
| 1256 | + */ |
|
| 1257 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
| 1258 | + { |
|
| 1259 | + $post = get_post($post_id); |
|
| 1260 | + |
|
| 1261 | + if ( |
|
| 1262 | + empty($this->_req_data['action']) |
|
| 1263 | + || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1264 | + || ! $post instanceof WP_Post |
|
| 1265 | + || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
| 1266 | + ) { |
|
| 1267 | + return $delete_link; |
|
| 1268 | + } |
|
| 1269 | + $this->_set_model_object($post->ID, true); |
|
| 1270 | + |
|
| 1271 | + // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
| 1272 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1273 | + |
|
| 1274 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
| 1275 | + [ |
|
| 1276 | + 'page' => $this->_req_data['page'], |
|
| 1277 | + 'action' => $action, |
|
| 1278 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
| 1279 | + => $post->ID, |
|
| 1280 | + ], |
|
| 1281 | + admin_url() |
|
| 1282 | + ); |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + |
|
| 1286 | + /** |
|
| 1287 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
| 1288 | + * so that we can hijack the default redirect locations for wp custom post types |
|
| 1289 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
| 1290 | + * |
|
| 1291 | + * @param string $location This is the incoming currently set redirect location |
|
| 1292 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
| 1293 | + * @return string the new location to redirect to |
|
| 1294 | + * @throws EE_Error |
|
| 1295 | + * @throws EE_Error |
|
| 1296 | + */ |
|
| 1297 | + public function cpt_post_location_redirect($location, $post_id) |
|
| 1298 | + { |
|
| 1299 | + // we DO have a match so let's setup the url |
|
| 1300 | + // we have to get the post to determine our route |
|
| 1301 | + $post = get_post($post_id); |
|
| 1302 | + $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
| 1303 | + // shared query_args |
|
| 1304 | + $query_args = ['action' => $edit_route, 'post' => $post_id]; |
|
| 1305 | + $admin_url = $this->_admin_base_url; |
|
| 1306 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
| 1307 | + $status = get_post_status($post_id); |
|
| 1308 | + if (isset($this->_req_data['publish'])) { |
|
| 1309 | + switch ($status) { |
|
| 1310 | + case 'pending': |
|
| 1311 | + $message = 8; |
|
| 1312 | + break; |
|
| 1313 | + case 'future': |
|
| 1314 | + $message = 9; |
|
| 1315 | + break; |
|
| 1316 | + default: |
|
| 1317 | + $message = 6; |
|
| 1318 | + } |
|
| 1319 | + } else { |
|
| 1320 | + $message = 'draft' === $status ? 10 : 1; |
|
| 1321 | + } |
|
| 1322 | + } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
| 1323 | + $message = 2; |
|
| 1324 | + } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
| 1325 | + $message = 3; |
|
| 1326 | + } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
| 1327 | + $message = 7; |
|
| 1328 | + } else { |
|
| 1329 | + $message = 4; |
|
| 1330 | + } |
|
| 1331 | + // change the message if the post type is not viewable on the frontend |
|
| 1332 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
| 1333 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
| 1334 | + $query_args = array_merge(['message' => $message], $query_args); |
|
| 1335 | + $this->_process_notices($query_args, true); |
|
| 1336 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + |
|
| 1340 | + /** |
|
| 1341 | + * This method is called to inject nav tabs on core WP cpt pages |
|
| 1342 | + * |
|
| 1343 | + * @return void |
|
| 1344 | + * @throws EE_Error |
|
| 1345 | + * @throws EE_Error |
|
| 1346 | + */ |
|
| 1347 | + public function inject_nav_tabs() |
|
| 1348 | + { |
|
| 1349 | + echo wp_kses($this->_get_main_nav_tabs(), AllowedTags::getWithFormTags()); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * This just sets up the post update messages when an update form is loaded |
|
| 1355 | + * |
|
| 1356 | + * @param array $messages the original messages array |
|
| 1357 | + * @return array the new messages array |
|
| 1358 | + */ |
|
| 1359 | + public function post_update_messages($messages) |
|
| 1360 | + { |
|
| 1361 | + global $post; |
|
| 1362 | + $id = $this->request->getRequestParam('post'); |
|
| 1363 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
| 1364 | + $revision = $this->request->getRequestParam('revision', 0, 'int'); |
|
| 1365 | + |
|
| 1366 | + $messages[ $post->post_type ] = [ |
|
| 1367 | + 0 => '', // Unused. Messages start at index 1. |
|
| 1368 | + 1 => sprintf( |
|
| 1369 | + esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1370 | + $this->_cpt_object->labels->singular_name, |
|
| 1371 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1372 | + '</a>' |
|
| 1373 | + ), |
|
| 1374 | + 2 => esc_html__('Custom field updated', 'event_espresso'), |
|
| 1375 | + 3 => esc_html__('Custom field deleted.', 'event_espresso'), |
|
| 1376 | + 4 => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1377 | + 5 => $revision |
|
| 1378 | + ? sprintf( |
|
| 1379 | + esc_html__('%s restored to revision from %s', 'event_espresso'), |
|
| 1380 | + $this->_cpt_object->labels->singular_name, |
|
| 1381 | + wp_post_revision_title($revision, false) |
|
| 1382 | + ) |
|
| 1383 | + : false, |
|
| 1384 | + 6 => sprintf( |
|
| 1385 | + esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1386 | + $this->_cpt_object->labels->singular_name, |
|
| 1387 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1388 | + '</a>' |
|
| 1389 | + ), |
|
| 1390 | + 7 => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1391 | + 8 => sprintf( |
|
| 1392 | + esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
| 1393 | + $this->_cpt_object->labels->singular_name, |
|
| 1394 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1395 | + '</a>' |
|
| 1396 | + ), |
|
| 1397 | + 9 => sprintf( |
|
| 1398 | + esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
| 1399 | + $this->_cpt_object->labels->singular_name, |
|
| 1400 | + '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
| 1401 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1402 | + '</a>' |
|
| 1403 | + ), |
|
| 1404 | + 10 => sprintf( |
|
| 1405 | + esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
| 1406 | + $this->_cpt_object->labels->singular_name, |
|
| 1407 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1408 | + '</a>' |
|
| 1409 | + ), |
|
| 1410 | + ]; |
|
| 1411 | + return $messages; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + |
|
| 1415 | + /** |
|
| 1416 | + * default method for the 'create_new' route for cpt admin pages. |
|
| 1417 | + * For reference what to include in here, see wp-admin/post-new.php |
|
| 1418 | + * |
|
| 1419 | + * @return void |
|
| 1420 | + */ |
|
| 1421 | + protected function _create_new_cpt_item() |
|
| 1422 | + { |
|
| 1423 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1424 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1425 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1426 | + $post_type_object = $this->_cpt_object; |
|
| 1427 | + $title = $post_type_object->labels->add_new_item; |
|
| 1428 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
| 1429 | + add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1430 | + // modify the default editor title field with default title. |
|
| 1431 | + add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10); |
|
| 1432 | + $this->loadEditorTemplate(true); |
|
| 1433 | + } |
|
| 1434 | + |
|
| 1435 | + |
|
| 1436 | + /** |
|
| 1437 | + * Enqueues auto-save and loads the editor template |
|
| 1438 | + * |
|
| 1439 | + * @param bool $creating |
|
| 1440 | + */ |
|
| 1441 | + private function loadEditorTemplate($creating = true) |
|
| 1442 | + { |
|
| 1443 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1444 | + // these vars are used by the template |
|
| 1445 | + $editing = true; |
|
| 1446 | + $post_ID = $post->ID; |
|
| 1447 | + if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
| 1448 | + // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
| 1449 | + // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
| 1450 | + if ($creating) { |
|
| 1451 | + wp_enqueue_script('autosave'); |
|
| 1452 | + } else { |
|
| 1453 | + if ( |
|
| 1454 | + isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
| 1455 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
| 1456 | + ) { |
|
| 1457 | + $create_new_action = apply_filters( |
|
| 1458 | + 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
| 1459 | + 'create_new', |
|
| 1460 | + $this |
|
| 1461 | + ); |
|
| 1462 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1463 | + [ |
|
| 1464 | + 'action' => $create_new_action, |
|
| 1465 | + 'page' => $this->page_slug, |
|
| 1466 | + ], |
|
| 1467 | + 'admin.php' |
|
| 1468 | + ); |
|
| 1469 | + } |
|
| 1470 | + } |
|
| 1471 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1472 | + } |
|
| 1473 | + } |
|
| 1474 | + |
|
| 1475 | + |
|
| 1476 | + public function add_new_admin_page_global() |
|
| 1477 | + { |
|
| 1478 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
| 1479 | + ?> |
|
| 1480 | 1480 | <script type="text/javascript"> |
| 1481 | 1481 | adminpage = '<?php echo esc_js($admin_page); ?>'; |
| 1482 | 1482 | </script> |
| 1483 | 1483 | <?php |
| 1484 | - } |
|
| 1485 | - |
|
| 1486 | - |
|
| 1487 | - /** |
|
| 1488 | - * default method for the 'edit' route for cpt admin pages |
|
| 1489 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
| 1490 | - * |
|
| 1491 | - * @return string template for edit cpt form |
|
| 1492 | - */ |
|
| 1493 | - protected function _edit_cpt_item() |
|
| 1494 | - { |
|
| 1495 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1496 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 1497 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
| 1498 | - if (empty($post)) { |
|
| 1499 | - wp_die(esc_html__( |
|
| 1500 | - 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', |
|
| 1501 | - 'event_espresso' |
|
| 1502 | - )); |
|
| 1503 | - } |
|
| 1504 | - |
|
| 1505 | - $post_lock = $this->request->getRequestParam('get-post-lock'); |
|
| 1506 | - if ($post_lock) { |
|
| 1507 | - wp_set_post_lock($post_id); |
|
| 1508 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
| 1509 | - exit(); |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1513 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1514 | - $post_type_object = $this->_cpt_object; |
|
| 1515 | - |
|
| 1516 | - if (! wp_check_post_lock($post->ID)) { |
|
| 1517 | - wp_set_post_lock($post->ID); |
|
| 1518 | - } |
|
| 1519 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
| 1520 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
| 1521 | - wp_enqueue_script('admin-comments'); |
|
| 1522 | - enqueue_comment_hotkeys_js(); |
|
| 1523 | - } |
|
| 1524 | - add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1525 | - // modify the default editor title field with default title. |
|
| 1526 | - add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10); |
|
| 1527 | - $this->loadEditorTemplate(false); |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - |
|
| 1531 | - |
|
| 1532 | - /** |
|
| 1533 | - * some getters |
|
| 1534 | - */ |
|
| 1535 | - /** |
|
| 1536 | - * This returns the protected _cpt_model_obj property |
|
| 1537 | - * |
|
| 1538 | - * @return EE_CPT_Base |
|
| 1539 | - */ |
|
| 1540 | - public function get_cpt_model_obj() |
|
| 1541 | - { |
|
| 1542 | - return $this->_cpt_model_obj; |
|
| 1543 | - } |
|
| 1484 | + } |
|
| 1485 | + |
|
| 1486 | + |
|
| 1487 | + /** |
|
| 1488 | + * default method for the 'edit' route for cpt admin pages |
|
| 1489 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
| 1490 | + * |
|
| 1491 | + * @return string template for edit cpt form |
|
| 1492 | + */ |
|
| 1493 | + protected function _edit_cpt_item() |
|
| 1494 | + { |
|
| 1495 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1496 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 1497 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
| 1498 | + if (empty($post)) { |
|
| 1499 | + wp_die(esc_html__( |
|
| 1500 | + 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', |
|
| 1501 | + 'event_espresso' |
|
| 1502 | + )); |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + $post_lock = $this->request->getRequestParam('get-post-lock'); |
|
| 1506 | + if ($post_lock) { |
|
| 1507 | + wp_set_post_lock($post_id); |
|
| 1508 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
| 1509 | + exit(); |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1513 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1514 | + $post_type_object = $this->_cpt_object; |
|
| 1515 | + |
|
| 1516 | + if (! wp_check_post_lock($post->ID)) { |
|
| 1517 | + wp_set_post_lock($post->ID); |
|
| 1518 | + } |
|
| 1519 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
| 1520 | + if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
| 1521 | + wp_enqueue_script('admin-comments'); |
|
| 1522 | + enqueue_comment_hotkeys_js(); |
|
| 1523 | + } |
|
| 1524 | + add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1525 | + // modify the default editor title field with default title. |
|
| 1526 | + add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10); |
|
| 1527 | + $this->loadEditorTemplate(false); |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + |
|
| 1531 | + |
|
| 1532 | + /** |
|
| 1533 | + * some getters |
|
| 1534 | + */ |
|
| 1535 | + /** |
|
| 1536 | + * This returns the protected _cpt_model_obj property |
|
| 1537 | + * |
|
| 1538 | + * @return EE_CPT_Base |
|
| 1539 | + */ |
|
| 1540 | + public function get_cpt_model_obj() |
|
| 1541 | + { |
|
| 1542 | + return $this->_cpt_model_obj; |
|
| 1543 | + } |
|
| 1544 | 1544 | } |
@@ -19,3979 +19,3979 @@ |
||
| 19 | 19 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var LoaderInterface |
|
| 24 | - */ |
|
| 25 | - protected $loader; |
|
| 22 | + /** |
|
| 23 | + * @var LoaderInterface |
|
| 24 | + */ |
|
| 25 | + protected $loader; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var RequestInterface |
|
| 29 | - */ |
|
| 30 | - protected $request; |
|
| 27 | + /** |
|
| 28 | + * @var RequestInterface |
|
| 29 | + */ |
|
| 30 | + protected $request; |
|
| 31 | 31 | |
| 32 | - // set in _init_page_props() |
|
| 33 | - public $page_slug; |
|
| 32 | + // set in _init_page_props() |
|
| 33 | + public $page_slug; |
|
| 34 | 34 | |
| 35 | - public $page_label; |
|
| 35 | + public $page_label; |
|
| 36 | 36 | |
| 37 | - public $page_folder; |
|
| 37 | + public $page_folder; |
|
| 38 | 38 | |
| 39 | - // set in define_page_props() |
|
| 40 | - protected $_admin_base_url; |
|
| 39 | + // set in define_page_props() |
|
| 40 | + protected $_admin_base_url; |
|
| 41 | 41 | |
| 42 | - protected $_admin_base_path; |
|
| 42 | + protected $_admin_base_path; |
|
| 43 | 43 | |
| 44 | - protected $_admin_page_title; |
|
| 44 | + protected $_admin_page_title; |
|
| 45 | 45 | |
| 46 | - protected $_labels; |
|
| 46 | + protected $_labels; |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - // set early within EE_Admin_Init |
|
| 50 | - protected $_wp_page_slug; |
|
| 49 | + // set early within EE_Admin_Init |
|
| 50 | + protected $_wp_page_slug; |
|
| 51 | 51 | |
| 52 | - // navtabs |
|
| 53 | - protected $_nav_tabs; |
|
| 52 | + // navtabs |
|
| 53 | + protected $_nav_tabs; |
|
| 54 | 54 | |
| 55 | - protected $_default_nav_tab_name; |
|
| 55 | + protected $_default_nav_tab_name; |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - // template variables (used by templates) |
|
| 59 | - protected $_template_path; |
|
| 58 | + // template variables (used by templates) |
|
| 59 | + protected $_template_path; |
|
| 60 | 60 | |
| 61 | - protected $_column_template_path; |
|
| 61 | + protected $_column_template_path; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var array $_template_args |
|
| 65 | - */ |
|
| 66 | - protected $_template_args = []; |
|
| 63 | + /** |
|
| 64 | + * @var array $_template_args |
|
| 65 | + */ |
|
| 66 | + protected $_template_args = []; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * this will hold the list table object for a given view. |
|
| 70 | - * |
|
| 71 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 72 | - */ |
|
| 73 | - protected $_list_table_object; |
|
| 68 | + /** |
|
| 69 | + * this will hold the list table object for a given view. |
|
| 70 | + * |
|
| 71 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 72 | + */ |
|
| 73 | + protected $_list_table_object; |
|
| 74 | 74 | |
| 75 | - // bools |
|
| 76 | - protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 75 | + // bools |
|
| 76 | + protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 77 | 77 | |
| 78 | - protected $_routing; |
|
| 78 | + protected $_routing; |
|
| 79 | 79 | |
| 80 | - // list table args |
|
| 81 | - protected $_view; |
|
| 80 | + // list table args |
|
| 81 | + protected $_view; |
|
| 82 | 82 | |
| 83 | - protected $_views; |
|
| 83 | + protected $_views; |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - // action => method pairs used for routing incoming requests |
|
| 87 | - protected $_page_routes; |
|
| 86 | + // action => method pairs used for routing incoming requests |
|
| 87 | + protected $_page_routes; |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @var array $_page_config |
|
| 91 | - */ |
|
| 92 | - protected $_page_config; |
|
| 89 | + /** |
|
| 90 | + * @var array $_page_config |
|
| 91 | + */ |
|
| 92 | + protected $_page_config; |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * the current page route and route config |
|
| 96 | - * |
|
| 97 | - * @var string $_route |
|
| 98 | - */ |
|
| 99 | - protected $_route; |
|
| 94 | + /** |
|
| 95 | + * the current page route and route config |
|
| 96 | + * |
|
| 97 | + * @var string $_route |
|
| 98 | + */ |
|
| 99 | + protected $_route; |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @var string $_cpt_route |
|
| 103 | - */ |
|
| 104 | - protected $_cpt_route; |
|
| 101 | + /** |
|
| 102 | + * @var string $_cpt_route |
|
| 103 | + */ |
|
| 104 | + protected $_cpt_route; |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @var array $_route_config |
|
| 108 | - */ |
|
| 109 | - protected $_route_config; |
|
| 106 | + /** |
|
| 107 | + * @var array $_route_config |
|
| 108 | + */ |
|
| 109 | + protected $_route_config; |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 113 | - * actions. |
|
| 114 | - * |
|
| 115 | - * @since 4.6.x |
|
| 116 | - * @var array. |
|
| 117 | - */ |
|
| 118 | - protected $_default_route_query_args; |
|
| 119 | - |
|
| 120 | - // set via request page and action args. |
|
| 121 | - protected $_current_page; |
|
| 122 | - |
|
| 123 | - protected $_current_view; |
|
| 124 | - |
|
| 125 | - protected $_current_page_view_url; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * unprocessed value for the 'action' request param (default '') |
|
| 129 | - * |
|
| 130 | - * @var string |
|
| 131 | - */ |
|
| 132 | - protected $raw_req_action = ''; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * unprocessed value for the 'page' request param (default '') |
|
| 136 | - * |
|
| 137 | - * @var string |
|
| 138 | - */ |
|
| 139 | - protected $raw_req_page = ''; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * sanitized request action (and nonce) |
|
| 143 | - * |
|
| 144 | - * @var string |
|
| 145 | - */ |
|
| 146 | - protected $_req_action = ''; |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * sanitized request action nonce |
|
| 150 | - * |
|
| 151 | - * @var string |
|
| 152 | - */ |
|
| 153 | - protected $_req_nonce = ''; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @var string |
|
| 157 | - */ |
|
| 158 | - protected $_search_btn_label = ''; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @var string |
|
| 162 | - */ |
|
| 163 | - protected $_search_box_callback = ''; |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @var WP_Screen |
|
| 167 | - */ |
|
| 168 | - protected $_current_screen; |
|
| 169 | - |
|
| 170 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 171 | - protected $_hook_obj; |
|
| 172 | - |
|
| 173 | - // for holding incoming request data |
|
| 174 | - protected $_req_data = []; |
|
| 175 | - |
|
| 176 | - // yes / no array for admin form fields |
|
| 177 | - protected $_yes_no_values = []; |
|
| 178 | - |
|
| 179 | - // some default things shared by all child classes |
|
| 180 | - protected $_default_espresso_metaboxes; |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @var EE_Registry |
|
| 184 | - */ |
|
| 185 | - protected $EE = null; |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 190 | - * |
|
| 191 | - * @var boolean |
|
| 192 | - */ |
|
| 193 | - protected $_is_caf = false; |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @Constructor |
|
| 198 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 199 | - * @throws EE_Error |
|
| 200 | - * @throws InvalidArgumentException |
|
| 201 | - * @throws ReflectionException |
|
| 202 | - * @throws InvalidDataTypeException |
|
| 203 | - * @throws InvalidInterfaceException |
|
| 204 | - */ |
|
| 205 | - public function __construct($routing = true) |
|
| 206 | - { |
|
| 207 | - $this->loader = LoaderFactory::getLoader(); |
|
| 208 | - $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 209 | - $this->_routing = $routing; |
|
| 210 | - |
|
| 211 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 212 | - $this->_is_caf = true; |
|
| 213 | - } |
|
| 214 | - $this->_yes_no_values = [ |
|
| 215 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 216 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 217 | - ]; |
|
| 218 | - // set the _req_data property. |
|
| 219 | - $this->_req_data = $this->request->requestParams(); |
|
| 220 | - // set initial page props (child method) |
|
| 221 | - $this->_init_page_props(); |
|
| 222 | - // set global defaults |
|
| 223 | - $this->_set_defaults(); |
|
| 224 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 225 | - $this->_global_ajax_hooks(); |
|
| 226 | - $this->_ajax_hooks(); |
|
| 227 | - // other_page_hooks have to be early too. |
|
| 228 | - $this->_do_other_page_hooks(); |
|
| 229 | - // set up page dependencies |
|
| 230 | - $this->_before_page_setup(); |
|
| 231 | - $this->_page_setup(); |
|
| 232 | - // die(); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * _init_page_props |
|
| 238 | - * Child classes use to set at least the following properties: |
|
| 239 | - * $page_slug. |
|
| 240 | - * $page_label. |
|
| 241 | - * |
|
| 242 | - * @abstract |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - abstract protected function _init_page_props(); |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * _ajax_hooks |
|
| 250 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 251 | - * Note: within the ajax callback methods. |
|
| 252 | - * |
|
| 253 | - * @abstract |
|
| 254 | - * @return void |
|
| 255 | - */ |
|
| 256 | - abstract protected function _ajax_hooks(); |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * _define_page_props |
|
| 261 | - * child classes define page properties in here. Must include at least: |
|
| 262 | - * $_admin_base_url = base_url for all admin pages |
|
| 263 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 264 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 265 | - * array( |
|
| 266 | - * 'buttons' => array( |
|
| 267 | - * 'add' => esc_html__('label for add new button'), |
|
| 268 | - * 'edit' => esc_html__('label for edit button'), |
|
| 269 | - * 'delete' => esc_html__('label for delete button') |
|
| 270 | - * ) |
|
| 271 | - * ) |
|
| 272 | - * |
|
| 273 | - * @abstract |
|
| 274 | - * @return void |
|
| 275 | - */ |
|
| 276 | - abstract protected function _define_page_props(); |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * _set_page_routes |
|
| 281 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 282 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 283 | - * have a 'default' route. Here's the format |
|
| 284 | - * $this->_page_routes = array( |
|
| 285 | - * 'default' => array( |
|
| 286 | - * 'func' => '_default_method_handling_route', |
|
| 287 | - * 'args' => array('array','of','args'), |
|
| 288 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 289 | - * ajax request, backend processing) |
|
| 290 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 291 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 292 | - * headers sent route. |
|
| 293 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 294 | - * this route. |
|
| 295 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 296 | - * checks). |
|
| 297 | - * ), |
|
| 298 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 299 | - * handling method. |
|
| 300 | - * ) |
|
| 301 | - * ) |
|
| 302 | - * |
|
| 303 | - * @abstract |
|
| 304 | - * @return void |
|
| 305 | - */ |
|
| 306 | - abstract protected function _set_page_routes(); |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * _set_page_config |
|
| 311 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 312 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 313 | - * $this->_page_config = array( |
|
| 314 | - * 'default' => array( |
|
| 315 | - * 'labels' => array( |
|
| 316 | - * 'buttons' => array( |
|
| 317 | - * 'add' => esc_html__('label for adding item'), |
|
| 318 | - * 'edit' => esc_html__('label for editing item'), |
|
| 319 | - * 'delete' => esc_html__('label for deleting item') |
|
| 320 | - * ), |
|
| 321 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 322 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 323 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 324 | - * _define_page_props() method |
|
| 325 | - * 'nav' => array( |
|
| 326 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 327 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 328 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 329 | - * 'order' => 10, //required to indicate tab position. |
|
| 330 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 331 | - * displayed then add this parameter. |
|
| 332 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 333 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 334 | - * metaboxes set for eventespresso admin pages. |
|
| 335 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 336 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 337 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 338 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 339 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 340 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 341 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 342 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 343 | - * want to display. |
|
| 344 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 345 | - * 'tab_id' => array( |
|
| 346 | - * 'title' => 'tab_title', |
|
| 347 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 348 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 349 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 350 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 351 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 352 | - * attempt to use the callback which should match the name of a method in the class |
|
| 353 | - * ), |
|
| 354 | - * 'tab2_id' => array( |
|
| 355 | - * 'title' => 'tab2 title', |
|
| 356 | - * 'filename' => 'file_name_2' |
|
| 357 | - * 'callback' => 'callback_method_for_content', |
|
| 358 | - * ), |
|
| 359 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 360 | - * help tab area on an admin page. @return void |
|
| 361 | - * |
|
| 362 | - * @abstract |
|
| 363 | - */ |
|
| 364 | - abstract protected function _set_page_config(); |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * _add_screen_options |
|
| 369 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 370 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 371 | - * to a particular view. |
|
| 372 | - * |
|
| 373 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 374 | - * see also WP_Screen object documents... |
|
| 375 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 376 | - * @abstract |
|
| 377 | - * @return void |
|
| 378 | - */ |
|
| 379 | - abstract protected function _add_screen_options(); |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * _add_feature_pointers |
|
| 384 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 385 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 386 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 387 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 388 | - * extended) also see: |
|
| 389 | - * |
|
| 390 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 391 | - * @abstract |
|
| 392 | - * @return void |
|
| 393 | - */ |
|
| 394 | - abstract protected function _add_feature_pointers(); |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * load_scripts_styles |
|
| 399 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 400 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 401 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 402 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 403 | - * |
|
| 404 | - * @abstract |
|
| 405 | - * @return void |
|
| 406 | - */ |
|
| 407 | - abstract public function load_scripts_styles(); |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * admin_init |
|
| 412 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 413 | - * all pages/views loaded by child class. |
|
| 414 | - * |
|
| 415 | - * @abstract |
|
| 416 | - * @return void |
|
| 417 | - */ |
|
| 418 | - abstract public function admin_init(); |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * admin_notices |
|
| 423 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 424 | - * all pages/views loaded by child class. |
|
| 425 | - * |
|
| 426 | - * @abstract |
|
| 427 | - * @return void |
|
| 428 | - */ |
|
| 429 | - abstract public function admin_notices(); |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * admin_footer_scripts |
|
| 434 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 435 | - * will apply to all pages/views loaded by child class. |
|
| 436 | - * |
|
| 437 | - * @return void |
|
| 438 | - */ |
|
| 439 | - abstract public function admin_footer_scripts(); |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * admin_footer |
|
| 444 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 445 | - * apply to all pages/views loaded by child class. |
|
| 446 | - * |
|
| 447 | - * @return void |
|
| 448 | - */ |
|
| 449 | - public function admin_footer() |
|
| 450 | - { |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * _global_ajax_hooks |
|
| 456 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 457 | - * Note: within the ajax callback methods. |
|
| 458 | - * |
|
| 459 | - * @abstract |
|
| 460 | - * @return void |
|
| 461 | - */ |
|
| 462 | - protected function _global_ajax_hooks() |
|
| 463 | - { |
|
| 464 | - // for lazy loading of metabox content |
|
| 465 | - add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - public function ajax_metabox_content() |
|
| 470 | - { |
|
| 471 | - $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 472 | - $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 473 | - self::cached_rss_display($content_id, $content_url); |
|
| 474 | - wp_die(); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 480 | - * |
|
| 481 | - * @return void |
|
| 482 | - */ |
|
| 483 | - protected function _before_page_setup() |
|
| 484 | - { |
|
| 485 | - // default is to do nothing |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Makes sure any things that need to be loaded early get handled. |
|
| 491 | - * We also escape early here if the page requested doesn't match the object. |
|
| 492 | - * |
|
| 493 | - * @final |
|
| 494 | - * @return void |
|
| 495 | - * @throws EE_Error |
|
| 496 | - * @throws InvalidArgumentException |
|
| 497 | - * @throws ReflectionException |
|
| 498 | - * @throws InvalidDataTypeException |
|
| 499 | - * @throws InvalidInterfaceException |
|
| 500 | - */ |
|
| 501 | - final protected function _page_setup() |
|
| 502 | - { |
|
| 503 | - // requires? |
|
| 504 | - // admin_init stuff - global - we're setting this REALLY early |
|
| 505 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 506 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 507 | - add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 508 | - // next verify if we need to load anything... |
|
| 509 | - $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 510 | - $this->page_folder = strtolower( |
|
| 511 | - str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 512 | - ); |
|
| 513 | - global $ee_menu_slugs; |
|
| 514 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 515 | - if ( |
|
| 516 | - ! $this->request->isAjax() |
|
| 517 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 518 | - ) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 522 | - // we need to copy the action from the second to the first |
|
| 523 | - $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 524 | - $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 525 | - $action = $action !== '-1' ? $action : $action2; |
|
| 526 | - $req_action = $action !== '-1' ? $action : 'default'; |
|
| 527 | - |
|
| 528 | - // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 529 | - // then let's use the route as the action. |
|
| 530 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 531 | - $route = $this->request->getRequestParam('route'); |
|
| 532 | - $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 533 | - ? $route |
|
| 534 | - : $req_action; |
|
| 535 | - |
|
| 536 | - $this->_current_view = $this->_req_action; |
|
| 537 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 538 | - $this->_define_page_props(); |
|
| 539 | - $this->_current_page_view_url = add_query_arg( |
|
| 540 | - ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 541 | - $this->_admin_base_url |
|
| 542 | - ); |
|
| 543 | - // default things |
|
| 544 | - $this->_default_espresso_metaboxes = [ |
|
| 545 | - '_espresso_news_post_box', |
|
| 546 | - '_espresso_links_post_box', |
|
| 547 | - '_espresso_ratings_request', |
|
| 548 | - '_espresso_sponsors_post_box', |
|
| 549 | - ]; |
|
| 550 | - // set page configs |
|
| 551 | - $this->_set_page_routes(); |
|
| 552 | - $this->_set_page_config(); |
|
| 553 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 554 | - if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 555 | - $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 556 | - if ($wp_referer) { |
|
| 557 | - $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - // for caffeinated and other extended functionality. |
|
| 561 | - // If there is a _extend_page_config method |
|
| 562 | - // then let's run that to modify the all the various page configuration arrays |
|
| 563 | - if (method_exists($this, '_extend_page_config')) { |
|
| 564 | - $this->_extend_page_config(); |
|
| 565 | - } |
|
| 566 | - // for CPT and other extended functionality. |
|
| 567 | - // If there is an _extend_page_config_for_cpt |
|
| 568 | - // then let's run that to modify all the various page configuration arrays. |
|
| 569 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | - $this->_extend_page_config_for_cpt(); |
|
| 571 | - } |
|
| 572 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | - $this->_page_routes = apply_filters( |
|
| 574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | - $this->_page_routes, |
|
| 576 | - $this |
|
| 577 | - ); |
|
| 578 | - $this->_page_config = apply_filters( |
|
| 579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | - $this->_page_config, |
|
| 581 | - $this |
|
| 582 | - ); |
|
| 583 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 586 | - add_action( |
|
| 587 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 588 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 589 | - 10, |
|
| 590 | - 2 |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - // next route only if routing enabled |
|
| 594 | - if ($this->_routing && ! $this->request->isAjax()) { |
|
| 595 | - $this->_verify_routes(); |
|
| 596 | - // next let's just check user_access and kill if no access |
|
| 597 | - $this->check_user_access(); |
|
| 598 | - if ($this->_is_UI_request) { |
|
| 599 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 600 | - add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 601 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 602 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 603 | - } |
|
| 604 | - } else { |
|
| 605 | - // hijack regular WP loading and route admin request immediately |
|
| 606 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 607 | - $this->route_admin_request(); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 615 | - * |
|
| 616 | - * @return void |
|
| 617 | - * @throws EE_Error |
|
| 618 | - */ |
|
| 619 | - private function _do_other_page_hooks() |
|
| 620 | - { |
|
| 621 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 622 | - foreach ($registered_pages as $page) { |
|
| 623 | - // now let's setup the file name and class that should be present |
|
| 624 | - $classname = str_replace('.class.php', '', $page); |
|
| 625 | - // autoloaders should take care of loading file |
|
| 626 | - if (! class_exists($classname)) { |
|
| 627 | - $error_msg[] = sprintf( |
|
| 628 | - esc_html__( |
|
| 629 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 630 | - 'event_espresso' |
|
| 631 | - ), |
|
| 632 | - $page |
|
| 633 | - ); |
|
| 634 | - $error_msg[] = $error_msg[0] |
|
| 635 | - . "\r\n" |
|
| 636 | - . sprintf( |
|
| 637 | - esc_html__( |
|
| 638 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 639 | - 'event_espresso' |
|
| 640 | - ), |
|
| 641 | - $page, |
|
| 642 | - '<br />', |
|
| 643 | - '<strong>' . $classname . '</strong>' |
|
| 644 | - ); |
|
| 645 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 646 | - } |
|
| 647 | - // notice we are passing the instance of this class to the hook object. |
|
| 648 | - $this->loader->getShared($classname, [$this]); |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * @throws ReflectionException |
|
| 655 | - * @throws EE_Error |
|
| 656 | - */ |
|
| 657 | - public function load_page_dependencies() |
|
| 658 | - { |
|
| 659 | - try { |
|
| 660 | - $this->_load_page_dependencies(); |
|
| 661 | - } catch (EE_Error $e) { |
|
| 662 | - $e->get_error(); |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * load_page_dependencies |
|
| 669 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 670 | - * |
|
| 671 | - * @return void |
|
| 672 | - * @throws DomainException |
|
| 673 | - * @throws EE_Error |
|
| 674 | - * @throws InvalidArgumentException |
|
| 675 | - * @throws InvalidDataTypeException |
|
| 676 | - * @throws InvalidInterfaceException |
|
| 677 | - */ |
|
| 678 | - protected function _load_page_dependencies() |
|
| 679 | - { |
|
| 680 | - // let's set the current_screen and screen options to override what WP set |
|
| 681 | - $this->_current_screen = get_current_screen(); |
|
| 682 | - // load admin_notices - global, page class, and view specific |
|
| 683 | - add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 684 | - add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 685 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 686 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 687 | - } |
|
| 688 | - // load network admin_notices - global, page class, and view specific |
|
| 689 | - add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 690 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 691 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 692 | - } |
|
| 693 | - // this will save any per_page screen options if they are present |
|
| 694 | - $this->_set_per_page_screen_options(); |
|
| 695 | - // setup list table properties |
|
| 696 | - $this->_set_list_table(); |
|
| 697 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 698 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 699 | - $this->_add_registered_meta_boxes(); |
|
| 700 | - $this->_add_screen_columns(); |
|
| 701 | - // add screen options - global, page child class, and view specific |
|
| 702 | - $this->_add_global_screen_options(); |
|
| 703 | - $this->_add_screen_options(); |
|
| 704 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 705 | - if (method_exists($this, $add_screen_options)) { |
|
| 706 | - $this->{$add_screen_options}(); |
|
| 707 | - } |
|
| 708 | - // add help tab(s) - set via page_config and qtips. |
|
| 709 | - $this->_add_help_tabs(); |
|
| 710 | - $this->_add_qtips(); |
|
| 711 | - // add feature_pointers - global, page child class, and view specific |
|
| 712 | - $this->_add_feature_pointers(); |
|
| 713 | - $this->_add_global_feature_pointers(); |
|
| 714 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 715 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 716 | - $this->{$add_feature_pointer}(); |
|
| 717 | - } |
|
| 718 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 719 | - add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 720 | - add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 721 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 722 | - add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 723 | - } |
|
| 724 | - add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 725 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 726 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 727 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 728 | - // is a good use case. Notice the late priority we're giving these |
|
| 729 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 730 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 731 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 732 | - add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 733 | - } |
|
| 734 | - // admin footer scripts |
|
| 735 | - add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 736 | - add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 737 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 738 | - add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 739 | - } |
|
| 740 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 741 | - // targeted hook |
|
| 742 | - do_action( |
|
| 743 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 744 | - ); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * _set_defaults |
|
| 750 | - * This sets some global defaults for class properties. |
|
| 751 | - */ |
|
| 752 | - private function _set_defaults() |
|
| 753 | - { |
|
| 754 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 755 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 756 | - $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 757 | - $this->_page_config = $this->_default_route_query_args = []; |
|
| 758 | - $this->_default_nav_tab_name = 'overview'; |
|
| 759 | - // init template args |
|
| 760 | - $this->_template_args = [ |
|
| 761 | - 'admin_page_header' => '', |
|
| 762 | - 'admin_page_content' => '', |
|
| 763 | - 'post_body_content' => '', |
|
| 764 | - 'before_list_table' => '', |
|
| 765 | - 'after_list_table' => '', |
|
| 766 | - ]; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * route_admin_request |
|
| 772 | - * |
|
| 773 | - * @return void |
|
| 774 | - * @throws InvalidArgumentException |
|
| 775 | - * @throws InvalidInterfaceException |
|
| 776 | - * @throws InvalidDataTypeException |
|
| 777 | - * @throws EE_Error |
|
| 778 | - * @throws ReflectionException |
|
| 779 | - * @see _route_admin_request() |
|
| 780 | - */ |
|
| 781 | - public function route_admin_request() |
|
| 782 | - { |
|
| 783 | - try { |
|
| 784 | - $this->_route_admin_request(); |
|
| 785 | - } catch (EE_Error $e) { |
|
| 786 | - $e->get_error(); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - public function set_wp_page_slug($wp_page_slug) |
|
| 792 | - { |
|
| 793 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 794 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 795 | - if (is_network_admin()) { |
|
| 796 | - $this->_wp_page_slug .= '-network'; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * _verify_routes |
|
| 803 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 804 | - * we know if we need to drop out. |
|
| 805 | - * |
|
| 806 | - * @return bool |
|
| 807 | - * @throws EE_Error |
|
| 808 | - */ |
|
| 809 | - protected function _verify_routes() |
|
| 810 | - { |
|
| 811 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 812 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 813 | - return false; |
|
| 814 | - } |
|
| 815 | - $this->_route = false; |
|
| 816 | - // check that the page_routes array is not empty |
|
| 817 | - if (empty($this->_page_routes)) { |
|
| 818 | - // user error msg |
|
| 819 | - $error_msg = sprintf( |
|
| 820 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 821 | - $this->_admin_page_title |
|
| 822 | - ); |
|
| 823 | - // developer error msg |
|
| 824 | - $error_msg .= '||' . $error_msg |
|
| 825 | - . esc_html__( |
|
| 826 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 827 | - 'event_espresso' |
|
| 828 | - ); |
|
| 829 | - throw new EE_Error($error_msg); |
|
| 830 | - } |
|
| 831 | - // and that the requested page route exists |
|
| 832 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 833 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 834 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 835 | - ? $this->_page_config[ $this->_req_action ] |
|
| 836 | - : []; |
|
| 837 | - } else { |
|
| 838 | - // user error msg |
|
| 839 | - $error_msg = sprintf( |
|
| 840 | - esc_html__( |
|
| 841 | - 'The requested page route does not exist for the %s admin page.', |
|
| 842 | - 'event_espresso' |
|
| 843 | - ), |
|
| 844 | - $this->_admin_page_title |
|
| 845 | - ); |
|
| 846 | - // developer error msg |
|
| 847 | - $error_msg .= '||' . $error_msg |
|
| 848 | - . sprintf( |
|
| 849 | - esc_html__( |
|
| 850 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ), |
|
| 853 | - $this->_req_action |
|
| 854 | - ); |
|
| 855 | - throw new EE_Error($error_msg); |
|
| 856 | - } |
|
| 857 | - // and that a default route exists |
|
| 858 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 859 | - // user error msg |
|
| 860 | - $error_msg = sprintf( |
|
| 861 | - esc_html__( |
|
| 862 | - 'A default page route has not been set for the % admin page.', |
|
| 863 | - 'event_espresso' |
|
| 864 | - ), |
|
| 865 | - $this->_admin_page_title |
|
| 866 | - ); |
|
| 867 | - // developer error msg |
|
| 868 | - $error_msg .= '||' . $error_msg |
|
| 869 | - . esc_html__( |
|
| 870 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 871 | - 'event_espresso' |
|
| 872 | - ); |
|
| 873 | - throw new EE_Error($error_msg); |
|
| 874 | - } |
|
| 875 | - // first lets' catch if the UI request has EVER been set. |
|
| 876 | - if ($this->_is_UI_request === null) { |
|
| 877 | - // lets set if this is a UI request or not. |
|
| 878 | - $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 879 | - // wait a minute... we might have a noheader in the route array |
|
| 880 | - $this->_is_UI_request = ! ( |
|
| 881 | - is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 882 | - ) |
|
| 883 | - ? $this->_is_UI_request |
|
| 884 | - : false; |
|
| 885 | - } |
|
| 886 | - $this->_set_current_labels(); |
|
| 887 | - return true; |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 893 | - * |
|
| 894 | - * @param string $route the route name we're verifying |
|
| 895 | - * @return bool we'll throw an exception if this isn't a valid route. |
|
| 896 | - * @throws EE_Error |
|
| 897 | - */ |
|
| 898 | - protected function _verify_route($route) |
|
| 899 | - { |
|
| 900 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 901 | - return true; |
|
| 902 | - } |
|
| 903 | - // user error msg |
|
| 904 | - $error_msg = sprintf( |
|
| 905 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 906 | - $this->_admin_page_title |
|
| 907 | - ); |
|
| 908 | - // developer error msg |
|
| 909 | - $error_msg .= '||' . $error_msg |
|
| 910 | - . sprintf( |
|
| 911 | - esc_html__( |
|
| 912 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 913 | - 'event_espresso' |
|
| 914 | - ), |
|
| 915 | - $route |
|
| 916 | - ); |
|
| 917 | - throw new EE_Error($error_msg); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * perform nonce verification |
|
| 923 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 924 | - * using this method (and save retyping!) |
|
| 925 | - * |
|
| 926 | - * @param string $nonce The nonce sent |
|
| 927 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 928 | - * @return void |
|
| 929 | - * @throws EE_Error |
|
| 930 | - */ |
|
| 931 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 932 | - { |
|
| 933 | - // verify nonce against expected value |
|
| 934 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 935 | - // these are not the droids you are looking for !!! |
|
| 936 | - $msg = sprintf( |
|
| 937 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 938 | - '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 939 | - '</a>' |
|
| 940 | - ); |
|
| 941 | - if (WP_DEBUG) { |
|
| 942 | - $msg .= "\n "; |
|
| 943 | - $msg .= sprintf( |
|
| 944 | - esc_html__( |
|
| 945 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 946 | - 'event_espresso' |
|
| 947 | - ), |
|
| 948 | - __CLASS__ |
|
| 949 | - ); |
|
| 950 | - } |
|
| 951 | - if (! $this->request->isAjax()) { |
|
| 952 | - wp_die($msg); |
|
| 953 | - } |
|
| 954 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 955 | - $this->_return_json(); |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - |
|
| 960 | - /** |
|
| 961 | - * _route_admin_request() |
|
| 962 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 963 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 964 | - * in the page routes and then will try to load the corresponding method. |
|
| 965 | - * |
|
| 966 | - * @return void |
|
| 967 | - * @throws EE_Error |
|
| 968 | - * @throws InvalidArgumentException |
|
| 969 | - * @throws InvalidDataTypeException |
|
| 970 | - * @throws InvalidInterfaceException |
|
| 971 | - * @throws ReflectionException |
|
| 972 | - */ |
|
| 973 | - protected function _route_admin_request() |
|
| 974 | - { |
|
| 975 | - if (! $this->_is_UI_request) { |
|
| 976 | - $this->_verify_routes(); |
|
| 977 | - } |
|
| 978 | - $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 979 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 980 | - // set nonce from post data |
|
| 981 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 982 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 983 | - } |
|
| 984 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 985 | - if ($this->_is_UI_request) { |
|
| 986 | - $this->_set_nav_tabs(); |
|
| 987 | - } |
|
| 988 | - // grab callback function |
|
| 989 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 990 | - // check if callback has args |
|
| 991 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 992 | - $error_msg = ''; |
|
| 993 | - // action right before calling route |
|
| 994 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 995 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 996 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 997 | - } |
|
| 998 | - // right before calling the route, let's clean the _wp_http_referer |
|
| 999 | - $this->request->setServerParam( |
|
| 1000 | - 'REQUEST_URI', |
|
| 1001 | - remove_query_arg( |
|
| 1002 | - '_wp_http_referer', |
|
| 1003 | - wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1004 | - ) |
|
| 1005 | - ); |
|
| 1006 | - if (! empty($func)) { |
|
| 1007 | - if (is_array($func)) { |
|
| 1008 | - list($class, $method) = $func; |
|
| 1009 | - } elseif (strpos($func, '::') !== false) { |
|
| 1010 | - list($class, $method) = explode('::', $func); |
|
| 1011 | - } else { |
|
| 1012 | - $class = $this; |
|
| 1013 | - $method = $func; |
|
| 1014 | - } |
|
| 1015 | - if (! (is_object($class) && $class === $this)) { |
|
| 1016 | - // send along this admin page object for access by addons. |
|
| 1017 | - $args['admin_page_object'] = $this; |
|
| 1018 | - } |
|
| 1019 | - if ( |
|
| 1020 | - // is it a method on a class that doesn't work? |
|
| 1021 | - ( |
|
| 1022 | - ( |
|
| 1023 | - method_exists($class, $method) |
|
| 1024 | - && call_user_func_array([$class, $method], $args) === false |
|
| 1025 | - ) |
|
| 1026 | - && ( |
|
| 1027 | - // is it a standalone function that doesn't work? |
|
| 1028 | - function_exists($method) |
|
| 1029 | - && call_user_func_array( |
|
| 1030 | - $func, |
|
| 1031 | - array_merge(['admin_page_object' => $this], $args) |
|
| 1032 | - ) === false |
|
| 1033 | - ) |
|
| 1034 | - ) |
|
| 1035 | - || ( |
|
| 1036 | - // is it neither a class method NOR a standalone function? |
|
| 1037 | - ! method_exists($class, $method) |
|
| 1038 | - && ! function_exists($method) |
|
| 1039 | - ) |
|
| 1040 | - ) { |
|
| 1041 | - // user error msg |
|
| 1042 | - $error_msg = esc_html__( |
|
| 1043 | - 'An error occurred. The requested page route could not be found.', |
|
| 1044 | - 'event_espresso' |
|
| 1045 | - ); |
|
| 1046 | - // developer error msg |
|
| 1047 | - $error_msg .= '||'; |
|
| 1048 | - $error_msg .= sprintf( |
|
| 1049 | - esc_html__( |
|
| 1050 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1051 | - 'event_espresso' |
|
| 1052 | - ), |
|
| 1053 | - $method |
|
| 1054 | - ); |
|
| 1055 | - } |
|
| 1056 | - if (! empty($error_msg)) { |
|
| 1057 | - throw new EE_Error($error_msg); |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1061 | - // then we need to reset the routing properties to the new route. |
|
| 1062 | - // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1063 | - if ( |
|
| 1064 | - $this->_is_UI_request === false |
|
| 1065 | - && is_array($this->_route) |
|
| 1066 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1067 | - ) { |
|
| 1068 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - |
|
| 1073 | - /** |
|
| 1074 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1075 | - * route redirects to a headers route in its route config. |
|
| 1076 | - * |
|
| 1077 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1078 | - * @return void |
|
| 1079 | - * @throws ReflectionException |
|
| 1080 | - * @throws InvalidArgumentException |
|
| 1081 | - * @throws InvalidInterfaceException |
|
| 1082 | - * @throws InvalidDataTypeException |
|
| 1083 | - * @throws EE_Error |
|
| 1084 | - * @since 4.3.0 |
|
| 1085 | - */ |
|
| 1086 | - protected function _reset_routing_properties($new_route) |
|
| 1087 | - { |
|
| 1088 | - $this->_is_UI_request = true; |
|
| 1089 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1090 | - $this->request->setRequestParam('action', $new_route); |
|
| 1091 | - // rerun page setup |
|
| 1092 | - $this->_page_setup(); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * _add_query_arg |
|
| 1098 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1099 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1100 | - * |
|
| 1101 | - * @param array $args |
|
| 1102 | - * @param string $url |
|
| 1103 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1104 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1105 | - * Example usage: If the current page is: |
|
| 1106 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1107 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1108 | - * &_wpnonce=5467821 |
|
| 1109 | - * and you call: |
|
| 1110 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1111 | - * array( |
|
| 1112 | - * 'action' => 'resend_something', |
|
| 1113 | - * 'page=>espresso_registrations' |
|
| 1114 | - * ), |
|
| 1115 | - * $some_url, |
|
| 1116 | - * true |
|
| 1117 | - * ); |
|
| 1118 | - * It will produce a url in this structure: |
|
| 1119 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1120 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1121 | - * month_range]=March%202015 |
|
| 1122 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1123 | - * @return string |
|
| 1124 | - */ |
|
| 1125 | - public static function add_query_args_and_nonce( |
|
| 1126 | - $args = [], |
|
| 1127 | - $url = false, |
|
| 1128 | - $sticky = false, |
|
| 1129 | - $exclude_nonce = false |
|
| 1130 | - ) { |
|
| 1131 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1132 | - if ($sticky) { |
|
| 1133 | - /** @var RequestInterface $request */ |
|
| 1134 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1135 | - $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1136 | - foreach ($request->requestParams() as $key => $value) { |
|
| 1137 | - // do not add nonces |
|
| 1138 | - if (strpos($key, 'nonce') !== false) { |
|
| 1139 | - continue; |
|
| 1140 | - } |
|
| 1141 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * This returns a generated link that will load the related help tab. |
|
| 1150 | - * |
|
| 1151 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1152 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1153 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1154 | - * @return string generated link |
|
| 1155 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1156 | - */ |
|
| 1157 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1158 | - { |
|
| 1159 | - return EEH_Template::get_help_tab_link( |
|
| 1160 | - $help_tab_id, |
|
| 1161 | - $this->page_slug, |
|
| 1162 | - $this->_req_action, |
|
| 1163 | - $icon_style, |
|
| 1164 | - $help_text |
|
| 1165 | - ); |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * _add_help_tabs |
|
| 1171 | - * Note child classes define their help tabs within the page_config array. |
|
| 1172 | - * |
|
| 1173 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1174 | - * @return void |
|
| 1175 | - * @throws DomainException |
|
| 1176 | - * @throws EE_Error |
|
| 1177 | - */ |
|
| 1178 | - protected function _add_help_tabs() |
|
| 1179 | - { |
|
| 1180 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1181 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1182 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1183 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1184 | - // check that the callback given is valid |
|
| 1185 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1186 | - throw new EE_Error( |
|
| 1187 | - sprintf( |
|
| 1188 | - esc_html__( |
|
| 1189 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1190 | - 'event_espresso' |
|
| 1191 | - ), |
|
| 1192 | - $config['help_sidebar'], |
|
| 1193 | - get_class($this) |
|
| 1194 | - ) |
|
| 1195 | - ); |
|
| 1196 | - } |
|
| 1197 | - $content = apply_filters( |
|
| 1198 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1199 | - $this->{$config['help_sidebar']}() |
|
| 1200 | - ); |
|
| 1201 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1202 | - } |
|
| 1203 | - if (! isset($config['help_tabs'])) { |
|
| 1204 | - return; |
|
| 1205 | - } //no help tabs for this route |
|
| 1206 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1207 | - // we're here so there ARE help tabs! |
|
| 1208 | - // make sure we've got what we need |
|
| 1209 | - if (! isset($cfg['title'])) { |
|
| 1210 | - throw new EE_Error( |
|
| 1211 | - esc_html__( |
|
| 1212 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1213 | - 'event_espresso' |
|
| 1214 | - ) |
|
| 1215 | - ); |
|
| 1216 | - } |
|
| 1217 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1218 | - throw new EE_Error( |
|
| 1219 | - esc_html__( |
|
| 1220 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1221 | - 'event_espresso' |
|
| 1222 | - ) |
|
| 1223 | - ); |
|
| 1224 | - } |
|
| 1225 | - // first priority goes to content. |
|
| 1226 | - if (! empty($cfg['content'])) { |
|
| 1227 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1228 | - // second priority goes to filename |
|
| 1229 | - } elseif (! empty($cfg['filename'])) { |
|
| 1230 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1231 | - // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1232 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1233 | - . basename($this->_get_dir()) |
|
| 1234 | - . '/help_tabs/' |
|
| 1235 | - . $cfg['filename'] |
|
| 1236 | - . '.help_tab.php' : $file_path; |
|
| 1237 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1238 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1239 | - EE_Error::add_error( |
|
| 1240 | - sprintf( |
|
| 1241 | - esc_html__( |
|
| 1242 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1243 | - 'event_espresso' |
|
| 1244 | - ), |
|
| 1245 | - $tab_id, |
|
| 1246 | - key($config), |
|
| 1247 | - $file_path |
|
| 1248 | - ), |
|
| 1249 | - __FILE__, |
|
| 1250 | - __FUNCTION__, |
|
| 1251 | - __LINE__ |
|
| 1252 | - ); |
|
| 1253 | - return; |
|
| 1254 | - } |
|
| 1255 | - $template_args['admin_page_obj'] = $this; |
|
| 1256 | - $content = EEH_Template::display_template( |
|
| 1257 | - $file_path, |
|
| 1258 | - $template_args, |
|
| 1259 | - true |
|
| 1260 | - ); |
|
| 1261 | - } else { |
|
| 1262 | - $content = ''; |
|
| 1263 | - } |
|
| 1264 | - // check if callback is valid |
|
| 1265 | - if ( |
|
| 1266 | - empty($content) |
|
| 1267 | - && ( |
|
| 1268 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1269 | - ) |
|
| 1270 | - ) { |
|
| 1271 | - EE_Error::add_error( |
|
| 1272 | - sprintf( |
|
| 1273 | - esc_html__( |
|
| 1274 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1275 | - 'event_espresso' |
|
| 1276 | - ), |
|
| 1277 | - $cfg['title'] |
|
| 1278 | - ), |
|
| 1279 | - __FILE__, |
|
| 1280 | - __FUNCTION__, |
|
| 1281 | - __LINE__ |
|
| 1282 | - ); |
|
| 1283 | - return; |
|
| 1284 | - } |
|
| 1285 | - // setup config array for help tab method |
|
| 1286 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1287 | - $_ht = [ |
|
| 1288 | - 'id' => $id, |
|
| 1289 | - 'title' => $cfg['title'], |
|
| 1290 | - 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1291 | - 'content' => $content, |
|
| 1292 | - ]; |
|
| 1293 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1294 | - } |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - |
|
| 1299 | - /** |
|
| 1300 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1301 | - * |
|
| 1302 | - * @return void |
|
| 1303 | - */ |
|
| 1304 | - protected function _add_qtips() |
|
| 1305 | - { |
|
| 1306 | - if (isset($this->_route_config['qtips'])) { |
|
| 1307 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1308 | - // load qtip loader |
|
| 1309 | - $path = [ |
|
| 1310 | - $this->_get_dir() . '/qtips/', |
|
| 1311 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1312 | - ]; |
|
| 1313 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * _set_nav_tabs |
|
| 1320 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1321 | - * wish to add additional tabs or modify accordingly. |
|
| 1322 | - * |
|
| 1323 | - * @return void |
|
| 1324 | - * @throws InvalidArgumentException |
|
| 1325 | - * @throws InvalidInterfaceException |
|
| 1326 | - * @throws InvalidDataTypeException |
|
| 1327 | - */ |
|
| 1328 | - protected function _set_nav_tabs() |
|
| 1329 | - { |
|
| 1330 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1331 | - $i = 0; |
|
| 1332 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1333 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1334 | - continue; |
|
| 1335 | - } |
|
| 1336 | - // no nav tab for this config |
|
| 1337 | - // check for persistent flag |
|
| 1338 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1339 | - // nav tab is only to appear when route requested. |
|
| 1340 | - continue; |
|
| 1341 | - } |
|
| 1342 | - if (! $this->check_user_access($slug, true)) { |
|
| 1343 | - // no nav tab because current user does not have access. |
|
| 1344 | - continue; |
|
| 1345 | - } |
|
| 1346 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1347 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1348 | - 'url' => isset($config['nav']['url']) |
|
| 1349 | - ? $config['nav']['url'] |
|
| 1350 | - : self::add_query_args_and_nonce( |
|
| 1351 | - ['action' => $slug], |
|
| 1352 | - $this->_admin_base_url |
|
| 1353 | - ), |
|
| 1354 | - 'link_text' => isset($config['nav']['label']) |
|
| 1355 | - ? $config['nav']['label'] |
|
| 1356 | - : ucwords( |
|
| 1357 | - str_replace('_', ' ', $slug) |
|
| 1358 | - ), |
|
| 1359 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1360 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1361 | - ]; |
|
| 1362 | - $i++; |
|
| 1363 | - } |
|
| 1364 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1365 | - if (empty($this->_nav_tabs)) { |
|
| 1366 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1367 | - 'url' => $this->_admin_base_url, |
|
| 1368 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1369 | - 'css_class' => 'nav-tab-active', |
|
| 1370 | - 'order' => 10, |
|
| 1371 | - ]; |
|
| 1372 | - } |
|
| 1373 | - // now let's sort the tabs according to order |
|
| 1374 | - usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * _set_current_labels |
|
| 1380 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1381 | - * property array |
|
| 1382 | - * |
|
| 1383 | - * @return void |
|
| 1384 | - */ |
|
| 1385 | - private function _set_current_labels() |
|
| 1386 | - { |
|
| 1387 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1388 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1389 | - if (is_array($text)) { |
|
| 1390 | - foreach ($text as $sublabel => $subtext) { |
|
| 1391 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1392 | - } |
|
| 1393 | - } else { |
|
| 1394 | - $this->_labels[ $label ] = $text; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * verifies user access for this admin page |
|
| 1403 | - * |
|
| 1404 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1405 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1406 | - * return false if verify fail. |
|
| 1407 | - * @return bool |
|
| 1408 | - * @throws InvalidArgumentException |
|
| 1409 | - * @throws InvalidDataTypeException |
|
| 1410 | - * @throws InvalidInterfaceException |
|
| 1411 | - */ |
|
| 1412 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1413 | - { |
|
| 1414 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1415 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1416 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1417 | - && is_array( |
|
| 1418 | - $this->_page_routes[ $route_to_check ] |
|
| 1419 | - ) |
|
| 1420 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1421 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1422 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1423 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1424 | - : $this->_route['capability']; |
|
| 1425 | - } else { |
|
| 1426 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1427 | - } |
|
| 1428 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1429 | - if ( |
|
| 1430 | - ! $this->request->isAjax() |
|
| 1431 | - && ( |
|
| 1432 | - ! function_exists('is_admin') |
|
| 1433 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1434 | - $capability, |
|
| 1435 | - $this->page_slug |
|
| 1436 | - . '_' |
|
| 1437 | - . $route_to_check, |
|
| 1438 | - $id |
|
| 1439 | - ) |
|
| 1440 | - ) |
|
| 1441 | - ) { |
|
| 1442 | - if ($verify_only) { |
|
| 1443 | - return false; |
|
| 1444 | - } |
|
| 1445 | - if (is_user_logged_in()) { |
|
| 1446 | - wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1447 | - } else { |
|
| 1448 | - return false; |
|
| 1449 | - } |
|
| 1450 | - } |
|
| 1451 | - return true; |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - |
|
| 1455 | - /** |
|
| 1456 | - * admin_init_global |
|
| 1457 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1458 | - * This method executes for ALL EE Admin pages. |
|
| 1459 | - * |
|
| 1460 | - * @return void |
|
| 1461 | - */ |
|
| 1462 | - public function admin_init_global() |
|
| 1463 | - { |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * wp_loaded_global |
|
| 1469 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1470 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1471 | - * |
|
| 1472 | - * @return void |
|
| 1473 | - */ |
|
| 1474 | - public function wp_loaded() |
|
| 1475 | - { |
|
| 1476 | - } |
|
| 1477 | - |
|
| 1478 | - |
|
| 1479 | - /** |
|
| 1480 | - * admin_notices |
|
| 1481 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1482 | - * ALL EE_Admin pages. |
|
| 1483 | - * |
|
| 1484 | - * @return void |
|
| 1485 | - */ |
|
| 1486 | - public function admin_notices_global() |
|
| 1487 | - { |
|
| 1488 | - $this->_display_no_javascript_warning(); |
|
| 1489 | - $this->_display_espresso_notices(); |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - |
|
| 1493 | - public function network_admin_notices_global() |
|
| 1494 | - { |
|
| 1495 | - $this->_display_no_javascript_warning(); |
|
| 1496 | - $this->_display_espresso_notices(); |
|
| 1497 | - } |
|
| 1498 | - |
|
| 1499 | - |
|
| 1500 | - /** |
|
| 1501 | - * admin_footer_scripts_global |
|
| 1502 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1503 | - * will apply on ALL EE_Admin pages. |
|
| 1504 | - * |
|
| 1505 | - * @return void |
|
| 1506 | - */ |
|
| 1507 | - public function admin_footer_scripts_global() |
|
| 1508 | - { |
|
| 1509 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1510 | - $this->_add_admin_page_overlay(); |
|
| 1511 | - // if metaboxes are present we need to add the nonce field |
|
| 1512 | - if ( |
|
| 1513 | - isset($this->_route_config['metaboxes']) |
|
| 1514 | - || isset($this->_route_config['list_table']) |
|
| 1515 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1516 | - ) { |
|
| 1517 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1518 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * admin_footer_global |
|
| 1525 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1526 | - * ALL EE_Admin Pages. |
|
| 1527 | - * |
|
| 1528 | - * @return void |
|
| 1529 | - */ |
|
| 1530 | - public function admin_footer_global() |
|
| 1531 | - { |
|
| 1532 | - // dialog container for dialog helper |
|
| 1533 | - echo ' |
|
| 111 | + /** |
|
| 112 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 113 | + * actions. |
|
| 114 | + * |
|
| 115 | + * @since 4.6.x |
|
| 116 | + * @var array. |
|
| 117 | + */ |
|
| 118 | + protected $_default_route_query_args; |
|
| 119 | + |
|
| 120 | + // set via request page and action args. |
|
| 121 | + protected $_current_page; |
|
| 122 | + |
|
| 123 | + protected $_current_view; |
|
| 124 | + |
|
| 125 | + protected $_current_page_view_url; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * unprocessed value for the 'action' request param (default '') |
|
| 129 | + * |
|
| 130 | + * @var string |
|
| 131 | + */ |
|
| 132 | + protected $raw_req_action = ''; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * unprocessed value for the 'page' request param (default '') |
|
| 136 | + * |
|
| 137 | + * @var string |
|
| 138 | + */ |
|
| 139 | + protected $raw_req_page = ''; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * sanitized request action (and nonce) |
|
| 143 | + * |
|
| 144 | + * @var string |
|
| 145 | + */ |
|
| 146 | + protected $_req_action = ''; |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * sanitized request action nonce |
|
| 150 | + * |
|
| 151 | + * @var string |
|
| 152 | + */ |
|
| 153 | + protected $_req_nonce = ''; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @var string |
|
| 157 | + */ |
|
| 158 | + protected $_search_btn_label = ''; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @var string |
|
| 162 | + */ |
|
| 163 | + protected $_search_box_callback = ''; |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @var WP_Screen |
|
| 167 | + */ |
|
| 168 | + protected $_current_screen; |
|
| 169 | + |
|
| 170 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 171 | + protected $_hook_obj; |
|
| 172 | + |
|
| 173 | + // for holding incoming request data |
|
| 174 | + protected $_req_data = []; |
|
| 175 | + |
|
| 176 | + // yes / no array for admin form fields |
|
| 177 | + protected $_yes_no_values = []; |
|
| 178 | + |
|
| 179 | + // some default things shared by all child classes |
|
| 180 | + protected $_default_espresso_metaboxes; |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @var EE_Registry |
|
| 184 | + */ |
|
| 185 | + protected $EE = null; |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 190 | + * |
|
| 191 | + * @var boolean |
|
| 192 | + */ |
|
| 193 | + protected $_is_caf = false; |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @Constructor |
|
| 198 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 199 | + * @throws EE_Error |
|
| 200 | + * @throws InvalidArgumentException |
|
| 201 | + * @throws ReflectionException |
|
| 202 | + * @throws InvalidDataTypeException |
|
| 203 | + * @throws InvalidInterfaceException |
|
| 204 | + */ |
|
| 205 | + public function __construct($routing = true) |
|
| 206 | + { |
|
| 207 | + $this->loader = LoaderFactory::getLoader(); |
|
| 208 | + $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 209 | + $this->_routing = $routing; |
|
| 210 | + |
|
| 211 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 212 | + $this->_is_caf = true; |
|
| 213 | + } |
|
| 214 | + $this->_yes_no_values = [ |
|
| 215 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 216 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 217 | + ]; |
|
| 218 | + // set the _req_data property. |
|
| 219 | + $this->_req_data = $this->request->requestParams(); |
|
| 220 | + // set initial page props (child method) |
|
| 221 | + $this->_init_page_props(); |
|
| 222 | + // set global defaults |
|
| 223 | + $this->_set_defaults(); |
|
| 224 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 225 | + $this->_global_ajax_hooks(); |
|
| 226 | + $this->_ajax_hooks(); |
|
| 227 | + // other_page_hooks have to be early too. |
|
| 228 | + $this->_do_other_page_hooks(); |
|
| 229 | + // set up page dependencies |
|
| 230 | + $this->_before_page_setup(); |
|
| 231 | + $this->_page_setup(); |
|
| 232 | + // die(); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * _init_page_props |
|
| 238 | + * Child classes use to set at least the following properties: |
|
| 239 | + * $page_slug. |
|
| 240 | + * $page_label. |
|
| 241 | + * |
|
| 242 | + * @abstract |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + abstract protected function _init_page_props(); |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * _ajax_hooks |
|
| 250 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 251 | + * Note: within the ajax callback methods. |
|
| 252 | + * |
|
| 253 | + * @abstract |
|
| 254 | + * @return void |
|
| 255 | + */ |
|
| 256 | + abstract protected function _ajax_hooks(); |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * _define_page_props |
|
| 261 | + * child classes define page properties in here. Must include at least: |
|
| 262 | + * $_admin_base_url = base_url for all admin pages |
|
| 263 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 264 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 265 | + * array( |
|
| 266 | + * 'buttons' => array( |
|
| 267 | + * 'add' => esc_html__('label for add new button'), |
|
| 268 | + * 'edit' => esc_html__('label for edit button'), |
|
| 269 | + * 'delete' => esc_html__('label for delete button') |
|
| 270 | + * ) |
|
| 271 | + * ) |
|
| 272 | + * |
|
| 273 | + * @abstract |
|
| 274 | + * @return void |
|
| 275 | + */ |
|
| 276 | + abstract protected function _define_page_props(); |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * _set_page_routes |
|
| 281 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 282 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 283 | + * have a 'default' route. Here's the format |
|
| 284 | + * $this->_page_routes = array( |
|
| 285 | + * 'default' => array( |
|
| 286 | + * 'func' => '_default_method_handling_route', |
|
| 287 | + * 'args' => array('array','of','args'), |
|
| 288 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 289 | + * ajax request, backend processing) |
|
| 290 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 291 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 292 | + * headers sent route. |
|
| 293 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 294 | + * this route. |
|
| 295 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 296 | + * checks). |
|
| 297 | + * ), |
|
| 298 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 299 | + * handling method. |
|
| 300 | + * ) |
|
| 301 | + * ) |
|
| 302 | + * |
|
| 303 | + * @abstract |
|
| 304 | + * @return void |
|
| 305 | + */ |
|
| 306 | + abstract protected function _set_page_routes(); |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * _set_page_config |
|
| 311 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 312 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 313 | + * $this->_page_config = array( |
|
| 314 | + * 'default' => array( |
|
| 315 | + * 'labels' => array( |
|
| 316 | + * 'buttons' => array( |
|
| 317 | + * 'add' => esc_html__('label for adding item'), |
|
| 318 | + * 'edit' => esc_html__('label for editing item'), |
|
| 319 | + * 'delete' => esc_html__('label for deleting item') |
|
| 320 | + * ), |
|
| 321 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 322 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 323 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 324 | + * _define_page_props() method |
|
| 325 | + * 'nav' => array( |
|
| 326 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 327 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 328 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 329 | + * 'order' => 10, //required to indicate tab position. |
|
| 330 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 331 | + * displayed then add this parameter. |
|
| 332 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 333 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 334 | + * metaboxes set for eventespresso admin pages. |
|
| 335 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 336 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 337 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 338 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 339 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 340 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 341 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 342 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 343 | + * want to display. |
|
| 344 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 345 | + * 'tab_id' => array( |
|
| 346 | + * 'title' => 'tab_title', |
|
| 347 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 348 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 349 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 350 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 351 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 352 | + * attempt to use the callback which should match the name of a method in the class |
|
| 353 | + * ), |
|
| 354 | + * 'tab2_id' => array( |
|
| 355 | + * 'title' => 'tab2 title', |
|
| 356 | + * 'filename' => 'file_name_2' |
|
| 357 | + * 'callback' => 'callback_method_for_content', |
|
| 358 | + * ), |
|
| 359 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 360 | + * help tab area on an admin page. @return void |
|
| 361 | + * |
|
| 362 | + * @abstract |
|
| 363 | + */ |
|
| 364 | + abstract protected function _set_page_config(); |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * _add_screen_options |
|
| 369 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 370 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 371 | + * to a particular view. |
|
| 372 | + * |
|
| 373 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 374 | + * see also WP_Screen object documents... |
|
| 375 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 376 | + * @abstract |
|
| 377 | + * @return void |
|
| 378 | + */ |
|
| 379 | + abstract protected function _add_screen_options(); |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * _add_feature_pointers |
|
| 384 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 385 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 386 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 387 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 388 | + * extended) also see: |
|
| 389 | + * |
|
| 390 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 391 | + * @abstract |
|
| 392 | + * @return void |
|
| 393 | + */ |
|
| 394 | + abstract protected function _add_feature_pointers(); |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * load_scripts_styles |
|
| 399 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 400 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 401 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 402 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 403 | + * |
|
| 404 | + * @abstract |
|
| 405 | + * @return void |
|
| 406 | + */ |
|
| 407 | + abstract public function load_scripts_styles(); |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * admin_init |
|
| 412 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 413 | + * all pages/views loaded by child class. |
|
| 414 | + * |
|
| 415 | + * @abstract |
|
| 416 | + * @return void |
|
| 417 | + */ |
|
| 418 | + abstract public function admin_init(); |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * admin_notices |
|
| 423 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 424 | + * all pages/views loaded by child class. |
|
| 425 | + * |
|
| 426 | + * @abstract |
|
| 427 | + * @return void |
|
| 428 | + */ |
|
| 429 | + abstract public function admin_notices(); |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * admin_footer_scripts |
|
| 434 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 435 | + * will apply to all pages/views loaded by child class. |
|
| 436 | + * |
|
| 437 | + * @return void |
|
| 438 | + */ |
|
| 439 | + abstract public function admin_footer_scripts(); |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * admin_footer |
|
| 444 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 445 | + * apply to all pages/views loaded by child class. |
|
| 446 | + * |
|
| 447 | + * @return void |
|
| 448 | + */ |
|
| 449 | + public function admin_footer() |
|
| 450 | + { |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * _global_ajax_hooks |
|
| 456 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 457 | + * Note: within the ajax callback methods. |
|
| 458 | + * |
|
| 459 | + * @abstract |
|
| 460 | + * @return void |
|
| 461 | + */ |
|
| 462 | + protected function _global_ajax_hooks() |
|
| 463 | + { |
|
| 464 | + // for lazy loading of metabox content |
|
| 465 | + add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + public function ajax_metabox_content() |
|
| 470 | + { |
|
| 471 | + $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 472 | + $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 473 | + self::cached_rss_display($content_id, $content_url); |
|
| 474 | + wp_die(); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 480 | + * |
|
| 481 | + * @return void |
|
| 482 | + */ |
|
| 483 | + protected function _before_page_setup() |
|
| 484 | + { |
|
| 485 | + // default is to do nothing |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Makes sure any things that need to be loaded early get handled. |
|
| 491 | + * We also escape early here if the page requested doesn't match the object. |
|
| 492 | + * |
|
| 493 | + * @final |
|
| 494 | + * @return void |
|
| 495 | + * @throws EE_Error |
|
| 496 | + * @throws InvalidArgumentException |
|
| 497 | + * @throws ReflectionException |
|
| 498 | + * @throws InvalidDataTypeException |
|
| 499 | + * @throws InvalidInterfaceException |
|
| 500 | + */ |
|
| 501 | + final protected function _page_setup() |
|
| 502 | + { |
|
| 503 | + // requires? |
|
| 504 | + // admin_init stuff - global - we're setting this REALLY early |
|
| 505 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 506 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 507 | + add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 508 | + // next verify if we need to load anything... |
|
| 509 | + $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 510 | + $this->page_folder = strtolower( |
|
| 511 | + str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 512 | + ); |
|
| 513 | + global $ee_menu_slugs; |
|
| 514 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 515 | + if ( |
|
| 516 | + ! $this->request->isAjax() |
|
| 517 | + && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 518 | + ) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 522 | + // we need to copy the action from the second to the first |
|
| 523 | + $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 524 | + $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 525 | + $action = $action !== '-1' ? $action : $action2; |
|
| 526 | + $req_action = $action !== '-1' ? $action : 'default'; |
|
| 527 | + |
|
| 528 | + // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 529 | + // then let's use the route as the action. |
|
| 530 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 531 | + $route = $this->request->getRequestParam('route'); |
|
| 532 | + $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 533 | + ? $route |
|
| 534 | + : $req_action; |
|
| 535 | + |
|
| 536 | + $this->_current_view = $this->_req_action; |
|
| 537 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 538 | + $this->_define_page_props(); |
|
| 539 | + $this->_current_page_view_url = add_query_arg( |
|
| 540 | + ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 541 | + $this->_admin_base_url |
|
| 542 | + ); |
|
| 543 | + // default things |
|
| 544 | + $this->_default_espresso_metaboxes = [ |
|
| 545 | + '_espresso_news_post_box', |
|
| 546 | + '_espresso_links_post_box', |
|
| 547 | + '_espresso_ratings_request', |
|
| 548 | + '_espresso_sponsors_post_box', |
|
| 549 | + ]; |
|
| 550 | + // set page configs |
|
| 551 | + $this->_set_page_routes(); |
|
| 552 | + $this->_set_page_config(); |
|
| 553 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 554 | + if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 555 | + $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 556 | + if ($wp_referer) { |
|
| 557 | + $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + // for caffeinated and other extended functionality. |
|
| 561 | + // If there is a _extend_page_config method |
|
| 562 | + // then let's run that to modify the all the various page configuration arrays |
|
| 563 | + if (method_exists($this, '_extend_page_config')) { |
|
| 564 | + $this->_extend_page_config(); |
|
| 565 | + } |
|
| 566 | + // for CPT and other extended functionality. |
|
| 567 | + // If there is an _extend_page_config_for_cpt |
|
| 568 | + // then let's run that to modify all the various page configuration arrays. |
|
| 569 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | + $this->_extend_page_config_for_cpt(); |
|
| 571 | + } |
|
| 572 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | + $this->_page_routes = apply_filters( |
|
| 574 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | + $this->_page_routes, |
|
| 576 | + $this |
|
| 577 | + ); |
|
| 578 | + $this->_page_config = apply_filters( |
|
| 579 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | + $this->_page_config, |
|
| 581 | + $this |
|
| 582 | + ); |
|
| 583 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 586 | + add_action( |
|
| 587 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 588 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 589 | + 10, |
|
| 590 | + 2 |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + // next route only if routing enabled |
|
| 594 | + if ($this->_routing && ! $this->request->isAjax()) { |
|
| 595 | + $this->_verify_routes(); |
|
| 596 | + // next let's just check user_access and kill if no access |
|
| 597 | + $this->check_user_access(); |
|
| 598 | + if ($this->_is_UI_request) { |
|
| 599 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 600 | + add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 601 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 602 | + add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 603 | + } |
|
| 604 | + } else { |
|
| 605 | + // hijack regular WP loading and route admin request immediately |
|
| 606 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 607 | + $this->route_admin_request(); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 615 | + * |
|
| 616 | + * @return void |
|
| 617 | + * @throws EE_Error |
|
| 618 | + */ |
|
| 619 | + private function _do_other_page_hooks() |
|
| 620 | + { |
|
| 621 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 622 | + foreach ($registered_pages as $page) { |
|
| 623 | + // now let's setup the file name and class that should be present |
|
| 624 | + $classname = str_replace('.class.php', '', $page); |
|
| 625 | + // autoloaders should take care of loading file |
|
| 626 | + if (! class_exists($classname)) { |
|
| 627 | + $error_msg[] = sprintf( |
|
| 628 | + esc_html__( |
|
| 629 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 630 | + 'event_espresso' |
|
| 631 | + ), |
|
| 632 | + $page |
|
| 633 | + ); |
|
| 634 | + $error_msg[] = $error_msg[0] |
|
| 635 | + . "\r\n" |
|
| 636 | + . sprintf( |
|
| 637 | + esc_html__( |
|
| 638 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 639 | + 'event_espresso' |
|
| 640 | + ), |
|
| 641 | + $page, |
|
| 642 | + '<br />', |
|
| 643 | + '<strong>' . $classname . '</strong>' |
|
| 644 | + ); |
|
| 645 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 646 | + } |
|
| 647 | + // notice we are passing the instance of this class to the hook object. |
|
| 648 | + $this->loader->getShared($classname, [$this]); |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * @throws ReflectionException |
|
| 655 | + * @throws EE_Error |
|
| 656 | + */ |
|
| 657 | + public function load_page_dependencies() |
|
| 658 | + { |
|
| 659 | + try { |
|
| 660 | + $this->_load_page_dependencies(); |
|
| 661 | + } catch (EE_Error $e) { |
|
| 662 | + $e->get_error(); |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * load_page_dependencies |
|
| 669 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 670 | + * |
|
| 671 | + * @return void |
|
| 672 | + * @throws DomainException |
|
| 673 | + * @throws EE_Error |
|
| 674 | + * @throws InvalidArgumentException |
|
| 675 | + * @throws InvalidDataTypeException |
|
| 676 | + * @throws InvalidInterfaceException |
|
| 677 | + */ |
|
| 678 | + protected function _load_page_dependencies() |
|
| 679 | + { |
|
| 680 | + // let's set the current_screen and screen options to override what WP set |
|
| 681 | + $this->_current_screen = get_current_screen(); |
|
| 682 | + // load admin_notices - global, page class, and view specific |
|
| 683 | + add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 684 | + add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 685 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 686 | + add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 687 | + } |
|
| 688 | + // load network admin_notices - global, page class, and view specific |
|
| 689 | + add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 690 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 691 | + add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 692 | + } |
|
| 693 | + // this will save any per_page screen options if they are present |
|
| 694 | + $this->_set_per_page_screen_options(); |
|
| 695 | + // setup list table properties |
|
| 696 | + $this->_set_list_table(); |
|
| 697 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 698 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 699 | + $this->_add_registered_meta_boxes(); |
|
| 700 | + $this->_add_screen_columns(); |
|
| 701 | + // add screen options - global, page child class, and view specific |
|
| 702 | + $this->_add_global_screen_options(); |
|
| 703 | + $this->_add_screen_options(); |
|
| 704 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 705 | + if (method_exists($this, $add_screen_options)) { |
|
| 706 | + $this->{$add_screen_options}(); |
|
| 707 | + } |
|
| 708 | + // add help tab(s) - set via page_config and qtips. |
|
| 709 | + $this->_add_help_tabs(); |
|
| 710 | + $this->_add_qtips(); |
|
| 711 | + // add feature_pointers - global, page child class, and view specific |
|
| 712 | + $this->_add_feature_pointers(); |
|
| 713 | + $this->_add_global_feature_pointers(); |
|
| 714 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 715 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 716 | + $this->{$add_feature_pointer}(); |
|
| 717 | + } |
|
| 718 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 719 | + add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 720 | + add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 721 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 722 | + add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 723 | + } |
|
| 724 | + add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 725 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 726 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 727 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 728 | + // is a good use case. Notice the late priority we're giving these |
|
| 729 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 730 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 731 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 732 | + add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 733 | + } |
|
| 734 | + // admin footer scripts |
|
| 735 | + add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 736 | + add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 737 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 738 | + add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 739 | + } |
|
| 740 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 741 | + // targeted hook |
|
| 742 | + do_action( |
|
| 743 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 744 | + ); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * _set_defaults |
|
| 750 | + * This sets some global defaults for class properties. |
|
| 751 | + */ |
|
| 752 | + private function _set_defaults() |
|
| 753 | + { |
|
| 754 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 755 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 756 | + $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 757 | + $this->_page_config = $this->_default_route_query_args = []; |
|
| 758 | + $this->_default_nav_tab_name = 'overview'; |
|
| 759 | + // init template args |
|
| 760 | + $this->_template_args = [ |
|
| 761 | + 'admin_page_header' => '', |
|
| 762 | + 'admin_page_content' => '', |
|
| 763 | + 'post_body_content' => '', |
|
| 764 | + 'before_list_table' => '', |
|
| 765 | + 'after_list_table' => '', |
|
| 766 | + ]; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * route_admin_request |
|
| 772 | + * |
|
| 773 | + * @return void |
|
| 774 | + * @throws InvalidArgumentException |
|
| 775 | + * @throws InvalidInterfaceException |
|
| 776 | + * @throws InvalidDataTypeException |
|
| 777 | + * @throws EE_Error |
|
| 778 | + * @throws ReflectionException |
|
| 779 | + * @see _route_admin_request() |
|
| 780 | + */ |
|
| 781 | + public function route_admin_request() |
|
| 782 | + { |
|
| 783 | + try { |
|
| 784 | + $this->_route_admin_request(); |
|
| 785 | + } catch (EE_Error $e) { |
|
| 786 | + $e->get_error(); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + public function set_wp_page_slug($wp_page_slug) |
|
| 792 | + { |
|
| 793 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 794 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 795 | + if (is_network_admin()) { |
|
| 796 | + $this->_wp_page_slug .= '-network'; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * _verify_routes |
|
| 803 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 804 | + * we know if we need to drop out. |
|
| 805 | + * |
|
| 806 | + * @return bool |
|
| 807 | + * @throws EE_Error |
|
| 808 | + */ |
|
| 809 | + protected function _verify_routes() |
|
| 810 | + { |
|
| 811 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 812 | + if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 813 | + return false; |
|
| 814 | + } |
|
| 815 | + $this->_route = false; |
|
| 816 | + // check that the page_routes array is not empty |
|
| 817 | + if (empty($this->_page_routes)) { |
|
| 818 | + // user error msg |
|
| 819 | + $error_msg = sprintf( |
|
| 820 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 821 | + $this->_admin_page_title |
|
| 822 | + ); |
|
| 823 | + // developer error msg |
|
| 824 | + $error_msg .= '||' . $error_msg |
|
| 825 | + . esc_html__( |
|
| 826 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 827 | + 'event_espresso' |
|
| 828 | + ); |
|
| 829 | + throw new EE_Error($error_msg); |
|
| 830 | + } |
|
| 831 | + // and that the requested page route exists |
|
| 832 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 833 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 834 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 835 | + ? $this->_page_config[ $this->_req_action ] |
|
| 836 | + : []; |
|
| 837 | + } else { |
|
| 838 | + // user error msg |
|
| 839 | + $error_msg = sprintf( |
|
| 840 | + esc_html__( |
|
| 841 | + 'The requested page route does not exist for the %s admin page.', |
|
| 842 | + 'event_espresso' |
|
| 843 | + ), |
|
| 844 | + $this->_admin_page_title |
|
| 845 | + ); |
|
| 846 | + // developer error msg |
|
| 847 | + $error_msg .= '||' . $error_msg |
|
| 848 | + . sprintf( |
|
| 849 | + esc_html__( |
|
| 850 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ), |
|
| 853 | + $this->_req_action |
|
| 854 | + ); |
|
| 855 | + throw new EE_Error($error_msg); |
|
| 856 | + } |
|
| 857 | + // and that a default route exists |
|
| 858 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 859 | + // user error msg |
|
| 860 | + $error_msg = sprintf( |
|
| 861 | + esc_html__( |
|
| 862 | + 'A default page route has not been set for the % admin page.', |
|
| 863 | + 'event_espresso' |
|
| 864 | + ), |
|
| 865 | + $this->_admin_page_title |
|
| 866 | + ); |
|
| 867 | + // developer error msg |
|
| 868 | + $error_msg .= '||' . $error_msg |
|
| 869 | + . esc_html__( |
|
| 870 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 871 | + 'event_espresso' |
|
| 872 | + ); |
|
| 873 | + throw new EE_Error($error_msg); |
|
| 874 | + } |
|
| 875 | + // first lets' catch if the UI request has EVER been set. |
|
| 876 | + if ($this->_is_UI_request === null) { |
|
| 877 | + // lets set if this is a UI request or not. |
|
| 878 | + $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 879 | + // wait a minute... we might have a noheader in the route array |
|
| 880 | + $this->_is_UI_request = ! ( |
|
| 881 | + is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 882 | + ) |
|
| 883 | + ? $this->_is_UI_request |
|
| 884 | + : false; |
|
| 885 | + } |
|
| 886 | + $this->_set_current_labels(); |
|
| 887 | + return true; |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 893 | + * |
|
| 894 | + * @param string $route the route name we're verifying |
|
| 895 | + * @return bool we'll throw an exception if this isn't a valid route. |
|
| 896 | + * @throws EE_Error |
|
| 897 | + */ |
|
| 898 | + protected function _verify_route($route) |
|
| 899 | + { |
|
| 900 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 901 | + return true; |
|
| 902 | + } |
|
| 903 | + // user error msg |
|
| 904 | + $error_msg = sprintf( |
|
| 905 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 906 | + $this->_admin_page_title |
|
| 907 | + ); |
|
| 908 | + // developer error msg |
|
| 909 | + $error_msg .= '||' . $error_msg |
|
| 910 | + . sprintf( |
|
| 911 | + esc_html__( |
|
| 912 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 913 | + 'event_espresso' |
|
| 914 | + ), |
|
| 915 | + $route |
|
| 916 | + ); |
|
| 917 | + throw new EE_Error($error_msg); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * perform nonce verification |
|
| 923 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 924 | + * using this method (and save retyping!) |
|
| 925 | + * |
|
| 926 | + * @param string $nonce The nonce sent |
|
| 927 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 928 | + * @return void |
|
| 929 | + * @throws EE_Error |
|
| 930 | + */ |
|
| 931 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 932 | + { |
|
| 933 | + // verify nonce against expected value |
|
| 934 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 935 | + // these are not the droids you are looking for !!! |
|
| 936 | + $msg = sprintf( |
|
| 937 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 938 | + '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 939 | + '</a>' |
|
| 940 | + ); |
|
| 941 | + if (WP_DEBUG) { |
|
| 942 | + $msg .= "\n "; |
|
| 943 | + $msg .= sprintf( |
|
| 944 | + esc_html__( |
|
| 945 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 946 | + 'event_espresso' |
|
| 947 | + ), |
|
| 948 | + __CLASS__ |
|
| 949 | + ); |
|
| 950 | + } |
|
| 951 | + if (! $this->request->isAjax()) { |
|
| 952 | + wp_die($msg); |
|
| 953 | + } |
|
| 954 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 955 | + $this->_return_json(); |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + |
|
| 960 | + /** |
|
| 961 | + * _route_admin_request() |
|
| 962 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 963 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 964 | + * in the page routes and then will try to load the corresponding method. |
|
| 965 | + * |
|
| 966 | + * @return void |
|
| 967 | + * @throws EE_Error |
|
| 968 | + * @throws InvalidArgumentException |
|
| 969 | + * @throws InvalidDataTypeException |
|
| 970 | + * @throws InvalidInterfaceException |
|
| 971 | + * @throws ReflectionException |
|
| 972 | + */ |
|
| 973 | + protected function _route_admin_request() |
|
| 974 | + { |
|
| 975 | + if (! $this->_is_UI_request) { |
|
| 976 | + $this->_verify_routes(); |
|
| 977 | + } |
|
| 978 | + $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 979 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 980 | + // set nonce from post data |
|
| 981 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 982 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 983 | + } |
|
| 984 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 985 | + if ($this->_is_UI_request) { |
|
| 986 | + $this->_set_nav_tabs(); |
|
| 987 | + } |
|
| 988 | + // grab callback function |
|
| 989 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 990 | + // check if callback has args |
|
| 991 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 992 | + $error_msg = ''; |
|
| 993 | + // action right before calling route |
|
| 994 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 995 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 996 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 997 | + } |
|
| 998 | + // right before calling the route, let's clean the _wp_http_referer |
|
| 999 | + $this->request->setServerParam( |
|
| 1000 | + 'REQUEST_URI', |
|
| 1001 | + remove_query_arg( |
|
| 1002 | + '_wp_http_referer', |
|
| 1003 | + wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1004 | + ) |
|
| 1005 | + ); |
|
| 1006 | + if (! empty($func)) { |
|
| 1007 | + if (is_array($func)) { |
|
| 1008 | + list($class, $method) = $func; |
|
| 1009 | + } elseif (strpos($func, '::') !== false) { |
|
| 1010 | + list($class, $method) = explode('::', $func); |
|
| 1011 | + } else { |
|
| 1012 | + $class = $this; |
|
| 1013 | + $method = $func; |
|
| 1014 | + } |
|
| 1015 | + if (! (is_object($class) && $class === $this)) { |
|
| 1016 | + // send along this admin page object for access by addons. |
|
| 1017 | + $args['admin_page_object'] = $this; |
|
| 1018 | + } |
|
| 1019 | + if ( |
|
| 1020 | + // is it a method on a class that doesn't work? |
|
| 1021 | + ( |
|
| 1022 | + ( |
|
| 1023 | + method_exists($class, $method) |
|
| 1024 | + && call_user_func_array([$class, $method], $args) === false |
|
| 1025 | + ) |
|
| 1026 | + && ( |
|
| 1027 | + // is it a standalone function that doesn't work? |
|
| 1028 | + function_exists($method) |
|
| 1029 | + && call_user_func_array( |
|
| 1030 | + $func, |
|
| 1031 | + array_merge(['admin_page_object' => $this], $args) |
|
| 1032 | + ) === false |
|
| 1033 | + ) |
|
| 1034 | + ) |
|
| 1035 | + || ( |
|
| 1036 | + // is it neither a class method NOR a standalone function? |
|
| 1037 | + ! method_exists($class, $method) |
|
| 1038 | + && ! function_exists($method) |
|
| 1039 | + ) |
|
| 1040 | + ) { |
|
| 1041 | + // user error msg |
|
| 1042 | + $error_msg = esc_html__( |
|
| 1043 | + 'An error occurred. The requested page route could not be found.', |
|
| 1044 | + 'event_espresso' |
|
| 1045 | + ); |
|
| 1046 | + // developer error msg |
|
| 1047 | + $error_msg .= '||'; |
|
| 1048 | + $error_msg .= sprintf( |
|
| 1049 | + esc_html__( |
|
| 1050 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1051 | + 'event_espresso' |
|
| 1052 | + ), |
|
| 1053 | + $method |
|
| 1054 | + ); |
|
| 1055 | + } |
|
| 1056 | + if (! empty($error_msg)) { |
|
| 1057 | + throw new EE_Error($error_msg); |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1061 | + // then we need to reset the routing properties to the new route. |
|
| 1062 | + // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1063 | + if ( |
|
| 1064 | + $this->_is_UI_request === false |
|
| 1065 | + && is_array($this->_route) |
|
| 1066 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1067 | + ) { |
|
| 1068 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + |
|
| 1073 | + /** |
|
| 1074 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1075 | + * route redirects to a headers route in its route config. |
|
| 1076 | + * |
|
| 1077 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1078 | + * @return void |
|
| 1079 | + * @throws ReflectionException |
|
| 1080 | + * @throws InvalidArgumentException |
|
| 1081 | + * @throws InvalidInterfaceException |
|
| 1082 | + * @throws InvalidDataTypeException |
|
| 1083 | + * @throws EE_Error |
|
| 1084 | + * @since 4.3.0 |
|
| 1085 | + */ |
|
| 1086 | + protected function _reset_routing_properties($new_route) |
|
| 1087 | + { |
|
| 1088 | + $this->_is_UI_request = true; |
|
| 1089 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1090 | + $this->request->setRequestParam('action', $new_route); |
|
| 1091 | + // rerun page setup |
|
| 1092 | + $this->_page_setup(); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * _add_query_arg |
|
| 1098 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1099 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1100 | + * |
|
| 1101 | + * @param array $args |
|
| 1102 | + * @param string $url |
|
| 1103 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1104 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1105 | + * Example usage: If the current page is: |
|
| 1106 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1107 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1108 | + * &_wpnonce=5467821 |
|
| 1109 | + * and you call: |
|
| 1110 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1111 | + * array( |
|
| 1112 | + * 'action' => 'resend_something', |
|
| 1113 | + * 'page=>espresso_registrations' |
|
| 1114 | + * ), |
|
| 1115 | + * $some_url, |
|
| 1116 | + * true |
|
| 1117 | + * ); |
|
| 1118 | + * It will produce a url in this structure: |
|
| 1119 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1120 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1121 | + * month_range]=March%202015 |
|
| 1122 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1123 | + * @return string |
|
| 1124 | + */ |
|
| 1125 | + public static function add_query_args_and_nonce( |
|
| 1126 | + $args = [], |
|
| 1127 | + $url = false, |
|
| 1128 | + $sticky = false, |
|
| 1129 | + $exclude_nonce = false |
|
| 1130 | + ) { |
|
| 1131 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1132 | + if ($sticky) { |
|
| 1133 | + /** @var RequestInterface $request */ |
|
| 1134 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1135 | + $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1136 | + foreach ($request->requestParams() as $key => $value) { |
|
| 1137 | + // do not add nonces |
|
| 1138 | + if (strpos($key, 'nonce') !== false) { |
|
| 1139 | + continue; |
|
| 1140 | + } |
|
| 1141 | + $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * This returns a generated link that will load the related help tab. |
|
| 1150 | + * |
|
| 1151 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1152 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1153 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1154 | + * @return string generated link |
|
| 1155 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1156 | + */ |
|
| 1157 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1158 | + { |
|
| 1159 | + return EEH_Template::get_help_tab_link( |
|
| 1160 | + $help_tab_id, |
|
| 1161 | + $this->page_slug, |
|
| 1162 | + $this->_req_action, |
|
| 1163 | + $icon_style, |
|
| 1164 | + $help_text |
|
| 1165 | + ); |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * _add_help_tabs |
|
| 1171 | + * Note child classes define their help tabs within the page_config array. |
|
| 1172 | + * |
|
| 1173 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1174 | + * @return void |
|
| 1175 | + * @throws DomainException |
|
| 1176 | + * @throws EE_Error |
|
| 1177 | + */ |
|
| 1178 | + protected function _add_help_tabs() |
|
| 1179 | + { |
|
| 1180 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1181 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1182 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1183 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1184 | + // check that the callback given is valid |
|
| 1185 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1186 | + throw new EE_Error( |
|
| 1187 | + sprintf( |
|
| 1188 | + esc_html__( |
|
| 1189 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1190 | + 'event_espresso' |
|
| 1191 | + ), |
|
| 1192 | + $config['help_sidebar'], |
|
| 1193 | + get_class($this) |
|
| 1194 | + ) |
|
| 1195 | + ); |
|
| 1196 | + } |
|
| 1197 | + $content = apply_filters( |
|
| 1198 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1199 | + $this->{$config['help_sidebar']}() |
|
| 1200 | + ); |
|
| 1201 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1202 | + } |
|
| 1203 | + if (! isset($config['help_tabs'])) { |
|
| 1204 | + return; |
|
| 1205 | + } //no help tabs for this route |
|
| 1206 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1207 | + // we're here so there ARE help tabs! |
|
| 1208 | + // make sure we've got what we need |
|
| 1209 | + if (! isset($cfg['title'])) { |
|
| 1210 | + throw new EE_Error( |
|
| 1211 | + esc_html__( |
|
| 1212 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1213 | + 'event_espresso' |
|
| 1214 | + ) |
|
| 1215 | + ); |
|
| 1216 | + } |
|
| 1217 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1218 | + throw new EE_Error( |
|
| 1219 | + esc_html__( |
|
| 1220 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1221 | + 'event_espresso' |
|
| 1222 | + ) |
|
| 1223 | + ); |
|
| 1224 | + } |
|
| 1225 | + // first priority goes to content. |
|
| 1226 | + if (! empty($cfg['content'])) { |
|
| 1227 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1228 | + // second priority goes to filename |
|
| 1229 | + } elseif (! empty($cfg['filename'])) { |
|
| 1230 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1231 | + // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1232 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1233 | + . basename($this->_get_dir()) |
|
| 1234 | + . '/help_tabs/' |
|
| 1235 | + . $cfg['filename'] |
|
| 1236 | + . '.help_tab.php' : $file_path; |
|
| 1237 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1238 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1239 | + EE_Error::add_error( |
|
| 1240 | + sprintf( |
|
| 1241 | + esc_html__( |
|
| 1242 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1243 | + 'event_espresso' |
|
| 1244 | + ), |
|
| 1245 | + $tab_id, |
|
| 1246 | + key($config), |
|
| 1247 | + $file_path |
|
| 1248 | + ), |
|
| 1249 | + __FILE__, |
|
| 1250 | + __FUNCTION__, |
|
| 1251 | + __LINE__ |
|
| 1252 | + ); |
|
| 1253 | + return; |
|
| 1254 | + } |
|
| 1255 | + $template_args['admin_page_obj'] = $this; |
|
| 1256 | + $content = EEH_Template::display_template( |
|
| 1257 | + $file_path, |
|
| 1258 | + $template_args, |
|
| 1259 | + true |
|
| 1260 | + ); |
|
| 1261 | + } else { |
|
| 1262 | + $content = ''; |
|
| 1263 | + } |
|
| 1264 | + // check if callback is valid |
|
| 1265 | + if ( |
|
| 1266 | + empty($content) |
|
| 1267 | + && ( |
|
| 1268 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1269 | + ) |
|
| 1270 | + ) { |
|
| 1271 | + EE_Error::add_error( |
|
| 1272 | + sprintf( |
|
| 1273 | + esc_html__( |
|
| 1274 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1275 | + 'event_espresso' |
|
| 1276 | + ), |
|
| 1277 | + $cfg['title'] |
|
| 1278 | + ), |
|
| 1279 | + __FILE__, |
|
| 1280 | + __FUNCTION__, |
|
| 1281 | + __LINE__ |
|
| 1282 | + ); |
|
| 1283 | + return; |
|
| 1284 | + } |
|
| 1285 | + // setup config array for help tab method |
|
| 1286 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1287 | + $_ht = [ |
|
| 1288 | + 'id' => $id, |
|
| 1289 | + 'title' => $cfg['title'], |
|
| 1290 | + 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1291 | + 'content' => $content, |
|
| 1292 | + ]; |
|
| 1293 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1294 | + } |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + |
|
| 1299 | + /** |
|
| 1300 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1301 | + * |
|
| 1302 | + * @return void |
|
| 1303 | + */ |
|
| 1304 | + protected function _add_qtips() |
|
| 1305 | + { |
|
| 1306 | + if (isset($this->_route_config['qtips'])) { |
|
| 1307 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1308 | + // load qtip loader |
|
| 1309 | + $path = [ |
|
| 1310 | + $this->_get_dir() . '/qtips/', |
|
| 1311 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1312 | + ]; |
|
| 1313 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * _set_nav_tabs |
|
| 1320 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1321 | + * wish to add additional tabs or modify accordingly. |
|
| 1322 | + * |
|
| 1323 | + * @return void |
|
| 1324 | + * @throws InvalidArgumentException |
|
| 1325 | + * @throws InvalidInterfaceException |
|
| 1326 | + * @throws InvalidDataTypeException |
|
| 1327 | + */ |
|
| 1328 | + protected function _set_nav_tabs() |
|
| 1329 | + { |
|
| 1330 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1331 | + $i = 0; |
|
| 1332 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1333 | + if (! is_array($config) || empty($config['nav'])) { |
|
| 1334 | + continue; |
|
| 1335 | + } |
|
| 1336 | + // no nav tab for this config |
|
| 1337 | + // check for persistent flag |
|
| 1338 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1339 | + // nav tab is only to appear when route requested. |
|
| 1340 | + continue; |
|
| 1341 | + } |
|
| 1342 | + if (! $this->check_user_access($slug, true)) { |
|
| 1343 | + // no nav tab because current user does not have access. |
|
| 1344 | + continue; |
|
| 1345 | + } |
|
| 1346 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1347 | + $this->_nav_tabs[ $slug ] = [ |
|
| 1348 | + 'url' => isset($config['nav']['url']) |
|
| 1349 | + ? $config['nav']['url'] |
|
| 1350 | + : self::add_query_args_and_nonce( |
|
| 1351 | + ['action' => $slug], |
|
| 1352 | + $this->_admin_base_url |
|
| 1353 | + ), |
|
| 1354 | + 'link_text' => isset($config['nav']['label']) |
|
| 1355 | + ? $config['nav']['label'] |
|
| 1356 | + : ucwords( |
|
| 1357 | + str_replace('_', ' ', $slug) |
|
| 1358 | + ), |
|
| 1359 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1360 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1361 | + ]; |
|
| 1362 | + $i++; |
|
| 1363 | + } |
|
| 1364 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1365 | + if (empty($this->_nav_tabs)) { |
|
| 1366 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1367 | + 'url' => $this->_admin_base_url, |
|
| 1368 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1369 | + 'css_class' => 'nav-tab-active', |
|
| 1370 | + 'order' => 10, |
|
| 1371 | + ]; |
|
| 1372 | + } |
|
| 1373 | + // now let's sort the tabs according to order |
|
| 1374 | + usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * _set_current_labels |
|
| 1380 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1381 | + * property array |
|
| 1382 | + * |
|
| 1383 | + * @return void |
|
| 1384 | + */ |
|
| 1385 | + private function _set_current_labels() |
|
| 1386 | + { |
|
| 1387 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1388 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1389 | + if (is_array($text)) { |
|
| 1390 | + foreach ($text as $sublabel => $subtext) { |
|
| 1391 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1392 | + } |
|
| 1393 | + } else { |
|
| 1394 | + $this->_labels[ $label ] = $text; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * verifies user access for this admin page |
|
| 1403 | + * |
|
| 1404 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1405 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1406 | + * return false if verify fail. |
|
| 1407 | + * @return bool |
|
| 1408 | + * @throws InvalidArgumentException |
|
| 1409 | + * @throws InvalidDataTypeException |
|
| 1410 | + * @throws InvalidInterfaceException |
|
| 1411 | + */ |
|
| 1412 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1413 | + { |
|
| 1414 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1415 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1416 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1417 | + && is_array( |
|
| 1418 | + $this->_page_routes[ $route_to_check ] |
|
| 1419 | + ) |
|
| 1420 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1421 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1422 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1423 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1424 | + : $this->_route['capability']; |
|
| 1425 | + } else { |
|
| 1426 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1427 | + } |
|
| 1428 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1429 | + if ( |
|
| 1430 | + ! $this->request->isAjax() |
|
| 1431 | + && ( |
|
| 1432 | + ! function_exists('is_admin') |
|
| 1433 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1434 | + $capability, |
|
| 1435 | + $this->page_slug |
|
| 1436 | + . '_' |
|
| 1437 | + . $route_to_check, |
|
| 1438 | + $id |
|
| 1439 | + ) |
|
| 1440 | + ) |
|
| 1441 | + ) { |
|
| 1442 | + if ($verify_only) { |
|
| 1443 | + return false; |
|
| 1444 | + } |
|
| 1445 | + if (is_user_logged_in()) { |
|
| 1446 | + wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1447 | + } else { |
|
| 1448 | + return false; |
|
| 1449 | + } |
|
| 1450 | + } |
|
| 1451 | + return true; |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + |
|
| 1455 | + /** |
|
| 1456 | + * admin_init_global |
|
| 1457 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1458 | + * This method executes for ALL EE Admin pages. |
|
| 1459 | + * |
|
| 1460 | + * @return void |
|
| 1461 | + */ |
|
| 1462 | + public function admin_init_global() |
|
| 1463 | + { |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * wp_loaded_global |
|
| 1469 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1470 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1471 | + * |
|
| 1472 | + * @return void |
|
| 1473 | + */ |
|
| 1474 | + public function wp_loaded() |
|
| 1475 | + { |
|
| 1476 | + } |
|
| 1477 | + |
|
| 1478 | + |
|
| 1479 | + /** |
|
| 1480 | + * admin_notices |
|
| 1481 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1482 | + * ALL EE_Admin pages. |
|
| 1483 | + * |
|
| 1484 | + * @return void |
|
| 1485 | + */ |
|
| 1486 | + public function admin_notices_global() |
|
| 1487 | + { |
|
| 1488 | + $this->_display_no_javascript_warning(); |
|
| 1489 | + $this->_display_espresso_notices(); |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + |
|
| 1493 | + public function network_admin_notices_global() |
|
| 1494 | + { |
|
| 1495 | + $this->_display_no_javascript_warning(); |
|
| 1496 | + $this->_display_espresso_notices(); |
|
| 1497 | + } |
|
| 1498 | + |
|
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * admin_footer_scripts_global |
|
| 1502 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1503 | + * will apply on ALL EE_Admin pages. |
|
| 1504 | + * |
|
| 1505 | + * @return void |
|
| 1506 | + */ |
|
| 1507 | + public function admin_footer_scripts_global() |
|
| 1508 | + { |
|
| 1509 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1510 | + $this->_add_admin_page_overlay(); |
|
| 1511 | + // if metaboxes are present we need to add the nonce field |
|
| 1512 | + if ( |
|
| 1513 | + isset($this->_route_config['metaboxes']) |
|
| 1514 | + || isset($this->_route_config['list_table']) |
|
| 1515 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1516 | + ) { |
|
| 1517 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1518 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1519 | + } |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * admin_footer_global |
|
| 1525 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1526 | + * ALL EE_Admin Pages. |
|
| 1527 | + * |
|
| 1528 | + * @return void |
|
| 1529 | + */ |
|
| 1530 | + public function admin_footer_global() |
|
| 1531 | + { |
|
| 1532 | + // dialog container for dialog helper |
|
| 1533 | + echo ' |
|
| 1534 | 1534 | <div class="ee-admin-dialog-container auto-hide hidden"> |
| 1535 | 1535 | <div class="ee-notices"></div> |
| 1536 | 1536 | <div class="ee-admin-dialog-container-inner-content"></div> |
| 1537 | 1537 | </div> |
| 1538 | 1538 | '; |
| 1539 | 1539 | |
| 1540 | - // current set timezone for timezone js |
|
| 1541 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1542 | - } |
|
| 1543 | - |
|
| 1544 | - |
|
| 1545 | - /** |
|
| 1546 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1547 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1548 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1549 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1550 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1551 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1552 | - * for the |
|
| 1553 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1554 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1555 | - * 'help_trigger_id' => array( |
|
| 1556 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1557 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1558 | - * ) |
|
| 1559 | - * ); |
|
| 1560 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1561 | - * |
|
| 1562 | - * @param array $help_array |
|
| 1563 | - * @param bool $display |
|
| 1564 | - * @return string content |
|
| 1565 | - * @throws DomainException |
|
| 1566 | - * @throws EE_Error |
|
| 1567 | - */ |
|
| 1568 | - protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1569 | - { |
|
| 1570 | - $content = ''; |
|
| 1571 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1572 | - // loop through the array and setup content |
|
| 1573 | - foreach ($help_array as $trigger => $help) { |
|
| 1574 | - // make sure the array is setup properly |
|
| 1575 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1576 | - throw new EE_Error( |
|
| 1577 | - esc_html__( |
|
| 1578 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1579 | - 'event_espresso' |
|
| 1580 | - ) |
|
| 1581 | - ); |
|
| 1582 | - } |
|
| 1583 | - // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1584 | - $template_args = [ |
|
| 1585 | - 'help_popup_id' => $trigger, |
|
| 1586 | - 'help_popup_title' => $help['title'], |
|
| 1587 | - 'help_popup_content' => $help['content'], |
|
| 1588 | - ]; |
|
| 1589 | - $content .= EEH_Template::display_template( |
|
| 1590 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1591 | - $template_args, |
|
| 1592 | - true |
|
| 1593 | - ); |
|
| 1594 | - } |
|
| 1595 | - if ($display) { |
|
| 1596 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1597 | - return ''; |
|
| 1598 | - } |
|
| 1599 | - return $content; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - |
|
| 1603 | - /** |
|
| 1604 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1605 | - * |
|
| 1606 | - * @return array properly formatted array for help popup content |
|
| 1607 | - * @throws EE_Error |
|
| 1608 | - */ |
|
| 1609 | - private function _get_help_content() |
|
| 1610 | - { |
|
| 1611 | - // what is the method we're looking for? |
|
| 1612 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1613 | - // if method doesn't exist let's get out. |
|
| 1614 | - if (! method_exists($this, $method_name)) { |
|
| 1615 | - return []; |
|
| 1616 | - } |
|
| 1617 | - // k we're good to go let's retrieve the help array |
|
| 1618 | - $help_array = call_user_func([$this, $method_name]); |
|
| 1619 | - // make sure we've got an array! |
|
| 1620 | - if (! is_array($help_array)) { |
|
| 1621 | - throw new EE_Error( |
|
| 1622 | - esc_html__( |
|
| 1623 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1624 | - 'event_espresso' |
|
| 1625 | - ) |
|
| 1626 | - ); |
|
| 1627 | - } |
|
| 1628 | - return $help_array; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - |
|
| 1632 | - /** |
|
| 1633 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1634 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1635 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1636 | - * |
|
| 1637 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1638 | - * @param boolean $display if false then we return the trigger string |
|
| 1639 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1640 | - * @return string |
|
| 1641 | - * @throws DomainException |
|
| 1642 | - * @throws EE_Error |
|
| 1643 | - */ |
|
| 1644 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1645 | - { |
|
| 1646 | - if ($this->request->isAjax()) { |
|
| 1647 | - return ''; |
|
| 1648 | - } |
|
| 1649 | - // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1650 | - $help_array = $this->_get_help_content(); |
|
| 1651 | - $help_content = ''; |
|
| 1652 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1653 | - $help_array[ $trigger_id ] = [ |
|
| 1654 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1655 | - 'content' => esc_html__( |
|
| 1656 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1657 | - 'event_espresso' |
|
| 1658 | - ), |
|
| 1659 | - ]; |
|
| 1660 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1661 | - } |
|
| 1662 | - // let's setup the trigger |
|
| 1663 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1664 | - . esc_attr($dimensions[0]) |
|
| 1665 | - . '&width=' |
|
| 1666 | - . esc_attr($dimensions[1]) |
|
| 1667 | - . '&inlineId=' |
|
| 1668 | - . esc_attr($trigger_id) |
|
| 1669 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1670 | - $content .= $help_content; |
|
| 1671 | - if ($display) { |
|
| 1672 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1673 | - return ''; |
|
| 1674 | - } |
|
| 1675 | - return $content; |
|
| 1676 | - } |
|
| 1677 | - |
|
| 1678 | - |
|
| 1679 | - /** |
|
| 1680 | - * _add_global_screen_options |
|
| 1681 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1682 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1683 | - * |
|
| 1684 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1685 | - * see also WP_Screen object documents... |
|
| 1686 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1687 | - * @abstract |
|
| 1688 | - * @return void |
|
| 1689 | - */ |
|
| 1690 | - private function _add_global_screen_options() |
|
| 1691 | - { |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - |
|
| 1695 | - /** |
|
| 1696 | - * _add_global_feature_pointers |
|
| 1697 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1698 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1699 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1700 | - * |
|
| 1701 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1702 | - * extended) also see: |
|
| 1703 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1704 | - * @abstract |
|
| 1705 | - * @return void |
|
| 1706 | - */ |
|
| 1707 | - private function _add_global_feature_pointers() |
|
| 1708 | - { |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * load_global_scripts_styles |
|
| 1714 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1715 | - * |
|
| 1716 | - * @return void |
|
| 1717 | - */ |
|
| 1718 | - public function load_global_scripts_styles() |
|
| 1719 | - { |
|
| 1720 | - /** STYLES **/ |
|
| 1721 | - // add debugging styles |
|
| 1722 | - if (WP_DEBUG) { |
|
| 1723 | - add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1724 | - } |
|
| 1725 | - // register all styles |
|
| 1726 | - wp_register_style( |
|
| 1727 | - 'espresso-ui-theme', |
|
| 1728 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1729 | - [], |
|
| 1730 | - EVENT_ESPRESSO_VERSION |
|
| 1731 | - ); |
|
| 1732 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1733 | - // helpers styles |
|
| 1734 | - wp_register_style( |
|
| 1735 | - 'ee-text-links', |
|
| 1736 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1737 | - [], |
|
| 1738 | - EVENT_ESPRESSO_VERSION |
|
| 1739 | - ); |
|
| 1740 | - /** SCRIPTS **/ |
|
| 1741 | - // register all scripts |
|
| 1742 | - wp_register_script( |
|
| 1743 | - 'ee-dialog', |
|
| 1744 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1745 | - ['jquery', 'jquery-ui-draggable'], |
|
| 1746 | - EVENT_ESPRESSO_VERSION, |
|
| 1747 | - true |
|
| 1748 | - ); |
|
| 1749 | - wp_register_script( |
|
| 1750 | - 'ee_admin_js', |
|
| 1751 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1752 | - ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
| 1753 | - EVENT_ESPRESSO_VERSION, |
|
| 1754 | - true |
|
| 1755 | - ); |
|
| 1756 | - wp_register_script( |
|
| 1757 | - 'jquery-ui-timepicker-addon', |
|
| 1758 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1759 | - ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
| 1760 | - EVENT_ESPRESSO_VERSION, |
|
| 1761 | - true |
|
| 1762 | - ); |
|
| 1763 | - // script for sorting tables |
|
| 1764 | - wp_register_script( |
|
| 1765 | - 'espresso_ajax_table_sorting', |
|
| 1766 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1767 | - ['ee_admin_js', 'jquery-ui-sortable'], |
|
| 1768 | - EVENT_ESPRESSO_VERSION, |
|
| 1769 | - true |
|
| 1770 | - ); |
|
| 1771 | - // script for parsing uri's |
|
| 1772 | - wp_register_script( |
|
| 1773 | - 'ee-parse-uri', |
|
| 1774 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1775 | - [], |
|
| 1776 | - EVENT_ESPRESSO_VERSION, |
|
| 1777 | - true |
|
| 1778 | - ); |
|
| 1779 | - // and parsing associative serialized form elements |
|
| 1780 | - wp_register_script( |
|
| 1781 | - 'ee-serialize-full-array', |
|
| 1782 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1783 | - ['jquery'], |
|
| 1784 | - EVENT_ESPRESSO_VERSION, |
|
| 1785 | - true |
|
| 1786 | - ); |
|
| 1787 | - // helpers scripts |
|
| 1788 | - wp_register_script( |
|
| 1789 | - 'ee-text-links', |
|
| 1790 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1791 | - ['jquery'], |
|
| 1792 | - EVENT_ESPRESSO_VERSION, |
|
| 1793 | - true |
|
| 1794 | - ); |
|
| 1795 | - wp_register_script( |
|
| 1796 | - 'ee-moment-core', |
|
| 1797 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1798 | - [], |
|
| 1799 | - EVENT_ESPRESSO_VERSION, |
|
| 1800 | - true |
|
| 1801 | - ); |
|
| 1802 | - wp_register_script( |
|
| 1803 | - 'ee-moment', |
|
| 1804 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1805 | - ['ee-moment-core'], |
|
| 1806 | - EVENT_ESPRESSO_VERSION, |
|
| 1807 | - true |
|
| 1808 | - ); |
|
| 1809 | - wp_register_script( |
|
| 1810 | - 'ee-datepicker', |
|
| 1811 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1812 | - ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
| 1813 | - EVENT_ESPRESSO_VERSION, |
|
| 1814 | - true |
|
| 1815 | - ); |
|
| 1816 | - // google charts |
|
| 1817 | - wp_register_script( |
|
| 1818 | - 'google-charts', |
|
| 1819 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1820 | - [], |
|
| 1821 | - EVENT_ESPRESSO_VERSION |
|
| 1822 | - ); |
|
| 1823 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1824 | - wp_enqueue_style('ee-admin-css'); |
|
| 1825 | - wp_enqueue_script('ee_admin_js'); |
|
| 1826 | - wp_enqueue_script('ee-accounting'); |
|
| 1827 | - wp_enqueue_script('jquery-validate'); |
|
| 1828 | - // taking care of metaboxes |
|
| 1829 | - if ( |
|
| 1830 | - empty($this->_cpt_route) |
|
| 1831 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1832 | - ) { |
|
| 1833 | - wp_enqueue_script('dashboard'); |
|
| 1834 | - } |
|
| 1835 | - // LOCALIZED DATA |
|
| 1836 | - // localize script for ajax lazy loading |
|
| 1837 | - $lazy_loader_container_ids = apply_filters( |
|
| 1838 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1839 | - ['espresso_news_post_box_content'] |
|
| 1840 | - ); |
|
| 1841 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1842 | - add_filter( |
|
| 1843 | - 'admin_body_class', |
|
| 1844 | - function ($classes) { |
|
| 1845 | - if (strpos($classes, 'espresso-admin') === false) { |
|
| 1846 | - $classes .= ' espresso-admin'; |
|
| 1847 | - } |
|
| 1848 | - return $classes; |
|
| 1849 | - } |
|
| 1850 | - ); |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - |
|
| 1854 | - /** |
|
| 1855 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1856 | - * |
|
| 1857 | - * @return void |
|
| 1858 | - */ |
|
| 1859 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1860 | - { |
|
| 1861 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1862 | - EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1863 | - __( |
|
| 1864 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 1865 | - 'event_espresso' |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1869 | - EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1870 | - EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1871 | - EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1872 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1873 | - EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1874 | - EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1875 | - EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1876 | - EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1877 | - EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1878 | - EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1879 | - EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1880 | - EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1881 | - EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1882 | - EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1883 | - EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1884 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1885 | - EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1886 | - EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1887 | - EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1888 | - EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1889 | - EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1890 | - EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1891 | - EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1892 | - EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1893 | - EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1894 | - EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1895 | - EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1896 | - EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1897 | - EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1898 | - EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1899 | - EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1900 | - EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1901 | - EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1902 | - EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1903 | - EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1904 | - EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1905 | - EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1906 | - } |
|
| 1907 | - |
|
| 1908 | - |
|
| 1909 | - /** |
|
| 1910 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1911 | - * |
|
| 1912 | - * @return void |
|
| 1913 | - */ |
|
| 1914 | - public function add_xdebug_style() |
|
| 1915 | - { |
|
| 1916 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1917 | - } |
|
| 1918 | - |
|
| 1919 | - |
|
| 1920 | - /************************/ |
|
| 1921 | - /** LIST TABLE METHODS **/ |
|
| 1922 | - /************************/ |
|
| 1923 | - /** |
|
| 1924 | - * this sets up the list table if the current view requires it. |
|
| 1925 | - * |
|
| 1926 | - * @return void |
|
| 1927 | - * @throws EE_Error |
|
| 1928 | - */ |
|
| 1929 | - protected function _set_list_table() |
|
| 1930 | - { |
|
| 1931 | - // first is this a list_table view? |
|
| 1932 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1933 | - return; |
|
| 1934 | - } //not a list_table view so get out. |
|
| 1935 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 1936 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1937 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1938 | - // user error msg |
|
| 1939 | - $error_msg = esc_html__( |
|
| 1940 | - 'An error occurred. The requested list table views could not be found.', |
|
| 1941 | - 'event_espresso' |
|
| 1942 | - ); |
|
| 1943 | - // developer error msg |
|
| 1944 | - $error_msg .= '||' |
|
| 1945 | - . sprintf( |
|
| 1946 | - esc_html__( |
|
| 1947 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 1948 | - 'event_espresso' |
|
| 1949 | - ), |
|
| 1950 | - $this->_req_action, |
|
| 1951 | - $list_table_view |
|
| 1952 | - ); |
|
| 1953 | - throw new EE_Error($error_msg); |
|
| 1954 | - } |
|
| 1955 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1956 | - $this->_views = apply_filters( |
|
| 1957 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 1958 | - $this->_views |
|
| 1959 | - ); |
|
| 1960 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1961 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1962 | - $this->_set_list_table_view(); |
|
| 1963 | - $this->_set_list_table_object(); |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - |
|
| 1967 | - /** |
|
| 1968 | - * set current view for List Table |
|
| 1969 | - * |
|
| 1970 | - * @return void |
|
| 1971 | - */ |
|
| 1972 | - protected function _set_list_table_view() |
|
| 1973 | - { |
|
| 1974 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1975 | - $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 1976 | - $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 1977 | - ? $status |
|
| 1978 | - : $this->_view; |
|
| 1979 | - } |
|
| 1980 | - |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * _set_list_table_object |
|
| 1984 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1985 | - * |
|
| 1986 | - * @throws InvalidInterfaceException |
|
| 1987 | - * @throws InvalidArgumentException |
|
| 1988 | - * @throws InvalidDataTypeException |
|
| 1989 | - * @throws EE_Error |
|
| 1990 | - * @throws InvalidInterfaceException |
|
| 1991 | - */ |
|
| 1992 | - protected function _set_list_table_object() |
|
| 1993 | - { |
|
| 1994 | - if (isset($this->_route_config['list_table'])) { |
|
| 1995 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 1996 | - throw new EE_Error( |
|
| 1997 | - sprintf( |
|
| 1998 | - esc_html__( |
|
| 1999 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2000 | - 'event_espresso' |
|
| 2001 | - ), |
|
| 2002 | - $this->_route_config['list_table'], |
|
| 2003 | - get_class($this) |
|
| 2004 | - ) |
|
| 2005 | - ); |
|
| 2006 | - } |
|
| 2007 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2008 | - $this->_route_config['list_table'], |
|
| 2009 | - [$this] |
|
| 2010 | - ); |
|
| 2011 | - } |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2017 | - * |
|
| 2018 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2019 | - * urls. The array should be indexed by the view it is being |
|
| 2020 | - * added to. |
|
| 2021 | - * @return array |
|
| 2022 | - */ |
|
| 2023 | - public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2024 | - { |
|
| 2025 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2026 | - if (empty($this->_views)) { |
|
| 2027 | - $this->_views = []; |
|
| 2028 | - } |
|
| 2029 | - // cycle thru views |
|
| 2030 | - foreach ($this->_views as $key => $view) { |
|
| 2031 | - $query_args = []; |
|
| 2032 | - // check for current view |
|
| 2033 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2034 | - $query_args['action'] = $this->_req_action; |
|
| 2035 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2036 | - $query_args['status'] = $view['slug']; |
|
| 2037 | - // merge any other arguments sent in. |
|
| 2038 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2039 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2040 | - } |
|
| 2041 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2042 | - } |
|
| 2043 | - return $this->_views; |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - |
|
| 2047 | - /** |
|
| 2048 | - * _entries_per_page_dropdown |
|
| 2049 | - * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2050 | - * |
|
| 2051 | - * @param int $max_entries total number of rows in the table |
|
| 2052 | - * @return string |
|
| 2053 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2054 | - * WP does it. |
|
| 2055 | - */ |
|
| 2056 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2057 | - { |
|
| 2058 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2059 | - $values = [10, 25, 50, 100]; |
|
| 2060 | - $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2061 | - if ($max_entries) { |
|
| 2062 | - $values[] = $max_entries; |
|
| 2063 | - sort($values); |
|
| 2064 | - } |
|
| 2065 | - $entries_per_page_dropdown = ' |
|
| 1540 | + // current set timezone for timezone js |
|
| 1541 | + echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + |
|
| 1545 | + /** |
|
| 1546 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1547 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1548 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1549 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1550 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1551 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1552 | + * for the |
|
| 1553 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1554 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1555 | + * 'help_trigger_id' => array( |
|
| 1556 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1557 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1558 | + * ) |
|
| 1559 | + * ); |
|
| 1560 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1561 | + * |
|
| 1562 | + * @param array $help_array |
|
| 1563 | + * @param bool $display |
|
| 1564 | + * @return string content |
|
| 1565 | + * @throws DomainException |
|
| 1566 | + * @throws EE_Error |
|
| 1567 | + */ |
|
| 1568 | + protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1569 | + { |
|
| 1570 | + $content = ''; |
|
| 1571 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1572 | + // loop through the array and setup content |
|
| 1573 | + foreach ($help_array as $trigger => $help) { |
|
| 1574 | + // make sure the array is setup properly |
|
| 1575 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1576 | + throw new EE_Error( |
|
| 1577 | + esc_html__( |
|
| 1578 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1579 | + 'event_espresso' |
|
| 1580 | + ) |
|
| 1581 | + ); |
|
| 1582 | + } |
|
| 1583 | + // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1584 | + $template_args = [ |
|
| 1585 | + 'help_popup_id' => $trigger, |
|
| 1586 | + 'help_popup_title' => $help['title'], |
|
| 1587 | + 'help_popup_content' => $help['content'], |
|
| 1588 | + ]; |
|
| 1589 | + $content .= EEH_Template::display_template( |
|
| 1590 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1591 | + $template_args, |
|
| 1592 | + true |
|
| 1593 | + ); |
|
| 1594 | + } |
|
| 1595 | + if ($display) { |
|
| 1596 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1597 | + return ''; |
|
| 1598 | + } |
|
| 1599 | + return $content; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + |
|
| 1603 | + /** |
|
| 1604 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1605 | + * |
|
| 1606 | + * @return array properly formatted array for help popup content |
|
| 1607 | + * @throws EE_Error |
|
| 1608 | + */ |
|
| 1609 | + private function _get_help_content() |
|
| 1610 | + { |
|
| 1611 | + // what is the method we're looking for? |
|
| 1612 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1613 | + // if method doesn't exist let's get out. |
|
| 1614 | + if (! method_exists($this, $method_name)) { |
|
| 1615 | + return []; |
|
| 1616 | + } |
|
| 1617 | + // k we're good to go let's retrieve the help array |
|
| 1618 | + $help_array = call_user_func([$this, $method_name]); |
|
| 1619 | + // make sure we've got an array! |
|
| 1620 | + if (! is_array($help_array)) { |
|
| 1621 | + throw new EE_Error( |
|
| 1622 | + esc_html__( |
|
| 1623 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1624 | + 'event_espresso' |
|
| 1625 | + ) |
|
| 1626 | + ); |
|
| 1627 | + } |
|
| 1628 | + return $help_array; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + |
|
| 1632 | + /** |
|
| 1633 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1634 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1635 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1636 | + * |
|
| 1637 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1638 | + * @param boolean $display if false then we return the trigger string |
|
| 1639 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1640 | + * @return string |
|
| 1641 | + * @throws DomainException |
|
| 1642 | + * @throws EE_Error |
|
| 1643 | + */ |
|
| 1644 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1645 | + { |
|
| 1646 | + if ($this->request->isAjax()) { |
|
| 1647 | + return ''; |
|
| 1648 | + } |
|
| 1649 | + // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1650 | + $help_array = $this->_get_help_content(); |
|
| 1651 | + $help_content = ''; |
|
| 1652 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1653 | + $help_array[ $trigger_id ] = [ |
|
| 1654 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1655 | + 'content' => esc_html__( |
|
| 1656 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1657 | + 'event_espresso' |
|
| 1658 | + ), |
|
| 1659 | + ]; |
|
| 1660 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1661 | + } |
|
| 1662 | + // let's setup the trigger |
|
| 1663 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1664 | + . esc_attr($dimensions[0]) |
|
| 1665 | + . '&width=' |
|
| 1666 | + . esc_attr($dimensions[1]) |
|
| 1667 | + . '&inlineId=' |
|
| 1668 | + . esc_attr($trigger_id) |
|
| 1669 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1670 | + $content .= $help_content; |
|
| 1671 | + if ($display) { |
|
| 1672 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1673 | + return ''; |
|
| 1674 | + } |
|
| 1675 | + return $content; |
|
| 1676 | + } |
|
| 1677 | + |
|
| 1678 | + |
|
| 1679 | + /** |
|
| 1680 | + * _add_global_screen_options |
|
| 1681 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1682 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1683 | + * |
|
| 1684 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1685 | + * see also WP_Screen object documents... |
|
| 1686 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1687 | + * @abstract |
|
| 1688 | + * @return void |
|
| 1689 | + */ |
|
| 1690 | + private function _add_global_screen_options() |
|
| 1691 | + { |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + |
|
| 1695 | + /** |
|
| 1696 | + * _add_global_feature_pointers |
|
| 1697 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1698 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1699 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1700 | + * |
|
| 1701 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1702 | + * extended) also see: |
|
| 1703 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1704 | + * @abstract |
|
| 1705 | + * @return void |
|
| 1706 | + */ |
|
| 1707 | + private function _add_global_feature_pointers() |
|
| 1708 | + { |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * load_global_scripts_styles |
|
| 1714 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1715 | + * |
|
| 1716 | + * @return void |
|
| 1717 | + */ |
|
| 1718 | + public function load_global_scripts_styles() |
|
| 1719 | + { |
|
| 1720 | + /** STYLES **/ |
|
| 1721 | + // add debugging styles |
|
| 1722 | + if (WP_DEBUG) { |
|
| 1723 | + add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1724 | + } |
|
| 1725 | + // register all styles |
|
| 1726 | + wp_register_style( |
|
| 1727 | + 'espresso-ui-theme', |
|
| 1728 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1729 | + [], |
|
| 1730 | + EVENT_ESPRESSO_VERSION |
|
| 1731 | + ); |
|
| 1732 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1733 | + // helpers styles |
|
| 1734 | + wp_register_style( |
|
| 1735 | + 'ee-text-links', |
|
| 1736 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1737 | + [], |
|
| 1738 | + EVENT_ESPRESSO_VERSION |
|
| 1739 | + ); |
|
| 1740 | + /** SCRIPTS **/ |
|
| 1741 | + // register all scripts |
|
| 1742 | + wp_register_script( |
|
| 1743 | + 'ee-dialog', |
|
| 1744 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1745 | + ['jquery', 'jquery-ui-draggable'], |
|
| 1746 | + EVENT_ESPRESSO_VERSION, |
|
| 1747 | + true |
|
| 1748 | + ); |
|
| 1749 | + wp_register_script( |
|
| 1750 | + 'ee_admin_js', |
|
| 1751 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1752 | + ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
| 1753 | + EVENT_ESPRESSO_VERSION, |
|
| 1754 | + true |
|
| 1755 | + ); |
|
| 1756 | + wp_register_script( |
|
| 1757 | + 'jquery-ui-timepicker-addon', |
|
| 1758 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1759 | + ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
| 1760 | + EVENT_ESPRESSO_VERSION, |
|
| 1761 | + true |
|
| 1762 | + ); |
|
| 1763 | + // script for sorting tables |
|
| 1764 | + wp_register_script( |
|
| 1765 | + 'espresso_ajax_table_sorting', |
|
| 1766 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1767 | + ['ee_admin_js', 'jquery-ui-sortable'], |
|
| 1768 | + EVENT_ESPRESSO_VERSION, |
|
| 1769 | + true |
|
| 1770 | + ); |
|
| 1771 | + // script for parsing uri's |
|
| 1772 | + wp_register_script( |
|
| 1773 | + 'ee-parse-uri', |
|
| 1774 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1775 | + [], |
|
| 1776 | + EVENT_ESPRESSO_VERSION, |
|
| 1777 | + true |
|
| 1778 | + ); |
|
| 1779 | + // and parsing associative serialized form elements |
|
| 1780 | + wp_register_script( |
|
| 1781 | + 'ee-serialize-full-array', |
|
| 1782 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1783 | + ['jquery'], |
|
| 1784 | + EVENT_ESPRESSO_VERSION, |
|
| 1785 | + true |
|
| 1786 | + ); |
|
| 1787 | + // helpers scripts |
|
| 1788 | + wp_register_script( |
|
| 1789 | + 'ee-text-links', |
|
| 1790 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1791 | + ['jquery'], |
|
| 1792 | + EVENT_ESPRESSO_VERSION, |
|
| 1793 | + true |
|
| 1794 | + ); |
|
| 1795 | + wp_register_script( |
|
| 1796 | + 'ee-moment-core', |
|
| 1797 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1798 | + [], |
|
| 1799 | + EVENT_ESPRESSO_VERSION, |
|
| 1800 | + true |
|
| 1801 | + ); |
|
| 1802 | + wp_register_script( |
|
| 1803 | + 'ee-moment', |
|
| 1804 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1805 | + ['ee-moment-core'], |
|
| 1806 | + EVENT_ESPRESSO_VERSION, |
|
| 1807 | + true |
|
| 1808 | + ); |
|
| 1809 | + wp_register_script( |
|
| 1810 | + 'ee-datepicker', |
|
| 1811 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1812 | + ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
| 1813 | + EVENT_ESPRESSO_VERSION, |
|
| 1814 | + true |
|
| 1815 | + ); |
|
| 1816 | + // google charts |
|
| 1817 | + wp_register_script( |
|
| 1818 | + 'google-charts', |
|
| 1819 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1820 | + [], |
|
| 1821 | + EVENT_ESPRESSO_VERSION |
|
| 1822 | + ); |
|
| 1823 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1824 | + wp_enqueue_style('ee-admin-css'); |
|
| 1825 | + wp_enqueue_script('ee_admin_js'); |
|
| 1826 | + wp_enqueue_script('ee-accounting'); |
|
| 1827 | + wp_enqueue_script('jquery-validate'); |
|
| 1828 | + // taking care of metaboxes |
|
| 1829 | + if ( |
|
| 1830 | + empty($this->_cpt_route) |
|
| 1831 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1832 | + ) { |
|
| 1833 | + wp_enqueue_script('dashboard'); |
|
| 1834 | + } |
|
| 1835 | + // LOCALIZED DATA |
|
| 1836 | + // localize script for ajax lazy loading |
|
| 1837 | + $lazy_loader_container_ids = apply_filters( |
|
| 1838 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1839 | + ['espresso_news_post_box_content'] |
|
| 1840 | + ); |
|
| 1841 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1842 | + add_filter( |
|
| 1843 | + 'admin_body_class', |
|
| 1844 | + function ($classes) { |
|
| 1845 | + if (strpos($classes, 'espresso-admin') === false) { |
|
| 1846 | + $classes .= ' espresso-admin'; |
|
| 1847 | + } |
|
| 1848 | + return $classes; |
|
| 1849 | + } |
|
| 1850 | + ); |
|
| 1851 | + } |
|
| 1852 | + |
|
| 1853 | + |
|
| 1854 | + /** |
|
| 1855 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1856 | + * |
|
| 1857 | + * @return void |
|
| 1858 | + */ |
|
| 1859 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1860 | + { |
|
| 1861 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1862 | + EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1863 | + __( |
|
| 1864 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 1865 | + 'event_espresso' |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1869 | + EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1870 | + EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1871 | + EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1872 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1873 | + EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1874 | + EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1875 | + EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1876 | + EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1877 | + EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1878 | + EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1879 | + EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1880 | + EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1881 | + EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1882 | + EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1883 | + EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1884 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1885 | + EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1886 | + EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1887 | + EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1888 | + EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1889 | + EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1890 | + EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1891 | + EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1892 | + EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1893 | + EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1894 | + EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1895 | + EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1896 | + EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1897 | + EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1898 | + EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1899 | + EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1900 | + EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1901 | + EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1902 | + EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1903 | + EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1904 | + EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1905 | + EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1906 | + } |
|
| 1907 | + |
|
| 1908 | + |
|
| 1909 | + /** |
|
| 1910 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1911 | + * |
|
| 1912 | + * @return void |
|
| 1913 | + */ |
|
| 1914 | + public function add_xdebug_style() |
|
| 1915 | + { |
|
| 1916 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1917 | + } |
|
| 1918 | + |
|
| 1919 | + |
|
| 1920 | + /************************/ |
|
| 1921 | + /** LIST TABLE METHODS **/ |
|
| 1922 | + /************************/ |
|
| 1923 | + /** |
|
| 1924 | + * this sets up the list table if the current view requires it. |
|
| 1925 | + * |
|
| 1926 | + * @return void |
|
| 1927 | + * @throws EE_Error |
|
| 1928 | + */ |
|
| 1929 | + protected function _set_list_table() |
|
| 1930 | + { |
|
| 1931 | + // first is this a list_table view? |
|
| 1932 | + if (! isset($this->_route_config['list_table'])) { |
|
| 1933 | + return; |
|
| 1934 | + } //not a list_table view so get out. |
|
| 1935 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 1936 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1937 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1938 | + // user error msg |
|
| 1939 | + $error_msg = esc_html__( |
|
| 1940 | + 'An error occurred. The requested list table views could not be found.', |
|
| 1941 | + 'event_espresso' |
|
| 1942 | + ); |
|
| 1943 | + // developer error msg |
|
| 1944 | + $error_msg .= '||' |
|
| 1945 | + . sprintf( |
|
| 1946 | + esc_html__( |
|
| 1947 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 1948 | + 'event_espresso' |
|
| 1949 | + ), |
|
| 1950 | + $this->_req_action, |
|
| 1951 | + $list_table_view |
|
| 1952 | + ); |
|
| 1953 | + throw new EE_Error($error_msg); |
|
| 1954 | + } |
|
| 1955 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1956 | + $this->_views = apply_filters( |
|
| 1957 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 1958 | + $this->_views |
|
| 1959 | + ); |
|
| 1960 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1961 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1962 | + $this->_set_list_table_view(); |
|
| 1963 | + $this->_set_list_table_object(); |
|
| 1964 | + } |
|
| 1965 | + |
|
| 1966 | + |
|
| 1967 | + /** |
|
| 1968 | + * set current view for List Table |
|
| 1969 | + * |
|
| 1970 | + * @return void |
|
| 1971 | + */ |
|
| 1972 | + protected function _set_list_table_view() |
|
| 1973 | + { |
|
| 1974 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1975 | + $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 1976 | + $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 1977 | + ? $status |
|
| 1978 | + : $this->_view; |
|
| 1979 | + } |
|
| 1980 | + |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * _set_list_table_object |
|
| 1984 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1985 | + * |
|
| 1986 | + * @throws InvalidInterfaceException |
|
| 1987 | + * @throws InvalidArgumentException |
|
| 1988 | + * @throws InvalidDataTypeException |
|
| 1989 | + * @throws EE_Error |
|
| 1990 | + * @throws InvalidInterfaceException |
|
| 1991 | + */ |
|
| 1992 | + protected function _set_list_table_object() |
|
| 1993 | + { |
|
| 1994 | + if (isset($this->_route_config['list_table'])) { |
|
| 1995 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 1996 | + throw new EE_Error( |
|
| 1997 | + sprintf( |
|
| 1998 | + esc_html__( |
|
| 1999 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2000 | + 'event_espresso' |
|
| 2001 | + ), |
|
| 2002 | + $this->_route_config['list_table'], |
|
| 2003 | + get_class($this) |
|
| 2004 | + ) |
|
| 2005 | + ); |
|
| 2006 | + } |
|
| 2007 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2008 | + $this->_route_config['list_table'], |
|
| 2009 | + [$this] |
|
| 2010 | + ); |
|
| 2011 | + } |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2017 | + * |
|
| 2018 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2019 | + * urls. The array should be indexed by the view it is being |
|
| 2020 | + * added to. |
|
| 2021 | + * @return array |
|
| 2022 | + */ |
|
| 2023 | + public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2024 | + { |
|
| 2025 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2026 | + if (empty($this->_views)) { |
|
| 2027 | + $this->_views = []; |
|
| 2028 | + } |
|
| 2029 | + // cycle thru views |
|
| 2030 | + foreach ($this->_views as $key => $view) { |
|
| 2031 | + $query_args = []; |
|
| 2032 | + // check for current view |
|
| 2033 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2034 | + $query_args['action'] = $this->_req_action; |
|
| 2035 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2036 | + $query_args['status'] = $view['slug']; |
|
| 2037 | + // merge any other arguments sent in. |
|
| 2038 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2039 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2040 | + } |
|
| 2041 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2042 | + } |
|
| 2043 | + return $this->_views; |
|
| 2044 | + } |
|
| 2045 | + |
|
| 2046 | + |
|
| 2047 | + /** |
|
| 2048 | + * _entries_per_page_dropdown |
|
| 2049 | + * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2050 | + * |
|
| 2051 | + * @param int $max_entries total number of rows in the table |
|
| 2052 | + * @return string |
|
| 2053 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2054 | + * WP does it. |
|
| 2055 | + */ |
|
| 2056 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2057 | + { |
|
| 2058 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2059 | + $values = [10, 25, 50, 100]; |
|
| 2060 | + $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2061 | + if ($max_entries) { |
|
| 2062 | + $values[] = $max_entries; |
|
| 2063 | + sort($values); |
|
| 2064 | + } |
|
| 2065 | + $entries_per_page_dropdown = ' |
|
| 2066 | 2066 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2067 | 2067 | <label class="hide-if-no-js"> |
| 2068 | 2068 | Show |
| 2069 | 2069 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2070 | - foreach ($values as $value) { |
|
| 2071 | - if ($value < $max_entries) { |
|
| 2072 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2073 | - $entries_per_page_dropdown .= ' |
|
| 2070 | + foreach ($values as $value) { |
|
| 2071 | + if ($value < $max_entries) { |
|
| 2072 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2073 | + $entries_per_page_dropdown .= ' |
|
| 2074 | 2074 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2075 | - } |
|
| 2076 | - } |
|
| 2077 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2078 | - $entries_per_page_dropdown .= ' |
|
| 2075 | + } |
|
| 2076 | + } |
|
| 2077 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2078 | + $entries_per_page_dropdown .= ' |
|
| 2079 | 2079 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2080 | - $entries_per_page_dropdown .= ' |
|
| 2080 | + $entries_per_page_dropdown .= ' |
|
| 2081 | 2081 | </select> |
| 2082 | 2082 | entries |
| 2083 | 2083 | </label> |
| 2084 | 2084 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2085 | 2085 | </div> |
| 2086 | 2086 | '; |
| 2087 | - return $entries_per_page_dropdown; |
|
| 2088 | - } |
|
| 2089 | - |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * _set_search_attributes |
|
| 2093 | - * |
|
| 2094 | - * @return void |
|
| 2095 | - */ |
|
| 2096 | - public function _set_search_attributes() |
|
| 2097 | - { |
|
| 2098 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2099 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2100 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2101 | - : $this->_search_btn_label |
|
| 2102 | - ); |
|
| 2103 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - |
|
| 2107 | - |
|
| 2108 | - /*** END LIST TABLE METHODS **/ |
|
| 2109 | - |
|
| 2110 | - |
|
| 2111 | - /** |
|
| 2112 | - * _add_registered_metaboxes |
|
| 2113 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2114 | - * |
|
| 2115 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2116 | - * @return void |
|
| 2117 | - * @throws EE_Error |
|
| 2118 | - */ |
|
| 2119 | - private function _add_registered_meta_boxes() |
|
| 2120 | - { |
|
| 2121 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2122 | - // we only add meta boxes if the page_route calls for it |
|
| 2123 | - if ( |
|
| 2124 | - is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2125 | - && is_array( |
|
| 2126 | - $this->_route_config['metaboxes'] |
|
| 2127 | - ) |
|
| 2128 | - ) { |
|
| 2129 | - // this simply loops through the callbacks provided |
|
| 2130 | - // and checks if there is a corresponding callback registered by the child |
|
| 2131 | - // if there is then we go ahead and process the metabox loader. |
|
| 2132 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2133 | - // first check for Closures |
|
| 2134 | - if ($metabox_callback instanceof Closure) { |
|
| 2135 | - $result = $metabox_callback(); |
|
| 2136 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2137 | - $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2138 | - } else { |
|
| 2139 | - $result = call_user_func([$this, &$metabox_callback]); |
|
| 2140 | - } |
|
| 2141 | - if ($result === false) { |
|
| 2142 | - // user error msg |
|
| 2143 | - $error_msg = esc_html__( |
|
| 2144 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2145 | - 'event_espresso' |
|
| 2146 | - ); |
|
| 2147 | - // developer error msg |
|
| 2148 | - $error_msg .= '||' |
|
| 2149 | - . sprintf( |
|
| 2150 | - esc_html__( |
|
| 2151 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2152 | - 'event_espresso' |
|
| 2153 | - ), |
|
| 2154 | - $metabox_callback |
|
| 2155 | - ); |
|
| 2156 | - throw new EE_Error($error_msg); |
|
| 2157 | - } |
|
| 2158 | - } |
|
| 2159 | - } |
|
| 2160 | - } |
|
| 2161 | - |
|
| 2162 | - |
|
| 2163 | - /** |
|
| 2164 | - * _add_screen_columns |
|
| 2165 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2166 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2167 | - * |
|
| 2168 | - * @return void |
|
| 2169 | - */ |
|
| 2170 | - private function _add_screen_columns() |
|
| 2171 | - { |
|
| 2172 | - if ( |
|
| 2173 | - is_array($this->_route_config) |
|
| 2174 | - && isset($this->_route_config['columns']) |
|
| 2175 | - && is_array($this->_route_config['columns']) |
|
| 2176 | - && count($this->_route_config['columns']) === 2 |
|
| 2177 | - ) { |
|
| 2178 | - add_screen_option( |
|
| 2179 | - 'layout_columns', |
|
| 2180 | - [ |
|
| 2181 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2182 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2183 | - ] |
|
| 2184 | - ); |
|
| 2185 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2186 | - $screen_id = $this->_current_screen->id; |
|
| 2187 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2188 | - $total_columns = ! empty($screen_columns) |
|
| 2189 | - ? $screen_columns |
|
| 2190 | - : $this->_route_config['columns'][1]; |
|
| 2191 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2192 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2193 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2194 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2195 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2196 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2197 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2198 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2199 | - } |
|
| 2200 | - } |
|
| 2201 | - |
|
| 2202 | - |
|
| 2203 | - |
|
| 2204 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2205 | - |
|
| 2206 | - |
|
| 2207 | - /** |
|
| 2208 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2209 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2210 | - * these get loaded on. |
|
| 2211 | - */ |
|
| 2212 | - private function _espresso_news_post_box() |
|
| 2213 | - { |
|
| 2214 | - $news_box_title = apply_filters( |
|
| 2215 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2216 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2217 | - ); |
|
| 2218 | - add_meta_box( |
|
| 2219 | - 'espresso_news_post_box', |
|
| 2220 | - $news_box_title, |
|
| 2221 | - [ |
|
| 2222 | - $this, |
|
| 2223 | - 'espresso_news_post_box', |
|
| 2224 | - ], |
|
| 2225 | - $this->_wp_page_slug, |
|
| 2226 | - 'side' |
|
| 2227 | - ); |
|
| 2228 | - } |
|
| 2229 | - |
|
| 2230 | - |
|
| 2231 | - /** |
|
| 2232 | - * Code for setting up espresso ratings request metabox. |
|
| 2233 | - */ |
|
| 2234 | - protected function _espresso_ratings_request() |
|
| 2235 | - { |
|
| 2236 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2237 | - return; |
|
| 2238 | - } |
|
| 2239 | - $ratings_box_title = apply_filters( |
|
| 2240 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2241 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2242 | - ); |
|
| 2243 | - add_meta_box( |
|
| 2244 | - 'espresso_ratings_request', |
|
| 2245 | - $ratings_box_title, |
|
| 2246 | - [ |
|
| 2247 | - $this, |
|
| 2248 | - 'espresso_ratings_request', |
|
| 2249 | - ], |
|
| 2250 | - $this->_wp_page_slug, |
|
| 2251 | - 'side' |
|
| 2252 | - ); |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - |
|
| 2256 | - /** |
|
| 2257 | - * Code for setting up espresso ratings request metabox content. |
|
| 2258 | - * |
|
| 2259 | - * @throws DomainException |
|
| 2260 | - */ |
|
| 2261 | - public function espresso_ratings_request() |
|
| 2262 | - { |
|
| 2263 | - EEH_Template::display_template( |
|
| 2264 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2265 | - [] |
|
| 2266 | - ); |
|
| 2267 | - } |
|
| 2268 | - |
|
| 2269 | - |
|
| 2270 | - public static function cached_rss_display($rss_id, $url) |
|
| 2271 | - { |
|
| 2272 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2273 | - . esc_html__('Loading…', 'event_espresso') |
|
| 2274 | - . '</p><p class="hide-if-js">' |
|
| 2275 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2276 | - . '</p>'; |
|
| 2277 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2278 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2279 | - $post = '</div>' . "\n"; |
|
| 2280 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2281 | - $output = get_transient($cache_key); |
|
| 2282 | - if ($output !== false) { |
|
| 2283 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2284 | - return true; |
|
| 2285 | - } |
|
| 2286 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2288 | - return false; |
|
| 2289 | - } |
|
| 2290 | - ob_start(); |
|
| 2291 | - wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2292 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2293 | - return true; |
|
| 2294 | - } |
|
| 2295 | - |
|
| 2296 | - |
|
| 2297 | - public function espresso_news_post_box() |
|
| 2298 | - { |
|
| 2299 | - ?> |
|
| 2087 | + return $entries_per_page_dropdown; |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * _set_search_attributes |
|
| 2093 | + * |
|
| 2094 | + * @return void |
|
| 2095 | + */ |
|
| 2096 | + public function _set_search_attributes() |
|
| 2097 | + { |
|
| 2098 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2099 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2100 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2101 | + : $this->_search_btn_label |
|
| 2102 | + ); |
|
| 2103 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + |
|
| 2107 | + |
|
| 2108 | + /*** END LIST TABLE METHODS **/ |
|
| 2109 | + |
|
| 2110 | + |
|
| 2111 | + /** |
|
| 2112 | + * _add_registered_metaboxes |
|
| 2113 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2114 | + * |
|
| 2115 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2116 | + * @return void |
|
| 2117 | + * @throws EE_Error |
|
| 2118 | + */ |
|
| 2119 | + private function _add_registered_meta_boxes() |
|
| 2120 | + { |
|
| 2121 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2122 | + // we only add meta boxes if the page_route calls for it |
|
| 2123 | + if ( |
|
| 2124 | + is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2125 | + && is_array( |
|
| 2126 | + $this->_route_config['metaboxes'] |
|
| 2127 | + ) |
|
| 2128 | + ) { |
|
| 2129 | + // this simply loops through the callbacks provided |
|
| 2130 | + // and checks if there is a corresponding callback registered by the child |
|
| 2131 | + // if there is then we go ahead and process the metabox loader. |
|
| 2132 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2133 | + // first check for Closures |
|
| 2134 | + if ($metabox_callback instanceof Closure) { |
|
| 2135 | + $result = $metabox_callback(); |
|
| 2136 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2137 | + $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2138 | + } else { |
|
| 2139 | + $result = call_user_func([$this, &$metabox_callback]); |
|
| 2140 | + } |
|
| 2141 | + if ($result === false) { |
|
| 2142 | + // user error msg |
|
| 2143 | + $error_msg = esc_html__( |
|
| 2144 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2145 | + 'event_espresso' |
|
| 2146 | + ); |
|
| 2147 | + // developer error msg |
|
| 2148 | + $error_msg .= '||' |
|
| 2149 | + . sprintf( |
|
| 2150 | + esc_html__( |
|
| 2151 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2152 | + 'event_espresso' |
|
| 2153 | + ), |
|
| 2154 | + $metabox_callback |
|
| 2155 | + ); |
|
| 2156 | + throw new EE_Error($error_msg); |
|
| 2157 | + } |
|
| 2158 | + } |
|
| 2159 | + } |
|
| 2160 | + } |
|
| 2161 | + |
|
| 2162 | + |
|
| 2163 | + /** |
|
| 2164 | + * _add_screen_columns |
|
| 2165 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2166 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2167 | + * |
|
| 2168 | + * @return void |
|
| 2169 | + */ |
|
| 2170 | + private function _add_screen_columns() |
|
| 2171 | + { |
|
| 2172 | + if ( |
|
| 2173 | + is_array($this->_route_config) |
|
| 2174 | + && isset($this->_route_config['columns']) |
|
| 2175 | + && is_array($this->_route_config['columns']) |
|
| 2176 | + && count($this->_route_config['columns']) === 2 |
|
| 2177 | + ) { |
|
| 2178 | + add_screen_option( |
|
| 2179 | + 'layout_columns', |
|
| 2180 | + [ |
|
| 2181 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2182 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2183 | + ] |
|
| 2184 | + ); |
|
| 2185 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2186 | + $screen_id = $this->_current_screen->id; |
|
| 2187 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2188 | + $total_columns = ! empty($screen_columns) |
|
| 2189 | + ? $screen_columns |
|
| 2190 | + : $this->_route_config['columns'][1]; |
|
| 2191 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2192 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2193 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2194 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2195 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2196 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2197 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2198 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2199 | + } |
|
| 2200 | + } |
|
| 2201 | + |
|
| 2202 | + |
|
| 2203 | + |
|
| 2204 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2205 | + |
|
| 2206 | + |
|
| 2207 | + /** |
|
| 2208 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2209 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2210 | + * these get loaded on. |
|
| 2211 | + */ |
|
| 2212 | + private function _espresso_news_post_box() |
|
| 2213 | + { |
|
| 2214 | + $news_box_title = apply_filters( |
|
| 2215 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2216 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2217 | + ); |
|
| 2218 | + add_meta_box( |
|
| 2219 | + 'espresso_news_post_box', |
|
| 2220 | + $news_box_title, |
|
| 2221 | + [ |
|
| 2222 | + $this, |
|
| 2223 | + 'espresso_news_post_box', |
|
| 2224 | + ], |
|
| 2225 | + $this->_wp_page_slug, |
|
| 2226 | + 'side' |
|
| 2227 | + ); |
|
| 2228 | + } |
|
| 2229 | + |
|
| 2230 | + |
|
| 2231 | + /** |
|
| 2232 | + * Code for setting up espresso ratings request metabox. |
|
| 2233 | + */ |
|
| 2234 | + protected function _espresso_ratings_request() |
|
| 2235 | + { |
|
| 2236 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2237 | + return; |
|
| 2238 | + } |
|
| 2239 | + $ratings_box_title = apply_filters( |
|
| 2240 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2241 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2242 | + ); |
|
| 2243 | + add_meta_box( |
|
| 2244 | + 'espresso_ratings_request', |
|
| 2245 | + $ratings_box_title, |
|
| 2246 | + [ |
|
| 2247 | + $this, |
|
| 2248 | + 'espresso_ratings_request', |
|
| 2249 | + ], |
|
| 2250 | + $this->_wp_page_slug, |
|
| 2251 | + 'side' |
|
| 2252 | + ); |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + |
|
| 2256 | + /** |
|
| 2257 | + * Code for setting up espresso ratings request metabox content. |
|
| 2258 | + * |
|
| 2259 | + * @throws DomainException |
|
| 2260 | + */ |
|
| 2261 | + public function espresso_ratings_request() |
|
| 2262 | + { |
|
| 2263 | + EEH_Template::display_template( |
|
| 2264 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2265 | + [] |
|
| 2266 | + ); |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + |
|
| 2270 | + public static function cached_rss_display($rss_id, $url) |
|
| 2271 | + { |
|
| 2272 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2273 | + . esc_html__('Loading…', 'event_espresso') |
|
| 2274 | + . '</p><p class="hide-if-js">' |
|
| 2275 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2276 | + . '</p>'; |
|
| 2277 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2278 | + $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2279 | + $post = '</div>' . "\n"; |
|
| 2280 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2281 | + $output = get_transient($cache_key); |
|
| 2282 | + if ($output !== false) { |
|
| 2283 | + echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2284 | + return true; |
|
| 2285 | + } |
|
| 2286 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | + echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2288 | + return false; |
|
| 2289 | + } |
|
| 2290 | + ob_start(); |
|
| 2291 | + wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2292 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2293 | + return true; |
|
| 2294 | + } |
|
| 2295 | + |
|
| 2296 | + |
|
| 2297 | + public function espresso_news_post_box() |
|
| 2298 | + { |
|
| 2299 | + ?> |
|
| 2300 | 2300 | <div class="padding"> |
| 2301 | 2301 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2302 | 2302 | <?php |
| 2303 | - // Get RSS Feed(s) |
|
| 2304 | - self::cached_rss_display( |
|
| 2305 | - 'espresso_news_post_box_content', |
|
| 2306 | - esc_url_raw( |
|
| 2307 | - apply_filters( |
|
| 2308 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2309 | - 'https://eventespresso.com/feed/' |
|
| 2310 | - ) |
|
| 2311 | - ) |
|
| 2312 | - ); |
|
| 2313 | - ?> |
|
| 2303 | + // Get RSS Feed(s) |
|
| 2304 | + self::cached_rss_display( |
|
| 2305 | + 'espresso_news_post_box_content', |
|
| 2306 | + esc_url_raw( |
|
| 2307 | + apply_filters( |
|
| 2308 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2309 | + 'https://eventespresso.com/feed/' |
|
| 2310 | + ) |
|
| 2311 | + ) |
|
| 2312 | + ); |
|
| 2313 | + ?> |
|
| 2314 | 2314 | </div> |
| 2315 | 2315 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2316 | 2316 | </div> |
| 2317 | 2317 | <?php |
| 2318 | - } |
|
| 2319 | - |
|
| 2320 | - |
|
| 2321 | - private function _espresso_links_post_box() |
|
| 2322 | - { |
|
| 2323 | - // Hiding until we actually have content to put in here... |
|
| 2324 | - // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2325 | - } |
|
| 2326 | - |
|
| 2327 | - |
|
| 2328 | - public function espresso_links_post_box() |
|
| 2329 | - { |
|
| 2330 | - // Hiding until we actually have content to put in here... |
|
| 2331 | - // EEH_Template::display_template( |
|
| 2332 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2333 | - // ); |
|
| 2334 | - } |
|
| 2335 | - |
|
| 2336 | - |
|
| 2337 | - protected function _espresso_sponsors_post_box() |
|
| 2338 | - { |
|
| 2339 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2340 | - add_meta_box( |
|
| 2341 | - 'espresso_sponsors_post_box', |
|
| 2342 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2343 | - [$this, 'espresso_sponsors_post_box'], |
|
| 2344 | - $this->_wp_page_slug, |
|
| 2345 | - 'side' |
|
| 2346 | - ); |
|
| 2347 | - } |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - |
|
| 2351 | - public function espresso_sponsors_post_box() |
|
| 2352 | - { |
|
| 2353 | - EEH_Template::display_template( |
|
| 2354 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2355 | - ); |
|
| 2356 | - } |
|
| 2357 | - |
|
| 2358 | - |
|
| 2359 | - private function _publish_post_box() |
|
| 2360 | - { |
|
| 2361 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2362 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2363 | - // then we'll use that for the metabox label. |
|
| 2364 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2365 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2366 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2367 | - : $this->_labels['publishbox']; |
|
| 2368 | - } else { |
|
| 2369 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2370 | - } |
|
| 2371 | - $box_label = apply_filters( |
|
| 2372 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2373 | - $box_label, |
|
| 2374 | - $this->_req_action, |
|
| 2375 | - $this |
|
| 2376 | - ); |
|
| 2377 | - add_meta_box( |
|
| 2378 | - $meta_box_ref, |
|
| 2379 | - $box_label, |
|
| 2380 | - [$this, 'editor_overview'], |
|
| 2381 | - $this->_current_screen->id, |
|
| 2382 | - 'side', |
|
| 2383 | - 'high' |
|
| 2384 | - ); |
|
| 2385 | - } |
|
| 2386 | - |
|
| 2387 | - |
|
| 2388 | - public function editor_overview() |
|
| 2389 | - { |
|
| 2390 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2391 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2392 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2393 | - : ''; |
|
| 2394 | - echo EEH_Template::display_template( |
|
| 2395 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2396 | - $this->_template_args, |
|
| 2397 | - true |
|
| 2398 | - ); |
|
| 2399 | - } |
|
| 2400 | - |
|
| 2401 | - |
|
| 2402 | - /** end of globally available metaboxes section **/ |
|
| 2403 | - |
|
| 2404 | - |
|
| 2405 | - /** |
|
| 2406 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2407 | - * protected method. |
|
| 2408 | - * |
|
| 2409 | - * @param string $name |
|
| 2410 | - * @param int $id |
|
| 2411 | - * @param bool $delete |
|
| 2412 | - * @param string $save_close_redirect_URL |
|
| 2413 | - * @param bool $both_btns |
|
| 2414 | - * @throws EE_Error |
|
| 2415 | - * @throws InvalidArgumentException |
|
| 2416 | - * @throws InvalidDataTypeException |
|
| 2417 | - * @throws InvalidInterfaceException |
|
| 2418 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2419 | - * @since 4.6.0 |
|
| 2420 | - */ |
|
| 2421 | - public function set_publish_post_box_vars( |
|
| 2422 | - $name = '', |
|
| 2423 | - $id = 0, |
|
| 2424 | - $delete = false, |
|
| 2425 | - $save_close_redirect_URL = '', |
|
| 2426 | - $both_btns = true |
|
| 2427 | - ) { |
|
| 2428 | - $this->_set_publish_post_box_vars( |
|
| 2429 | - $name, |
|
| 2430 | - $id, |
|
| 2431 | - $delete, |
|
| 2432 | - $save_close_redirect_URL, |
|
| 2433 | - $both_btns |
|
| 2434 | - ); |
|
| 2435 | - } |
|
| 2436 | - |
|
| 2437 | - |
|
| 2438 | - /** |
|
| 2439 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2440 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2441 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2442 | - * values for the name and id arguments. |
|
| 2443 | - * |
|
| 2444 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2445 | - * @param int $id id attached to the item published |
|
| 2446 | - * @param string $delete page route callback for the delete action |
|
| 2447 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2448 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2449 | - * the Save button |
|
| 2450 | - * @throws EE_Error |
|
| 2451 | - * @throws InvalidArgumentException |
|
| 2452 | - * @throws InvalidDataTypeException |
|
| 2453 | - * @throws InvalidInterfaceException |
|
| 2454 | - * @todo Add in validation for name/id arguments. |
|
| 2455 | - */ |
|
| 2456 | - protected function _set_publish_post_box_vars( |
|
| 2457 | - $name = '', |
|
| 2458 | - $id = 0, |
|
| 2459 | - $delete = '', |
|
| 2460 | - $save_close_redirect_URL = '', |
|
| 2461 | - $both_btns = true |
|
| 2462 | - ) { |
|
| 2463 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2464 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2465 | - ? $save_close_redirect_URL |
|
| 2466 | - : $this->_admin_base_url; |
|
| 2467 | - // create the Save & Close and Save buttons |
|
| 2468 | - $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2469 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2470 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2471 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2472 | - : ''; |
|
| 2473 | - if ($delete && ! empty($id)) { |
|
| 2474 | - // make sure we have a default if just true is sent. |
|
| 2475 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2476 | - $delete_link_args = [$name => $id]; |
|
| 2477 | - $delete = $this->get_action_link_or_button( |
|
| 2478 | - $delete, |
|
| 2479 | - $delete, |
|
| 2480 | - $delete_link_args, |
|
| 2481 | - 'submitdelete deletion', |
|
| 2482 | - '', |
|
| 2483 | - false |
|
| 2484 | - ); |
|
| 2485 | - } |
|
| 2486 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2487 | - if (! empty($name) && ! empty($id)) { |
|
| 2488 | - $hidden_field_arr[ $name ] = [ |
|
| 2489 | - 'type' => 'hidden', |
|
| 2490 | - 'value' => $id, |
|
| 2491 | - ]; |
|
| 2492 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2493 | - } else { |
|
| 2494 | - $hf = ''; |
|
| 2495 | - } |
|
| 2496 | - // add hidden field |
|
| 2497 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2498 | - ? $hf[ $name ]['field'] |
|
| 2499 | - : $hf; |
|
| 2500 | - } |
|
| 2501 | - |
|
| 2502 | - |
|
| 2503 | - /** |
|
| 2504 | - * displays an error message to ppl who have javascript disabled |
|
| 2505 | - * |
|
| 2506 | - * @return void |
|
| 2507 | - */ |
|
| 2508 | - private function _display_no_javascript_warning() |
|
| 2509 | - { |
|
| 2510 | - ?> |
|
| 2318 | + } |
|
| 2319 | + |
|
| 2320 | + |
|
| 2321 | + private function _espresso_links_post_box() |
|
| 2322 | + { |
|
| 2323 | + // Hiding until we actually have content to put in here... |
|
| 2324 | + // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2325 | + } |
|
| 2326 | + |
|
| 2327 | + |
|
| 2328 | + public function espresso_links_post_box() |
|
| 2329 | + { |
|
| 2330 | + // Hiding until we actually have content to put in here... |
|
| 2331 | + // EEH_Template::display_template( |
|
| 2332 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2333 | + // ); |
|
| 2334 | + } |
|
| 2335 | + |
|
| 2336 | + |
|
| 2337 | + protected function _espresso_sponsors_post_box() |
|
| 2338 | + { |
|
| 2339 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2340 | + add_meta_box( |
|
| 2341 | + 'espresso_sponsors_post_box', |
|
| 2342 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2343 | + [$this, 'espresso_sponsors_post_box'], |
|
| 2344 | + $this->_wp_page_slug, |
|
| 2345 | + 'side' |
|
| 2346 | + ); |
|
| 2347 | + } |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + |
|
| 2351 | + public function espresso_sponsors_post_box() |
|
| 2352 | + { |
|
| 2353 | + EEH_Template::display_template( |
|
| 2354 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2355 | + ); |
|
| 2356 | + } |
|
| 2357 | + |
|
| 2358 | + |
|
| 2359 | + private function _publish_post_box() |
|
| 2360 | + { |
|
| 2361 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2362 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2363 | + // then we'll use that for the metabox label. |
|
| 2364 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2365 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2366 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2367 | + : $this->_labels['publishbox']; |
|
| 2368 | + } else { |
|
| 2369 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2370 | + } |
|
| 2371 | + $box_label = apply_filters( |
|
| 2372 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2373 | + $box_label, |
|
| 2374 | + $this->_req_action, |
|
| 2375 | + $this |
|
| 2376 | + ); |
|
| 2377 | + add_meta_box( |
|
| 2378 | + $meta_box_ref, |
|
| 2379 | + $box_label, |
|
| 2380 | + [$this, 'editor_overview'], |
|
| 2381 | + $this->_current_screen->id, |
|
| 2382 | + 'side', |
|
| 2383 | + 'high' |
|
| 2384 | + ); |
|
| 2385 | + } |
|
| 2386 | + |
|
| 2387 | + |
|
| 2388 | + public function editor_overview() |
|
| 2389 | + { |
|
| 2390 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2391 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2392 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2393 | + : ''; |
|
| 2394 | + echo EEH_Template::display_template( |
|
| 2395 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2396 | + $this->_template_args, |
|
| 2397 | + true |
|
| 2398 | + ); |
|
| 2399 | + } |
|
| 2400 | + |
|
| 2401 | + |
|
| 2402 | + /** end of globally available metaboxes section **/ |
|
| 2403 | + |
|
| 2404 | + |
|
| 2405 | + /** |
|
| 2406 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2407 | + * protected method. |
|
| 2408 | + * |
|
| 2409 | + * @param string $name |
|
| 2410 | + * @param int $id |
|
| 2411 | + * @param bool $delete |
|
| 2412 | + * @param string $save_close_redirect_URL |
|
| 2413 | + * @param bool $both_btns |
|
| 2414 | + * @throws EE_Error |
|
| 2415 | + * @throws InvalidArgumentException |
|
| 2416 | + * @throws InvalidDataTypeException |
|
| 2417 | + * @throws InvalidInterfaceException |
|
| 2418 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2419 | + * @since 4.6.0 |
|
| 2420 | + */ |
|
| 2421 | + public function set_publish_post_box_vars( |
|
| 2422 | + $name = '', |
|
| 2423 | + $id = 0, |
|
| 2424 | + $delete = false, |
|
| 2425 | + $save_close_redirect_URL = '', |
|
| 2426 | + $both_btns = true |
|
| 2427 | + ) { |
|
| 2428 | + $this->_set_publish_post_box_vars( |
|
| 2429 | + $name, |
|
| 2430 | + $id, |
|
| 2431 | + $delete, |
|
| 2432 | + $save_close_redirect_URL, |
|
| 2433 | + $both_btns |
|
| 2434 | + ); |
|
| 2435 | + } |
|
| 2436 | + |
|
| 2437 | + |
|
| 2438 | + /** |
|
| 2439 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2440 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2441 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2442 | + * values for the name and id arguments. |
|
| 2443 | + * |
|
| 2444 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2445 | + * @param int $id id attached to the item published |
|
| 2446 | + * @param string $delete page route callback for the delete action |
|
| 2447 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2448 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2449 | + * the Save button |
|
| 2450 | + * @throws EE_Error |
|
| 2451 | + * @throws InvalidArgumentException |
|
| 2452 | + * @throws InvalidDataTypeException |
|
| 2453 | + * @throws InvalidInterfaceException |
|
| 2454 | + * @todo Add in validation for name/id arguments. |
|
| 2455 | + */ |
|
| 2456 | + protected function _set_publish_post_box_vars( |
|
| 2457 | + $name = '', |
|
| 2458 | + $id = 0, |
|
| 2459 | + $delete = '', |
|
| 2460 | + $save_close_redirect_URL = '', |
|
| 2461 | + $both_btns = true |
|
| 2462 | + ) { |
|
| 2463 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2464 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2465 | + ? $save_close_redirect_URL |
|
| 2466 | + : $this->_admin_base_url; |
|
| 2467 | + // create the Save & Close and Save buttons |
|
| 2468 | + $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2469 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2470 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2471 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2472 | + : ''; |
|
| 2473 | + if ($delete && ! empty($id)) { |
|
| 2474 | + // make sure we have a default if just true is sent. |
|
| 2475 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2476 | + $delete_link_args = [$name => $id]; |
|
| 2477 | + $delete = $this->get_action_link_or_button( |
|
| 2478 | + $delete, |
|
| 2479 | + $delete, |
|
| 2480 | + $delete_link_args, |
|
| 2481 | + 'submitdelete deletion', |
|
| 2482 | + '', |
|
| 2483 | + false |
|
| 2484 | + ); |
|
| 2485 | + } |
|
| 2486 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2487 | + if (! empty($name) && ! empty($id)) { |
|
| 2488 | + $hidden_field_arr[ $name ] = [ |
|
| 2489 | + 'type' => 'hidden', |
|
| 2490 | + 'value' => $id, |
|
| 2491 | + ]; |
|
| 2492 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2493 | + } else { |
|
| 2494 | + $hf = ''; |
|
| 2495 | + } |
|
| 2496 | + // add hidden field |
|
| 2497 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2498 | + ? $hf[ $name ]['field'] |
|
| 2499 | + : $hf; |
|
| 2500 | + } |
|
| 2501 | + |
|
| 2502 | + |
|
| 2503 | + /** |
|
| 2504 | + * displays an error message to ppl who have javascript disabled |
|
| 2505 | + * |
|
| 2506 | + * @return void |
|
| 2507 | + */ |
|
| 2508 | + private function _display_no_javascript_warning() |
|
| 2509 | + { |
|
| 2510 | + ?> |
|
| 2511 | 2511 | <noscript> |
| 2512 | 2512 | <div id="no-js-message" class="error"> |
| 2513 | 2513 | <p style="font-size:1.3em;"> |
| 2514 | 2514 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2515 | 2515 | <?php esc_html_e( |
| 2516 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2517 | - 'event_espresso' |
|
| 2518 | - ); ?> |
|
| 2516 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2517 | + 'event_espresso' |
|
| 2518 | + ); ?> |
|
| 2519 | 2519 | </p> |
| 2520 | 2520 | </div> |
| 2521 | 2521 | </noscript> |
| 2522 | 2522 | <?php |
| 2523 | - } |
|
| 2524 | - |
|
| 2525 | - |
|
| 2526 | - /** |
|
| 2527 | - * displays espresso success and/or error notices |
|
| 2528 | - * |
|
| 2529 | - * @return void |
|
| 2530 | - */ |
|
| 2531 | - protected function _display_espresso_notices() |
|
| 2532 | - { |
|
| 2533 | - $notices = $this->_get_transient(true); |
|
| 2534 | - echo stripslashes($notices); |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - |
|
| 2538 | - /** |
|
| 2539 | - * spinny things pacify the masses |
|
| 2540 | - * |
|
| 2541 | - * @return void |
|
| 2542 | - */ |
|
| 2543 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2544 | - { |
|
| 2545 | - ?> |
|
| 2523 | + } |
|
| 2524 | + |
|
| 2525 | + |
|
| 2526 | + /** |
|
| 2527 | + * displays espresso success and/or error notices |
|
| 2528 | + * |
|
| 2529 | + * @return void |
|
| 2530 | + */ |
|
| 2531 | + protected function _display_espresso_notices() |
|
| 2532 | + { |
|
| 2533 | + $notices = $this->_get_transient(true); |
|
| 2534 | + echo stripslashes($notices); |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * spinny things pacify the masses |
|
| 2540 | + * |
|
| 2541 | + * @return void |
|
| 2542 | + */ |
|
| 2543 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2544 | + { |
|
| 2545 | + ?> |
|
| 2546 | 2546 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2547 | 2547 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2548 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2548 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2549 | 2549 | </div> |
| 2550 | 2550 | <?php |
| 2551 | - } |
|
| 2551 | + } |
|
| 2552 | 2552 | |
| 2553 | 2553 | |
| 2554 | - /** |
|
| 2555 | - * add admin page overlay for modal boxes |
|
| 2556 | - * |
|
| 2557 | - * @return void |
|
| 2558 | - */ |
|
| 2559 | - protected function _add_admin_page_overlay() |
|
| 2560 | - { |
|
| 2561 | - ?> |
|
| 2554 | + /** |
|
| 2555 | + * add admin page overlay for modal boxes |
|
| 2556 | + * |
|
| 2557 | + * @return void |
|
| 2558 | + */ |
|
| 2559 | + protected function _add_admin_page_overlay() |
|
| 2560 | + { |
|
| 2561 | + ?> |
|
| 2562 | 2562 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2563 | 2563 | <?php |
| 2564 | - } |
|
| 2565 | - |
|
| 2566 | - |
|
| 2567 | - /** |
|
| 2568 | - * facade for add_meta_box |
|
| 2569 | - * |
|
| 2570 | - * @param string $action where the metabox gets displayed |
|
| 2571 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2572 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2573 | - * instead of the one created in here. |
|
| 2574 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2575 | - * @param string $column what metabox column |
|
| 2576 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2577 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2578 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2579 | - * @throws DomainException |
|
| 2580 | - */ |
|
| 2581 | - public function _add_admin_page_meta_box( |
|
| 2582 | - $action, |
|
| 2583 | - $title, |
|
| 2584 | - $callback, |
|
| 2585 | - $callback_args, |
|
| 2586 | - $column = 'normal', |
|
| 2587 | - $priority = 'high', |
|
| 2588 | - $create_func = true |
|
| 2589 | - ) { |
|
| 2590 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2591 | - // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2592 | - if (empty($callback_args) && $create_func) { |
|
| 2593 | - $callback_args = [ |
|
| 2594 | - 'template_path' => $this->_template_path, |
|
| 2595 | - 'template_args' => $this->_template_args, |
|
| 2596 | - ]; |
|
| 2597 | - } |
|
| 2598 | - // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2599 | - $call_back_func = $create_func |
|
| 2600 | - ? function ($post, $metabox) { |
|
| 2601 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2602 | - echo EEH_Template::display_template( |
|
| 2603 | - $metabox['args']['template_path'], |
|
| 2604 | - $metabox['args']['template_args'], |
|
| 2605 | - true |
|
| 2606 | - ); |
|
| 2607 | - } |
|
| 2608 | - : $callback; |
|
| 2609 | - add_meta_box( |
|
| 2610 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2611 | - $title, |
|
| 2612 | - $call_back_func, |
|
| 2613 | - $this->_wp_page_slug, |
|
| 2614 | - $column, |
|
| 2615 | - $priority, |
|
| 2616 | - $callback_args |
|
| 2617 | - ); |
|
| 2618 | - } |
|
| 2619 | - |
|
| 2620 | - |
|
| 2621 | - /** |
|
| 2622 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2623 | - * |
|
| 2624 | - * @throws DomainException |
|
| 2625 | - * @throws EE_Error |
|
| 2626 | - */ |
|
| 2627 | - public function display_admin_page_with_metabox_columns() |
|
| 2628 | - { |
|
| 2629 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2630 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2631 | - $this->_column_template_path, |
|
| 2632 | - $this->_template_args, |
|
| 2633 | - true |
|
| 2634 | - ); |
|
| 2635 | - // the final wrapper |
|
| 2636 | - $this->admin_page_wrapper(); |
|
| 2637 | - } |
|
| 2638 | - |
|
| 2639 | - |
|
| 2640 | - /** |
|
| 2641 | - * generates HTML wrapper for an admin details page |
|
| 2642 | - * |
|
| 2643 | - * @return void |
|
| 2644 | - * @throws EE_Error |
|
| 2645 | - * @throws DomainException |
|
| 2646 | - */ |
|
| 2647 | - public function display_admin_page_with_sidebar() |
|
| 2648 | - { |
|
| 2649 | - $this->_display_admin_page(true); |
|
| 2650 | - } |
|
| 2651 | - |
|
| 2652 | - |
|
| 2653 | - /** |
|
| 2654 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2655 | - * |
|
| 2656 | - * @return void |
|
| 2657 | - * @throws EE_Error |
|
| 2658 | - * @throws DomainException |
|
| 2659 | - */ |
|
| 2660 | - public function display_admin_page_with_no_sidebar() |
|
| 2661 | - { |
|
| 2662 | - $this->_display_admin_page(); |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - |
|
| 2666 | - /** |
|
| 2667 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2668 | - * |
|
| 2669 | - * @return void |
|
| 2670 | - * @throws EE_Error |
|
| 2671 | - * @throws DomainException |
|
| 2672 | - */ |
|
| 2673 | - public function display_about_admin_page() |
|
| 2674 | - { |
|
| 2675 | - $this->_display_admin_page(false, true); |
|
| 2676 | - } |
|
| 2677 | - |
|
| 2678 | - |
|
| 2679 | - /** |
|
| 2680 | - * display_admin_page |
|
| 2681 | - * contains the code for actually displaying an admin page |
|
| 2682 | - * |
|
| 2683 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2684 | - * @param boolean $about use the about_admin_wrapper instead of the default. |
|
| 2685 | - * @return void |
|
| 2686 | - * @throws DomainException |
|
| 2687 | - * @throws EE_Error |
|
| 2688 | - */ |
|
| 2689 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2690 | - { |
|
| 2691 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2692 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2693 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2694 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2695 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2696 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2697 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2698 | - ? 'poststuff' |
|
| 2699 | - : 'espresso-default-admin'; |
|
| 2700 | - $template_path = $sidebar |
|
| 2701 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2702 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2703 | - if ($this->request->isAjax()) { |
|
| 2704 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2705 | - } |
|
| 2706 | - $template_path = ! empty($this->_column_template_path) |
|
| 2707 | - ? $this->_column_template_path : $template_path; |
|
| 2708 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2709 | - ? $this->_template_args['admin_page_content'] |
|
| 2710 | - : ''; |
|
| 2711 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2712 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2713 | - : ''; |
|
| 2714 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2715 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2716 | - : ''; |
|
| 2717 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2718 | - $template_path, |
|
| 2719 | - $this->_template_args, |
|
| 2720 | - true |
|
| 2721 | - ); |
|
| 2722 | - // the final template wrapper |
|
| 2723 | - $this->admin_page_wrapper($about); |
|
| 2724 | - } |
|
| 2725 | - |
|
| 2726 | - |
|
| 2727 | - /** |
|
| 2728 | - * This is used to display caf preview pages. |
|
| 2729 | - * |
|
| 2730 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2731 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2732 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2733 | - * @return void |
|
| 2734 | - * @throws DomainException |
|
| 2735 | - * @throws EE_Error |
|
| 2736 | - * @throws InvalidArgumentException |
|
| 2737 | - * @throws InvalidDataTypeException |
|
| 2738 | - * @throws InvalidInterfaceException |
|
| 2739 | - * @since 4.3.2 |
|
| 2740 | - */ |
|
| 2741 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2742 | - { |
|
| 2743 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2744 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2745 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2746 | - 'event_espresso' |
|
| 2747 | - ); |
|
| 2748 | - $buy_now_url = add_query_arg( |
|
| 2749 | - [ |
|
| 2750 | - 'ee_ver' => 'ee4', |
|
| 2751 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2752 | - 'utm_medium' => 'link', |
|
| 2753 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2754 | - 'utm_content' => 'buy_now_button', |
|
| 2755 | - ], |
|
| 2756 | - 'https://eventespresso.com/pricing/' |
|
| 2757 | - ); |
|
| 2758 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2759 | - ? $this->get_action_link_or_button( |
|
| 2760 | - '', |
|
| 2761 | - 'buy_now', |
|
| 2762 | - [], |
|
| 2763 | - 'button-primary button-large', |
|
| 2764 | - esc_url_raw($buy_now_url), |
|
| 2765 | - true |
|
| 2766 | - ) |
|
| 2767 | - : $this->_template_args['preview_action_button']; |
|
| 2768 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2770 | - $this->_template_args, |
|
| 2771 | - true |
|
| 2772 | - ); |
|
| 2773 | - $this->_display_admin_page($display_sidebar); |
|
| 2774 | - } |
|
| 2775 | - |
|
| 2776 | - |
|
| 2777 | - /** |
|
| 2778 | - * display_admin_list_table_page_with_sidebar |
|
| 2779 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2780 | - * |
|
| 2781 | - * @return void |
|
| 2782 | - * @throws EE_Error |
|
| 2783 | - * @throws DomainException |
|
| 2784 | - */ |
|
| 2785 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2786 | - { |
|
| 2787 | - $this->_display_admin_list_table_page(true); |
|
| 2788 | - } |
|
| 2789 | - |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2793 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2794 | - * |
|
| 2795 | - * @return void |
|
| 2796 | - * @throws EE_Error |
|
| 2797 | - * @throws DomainException |
|
| 2798 | - */ |
|
| 2799 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2800 | - { |
|
| 2801 | - $this->_display_admin_list_table_page(); |
|
| 2802 | - } |
|
| 2803 | - |
|
| 2804 | - |
|
| 2805 | - /** |
|
| 2806 | - * generates html wrapper for an admin_list_table page |
|
| 2807 | - * |
|
| 2808 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2809 | - * @return void |
|
| 2810 | - * @throws DomainException |
|
| 2811 | - * @throws EE_Error |
|
| 2812 | - */ |
|
| 2813 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2814 | - { |
|
| 2815 | - // setup search attributes |
|
| 2816 | - $this->_set_search_attributes(); |
|
| 2817 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2818 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2819 | - $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2820 | - ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2821 | - : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2822 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2823 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2824 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2825 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2826 | - if (! empty($ajax_sorting_callback)) { |
|
| 2827 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2828 | - $ajax_sorting_callback . '_nonce', |
|
| 2829 | - $ajax_sorting_callback . '_nonce', |
|
| 2830 | - false, |
|
| 2831 | - false |
|
| 2832 | - ); |
|
| 2833 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2834 | - . $this->page_slug |
|
| 2835 | - . '" />'; |
|
| 2836 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2837 | - . $ajax_sorting_callback |
|
| 2838 | - . '" />'; |
|
| 2839 | - } else { |
|
| 2840 | - $sortable_list_table_form_fields = ''; |
|
| 2841 | - } |
|
| 2842 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2843 | - $hidden_form_fields = |
|
| 2844 | - isset($this->_template_args['list_table_hidden_fields']) |
|
| 2845 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 2846 | - : ''; |
|
| 2847 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2848 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 2849 | - . $nonce_ref |
|
| 2850 | - . '" value="' |
|
| 2851 | - . wp_create_nonce($nonce_ref) |
|
| 2852 | - . '">'; |
|
| 2853 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2854 | - // display message about search results? |
|
| 2855 | - $search = $this->request->getRequestParam('s'); |
|
| 2856 | - $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2857 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2858 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2859 | - trim($search, '%') |
|
| 2860 | - ) . '</p>' |
|
| 2861 | - : ''; |
|
| 2862 | - // filter before_list_table template arg |
|
| 2863 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 2864 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2865 | - $this->_template_args['before_list_table'], |
|
| 2866 | - $this->page_slug, |
|
| 2867 | - $this->request->requestParams(), |
|
| 2868 | - $this->_req_action |
|
| 2869 | - ); |
|
| 2870 | - // convert to array and filter again |
|
| 2871 | - // arrays are easier to inject new items in a specific location, |
|
| 2872 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2873 | - $this->_template_args['before_list_table'] = implode( |
|
| 2874 | - " \n", |
|
| 2875 | - (array) apply_filters( |
|
| 2876 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2877 | - (array) $this->_template_args['before_list_table'], |
|
| 2878 | - $this->page_slug, |
|
| 2879 | - $this->request->requestParams(), |
|
| 2880 | - $this->_req_action |
|
| 2881 | - ) |
|
| 2882 | - ); |
|
| 2883 | - // filter after_list_table template arg |
|
| 2884 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 2885 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2886 | - $this->_template_args['after_list_table'], |
|
| 2887 | - $this->page_slug, |
|
| 2888 | - $this->request->requestParams(), |
|
| 2889 | - $this->_req_action |
|
| 2890 | - ); |
|
| 2891 | - // convert to array and filter again |
|
| 2892 | - // arrays are easier to inject new items in a specific location, |
|
| 2893 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2894 | - $this->_template_args['after_list_table'] = implode( |
|
| 2895 | - " \n", |
|
| 2896 | - (array) apply_filters( |
|
| 2897 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2898 | - (array) $this->_template_args['after_list_table'], |
|
| 2899 | - $this->page_slug, |
|
| 2900 | - $this->request->requestParams(), |
|
| 2901 | - $this->_req_action |
|
| 2902 | - ) |
|
| 2903 | - ); |
|
| 2904 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2905 | - $template_path, |
|
| 2906 | - $this->_template_args, |
|
| 2907 | - true |
|
| 2908 | - ); |
|
| 2909 | - // the final template wrapper |
|
| 2910 | - if ($sidebar) { |
|
| 2911 | - $this->display_admin_page_with_sidebar(); |
|
| 2912 | - } else { |
|
| 2913 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2914 | - } |
|
| 2915 | - } |
|
| 2916 | - |
|
| 2917 | - |
|
| 2918 | - /** |
|
| 2919 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 2920 | - * html string for the legend. |
|
| 2921 | - * $items are expected in an array in the following format: |
|
| 2922 | - * $legend_items = array( |
|
| 2923 | - * 'item_id' => array( |
|
| 2924 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2925 | - * 'desc' => esc_html__('localized description of item'); |
|
| 2926 | - * ) |
|
| 2927 | - * ); |
|
| 2928 | - * |
|
| 2929 | - * @param array $items see above for format of array |
|
| 2930 | - * @return string html string of legend |
|
| 2931 | - * @throws DomainException |
|
| 2932 | - */ |
|
| 2933 | - protected function _display_legend($items) |
|
| 2934 | - { |
|
| 2935 | - $this->_template_args['items'] = apply_filters( |
|
| 2936 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 2937 | - (array) $items, |
|
| 2938 | - $this |
|
| 2939 | - ); |
|
| 2940 | - return EEH_Template::display_template( |
|
| 2941 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 2942 | - $this->_template_args, |
|
| 2943 | - true |
|
| 2944 | - ); |
|
| 2945 | - } |
|
| 2946 | - |
|
| 2947 | - |
|
| 2948 | - /** |
|
| 2949 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2950 | - * The returned json object is created from an array in the following format: |
|
| 2951 | - * array( |
|
| 2952 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2953 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2954 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2955 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2956 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 2957 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 2958 | - * that might be included in here) |
|
| 2959 | - * ) |
|
| 2960 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 2961 | - * |
|
| 2962 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 2963 | - * instead of displayed. |
|
| 2964 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 2965 | - * @return void |
|
| 2966 | - * @throws EE_Error |
|
| 2967 | - */ |
|
| 2968 | - protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 2969 | - { |
|
| 2970 | - // make sure any EE_Error notices have been handled. |
|
| 2971 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 2972 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 2973 | - unset($this->_template_args['data']); |
|
| 2974 | - $json = [ |
|
| 2975 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2976 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2977 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2978 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2979 | - 'notices' => EE_Error::get_notices(), |
|
| 2980 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 2981 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 2982 | - 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 2983 | - 'isEEajax' => true |
|
| 2984 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2985 | - ]; |
|
| 2986 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2987 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 2988 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 2989 | - } |
|
| 2990 | - echo wp_json_encode($json); |
|
| 2991 | - exit(); |
|
| 2992 | - } |
|
| 2993 | - |
|
| 2994 | - |
|
| 2995 | - /** |
|
| 2996 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2997 | - * |
|
| 2998 | - * @return void |
|
| 2999 | - * @throws EE_Error |
|
| 3000 | - */ |
|
| 3001 | - public function return_json() |
|
| 3002 | - { |
|
| 3003 | - if ($this->request->isAjax()) { |
|
| 3004 | - $this->_return_json(); |
|
| 3005 | - } else { |
|
| 3006 | - throw new EE_Error( |
|
| 3007 | - sprintf( |
|
| 3008 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3009 | - __FUNCTION__ |
|
| 3010 | - ) |
|
| 3011 | - ); |
|
| 3012 | - } |
|
| 3013 | - } |
|
| 3014 | - |
|
| 3015 | - |
|
| 3016 | - /** |
|
| 3017 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3018 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3019 | - * |
|
| 3020 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3021 | - */ |
|
| 3022 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3023 | - { |
|
| 3024 | - $this->_hook_obj = $hook_obj; |
|
| 3025 | - } |
|
| 3026 | - |
|
| 3027 | - |
|
| 3028 | - /** |
|
| 3029 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3030 | - * |
|
| 3031 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3032 | - * @return void |
|
| 3033 | - * @throws DomainException |
|
| 3034 | - * @throws EE_Error |
|
| 3035 | - */ |
|
| 3036 | - public function admin_page_wrapper($about = false) |
|
| 3037 | - { |
|
| 3038 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3039 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3040 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3041 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3042 | - |
|
| 3043 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3044 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3045 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3046 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3047 | - : '' |
|
| 3048 | - ); |
|
| 3049 | - |
|
| 3050 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3051 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3052 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3053 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3054 | - : '' |
|
| 3055 | - ); |
|
| 3056 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3057 | - |
|
| 3058 | - if ($this->request->isAjax()) { |
|
| 3059 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3060 | - // $template_path, |
|
| 3061 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3062 | - $this->_template_args, |
|
| 3063 | - true |
|
| 3064 | - ); |
|
| 3065 | - $this->_return_json(); |
|
| 3066 | - } |
|
| 3067 | - // load settings page wrapper template |
|
| 3068 | - $template_path = $about |
|
| 3069 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3070 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3071 | - |
|
| 3072 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3073 | - } |
|
| 3074 | - |
|
| 3075 | - |
|
| 3076 | - /** |
|
| 3077 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3078 | - * |
|
| 3079 | - * @return string html |
|
| 3080 | - * @throws EE_Error |
|
| 3081 | - */ |
|
| 3082 | - protected function _get_main_nav_tabs() |
|
| 3083 | - { |
|
| 3084 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3085 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3086 | - // (rather than setting in the page_routes array) |
|
| 3087 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3088 | - } |
|
| 3089 | - |
|
| 3090 | - |
|
| 3091 | - /** |
|
| 3092 | - * sort nav tabs |
|
| 3093 | - * |
|
| 3094 | - * @param $a |
|
| 3095 | - * @param $b |
|
| 3096 | - * @return int |
|
| 3097 | - */ |
|
| 3098 | - private function _sort_nav_tabs($a, $b) |
|
| 3099 | - { |
|
| 3100 | - if ($a['order'] === $b['order']) { |
|
| 3101 | - return 0; |
|
| 3102 | - } |
|
| 3103 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3104 | - } |
|
| 3105 | - |
|
| 3106 | - |
|
| 3107 | - /** |
|
| 3108 | - * generates HTML for the forms used on admin pages |
|
| 3109 | - * |
|
| 3110 | - * @param array $input_vars - array of input field details |
|
| 3111 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3112 | - * use) |
|
| 3113 | - * @param bool $id |
|
| 3114 | - * @return array|string |
|
| 3115 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3116 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3117 | - */ |
|
| 3118 | - protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3119 | - { |
|
| 3120 | - return $generator === 'string' |
|
| 3121 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3122 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3123 | - } |
|
| 3124 | - |
|
| 3125 | - |
|
| 3126 | - /** |
|
| 3127 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3128 | - * |
|
| 3129 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3130 | - * Close" button. |
|
| 3131 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3132 | - * 'Save', [1] => 'save & close') |
|
| 3133 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3134 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3135 | - * default actions by submitting some other value. |
|
| 3136 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3137 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3138 | - * close (normal form handling). |
|
| 3139 | - */ |
|
| 3140 | - protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3141 | - { |
|
| 3142 | - // make sure $text and $actions are in an array |
|
| 3143 | - $text = (array) $text; |
|
| 3144 | - $actions = (array) $actions; |
|
| 3145 | - $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3146 | - $button_text = ! empty($text) |
|
| 3147 | - ? $text |
|
| 3148 | - : [ |
|
| 3149 | - esc_html__('Save', 'event_espresso'), |
|
| 3150 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3151 | - ]; |
|
| 3152 | - $default_names = ['save', 'save_and_close']; |
|
| 3153 | - $buttons = ''; |
|
| 3154 | - foreach ($button_text as $key => $button) { |
|
| 3155 | - $ref = $default_names[ $key ]; |
|
| 3156 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3157 | - $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
| 3158 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3159 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3160 | - if (! $both) { |
|
| 3161 | - break; |
|
| 3162 | - } |
|
| 3163 | - } |
|
| 3164 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3165 | - $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3166 | - . $referrer_url |
|
| 3167 | - . '" />'; |
|
| 3168 | - $this->_template_args['save_buttons'] = $buttons; |
|
| 3169 | - } |
|
| 3170 | - |
|
| 3171 | - |
|
| 3172 | - /** |
|
| 3173 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3174 | - * |
|
| 3175 | - * @param string $route |
|
| 3176 | - * @param array $additional_hidden_fields |
|
| 3177 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3178 | - * @since 4.6.0 |
|
| 3179 | - */ |
|
| 3180 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3181 | - { |
|
| 3182 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3183 | - } |
|
| 3184 | - |
|
| 3185 | - |
|
| 3186 | - /** |
|
| 3187 | - * set form open and close tags on add/edit pages. |
|
| 3188 | - * |
|
| 3189 | - * @param string $route the route you want the form to direct to |
|
| 3190 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3191 | - * @return void |
|
| 3192 | - */ |
|
| 3193 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3194 | - { |
|
| 3195 | - if (empty($route)) { |
|
| 3196 | - $user_msg = esc_html__( |
|
| 3197 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3198 | - 'event_espresso' |
|
| 3199 | - ); |
|
| 3200 | - $dev_msg = $user_msg . "\n" |
|
| 3201 | - . sprintf( |
|
| 3202 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3203 | - __FUNCTION__, |
|
| 3204 | - __CLASS__ |
|
| 3205 | - ); |
|
| 3206 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3207 | - } |
|
| 3208 | - // open form |
|
| 3209 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3210 | - . $this->_admin_base_url |
|
| 3211 | - . '" id="' |
|
| 3212 | - . $route |
|
| 3213 | - . '_event_form" >'; |
|
| 3214 | - // add nonce |
|
| 3215 | - $nonce = |
|
| 3216 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3217 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3218 | - // add REQUIRED form action |
|
| 3219 | - $hidden_fields = [ |
|
| 3220 | - 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3221 | - ]; |
|
| 3222 | - // merge arrays |
|
| 3223 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3224 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3225 | - : $hidden_fields; |
|
| 3226 | - // generate form fields |
|
| 3227 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3228 | - // add fields to form |
|
| 3229 | - foreach ((array) $form_fields as $form_field) { |
|
| 3230 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3231 | - } |
|
| 3232 | - // close form |
|
| 3233 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3234 | - } |
|
| 3235 | - |
|
| 3236 | - |
|
| 3237 | - /** |
|
| 3238 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3239 | - * discovered it would be useful for external code to have access. |
|
| 3240 | - * |
|
| 3241 | - * @param bool $success |
|
| 3242 | - * @param string $what |
|
| 3243 | - * @param string $action_desc |
|
| 3244 | - * @param array $query_args |
|
| 3245 | - * @param bool $override_overwrite |
|
| 3246 | - * @throws EE_Error |
|
| 3247 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3248 | - * @since 4.5.0 |
|
| 3249 | - */ |
|
| 3250 | - public function redirect_after_action( |
|
| 3251 | - $success = false, |
|
| 3252 | - $what = 'item', |
|
| 3253 | - $action_desc = 'processed', |
|
| 3254 | - $query_args = [], |
|
| 3255 | - $override_overwrite = false |
|
| 3256 | - ) { |
|
| 3257 | - $this->_redirect_after_action( |
|
| 3258 | - $success, |
|
| 3259 | - $what, |
|
| 3260 | - $action_desc, |
|
| 3261 | - $query_args, |
|
| 3262 | - $override_overwrite |
|
| 3263 | - ); |
|
| 3264 | - } |
|
| 3265 | - |
|
| 3266 | - |
|
| 3267 | - /** |
|
| 3268 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3269 | - * |
|
| 3270 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3271 | - * filters are still applied. |
|
| 3272 | - * |
|
| 3273 | - * @param array $new_route_data |
|
| 3274 | - * @return array |
|
| 3275 | - */ |
|
| 3276 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3277 | - { |
|
| 3278 | - foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3279 | - // unset nonces |
|
| 3280 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3281 | - $this->request->unSetRequestParam($ref); |
|
| 3282 | - continue; |
|
| 3283 | - } |
|
| 3284 | - // urlencode values. |
|
| 3285 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3286 | - $this->request->setRequestParam($ref, $value); |
|
| 3287 | - } |
|
| 3288 | - return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3289 | - } |
|
| 3290 | - |
|
| 3291 | - |
|
| 3292 | - /** |
|
| 3293 | - * _redirect_after_action |
|
| 3294 | - * |
|
| 3295 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3296 | - * @param string $what - what the action was performed on |
|
| 3297 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3298 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3299 | - * action is completed |
|
| 3300 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3301 | - * override this so that they show. |
|
| 3302 | - * @return void |
|
| 3303 | - * @throws EE_Error |
|
| 3304 | - */ |
|
| 3305 | - protected function _redirect_after_action( |
|
| 3306 | - $success = 0, |
|
| 3307 | - $what = 'item', |
|
| 3308 | - $action_desc = 'processed', |
|
| 3309 | - $query_args = [], |
|
| 3310 | - $override_overwrite = false |
|
| 3311 | - ) { |
|
| 3312 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3313 | - // class name for actions/filters. |
|
| 3314 | - $classname = get_class($this); |
|
| 3315 | - // set redirect url. |
|
| 3316 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3317 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3318 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3319 | - $notices = EE_Error::get_notices(false); |
|
| 3320 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3321 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3322 | - EE_Error::overwrite_success(); |
|
| 3323 | - } |
|
| 3324 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3325 | - // how many records affected ? more than one record ? or just one ? |
|
| 3326 | - if ($success > 1) { |
|
| 3327 | - // set plural msg |
|
| 3328 | - EE_Error::add_success( |
|
| 3329 | - sprintf( |
|
| 3330 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3331 | - $what, |
|
| 3332 | - $action_desc |
|
| 3333 | - ), |
|
| 3334 | - __FILE__, |
|
| 3335 | - __FUNCTION__, |
|
| 3336 | - __LINE__ |
|
| 3337 | - ); |
|
| 3338 | - } elseif ($success === 1) { |
|
| 3339 | - // set singular msg |
|
| 3340 | - EE_Error::add_success( |
|
| 3341 | - sprintf( |
|
| 3342 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3343 | - $what, |
|
| 3344 | - $action_desc |
|
| 3345 | - ), |
|
| 3346 | - __FILE__, |
|
| 3347 | - __FUNCTION__, |
|
| 3348 | - __LINE__ |
|
| 3349 | - ); |
|
| 3350 | - } |
|
| 3351 | - } |
|
| 3352 | - // check that $query_args isn't something crazy |
|
| 3353 | - if (! is_array($query_args)) { |
|
| 3354 | - $query_args = []; |
|
| 3355 | - } |
|
| 3356 | - /** |
|
| 3357 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3358 | - * redirections on save and close actions |
|
| 3359 | - * |
|
| 3360 | - * @param array $query_args The original query_args array coming into the |
|
| 3361 | - * method. |
|
| 3362 | - * @since 4.2.0 |
|
| 3363 | - */ |
|
| 3364 | - do_action( |
|
| 3365 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3366 | - $query_args |
|
| 3367 | - ); |
|
| 3368 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3369 | - |
|
| 3370 | - if ( |
|
| 3371 | - $this->request->requestParamIsSet('save_and_close') |
|
| 3372 | - && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3373 | - ) { |
|
| 3374 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3375 | - $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3376 | - // regenerate query args array from referrer URL |
|
| 3377 | - parse_str($parsed_url['query'], $query_args); |
|
| 3378 | - // correct page and action will be in the query args now |
|
| 3379 | - $redirect_url = admin_url('admin.php'); |
|
| 3380 | - } |
|
| 3381 | - // merge any default query_args set in _default_route_query_args property |
|
| 3382 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3383 | - $args_to_merge = []; |
|
| 3384 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3385 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3386 | - if ($query_param === 'wp_referer') { |
|
| 3387 | - $query_value = (array) $query_value; |
|
| 3388 | - foreach ($query_value as $reference => $value) { |
|
| 3389 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3390 | - continue; |
|
| 3391 | - } |
|
| 3392 | - // finally we will override any arguments in the referer with |
|
| 3393 | - // what might be set on the _default_route_query_args array. |
|
| 3394 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3395 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3396 | - } else { |
|
| 3397 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3398 | - } |
|
| 3399 | - } |
|
| 3400 | - continue; |
|
| 3401 | - } |
|
| 3402 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3403 | - } |
|
| 3404 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3405 | - // redirect. |
|
| 3406 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3407 | - } |
|
| 3408 | - $this->_process_notices($query_args); |
|
| 3409 | - // generate redirect url |
|
| 3410 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3411 | - if (isset($query_args['action'])) { |
|
| 3412 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3413 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3414 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3415 | - } |
|
| 3416 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3417 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3418 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3419 | - $redirect_url = apply_filters( |
|
| 3420 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3421 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3422 | - $query_args |
|
| 3423 | - ); |
|
| 3424 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3425 | - if ($this->request->isAjax()) { |
|
| 3426 | - $default_data = [ |
|
| 3427 | - 'close' => true, |
|
| 3428 | - 'redirect_url' => $redirect_url, |
|
| 3429 | - 'where' => 'main', |
|
| 3430 | - 'what' => 'append', |
|
| 3431 | - ]; |
|
| 3432 | - $this->_template_args['success'] = $success; |
|
| 3433 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3434 | - $default_data, |
|
| 3435 | - $this->_template_args['data'] |
|
| 3436 | - ) : $default_data; |
|
| 3437 | - $this->_return_json(); |
|
| 3438 | - } |
|
| 3439 | - wp_safe_redirect($redirect_url); |
|
| 3440 | - exit(); |
|
| 3441 | - } |
|
| 3442 | - |
|
| 3443 | - |
|
| 3444 | - /** |
|
| 3445 | - * process any notices before redirecting (or returning ajax request) |
|
| 3446 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3447 | - * |
|
| 3448 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3449 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3450 | - * page_routes haven't been defined yet. |
|
| 3451 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3452 | - * still save a transient for the notice. |
|
| 3453 | - * @return void |
|
| 3454 | - * @throws EE_Error |
|
| 3455 | - */ |
|
| 3456 | - protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3457 | - { |
|
| 3458 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3459 | - if ($this->request->isAjax()) { |
|
| 3460 | - $notices = EE_Error::get_notices(false); |
|
| 3461 | - if (empty($this->_template_args['success'])) { |
|
| 3462 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3463 | - } |
|
| 3464 | - if (empty($this->_template_args['errors'])) { |
|
| 3465 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3466 | - } |
|
| 3467 | - if (empty($this->_template_args['attention'])) { |
|
| 3468 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3469 | - } |
|
| 3470 | - } |
|
| 3471 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3472 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3473 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3474 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3475 | - $this->_add_transient( |
|
| 3476 | - $route, |
|
| 3477 | - $this->_template_args['notices'], |
|
| 3478 | - true, |
|
| 3479 | - $skip_route_verify |
|
| 3480 | - ); |
|
| 3481 | - } |
|
| 3482 | - } |
|
| 3483 | - |
|
| 3484 | - |
|
| 3485 | - /** |
|
| 3486 | - * get_action_link_or_button |
|
| 3487 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3488 | - * |
|
| 3489 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3490 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3491 | - * property. |
|
| 3492 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3493 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3494 | - * @param string $base_url If this is not provided |
|
| 3495 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3496 | - * Otherwise this value will be used. |
|
| 3497 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3498 | - * @return string |
|
| 3499 | - * @throws InvalidArgumentException |
|
| 3500 | - * @throws InvalidInterfaceException |
|
| 3501 | - * @throws InvalidDataTypeException |
|
| 3502 | - * @throws EE_Error |
|
| 3503 | - */ |
|
| 3504 | - public function get_action_link_or_button( |
|
| 3505 | - $action, |
|
| 3506 | - $type = 'add', |
|
| 3507 | - $extra_request = [], |
|
| 3508 | - $class = 'button-primary', |
|
| 3509 | - $base_url = '', |
|
| 3510 | - $exclude_nonce = false |
|
| 3511 | - ) { |
|
| 3512 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3513 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3514 | - throw new EE_Error( |
|
| 3515 | - sprintf( |
|
| 3516 | - esc_html__( |
|
| 3517 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3518 | - 'event_espresso' |
|
| 3519 | - ), |
|
| 3520 | - $action |
|
| 3521 | - ) |
|
| 3522 | - ); |
|
| 3523 | - } |
|
| 3524 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3525 | - throw new EE_Error( |
|
| 3526 | - sprintf( |
|
| 3527 | - esc_html__( |
|
| 3528 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3529 | - 'event_espresso' |
|
| 3530 | - ), |
|
| 3531 | - $type |
|
| 3532 | - ) |
|
| 3533 | - ); |
|
| 3534 | - } |
|
| 3535 | - // finally check user access for this button. |
|
| 3536 | - $has_access = $this->check_user_access($action, true); |
|
| 3537 | - if (! $has_access) { |
|
| 3538 | - return ''; |
|
| 3539 | - } |
|
| 3540 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3541 | - $query_args = [ |
|
| 3542 | - 'action' => $action, |
|
| 3543 | - ]; |
|
| 3544 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3545 | - if (! empty($extra_request)) { |
|
| 3546 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3547 | - } |
|
| 3548 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3549 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3550 | - } |
|
| 3551 | - |
|
| 3552 | - |
|
| 3553 | - /** |
|
| 3554 | - * _per_page_screen_option |
|
| 3555 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3556 | - * |
|
| 3557 | - * @return void |
|
| 3558 | - * @throws InvalidArgumentException |
|
| 3559 | - * @throws InvalidInterfaceException |
|
| 3560 | - * @throws InvalidDataTypeException |
|
| 3561 | - */ |
|
| 3562 | - protected function _per_page_screen_option() |
|
| 3563 | - { |
|
| 3564 | - $option = 'per_page'; |
|
| 3565 | - $args = [ |
|
| 3566 | - 'label' => apply_filters( |
|
| 3567 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3568 | - $this->_admin_page_title, |
|
| 3569 | - $this |
|
| 3570 | - ), |
|
| 3571 | - 'default' => (int) apply_filters( |
|
| 3572 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3573 | - 20 |
|
| 3574 | - ), |
|
| 3575 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3576 | - ]; |
|
| 3577 | - // ONLY add the screen option if the user has access to it. |
|
| 3578 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3579 | - add_screen_option($option, $args); |
|
| 3580 | - } |
|
| 3581 | - } |
|
| 3582 | - |
|
| 3583 | - |
|
| 3584 | - /** |
|
| 3585 | - * set_per_page_screen_option |
|
| 3586 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3587 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3588 | - * admin_menu. |
|
| 3589 | - * |
|
| 3590 | - * @return void |
|
| 3591 | - */ |
|
| 3592 | - private function _set_per_page_screen_options() |
|
| 3593 | - { |
|
| 3594 | - if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3595 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3596 | - if (! $user = wp_get_current_user()) { |
|
| 3597 | - return; |
|
| 3598 | - } |
|
| 3599 | - $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3600 | - if (! $option) { |
|
| 3601 | - return; |
|
| 3602 | - } |
|
| 3603 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3604 | - $map_option = $option; |
|
| 3605 | - $option = str_replace('-', '_', $option); |
|
| 3606 | - switch ($map_option) { |
|
| 3607 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3608 | - $max_value = apply_filters( |
|
| 3609 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3610 | - 999, |
|
| 3611 | - $this->_current_page, |
|
| 3612 | - $this->_current_view |
|
| 3613 | - ); |
|
| 3614 | - if ($value < 1) { |
|
| 3615 | - return; |
|
| 3616 | - } |
|
| 3617 | - $value = min($value, $max_value); |
|
| 3618 | - break; |
|
| 3619 | - default: |
|
| 3620 | - $value = apply_filters( |
|
| 3621 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3622 | - false, |
|
| 3623 | - $option, |
|
| 3624 | - $value |
|
| 3625 | - ); |
|
| 3626 | - if (false === $value) { |
|
| 3627 | - return; |
|
| 3628 | - } |
|
| 3629 | - break; |
|
| 3630 | - } |
|
| 3631 | - update_user_meta($user->ID, $option, $value); |
|
| 3632 | - wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3633 | - exit; |
|
| 3634 | - } |
|
| 3635 | - } |
|
| 3636 | - |
|
| 3637 | - |
|
| 3638 | - /** |
|
| 3639 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3640 | - * |
|
| 3641 | - * @param array $data array that will be assigned to template args. |
|
| 3642 | - */ |
|
| 3643 | - public function set_template_args($data) |
|
| 3644 | - { |
|
| 3645 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3646 | - } |
|
| 3647 | - |
|
| 3648 | - |
|
| 3649 | - /** |
|
| 3650 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3651 | - * |
|
| 3652 | - * @param string $route the route that should receive the transient |
|
| 3653 | - * @param array $data the data that gets sent |
|
| 3654 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3655 | - * normal route transient. |
|
| 3656 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3657 | - * when we are adding a transient before page_routes have been defined. |
|
| 3658 | - * @return void |
|
| 3659 | - * @throws EE_Error |
|
| 3660 | - */ |
|
| 3661 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3662 | - { |
|
| 3663 | - $user_id = get_current_user_id(); |
|
| 3664 | - if (! $skip_route_verify) { |
|
| 3665 | - $this->_verify_route($route); |
|
| 3666 | - } |
|
| 3667 | - // now let's set the string for what kind of transient we're setting |
|
| 3668 | - $transient = $notices |
|
| 3669 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3670 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3671 | - $data = $notices ? ['notices' => $data] : $data; |
|
| 3672 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3673 | - $existing = is_multisite() && is_network_admin() |
|
| 3674 | - ? get_site_transient($transient) |
|
| 3675 | - : get_transient($transient); |
|
| 3676 | - if ($existing) { |
|
| 3677 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3678 | - } |
|
| 3679 | - if (is_multisite() && is_network_admin()) { |
|
| 3680 | - set_site_transient($transient, $data, 8); |
|
| 3681 | - } else { |
|
| 3682 | - set_transient($transient, $data, 8); |
|
| 3683 | - } |
|
| 3684 | - } |
|
| 3685 | - |
|
| 3686 | - |
|
| 3687 | - /** |
|
| 3688 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3689 | - * |
|
| 3690 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3691 | - * @param string $route |
|
| 3692 | - * @return mixed data |
|
| 3693 | - */ |
|
| 3694 | - protected function _get_transient($notices = false, $route = '') |
|
| 3695 | - { |
|
| 3696 | - $user_id = get_current_user_id(); |
|
| 3697 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3698 | - $transient = $notices |
|
| 3699 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3700 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3701 | - $data = is_multisite() && is_network_admin() |
|
| 3702 | - ? get_site_transient($transient) |
|
| 3703 | - : get_transient($transient); |
|
| 3704 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3705 | - if (is_multisite() && is_network_admin()) { |
|
| 3706 | - delete_site_transient($transient); |
|
| 3707 | - } else { |
|
| 3708 | - delete_transient($transient); |
|
| 3709 | - } |
|
| 3710 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3711 | - } |
|
| 3712 | - |
|
| 3713 | - |
|
| 3714 | - /** |
|
| 3715 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3716 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3717 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3718 | - * |
|
| 3719 | - * @return void |
|
| 3720 | - */ |
|
| 3721 | - protected function _transient_garbage_collection() |
|
| 3722 | - { |
|
| 3723 | - global $wpdb; |
|
| 3724 | - // retrieve all existing transients |
|
| 3725 | - $query = |
|
| 3726 | - "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3727 | - if ($results = $wpdb->get_results($query)) { |
|
| 3728 | - foreach ($results as $result) { |
|
| 3729 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3730 | - get_transient($transient); |
|
| 3731 | - if (is_multisite() && is_network_admin()) { |
|
| 3732 | - get_site_transient($transient); |
|
| 3733 | - } |
|
| 3734 | - } |
|
| 3735 | - } |
|
| 3736 | - } |
|
| 3737 | - |
|
| 3738 | - |
|
| 3739 | - /** |
|
| 3740 | - * get_view |
|
| 3741 | - * |
|
| 3742 | - * @return string content of _view property |
|
| 3743 | - */ |
|
| 3744 | - public function get_view() |
|
| 3745 | - { |
|
| 3746 | - return $this->_view; |
|
| 3747 | - } |
|
| 3748 | - |
|
| 3749 | - |
|
| 3750 | - /** |
|
| 3751 | - * getter for the protected $_views property |
|
| 3752 | - * |
|
| 3753 | - * @return array |
|
| 3754 | - */ |
|
| 3755 | - public function get_views() |
|
| 3756 | - { |
|
| 3757 | - return $this->_views; |
|
| 3758 | - } |
|
| 3759 | - |
|
| 3760 | - |
|
| 3761 | - /** |
|
| 3762 | - * get_current_page |
|
| 3763 | - * |
|
| 3764 | - * @return string _current_page property value |
|
| 3765 | - */ |
|
| 3766 | - public function get_current_page() |
|
| 3767 | - { |
|
| 3768 | - return $this->_current_page; |
|
| 3769 | - } |
|
| 3770 | - |
|
| 3771 | - |
|
| 3772 | - /** |
|
| 3773 | - * get_current_view |
|
| 3774 | - * |
|
| 3775 | - * @return string _current_view property value |
|
| 3776 | - */ |
|
| 3777 | - public function get_current_view() |
|
| 3778 | - { |
|
| 3779 | - return $this->_current_view; |
|
| 3780 | - } |
|
| 3781 | - |
|
| 3782 | - |
|
| 3783 | - /** |
|
| 3784 | - * get_current_screen |
|
| 3785 | - * |
|
| 3786 | - * @return object The current WP_Screen object |
|
| 3787 | - */ |
|
| 3788 | - public function get_current_screen() |
|
| 3789 | - { |
|
| 3790 | - return $this->_current_screen; |
|
| 3791 | - } |
|
| 3792 | - |
|
| 3793 | - |
|
| 3794 | - /** |
|
| 3795 | - * get_current_page_view_url |
|
| 3796 | - * |
|
| 3797 | - * @return string This returns the url for the current_page_view. |
|
| 3798 | - */ |
|
| 3799 | - public function get_current_page_view_url() |
|
| 3800 | - { |
|
| 3801 | - return $this->_current_page_view_url; |
|
| 3802 | - } |
|
| 3803 | - |
|
| 3804 | - |
|
| 3805 | - /** |
|
| 3806 | - * just returns the Request |
|
| 3807 | - * |
|
| 3808 | - * @return RequestInterface |
|
| 3809 | - */ |
|
| 3810 | - public function get_request() |
|
| 3811 | - { |
|
| 3812 | - return $this->request; |
|
| 3813 | - } |
|
| 3814 | - |
|
| 3815 | - |
|
| 3816 | - /** |
|
| 3817 | - * just returns the _req_data property |
|
| 3818 | - * |
|
| 3819 | - * @return array |
|
| 3820 | - */ |
|
| 3821 | - public function get_request_data() |
|
| 3822 | - { |
|
| 3823 | - return $this->request->requestParams(); |
|
| 3824 | - } |
|
| 3825 | - |
|
| 3826 | - |
|
| 3827 | - /** |
|
| 3828 | - * returns the _req_data protected property |
|
| 3829 | - * |
|
| 3830 | - * @return string |
|
| 3831 | - */ |
|
| 3832 | - public function get_req_action() |
|
| 3833 | - { |
|
| 3834 | - return $this->_req_action; |
|
| 3835 | - } |
|
| 3836 | - |
|
| 3837 | - |
|
| 3838 | - /** |
|
| 3839 | - * @return bool value of $_is_caf property |
|
| 3840 | - */ |
|
| 3841 | - public function is_caf() |
|
| 3842 | - { |
|
| 3843 | - return $this->_is_caf; |
|
| 3844 | - } |
|
| 3845 | - |
|
| 3846 | - |
|
| 3847 | - /** |
|
| 3848 | - * @return mixed |
|
| 3849 | - */ |
|
| 3850 | - public function default_espresso_metaboxes() |
|
| 3851 | - { |
|
| 3852 | - return $this->_default_espresso_metaboxes; |
|
| 3853 | - } |
|
| 3854 | - |
|
| 3855 | - |
|
| 3856 | - /** |
|
| 3857 | - * @return mixed |
|
| 3858 | - */ |
|
| 3859 | - public function admin_base_url() |
|
| 3860 | - { |
|
| 3861 | - return $this->_admin_base_url; |
|
| 3862 | - } |
|
| 3863 | - |
|
| 3864 | - |
|
| 3865 | - /** |
|
| 3866 | - * @return mixed |
|
| 3867 | - */ |
|
| 3868 | - public function wp_page_slug() |
|
| 3869 | - { |
|
| 3870 | - return $this->_wp_page_slug; |
|
| 3871 | - } |
|
| 3872 | - |
|
| 3873 | - |
|
| 3874 | - /** |
|
| 3875 | - * updates espresso configuration settings |
|
| 3876 | - * |
|
| 3877 | - * @param string $tab |
|
| 3878 | - * @param EE_Config_Base|EE_Config $config |
|
| 3879 | - * @param string $file file where error occurred |
|
| 3880 | - * @param string $func function where error occurred |
|
| 3881 | - * @param string $line line no where error occurred |
|
| 3882 | - * @return boolean |
|
| 3883 | - */ |
|
| 3884 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3885 | - { |
|
| 3886 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 3887 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 3888 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3889 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3890 | - update_option('ee_ueip_has_notified', true); |
|
| 3891 | - } |
|
| 3892 | - // and save it (note we're also doing the network save here) |
|
| 3893 | - $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 3894 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3895 | - if ($config_saved && $net_saved) { |
|
| 3896 | - EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3897 | - return true; |
|
| 3898 | - } |
|
| 3899 | - EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3900 | - return false; |
|
| 3901 | - } |
|
| 3902 | - |
|
| 3903 | - |
|
| 3904 | - /** |
|
| 3905 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3906 | - * |
|
| 3907 | - * @return array |
|
| 3908 | - */ |
|
| 3909 | - public function get_yes_no_values() |
|
| 3910 | - { |
|
| 3911 | - return $this->_yes_no_values; |
|
| 3912 | - } |
|
| 3913 | - |
|
| 3914 | - |
|
| 3915 | - protected function _get_dir() |
|
| 3916 | - { |
|
| 3917 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 3918 | - return dirname($reflector->getFileName()); |
|
| 3919 | - } |
|
| 3920 | - |
|
| 3921 | - |
|
| 3922 | - /** |
|
| 3923 | - * A helper for getting a "next link". |
|
| 3924 | - * |
|
| 3925 | - * @param string $url The url to link to |
|
| 3926 | - * @param string $class The class to use. |
|
| 3927 | - * @return string |
|
| 3928 | - */ |
|
| 3929 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3930 | - { |
|
| 3931 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3932 | - } |
|
| 3933 | - |
|
| 3934 | - |
|
| 3935 | - /** |
|
| 3936 | - * A helper for getting a "previous link". |
|
| 3937 | - * |
|
| 3938 | - * @param string $url The url to link to |
|
| 3939 | - * @param string $class The class to use. |
|
| 3940 | - * @return string |
|
| 3941 | - */ |
|
| 3942 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3943 | - { |
|
| 3944 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3945 | - } |
|
| 3946 | - |
|
| 3947 | - |
|
| 3948 | - |
|
| 3949 | - |
|
| 3950 | - |
|
| 3951 | - |
|
| 3952 | - |
|
| 3953 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3954 | - |
|
| 3955 | - |
|
| 3956 | - /** |
|
| 3957 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 3958 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 3959 | - * _req_data array. |
|
| 3960 | - * |
|
| 3961 | - * @return bool success/fail |
|
| 3962 | - * @throws EE_Error |
|
| 3963 | - * @throws InvalidArgumentException |
|
| 3964 | - * @throws ReflectionException |
|
| 3965 | - * @throws InvalidDataTypeException |
|
| 3966 | - * @throws InvalidInterfaceException |
|
| 3967 | - */ |
|
| 3968 | - protected function _process_resend_registration() |
|
| 3969 | - { |
|
| 3970 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3971 | - do_action( |
|
| 3972 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 3973 | - $this->_template_args['success'], |
|
| 3974 | - $this->request->requestParams() |
|
| 3975 | - ); |
|
| 3976 | - return $this->_template_args['success']; |
|
| 3977 | - } |
|
| 3978 | - |
|
| 3979 | - |
|
| 3980 | - /** |
|
| 3981 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3982 | - * |
|
| 3983 | - * @param EE_Payment $payment |
|
| 3984 | - * @return bool success/fail |
|
| 3985 | - */ |
|
| 3986 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 3987 | - { |
|
| 3988 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3989 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3990 | - $this->_template_args['success'] = apply_filters( |
|
| 3991 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 3992 | - false, |
|
| 3993 | - $payment |
|
| 3994 | - ); |
|
| 3995 | - return $this->_template_args['success']; |
|
| 3996 | - } |
|
| 2564 | + } |
|
| 2565 | + |
|
| 2566 | + |
|
| 2567 | + /** |
|
| 2568 | + * facade for add_meta_box |
|
| 2569 | + * |
|
| 2570 | + * @param string $action where the metabox gets displayed |
|
| 2571 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2572 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2573 | + * instead of the one created in here. |
|
| 2574 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2575 | + * @param string $column what metabox column |
|
| 2576 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2577 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2578 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2579 | + * @throws DomainException |
|
| 2580 | + */ |
|
| 2581 | + public function _add_admin_page_meta_box( |
|
| 2582 | + $action, |
|
| 2583 | + $title, |
|
| 2584 | + $callback, |
|
| 2585 | + $callback_args, |
|
| 2586 | + $column = 'normal', |
|
| 2587 | + $priority = 'high', |
|
| 2588 | + $create_func = true |
|
| 2589 | + ) { |
|
| 2590 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2591 | + // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2592 | + if (empty($callback_args) && $create_func) { |
|
| 2593 | + $callback_args = [ |
|
| 2594 | + 'template_path' => $this->_template_path, |
|
| 2595 | + 'template_args' => $this->_template_args, |
|
| 2596 | + ]; |
|
| 2597 | + } |
|
| 2598 | + // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2599 | + $call_back_func = $create_func |
|
| 2600 | + ? function ($post, $metabox) { |
|
| 2601 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2602 | + echo EEH_Template::display_template( |
|
| 2603 | + $metabox['args']['template_path'], |
|
| 2604 | + $metabox['args']['template_args'], |
|
| 2605 | + true |
|
| 2606 | + ); |
|
| 2607 | + } |
|
| 2608 | + : $callback; |
|
| 2609 | + add_meta_box( |
|
| 2610 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2611 | + $title, |
|
| 2612 | + $call_back_func, |
|
| 2613 | + $this->_wp_page_slug, |
|
| 2614 | + $column, |
|
| 2615 | + $priority, |
|
| 2616 | + $callback_args |
|
| 2617 | + ); |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + |
|
| 2621 | + /** |
|
| 2622 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2623 | + * |
|
| 2624 | + * @throws DomainException |
|
| 2625 | + * @throws EE_Error |
|
| 2626 | + */ |
|
| 2627 | + public function display_admin_page_with_metabox_columns() |
|
| 2628 | + { |
|
| 2629 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2630 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2631 | + $this->_column_template_path, |
|
| 2632 | + $this->_template_args, |
|
| 2633 | + true |
|
| 2634 | + ); |
|
| 2635 | + // the final wrapper |
|
| 2636 | + $this->admin_page_wrapper(); |
|
| 2637 | + } |
|
| 2638 | + |
|
| 2639 | + |
|
| 2640 | + /** |
|
| 2641 | + * generates HTML wrapper for an admin details page |
|
| 2642 | + * |
|
| 2643 | + * @return void |
|
| 2644 | + * @throws EE_Error |
|
| 2645 | + * @throws DomainException |
|
| 2646 | + */ |
|
| 2647 | + public function display_admin_page_with_sidebar() |
|
| 2648 | + { |
|
| 2649 | + $this->_display_admin_page(true); |
|
| 2650 | + } |
|
| 2651 | + |
|
| 2652 | + |
|
| 2653 | + /** |
|
| 2654 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2655 | + * |
|
| 2656 | + * @return void |
|
| 2657 | + * @throws EE_Error |
|
| 2658 | + * @throws DomainException |
|
| 2659 | + */ |
|
| 2660 | + public function display_admin_page_with_no_sidebar() |
|
| 2661 | + { |
|
| 2662 | + $this->_display_admin_page(); |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + |
|
| 2666 | + /** |
|
| 2667 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2668 | + * |
|
| 2669 | + * @return void |
|
| 2670 | + * @throws EE_Error |
|
| 2671 | + * @throws DomainException |
|
| 2672 | + */ |
|
| 2673 | + public function display_about_admin_page() |
|
| 2674 | + { |
|
| 2675 | + $this->_display_admin_page(false, true); |
|
| 2676 | + } |
|
| 2677 | + |
|
| 2678 | + |
|
| 2679 | + /** |
|
| 2680 | + * display_admin_page |
|
| 2681 | + * contains the code for actually displaying an admin page |
|
| 2682 | + * |
|
| 2683 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2684 | + * @param boolean $about use the about_admin_wrapper instead of the default. |
|
| 2685 | + * @return void |
|
| 2686 | + * @throws DomainException |
|
| 2687 | + * @throws EE_Error |
|
| 2688 | + */ |
|
| 2689 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2690 | + { |
|
| 2691 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2692 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2693 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2694 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2695 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2696 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2697 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2698 | + ? 'poststuff' |
|
| 2699 | + : 'espresso-default-admin'; |
|
| 2700 | + $template_path = $sidebar |
|
| 2701 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2702 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2703 | + if ($this->request->isAjax()) { |
|
| 2704 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2705 | + } |
|
| 2706 | + $template_path = ! empty($this->_column_template_path) |
|
| 2707 | + ? $this->_column_template_path : $template_path; |
|
| 2708 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2709 | + ? $this->_template_args['admin_page_content'] |
|
| 2710 | + : ''; |
|
| 2711 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2712 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2713 | + : ''; |
|
| 2714 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2715 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2716 | + : ''; |
|
| 2717 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2718 | + $template_path, |
|
| 2719 | + $this->_template_args, |
|
| 2720 | + true |
|
| 2721 | + ); |
|
| 2722 | + // the final template wrapper |
|
| 2723 | + $this->admin_page_wrapper($about); |
|
| 2724 | + } |
|
| 2725 | + |
|
| 2726 | + |
|
| 2727 | + /** |
|
| 2728 | + * This is used to display caf preview pages. |
|
| 2729 | + * |
|
| 2730 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2731 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2732 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2733 | + * @return void |
|
| 2734 | + * @throws DomainException |
|
| 2735 | + * @throws EE_Error |
|
| 2736 | + * @throws InvalidArgumentException |
|
| 2737 | + * @throws InvalidDataTypeException |
|
| 2738 | + * @throws InvalidInterfaceException |
|
| 2739 | + * @since 4.3.2 |
|
| 2740 | + */ |
|
| 2741 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2742 | + { |
|
| 2743 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2744 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2745 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2746 | + 'event_espresso' |
|
| 2747 | + ); |
|
| 2748 | + $buy_now_url = add_query_arg( |
|
| 2749 | + [ |
|
| 2750 | + 'ee_ver' => 'ee4', |
|
| 2751 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2752 | + 'utm_medium' => 'link', |
|
| 2753 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2754 | + 'utm_content' => 'buy_now_button', |
|
| 2755 | + ], |
|
| 2756 | + 'https://eventespresso.com/pricing/' |
|
| 2757 | + ); |
|
| 2758 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2759 | + ? $this->get_action_link_or_button( |
|
| 2760 | + '', |
|
| 2761 | + 'buy_now', |
|
| 2762 | + [], |
|
| 2763 | + 'button-primary button-large', |
|
| 2764 | + esc_url_raw($buy_now_url), |
|
| 2765 | + true |
|
| 2766 | + ) |
|
| 2767 | + : $this->_template_args['preview_action_button']; |
|
| 2768 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2770 | + $this->_template_args, |
|
| 2771 | + true |
|
| 2772 | + ); |
|
| 2773 | + $this->_display_admin_page($display_sidebar); |
|
| 2774 | + } |
|
| 2775 | + |
|
| 2776 | + |
|
| 2777 | + /** |
|
| 2778 | + * display_admin_list_table_page_with_sidebar |
|
| 2779 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2780 | + * |
|
| 2781 | + * @return void |
|
| 2782 | + * @throws EE_Error |
|
| 2783 | + * @throws DomainException |
|
| 2784 | + */ |
|
| 2785 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2786 | + { |
|
| 2787 | + $this->_display_admin_list_table_page(true); |
|
| 2788 | + } |
|
| 2789 | + |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2793 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2794 | + * |
|
| 2795 | + * @return void |
|
| 2796 | + * @throws EE_Error |
|
| 2797 | + * @throws DomainException |
|
| 2798 | + */ |
|
| 2799 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2800 | + { |
|
| 2801 | + $this->_display_admin_list_table_page(); |
|
| 2802 | + } |
|
| 2803 | + |
|
| 2804 | + |
|
| 2805 | + /** |
|
| 2806 | + * generates html wrapper for an admin_list_table page |
|
| 2807 | + * |
|
| 2808 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2809 | + * @return void |
|
| 2810 | + * @throws DomainException |
|
| 2811 | + * @throws EE_Error |
|
| 2812 | + */ |
|
| 2813 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2814 | + { |
|
| 2815 | + // setup search attributes |
|
| 2816 | + $this->_set_search_attributes(); |
|
| 2817 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2818 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2819 | + $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2820 | + ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2821 | + : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2822 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2823 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2824 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2825 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2826 | + if (! empty($ajax_sorting_callback)) { |
|
| 2827 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2828 | + $ajax_sorting_callback . '_nonce', |
|
| 2829 | + $ajax_sorting_callback . '_nonce', |
|
| 2830 | + false, |
|
| 2831 | + false |
|
| 2832 | + ); |
|
| 2833 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2834 | + . $this->page_slug |
|
| 2835 | + . '" />'; |
|
| 2836 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2837 | + . $ajax_sorting_callback |
|
| 2838 | + . '" />'; |
|
| 2839 | + } else { |
|
| 2840 | + $sortable_list_table_form_fields = ''; |
|
| 2841 | + } |
|
| 2842 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2843 | + $hidden_form_fields = |
|
| 2844 | + isset($this->_template_args['list_table_hidden_fields']) |
|
| 2845 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 2846 | + : ''; |
|
| 2847 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2848 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 2849 | + . $nonce_ref |
|
| 2850 | + . '" value="' |
|
| 2851 | + . wp_create_nonce($nonce_ref) |
|
| 2852 | + . '">'; |
|
| 2853 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2854 | + // display message about search results? |
|
| 2855 | + $search = $this->request->getRequestParam('s'); |
|
| 2856 | + $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2857 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 2858 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2859 | + trim($search, '%') |
|
| 2860 | + ) . '</p>' |
|
| 2861 | + : ''; |
|
| 2862 | + // filter before_list_table template arg |
|
| 2863 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 2864 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2865 | + $this->_template_args['before_list_table'], |
|
| 2866 | + $this->page_slug, |
|
| 2867 | + $this->request->requestParams(), |
|
| 2868 | + $this->_req_action |
|
| 2869 | + ); |
|
| 2870 | + // convert to array and filter again |
|
| 2871 | + // arrays are easier to inject new items in a specific location, |
|
| 2872 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2873 | + $this->_template_args['before_list_table'] = implode( |
|
| 2874 | + " \n", |
|
| 2875 | + (array) apply_filters( |
|
| 2876 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2877 | + (array) $this->_template_args['before_list_table'], |
|
| 2878 | + $this->page_slug, |
|
| 2879 | + $this->request->requestParams(), |
|
| 2880 | + $this->_req_action |
|
| 2881 | + ) |
|
| 2882 | + ); |
|
| 2883 | + // filter after_list_table template arg |
|
| 2884 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 2885 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2886 | + $this->_template_args['after_list_table'], |
|
| 2887 | + $this->page_slug, |
|
| 2888 | + $this->request->requestParams(), |
|
| 2889 | + $this->_req_action |
|
| 2890 | + ); |
|
| 2891 | + // convert to array and filter again |
|
| 2892 | + // arrays are easier to inject new items in a specific location, |
|
| 2893 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2894 | + $this->_template_args['after_list_table'] = implode( |
|
| 2895 | + " \n", |
|
| 2896 | + (array) apply_filters( |
|
| 2897 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2898 | + (array) $this->_template_args['after_list_table'], |
|
| 2899 | + $this->page_slug, |
|
| 2900 | + $this->request->requestParams(), |
|
| 2901 | + $this->_req_action |
|
| 2902 | + ) |
|
| 2903 | + ); |
|
| 2904 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2905 | + $template_path, |
|
| 2906 | + $this->_template_args, |
|
| 2907 | + true |
|
| 2908 | + ); |
|
| 2909 | + // the final template wrapper |
|
| 2910 | + if ($sidebar) { |
|
| 2911 | + $this->display_admin_page_with_sidebar(); |
|
| 2912 | + } else { |
|
| 2913 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2914 | + } |
|
| 2915 | + } |
|
| 2916 | + |
|
| 2917 | + |
|
| 2918 | + /** |
|
| 2919 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 2920 | + * html string for the legend. |
|
| 2921 | + * $items are expected in an array in the following format: |
|
| 2922 | + * $legend_items = array( |
|
| 2923 | + * 'item_id' => array( |
|
| 2924 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2925 | + * 'desc' => esc_html__('localized description of item'); |
|
| 2926 | + * ) |
|
| 2927 | + * ); |
|
| 2928 | + * |
|
| 2929 | + * @param array $items see above for format of array |
|
| 2930 | + * @return string html string of legend |
|
| 2931 | + * @throws DomainException |
|
| 2932 | + */ |
|
| 2933 | + protected function _display_legend($items) |
|
| 2934 | + { |
|
| 2935 | + $this->_template_args['items'] = apply_filters( |
|
| 2936 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 2937 | + (array) $items, |
|
| 2938 | + $this |
|
| 2939 | + ); |
|
| 2940 | + return EEH_Template::display_template( |
|
| 2941 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 2942 | + $this->_template_args, |
|
| 2943 | + true |
|
| 2944 | + ); |
|
| 2945 | + } |
|
| 2946 | + |
|
| 2947 | + |
|
| 2948 | + /** |
|
| 2949 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2950 | + * The returned json object is created from an array in the following format: |
|
| 2951 | + * array( |
|
| 2952 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2953 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2954 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2955 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2956 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 2957 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 2958 | + * that might be included in here) |
|
| 2959 | + * ) |
|
| 2960 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 2961 | + * |
|
| 2962 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 2963 | + * instead of displayed. |
|
| 2964 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 2965 | + * @return void |
|
| 2966 | + * @throws EE_Error |
|
| 2967 | + */ |
|
| 2968 | + protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 2969 | + { |
|
| 2970 | + // make sure any EE_Error notices have been handled. |
|
| 2971 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 2972 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 2973 | + unset($this->_template_args['data']); |
|
| 2974 | + $json = [ |
|
| 2975 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2976 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2977 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2978 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2979 | + 'notices' => EE_Error::get_notices(), |
|
| 2980 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 2981 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 2982 | + 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 2983 | + 'isEEajax' => true |
|
| 2984 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2985 | + ]; |
|
| 2986 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2987 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 2988 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 2989 | + } |
|
| 2990 | + echo wp_json_encode($json); |
|
| 2991 | + exit(); |
|
| 2992 | + } |
|
| 2993 | + |
|
| 2994 | + |
|
| 2995 | + /** |
|
| 2996 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2997 | + * |
|
| 2998 | + * @return void |
|
| 2999 | + * @throws EE_Error |
|
| 3000 | + */ |
|
| 3001 | + public function return_json() |
|
| 3002 | + { |
|
| 3003 | + if ($this->request->isAjax()) { |
|
| 3004 | + $this->_return_json(); |
|
| 3005 | + } else { |
|
| 3006 | + throw new EE_Error( |
|
| 3007 | + sprintf( |
|
| 3008 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3009 | + __FUNCTION__ |
|
| 3010 | + ) |
|
| 3011 | + ); |
|
| 3012 | + } |
|
| 3013 | + } |
|
| 3014 | + |
|
| 3015 | + |
|
| 3016 | + /** |
|
| 3017 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3018 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3019 | + * |
|
| 3020 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3021 | + */ |
|
| 3022 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3023 | + { |
|
| 3024 | + $this->_hook_obj = $hook_obj; |
|
| 3025 | + } |
|
| 3026 | + |
|
| 3027 | + |
|
| 3028 | + /** |
|
| 3029 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3030 | + * |
|
| 3031 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3032 | + * @return void |
|
| 3033 | + * @throws DomainException |
|
| 3034 | + * @throws EE_Error |
|
| 3035 | + */ |
|
| 3036 | + public function admin_page_wrapper($about = false) |
|
| 3037 | + { |
|
| 3038 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3039 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3040 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3041 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3042 | + |
|
| 3043 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3044 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3045 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3046 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3047 | + : '' |
|
| 3048 | + ); |
|
| 3049 | + |
|
| 3050 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3051 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3052 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3053 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3054 | + : '' |
|
| 3055 | + ); |
|
| 3056 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3057 | + |
|
| 3058 | + if ($this->request->isAjax()) { |
|
| 3059 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3060 | + // $template_path, |
|
| 3061 | + EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3062 | + $this->_template_args, |
|
| 3063 | + true |
|
| 3064 | + ); |
|
| 3065 | + $this->_return_json(); |
|
| 3066 | + } |
|
| 3067 | + // load settings page wrapper template |
|
| 3068 | + $template_path = $about |
|
| 3069 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3070 | + : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3071 | + |
|
| 3072 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3073 | + } |
|
| 3074 | + |
|
| 3075 | + |
|
| 3076 | + /** |
|
| 3077 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3078 | + * |
|
| 3079 | + * @return string html |
|
| 3080 | + * @throws EE_Error |
|
| 3081 | + */ |
|
| 3082 | + protected function _get_main_nav_tabs() |
|
| 3083 | + { |
|
| 3084 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3085 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3086 | + // (rather than setting in the page_routes array) |
|
| 3087 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3088 | + } |
|
| 3089 | + |
|
| 3090 | + |
|
| 3091 | + /** |
|
| 3092 | + * sort nav tabs |
|
| 3093 | + * |
|
| 3094 | + * @param $a |
|
| 3095 | + * @param $b |
|
| 3096 | + * @return int |
|
| 3097 | + */ |
|
| 3098 | + private function _sort_nav_tabs($a, $b) |
|
| 3099 | + { |
|
| 3100 | + if ($a['order'] === $b['order']) { |
|
| 3101 | + return 0; |
|
| 3102 | + } |
|
| 3103 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3104 | + } |
|
| 3105 | + |
|
| 3106 | + |
|
| 3107 | + /** |
|
| 3108 | + * generates HTML for the forms used on admin pages |
|
| 3109 | + * |
|
| 3110 | + * @param array $input_vars - array of input field details |
|
| 3111 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3112 | + * use) |
|
| 3113 | + * @param bool $id |
|
| 3114 | + * @return array|string |
|
| 3115 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3116 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3117 | + */ |
|
| 3118 | + protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3119 | + { |
|
| 3120 | + return $generator === 'string' |
|
| 3121 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3122 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3123 | + } |
|
| 3124 | + |
|
| 3125 | + |
|
| 3126 | + /** |
|
| 3127 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3128 | + * |
|
| 3129 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3130 | + * Close" button. |
|
| 3131 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3132 | + * 'Save', [1] => 'save & close') |
|
| 3133 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3134 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3135 | + * default actions by submitting some other value. |
|
| 3136 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3137 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3138 | + * close (normal form handling). |
|
| 3139 | + */ |
|
| 3140 | + protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3141 | + { |
|
| 3142 | + // make sure $text and $actions are in an array |
|
| 3143 | + $text = (array) $text; |
|
| 3144 | + $actions = (array) $actions; |
|
| 3145 | + $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3146 | + $button_text = ! empty($text) |
|
| 3147 | + ? $text |
|
| 3148 | + : [ |
|
| 3149 | + esc_html__('Save', 'event_espresso'), |
|
| 3150 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3151 | + ]; |
|
| 3152 | + $default_names = ['save', 'save_and_close']; |
|
| 3153 | + $buttons = ''; |
|
| 3154 | + foreach ($button_text as $key => $button) { |
|
| 3155 | + $ref = $default_names[ $key ]; |
|
| 3156 | + $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3157 | + $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
| 3158 | + . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3159 | + . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3160 | + if (! $both) { |
|
| 3161 | + break; |
|
| 3162 | + } |
|
| 3163 | + } |
|
| 3164 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3165 | + $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3166 | + . $referrer_url |
|
| 3167 | + . '" />'; |
|
| 3168 | + $this->_template_args['save_buttons'] = $buttons; |
|
| 3169 | + } |
|
| 3170 | + |
|
| 3171 | + |
|
| 3172 | + /** |
|
| 3173 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3174 | + * |
|
| 3175 | + * @param string $route |
|
| 3176 | + * @param array $additional_hidden_fields |
|
| 3177 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3178 | + * @since 4.6.0 |
|
| 3179 | + */ |
|
| 3180 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3181 | + { |
|
| 3182 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3183 | + } |
|
| 3184 | + |
|
| 3185 | + |
|
| 3186 | + /** |
|
| 3187 | + * set form open and close tags on add/edit pages. |
|
| 3188 | + * |
|
| 3189 | + * @param string $route the route you want the form to direct to |
|
| 3190 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3191 | + * @return void |
|
| 3192 | + */ |
|
| 3193 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3194 | + { |
|
| 3195 | + if (empty($route)) { |
|
| 3196 | + $user_msg = esc_html__( |
|
| 3197 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3198 | + 'event_espresso' |
|
| 3199 | + ); |
|
| 3200 | + $dev_msg = $user_msg . "\n" |
|
| 3201 | + . sprintf( |
|
| 3202 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3203 | + __FUNCTION__, |
|
| 3204 | + __CLASS__ |
|
| 3205 | + ); |
|
| 3206 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3207 | + } |
|
| 3208 | + // open form |
|
| 3209 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3210 | + . $this->_admin_base_url |
|
| 3211 | + . '" id="' |
|
| 3212 | + . $route |
|
| 3213 | + . '_event_form" >'; |
|
| 3214 | + // add nonce |
|
| 3215 | + $nonce = |
|
| 3216 | + wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3217 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3218 | + // add REQUIRED form action |
|
| 3219 | + $hidden_fields = [ |
|
| 3220 | + 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3221 | + ]; |
|
| 3222 | + // merge arrays |
|
| 3223 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3224 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3225 | + : $hidden_fields; |
|
| 3226 | + // generate form fields |
|
| 3227 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3228 | + // add fields to form |
|
| 3229 | + foreach ((array) $form_fields as $form_field) { |
|
| 3230 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3231 | + } |
|
| 3232 | + // close form |
|
| 3233 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3234 | + } |
|
| 3235 | + |
|
| 3236 | + |
|
| 3237 | + /** |
|
| 3238 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3239 | + * discovered it would be useful for external code to have access. |
|
| 3240 | + * |
|
| 3241 | + * @param bool $success |
|
| 3242 | + * @param string $what |
|
| 3243 | + * @param string $action_desc |
|
| 3244 | + * @param array $query_args |
|
| 3245 | + * @param bool $override_overwrite |
|
| 3246 | + * @throws EE_Error |
|
| 3247 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3248 | + * @since 4.5.0 |
|
| 3249 | + */ |
|
| 3250 | + public function redirect_after_action( |
|
| 3251 | + $success = false, |
|
| 3252 | + $what = 'item', |
|
| 3253 | + $action_desc = 'processed', |
|
| 3254 | + $query_args = [], |
|
| 3255 | + $override_overwrite = false |
|
| 3256 | + ) { |
|
| 3257 | + $this->_redirect_after_action( |
|
| 3258 | + $success, |
|
| 3259 | + $what, |
|
| 3260 | + $action_desc, |
|
| 3261 | + $query_args, |
|
| 3262 | + $override_overwrite |
|
| 3263 | + ); |
|
| 3264 | + } |
|
| 3265 | + |
|
| 3266 | + |
|
| 3267 | + /** |
|
| 3268 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3269 | + * |
|
| 3270 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3271 | + * filters are still applied. |
|
| 3272 | + * |
|
| 3273 | + * @param array $new_route_data |
|
| 3274 | + * @return array |
|
| 3275 | + */ |
|
| 3276 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3277 | + { |
|
| 3278 | + foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3279 | + // unset nonces |
|
| 3280 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3281 | + $this->request->unSetRequestParam($ref); |
|
| 3282 | + continue; |
|
| 3283 | + } |
|
| 3284 | + // urlencode values. |
|
| 3285 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3286 | + $this->request->setRequestParam($ref, $value); |
|
| 3287 | + } |
|
| 3288 | + return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3289 | + } |
|
| 3290 | + |
|
| 3291 | + |
|
| 3292 | + /** |
|
| 3293 | + * _redirect_after_action |
|
| 3294 | + * |
|
| 3295 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3296 | + * @param string $what - what the action was performed on |
|
| 3297 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3298 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3299 | + * action is completed |
|
| 3300 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3301 | + * override this so that they show. |
|
| 3302 | + * @return void |
|
| 3303 | + * @throws EE_Error |
|
| 3304 | + */ |
|
| 3305 | + protected function _redirect_after_action( |
|
| 3306 | + $success = 0, |
|
| 3307 | + $what = 'item', |
|
| 3308 | + $action_desc = 'processed', |
|
| 3309 | + $query_args = [], |
|
| 3310 | + $override_overwrite = false |
|
| 3311 | + ) { |
|
| 3312 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3313 | + // class name for actions/filters. |
|
| 3314 | + $classname = get_class($this); |
|
| 3315 | + // set redirect url. |
|
| 3316 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3317 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3318 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3319 | + $notices = EE_Error::get_notices(false); |
|
| 3320 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3321 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3322 | + EE_Error::overwrite_success(); |
|
| 3323 | + } |
|
| 3324 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3325 | + // how many records affected ? more than one record ? or just one ? |
|
| 3326 | + if ($success > 1) { |
|
| 3327 | + // set plural msg |
|
| 3328 | + EE_Error::add_success( |
|
| 3329 | + sprintf( |
|
| 3330 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3331 | + $what, |
|
| 3332 | + $action_desc |
|
| 3333 | + ), |
|
| 3334 | + __FILE__, |
|
| 3335 | + __FUNCTION__, |
|
| 3336 | + __LINE__ |
|
| 3337 | + ); |
|
| 3338 | + } elseif ($success === 1) { |
|
| 3339 | + // set singular msg |
|
| 3340 | + EE_Error::add_success( |
|
| 3341 | + sprintf( |
|
| 3342 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3343 | + $what, |
|
| 3344 | + $action_desc |
|
| 3345 | + ), |
|
| 3346 | + __FILE__, |
|
| 3347 | + __FUNCTION__, |
|
| 3348 | + __LINE__ |
|
| 3349 | + ); |
|
| 3350 | + } |
|
| 3351 | + } |
|
| 3352 | + // check that $query_args isn't something crazy |
|
| 3353 | + if (! is_array($query_args)) { |
|
| 3354 | + $query_args = []; |
|
| 3355 | + } |
|
| 3356 | + /** |
|
| 3357 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3358 | + * redirections on save and close actions |
|
| 3359 | + * |
|
| 3360 | + * @param array $query_args The original query_args array coming into the |
|
| 3361 | + * method. |
|
| 3362 | + * @since 4.2.0 |
|
| 3363 | + */ |
|
| 3364 | + do_action( |
|
| 3365 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3366 | + $query_args |
|
| 3367 | + ); |
|
| 3368 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3369 | + |
|
| 3370 | + if ( |
|
| 3371 | + $this->request->requestParamIsSet('save_and_close') |
|
| 3372 | + && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3373 | + ) { |
|
| 3374 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3375 | + $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3376 | + // regenerate query args array from referrer URL |
|
| 3377 | + parse_str($parsed_url['query'], $query_args); |
|
| 3378 | + // correct page and action will be in the query args now |
|
| 3379 | + $redirect_url = admin_url('admin.php'); |
|
| 3380 | + } |
|
| 3381 | + // merge any default query_args set in _default_route_query_args property |
|
| 3382 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3383 | + $args_to_merge = []; |
|
| 3384 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3385 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3386 | + if ($query_param === 'wp_referer') { |
|
| 3387 | + $query_value = (array) $query_value; |
|
| 3388 | + foreach ($query_value as $reference => $value) { |
|
| 3389 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3390 | + continue; |
|
| 3391 | + } |
|
| 3392 | + // finally we will override any arguments in the referer with |
|
| 3393 | + // what might be set on the _default_route_query_args array. |
|
| 3394 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3395 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3396 | + } else { |
|
| 3397 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3398 | + } |
|
| 3399 | + } |
|
| 3400 | + continue; |
|
| 3401 | + } |
|
| 3402 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3403 | + } |
|
| 3404 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3405 | + // redirect. |
|
| 3406 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3407 | + } |
|
| 3408 | + $this->_process_notices($query_args); |
|
| 3409 | + // generate redirect url |
|
| 3410 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3411 | + if (isset($query_args['action'])) { |
|
| 3412 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3413 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3414 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3415 | + } |
|
| 3416 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3417 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3418 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3419 | + $redirect_url = apply_filters( |
|
| 3420 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3421 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3422 | + $query_args |
|
| 3423 | + ); |
|
| 3424 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3425 | + if ($this->request->isAjax()) { |
|
| 3426 | + $default_data = [ |
|
| 3427 | + 'close' => true, |
|
| 3428 | + 'redirect_url' => $redirect_url, |
|
| 3429 | + 'where' => 'main', |
|
| 3430 | + 'what' => 'append', |
|
| 3431 | + ]; |
|
| 3432 | + $this->_template_args['success'] = $success; |
|
| 3433 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3434 | + $default_data, |
|
| 3435 | + $this->_template_args['data'] |
|
| 3436 | + ) : $default_data; |
|
| 3437 | + $this->_return_json(); |
|
| 3438 | + } |
|
| 3439 | + wp_safe_redirect($redirect_url); |
|
| 3440 | + exit(); |
|
| 3441 | + } |
|
| 3442 | + |
|
| 3443 | + |
|
| 3444 | + /** |
|
| 3445 | + * process any notices before redirecting (or returning ajax request) |
|
| 3446 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3447 | + * |
|
| 3448 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3449 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3450 | + * page_routes haven't been defined yet. |
|
| 3451 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3452 | + * still save a transient for the notice. |
|
| 3453 | + * @return void |
|
| 3454 | + * @throws EE_Error |
|
| 3455 | + */ |
|
| 3456 | + protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3457 | + { |
|
| 3458 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3459 | + if ($this->request->isAjax()) { |
|
| 3460 | + $notices = EE_Error::get_notices(false); |
|
| 3461 | + if (empty($this->_template_args['success'])) { |
|
| 3462 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3463 | + } |
|
| 3464 | + if (empty($this->_template_args['errors'])) { |
|
| 3465 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3466 | + } |
|
| 3467 | + if (empty($this->_template_args['attention'])) { |
|
| 3468 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3469 | + } |
|
| 3470 | + } |
|
| 3471 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3472 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3473 | + if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3474 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3475 | + $this->_add_transient( |
|
| 3476 | + $route, |
|
| 3477 | + $this->_template_args['notices'], |
|
| 3478 | + true, |
|
| 3479 | + $skip_route_verify |
|
| 3480 | + ); |
|
| 3481 | + } |
|
| 3482 | + } |
|
| 3483 | + |
|
| 3484 | + |
|
| 3485 | + /** |
|
| 3486 | + * get_action_link_or_button |
|
| 3487 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3488 | + * |
|
| 3489 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3490 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3491 | + * property. |
|
| 3492 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3493 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3494 | + * @param string $base_url If this is not provided |
|
| 3495 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3496 | + * Otherwise this value will be used. |
|
| 3497 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3498 | + * @return string |
|
| 3499 | + * @throws InvalidArgumentException |
|
| 3500 | + * @throws InvalidInterfaceException |
|
| 3501 | + * @throws InvalidDataTypeException |
|
| 3502 | + * @throws EE_Error |
|
| 3503 | + */ |
|
| 3504 | + public function get_action_link_or_button( |
|
| 3505 | + $action, |
|
| 3506 | + $type = 'add', |
|
| 3507 | + $extra_request = [], |
|
| 3508 | + $class = 'button-primary', |
|
| 3509 | + $base_url = '', |
|
| 3510 | + $exclude_nonce = false |
|
| 3511 | + ) { |
|
| 3512 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3513 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3514 | + throw new EE_Error( |
|
| 3515 | + sprintf( |
|
| 3516 | + esc_html__( |
|
| 3517 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3518 | + 'event_espresso' |
|
| 3519 | + ), |
|
| 3520 | + $action |
|
| 3521 | + ) |
|
| 3522 | + ); |
|
| 3523 | + } |
|
| 3524 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3525 | + throw new EE_Error( |
|
| 3526 | + sprintf( |
|
| 3527 | + esc_html__( |
|
| 3528 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3529 | + 'event_espresso' |
|
| 3530 | + ), |
|
| 3531 | + $type |
|
| 3532 | + ) |
|
| 3533 | + ); |
|
| 3534 | + } |
|
| 3535 | + // finally check user access for this button. |
|
| 3536 | + $has_access = $this->check_user_access($action, true); |
|
| 3537 | + if (! $has_access) { |
|
| 3538 | + return ''; |
|
| 3539 | + } |
|
| 3540 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3541 | + $query_args = [ |
|
| 3542 | + 'action' => $action, |
|
| 3543 | + ]; |
|
| 3544 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3545 | + if (! empty($extra_request)) { |
|
| 3546 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3547 | + } |
|
| 3548 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3549 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3550 | + } |
|
| 3551 | + |
|
| 3552 | + |
|
| 3553 | + /** |
|
| 3554 | + * _per_page_screen_option |
|
| 3555 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3556 | + * |
|
| 3557 | + * @return void |
|
| 3558 | + * @throws InvalidArgumentException |
|
| 3559 | + * @throws InvalidInterfaceException |
|
| 3560 | + * @throws InvalidDataTypeException |
|
| 3561 | + */ |
|
| 3562 | + protected function _per_page_screen_option() |
|
| 3563 | + { |
|
| 3564 | + $option = 'per_page'; |
|
| 3565 | + $args = [ |
|
| 3566 | + 'label' => apply_filters( |
|
| 3567 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3568 | + $this->_admin_page_title, |
|
| 3569 | + $this |
|
| 3570 | + ), |
|
| 3571 | + 'default' => (int) apply_filters( |
|
| 3572 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3573 | + 20 |
|
| 3574 | + ), |
|
| 3575 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3576 | + ]; |
|
| 3577 | + // ONLY add the screen option if the user has access to it. |
|
| 3578 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3579 | + add_screen_option($option, $args); |
|
| 3580 | + } |
|
| 3581 | + } |
|
| 3582 | + |
|
| 3583 | + |
|
| 3584 | + /** |
|
| 3585 | + * set_per_page_screen_option |
|
| 3586 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3587 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3588 | + * admin_menu. |
|
| 3589 | + * |
|
| 3590 | + * @return void |
|
| 3591 | + */ |
|
| 3592 | + private function _set_per_page_screen_options() |
|
| 3593 | + { |
|
| 3594 | + if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3595 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3596 | + if (! $user = wp_get_current_user()) { |
|
| 3597 | + return; |
|
| 3598 | + } |
|
| 3599 | + $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3600 | + if (! $option) { |
|
| 3601 | + return; |
|
| 3602 | + } |
|
| 3603 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3604 | + $map_option = $option; |
|
| 3605 | + $option = str_replace('-', '_', $option); |
|
| 3606 | + switch ($map_option) { |
|
| 3607 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3608 | + $max_value = apply_filters( |
|
| 3609 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3610 | + 999, |
|
| 3611 | + $this->_current_page, |
|
| 3612 | + $this->_current_view |
|
| 3613 | + ); |
|
| 3614 | + if ($value < 1) { |
|
| 3615 | + return; |
|
| 3616 | + } |
|
| 3617 | + $value = min($value, $max_value); |
|
| 3618 | + break; |
|
| 3619 | + default: |
|
| 3620 | + $value = apply_filters( |
|
| 3621 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3622 | + false, |
|
| 3623 | + $option, |
|
| 3624 | + $value |
|
| 3625 | + ); |
|
| 3626 | + if (false === $value) { |
|
| 3627 | + return; |
|
| 3628 | + } |
|
| 3629 | + break; |
|
| 3630 | + } |
|
| 3631 | + update_user_meta($user->ID, $option, $value); |
|
| 3632 | + wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3633 | + exit; |
|
| 3634 | + } |
|
| 3635 | + } |
|
| 3636 | + |
|
| 3637 | + |
|
| 3638 | + /** |
|
| 3639 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3640 | + * |
|
| 3641 | + * @param array $data array that will be assigned to template args. |
|
| 3642 | + */ |
|
| 3643 | + public function set_template_args($data) |
|
| 3644 | + { |
|
| 3645 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3646 | + } |
|
| 3647 | + |
|
| 3648 | + |
|
| 3649 | + /** |
|
| 3650 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3651 | + * |
|
| 3652 | + * @param string $route the route that should receive the transient |
|
| 3653 | + * @param array $data the data that gets sent |
|
| 3654 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3655 | + * normal route transient. |
|
| 3656 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3657 | + * when we are adding a transient before page_routes have been defined. |
|
| 3658 | + * @return void |
|
| 3659 | + * @throws EE_Error |
|
| 3660 | + */ |
|
| 3661 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3662 | + { |
|
| 3663 | + $user_id = get_current_user_id(); |
|
| 3664 | + if (! $skip_route_verify) { |
|
| 3665 | + $this->_verify_route($route); |
|
| 3666 | + } |
|
| 3667 | + // now let's set the string for what kind of transient we're setting |
|
| 3668 | + $transient = $notices |
|
| 3669 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3670 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3671 | + $data = $notices ? ['notices' => $data] : $data; |
|
| 3672 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3673 | + $existing = is_multisite() && is_network_admin() |
|
| 3674 | + ? get_site_transient($transient) |
|
| 3675 | + : get_transient($transient); |
|
| 3676 | + if ($existing) { |
|
| 3677 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3678 | + } |
|
| 3679 | + if (is_multisite() && is_network_admin()) { |
|
| 3680 | + set_site_transient($transient, $data, 8); |
|
| 3681 | + } else { |
|
| 3682 | + set_transient($transient, $data, 8); |
|
| 3683 | + } |
|
| 3684 | + } |
|
| 3685 | + |
|
| 3686 | + |
|
| 3687 | + /** |
|
| 3688 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3689 | + * |
|
| 3690 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3691 | + * @param string $route |
|
| 3692 | + * @return mixed data |
|
| 3693 | + */ |
|
| 3694 | + protected function _get_transient($notices = false, $route = '') |
|
| 3695 | + { |
|
| 3696 | + $user_id = get_current_user_id(); |
|
| 3697 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3698 | + $transient = $notices |
|
| 3699 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3700 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3701 | + $data = is_multisite() && is_network_admin() |
|
| 3702 | + ? get_site_transient($transient) |
|
| 3703 | + : get_transient($transient); |
|
| 3704 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3705 | + if (is_multisite() && is_network_admin()) { |
|
| 3706 | + delete_site_transient($transient); |
|
| 3707 | + } else { |
|
| 3708 | + delete_transient($transient); |
|
| 3709 | + } |
|
| 3710 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3711 | + } |
|
| 3712 | + |
|
| 3713 | + |
|
| 3714 | + /** |
|
| 3715 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3716 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3717 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3718 | + * |
|
| 3719 | + * @return void |
|
| 3720 | + */ |
|
| 3721 | + protected function _transient_garbage_collection() |
|
| 3722 | + { |
|
| 3723 | + global $wpdb; |
|
| 3724 | + // retrieve all existing transients |
|
| 3725 | + $query = |
|
| 3726 | + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3727 | + if ($results = $wpdb->get_results($query)) { |
|
| 3728 | + foreach ($results as $result) { |
|
| 3729 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3730 | + get_transient($transient); |
|
| 3731 | + if (is_multisite() && is_network_admin()) { |
|
| 3732 | + get_site_transient($transient); |
|
| 3733 | + } |
|
| 3734 | + } |
|
| 3735 | + } |
|
| 3736 | + } |
|
| 3737 | + |
|
| 3738 | + |
|
| 3739 | + /** |
|
| 3740 | + * get_view |
|
| 3741 | + * |
|
| 3742 | + * @return string content of _view property |
|
| 3743 | + */ |
|
| 3744 | + public function get_view() |
|
| 3745 | + { |
|
| 3746 | + return $this->_view; |
|
| 3747 | + } |
|
| 3748 | + |
|
| 3749 | + |
|
| 3750 | + /** |
|
| 3751 | + * getter for the protected $_views property |
|
| 3752 | + * |
|
| 3753 | + * @return array |
|
| 3754 | + */ |
|
| 3755 | + public function get_views() |
|
| 3756 | + { |
|
| 3757 | + return $this->_views; |
|
| 3758 | + } |
|
| 3759 | + |
|
| 3760 | + |
|
| 3761 | + /** |
|
| 3762 | + * get_current_page |
|
| 3763 | + * |
|
| 3764 | + * @return string _current_page property value |
|
| 3765 | + */ |
|
| 3766 | + public function get_current_page() |
|
| 3767 | + { |
|
| 3768 | + return $this->_current_page; |
|
| 3769 | + } |
|
| 3770 | + |
|
| 3771 | + |
|
| 3772 | + /** |
|
| 3773 | + * get_current_view |
|
| 3774 | + * |
|
| 3775 | + * @return string _current_view property value |
|
| 3776 | + */ |
|
| 3777 | + public function get_current_view() |
|
| 3778 | + { |
|
| 3779 | + return $this->_current_view; |
|
| 3780 | + } |
|
| 3781 | + |
|
| 3782 | + |
|
| 3783 | + /** |
|
| 3784 | + * get_current_screen |
|
| 3785 | + * |
|
| 3786 | + * @return object The current WP_Screen object |
|
| 3787 | + */ |
|
| 3788 | + public function get_current_screen() |
|
| 3789 | + { |
|
| 3790 | + return $this->_current_screen; |
|
| 3791 | + } |
|
| 3792 | + |
|
| 3793 | + |
|
| 3794 | + /** |
|
| 3795 | + * get_current_page_view_url |
|
| 3796 | + * |
|
| 3797 | + * @return string This returns the url for the current_page_view. |
|
| 3798 | + */ |
|
| 3799 | + public function get_current_page_view_url() |
|
| 3800 | + { |
|
| 3801 | + return $this->_current_page_view_url; |
|
| 3802 | + } |
|
| 3803 | + |
|
| 3804 | + |
|
| 3805 | + /** |
|
| 3806 | + * just returns the Request |
|
| 3807 | + * |
|
| 3808 | + * @return RequestInterface |
|
| 3809 | + */ |
|
| 3810 | + public function get_request() |
|
| 3811 | + { |
|
| 3812 | + return $this->request; |
|
| 3813 | + } |
|
| 3814 | + |
|
| 3815 | + |
|
| 3816 | + /** |
|
| 3817 | + * just returns the _req_data property |
|
| 3818 | + * |
|
| 3819 | + * @return array |
|
| 3820 | + */ |
|
| 3821 | + public function get_request_data() |
|
| 3822 | + { |
|
| 3823 | + return $this->request->requestParams(); |
|
| 3824 | + } |
|
| 3825 | + |
|
| 3826 | + |
|
| 3827 | + /** |
|
| 3828 | + * returns the _req_data protected property |
|
| 3829 | + * |
|
| 3830 | + * @return string |
|
| 3831 | + */ |
|
| 3832 | + public function get_req_action() |
|
| 3833 | + { |
|
| 3834 | + return $this->_req_action; |
|
| 3835 | + } |
|
| 3836 | + |
|
| 3837 | + |
|
| 3838 | + /** |
|
| 3839 | + * @return bool value of $_is_caf property |
|
| 3840 | + */ |
|
| 3841 | + public function is_caf() |
|
| 3842 | + { |
|
| 3843 | + return $this->_is_caf; |
|
| 3844 | + } |
|
| 3845 | + |
|
| 3846 | + |
|
| 3847 | + /** |
|
| 3848 | + * @return mixed |
|
| 3849 | + */ |
|
| 3850 | + public function default_espresso_metaboxes() |
|
| 3851 | + { |
|
| 3852 | + return $this->_default_espresso_metaboxes; |
|
| 3853 | + } |
|
| 3854 | + |
|
| 3855 | + |
|
| 3856 | + /** |
|
| 3857 | + * @return mixed |
|
| 3858 | + */ |
|
| 3859 | + public function admin_base_url() |
|
| 3860 | + { |
|
| 3861 | + return $this->_admin_base_url; |
|
| 3862 | + } |
|
| 3863 | + |
|
| 3864 | + |
|
| 3865 | + /** |
|
| 3866 | + * @return mixed |
|
| 3867 | + */ |
|
| 3868 | + public function wp_page_slug() |
|
| 3869 | + { |
|
| 3870 | + return $this->_wp_page_slug; |
|
| 3871 | + } |
|
| 3872 | + |
|
| 3873 | + |
|
| 3874 | + /** |
|
| 3875 | + * updates espresso configuration settings |
|
| 3876 | + * |
|
| 3877 | + * @param string $tab |
|
| 3878 | + * @param EE_Config_Base|EE_Config $config |
|
| 3879 | + * @param string $file file where error occurred |
|
| 3880 | + * @param string $func function where error occurred |
|
| 3881 | + * @param string $line line no where error occurred |
|
| 3882 | + * @return boolean |
|
| 3883 | + */ |
|
| 3884 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3885 | + { |
|
| 3886 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 3887 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 3888 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3889 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3890 | + update_option('ee_ueip_has_notified', true); |
|
| 3891 | + } |
|
| 3892 | + // and save it (note we're also doing the network save here) |
|
| 3893 | + $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 3894 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3895 | + if ($config_saved && $net_saved) { |
|
| 3896 | + EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3897 | + return true; |
|
| 3898 | + } |
|
| 3899 | + EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3900 | + return false; |
|
| 3901 | + } |
|
| 3902 | + |
|
| 3903 | + |
|
| 3904 | + /** |
|
| 3905 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3906 | + * |
|
| 3907 | + * @return array |
|
| 3908 | + */ |
|
| 3909 | + public function get_yes_no_values() |
|
| 3910 | + { |
|
| 3911 | + return $this->_yes_no_values; |
|
| 3912 | + } |
|
| 3913 | + |
|
| 3914 | + |
|
| 3915 | + protected function _get_dir() |
|
| 3916 | + { |
|
| 3917 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 3918 | + return dirname($reflector->getFileName()); |
|
| 3919 | + } |
|
| 3920 | + |
|
| 3921 | + |
|
| 3922 | + /** |
|
| 3923 | + * A helper for getting a "next link". |
|
| 3924 | + * |
|
| 3925 | + * @param string $url The url to link to |
|
| 3926 | + * @param string $class The class to use. |
|
| 3927 | + * @return string |
|
| 3928 | + */ |
|
| 3929 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3930 | + { |
|
| 3931 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3932 | + } |
|
| 3933 | + |
|
| 3934 | + |
|
| 3935 | + /** |
|
| 3936 | + * A helper for getting a "previous link". |
|
| 3937 | + * |
|
| 3938 | + * @param string $url The url to link to |
|
| 3939 | + * @param string $class The class to use. |
|
| 3940 | + * @return string |
|
| 3941 | + */ |
|
| 3942 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3943 | + { |
|
| 3944 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3945 | + } |
|
| 3946 | + |
|
| 3947 | + |
|
| 3948 | + |
|
| 3949 | + |
|
| 3950 | + |
|
| 3951 | + |
|
| 3952 | + |
|
| 3953 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3954 | + |
|
| 3955 | + |
|
| 3956 | + /** |
|
| 3957 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 3958 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 3959 | + * _req_data array. |
|
| 3960 | + * |
|
| 3961 | + * @return bool success/fail |
|
| 3962 | + * @throws EE_Error |
|
| 3963 | + * @throws InvalidArgumentException |
|
| 3964 | + * @throws ReflectionException |
|
| 3965 | + * @throws InvalidDataTypeException |
|
| 3966 | + * @throws InvalidInterfaceException |
|
| 3967 | + */ |
|
| 3968 | + protected function _process_resend_registration() |
|
| 3969 | + { |
|
| 3970 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3971 | + do_action( |
|
| 3972 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 3973 | + $this->_template_args['success'], |
|
| 3974 | + $this->request->requestParams() |
|
| 3975 | + ); |
|
| 3976 | + return $this->_template_args['success']; |
|
| 3977 | + } |
|
| 3978 | + |
|
| 3979 | + |
|
| 3980 | + /** |
|
| 3981 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3982 | + * |
|
| 3983 | + * @param EE_Payment $payment |
|
| 3984 | + * @return bool success/fail |
|
| 3985 | + */ |
|
| 3986 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 3987 | + { |
|
| 3988 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3989 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3990 | + $this->_template_args['success'] = apply_filters( |
|
| 3991 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 3992 | + false, |
|
| 3993 | + $payment |
|
| 3994 | + ); |
|
| 3995 | + return $this->_template_args['success']; |
|
| 3996 | + } |
|
| 3997 | 3997 | } |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 515 | 515 | if ( |
| 516 | 516 | ! $this->request->isAjax() |
| 517 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 517 | + && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) |
|
| 518 | 518 | ) { |
| 519 | 519 | return; |
| 520 | 520 | } |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | : $req_action; |
| 535 | 535 | |
| 536 | 536 | $this->_current_view = $this->_req_action; |
| 537 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 537 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 538 | 538 | $this->_define_page_props(); |
| 539 | 539 | $this->_current_page_view_url = add_query_arg( |
| 540 | 540 | ['page' => $this->_current_page, 'action' => $this->_current_view], |
@@ -571,21 +571,21 @@ discard block |
||
| 571 | 571 | } |
| 572 | 572 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 573 | 573 | $this->_page_routes = apply_filters( |
| 574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 574 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
| 575 | 575 | $this->_page_routes, |
| 576 | 576 | $this |
| 577 | 577 | ); |
| 578 | 578 | $this->_page_config = apply_filters( |
| 579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 579 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
| 580 | 580 | $this->_page_config, |
| 581 | 581 | $this |
| 582 | 582 | ); |
| 583 | 583 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 584 | 584 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 585 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 585 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 586 | 586 | add_action( |
| 587 | 587 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 588 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 588 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view], |
|
| 589 | 589 | 10, |
| 590 | 590 | 2 |
| 591 | 591 | ); |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | if ($this->_is_UI_request) { |
| 599 | 599 | // admin_init stuff - global, all views for this page class, specific view |
| 600 | 600 | add_action('admin_init', [$this, 'admin_init'], 10); |
| 601 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 602 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 601 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 602 | + add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15); |
|
| 603 | 603 | } |
| 604 | 604 | } else { |
| 605 | 605 | // hijack regular WP loading and route admin request immediately |
@@ -618,12 +618,12 @@ discard block |
||
| 618 | 618 | */ |
| 619 | 619 | private function _do_other_page_hooks() |
| 620 | 620 | { |
| 621 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 621 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []); |
|
| 622 | 622 | foreach ($registered_pages as $page) { |
| 623 | 623 | // now let's setup the file name and class that should be present |
| 624 | 624 | $classname = str_replace('.class.php', '', $page); |
| 625 | 625 | // autoloaders should take care of loading file |
| 626 | - if (! class_exists($classname)) { |
|
| 626 | + if ( ! class_exists($classname)) { |
|
| 627 | 627 | $error_msg[] = sprintf( |
| 628 | 628 | esc_html__( |
| 629 | 629 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | ), |
| 641 | 641 | $page, |
| 642 | 642 | '<br />', |
| 643 | - '<strong>' . $classname . '</strong>' |
|
| 643 | + '<strong>'.$classname.'</strong>' |
|
| 644 | 644 | ); |
| 645 | 645 | throw new EE_Error(implode('||', $error_msg)); |
| 646 | 646 | } |
@@ -682,13 +682,13 @@ discard block |
||
| 682 | 682 | // load admin_notices - global, page class, and view specific |
| 683 | 683 | add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
| 684 | 684 | add_action('admin_notices', [$this, 'admin_notices'], 10); |
| 685 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 686 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 685 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 686 | + add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15); |
|
| 687 | 687 | } |
| 688 | 688 | // load network admin_notices - global, page class, and view specific |
| 689 | 689 | add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
| 690 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 691 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 690 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 691 | + add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]); |
|
| 692 | 692 | } |
| 693 | 693 | // this will save any per_page screen options if they are present |
| 694 | 694 | $this->_set_per_page_screen_options(); |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | protected function _verify_routes() |
| 810 | 810 | { |
| 811 | 811 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 812 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 812 | + if ( ! $this->_current_page && ! $this->request->isAjax()) { |
|
| 813 | 813 | return false; |
| 814 | 814 | } |
| 815 | 815 | $this->_route = false; |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | $this->_admin_page_title |
| 822 | 822 | ); |
| 823 | 823 | // developer error msg |
| 824 | - $error_msg .= '||' . $error_msg |
|
| 824 | + $error_msg .= '||'.$error_msg |
|
| 825 | 825 | . esc_html__( |
| 826 | 826 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 827 | 827 | 'event_espresso' |
@@ -830,9 +830,9 @@ discard block |
||
| 830 | 830 | } |
| 831 | 831 | // and that the requested page route exists |
| 832 | 832 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 833 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 834 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 835 | - ? $this->_page_config[ $this->_req_action ] |
|
| 833 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 834 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 835 | + ? $this->_page_config[$this->_req_action] |
|
| 836 | 836 | : []; |
| 837 | 837 | } else { |
| 838 | 838 | // user error msg |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | $this->_admin_page_title |
| 845 | 845 | ); |
| 846 | 846 | // developer error msg |
| 847 | - $error_msg .= '||' . $error_msg |
|
| 847 | + $error_msg .= '||'.$error_msg |
|
| 848 | 848 | . sprintf( |
| 849 | 849 | esc_html__( |
| 850 | 850 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | throw new EE_Error($error_msg); |
| 856 | 856 | } |
| 857 | 857 | // and that a default route exists |
| 858 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 858 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 859 | 859 | // user error msg |
| 860 | 860 | $error_msg = sprintf( |
| 861 | 861 | esc_html__( |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | $this->_admin_page_title |
| 866 | 866 | ); |
| 867 | 867 | // developer error msg |
| 868 | - $error_msg .= '||' . $error_msg |
|
| 868 | + $error_msg .= '||'.$error_msg |
|
| 869 | 869 | . esc_html__( |
| 870 | 870 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 871 | 871 | 'event_espresso' |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | $this->_admin_page_title |
| 907 | 907 | ); |
| 908 | 908 | // developer error msg |
| 909 | - $error_msg .= '||' . $error_msg |
|
| 909 | + $error_msg .= '||'.$error_msg |
|
| 910 | 910 | . sprintf( |
| 911 | 911 | esc_html__( |
| 912 | 912 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | protected function _verify_nonce($nonce, $nonce_ref) |
| 932 | 932 | { |
| 933 | 933 | // verify nonce against expected value |
| 934 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 934 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 935 | 935 | // these are not the droids you are looking for !!! |
| 936 | 936 | $msg = sprintf( |
| 937 | 937 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | __CLASS__ |
| 949 | 949 | ); |
| 950 | 950 | } |
| 951 | - if (! $this->request->isAjax()) { |
|
| 951 | + if ( ! $this->request->isAjax()) { |
|
| 952 | 952 | wp_die($msg); |
| 953 | 953 | } |
| 954 | 954 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | */ |
| 973 | 973 | protected function _route_admin_request() |
| 974 | 974 | { |
| 975 | - if (! $this->_is_UI_request) { |
|
| 975 | + if ( ! $this->_is_UI_request) { |
|
| 976 | 976 | $this->_verify_routes(); |
| 977 | 977 | } |
| 978 | 978 | $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | $error_msg = ''; |
| 993 | 993 | // action right before calling route |
| 994 | 994 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 995 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 995 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 996 | 996 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 997 | 997 | } |
| 998 | 998 | // right before calling the route, let's clean the _wp_http_referer |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | wp_unslash($this->request->getServerParam('REQUEST_URI')) |
| 1004 | 1004 | ) |
| 1005 | 1005 | ); |
| 1006 | - if (! empty($func)) { |
|
| 1006 | + if ( ! empty($func)) { |
|
| 1007 | 1007 | if (is_array($func)) { |
| 1008 | 1008 | list($class, $method) = $func; |
| 1009 | 1009 | } elseif (strpos($func, '::') !== false) { |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | $class = $this; |
| 1013 | 1013 | $method = $func; |
| 1014 | 1014 | } |
| 1015 | - if (! (is_object($class) && $class === $this)) { |
|
| 1015 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 1016 | 1016 | // send along this admin page object for access by addons. |
| 1017 | 1017 | $args['admin_page_object'] = $this; |
| 1018 | 1018 | } |
@@ -1053,7 +1053,7 @@ discard block |
||
| 1053 | 1053 | $method |
| 1054 | 1054 | ); |
| 1055 | 1055 | } |
| 1056 | - if (! empty($error_msg)) { |
|
| 1056 | + if ( ! empty($error_msg)) { |
|
| 1057 | 1057 | throw new EE_Error($error_msg); |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | if (strpos($key, 'nonce') !== false) { |
| 1139 | 1139 | continue; |
| 1140 | 1140 | } |
| 1141 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1141 | + $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1142 | 1142 | } |
| 1143 | 1143 | } |
| 1144 | 1144 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1177,12 +1177,12 @@ discard block |
||
| 1177 | 1177 | */ |
| 1178 | 1178 | protected function _add_help_tabs() |
| 1179 | 1179 | { |
| 1180 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1181 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1180 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1181 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1182 | 1182 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1183 | 1183 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1184 | 1184 | // check that the callback given is valid |
| 1185 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1185 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1186 | 1186 | throw new EE_Error( |
| 1187 | 1187 | sprintf( |
| 1188 | 1188 | esc_html__( |
@@ -1195,18 +1195,18 @@ discard block |
||
| 1195 | 1195 | ); |
| 1196 | 1196 | } |
| 1197 | 1197 | $content = apply_filters( |
| 1198 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1198 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
| 1199 | 1199 | $this->{$config['help_sidebar']}() |
| 1200 | 1200 | ); |
| 1201 | 1201 | $this->_current_screen->set_help_sidebar($content); |
| 1202 | 1202 | } |
| 1203 | - if (! isset($config['help_tabs'])) { |
|
| 1203 | + if ( ! isset($config['help_tabs'])) { |
|
| 1204 | 1204 | return; |
| 1205 | 1205 | } //no help tabs for this route |
| 1206 | 1206 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1207 | 1207 | // we're here so there ARE help tabs! |
| 1208 | 1208 | // make sure we've got what we need |
| 1209 | - if (! isset($cfg['title'])) { |
|
| 1209 | + if ( ! isset($cfg['title'])) { |
|
| 1210 | 1210 | throw new EE_Error( |
| 1211 | 1211 | esc_html__( |
| 1212 | 1212 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1214,7 +1214,7 @@ discard block |
||
| 1214 | 1214 | ) |
| 1215 | 1215 | ); |
| 1216 | 1216 | } |
| 1217 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1217 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1218 | 1218 | throw new EE_Error( |
| 1219 | 1219 | esc_html__( |
| 1220 | 1220 | 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
@@ -1223,11 +1223,11 @@ discard block |
||
| 1223 | 1223 | ); |
| 1224 | 1224 | } |
| 1225 | 1225 | // first priority goes to content. |
| 1226 | - if (! empty($cfg['content'])) { |
|
| 1226 | + if ( ! empty($cfg['content'])) { |
|
| 1227 | 1227 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1228 | 1228 | // second priority goes to filename |
| 1229 | - } elseif (! empty($cfg['filename'])) { |
|
| 1230 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1229 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1230 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1231 | 1231 | // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
| 1232 | 1232 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1233 | 1233 | . basename($this->_get_dir()) |
@@ -1235,7 +1235,7 @@ discard block |
||
| 1235 | 1235 | . $cfg['filename'] |
| 1236 | 1236 | . '.help_tab.php' : $file_path; |
| 1237 | 1237 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1238 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1238 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1239 | 1239 | EE_Error::add_error( |
| 1240 | 1240 | sprintf( |
| 1241 | 1241 | esc_html__( |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | return; |
| 1284 | 1284 | } |
| 1285 | 1285 | // setup config array for help tab method |
| 1286 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1286 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1287 | 1287 | $_ht = [ |
| 1288 | 1288 | 'id' => $id, |
| 1289 | 1289 | 'title' => $cfg['title'], |
@@ -1307,8 +1307,8 @@ discard block |
||
| 1307 | 1307 | $qtips = (array) $this->_route_config['qtips']; |
| 1308 | 1308 | // load qtip loader |
| 1309 | 1309 | $path = [ |
| 1310 | - $this->_get_dir() . '/qtips/', |
|
| 1311 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1310 | + $this->_get_dir().'/qtips/', |
|
| 1311 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1312 | 1312 | ]; |
| 1313 | 1313 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1314 | 1314 | } |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1331 | 1331 | $i = 0; |
| 1332 | 1332 | foreach ($this->_page_config as $slug => $config) { |
| 1333 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1333 | + if ( ! is_array($config) || empty($config['nav'])) { |
|
| 1334 | 1334 | continue; |
| 1335 | 1335 | } |
| 1336 | 1336 | // no nav tab for this config |
@@ -1339,12 +1339,12 @@ discard block |
||
| 1339 | 1339 | // nav tab is only to appear when route requested. |
| 1340 | 1340 | continue; |
| 1341 | 1341 | } |
| 1342 | - if (! $this->check_user_access($slug, true)) { |
|
| 1342 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1343 | 1343 | // no nav tab because current user does not have access. |
| 1344 | 1344 | continue; |
| 1345 | 1345 | } |
| 1346 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1347 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1346 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1347 | + $this->_nav_tabs[$slug] = [ |
|
| 1348 | 1348 | 'url' => isset($config['nav']['url']) |
| 1349 | 1349 | ? $config['nav']['url'] |
| 1350 | 1350 | : self::add_query_args_and_nonce( |
@@ -1356,14 +1356,14 @@ discard block |
||
| 1356 | 1356 | : ucwords( |
| 1357 | 1357 | str_replace('_', ' ', $slug) |
| 1358 | 1358 | ), |
| 1359 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1359 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1360 | 1360 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1361 | 1361 | ]; |
| 1362 | 1362 | $i++; |
| 1363 | 1363 | } |
| 1364 | 1364 | // if $this->_nav_tabs is empty then lets set the default |
| 1365 | 1365 | if (empty($this->_nav_tabs)) { |
| 1366 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1366 | + $this->_nav_tabs[$this->_default_nav_tab_name] = [ |
|
| 1367 | 1367 | 'url' => $this->_admin_base_url, |
| 1368 | 1368 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1369 | 1369 | 'css_class' => 'nav-tab-active', |
@@ -1388,10 +1388,10 @@ discard block |
||
| 1388 | 1388 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1389 | 1389 | if (is_array($text)) { |
| 1390 | 1390 | foreach ($text as $sublabel => $subtext) { |
| 1391 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1391 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1392 | 1392 | } |
| 1393 | 1393 | } else { |
| 1394 | - $this->_labels[ $label ] = $text; |
|
| 1394 | + $this->_labels[$label] = $text; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | } |
| 1397 | 1397 | } |
@@ -1413,12 +1413,12 @@ discard block |
||
| 1413 | 1413 | { |
| 1414 | 1414 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1415 | 1415 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
| 1416 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1416 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1417 | 1417 | && is_array( |
| 1418 | - $this->_page_routes[ $route_to_check ] |
|
| 1418 | + $this->_page_routes[$route_to_check] |
|
| 1419 | 1419 | ) |
| 1420 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1421 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1420 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1421 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1422 | 1422 | if (empty($capability) && empty($route_to_check)) { |
| 1423 | 1423 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
| 1424 | 1424 | : $this->_route['capability']; |
@@ -1538,7 +1538,7 @@ discard block |
||
| 1538 | 1538 | '; |
| 1539 | 1539 | |
| 1540 | 1540 | // current set timezone for timezone js |
| 1541 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1541 | + echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>'; |
|
| 1542 | 1542 | } |
| 1543 | 1543 | |
| 1544 | 1544 | |
@@ -1572,7 +1572,7 @@ discard block |
||
| 1572 | 1572 | // loop through the array and setup content |
| 1573 | 1573 | foreach ($help_array as $trigger => $help) { |
| 1574 | 1574 | // make sure the array is setup properly |
| 1575 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1575 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1576 | 1576 | throw new EE_Error( |
| 1577 | 1577 | esc_html__( |
| 1578 | 1578 | 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
@@ -1586,8 +1586,8 @@ discard block |
||
| 1586 | 1586 | 'help_popup_title' => $help['title'], |
| 1587 | 1587 | 'help_popup_content' => $help['content'], |
| 1588 | 1588 | ]; |
| 1589 | - $content .= EEH_Template::display_template( |
|
| 1590 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1589 | + $content .= EEH_Template::display_template( |
|
| 1590 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1591 | 1591 | $template_args, |
| 1592 | 1592 | true |
| 1593 | 1593 | ); |
@@ -1609,15 +1609,15 @@ discard block |
||
| 1609 | 1609 | private function _get_help_content() |
| 1610 | 1610 | { |
| 1611 | 1611 | // what is the method we're looking for? |
| 1612 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1612 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1613 | 1613 | // if method doesn't exist let's get out. |
| 1614 | - if (! method_exists($this, $method_name)) { |
|
| 1614 | + if ( ! method_exists($this, $method_name)) { |
|
| 1615 | 1615 | return []; |
| 1616 | 1616 | } |
| 1617 | 1617 | // k we're good to go let's retrieve the help array |
| 1618 | 1618 | $help_array = call_user_func([$this, $method_name]); |
| 1619 | 1619 | // make sure we've got an array! |
| 1620 | - if (! is_array($help_array)) { |
|
| 1620 | + if ( ! is_array($help_array)) { |
|
| 1621 | 1621 | throw new EE_Error( |
| 1622 | 1622 | esc_html__( |
| 1623 | 1623 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1649,15 +1649,15 @@ discard block |
||
| 1649 | 1649 | // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
| 1650 | 1650 | $help_array = $this->_get_help_content(); |
| 1651 | 1651 | $help_content = ''; |
| 1652 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1653 | - $help_array[ $trigger_id ] = [ |
|
| 1652 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1653 | + $help_array[$trigger_id] = [ |
|
| 1654 | 1654 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1655 | 1655 | 'content' => esc_html__( |
| 1656 | 1656 | 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
| 1657 | 1657 | 'event_espresso' |
| 1658 | 1658 | ), |
| 1659 | 1659 | ]; |
| 1660 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1660 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | // let's setup the trigger |
| 1663 | 1663 | $content = '<a class="ee-dialog" href="?height=' |
@@ -1725,15 +1725,15 @@ discard block |
||
| 1725 | 1725 | // register all styles |
| 1726 | 1726 | wp_register_style( |
| 1727 | 1727 | 'espresso-ui-theme', |
| 1728 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1728 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1729 | 1729 | [], |
| 1730 | 1730 | EVENT_ESPRESSO_VERSION |
| 1731 | 1731 | ); |
| 1732 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1732 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1733 | 1733 | // helpers styles |
| 1734 | 1734 | wp_register_style( |
| 1735 | 1735 | 'ee-text-links', |
| 1736 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1736 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', |
|
| 1737 | 1737 | [], |
| 1738 | 1738 | EVENT_ESPRESSO_VERSION |
| 1739 | 1739 | ); |
@@ -1741,21 +1741,21 @@ discard block |
||
| 1741 | 1741 | // register all scripts |
| 1742 | 1742 | wp_register_script( |
| 1743 | 1743 | 'ee-dialog', |
| 1744 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1744 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
| 1745 | 1745 | ['jquery', 'jquery-ui-draggable'], |
| 1746 | 1746 | EVENT_ESPRESSO_VERSION, |
| 1747 | 1747 | true |
| 1748 | 1748 | ); |
| 1749 | 1749 | wp_register_script( |
| 1750 | 1750 | 'ee_admin_js', |
| 1751 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1751 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
| 1752 | 1752 | ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
| 1753 | 1753 | EVENT_ESPRESSO_VERSION, |
| 1754 | 1754 | true |
| 1755 | 1755 | ); |
| 1756 | 1756 | wp_register_script( |
| 1757 | 1757 | 'jquery-ui-timepicker-addon', |
| 1758 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1758 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', |
|
| 1759 | 1759 | ['jquery-ui-datepicker', 'jquery-ui-slider'], |
| 1760 | 1760 | EVENT_ESPRESSO_VERSION, |
| 1761 | 1761 | true |
@@ -1763,7 +1763,7 @@ discard block |
||
| 1763 | 1763 | // script for sorting tables |
| 1764 | 1764 | wp_register_script( |
| 1765 | 1765 | 'espresso_ajax_table_sorting', |
| 1766 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1766 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
| 1767 | 1767 | ['ee_admin_js', 'jquery-ui-sortable'], |
| 1768 | 1768 | EVENT_ESPRESSO_VERSION, |
| 1769 | 1769 | true |
@@ -1771,7 +1771,7 @@ discard block |
||
| 1771 | 1771 | // script for parsing uri's |
| 1772 | 1772 | wp_register_script( |
| 1773 | 1773 | 'ee-parse-uri', |
| 1774 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1774 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', |
|
| 1775 | 1775 | [], |
| 1776 | 1776 | EVENT_ESPRESSO_VERSION, |
| 1777 | 1777 | true |
@@ -1779,7 +1779,7 @@ discard block |
||
| 1779 | 1779 | // and parsing associative serialized form elements |
| 1780 | 1780 | wp_register_script( |
| 1781 | 1781 | 'ee-serialize-full-array', |
| 1782 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1782 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
| 1783 | 1783 | ['jquery'], |
| 1784 | 1784 | EVENT_ESPRESSO_VERSION, |
| 1785 | 1785 | true |
@@ -1787,28 +1787,28 @@ discard block |
||
| 1787 | 1787 | // helpers scripts |
| 1788 | 1788 | wp_register_script( |
| 1789 | 1789 | 'ee-text-links', |
| 1790 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1790 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
| 1791 | 1791 | ['jquery'], |
| 1792 | 1792 | EVENT_ESPRESSO_VERSION, |
| 1793 | 1793 | true |
| 1794 | 1794 | ); |
| 1795 | 1795 | wp_register_script( |
| 1796 | 1796 | 'ee-moment-core', |
| 1797 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1797 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', |
|
| 1798 | 1798 | [], |
| 1799 | 1799 | EVENT_ESPRESSO_VERSION, |
| 1800 | 1800 | true |
| 1801 | 1801 | ); |
| 1802 | 1802 | wp_register_script( |
| 1803 | 1803 | 'ee-moment', |
| 1804 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1804 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
| 1805 | 1805 | ['ee-moment-core'], |
| 1806 | 1806 | EVENT_ESPRESSO_VERSION, |
| 1807 | 1807 | true |
| 1808 | 1808 | ); |
| 1809 | 1809 | wp_register_script( |
| 1810 | 1810 | 'ee-datepicker', |
| 1811 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1811 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
| 1812 | 1812 | ['jquery-ui-timepicker-addon', 'ee-moment'], |
| 1813 | 1813 | EVENT_ESPRESSO_VERSION, |
| 1814 | 1814 | true |
@@ -1841,7 +1841,7 @@ discard block |
||
| 1841 | 1841 | wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
| 1842 | 1842 | add_filter( |
| 1843 | 1843 | 'admin_body_class', |
| 1844 | - function ($classes) { |
|
| 1844 | + function($classes) { |
|
| 1845 | 1845 | if (strpos($classes, 'espresso-admin') === false) { |
| 1846 | 1846 | $classes .= ' espresso-admin'; |
| 1847 | 1847 | } |
@@ -1929,12 +1929,12 @@ discard block |
||
| 1929 | 1929 | protected function _set_list_table() |
| 1930 | 1930 | { |
| 1931 | 1931 | // first is this a list_table view? |
| 1932 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1932 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 1933 | 1933 | return; |
| 1934 | 1934 | } //not a list_table view so get out. |
| 1935 | 1935 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 1936 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1937 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1936 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 1937 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1938 | 1938 | // user error msg |
| 1939 | 1939 | $error_msg = esc_html__( |
| 1940 | 1940 | 'An error occurred. The requested list table views could not be found.', |
@@ -1954,10 +1954,10 @@ discard block |
||
| 1954 | 1954 | } |
| 1955 | 1955 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 1956 | 1956 | $this->_views = apply_filters( |
| 1957 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 1957 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 1958 | 1958 | $this->_views |
| 1959 | 1959 | ); |
| 1960 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1960 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 1961 | 1961 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 1962 | 1962 | $this->_set_list_table_view(); |
| 1963 | 1963 | $this->_set_list_table_object(); |
@@ -1992,7 +1992,7 @@ discard block |
||
| 1992 | 1992 | protected function _set_list_table_object() |
| 1993 | 1993 | { |
| 1994 | 1994 | if (isset($this->_route_config['list_table'])) { |
| 1995 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 1995 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1996 | 1996 | throw new EE_Error( |
| 1997 | 1997 | sprintf( |
| 1998 | 1998 | esc_html__( |
@@ -2030,15 +2030,15 @@ discard block |
||
| 2030 | 2030 | foreach ($this->_views as $key => $view) { |
| 2031 | 2031 | $query_args = []; |
| 2032 | 2032 | // check for current view |
| 2033 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2033 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2034 | 2034 | $query_args['action'] = $this->_req_action; |
| 2035 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2035 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2036 | 2036 | $query_args['status'] = $view['slug']; |
| 2037 | 2037 | // merge any other arguments sent in. |
| 2038 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2039 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2038 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2039 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2040 | 2040 | } |
| 2041 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2041 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2042 | 2042 | } |
| 2043 | 2043 | return $this->_views; |
| 2044 | 2044 | } |
@@ -2069,14 +2069,14 @@ discard block |
||
| 2069 | 2069 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2070 | 2070 | foreach ($values as $value) { |
| 2071 | 2071 | if ($value < $max_entries) { |
| 2072 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2072 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2073 | 2073 | $entries_per_page_dropdown .= ' |
| 2074 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2074 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2075 | 2075 | } |
| 2076 | 2076 | } |
| 2077 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2077 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2078 | 2078 | $entries_per_page_dropdown .= ' |
| 2079 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2079 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2080 | 2080 | $entries_per_page_dropdown .= ' |
| 2081 | 2081 | </select> |
| 2082 | 2082 | entries |
@@ -2100,7 +2100,7 @@ discard block |
||
| 2100 | 2100 | empty($this->_search_btn_label) ? $this->page_label |
| 2101 | 2101 | : $this->_search_btn_label |
| 2102 | 2102 | ); |
| 2103 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2103 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2104 | 2104 | } |
| 2105 | 2105 | |
| 2106 | 2106 | |
@@ -2188,7 +2188,7 @@ discard block |
||
| 2188 | 2188 | $total_columns = ! empty($screen_columns) |
| 2189 | 2189 | ? $screen_columns |
| 2190 | 2190 | : $this->_route_config['columns'][1]; |
| 2191 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2191 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2192 | 2192 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2193 | 2193 | $this->_template_args['screen'] = $this->_current_screen; |
| 2194 | 2194 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2233,7 +2233,7 @@ discard block |
||
| 2233 | 2233 | */ |
| 2234 | 2234 | protected function _espresso_ratings_request() |
| 2235 | 2235 | { |
| 2236 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2236 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2237 | 2237 | return; |
| 2238 | 2238 | } |
| 2239 | 2239 | $ratings_box_title = apply_filters( |
@@ -2261,7 +2261,7 @@ discard block |
||
| 2261 | 2261 | public function espresso_ratings_request() |
| 2262 | 2262 | { |
| 2263 | 2263 | EEH_Template::display_template( |
| 2264 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2264 | + EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php', |
|
| 2265 | 2265 | [] |
| 2266 | 2266 | ); |
| 2267 | 2267 | } |
@@ -2269,22 +2269,22 @@ discard block |
||
| 2269 | 2269 | |
| 2270 | 2270 | public static function cached_rss_display($rss_id, $url) |
| 2271 | 2271 | { |
| 2272 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2272 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2273 | 2273 | . esc_html__('Loading…', 'event_espresso') |
| 2274 | 2274 | . '</p><p class="hide-if-js">' |
| 2275 | 2275 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2276 | 2276 | . '</p>'; |
| 2277 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2278 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2279 | - $post = '</div>' . "\n"; |
|
| 2280 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2277 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2278 | + $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>'; |
|
| 2279 | + $post = '</div>'."\n"; |
|
| 2280 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2281 | 2281 | $output = get_transient($cache_key); |
| 2282 | 2282 | if ($output !== false) { |
| 2283 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2283 | + echo wp_kses($pre.$output.$post, AllowedTags::getWithFormTags()); |
|
| 2284 | 2284 | return true; |
| 2285 | 2285 | } |
| 2286 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2286 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | + echo wp_kses($pre.$loading.$post, AllowedTags::getWithFormTags()); |
|
| 2288 | 2288 | return false; |
| 2289 | 2289 | } |
| 2290 | 2290 | ob_start(); |
@@ -2351,19 +2351,19 @@ discard block |
||
| 2351 | 2351 | public function espresso_sponsors_post_box() |
| 2352 | 2352 | { |
| 2353 | 2353 | EEH_Template::display_template( |
| 2354 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2354 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2355 | 2355 | ); |
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | 2358 | |
| 2359 | 2359 | private function _publish_post_box() |
| 2360 | 2360 | { |
| 2361 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2361 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2362 | 2362 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2363 | 2363 | // then we'll use that for the metabox label. |
| 2364 | 2364 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2365 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2366 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2365 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2366 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2367 | 2367 | : $this->_labels['publishbox']; |
| 2368 | 2368 | } else { |
| 2369 | 2369 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2392,7 +2392,7 @@ discard block |
||
| 2392 | 2392 | ? $this->_template_args['publish_box_extra_content'] |
| 2393 | 2393 | : ''; |
| 2394 | 2394 | echo EEH_Template::display_template( |
| 2395 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2395 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2396 | 2396 | $this->_template_args, |
| 2397 | 2397 | true |
| 2398 | 2398 | ); |
@@ -2484,18 +2484,18 @@ discard block |
||
| 2484 | 2484 | ); |
| 2485 | 2485 | } |
| 2486 | 2486 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
| 2487 | - if (! empty($name) && ! empty($id)) { |
|
| 2488 | - $hidden_field_arr[ $name ] = [ |
|
| 2487 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2488 | + $hidden_field_arr[$name] = [ |
|
| 2489 | 2489 | 'type' => 'hidden', |
| 2490 | 2490 | 'value' => $id, |
| 2491 | 2491 | ]; |
| 2492 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2492 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2493 | 2493 | } else { |
| 2494 | 2494 | $hf = ''; |
| 2495 | 2495 | } |
| 2496 | 2496 | // add hidden field |
| 2497 | 2497 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
| 2498 | - ? $hf[ $name ]['field'] |
|
| 2498 | + ? $hf[$name]['field'] |
|
| 2499 | 2499 | : $hf; |
| 2500 | 2500 | } |
| 2501 | 2501 | |
@@ -2597,7 +2597,7 @@ discard block |
||
| 2597 | 2597 | } |
| 2598 | 2598 | // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
| 2599 | 2599 | $call_back_func = $create_func |
| 2600 | - ? function ($post, $metabox) { |
|
| 2600 | + ? function($post, $metabox) { |
|
| 2601 | 2601 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2602 | 2602 | echo EEH_Template::display_template( |
| 2603 | 2603 | $metabox['args']['template_path'], |
@@ -2607,7 +2607,7 @@ discard block |
||
| 2607 | 2607 | } |
| 2608 | 2608 | : $callback; |
| 2609 | 2609 | add_meta_box( |
| 2610 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2610 | + str_replace('_', '-', $action).'-mbox', |
|
| 2611 | 2611 | $title, |
| 2612 | 2612 | $call_back_func, |
| 2613 | 2613 | $this->_wp_page_slug, |
@@ -2699,9 +2699,9 @@ discard block |
||
| 2699 | 2699 | : 'espresso-default-admin'; |
| 2700 | 2700 | $template_path = $sidebar |
| 2701 | 2701 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2702 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2702 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2703 | 2703 | if ($this->request->isAjax()) { |
| 2704 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2704 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2705 | 2705 | } |
| 2706 | 2706 | $template_path = ! empty($this->_column_template_path) |
| 2707 | 2707 | ? $this->_column_template_path : $template_path; |
@@ -2741,11 +2741,11 @@ discard block |
||
| 2741 | 2741 | public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
| 2742 | 2742 | { |
| 2743 | 2743 | // let's generate a default preview action button if there isn't one already present. |
| 2744 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2744 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2745 | 2745 | 'Upgrade to Event Espresso 4 Right Now', |
| 2746 | 2746 | 'event_espresso' |
| 2747 | 2747 | ); |
| 2748 | - $buy_now_url = add_query_arg( |
|
| 2748 | + $buy_now_url = add_query_arg( |
|
| 2749 | 2749 | [ |
| 2750 | 2750 | 'ee_ver' => 'ee4', |
| 2751 | 2751 | 'utm_source' => 'ee4_plugin_admin', |
@@ -2765,8 +2765,8 @@ discard block |
||
| 2765 | 2765 | true |
| 2766 | 2766 | ) |
| 2767 | 2767 | : $this->_template_args['preview_action_button']; |
| 2768 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2768 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2770 | 2770 | $this->_template_args, |
| 2771 | 2771 | true |
| 2772 | 2772 | ); |
@@ -2815,7 +2815,7 @@ discard block |
||
| 2815 | 2815 | // setup search attributes |
| 2816 | 2816 | $this->_set_search_attributes(); |
| 2817 | 2817 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2818 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2818 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2819 | 2819 | $this->_template_args['table_url'] = $this->request->isAjax() |
| 2820 | 2820 | ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
| 2821 | 2821 | : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
@@ -2823,10 +2823,10 @@ discard block |
||
| 2823 | 2823 | $this->_template_args['current_route'] = $this->_req_action; |
| 2824 | 2824 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 2825 | 2825 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2826 | - if (! empty($ajax_sorting_callback)) { |
|
| 2826 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2827 | 2827 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2828 | - $ajax_sorting_callback . '_nonce', |
|
| 2829 | - $ajax_sorting_callback . '_nonce', |
|
| 2828 | + $ajax_sorting_callback.'_nonce', |
|
| 2829 | + $ajax_sorting_callback.'_nonce', |
|
| 2830 | 2830 | false, |
| 2831 | 2831 | false |
| 2832 | 2832 | ); |
@@ -2844,20 +2844,20 @@ discard block |
||
| 2844 | 2844 | isset($this->_template_args['list_table_hidden_fields']) |
| 2845 | 2845 | ? $this->_template_args['list_table_hidden_fields'] |
| 2846 | 2846 | : ''; |
| 2847 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2848 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 2847 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2848 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 2849 | 2849 | . $nonce_ref |
| 2850 | 2850 | . '" value="' |
| 2851 | 2851 | . wp_create_nonce($nonce_ref) |
| 2852 | 2852 | . '">'; |
| 2853 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2853 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2854 | 2854 | // display message about search results? |
| 2855 | 2855 | $search = $this->request->getRequestParam('s'); |
| 2856 | 2856 | $this->_template_args['before_list_table'] .= ! empty($search) |
| 2857 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2857 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 2858 | 2858 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 2859 | 2859 | trim($search, '%') |
| 2860 | - ) . '</p>' |
|
| 2860 | + ).'</p>' |
|
| 2861 | 2861 | : ''; |
| 2862 | 2862 | // filter before_list_table template arg |
| 2863 | 2863 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -2891,7 +2891,7 @@ discard block |
||
| 2891 | 2891 | // convert to array and filter again |
| 2892 | 2892 | // arrays are easier to inject new items in a specific location, |
| 2893 | 2893 | // but would not be backwards compatible, so we have to add a new filter |
| 2894 | - $this->_template_args['after_list_table'] = implode( |
|
| 2894 | + $this->_template_args['after_list_table'] = implode( |
|
| 2895 | 2895 | " \n", |
| 2896 | 2896 | (array) apply_filters( |
| 2897 | 2897 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
@@ -2938,7 +2938,7 @@ discard block |
||
| 2938 | 2938 | $this |
| 2939 | 2939 | ); |
| 2940 | 2940 | return EEH_Template::display_template( |
| 2941 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 2941 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 2942 | 2942 | $this->_template_args, |
| 2943 | 2943 | true |
| 2944 | 2944 | ); |
@@ -3047,18 +3047,18 @@ discard block |
||
| 3047 | 3047 | : '' |
| 3048 | 3048 | ); |
| 3049 | 3049 | |
| 3050 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3050 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3051 | 3051 | "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
| 3052 | 3052 | isset($this->_template_args['after_admin_page_content']) |
| 3053 | 3053 | ? $this->_template_args['after_admin_page_content'] |
| 3054 | 3054 | : '' |
| 3055 | 3055 | ); |
| 3056 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3056 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3057 | 3057 | |
| 3058 | 3058 | if ($this->request->isAjax()) { |
| 3059 | 3059 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 3060 | 3060 | // $template_path, |
| 3061 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3061 | + EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php', |
|
| 3062 | 3062 | $this->_template_args, |
| 3063 | 3063 | true |
| 3064 | 3064 | ); |
@@ -3067,7 +3067,7 @@ discard block |
||
| 3067 | 3067 | // load settings page wrapper template |
| 3068 | 3068 | $template_path = $about |
| 3069 | 3069 | ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
| 3070 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3070 | + : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php'; |
|
| 3071 | 3071 | |
| 3072 | 3072 | EEH_Template::display_template($template_path, $this->_template_args); |
| 3073 | 3073 | } |
@@ -3152,12 +3152,12 @@ discard block |
||
| 3152 | 3152 | $default_names = ['save', 'save_and_close']; |
| 3153 | 3153 | $buttons = ''; |
| 3154 | 3154 | foreach ($button_text as $key => $button) { |
| 3155 | - $ref = $default_names[ $key ]; |
|
| 3156 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3157 | - $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
| 3158 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3159 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3160 | - if (! $both) { |
|
| 3155 | + $ref = $default_names[$key]; |
|
| 3156 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 3157 | + $buttons .= '<input type="submit" class="button-primary '.$ref.'" ' |
|
| 3158 | + . 'value="'.$button.'" name="'.$name.'" ' |
|
| 3159 | + . 'id="'.$this->_current_view.'_'.$ref.'" />'; |
|
| 3160 | + if ( ! $both) { |
|
| 3161 | 3161 | break; |
| 3162 | 3162 | } |
| 3163 | 3163 | } |
@@ -3197,13 +3197,13 @@ discard block |
||
| 3197 | 3197 | 'An error occurred. No action was set for this page\'s form.', |
| 3198 | 3198 | 'event_espresso' |
| 3199 | 3199 | ); |
| 3200 | - $dev_msg = $user_msg . "\n" |
|
| 3200 | + $dev_msg = $user_msg."\n" |
|
| 3201 | 3201 | . sprintf( |
| 3202 | 3202 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3203 | 3203 | __FUNCTION__, |
| 3204 | 3204 | __CLASS__ |
| 3205 | 3205 | ); |
| 3206 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3206 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3207 | 3207 | } |
| 3208 | 3208 | // open form |
| 3209 | 3209 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3212,9 +3212,9 @@ discard block |
||
| 3212 | 3212 | . $route |
| 3213 | 3213 | . '_event_form" >'; |
| 3214 | 3214 | // add nonce |
| 3215 | - $nonce = |
|
| 3216 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3217 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3215 | + $nonce = |
|
| 3216 | + wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3217 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3218 | 3218 | // add REQUIRED form action |
| 3219 | 3219 | $hidden_fields = [ |
| 3220 | 3220 | 'action' => ['type' => 'hidden', 'value' => $route], |
@@ -3227,7 +3227,7 @@ discard block |
||
| 3227 | 3227 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3228 | 3228 | // add fields to form |
| 3229 | 3229 | foreach ((array) $form_fields as $form_field) { |
| 3230 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3230 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3231 | 3231 | } |
| 3232 | 3232 | // close form |
| 3233 | 3233 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3318,10 +3318,10 @@ discard block |
||
| 3318 | 3318 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
| 3319 | 3319 | $notices = EE_Error::get_notices(false); |
| 3320 | 3320 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3321 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3321 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3322 | 3322 | EE_Error::overwrite_success(); |
| 3323 | 3323 | } |
| 3324 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3324 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3325 | 3325 | // how many records affected ? more than one record ? or just one ? |
| 3326 | 3326 | if ($success > 1) { |
| 3327 | 3327 | // set plural msg |
@@ -3350,7 +3350,7 @@ discard block |
||
| 3350 | 3350 | } |
| 3351 | 3351 | } |
| 3352 | 3352 | // check that $query_args isn't something crazy |
| 3353 | - if (! is_array($query_args)) { |
|
| 3353 | + if ( ! is_array($query_args)) { |
|
| 3354 | 3354 | $query_args = []; |
| 3355 | 3355 | } |
| 3356 | 3356 | /** |
@@ -3379,7 +3379,7 @@ discard block |
||
| 3379 | 3379 | $redirect_url = admin_url('admin.php'); |
| 3380 | 3380 | } |
| 3381 | 3381 | // merge any default query_args set in _default_route_query_args property |
| 3382 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3382 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3383 | 3383 | $args_to_merge = []; |
| 3384 | 3384 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3385 | 3385 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3391,15 +3391,15 @@ discard block |
||
| 3391 | 3391 | } |
| 3392 | 3392 | // finally we will override any arguments in the referer with |
| 3393 | 3393 | // what might be set on the _default_route_query_args array. |
| 3394 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3395 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3394 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3395 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3396 | 3396 | } else { |
| 3397 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3397 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3398 | 3398 | } |
| 3399 | 3399 | } |
| 3400 | 3400 | continue; |
| 3401 | 3401 | } |
| 3402 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3402 | + $args_to_merge[$query_param] = $query_value; |
|
| 3403 | 3403 | } |
| 3404 | 3404 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3405 | 3405 | // redirect. |
@@ -3411,19 +3411,19 @@ discard block |
||
| 3411 | 3411 | if (isset($query_args['action'])) { |
| 3412 | 3412 | // manually generate wp_nonce and merge that with the query vars |
| 3413 | 3413 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3414 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3414 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3415 | 3415 | } |
| 3416 | 3416 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3417 | 3417 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3418 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3418 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 3419 | 3419 | $redirect_url = apply_filters( |
| 3420 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3420 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
| 3421 | 3421 | self::add_query_args_and_nonce($query_args, $redirect_url), |
| 3422 | 3422 | $query_args |
| 3423 | 3423 | ); |
| 3424 | 3424 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 3425 | 3425 | if ($this->request->isAjax()) { |
| 3426 | - $default_data = [ |
|
| 3426 | + $default_data = [ |
|
| 3427 | 3427 | 'close' => true, |
| 3428 | 3428 | 'redirect_url' => $redirect_url, |
| 3429 | 3429 | 'where' => 'main', |
@@ -3470,7 +3470,7 @@ discard block |
||
| 3470 | 3470 | } |
| 3471 | 3471 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3472 | 3472 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3473 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3473 | + if ( ! $this->request->isAjax() || $sticky_notices) { |
|
| 3474 | 3474 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3475 | 3475 | $this->_add_transient( |
| 3476 | 3476 | $route, |
@@ -3510,7 +3510,7 @@ discard block |
||
| 3510 | 3510 | $exclude_nonce = false |
| 3511 | 3511 | ) { |
| 3512 | 3512 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3513 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3513 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3514 | 3514 | throw new EE_Error( |
| 3515 | 3515 | sprintf( |
| 3516 | 3516 | esc_html__( |
@@ -3521,7 +3521,7 @@ discard block |
||
| 3521 | 3521 | ) |
| 3522 | 3522 | ); |
| 3523 | 3523 | } |
| 3524 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3524 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3525 | 3525 | throw new EE_Error( |
| 3526 | 3526 | sprintf( |
| 3527 | 3527 | esc_html__( |
@@ -3534,7 +3534,7 @@ discard block |
||
| 3534 | 3534 | } |
| 3535 | 3535 | // finally check user access for this button. |
| 3536 | 3536 | $has_access = $this->check_user_access($action, true); |
| 3537 | - if (! $has_access) { |
|
| 3537 | + if ( ! $has_access) { |
|
| 3538 | 3538 | return ''; |
| 3539 | 3539 | } |
| 3540 | 3540 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3542,11 +3542,11 @@ discard block |
||
| 3542 | 3542 | 'action' => $action, |
| 3543 | 3543 | ]; |
| 3544 | 3544 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3545 | - if (! empty($extra_request)) { |
|
| 3545 | + if ( ! empty($extra_request)) { |
|
| 3546 | 3546 | $query_args = array_merge($extra_request, $query_args); |
| 3547 | 3547 | } |
| 3548 | 3548 | $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3549 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3549 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3550 | 3550 | } |
| 3551 | 3551 | |
| 3552 | 3552 | |
@@ -3572,7 +3572,7 @@ discard block |
||
| 3572 | 3572 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3573 | 3573 | 20 |
| 3574 | 3574 | ), |
| 3575 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3575 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3576 | 3576 | ]; |
| 3577 | 3577 | // ONLY add the screen option if the user has access to it. |
| 3578 | 3578 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3593,18 +3593,18 @@ discard block |
||
| 3593 | 3593 | { |
| 3594 | 3594 | if ($this->request->requestParamIsSet('wp_screen_options')) { |
| 3595 | 3595 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3596 | - if (! $user = wp_get_current_user()) { |
|
| 3596 | + if ( ! $user = wp_get_current_user()) { |
|
| 3597 | 3597 | return; |
| 3598 | 3598 | } |
| 3599 | 3599 | $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
| 3600 | - if (! $option) { |
|
| 3600 | + if ( ! $option) { |
|
| 3601 | 3601 | return; |
| 3602 | 3602 | } |
| 3603 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3603 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3604 | 3604 | $map_option = $option; |
| 3605 | 3605 | $option = str_replace('-', '_', $option); |
| 3606 | 3606 | switch ($map_option) { |
| 3607 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3607 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3608 | 3608 | $max_value = apply_filters( |
| 3609 | 3609 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
| 3610 | 3610 | 999, |
@@ -3661,13 +3661,13 @@ discard block |
||
| 3661 | 3661 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3662 | 3662 | { |
| 3663 | 3663 | $user_id = get_current_user_id(); |
| 3664 | - if (! $skip_route_verify) { |
|
| 3664 | + if ( ! $skip_route_verify) { |
|
| 3665 | 3665 | $this->_verify_route($route); |
| 3666 | 3666 | } |
| 3667 | 3667 | // now let's set the string for what kind of transient we're setting |
| 3668 | 3668 | $transient = $notices |
| 3669 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3670 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3669 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3670 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3671 | 3671 | $data = $notices ? ['notices' => $data] : $data; |
| 3672 | 3672 | // is there already a transient for this route? If there is then let's ADD to that transient |
| 3673 | 3673 | $existing = is_multisite() && is_network_admin() |
@@ -3696,8 +3696,8 @@ discard block |
||
| 3696 | 3696 | $user_id = get_current_user_id(); |
| 3697 | 3697 | $route = ! $route ? $this->_req_action : $route; |
| 3698 | 3698 | $transient = $notices |
| 3699 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3700 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3699 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3700 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3701 | 3701 | $data = is_multisite() && is_network_admin() |
| 3702 | 3702 | ? get_site_transient($transient) |
| 3703 | 3703 | : get_transient($transient); |
@@ -3928,7 +3928,7 @@ discard block |
||
| 3928 | 3928 | */ |
| 3929 | 3929 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 3930 | 3930 | { |
| 3931 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3931 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3932 | 3932 | } |
| 3933 | 3933 | |
| 3934 | 3934 | |
@@ -3941,7 +3941,7 @@ discard block |
||
| 3941 | 3941 | */ |
| 3942 | 3942 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 3943 | 3943 | { |
| 3944 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3944 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3945 | 3945 | } |
| 3946 | 3946 | |
| 3947 | 3947 | |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.30.rc.022'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.30.rc.022'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -102,8 +102,11 @@ discard block |
||
| 102 | 102 | name="archived_ticket[TKT_start_date]" |
| 103 | 103 | value="<?php echo esc_attr($TKT_start_date); ?>" |
| 104 | 104 | /> |
| 105 | - <?php else : ?> |
|
| 106 | - <label class='screen-reader-text' for="edit-ticket-TKT_start_date-<?php echo esc_attr($tkt_row); ?>"> |
|
| 105 | + <?php else { |
|
| 106 | + : ?> |
|
| 107 | + <label class='screen-reader-text' for="edit-ticket-TKT_start_date-<?php echo esc_attr($tkt_row); |
|
| 108 | +} |
|
| 109 | +?>"> |
|
| 107 | 110 | <?php esc_html_e('Sale Starts', 'event_espresso') ?> |
| 108 | 111 | </label> |
| 109 | 112 | <input type='text' |
@@ -136,8 +139,11 @@ discard block |
||
| 136 | 139 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_end_date]" |
| 137 | 140 | value="<?php echo esc_attr($TKT_end_date); ?>" |
| 138 | 141 | /> |
| 139 | - <?php else : ?> |
|
| 140 | - <label class='screen-reader-text' for='edit-ticket-TKT_end_date-<?php echo esc_attr($tkt_row); ?>'> |
|
| 142 | + <?php else { |
|
| 143 | + : ?> |
|
| 144 | + <label class='screen-reader-text' for='edit-ticket-TKT_end_date-<?php echo esc_attr($tkt_row); |
|
| 145 | +} |
|
| 146 | +?>'> |
|
| 141 | 147 | <?php esc_html_e('Sell Until', 'event_espresso') ?> |
| 142 | 148 | </label> |
| 143 | 149 | <input type='text' |
@@ -169,8 +175,11 @@ discard block |
||
| 169 | 175 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_base_price]" |
| 170 | 176 | value="<?php echo esc_attr($TKT_base_price); ?>" |
| 171 | 177 | /> |
| 172 | - <?php else : ?> |
|
| 173 | - <label class='screen-reader-text' for='edit-ticket-TKT_base_price-<?php echo esc_attr($tkt_row); ?>'> |
|
| 178 | + <?php else { |
|
| 179 | + : ?> |
|
| 180 | + <label class='screen-reader-text' for='edit-ticket-TKT_base_price-<?php echo esc_attr($tkt_row); |
|
| 181 | +} |
|
| 182 | +?>'> |
|
| 174 | 183 | <?php esc_html_e('Price', 'event_espresso') ?> |
| 175 | 184 | </label> |
| 176 | 185 | <input id="edit-ticket-TKT_base_price-<?php echo esc_attr($tkt_row); ?>" type="text" |
@@ -200,8 +209,11 @@ discard block |
||
| 200 | 209 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_qty]" |
| 201 | 210 | value="<?php echo esc_attr($TKT_qty_for_input); ?>" |
| 202 | 211 | /> |
| 203 | - <?php else : ?> |
|
| 204 | - <label class='screen-reader-text' for='edit-ticket-TKT_qty-<?php echo esc_attr($tkt_row); ?>'> |
|
| 212 | + <?php else { |
|
| 213 | + : ?> |
|
| 214 | + <label class='screen-reader-text' for='edit-ticket-TKT_qty-<?php echo esc_attr($tkt_row); |
|
| 215 | +} |
|
| 216 | +?>'> |
|
| 205 | 217 | <?php esc_html_e('Qty', 'event_espresso') ?> |
| 206 | 218 | </label> |
| 207 | 219 | <input type="text" |
@@ -321,9 +333,12 @@ discard block |
||
| 321 | 333 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_uses]" |
| 322 | 334 | value="<?php echo esc_attr($TKT_uses); ?>" |
| 323 | 335 | /> |
| 324 | - <?php else : ?> |
|
| 336 | + <?php else { |
|
| 337 | + : ?> |
|
| 325 | 338 | <label class='screen-reader-text' |
| 326 | - for='edit-ticket-TKT_uses-<?php echo esc_attr($tkt_row); ?>' |
|
| 339 | + for='edit-ticket-TKT_uses-<?php echo esc_attr($tkt_row); |
|
| 340 | +} |
|
| 341 | +?>' |
|
| 327 | 342 | > |
| 328 | 343 | <?php |
| 329 | 344 | esc_html_e('Ticket Uses', 'event_espresso') ?> |
@@ -353,8 +368,11 @@ discard block |
||
| 353 | 368 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_min]" |
| 354 | 369 | value="<?php echo esc_attr($TKT_min); ?>" |
| 355 | 370 | /> |
| 356 | - <?php else : ?> |
|
| 357 | - <label class='screen-reader-text' for='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>'> |
|
| 371 | + <?php else { |
|
| 372 | + : ?> |
|
| 373 | + <label class='screen-reader-text' for='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row); |
|
| 374 | +} |
|
| 375 | +?>'> |
|
| 358 | 376 | <?php esc_html_e('Minimum Quantity', 'event_espresso') ?> |
| 359 | 377 | </label> |
| 360 | 378 | <input type="text" |
@@ -380,8 +398,11 @@ discard block |
||
| 380 | 398 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_max]" |
| 381 | 399 | value="<?php echo esc_attr($TKT_max); ?>" |
| 382 | 400 | /> |
| 383 | - <?php else : ?> |
|
| 384 | - <label class='screen-reader-text' for='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row);?>'> |
|
| 401 | + <?php else { |
|
| 402 | + : ?> |
|
| 403 | + <label class='screen-reader-text' for='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row); |
|
| 404 | +} |
|
| 405 | +?>'> |
|
| 385 | 406 | <?php esc_html_e('Maximum Quantity', 'event_espresso') ?> |
| 386 | 407 | </label> |
| 387 | 408 | <input type="text" |
@@ -434,10 +455,13 @@ discard block |
||
| 434 | 455 | value="1" |
| 435 | 456 | <?php echo esc_attr($TKT_taxable); ?> |
| 436 | 457 | /> |
| 437 | - <?php else : ?> |
|
| 458 | + <?php else { |
|
| 459 | + : ?> |
|
| 438 | 460 | <input type='checkbox' |
| 439 | 461 | class="TKT-taxable-checkbox" |
| 440 | - id="edit-ticket-TKT_taxable-<?php echo esc_attr($tkt_row); ?>" |
|
| 462 | + id="edit-ticket-TKT_taxable-<?php echo esc_attr($tkt_row); |
|
| 463 | +} |
|
| 464 | +?>" |
|
| 441 | 465 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_taxable]" |
| 442 | 466 | value="1" |
| 443 | 467 | <?php echo esc_attr($TKT_taxable); ?> |
@@ -26,11 +26,11 @@ discard block |
||
| 26 | 26 | class="clickable ee-collapsible <?php echo sanitize_html_class($ee_collapsible_status); ?>"> |
| 27 | 27 | <span class="dashicons dashicons-clock ee-icon-size-20"></span> |
| 28 | 28 | <?php |
| 29 | - esc_html_e( |
|
| 30 | - 'Event Datetimes', |
|
| 31 | - 'event_espresso' |
|
| 32 | - ); |
|
| 33 | - ?> |
|
| 29 | + esc_html_e( |
|
| 30 | + 'Event Datetimes', |
|
| 31 | + 'event_espresso' |
|
| 32 | + ); |
|
| 33 | + ?> |
|
| 34 | 34 | </span> |
| 35 | 35 | </h3> |
| 36 | 36 | <?php echo wp_kses($event_datetime_help_link, AllowedTags::getAllowedTags()); ?> |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | </div> <!-- end .event-datetimes-container --> |
| 68 | 68 | <div id="add-event-datetime" class="event-datetime-row add-dtt-row" style="display:none;"> |
| 69 | 69 | <h4 class="datetime-tickets-heading"><?php |
| 70 | - esc_html_e( |
|
| 71 | - 'Add New Datetime', |
|
| 72 | - 'event_espresso' |
|
| 73 | - ); ?></h4><?php echo wp_kses($add_new_dtt_help_link, AllowedTags::getAllowedTags()); ?> |
|
| 70 | + esc_html_e( |
|
| 71 | + 'Add New Datetime', |
|
| 72 | + 'event_espresso' |
|
| 73 | + ); ?></h4><?php echo wp_kses($add_new_dtt_help_link, AllowedTags::getAllowedTags()); ?> |
|
| 74 | 74 | <div> |
| 75 | 75 | <table id="add-new-event-datetime-table" class="datetime-edit-table"> |
| 76 | 76 | <tr> |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | <td class="event-datetime-column date-column"> |
| 85 | 85 | <label class="add-new-event-datetime-DTT_EVT_start_label" |
| 86 | 86 | for="add-new-event-datetime-DTT_EVT_start"><?php |
| 87 | - esc_html_e( |
|
| 88 | - 'Event Start', |
|
| 89 | - 'event_espresso' |
|
| 90 | - ); ?></label> |
|
| 87 | + esc_html_e( |
|
| 88 | + 'Event Start', |
|
| 89 | + 'event_espresso' |
|
| 90 | + ); ?></label> |
|
| 91 | 91 | <input type="text" name="add_new_datetime[DTT_EVT_start]" |
| 92 | 92 | id="add-new-event-datetime-DTT_EVT_start" class="ee-text-inp ee-datepicker" |
| 93 | 93 | data-context="start-dtt" data-date-field-context="#add-event-datetime" |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | <td class="event-datetime-column date-column"> |
| 98 | 98 | <label class="add-new-event-datetime-DTT_EVT_end_label" |
| 99 | 99 | for="add-new-event-datetime-DTT_EVT_end"><?php |
| 100 | - esc_html_e( |
|
| 101 | - 'Event End', |
|
| 102 | - 'event_espresso' |
|
| 103 | - ); ?></label> |
|
| 100 | + esc_html_e( |
|
| 101 | + 'Event End', |
|
| 102 | + 'event_espresso' |
|
| 103 | + ); ?></label> |
|
| 104 | 104 | <input type="text" name="add_new_datetime[DTT_EVT_end]" id="add-new-event-datetime-DTT_EVT_end" |
| 105 | 105 | class="ee-text-inp ee-datepicker" data-context="end-dtt" |
| 106 | 106 | data-date-field-context="#add-event-datetime" |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | <td class="event-datetime-column reg-limit-column"> |
| 111 | 111 | <label class="add-new-event-datetime-DTT_EVT_end_label" |
| 112 | 112 | for="add-new-event-datetime-DTT_reg_limit"><?php |
| 113 | - esc_html_e( |
|
| 114 | - 'Limit', |
|
| 115 | - 'event_espresso' |
|
| 116 | - ); ?></label> |
|
| 113 | + esc_html_e( |
|
| 114 | + 'Limit', |
|
| 115 | + 'event_espresso' |
|
| 116 | + ); ?></label> |
|
| 117 | 117 | <input type="text" name="add_new_datetime[DTT_reg_limit]" |
| 118 | 118 | id="add-new-event-datetime-DTT_reg_limit" class="ee-numeric ee-small-text-inp"> |
| 119 | 119 | </td> |
@@ -136,16 +136,16 @@ discard block |
||
| 136 | 136 | <h3 class="event-tickets-datetimes-title"><span data-target=".event-tickets-container" |
| 137 | 137 | class="clickable ee-collapsible <?php echo sanitize_html_class($ee_collapsible_status); ?>"><span |
| 138 | 138 | class="ee-icon ee-icon-tickets ee-icon-size-20"></span><?php |
| 139 | - esc_html_e( |
|
| 140 | - 'Available Tickets', |
|
| 141 | - 'event_espresso' |
|
| 142 | - ); ?></span></h3> |
|
| 139 | + esc_html_e( |
|
| 140 | + 'Available Tickets', |
|
| 141 | + 'event_espresso' |
|
| 142 | + ); ?></span></h3> |
|
| 143 | 143 | <div class="event-tickets-container ee-create-ticket-button"> |
| 144 | 144 | <button class="ee-create-ticket-button button-secondary ee-create-button" data-context="ticket"><?php |
| 145 | - esc_html_e( |
|
| 146 | - 'Create Ticket', |
|
| 147 | - 'event_espresso' |
|
| 148 | - ); ?></button> |
|
| 145 | + esc_html_e( |
|
| 146 | + 'Create Ticket', |
|
| 147 | + 'event_espresso' |
|
| 148 | + ); ?></button> |
|
| 149 | 149 | </div> |
| 150 | 150 | <div style="clear:both"></div> |
| 151 | 151 | <div class="event-tickets-container"> |
@@ -15,2201 +15,2201 @@ |
||
| 15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * This property is just used to hold the status of whether an event is currently being |
|
| 20 | - * created (true) or edited (false) |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $_is_creating_event; |
|
| 18 | + /** |
|
| 19 | + * This property is just used to hold the status of whether an event is currently being |
|
| 20 | + * created (true) or edited (false) |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $_is_creating_event; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Used to contain the format strings for date and time that will be used for php date and |
|
| 29 | - * time. |
|
| 30 | - * Is set in the _set_hooks_properties() method. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $_date_format_strings; |
|
| 27 | + /** |
|
| 28 | + * Used to contain the format strings for date and time that will be used for php date and |
|
| 29 | + * time. |
|
| 30 | + * Is set in the _set_hooks_properties() method. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $_date_format_strings; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string $_date_time_format |
|
| 38 | - */ |
|
| 39 | - protected $_date_time_format; |
|
| 36 | + /** |
|
| 37 | + * @var string $_date_time_format |
|
| 38 | + */ |
|
| 39 | + protected $_date_time_format; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @throws InvalidArgumentException |
|
| 44 | - * @throws InvalidInterfaceException |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - protected function _set_hooks_properties() |
|
| 48 | - { |
|
| 49 | - $this->_name = 'pricing'; |
|
| 50 | - // capability check |
|
| 51 | - if ( |
|
| 52 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
| 53 | - 'ee_read_default_prices', |
|
| 54 | - 'advanced_ticket_datetime_metabox' |
|
| 55 | - ) |
|
| 56 | - ) { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - $this->_setup_metaboxes(); |
|
| 60 | - $this->_set_date_time_formats(); |
|
| 61 | - $this->_validate_format_strings(); |
|
| 62 | - $this->_set_scripts_styles(); |
|
| 63 | - // commented out temporarily until logic is implemented in callback |
|
| 64 | - // add_action( |
|
| 65 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 66 | - // array($this, 'autosave_handling') |
|
| 67 | - // ); |
|
| 68 | - add_filter( |
|
| 69 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 70 | - array($this, 'caf_updates') |
|
| 71 | - ); |
|
| 72 | - } |
|
| 42 | + /** |
|
| 43 | + * @throws InvalidArgumentException |
|
| 44 | + * @throws InvalidInterfaceException |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + protected function _set_hooks_properties() |
|
| 48 | + { |
|
| 49 | + $this->_name = 'pricing'; |
|
| 50 | + // capability check |
|
| 51 | + if ( |
|
| 52 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
| 53 | + 'ee_read_default_prices', |
|
| 54 | + 'advanced_ticket_datetime_metabox' |
|
| 55 | + ) |
|
| 56 | + ) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + $this->_setup_metaboxes(); |
|
| 60 | + $this->_set_date_time_formats(); |
|
| 61 | + $this->_validate_format_strings(); |
|
| 62 | + $this->_set_scripts_styles(); |
|
| 63 | + // commented out temporarily until logic is implemented in callback |
|
| 64 | + // add_action( |
|
| 65 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 66 | + // array($this, 'autosave_handling') |
|
| 67 | + // ); |
|
| 68 | + add_filter( |
|
| 69 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 70 | + array($this, 'caf_updates') |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return void |
|
| 77 | - */ |
|
| 78 | - protected function _setup_metaboxes() |
|
| 79 | - { |
|
| 80 | - // if we were going to add our own metaboxes we'd use the below. |
|
| 81 | - $this->_metaboxes = array( |
|
| 82 | - 0 => array( |
|
| 83 | - 'page_route' => array('edit', 'create_new'), |
|
| 84 | - 'func' => 'pricing_metabox', |
|
| 85 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 86 | - 'priority' => 'high', |
|
| 87 | - 'context' => 'normal', |
|
| 88 | - ), |
|
| 89 | - ); |
|
| 90 | - $this->_remove_metaboxes = array( |
|
| 91 | - 0 => array( |
|
| 92 | - 'page_route' => array('edit', 'create_new'), |
|
| 93 | - 'id' => 'espresso_event_editor_tickets', |
|
| 94 | - 'context' => 'normal', |
|
| 95 | - ), |
|
| 96 | - ); |
|
| 97 | - } |
|
| 75 | + /** |
|
| 76 | + * @return void |
|
| 77 | + */ |
|
| 78 | + protected function _setup_metaboxes() |
|
| 79 | + { |
|
| 80 | + // if we were going to add our own metaboxes we'd use the below. |
|
| 81 | + $this->_metaboxes = array( |
|
| 82 | + 0 => array( |
|
| 83 | + 'page_route' => array('edit', 'create_new'), |
|
| 84 | + 'func' => 'pricing_metabox', |
|
| 85 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 86 | + 'priority' => 'high', |
|
| 87 | + 'context' => 'normal', |
|
| 88 | + ), |
|
| 89 | + ); |
|
| 90 | + $this->_remove_metaboxes = array( |
|
| 91 | + 0 => array( |
|
| 92 | + 'page_route' => array('edit', 'create_new'), |
|
| 93 | + 'id' => 'espresso_event_editor_tickets', |
|
| 94 | + 'context' => 'normal', |
|
| 95 | + ), |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - protected function _set_date_time_formats() |
|
| 104 | - { |
|
| 105 | - /** |
|
| 106 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 107 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 108 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 109 | - * |
|
| 110 | - * @since 4.6.7 |
|
| 111 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 112 | - */ |
|
| 113 | - $this->_date_format_strings = apply_filters( |
|
| 114 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 115 | - array( |
|
| 116 | - 'date' => 'Y-m-d', |
|
| 117 | - 'time' => 'h:i a', |
|
| 118 | - ) |
|
| 119 | - ); |
|
| 120 | - // validate |
|
| 121 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 122 | - ? $this->_date_format_strings['date'] |
|
| 123 | - : null; |
|
| 124 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 125 | - ? $this->_date_format_strings['time'] |
|
| 126 | - : null; |
|
| 127 | - $this->_date_time_format = $this->_date_format_strings['date'] |
|
| 128 | - . ' ' |
|
| 129 | - . $this->_date_format_strings['time']; |
|
| 130 | - } |
|
| 100 | + /** |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + protected function _set_date_time_formats() |
|
| 104 | + { |
|
| 105 | + /** |
|
| 106 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 107 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 108 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 109 | + * |
|
| 110 | + * @since 4.6.7 |
|
| 111 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 112 | + */ |
|
| 113 | + $this->_date_format_strings = apply_filters( |
|
| 114 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 115 | + array( |
|
| 116 | + 'date' => 'Y-m-d', |
|
| 117 | + 'time' => 'h:i a', |
|
| 118 | + ) |
|
| 119 | + ); |
|
| 120 | + // validate |
|
| 121 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 122 | + ? $this->_date_format_strings['date'] |
|
| 123 | + : null; |
|
| 124 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 125 | + ? $this->_date_format_strings['time'] |
|
| 126 | + : null; |
|
| 127 | + $this->_date_time_format = $this->_date_format_strings['date'] |
|
| 128 | + . ' ' |
|
| 129 | + . $this->_date_format_strings['time']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return void |
|
| 135 | - */ |
|
| 136 | - protected function _validate_format_strings() |
|
| 137 | - { |
|
| 138 | - // validate format strings |
|
| 139 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 140 | - $this->_date_time_format |
|
| 141 | - ); |
|
| 142 | - if (is_array($format_validation)) { |
|
| 143 | - $msg = '<p>'; |
|
| 144 | - $msg .= sprintf( |
|
| 145 | - esc_html__( |
|
| 146 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 147 | - 'event_espresso' |
|
| 148 | - ), |
|
| 149 | - $this->_date_time_format |
|
| 150 | - ); |
|
| 151 | - $msg .= '</p><ul>'; |
|
| 152 | - foreach ($format_validation as $error) { |
|
| 153 | - $msg .= '<li>' . $error . '</li>'; |
|
| 154 | - } |
|
| 155 | - $msg .= '</ul><p>'; |
|
| 156 | - $msg .= sprintf( |
|
| 157 | - esc_html__( |
|
| 158 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ), |
|
| 161 | - '<span style="color:#D54E21;">', |
|
| 162 | - '</span>' |
|
| 163 | - ); |
|
| 164 | - $msg .= '</p>'; |
|
| 165 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 166 | - $this->_date_format_strings = array( |
|
| 167 | - 'date' => 'Y-m-d', |
|
| 168 | - 'time' => 'h:i a', |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - } |
|
| 133 | + /** |
|
| 134 | + * @return void |
|
| 135 | + */ |
|
| 136 | + protected function _validate_format_strings() |
|
| 137 | + { |
|
| 138 | + // validate format strings |
|
| 139 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 140 | + $this->_date_time_format |
|
| 141 | + ); |
|
| 142 | + if (is_array($format_validation)) { |
|
| 143 | + $msg = '<p>'; |
|
| 144 | + $msg .= sprintf( |
|
| 145 | + esc_html__( |
|
| 146 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 147 | + 'event_espresso' |
|
| 148 | + ), |
|
| 149 | + $this->_date_time_format |
|
| 150 | + ); |
|
| 151 | + $msg .= '</p><ul>'; |
|
| 152 | + foreach ($format_validation as $error) { |
|
| 153 | + $msg .= '<li>' . $error . '</li>'; |
|
| 154 | + } |
|
| 155 | + $msg .= '</ul><p>'; |
|
| 156 | + $msg .= sprintf( |
|
| 157 | + esc_html__( |
|
| 158 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ), |
|
| 161 | + '<span style="color:#D54E21;">', |
|
| 162 | + '</span>' |
|
| 163 | + ); |
|
| 164 | + $msg .= '</p>'; |
|
| 165 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 166 | + $this->_date_format_strings = array( |
|
| 167 | + 'date' => 'Y-m-d', |
|
| 168 | + 'time' => 'h:i a', |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * @return void |
|
| 176 | - */ |
|
| 177 | - protected function _set_scripts_styles() |
|
| 178 | - { |
|
| 179 | - $this->_scripts_styles = array( |
|
| 180 | - 'registers' => array( |
|
| 181 | - 'ee-tickets-datetimes-css' => array( |
|
| 182 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 183 | - 'type' => 'css', |
|
| 184 | - ), |
|
| 185 | - 'ee-dtt-ticket-metabox' => array( |
|
| 186 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 187 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 188 | - ), |
|
| 189 | - ), |
|
| 190 | - 'deregisters' => array( |
|
| 191 | - 'event-editor-css' => array('type' => 'css'), |
|
| 192 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
| 193 | - ), |
|
| 194 | - 'enqueues' => array( |
|
| 195 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 196 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 197 | - ), |
|
| 198 | - 'localize' => array( |
|
| 199 | - 'ee-dtt-ticket-metabox' => array( |
|
| 200 | - 'DTT_TRASH_BLOCK' => array( |
|
| 201 | - 'main_warning' => esc_html__( |
|
| 202 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 203 | - 'event_espresso' |
|
| 204 | - ), |
|
| 205 | - 'after_warning' => esc_html__( |
|
| 206 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 207 | - 'event_espresso' |
|
| 208 | - ), |
|
| 209 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 210 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 211 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 212 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 213 | - 'single_warning_from_tkt' => esc_html__( |
|
| 214 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 215 | - 'event_espresso' |
|
| 216 | - ), |
|
| 217 | - 'single_warning_from_dtt' => esc_html__( |
|
| 218 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 219 | - 'event_espresso' |
|
| 220 | - ), |
|
| 221 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 222 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 223 | - ), |
|
| 224 | - 'DTT_ERROR_MSG' => array( |
|
| 225 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 226 | - 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
| 227 | - . '<button class="button-secondary ee-modal-cancel">' |
|
| 228 | - . esc_html__('Dismiss', 'event_espresso') |
|
| 229 | - . '</button></div>', |
|
| 230 | - ), |
|
| 231 | - 'DTT_OVERSELL_WARNING' => array( |
|
| 232 | - 'datetime_ticket' => esc_html__( |
|
| 233 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 234 | - 'event_espresso' |
|
| 235 | - ), |
|
| 236 | - 'ticket_datetime' => esc_html__( |
|
| 237 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 238 | - 'event_espresso' |
|
| 239 | - ), |
|
| 240 | - ), |
|
| 241 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 242 | - $this->_date_format_strings['date'], |
|
| 243 | - $this->_date_format_strings['time'] |
|
| 244 | - ), |
|
| 245 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
| 246 | - ), |
|
| 247 | - ), |
|
| 248 | - ); |
|
| 249 | - } |
|
| 174 | + /** |
|
| 175 | + * @return void |
|
| 176 | + */ |
|
| 177 | + protected function _set_scripts_styles() |
|
| 178 | + { |
|
| 179 | + $this->_scripts_styles = array( |
|
| 180 | + 'registers' => array( |
|
| 181 | + 'ee-tickets-datetimes-css' => array( |
|
| 182 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 183 | + 'type' => 'css', |
|
| 184 | + ), |
|
| 185 | + 'ee-dtt-ticket-metabox' => array( |
|
| 186 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 187 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 188 | + ), |
|
| 189 | + ), |
|
| 190 | + 'deregisters' => array( |
|
| 191 | + 'event-editor-css' => array('type' => 'css'), |
|
| 192 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
| 193 | + ), |
|
| 194 | + 'enqueues' => array( |
|
| 195 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 196 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 197 | + ), |
|
| 198 | + 'localize' => array( |
|
| 199 | + 'ee-dtt-ticket-metabox' => array( |
|
| 200 | + 'DTT_TRASH_BLOCK' => array( |
|
| 201 | + 'main_warning' => esc_html__( |
|
| 202 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 203 | + 'event_espresso' |
|
| 204 | + ), |
|
| 205 | + 'after_warning' => esc_html__( |
|
| 206 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 207 | + 'event_espresso' |
|
| 208 | + ), |
|
| 209 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 210 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 211 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 212 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 213 | + 'single_warning_from_tkt' => esc_html__( |
|
| 214 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 215 | + 'event_espresso' |
|
| 216 | + ), |
|
| 217 | + 'single_warning_from_dtt' => esc_html__( |
|
| 218 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 219 | + 'event_espresso' |
|
| 220 | + ), |
|
| 221 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 222 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 223 | + ), |
|
| 224 | + 'DTT_ERROR_MSG' => array( |
|
| 225 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 226 | + 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
| 227 | + . '<button class="button-secondary ee-modal-cancel">' |
|
| 228 | + . esc_html__('Dismiss', 'event_espresso') |
|
| 229 | + . '</button></div>', |
|
| 230 | + ), |
|
| 231 | + 'DTT_OVERSELL_WARNING' => array( |
|
| 232 | + 'datetime_ticket' => esc_html__( |
|
| 233 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 234 | + 'event_espresso' |
|
| 235 | + ), |
|
| 236 | + 'ticket_datetime' => esc_html__( |
|
| 237 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 238 | + 'event_espresso' |
|
| 239 | + ), |
|
| 240 | + ), |
|
| 241 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 242 | + $this->_date_format_strings['date'], |
|
| 243 | + $this->_date_format_strings['time'] |
|
| 244 | + ), |
|
| 245 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
| 246 | + ), |
|
| 247 | + ), |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * @param array $update_callbacks |
|
| 254 | - * @return array |
|
| 255 | - */ |
|
| 256 | - public function caf_updates(array $update_callbacks) |
|
| 257 | - { |
|
| 258 | - foreach ($update_callbacks as $key => $callback) { |
|
| 259 | - if ($callback[1] === '_default_tickets_update') { |
|
| 260 | - unset($update_callbacks[ $key ]); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 264 | - return $update_callbacks; |
|
| 265 | - } |
|
| 252 | + /** |
|
| 253 | + * @param array $update_callbacks |
|
| 254 | + * @return array |
|
| 255 | + */ |
|
| 256 | + public function caf_updates(array $update_callbacks) |
|
| 257 | + { |
|
| 258 | + foreach ($update_callbacks as $key => $callback) { |
|
| 259 | + if ($callback[1] === '_default_tickets_update') { |
|
| 260 | + unset($update_callbacks[ $key ]); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 264 | + return $update_callbacks; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 270 | - * |
|
| 271 | - * @param EE_Event $event The Event object we're attaching data to |
|
| 272 | - * @param array $data The request data from the form |
|
| 273 | - * @throws ReflectionException |
|
| 274 | - * @throws Exception |
|
| 275 | - * @throws InvalidInterfaceException |
|
| 276 | - * @throws InvalidDataTypeException |
|
| 277 | - * @throws EE_Error |
|
| 278 | - * @throws InvalidArgumentException |
|
| 279 | - */ |
|
| 280 | - public function datetime_and_tickets_caf_update($event, $data) |
|
| 281 | - { |
|
| 282 | - // first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 283 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 284 | - // next tackle the tickets (and prices?) |
|
| 285 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 286 | - } |
|
| 268 | + /** |
|
| 269 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 270 | + * |
|
| 271 | + * @param EE_Event $event The Event object we're attaching data to |
|
| 272 | + * @param array $data The request data from the form |
|
| 273 | + * @throws ReflectionException |
|
| 274 | + * @throws Exception |
|
| 275 | + * @throws InvalidInterfaceException |
|
| 276 | + * @throws InvalidDataTypeException |
|
| 277 | + * @throws EE_Error |
|
| 278 | + * @throws InvalidArgumentException |
|
| 279 | + */ |
|
| 280 | + public function datetime_and_tickets_caf_update($event, $data) |
|
| 281 | + { |
|
| 282 | + // first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 283 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 284 | + // next tackle the tickets (and prices?) |
|
| 285 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * update event_datetimes |
|
| 291 | - * |
|
| 292 | - * @param EE_Event $event Event being updated |
|
| 293 | - * @param array $data the request data from the form |
|
| 294 | - * @return EE_Datetime[] |
|
| 295 | - * @throws Exception |
|
| 296 | - * @throws ReflectionException |
|
| 297 | - * @throws InvalidInterfaceException |
|
| 298 | - * @throws InvalidDataTypeException |
|
| 299 | - * @throws InvalidArgumentException |
|
| 300 | - * @throws EE_Error |
|
| 301 | - */ |
|
| 302 | - protected function _update_datetimes($event, $data) |
|
| 303 | - { |
|
| 304 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 305 | - $saved_dtt_ids = array(); |
|
| 306 | - $saved_dtt_objs = array(); |
|
| 307 | - if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
| 308 | - throw new InvalidArgumentException( |
|
| 309 | - esc_html__( |
|
| 310 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 311 | - 'event_espresso' |
|
| 312 | - ) |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 316 | - // trim all values to ensure any excess whitespace is removed. |
|
| 317 | - $datetime_data = array_map( |
|
| 318 | - function ($datetime_data) { |
|
| 319 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 320 | - }, |
|
| 321 | - $datetime_data |
|
| 322 | - ); |
|
| 323 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 324 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
| 325 | - ? $datetime_data['DTT_EVT_end'] |
|
| 326 | - : $datetime_data['DTT_EVT_start']; |
|
| 327 | - $datetime_values = array( |
|
| 328 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 329 | - ? $datetime_data['DTT_ID'] |
|
| 330 | - : null, |
|
| 331 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 332 | - ? $datetime_data['DTT_name'] |
|
| 333 | - : '', |
|
| 334 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 335 | - ? $datetime_data['DTT_description'] |
|
| 336 | - : '', |
|
| 337 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 338 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 339 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 340 | - ? EE_INF |
|
| 341 | - : $datetime_data['DTT_reg_limit'], |
|
| 342 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 343 | - ? $row |
|
| 344 | - : $datetime_data['DTT_order'], |
|
| 345 | - ); |
|
| 346 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 347 | - // Otherwise we instantiate a new object for save. |
|
| 348 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 349 | - $datetime = EE_Registry::instance() |
|
| 350 | - ->load_model('Datetime', array($timezone)) |
|
| 351 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 352 | - // set date and time format according to what is set in this class. |
|
| 353 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 354 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 355 | - foreach ($datetime_values as $field => $value) { |
|
| 356 | - $datetime->set($field, $value); |
|
| 357 | - } |
|
| 358 | - // make sure the $dtt_id here is saved just in case |
|
| 359 | - // after the add_relation_to() the autosave replaces it. |
|
| 360 | - // We need to do this so we dont' TRASH the parent DTT. |
|
| 361 | - // (save the ID for both key and value to avoid duplications) |
|
| 362 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 363 | - } else { |
|
| 364 | - $datetime = EE_Registry::instance()->load_class( |
|
| 365 | - 'Datetime', |
|
| 366 | - array( |
|
| 367 | - $datetime_values, |
|
| 368 | - $timezone, |
|
| 369 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 370 | - ), |
|
| 371 | - false, |
|
| 372 | - false |
|
| 373 | - ); |
|
| 374 | - foreach ($datetime_values as $field => $value) { |
|
| 375 | - $datetime->set($field, $value); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - $datetime->save(); |
|
| 379 | - do_action( |
|
| 380 | - 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
| 381 | - $datetime, |
|
| 382 | - $row, |
|
| 383 | - $datetime_data, |
|
| 384 | - $data |
|
| 385 | - ); |
|
| 386 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 387 | - // before going any further make sure our dates are setup correctly |
|
| 388 | - // so that the end date is always equal or greater than the start date. |
|
| 389 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 390 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 391 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 392 | - $datetime->save(); |
|
| 393 | - } |
|
| 394 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 395 | - // because it is possible there was a new one created for the autosave. |
|
| 396 | - // (save the ID for both key and value to avoid duplications) |
|
| 397 | - $DTT_ID = $datetime->ID(); |
|
| 398 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 399 | - $saved_dtt_objs[ $row ] = $datetime; |
|
| 400 | - // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 401 | - } |
|
| 402 | - $event->save(); |
|
| 403 | - // now we need to REMOVE any datetimes that got deleted. |
|
| 404 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 405 | - // So its safe to permanently delete at this point. |
|
| 406 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 407 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 408 | - if (is_array($old_datetimes)) { |
|
| 409 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 410 | - foreach ($datetimes_to_delete as $id) { |
|
| 411 | - $id = absint($id); |
|
| 412 | - if (empty($id)) { |
|
| 413 | - continue; |
|
| 414 | - } |
|
| 415 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 416 | - // remove tkt relationships. |
|
| 417 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 418 | - foreach ($related_tickets as $tkt) { |
|
| 419 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 420 | - } |
|
| 421 | - $event->_remove_relation_to($id, 'Datetime'); |
|
| 422 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - return $saved_dtt_objs; |
|
| 426 | - } |
|
| 289 | + /** |
|
| 290 | + * update event_datetimes |
|
| 291 | + * |
|
| 292 | + * @param EE_Event $event Event being updated |
|
| 293 | + * @param array $data the request data from the form |
|
| 294 | + * @return EE_Datetime[] |
|
| 295 | + * @throws Exception |
|
| 296 | + * @throws ReflectionException |
|
| 297 | + * @throws InvalidInterfaceException |
|
| 298 | + * @throws InvalidDataTypeException |
|
| 299 | + * @throws InvalidArgumentException |
|
| 300 | + * @throws EE_Error |
|
| 301 | + */ |
|
| 302 | + protected function _update_datetimes($event, $data) |
|
| 303 | + { |
|
| 304 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 305 | + $saved_dtt_ids = array(); |
|
| 306 | + $saved_dtt_objs = array(); |
|
| 307 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
| 308 | + throw new InvalidArgumentException( |
|
| 309 | + esc_html__( |
|
| 310 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 311 | + 'event_espresso' |
|
| 312 | + ) |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 316 | + // trim all values to ensure any excess whitespace is removed. |
|
| 317 | + $datetime_data = array_map( |
|
| 318 | + function ($datetime_data) { |
|
| 319 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 320 | + }, |
|
| 321 | + $datetime_data |
|
| 322 | + ); |
|
| 323 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 324 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
| 325 | + ? $datetime_data['DTT_EVT_end'] |
|
| 326 | + : $datetime_data['DTT_EVT_start']; |
|
| 327 | + $datetime_values = array( |
|
| 328 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 329 | + ? $datetime_data['DTT_ID'] |
|
| 330 | + : null, |
|
| 331 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 332 | + ? $datetime_data['DTT_name'] |
|
| 333 | + : '', |
|
| 334 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 335 | + ? $datetime_data['DTT_description'] |
|
| 336 | + : '', |
|
| 337 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 338 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 339 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 340 | + ? EE_INF |
|
| 341 | + : $datetime_data['DTT_reg_limit'], |
|
| 342 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 343 | + ? $row |
|
| 344 | + : $datetime_data['DTT_order'], |
|
| 345 | + ); |
|
| 346 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 347 | + // Otherwise we instantiate a new object for save. |
|
| 348 | + if (! empty($datetime_data['DTT_ID'])) { |
|
| 349 | + $datetime = EE_Registry::instance() |
|
| 350 | + ->load_model('Datetime', array($timezone)) |
|
| 351 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 352 | + // set date and time format according to what is set in this class. |
|
| 353 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 354 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 355 | + foreach ($datetime_values as $field => $value) { |
|
| 356 | + $datetime->set($field, $value); |
|
| 357 | + } |
|
| 358 | + // make sure the $dtt_id here is saved just in case |
|
| 359 | + // after the add_relation_to() the autosave replaces it. |
|
| 360 | + // We need to do this so we dont' TRASH the parent DTT. |
|
| 361 | + // (save the ID for both key and value to avoid duplications) |
|
| 362 | + $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 363 | + } else { |
|
| 364 | + $datetime = EE_Registry::instance()->load_class( |
|
| 365 | + 'Datetime', |
|
| 366 | + array( |
|
| 367 | + $datetime_values, |
|
| 368 | + $timezone, |
|
| 369 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 370 | + ), |
|
| 371 | + false, |
|
| 372 | + false |
|
| 373 | + ); |
|
| 374 | + foreach ($datetime_values as $field => $value) { |
|
| 375 | + $datetime->set($field, $value); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + $datetime->save(); |
|
| 379 | + do_action( |
|
| 380 | + 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
| 381 | + $datetime, |
|
| 382 | + $row, |
|
| 383 | + $datetime_data, |
|
| 384 | + $data |
|
| 385 | + ); |
|
| 386 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 387 | + // before going any further make sure our dates are setup correctly |
|
| 388 | + // so that the end date is always equal or greater than the start date. |
|
| 389 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 390 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 391 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 392 | + $datetime->save(); |
|
| 393 | + } |
|
| 394 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 395 | + // because it is possible there was a new one created for the autosave. |
|
| 396 | + // (save the ID for both key and value to avoid duplications) |
|
| 397 | + $DTT_ID = $datetime->ID(); |
|
| 398 | + $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 399 | + $saved_dtt_objs[ $row ] = $datetime; |
|
| 400 | + // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 401 | + } |
|
| 402 | + $event->save(); |
|
| 403 | + // now we need to REMOVE any datetimes that got deleted. |
|
| 404 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 405 | + // So its safe to permanently delete at this point. |
|
| 406 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 407 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 408 | + if (is_array($old_datetimes)) { |
|
| 409 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 410 | + foreach ($datetimes_to_delete as $id) { |
|
| 411 | + $id = absint($id); |
|
| 412 | + if (empty($id)) { |
|
| 413 | + continue; |
|
| 414 | + } |
|
| 415 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 416 | + // remove tkt relationships. |
|
| 417 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 418 | + foreach ($related_tickets as $tkt) { |
|
| 419 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 420 | + } |
|
| 421 | + $event->_remove_relation_to($id, 'Datetime'); |
|
| 422 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + return $saved_dtt_objs; |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | 428 | |
| 429 | - /** |
|
| 430 | - * update tickets |
|
| 431 | - * |
|
| 432 | - * @param EE_Event $event Event object being updated |
|
| 433 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 434 | - * @param array $data incoming request data |
|
| 435 | - * @return EE_Ticket[] |
|
| 436 | - * @throws Exception |
|
| 437 | - * @throws ReflectionException |
|
| 438 | - * @throws InvalidInterfaceException |
|
| 439 | - * @throws InvalidDataTypeException |
|
| 440 | - * @throws InvalidArgumentException |
|
| 441 | - * @throws EE_Error |
|
| 442 | - */ |
|
| 443 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 444 | - { |
|
| 445 | - $new_tkt = null; |
|
| 446 | - // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 447 | - $data = stripslashes_deep($data); |
|
| 448 | - $timezone = $data['timezone_string'] ?? null; |
|
| 449 | - $saved_tickets = array(); |
|
| 450 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 451 | - if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
| 452 | - throw new InvalidArgumentException( |
|
| 453 | - esc_html__( |
|
| 454 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 455 | - 'event_espresso' |
|
| 456 | - ) |
|
| 457 | - ); |
|
| 458 | - } |
|
| 459 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 460 | - $update_prices = $create_new_TKT = false; |
|
| 461 | - // figure out what datetimes were added to the ticket |
|
| 462 | - // and what datetimes were removed from the ticket in the session. |
|
| 463 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 464 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 465 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 466 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 467 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 468 | - $tkt = array_map( |
|
| 469 | - function ($ticket_data) { |
|
| 470 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 471 | - }, |
|
| 472 | - $tkt |
|
| 473 | - ); |
|
| 474 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 475 | - // because we're doing calculations prior to using the models. |
|
| 476 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 477 | - $ticket_price = isset($tkt['TKT_price']) |
|
| 478 | - ? round((float) $tkt['TKT_price'], 3) |
|
| 479 | - : 0; |
|
| 480 | - // note incoming base price needs converted from localized value. |
|
| 481 | - $base_price = isset($tkt['TKT_base_price']) |
|
| 482 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 483 | - : 0; |
|
| 484 | - // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 485 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 486 | - ? $base_price |
|
| 487 | - : $ticket_price; |
|
| 488 | - $base_price_id = $tkt['TKT_base_price_ID'] ?? 0; |
|
| 489 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 490 | - ? $data['edit_prices'][ $row ] |
|
| 491 | - : array(); |
|
| 492 | - $now = null; |
|
| 493 | - if (empty($tkt['TKT_start_date'])) { |
|
| 494 | - // lets' use now in the set timezone. |
|
| 495 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 496 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 497 | - } |
|
| 498 | - if (empty($tkt['TKT_end_date'])) { |
|
| 499 | - /** |
|
| 500 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 501 | - */ |
|
| 502 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 503 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 504 | - } |
|
| 505 | - $TKT_values = array( |
|
| 506 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 507 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 508 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 509 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 510 | - && $tkt['TKT_description'] !== esc_html__( |
|
| 511 | - 'You can modify this description', |
|
| 512 | - 'event_espresso' |
|
| 513 | - ) |
|
| 514 | - ? $tkt['TKT_description'] |
|
| 515 | - : '', |
|
| 516 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 517 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 518 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 519 | - ? EE_INF |
|
| 520 | - : $tkt['TKT_qty'], |
|
| 521 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 522 | - ? EE_INF |
|
| 523 | - : $tkt['TKT_uses'], |
|
| 524 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 525 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 526 | - 'TKT_row' => $row, |
|
| 527 | - 'TKT_order' => $tkt['TKT_order'] ?? 0, |
|
| 528 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 529 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 530 | - 'TKT_price' => $ticket_price, |
|
| 531 | - ); |
|
| 532 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 533 | - // which means in turn that the prices will become new prices as well. |
|
| 534 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 535 | - $TKT_values['TKT_ID'] = 0; |
|
| 536 | - $TKT_values['TKT_is_default'] = 0; |
|
| 537 | - $update_prices = true; |
|
| 538 | - } |
|
| 539 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 540 | - // we actually do our saves ahead of doing any add_relations to |
|
| 541 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 542 | - // but DID have it's items modified. |
|
| 543 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 544 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 545 | - if (absint($TKT_values['TKT_ID'])) { |
|
| 546 | - $ticket = EE_Registry::instance() |
|
| 547 | - ->load_model('Ticket', array($timezone)) |
|
| 548 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 549 | - if ($ticket instanceof EE_Ticket) { |
|
| 550 | - $ticket = $this->_update_ticket_datetimes( |
|
| 551 | - $ticket, |
|
| 552 | - $saved_datetimes, |
|
| 553 | - $datetimes_added, |
|
| 554 | - $datetimes_removed |
|
| 555 | - ); |
|
| 556 | - // are there any registrations using this ticket ? |
|
| 557 | - $tickets_sold = $ticket->count_related( |
|
| 558 | - 'Registration', |
|
| 559 | - array( |
|
| 560 | - array( |
|
| 561 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 562 | - ), |
|
| 563 | - ) |
|
| 564 | - ); |
|
| 565 | - // set ticket formats |
|
| 566 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 567 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 568 | - // let's just check the total price for the existing ticket |
|
| 569 | - // and determine if it matches the new total price. |
|
| 570 | - // if they are different then we create a new ticket (if tickets sold) |
|
| 571 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 572 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 573 | - // set new values |
|
| 574 | - foreach ($TKT_values as $field => $value) { |
|
| 575 | - if ($field === 'TKT_qty') { |
|
| 576 | - $ticket->set_qty($value); |
|
| 577 | - } else { |
|
| 578 | - $ticket->set($field, $value); |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 582 | - // Otherwise we have to create a new ticket. |
|
| 583 | - if ($create_new_TKT) { |
|
| 584 | - $new_tkt = $this->_duplicate_ticket( |
|
| 585 | - $ticket, |
|
| 586 | - $price_rows, |
|
| 587 | - $ticket_price, |
|
| 588 | - $base_price, |
|
| 589 | - $base_price_id |
|
| 590 | - ); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - } else { |
|
| 594 | - // no TKT_id so a new TKT |
|
| 595 | - $ticket = EE_Ticket::new_instance( |
|
| 596 | - $TKT_values, |
|
| 597 | - $timezone, |
|
| 598 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 599 | - ); |
|
| 600 | - if ($ticket instanceof EE_Ticket) { |
|
| 601 | - // make sure ticket has an ID of setting relations won't work |
|
| 602 | - $ticket->save(); |
|
| 603 | - $ticket = $this->_update_ticket_datetimes( |
|
| 604 | - $ticket, |
|
| 605 | - $saved_datetimes, |
|
| 606 | - $datetimes_added, |
|
| 607 | - $datetimes_removed |
|
| 608 | - ); |
|
| 609 | - $update_prices = true; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - // make sure any current values have been saved. |
|
| 613 | - // $ticket->save(); |
|
| 614 | - // before going any further make sure our dates are setup correctly |
|
| 615 | - // so that the end date is always equal or greater than the start date. |
|
| 616 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 617 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 618 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 619 | - } |
|
| 620 | - // let's make sure the base price is handled |
|
| 621 | - $ticket = ! $create_new_TKT |
|
| 622 | - ? $this->_add_prices_to_ticket( |
|
| 623 | - array(), |
|
| 624 | - $ticket, |
|
| 625 | - $update_prices, |
|
| 626 | - $base_price, |
|
| 627 | - $base_price_id |
|
| 628 | - ) |
|
| 629 | - : $ticket; |
|
| 630 | - // add/update price_modifiers |
|
| 631 | - $ticket = ! $create_new_TKT |
|
| 632 | - ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
| 633 | - : $ticket; |
|
| 634 | - // need to make sue that the TKT_price is accurate after saving the prices. |
|
| 635 | - $ticket->ensure_TKT_Price_correct(); |
|
| 636 | - // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 637 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 638 | - $update_prices = true; |
|
| 639 | - $new_default = clone $ticket; |
|
| 640 | - $new_default->set('TKT_ID', 0); |
|
| 641 | - $new_default->set('TKT_is_default', 1); |
|
| 642 | - $new_default->set('TKT_row', 1); |
|
| 643 | - $new_default->set('TKT_price', $ticket_price); |
|
| 644 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 645 | - // (note this is just removing the cached relations in the object) |
|
| 646 | - $new_default->_remove_relations('Datetime'); |
|
| 647 | - // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 648 | - $new_default = $this->_add_prices_to_ticket( |
|
| 649 | - $price_rows, |
|
| 650 | - $new_default, |
|
| 651 | - $update_prices |
|
| 652 | - ); |
|
| 653 | - // don't forget the base price! |
|
| 654 | - $new_default = $this->_add_prices_to_ticket( |
|
| 655 | - array(), |
|
| 656 | - $new_default, |
|
| 657 | - $update_prices, |
|
| 658 | - $base_price, |
|
| 659 | - $base_price_id |
|
| 660 | - ); |
|
| 661 | - $new_default->save(); |
|
| 662 | - do_action( |
|
| 663 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 664 | - $new_default, |
|
| 665 | - $row, |
|
| 666 | - $ticket, |
|
| 667 | - $data |
|
| 668 | - ); |
|
| 669 | - } |
|
| 670 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 671 | - // for the given dtt that are related to the current ticket. |
|
| 672 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 673 | - // what current ticket the archived tickets are related to |
|
| 674 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 675 | - // let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 676 | - // save existing TKT |
|
| 677 | - $ticket->save(); |
|
| 678 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 679 | - // save new TKT |
|
| 680 | - $new_tkt->save(); |
|
| 681 | - // add new ticket to array |
|
| 682 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 683 | - do_action( |
|
| 684 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 685 | - $new_tkt, |
|
| 686 | - $row, |
|
| 687 | - $tkt, |
|
| 688 | - $data |
|
| 689 | - ); |
|
| 690 | - } else { |
|
| 691 | - // add tkt to saved tkts |
|
| 692 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 693 | - do_action( |
|
| 694 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 695 | - $ticket, |
|
| 696 | - $row, |
|
| 697 | - $tkt, |
|
| 698 | - $data |
|
| 699 | - ); |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - // now we need to handle tickets actually "deleted permanently". |
|
| 703 | - // There are cases where we'd want this to happen |
|
| 704 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 705 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 706 | - // No sense in keeping all the related data in the db! |
|
| 707 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 708 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 709 | - foreach ($tickets_removed as $id) { |
|
| 710 | - $id = absint($id); |
|
| 711 | - // get the ticket for this id |
|
| 712 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 713 | - // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 714 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 715 | - continue; |
|
| 716 | - } |
|
| 717 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 718 | - // because we don't actually permanently delete these tickets. |
|
| 719 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 720 | - $tkt_to_remove->delete(); |
|
| 721 | - continue; |
|
| 722 | - } |
|
| 723 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 724 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 725 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 726 | - foreach ($datetimes as $datetime) { |
|
| 727 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 728 | - } |
|
| 729 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 730 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 731 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 732 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 733 | - // finally let's delete this ticket |
|
| 734 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 735 | - $tkt_to_remove->delete_permanently(); |
|
| 736 | - } |
|
| 737 | - return $saved_tickets; |
|
| 738 | - } |
|
| 429 | + /** |
|
| 430 | + * update tickets |
|
| 431 | + * |
|
| 432 | + * @param EE_Event $event Event object being updated |
|
| 433 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 434 | + * @param array $data incoming request data |
|
| 435 | + * @return EE_Ticket[] |
|
| 436 | + * @throws Exception |
|
| 437 | + * @throws ReflectionException |
|
| 438 | + * @throws InvalidInterfaceException |
|
| 439 | + * @throws InvalidDataTypeException |
|
| 440 | + * @throws InvalidArgumentException |
|
| 441 | + * @throws EE_Error |
|
| 442 | + */ |
|
| 443 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 444 | + { |
|
| 445 | + $new_tkt = null; |
|
| 446 | + // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 447 | + $data = stripslashes_deep($data); |
|
| 448 | + $timezone = $data['timezone_string'] ?? null; |
|
| 449 | + $saved_tickets = array(); |
|
| 450 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 451 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
| 452 | + throw new InvalidArgumentException( |
|
| 453 | + esc_html__( |
|
| 454 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 455 | + 'event_espresso' |
|
| 456 | + ) |
|
| 457 | + ); |
|
| 458 | + } |
|
| 459 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 460 | + $update_prices = $create_new_TKT = false; |
|
| 461 | + // figure out what datetimes were added to the ticket |
|
| 462 | + // and what datetimes were removed from the ticket in the session. |
|
| 463 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 464 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 465 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 466 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 467 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 468 | + $tkt = array_map( |
|
| 469 | + function ($ticket_data) { |
|
| 470 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 471 | + }, |
|
| 472 | + $tkt |
|
| 473 | + ); |
|
| 474 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 475 | + // because we're doing calculations prior to using the models. |
|
| 476 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 477 | + $ticket_price = isset($tkt['TKT_price']) |
|
| 478 | + ? round((float) $tkt['TKT_price'], 3) |
|
| 479 | + : 0; |
|
| 480 | + // note incoming base price needs converted from localized value. |
|
| 481 | + $base_price = isset($tkt['TKT_base_price']) |
|
| 482 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 483 | + : 0; |
|
| 484 | + // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 485 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 486 | + ? $base_price |
|
| 487 | + : $ticket_price; |
|
| 488 | + $base_price_id = $tkt['TKT_base_price_ID'] ?? 0; |
|
| 489 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 490 | + ? $data['edit_prices'][ $row ] |
|
| 491 | + : array(); |
|
| 492 | + $now = null; |
|
| 493 | + if (empty($tkt['TKT_start_date'])) { |
|
| 494 | + // lets' use now in the set timezone. |
|
| 495 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 496 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 497 | + } |
|
| 498 | + if (empty($tkt['TKT_end_date'])) { |
|
| 499 | + /** |
|
| 500 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 501 | + */ |
|
| 502 | + $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 503 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 504 | + } |
|
| 505 | + $TKT_values = array( |
|
| 506 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 507 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 508 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 509 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 510 | + && $tkt['TKT_description'] !== esc_html__( |
|
| 511 | + 'You can modify this description', |
|
| 512 | + 'event_espresso' |
|
| 513 | + ) |
|
| 514 | + ? $tkt['TKT_description'] |
|
| 515 | + : '', |
|
| 516 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 517 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 518 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 519 | + ? EE_INF |
|
| 520 | + : $tkt['TKT_qty'], |
|
| 521 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 522 | + ? EE_INF |
|
| 523 | + : $tkt['TKT_uses'], |
|
| 524 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 525 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 526 | + 'TKT_row' => $row, |
|
| 527 | + 'TKT_order' => $tkt['TKT_order'] ?? 0, |
|
| 528 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 529 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 530 | + 'TKT_price' => $ticket_price, |
|
| 531 | + ); |
|
| 532 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 533 | + // which means in turn that the prices will become new prices as well. |
|
| 534 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 535 | + $TKT_values['TKT_ID'] = 0; |
|
| 536 | + $TKT_values['TKT_is_default'] = 0; |
|
| 537 | + $update_prices = true; |
|
| 538 | + } |
|
| 539 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 540 | + // we actually do our saves ahead of doing any add_relations to |
|
| 541 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 542 | + // but DID have it's items modified. |
|
| 543 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 544 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 545 | + if (absint($TKT_values['TKT_ID'])) { |
|
| 546 | + $ticket = EE_Registry::instance() |
|
| 547 | + ->load_model('Ticket', array($timezone)) |
|
| 548 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 549 | + if ($ticket instanceof EE_Ticket) { |
|
| 550 | + $ticket = $this->_update_ticket_datetimes( |
|
| 551 | + $ticket, |
|
| 552 | + $saved_datetimes, |
|
| 553 | + $datetimes_added, |
|
| 554 | + $datetimes_removed |
|
| 555 | + ); |
|
| 556 | + // are there any registrations using this ticket ? |
|
| 557 | + $tickets_sold = $ticket->count_related( |
|
| 558 | + 'Registration', |
|
| 559 | + array( |
|
| 560 | + array( |
|
| 561 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 562 | + ), |
|
| 563 | + ) |
|
| 564 | + ); |
|
| 565 | + // set ticket formats |
|
| 566 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 567 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 568 | + // let's just check the total price for the existing ticket |
|
| 569 | + // and determine if it matches the new total price. |
|
| 570 | + // if they are different then we create a new ticket (if tickets sold) |
|
| 571 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 572 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 573 | + // set new values |
|
| 574 | + foreach ($TKT_values as $field => $value) { |
|
| 575 | + if ($field === 'TKT_qty') { |
|
| 576 | + $ticket->set_qty($value); |
|
| 577 | + } else { |
|
| 578 | + $ticket->set($field, $value); |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 582 | + // Otherwise we have to create a new ticket. |
|
| 583 | + if ($create_new_TKT) { |
|
| 584 | + $new_tkt = $this->_duplicate_ticket( |
|
| 585 | + $ticket, |
|
| 586 | + $price_rows, |
|
| 587 | + $ticket_price, |
|
| 588 | + $base_price, |
|
| 589 | + $base_price_id |
|
| 590 | + ); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + } else { |
|
| 594 | + // no TKT_id so a new TKT |
|
| 595 | + $ticket = EE_Ticket::new_instance( |
|
| 596 | + $TKT_values, |
|
| 597 | + $timezone, |
|
| 598 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 599 | + ); |
|
| 600 | + if ($ticket instanceof EE_Ticket) { |
|
| 601 | + // make sure ticket has an ID of setting relations won't work |
|
| 602 | + $ticket->save(); |
|
| 603 | + $ticket = $this->_update_ticket_datetimes( |
|
| 604 | + $ticket, |
|
| 605 | + $saved_datetimes, |
|
| 606 | + $datetimes_added, |
|
| 607 | + $datetimes_removed |
|
| 608 | + ); |
|
| 609 | + $update_prices = true; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + // make sure any current values have been saved. |
|
| 613 | + // $ticket->save(); |
|
| 614 | + // before going any further make sure our dates are setup correctly |
|
| 615 | + // so that the end date is always equal or greater than the start date. |
|
| 616 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 617 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 618 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 619 | + } |
|
| 620 | + // let's make sure the base price is handled |
|
| 621 | + $ticket = ! $create_new_TKT |
|
| 622 | + ? $this->_add_prices_to_ticket( |
|
| 623 | + array(), |
|
| 624 | + $ticket, |
|
| 625 | + $update_prices, |
|
| 626 | + $base_price, |
|
| 627 | + $base_price_id |
|
| 628 | + ) |
|
| 629 | + : $ticket; |
|
| 630 | + // add/update price_modifiers |
|
| 631 | + $ticket = ! $create_new_TKT |
|
| 632 | + ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
| 633 | + : $ticket; |
|
| 634 | + // need to make sue that the TKT_price is accurate after saving the prices. |
|
| 635 | + $ticket->ensure_TKT_Price_correct(); |
|
| 636 | + // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 637 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 638 | + $update_prices = true; |
|
| 639 | + $new_default = clone $ticket; |
|
| 640 | + $new_default->set('TKT_ID', 0); |
|
| 641 | + $new_default->set('TKT_is_default', 1); |
|
| 642 | + $new_default->set('TKT_row', 1); |
|
| 643 | + $new_default->set('TKT_price', $ticket_price); |
|
| 644 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 645 | + // (note this is just removing the cached relations in the object) |
|
| 646 | + $new_default->_remove_relations('Datetime'); |
|
| 647 | + // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 648 | + $new_default = $this->_add_prices_to_ticket( |
|
| 649 | + $price_rows, |
|
| 650 | + $new_default, |
|
| 651 | + $update_prices |
|
| 652 | + ); |
|
| 653 | + // don't forget the base price! |
|
| 654 | + $new_default = $this->_add_prices_to_ticket( |
|
| 655 | + array(), |
|
| 656 | + $new_default, |
|
| 657 | + $update_prices, |
|
| 658 | + $base_price, |
|
| 659 | + $base_price_id |
|
| 660 | + ); |
|
| 661 | + $new_default->save(); |
|
| 662 | + do_action( |
|
| 663 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 664 | + $new_default, |
|
| 665 | + $row, |
|
| 666 | + $ticket, |
|
| 667 | + $data |
|
| 668 | + ); |
|
| 669 | + } |
|
| 670 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 671 | + // for the given dtt that are related to the current ticket. |
|
| 672 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 673 | + // what current ticket the archived tickets are related to |
|
| 674 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 675 | + // let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 676 | + // save existing TKT |
|
| 677 | + $ticket->save(); |
|
| 678 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 679 | + // save new TKT |
|
| 680 | + $new_tkt->save(); |
|
| 681 | + // add new ticket to array |
|
| 682 | + $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 683 | + do_action( |
|
| 684 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 685 | + $new_tkt, |
|
| 686 | + $row, |
|
| 687 | + $tkt, |
|
| 688 | + $data |
|
| 689 | + ); |
|
| 690 | + } else { |
|
| 691 | + // add tkt to saved tkts |
|
| 692 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 693 | + do_action( |
|
| 694 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 695 | + $ticket, |
|
| 696 | + $row, |
|
| 697 | + $tkt, |
|
| 698 | + $data |
|
| 699 | + ); |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + // now we need to handle tickets actually "deleted permanently". |
|
| 703 | + // There are cases where we'd want this to happen |
|
| 704 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 705 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 706 | + // No sense in keeping all the related data in the db! |
|
| 707 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 708 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 709 | + foreach ($tickets_removed as $id) { |
|
| 710 | + $id = absint($id); |
|
| 711 | + // get the ticket for this id |
|
| 712 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 713 | + // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 714 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 715 | + continue; |
|
| 716 | + } |
|
| 717 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 718 | + // because we don't actually permanently delete these tickets. |
|
| 719 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 720 | + $tkt_to_remove->delete(); |
|
| 721 | + continue; |
|
| 722 | + } |
|
| 723 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 724 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 725 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 726 | + foreach ($datetimes as $datetime) { |
|
| 727 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 728 | + } |
|
| 729 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 730 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 731 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 732 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 733 | + // finally let's delete this ticket |
|
| 734 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 735 | + $tkt_to_remove->delete_permanently(); |
|
| 736 | + } |
|
| 737 | + return $saved_tickets; |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | 740 | |
| 741 | - /** |
|
| 742 | - * @access protected |
|
| 743 | - * @param EE_Ticket $ticket |
|
| 744 | - * @param \EE_Datetime[] $saved_datetimes |
|
| 745 | - * @param \EE_Datetime[] $added_datetimes |
|
| 746 | - * @param \EE_Datetime[] $removed_datetimes |
|
| 747 | - * @return EE_Ticket |
|
| 748 | - * @throws EE_Error |
|
| 749 | - */ |
|
| 750 | - protected function _update_ticket_datetimes( |
|
| 751 | - EE_Ticket $ticket, |
|
| 752 | - $saved_datetimes = array(), |
|
| 753 | - $added_datetimes = array(), |
|
| 754 | - $removed_datetimes = array() |
|
| 755 | - ) { |
|
| 756 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 757 | - // and removing the ticket from datetimes it got removed from. |
|
| 758 | - // first let's add datetimes |
|
| 759 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 760 | - foreach ($added_datetimes as $row_id) { |
|
| 761 | - $row_id = (int) $row_id; |
|
| 762 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 763 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 764 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 765 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 766 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 767 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - // then remove datetimes |
|
| 773 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 774 | - foreach ($removed_datetimes as $row_id) { |
|
| 775 | - $row_id = (int) $row_id; |
|
| 776 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 777 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 778 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 779 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 780 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 781 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
| 782 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 783 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - // cap ticket qty by datetime reg limits |
|
| 789 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 790 | - return $ticket; |
|
| 791 | - } |
|
| 741 | + /** |
|
| 742 | + * @access protected |
|
| 743 | + * @param EE_Ticket $ticket |
|
| 744 | + * @param \EE_Datetime[] $saved_datetimes |
|
| 745 | + * @param \EE_Datetime[] $added_datetimes |
|
| 746 | + * @param \EE_Datetime[] $removed_datetimes |
|
| 747 | + * @return EE_Ticket |
|
| 748 | + * @throws EE_Error |
|
| 749 | + */ |
|
| 750 | + protected function _update_ticket_datetimes( |
|
| 751 | + EE_Ticket $ticket, |
|
| 752 | + $saved_datetimes = array(), |
|
| 753 | + $added_datetimes = array(), |
|
| 754 | + $removed_datetimes = array() |
|
| 755 | + ) { |
|
| 756 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 757 | + // and removing the ticket from datetimes it got removed from. |
|
| 758 | + // first let's add datetimes |
|
| 759 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 760 | + foreach ($added_datetimes as $row_id) { |
|
| 761 | + $row_id = (int) $row_id; |
|
| 762 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 763 | + $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 764 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 765 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 766 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 767 | + $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + // then remove datetimes |
|
| 773 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 774 | + foreach ($removed_datetimes as $row_id) { |
|
| 775 | + $row_id = (int) $row_id; |
|
| 776 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 777 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 778 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 779 | + $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 780 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 781 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
| 782 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 783 | + $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + // cap ticket qty by datetime reg limits |
|
| 789 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 790 | + return $ticket; |
|
| 791 | + } |
|
| 792 | 792 | |
| 793 | 793 | |
| 794 | - /** |
|
| 795 | - * @access protected |
|
| 796 | - * @param EE_Ticket $ticket |
|
| 797 | - * @param array $price_rows |
|
| 798 | - * @param int $ticket_price |
|
| 799 | - * @param int $base_price |
|
| 800 | - * @param int $base_price_id |
|
| 801 | - * @return EE_Ticket |
|
| 802 | - * @throws ReflectionException |
|
| 803 | - * @throws InvalidArgumentException |
|
| 804 | - * @throws InvalidInterfaceException |
|
| 805 | - * @throws InvalidDataTypeException |
|
| 806 | - * @throws EE_Error |
|
| 807 | - */ |
|
| 808 | - protected function _duplicate_ticket( |
|
| 809 | - EE_Ticket $ticket, |
|
| 810 | - $price_rows = array(), |
|
| 811 | - $ticket_price = 0, |
|
| 812 | - $base_price = 0, |
|
| 813 | - $base_price_id = 0 |
|
| 814 | - ) { |
|
| 815 | - // create new ticket that's a copy of the existing |
|
| 816 | - // except a new id of course (and not archived) |
|
| 817 | - // AND has the new TKT_price associated with it. |
|
| 818 | - $new_ticket = clone $ticket; |
|
| 819 | - $new_ticket->set('TKT_ID', 0); |
|
| 820 | - $new_ticket->set_deleted(0); |
|
| 821 | - $new_ticket->set_price($ticket_price); |
|
| 822 | - $new_ticket->set_sold(0); |
|
| 823 | - // let's get a new ID for this ticket |
|
| 824 | - $new_ticket->save(); |
|
| 825 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 826 | - $datetimes_on_existing = $ticket->datetimes(); |
|
| 827 | - $new_ticket = $this->_update_ticket_datetimes( |
|
| 828 | - $new_ticket, |
|
| 829 | - $datetimes_on_existing, |
|
| 830 | - array_keys($datetimes_on_existing) |
|
| 831 | - ); |
|
| 832 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 833 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 834 | - // available. |
|
| 835 | - if ($ticket->sold() > 0) { |
|
| 836 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 837 | - $new_ticket->set_qty($new_qty); |
|
| 838 | - } |
|
| 839 | - // now we update the prices just for this ticket |
|
| 840 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 841 | - // and we update the base price |
|
| 842 | - $new_ticket = $this->_add_prices_to_ticket( |
|
| 843 | - array(), |
|
| 844 | - $new_ticket, |
|
| 845 | - true, |
|
| 846 | - $base_price, |
|
| 847 | - $base_price_id |
|
| 848 | - ); |
|
| 849 | - return $new_ticket; |
|
| 850 | - } |
|
| 794 | + /** |
|
| 795 | + * @access protected |
|
| 796 | + * @param EE_Ticket $ticket |
|
| 797 | + * @param array $price_rows |
|
| 798 | + * @param int $ticket_price |
|
| 799 | + * @param int $base_price |
|
| 800 | + * @param int $base_price_id |
|
| 801 | + * @return EE_Ticket |
|
| 802 | + * @throws ReflectionException |
|
| 803 | + * @throws InvalidArgumentException |
|
| 804 | + * @throws InvalidInterfaceException |
|
| 805 | + * @throws InvalidDataTypeException |
|
| 806 | + * @throws EE_Error |
|
| 807 | + */ |
|
| 808 | + protected function _duplicate_ticket( |
|
| 809 | + EE_Ticket $ticket, |
|
| 810 | + $price_rows = array(), |
|
| 811 | + $ticket_price = 0, |
|
| 812 | + $base_price = 0, |
|
| 813 | + $base_price_id = 0 |
|
| 814 | + ) { |
|
| 815 | + // create new ticket that's a copy of the existing |
|
| 816 | + // except a new id of course (and not archived) |
|
| 817 | + // AND has the new TKT_price associated with it. |
|
| 818 | + $new_ticket = clone $ticket; |
|
| 819 | + $new_ticket->set('TKT_ID', 0); |
|
| 820 | + $new_ticket->set_deleted(0); |
|
| 821 | + $new_ticket->set_price($ticket_price); |
|
| 822 | + $new_ticket->set_sold(0); |
|
| 823 | + // let's get a new ID for this ticket |
|
| 824 | + $new_ticket->save(); |
|
| 825 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 826 | + $datetimes_on_existing = $ticket->datetimes(); |
|
| 827 | + $new_ticket = $this->_update_ticket_datetimes( |
|
| 828 | + $new_ticket, |
|
| 829 | + $datetimes_on_existing, |
|
| 830 | + array_keys($datetimes_on_existing) |
|
| 831 | + ); |
|
| 832 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 833 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 834 | + // available. |
|
| 835 | + if ($ticket->sold() > 0) { |
|
| 836 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 837 | + $new_ticket->set_qty($new_qty); |
|
| 838 | + } |
|
| 839 | + // now we update the prices just for this ticket |
|
| 840 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 841 | + // and we update the base price |
|
| 842 | + $new_ticket = $this->_add_prices_to_ticket( |
|
| 843 | + array(), |
|
| 844 | + $new_ticket, |
|
| 845 | + true, |
|
| 846 | + $base_price, |
|
| 847 | + $base_price_id |
|
| 848 | + ); |
|
| 849 | + return $new_ticket; |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | 852 | |
| 853 | - /** |
|
| 854 | - * This attaches a list of given prices to a ticket. |
|
| 855 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 856 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 857 | - * price info and prices are automatically "archived" via the ticket. |
|
| 858 | - * |
|
| 859 | - * @access private |
|
| 860 | - * @param array $prices Array of prices from the form. |
|
| 861 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 862 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 863 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 864 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 865 | - * @return EE_Ticket |
|
| 866 | - * @throws ReflectionException |
|
| 867 | - * @throws InvalidArgumentException |
|
| 868 | - * @throws InvalidInterfaceException |
|
| 869 | - * @throws InvalidDataTypeException |
|
| 870 | - * @throws EE_Error |
|
| 871 | - */ |
|
| 872 | - protected function _add_prices_to_ticket( |
|
| 873 | - $prices = array(), |
|
| 874 | - EE_Ticket $ticket, |
|
| 875 | - $new_prices = false, |
|
| 876 | - $base_price = false, |
|
| 877 | - $base_price_id = false |
|
| 878 | - ) { |
|
| 879 | - // let's just get any current prices that may exist on the given ticket |
|
| 880 | - // so we can remove any prices that got trashed in this session. |
|
| 881 | - $current_prices_on_ticket = $base_price !== false |
|
| 882 | - ? $ticket->base_price(true) |
|
| 883 | - : $ticket->price_modifiers(); |
|
| 884 | - $updated_prices = array(); |
|
| 885 | - // if $base_price ! FALSE then updating a base price. |
|
| 886 | - if ($base_price !== false) { |
|
| 887 | - $prices[1] = array( |
|
| 888 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 889 | - 'PRT_ID' => 1, |
|
| 890 | - 'PRC_amount' => $base_price, |
|
| 891 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
| 892 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 893 | - ); |
|
| 894 | - } |
|
| 895 | - // possibly need to save tkt |
|
| 896 | - if (! $ticket->ID()) { |
|
| 897 | - $ticket->save(); |
|
| 898 | - } |
|
| 899 | - foreach ($prices as $row => $prc) { |
|
| 900 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 901 | - if (empty($prt_id)) { |
|
| 902 | - continue; |
|
| 903 | - } //prices MUST have a price type id. |
|
| 904 | - $PRC_values = array( |
|
| 905 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 906 | - 'PRT_ID' => $prt_id, |
|
| 907 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 908 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 909 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 910 | - 'PRC_is_default' => false, |
|
| 911 | - // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 912 | - 'PRC_order' => $row, |
|
| 913 | - ); |
|
| 914 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 915 | - $PRC_values['PRC_ID'] = 0; |
|
| 916 | - $price = EE_Registry::instance()->load_class( |
|
| 917 | - 'Price', |
|
| 918 | - array($PRC_values), |
|
| 919 | - false, |
|
| 920 | - false |
|
| 921 | - ); |
|
| 922 | - } else { |
|
| 923 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 924 | - // update this price with new values |
|
| 925 | - foreach ($PRC_values as $field => $value) { |
|
| 926 | - $price->set($field, $value); |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - $price->save(); |
|
| 930 | - $updated_prices[ $price->ID() ] = $price; |
|
| 931 | - $ticket->_add_relation_to($price, 'Price'); |
|
| 932 | - } |
|
| 933 | - // now let's remove any prices that got removed from the ticket |
|
| 934 | - if (! empty($current_prices_on_ticket)) { |
|
| 935 | - $current = array_keys($current_prices_on_ticket); |
|
| 936 | - $updated = array_keys($updated_prices); |
|
| 937 | - $prices_to_remove = array_diff($current, $updated); |
|
| 938 | - if (! empty($prices_to_remove)) { |
|
| 939 | - foreach ($prices_to_remove as $prc_id) { |
|
| 940 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 941 | - $ticket->_remove_relation_to($p, 'Price'); |
|
| 942 | - // delete permanently the price |
|
| 943 | - $p->delete_permanently(); |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - return $ticket; |
|
| 948 | - } |
|
| 853 | + /** |
|
| 854 | + * This attaches a list of given prices to a ticket. |
|
| 855 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 856 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 857 | + * price info and prices are automatically "archived" via the ticket. |
|
| 858 | + * |
|
| 859 | + * @access private |
|
| 860 | + * @param array $prices Array of prices from the form. |
|
| 861 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 862 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 863 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 864 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 865 | + * @return EE_Ticket |
|
| 866 | + * @throws ReflectionException |
|
| 867 | + * @throws InvalidArgumentException |
|
| 868 | + * @throws InvalidInterfaceException |
|
| 869 | + * @throws InvalidDataTypeException |
|
| 870 | + * @throws EE_Error |
|
| 871 | + */ |
|
| 872 | + protected function _add_prices_to_ticket( |
|
| 873 | + $prices = array(), |
|
| 874 | + EE_Ticket $ticket, |
|
| 875 | + $new_prices = false, |
|
| 876 | + $base_price = false, |
|
| 877 | + $base_price_id = false |
|
| 878 | + ) { |
|
| 879 | + // let's just get any current prices that may exist on the given ticket |
|
| 880 | + // so we can remove any prices that got trashed in this session. |
|
| 881 | + $current_prices_on_ticket = $base_price !== false |
|
| 882 | + ? $ticket->base_price(true) |
|
| 883 | + : $ticket->price_modifiers(); |
|
| 884 | + $updated_prices = array(); |
|
| 885 | + // if $base_price ! FALSE then updating a base price. |
|
| 886 | + if ($base_price !== false) { |
|
| 887 | + $prices[1] = array( |
|
| 888 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 889 | + 'PRT_ID' => 1, |
|
| 890 | + 'PRC_amount' => $base_price, |
|
| 891 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
| 892 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 893 | + ); |
|
| 894 | + } |
|
| 895 | + // possibly need to save tkt |
|
| 896 | + if (! $ticket->ID()) { |
|
| 897 | + $ticket->save(); |
|
| 898 | + } |
|
| 899 | + foreach ($prices as $row => $prc) { |
|
| 900 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 901 | + if (empty($prt_id)) { |
|
| 902 | + continue; |
|
| 903 | + } //prices MUST have a price type id. |
|
| 904 | + $PRC_values = array( |
|
| 905 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 906 | + 'PRT_ID' => $prt_id, |
|
| 907 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 908 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 909 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 910 | + 'PRC_is_default' => false, |
|
| 911 | + // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 912 | + 'PRC_order' => $row, |
|
| 913 | + ); |
|
| 914 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 915 | + $PRC_values['PRC_ID'] = 0; |
|
| 916 | + $price = EE_Registry::instance()->load_class( |
|
| 917 | + 'Price', |
|
| 918 | + array($PRC_values), |
|
| 919 | + false, |
|
| 920 | + false |
|
| 921 | + ); |
|
| 922 | + } else { |
|
| 923 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 924 | + // update this price with new values |
|
| 925 | + foreach ($PRC_values as $field => $value) { |
|
| 926 | + $price->set($field, $value); |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + $price->save(); |
|
| 930 | + $updated_prices[ $price->ID() ] = $price; |
|
| 931 | + $ticket->_add_relation_to($price, 'Price'); |
|
| 932 | + } |
|
| 933 | + // now let's remove any prices that got removed from the ticket |
|
| 934 | + if (! empty($current_prices_on_ticket)) { |
|
| 935 | + $current = array_keys($current_prices_on_ticket); |
|
| 936 | + $updated = array_keys($updated_prices); |
|
| 937 | + $prices_to_remove = array_diff($current, $updated); |
|
| 938 | + if (! empty($prices_to_remove)) { |
|
| 939 | + foreach ($prices_to_remove as $prc_id) { |
|
| 940 | + $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 941 | + $ticket->_remove_relation_to($p, 'Price'); |
|
| 942 | + // delete permanently the price |
|
| 943 | + $p->delete_permanently(); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + return $ticket; |
|
| 948 | + } |
|
| 949 | 949 | |
| 950 | 950 | |
| 951 | - /** |
|
| 952 | - * @param Events_Admin_Page $event_admin_obj |
|
| 953 | - * @return Events_Admin_Page |
|
| 954 | - */ |
|
| 955 | - public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
| 956 | - { |
|
| 957 | - return $event_admin_obj; |
|
| 958 | - // doing nothing for the moment. |
|
| 959 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 960 | - // (use the set_template_args() method) |
|
| 961 | - /** |
|
| 962 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 963 | - * 1. TKT_is_default_selector (visible) |
|
| 964 | - * 2. TKT_is_default (hidden) |
|
| 965 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 966 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 967 | - * this ticket to be saved as a default. |
|
| 968 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 969 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 970 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 971 | - * the TKT HAS been saved as a default.. |
|
| 972 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 973 | - * On Autosave: |
|
| 974 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 975 | - * then set the TKT_is_default to false. |
|
| 976 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 977 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 978 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 979 | - */ |
|
| 980 | - } |
|
| 951 | + /** |
|
| 952 | + * @param Events_Admin_Page $event_admin_obj |
|
| 953 | + * @return Events_Admin_Page |
|
| 954 | + */ |
|
| 955 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
| 956 | + { |
|
| 957 | + return $event_admin_obj; |
|
| 958 | + // doing nothing for the moment. |
|
| 959 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 960 | + // (use the set_template_args() method) |
|
| 961 | + /** |
|
| 962 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 963 | + * 1. TKT_is_default_selector (visible) |
|
| 964 | + * 2. TKT_is_default (hidden) |
|
| 965 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 966 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 967 | + * this ticket to be saved as a default. |
|
| 968 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 969 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 970 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 971 | + * the TKT HAS been saved as a default.. |
|
| 972 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 973 | + * On Autosave: |
|
| 974 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 975 | + * then set the TKT_is_default to false. |
|
| 976 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 977 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 978 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 979 | + */ |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | 982 | |
| 983 | - /** |
|
| 984 | - * @throws ReflectionException |
|
| 985 | - * @throws InvalidArgumentException |
|
| 986 | - * @throws InvalidInterfaceException |
|
| 987 | - * @throws InvalidDataTypeException |
|
| 988 | - * @throws DomainException |
|
| 989 | - * @throws EE_Error |
|
| 990 | - */ |
|
| 991 | - public function pricing_metabox() |
|
| 992 | - { |
|
| 993 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 994 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 995 | - // set is_creating_event property. |
|
| 996 | - $EVT_ID = $event->ID(); |
|
| 997 | - $this->_is_creating_event = empty($this->_req_data['post']); |
|
| 998 | - // default main template args |
|
| 999 | - $main_template_args = array( |
|
| 1000 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 1001 | - 'event_editor_event_datetimes_help_tab', |
|
| 1002 | - $this->_adminpage_obj->page_slug, |
|
| 1003 | - $this->_adminpage_obj->get_req_action(), |
|
| 1004 | - false, |
|
| 1005 | - false |
|
| 1006 | - ), |
|
| 1007 | - // todo need to add a filter to the template for the help text |
|
| 1008 | - // in the Events_Admin_Page core file so we can add further help |
|
| 1009 | - 'existing_datetime_ids' => '', |
|
| 1010 | - 'total_dtt_rows' => 1, |
|
| 1011 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 1012 | - 'add_new_dtt_info', |
|
| 1013 | - $this->_adminpage_obj->page_slug, |
|
| 1014 | - $this->_adminpage_obj->get_req_action(), |
|
| 1015 | - false, |
|
| 1016 | - false |
|
| 1017 | - ), |
|
| 1018 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1019 | - 'datetime_rows' => '', |
|
| 1020 | - 'show_tickets_container' => '', |
|
| 1021 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 1022 | - 'ticket_rows' => '', |
|
| 1023 | - 'existing_ticket_ids' => '', |
|
| 1024 | - 'total_ticket_rows' => 1, |
|
| 1025 | - 'ticket_js_structure' => '', |
|
| 1026 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 1027 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 1028 | - ); |
|
| 1029 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 1030 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1031 | - /** |
|
| 1032 | - * 1. Start with retrieving Datetimes |
|
| 1033 | - * 2. For each datetime get related tickets |
|
| 1034 | - * 3. For each ticket get related prices |
|
| 1035 | - */ |
|
| 1036 | - /** @var EEM_Datetime $datetime_model */ |
|
| 1037 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 1038 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 1039 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 1040 | - /** |
|
| 1041 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 1042 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1043 | - */ |
|
| 1044 | - $datetime_row = 1; |
|
| 1045 | - foreach ($datetimes as $datetime) { |
|
| 1046 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1047 | - $datetime->set('DTT_order', $datetime_row); |
|
| 1048 | - $existing_datetime_ids[] = $DTT_ID; |
|
| 1049 | - // tickets attached |
|
| 1050 | - $related_tickets = $datetime->ID() > 0 |
|
| 1051 | - ? $datetime->get_many_related( |
|
| 1052 | - 'Ticket', |
|
| 1053 | - array( |
|
| 1054 | - array( |
|
| 1055 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1056 | - ), |
|
| 1057 | - 'default_where_conditions' => 'none', |
|
| 1058 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1059 | - ) |
|
| 1060 | - ) |
|
| 1061 | - : array(); |
|
| 1062 | - // if there are no related tickets this is likely a new event OR autodraft |
|
| 1063 | - // event so we need to generate the default tickets because datetimes |
|
| 1064 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1065 | - // datetime on the event. |
|
| 1066 | - if (empty($related_tickets) && count($datetimes) < 2) { |
|
| 1067 | - /** @var EEM_Ticket $ticket_model */ |
|
| 1068 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1069 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1070 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1071 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1072 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1073 | - $main_default_ticket = reset($related_tickets); |
|
| 1074 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1075 | - foreach ($default_prices as $default_price) { |
|
| 1076 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1077 | - continue; |
|
| 1078 | - } |
|
| 1079 | - $main_default_ticket->cache('Price', $default_price); |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1084 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1085 | - // So we're going to temporarily cache some of that information. |
|
| 1086 | - // loop through and setup the ticket rows and make sure the order is set. |
|
| 1087 | - foreach ($related_tickets as $ticket) { |
|
| 1088 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1089 | - $ticket_row = $ticket->get('TKT_row'); |
|
| 1090 | - // we only want unique tickets in our final display!! |
|
| 1091 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1092 | - $existing_ticket_ids[] = $TKT_ID; |
|
| 1093 | - $all_tickets[] = $ticket; |
|
| 1094 | - } |
|
| 1095 | - // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1096 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1097 | - // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1098 | - if ( |
|
| 1099 | - ! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1100 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1101 | - ) { |
|
| 1102 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1103 | - } |
|
| 1104 | - } |
|
| 1105 | - $datetime_row++; |
|
| 1106 | - } |
|
| 1107 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1108 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1109 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1110 | - // sort $all_tickets by order |
|
| 1111 | - usort( |
|
| 1112 | - $all_tickets, |
|
| 1113 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1114 | - $a_order = (int) $a->get('TKT_order'); |
|
| 1115 | - $b_order = (int) $b->get('TKT_order'); |
|
| 1116 | - if ($a_order === $b_order) { |
|
| 1117 | - return 0; |
|
| 1118 | - } |
|
| 1119 | - return ($a_order < $b_order) ? -1 : 1; |
|
| 1120 | - } |
|
| 1121 | - ); |
|
| 1122 | - // k NOW we have all the data we need for setting up the dtt rows |
|
| 1123 | - // and ticket rows so we start our dtt loop again. |
|
| 1124 | - $datetime_row = 1; |
|
| 1125 | - foreach ($datetimes as $datetime) { |
|
| 1126 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1127 | - $datetime_row, |
|
| 1128 | - $datetime, |
|
| 1129 | - $datetime_tickets, |
|
| 1130 | - $all_tickets, |
|
| 1131 | - false, |
|
| 1132 | - $datetimes |
|
| 1133 | - ); |
|
| 1134 | - $datetime_row++; |
|
| 1135 | - } |
|
| 1136 | - // then loop through all tickets for the ticket rows. |
|
| 1137 | - $ticket_row = 1; |
|
| 1138 | - foreach ($all_tickets as $ticket) { |
|
| 1139 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1140 | - $ticket_row, |
|
| 1141 | - $ticket, |
|
| 1142 | - $ticket_datetimes, |
|
| 1143 | - $datetimes, |
|
| 1144 | - false, |
|
| 1145 | - $all_tickets |
|
| 1146 | - ); |
|
| 1147 | - $ticket_row++; |
|
| 1148 | - } |
|
| 1149 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1150 | - EEH_Template::display_template( |
|
| 1151 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1152 | - $main_template_args |
|
| 1153 | - ); |
|
| 1154 | - } |
|
| 983 | + /** |
|
| 984 | + * @throws ReflectionException |
|
| 985 | + * @throws InvalidArgumentException |
|
| 986 | + * @throws InvalidInterfaceException |
|
| 987 | + * @throws InvalidDataTypeException |
|
| 988 | + * @throws DomainException |
|
| 989 | + * @throws EE_Error |
|
| 990 | + */ |
|
| 991 | + public function pricing_metabox() |
|
| 992 | + { |
|
| 993 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 994 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 995 | + // set is_creating_event property. |
|
| 996 | + $EVT_ID = $event->ID(); |
|
| 997 | + $this->_is_creating_event = empty($this->_req_data['post']); |
|
| 998 | + // default main template args |
|
| 999 | + $main_template_args = array( |
|
| 1000 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 1001 | + 'event_editor_event_datetimes_help_tab', |
|
| 1002 | + $this->_adminpage_obj->page_slug, |
|
| 1003 | + $this->_adminpage_obj->get_req_action(), |
|
| 1004 | + false, |
|
| 1005 | + false |
|
| 1006 | + ), |
|
| 1007 | + // todo need to add a filter to the template for the help text |
|
| 1008 | + // in the Events_Admin_Page core file so we can add further help |
|
| 1009 | + 'existing_datetime_ids' => '', |
|
| 1010 | + 'total_dtt_rows' => 1, |
|
| 1011 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 1012 | + 'add_new_dtt_info', |
|
| 1013 | + $this->_adminpage_obj->page_slug, |
|
| 1014 | + $this->_adminpage_obj->get_req_action(), |
|
| 1015 | + false, |
|
| 1016 | + false |
|
| 1017 | + ), |
|
| 1018 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1019 | + 'datetime_rows' => '', |
|
| 1020 | + 'show_tickets_container' => '', |
|
| 1021 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 1022 | + 'ticket_rows' => '', |
|
| 1023 | + 'existing_ticket_ids' => '', |
|
| 1024 | + 'total_ticket_rows' => 1, |
|
| 1025 | + 'ticket_js_structure' => '', |
|
| 1026 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 1027 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 1028 | + ); |
|
| 1029 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 1030 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1031 | + /** |
|
| 1032 | + * 1. Start with retrieving Datetimes |
|
| 1033 | + * 2. For each datetime get related tickets |
|
| 1034 | + * 3. For each ticket get related prices |
|
| 1035 | + */ |
|
| 1036 | + /** @var EEM_Datetime $datetime_model */ |
|
| 1037 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 1038 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 1039 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 1040 | + /** |
|
| 1041 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 1042 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1043 | + */ |
|
| 1044 | + $datetime_row = 1; |
|
| 1045 | + foreach ($datetimes as $datetime) { |
|
| 1046 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1047 | + $datetime->set('DTT_order', $datetime_row); |
|
| 1048 | + $existing_datetime_ids[] = $DTT_ID; |
|
| 1049 | + // tickets attached |
|
| 1050 | + $related_tickets = $datetime->ID() > 0 |
|
| 1051 | + ? $datetime->get_many_related( |
|
| 1052 | + 'Ticket', |
|
| 1053 | + array( |
|
| 1054 | + array( |
|
| 1055 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1056 | + ), |
|
| 1057 | + 'default_where_conditions' => 'none', |
|
| 1058 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1059 | + ) |
|
| 1060 | + ) |
|
| 1061 | + : array(); |
|
| 1062 | + // if there are no related tickets this is likely a new event OR autodraft |
|
| 1063 | + // event so we need to generate the default tickets because datetimes |
|
| 1064 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1065 | + // datetime on the event. |
|
| 1066 | + if (empty($related_tickets) && count($datetimes) < 2) { |
|
| 1067 | + /** @var EEM_Ticket $ticket_model */ |
|
| 1068 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1069 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1070 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1071 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1072 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1073 | + $main_default_ticket = reset($related_tickets); |
|
| 1074 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1075 | + foreach ($default_prices as $default_price) { |
|
| 1076 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1077 | + continue; |
|
| 1078 | + } |
|
| 1079 | + $main_default_ticket->cache('Price', $default_price); |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1084 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1085 | + // So we're going to temporarily cache some of that information. |
|
| 1086 | + // loop through and setup the ticket rows and make sure the order is set. |
|
| 1087 | + foreach ($related_tickets as $ticket) { |
|
| 1088 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1089 | + $ticket_row = $ticket->get('TKT_row'); |
|
| 1090 | + // we only want unique tickets in our final display!! |
|
| 1091 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1092 | + $existing_ticket_ids[] = $TKT_ID; |
|
| 1093 | + $all_tickets[] = $ticket; |
|
| 1094 | + } |
|
| 1095 | + // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1096 | + $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1097 | + // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1098 | + if ( |
|
| 1099 | + ! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1100 | + || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1101 | + ) { |
|
| 1102 | + $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1103 | + } |
|
| 1104 | + } |
|
| 1105 | + $datetime_row++; |
|
| 1106 | + } |
|
| 1107 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1108 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1109 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1110 | + // sort $all_tickets by order |
|
| 1111 | + usort( |
|
| 1112 | + $all_tickets, |
|
| 1113 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1114 | + $a_order = (int) $a->get('TKT_order'); |
|
| 1115 | + $b_order = (int) $b->get('TKT_order'); |
|
| 1116 | + if ($a_order === $b_order) { |
|
| 1117 | + return 0; |
|
| 1118 | + } |
|
| 1119 | + return ($a_order < $b_order) ? -1 : 1; |
|
| 1120 | + } |
|
| 1121 | + ); |
|
| 1122 | + // k NOW we have all the data we need for setting up the dtt rows |
|
| 1123 | + // and ticket rows so we start our dtt loop again. |
|
| 1124 | + $datetime_row = 1; |
|
| 1125 | + foreach ($datetimes as $datetime) { |
|
| 1126 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1127 | + $datetime_row, |
|
| 1128 | + $datetime, |
|
| 1129 | + $datetime_tickets, |
|
| 1130 | + $all_tickets, |
|
| 1131 | + false, |
|
| 1132 | + $datetimes |
|
| 1133 | + ); |
|
| 1134 | + $datetime_row++; |
|
| 1135 | + } |
|
| 1136 | + // then loop through all tickets for the ticket rows. |
|
| 1137 | + $ticket_row = 1; |
|
| 1138 | + foreach ($all_tickets as $ticket) { |
|
| 1139 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1140 | + $ticket_row, |
|
| 1141 | + $ticket, |
|
| 1142 | + $ticket_datetimes, |
|
| 1143 | + $datetimes, |
|
| 1144 | + false, |
|
| 1145 | + $all_tickets |
|
| 1146 | + ); |
|
| 1147 | + $ticket_row++; |
|
| 1148 | + } |
|
| 1149 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1150 | + EEH_Template::display_template( |
|
| 1151 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1152 | + $main_template_args |
|
| 1153 | + ); |
|
| 1154 | + } |
|
| 1155 | 1155 | |
| 1156 | 1156 | |
| 1157 | - /** |
|
| 1158 | - * @param int $datetime_row |
|
| 1159 | - * @param EE_Datetime $datetime |
|
| 1160 | - * @param array $datetime_tickets |
|
| 1161 | - * @param array $all_tickets |
|
| 1162 | - * @param bool $default |
|
| 1163 | - * @param array $all_datetimes |
|
| 1164 | - * @return mixed |
|
| 1165 | - * @throws DomainException |
|
| 1166 | - * @throws EE_Error |
|
| 1167 | - */ |
|
| 1168 | - protected function _get_datetime_row( |
|
| 1169 | - $datetime_row, |
|
| 1170 | - EE_Datetime $datetime, |
|
| 1171 | - $datetime_tickets = array(), |
|
| 1172 | - $all_tickets = array(), |
|
| 1173 | - $default = false, |
|
| 1174 | - $all_datetimes = array() |
|
| 1175 | - ) { |
|
| 1176 | - $dtt_display_template_args = array( |
|
| 1177 | - 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
| 1178 | - $datetime_row, |
|
| 1179 | - $datetime, |
|
| 1180 | - $default, |
|
| 1181 | - $all_datetimes |
|
| 1182 | - ), |
|
| 1183 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1184 | - $datetime_row, |
|
| 1185 | - $datetime, |
|
| 1186 | - $datetime_tickets, |
|
| 1187 | - $all_tickets, |
|
| 1188 | - $default |
|
| 1189 | - ), |
|
| 1190 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1191 | - ); |
|
| 1192 | - return EEH_Template::display_template( |
|
| 1193 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1194 | - $dtt_display_template_args, |
|
| 1195 | - true |
|
| 1196 | - ); |
|
| 1197 | - } |
|
| 1157 | + /** |
|
| 1158 | + * @param int $datetime_row |
|
| 1159 | + * @param EE_Datetime $datetime |
|
| 1160 | + * @param array $datetime_tickets |
|
| 1161 | + * @param array $all_tickets |
|
| 1162 | + * @param bool $default |
|
| 1163 | + * @param array $all_datetimes |
|
| 1164 | + * @return mixed |
|
| 1165 | + * @throws DomainException |
|
| 1166 | + * @throws EE_Error |
|
| 1167 | + */ |
|
| 1168 | + protected function _get_datetime_row( |
|
| 1169 | + $datetime_row, |
|
| 1170 | + EE_Datetime $datetime, |
|
| 1171 | + $datetime_tickets = array(), |
|
| 1172 | + $all_tickets = array(), |
|
| 1173 | + $default = false, |
|
| 1174 | + $all_datetimes = array() |
|
| 1175 | + ) { |
|
| 1176 | + $dtt_display_template_args = array( |
|
| 1177 | + 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
| 1178 | + $datetime_row, |
|
| 1179 | + $datetime, |
|
| 1180 | + $default, |
|
| 1181 | + $all_datetimes |
|
| 1182 | + ), |
|
| 1183 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1184 | + $datetime_row, |
|
| 1185 | + $datetime, |
|
| 1186 | + $datetime_tickets, |
|
| 1187 | + $all_tickets, |
|
| 1188 | + $default |
|
| 1189 | + ), |
|
| 1190 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1191 | + ); |
|
| 1192 | + return EEH_Template::display_template( |
|
| 1193 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1194 | + $dtt_display_template_args, |
|
| 1195 | + true |
|
| 1196 | + ); |
|
| 1197 | + } |
|
| 1198 | 1198 | |
| 1199 | 1199 | |
| 1200 | - /** |
|
| 1201 | - * This method is used to generate a dtt fields edit row. |
|
| 1202 | - * The same row is used to generate a row with valid DTT objects |
|
| 1203 | - * and the default row that is used as the skeleton by the js. |
|
| 1204 | - * |
|
| 1205 | - * @param int $datetime_row The row number for the row being generated. |
|
| 1206 | - * @param EE_Datetime $datetime |
|
| 1207 | - * @param bool $default Whether a default row is being generated or not. |
|
| 1208 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1209 | - * @return string |
|
| 1210 | - * @throws DomainException |
|
| 1211 | - * @throws EE_Error |
|
| 1212 | - */ |
|
| 1213 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1214 | - { |
|
| 1215 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1216 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1217 | - $template_args = array( |
|
| 1218 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1219 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1220 | - 'edit_dtt_expanded' => '', |
|
| 1221 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1222 | - 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
| 1223 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1224 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1225 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1226 | - 'DTT_reg_limit' => $default |
|
| 1227 | - ? '' |
|
| 1228 | - : $datetime->get_pretty( |
|
| 1229 | - 'DTT_reg_limit', |
|
| 1230 | - 'input' |
|
| 1231 | - ), |
|
| 1232 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1233 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1234 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1235 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1236 | - ? '' |
|
| 1237 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1238 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1239 | - ? 'ee-lock-icon' |
|
| 1240 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1241 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1242 | - ? '' |
|
| 1243 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1244 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1245 | - REG_ADMIN_URL |
|
| 1246 | - ), |
|
| 1247 | - ); |
|
| 1248 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1249 | - ? 'display:none' |
|
| 1250 | - : ''; |
|
| 1251 | - // allow filtering of template args at this point. |
|
| 1252 | - $template_args = apply_filters( |
|
| 1253 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1254 | - $template_args, |
|
| 1255 | - $datetime_row, |
|
| 1256 | - $datetime, |
|
| 1257 | - $default, |
|
| 1258 | - $all_datetimes, |
|
| 1259 | - $this->_is_creating_event |
|
| 1260 | - ); |
|
| 1261 | - return EEH_Template::display_template( |
|
| 1262 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1263 | - $template_args, |
|
| 1264 | - true |
|
| 1265 | - ); |
|
| 1266 | - } |
|
| 1200 | + /** |
|
| 1201 | + * This method is used to generate a dtt fields edit row. |
|
| 1202 | + * The same row is used to generate a row with valid DTT objects |
|
| 1203 | + * and the default row that is used as the skeleton by the js. |
|
| 1204 | + * |
|
| 1205 | + * @param int $datetime_row The row number for the row being generated. |
|
| 1206 | + * @param EE_Datetime $datetime |
|
| 1207 | + * @param bool $default Whether a default row is being generated or not. |
|
| 1208 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1209 | + * @return string |
|
| 1210 | + * @throws DomainException |
|
| 1211 | + * @throws EE_Error |
|
| 1212 | + */ |
|
| 1213 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1214 | + { |
|
| 1215 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1216 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1217 | + $template_args = array( |
|
| 1218 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1219 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1220 | + 'edit_dtt_expanded' => '', |
|
| 1221 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1222 | + 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
| 1223 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1224 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1225 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1226 | + 'DTT_reg_limit' => $default |
|
| 1227 | + ? '' |
|
| 1228 | + : $datetime->get_pretty( |
|
| 1229 | + 'DTT_reg_limit', |
|
| 1230 | + 'input' |
|
| 1231 | + ), |
|
| 1232 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1233 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1234 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1235 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1236 | + ? '' |
|
| 1237 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1238 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1239 | + ? 'ee-lock-icon' |
|
| 1240 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1241 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1242 | + ? '' |
|
| 1243 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1244 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1245 | + REG_ADMIN_URL |
|
| 1246 | + ), |
|
| 1247 | + ); |
|
| 1248 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1249 | + ? 'display:none' |
|
| 1250 | + : ''; |
|
| 1251 | + // allow filtering of template args at this point. |
|
| 1252 | + $template_args = apply_filters( |
|
| 1253 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1254 | + $template_args, |
|
| 1255 | + $datetime_row, |
|
| 1256 | + $datetime, |
|
| 1257 | + $default, |
|
| 1258 | + $all_datetimes, |
|
| 1259 | + $this->_is_creating_event |
|
| 1260 | + ); |
|
| 1261 | + return EEH_Template::display_template( |
|
| 1262 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1263 | + $template_args, |
|
| 1264 | + true |
|
| 1265 | + ); |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | 1268 | |
| 1269 | - /** |
|
| 1270 | - * @param int $datetime_row |
|
| 1271 | - * @param EE_Datetime $datetime |
|
| 1272 | - * @param array $datetime_tickets |
|
| 1273 | - * @param array $all_tickets |
|
| 1274 | - * @param bool $default |
|
| 1275 | - * @return mixed |
|
| 1276 | - * @throws DomainException |
|
| 1277 | - * @throws EE_Error |
|
| 1278 | - */ |
|
| 1279 | - protected function _get_dtt_attached_tickets_row( |
|
| 1280 | - $datetime_row, |
|
| 1281 | - $datetime, |
|
| 1282 | - $datetime_tickets = array(), |
|
| 1283 | - $all_tickets = array(), |
|
| 1284 | - $default |
|
| 1285 | - ) { |
|
| 1286 | - $template_args = array( |
|
| 1287 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1288 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1289 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1290 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1291 | - 'show_tickets_row' => 'display:none;', |
|
| 1292 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1293 | - 'add_new_ticket_via_datetime', |
|
| 1294 | - $this->_adminpage_obj->page_slug, |
|
| 1295 | - $this->_adminpage_obj->get_req_action(), |
|
| 1296 | - false, |
|
| 1297 | - false |
|
| 1298 | - ), |
|
| 1299 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1300 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1301 | - ); |
|
| 1302 | - // need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1303 | - if (! $default) { |
|
| 1304 | - $ticket_row = 1; |
|
| 1305 | - foreach ($all_tickets as $ticket) { |
|
| 1306 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1307 | - $datetime_row, |
|
| 1308 | - $ticket_row, |
|
| 1309 | - $datetime, |
|
| 1310 | - $ticket, |
|
| 1311 | - $datetime_tickets, |
|
| 1312 | - $default |
|
| 1313 | - ); |
|
| 1314 | - $ticket_row++; |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - // filter template args at this point |
|
| 1318 | - $template_args = apply_filters( |
|
| 1319 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1320 | - $template_args, |
|
| 1321 | - $datetime_row, |
|
| 1322 | - $datetime, |
|
| 1323 | - $datetime_tickets, |
|
| 1324 | - $all_tickets, |
|
| 1325 | - $default, |
|
| 1326 | - $this->_is_creating_event |
|
| 1327 | - ); |
|
| 1328 | - return EEH_Template::display_template( |
|
| 1329 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1330 | - $template_args, |
|
| 1331 | - true |
|
| 1332 | - ); |
|
| 1333 | - } |
|
| 1269 | + /** |
|
| 1270 | + * @param int $datetime_row |
|
| 1271 | + * @param EE_Datetime $datetime |
|
| 1272 | + * @param array $datetime_tickets |
|
| 1273 | + * @param array $all_tickets |
|
| 1274 | + * @param bool $default |
|
| 1275 | + * @return mixed |
|
| 1276 | + * @throws DomainException |
|
| 1277 | + * @throws EE_Error |
|
| 1278 | + */ |
|
| 1279 | + protected function _get_dtt_attached_tickets_row( |
|
| 1280 | + $datetime_row, |
|
| 1281 | + $datetime, |
|
| 1282 | + $datetime_tickets = array(), |
|
| 1283 | + $all_tickets = array(), |
|
| 1284 | + $default |
|
| 1285 | + ) { |
|
| 1286 | + $template_args = array( |
|
| 1287 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1288 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1289 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1290 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1291 | + 'show_tickets_row' => 'display:none;', |
|
| 1292 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1293 | + 'add_new_ticket_via_datetime', |
|
| 1294 | + $this->_adminpage_obj->page_slug, |
|
| 1295 | + $this->_adminpage_obj->get_req_action(), |
|
| 1296 | + false, |
|
| 1297 | + false |
|
| 1298 | + ), |
|
| 1299 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1300 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1301 | + ); |
|
| 1302 | + // need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1303 | + if (! $default) { |
|
| 1304 | + $ticket_row = 1; |
|
| 1305 | + foreach ($all_tickets as $ticket) { |
|
| 1306 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1307 | + $datetime_row, |
|
| 1308 | + $ticket_row, |
|
| 1309 | + $datetime, |
|
| 1310 | + $ticket, |
|
| 1311 | + $datetime_tickets, |
|
| 1312 | + $default |
|
| 1313 | + ); |
|
| 1314 | + $ticket_row++; |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | + // filter template args at this point |
|
| 1318 | + $template_args = apply_filters( |
|
| 1319 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1320 | + $template_args, |
|
| 1321 | + $datetime_row, |
|
| 1322 | + $datetime, |
|
| 1323 | + $datetime_tickets, |
|
| 1324 | + $all_tickets, |
|
| 1325 | + $default, |
|
| 1326 | + $this->_is_creating_event |
|
| 1327 | + ); |
|
| 1328 | + return EEH_Template::display_template( |
|
| 1329 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1330 | + $template_args, |
|
| 1331 | + true |
|
| 1332 | + ); |
|
| 1333 | + } |
|
| 1334 | 1334 | |
| 1335 | 1335 | |
| 1336 | - /** |
|
| 1337 | - * @param int $datetime_row |
|
| 1338 | - * @param int $ticket_row |
|
| 1339 | - * @param EE_Datetime $datetime |
|
| 1340 | - * @param EE_Ticket $ticket |
|
| 1341 | - * @param array $datetime_tickets |
|
| 1342 | - * @param bool $default |
|
| 1343 | - * @return mixed |
|
| 1344 | - * @throws DomainException |
|
| 1345 | - * @throws EE_Error |
|
| 1346 | - */ |
|
| 1347 | - protected function _get_datetime_tickets_list_item( |
|
| 1348 | - $datetime_row, |
|
| 1349 | - $ticket_row, |
|
| 1350 | - $datetime, |
|
| 1351 | - $ticket, |
|
| 1352 | - $datetime_tickets = array(), |
|
| 1353 | - $default |
|
| 1354 | - ) { |
|
| 1355 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1356 | - ? $datetime_tickets[ $datetime->ID() ] |
|
| 1357 | - : array(); |
|
| 1358 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1359 | - $no_ticket = $default && empty($ticket); |
|
| 1360 | - $template_args = array( |
|
| 1361 | - 'dtt_row' => $default |
|
| 1362 | - ? 'DTTNUM' |
|
| 1363 | - : $datetime_row, |
|
| 1364 | - 'tkt_row' => $no_ticket |
|
| 1365 | - ? 'TICKETNUM' |
|
| 1366 | - : $ticket_row, |
|
| 1367 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1368 | - ? ' checked' |
|
| 1369 | - : '', |
|
| 1370 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1371 | - ? ' ticket-selected' |
|
| 1372 | - : '', |
|
| 1373 | - 'TKT_name' => $no_ticket |
|
| 1374 | - ? 'TKTNAME' |
|
| 1375 | - : $ticket->get('TKT_name'), |
|
| 1376 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1377 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1378 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1379 | - ); |
|
| 1380 | - // filter template args |
|
| 1381 | - $template_args = apply_filters( |
|
| 1382 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1383 | - $template_args, |
|
| 1384 | - $datetime_row, |
|
| 1385 | - $ticket_row, |
|
| 1386 | - $datetime, |
|
| 1387 | - $ticket, |
|
| 1388 | - $datetime_tickets, |
|
| 1389 | - $default, |
|
| 1390 | - $this->_is_creating_event |
|
| 1391 | - ); |
|
| 1392 | - return EEH_Template::display_template( |
|
| 1393 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1394 | - $template_args, |
|
| 1395 | - true |
|
| 1396 | - ); |
|
| 1397 | - } |
|
| 1336 | + /** |
|
| 1337 | + * @param int $datetime_row |
|
| 1338 | + * @param int $ticket_row |
|
| 1339 | + * @param EE_Datetime $datetime |
|
| 1340 | + * @param EE_Ticket $ticket |
|
| 1341 | + * @param array $datetime_tickets |
|
| 1342 | + * @param bool $default |
|
| 1343 | + * @return mixed |
|
| 1344 | + * @throws DomainException |
|
| 1345 | + * @throws EE_Error |
|
| 1346 | + */ |
|
| 1347 | + protected function _get_datetime_tickets_list_item( |
|
| 1348 | + $datetime_row, |
|
| 1349 | + $ticket_row, |
|
| 1350 | + $datetime, |
|
| 1351 | + $ticket, |
|
| 1352 | + $datetime_tickets = array(), |
|
| 1353 | + $default |
|
| 1354 | + ) { |
|
| 1355 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1356 | + ? $datetime_tickets[ $datetime->ID() ] |
|
| 1357 | + : array(); |
|
| 1358 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1359 | + $no_ticket = $default && empty($ticket); |
|
| 1360 | + $template_args = array( |
|
| 1361 | + 'dtt_row' => $default |
|
| 1362 | + ? 'DTTNUM' |
|
| 1363 | + : $datetime_row, |
|
| 1364 | + 'tkt_row' => $no_ticket |
|
| 1365 | + ? 'TICKETNUM' |
|
| 1366 | + : $ticket_row, |
|
| 1367 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1368 | + ? ' checked' |
|
| 1369 | + : '', |
|
| 1370 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1371 | + ? ' ticket-selected' |
|
| 1372 | + : '', |
|
| 1373 | + 'TKT_name' => $no_ticket |
|
| 1374 | + ? 'TKTNAME' |
|
| 1375 | + : $ticket->get('TKT_name'), |
|
| 1376 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1377 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1378 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1379 | + ); |
|
| 1380 | + // filter template args |
|
| 1381 | + $template_args = apply_filters( |
|
| 1382 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1383 | + $template_args, |
|
| 1384 | + $datetime_row, |
|
| 1385 | + $ticket_row, |
|
| 1386 | + $datetime, |
|
| 1387 | + $ticket, |
|
| 1388 | + $datetime_tickets, |
|
| 1389 | + $default, |
|
| 1390 | + $this->_is_creating_event |
|
| 1391 | + ); |
|
| 1392 | + return EEH_Template::display_template( |
|
| 1393 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1394 | + $template_args, |
|
| 1395 | + true |
|
| 1396 | + ); |
|
| 1397 | + } |
|
| 1398 | 1398 | |
| 1399 | 1399 | |
| 1400 | - /** |
|
| 1401 | - * This generates the ticket row for tickets. |
|
| 1402 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1403 | - * (when default === true) |
|
| 1404 | - * |
|
| 1405 | - * @param int $ticket_row Represents the row number being generated. |
|
| 1406 | - * @param $ticket |
|
| 1407 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1408 | - * or empty for default |
|
| 1409 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1410 | - * @param bool $default Whether default row being generated or not. |
|
| 1411 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1412 | - * (or empty in the case of defaults) |
|
| 1413 | - * @return mixed |
|
| 1414 | - * @throws InvalidArgumentException |
|
| 1415 | - * @throws InvalidInterfaceException |
|
| 1416 | - * @throws InvalidDataTypeException |
|
| 1417 | - * @throws DomainException |
|
| 1418 | - * @throws EE_Error |
|
| 1419 | - * @throws ReflectionException |
|
| 1420 | - */ |
|
| 1421 | - protected function _get_ticket_row( |
|
| 1422 | - $ticket_row, |
|
| 1423 | - $ticket, |
|
| 1424 | - $ticket_datetimes, |
|
| 1425 | - $all_datetimes, |
|
| 1426 | - $default = false, |
|
| 1427 | - $all_tickets = array() |
|
| 1428 | - ) { |
|
| 1429 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1430 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1431 | - $prices = ! empty($ticket) && ! $default |
|
| 1432 | - ? $ticket->get_many_related( |
|
| 1433 | - 'Price', |
|
| 1434 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
| 1435 | - ) |
|
| 1436 | - : array(); |
|
| 1437 | - // if there is only one price (which would be the base price) |
|
| 1438 | - // or NO prices and this ticket is a default ticket, |
|
| 1439 | - // let's just make sure there are no cached default prices on the object. |
|
| 1440 | - // This is done by not including any query_params. |
|
| 1441 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1442 | - $prices = $ticket->prices(); |
|
| 1443 | - } |
|
| 1444 | - // check if we're dealing with a default ticket in which case |
|
| 1445 | - // we don't want any starting_ticket_datetime_row values set |
|
| 1446 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1447 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1448 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
| 1449 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1450 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1451 | - : array(); |
|
| 1452 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1453 | - $base_price = $default ? null : $ticket->base_price(); |
|
| 1454 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1455 | - // breaking out complicated condition for ticket_status |
|
| 1456 | - if ($default) { |
|
| 1457 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1458 | - } else { |
|
| 1459 | - $ticket_status_class = $ticket->is_default() |
|
| 1460 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1461 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1462 | - } |
|
| 1463 | - // breaking out complicated condition for TKT_taxable |
|
| 1464 | - if ($default) { |
|
| 1465 | - $TKT_taxable = ''; |
|
| 1466 | - } else { |
|
| 1467 | - $TKT_taxable = $ticket->taxable() |
|
| 1468 | - ? 'checked' |
|
| 1469 | - : ''; |
|
| 1470 | - } |
|
| 1471 | - if ($default) { |
|
| 1472 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1473 | - } elseif ($ticket->is_default()) { |
|
| 1474 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1475 | - } else { |
|
| 1476 | - $TKT_status = $ticket->ticket_status(true); |
|
| 1477 | - } |
|
| 1478 | - if ($default) { |
|
| 1479 | - $TKT_min = ''; |
|
| 1480 | - } else { |
|
| 1481 | - $TKT_min = $ticket->min(); |
|
| 1482 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1483 | - $TKT_min = ''; |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - $template_args = array( |
|
| 1487 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1488 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1489 | - // on initial page load this will always be the correct order. |
|
| 1490 | - 'tkt_status_class' => $ticket_status_class, |
|
| 1491 | - 'display_edit_tkt_row' => 'display:none;', |
|
| 1492 | - 'edit_tkt_expanded' => '', |
|
| 1493 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1494 | - 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
| 1495 | - 'TKT_start_date' => $default |
|
| 1496 | - ? '' |
|
| 1497 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
| 1498 | - 'TKT_end_date' => $default |
|
| 1499 | - ? '' |
|
| 1500 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
| 1501 | - 'TKT_status' => $TKT_status, |
|
| 1502 | - 'TKT_price' => $default |
|
| 1503 | - ? '' |
|
| 1504 | - : EEH_Template::format_currency( |
|
| 1505 | - $ticket->get_ticket_total_with_taxes(), |
|
| 1506 | - false, |
|
| 1507 | - false |
|
| 1508 | - ), |
|
| 1509 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1510 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1511 | - 'TKT_qty' => $default |
|
| 1512 | - ? '' |
|
| 1513 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1514 | - 'TKT_qty_for_input' => $default |
|
| 1515 | - ? '' |
|
| 1516 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1517 | - 'TKT_uses' => $default |
|
| 1518 | - ? '' |
|
| 1519 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1520 | - 'TKT_min' => $TKT_min, |
|
| 1521 | - 'TKT_max' => $default |
|
| 1522 | - ? '' |
|
| 1523 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1524 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1525 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1526 | - 'TKT_registrations' => $default |
|
| 1527 | - ? 0 |
|
| 1528 | - : $ticket->count_registrations( |
|
| 1529 | - array( |
|
| 1530 | - array( |
|
| 1531 | - 'STS_ID' => array( |
|
| 1532 | - '!=', |
|
| 1533 | - EEM_Registration::status_id_incomplete, |
|
| 1534 | - ), |
|
| 1535 | - ), |
|
| 1536 | - ) |
|
| 1537 | - ), |
|
| 1538 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
| 1539 | - 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
| 1540 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
| 1541 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1542 | - 'TKT_is_default_selector' => '', |
|
| 1543 | - 'ticket_price_rows' => '', |
|
| 1544 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1545 | - ? '' |
|
| 1546 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1547 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1548 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1549 | - ? '' |
|
| 1550 | - : 'display:none;', |
|
| 1551 | - 'show_price_mod_button' => count($prices) > 1 |
|
| 1552 | - || ($default && $count_price_mods > 0) |
|
| 1553 | - || (! $default && $ticket->deleted()) |
|
| 1554 | - ? 'display:none;' |
|
| 1555 | - : '', |
|
| 1556 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1557 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1558 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1559 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1560 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1561 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1562 | - 'TKT_taxable' => $TKT_taxable, |
|
| 1563 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
| 1564 | - ? '' |
|
| 1565 | - : 'display:none;', |
|
| 1566 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1567 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1568 | - $ticket_subtotal, |
|
| 1569 | - false, |
|
| 1570 | - false |
|
| 1571 | - ), |
|
| 1572 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1573 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1574 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
| 1575 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1576 | - ? ' ticket-archived' |
|
| 1577 | - : '', |
|
| 1578 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
| 1579 | - && $ticket->deleted() |
|
| 1580 | - && ! $ticket->is_permanently_deleteable() |
|
| 1581 | - ? 'ee-lock-icon ' |
|
| 1582 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1583 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1584 | - ? '' |
|
| 1585 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1586 | - ); |
|
| 1587 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1588 | - ? 'display:none' |
|
| 1589 | - : ''; |
|
| 1590 | - // handle rows that should NOT be empty |
|
| 1591 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1592 | - // if empty then the start date will be now. |
|
| 1593 | - $template_args['TKT_start_date'] = date( |
|
| 1594 | - $this->_date_time_format, |
|
| 1595 | - current_time('timestamp') |
|
| 1596 | - ); |
|
| 1597 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1598 | - } |
|
| 1599 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1600 | - // get the earliest datetime (if present); |
|
| 1601 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1602 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1603 | - 'Datetime', |
|
| 1604 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1605 | - ) |
|
| 1606 | - : null; |
|
| 1607 | - if (! empty($earliest_dtt)) { |
|
| 1608 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1609 | - 'DTT_EVT_start', |
|
| 1610 | - $this->_date_time_format |
|
| 1611 | - ); |
|
| 1612 | - } else { |
|
| 1613 | - // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1614 | - $template_args['TKT_end_date'] = date( |
|
| 1615 | - $this->_date_time_format, |
|
| 1616 | - mktime( |
|
| 1617 | - 24, |
|
| 1618 | - 0, |
|
| 1619 | - 0, |
|
| 1620 | - date('m'), |
|
| 1621 | - date('d') + 29, |
|
| 1622 | - date('Y') |
|
| 1623 | - ) |
|
| 1624 | - ); |
|
| 1625 | - } |
|
| 1626 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1627 | - } |
|
| 1628 | - // generate ticket_datetime items |
|
| 1629 | - if (! $default) { |
|
| 1630 | - $datetime_row = 1; |
|
| 1631 | - foreach ($all_datetimes as $datetime) { |
|
| 1632 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1633 | - $datetime_row, |
|
| 1634 | - $ticket_row, |
|
| 1635 | - $datetime, |
|
| 1636 | - $ticket, |
|
| 1637 | - $ticket_datetimes, |
|
| 1638 | - $default |
|
| 1639 | - ); |
|
| 1640 | - $datetime_row++; |
|
| 1641 | - } |
|
| 1642 | - } |
|
| 1643 | - $price_row = 1; |
|
| 1644 | - foreach ($prices as $price) { |
|
| 1645 | - if (! $price instanceof EE_Price) { |
|
| 1646 | - continue; |
|
| 1647 | - } |
|
| 1648 | - if ($price->is_base_price()) { |
|
| 1649 | - $price_row++; |
|
| 1650 | - continue; |
|
| 1651 | - } |
|
| 1652 | - $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1653 | - $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
| 1654 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1655 | - $ticket_row, |
|
| 1656 | - $price_row, |
|
| 1657 | - $price, |
|
| 1658 | - $default, |
|
| 1659 | - $ticket, |
|
| 1660 | - $show_trash, |
|
| 1661 | - $show_create |
|
| 1662 | - ); |
|
| 1663 | - $price_row++; |
|
| 1664 | - } |
|
| 1665 | - // filter $template_args |
|
| 1666 | - $template_args = apply_filters( |
|
| 1667 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1668 | - $template_args, |
|
| 1669 | - $ticket_row, |
|
| 1670 | - $ticket, |
|
| 1671 | - $ticket_datetimes, |
|
| 1672 | - $all_datetimes, |
|
| 1673 | - $default, |
|
| 1674 | - $all_tickets, |
|
| 1675 | - $this->_is_creating_event |
|
| 1676 | - ); |
|
| 1677 | - return EEH_Template::display_template( |
|
| 1678 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1679 | - $template_args, |
|
| 1680 | - true |
|
| 1681 | - ); |
|
| 1682 | - } |
|
| 1400 | + /** |
|
| 1401 | + * This generates the ticket row for tickets. |
|
| 1402 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1403 | + * (when default === true) |
|
| 1404 | + * |
|
| 1405 | + * @param int $ticket_row Represents the row number being generated. |
|
| 1406 | + * @param $ticket |
|
| 1407 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1408 | + * or empty for default |
|
| 1409 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1410 | + * @param bool $default Whether default row being generated or not. |
|
| 1411 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1412 | + * (or empty in the case of defaults) |
|
| 1413 | + * @return mixed |
|
| 1414 | + * @throws InvalidArgumentException |
|
| 1415 | + * @throws InvalidInterfaceException |
|
| 1416 | + * @throws InvalidDataTypeException |
|
| 1417 | + * @throws DomainException |
|
| 1418 | + * @throws EE_Error |
|
| 1419 | + * @throws ReflectionException |
|
| 1420 | + */ |
|
| 1421 | + protected function _get_ticket_row( |
|
| 1422 | + $ticket_row, |
|
| 1423 | + $ticket, |
|
| 1424 | + $ticket_datetimes, |
|
| 1425 | + $all_datetimes, |
|
| 1426 | + $default = false, |
|
| 1427 | + $all_tickets = array() |
|
| 1428 | + ) { |
|
| 1429 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1430 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1431 | + $prices = ! empty($ticket) && ! $default |
|
| 1432 | + ? $ticket->get_many_related( |
|
| 1433 | + 'Price', |
|
| 1434 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
| 1435 | + ) |
|
| 1436 | + : array(); |
|
| 1437 | + // if there is only one price (which would be the base price) |
|
| 1438 | + // or NO prices and this ticket is a default ticket, |
|
| 1439 | + // let's just make sure there are no cached default prices on the object. |
|
| 1440 | + // This is done by not including any query_params. |
|
| 1441 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1442 | + $prices = $ticket->prices(); |
|
| 1443 | + } |
|
| 1444 | + // check if we're dealing with a default ticket in which case |
|
| 1445 | + // we don't want any starting_ticket_datetime_row values set |
|
| 1446 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1447 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1448 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
| 1449 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1450 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1451 | + : array(); |
|
| 1452 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1453 | + $base_price = $default ? null : $ticket->base_price(); |
|
| 1454 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1455 | + // breaking out complicated condition for ticket_status |
|
| 1456 | + if ($default) { |
|
| 1457 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1458 | + } else { |
|
| 1459 | + $ticket_status_class = $ticket->is_default() |
|
| 1460 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1461 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1462 | + } |
|
| 1463 | + // breaking out complicated condition for TKT_taxable |
|
| 1464 | + if ($default) { |
|
| 1465 | + $TKT_taxable = ''; |
|
| 1466 | + } else { |
|
| 1467 | + $TKT_taxable = $ticket->taxable() |
|
| 1468 | + ? 'checked' |
|
| 1469 | + : ''; |
|
| 1470 | + } |
|
| 1471 | + if ($default) { |
|
| 1472 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1473 | + } elseif ($ticket->is_default()) { |
|
| 1474 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1475 | + } else { |
|
| 1476 | + $TKT_status = $ticket->ticket_status(true); |
|
| 1477 | + } |
|
| 1478 | + if ($default) { |
|
| 1479 | + $TKT_min = ''; |
|
| 1480 | + } else { |
|
| 1481 | + $TKT_min = $ticket->min(); |
|
| 1482 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1483 | + $TKT_min = ''; |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + $template_args = array( |
|
| 1487 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1488 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1489 | + // on initial page load this will always be the correct order. |
|
| 1490 | + 'tkt_status_class' => $ticket_status_class, |
|
| 1491 | + 'display_edit_tkt_row' => 'display:none;', |
|
| 1492 | + 'edit_tkt_expanded' => '', |
|
| 1493 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1494 | + 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
| 1495 | + 'TKT_start_date' => $default |
|
| 1496 | + ? '' |
|
| 1497 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
| 1498 | + 'TKT_end_date' => $default |
|
| 1499 | + ? '' |
|
| 1500 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
| 1501 | + 'TKT_status' => $TKT_status, |
|
| 1502 | + 'TKT_price' => $default |
|
| 1503 | + ? '' |
|
| 1504 | + : EEH_Template::format_currency( |
|
| 1505 | + $ticket->get_ticket_total_with_taxes(), |
|
| 1506 | + false, |
|
| 1507 | + false |
|
| 1508 | + ), |
|
| 1509 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1510 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1511 | + 'TKT_qty' => $default |
|
| 1512 | + ? '' |
|
| 1513 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1514 | + 'TKT_qty_for_input' => $default |
|
| 1515 | + ? '' |
|
| 1516 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1517 | + 'TKT_uses' => $default |
|
| 1518 | + ? '' |
|
| 1519 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1520 | + 'TKT_min' => $TKT_min, |
|
| 1521 | + 'TKT_max' => $default |
|
| 1522 | + ? '' |
|
| 1523 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1524 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1525 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1526 | + 'TKT_registrations' => $default |
|
| 1527 | + ? 0 |
|
| 1528 | + : $ticket->count_registrations( |
|
| 1529 | + array( |
|
| 1530 | + array( |
|
| 1531 | + 'STS_ID' => array( |
|
| 1532 | + '!=', |
|
| 1533 | + EEM_Registration::status_id_incomplete, |
|
| 1534 | + ), |
|
| 1535 | + ), |
|
| 1536 | + ) |
|
| 1537 | + ), |
|
| 1538 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
| 1539 | + 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
| 1540 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
| 1541 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1542 | + 'TKT_is_default_selector' => '', |
|
| 1543 | + 'ticket_price_rows' => '', |
|
| 1544 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1545 | + ? '' |
|
| 1546 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1547 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1548 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1549 | + ? '' |
|
| 1550 | + : 'display:none;', |
|
| 1551 | + 'show_price_mod_button' => count($prices) > 1 |
|
| 1552 | + || ($default && $count_price_mods > 0) |
|
| 1553 | + || (! $default && $ticket->deleted()) |
|
| 1554 | + ? 'display:none;' |
|
| 1555 | + : '', |
|
| 1556 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1557 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1558 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1559 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1560 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1561 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1562 | + 'TKT_taxable' => $TKT_taxable, |
|
| 1563 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
| 1564 | + ? '' |
|
| 1565 | + : 'display:none;', |
|
| 1566 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1567 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1568 | + $ticket_subtotal, |
|
| 1569 | + false, |
|
| 1570 | + false |
|
| 1571 | + ), |
|
| 1572 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1573 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1574 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
| 1575 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1576 | + ? ' ticket-archived' |
|
| 1577 | + : '', |
|
| 1578 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
| 1579 | + && $ticket->deleted() |
|
| 1580 | + && ! $ticket->is_permanently_deleteable() |
|
| 1581 | + ? 'ee-lock-icon ' |
|
| 1582 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1583 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1584 | + ? '' |
|
| 1585 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1586 | + ); |
|
| 1587 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1588 | + ? 'display:none' |
|
| 1589 | + : ''; |
|
| 1590 | + // handle rows that should NOT be empty |
|
| 1591 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1592 | + // if empty then the start date will be now. |
|
| 1593 | + $template_args['TKT_start_date'] = date( |
|
| 1594 | + $this->_date_time_format, |
|
| 1595 | + current_time('timestamp') |
|
| 1596 | + ); |
|
| 1597 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1598 | + } |
|
| 1599 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1600 | + // get the earliest datetime (if present); |
|
| 1601 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1602 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1603 | + 'Datetime', |
|
| 1604 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1605 | + ) |
|
| 1606 | + : null; |
|
| 1607 | + if (! empty($earliest_dtt)) { |
|
| 1608 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1609 | + 'DTT_EVT_start', |
|
| 1610 | + $this->_date_time_format |
|
| 1611 | + ); |
|
| 1612 | + } else { |
|
| 1613 | + // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1614 | + $template_args['TKT_end_date'] = date( |
|
| 1615 | + $this->_date_time_format, |
|
| 1616 | + mktime( |
|
| 1617 | + 24, |
|
| 1618 | + 0, |
|
| 1619 | + 0, |
|
| 1620 | + date('m'), |
|
| 1621 | + date('d') + 29, |
|
| 1622 | + date('Y') |
|
| 1623 | + ) |
|
| 1624 | + ); |
|
| 1625 | + } |
|
| 1626 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1627 | + } |
|
| 1628 | + // generate ticket_datetime items |
|
| 1629 | + if (! $default) { |
|
| 1630 | + $datetime_row = 1; |
|
| 1631 | + foreach ($all_datetimes as $datetime) { |
|
| 1632 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1633 | + $datetime_row, |
|
| 1634 | + $ticket_row, |
|
| 1635 | + $datetime, |
|
| 1636 | + $ticket, |
|
| 1637 | + $ticket_datetimes, |
|
| 1638 | + $default |
|
| 1639 | + ); |
|
| 1640 | + $datetime_row++; |
|
| 1641 | + } |
|
| 1642 | + } |
|
| 1643 | + $price_row = 1; |
|
| 1644 | + foreach ($prices as $price) { |
|
| 1645 | + if (! $price instanceof EE_Price) { |
|
| 1646 | + continue; |
|
| 1647 | + } |
|
| 1648 | + if ($price->is_base_price()) { |
|
| 1649 | + $price_row++; |
|
| 1650 | + continue; |
|
| 1651 | + } |
|
| 1652 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1653 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
| 1654 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1655 | + $ticket_row, |
|
| 1656 | + $price_row, |
|
| 1657 | + $price, |
|
| 1658 | + $default, |
|
| 1659 | + $ticket, |
|
| 1660 | + $show_trash, |
|
| 1661 | + $show_create |
|
| 1662 | + ); |
|
| 1663 | + $price_row++; |
|
| 1664 | + } |
|
| 1665 | + // filter $template_args |
|
| 1666 | + $template_args = apply_filters( |
|
| 1667 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1668 | + $template_args, |
|
| 1669 | + $ticket_row, |
|
| 1670 | + $ticket, |
|
| 1671 | + $ticket_datetimes, |
|
| 1672 | + $all_datetimes, |
|
| 1673 | + $default, |
|
| 1674 | + $all_tickets, |
|
| 1675 | + $this->_is_creating_event |
|
| 1676 | + ); |
|
| 1677 | + return EEH_Template::display_template( |
|
| 1678 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1679 | + $template_args, |
|
| 1680 | + true |
|
| 1681 | + ); |
|
| 1682 | + } |
|
| 1683 | 1683 | |
| 1684 | 1684 | |
| 1685 | - /** |
|
| 1686 | - * @param int $ticket_row |
|
| 1687 | - * @param EE_Ticket|null $ticket |
|
| 1688 | - * @return string |
|
| 1689 | - * @throws DomainException |
|
| 1690 | - * @throws EE_Error |
|
| 1691 | - */ |
|
| 1692 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1693 | - { |
|
| 1694 | - $tax_rows = ''; |
|
| 1695 | - /** @var EE_Price[] $taxes */ |
|
| 1696 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1697 | - foreach ($taxes as $tax) { |
|
| 1698 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1699 | - $template_args = array( |
|
| 1700 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1701 | - ? '' |
|
| 1702 | - : 'display:none;', |
|
| 1703 | - 'tax_id' => $tax->ID(), |
|
| 1704 | - 'tkt_row' => $ticket_row, |
|
| 1705 | - 'tax_label' => $tax->get('PRC_name'), |
|
| 1706 | - 'tax_added' => $tax_added, |
|
| 1707 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1708 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1709 | - ); |
|
| 1710 | - $template_args = apply_filters( |
|
| 1711 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1712 | - $template_args, |
|
| 1713 | - $ticket_row, |
|
| 1714 | - $ticket, |
|
| 1715 | - $this->_is_creating_event |
|
| 1716 | - ); |
|
| 1717 | - $tax_rows .= EEH_Template::display_template( |
|
| 1718 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1719 | - $template_args, |
|
| 1720 | - true |
|
| 1721 | - ); |
|
| 1722 | - } |
|
| 1723 | - return $tax_rows; |
|
| 1724 | - } |
|
| 1685 | + /** |
|
| 1686 | + * @param int $ticket_row |
|
| 1687 | + * @param EE_Ticket|null $ticket |
|
| 1688 | + * @return string |
|
| 1689 | + * @throws DomainException |
|
| 1690 | + * @throws EE_Error |
|
| 1691 | + */ |
|
| 1692 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1693 | + { |
|
| 1694 | + $tax_rows = ''; |
|
| 1695 | + /** @var EE_Price[] $taxes */ |
|
| 1696 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1697 | + foreach ($taxes as $tax) { |
|
| 1698 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1699 | + $template_args = array( |
|
| 1700 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1701 | + ? '' |
|
| 1702 | + : 'display:none;', |
|
| 1703 | + 'tax_id' => $tax->ID(), |
|
| 1704 | + 'tkt_row' => $ticket_row, |
|
| 1705 | + 'tax_label' => $tax->get('PRC_name'), |
|
| 1706 | + 'tax_added' => $tax_added, |
|
| 1707 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1708 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1709 | + ); |
|
| 1710 | + $template_args = apply_filters( |
|
| 1711 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1712 | + $template_args, |
|
| 1713 | + $ticket_row, |
|
| 1714 | + $ticket, |
|
| 1715 | + $this->_is_creating_event |
|
| 1716 | + ); |
|
| 1717 | + $tax_rows .= EEH_Template::display_template( |
|
| 1718 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1719 | + $template_args, |
|
| 1720 | + true |
|
| 1721 | + ); |
|
| 1722 | + } |
|
| 1723 | + return $tax_rows; |
|
| 1724 | + } |
|
| 1725 | 1725 | |
| 1726 | 1726 | |
| 1727 | - /** |
|
| 1728 | - * @param EE_Price $tax |
|
| 1729 | - * @param EE_Ticket|null $ticket |
|
| 1730 | - * @return float|int |
|
| 1731 | - * @throws EE_Error |
|
| 1732 | - */ |
|
| 1733 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1734 | - { |
|
| 1735 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1736 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1737 | - } |
|
| 1727 | + /** |
|
| 1728 | + * @param EE_Price $tax |
|
| 1729 | + * @param EE_Ticket|null $ticket |
|
| 1730 | + * @return float|int |
|
| 1731 | + * @throws EE_Error |
|
| 1732 | + */ |
|
| 1733 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1734 | + { |
|
| 1735 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1736 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1737 | + } |
|
| 1738 | 1738 | |
| 1739 | 1739 | |
| 1740 | - /** |
|
| 1741 | - * @param int $ticket_row |
|
| 1742 | - * @param int $price_row |
|
| 1743 | - * @param EE_Price|null $price |
|
| 1744 | - * @param bool $default |
|
| 1745 | - * @param EE_Ticket|null $ticket |
|
| 1746 | - * @param bool $show_trash |
|
| 1747 | - * @param bool $show_create |
|
| 1748 | - * @return mixed |
|
| 1749 | - * @throws InvalidArgumentException |
|
| 1750 | - * @throws InvalidInterfaceException |
|
| 1751 | - * @throws InvalidDataTypeException |
|
| 1752 | - * @throws DomainException |
|
| 1753 | - * @throws EE_Error |
|
| 1754 | - * @throws ReflectionException |
|
| 1755 | - */ |
|
| 1756 | - protected function _get_ticket_price_row( |
|
| 1757 | - $ticket_row, |
|
| 1758 | - $price_row, |
|
| 1759 | - $price, |
|
| 1760 | - $default, |
|
| 1761 | - $ticket, |
|
| 1762 | - $show_trash = true, |
|
| 1763 | - $show_create = true |
|
| 1764 | - ) { |
|
| 1765 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1766 | - $template_args = array( |
|
| 1767 | - 'tkt_row' => $default && empty($ticket) |
|
| 1768 | - ? 'TICKETNUM' |
|
| 1769 | - : $ticket_row, |
|
| 1770 | - 'PRC_order' => $default && empty($price) |
|
| 1771 | - ? 'PRICENUM' |
|
| 1772 | - : $price_row, |
|
| 1773 | - 'edit_prices_name' => $default && empty($price) |
|
| 1774 | - ? 'PRICENAMEATTR' |
|
| 1775 | - : 'edit_prices', |
|
| 1776 | - 'price_type_selector' => $default && empty($price) |
|
| 1777 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1778 | - : $this->_get_price_type_selector( |
|
| 1779 | - $ticket_row, |
|
| 1780 | - $price_row, |
|
| 1781 | - $price, |
|
| 1782 | - $default, |
|
| 1783 | - $send_disabled |
|
| 1784 | - ), |
|
| 1785 | - 'PRC_ID' => $default && empty($price) |
|
| 1786 | - ? 0 |
|
| 1787 | - : $price->ID(), |
|
| 1788 | - 'PRC_is_default' => $default && empty($price) |
|
| 1789 | - ? 0 |
|
| 1790 | - : $price->get('PRC_is_default'), |
|
| 1791 | - 'PRC_name' => $default && empty($price) |
|
| 1792 | - ? '' |
|
| 1793 | - : $price->get('PRC_name'), |
|
| 1794 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1795 | - 'show_plus_or_minus' => $default && empty($price) |
|
| 1796 | - ? '' |
|
| 1797 | - : 'display:none;', |
|
| 1798 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1799 | - ? 'display:none;' |
|
| 1800 | - : '', |
|
| 1801 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1802 | - ? 'display:none;' |
|
| 1803 | - : '', |
|
| 1804 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1805 | - ? 'display:none' |
|
| 1806 | - : '', |
|
| 1807 | - 'PRC_amount' => $default && empty($price) |
|
| 1808 | - ? 0 |
|
| 1809 | - : $price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1810 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1811 | - ? 'display:none;' |
|
| 1812 | - : '', |
|
| 1813 | - 'show_trash_icon' => $show_trash |
|
| 1814 | - ? '' |
|
| 1815 | - : ' style="display:none;"', |
|
| 1816 | - 'show_create_button' => $show_create |
|
| 1817 | - ? '' |
|
| 1818 | - : ' style="display:none;"', |
|
| 1819 | - 'PRC_desc' => $default && empty($price) |
|
| 1820 | - ? '' |
|
| 1821 | - : $price->get('PRC_desc'), |
|
| 1822 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1823 | - ); |
|
| 1824 | - $template_args = apply_filters( |
|
| 1825 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1826 | - $template_args, |
|
| 1827 | - $ticket_row, |
|
| 1828 | - $price_row, |
|
| 1829 | - $price, |
|
| 1830 | - $default, |
|
| 1831 | - $ticket, |
|
| 1832 | - $show_trash, |
|
| 1833 | - $show_create, |
|
| 1834 | - $this->_is_creating_event |
|
| 1835 | - ); |
|
| 1836 | - return EEH_Template::display_template( |
|
| 1837 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1838 | - $template_args, |
|
| 1839 | - true |
|
| 1840 | - ); |
|
| 1841 | - } |
|
| 1740 | + /** |
|
| 1741 | + * @param int $ticket_row |
|
| 1742 | + * @param int $price_row |
|
| 1743 | + * @param EE_Price|null $price |
|
| 1744 | + * @param bool $default |
|
| 1745 | + * @param EE_Ticket|null $ticket |
|
| 1746 | + * @param bool $show_trash |
|
| 1747 | + * @param bool $show_create |
|
| 1748 | + * @return mixed |
|
| 1749 | + * @throws InvalidArgumentException |
|
| 1750 | + * @throws InvalidInterfaceException |
|
| 1751 | + * @throws InvalidDataTypeException |
|
| 1752 | + * @throws DomainException |
|
| 1753 | + * @throws EE_Error |
|
| 1754 | + * @throws ReflectionException |
|
| 1755 | + */ |
|
| 1756 | + protected function _get_ticket_price_row( |
|
| 1757 | + $ticket_row, |
|
| 1758 | + $price_row, |
|
| 1759 | + $price, |
|
| 1760 | + $default, |
|
| 1761 | + $ticket, |
|
| 1762 | + $show_trash = true, |
|
| 1763 | + $show_create = true |
|
| 1764 | + ) { |
|
| 1765 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1766 | + $template_args = array( |
|
| 1767 | + 'tkt_row' => $default && empty($ticket) |
|
| 1768 | + ? 'TICKETNUM' |
|
| 1769 | + : $ticket_row, |
|
| 1770 | + 'PRC_order' => $default && empty($price) |
|
| 1771 | + ? 'PRICENUM' |
|
| 1772 | + : $price_row, |
|
| 1773 | + 'edit_prices_name' => $default && empty($price) |
|
| 1774 | + ? 'PRICENAMEATTR' |
|
| 1775 | + : 'edit_prices', |
|
| 1776 | + 'price_type_selector' => $default && empty($price) |
|
| 1777 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1778 | + : $this->_get_price_type_selector( |
|
| 1779 | + $ticket_row, |
|
| 1780 | + $price_row, |
|
| 1781 | + $price, |
|
| 1782 | + $default, |
|
| 1783 | + $send_disabled |
|
| 1784 | + ), |
|
| 1785 | + 'PRC_ID' => $default && empty($price) |
|
| 1786 | + ? 0 |
|
| 1787 | + : $price->ID(), |
|
| 1788 | + 'PRC_is_default' => $default && empty($price) |
|
| 1789 | + ? 0 |
|
| 1790 | + : $price->get('PRC_is_default'), |
|
| 1791 | + 'PRC_name' => $default && empty($price) |
|
| 1792 | + ? '' |
|
| 1793 | + : $price->get('PRC_name'), |
|
| 1794 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1795 | + 'show_plus_or_minus' => $default && empty($price) |
|
| 1796 | + ? '' |
|
| 1797 | + : 'display:none;', |
|
| 1798 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1799 | + ? 'display:none;' |
|
| 1800 | + : '', |
|
| 1801 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1802 | + ? 'display:none;' |
|
| 1803 | + : '', |
|
| 1804 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1805 | + ? 'display:none' |
|
| 1806 | + : '', |
|
| 1807 | + 'PRC_amount' => $default && empty($price) |
|
| 1808 | + ? 0 |
|
| 1809 | + : $price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1810 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1811 | + ? 'display:none;' |
|
| 1812 | + : '', |
|
| 1813 | + 'show_trash_icon' => $show_trash |
|
| 1814 | + ? '' |
|
| 1815 | + : ' style="display:none;"', |
|
| 1816 | + 'show_create_button' => $show_create |
|
| 1817 | + ? '' |
|
| 1818 | + : ' style="display:none;"', |
|
| 1819 | + 'PRC_desc' => $default && empty($price) |
|
| 1820 | + ? '' |
|
| 1821 | + : $price->get('PRC_desc'), |
|
| 1822 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1823 | + ); |
|
| 1824 | + $template_args = apply_filters( |
|
| 1825 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1826 | + $template_args, |
|
| 1827 | + $ticket_row, |
|
| 1828 | + $price_row, |
|
| 1829 | + $price, |
|
| 1830 | + $default, |
|
| 1831 | + $ticket, |
|
| 1832 | + $show_trash, |
|
| 1833 | + $show_create, |
|
| 1834 | + $this->_is_creating_event |
|
| 1835 | + ); |
|
| 1836 | + return EEH_Template::display_template( |
|
| 1837 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1838 | + $template_args, |
|
| 1839 | + true |
|
| 1840 | + ); |
|
| 1841 | + } |
|
| 1842 | 1842 | |
| 1843 | 1843 | |
| 1844 | - /** |
|
| 1845 | - * @param int $ticket_row |
|
| 1846 | - * @param int $price_row |
|
| 1847 | - * @param EE_Price $price |
|
| 1848 | - * @param bool $default |
|
| 1849 | - * @param bool $disabled |
|
| 1850 | - * @return mixed |
|
| 1851 | - * @throws ReflectionException |
|
| 1852 | - * @throws InvalidArgumentException |
|
| 1853 | - * @throws InvalidInterfaceException |
|
| 1854 | - * @throws InvalidDataTypeException |
|
| 1855 | - * @throws DomainException |
|
| 1856 | - * @throws EE_Error |
|
| 1857 | - */ |
|
| 1858 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1859 | - { |
|
| 1860 | - if ($price->is_base_price()) { |
|
| 1861 | - return $this->_get_base_price_template( |
|
| 1862 | - $ticket_row, |
|
| 1863 | - $price_row, |
|
| 1864 | - $price, |
|
| 1865 | - $default |
|
| 1866 | - ); |
|
| 1867 | - } |
|
| 1868 | - return $this->_get_price_modifier_template( |
|
| 1869 | - $ticket_row, |
|
| 1870 | - $price_row, |
|
| 1871 | - $price, |
|
| 1872 | - $default, |
|
| 1873 | - $disabled |
|
| 1874 | - ); |
|
| 1875 | - } |
|
| 1844 | + /** |
|
| 1845 | + * @param int $ticket_row |
|
| 1846 | + * @param int $price_row |
|
| 1847 | + * @param EE_Price $price |
|
| 1848 | + * @param bool $default |
|
| 1849 | + * @param bool $disabled |
|
| 1850 | + * @return mixed |
|
| 1851 | + * @throws ReflectionException |
|
| 1852 | + * @throws InvalidArgumentException |
|
| 1853 | + * @throws InvalidInterfaceException |
|
| 1854 | + * @throws InvalidDataTypeException |
|
| 1855 | + * @throws DomainException |
|
| 1856 | + * @throws EE_Error |
|
| 1857 | + */ |
|
| 1858 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1859 | + { |
|
| 1860 | + if ($price->is_base_price()) { |
|
| 1861 | + return $this->_get_base_price_template( |
|
| 1862 | + $ticket_row, |
|
| 1863 | + $price_row, |
|
| 1864 | + $price, |
|
| 1865 | + $default |
|
| 1866 | + ); |
|
| 1867 | + } |
|
| 1868 | + return $this->_get_price_modifier_template( |
|
| 1869 | + $ticket_row, |
|
| 1870 | + $price_row, |
|
| 1871 | + $price, |
|
| 1872 | + $default, |
|
| 1873 | + $disabled |
|
| 1874 | + ); |
|
| 1875 | + } |
|
| 1876 | 1876 | |
| 1877 | 1877 | |
| 1878 | - /** |
|
| 1879 | - * @param int $ticket_row |
|
| 1880 | - * @param int $price_row |
|
| 1881 | - * @param EE_Price $price |
|
| 1882 | - * @param bool $default |
|
| 1883 | - * @return mixed |
|
| 1884 | - * @throws DomainException |
|
| 1885 | - * @throws EE_Error |
|
| 1886 | - */ |
|
| 1887 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1888 | - { |
|
| 1889 | - $template_args = array( |
|
| 1890 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1891 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1892 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1893 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1894 | - 'price_selected_operator' => '+', |
|
| 1895 | - 'price_selected_is_percent' => 0, |
|
| 1896 | - ); |
|
| 1897 | - $template_args = apply_filters( |
|
| 1898 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1899 | - $template_args, |
|
| 1900 | - $ticket_row, |
|
| 1901 | - $price_row, |
|
| 1902 | - $price, |
|
| 1903 | - $default, |
|
| 1904 | - $this->_is_creating_event |
|
| 1905 | - ); |
|
| 1906 | - return EEH_Template::display_template( |
|
| 1907 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1908 | - $template_args, |
|
| 1909 | - true |
|
| 1910 | - ); |
|
| 1911 | - } |
|
| 1878 | + /** |
|
| 1879 | + * @param int $ticket_row |
|
| 1880 | + * @param int $price_row |
|
| 1881 | + * @param EE_Price $price |
|
| 1882 | + * @param bool $default |
|
| 1883 | + * @return mixed |
|
| 1884 | + * @throws DomainException |
|
| 1885 | + * @throws EE_Error |
|
| 1886 | + */ |
|
| 1887 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1888 | + { |
|
| 1889 | + $template_args = array( |
|
| 1890 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1891 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1892 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1893 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1894 | + 'price_selected_operator' => '+', |
|
| 1895 | + 'price_selected_is_percent' => 0, |
|
| 1896 | + ); |
|
| 1897 | + $template_args = apply_filters( |
|
| 1898 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1899 | + $template_args, |
|
| 1900 | + $ticket_row, |
|
| 1901 | + $price_row, |
|
| 1902 | + $price, |
|
| 1903 | + $default, |
|
| 1904 | + $this->_is_creating_event |
|
| 1905 | + ); |
|
| 1906 | + return EEH_Template::display_template( |
|
| 1907 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1908 | + $template_args, |
|
| 1909 | + true |
|
| 1910 | + ); |
|
| 1911 | + } |
|
| 1912 | 1912 | |
| 1913 | 1913 | |
| 1914 | - /** |
|
| 1915 | - * @param int $ticket_row |
|
| 1916 | - * @param int $price_row |
|
| 1917 | - * @param EE_Price $price |
|
| 1918 | - * @param bool $default |
|
| 1919 | - * @param bool $disabled |
|
| 1920 | - * @return mixed |
|
| 1921 | - * @throws ReflectionException |
|
| 1922 | - * @throws InvalidArgumentException |
|
| 1923 | - * @throws InvalidInterfaceException |
|
| 1924 | - * @throws InvalidDataTypeException |
|
| 1925 | - * @throws DomainException |
|
| 1926 | - * @throws EE_Error |
|
| 1927 | - */ |
|
| 1928 | - protected function _get_price_modifier_template( |
|
| 1929 | - $ticket_row, |
|
| 1930 | - $price_row, |
|
| 1931 | - $price, |
|
| 1932 | - $default, |
|
| 1933 | - $disabled = false |
|
| 1934 | - ) { |
|
| 1935 | - $select_name = $default && ! $price instanceof EE_Price |
|
| 1936 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1937 | - : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]'; |
|
| 1938 | - /** @var EEM_Price_Type $price_type_model */ |
|
| 1939 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1940 | - $price_types = $price_type_model->get_all(array( |
|
| 1941 | - array( |
|
| 1942 | - 'OR' => array( |
|
| 1943 | - 'PBT_ID' => '2', |
|
| 1944 | - 'PBT_ID*' => '3', |
|
| 1945 | - ), |
|
| 1946 | - ), |
|
| 1947 | - )); |
|
| 1948 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1949 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1950 | - : array(); |
|
| 1951 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1952 | - $price_option_spans = ''; |
|
| 1953 | - // setup price types for selector |
|
| 1954 | - foreach ($price_types as $price_type) { |
|
| 1955 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1956 | - continue; |
|
| 1957 | - } |
|
| 1958 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
| 1959 | - // while we're in the loop let's setup the option spans used by js |
|
| 1960 | - $span_args = array( |
|
| 1961 | - 'PRT_ID' => $price_type->ID(), |
|
| 1962 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1963 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1964 | - ); |
|
| 1965 | - $price_option_spans .= EEH_Template::display_template( |
|
| 1966 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | - $span_args, |
|
| 1968 | - true |
|
| 1969 | - ); |
|
| 1970 | - } |
|
| 1971 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1972 | - : $select_name; |
|
| 1973 | - $select_input = new EE_Select_Input( |
|
| 1974 | - $all_price_types, |
|
| 1975 | - array( |
|
| 1976 | - 'default' => $selected_price_type_id, |
|
| 1977 | - 'html_name' => $select_name, |
|
| 1978 | - 'html_class' => 'edit-price-PRT_ID', |
|
| 1979 | - 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
| 1980 | - ) |
|
| 1981 | - ); |
|
| 1982 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1983 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1984 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1985 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1986 | - $template_args = array( |
|
| 1987 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1988 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1989 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1990 | - 'main_name' => $select_name, |
|
| 1991 | - 'selected_price_type_id' => $selected_price_type_id, |
|
| 1992 | - 'price_option_spans' => $price_option_spans, |
|
| 1993 | - 'price_selected_operator' => $price_selected_operator, |
|
| 1994 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1995 | - 'disabled' => $disabled, |
|
| 1996 | - ); |
|
| 1997 | - $template_args = apply_filters( |
|
| 1998 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1999 | - $template_args, |
|
| 2000 | - $ticket_row, |
|
| 2001 | - $price_row, |
|
| 2002 | - $price, |
|
| 2003 | - $default, |
|
| 2004 | - $disabled, |
|
| 2005 | - $this->_is_creating_event |
|
| 2006 | - ); |
|
| 2007 | - return EEH_Template::display_template( |
|
| 2008 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2009 | - $template_args, |
|
| 2010 | - true |
|
| 2011 | - ); |
|
| 2012 | - } |
|
| 1914 | + /** |
|
| 1915 | + * @param int $ticket_row |
|
| 1916 | + * @param int $price_row |
|
| 1917 | + * @param EE_Price $price |
|
| 1918 | + * @param bool $default |
|
| 1919 | + * @param bool $disabled |
|
| 1920 | + * @return mixed |
|
| 1921 | + * @throws ReflectionException |
|
| 1922 | + * @throws InvalidArgumentException |
|
| 1923 | + * @throws InvalidInterfaceException |
|
| 1924 | + * @throws InvalidDataTypeException |
|
| 1925 | + * @throws DomainException |
|
| 1926 | + * @throws EE_Error |
|
| 1927 | + */ |
|
| 1928 | + protected function _get_price_modifier_template( |
|
| 1929 | + $ticket_row, |
|
| 1930 | + $price_row, |
|
| 1931 | + $price, |
|
| 1932 | + $default, |
|
| 1933 | + $disabled = false |
|
| 1934 | + ) { |
|
| 1935 | + $select_name = $default && ! $price instanceof EE_Price |
|
| 1936 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1937 | + : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]'; |
|
| 1938 | + /** @var EEM_Price_Type $price_type_model */ |
|
| 1939 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1940 | + $price_types = $price_type_model->get_all(array( |
|
| 1941 | + array( |
|
| 1942 | + 'OR' => array( |
|
| 1943 | + 'PBT_ID' => '2', |
|
| 1944 | + 'PBT_ID*' => '3', |
|
| 1945 | + ), |
|
| 1946 | + ), |
|
| 1947 | + )); |
|
| 1948 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1949 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1950 | + : array(); |
|
| 1951 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1952 | + $price_option_spans = ''; |
|
| 1953 | + // setup price types for selector |
|
| 1954 | + foreach ($price_types as $price_type) { |
|
| 1955 | + if (! $price_type instanceof EE_Price_Type) { |
|
| 1956 | + continue; |
|
| 1957 | + } |
|
| 1958 | + $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
| 1959 | + // while we're in the loop let's setup the option spans used by js |
|
| 1960 | + $span_args = array( |
|
| 1961 | + 'PRT_ID' => $price_type->ID(), |
|
| 1962 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1963 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1964 | + ); |
|
| 1965 | + $price_option_spans .= EEH_Template::display_template( |
|
| 1966 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | + $span_args, |
|
| 1968 | + true |
|
| 1969 | + ); |
|
| 1970 | + } |
|
| 1971 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1972 | + : $select_name; |
|
| 1973 | + $select_input = new EE_Select_Input( |
|
| 1974 | + $all_price_types, |
|
| 1975 | + array( |
|
| 1976 | + 'default' => $selected_price_type_id, |
|
| 1977 | + 'html_name' => $select_name, |
|
| 1978 | + 'html_class' => 'edit-price-PRT_ID', |
|
| 1979 | + 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
| 1980 | + ) |
|
| 1981 | + ); |
|
| 1982 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1983 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1984 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1985 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1986 | + $template_args = array( |
|
| 1987 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1988 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1989 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1990 | + 'main_name' => $select_name, |
|
| 1991 | + 'selected_price_type_id' => $selected_price_type_id, |
|
| 1992 | + 'price_option_spans' => $price_option_spans, |
|
| 1993 | + 'price_selected_operator' => $price_selected_operator, |
|
| 1994 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1995 | + 'disabled' => $disabled, |
|
| 1996 | + ); |
|
| 1997 | + $template_args = apply_filters( |
|
| 1998 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1999 | + $template_args, |
|
| 2000 | + $ticket_row, |
|
| 2001 | + $price_row, |
|
| 2002 | + $price, |
|
| 2003 | + $default, |
|
| 2004 | + $disabled, |
|
| 2005 | + $this->_is_creating_event |
|
| 2006 | + ); |
|
| 2007 | + return EEH_Template::display_template( |
|
| 2008 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2009 | + $template_args, |
|
| 2010 | + true |
|
| 2011 | + ); |
|
| 2012 | + } |
|
| 2013 | 2013 | |
| 2014 | 2014 | |
| 2015 | - /** |
|
| 2016 | - * @param int $datetime_row |
|
| 2017 | - * @param int $ticket_row |
|
| 2018 | - * @param EE_Datetime|null $datetime |
|
| 2019 | - * @param EE_Ticket|null $ticket |
|
| 2020 | - * @param array $ticket_datetimes |
|
| 2021 | - * @param bool $default |
|
| 2022 | - * @return mixed |
|
| 2023 | - * @throws DomainException |
|
| 2024 | - * @throws EE_Error |
|
| 2025 | - */ |
|
| 2026 | - protected function _get_ticket_datetime_list_item( |
|
| 2027 | - $datetime_row, |
|
| 2028 | - $ticket_row, |
|
| 2029 | - $datetime, |
|
| 2030 | - $ticket, |
|
| 2031 | - $ticket_datetimes = array(), |
|
| 2032 | - $default |
|
| 2033 | - ) { |
|
| 2034 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2035 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2036 | - : array(); |
|
| 2037 | - $template_args = array( |
|
| 2038 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 2039 | - ? 'DTTNUM' |
|
| 2040 | - : $datetime_row, |
|
| 2041 | - 'tkt_row' => $default |
|
| 2042 | - ? 'TICKETNUM' |
|
| 2043 | - : $ticket_row, |
|
| 2044 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2045 | - ? ' ticket-selected' |
|
| 2046 | - : '', |
|
| 2047 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2048 | - ? ' checked' |
|
| 2049 | - : '', |
|
| 2050 | - 'DTT_name' => $default && empty($datetime) |
|
| 2051 | - ? 'DTTNAME' |
|
| 2052 | - : $datetime->get_dtt_display_name(true), |
|
| 2053 | - 'tkt_status_class' => '', |
|
| 2054 | - ); |
|
| 2055 | - $template_args = apply_filters( |
|
| 2056 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 2057 | - $template_args, |
|
| 2058 | - $datetime_row, |
|
| 2059 | - $ticket_row, |
|
| 2060 | - $datetime, |
|
| 2061 | - $ticket, |
|
| 2062 | - $ticket_datetimes, |
|
| 2063 | - $default, |
|
| 2064 | - $this->_is_creating_event |
|
| 2065 | - ); |
|
| 2066 | - return EEH_Template::display_template( |
|
| 2067 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2068 | - $template_args, |
|
| 2069 | - true |
|
| 2070 | - ); |
|
| 2071 | - } |
|
| 2015 | + /** |
|
| 2016 | + * @param int $datetime_row |
|
| 2017 | + * @param int $ticket_row |
|
| 2018 | + * @param EE_Datetime|null $datetime |
|
| 2019 | + * @param EE_Ticket|null $ticket |
|
| 2020 | + * @param array $ticket_datetimes |
|
| 2021 | + * @param bool $default |
|
| 2022 | + * @return mixed |
|
| 2023 | + * @throws DomainException |
|
| 2024 | + * @throws EE_Error |
|
| 2025 | + */ |
|
| 2026 | + protected function _get_ticket_datetime_list_item( |
|
| 2027 | + $datetime_row, |
|
| 2028 | + $ticket_row, |
|
| 2029 | + $datetime, |
|
| 2030 | + $ticket, |
|
| 2031 | + $ticket_datetimes = array(), |
|
| 2032 | + $default |
|
| 2033 | + ) { |
|
| 2034 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2035 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2036 | + : array(); |
|
| 2037 | + $template_args = array( |
|
| 2038 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 2039 | + ? 'DTTNUM' |
|
| 2040 | + : $datetime_row, |
|
| 2041 | + 'tkt_row' => $default |
|
| 2042 | + ? 'TICKETNUM' |
|
| 2043 | + : $ticket_row, |
|
| 2044 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2045 | + ? ' ticket-selected' |
|
| 2046 | + : '', |
|
| 2047 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2048 | + ? ' checked' |
|
| 2049 | + : '', |
|
| 2050 | + 'DTT_name' => $default && empty($datetime) |
|
| 2051 | + ? 'DTTNAME' |
|
| 2052 | + : $datetime->get_dtt_display_name(true), |
|
| 2053 | + 'tkt_status_class' => '', |
|
| 2054 | + ); |
|
| 2055 | + $template_args = apply_filters( |
|
| 2056 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 2057 | + $template_args, |
|
| 2058 | + $datetime_row, |
|
| 2059 | + $ticket_row, |
|
| 2060 | + $datetime, |
|
| 2061 | + $ticket, |
|
| 2062 | + $ticket_datetimes, |
|
| 2063 | + $default, |
|
| 2064 | + $this->_is_creating_event |
|
| 2065 | + ); |
|
| 2066 | + return EEH_Template::display_template( |
|
| 2067 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2068 | + $template_args, |
|
| 2069 | + true |
|
| 2070 | + ); |
|
| 2071 | + } |
|
| 2072 | 2072 | |
| 2073 | 2073 | |
| 2074 | - /** |
|
| 2075 | - * @param array $all_datetimes |
|
| 2076 | - * @param array $all_tickets |
|
| 2077 | - * @return mixed |
|
| 2078 | - * @throws ReflectionException |
|
| 2079 | - * @throws InvalidArgumentException |
|
| 2080 | - * @throws InvalidInterfaceException |
|
| 2081 | - * @throws InvalidDataTypeException |
|
| 2082 | - * @throws DomainException |
|
| 2083 | - * @throws EE_Error |
|
| 2084 | - */ |
|
| 2085 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2086 | - { |
|
| 2087 | - $template_args = array( |
|
| 2088 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2089 | - 'DTTNUM', |
|
| 2090 | - null, |
|
| 2091 | - true, |
|
| 2092 | - $all_datetimes |
|
| 2093 | - ), |
|
| 2094 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2095 | - 'TICKETNUM', |
|
| 2096 | - null, |
|
| 2097 | - array(), |
|
| 2098 | - array(), |
|
| 2099 | - true |
|
| 2100 | - ), |
|
| 2101 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2102 | - 'TICKETNUM', |
|
| 2103 | - 'PRICENUM', |
|
| 2104 | - null, |
|
| 2105 | - true, |
|
| 2106 | - null |
|
| 2107 | - ), |
|
| 2108 | - 'default_price_rows' => '', |
|
| 2109 | - 'default_base_price_amount' => 0, |
|
| 2110 | - 'default_base_price_name' => '', |
|
| 2111 | - 'default_base_price_description' => '', |
|
| 2112 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2113 | - 'TICKETNUM', |
|
| 2114 | - 'PRICENUM', |
|
| 2115 | - null, |
|
| 2116 | - true |
|
| 2117 | - ), |
|
| 2118 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2119 | - 'DTTNUM', |
|
| 2120 | - null, |
|
| 2121 | - array(), |
|
| 2122 | - array(), |
|
| 2123 | - true |
|
| 2124 | - ), |
|
| 2125 | - 'existing_available_datetime_tickets_list' => '', |
|
| 2126 | - 'existing_available_ticket_datetimes_list' => '', |
|
| 2127 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2128 | - 'DTTNUM', |
|
| 2129 | - 'TICKETNUM', |
|
| 2130 | - null, |
|
| 2131 | - null, |
|
| 2132 | - array(), |
|
| 2133 | - true |
|
| 2134 | - ), |
|
| 2135 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2136 | - 'DTTNUM', |
|
| 2137 | - 'TICKETNUM', |
|
| 2138 | - null, |
|
| 2139 | - null, |
|
| 2140 | - array(), |
|
| 2141 | - true |
|
| 2142 | - ), |
|
| 2143 | - ); |
|
| 2144 | - $ticket_row = 1; |
|
| 2145 | - foreach ($all_tickets as $ticket) { |
|
| 2146 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2147 | - 'DTTNUM', |
|
| 2148 | - $ticket_row, |
|
| 2149 | - null, |
|
| 2150 | - $ticket, |
|
| 2151 | - array(), |
|
| 2152 | - true |
|
| 2153 | - ); |
|
| 2154 | - $ticket_row++; |
|
| 2155 | - } |
|
| 2156 | - $datetime_row = 1; |
|
| 2157 | - foreach ($all_datetimes as $datetime) { |
|
| 2158 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2159 | - $datetime_row, |
|
| 2160 | - 'TICKETNUM', |
|
| 2161 | - $datetime, |
|
| 2162 | - null, |
|
| 2163 | - array(), |
|
| 2164 | - true |
|
| 2165 | - ); |
|
| 2166 | - $datetime_row++; |
|
| 2167 | - } |
|
| 2168 | - /** @var EEM_Price $price_model */ |
|
| 2169 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2170 | - $default_prices = $price_model->get_all_default_prices(); |
|
| 2171 | - $price_row = 1; |
|
| 2172 | - foreach ($default_prices as $price) { |
|
| 2173 | - if (! $price instanceof EE_Price) { |
|
| 2174 | - continue; |
|
| 2175 | - } |
|
| 2176 | - if ($price->is_base_price()) { |
|
| 2177 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2178 | - 'PRC_amount', |
|
| 2179 | - 'localized_float' |
|
| 2180 | - ); |
|
| 2181 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2182 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2183 | - $price_row++; |
|
| 2184 | - continue; |
|
| 2185 | - } |
|
| 2186 | - $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
| 2187 | - || count($default_prices) === 1); |
|
| 2188 | - $show_create = ! (count($default_prices) > 1 |
|
| 2189 | - && count($default_prices) |
|
| 2190 | - !== $price_row); |
|
| 2191 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2192 | - 'TICKETNUM', |
|
| 2193 | - $price_row, |
|
| 2194 | - $price, |
|
| 2195 | - true, |
|
| 2196 | - null, |
|
| 2197 | - $show_trash, |
|
| 2198 | - $show_create |
|
| 2199 | - ); |
|
| 2200 | - $price_row++; |
|
| 2201 | - } |
|
| 2202 | - $template_args = apply_filters( |
|
| 2203 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2204 | - $template_args, |
|
| 2205 | - $all_datetimes, |
|
| 2206 | - $all_tickets, |
|
| 2207 | - $this->_is_creating_event |
|
| 2208 | - ); |
|
| 2209 | - return EEH_Template::display_template( |
|
| 2210 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2211 | - $template_args, |
|
| 2212 | - true |
|
| 2213 | - ); |
|
| 2214 | - } |
|
| 2074 | + /** |
|
| 2075 | + * @param array $all_datetimes |
|
| 2076 | + * @param array $all_tickets |
|
| 2077 | + * @return mixed |
|
| 2078 | + * @throws ReflectionException |
|
| 2079 | + * @throws InvalidArgumentException |
|
| 2080 | + * @throws InvalidInterfaceException |
|
| 2081 | + * @throws InvalidDataTypeException |
|
| 2082 | + * @throws DomainException |
|
| 2083 | + * @throws EE_Error |
|
| 2084 | + */ |
|
| 2085 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2086 | + { |
|
| 2087 | + $template_args = array( |
|
| 2088 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2089 | + 'DTTNUM', |
|
| 2090 | + null, |
|
| 2091 | + true, |
|
| 2092 | + $all_datetimes |
|
| 2093 | + ), |
|
| 2094 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2095 | + 'TICKETNUM', |
|
| 2096 | + null, |
|
| 2097 | + array(), |
|
| 2098 | + array(), |
|
| 2099 | + true |
|
| 2100 | + ), |
|
| 2101 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2102 | + 'TICKETNUM', |
|
| 2103 | + 'PRICENUM', |
|
| 2104 | + null, |
|
| 2105 | + true, |
|
| 2106 | + null |
|
| 2107 | + ), |
|
| 2108 | + 'default_price_rows' => '', |
|
| 2109 | + 'default_base_price_amount' => 0, |
|
| 2110 | + 'default_base_price_name' => '', |
|
| 2111 | + 'default_base_price_description' => '', |
|
| 2112 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2113 | + 'TICKETNUM', |
|
| 2114 | + 'PRICENUM', |
|
| 2115 | + null, |
|
| 2116 | + true |
|
| 2117 | + ), |
|
| 2118 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2119 | + 'DTTNUM', |
|
| 2120 | + null, |
|
| 2121 | + array(), |
|
| 2122 | + array(), |
|
| 2123 | + true |
|
| 2124 | + ), |
|
| 2125 | + 'existing_available_datetime_tickets_list' => '', |
|
| 2126 | + 'existing_available_ticket_datetimes_list' => '', |
|
| 2127 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2128 | + 'DTTNUM', |
|
| 2129 | + 'TICKETNUM', |
|
| 2130 | + null, |
|
| 2131 | + null, |
|
| 2132 | + array(), |
|
| 2133 | + true |
|
| 2134 | + ), |
|
| 2135 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2136 | + 'DTTNUM', |
|
| 2137 | + 'TICKETNUM', |
|
| 2138 | + null, |
|
| 2139 | + null, |
|
| 2140 | + array(), |
|
| 2141 | + true |
|
| 2142 | + ), |
|
| 2143 | + ); |
|
| 2144 | + $ticket_row = 1; |
|
| 2145 | + foreach ($all_tickets as $ticket) { |
|
| 2146 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2147 | + 'DTTNUM', |
|
| 2148 | + $ticket_row, |
|
| 2149 | + null, |
|
| 2150 | + $ticket, |
|
| 2151 | + array(), |
|
| 2152 | + true |
|
| 2153 | + ); |
|
| 2154 | + $ticket_row++; |
|
| 2155 | + } |
|
| 2156 | + $datetime_row = 1; |
|
| 2157 | + foreach ($all_datetimes as $datetime) { |
|
| 2158 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2159 | + $datetime_row, |
|
| 2160 | + 'TICKETNUM', |
|
| 2161 | + $datetime, |
|
| 2162 | + null, |
|
| 2163 | + array(), |
|
| 2164 | + true |
|
| 2165 | + ); |
|
| 2166 | + $datetime_row++; |
|
| 2167 | + } |
|
| 2168 | + /** @var EEM_Price $price_model */ |
|
| 2169 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2170 | + $default_prices = $price_model->get_all_default_prices(); |
|
| 2171 | + $price_row = 1; |
|
| 2172 | + foreach ($default_prices as $price) { |
|
| 2173 | + if (! $price instanceof EE_Price) { |
|
| 2174 | + continue; |
|
| 2175 | + } |
|
| 2176 | + if ($price->is_base_price()) { |
|
| 2177 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2178 | + 'PRC_amount', |
|
| 2179 | + 'localized_float' |
|
| 2180 | + ); |
|
| 2181 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2182 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2183 | + $price_row++; |
|
| 2184 | + continue; |
|
| 2185 | + } |
|
| 2186 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
| 2187 | + || count($default_prices) === 1); |
|
| 2188 | + $show_create = ! (count($default_prices) > 1 |
|
| 2189 | + && count($default_prices) |
|
| 2190 | + !== $price_row); |
|
| 2191 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2192 | + 'TICKETNUM', |
|
| 2193 | + $price_row, |
|
| 2194 | + $price, |
|
| 2195 | + true, |
|
| 2196 | + null, |
|
| 2197 | + $show_trash, |
|
| 2198 | + $show_create |
|
| 2199 | + ); |
|
| 2200 | + $price_row++; |
|
| 2201 | + } |
|
| 2202 | + $template_args = apply_filters( |
|
| 2203 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2204 | + $template_args, |
|
| 2205 | + $all_datetimes, |
|
| 2206 | + $all_tickets, |
|
| 2207 | + $this->_is_creating_event |
|
| 2208 | + ); |
|
| 2209 | + return EEH_Template::display_template( |
|
| 2210 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2211 | + $template_args, |
|
| 2212 | + true |
|
| 2213 | + ); |
|
| 2214 | + } |
|
| 2215 | 2215 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | ); |
| 151 | 151 | $msg .= '</p><ul>'; |
| 152 | 152 | foreach ($format_validation as $error) { |
| 153 | - $msg .= '<li>' . $error . '</li>'; |
|
| 153 | + $msg .= '<li>'.$error.'</li>'; |
|
| 154 | 154 | } |
| 155 | 155 | $msg .= '</ul><p>'; |
| 156 | 156 | $msg .= sprintf( |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | $this->_scripts_styles = array( |
| 180 | 180 | 'registers' => array( |
| 181 | 181 | 'ee-tickets-datetimes-css' => array( |
| 182 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 182 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
| 183 | 183 | 'type' => 'css', |
| 184 | 184 | ), |
| 185 | 185 | 'ee-dtt-ticket-metabox' => array( |
| 186 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 186 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
| 187 | 187 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
| 188 | 188 | ), |
| 189 | 189 | ), |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | 'event_espresso' |
| 208 | 208 | ), |
| 209 | 209 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
| 210 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 210 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
| 211 | 211 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
| 212 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 212 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
| 213 | 213 | 'single_warning_from_tkt' => esc_html__( |
| 214 | 214 | 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
| 215 | 215 | 'event_espresso' |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | 'event_espresso' |
| 220 | 220 | ), |
| 221 | 221 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
| 222 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 222 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
| 223 | 223 | ), |
| 224 | 224 | 'DTT_ERROR_MSG' => array( |
| 225 | 225 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | { |
| 258 | 258 | foreach ($update_callbacks as $key => $callback) { |
| 259 | 259 | if ($callback[1] === '_default_tickets_update') { |
| 260 | - unset($update_callbacks[ $key ]); |
|
| 260 | + unset($update_callbacks[$key]); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
| 316 | 316 | // trim all values to ensure any excess whitespace is removed. |
| 317 | 317 | $datetime_data = array_map( |
| 318 | - function ($datetime_data) { |
|
| 318 | + function($datetime_data) { |
|
| 319 | 319 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
| 320 | 320 | }, |
| 321 | 321 | $datetime_data |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | ); |
| 346 | 346 | // if we have an id then let's get existing object first and then set the new values. |
| 347 | 347 | // Otherwise we instantiate a new object for save. |
| 348 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 348 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
| 349 | 349 | $datetime = EE_Registry::instance() |
| 350 | 350 | ->load_model('Datetime', array($timezone)) |
| 351 | 351 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | // after the add_relation_to() the autosave replaces it. |
| 360 | 360 | // We need to do this so we dont' TRASH the parent DTT. |
| 361 | 361 | // (save the ID for both key and value to avoid duplications) |
| 362 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 362 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
| 363 | 363 | } else { |
| 364 | 364 | $datetime = EE_Registry::instance()->load_class( |
| 365 | 365 | 'Datetime', |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | // because it is possible there was a new one created for the autosave. |
| 396 | 396 | // (save the ID for both key and value to avoid duplications) |
| 397 | 397 | $DTT_ID = $datetime->ID(); |
| 398 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 399 | - $saved_dtt_objs[ $row ] = $datetime; |
|
| 398 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
| 399 | + $saved_dtt_objs[$row] = $datetime; |
|
| 400 | 400 | // @todo if ANY of these updates fail then we want the appropriate global error message. |
| 401 | 401 | } |
| 402 | 402 | $event->save(); |
@@ -460,13 +460,13 @@ discard block |
||
| 460 | 460 | $update_prices = $create_new_TKT = false; |
| 461 | 461 | // figure out what datetimes were added to the ticket |
| 462 | 462 | // and what datetimes were removed from the ticket in the session. |
| 463 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 464 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 463 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 464 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 465 | 465 | $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
| 466 | 466 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
| 467 | 467 | // trim inputs to ensure any excess whitespace is removed. |
| 468 | 468 | $tkt = array_map( |
| 469 | - function ($ticket_data) { |
|
| 469 | + function($ticket_data) { |
|
| 470 | 470 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
| 471 | 471 | }, |
| 472 | 472 | $tkt |
@@ -486,8 +486,8 @@ discard block |
||
| 486 | 486 | ? $base_price |
| 487 | 487 | : $ticket_price; |
| 488 | 488 | $base_price_id = $tkt['TKT_base_price_ID'] ?? 0; |
| 489 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 490 | - ? $data['edit_prices'][ $row ] |
|
| 489 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
| 490 | + ? $data['edit_prices'][$row] |
|
| 491 | 491 | : array(); |
| 492 | 492 | $now = null; |
| 493 | 493 | if (empty($tkt['TKT_start_date'])) { |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | /** |
| 500 | 500 | * set the TKT_end_date to the first datetime attached to the ticket. |
| 501 | 501 | */ |
| 502 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 502 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
| 503 | 503 | $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
| 504 | 504 | } |
| 505 | 505 | $TKT_values = array( |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | // need to make sue that the TKT_price is accurate after saving the prices. |
| 635 | 635 | $ticket->ensure_TKT_Price_correct(); |
| 636 | 636 | // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
| 637 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 637 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 638 | 638 | $update_prices = true; |
| 639 | 639 | $new_default = clone $ticket; |
| 640 | 640 | $new_default->set('TKT_ID', 0); |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | // save new TKT |
| 680 | 680 | $new_tkt->save(); |
| 681 | 681 | // add new ticket to array |
| 682 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 682 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 683 | 683 | do_action( |
| 684 | 684 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
| 685 | 685 | $new_tkt, |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | ); |
| 690 | 690 | } else { |
| 691 | 691 | // add tkt to saved tkts |
| 692 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 692 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
| 693 | 693 | do_action( |
| 694 | 694 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
| 695 | 695 | $ticket, |
@@ -756,31 +756,31 @@ discard block |
||
| 756 | 756 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
| 757 | 757 | // and removing the ticket from datetimes it got removed from. |
| 758 | 758 | // first let's add datetimes |
| 759 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 759 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 760 | 760 | foreach ($added_datetimes as $row_id) { |
| 761 | 761 | $row_id = (int) $row_id; |
| 762 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 763 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 762 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 763 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 764 | 764 | // Is this an existing ticket (has an ID) and does it have any sold? |
| 765 | 765 | // If so, then we need to add that to the DTT sold because this DTT is getting added. |
| 766 | 766 | if ($ticket->ID() && $ticket->sold() > 0) { |
| 767 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 767 | + $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false); |
|
| 768 | 768 | } |
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | 771 | } |
| 772 | 772 | // then remove datetimes |
| 773 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 773 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 774 | 774 | foreach ($removed_datetimes as $row_id) { |
| 775 | 775 | $row_id = (int) $row_id; |
| 776 | 776 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
| 777 | 777 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
| 778 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 779 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 778 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 779 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 780 | 780 | // Is this an existing ticket (has an ID) and does it have any sold? |
| 781 | 781 | // If so, then we need to remove it's sold from the DTT_sold. |
| 782 | 782 | if ($ticket->ID() && $ticket->sold() > 0) { |
| 783 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 783 | + $saved_datetimes[$row_id]->decreaseSold($ticket->sold()); |
|
| 784 | 784 | } |
| 785 | 785 | } |
| 786 | 786 | } |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | ); |
| 894 | 894 | } |
| 895 | 895 | // possibly need to save tkt |
| 896 | - if (! $ticket->ID()) { |
|
| 896 | + if ( ! $ticket->ID()) { |
|
| 897 | 897 | $ticket->save(); |
| 898 | 898 | } |
| 899 | 899 | foreach ($prices as $row => $prc) { |
@@ -927,17 +927,17 @@ discard block |
||
| 927 | 927 | } |
| 928 | 928 | } |
| 929 | 929 | $price->save(); |
| 930 | - $updated_prices[ $price->ID() ] = $price; |
|
| 930 | + $updated_prices[$price->ID()] = $price; |
|
| 931 | 931 | $ticket->_add_relation_to($price, 'Price'); |
| 932 | 932 | } |
| 933 | 933 | // now let's remove any prices that got removed from the ticket |
| 934 | - if (! empty($current_prices_on_ticket)) { |
|
| 934 | + if ( ! empty($current_prices_on_ticket)) { |
|
| 935 | 935 | $current = array_keys($current_prices_on_ticket); |
| 936 | 936 | $updated = array_keys($updated_prices); |
| 937 | 937 | $prices_to_remove = array_diff($current, $updated); |
| 938 | - if (! empty($prices_to_remove)) { |
|
| 938 | + if ( ! empty($prices_to_remove)) { |
|
| 939 | 939 | foreach ($prices_to_remove as $prc_id) { |
| 940 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 940 | + $p = $current_prices_on_ticket[$prc_id]; |
|
| 941 | 941 | $ticket->_remove_relation_to($p, 'Price'); |
| 942 | 942 | // delete permanently the price |
| 943 | 943 | $p->delete_permanently(); |
@@ -1088,18 +1088,18 @@ discard block |
||
| 1088 | 1088 | $TKT_ID = $ticket->get('TKT_ID'); |
| 1089 | 1089 | $ticket_row = $ticket->get('TKT_row'); |
| 1090 | 1090 | // we only want unique tickets in our final display!! |
| 1091 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1091 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1092 | 1092 | $existing_ticket_ids[] = $TKT_ID; |
| 1093 | 1093 | $all_tickets[] = $ticket; |
| 1094 | 1094 | } |
| 1095 | 1095 | // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
| 1096 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1096 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
| 1097 | 1097 | // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
| 1098 | 1098 | if ( |
| 1099 | - ! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1100 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1099 | + ! isset($ticket_datetimes[$TKT_ID]) |
|
| 1100 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
| 1101 | 1101 | ) { |
| 1102 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1102 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
| 1103 | 1103 | } |
| 1104 | 1104 | } |
| 1105 | 1105 | $datetime_row++; |
@@ -1110,7 +1110,7 @@ discard block |
||
| 1110 | 1110 | // sort $all_tickets by order |
| 1111 | 1111 | usort( |
| 1112 | 1112 | $all_tickets, |
| 1113 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1113 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
| 1114 | 1114 | $a_order = (int) $a->get('TKT_order'); |
| 1115 | 1115 | $b_order = (int) $b->get('TKT_order'); |
| 1116 | 1116 | if ($a_order === $b_order) { |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | } |
| 1149 | 1149 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
| 1150 | 1150 | EEH_Template::display_template( |
| 1151 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1151 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
| 1152 | 1152 | $main_template_args |
| 1153 | 1153 | ); |
| 1154 | 1154 | } |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
| 1191 | 1191 | ); |
| 1192 | 1192 | return EEH_Template::display_template( |
| 1193 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1193 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
| 1194 | 1194 | $dtt_display_template_args, |
| 1195 | 1195 | true |
| 1196 | 1196 | ); |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | $this->_is_creating_event |
| 1260 | 1260 | ); |
| 1261 | 1261 | return EEH_Template::display_template( |
| 1262 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1262 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
| 1263 | 1263 | $template_args, |
| 1264 | 1264 | true |
| 1265 | 1265 | ); |
@@ -1300,7 +1300,7 @@ discard block |
||
| 1300 | 1300 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
| 1301 | 1301 | ); |
| 1302 | 1302 | // need to setup the list items (but only if this isn't a default skeleton setup) |
| 1303 | - if (! $default) { |
|
| 1303 | + if ( ! $default) { |
|
| 1304 | 1304 | $ticket_row = 1; |
| 1305 | 1305 | foreach ($all_tickets as $ticket) { |
| 1306 | 1306 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1326,7 +1326,7 @@ discard block |
||
| 1326 | 1326 | $this->_is_creating_event |
| 1327 | 1327 | ); |
| 1328 | 1328 | return EEH_Template::display_template( |
| 1329 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1329 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1330 | 1330 | $template_args, |
| 1331 | 1331 | true |
| 1332 | 1332 | ); |
@@ -1352,8 +1352,8 @@ discard block |
||
| 1352 | 1352 | $datetime_tickets = array(), |
| 1353 | 1353 | $default |
| 1354 | 1354 | ) { |
| 1355 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1356 | - ? $datetime_tickets[ $datetime->ID() ] |
|
| 1355 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
| 1356 | + ? $datetime_tickets[$datetime->ID()] |
|
| 1357 | 1357 | : array(); |
| 1358 | 1358 | $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
| 1359 | 1359 | $no_ticket = $default && empty($ticket); |
@@ -1374,8 +1374,8 @@ discard block |
||
| 1374 | 1374 | ? 'TKTNAME' |
| 1375 | 1375 | : $ticket->get('TKT_name'), |
| 1376 | 1376 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
| 1377 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1378 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1377 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1378 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
| 1379 | 1379 | ); |
| 1380 | 1380 | // filter template args |
| 1381 | 1381 | $template_args = apply_filters( |
@@ -1390,7 +1390,7 @@ discard block |
||
| 1390 | 1390 | $this->_is_creating_event |
| 1391 | 1391 | ); |
| 1392 | 1392 | return EEH_Template::display_template( |
| 1393 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1393 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1394 | 1394 | $template_args, |
| 1395 | 1395 | true |
| 1396 | 1396 | ); |
@@ -1446,19 +1446,19 @@ discard block |
||
| 1446 | 1446 | // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
| 1447 | 1447 | // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
| 1448 | 1448 | $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
| 1449 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1450 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1449 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 1450 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 1451 | 1451 | : array(); |
| 1452 | 1452 | $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
| 1453 | 1453 | $base_price = $default ? null : $ticket->base_price(); |
| 1454 | 1454 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
| 1455 | 1455 | // breaking out complicated condition for ticket_status |
| 1456 | 1456 | if ($default) { |
| 1457 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1457 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1458 | 1458 | } else { |
| 1459 | 1459 | $ticket_status_class = $ticket->is_default() |
| 1460 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1461 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1460 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1461 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
| 1462 | 1462 | } |
| 1463 | 1463 | // breaking out complicated condition for TKT_taxable |
| 1464 | 1464 | if ($default) { |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | : 'display:none;', |
| 1551 | 1551 | 'show_price_mod_button' => count($prices) > 1 |
| 1552 | 1552 | || ($default && $count_price_mods > 0) |
| 1553 | - || (! $default && $ticket->deleted()) |
|
| 1553 | + || ( ! $default && $ticket->deleted()) |
|
| 1554 | 1554 | ? 'display:none;' |
| 1555 | 1555 | : '', |
| 1556 | 1556 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1594,7 +1594,7 @@ discard block |
||
| 1594 | 1594 | $this->_date_time_format, |
| 1595 | 1595 | current_time('timestamp') |
| 1596 | 1596 | ); |
| 1597 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1597 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1598 | 1598 | } |
| 1599 | 1599 | if (empty($template_args['TKT_end_date'])) { |
| 1600 | 1600 | // get the earliest datetime (if present); |
@@ -1604,7 +1604,7 @@ discard block |
||
| 1604 | 1604 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
| 1605 | 1605 | ) |
| 1606 | 1606 | : null; |
| 1607 | - if (! empty($earliest_dtt)) { |
|
| 1607 | + if ( ! empty($earliest_dtt)) { |
|
| 1608 | 1608 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
| 1609 | 1609 | 'DTT_EVT_start', |
| 1610 | 1610 | $this->_date_time_format |
@@ -1623,10 +1623,10 @@ discard block |
||
| 1623 | 1623 | ) |
| 1624 | 1624 | ); |
| 1625 | 1625 | } |
| 1626 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1626 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1627 | 1627 | } |
| 1628 | 1628 | // generate ticket_datetime items |
| 1629 | - if (! $default) { |
|
| 1629 | + if ( ! $default) { |
|
| 1630 | 1630 | $datetime_row = 1; |
| 1631 | 1631 | foreach ($all_datetimes as $datetime) { |
| 1632 | 1632 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1642,7 +1642,7 @@ discard block |
||
| 1642 | 1642 | } |
| 1643 | 1643 | $price_row = 1; |
| 1644 | 1644 | foreach ($prices as $price) { |
| 1645 | - if (! $price instanceof EE_Price) { |
|
| 1645 | + if ( ! $price instanceof EE_Price) { |
|
| 1646 | 1646 | continue; |
| 1647 | 1647 | } |
| 1648 | 1648 | if ($price->is_base_price()) { |
@@ -1675,7 +1675,7 @@ discard block |
||
| 1675 | 1675 | $this->_is_creating_event |
| 1676 | 1676 | ); |
| 1677 | 1677 | return EEH_Template::display_template( |
| 1678 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1678 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
| 1679 | 1679 | $template_args, |
| 1680 | 1680 | true |
| 1681 | 1681 | ); |
@@ -1715,7 +1715,7 @@ discard block |
||
| 1715 | 1715 | $this->_is_creating_event |
| 1716 | 1716 | ); |
| 1717 | 1717 | $tax_rows .= EEH_Template::display_template( |
| 1718 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1718 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1719 | 1719 | $template_args, |
| 1720 | 1720 | true |
| 1721 | 1721 | ); |
@@ -1834,7 +1834,7 @@ discard block |
||
| 1834 | 1834 | $this->_is_creating_event |
| 1835 | 1835 | ); |
| 1836 | 1836 | return EEH_Template::display_template( |
| 1837 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1837 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1838 | 1838 | $template_args, |
| 1839 | 1839 | true |
| 1840 | 1840 | ); |
@@ -1904,7 +1904,7 @@ discard block |
||
| 1904 | 1904 | $this->_is_creating_event |
| 1905 | 1905 | ); |
| 1906 | 1906 | return EEH_Template::display_template( |
| 1907 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1907 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
| 1908 | 1908 | $template_args, |
| 1909 | 1909 | true |
| 1910 | 1910 | ); |
@@ -1934,7 +1934,7 @@ discard block |
||
| 1934 | 1934 | ) { |
| 1935 | 1935 | $select_name = $default && ! $price instanceof EE_Price |
| 1936 | 1936 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
| 1937 | - : 'edit_prices[' . esc_attr($ticket_row) . '][' . esc_attr($price_row) . '][PRT_ID]'; |
|
| 1937 | + : 'edit_prices['.esc_attr($ticket_row).']['.esc_attr($price_row).'][PRT_ID]'; |
|
| 1938 | 1938 | /** @var EEM_Price_Type $price_type_model */ |
| 1939 | 1939 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
| 1940 | 1940 | $price_types = $price_type_model->get_all(array( |
@@ -1952,10 +1952,10 @@ discard block |
||
| 1952 | 1952 | $price_option_spans = ''; |
| 1953 | 1953 | // setup price types for selector |
| 1954 | 1954 | foreach ($price_types as $price_type) { |
| 1955 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1955 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
| 1956 | 1956 | continue; |
| 1957 | 1957 | } |
| 1958 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
| 1958 | + $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
| 1959 | 1959 | // while we're in the loop let's setup the option spans used by js |
| 1960 | 1960 | $span_args = array( |
| 1961 | 1961 | 'PRT_ID' => $price_type->ID(), |
@@ -1963,12 +1963,12 @@ discard block |
||
| 1963 | 1963 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
| 1964 | 1964 | ); |
| 1965 | 1965 | $price_option_spans .= EEH_Template::display_template( |
| 1966 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1966 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | 1967 | $span_args, |
| 1968 | 1968 | true |
| 1969 | 1969 | ); |
| 1970 | 1970 | } |
| 1971 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1971 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' |
|
| 1972 | 1972 | : $select_name; |
| 1973 | 1973 | $select_input = new EE_Select_Input( |
| 1974 | 1974 | $all_price_types, |
@@ -2005,7 +2005,7 @@ discard block |
||
| 2005 | 2005 | $this->_is_creating_event |
| 2006 | 2006 | ); |
| 2007 | 2007 | return EEH_Template::display_template( |
| 2008 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2008 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2009 | 2009 | $template_args, |
| 2010 | 2010 | true |
| 2011 | 2011 | ); |
@@ -2031,8 +2031,8 @@ discard block |
||
| 2031 | 2031 | $ticket_datetimes = array(), |
| 2032 | 2032 | $default |
| 2033 | 2033 | ) { |
| 2034 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2035 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2034 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 2035 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 2036 | 2036 | : array(); |
| 2037 | 2037 | $template_args = array( |
| 2038 | 2038 | 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
@@ -2064,7 +2064,7 @@ discard block |
||
| 2064 | 2064 | $this->_is_creating_event |
| 2065 | 2065 | ); |
| 2066 | 2066 | return EEH_Template::display_template( |
| 2067 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2067 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2068 | 2068 | $template_args, |
| 2069 | 2069 | true |
| 2070 | 2070 | ); |
@@ -2170,7 +2170,7 @@ discard block |
||
| 2170 | 2170 | $default_prices = $price_model->get_all_default_prices(); |
| 2171 | 2171 | $price_row = 1; |
| 2172 | 2172 | foreach ($default_prices as $price) { |
| 2173 | - if (! $price instanceof EE_Price) { |
|
| 2173 | + if ( ! $price instanceof EE_Price) { |
|
| 2174 | 2174 | continue; |
| 2175 | 2175 | } |
| 2176 | 2176 | if ($price->is_base_price()) { |
@@ -2207,7 +2207,7 @@ discard block |
||
| 2207 | 2207 | $this->_is_creating_event |
| 2208 | 2208 | ); |
| 2209 | 2209 | return EEH_Template::display_template( |
| 2210 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2210 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2211 | 2211 | $template_args, |
| 2212 | 2212 | true |
| 2213 | 2213 | ); |