Completed
Pull Request — FET/editor-dates-tickets-refac... (#1368)
by
unknown
21:01 queued 11:35
created
admin_pages/events/Events_Admin_Page.core.php 2 patches
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -548,11 +548,11 @@  discard block
 block discarded – undo
548 548
     {
549 549
         wp_register_style(
550 550
             'events-admin-css',
551
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
551
+            EVENTS_ASSETS_URL.'events-admin-page.css',
552 552
             array(),
553 553
             EVENT_ESPRESSO_VERSION
554 554
         );
555
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
555
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
556 556
         wp_enqueue_style('events-admin-css');
557 557
         wp_enqueue_style('ee-cat-admin');
558 558
         // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
         // scripts
561 561
         wp_register_script(
562 562
             'event_editor_js',
563
-            EVENTS_ASSETS_URL . 'event_editor.js',
563
+            EVENTS_ASSETS_URL.'event_editor.js',
564 564
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
565 565
             EVENT_ESPRESSO_VERSION,
566 566
             true
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
         wp_enqueue_style('espresso-ui-theme');
587 587
         wp_register_style(
588 588
             'event-editor-css',
589
-            EVENTS_ASSETS_URL . 'event-editor.css',
589
+            EVENTS_ASSETS_URL.'event-editor.css',
590 590
             array('ee-admin-css'),
591 591
             EVENT_ESPRESSO_VERSION
592 592
         );
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
         // scripts
595 595
         wp_register_script(
596 596
             'event-datetime-metabox',
597
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
597
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
598 598
             array('event_editor_js', 'ee-datepicker'),
599 599
             EVENT_ESPRESSO_VERSION
600 600
         );
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
     public function verify_event_edit($event = null, $req_type = '')
664 664
     {
665 665
         // don't need to do this when processing
666
-        if (! empty($req_type)) {
666
+        if ( ! empty($req_type)) {
667 667
             return;
668 668
         }
669 669
         // no event?
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
             $event = $this->_cpt_model_obj;
673 673
         }
674 674
         // STILL no event?
675
-        if (! $event instanceof EE_Event) {
675
+        if ( ! $event instanceof EE_Event) {
676 676
             return;
677 677
         }
678 678
         $orig_status = $event->status();
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
             );
711 711
         }
712 712
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
713
-        if (! $event->tickets_on_sale()) {
713
+        if ( ! $event->tickets_on_sale()) {
714 714
             return;
715 715
         }
716 716
         // made it here so show warning
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
     {
756 756
         $has_timezone_string = get_option('timezone_string');
757 757
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
758
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
758
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
759 759
             EE_Error::add_attention(
760 760
                 sprintf(
761 761
                     __(
@@ -839,31 +839,31 @@  discard block
 block discarded – undo
839 839
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
840 840
         $statuses = array(
841 841
             'sold_out_status'  => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
842
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
843 843
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
844 844
             ),
845 845
             'active_status'    => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
846
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
847 847
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
848 848
             ),
849 849
             'upcoming_status'  => array(
850
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
850
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
851 851
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
852 852
             ),
853 853
             'postponed_status' => array(
854
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
854
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
855 855
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
856 856
             ),
857 857
             'cancelled_status' => array(
858
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
858
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
859 859
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
860 860
             ),
861 861
             'expired_status'   => array(
862
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
862
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
863 863
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
864 864
             ),
865 865
             'inactive_status'  => array(
866
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
866
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
867 867
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
868 868
             ),
869 869
         );
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
      */
878 878
     private function _event_model()
879 879
     {
880
-        if (! $this->_event_model instanceof EEM_Event) {
880
+        if ( ! $this->_event_model instanceof EEM_Event) {
881 881
             $this->_event_model = EE_Registry::instance()->load_model('Event');
882 882
         }
883 883
         return $this->_event_model;
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
898 898
     {
899 899
         // make sure this is only when editing
900
-        if (! empty($id)) {
900
+        if ( ! empty($id)) {
901 901
             $post = get_post($id);
902 902
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
903 903
                        . esc_html__('Shortcode', 'event_espresso')
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
                     'button'
932 932
                 );
933 933
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
934
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
934
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
935 935
             'create_new',
936 936
             'add',
937 937
             array(),
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
      */
1072 1072
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1073 1073
     {
1074
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1074
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1075 1075
         $venue_model = EE_Registry::instance()->load_model('Venue');
1076 1076
         $rows_affected = null;
1077 1077
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
             'status'              => 'publish',
1103 1103
         );
1104 1104
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1105
-        if (! empty($venue_id)) {
1105
+        if ( ! empty($venue_id)) {
1106 1106
             $update_where = array($venue_model->primary_key_name() => $venue_id);
1107 1107
             $rows_affected = $venue_model->update($venue_array, array($update_where));
1108 1108
             // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
                 'DTT_order'     => $row,
1145 1145
             );
1146 1146
             // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1147
-            if (! empty($dtt['DTT_ID'])) {
1147
+            if ( ! empty($dtt['DTT_ID'])) {
1148 1148
                 $DTM = EE_Registry::instance()
1149 1149
                                   ->load_model('Datetime', array($evtobj->get_timezone()))
1150 1150
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1154,7 +1154,7 @@  discard block
 block discarded – undo
1154 1154
                     $DTM->set($field, $value);
1155 1155
                 }
1156 1156
                 // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1157
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1157
+                $saved_dtts[$DTM->ID()] = $DTM;
1158 1158
             } else {
1159 1159
                 $DTM = EE_Registry::instance()->load_class(
1160 1160
                     'Datetime',
@@ -1187,14 +1187,14 @@  discard block
 block discarded – undo
1187 1187
         foreach ($data['edit_tickets'] as $row => $tkt) {
1188 1188
             $incoming_date_formats = array('Y-m-d', 'h:i a');
1189 1189
             $update_prices = false;
1190
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1191
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1190
+            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1191
+                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1192 1192
             // trim inputs to ensure any excess whitespace is removed.
1193 1193
             $tkt = array_map('trim', $tkt);
1194 1194
             if (empty($tkt['TKT_start_date'])) {
1195 1195
                 // let's use now in the set timezone.
1196 1196
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1197
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1197
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1198 1198
             }
1199 1199
             if (empty($tkt['TKT_end_date'])) {
1200 1200
                 // use the start date of the first datetime
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
             // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1230 1230
             // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1231 1231
             // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1232
-            if (! empty($tkt['TKT_ID'])) {
1232
+            if ( ! empty($tkt['TKT_ID'])) {
1233 1233
                 $TKT = EE_Registry::instance()
1234 1234
                                   ->load_model('Ticket', array($evtobj->get_timezone()))
1235 1235
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
                         $TKT->set('TKT_deleted', 1);
1265 1265
                         $TKT->save();
1266 1266
                         // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1267
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1267
+                        $saved_tickets[$TKT->ID()] = $TKT;
1268 1268
                         // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1269 1269
                         $TKT = clone $TKT;
1270 1270
                         $TKT->set('TKT_ID', 0);
@@ -1309,9 +1309,9 @@  discard block
 block discarded – undo
1309 1309
             }
1310 1310
             // initially let's add the ticket to the dtt
1311 1311
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1312
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1312
+            $saved_tickets[$TKT->ID()] = $TKT;
1313 1313
             // add prices to ticket
1314
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1314
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1315 1315
         }
1316 1316
         // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1317 1317
         $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
@@ -1468,7 +1468,7 @@  discard block
 block discarded – undo
1468 1468
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1469 1469
         // load template
1470 1470
         EEH_Template::display_template(
1471
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1471
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1472 1472
             $publish_box_extra_args
1473 1473
         );
1474 1474
     }
@@ -1560,7 +1560,7 @@  discard block
 block discarded – undo
1560 1560
                     'default_where_conditions' => 'none',
1561 1561
                 )
1562 1562
             );
1563
-            if (! empty($related_tickets)) {
1563
+            if ( ! empty($related_tickets)) {
1564 1564
                 $template_args['total_ticket_rows'] = count($related_tickets);
1565 1565
                 $row = 0;
1566 1566
                 foreach ($related_tickets as $ticket) {
@@ -1594,7 +1594,7 @@  discard block
 block discarded – undo
1594 1594
         );
1595 1595
         $template = apply_filters(
1596 1596
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1597
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1597
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1598 1598
         );
1599 1599
         EEH_Template::display_template($template, $template_args);
1600 1600
     }
@@ -1612,7 +1612,7 @@  discard block
 block discarded – undo
1612 1612
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1613 1613
     {
1614 1614
         $template_args = array(
1615
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1615
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1616 1616
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1617 1617
                 : '',
1618 1618
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1624,10 +1624,10 @@  discard block
 block discarded – undo
1624 1624
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1625 1625
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1626 1626
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1627
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1628
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1627
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1628
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1629 1629
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1630
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1630
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1631 1631
                 : ' disabled=disabled',
1632 1632
         );
1633 1633
         $price = $ticket->ID() !== 0
@@ -1654,7 +1654,7 @@  discard block
 block discarded – undo
1654 1654
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1655 1655
                 )
1656 1656
                 : null;
1657
-            if (! empty($earliest_dtt)) {
1657
+            if ( ! empty($earliest_dtt)) {
1658 1658
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1659 1659
             } else {
1660 1660
                 $template_args['TKT_end_date'] = date(
@@ -1666,7 +1666,7 @@  discard block
 block discarded – undo
1666 1666
         $template_args = array_merge($template_args, $price_args);
1667 1667
         $template = apply_filters(
1668 1668
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1669
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1669
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1670 1670
             $ticket
1671 1671
         );
1672 1672
         return EEH_Template::display_template($template, $template_args, true);
@@ -1720,7 +1720,7 @@  discard block
 block discarded – undo
1720 1720
             $default_reg_status_values
1721 1721
         );
1722 1722
         EEH_Template::display_template(
1723
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1723
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1724 1724
             $template_args
1725 1725
         );
1726 1726
     }
@@ -1742,7 +1742,7 @@  discard block
 block discarded – undo
1742 1742
     {
1743 1743
         $EEME = $this->_event_model();
1744 1744
         $offset = ($current_page - 1) * $per_page;
1745
-        $limit = $count ? null : $offset . ',' . $per_page;
1745
+        $limit = $count ? null : $offset.','.$per_page;
1746 1746
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1747 1747
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1748 1748
         if (isset($this->_req_data['month_range'])) {
@@ -1771,7 +1771,7 @@  discard block
 block discarded – undo
1771 1771
         // categories?
1772 1772
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1773 1773
             ? $this->_req_data['EVT_CAT'] : null;
1774
-        if (! empty($category)) {
1774
+        if ( ! empty($category)) {
1775 1775
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1776 1776
             $where['Term_Taxonomy.term_id'] = $category;
1777 1777
         }
@@ -1779,7 +1779,7 @@  discard block
 block discarded – undo
1779 1779
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1780 1780
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1781 1781
             $DateTime = new DateTime(
1782
-                $year_r . '-' . $month_r . '-01 00:00:00',
1782
+                $year_r.'-'.$month_r.'-01 00:00:00',
1783 1783
                 new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1784 1784
             );
1785 1785
             $start = $DateTime->format(implode(' ', $start_formats));
@@ -1805,11 +1805,11 @@  discard block
 block discarded – undo
1805 1805
                             ->format(implode(' ', $start_formats));
1806 1806
             $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1807 1807
         }
1808
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1808
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1809 1809
             $where['EVT_wp_user'] = get_current_user_id();
1810 1810
         } else {
1811
-            if (! isset($where['status'])) {
1812
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1811
+            if ( ! isset($where['status'])) {
1812
+                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1813 1813
                     $where['OR'] = array(
1814 1814
                         'status*restrict_private' => array('!=', 'private'),
1815 1815
                         'AND'                     => array(
@@ -1829,7 +1829,7 @@  discard block
 block discarded – undo
1829 1829
         }
1830 1830
         // search query handling
1831 1831
         if (isset($this->_req_data['s'])) {
1832
-            $search_string = '%' . $this->_req_data['s'] . '%';
1832
+            $search_string = '%'.$this->_req_data['s'].'%';
1833 1833
             $where['OR'] = array(
1834 1834
                 'EVT_name'       => array('LIKE', $search_string),
1835 1835
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1918,7 +1918,7 @@  discard block
 block discarded – undo
1918 1918
             // clean status
1919 1919
             $event_status = sanitize_key($event_status);
1920 1920
             // grab status
1921
-            if (! empty($event_status)) {
1921
+            if ( ! empty($event_status)) {
1922 1922
                 $success = $this->_change_event_status($EVT_ID, $event_status);
1923 1923
             } else {
1924 1924
                 $success = false;
@@ -1955,7 +1955,7 @@  discard block
 block discarded – undo
1955 1955
         // clean status
1956 1956
         $event_status = sanitize_key($event_status);
1957 1957
         // grab status
1958
-        if (! empty($event_status)) {
1958
+        if ( ! empty($event_status)) {
1959 1959
             $success = true;
1960 1960
             // determine the event id and set to array.
1961 1961
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
@@ -2002,7 +2002,7 @@  discard block
 block discarded – undo
2002 2002
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2003 2003
     {
2004 2004
         // grab event id
2005
-        if (! $EVT_ID) {
2005
+        if ( ! $EVT_ID) {
2006 2006
             $msg = esc_html__(
2007 2007
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2008 2008
                 'event_espresso'
@@ -2068,8 +2068,8 @@  discard block
 block discarded – undo
2068 2068
             // get list of events with no prices
2069 2069
             $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2070 2070
             // remove this event from the list of events with no prices
2071
-            if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2072
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2071
+            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2072
+                unset($espresso_no_ticket_prices[$EVT_ID]);
2073 2073
             }
2074 2074
             update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2075 2075
         } else {
@@ -2111,7 +2111,7 @@  discard block
 block discarded – undo
2111 2111
                 $results = $this->_permanently_delete_event($EVT_ID);
2112 2112
                 $success = $results !== false ? $success : false;
2113 2113
                 // remove this event from the list of events with no prices
2114
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2114
+                unset($espresso_no_ticket_prices[$EVT_ID]);
2115 2115
             } else {
2116 2116
                 $success = false;
2117 2117
                 $msg = esc_html__(
@@ -2138,7 +2138,7 @@  discard block
 block discarded – undo
2138 2138
     private function _permanently_delete_event($EVT_ID = 0)
2139 2139
     {
2140 2140
         // grab event id
2141
-        if (! $EVT_ID) {
2141
+        if ( ! $EVT_ID) {
2142 2142
             $msg = esc_html__(
2143 2143
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2144 2144
                 'event_espresso'
@@ -2146,12 +2146,12 @@  discard block
 block discarded – undo
2146 2146
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2147 2147
             return false;
2148 2148
         }
2149
-        if (! $this->_cpt_model_obj instanceof EE_Event
2149
+        if ( ! $this->_cpt_model_obj instanceof EE_Event
2150 2150
             || $this->_cpt_model_obj->ID() !== $EVT_ID
2151 2151
         ) {
2152 2152
             $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2153 2153
         }
2154
-        if (! $this->_cpt_model_obj instanceof EE_Event) {
2154
+        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2155 2155
             return false;
2156 2156
         }
2157 2157
         // need to delete related tickets and prices first.
@@ -2173,7 +2173,7 @@  discard block
 block discarded – undo
2173 2173
         }
2174 2174
         // any attached question groups?
2175 2175
         $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2176
-        if (! empty($question_groups)) {
2176
+        if ( ! empty($question_groups)) {
2177 2177
             foreach ($question_groups as $question_group) {
2178 2178
                 $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2179 2179
             }
@@ -2386,7 +2386,7 @@  discard block
 block discarded – undo
2386 2386
                                                 . esc_html__(
2387 2387
                                                     'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2388 2388
                                                     'event_espresso'
2389
-                                                ) . '</strong>';
2389
+                                                ).'</strong>';
2390 2390
         $this->display_admin_caf_preview_page('template_settings_tab');
2391 2391
     }
2392 2392
 
@@ -2406,12 +2406,12 @@  discard block
 block discarded – undo
2406 2406
         // set default category object
2407 2407
         $this->_set_empty_category_object();
2408 2408
         // only set if we've got an id
2409
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2409
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2410 2410
             return;
2411 2411
         }
2412 2412
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2413 2413
         $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2414
-        if (! empty($term)) {
2414
+        if ( ! empty($term)) {
2415 2415
             $this->_category->category_name = $term->name;
2416 2416
             $this->_category->category_identifier = $term->slug;
2417 2417
             $this->_category->category_desc = $term->description;
@@ -2439,7 +2439,7 @@  discard block
 block discarded – undo
2439 2439
     {
2440 2440
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2441 2441
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2442
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2442
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2443 2443
             'add_category',
2444 2444
             'add_category',
2445 2445
             array(),
@@ -2513,7 +2513,7 @@  discard block
 block discarded – undo
2513 2513
             'disable'                  => '',
2514 2514
             'disabled_message'         => false,
2515 2515
         );
2516
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2516
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2517 2517
         return EEH_Template::display_template($template, $template_args, true);
2518 2518
     }
2519 2519
 
@@ -2598,7 +2598,7 @@  discard block
 block discarded – undo
2598 2598
         $insert_ids = $update
2599 2599
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2600 2600
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2601
-        if (! is_array($insert_ids)) {
2601
+        if ( ! is_array($insert_ids)) {
2602 2602
             $msg = esc_html__(
2603 2603
                 'An error occurred and the category has not been saved to the database.',
2604 2604
                 'event_espresso'
@@ -2629,7 +2629,7 @@  discard block
 block discarded – undo
2629 2629
         $limit = ($current_page - 1) * $per_page;
2630 2630
         $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2631 2631
         if (isset($this->_req_data['s'])) {
2632
-            $sstr = '%' . $this->_req_data['s'] . '%';
2632
+            $sstr = '%'.$this->_req_data['s'].'%';
2633 2633
             $where['OR'] = array(
2634 2634
                 'Term.name'   => array('LIKE', $sstr),
2635 2635
                 'description' => array('LIKE', $sstr),
@@ -2638,7 +2638,7 @@  discard block
 block discarded – undo
2638 2638
         $query_params = array(
2639 2639
             $where,
2640 2640
             'order_by'   => array($orderby => $order),
2641
-            'limit'      => $limit . ',' . $per_page,
2641
+            'limit'      => $limit.','.$per_page,
2642 2642
             'force_join' => array('Term'),
2643 2643
         );
2644 2644
         $categories = $count
Please login to merge, or discard this patch.
Indentation   +2673 added lines, -2673 removed lines patch added patch discarded remove patch
@@ -15,2677 +15,2677 @@
 block discarded – undo
15 15
 class Events_Admin_Page extends EE_Admin_Page_CPT
16 16
 {
17 17
 
18
-    /**
19
-     * This will hold the event object for event_details screen.
20
-     *
21
-     * @access protected
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * Initialize page props for this admin page group.
51
-     */
52
-    protected function _init_page_props()
53
-    {
54
-        $this->page_slug = EVENTS_PG_SLUG;
55
-        $this->page_label = EVENTS_LABEL;
56
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
57
-        $this->_admin_base_path = EVENTS_ADMIN;
58
-        $this->_cpt_model_names = array(
59
-            'create_new' => 'EEM_Event',
60
-            'edit'       => 'EEM_Event',
61
-        );
62
-        $this->_cpt_edit_routes = array(
63
-            'espresso_events' => 'edit',
64
-        );
65
-        add_action(
66
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
-            array($this, 'verify_event_edit'),
68
-            10,
69
-            2
70
-        );
71
-    }
72
-
73
-
74
-    /**
75
-     * Sets the ajax hooks used for this admin page group.
76
-     */
77
-    protected function _ajax_hooks()
78
-    {
79
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets the page properties for this admin page group.
85
-     */
86
-    protected function _define_page_props()
87
-    {
88
-        $this->_admin_page_title = EVENTS_LABEL;
89
-        $this->_labels = array(
90
-            'buttons'      => array(
91
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
92
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
93
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
94
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
95
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
96
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
97
-            ),
98
-            'editor_title' => array(
99
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
100
-            ),
101
-            'publishbox'   => array(
102
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
103
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
104
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
105
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
106
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
107
-            ),
108
-        );
109
-    }
110
-
111
-
112
-    /**
113
-     * Sets the page routes property for this admin page group.
114
-     */
115
-    protected function _set_page_routes()
116
-    {
117
-        // load formatter helper
118
-        // load field generator helper
119
-        // is there a evt_id in the request?
120
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
121
-            ? $this->_req_data['EVT_ID']
122
-            : 0;
123
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
124
-        $this->_page_routes = array(
125
-            'default'                       => array(
126
-                'func'       => '_events_overview_list_table',
127
-                'capability' => 'ee_read_events',
128
-            ),
129
-            'create_new'                    => array(
130
-                'func'       => '_create_new_cpt_item',
131
-                'capability' => 'ee_edit_events',
132
-            ),
133
-            'edit'                          => array(
134
-                'func'       => '_edit_cpt_item',
135
-                'capability' => 'ee_edit_event',
136
-                'obj_id'     => $evt_id,
137
-            ),
138
-            'copy_event'                    => array(
139
-                'func'       => '_copy_events',
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $evt_id,
142
-                'noheader'   => true,
143
-            ),
144
-            'trash_event'                   => array(
145
-                'func'       => '_trash_or_restore_event',
146
-                'args'       => array('event_status' => 'trash'),
147
-                'capability' => 'ee_delete_event',
148
-                'obj_id'     => $evt_id,
149
-                'noheader'   => true,
150
-            ),
151
-            'trash_events'                  => array(
152
-                'func'       => '_trash_or_restore_events',
153
-                'args'       => array('event_status' => 'trash'),
154
-                'capability' => 'ee_delete_events',
155
-                'noheader'   => true,
156
-            ),
157
-            'restore_event'                 => array(
158
-                'func'       => '_trash_or_restore_event',
159
-                'args'       => array('event_status' => 'draft'),
160
-                'capability' => 'ee_delete_event',
161
-                'obj_id'     => $evt_id,
162
-                'noheader'   => true,
163
-            ),
164
-            'restore_events'                => array(
165
-                'func'       => '_trash_or_restore_events',
166
-                'args'       => array('event_status' => 'draft'),
167
-                'capability' => 'ee_delete_events',
168
-                'noheader'   => true,
169
-            ),
170
-            'delete_event'                  => array(
171
-                'func'       => '_delete_event',
172
-                'capability' => 'ee_delete_event',
173
-                'obj_id'     => $evt_id,
174
-                'noheader'   => true,
175
-            ),
176
-            'delete_events'                 => array(
177
-                'func'       => '_delete_events',
178
-                'capability' => 'ee_delete_events',
179
-                'noheader'   => true,
180
-            ),
181
-            'view_report'                   => array(
182
-                'func'      => '_view_report',
183
-                'capablity' => 'ee_edit_events',
184
-            ),
185
-            'default_event_settings'        => array(
186
-                'func'       => '_default_event_settings',
187
-                'capability' => 'manage_options',
188
-            ),
189
-            'update_default_event_settings' => array(
190
-                'func'       => '_update_default_event_settings',
191
-                'capability' => 'manage_options',
192
-                'noheader'   => true,
193
-            ),
194
-            'template_settings'             => array(
195
-                'func'       => '_template_settings',
196
-                'capability' => 'manage_options',
197
-            ),
198
-            // event category tab related
199
-            'add_category'                  => array(
200
-                'func'       => '_category_details',
201
-                'capability' => 'ee_edit_event_category',
202
-                'args'       => array('add'),
203
-            ),
204
-            'edit_category'                 => array(
205
-                'func'       => '_category_details',
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => array('edit'),
208
-            ),
209
-            'delete_categories'             => array(
210
-                'func'       => '_delete_categories',
211
-                'capability' => 'ee_delete_event_category',
212
-                'noheader'   => true,
213
-            ),
214
-            'delete_category'               => array(
215
-                'func'       => '_delete_categories',
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ),
219
-            'insert_category'               => array(
220
-                'func'       => '_insert_or_update_category',
221
-                'args'       => array('new_category' => true),
222
-                'capability' => 'ee_edit_event_category',
223
-                'noheader'   => true,
224
-            ),
225
-            'update_category'               => array(
226
-                'func'       => '_insert_or_update_category',
227
-                'args'       => array('new_category' => false),
228
-                'capability' => 'ee_edit_event_category',
229
-                'noheader'   => true,
230
-            ),
231
-            'category_list'                 => array(
232
-                'func'       => '_category_list_table',
233
-                'capability' => 'ee_manage_event_categories',
234
-            ),
235
-        );
236
-    }
237
-
238
-
239
-    /**
240
-     * Set the _page_config property for this admin page group.
241
-     */
242
-    protected function _set_page_config()
243
-    {
244
-        $this->_page_config = array(
245
-            'default'                => array(
246
-                'nav'           => array(
247
-                    'label' => esc_html__('Overview', 'event_espresso'),
248
-                    'order' => 10,
249
-                ),
250
-                'list_table'    => 'Events_Admin_List_Table',
251
-                'help_tabs'     => array(
252
-                    'events_overview_help_tab'                       => array(
253
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
254
-                        'filename' => 'events_overview',
255
-                    ),
256
-                    'events_overview_table_column_headings_help_tab' => array(
257
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
258
-                        'filename' => 'events_overview_table_column_headings',
259
-                    ),
260
-                    'events_overview_filters_help_tab'               => array(
261
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
262
-                        'filename' => 'events_overview_filters',
263
-                    ),
264
-                    'events_overview_view_help_tab'                  => array(
265
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
266
-                        'filename' => 'events_overview_views',
267
-                    ),
268
-                    'events_overview_other_help_tab'                 => array(
269
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
270
-                        'filename' => 'events_overview_other',
271
-                    ),
272
-                ),
273
-                'help_tour'     => array(
274
-                    'Event_Overview_Help_Tour',
275
-                    // 'New_Features_Test_Help_Tour' for testing multiple help tour
276
-                ),
277
-                'qtips'         => array(
278
-                    'EE_Event_List_Table_Tips',
279
-                ),
280
-                'require_nonce' => false,
281
-            ),
282
-            'create_new'             => array(
283
-                'nav'           => array(
284
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
285
-                    'order'      => 5,
286
-                    'persistent' => false,
287
-                ),
288
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
289
-                'help_tabs'     => array(
290
-                    'event_editor_help_tab'                            => array(
291
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
292
-                        'filename' => 'event_editor',
293
-                    ),
294
-                    'event_editor_title_richtexteditor_help_tab'       => array(
295
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
296
-                        'filename' => 'event_editor_title_richtexteditor',
297
-                    ),
298
-                    'event_editor_venue_details_help_tab'              => array(
299
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
300
-                        'filename' => 'event_editor_venue_details',
301
-                    ),
302
-                    'event_editor_event_datetimes_help_tab'            => array(
303
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
304
-                        'filename' => 'event_editor_event_datetimes',
305
-                    ),
306
-                    'event_editor_event_tickets_help_tab'              => array(
307
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
308
-                        'filename' => 'event_editor_event_tickets',
309
-                    ),
310
-                    'event_editor_event_registration_options_help_tab' => array(
311
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
312
-                        'filename' => 'event_editor_event_registration_options',
313
-                    ),
314
-                    'event_editor_tags_categories_help_tab'            => array(
315
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
316
-                        'filename' => 'event_editor_tags_categories',
317
-                    ),
318
-                    'event_editor_questions_registrants_help_tab'      => array(
319
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
320
-                        'filename' => 'event_editor_questions_registrants',
321
-                    ),
322
-                    'event_editor_save_new_event_help_tab'             => array(
323
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
324
-                        'filename' => 'event_editor_save_new_event',
325
-                    ),
326
-                    'event_editor_other_help_tab'                      => array(
327
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
328
-                        'filename' => 'event_editor_other',
329
-                    ),
330
-                ),
331
-                'help_tour'     => array(
332
-                    'Event_Editor_Help_Tour',
333
-                ),
334
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
335
-                'require_nonce' => false,
336
-            ),
337
-            'edit'                   => array(
338
-                'nav'           => array(
339
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
340
-                    'order'      => 5,
341
-                    'persistent' => false,
342
-                    'url'        => isset($this->_req_data['post'])
343
-                        ? EE_Admin_Page::add_query_args_and_nonce(
344
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
345
-                            $this->_current_page_view_url
346
-                        )
347
-                        : $this->_admin_base_url,
348
-                ),
349
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
350
-                'help_tabs'     => array(
351
-                    'event_editor_help_tab'                            => array(
352
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
353
-                        'filename' => 'event_editor',
354
-                    ),
355
-                    'event_editor_title_richtexteditor_help_tab'       => array(
356
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
357
-                        'filename' => 'event_editor_title_richtexteditor',
358
-                    ),
359
-                    'event_editor_venue_details_help_tab'              => array(
360
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
361
-                        'filename' => 'event_editor_venue_details',
362
-                    ),
363
-                    'event_editor_event_datetimes_help_tab'            => array(
364
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
365
-                        'filename' => 'event_editor_event_datetimes',
366
-                    ),
367
-                    'event_editor_event_tickets_help_tab'              => array(
368
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
369
-                        'filename' => 'event_editor_event_tickets',
370
-                    ),
371
-                    'event_editor_event_registration_options_help_tab' => array(
372
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
373
-                        'filename' => 'event_editor_event_registration_options',
374
-                    ),
375
-                    'event_editor_tags_categories_help_tab'            => array(
376
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
377
-                        'filename' => 'event_editor_tags_categories',
378
-                    ),
379
-                    'event_editor_questions_registrants_help_tab'      => array(
380
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
381
-                        'filename' => 'event_editor_questions_registrants',
382
-                    ),
383
-                    'event_editor_save_new_event_help_tab'             => array(
384
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
385
-                        'filename' => 'event_editor_save_new_event',
386
-                    ),
387
-                    'event_editor_other_help_tab'                      => array(
388
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
389
-                        'filename' => 'event_editor_other',
390
-                    ),
391
-                ),
392
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
393
-                'require_nonce' => false,
394
-            ),
395
-            'default_event_settings' => array(
396
-                'nav'           => array(
397
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
398
-                    'order' => 40,
399
-                ),
400
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
401
-                'labels'        => array(
402
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
403
-                ),
404
-                'help_tabs'     => array(
405
-                    'default_settings_help_tab'        => array(
406
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
407
-                        'filename' => 'events_default_settings',
408
-                    ),
409
-                    'default_settings_status_help_tab' => array(
410
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
411
-                        'filename' => 'events_default_settings_status',
412
-                    ),
413
-                    'default_maximum_tickets_help_tab' => array(
414
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
415
-                        'filename' => 'events_default_settings_max_tickets',
416
-                    ),
417
-                ),
418
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
419
-                'require_nonce' => false,
420
-            ),
421
-            // template settings
422
-            'template_settings'      => array(
423
-                'nav'           => array(
424
-                    'label' => esc_html__('Templates', 'event_espresso'),
425
-                    'order' => 30,
426
-                ),
427
-                'metaboxes'     => $this->_default_espresso_metaboxes,
428
-                'help_tabs'     => array(
429
-                    'general_settings_templates_help_tab' => array(
430
-                        'title'    => esc_html__('Templates', 'event_espresso'),
431
-                        'filename' => 'general_settings_templates',
432
-                    ),
433
-                ),
434
-                'help_tour'     => array('Templates_Help_Tour'),
435
-                'require_nonce' => false,
436
-            ),
437
-            // event category stuff
438
-            'add_category'           => array(
439
-                'nav'           => array(
440
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
441
-                    'order'      => 15,
442
-                    'persistent' => false,
443
-                ),
444
-                'help_tabs'     => array(
445
-                    'add_category_help_tab' => array(
446
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
447
-                        'filename' => 'events_add_category',
448
-                    ),
449
-                ),
450
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
451
-                'metaboxes'     => array('_publish_post_box'),
452
-                'require_nonce' => false,
453
-            ),
454
-            'edit_category'          => array(
455
-                'nav'           => array(
456
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
457
-                    'order'      => 15,
458
-                    'persistent' => false,
459
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
460
-                        ? add_query_arg(
461
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
462
-                            $this->_current_page_view_url
463
-                        )
464
-                        : $this->_admin_base_url,
465
-                ),
466
-                'help_tabs'     => array(
467
-                    'edit_category_help_tab' => array(
468
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
469
-                        'filename' => 'events_edit_category',
470
-                    ),
471
-                ),
472
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
473
-                'metaboxes'     => array('_publish_post_box'),
474
-                'require_nonce' => false,
475
-            ),
476
-            'category_list'          => array(
477
-                'nav'           => array(
478
-                    'label' => esc_html__('Categories', 'event_espresso'),
479
-                    'order' => 20,
480
-                ),
481
-                'list_table'    => 'Event_Categories_Admin_List_Table',
482
-                'help_tabs'     => array(
483
-                    'events_categories_help_tab'                       => array(
484
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
485
-                        'filename' => 'events_categories',
486
-                    ),
487
-                    'events_categories_table_column_headings_help_tab' => array(
488
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
489
-                        'filename' => 'events_categories_table_column_headings',
490
-                    ),
491
-                    'events_categories_view_help_tab'                  => array(
492
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
493
-                        'filename' => 'events_categories_views',
494
-                    ),
495
-                    'events_categories_other_help_tab'                 => array(
496
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
497
-                        'filename' => 'events_categories_other',
498
-                    ),
499
-                ),
500
-                'help_tour'     => array(
501
-                    'Event_Categories_Help_Tour',
502
-                ),
503
-                'metaboxes'     => $this->_default_espresso_metaboxes,
504
-                'require_nonce' => false,
505
-            ),
506
-        );
507
-    }
508
-
509
-
510
-    /**
511
-     * Used to register any global screen options if necessary for every route in this admin page group.
512
-     */
513
-    protected function _add_screen_options()
514
-    {
515
-    }
516
-
517
-
518
-    /**
519
-     * Implementing the screen options for the 'default' route.
520
-     */
521
-    protected function _add_screen_options_default()
522
-    {
523
-        $this->_per_page_screen_option();
524
-    }
525
-
526
-
527
-    /**
528
-     * Implementing screen options for the category list route.
529
-     */
530
-    protected function _add_screen_options_category_list()
531
-    {
532
-        $page_title = $this->_admin_page_title;
533
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
534
-        $this->_per_page_screen_option();
535
-        $this->_admin_page_title = $page_title;
536
-    }
537
-
538
-
539
-    /**
540
-     * Used to register any global feature pointers for the admin page group.
541
-     */
542
-    protected function _add_feature_pointers()
543
-    {
544
-    }
545
-
546
-
547
-    /**
548
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
549
-     */
550
-    public function load_scripts_styles()
551
-    {
552
-        wp_register_style(
553
-            'events-admin-css',
554
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
555
-            array(),
556
-            EVENT_ESPRESSO_VERSION
557
-        );
558
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
559
-        wp_enqueue_style('events-admin-css');
560
-        wp_enqueue_style('ee-cat-admin');
561
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
562
-        // registers for all views
563
-        // scripts
564
-        wp_register_script(
565
-            'event_editor_js',
566
-            EVENTS_ASSETS_URL . 'event_editor.js',
567
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
568
-            EVENT_ESPRESSO_VERSION,
569
-            true
570
-        );
571
-    }
572
-
573
-
574
-    /**
575
-     * Enqueuing scripts and styles specific to this view
576
-     */
577
-    public function load_scripts_styles_create_new()
578
-    {
579
-        $this->load_scripts_styles_edit();
580
-    }
581
-
582
-
583
-    /**
584
-     * Enqueuing scripts and styles specific to this view
585
-     */
586
-    public function load_scripts_styles_edit()
587
-    {
588
-        // styles
589
-        wp_enqueue_style('espresso-ui-theme');
590
-        wp_register_style(
591
-            'event-editor-css',
592
-            EVENTS_ASSETS_URL . 'event-editor.css',
593
-            array('ee-admin-css'),
594
-            EVENT_ESPRESSO_VERSION
595
-        );
596
-        wp_enqueue_style('event-editor-css');
597
-        // scripts
598
-        wp_register_script(
599
-            'event-datetime-metabox',
600
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
601
-            array('event_editor_js', 'ee-datepicker'),
602
-            EVENT_ESPRESSO_VERSION
603
-        );
604
-        wp_enqueue_script('event-datetime-metabox');
605
-    }
606
-
607
-
608
-    /**
609
-     * Populating the _views property for the category list table view.
610
-     */
611
-    protected function _set_list_table_views_category_list()
612
-    {
613
-        $this->_views = array(
614
-            'all' => array(
615
-                'slug'        => 'all',
616
-                'label'       => esc_html__('All', 'event_espresso'),
617
-                'count'       => 0,
618
-                'bulk_action' => array(
619
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
620
-                ),
621
-            ),
622
-        );
623
-    }
624
-
625
-
626
-    /**
627
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
628
-     */
629
-    public function admin_init()
630
-    {
631
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
632
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
633
-            'event_espresso'
634
-        );
635
-    }
636
-
637
-
638
-    /**
639
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
640
-     * group.
641
-     */
642
-    public function admin_notices()
643
-    {
644
-    }
645
-
646
-
647
-    /**
648
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
649
-     * this admin page group.
650
-     */
651
-    public function admin_footer_scripts()
652
-    {
653
-    }
654
-
655
-
656
-    /**
657
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
658
-     * warning (via EE_Error::add_error());
659
-     *
660
-     * @param  EE_Event $event Event object
661
-     * @param string    $req_type
662
-     * @return void
663
-     * @throws EE_Error
664
-     * @access public
665
-     */
666
-    public function verify_event_edit($event = null, $req_type = '')
667
-    {
668
-        // don't need to do this when processing
669
-        if (! empty($req_type)) {
670
-            return;
671
-        }
672
-        // no event?
673
-        if (empty($event)) {
674
-            // set event
675
-            $event = $this->_cpt_model_obj;
676
-        }
677
-        // STILL no event?
678
-        if (! $event instanceof EE_Event) {
679
-            return;
680
-        }
681
-        $orig_status = $event->status();
682
-        // first check if event is active.
683
-        if ($orig_status === EEM_Event::cancelled
684
-            || $orig_status === EEM_Event::postponed
685
-            || $event->is_expired()
686
-            || $event->is_inactive()
687
-        ) {
688
-            return;
689
-        }
690
-        // made it here so it IS active... next check that any of the tickets are sold.
691
-        if ($event->is_sold_out(true)) {
692
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
693
-                EE_Error::add_attention(
694
-                    sprintf(
695
-                        esc_html__(
696
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
697
-                            'event_espresso'
698
-                        ),
699
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
700
-                    )
701
-                );
702
-            }
703
-            return;
704
-        } elseif ($orig_status === EEM_Event::sold_out) {
705
-            EE_Error::add_attention(
706
-                sprintf(
707
-                    esc_html__(
708
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
709
-                        'event_espresso'
710
-                    ),
711
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
712
-                )
713
-            );
714
-        }
715
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
716
-        if (! $event->tickets_on_sale()) {
717
-            return;
718
-        }
719
-        // made it here so show warning
720
-        $this->_edit_event_warning();
721
-    }
722
-
723
-
724
-    /**
725
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
726
-     * When needed, hook this into a EE_Error::add_error() notice.
727
-     *
728
-     * @access protected
729
-     * @return void
730
-     */
731
-    protected function _edit_event_warning()
732
-    {
733
-        // we don't want to add warnings during these requests
734
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
735
-            return;
736
-        }
737
-        EE_Error::add_attention(
738
-            sprintf(
739
-                esc_html__(
740
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
741
-                    'event_espresso'
742
-                ),
743
-                '<a class="espresso-help-tab-lnk">',
744
-                '</a>'
745
-            )
746
-        );
747
-    }
748
-
749
-
750
-    /**
751
-     * When a user is creating a new event, notify them if they haven't set their timezone.
752
-     * Otherwise, do the normal logic
753
-     *
754
-     * @return string
755
-     * @throws \EE_Error
756
-     */
757
-    protected function _create_new_cpt_item()
758
-    {
759
-        $has_timezone_string = get_option('timezone_string');
760
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
761
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
762
-            EE_Error::add_attention(
763
-                sprintf(
764
-                    __(
765
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
766
-                        'event_espresso'
767
-                    ),
768
-                    '<br>',
769
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
770
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
771
-                    . '</select>',
772
-                    '<button class="button button-secondary timezone-submit">',
773
-                    '</button><span class="spinner"></span>'
774
-                ),
775
-                __FILE__,
776
-                __FUNCTION__,
777
-                __LINE__
778
-            );
779
-        }
780
-        return parent::_create_new_cpt_item();
781
-    }
782
-
783
-
784
-    /**
785
-     * Sets the _views property for the default route in this admin page group.
786
-     */
787
-    protected function _set_list_table_views_default()
788
-    {
789
-        $this->_views = array(
790
-            'all'   => array(
791
-                'slug'        => 'all',
792
-                'label'       => esc_html__('View All Events', 'event_espresso'),
793
-                'count'       => 0,
794
-                'bulk_action' => array(
795
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
796
-                ),
797
-            ),
798
-            'draft' => array(
799
-                'slug'        => 'draft',
800
-                'label'       => esc_html__('Draft', 'event_espresso'),
801
-                'count'       => 0,
802
-                'bulk_action' => array(
803
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
804
-                ),
805
-            ),
806
-        );
807
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
808
-            $this->_views['trash'] = array(
809
-                'slug'        => 'trash',
810
-                'label'       => esc_html__('Trash', 'event_espresso'),
811
-                'count'       => 0,
812
-                'bulk_action' => array(
813
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
814
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
815
-                ),
816
-            );
817
-        }
818
-    }
819
-
820
-
821
-    /**
822
-     * Provides the legend item array for the default list table view.
823
-     *
824
-     * @return array
825
-     */
826
-    protected function _event_legend_items()
827
-    {
828
-        $items = array(
829
-            'view_details'   => array(
830
-                'class' => 'dashicons dashicons-search',
831
-                'desc'  => esc_html__('View Event', 'event_espresso'),
832
-            ),
833
-            'edit_event'     => array(
834
-                'class' => 'ee-icon ee-icon-calendar-edit',
835
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
836
-            ),
837
-            'view_attendees' => array(
838
-                'class' => 'dashicons dashicons-groups',
839
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
840
-            ),
841
-        );
842
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
843
-        $statuses = array(
844
-            'sold_out_status'  => array(
845
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
846
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
847
-            ),
848
-            'active_status'    => array(
849
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
850
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
851
-            ),
852
-            'upcoming_status'  => array(
853
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
854
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
855
-            ),
856
-            'postponed_status' => array(
857
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
858
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
859
-            ),
860
-            'cancelled_status' => array(
861
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
862
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
863
-            ),
864
-            'expired_status'   => array(
865
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
866
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
867
-            ),
868
-            'inactive_status'  => array(
869
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
870
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
871
-            ),
872
-        );
873
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
874
-        return array_merge($items, $statuses);
875
-    }
876
-
877
-
878
-    /**
879
-     * @return EEM_Event
880
-     */
881
-    private function _event_model()
882
-    {
883
-        if (! $this->_event_model instanceof EEM_Event) {
884
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
885
-        }
886
-        return $this->_event_model;
887
-    }
888
-
889
-
890
-    /**
891
-     * Adds extra buttons to the WP CPT permalink field row.
892
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
893
-     *
894
-     * @param  string $return    the current html
895
-     * @param  int    $id        the post id for the page
896
-     * @param  string $new_title What the title is
897
-     * @param  string $new_slug  what the slug is
898
-     * @return string            The new html string for the permalink area
899
-     */
900
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
901
-    {
902
-        // make sure this is only when editing
903
-        if (! empty($id)) {
904
-            $post = get_post($id);
905
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
906
-                       . esc_html__('Shortcode', 'event_espresso')
907
-                       . '</a> ';
908
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
909
-                       . $post->ID
910
-                       . ']">';
911
-        }
912
-        return $return;
913
-    }
914
-
915
-
916
-    /**
917
-     * _events_overview_list_table
918
-     * This contains the logic for showing the events_overview list
919
-     *
920
-     * @access protected
921
-     * @return void
922
-     * @throws \EE_Error
923
-     */
924
-    protected function _events_overview_list_table()
925
-    {
926
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
927
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
928
-            ? (array) $this->_template_args['after_list_table']
929
-            : array();
930
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
931
-                . EEH_Template::get_button_or_link(
932
-                    get_post_type_archive_link('espresso_events'),
933
-                    esc_html__("View Event Archive Page", "event_espresso"),
934
-                    'button'
935
-                );
936
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
937
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
938
-            'create_new',
939
-            'add',
940
-            array(),
941
-            'add-new-h2'
942
-        );
943
-        $this->display_admin_list_table_page_with_no_sidebar();
944
-    }
945
-
946
-
947
-    /**
948
-     * this allows for extra misc actions in the default WP publish box
949
-     *
950
-     * @return void
951
-     */
952
-    public function extra_misc_actions_publish_box()
953
-    {
954
-        $this->_generate_publish_box_extra_content();
955
-    }
956
-
957
-
958
-    /**
959
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
960
-     * saved.
961
-     * Typically you would use this to save any additional data.
962
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
963
-     * ALSO very important.  When a post transitions from scheduled to published,
964
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
965
-     * other meta saves. So MAKE sure that you handle this accordingly.
966
-     *
967
-     * @access protected
968
-     * @abstract
969
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
970
-     * @param  object $post    The post object of the cpt that was saved.
971
-     * @return void
972
-     * @throws \EE_Error
973
-     */
974
-    protected function _insert_update_cpt_item($post_id, $post)
975
-    {
976
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
977
-            // get out we're not processing an event save.
978
-            return;
979
-        }
980
-        $event_values = array(
981
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
982
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
983
-            'EVT_additional_limit'            => min(
984
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
985
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
986
-            ),
987
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
988
-                ? $this->_req_data['EVT_default_registration_status']
989
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
990
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
991
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
992
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
993
-                ? $this->_req_data['timezone_string'] : null,
994
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
995
-                ? $this->_req_data['externalURL'] : null,
996
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
997
-                ? $this->_req_data['event_phone'] : null,
998
-        );
999
-        // update event
1000
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1001
-        // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1002
-        $get_one_where = array(
1003
-            $this->_event_model()->primary_key_name() => $post_id,
1004
-            'OR'                                      => array(
1005
-                'status'   => $post->post_status,
1006
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1007
-                // but the returned object here has a status of "publish", so use the original post status as well
1008
-                'status*1' => $this->_req_data['original_post_status'],
1009
-            ),
1010
-        );
1011
-        $event = $this->_event_model()->get_one(array($get_one_where));
1012
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1013
-        $event_update_callbacks = apply_filters(
1014
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1015
-            array(
1016
-                array($this, '_default_venue_update'),
1017
-                array($this, '_default_tickets_update'),
1018
-            )
1019
-        );
1020
-        $att_success = true;
1021
-        foreach ($event_update_callbacks as $e_callback) {
1022
-            $_success = is_callable($e_callback)
1023
-                ? call_user_func($e_callback, $event, $this->_req_data)
1024
-                : false;
1025
-            // if ANY of these updates fail then we want the appropriate global error message
1026
-            $att_success = ! $att_success ? $att_success : $_success;
1027
-        }
1028
-        // any errors?
1029
-        if ($success && false === $att_success) {
1030
-            EE_Error::add_error(
1031
-                esc_html__(
1032
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1033
-                    'event_espresso'
1034
-                ),
1035
-                __FILE__,
1036
-                __FUNCTION__,
1037
-                __LINE__
1038
-            );
1039
-        } elseif ($success === false) {
1040
-            EE_Error::add_error(
1041
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1042
-                __FILE__,
1043
-                __FUNCTION__,
1044
-                __LINE__
1045
-            );
1046
-        }
1047
-    }
1048
-
1049
-
1050
-    /**
1051
-     * @see parent::restore_item()
1052
-     * @param int $post_id
1053
-     * @param int $revision_id
1054
-     */
1055
-    protected function _restore_cpt_item($post_id, $revision_id)
1056
-    {
1057
-        // copy existing event meta to new post
1058
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1059
-        if ($post_evt instanceof EE_Event) {
1060
-            // meta revision restore
1061
-            $post_evt->restore_revision($revision_id);
1062
-            // related objs restore
1063
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1064
-        }
1065
-    }
1066
-
1067
-
1068
-    /**
1069
-     * Attach the venue to the Event
1070
-     *
1071
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1072
-     * @param  array     $data   The request data from the form
1073
-     * @return bool           Success or fail.
1074
-     */
1075
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1076
-    {
1077
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1078
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1079
-        $rows_affected = null;
1080
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1081
-        // very important.  If we don't have a venue name...
1082
-        // then we'll get out because not necessary to create empty venue
1083
-        if (empty($data['venue_title'])) {
1084
-            return false;
1085
-        }
1086
-        $venue_array = array(
1087
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1088
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1089
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1090
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1091
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1092
-                : null,
1093
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1094
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1095
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1096
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1097
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1098
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1099
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1100
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1101
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1102
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1103
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1104
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1105
-            'status'              => 'publish',
1106
-        );
1107
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1108
-        if (! empty($venue_id)) {
1109
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1110
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1111
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1112
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1113
-            return $rows_affected > 0 ? true : false;
1114
-        } else {
1115
-            // we insert the venue
1116
-            $venue_id = $venue_model->insert($venue_array);
1117
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1118
-            return ! empty($venue_id) ? true : false;
1119
-        }
1120
-        // when we have the ancestor come in it's already been handled by the revision save.
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1126
-     *
1127
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1128
-     * @param  array    $data   The request data from the form
1129
-     * @return array
1130
-     */
1131
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1132
-    {
1133
-        $success = true;
1134
-        $saved_dtt = null;
1135
-        $saved_tickets = array();
1136
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1137
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1138
-            // trim all values to ensure any excess whitespace is removed.
1139
-            $dtt = array_map('trim', $dtt);
1140
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1141
-                : $dtt['DTT_EVT_start'];
1142
-            $datetime_values = array(
1143
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1144
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1145
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1146
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1147
-                'DTT_order'     => $row,
1148
-            );
1149
-            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1150
-            if (! empty($dtt['DTT_ID'])) {
1151
-                $DTM = EE_Registry::instance()
1152
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1153
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1154
-                $DTM->set_date_format($incoming_date_formats[0]);
1155
-                $DTM->set_time_format($incoming_date_formats[1]);
1156
-                foreach ($datetime_values as $field => $value) {
1157
-                    $DTM->set($field, $value);
1158
-                }
1159
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1160
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1161
-            } else {
1162
-                $DTM = EE_Registry::instance()->load_class(
1163
-                    'Datetime',
1164
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1165
-                    false,
1166
-                    false
1167
-                );
1168
-                foreach ($datetime_values as $field => $value) {
1169
-                    $DTM->set($field, $value);
1170
-                }
1171
-            }
1172
-            $DTM->save();
1173
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1174
-            // load DTT helper
1175
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1176
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1177
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1178
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1179
-                $DTT->save();
1180
-            }
1181
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1182
-            $saved_dtt = $DTT;
1183
-            $success = ! $success ? $success : $DTT;
1184
-            // if ANY of these updates fail then we want the appropriate global error message.
1185
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1186
-        }
1187
-        // no dtts get deleted so we don't do any of that logic here.
1188
-        // update tickets next
1189
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1190
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1191
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1192
-            $update_prices = false;
1193
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1194
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1195
-            // trim inputs to ensure any excess whitespace is removed.
1196
-            $tkt = array_map('trim', $tkt);
1197
-            if (empty($tkt['TKT_start_date'])) {
1198
-                // let's use now in the set timezone.
1199
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1200
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1201
-            }
1202
-            if (empty($tkt['TKT_end_date'])) {
1203
-                // use the start date of the first datetime
1204
-                $dtt = $evtobj->first_datetime();
1205
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1206
-                    $incoming_date_formats[0],
1207
-                    $incoming_date_formats[1]
1208
-                );
1209
-            }
1210
-            $TKT_values = array(
1211
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1212
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1213
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1214
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1215
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1216
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1217
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1218
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1219
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1220
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1221
-                'TKT_row'         => $row,
1222
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1223
-                'TKT_price'       => $ticket_price,
1224
-            );
1225
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1226
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1227
-                $TKT_values['TKT_ID'] = 0;
1228
-                $TKT_values['TKT_is_default'] = 0;
1229
-                $TKT_values['TKT_price'] = $ticket_price;
1230
-                $update_prices = true;
1231
-            }
1232
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1233
-            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1234
-            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1235
-            if (! empty($tkt['TKT_ID'])) {
1236
-                $TKT = EE_Registry::instance()
1237
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1238
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1239
-                if ($TKT instanceof EE_Ticket) {
1240
-                    $ticket_sold = $TKT->count_related(
1241
-                        'Registration',
1242
-                        array(
1243
-                            array(
1244
-                                'STS_ID' => array(
1245
-                                    'NOT IN',
1246
-                                    array(EEM_Registration::status_id_incomplete),
1247
-                                ),
1248
-                            ),
1249
-                        )
1250
-                    ) > 0 ? true : false;
1251
-                    // let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1252
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1253
-                                      && ! $TKT->get('TKT_deleted');
1254
-                    $TKT->set_date_format($incoming_date_formats[0]);
1255
-                    $TKT->set_time_format($incoming_date_formats[1]);
1256
-                    // set new values
1257
-                    foreach ($TKT_values as $field => $value) {
1258
-                        if ($field == 'TKT_qty') {
1259
-                            $TKT->set_qty($value);
1260
-                        } else {
1261
-                            $TKT->set($field, $value);
1262
-                        }
1263
-                    }
1264
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1265
-                    if ($create_new_TKT) {
1266
-                        // archive the old ticket first
1267
-                        $TKT->set('TKT_deleted', 1);
1268
-                        $TKT->save();
1269
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1270
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1271
-                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1272
-                        $TKT = clone $TKT;
1273
-                        $TKT->set('TKT_ID', 0);
1274
-                        $TKT->set('TKT_deleted', 0);
1275
-                        $TKT->set('TKT_price', $ticket_price);
1276
-                        $TKT->set('TKT_sold', 0);
1277
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1278
-                        $update_prices = true;
1279
-                    }
1280
-                    // make sure price is set if it hasn't been already
1281
-                    $TKT->set('TKT_price', $ticket_price);
1282
-                }
1283
-            } else {
1284
-                // no TKT_id so a new TKT
1285
-                $TKT_values['TKT_price'] = $ticket_price;
1286
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1287
-                if ($TKT instanceof EE_Ticket) {
1288
-                    // need to reset values to properly account for the date formats
1289
-                    $TKT->set_date_format($incoming_date_formats[0]);
1290
-                    $TKT->set_time_format($incoming_date_formats[1]);
1291
-                    $TKT->set_timezone($evtobj->get_timezone());
1292
-                    // set new values
1293
-                    foreach ($TKT_values as $field => $value) {
1294
-                        if ($field == 'TKT_qty') {
1295
-                            $TKT->set_qty($value);
1296
-                        } else {
1297
-                            $TKT->set($field, $value);
1298
-                        }
1299
-                    }
1300
-                    $update_prices = true;
1301
-                }
1302
-            }
1303
-            // cap ticket qty by datetime reg limits
1304
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1305
-            // update ticket.
1306
-            $TKT->save();
1307
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1308
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1309
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1310
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1311
-                $TKT->save();
1312
-            }
1313
-            // initially let's add the ticket to the dtt
1314
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1315
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1316
-            // add prices to ticket
1317
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1318
-        }
1319
-        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1320
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1321
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1322
-        foreach ($tickets_removed as $id) {
1323
-            $id = absint($id);
1324
-            // get the ticket for this id
1325
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1326
-            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1327
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1328
-            foreach ($dtts as $dtt) {
1329
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1330
-            }
1331
-            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1332
-            $tkt_to_remove->delete_related_permanently('Price');
1333
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1334
-            $tkt_to_remove->delete_permanently();
1335
-        }
1336
-        return array($saved_dtt, $saved_tickets);
1337
-    }
1338
-
1339
-
1340
-    /**
1341
-     * This attaches a list of given prices to a ticket.
1342
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1343
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1344
-     * price info and prices are automatically "archived" via the ticket.
1345
-     *
1346
-     * @access  private
1347
-     * @param array     $prices     Array of prices from the form.
1348
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1349
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1350
-     * @return  void
1351
-     */
1352
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1353
-    {
1354
-        foreach ($prices as $row => $prc) {
1355
-            $PRC_values = array(
1356
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1357
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1358
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1359
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1360
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1361
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1362
-                'PRC_order'      => $row,
1363
-            );
1364
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1365
-                $PRC_values['PRC_ID'] = 0;
1366
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1367
-            } else {
1368
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1369
-                // update this price with new values
1370
-                foreach ($PRC_values as $field => $newprc) {
1371
-                    $PRC->set($field, $newprc);
1372
-                }
1373
-                $PRC->save();
1374
-            }
1375
-            $ticket->_add_relation_to($PRC, 'Price');
1376
-        }
1377
-    }
1378
-
1379
-
1380
-    /**
1381
-     * Add in our autosave ajax handlers
1382
-     *
1383
-     */
1384
-    protected function _ee_autosave_create_new()
1385
-    {
1386
-    }
1387
-
1388
-
1389
-    /**
1390
-     * More autosave handlers.
1391
-     */
1392
-    protected function _ee_autosave_edit()
1393
-    {
1394
-        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1395
-    }
1396
-
1397
-
1398
-    /**
1399
-     *    _generate_publish_box_extra_content
1400
-     */
1401
-    private function _generate_publish_box_extra_content()
1402
-    {
1403
-        // load formatter helper
1404
-        // args for getting related registrations
1405
-        $approved_query_args = array(
1406
-            array(
1407
-                'REG_deleted' => 0,
1408
-                'STS_ID'      => EEM_Registration::status_id_approved,
1409
-            ),
1410
-        );
1411
-        $not_approved_query_args = array(
1412
-            array(
1413
-                'REG_deleted' => 0,
1414
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1415
-            ),
1416
-        );
1417
-        $pending_payment_query_args = array(
1418
-            array(
1419
-                'REG_deleted' => 0,
1420
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1421
-            ),
1422
-        );
1423
-        // publish box
1424
-        $publish_box_extra_args = array(
1425
-            'view_approved_reg_url'        => add_query_arg(
1426
-                array(
1427
-                    'action'      => 'default',
1428
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1429
-                    '_reg_status' => EEM_Registration::status_id_approved,
1430
-                ),
1431
-                REG_ADMIN_URL
1432
-            ),
1433
-            'view_not_approved_reg_url'    => add_query_arg(
1434
-                array(
1435
-                    'action'      => 'default',
1436
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1437
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1438
-                ),
1439
-                REG_ADMIN_URL
1440
-            ),
1441
-            'view_pending_payment_reg_url' => add_query_arg(
1442
-                array(
1443
-                    'action'      => 'default',
1444
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1445
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1446
-                ),
1447
-                REG_ADMIN_URL
1448
-            ),
1449
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1450
-                'Registration',
1451
-                $approved_query_args
1452
-            ),
1453
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1454
-                'Registration',
1455
-                $not_approved_query_args
1456
-            ),
1457
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1458
-                'Registration',
1459
-                $pending_payment_query_args
1460
-            ),
1461
-            'misc_pub_section_class'       => apply_filters(
1462
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1463
-                'misc-pub-section'
1464
-            ),
1465
-        );
1466
-        ob_start();
1467
-        do_action(
1468
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1469
-            $this->_cpt_model_obj
1470
-        );
1471
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1472
-        // load template
1473
-        EEH_Template::display_template(
1474
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1475
-            $publish_box_extra_args
1476
-        );
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * @return EE_Event
1482
-     */
1483
-    public function get_event_object()
1484
-    {
1485
-        return $this->_cpt_model_obj;
1486
-    }
1487
-
1488
-
1489
-
1490
-
1491
-    /** METABOXES * */
1492
-    /**
1493
-     * _register_event_editor_meta_boxes
1494
-     * add all metaboxes related to the event_editor
1495
-     *
1496
-     * @return void
1497
-     */
1498
-    protected function _register_event_editor_meta_boxes()
1499
-    {
1500
-        $this->verify_cpt_object();
1501
-        // add_meta_box(
1502
-        //     'espresso_event_editor_tickets',
1503
-        //     esc_html__('Event Datetime & Ticket', 'event_espresso'),
1504
-        //     array($this, 'ticket_metabox'),
1505
-        //     $this->page_slug,
1506
-        //     'normal',
1507
-        //     'high'
1508
-        // );
1509
-        add_meta_box(
1510
-            'espresso_event_editor_event_options',
1511
-            esc_html__('Event Registration Options', 'event_espresso'),
1512
-            array($this, 'registration_options_meta_box'),
1513
-            $this->page_slug,
1514
-            'side',
1515
-            'default'
1516
-        );
1517
-        // NOTE: if you're looking for other metaboxes in here,
1518
-        // where a metabox has a related management page in the admin
1519
-        // you will find it setup in the related management page's "_Hooks" file.
1520
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1521
-    }
1522
-
1523
-
1524
-    /**
1525
-     * @throws DomainException
1526
-     * @throws EE_Error
1527
-     */
1528
-    public function ticket_metabox()
1529
-    {
1530
-        $existing_datetime_ids = $existing_ticket_ids = array();
1531
-        // defaults for template args
1532
-        $template_args = array(
1533
-            'existing_datetime_ids'    => '',
1534
-            'event_datetime_help_link' => '',
1535
-            'ticket_options_help_link' => '',
1536
-            'time'                     => null,
1537
-            'ticket_rows'              => '',
1538
-            'existing_ticket_ids'      => '',
1539
-            'total_ticket_rows'        => 1,
1540
-            'ticket_js_structure'      => '',
1541
-            'trash_icon'               => 'ee-lock-icon',
1542
-            'disabled'                 => '',
1543
-        );
1544
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1545
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1546
-        /**
1547
-         * 1. Start with retrieving Datetimes
1548
-         * 2. Fore each datetime get related tickets
1549
-         * 3. For each ticket get related prices
1550
-         */
1551
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1552
-        /** @type EE_Datetime $first_datetime */
1553
-        $first_datetime = reset($times);
1554
-        // do we get related tickets?
1555
-        if ($first_datetime instanceof EE_Datetime
1556
-            && $first_datetime->ID() !== 0
1557
-        ) {
1558
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1559
-            $template_args['time'] = $first_datetime;
1560
-            $related_tickets = $first_datetime->tickets(
1561
-                array(
1562
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1563
-                    'default_where_conditions' => 'none',
1564
-                )
1565
-            );
1566
-            if (! empty($related_tickets)) {
1567
-                $template_args['total_ticket_rows'] = count($related_tickets);
1568
-                $row = 0;
1569
-                foreach ($related_tickets as $ticket) {
1570
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1571
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1572
-                    $row++;
1573
-                }
1574
-            } else {
1575
-                $template_args['total_ticket_rows'] = 1;
1576
-                /** @type EE_Ticket $ticket */
1577
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1578
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1579
-            }
1580
-        } else {
1581
-            $template_args['time'] = $times[0];
1582
-            /** @type EE_Ticket $ticket */
1583
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1584
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1585
-            // NOTE: we're just sending the first default row
1586
-            // (decaf can't manage default tickets so this should be sufficient);
1587
-        }
1588
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1589
-            'event_editor_event_datetimes_help_tab'
1590
-        );
1591
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1592
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1593
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1594
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1595
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1596
-            true
1597
-        );
1598
-        $template = apply_filters(
1599
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1600
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1601
-        );
1602
-        EEH_Template::display_template($template, $template_args);
1603
-    }
1604
-
1605
-
1606
-    /**
1607
-     * Setup an individual ticket form for the decaf event editor page
1608
-     *
1609
-     * @access private
1610
-     * @param  EE_Ticket $ticket   the ticket object
1611
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1612
-     * @param int        $row
1613
-     * @return string generated html for the ticket row.
1614
-     */
1615
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1616
-    {
1617
-        $template_args = array(
1618
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1619
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1620
-                : '',
1621
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1622
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1623
-            'TKT_name'            => $ticket->get('TKT_name'),
1624
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1625
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1626
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1627
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1628
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1629
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1630
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1631
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1632
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1633
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1634
-                : ' disabled=disabled',
1635
-        );
1636
-        $price = $ticket->ID() !== 0
1637
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1638
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1639
-        $price_args = array(
1640
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1641
-            'PRC_amount'            => $price->get('PRC_amount'),
1642
-            'PRT_ID'                => $price->get('PRT_ID'),
1643
-            'PRC_ID'                => $price->get('PRC_ID'),
1644
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1645
-        );
1646
-        // make sure we have default start and end dates if skeleton
1647
-        // handle rows that should NOT be empty
1648
-        if (empty($template_args['TKT_start_date'])) {
1649
-            // if empty then the start date will be now.
1650
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1651
-        }
1652
-        if (empty($template_args['TKT_end_date'])) {
1653
-            // get the earliest datetime (if present);
1654
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1655
-                ? $this->_cpt_model_obj->get_first_related(
1656
-                    'Datetime',
1657
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1658
-                )
1659
-                : null;
1660
-            if (! empty($earliest_dtt)) {
1661
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1662
-            } else {
1663
-                $template_args['TKT_end_date'] = date(
1664
-                    'Y-m-d h:i a',
1665
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1666
-                );
1667
-            }
1668
-        }
1669
-        $template_args = array_merge($template_args, $price_args);
1670
-        $template = apply_filters(
1671
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1672
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1673
-            $ticket
1674
-        );
1675
-        return EEH_Template::display_template($template, $template_args, true);
1676
-    }
1677
-
1678
-
1679
-    /**
1680
-     * @throws DomainException
1681
-     */
1682
-    public function registration_options_meta_box()
1683
-    {
1684
-        $yes_no_values = array(
1685
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1686
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1687
-        );
1688
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1689
-            array(
1690
-                EEM_Registration::status_id_cancelled,
1691
-                EEM_Registration::status_id_declined,
1692
-                EEM_Registration::status_id_incomplete,
1693
-            ),
1694
-            true
1695
-        );
1696
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1697
-        $template_args['_event'] = $this->_cpt_model_obj;
1698
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1699
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1700
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1701
-            'default_reg_status',
1702
-            $default_reg_status_values,
1703
-            $this->_cpt_model_obj->default_registration_status()
1704
-        );
1705
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1706
-            'display_desc',
1707
-            $yes_no_values,
1708
-            $this->_cpt_model_obj->display_description()
1709
-        );
1710
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1711
-            'display_ticket_selector',
1712
-            $yes_no_values,
1713
-            $this->_cpt_model_obj->display_ticket_selector(),
1714
-            '',
1715
-            '',
1716
-            false
1717
-        );
1718
-        $template_args['additional_registration_options'] = apply_filters(
1719
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1720
-            '',
1721
-            $template_args,
1722
-            $yes_no_values,
1723
-            $default_reg_status_values
1724
-        );
1725
-        EEH_Template::display_template(
1726
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1727
-            $template_args
1728
-        );
1729
-    }
1730
-
1731
-
1732
-    /**
1733
-     * _get_events()
1734
-     * This method simply returns all the events (for the given _view and paging)
1735
-     *
1736
-     * @access public
1737
-     * @param int  $per_page     count of items per page (20 default);
1738
-     * @param int  $current_page what is the current page being viewed.
1739
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1740
-     *                           If FALSE then we return an array of event objects
1741
-     *                           that match the given _view and paging parameters.
1742
-     * @return array an array of event objects.
1743
-     */
1744
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1745
-    {
1746
-        $EEME = $this->_event_model();
1747
-        $offset = ($current_page - 1) * $per_page;
1748
-        $limit = $count ? null : $offset . ',' . $per_page;
1749
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1750
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1751
-        if (isset($this->_req_data['month_range'])) {
1752
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1753
-            // simulate the FIRST day of the month, that fixes issues for months like February
1754
-            // where PHP doesn't know what to assume for date.
1755
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1756
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1757
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1758
-        }
1759
-        $where = array();
1760
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1761
-        // determine what post_status our condition will have for the query.
1762
-        switch ($status) {
1763
-            case 'month':
1764
-            case 'today':
1765
-            case null:
1766
-            case 'all':
1767
-                break;
1768
-            case 'draft':
1769
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1770
-                break;
1771
-            default:
1772
-                $where['status'] = $status;
1773
-        }
1774
-        // categories?
1775
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1776
-            ? $this->_req_data['EVT_CAT'] : null;
1777
-        if (! empty($category)) {
1778
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1779
-            $where['Term_Taxonomy.term_id'] = $category;
1780
-        }
1781
-        // date where conditions
1782
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1783
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1784
-            $DateTime = new DateTime(
1785
-                $year_r . '-' . $month_r . '-01 00:00:00',
1786
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1787
-            );
1788
-            $start = $DateTime->format(implode(' ', $start_formats));
1789
-            $end = $DateTime->setDate(
1790
-                $year_r,
1791
-                $month_r,
1792
-                $DateTime
1793
-                    ->format('t')
1794
-            )->setTime(23, 59, 59)
1795
-                            ->format(implode(' ', $start_formats));
1796
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1797
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1798
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1799
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1800
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1801
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1802
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1803
-            $now = date('Y-m-01');
1804
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1805
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1806
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1807
-                            ->setTime(23, 59, 59)
1808
-                            ->format(implode(' ', $start_formats));
1809
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1810
-        }
1811
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1812
-            $where['EVT_wp_user'] = get_current_user_id();
1813
-        } else {
1814
-            if (! isset($where['status'])) {
1815
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1816
-                    $where['OR'] = array(
1817
-                        'status*restrict_private' => array('!=', 'private'),
1818
-                        'AND'                     => array(
1819
-                            'status*inclusive' => array('=', 'private'),
1820
-                            'EVT_wp_user'      => get_current_user_id(),
1821
-                        ),
1822
-                    );
1823
-                }
1824
-            }
1825
-        }
1826
-        if (isset($this->_req_data['EVT_wp_user'])) {
1827
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1828
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1829
-            ) {
1830
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1831
-            }
1832
-        }
1833
-        // search query handling
1834
-        if (isset($this->_req_data['s'])) {
1835
-            $search_string = '%' . $this->_req_data['s'] . '%';
1836
-            $where['OR'] = array(
1837
-                'EVT_name'       => array('LIKE', $search_string),
1838
-                'EVT_desc'       => array('LIKE', $search_string),
1839
-                'EVT_short_desc' => array('LIKE', $search_string),
1840
-            );
1841
-        }
1842
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1843
-        $query_params = apply_filters(
1844
-            'FHEE__Events_Admin_Page__get_events__query_params',
1845
-            array(
1846
-                $where,
1847
-                'limit'    => $limit,
1848
-                'order_by' => $orderby,
1849
-                'order'    => $order,
1850
-                'group_by' => 'EVT_ID',
1851
-            ),
1852
-            $this->_req_data
1853
-        );
1854
-        // let's first check if we have special requests coming in.
1855
-        if (isset($this->_req_data['active_status'])) {
1856
-            switch ($this->_req_data['active_status']) {
1857
-                case 'upcoming':
1858
-                    return $EEME->get_upcoming_events($query_params, $count);
1859
-                    break;
1860
-                case 'expired':
1861
-                    return $EEME->get_expired_events($query_params, $count);
1862
-                    break;
1863
-                case 'active':
1864
-                    return $EEME->get_active_events($query_params, $count);
1865
-                    break;
1866
-                case 'inactive':
1867
-                    return $EEME->get_inactive_events($query_params, $count);
1868
-                    break;
1869
-            }
1870
-        }
1871
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1872
-        return $events;
1873
-    }
1874
-
1875
-
1876
-    /**
1877
-     * handling for WordPress CPT actions (trash, restore, delete)
1878
-     *
1879
-     * @param string $post_id
1880
-     */
1881
-    public function trash_cpt_item($post_id)
1882
-    {
1883
-        $this->_req_data['EVT_ID'] = $post_id;
1884
-        $this->_trash_or_restore_event('trash', false);
1885
-    }
1886
-
1887
-
1888
-    /**
1889
-     * @param string $post_id
1890
-     */
1891
-    public function restore_cpt_item($post_id)
1892
-    {
1893
-        $this->_req_data['EVT_ID'] = $post_id;
1894
-        $this->_trash_or_restore_event('draft', false);
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * @param string $post_id
1900
-     */
1901
-    public function delete_cpt_item($post_id)
1902
-    {
1903
-        $this->_req_data['EVT_ID'] = $post_id;
1904
-        $this->_delete_event(false);
1905
-    }
1906
-
1907
-
1908
-    /**
1909
-     * _trash_or_restore_event
1910
-     *
1911
-     * @access protected
1912
-     * @param  string $event_status
1913
-     * @param bool    $redirect_after
1914
-     */
1915
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1916
-    {
1917
-        // determine the event id and set to array.
1918
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1919
-        // loop thru events
1920
-        if ($EVT_ID) {
1921
-            // clean status
1922
-            $event_status = sanitize_key($event_status);
1923
-            // grab status
1924
-            if (! empty($event_status)) {
1925
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1926
-            } else {
1927
-                $success = false;
1928
-                $msg = esc_html__(
1929
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1930
-                    'event_espresso'
1931
-                );
1932
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1933
-            }
1934
-        } else {
1935
-            $success = false;
1936
-            $msg = esc_html__(
1937
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1938
-                'event_espresso'
1939
-            );
1940
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1941
-        }
1942
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1943
-        if ($redirect_after) {
1944
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1945
-        }
1946
-    }
1947
-
1948
-
1949
-    /**
1950
-     * _trash_or_restore_events
1951
-     *
1952
-     * @access protected
1953
-     * @param  string $event_status
1954
-     * @return void
1955
-     */
1956
-    protected function _trash_or_restore_events($event_status = 'trash')
1957
-    {
1958
-        // clean status
1959
-        $event_status = sanitize_key($event_status);
1960
-        // grab status
1961
-        if (! empty($event_status)) {
1962
-            $success = true;
1963
-            // determine the event id and set to array.
1964
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1965
-            // loop thru events
1966
-            foreach ($EVT_IDs as $EVT_ID) {
1967
-                if ($EVT_ID = absint($EVT_ID)) {
1968
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1969
-                    $success = $results !== false ? $success : false;
1970
-                } else {
1971
-                    $msg = sprintf(
1972
-                        esc_html__(
1973
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1974
-                            'event_espresso'
1975
-                        ),
1976
-                        $EVT_ID
1977
-                    );
1978
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1979
-                    $success = false;
1980
-                }
1981
-            }
1982
-        } else {
1983
-            $success = false;
1984
-            $msg = esc_html__(
1985
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1986
-                'event_espresso'
1987
-            );
1988
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1989
-        }
1990
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1991
-        $success = $success ? 2 : false;
1992
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1993
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1994
-    }
1995
-
1996
-
1997
-    /**
1998
-     * _trash_or_restore_events
1999
-     *
2000
-     * @access  private
2001
-     * @param  int    $EVT_ID
2002
-     * @param  string $event_status
2003
-     * @return bool
2004
-     */
2005
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2006
-    {
2007
-        // grab event id
2008
-        if (! $EVT_ID) {
2009
-            $msg = esc_html__(
2010
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2011
-                'event_espresso'
2012
-            );
2013
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2014
-            return false;
2015
-        }
2016
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2017
-        // clean status
2018
-        $event_status = sanitize_key($event_status);
2019
-        // grab status
2020
-        if (empty($event_status)) {
2021
-            $msg = esc_html__(
2022
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2023
-                'event_espresso'
2024
-            );
2025
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2026
-            return false;
2027
-        }
2028
-        // was event trashed or restored ?
2029
-        switch ($event_status) {
2030
-            case 'draft':
2031
-                $action = 'restored from the trash';
2032
-                $hook = 'AHEE_event_restored_from_trash';
2033
-                break;
2034
-            case 'trash':
2035
-                $action = 'moved to the trash';
2036
-                $hook = 'AHEE_event_moved_to_trash';
2037
-                break;
2038
-            default:
2039
-                $action = 'updated';
2040
-                $hook = false;
2041
-        }
2042
-        // use class to change status
2043
-        $this->_cpt_model_obj->set_status($event_status);
2044
-        $success = $this->_cpt_model_obj->save();
2045
-        if ($success === false) {
2046
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2047
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2048
-            return false;
2049
-        }
2050
-        if ($hook) {
2051
-            do_action($hook);
2052
-        }
2053
-        return true;
2054
-    }
2055
-
2056
-
2057
-    /**
2058
-     * _delete_event
2059
-     *
2060
-     * @access protected
2061
-     * @param bool $redirect_after
2062
-     */
2063
-    protected function _delete_event($redirect_after = true)
2064
-    {
2065
-        // determine the event id and set to array.
2066
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2067
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2068
-        // loop thru events
2069
-        if ($EVT_ID) {
2070
-            $success = $this->_permanently_delete_event($EVT_ID);
2071
-            // get list of events with no prices
2072
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2073
-            // remove this event from the list of events with no prices
2074
-            if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2075
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2076
-            }
2077
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2078
-        } else {
2079
-            $success = false;
2080
-            $msg = esc_html__(
2081
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2082
-                'event_espresso'
2083
-            );
2084
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2085
-        }
2086
-        if ($redirect_after) {
2087
-            $this->_redirect_after_action(
2088
-                $success,
2089
-                'Event',
2090
-                'deleted',
2091
-                array('action' => 'default', 'status' => 'trash')
2092
-            );
2093
-        }
2094
-    }
2095
-
2096
-
2097
-    /**
2098
-     * _delete_events
2099
-     *
2100
-     * @access protected
2101
-     * @return void
2102
-     */
2103
-    protected function _delete_events()
2104
-    {
2105
-        $success = true;
2106
-        // get list of events with no prices
2107
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2108
-        // determine the event id and set to array.
2109
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2110
-        // loop thru events
2111
-        foreach ($EVT_IDs as $EVT_ID) {
2112
-            $EVT_ID = absint($EVT_ID);
2113
-            if ($EVT_ID) {
2114
-                $results = $this->_permanently_delete_event($EVT_ID);
2115
-                $success = $results !== false ? $success : false;
2116
-                // remove this event from the list of events with no prices
2117
-                unset($espresso_no_ticket_prices[ $EVT_ID ]);
2118
-            } else {
2119
-                $success = false;
2120
-                $msg = esc_html__(
2121
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2122
-                    'event_espresso'
2123
-                );
2124
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2125
-            }
2126
-        }
2127
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2128
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2129
-        $success = $success ? 2 : false;
2130
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2131
-    }
2132
-
2133
-
2134
-    /**
2135
-     * _permanently_delete_event
2136
-     *
2137
-     * @access  private
2138
-     * @param  int $EVT_ID
2139
-     * @return bool
2140
-     */
2141
-    private function _permanently_delete_event($EVT_ID = 0)
2142
-    {
2143
-        // grab event id
2144
-        if (! $EVT_ID) {
2145
-            $msg = esc_html__(
2146
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2147
-                'event_espresso'
2148
-            );
2149
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2150
-            return false;
2151
-        }
2152
-        if (! $this->_cpt_model_obj instanceof EE_Event
2153
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2154
-        ) {
2155
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2156
-        }
2157
-        if (! $this->_cpt_model_obj instanceof EE_Event) {
2158
-            return false;
2159
-        }
2160
-        // need to delete related tickets and prices first.
2161
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2162
-        foreach ($datetimes as $datetime) {
2163
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2164
-            $tickets = $datetime->get_many_related('Ticket');
2165
-            foreach ($tickets as $ticket) {
2166
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2167
-                $ticket->delete_related_permanently('Price');
2168
-                $ticket->delete_permanently();
2169
-            }
2170
-            $datetime->delete();
2171
-        }
2172
-        // what about related venues or terms?
2173
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2174
-        foreach ($venues as $venue) {
2175
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2176
-        }
2177
-        // any attached question groups?
2178
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2179
-        if (! empty($question_groups)) {
2180
-            foreach ($question_groups as $question_group) {
2181
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2182
-            }
2183
-        }
2184
-        // Message Template Groups
2185
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2186
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2187
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2188
-        foreach ($term_taxonomies as $term_taxonomy) {
2189
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2190
-        }
2191
-        $success = $this->_cpt_model_obj->delete_permanently();
2192
-        // did it all go as planned ?
2193
-        if ($success) {
2194
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2195
-            EE_Error::add_success($msg);
2196
-        } else {
2197
-            $msg = sprintf(
2198
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2199
-                $EVT_ID
2200
-            );
2201
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2202
-            return false;
2203
-        }
2204
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2205
-        return true;
2206
-    }
2207
-
2208
-
2209
-    /**
2210
-     * get total number of events
2211
-     *
2212
-     * @access public
2213
-     * @return int
2214
-     */
2215
-    public function total_events()
2216
-    {
2217
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2218
-        return $count;
2219
-    }
2220
-
2221
-
2222
-    /**
2223
-     * get total number of draft events
2224
-     *
2225
-     * @access public
2226
-     * @return int
2227
-     */
2228
-    public function total_events_draft()
2229
-    {
2230
-        $where = array(
2231
-            'status' => array('IN', array('draft', 'auto-draft')),
2232
-        );
2233
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2234
-        return $count;
2235
-    }
2236
-
2237
-
2238
-    /**
2239
-     * get total number of trashed events
2240
-     *
2241
-     * @access public
2242
-     * @return int
2243
-     */
2244
-    public function total_trashed_events()
2245
-    {
2246
-        $where = array(
2247
-            'status' => 'trash',
2248
-        );
2249
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2250
-        return $count;
2251
-    }
2252
-
2253
-
2254
-    /**
2255
-     *    _default_event_settings
2256
-     *    This generates the Default Settings Tab
2257
-     *
2258
-     * @return void
2259
-     * @throws EE_Error
2260
-     */
2261
-    protected function _default_event_settings()
2262
-    {
2263
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2264
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2265
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2266
-        $this->display_admin_page_with_sidebar();
2267
-    }
2268
-
2269
-
2270
-    /**
2271
-     * Return the form for event settings.
2272
-     *
2273
-     * @return EE_Form_Section_Proper
2274
-     * @throws EE_Error
2275
-     */
2276
-    protected function _default_event_settings_form()
2277
-    {
2278
-        $registration_config = EE_Registry::instance()->CFG->registration;
2279
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2280
-            // exclude
2281
-            array(
2282
-                EEM_Registration::status_id_cancelled,
2283
-                EEM_Registration::status_id_declined,
2284
-                EEM_Registration::status_id_incomplete,
2285
-                EEM_Registration::status_id_wait_list,
2286
-            ),
2287
-            true
2288
-        );
2289
-        return new EE_Form_Section_Proper(
2290
-            array(
2291
-                'name'            => 'update_default_event_settings',
2292
-                'html_id'         => 'update_default_event_settings',
2293
-                'html_class'      => 'form-table',
2294
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2295
-                'subsections'     => apply_filters(
2296
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2297
-                    array(
2298
-                        'default_reg_status'  => new EE_Select_Input(
2299
-                            $registration_stati_for_selection,
2300
-                            array(
2301
-                                'default'         => isset($registration_config->default_STS_ID)
2302
-                                                     && array_key_exists(
2303
-                                                         $registration_config->default_STS_ID,
2304
-                                                         $registration_stati_for_selection
2305
-                                                     )
2306
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2307
-                                    : EEM_Registration::status_id_pending_payment,
2308
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2309
-                                                     . EEH_Template::get_help_tab_link(
2310
-                                                         'default_settings_status_help_tab'
2311
-                                                     ),
2312
-                                'html_help_text'  => esc_html__(
2313
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2314
-                                    'event_espresso'
2315
-                                ),
2316
-                            )
2317
-                        ),
2318
-                        'default_max_tickets' => new EE_Integer_Input(
2319
-                            array(
2320
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2321
-                                    ? $registration_config->default_maximum_number_of_tickets
2322
-                                    : EEM_Event::get_default_additional_limit(),
2323
-                                'html_label_text' => esc_html__(
2324
-                                    'Default Maximum Tickets Allowed Per Order:',
2325
-                                    'event_espresso'
2326
-                                )
2327
-                                                     . EEH_Template::get_help_tab_link(
2328
-                                                         'default_maximum_tickets_help_tab"'
2329
-                                                     ),
2330
-                                'html_help_text'  => esc_html__(
2331
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2332
-                                    'event_espresso'
2333
-                                ),
2334
-                            )
2335
-                        ),
2336
-                    )
2337
-                ),
2338
-            )
2339
-        );
2340
-    }
2341
-
2342
-
2343
-    /**
2344
-     * @return void
2345
-     * @throws EE_Error
2346
-     * @throws InvalidArgumentException
2347
-     * @throws InvalidDataTypeException
2348
-     * @throws InvalidInterfaceException
2349
-     */
2350
-    protected function _update_default_event_settings()
2351
-    {
2352
-        $form = $this->_default_event_settings_form();
2353
-        if ($form->was_submitted()) {
2354
-            $form->receive_form_submission();
2355
-            if ($form->is_valid()) {
2356
-                $registration_config = EE_Registry::instance()->CFG->registration;
2357
-                $valid_data = $form->valid_data();
2358
-                if (isset($valid_data['default_reg_status'])) {
2359
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2360
-                }
2361
-                if (isset($valid_data['default_max_tickets'])) {
2362
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2363
-                }
2364
-                do_action(
2365
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2366
-                    $valid_data,
2367
-                    EE_Registry::instance()->CFG,
2368
-                    $this
2369
-                );
2370
-                // update because data was valid!
2371
-                EE_Registry::instance()->CFG->update_espresso_config();
2372
-                EE_Error::overwrite_success();
2373
-                EE_Error::add_success(
2374
-                    __('Default Event Settings were updated', 'event_espresso')
2375
-                );
2376
-            }
2377
-        }
2378
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2379
-    }
2380
-
2381
-
2382
-    /*************        Templates        *************/
2383
-    protected function _template_settings()
2384
-    {
2385
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2386
-        $this->_template_args['preview_img'] = '<img src="'
2387
-                                               . EVENTS_ASSETS_URL
2388
-                                               . DS
2389
-                                               . 'images'
2390
-                                               . DS
2391
-                                               . 'caffeinated_template_features.jpg" alt="'
2392
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2393
-                                               . '" />';
2394
-        $this->_template_args['preview_text'] = '<strong>'
2395
-                                                . esc_html__(
2396
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2397
-                                                    'event_espresso'
2398
-                                                ) . '</strong>';
2399
-        $this->display_admin_caf_preview_page('template_settings_tab');
2400
-    }
2401
-
2402
-
2403
-    /** Event Category Stuff **/
2404
-    /**
2405
-     * set the _category property with the category object for the loaded page.
2406
-     *
2407
-     * @access private
2408
-     * @return void
2409
-     */
2410
-    private function _set_category_object()
2411
-    {
2412
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2413
-            return;
2414
-        } //already have the category object so get out.
2415
-        // set default category object
2416
-        $this->_set_empty_category_object();
2417
-        // only set if we've got an id
2418
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2419
-            return;
2420
-        }
2421
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2422
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2423
-        if (! empty($term)) {
2424
-            $this->_category->category_name = $term->name;
2425
-            $this->_category->category_identifier = $term->slug;
2426
-            $this->_category->category_desc = $term->description;
2427
-            $this->_category->id = $term->term_id;
2428
-            $this->_category->parent = $term->parent;
2429
-        }
2430
-    }
2431
-
2432
-
2433
-    /**
2434
-     * Clears out category properties.
2435
-     */
2436
-    private function _set_empty_category_object()
2437
-    {
2438
-        $this->_category = new stdClass();
2439
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2440
-        $this->_category->id = $this->_category->parent = 0;
2441
-    }
2442
-
2443
-
2444
-    /**
2445
-     * @throws EE_Error
2446
-     */
2447
-    protected function _category_list_table()
2448
-    {
2449
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2450
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2451
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2452
-            'add_category',
2453
-            'add_category',
2454
-            array(),
2455
-            'add-new-h2'
2456
-        );
2457
-        $this->display_admin_list_table_page_with_sidebar();
2458
-    }
2459
-
2460
-
2461
-    /**
2462
-     * Output category details view.
2463
-     */
2464
-    protected function _category_details($view)
2465
-    {
2466
-        // load formatter helper
2467
-        // load field generator helper
2468
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2469
-        $this->_set_add_edit_form_tags($route);
2470
-        $this->_set_category_object();
2471
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2472
-        $delete_action = 'delete_category';
2473
-        // custom redirect
2474
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2475
-            array('action' => 'category_list'),
2476
-            $this->_admin_base_url
2477
-        );
2478
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2479
-        // take care of contents
2480
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2481
-        $this->display_admin_page_with_sidebar();
2482
-    }
2483
-
2484
-
2485
-    /**
2486
-     * Output category details content.
2487
-     */
2488
-    protected function _category_details_content()
2489
-    {
2490
-        $editor_args['category_desc'] = array(
2491
-            'type'          => 'wp_editor',
2492
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2493
-            'class'         => 'my_editor_custom',
2494
-            'wpeditor_args' => array('media_buttons' => false),
2495
-        );
2496
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2497
-        $all_terms = get_terms(
2498
-            array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2499
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2500
-        );
2501
-        // setup category select for term parents.
2502
-        $category_select_values[] = array(
2503
-            'text' => esc_html__('No Parent', 'event_espresso'),
2504
-            'id'   => 0,
2505
-        );
2506
-        foreach ($all_terms as $term) {
2507
-            $category_select_values[] = array(
2508
-                'text' => $term->name,
2509
-                'id'   => $term->term_id,
2510
-            );
2511
-        }
2512
-        $category_select = EEH_Form_Fields::select_input(
2513
-            'category_parent',
2514
-            $category_select_values,
2515
-            $this->_category->parent
2516
-        );
2517
-        $template_args = array(
2518
-            'category'                 => $this->_category,
2519
-            'category_select'          => $category_select,
2520
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2521
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2522
-            'disable'                  => '',
2523
-            'disabled_message'         => false,
2524
-        );
2525
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2526
-        return EEH_Template::display_template($template, $template_args, true);
2527
-    }
2528
-
2529
-
2530
-    /**
2531
-     * Handles deleting categories.
2532
-     */
2533
-    protected function _delete_categories()
2534
-    {
2535
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2536
-            : (array) $this->_req_data['category_id'];
2537
-        foreach ($cat_ids as $cat_id) {
2538
-            $this->_delete_category($cat_id);
2539
-        }
2540
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2541
-        $query_args = array(
2542
-            'action' => 'category_list',
2543
-        );
2544
-        $this->_redirect_after_action(0, '', '', $query_args);
2545
-    }
2546
-
2547
-
2548
-    /**
2549
-     * Handles deleting specific category.
2550
-     *
2551
-     * @param int $cat_id
2552
-     */
2553
-    protected function _delete_category($cat_id)
2554
-    {
2555
-        $cat_id = absint($cat_id);
2556
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2557
-    }
2558
-
2559
-
2560
-    /**
2561
-     * Handles triggering the update or insertion of a new category.
2562
-     *
2563
-     * @param bool $new_category true means we're triggering the insert of a new category.
2564
-     */
2565
-    protected function _insert_or_update_category($new_category)
2566
-    {
2567
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2568
-        $success = 0; // we already have a success message so lets not send another.
2569
-        if ($cat_id) {
2570
-            $query_args = array(
2571
-                'action'     => 'edit_category',
2572
-                'EVT_CAT_ID' => $cat_id,
2573
-            );
2574
-        } else {
2575
-            $query_args = array('action' => 'add_category');
2576
-        }
2577
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2578
-    }
2579
-
2580
-
2581
-    /**
2582
-     * Inserts or updates category
2583
-     *
2584
-     * @param bool $update (true indicates we're updating a category).
2585
-     * @return bool|mixed|string
2586
-     */
2587
-    private function _insert_category($update = false)
2588
-    {
2589
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2590
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2591
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2592
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2593
-        if (empty($category_name)) {
2594
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2595
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2596
-            return false;
2597
-        }
2598
-        $term_args = array(
2599
-            'name'        => $category_name,
2600
-            'description' => $category_desc,
2601
-            'parent'      => $category_parent,
2602
-        );
2603
-        // was the category_identifier input disabled?
2604
-        if (isset($this->_req_data['category_identifier'])) {
2605
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2606
-        }
2607
-        $insert_ids = $update
2608
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2609
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2610
-        if (! is_array($insert_ids)) {
2611
-            $msg = esc_html__(
2612
-                'An error occurred and the category has not been saved to the database.',
2613
-                'event_espresso'
2614
-            );
2615
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2616
-        } else {
2617
-            $cat_id = $insert_ids['term_id'];
2618
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2619
-            EE_Error::add_success($msg);
2620
-        }
2621
-        return $cat_id;
2622
-    }
2623
-
2624
-
2625
-    /**
2626
-     * Gets categories or count of categories matching the arguments in the request.
2627
-     *
2628
-     * @param int  $per_page
2629
-     * @param int  $current_page
2630
-     * @param bool $count
2631
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2632
-     */
2633
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2634
-    {
2635
-        // testing term stuff
2636
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2637
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2638
-        $limit = ($current_page - 1) * $per_page;
2639
-        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2640
-        if (isset($this->_req_data['s'])) {
2641
-            $sstr = '%' . $this->_req_data['s'] . '%';
2642
-            $where['OR'] = array(
2643
-                'Term.name'   => array('LIKE', $sstr),
2644
-                'description' => array('LIKE', $sstr),
2645
-            );
2646
-        }
2647
-        $query_params = array(
2648
-            $where,
2649
-            'order_by'   => array($orderby => $order),
2650
-            'limit'      => $limit . ',' . $per_page,
2651
-            'force_join' => array('Term'),
2652
-        );
2653
-        $categories = $count
2654
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2655
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2656
-        return $categories;
2657
-    }
2658
-
2659
-    /* end category stuff */
2660
-    /**************/
2661
-
2662
-
2663
-    /**
2664
-     * Callback for the `ee_save_timezone_setting` ajax action.
2665
-     *
2666
-     * @throws EE_Error
2667
-     */
2668
-    public function save_timezonestring_setting()
2669
-    {
2670
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2671
-            ? $this->_req_data['timezone_selected']
2672
-            : '';
2673
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2674
-            EE_Error::add_error(
2675
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2676
-                __FILE__,
2677
-                __FUNCTION__,
2678
-                __LINE__
2679
-            );
2680
-            $this->_template_args['error'] = true;
2681
-            $this->_return_json();
2682
-        }
2683
-
2684
-        update_option('timezone_string', $timezone_string);
2685
-        EE_Error::add_success(
2686
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2687
-        );
2688
-        $this->_template_args['success'] = true;
2689
-        $this->_return_json(true, array('action' => 'create_new'));
2690
-    }
18
+	/**
19
+	 * This will hold the event object for event_details screen.
20
+	 *
21
+	 * @access protected
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * Initialize page props for this admin page group.
51
+	 */
52
+	protected function _init_page_props()
53
+	{
54
+		$this->page_slug = EVENTS_PG_SLUG;
55
+		$this->page_label = EVENTS_LABEL;
56
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
57
+		$this->_admin_base_path = EVENTS_ADMIN;
58
+		$this->_cpt_model_names = array(
59
+			'create_new' => 'EEM_Event',
60
+			'edit'       => 'EEM_Event',
61
+		);
62
+		$this->_cpt_edit_routes = array(
63
+			'espresso_events' => 'edit',
64
+		);
65
+		add_action(
66
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
+			array($this, 'verify_event_edit'),
68
+			10,
69
+			2
70
+		);
71
+	}
72
+
73
+
74
+	/**
75
+	 * Sets the ajax hooks used for this admin page group.
76
+	 */
77
+	protected function _ajax_hooks()
78
+	{
79
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets the page properties for this admin page group.
85
+	 */
86
+	protected function _define_page_props()
87
+	{
88
+		$this->_admin_page_title = EVENTS_LABEL;
89
+		$this->_labels = array(
90
+			'buttons'      => array(
91
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
92
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
93
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
94
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
95
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
96
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
97
+			),
98
+			'editor_title' => array(
99
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
100
+			),
101
+			'publishbox'   => array(
102
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
103
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
104
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
105
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
106
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
107
+			),
108
+		);
109
+	}
110
+
111
+
112
+	/**
113
+	 * Sets the page routes property for this admin page group.
114
+	 */
115
+	protected function _set_page_routes()
116
+	{
117
+		// load formatter helper
118
+		// load field generator helper
119
+		// is there a evt_id in the request?
120
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
121
+			? $this->_req_data['EVT_ID']
122
+			: 0;
123
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
124
+		$this->_page_routes = array(
125
+			'default'                       => array(
126
+				'func'       => '_events_overview_list_table',
127
+				'capability' => 'ee_read_events',
128
+			),
129
+			'create_new'                    => array(
130
+				'func'       => '_create_new_cpt_item',
131
+				'capability' => 'ee_edit_events',
132
+			),
133
+			'edit'                          => array(
134
+				'func'       => '_edit_cpt_item',
135
+				'capability' => 'ee_edit_event',
136
+				'obj_id'     => $evt_id,
137
+			),
138
+			'copy_event'                    => array(
139
+				'func'       => '_copy_events',
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $evt_id,
142
+				'noheader'   => true,
143
+			),
144
+			'trash_event'                   => array(
145
+				'func'       => '_trash_or_restore_event',
146
+				'args'       => array('event_status' => 'trash'),
147
+				'capability' => 'ee_delete_event',
148
+				'obj_id'     => $evt_id,
149
+				'noheader'   => true,
150
+			),
151
+			'trash_events'                  => array(
152
+				'func'       => '_trash_or_restore_events',
153
+				'args'       => array('event_status' => 'trash'),
154
+				'capability' => 'ee_delete_events',
155
+				'noheader'   => true,
156
+			),
157
+			'restore_event'                 => array(
158
+				'func'       => '_trash_or_restore_event',
159
+				'args'       => array('event_status' => 'draft'),
160
+				'capability' => 'ee_delete_event',
161
+				'obj_id'     => $evt_id,
162
+				'noheader'   => true,
163
+			),
164
+			'restore_events'                => array(
165
+				'func'       => '_trash_or_restore_events',
166
+				'args'       => array('event_status' => 'draft'),
167
+				'capability' => 'ee_delete_events',
168
+				'noheader'   => true,
169
+			),
170
+			'delete_event'                  => array(
171
+				'func'       => '_delete_event',
172
+				'capability' => 'ee_delete_event',
173
+				'obj_id'     => $evt_id,
174
+				'noheader'   => true,
175
+			),
176
+			'delete_events'                 => array(
177
+				'func'       => '_delete_events',
178
+				'capability' => 'ee_delete_events',
179
+				'noheader'   => true,
180
+			),
181
+			'view_report'                   => array(
182
+				'func'      => '_view_report',
183
+				'capablity' => 'ee_edit_events',
184
+			),
185
+			'default_event_settings'        => array(
186
+				'func'       => '_default_event_settings',
187
+				'capability' => 'manage_options',
188
+			),
189
+			'update_default_event_settings' => array(
190
+				'func'       => '_update_default_event_settings',
191
+				'capability' => 'manage_options',
192
+				'noheader'   => true,
193
+			),
194
+			'template_settings'             => array(
195
+				'func'       => '_template_settings',
196
+				'capability' => 'manage_options',
197
+			),
198
+			// event category tab related
199
+			'add_category'                  => array(
200
+				'func'       => '_category_details',
201
+				'capability' => 'ee_edit_event_category',
202
+				'args'       => array('add'),
203
+			),
204
+			'edit_category'                 => array(
205
+				'func'       => '_category_details',
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => array('edit'),
208
+			),
209
+			'delete_categories'             => array(
210
+				'func'       => '_delete_categories',
211
+				'capability' => 'ee_delete_event_category',
212
+				'noheader'   => true,
213
+			),
214
+			'delete_category'               => array(
215
+				'func'       => '_delete_categories',
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			),
219
+			'insert_category'               => array(
220
+				'func'       => '_insert_or_update_category',
221
+				'args'       => array('new_category' => true),
222
+				'capability' => 'ee_edit_event_category',
223
+				'noheader'   => true,
224
+			),
225
+			'update_category'               => array(
226
+				'func'       => '_insert_or_update_category',
227
+				'args'       => array('new_category' => false),
228
+				'capability' => 'ee_edit_event_category',
229
+				'noheader'   => true,
230
+			),
231
+			'category_list'                 => array(
232
+				'func'       => '_category_list_table',
233
+				'capability' => 'ee_manage_event_categories',
234
+			),
235
+		);
236
+	}
237
+
238
+
239
+	/**
240
+	 * Set the _page_config property for this admin page group.
241
+	 */
242
+	protected function _set_page_config()
243
+	{
244
+		$this->_page_config = array(
245
+			'default'                => array(
246
+				'nav'           => array(
247
+					'label' => esc_html__('Overview', 'event_espresso'),
248
+					'order' => 10,
249
+				),
250
+				'list_table'    => 'Events_Admin_List_Table',
251
+				'help_tabs'     => array(
252
+					'events_overview_help_tab'                       => array(
253
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
254
+						'filename' => 'events_overview',
255
+					),
256
+					'events_overview_table_column_headings_help_tab' => array(
257
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
258
+						'filename' => 'events_overview_table_column_headings',
259
+					),
260
+					'events_overview_filters_help_tab'               => array(
261
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
262
+						'filename' => 'events_overview_filters',
263
+					),
264
+					'events_overview_view_help_tab'                  => array(
265
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
266
+						'filename' => 'events_overview_views',
267
+					),
268
+					'events_overview_other_help_tab'                 => array(
269
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
270
+						'filename' => 'events_overview_other',
271
+					),
272
+				),
273
+				'help_tour'     => array(
274
+					'Event_Overview_Help_Tour',
275
+					// 'New_Features_Test_Help_Tour' for testing multiple help tour
276
+				),
277
+				'qtips'         => array(
278
+					'EE_Event_List_Table_Tips',
279
+				),
280
+				'require_nonce' => false,
281
+			),
282
+			'create_new'             => array(
283
+				'nav'           => array(
284
+					'label'      => esc_html__('Add Event', 'event_espresso'),
285
+					'order'      => 5,
286
+					'persistent' => false,
287
+				),
288
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
289
+				'help_tabs'     => array(
290
+					'event_editor_help_tab'                            => array(
291
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
292
+						'filename' => 'event_editor',
293
+					),
294
+					'event_editor_title_richtexteditor_help_tab'       => array(
295
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
296
+						'filename' => 'event_editor_title_richtexteditor',
297
+					),
298
+					'event_editor_venue_details_help_tab'              => array(
299
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
300
+						'filename' => 'event_editor_venue_details',
301
+					),
302
+					'event_editor_event_datetimes_help_tab'            => array(
303
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
304
+						'filename' => 'event_editor_event_datetimes',
305
+					),
306
+					'event_editor_event_tickets_help_tab'              => array(
307
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
308
+						'filename' => 'event_editor_event_tickets',
309
+					),
310
+					'event_editor_event_registration_options_help_tab' => array(
311
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
312
+						'filename' => 'event_editor_event_registration_options',
313
+					),
314
+					'event_editor_tags_categories_help_tab'            => array(
315
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
316
+						'filename' => 'event_editor_tags_categories',
317
+					),
318
+					'event_editor_questions_registrants_help_tab'      => array(
319
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
320
+						'filename' => 'event_editor_questions_registrants',
321
+					),
322
+					'event_editor_save_new_event_help_tab'             => array(
323
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
324
+						'filename' => 'event_editor_save_new_event',
325
+					),
326
+					'event_editor_other_help_tab'                      => array(
327
+						'title'    => esc_html__('Event Other', 'event_espresso'),
328
+						'filename' => 'event_editor_other',
329
+					),
330
+				),
331
+				'help_tour'     => array(
332
+					'Event_Editor_Help_Tour',
333
+				),
334
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
335
+				'require_nonce' => false,
336
+			),
337
+			'edit'                   => array(
338
+				'nav'           => array(
339
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
340
+					'order'      => 5,
341
+					'persistent' => false,
342
+					'url'        => isset($this->_req_data['post'])
343
+						? EE_Admin_Page::add_query_args_and_nonce(
344
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
345
+							$this->_current_page_view_url
346
+						)
347
+						: $this->_admin_base_url,
348
+				),
349
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
350
+				'help_tabs'     => array(
351
+					'event_editor_help_tab'                            => array(
352
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
353
+						'filename' => 'event_editor',
354
+					),
355
+					'event_editor_title_richtexteditor_help_tab'       => array(
356
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
357
+						'filename' => 'event_editor_title_richtexteditor',
358
+					),
359
+					'event_editor_venue_details_help_tab'              => array(
360
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
361
+						'filename' => 'event_editor_venue_details',
362
+					),
363
+					'event_editor_event_datetimes_help_tab'            => array(
364
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
365
+						'filename' => 'event_editor_event_datetimes',
366
+					),
367
+					'event_editor_event_tickets_help_tab'              => array(
368
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
369
+						'filename' => 'event_editor_event_tickets',
370
+					),
371
+					'event_editor_event_registration_options_help_tab' => array(
372
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
373
+						'filename' => 'event_editor_event_registration_options',
374
+					),
375
+					'event_editor_tags_categories_help_tab'            => array(
376
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
377
+						'filename' => 'event_editor_tags_categories',
378
+					),
379
+					'event_editor_questions_registrants_help_tab'      => array(
380
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
381
+						'filename' => 'event_editor_questions_registrants',
382
+					),
383
+					'event_editor_save_new_event_help_tab'             => array(
384
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
385
+						'filename' => 'event_editor_save_new_event',
386
+					),
387
+					'event_editor_other_help_tab'                      => array(
388
+						'title'    => esc_html__('Event Other', 'event_espresso'),
389
+						'filename' => 'event_editor_other',
390
+					),
391
+				),
392
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
393
+				'require_nonce' => false,
394
+			),
395
+			'default_event_settings' => array(
396
+				'nav'           => array(
397
+					'label' => esc_html__('Default Settings', 'event_espresso'),
398
+					'order' => 40,
399
+				),
400
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
401
+				'labels'        => array(
402
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
403
+				),
404
+				'help_tabs'     => array(
405
+					'default_settings_help_tab'        => array(
406
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
407
+						'filename' => 'events_default_settings',
408
+					),
409
+					'default_settings_status_help_tab' => array(
410
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
411
+						'filename' => 'events_default_settings_status',
412
+					),
413
+					'default_maximum_tickets_help_tab' => array(
414
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
415
+						'filename' => 'events_default_settings_max_tickets',
416
+					),
417
+				),
418
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
419
+				'require_nonce' => false,
420
+			),
421
+			// template settings
422
+			'template_settings'      => array(
423
+				'nav'           => array(
424
+					'label' => esc_html__('Templates', 'event_espresso'),
425
+					'order' => 30,
426
+				),
427
+				'metaboxes'     => $this->_default_espresso_metaboxes,
428
+				'help_tabs'     => array(
429
+					'general_settings_templates_help_tab' => array(
430
+						'title'    => esc_html__('Templates', 'event_espresso'),
431
+						'filename' => 'general_settings_templates',
432
+					),
433
+				),
434
+				'help_tour'     => array('Templates_Help_Tour'),
435
+				'require_nonce' => false,
436
+			),
437
+			// event category stuff
438
+			'add_category'           => array(
439
+				'nav'           => array(
440
+					'label'      => esc_html__('Add Category', 'event_espresso'),
441
+					'order'      => 15,
442
+					'persistent' => false,
443
+				),
444
+				'help_tabs'     => array(
445
+					'add_category_help_tab' => array(
446
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
447
+						'filename' => 'events_add_category',
448
+					),
449
+				),
450
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
451
+				'metaboxes'     => array('_publish_post_box'),
452
+				'require_nonce' => false,
453
+			),
454
+			'edit_category'          => array(
455
+				'nav'           => array(
456
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
457
+					'order'      => 15,
458
+					'persistent' => false,
459
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
460
+						? add_query_arg(
461
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
462
+							$this->_current_page_view_url
463
+						)
464
+						: $this->_admin_base_url,
465
+				),
466
+				'help_tabs'     => array(
467
+					'edit_category_help_tab' => array(
468
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
469
+						'filename' => 'events_edit_category',
470
+					),
471
+				),
472
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
473
+				'metaboxes'     => array('_publish_post_box'),
474
+				'require_nonce' => false,
475
+			),
476
+			'category_list'          => array(
477
+				'nav'           => array(
478
+					'label' => esc_html__('Categories', 'event_espresso'),
479
+					'order' => 20,
480
+				),
481
+				'list_table'    => 'Event_Categories_Admin_List_Table',
482
+				'help_tabs'     => array(
483
+					'events_categories_help_tab'                       => array(
484
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
485
+						'filename' => 'events_categories',
486
+					),
487
+					'events_categories_table_column_headings_help_tab' => array(
488
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
489
+						'filename' => 'events_categories_table_column_headings',
490
+					),
491
+					'events_categories_view_help_tab'                  => array(
492
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
493
+						'filename' => 'events_categories_views',
494
+					),
495
+					'events_categories_other_help_tab'                 => array(
496
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
497
+						'filename' => 'events_categories_other',
498
+					),
499
+				),
500
+				'help_tour'     => array(
501
+					'Event_Categories_Help_Tour',
502
+				),
503
+				'metaboxes'     => $this->_default_espresso_metaboxes,
504
+				'require_nonce' => false,
505
+			),
506
+		);
507
+	}
508
+
509
+
510
+	/**
511
+	 * Used to register any global screen options if necessary for every route in this admin page group.
512
+	 */
513
+	protected function _add_screen_options()
514
+	{
515
+	}
516
+
517
+
518
+	/**
519
+	 * Implementing the screen options for the 'default' route.
520
+	 */
521
+	protected function _add_screen_options_default()
522
+	{
523
+		$this->_per_page_screen_option();
524
+	}
525
+
526
+
527
+	/**
528
+	 * Implementing screen options for the category list route.
529
+	 */
530
+	protected function _add_screen_options_category_list()
531
+	{
532
+		$page_title = $this->_admin_page_title;
533
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
534
+		$this->_per_page_screen_option();
535
+		$this->_admin_page_title = $page_title;
536
+	}
537
+
538
+
539
+	/**
540
+	 * Used to register any global feature pointers for the admin page group.
541
+	 */
542
+	protected function _add_feature_pointers()
543
+	{
544
+	}
545
+
546
+
547
+	/**
548
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
549
+	 */
550
+	public function load_scripts_styles()
551
+	{
552
+		wp_register_style(
553
+			'events-admin-css',
554
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
555
+			array(),
556
+			EVENT_ESPRESSO_VERSION
557
+		);
558
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
559
+		wp_enqueue_style('events-admin-css');
560
+		wp_enqueue_style('ee-cat-admin');
561
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
562
+		// registers for all views
563
+		// scripts
564
+		wp_register_script(
565
+			'event_editor_js',
566
+			EVENTS_ASSETS_URL . 'event_editor.js',
567
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
568
+			EVENT_ESPRESSO_VERSION,
569
+			true
570
+		);
571
+	}
572
+
573
+
574
+	/**
575
+	 * Enqueuing scripts and styles specific to this view
576
+	 */
577
+	public function load_scripts_styles_create_new()
578
+	{
579
+		$this->load_scripts_styles_edit();
580
+	}
581
+
582
+
583
+	/**
584
+	 * Enqueuing scripts and styles specific to this view
585
+	 */
586
+	public function load_scripts_styles_edit()
587
+	{
588
+		// styles
589
+		wp_enqueue_style('espresso-ui-theme');
590
+		wp_register_style(
591
+			'event-editor-css',
592
+			EVENTS_ASSETS_URL . 'event-editor.css',
593
+			array('ee-admin-css'),
594
+			EVENT_ESPRESSO_VERSION
595
+		);
596
+		wp_enqueue_style('event-editor-css');
597
+		// scripts
598
+		wp_register_script(
599
+			'event-datetime-metabox',
600
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
601
+			array('event_editor_js', 'ee-datepicker'),
602
+			EVENT_ESPRESSO_VERSION
603
+		);
604
+		wp_enqueue_script('event-datetime-metabox');
605
+	}
606
+
607
+
608
+	/**
609
+	 * Populating the _views property for the category list table view.
610
+	 */
611
+	protected function _set_list_table_views_category_list()
612
+	{
613
+		$this->_views = array(
614
+			'all' => array(
615
+				'slug'        => 'all',
616
+				'label'       => esc_html__('All', 'event_espresso'),
617
+				'count'       => 0,
618
+				'bulk_action' => array(
619
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
620
+				),
621
+			),
622
+		);
623
+	}
624
+
625
+
626
+	/**
627
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
628
+	 */
629
+	public function admin_init()
630
+	{
631
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
632
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
633
+			'event_espresso'
634
+		);
635
+	}
636
+
637
+
638
+	/**
639
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
640
+	 * group.
641
+	 */
642
+	public function admin_notices()
643
+	{
644
+	}
645
+
646
+
647
+	/**
648
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
649
+	 * this admin page group.
650
+	 */
651
+	public function admin_footer_scripts()
652
+	{
653
+	}
654
+
655
+
656
+	/**
657
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
658
+	 * warning (via EE_Error::add_error());
659
+	 *
660
+	 * @param  EE_Event $event Event object
661
+	 * @param string    $req_type
662
+	 * @return void
663
+	 * @throws EE_Error
664
+	 * @access public
665
+	 */
666
+	public function verify_event_edit($event = null, $req_type = '')
667
+	{
668
+		// don't need to do this when processing
669
+		if (! empty($req_type)) {
670
+			return;
671
+		}
672
+		// no event?
673
+		if (empty($event)) {
674
+			// set event
675
+			$event = $this->_cpt_model_obj;
676
+		}
677
+		// STILL no event?
678
+		if (! $event instanceof EE_Event) {
679
+			return;
680
+		}
681
+		$orig_status = $event->status();
682
+		// first check if event is active.
683
+		if ($orig_status === EEM_Event::cancelled
684
+			|| $orig_status === EEM_Event::postponed
685
+			|| $event->is_expired()
686
+			|| $event->is_inactive()
687
+		) {
688
+			return;
689
+		}
690
+		// made it here so it IS active... next check that any of the tickets are sold.
691
+		if ($event->is_sold_out(true)) {
692
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
693
+				EE_Error::add_attention(
694
+					sprintf(
695
+						esc_html__(
696
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
697
+							'event_espresso'
698
+						),
699
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
700
+					)
701
+				);
702
+			}
703
+			return;
704
+		} elseif ($orig_status === EEM_Event::sold_out) {
705
+			EE_Error::add_attention(
706
+				sprintf(
707
+					esc_html__(
708
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
709
+						'event_espresso'
710
+					),
711
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
712
+				)
713
+			);
714
+		}
715
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
716
+		if (! $event->tickets_on_sale()) {
717
+			return;
718
+		}
719
+		// made it here so show warning
720
+		$this->_edit_event_warning();
721
+	}
722
+
723
+
724
+	/**
725
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
726
+	 * When needed, hook this into a EE_Error::add_error() notice.
727
+	 *
728
+	 * @access protected
729
+	 * @return void
730
+	 */
731
+	protected function _edit_event_warning()
732
+	{
733
+		// we don't want to add warnings during these requests
734
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
735
+			return;
736
+		}
737
+		EE_Error::add_attention(
738
+			sprintf(
739
+				esc_html__(
740
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
741
+					'event_espresso'
742
+				),
743
+				'<a class="espresso-help-tab-lnk">',
744
+				'</a>'
745
+			)
746
+		);
747
+	}
748
+
749
+
750
+	/**
751
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
752
+	 * Otherwise, do the normal logic
753
+	 *
754
+	 * @return string
755
+	 * @throws \EE_Error
756
+	 */
757
+	protected function _create_new_cpt_item()
758
+	{
759
+		$has_timezone_string = get_option('timezone_string');
760
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
761
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
762
+			EE_Error::add_attention(
763
+				sprintf(
764
+					__(
765
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
766
+						'event_espresso'
767
+					),
768
+					'<br>',
769
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
770
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
771
+					. '</select>',
772
+					'<button class="button button-secondary timezone-submit">',
773
+					'</button><span class="spinner"></span>'
774
+				),
775
+				__FILE__,
776
+				__FUNCTION__,
777
+				__LINE__
778
+			);
779
+		}
780
+		return parent::_create_new_cpt_item();
781
+	}
782
+
783
+
784
+	/**
785
+	 * Sets the _views property for the default route in this admin page group.
786
+	 */
787
+	protected function _set_list_table_views_default()
788
+	{
789
+		$this->_views = array(
790
+			'all'   => array(
791
+				'slug'        => 'all',
792
+				'label'       => esc_html__('View All Events', 'event_espresso'),
793
+				'count'       => 0,
794
+				'bulk_action' => array(
795
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
796
+				),
797
+			),
798
+			'draft' => array(
799
+				'slug'        => 'draft',
800
+				'label'       => esc_html__('Draft', 'event_espresso'),
801
+				'count'       => 0,
802
+				'bulk_action' => array(
803
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
804
+				),
805
+			),
806
+		);
807
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
808
+			$this->_views['trash'] = array(
809
+				'slug'        => 'trash',
810
+				'label'       => esc_html__('Trash', 'event_espresso'),
811
+				'count'       => 0,
812
+				'bulk_action' => array(
813
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
814
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
815
+				),
816
+			);
817
+		}
818
+	}
819
+
820
+
821
+	/**
822
+	 * Provides the legend item array for the default list table view.
823
+	 *
824
+	 * @return array
825
+	 */
826
+	protected function _event_legend_items()
827
+	{
828
+		$items = array(
829
+			'view_details'   => array(
830
+				'class' => 'dashicons dashicons-search',
831
+				'desc'  => esc_html__('View Event', 'event_espresso'),
832
+			),
833
+			'edit_event'     => array(
834
+				'class' => 'ee-icon ee-icon-calendar-edit',
835
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
836
+			),
837
+			'view_attendees' => array(
838
+				'class' => 'dashicons dashicons-groups',
839
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
840
+			),
841
+		);
842
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
843
+		$statuses = array(
844
+			'sold_out_status'  => array(
845
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
846
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
847
+			),
848
+			'active_status'    => array(
849
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
850
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
851
+			),
852
+			'upcoming_status'  => array(
853
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
854
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
855
+			),
856
+			'postponed_status' => array(
857
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
858
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
859
+			),
860
+			'cancelled_status' => array(
861
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
862
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
863
+			),
864
+			'expired_status'   => array(
865
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
866
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
867
+			),
868
+			'inactive_status'  => array(
869
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
870
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
871
+			),
872
+		);
873
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
874
+		return array_merge($items, $statuses);
875
+	}
876
+
877
+
878
+	/**
879
+	 * @return EEM_Event
880
+	 */
881
+	private function _event_model()
882
+	{
883
+		if (! $this->_event_model instanceof EEM_Event) {
884
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
885
+		}
886
+		return $this->_event_model;
887
+	}
888
+
889
+
890
+	/**
891
+	 * Adds extra buttons to the WP CPT permalink field row.
892
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
893
+	 *
894
+	 * @param  string $return    the current html
895
+	 * @param  int    $id        the post id for the page
896
+	 * @param  string $new_title What the title is
897
+	 * @param  string $new_slug  what the slug is
898
+	 * @return string            The new html string for the permalink area
899
+	 */
900
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
901
+	{
902
+		// make sure this is only when editing
903
+		if (! empty($id)) {
904
+			$post = get_post($id);
905
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
906
+					   . esc_html__('Shortcode', 'event_espresso')
907
+					   . '</a> ';
908
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
909
+					   . $post->ID
910
+					   . ']">';
911
+		}
912
+		return $return;
913
+	}
914
+
915
+
916
+	/**
917
+	 * _events_overview_list_table
918
+	 * This contains the logic for showing the events_overview list
919
+	 *
920
+	 * @access protected
921
+	 * @return void
922
+	 * @throws \EE_Error
923
+	 */
924
+	protected function _events_overview_list_table()
925
+	{
926
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
927
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
928
+			? (array) $this->_template_args['after_list_table']
929
+			: array();
930
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
931
+				. EEH_Template::get_button_or_link(
932
+					get_post_type_archive_link('espresso_events'),
933
+					esc_html__("View Event Archive Page", "event_espresso"),
934
+					'button'
935
+				);
936
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
937
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
938
+			'create_new',
939
+			'add',
940
+			array(),
941
+			'add-new-h2'
942
+		);
943
+		$this->display_admin_list_table_page_with_no_sidebar();
944
+	}
945
+
946
+
947
+	/**
948
+	 * this allows for extra misc actions in the default WP publish box
949
+	 *
950
+	 * @return void
951
+	 */
952
+	public function extra_misc_actions_publish_box()
953
+	{
954
+		$this->_generate_publish_box_extra_content();
955
+	}
956
+
957
+
958
+	/**
959
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
960
+	 * saved.
961
+	 * Typically you would use this to save any additional data.
962
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
963
+	 * ALSO very important.  When a post transitions from scheduled to published,
964
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
965
+	 * other meta saves. So MAKE sure that you handle this accordingly.
966
+	 *
967
+	 * @access protected
968
+	 * @abstract
969
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
970
+	 * @param  object $post    The post object of the cpt that was saved.
971
+	 * @return void
972
+	 * @throws \EE_Error
973
+	 */
974
+	protected function _insert_update_cpt_item($post_id, $post)
975
+	{
976
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
977
+			// get out we're not processing an event save.
978
+			return;
979
+		}
980
+		$event_values = array(
981
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
982
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
983
+			'EVT_additional_limit'            => min(
984
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
985
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
986
+			),
987
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
988
+				? $this->_req_data['EVT_default_registration_status']
989
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
990
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
991
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
992
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
993
+				? $this->_req_data['timezone_string'] : null,
994
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
995
+				? $this->_req_data['externalURL'] : null,
996
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
997
+				? $this->_req_data['event_phone'] : null,
998
+		);
999
+		// update event
1000
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1001
+		// get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1002
+		$get_one_where = array(
1003
+			$this->_event_model()->primary_key_name() => $post_id,
1004
+			'OR'                                      => array(
1005
+				'status'   => $post->post_status,
1006
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1007
+				// but the returned object here has a status of "publish", so use the original post status as well
1008
+				'status*1' => $this->_req_data['original_post_status'],
1009
+			),
1010
+		);
1011
+		$event = $this->_event_model()->get_one(array($get_one_where));
1012
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1013
+		$event_update_callbacks = apply_filters(
1014
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1015
+			array(
1016
+				array($this, '_default_venue_update'),
1017
+				array($this, '_default_tickets_update'),
1018
+			)
1019
+		);
1020
+		$att_success = true;
1021
+		foreach ($event_update_callbacks as $e_callback) {
1022
+			$_success = is_callable($e_callback)
1023
+				? call_user_func($e_callback, $event, $this->_req_data)
1024
+				: false;
1025
+			// if ANY of these updates fail then we want the appropriate global error message
1026
+			$att_success = ! $att_success ? $att_success : $_success;
1027
+		}
1028
+		// any errors?
1029
+		if ($success && false === $att_success) {
1030
+			EE_Error::add_error(
1031
+				esc_html__(
1032
+					'Event Details saved successfully but something went wrong with saving attachments.',
1033
+					'event_espresso'
1034
+				),
1035
+				__FILE__,
1036
+				__FUNCTION__,
1037
+				__LINE__
1038
+			);
1039
+		} elseif ($success === false) {
1040
+			EE_Error::add_error(
1041
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1042
+				__FILE__,
1043
+				__FUNCTION__,
1044
+				__LINE__
1045
+			);
1046
+		}
1047
+	}
1048
+
1049
+
1050
+	/**
1051
+	 * @see parent::restore_item()
1052
+	 * @param int $post_id
1053
+	 * @param int $revision_id
1054
+	 */
1055
+	protected function _restore_cpt_item($post_id, $revision_id)
1056
+	{
1057
+		// copy existing event meta to new post
1058
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1059
+		if ($post_evt instanceof EE_Event) {
1060
+			// meta revision restore
1061
+			$post_evt->restore_revision($revision_id);
1062
+			// related objs restore
1063
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1064
+		}
1065
+	}
1066
+
1067
+
1068
+	/**
1069
+	 * Attach the venue to the Event
1070
+	 *
1071
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1072
+	 * @param  array     $data   The request data from the form
1073
+	 * @return bool           Success or fail.
1074
+	 */
1075
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1076
+	{
1077
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1078
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1079
+		$rows_affected = null;
1080
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1081
+		// very important.  If we don't have a venue name...
1082
+		// then we'll get out because not necessary to create empty venue
1083
+		if (empty($data['venue_title'])) {
1084
+			return false;
1085
+		}
1086
+		$venue_array = array(
1087
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1088
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1089
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1090
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1091
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1092
+				: null,
1093
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1094
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1095
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1096
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1097
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1098
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1099
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1100
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1101
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1102
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1103
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1104
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1105
+			'status'              => 'publish',
1106
+		);
1107
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1108
+		if (! empty($venue_id)) {
1109
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1110
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1111
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1112
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1113
+			return $rows_affected > 0 ? true : false;
1114
+		} else {
1115
+			// we insert the venue
1116
+			$venue_id = $venue_model->insert($venue_array);
1117
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1118
+			return ! empty($venue_id) ? true : false;
1119
+		}
1120
+		// when we have the ancestor come in it's already been handled by the revision save.
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1126
+	 *
1127
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1128
+	 * @param  array    $data   The request data from the form
1129
+	 * @return array
1130
+	 */
1131
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1132
+	{
1133
+		$success = true;
1134
+		$saved_dtt = null;
1135
+		$saved_tickets = array();
1136
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1137
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1138
+			// trim all values to ensure any excess whitespace is removed.
1139
+			$dtt = array_map('trim', $dtt);
1140
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1141
+				: $dtt['DTT_EVT_start'];
1142
+			$datetime_values = array(
1143
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1144
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1145
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1146
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1147
+				'DTT_order'     => $row,
1148
+			);
1149
+			// if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1150
+			if (! empty($dtt['DTT_ID'])) {
1151
+				$DTM = EE_Registry::instance()
1152
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1153
+								  ->get_one_by_ID($dtt['DTT_ID']);
1154
+				$DTM->set_date_format($incoming_date_formats[0]);
1155
+				$DTM->set_time_format($incoming_date_formats[1]);
1156
+				foreach ($datetime_values as $field => $value) {
1157
+					$DTM->set($field, $value);
1158
+				}
1159
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1160
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1161
+			} else {
1162
+				$DTM = EE_Registry::instance()->load_class(
1163
+					'Datetime',
1164
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1165
+					false,
1166
+					false
1167
+				);
1168
+				foreach ($datetime_values as $field => $value) {
1169
+					$DTM->set($field, $value);
1170
+				}
1171
+			}
1172
+			$DTM->save();
1173
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1174
+			// load DTT helper
1175
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1176
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1177
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1178
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1179
+				$DTT->save();
1180
+			}
1181
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1182
+			$saved_dtt = $DTT;
1183
+			$success = ! $success ? $success : $DTT;
1184
+			// if ANY of these updates fail then we want the appropriate global error message.
1185
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1186
+		}
1187
+		// no dtts get deleted so we don't do any of that logic here.
1188
+		// update tickets next
1189
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1190
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1191
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1192
+			$update_prices = false;
1193
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1194
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1195
+			// trim inputs to ensure any excess whitespace is removed.
1196
+			$tkt = array_map('trim', $tkt);
1197
+			if (empty($tkt['TKT_start_date'])) {
1198
+				// let's use now in the set timezone.
1199
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1200
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1201
+			}
1202
+			if (empty($tkt['TKT_end_date'])) {
1203
+				// use the start date of the first datetime
1204
+				$dtt = $evtobj->first_datetime();
1205
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1206
+					$incoming_date_formats[0],
1207
+					$incoming_date_formats[1]
1208
+				);
1209
+			}
1210
+			$TKT_values = array(
1211
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1212
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1213
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1214
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1215
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1216
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1217
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1218
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1219
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1220
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1221
+				'TKT_row'         => $row,
1222
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1223
+				'TKT_price'       => $ticket_price,
1224
+			);
1225
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1226
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1227
+				$TKT_values['TKT_ID'] = 0;
1228
+				$TKT_values['TKT_is_default'] = 0;
1229
+				$TKT_values['TKT_price'] = $ticket_price;
1230
+				$update_prices = true;
1231
+			}
1232
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1233
+			// we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1234
+			// keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1235
+			if (! empty($tkt['TKT_ID'])) {
1236
+				$TKT = EE_Registry::instance()
1237
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1238
+								  ->get_one_by_ID($tkt['TKT_ID']);
1239
+				if ($TKT instanceof EE_Ticket) {
1240
+					$ticket_sold = $TKT->count_related(
1241
+						'Registration',
1242
+						array(
1243
+							array(
1244
+								'STS_ID' => array(
1245
+									'NOT IN',
1246
+									array(EEM_Registration::status_id_incomplete),
1247
+								),
1248
+							),
1249
+						)
1250
+					) > 0 ? true : false;
1251
+					// let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1252
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1253
+									  && ! $TKT->get('TKT_deleted');
1254
+					$TKT->set_date_format($incoming_date_formats[0]);
1255
+					$TKT->set_time_format($incoming_date_formats[1]);
1256
+					// set new values
1257
+					foreach ($TKT_values as $field => $value) {
1258
+						if ($field == 'TKT_qty') {
1259
+							$TKT->set_qty($value);
1260
+						} else {
1261
+							$TKT->set($field, $value);
1262
+						}
1263
+					}
1264
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1265
+					if ($create_new_TKT) {
1266
+						// archive the old ticket first
1267
+						$TKT->set('TKT_deleted', 1);
1268
+						$TKT->save();
1269
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1270
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1271
+						// create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1272
+						$TKT = clone $TKT;
1273
+						$TKT->set('TKT_ID', 0);
1274
+						$TKT->set('TKT_deleted', 0);
1275
+						$TKT->set('TKT_price', $ticket_price);
1276
+						$TKT->set('TKT_sold', 0);
1277
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1278
+						$update_prices = true;
1279
+					}
1280
+					// make sure price is set if it hasn't been already
1281
+					$TKT->set('TKT_price', $ticket_price);
1282
+				}
1283
+			} else {
1284
+				// no TKT_id so a new TKT
1285
+				$TKT_values['TKT_price'] = $ticket_price;
1286
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1287
+				if ($TKT instanceof EE_Ticket) {
1288
+					// need to reset values to properly account for the date formats
1289
+					$TKT->set_date_format($incoming_date_formats[0]);
1290
+					$TKT->set_time_format($incoming_date_formats[1]);
1291
+					$TKT->set_timezone($evtobj->get_timezone());
1292
+					// set new values
1293
+					foreach ($TKT_values as $field => $value) {
1294
+						if ($field == 'TKT_qty') {
1295
+							$TKT->set_qty($value);
1296
+						} else {
1297
+							$TKT->set($field, $value);
1298
+						}
1299
+					}
1300
+					$update_prices = true;
1301
+				}
1302
+			}
1303
+			// cap ticket qty by datetime reg limits
1304
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1305
+			// update ticket.
1306
+			$TKT->save();
1307
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1308
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1309
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1310
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1311
+				$TKT->save();
1312
+			}
1313
+			// initially let's add the ticket to the dtt
1314
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1315
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1316
+			// add prices to ticket
1317
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1318
+		}
1319
+		// however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1320
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1321
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1322
+		foreach ($tickets_removed as $id) {
1323
+			$id = absint($id);
1324
+			// get the ticket for this id
1325
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1326
+			// need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1327
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1328
+			foreach ($dtts as $dtt) {
1329
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1330
+			}
1331
+			// need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1332
+			$tkt_to_remove->delete_related_permanently('Price');
1333
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1334
+			$tkt_to_remove->delete_permanently();
1335
+		}
1336
+		return array($saved_dtt, $saved_tickets);
1337
+	}
1338
+
1339
+
1340
+	/**
1341
+	 * This attaches a list of given prices to a ticket.
1342
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1343
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1344
+	 * price info and prices are automatically "archived" via the ticket.
1345
+	 *
1346
+	 * @access  private
1347
+	 * @param array     $prices     Array of prices from the form.
1348
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1349
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1350
+	 * @return  void
1351
+	 */
1352
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1353
+	{
1354
+		foreach ($prices as $row => $prc) {
1355
+			$PRC_values = array(
1356
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1357
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1358
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1359
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1360
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1361
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1362
+				'PRC_order'      => $row,
1363
+			);
1364
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1365
+				$PRC_values['PRC_ID'] = 0;
1366
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1367
+			} else {
1368
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1369
+				// update this price with new values
1370
+				foreach ($PRC_values as $field => $newprc) {
1371
+					$PRC->set($field, $newprc);
1372
+				}
1373
+				$PRC->save();
1374
+			}
1375
+			$ticket->_add_relation_to($PRC, 'Price');
1376
+		}
1377
+	}
1378
+
1379
+
1380
+	/**
1381
+	 * Add in our autosave ajax handlers
1382
+	 *
1383
+	 */
1384
+	protected function _ee_autosave_create_new()
1385
+	{
1386
+	}
1387
+
1388
+
1389
+	/**
1390
+	 * More autosave handlers.
1391
+	 */
1392
+	protected function _ee_autosave_edit()
1393
+	{
1394
+		return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1395
+	}
1396
+
1397
+
1398
+	/**
1399
+	 *    _generate_publish_box_extra_content
1400
+	 */
1401
+	private function _generate_publish_box_extra_content()
1402
+	{
1403
+		// load formatter helper
1404
+		// args for getting related registrations
1405
+		$approved_query_args = array(
1406
+			array(
1407
+				'REG_deleted' => 0,
1408
+				'STS_ID'      => EEM_Registration::status_id_approved,
1409
+			),
1410
+		);
1411
+		$not_approved_query_args = array(
1412
+			array(
1413
+				'REG_deleted' => 0,
1414
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1415
+			),
1416
+		);
1417
+		$pending_payment_query_args = array(
1418
+			array(
1419
+				'REG_deleted' => 0,
1420
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1421
+			),
1422
+		);
1423
+		// publish box
1424
+		$publish_box_extra_args = array(
1425
+			'view_approved_reg_url'        => add_query_arg(
1426
+				array(
1427
+					'action'      => 'default',
1428
+					'event_id'    => $this->_cpt_model_obj->ID(),
1429
+					'_reg_status' => EEM_Registration::status_id_approved,
1430
+				),
1431
+				REG_ADMIN_URL
1432
+			),
1433
+			'view_not_approved_reg_url'    => add_query_arg(
1434
+				array(
1435
+					'action'      => 'default',
1436
+					'event_id'    => $this->_cpt_model_obj->ID(),
1437
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1438
+				),
1439
+				REG_ADMIN_URL
1440
+			),
1441
+			'view_pending_payment_reg_url' => add_query_arg(
1442
+				array(
1443
+					'action'      => 'default',
1444
+					'event_id'    => $this->_cpt_model_obj->ID(),
1445
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1446
+				),
1447
+				REG_ADMIN_URL
1448
+			),
1449
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1450
+				'Registration',
1451
+				$approved_query_args
1452
+			),
1453
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1454
+				'Registration',
1455
+				$not_approved_query_args
1456
+			),
1457
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1458
+				'Registration',
1459
+				$pending_payment_query_args
1460
+			),
1461
+			'misc_pub_section_class'       => apply_filters(
1462
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1463
+				'misc-pub-section'
1464
+			),
1465
+		);
1466
+		ob_start();
1467
+		do_action(
1468
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1469
+			$this->_cpt_model_obj
1470
+		);
1471
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1472
+		// load template
1473
+		EEH_Template::display_template(
1474
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1475
+			$publish_box_extra_args
1476
+		);
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * @return EE_Event
1482
+	 */
1483
+	public function get_event_object()
1484
+	{
1485
+		return $this->_cpt_model_obj;
1486
+	}
1487
+
1488
+
1489
+
1490
+
1491
+	/** METABOXES * */
1492
+	/**
1493
+	 * _register_event_editor_meta_boxes
1494
+	 * add all metaboxes related to the event_editor
1495
+	 *
1496
+	 * @return void
1497
+	 */
1498
+	protected function _register_event_editor_meta_boxes()
1499
+	{
1500
+		$this->verify_cpt_object();
1501
+		// add_meta_box(
1502
+		//     'espresso_event_editor_tickets',
1503
+		//     esc_html__('Event Datetime & Ticket', 'event_espresso'),
1504
+		//     array($this, 'ticket_metabox'),
1505
+		//     $this->page_slug,
1506
+		//     'normal',
1507
+		//     'high'
1508
+		// );
1509
+		add_meta_box(
1510
+			'espresso_event_editor_event_options',
1511
+			esc_html__('Event Registration Options', 'event_espresso'),
1512
+			array($this, 'registration_options_meta_box'),
1513
+			$this->page_slug,
1514
+			'side',
1515
+			'default'
1516
+		);
1517
+		// NOTE: if you're looking for other metaboxes in here,
1518
+		// where a metabox has a related management page in the admin
1519
+		// you will find it setup in the related management page's "_Hooks" file.
1520
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1521
+	}
1522
+
1523
+
1524
+	/**
1525
+	 * @throws DomainException
1526
+	 * @throws EE_Error
1527
+	 */
1528
+	public function ticket_metabox()
1529
+	{
1530
+		$existing_datetime_ids = $existing_ticket_ids = array();
1531
+		// defaults for template args
1532
+		$template_args = array(
1533
+			'existing_datetime_ids'    => '',
1534
+			'event_datetime_help_link' => '',
1535
+			'ticket_options_help_link' => '',
1536
+			'time'                     => null,
1537
+			'ticket_rows'              => '',
1538
+			'existing_ticket_ids'      => '',
1539
+			'total_ticket_rows'        => 1,
1540
+			'ticket_js_structure'      => '',
1541
+			'trash_icon'               => 'ee-lock-icon',
1542
+			'disabled'                 => '',
1543
+		);
1544
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1545
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1546
+		/**
1547
+		 * 1. Start with retrieving Datetimes
1548
+		 * 2. Fore each datetime get related tickets
1549
+		 * 3. For each ticket get related prices
1550
+		 */
1551
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1552
+		/** @type EE_Datetime $first_datetime */
1553
+		$first_datetime = reset($times);
1554
+		// do we get related tickets?
1555
+		if ($first_datetime instanceof EE_Datetime
1556
+			&& $first_datetime->ID() !== 0
1557
+		) {
1558
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1559
+			$template_args['time'] = $first_datetime;
1560
+			$related_tickets = $first_datetime->tickets(
1561
+				array(
1562
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1563
+					'default_where_conditions' => 'none',
1564
+				)
1565
+			);
1566
+			if (! empty($related_tickets)) {
1567
+				$template_args['total_ticket_rows'] = count($related_tickets);
1568
+				$row = 0;
1569
+				foreach ($related_tickets as $ticket) {
1570
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1571
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1572
+					$row++;
1573
+				}
1574
+			} else {
1575
+				$template_args['total_ticket_rows'] = 1;
1576
+				/** @type EE_Ticket $ticket */
1577
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1578
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1579
+			}
1580
+		} else {
1581
+			$template_args['time'] = $times[0];
1582
+			/** @type EE_Ticket $ticket */
1583
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1584
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1585
+			// NOTE: we're just sending the first default row
1586
+			// (decaf can't manage default tickets so this should be sufficient);
1587
+		}
1588
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1589
+			'event_editor_event_datetimes_help_tab'
1590
+		);
1591
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1592
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1593
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1594
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1595
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1596
+			true
1597
+		);
1598
+		$template = apply_filters(
1599
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1600
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1601
+		);
1602
+		EEH_Template::display_template($template, $template_args);
1603
+	}
1604
+
1605
+
1606
+	/**
1607
+	 * Setup an individual ticket form for the decaf event editor page
1608
+	 *
1609
+	 * @access private
1610
+	 * @param  EE_Ticket $ticket   the ticket object
1611
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1612
+	 * @param int        $row
1613
+	 * @return string generated html for the ticket row.
1614
+	 */
1615
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1616
+	{
1617
+		$template_args = array(
1618
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1619
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1620
+				: '',
1621
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1622
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1623
+			'TKT_name'            => $ticket->get('TKT_name'),
1624
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1625
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1626
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1627
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1628
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1629
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1630
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1631
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1632
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1633
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1634
+				: ' disabled=disabled',
1635
+		);
1636
+		$price = $ticket->ID() !== 0
1637
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1638
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1639
+		$price_args = array(
1640
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1641
+			'PRC_amount'            => $price->get('PRC_amount'),
1642
+			'PRT_ID'                => $price->get('PRT_ID'),
1643
+			'PRC_ID'                => $price->get('PRC_ID'),
1644
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1645
+		);
1646
+		// make sure we have default start and end dates if skeleton
1647
+		// handle rows that should NOT be empty
1648
+		if (empty($template_args['TKT_start_date'])) {
1649
+			// if empty then the start date will be now.
1650
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1651
+		}
1652
+		if (empty($template_args['TKT_end_date'])) {
1653
+			// get the earliest datetime (if present);
1654
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1655
+				? $this->_cpt_model_obj->get_first_related(
1656
+					'Datetime',
1657
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1658
+				)
1659
+				: null;
1660
+			if (! empty($earliest_dtt)) {
1661
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1662
+			} else {
1663
+				$template_args['TKT_end_date'] = date(
1664
+					'Y-m-d h:i a',
1665
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1666
+				);
1667
+			}
1668
+		}
1669
+		$template_args = array_merge($template_args, $price_args);
1670
+		$template = apply_filters(
1671
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1672
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1673
+			$ticket
1674
+		);
1675
+		return EEH_Template::display_template($template, $template_args, true);
1676
+	}
1677
+
1678
+
1679
+	/**
1680
+	 * @throws DomainException
1681
+	 */
1682
+	public function registration_options_meta_box()
1683
+	{
1684
+		$yes_no_values = array(
1685
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1686
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1687
+		);
1688
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1689
+			array(
1690
+				EEM_Registration::status_id_cancelled,
1691
+				EEM_Registration::status_id_declined,
1692
+				EEM_Registration::status_id_incomplete,
1693
+			),
1694
+			true
1695
+		);
1696
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1697
+		$template_args['_event'] = $this->_cpt_model_obj;
1698
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1699
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1700
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1701
+			'default_reg_status',
1702
+			$default_reg_status_values,
1703
+			$this->_cpt_model_obj->default_registration_status()
1704
+		);
1705
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1706
+			'display_desc',
1707
+			$yes_no_values,
1708
+			$this->_cpt_model_obj->display_description()
1709
+		);
1710
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1711
+			'display_ticket_selector',
1712
+			$yes_no_values,
1713
+			$this->_cpt_model_obj->display_ticket_selector(),
1714
+			'',
1715
+			'',
1716
+			false
1717
+		);
1718
+		$template_args['additional_registration_options'] = apply_filters(
1719
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1720
+			'',
1721
+			$template_args,
1722
+			$yes_no_values,
1723
+			$default_reg_status_values
1724
+		);
1725
+		EEH_Template::display_template(
1726
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1727
+			$template_args
1728
+		);
1729
+	}
1730
+
1731
+
1732
+	/**
1733
+	 * _get_events()
1734
+	 * This method simply returns all the events (for the given _view and paging)
1735
+	 *
1736
+	 * @access public
1737
+	 * @param int  $per_page     count of items per page (20 default);
1738
+	 * @param int  $current_page what is the current page being viewed.
1739
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1740
+	 *                           If FALSE then we return an array of event objects
1741
+	 *                           that match the given _view and paging parameters.
1742
+	 * @return array an array of event objects.
1743
+	 */
1744
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1745
+	{
1746
+		$EEME = $this->_event_model();
1747
+		$offset = ($current_page - 1) * $per_page;
1748
+		$limit = $count ? null : $offset . ',' . $per_page;
1749
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1750
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1751
+		if (isset($this->_req_data['month_range'])) {
1752
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1753
+			// simulate the FIRST day of the month, that fixes issues for months like February
1754
+			// where PHP doesn't know what to assume for date.
1755
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1756
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1757
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1758
+		}
1759
+		$where = array();
1760
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1761
+		// determine what post_status our condition will have for the query.
1762
+		switch ($status) {
1763
+			case 'month':
1764
+			case 'today':
1765
+			case null:
1766
+			case 'all':
1767
+				break;
1768
+			case 'draft':
1769
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1770
+				break;
1771
+			default:
1772
+				$where['status'] = $status;
1773
+		}
1774
+		// categories?
1775
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1776
+			? $this->_req_data['EVT_CAT'] : null;
1777
+		if (! empty($category)) {
1778
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1779
+			$where['Term_Taxonomy.term_id'] = $category;
1780
+		}
1781
+		// date where conditions
1782
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1783
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1784
+			$DateTime = new DateTime(
1785
+				$year_r . '-' . $month_r . '-01 00:00:00',
1786
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1787
+			);
1788
+			$start = $DateTime->format(implode(' ', $start_formats));
1789
+			$end = $DateTime->setDate(
1790
+				$year_r,
1791
+				$month_r,
1792
+				$DateTime
1793
+					->format('t')
1794
+			)->setTime(23, 59, 59)
1795
+							->format(implode(' ', $start_formats));
1796
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1797
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1798
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1799
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1800
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1801
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1802
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1803
+			$now = date('Y-m-01');
1804
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1805
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1806
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1807
+							->setTime(23, 59, 59)
1808
+							->format(implode(' ', $start_formats));
1809
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1810
+		}
1811
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1812
+			$where['EVT_wp_user'] = get_current_user_id();
1813
+		} else {
1814
+			if (! isset($where['status'])) {
1815
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1816
+					$where['OR'] = array(
1817
+						'status*restrict_private' => array('!=', 'private'),
1818
+						'AND'                     => array(
1819
+							'status*inclusive' => array('=', 'private'),
1820
+							'EVT_wp_user'      => get_current_user_id(),
1821
+						),
1822
+					);
1823
+				}
1824
+			}
1825
+		}
1826
+		if (isset($this->_req_data['EVT_wp_user'])) {
1827
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1828
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1829
+			) {
1830
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1831
+			}
1832
+		}
1833
+		// search query handling
1834
+		if (isset($this->_req_data['s'])) {
1835
+			$search_string = '%' . $this->_req_data['s'] . '%';
1836
+			$where['OR'] = array(
1837
+				'EVT_name'       => array('LIKE', $search_string),
1838
+				'EVT_desc'       => array('LIKE', $search_string),
1839
+				'EVT_short_desc' => array('LIKE', $search_string),
1840
+			);
1841
+		}
1842
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1843
+		$query_params = apply_filters(
1844
+			'FHEE__Events_Admin_Page__get_events__query_params',
1845
+			array(
1846
+				$where,
1847
+				'limit'    => $limit,
1848
+				'order_by' => $orderby,
1849
+				'order'    => $order,
1850
+				'group_by' => 'EVT_ID',
1851
+			),
1852
+			$this->_req_data
1853
+		);
1854
+		// let's first check if we have special requests coming in.
1855
+		if (isset($this->_req_data['active_status'])) {
1856
+			switch ($this->_req_data['active_status']) {
1857
+				case 'upcoming':
1858
+					return $EEME->get_upcoming_events($query_params, $count);
1859
+					break;
1860
+				case 'expired':
1861
+					return $EEME->get_expired_events($query_params, $count);
1862
+					break;
1863
+				case 'active':
1864
+					return $EEME->get_active_events($query_params, $count);
1865
+					break;
1866
+				case 'inactive':
1867
+					return $EEME->get_inactive_events($query_params, $count);
1868
+					break;
1869
+			}
1870
+		}
1871
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1872
+		return $events;
1873
+	}
1874
+
1875
+
1876
+	/**
1877
+	 * handling for WordPress CPT actions (trash, restore, delete)
1878
+	 *
1879
+	 * @param string $post_id
1880
+	 */
1881
+	public function trash_cpt_item($post_id)
1882
+	{
1883
+		$this->_req_data['EVT_ID'] = $post_id;
1884
+		$this->_trash_or_restore_event('trash', false);
1885
+	}
1886
+
1887
+
1888
+	/**
1889
+	 * @param string $post_id
1890
+	 */
1891
+	public function restore_cpt_item($post_id)
1892
+	{
1893
+		$this->_req_data['EVT_ID'] = $post_id;
1894
+		$this->_trash_or_restore_event('draft', false);
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * @param string $post_id
1900
+	 */
1901
+	public function delete_cpt_item($post_id)
1902
+	{
1903
+		$this->_req_data['EVT_ID'] = $post_id;
1904
+		$this->_delete_event(false);
1905
+	}
1906
+
1907
+
1908
+	/**
1909
+	 * _trash_or_restore_event
1910
+	 *
1911
+	 * @access protected
1912
+	 * @param  string $event_status
1913
+	 * @param bool    $redirect_after
1914
+	 */
1915
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1916
+	{
1917
+		// determine the event id and set to array.
1918
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1919
+		// loop thru events
1920
+		if ($EVT_ID) {
1921
+			// clean status
1922
+			$event_status = sanitize_key($event_status);
1923
+			// grab status
1924
+			if (! empty($event_status)) {
1925
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1926
+			} else {
1927
+				$success = false;
1928
+				$msg = esc_html__(
1929
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1930
+					'event_espresso'
1931
+				);
1932
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1933
+			}
1934
+		} else {
1935
+			$success = false;
1936
+			$msg = esc_html__(
1937
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1938
+				'event_espresso'
1939
+			);
1940
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1941
+		}
1942
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1943
+		if ($redirect_after) {
1944
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1945
+		}
1946
+	}
1947
+
1948
+
1949
+	/**
1950
+	 * _trash_or_restore_events
1951
+	 *
1952
+	 * @access protected
1953
+	 * @param  string $event_status
1954
+	 * @return void
1955
+	 */
1956
+	protected function _trash_or_restore_events($event_status = 'trash')
1957
+	{
1958
+		// clean status
1959
+		$event_status = sanitize_key($event_status);
1960
+		// grab status
1961
+		if (! empty($event_status)) {
1962
+			$success = true;
1963
+			// determine the event id and set to array.
1964
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1965
+			// loop thru events
1966
+			foreach ($EVT_IDs as $EVT_ID) {
1967
+				if ($EVT_ID = absint($EVT_ID)) {
1968
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1969
+					$success = $results !== false ? $success : false;
1970
+				} else {
1971
+					$msg = sprintf(
1972
+						esc_html__(
1973
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1974
+							'event_espresso'
1975
+						),
1976
+						$EVT_ID
1977
+					);
1978
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1979
+					$success = false;
1980
+				}
1981
+			}
1982
+		} else {
1983
+			$success = false;
1984
+			$msg = esc_html__(
1985
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1986
+				'event_espresso'
1987
+			);
1988
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1989
+		}
1990
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1991
+		$success = $success ? 2 : false;
1992
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1993
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1994
+	}
1995
+
1996
+
1997
+	/**
1998
+	 * _trash_or_restore_events
1999
+	 *
2000
+	 * @access  private
2001
+	 * @param  int    $EVT_ID
2002
+	 * @param  string $event_status
2003
+	 * @return bool
2004
+	 */
2005
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2006
+	{
2007
+		// grab event id
2008
+		if (! $EVT_ID) {
2009
+			$msg = esc_html__(
2010
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2011
+				'event_espresso'
2012
+			);
2013
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2014
+			return false;
2015
+		}
2016
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2017
+		// clean status
2018
+		$event_status = sanitize_key($event_status);
2019
+		// grab status
2020
+		if (empty($event_status)) {
2021
+			$msg = esc_html__(
2022
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2023
+				'event_espresso'
2024
+			);
2025
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2026
+			return false;
2027
+		}
2028
+		// was event trashed or restored ?
2029
+		switch ($event_status) {
2030
+			case 'draft':
2031
+				$action = 'restored from the trash';
2032
+				$hook = 'AHEE_event_restored_from_trash';
2033
+				break;
2034
+			case 'trash':
2035
+				$action = 'moved to the trash';
2036
+				$hook = 'AHEE_event_moved_to_trash';
2037
+				break;
2038
+			default:
2039
+				$action = 'updated';
2040
+				$hook = false;
2041
+		}
2042
+		// use class to change status
2043
+		$this->_cpt_model_obj->set_status($event_status);
2044
+		$success = $this->_cpt_model_obj->save();
2045
+		if ($success === false) {
2046
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2047
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2048
+			return false;
2049
+		}
2050
+		if ($hook) {
2051
+			do_action($hook);
2052
+		}
2053
+		return true;
2054
+	}
2055
+
2056
+
2057
+	/**
2058
+	 * _delete_event
2059
+	 *
2060
+	 * @access protected
2061
+	 * @param bool $redirect_after
2062
+	 */
2063
+	protected function _delete_event($redirect_after = true)
2064
+	{
2065
+		// determine the event id and set to array.
2066
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2067
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2068
+		// loop thru events
2069
+		if ($EVT_ID) {
2070
+			$success = $this->_permanently_delete_event($EVT_ID);
2071
+			// get list of events with no prices
2072
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2073
+			// remove this event from the list of events with no prices
2074
+			if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2075
+				unset($espresso_no_ticket_prices[ $EVT_ID ]);
2076
+			}
2077
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2078
+		} else {
2079
+			$success = false;
2080
+			$msg = esc_html__(
2081
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2082
+				'event_espresso'
2083
+			);
2084
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2085
+		}
2086
+		if ($redirect_after) {
2087
+			$this->_redirect_after_action(
2088
+				$success,
2089
+				'Event',
2090
+				'deleted',
2091
+				array('action' => 'default', 'status' => 'trash')
2092
+			);
2093
+		}
2094
+	}
2095
+
2096
+
2097
+	/**
2098
+	 * _delete_events
2099
+	 *
2100
+	 * @access protected
2101
+	 * @return void
2102
+	 */
2103
+	protected function _delete_events()
2104
+	{
2105
+		$success = true;
2106
+		// get list of events with no prices
2107
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2108
+		// determine the event id and set to array.
2109
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2110
+		// loop thru events
2111
+		foreach ($EVT_IDs as $EVT_ID) {
2112
+			$EVT_ID = absint($EVT_ID);
2113
+			if ($EVT_ID) {
2114
+				$results = $this->_permanently_delete_event($EVT_ID);
2115
+				$success = $results !== false ? $success : false;
2116
+				// remove this event from the list of events with no prices
2117
+				unset($espresso_no_ticket_prices[ $EVT_ID ]);
2118
+			} else {
2119
+				$success = false;
2120
+				$msg = esc_html__(
2121
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2122
+					'event_espresso'
2123
+				);
2124
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2125
+			}
2126
+		}
2127
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2128
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2129
+		$success = $success ? 2 : false;
2130
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2131
+	}
2132
+
2133
+
2134
+	/**
2135
+	 * _permanently_delete_event
2136
+	 *
2137
+	 * @access  private
2138
+	 * @param  int $EVT_ID
2139
+	 * @return bool
2140
+	 */
2141
+	private function _permanently_delete_event($EVT_ID = 0)
2142
+	{
2143
+		// grab event id
2144
+		if (! $EVT_ID) {
2145
+			$msg = esc_html__(
2146
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2147
+				'event_espresso'
2148
+			);
2149
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2150
+			return false;
2151
+		}
2152
+		if (! $this->_cpt_model_obj instanceof EE_Event
2153
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2154
+		) {
2155
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2156
+		}
2157
+		if (! $this->_cpt_model_obj instanceof EE_Event) {
2158
+			return false;
2159
+		}
2160
+		// need to delete related tickets and prices first.
2161
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2162
+		foreach ($datetimes as $datetime) {
2163
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2164
+			$tickets = $datetime->get_many_related('Ticket');
2165
+			foreach ($tickets as $ticket) {
2166
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2167
+				$ticket->delete_related_permanently('Price');
2168
+				$ticket->delete_permanently();
2169
+			}
2170
+			$datetime->delete();
2171
+		}
2172
+		// what about related venues or terms?
2173
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2174
+		foreach ($venues as $venue) {
2175
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2176
+		}
2177
+		// any attached question groups?
2178
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2179
+		if (! empty($question_groups)) {
2180
+			foreach ($question_groups as $question_group) {
2181
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2182
+			}
2183
+		}
2184
+		// Message Template Groups
2185
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2186
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2187
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2188
+		foreach ($term_taxonomies as $term_taxonomy) {
2189
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2190
+		}
2191
+		$success = $this->_cpt_model_obj->delete_permanently();
2192
+		// did it all go as planned ?
2193
+		if ($success) {
2194
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2195
+			EE_Error::add_success($msg);
2196
+		} else {
2197
+			$msg = sprintf(
2198
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2199
+				$EVT_ID
2200
+			);
2201
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2202
+			return false;
2203
+		}
2204
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2205
+		return true;
2206
+	}
2207
+
2208
+
2209
+	/**
2210
+	 * get total number of events
2211
+	 *
2212
+	 * @access public
2213
+	 * @return int
2214
+	 */
2215
+	public function total_events()
2216
+	{
2217
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2218
+		return $count;
2219
+	}
2220
+
2221
+
2222
+	/**
2223
+	 * get total number of draft events
2224
+	 *
2225
+	 * @access public
2226
+	 * @return int
2227
+	 */
2228
+	public function total_events_draft()
2229
+	{
2230
+		$where = array(
2231
+			'status' => array('IN', array('draft', 'auto-draft')),
2232
+		);
2233
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2234
+		return $count;
2235
+	}
2236
+
2237
+
2238
+	/**
2239
+	 * get total number of trashed events
2240
+	 *
2241
+	 * @access public
2242
+	 * @return int
2243
+	 */
2244
+	public function total_trashed_events()
2245
+	{
2246
+		$where = array(
2247
+			'status' => 'trash',
2248
+		);
2249
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2250
+		return $count;
2251
+	}
2252
+
2253
+
2254
+	/**
2255
+	 *    _default_event_settings
2256
+	 *    This generates the Default Settings Tab
2257
+	 *
2258
+	 * @return void
2259
+	 * @throws EE_Error
2260
+	 */
2261
+	protected function _default_event_settings()
2262
+	{
2263
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2264
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2265
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2266
+		$this->display_admin_page_with_sidebar();
2267
+	}
2268
+
2269
+
2270
+	/**
2271
+	 * Return the form for event settings.
2272
+	 *
2273
+	 * @return EE_Form_Section_Proper
2274
+	 * @throws EE_Error
2275
+	 */
2276
+	protected function _default_event_settings_form()
2277
+	{
2278
+		$registration_config = EE_Registry::instance()->CFG->registration;
2279
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2280
+			// exclude
2281
+			array(
2282
+				EEM_Registration::status_id_cancelled,
2283
+				EEM_Registration::status_id_declined,
2284
+				EEM_Registration::status_id_incomplete,
2285
+				EEM_Registration::status_id_wait_list,
2286
+			),
2287
+			true
2288
+		);
2289
+		return new EE_Form_Section_Proper(
2290
+			array(
2291
+				'name'            => 'update_default_event_settings',
2292
+				'html_id'         => 'update_default_event_settings',
2293
+				'html_class'      => 'form-table',
2294
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2295
+				'subsections'     => apply_filters(
2296
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2297
+					array(
2298
+						'default_reg_status'  => new EE_Select_Input(
2299
+							$registration_stati_for_selection,
2300
+							array(
2301
+								'default'         => isset($registration_config->default_STS_ID)
2302
+													 && array_key_exists(
2303
+														 $registration_config->default_STS_ID,
2304
+														 $registration_stati_for_selection
2305
+													 )
2306
+									? sanitize_text_field($registration_config->default_STS_ID)
2307
+									: EEM_Registration::status_id_pending_payment,
2308
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2309
+													 . EEH_Template::get_help_tab_link(
2310
+														 'default_settings_status_help_tab'
2311
+													 ),
2312
+								'html_help_text'  => esc_html__(
2313
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2314
+									'event_espresso'
2315
+								),
2316
+							)
2317
+						),
2318
+						'default_max_tickets' => new EE_Integer_Input(
2319
+							array(
2320
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2321
+									? $registration_config->default_maximum_number_of_tickets
2322
+									: EEM_Event::get_default_additional_limit(),
2323
+								'html_label_text' => esc_html__(
2324
+									'Default Maximum Tickets Allowed Per Order:',
2325
+									'event_espresso'
2326
+								)
2327
+													 . EEH_Template::get_help_tab_link(
2328
+														 'default_maximum_tickets_help_tab"'
2329
+													 ),
2330
+								'html_help_text'  => esc_html__(
2331
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2332
+									'event_espresso'
2333
+								),
2334
+							)
2335
+						),
2336
+					)
2337
+				),
2338
+			)
2339
+		);
2340
+	}
2341
+
2342
+
2343
+	/**
2344
+	 * @return void
2345
+	 * @throws EE_Error
2346
+	 * @throws InvalidArgumentException
2347
+	 * @throws InvalidDataTypeException
2348
+	 * @throws InvalidInterfaceException
2349
+	 */
2350
+	protected function _update_default_event_settings()
2351
+	{
2352
+		$form = $this->_default_event_settings_form();
2353
+		if ($form->was_submitted()) {
2354
+			$form->receive_form_submission();
2355
+			if ($form->is_valid()) {
2356
+				$registration_config = EE_Registry::instance()->CFG->registration;
2357
+				$valid_data = $form->valid_data();
2358
+				if (isset($valid_data['default_reg_status'])) {
2359
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2360
+				}
2361
+				if (isset($valid_data['default_max_tickets'])) {
2362
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2363
+				}
2364
+				do_action(
2365
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2366
+					$valid_data,
2367
+					EE_Registry::instance()->CFG,
2368
+					$this
2369
+				);
2370
+				// update because data was valid!
2371
+				EE_Registry::instance()->CFG->update_espresso_config();
2372
+				EE_Error::overwrite_success();
2373
+				EE_Error::add_success(
2374
+					__('Default Event Settings were updated', 'event_espresso')
2375
+				);
2376
+			}
2377
+		}
2378
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2379
+	}
2380
+
2381
+
2382
+	/*************        Templates        *************/
2383
+	protected function _template_settings()
2384
+	{
2385
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2386
+		$this->_template_args['preview_img'] = '<img src="'
2387
+											   . EVENTS_ASSETS_URL
2388
+											   . DS
2389
+											   . 'images'
2390
+											   . DS
2391
+											   . 'caffeinated_template_features.jpg" alt="'
2392
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2393
+											   . '" />';
2394
+		$this->_template_args['preview_text'] = '<strong>'
2395
+												. esc_html__(
2396
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2397
+													'event_espresso'
2398
+												) . '</strong>';
2399
+		$this->display_admin_caf_preview_page('template_settings_tab');
2400
+	}
2401
+
2402
+
2403
+	/** Event Category Stuff **/
2404
+	/**
2405
+	 * set the _category property with the category object for the loaded page.
2406
+	 *
2407
+	 * @access private
2408
+	 * @return void
2409
+	 */
2410
+	private function _set_category_object()
2411
+	{
2412
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2413
+			return;
2414
+		} //already have the category object so get out.
2415
+		// set default category object
2416
+		$this->_set_empty_category_object();
2417
+		// only set if we've got an id
2418
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2419
+			return;
2420
+		}
2421
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2422
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2423
+		if (! empty($term)) {
2424
+			$this->_category->category_name = $term->name;
2425
+			$this->_category->category_identifier = $term->slug;
2426
+			$this->_category->category_desc = $term->description;
2427
+			$this->_category->id = $term->term_id;
2428
+			$this->_category->parent = $term->parent;
2429
+		}
2430
+	}
2431
+
2432
+
2433
+	/**
2434
+	 * Clears out category properties.
2435
+	 */
2436
+	private function _set_empty_category_object()
2437
+	{
2438
+		$this->_category = new stdClass();
2439
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2440
+		$this->_category->id = $this->_category->parent = 0;
2441
+	}
2442
+
2443
+
2444
+	/**
2445
+	 * @throws EE_Error
2446
+	 */
2447
+	protected function _category_list_table()
2448
+	{
2449
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2450
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2451
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2452
+			'add_category',
2453
+			'add_category',
2454
+			array(),
2455
+			'add-new-h2'
2456
+		);
2457
+		$this->display_admin_list_table_page_with_sidebar();
2458
+	}
2459
+
2460
+
2461
+	/**
2462
+	 * Output category details view.
2463
+	 */
2464
+	protected function _category_details($view)
2465
+	{
2466
+		// load formatter helper
2467
+		// load field generator helper
2468
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2469
+		$this->_set_add_edit_form_tags($route);
2470
+		$this->_set_category_object();
2471
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2472
+		$delete_action = 'delete_category';
2473
+		// custom redirect
2474
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2475
+			array('action' => 'category_list'),
2476
+			$this->_admin_base_url
2477
+		);
2478
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2479
+		// take care of contents
2480
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2481
+		$this->display_admin_page_with_sidebar();
2482
+	}
2483
+
2484
+
2485
+	/**
2486
+	 * Output category details content.
2487
+	 */
2488
+	protected function _category_details_content()
2489
+	{
2490
+		$editor_args['category_desc'] = array(
2491
+			'type'          => 'wp_editor',
2492
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2493
+			'class'         => 'my_editor_custom',
2494
+			'wpeditor_args' => array('media_buttons' => false),
2495
+		);
2496
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2497
+		$all_terms = get_terms(
2498
+			array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2499
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2500
+		);
2501
+		// setup category select for term parents.
2502
+		$category_select_values[] = array(
2503
+			'text' => esc_html__('No Parent', 'event_espresso'),
2504
+			'id'   => 0,
2505
+		);
2506
+		foreach ($all_terms as $term) {
2507
+			$category_select_values[] = array(
2508
+				'text' => $term->name,
2509
+				'id'   => $term->term_id,
2510
+			);
2511
+		}
2512
+		$category_select = EEH_Form_Fields::select_input(
2513
+			'category_parent',
2514
+			$category_select_values,
2515
+			$this->_category->parent
2516
+		);
2517
+		$template_args = array(
2518
+			'category'                 => $this->_category,
2519
+			'category_select'          => $category_select,
2520
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2521
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2522
+			'disable'                  => '',
2523
+			'disabled_message'         => false,
2524
+		);
2525
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2526
+		return EEH_Template::display_template($template, $template_args, true);
2527
+	}
2528
+
2529
+
2530
+	/**
2531
+	 * Handles deleting categories.
2532
+	 */
2533
+	protected function _delete_categories()
2534
+	{
2535
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2536
+			: (array) $this->_req_data['category_id'];
2537
+		foreach ($cat_ids as $cat_id) {
2538
+			$this->_delete_category($cat_id);
2539
+		}
2540
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2541
+		$query_args = array(
2542
+			'action' => 'category_list',
2543
+		);
2544
+		$this->_redirect_after_action(0, '', '', $query_args);
2545
+	}
2546
+
2547
+
2548
+	/**
2549
+	 * Handles deleting specific category.
2550
+	 *
2551
+	 * @param int $cat_id
2552
+	 */
2553
+	protected function _delete_category($cat_id)
2554
+	{
2555
+		$cat_id = absint($cat_id);
2556
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2557
+	}
2558
+
2559
+
2560
+	/**
2561
+	 * Handles triggering the update or insertion of a new category.
2562
+	 *
2563
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2564
+	 */
2565
+	protected function _insert_or_update_category($new_category)
2566
+	{
2567
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2568
+		$success = 0; // we already have a success message so lets not send another.
2569
+		if ($cat_id) {
2570
+			$query_args = array(
2571
+				'action'     => 'edit_category',
2572
+				'EVT_CAT_ID' => $cat_id,
2573
+			);
2574
+		} else {
2575
+			$query_args = array('action' => 'add_category');
2576
+		}
2577
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2578
+	}
2579
+
2580
+
2581
+	/**
2582
+	 * Inserts or updates category
2583
+	 *
2584
+	 * @param bool $update (true indicates we're updating a category).
2585
+	 * @return bool|mixed|string
2586
+	 */
2587
+	private function _insert_category($update = false)
2588
+	{
2589
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2590
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2591
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2592
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2593
+		if (empty($category_name)) {
2594
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2595
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2596
+			return false;
2597
+		}
2598
+		$term_args = array(
2599
+			'name'        => $category_name,
2600
+			'description' => $category_desc,
2601
+			'parent'      => $category_parent,
2602
+		);
2603
+		// was the category_identifier input disabled?
2604
+		if (isset($this->_req_data['category_identifier'])) {
2605
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2606
+		}
2607
+		$insert_ids = $update
2608
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2609
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2610
+		if (! is_array($insert_ids)) {
2611
+			$msg = esc_html__(
2612
+				'An error occurred and the category has not been saved to the database.',
2613
+				'event_espresso'
2614
+			);
2615
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2616
+		} else {
2617
+			$cat_id = $insert_ids['term_id'];
2618
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2619
+			EE_Error::add_success($msg);
2620
+		}
2621
+		return $cat_id;
2622
+	}
2623
+
2624
+
2625
+	/**
2626
+	 * Gets categories or count of categories matching the arguments in the request.
2627
+	 *
2628
+	 * @param int  $per_page
2629
+	 * @param int  $current_page
2630
+	 * @param bool $count
2631
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2632
+	 */
2633
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2634
+	{
2635
+		// testing term stuff
2636
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2637
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2638
+		$limit = ($current_page - 1) * $per_page;
2639
+		$where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2640
+		if (isset($this->_req_data['s'])) {
2641
+			$sstr = '%' . $this->_req_data['s'] . '%';
2642
+			$where['OR'] = array(
2643
+				'Term.name'   => array('LIKE', $sstr),
2644
+				'description' => array('LIKE', $sstr),
2645
+			);
2646
+		}
2647
+		$query_params = array(
2648
+			$where,
2649
+			'order_by'   => array($orderby => $order),
2650
+			'limit'      => $limit . ',' . $per_page,
2651
+			'force_join' => array('Term'),
2652
+		);
2653
+		$categories = $count
2654
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2655
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2656
+		return $categories;
2657
+	}
2658
+
2659
+	/* end category stuff */
2660
+	/**************/
2661
+
2662
+
2663
+	/**
2664
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2665
+	 *
2666
+	 * @throws EE_Error
2667
+	 */
2668
+	public function save_timezonestring_setting()
2669
+	{
2670
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2671
+			? $this->_req_data['timezone_selected']
2672
+			: '';
2673
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2674
+			EE_Error::add_error(
2675
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2676
+				__FILE__,
2677
+				__FUNCTION__,
2678
+				__LINE__
2679
+			);
2680
+			$this->_template_args['error'] = true;
2681
+			$this->_return_json();
2682
+		}
2683
+
2684
+		update_option('timezone_string', $timezone_string);
2685
+		EE_Error::add_success(
2686
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2687
+		);
2688
+		$this->_template_args['success'] = true;
2689
+		$this->_return_json(true, array('action' => 'create_new'));
2690
+	}
2691 2691
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 2 patches
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
             );
152 152
             $msg .= '</p><ul>';
153 153
             foreach ($format_validation as $error) {
154
-                $msg .= '<li>' . $error . '</li>';
154
+                $msg .= '<li>'.$error.'</li>';
155 155
             }
156 156
             $msg .= '</ul><p>';
157 157
             $msg .= sprintf(
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
         $this->_scripts_styles = array(
181 181
             'registers'   => array(
182 182
                 'ee-tickets-datetimes-css' => array(
183
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
183
+                    'url'  => PRICING_ASSETS_URL.'event-tickets-datetimes.css',
184 184
                     'type' => 'css',
185 185
                 ),
186 186
                 'ee-dtt-ticket-metabox'    => array(
187
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
187
+                    'url'     => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js',
188 188
                     'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
189 189
                 ),
190 190
             ),
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
                             'event_espresso'
209 209
                         ),
210 210
                         'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
211
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
211
+                                                     . esc_html__('Cancel', 'event_espresso').'</button>',
212 212
                         'close_button'            => '<button class="button-secondary ee-modal-cancel">'
213
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
213
+                                                     . esc_html__('Close', 'event_espresso').'</button>',
214 214
                         'single_warning_from_tkt' => esc_html__(
215 215
                             '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.',
216 216
                             'event_espresso'
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
                             'event_espresso'
221 221
                         ),
222 222
                         'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
223
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
223
+                                                     . esc_html__('Dismiss', 'event_espresso').'</button>',
224 224
                     ),
225 225
                     'DTT_ERROR_MSG'         => array(
226 226
                         'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     {
259 259
         foreach ($update_callbacks as $key => $callback) {
260 260
             if ($callback[1] === '_default_tickets_update') {
261
-                unset($update_callbacks[ $key ]);
261
+                unset($update_callbacks[$key]);
262 262
             }
263 263
         }
264 264
         $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
         foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
317 317
             // trim all values to ensure any excess whitespace is removed.
318 318
             $datetime_data = array_map(
319
-                function ($datetime_data) {
319
+                function($datetime_data) {
320 320
                     return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
321 321
                 },
322 322
                 $datetime_data
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
             );
347 347
             // if we have an id then let's get existing object first and then set the new values.
348 348
             // Otherwise we instantiate a new object for save.
349
-            if (! empty($datetime_data['DTT_ID'])) {
349
+            if ( ! empty($datetime_data['DTT_ID'])) {
350 350
                 $datetime = EE_Registry::instance()
351 351
                                        ->load_model('Datetime', array($timezone))
352 352
                                        ->get_one_by_ID($datetime_data['DTT_ID']);
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
                 // after the add_relation_to() the autosave replaces it.
361 361
                 // We need to do this so we dont' TRASH the parent DTT.
362 362
                 // (save the ID for both key and value to avoid duplications)
363
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
363
+                $saved_dtt_ids[$datetime->ID()] = $datetime->ID();
364 364
             } else {
365 365
                 $datetime = EE_Registry::instance()->load_class(
366 366
                     'Datetime',
@@ -389,8 +389,8 @@  discard block
 block discarded – undo
389 389
             // because it is possible there was a new one created for the autosave.
390 390
             // (save the ID for both key and value to avoid duplications)
391 391
             $DTT_ID = $datetime->ID();
392
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
393
-            $saved_dtt_objs[ $row ] = $datetime;
392
+            $saved_dtt_ids[$DTT_ID] = $DTT_ID;
393
+            $saved_dtt_objs[$row] = $datetime;
394 394
             // @todo if ANY of these updates fail then we want the appropriate global error message.
395 395
         }
396 396
         $event->save();
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
             $update_prices = $create_new_TKT = false;
456 456
             // figure out what datetimes were added to the ticket
457 457
             // and what datetimes were removed from the ticket in the session.
458
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
459
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
458
+            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
459
+            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]);
460 460
             $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
461 461
             $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
462 462
             // trim inputs to ensure any excess whitespace is removed.
463 463
             $tkt = array_map(
464
-                function ($ticket_data) {
464
+                function($ticket_data) {
465 465
                     return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
466 466
                 },
467 467
                 $tkt
@@ -483,8 +483,8 @@  discard block
 block discarded – undo
483 483
             $base_price_id = isset($tkt['TKT_base_price_ID'])
484 484
                 ? $tkt['TKT_base_price_ID']
485 485
                 : 0;
486
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
487
-                ? $data['edit_prices'][ $row ]
486
+            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row])
487
+                ? $data['edit_prices'][$row]
488 488
                 : array();
489 489
             $now = null;
490 490
             if (empty($tkt['TKT_start_date'])) {
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
                 /**
497 497
                  * set the TKT_end_date to the first datetime attached to the ticket.
498 498
                  */
499
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
499
+                $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)];
500 500
                 $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
501 501
             }
502 502
             $TKT_values = array(
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
             // need to make sue that the TKT_price is accurate after saving the prices.
632 632
             $ticket->ensure_TKT_Price_correct();
633 633
             // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
634
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
634
+            if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
635 635
                 $update_prices = true;
636 636
                 $new_default = clone $ticket;
637 637
                 $new_default->set('TKT_ID', 0);
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
                 // save new TKT
677 677
                 $new_tkt->save();
678 678
                 // add new ticket to array
679
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
679
+                $saved_tickets[$new_tkt->ID()] = $new_tkt;
680 680
                 do_action(
681 681
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
682 682
                     $new_tkt,
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
                 );
687 687
             } else {
688 688
                 // add tkt to saved tkts
689
-                $saved_tickets[ $ticket->ID() ] = $ticket;
689
+                $saved_tickets[$ticket->ID()] = $ticket;
690 690
                 do_action(
691 691
                     'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
692 692
                     $ticket,
@@ -753,31 +753,31 @@  discard block
 block discarded – undo
753 753
         // to start we have to add the ticket to all the datetimes its supposed to be with,
754 754
         // and removing the ticket from datetimes it got removed from.
755 755
         // first let's add datetimes
756
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
756
+        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
757 757
             foreach ($added_datetimes as $row_id) {
758 758
                 $row_id = (int) $row_id;
759
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
760
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
759
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
760
+                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
761 761
                     // Is this an existing ticket (has an ID) and does it have any sold?
762 762
                     // If so, then we need to add that to the DTT sold because this DTT is getting added.
763 763
                     if ($ticket->ID() && $ticket->sold() > 0) {
764
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
764
+                        $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false);
765 765
                     }
766 766
                 }
767 767
             }
768 768
         }
769 769
         // then remove datetimes
770
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
770
+        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
771 771
             foreach ($removed_datetimes as $row_id) {
772 772
                 $row_id = (int) $row_id;
773 773
                 // its entirely possible that a datetime got deleted (instead of just removed from relationship.
774 774
                 // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
775
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
776
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
775
+                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
776
+                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
777 777
                     // Is this an existing ticket (has an ID) and does it have any sold?
778 778
                     // If so, then we need to remove it's sold from the DTT_sold.
779 779
                     if ($ticket->ID() && $ticket->sold() > 0) {
780
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
780
+                        $saved_datetimes[$row_id]->decreaseSold($ticket->sold());
781 781
                     }
782 782
                 }
783 783
             }
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
             );
891 891
         }
892 892
         // possibly need to save tkt
893
-        if (! $ticket->ID()) {
893
+        if ( ! $ticket->ID()) {
894 894
             $ticket->save();
895 895
         }
896 896
         foreach ($prices as $row => $prc) {
@@ -924,17 +924,17 @@  discard block
 block discarded – undo
924 924
                 }
925 925
             }
926 926
             $price->save();
927
-            $updated_prices[ $price->ID() ] = $price;
927
+            $updated_prices[$price->ID()] = $price;
928 928
             $ticket->_add_relation_to($price, 'Price');
929 929
         }
930 930
         // now let's remove any prices that got removed from the ticket
931
-        if (! empty($current_prices_on_ticket)) {
931
+        if ( ! empty($current_prices_on_ticket)) {
932 932
             $current = array_keys($current_prices_on_ticket);
933 933
             $updated = array_keys($updated_prices);
934 934
             $prices_to_remove = array_diff($current, $updated);
935
-            if (! empty($prices_to_remove)) {
935
+            if ( ! empty($prices_to_remove)) {
936 936
                 foreach ($prices_to_remove as $prc_id) {
937
-                    $p = $current_prices_on_ticket[ $prc_id ];
937
+                    $p = $current_prices_on_ticket[$prc_id];
938 938
                     $ticket->_remove_relation_to($p, 'Price');
939 939
                     // delete permanently the price
940 940
                     $p->delete_permanently();
@@ -1085,17 +1085,17 @@  discard block
 block discarded – undo
1085 1085
                 $TKT_ID = $ticket->get('TKT_ID');
1086 1086
                 $ticket_row = $ticket->get('TKT_row');
1087 1087
                 // we only want unique tickets in our final display!!
1088
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1088
+                if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) {
1089 1089
                     $existing_ticket_ids[] = $TKT_ID;
1090 1090
                     $all_tickets[] = $ticket;
1091 1091
                 }
1092 1092
                 // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1093
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1093
+                $datetime_tickets[$DTT_ID][] = $ticket_row;
1094 1094
                 // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1095
-                if (! isset($ticket_datetimes[ $TKT_ID ])
1096
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1095
+                if ( ! isset($ticket_datetimes[$TKT_ID])
1096
+                    || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true)
1097 1097
                 ) {
1098
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1098
+                    $ticket_datetimes[$TKT_ID][] = $datetime_row;
1099 1099
                 }
1100 1100
             }
1101 1101
             $datetime_row++;
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
         // sort $all_tickets by order
1107 1107
         usort(
1108 1108
             $all_tickets,
1109
-            function (EE_Ticket $a, EE_Ticket $b) {
1109
+            function(EE_Ticket $a, EE_Ticket $b) {
1110 1110
                 $a_order = (int) $a->get('TKT_order');
1111 1111
                 $b_order = (int) $b->get('TKT_order');
1112 1112
                 if ($a_order === $b_order) {
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
         }
1145 1145
         $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1146 1146
         EEH_Template::display_template(
1147
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1147
+            PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php',
1148 1148
             $main_template_args
1149 1149
         );
1150 1150
     }
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
             'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1187 1187
         );
1188 1188
         return EEH_Template::display_template(
1189
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1189
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php',
1190 1190
             $dtt_display_template_args,
1191 1191
             true
1192 1192
         );
@@ -1255,7 +1255,7 @@  discard block
 block discarded – undo
1255 1255
             $this->_is_creating_event
1256 1256
         );
1257 1257
         return EEH_Template::display_template(
1258
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1258
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php',
1259 1259
             $template_args,
1260 1260
             true
1261 1261
         );
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
             'DTT_ID'                            => $default ? '' : $datetime->ID(),
1297 1297
         );
1298 1298
         // need to setup the list items (but only if this isn't a default skeleton setup)
1299
-        if (! $default) {
1299
+        if ( ! $default) {
1300 1300
             $ticket_row = 1;
1301 1301
             foreach ($all_tickets as $ticket) {
1302 1302
                 $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
@@ -1322,7 +1322,7 @@  discard block
 block discarded – undo
1322 1322
             $this->_is_creating_event
1323 1323
         );
1324 1324
         return EEH_Template::display_template(
1325
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1325
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php',
1326 1326
             $template_args,
1327 1327
             true
1328 1328
         );
@@ -1348,8 +1348,8 @@  discard block
 block discarded – undo
1348 1348
         $datetime_tickets = array(),
1349 1349
         $default
1350 1350
     ) {
1351
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1352
-            ? $datetime_tickets[ $datetime->ID() ]
1351
+        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()])
1352
+            ? $datetime_tickets[$datetime->ID()]
1353 1353
             : array();
1354 1354
         $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1355 1355
         $no_ticket = $default && empty($ticket);
@@ -1370,8 +1370,8 @@  discard block
 block discarded – undo
1370 1370
                 ? 'TKTNAME'
1371 1371
                 : $ticket->get('TKT_name'),
1372 1372
             'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1373
-                ? ' tkt-status-' . EE_Ticket::onsale
1374
-                : ' tkt-status-' . $ticket->ticket_status(),
1373
+                ? ' tkt-status-'.EE_Ticket::onsale
1374
+                : ' tkt-status-'.$ticket->ticket_status(),
1375 1375
         );
1376 1376
         // filter template args
1377 1377
         $template_args = apply_filters(
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
             $this->_is_creating_event
1387 1387
         );
1388 1388
         return EEH_Template::display_template(
1389
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1389
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php',
1390 1390
             $template_args,
1391 1391
             true
1392 1392
         );
@@ -1442,19 +1442,19 @@  discard block
 block discarded – undo
1442 1442
         // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1443 1443
         // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1444 1444
         $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1445
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1446
-            ? $ticket_datetimes[ $ticket->ID() ]
1445
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
1446
+            ? $ticket_datetimes[$ticket->ID()]
1447 1447
             : array();
1448 1448
         $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1449 1449
         $base_price = $default ? null : $ticket->base_price();
1450 1450
         $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1451 1451
         // breaking out complicated condition for ticket_status
1452 1452
         if ($default) {
1453
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1453
+            $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale;
1454 1454
         } else {
1455 1455
             $ticket_status_class = $ticket->is_default()
1456
-                ? ' tkt-status-' . EE_Ticket::onsale
1457
-                : ' tkt-status-' . $ticket->ticket_status();
1456
+                ? ' tkt-status-'.EE_Ticket::onsale
1457
+                : ' tkt-status-'.$ticket->ticket_status();
1458 1458
         }
1459 1459
         // breaking out complicated condition for TKT_taxable
1460 1460
         if ($default) {
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
                 : ' style="display:none;"',
1547 1547
             'show_price_mod_button'         => count($prices) > 1
1548 1548
                                                || ($default && $count_price_mods > 0)
1549
-                                               || (! $default && $ticket->deleted())
1549
+                                               || ( ! $default && $ticket->deleted())
1550 1550
                 ? ' style="display:none;"'
1551 1551
                 : '',
1552 1552
             'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
@@ -1590,7 +1590,7 @@  discard block
 block discarded – undo
1590 1590
                 $this->_date_time_format,
1591 1591
                 current_time('timestamp')
1592 1592
             );
1593
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1593
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1594 1594
         }
1595 1595
         if (empty($template_args['TKT_end_date'])) {
1596 1596
             // get the earliest datetime (if present);
@@ -1600,7 +1600,7 @@  discard block
 block discarded – undo
1600 1600
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1601 1601
                 )
1602 1602
                 : null;
1603
-            if (! empty($earliest_dtt)) {
1603
+            if ( ! empty($earliest_dtt)) {
1604 1604
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1605 1605
                     'DTT_EVT_start',
1606 1606
                     $this->_date_time_format
@@ -1619,10 +1619,10 @@  discard block
 block discarded – undo
1619 1619
                     )
1620 1620
                 );
1621 1621
             }
1622
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1622
+            $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale;
1623 1623
         }
1624 1624
         // generate ticket_datetime items
1625
-        if (! $default) {
1625
+        if ( ! $default) {
1626 1626
             $datetime_row = 1;
1627 1627
             foreach ($all_datetimes as $datetime) {
1628 1628
                 $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
@@ -1638,7 +1638,7 @@  discard block
 block discarded – undo
1638 1638
         }
1639 1639
         $price_row = 1;
1640 1640
         foreach ($prices as $price) {
1641
-            if (! $price instanceof EE_Price) {
1641
+            if ( ! $price instanceof EE_Price) {
1642 1642
                 continue;
1643 1643
             }
1644 1644
             if ($price->is_base_price()) {
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
             $this->_is_creating_event
1672 1672
         );
1673 1673
         return EEH_Template::display_template(
1674
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1674
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php',
1675 1675
             $template_args,
1676 1676
             true
1677 1677
         );
@@ -1711,7 +1711,7 @@  discard block
 block discarded – undo
1711 1711
                 $this->_is_creating_event
1712 1712
             );
1713 1713
             $tax_rows .= EEH_Template::display_template(
1714
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1714
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php',
1715 1715
                 $template_args,
1716 1716
                 true
1717 1717
             );
@@ -1830,7 +1830,7 @@  discard block
 block discarded – undo
1830 1830
             $this->_is_creating_event
1831 1831
         );
1832 1832
         return EEH_Template::display_template(
1833
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1833
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php',
1834 1834
             $template_args,
1835 1835
             true
1836 1836
         );
@@ -1900,7 +1900,7 @@  discard block
 block discarded – undo
1900 1900
             $this->_is_creating_event
1901 1901
         );
1902 1902
         return EEH_Template::display_template(
1903
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1903
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php',
1904 1904
             $template_args,
1905 1905
             true
1906 1906
         );
@@ -1930,7 +1930,7 @@  discard block
 block discarded – undo
1930 1930
     ) {
1931 1931
         $select_name = $default && ! $price instanceof EE_Price
1932 1932
             ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1933
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1933
+            : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]';
1934 1934
         /** @var EEM_Price_Type $price_type_model */
1935 1935
         $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1936 1936
         $price_types = $price_type_model->get_all(array(
@@ -1948,10 +1948,10 @@  discard block
 block discarded – undo
1948 1948
         $price_option_spans = '';
1949 1949
         // setup price types for selector
1950 1950
         foreach ($price_types as $price_type) {
1951
-            if (! $price_type instanceof EE_Price_Type) {
1951
+            if ( ! $price_type instanceof EE_Price_Type) {
1952 1952
                 continue;
1953 1953
             }
1954
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1954
+            $all_price_types[$price_type->ID()] = $price_type->get('PRT_name');
1955 1955
             // while we're in the loop let's setup the option spans used by js
1956 1956
             $span_args = array(
1957 1957
                 'PRT_ID'         => $price_type->ID(),
@@ -1959,12 +1959,12 @@  discard block
 block discarded – undo
1959 1959
                 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1960 1960
             );
1961 1961
             $price_option_spans .= EEH_Template::display_template(
1962
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1962
+                PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php',
1963 1963
                 $span_args,
1964 1964
                 true
1965 1965
             );
1966 1966
         }
1967
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1967
+        $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]'
1968 1968
             : $select_name;
1969 1969
         $select_input = new EE_Select_Input(
1970 1970
             $all_price_types,
@@ -2001,7 +2001,7 @@  discard block
 block discarded – undo
2001 2001
             $this->_is_creating_event
2002 2002
         );
2003 2003
         return EEH_Template::display_template(
2004
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2004
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php',
2005 2005
             $template_args,
2006 2006
             true
2007 2007
         );
@@ -2027,8 +2027,8 @@  discard block
 block discarded – undo
2027 2027
         $ticket_datetimes = array(),
2028 2028
         $default
2029 2029
     ) {
2030
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2031
-            ? $ticket_datetimes[ $ticket->ID() ]
2030
+        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()])
2031
+            ? $ticket_datetimes[$ticket->ID()]
2032 2032
             : array();
2033 2033
         $template_args = array(
2034 2034
             'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
@@ -2060,7 +2060,7 @@  discard block
 block discarded – undo
2060 2060
             $this->_is_creating_event
2061 2061
         );
2062 2062
         return EEH_Template::display_template(
2063
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2063
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2064 2064
             $template_args,
2065 2065
             true
2066 2066
         );
@@ -2166,7 +2166,7 @@  discard block
 block discarded – undo
2166 2166
         $default_prices = $price_model->get_all_default_prices();
2167 2167
         $price_row = 1;
2168 2168
         foreach ($default_prices as $price) {
2169
-            if (! $price instanceof EE_Price) {
2169
+            if ( ! $price instanceof EE_Price) {
2170 2170
                 continue;
2171 2171
             }
2172 2172
             if ($price->is_base_price()) {
@@ -2203,7 +2203,7 @@  discard block
 block discarded – undo
2203 2203
             $this->_is_creating_event
2204 2204
         );
2205 2205
         return EEH_Template::display_template(
2206
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2206
+            PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php',
2207 2207
             $template_args,
2208 2208
             true
2209 2209
         );
Please login to merge, or discard this patch.
Indentation   +2136 added lines, -2136 removed lines patch added patch discarded remove patch
@@ -15,2196 +15,2196 @@
 block discarded – undo
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 (EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
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 (EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
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
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
380
-            // before going any further make sure our dates are setup correctly
381
-            // so that the end date is always equal or greater than the start date.
382
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
383
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
384
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
385
-                $datetime->save();
386
-            }
387
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
388
-            // because it is possible there was a new one created for the autosave.
389
-            // (save the ID for both key and value to avoid duplications)
390
-            $DTT_ID = $datetime->ID();
391
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
392
-            $saved_dtt_objs[ $row ] = $datetime;
393
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
394
-        }
395
-        $event->save();
396
-        // now we need to REMOVE any datetimes that got deleted.
397
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
398
-        // So its safe to permanently delete at this point.
399
-        $old_datetimes = explode(',', $data['datetime_IDs']);
400
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
401
-        if (is_array($old_datetimes)) {
402
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
403
-            foreach ($datetimes_to_delete as $id) {
404
-                $id = absint($id);
405
-                if (empty($id)) {
406
-                    continue;
407
-                }
408
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
409
-                // remove tkt relationships.
410
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
411
-                foreach ($related_tickets as $tkt) {
412
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
413
-                }
414
-                $event->_remove_relation_to($id, 'Datetime');
415
-                $dtt_to_remove->refresh_cache_of_related_objects();
416
-            }
417
-        }
418
-        return $saved_dtt_objs;
419
-    }
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
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
380
+			// before going any further make sure our dates are setup correctly
381
+			// so that the end date is always equal or greater than the start date.
382
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
383
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
384
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
385
+				$datetime->save();
386
+			}
387
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
388
+			// because it is possible there was a new one created for the autosave.
389
+			// (save the ID for both key and value to avoid duplications)
390
+			$DTT_ID = $datetime->ID();
391
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
392
+			$saved_dtt_objs[ $row ] = $datetime;
393
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
394
+		}
395
+		$event->save();
396
+		// now we need to REMOVE any datetimes that got deleted.
397
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
398
+		// So its safe to permanently delete at this point.
399
+		$old_datetimes = explode(',', $data['datetime_IDs']);
400
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
401
+		if (is_array($old_datetimes)) {
402
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
403
+			foreach ($datetimes_to_delete as $id) {
404
+				$id = absint($id);
405
+				if (empty($id)) {
406
+					continue;
407
+				}
408
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
409
+				// remove tkt relationships.
410
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
411
+				foreach ($related_tickets as $tkt) {
412
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
413
+				}
414
+				$event->_remove_relation_to($id, 'Datetime');
415
+				$dtt_to_remove->refresh_cache_of_related_objects();
416
+			}
417
+		}
418
+		return $saved_dtt_objs;
419
+	}
420 420
 
421 421
 
422
-    /**
423
-     * update tickets
424
-     *
425
-     * @param  EE_Event      $event           Event object being updated
426
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
427
-     * @param  array         $data            incoming request data
428
-     * @return EE_Ticket[]
429
-     * @throws Exception
430
-     * @throws ReflectionException
431
-     * @throws InvalidInterfaceException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidArgumentException
434
-     * @throws EE_Error
435
-     */
436
-    protected function _update_tickets($event, $saved_datetimes, $data)
437
-    {
438
-        $new_tkt = null;
439
-        $new_default = null;
440
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
441
-        $data = stripslashes_deep($data);
442
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
443
-        $saved_tickets = $datetimes_on_existing = array();
444
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
445
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
446
-            throw new InvalidArgumentException(
447
-                esc_html__(
448
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
449
-                    'event_espresso'
450
-                )
451
-            );
452
-        }
453
-        foreach ($data['edit_tickets'] as $row => $tkt) {
454
-            $update_prices = $create_new_TKT = false;
455
-            // figure out what datetimes were added to the ticket
456
-            // and what datetimes were removed from the ticket in the session.
457
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
458
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
459
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
460
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
461
-            // trim inputs to ensure any excess whitespace is removed.
462
-            $tkt = array_map(
463
-                function ($ticket_data) {
464
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
465
-                },
466
-                $tkt
467
-            );
468
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
469
-            // because we're doing calculations prior to using the models.
470
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
471
-            $ticket_price = isset($tkt['TKT_price'])
472
-                ? round((float) $tkt['TKT_price'], 3)
473
-                : 0;
474
-            // note incoming base price needs converted from localized value.
475
-            $base_price = isset($tkt['TKT_base_price'])
476
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
477
-                : 0;
478
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
479
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
480
-                ? $base_price
481
-                : $ticket_price;
482
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
483
-                ? $tkt['TKT_base_price_ID']
484
-                : 0;
485
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
486
-                ? $data['edit_prices'][ $row ]
487
-                : array();
488
-            $now = null;
489
-            if (empty($tkt['TKT_start_date'])) {
490
-                // lets' use now in the set timezone.
491
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
492
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
493
-            }
494
-            if (empty($tkt['TKT_end_date'])) {
495
-                /**
496
-                 * set the TKT_end_date to the first datetime attached to the ticket.
497
-                 */
498
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
499
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
500
-            }
501
-            $TKT_values = array(
502
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
503
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
504
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
505
-                'TKT_description' => ! empty($tkt['TKT_description'])
506
-                                     && $tkt['TKT_description'] !== esc_html__(
507
-                                         'You can modify this description',
508
-                                         'event_espresso'
509
-                                     )
510
-                    ? $tkt['TKT_description']
511
-                    : '',
512
-                'TKT_start_date'  => $tkt['TKT_start_date'],
513
-                'TKT_end_date'    => $tkt['TKT_end_date'],
514
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
515
-                    ? EE_INF
516
-                    : $tkt['TKT_qty'],
517
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
518
-                    ? EE_INF
519
-                    : $tkt['TKT_uses'],
520
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
521
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
522
-                'TKT_row'         => $row,
523
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
524
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
525
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
526
-                'TKT_price'       => $ticket_price,
527
-            );
528
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
529
-            // which means in turn that the prices will become new prices as well.
530
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
531
-                $TKT_values['TKT_ID'] = 0;
532
-                $TKT_values['TKT_is_default'] = 0;
533
-                $update_prices = true;
534
-            }
535
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
536
-            // we actually do our saves ahead of doing any add_relations to
537
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
538
-            // but DID have it's items modified.
539
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
540
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
541
-            if (absint($TKT_values['TKT_ID'])) {
542
-                $ticket = EE_Registry::instance()
543
-                                     ->load_model('Ticket', array($timezone))
544
-                                     ->get_one_by_ID($tkt['TKT_ID']);
545
-                if ($ticket instanceof EE_Ticket) {
546
-                    $ticket = $this->_update_ticket_datetimes(
547
-                        $ticket,
548
-                        $saved_datetimes,
549
-                        $datetimes_added,
550
-                        $datetimes_removed
551
-                    );
552
-                    // are there any registrations using this ticket ?
553
-                    $tickets_sold = $ticket->count_related(
554
-                        'Registration',
555
-                        array(
556
-                            array(
557
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
558
-                            ),
559
-                        )
560
-                    );
561
-                    // set ticket formats
562
-                    $ticket->set_date_format($this->_date_format_strings['date']);
563
-                    $ticket->set_time_format($this->_date_format_strings['time']);
564
-                    // let's just check the total price for the existing ticket
565
-                    // and determine if it matches the new total price.
566
-                    // if they are different then we create a new ticket (if tickets sold)
567
-                    // if they aren't different then we go ahead and modify existing ticket.
568
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
569
-                    // set new values
570
-                    foreach ($TKT_values as $field => $value) {
571
-                        if ($field === 'TKT_qty') {
572
-                            $ticket->set_qty($value);
573
-                        } else {
574
-                            $ticket->set($field, $value);
575
-                        }
576
-                    }
577
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
578
-                    // Otherwise we have to create a new ticket.
579
-                    if ($create_new_TKT) {
580
-                        $new_tkt = $this->_duplicate_ticket(
581
-                            $ticket,
582
-                            $price_rows,
583
-                            $ticket_price,
584
-                            $base_price,
585
-                            $base_price_id
586
-                        );
587
-                    }
588
-                }
589
-            } else {
590
-                // no TKT_id so a new TKT
591
-                $ticket = EE_Ticket::new_instance(
592
-                    $TKT_values,
593
-                    $timezone,
594
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
595
-                );
596
-                if ($ticket instanceof EE_Ticket) {
597
-                    // make sure ticket has an ID of setting relations won't work
598
-                    $ticket->save();
599
-                    $ticket = $this->_update_ticket_datetimes(
600
-                        $ticket,
601
-                        $saved_datetimes,
602
-                        $datetimes_added,
603
-                        $datetimes_removed
604
-                    );
605
-                    $update_prices = true;
606
-                }
607
-            }
608
-            // make sure any current values have been saved.
609
-            // $ticket->save();
610
-            // before going any further make sure our dates are setup correctly
611
-            // so that the end date is always equal or greater than the start date.
612
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
613
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
614
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
615
-            }
616
-            // let's make sure the base price is handled
617
-            $ticket = ! $create_new_TKT
618
-                ? $this->_add_prices_to_ticket(
619
-                    array(),
620
-                    $ticket,
621
-                    $update_prices,
622
-                    $base_price,
623
-                    $base_price_id
624
-                )
625
-                : $ticket;
626
-            // add/update price_modifiers
627
-            $ticket = ! $create_new_TKT
628
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
629
-                : $ticket;
630
-            // need to make sue that the TKT_price is accurate after saving the prices.
631
-            $ticket->ensure_TKT_Price_correct();
632
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
633
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
634
-                $update_prices = true;
635
-                $new_default = clone $ticket;
636
-                $new_default->set('TKT_ID', 0);
637
-                $new_default->set('TKT_is_default', 1);
638
-                $new_default->set('TKT_row', 1);
639
-                $new_default->set('TKT_price', $ticket_price);
640
-                // remove any dtt relations cause we DON'T want dtt relations attached
641
-                // (note this is just removing the cached relations in the object)
642
-                $new_default->_remove_relations('Datetime');
643
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
644
-                $new_default = $this->_add_prices_to_ticket(
645
-                    $price_rows,
646
-                    $new_default,
647
-                    $update_prices
648
-                );
649
-                // don't forget the base price!
650
-                $new_default = $this->_add_prices_to_ticket(
651
-                    array(),
652
-                    $new_default,
653
-                    $update_prices,
654
-                    $base_price,
655
-                    $base_price_id
656
-                );
657
-                $new_default->save();
658
-                do_action(
659
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
660
-                    $new_default,
661
-                    $row,
662
-                    $ticket,
663
-                    $data
664
-                );
665
-            }
666
-            // DO ALL dtt relationships for both current tickets and any archived tickets
667
-            // for the given dtt that are related to the current ticket.
668
-            // TODO... not sure exactly how we're going to do this considering we don't know
669
-            // what current ticket the archived tickets are related to
670
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
671
-            // let's assign any tickets that have been setup to the saved_tickets tracker
672
-            // save existing TKT
673
-            $ticket->save();
674
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
675
-                // save new TKT
676
-                $new_tkt->save();
677
-                // add new ticket to array
678
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
679
-                do_action(
680
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
681
-                    $new_tkt,
682
-                    $row,
683
-                    $tkt,
684
-                    $data
685
-                );
686
-            } else {
687
-                // add tkt to saved tkts
688
-                $saved_tickets[ $ticket->ID() ] = $ticket;
689
-                do_action(
690
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
691
-                    $ticket,
692
-                    $row,
693
-                    $tkt,
694
-                    $data
695
-                );
696
-            }
697
-        }
698
-        // now we need to handle tickets actually "deleted permanently".
699
-        // There are cases where we'd want this to happen
700
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
701
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
702
-        // No sense in keeping all the related data in the db!
703
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
704
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
705
-        foreach ($tickets_removed as $id) {
706
-            $id = absint($id);
707
-            // get the ticket for this id
708
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
709
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
710
-            if ($tkt_to_remove->get('TKT_is_default')) {
711
-                continue;
712
-            }
713
-            // if this tkt has any registrations attached so then we just ARCHIVE
714
-            // because we don't actually permanently delete these tickets.
715
-            if ($tkt_to_remove->count_related('Registration') > 0) {
716
-                $tkt_to_remove->delete();
717
-                continue;
718
-            }
719
-            // need to get all the related datetimes on this ticket and remove from every single one of them
720
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
721
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
722
-            foreach ($datetimes as $datetime) {
723
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
724
-            }
725
-            // need to do the same for prices (except these prices can also be deleted because again,
726
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
727
-            $tkt_to_remove->delete_related_permanently('Price');
728
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
729
-            // finally let's delete this ticket
730
-            // (which should not be blocked at this point b/c we've removed all our relationships)
731
-            $tkt_to_remove->delete_permanently();
732
-        }
733
-        return $saved_tickets;
734
-    }
422
+	/**
423
+	 * update tickets
424
+	 *
425
+	 * @param  EE_Event      $event           Event object being updated
426
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
427
+	 * @param  array         $data            incoming request data
428
+	 * @return EE_Ticket[]
429
+	 * @throws Exception
430
+	 * @throws ReflectionException
431
+	 * @throws InvalidInterfaceException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidArgumentException
434
+	 * @throws EE_Error
435
+	 */
436
+	protected function _update_tickets($event, $saved_datetimes, $data)
437
+	{
438
+		$new_tkt = null;
439
+		$new_default = null;
440
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
441
+		$data = stripslashes_deep($data);
442
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
443
+		$saved_tickets = $datetimes_on_existing = array();
444
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
445
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
446
+			throw new InvalidArgumentException(
447
+				esc_html__(
448
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
449
+					'event_espresso'
450
+				)
451
+			);
452
+		}
453
+		foreach ($data['edit_tickets'] as $row => $tkt) {
454
+			$update_prices = $create_new_TKT = false;
455
+			// figure out what datetimes were added to the ticket
456
+			// and what datetimes were removed from the ticket in the session.
457
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
458
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
459
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
460
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
461
+			// trim inputs to ensure any excess whitespace is removed.
462
+			$tkt = array_map(
463
+				function ($ticket_data) {
464
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
465
+				},
466
+				$tkt
467
+			);
468
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
469
+			// because we're doing calculations prior to using the models.
470
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
471
+			$ticket_price = isset($tkt['TKT_price'])
472
+				? round((float) $tkt['TKT_price'], 3)
473
+				: 0;
474
+			// note incoming base price needs converted from localized value.
475
+			$base_price = isset($tkt['TKT_base_price'])
476
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
477
+				: 0;
478
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
479
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
480
+				? $base_price
481
+				: $ticket_price;
482
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
483
+				? $tkt['TKT_base_price_ID']
484
+				: 0;
485
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
486
+				? $data['edit_prices'][ $row ]
487
+				: array();
488
+			$now = null;
489
+			if (empty($tkt['TKT_start_date'])) {
490
+				// lets' use now in the set timezone.
491
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
492
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
493
+			}
494
+			if (empty($tkt['TKT_end_date'])) {
495
+				/**
496
+				 * set the TKT_end_date to the first datetime attached to the ticket.
497
+				 */
498
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
499
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
500
+			}
501
+			$TKT_values = array(
502
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
503
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
504
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
505
+				'TKT_description' => ! empty($tkt['TKT_description'])
506
+									 && $tkt['TKT_description'] !== esc_html__(
507
+										 'You can modify this description',
508
+										 'event_espresso'
509
+									 )
510
+					? $tkt['TKT_description']
511
+					: '',
512
+				'TKT_start_date'  => $tkt['TKT_start_date'],
513
+				'TKT_end_date'    => $tkt['TKT_end_date'],
514
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
515
+					? EE_INF
516
+					: $tkt['TKT_qty'],
517
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
518
+					? EE_INF
519
+					: $tkt['TKT_uses'],
520
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
521
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
522
+				'TKT_row'         => $row,
523
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
524
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
525
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
526
+				'TKT_price'       => $ticket_price,
527
+			);
528
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
529
+			// which means in turn that the prices will become new prices as well.
530
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
531
+				$TKT_values['TKT_ID'] = 0;
532
+				$TKT_values['TKT_is_default'] = 0;
533
+				$update_prices = true;
534
+			}
535
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
536
+			// we actually do our saves ahead of doing any add_relations to
537
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
538
+			// but DID have it's items modified.
539
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
540
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
541
+			if (absint($TKT_values['TKT_ID'])) {
542
+				$ticket = EE_Registry::instance()
543
+									 ->load_model('Ticket', array($timezone))
544
+									 ->get_one_by_ID($tkt['TKT_ID']);
545
+				if ($ticket instanceof EE_Ticket) {
546
+					$ticket = $this->_update_ticket_datetimes(
547
+						$ticket,
548
+						$saved_datetimes,
549
+						$datetimes_added,
550
+						$datetimes_removed
551
+					);
552
+					// are there any registrations using this ticket ?
553
+					$tickets_sold = $ticket->count_related(
554
+						'Registration',
555
+						array(
556
+							array(
557
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
558
+							),
559
+						)
560
+					);
561
+					// set ticket formats
562
+					$ticket->set_date_format($this->_date_format_strings['date']);
563
+					$ticket->set_time_format($this->_date_format_strings['time']);
564
+					// let's just check the total price for the existing ticket
565
+					// and determine if it matches the new total price.
566
+					// if they are different then we create a new ticket (if tickets sold)
567
+					// if they aren't different then we go ahead and modify existing ticket.
568
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
569
+					// set new values
570
+					foreach ($TKT_values as $field => $value) {
571
+						if ($field === 'TKT_qty') {
572
+							$ticket->set_qty($value);
573
+						} else {
574
+							$ticket->set($field, $value);
575
+						}
576
+					}
577
+					// if $create_new_TKT is false then we can safely update the existing ticket.
578
+					// Otherwise we have to create a new ticket.
579
+					if ($create_new_TKT) {
580
+						$new_tkt = $this->_duplicate_ticket(
581
+							$ticket,
582
+							$price_rows,
583
+							$ticket_price,
584
+							$base_price,
585
+							$base_price_id
586
+						);
587
+					}
588
+				}
589
+			} else {
590
+				// no TKT_id so a new TKT
591
+				$ticket = EE_Ticket::new_instance(
592
+					$TKT_values,
593
+					$timezone,
594
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
595
+				);
596
+				if ($ticket instanceof EE_Ticket) {
597
+					// make sure ticket has an ID of setting relations won't work
598
+					$ticket->save();
599
+					$ticket = $this->_update_ticket_datetimes(
600
+						$ticket,
601
+						$saved_datetimes,
602
+						$datetimes_added,
603
+						$datetimes_removed
604
+					);
605
+					$update_prices = true;
606
+				}
607
+			}
608
+			// make sure any current values have been saved.
609
+			// $ticket->save();
610
+			// before going any further make sure our dates are setup correctly
611
+			// so that the end date is always equal or greater than the start date.
612
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
613
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
614
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
615
+			}
616
+			// let's make sure the base price is handled
617
+			$ticket = ! $create_new_TKT
618
+				? $this->_add_prices_to_ticket(
619
+					array(),
620
+					$ticket,
621
+					$update_prices,
622
+					$base_price,
623
+					$base_price_id
624
+				)
625
+				: $ticket;
626
+			// add/update price_modifiers
627
+			$ticket = ! $create_new_TKT
628
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
629
+				: $ticket;
630
+			// need to make sue that the TKT_price is accurate after saving the prices.
631
+			$ticket->ensure_TKT_Price_correct();
632
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
633
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
634
+				$update_prices = true;
635
+				$new_default = clone $ticket;
636
+				$new_default->set('TKT_ID', 0);
637
+				$new_default->set('TKT_is_default', 1);
638
+				$new_default->set('TKT_row', 1);
639
+				$new_default->set('TKT_price', $ticket_price);
640
+				// remove any dtt relations cause we DON'T want dtt relations attached
641
+				// (note this is just removing the cached relations in the object)
642
+				$new_default->_remove_relations('Datetime');
643
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
644
+				$new_default = $this->_add_prices_to_ticket(
645
+					$price_rows,
646
+					$new_default,
647
+					$update_prices
648
+				);
649
+				// don't forget the base price!
650
+				$new_default = $this->_add_prices_to_ticket(
651
+					array(),
652
+					$new_default,
653
+					$update_prices,
654
+					$base_price,
655
+					$base_price_id
656
+				);
657
+				$new_default->save();
658
+				do_action(
659
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
660
+					$new_default,
661
+					$row,
662
+					$ticket,
663
+					$data
664
+				);
665
+			}
666
+			// DO ALL dtt relationships for both current tickets and any archived tickets
667
+			// for the given dtt that are related to the current ticket.
668
+			// TODO... not sure exactly how we're going to do this considering we don't know
669
+			// what current ticket the archived tickets are related to
670
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
671
+			// let's assign any tickets that have been setup to the saved_tickets tracker
672
+			// save existing TKT
673
+			$ticket->save();
674
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
675
+				// save new TKT
676
+				$new_tkt->save();
677
+				// add new ticket to array
678
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
679
+				do_action(
680
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
681
+					$new_tkt,
682
+					$row,
683
+					$tkt,
684
+					$data
685
+				);
686
+			} else {
687
+				// add tkt to saved tkts
688
+				$saved_tickets[ $ticket->ID() ] = $ticket;
689
+				do_action(
690
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
691
+					$ticket,
692
+					$row,
693
+					$tkt,
694
+					$data
695
+				);
696
+			}
697
+		}
698
+		// now we need to handle tickets actually "deleted permanently".
699
+		// There are cases where we'd want this to happen
700
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
701
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
702
+		// No sense in keeping all the related data in the db!
703
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
704
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
705
+		foreach ($tickets_removed as $id) {
706
+			$id = absint($id);
707
+			// get the ticket for this id
708
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
709
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
710
+			if ($tkt_to_remove->get('TKT_is_default')) {
711
+				continue;
712
+			}
713
+			// if this tkt has any registrations attached so then we just ARCHIVE
714
+			// because we don't actually permanently delete these tickets.
715
+			if ($tkt_to_remove->count_related('Registration') > 0) {
716
+				$tkt_to_remove->delete();
717
+				continue;
718
+			}
719
+			// need to get all the related datetimes on this ticket and remove from every single one of them
720
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
721
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
722
+			foreach ($datetimes as $datetime) {
723
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
724
+			}
725
+			// need to do the same for prices (except these prices can also be deleted because again,
726
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
727
+			$tkt_to_remove->delete_related_permanently('Price');
728
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
729
+			// finally let's delete this ticket
730
+			// (which should not be blocked at this point b/c we've removed all our relationships)
731
+			$tkt_to_remove->delete_permanently();
732
+		}
733
+		return $saved_tickets;
734
+	}
735 735
 
736 736
 
737
-    /**
738
-     * @access  protected
739
-     * @param EE_Ticket      $ticket
740
-     * @param \EE_Datetime[] $saved_datetimes
741
-     * @param \EE_Datetime[] $added_datetimes
742
-     * @param \EE_Datetime[] $removed_datetimes
743
-     * @return EE_Ticket
744
-     * @throws EE_Error
745
-     */
746
-    protected function _update_ticket_datetimes(
747
-        EE_Ticket $ticket,
748
-        $saved_datetimes = array(),
749
-        $added_datetimes = array(),
750
-        $removed_datetimes = array()
751
-    ) {
752
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
753
-        // and removing the ticket from datetimes it got removed from.
754
-        // first let's add datetimes
755
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
756
-            foreach ($added_datetimes as $row_id) {
757
-                $row_id = (int) $row_id;
758
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
759
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
760
-                    // Is this an existing ticket (has an ID) and does it have any sold?
761
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
762
-                    if ($ticket->ID() && $ticket->sold() > 0) {
763
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
764
-                    }
765
-                }
766
-            }
767
-        }
768
-        // then remove datetimes
769
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
770
-            foreach ($removed_datetimes as $row_id) {
771
-                $row_id = (int) $row_id;
772
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
773
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
774
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
775
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
776
-                    // Is this an existing ticket (has an ID) and does it have any sold?
777
-                    // If so, then we need to remove it's sold from the DTT_sold.
778
-                    if ($ticket->ID() && $ticket->sold() > 0) {
779
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
780
-                    }
781
-                }
782
-            }
783
-        }
784
-        // cap ticket qty by datetime reg limits
785
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
-        return $ticket;
787
-    }
737
+	/**
738
+	 * @access  protected
739
+	 * @param EE_Ticket      $ticket
740
+	 * @param \EE_Datetime[] $saved_datetimes
741
+	 * @param \EE_Datetime[] $added_datetimes
742
+	 * @param \EE_Datetime[] $removed_datetimes
743
+	 * @return EE_Ticket
744
+	 * @throws EE_Error
745
+	 */
746
+	protected function _update_ticket_datetimes(
747
+		EE_Ticket $ticket,
748
+		$saved_datetimes = array(),
749
+		$added_datetimes = array(),
750
+		$removed_datetimes = array()
751
+	) {
752
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
753
+		// and removing the ticket from datetimes it got removed from.
754
+		// first let's add datetimes
755
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
756
+			foreach ($added_datetimes as $row_id) {
757
+				$row_id = (int) $row_id;
758
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
759
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
760
+					// Is this an existing ticket (has an ID) and does it have any sold?
761
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
762
+					if ($ticket->ID() && $ticket->sold() > 0) {
763
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
764
+					}
765
+				}
766
+			}
767
+		}
768
+		// then remove datetimes
769
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
770
+			foreach ($removed_datetimes as $row_id) {
771
+				$row_id = (int) $row_id;
772
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
773
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
774
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
775
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
776
+					// Is this an existing ticket (has an ID) and does it have any sold?
777
+					// If so, then we need to remove it's sold from the DTT_sold.
778
+					if ($ticket->ID() && $ticket->sold() > 0) {
779
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
780
+					}
781
+				}
782
+			}
783
+		}
784
+		// cap ticket qty by datetime reg limits
785
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
786
+		return $ticket;
787
+	}
788 788
 
789 789
 
790
-    /**
791
-     * @access  protected
792
-     * @param EE_Ticket $ticket
793
-     * @param array     $price_rows
794
-     * @param int       $ticket_price
795
-     * @param int       $base_price
796
-     * @param int       $base_price_id
797
-     * @return EE_Ticket
798
-     * @throws ReflectionException
799
-     * @throws InvalidArgumentException
800
-     * @throws InvalidInterfaceException
801
-     * @throws InvalidDataTypeException
802
-     * @throws EE_Error
803
-     */
804
-    protected function _duplicate_ticket(
805
-        EE_Ticket $ticket,
806
-        $price_rows = array(),
807
-        $ticket_price = 0,
808
-        $base_price = 0,
809
-        $base_price_id = 0
810
-    ) {
811
-        // create new ticket that's a copy of the existing
812
-        // except a new id of course (and not archived)
813
-        // AND has the new TKT_price associated with it.
814
-        $new_ticket = clone $ticket;
815
-        $new_ticket->set('TKT_ID', 0);
816
-        $new_ticket->set_deleted(0);
817
-        $new_ticket->set_price($ticket_price);
818
-        $new_ticket->set_sold(0);
819
-        // let's get a new ID for this ticket
820
-        $new_ticket->save();
821
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
-        $datetimes_on_existing = $ticket->datetimes();
823
-        $new_ticket = $this->_update_ticket_datetimes(
824
-            $new_ticket,
825
-            $datetimes_on_existing,
826
-            array_keys($datetimes_on_existing)
827
-        );
828
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
-        // available.
831
-        if ($ticket->sold() > 0) {
832
-            $new_qty = $ticket->qty() - $ticket->sold();
833
-            $new_ticket->set_qty($new_qty);
834
-        }
835
-        // now we update the prices just for this ticket
836
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
-        // and we update the base price
838
-        $new_ticket = $this->_add_prices_to_ticket(
839
-            array(),
840
-            $new_ticket,
841
-            true,
842
-            $base_price,
843
-            $base_price_id
844
-        );
845
-        return $new_ticket;
846
-    }
790
+	/**
791
+	 * @access  protected
792
+	 * @param EE_Ticket $ticket
793
+	 * @param array     $price_rows
794
+	 * @param int       $ticket_price
795
+	 * @param int       $base_price
796
+	 * @param int       $base_price_id
797
+	 * @return EE_Ticket
798
+	 * @throws ReflectionException
799
+	 * @throws InvalidArgumentException
800
+	 * @throws InvalidInterfaceException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws EE_Error
803
+	 */
804
+	protected function _duplicate_ticket(
805
+		EE_Ticket $ticket,
806
+		$price_rows = array(),
807
+		$ticket_price = 0,
808
+		$base_price = 0,
809
+		$base_price_id = 0
810
+	) {
811
+		// create new ticket that's a copy of the existing
812
+		// except a new id of course (and not archived)
813
+		// AND has the new TKT_price associated with it.
814
+		$new_ticket = clone $ticket;
815
+		$new_ticket->set('TKT_ID', 0);
816
+		$new_ticket->set_deleted(0);
817
+		$new_ticket->set_price($ticket_price);
818
+		$new_ticket->set_sold(0);
819
+		// let's get a new ID for this ticket
820
+		$new_ticket->save();
821
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
822
+		$datetimes_on_existing = $ticket->datetimes();
823
+		$new_ticket = $this->_update_ticket_datetimes(
824
+			$new_ticket,
825
+			$datetimes_on_existing,
826
+			array_keys($datetimes_on_existing)
827
+		);
828
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
829
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
830
+		// available.
831
+		if ($ticket->sold() > 0) {
832
+			$new_qty = $ticket->qty() - $ticket->sold();
833
+			$new_ticket->set_qty($new_qty);
834
+		}
835
+		// now we update the prices just for this ticket
836
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
837
+		// and we update the base price
838
+		$new_ticket = $this->_add_prices_to_ticket(
839
+			array(),
840
+			$new_ticket,
841
+			true,
842
+			$base_price,
843
+			$base_price_id
844
+		);
845
+		return $new_ticket;
846
+	}
847 847
 
848 848
 
849
-    /**
850
-     * This attaches a list of given prices to a ticket.
851
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
-     * price info and prices are automatically "archived" via the ticket.
854
-     *
855
-     * @access  private
856
-     * @param array     $prices        Array of prices from the form.
857
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
-     * @return EE_Ticket
862
-     * @throws ReflectionException
863
-     * @throws InvalidArgumentException
864
-     * @throws InvalidInterfaceException
865
-     * @throws InvalidDataTypeException
866
-     * @throws EE_Error
867
-     */
868
-    protected function _add_prices_to_ticket(
869
-        $prices = array(),
870
-        EE_Ticket $ticket,
871
-        $new_prices = false,
872
-        $base_price = false,
873
-        $base_price_id = false
874
-    ) {
875
-        // let's just get any current prices that may exist on the given ticket
876
-        // so we can remove any prices that got trashed in this session.
877
-        $current_prices_on_ticket = $base_price !== false
878
-            ? $ticket->base_price(true)
879
-            : $ticket->price_modifiers();
880
-        $updated_prices = array();
881
-        // if $base_price ! FALSE then updating a base price.
882
-        if ($base_price !== false) {
883
-            $prices[1] = array(
884
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
-                'PRT_ID'     => 1,
886
-                'PRC_amount' => $base_price,
887
-                'PRC_name'   => $ticket->get('TKT_name'),
888
-                'PRC_desc'   => $ticket->get('TKT_description'),
889
-            );
890
-        }
891
-        // possibly need to save tkt
892
-        if (! $ticket->ID()) {
893
-            $ticket->save();
894
-        }
895
-        foreach ($prices as $row => $prc) {
896
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
-            if (empty($prt_id)) {
898
-                continue;
899
-            } //prices MUST have a price type id.
900
-            $PRC_values = array(
901
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
-                'PRT_ID'         => $prt_id,
903
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
-                'PRC_is_default' => false,
907
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
908
-                'PRC_order'      => $row,
909
-            );
910
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
-                $PRC_values['PRC_ID'] = 0;
912
-                $price = EE_Registry::instance()->load_class(
913
-                    'Price',
914
-                    array($PRC_values),
915
-                    false,
916
-                    false
917
-                );
918
-            } else {
919
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
-                // update this price with new values
921
-                foreach ($PRC_values as $field => $value) {
922
-                    $price->set($field, $value);
923
-                }
924
-            }
925
-            $price->save();
926
-            $updated_prices[ $price->ID() ] = $price;
927
-            $ticket->_add_relation_to($price, 'Price');
928
-        }
929
-        // now let's remove any prices that got removed from the ticket
930
-        if (! empty($current_prices_on_ticket)) {
931
-            $current = array_keys($current_prices_on_ticket);
932
-            $updated = array_keys($updated_prices);
933
-            $prices_to_remove = array_diff($current, $updated);
934
-            if (! empty($prices_to_remove)) {
935
-                foreach ($prices_to_remove as $prc_id) {
936
-                    $p = $current_prices_on_ticket[ $prc_id ];
937
-                    $ticket->_remove_relation_to($p, 'Price');
938
-                    // delete permanently the price
939
-                    $p->delete_permanently();
940
-                }
941
-            }
942
-        }
943
-        return $ticket;
944
-    }
849
+	/**
850
+	 * This attaches a list of given prices to a ticket.
851
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
852
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
853
+	 * price info and prices are automatically "archived" via the ticket.
854
+	 *
855
+	 * @access  private
856
+	 * @param array     $prices        Array of prices from the form.
857
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
858
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
859
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
860
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
861
+	 * @return EE_Ticket
862
+	 * @throws ReflectionException
863
+	 * @throws InvalidArgumentException
864
+	 * @throws InvalidInterfaceException
865
+	 * @throws InvalidDataTypeException
866
+	 * @throws EE_Error
867
+	 */
868
+	protected function _add_prices_to_ticket(
869
+		$prices = array(),
870
+		EE_Ticket $ticket,
871
+		$new_prices = false,
872
+		$base_price = false,
873
+		$base_price_id = false
874
+	) {
875
+		// let's just get any current prices that may exist on the given ticket
876
+		// so we can remove any prices that got trashed in this session.
877
+		$current_prices_on_ticket = $base_price !== false
878
+			? $ticket->base_price(true)
879
+			: $ticket->price_modifiers();
880
+		$updated_prices = array();
881
+		// if $base_price ! FALSE then updating a base price.
882
+		if ($base_price !== false) {
883
+			$prices[1] = array(
884
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
885
+				'PRT_ID'     => 1,
886
+				'PRC_amount' => $base_price,
887
+				'PRC_name'   => $ticket->get('TKT_name'),
888
+				'PRC_desc'   => $ticket->get('TKT_description'),
889
+			);
890
+		}
891
+		// possibly need to save tkt
892
+		if (! $ticket->ID()) {
893
+			$ticket->save();
894
+		}
895
+		foreach ($prices as $row => $prc) {
896
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
897
+			if (empty($prt_id)) {
898
+				continue;
899
+			} //prices MUST have a price type id.
900
+			$PRC_values = array(
901
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
902
+				'PRT_ID'         => $prt_id,
903
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
904
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
905
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
906
+				'PRC_is_default' => false,
907
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
908
+				'PRC_order'      => $row,
909
+			);
910
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
911
+				$PRC_values['PRC_ID'] = 0;
912
+				$price = EE_Registry::instance()->load_class(
913
+					'Price',
914
+					array($PRC_values),
915
+					false,
916
+					false
917
+				);
918
+			} else {
919
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
920
+				// update this price with new values
921
+				foreach ($PRC_values as $field => $value) {
922
+					$price->set($field, $value);
923
+				}
924
+			}
925
+			$price->save();
926
+			$updated_prices[ $price->ID() ] = $price;
927
+			$ticket->_add_relation_to($price, 'Price');
928
+		}
929
+		// now let's remove any prices that got removed from the ticket
930
+		if (! empty($current_prices_on_ticket)) {
931
+			$current = array_keys($current_prices_on_ticket);
932
+			$updated = array_keys($updated_prices);
933
+			$prices_to_remove = array_diff($current, $updated);
934
+			if (! empty($prices_to_remove)) {
935
+				foreach ($prices_to_remove as $prc_id) {
936
+					$p = $current_prices_on_ticket[ $prc_id ];
937
+					$ticket->_remove_relation_to($p, 'Price');
938
+					// delete permanently the price
939
+					$p->delete_permanently();
940
+				}
941
+			}
942
+		}
943
+		return $ticket;
944
+	}
945 945
 
946 946
 
947
-    /**
948
-     * @param Events_Admin_Page $event_admin_obj
949
-     * @return Events_Admin_Page
950
-     */
951
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
-    {
953
-        return $event_admin_obj;
954
-        // doing nothing for the moment.
955
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
-        // (use the set_template_args() method)
957
-        /**
958
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
-         * 1. TKT_is_default_selector (visible)
960
-         * 2. TKT_is_default (hidden)
961
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
-         * this ticket to be saved as a default.
964
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
965
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
-         * the TKT HAS been saved as a default..
968
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
-         * On Autosave:
970
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
-         * then set the TKT_is_default to false.
972
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
-         */
976
-    }
947
+	/**
948
+	 * @param Events_Admin_Page $event_admin_obj
949
+	 * @return Events_Admin_Page
950
+	 */
951
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
952
+	{
953
+		return $event_admin_obj;
954
+		// doing nothing for the moment.
955
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
956
+		// (use the set_template_args() method)
957
+		/**
958
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
959
+		 * 1. TKT_is_default_selector (visible)
960
+		 * 2. TKT_is_default (hidden)
961
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
962
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
963
+		 * this ticket to be saved as a default.
964
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
965
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
966
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
967
+		 * the TKT HAS been saved as a default..
968
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
969
+		 * On Autosave:
970
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
971
+		 * then set the TKT_is_default to false.
972
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
973
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
974
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
975
+		 */
976
+	}
977 977
 
978 978
 
979
-    /**
980
-     * @throws ReflectionException
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidInterfaceException
983
-     * @throws InvalidDataTypeException
984
-     * @throws DomainException
985
-     * @throws EE_Error
986
-     */
987
-    public function pricing_metabox()
988
-    {
989
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
990
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
991
-        // set is_creating_event property.
992
-        $EVT_ID = $event->ID();
993
-        $this->_is_creating_event = empty($this->_req_data['post']);
994
-        // default main template args
995
-        $main_template_args = array(
996
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
997
-                'event_editor_event_datetimes_help_tab',
998
-                $this->_adminpage_obj->page_slug,
999
-                $this->_adminpage_obj->get_req_action(),
1000
-                false,
1001
-                false
1002
-            ),
1003
-            // todo need to add a filter to the template for the help text
1004
-            // in the Events_Admin_Page core file so we can add further help
1005
-            'existing_datetime_ids'    => '',
1006
-            'total_dtt_rows'           => 1,
1007
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1008
-                'add_new_dtt_info',
1009
-                $this->_adminpage_obj->page_slug,
1010
-                $this->_adminpage_obj->get_req_action(),
1011
-                false,
1012
-                false
1013
-            ),
1014
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1015
-            'datetime_rows'            => '',
1016
-            'show_tickets_container'   => '',
1017
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1018
-            'ticket_rows'              => '',
1019
-            'existing_ticket_ids'      => '',
1020
-            'total_ticket_rows'        => 1,
1021
-            'ticket_js_structure'      => '',
1022
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1023
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1024
-        );
1025
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1026
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1027
-        /**
1028
-         * 1. Start with retrieving Datetimes
1029
-         * 2. For each datetime get related tickets
1030
-         * 3. For each ticket get related prices
1031
-         */
1032
-        /** @var EEM_Datetime $datetime_model */
1033
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1034
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1035
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1036
-        /**
1037
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1038
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1039
-         */
1040
-        $datetime_row = 1;
1041
-        foreach ($datetimes as $datetime) {
1042
-            $DTT_ID = $datetime->get('DTT_ID');
1043
-            $datetime->set('DTT_order', $datetime_row);
1044
-            $existing_datetime_ids[] = $DTT_ID;
1045
-            // tickets attached
1046
-            $related_tickets = $datetime->ID() > 0
1047
-                ? $datetime->get_many_related(
1048
-                    'Ticket',
1049
-                    array(
1050
-                        array(
1051
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1052
-                        ),
1053
-                        'default_where_conditions' => 'none',
1054
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1055
-                    )
1056
-                )
1057
-                : array();
1058
-            // if there are no related tickets this is likely a new event OR autodraft
1059
-            // event so we need to generate the default tickets because datetimes
1060
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1061
-            // datetime on the event.
1062
-            if (empty($related_tickets) && count($datetimes) < 2) {
1063
-                /** @var EEM_Ticket $ticket_model */
1064
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1065
-                $related_tickets = $ticket_model->get_all_default_tickets();
1066
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1067
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1068
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1069
-                $main_default_ticket = reset($related_tickets);
1070
-                if ($main_default_ticket instanceof EE_Ticket) {
1071
-                    foreach ($default_prices as $default_price) {
1072
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1073
-                            continue;
1074
-                        }
1075
-                        $main_default_ticket->cache('Price', $default_price);
1076
-                    }
1077
-                }
1078
-            }
1079
-            // we can't actually setup rows in this loop yet cause we don't know all
1080
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1081
-            // So we're going to temporarily cache some of that information.
1082
-            // loop through and setup the ticket rows and make sure the order is set.
1083
-            foreach ($related_tickets as $ticket) {
1084
-                $TKT_ID = $ticket->get('TKT_ID');
1085
-                $ticket_row = $ticket->get('TKT_row');
1086
-                // we only want unique tickets in our final display!!
1087
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1088
-                    $existing_ticket_ids[] = $TKT_ID;
1089
-                    $all_tickets[] = $ticket;
1090
-                }
1091
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1092
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1093
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1094
-                if (! isset($ticket_datetimes[ $TKT_ID ])
1095
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1096
-                ) {
1097
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1098
-                }
1099
-            }
1100
-            $datetime_row++;
1101
-        }
1102
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1103
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1104
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1105
-        // sort $all_tickets by order
1106
-        usort(
1107
-            $all_tickets,
1108
-            function (EE_Ticket $a, EE_Ticket $b) {
1109
-                $a_order = (int) $a->get('TKT_order');
1110
-                $b_order = (int) $b->get('TKT_order');
1111
-                if ($a_order === $b_order) {
1112
-                    return 0;
1113
-                }
1114
-                return ($a_order < $b_order) ? -1 : 1;
1115
-            }
1116
-        );
1117
-        // k NOW we have all the data we need for setting up the dtt rows
1118
-        // and ticket rows so we start our dtt loop again.
1119
-        $datetime_row = 1;
1120
-        foreach ($datetimes as $datetime) {
1121
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1122
-                $datetime_row,
1123
-                $datetime,
1124
-                $datetime_tickets,
1125
-                $all_tickets,
1126
-                false,
1127
-                $datetimes
1128
-            );
1129
-            $datetime_row++;
1130
-        }
1131
-        // then loop through all tickets for the ticket rows.
1132
-        $ticket_row = 1;
1133
-        foreach ($all_tickets as $ticket) {
1134
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1135
-                $ticket_row,
1136
-                $ticket,
1137
-                $ticket_datetimes,
1138
-                $datetimes,
1139
-                false,
1140
-                $all_tickets
1141
-            );
1142
-            $ticket_row++;
1143
-        }
1144
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1145
-        EEH_Template::display_template(
1146
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1147
-            $main_template_args
1148
-        );
1149
-    }
979
+	/**
980
+	 * @throws ReflectionException
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidInterfaceException
983
+	 * @throws InvalidDataTypeException
984
+	 * @throws DomainException
985
+	 * @throws EE_Error
986
+	 */
987
+	public function pricing_metabox()
988
+	{
989
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
990
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
991
+		// set is_creating_event property.
992
+		$EVT_ID = $event->ID();
993
+		$this->_is_creating_event = empty($this->_req_data['post']);
994
+		// default main template args
995
+		$main_template_args = array(
996
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
997
+				'event_editor_event_datetimes_help_tab',
998
+				$this->_adminpage_obj->page_slug,
999
+				$this->_adminpage_obj->get_req_action(),
1000
+				false,
1001
+				false
1002
+			),
1003
+			// todo need to add a filter to the template for the help text
1004
+			// in the Events_Admin_Page core file so we can add further help
1005
+			'existing_datetime_ids'    => '',
1006
+			'total_dtt_rows'           => 1,
1007
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1008
+				'add_new_dtt_info',
1009
+				$this->_adminpage_obj->page_slug,
1010
+				$this->_adminpage_obj->get_req_action(),
1011
+				false,
1012
+				false
1013
+			),
1014
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1015
+			'datetime_rows'            => '',
1016
+			'show_tickets_container'   => '',
1017
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1018
+			'ticket_rows'              => '',
1019
+			'existing_ticket_ids'      => '',
1020
+			'total_ticket_rows'        => 1,
1021
+			'ticket_js_structure'      => '',
1022
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1023
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1024
+		);
1025
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1026
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1027
+		/**
1028
+		 * 1. Start with retrieving Datetimes
1029
+		 * 2. For each datetime get related tickets
1030
+		 * 3. For each ticket get related prices
1031
+		 */
1032
+		/** @var EEM_Datetime $datetime_model */
1033
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1034
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1035
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1036
+		/**
1037
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1038
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1039
+		 */
1040
+		$datetime_row = 1;
1041
+		foreach ($datetimes as $datetime) {
1042
+			$DTT_ID = $datetime->get('DTT_ID');
1043
+			$datetime->set('DTT_order', $datetime_row);
1044
+			$existing_datetime_ids[] = $DTT_ID;
1045
+			// tickets attached
1046
+			$related_tickets = $datetime->ID() > 0
1047
+				? $datetime->get_many_related(
1048
+					'Ticket',
1049
+					array(
1050
+						array(
1051
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1052
+						),
1053
+						'default_where_conditions' => 'none',
1054
+						'order_by'                 => array('TKT_order' => 'ASC'),
1055
+					)
1056
+				)
1057
+				: array();
1058
+			// if there are no related tickets this is likely a new event OR autodraft
1059
+			// event so we need to generate the default tickets because datetimes
1060
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1061
+			// datetime on the event.
1062
+			if (empty($related_tickets) && count($datetimes) < 2) {
1063
+				/** @var EEM_Ticket $ticket_model */
1064
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1065
+				$related_tickets = $ticket_model->get_all_default_tickets();
1066
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1067
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1068
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1069
+				$main_default_ticket = reset($related_tickets);
1070
+				if ($main_default_ticket instanceof EE_Ticket) {
1071
+					foreach ($default_prices as $default_price) {
1072
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1073
+							continue;
1074
+						}
1075
+						$main_default_ticket->cache('Price', $default_price);
1076
+					}
1077
+				}
1078
+			}
1079
+			// we can't actually setup rows in this loop yet cause we don't know all
1080
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1081
+			// So we're going to temporarily cache some of that information.
1082
+			// loop through and setup the ticket rows and make sure the order is set.
1083
+			foreach ($related_tickets as $ticket) {
1084
+				$TKT_ID = $ticket->get('TKT_ID');
1085
+				$ticket_row = $ticket->get('TKT_row');
1086
+				// we only want unique tickets in our final display!!
1087
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1088
+					$existing_ticket_ids[] = $TKT_ID;
1089
+					$all_tickets[] = $ticket;
1090
+				}
1091
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1092
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1093
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1094
+				if (! isset($ticket_datetimes[ $TKT_ID ])
1095
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1096
+				) {
1097
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1098
+				}
1099
+			}
1100
+			$datetime_row++;
1101
+		}
1102
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1103
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1104
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1105
+		// sort $all_tickets by order
1106
+		usort(
1107
+			$all_tickets,
1108
+			function (EE_Ticket $a, EE_Ticket $b) {
1109
+				$a_order = (int) $a->get('TKT_order');
1110
+				$b_order = (int) $b->get('TKT_order');
1111
+				if ($a_order === $b_order) {
1112
+					return 0;
1113
+				}
1114
+				return ($a_order < $b_order) ? -1 : 1;
1115
+			}
1116
+		);
1117
+		// k NOW we have all the data we need for setting up the dtt rows
1118
+		// and ticket rows so we start our dtt loop again.
1119
+		$datetime_row = 1;
1120
+		foreach ($datetimes as $datetime) {
1121
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1122
+				$datetime_row,
1123
+				$datetime,
1124
+				$datetime_tickets,
1125
+				$all_tickets,
1126
+				false,
1127
+				$datetimes
1128
+			);
1129
+			$datetime_row++;
1130
+		}
1131
+		// then loop through all tickets for the ticket rows.
1132
+		$ticket_row = 1;
1133
+		foreach ($all_tickets as $ticket) {
1134
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1135
+				$ticket_row,
1136
+				$ticket,
1137
+				$ticket_datetimes,
1138
+				$datetimes,
1139
+				false,
1140
+				$all_tickets
1141
+			);
1142
+			$ticket_row++;
1143
+		}
1144
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1145
+		EEH_Template::display_template(
1146
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1147
+			$main_template_args
1148
+		);
1149
+	}
1150 1150
 
1151 1151
 
1152
-    /**
1153
-     * @param int         $datetime_row
1154
-     * @param EE_Datetime $datetime
1155
-     * @param array       $datetime_tickets
1156
-     * @param array       $all_tickets
1157
-     * @param bool        $default
1158
-     * @param array       $all_datetimes
1159
-     * @return mixed
1160
-     * @throws DomainException
1161
-     * @throws EE_Error
1162
-     */
1163
-    protected function _get_datetime_row(
1164
-        $datetime_row,
1165
-        EE_Datetime $datetime,
1166
-        $datetime_tickets = array(),
1167
-        $all_tickets = array(),
1168
-        $default = false,
1169
-        $all_datetimes = array()
1170
-    ) {
1171
-        $dtt_display_template_args = array(
1172
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1173
-                $datetime_row,
1174
-                $datetime,
1175
-                $default,
1176
-                $all_datetimes
1177
-            ),
1178
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1179
-                $datetime_row,
1180
-                $datetime,
1181
-                $datetime_tickets,
1182
-                $all_tickets,
1183
-                $default
1184
-            ),
1185
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1186
-        );
1187
-        return EEH_Template::display_template(
1188
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1189
-            $dtt_display_template_args,
1190
-            true
1191
-        );
1192
-    }
1152
+	/**
1153
+	 * @param int         $datetime_row
1154
+	 * @param EE_Datetime $datetime
1155
+	 * @param array       $datetime_tickets
1156
+	 * @param array       $all_tickets
1157
+	 * @param bool        $default
1158
+	 * @param array       $all_datetimes
1159
+	 * @return mixed
1160
+	 * @throws DomainException
1161
+	 * @throws EE_Error
1162
+	 */
1163
+	protected function _get_datetime_row(
1164
+		$datetime_row,
1165
+		EE_Datetime $datetime,
1166
+		$datetime_tickets = array(),
1167
+		$all_tickets = array(),
1168
+		$default = false,
1169
+		$all_datetimes = array()
1170
+	) {
1171
+		$dtt_display_template_args = array(
1172
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1173
+				$datetime_row,
1174
+				$datetime,
1175
+				$default,
1176
+				$all_datetimes
1177
+			),
1178
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1179
+				$datetime_row,
1180
+				$datetime,
1181
+				$datetime_tickets,
1182
+				$all_tickets,
1183
+				$default
1184
+			),
1185
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1186
+		);
1187
+		return EEH_Template::display_template(
1188
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1189
+			$dtt_display_template_args,
1190
+			true
1191
+		);
1192
+	}
1193 1193
 
1194 1194
 
1195
-    /**
1196
-     * This method is used to generate a dtt fields  edit row.
1197
-     * The same row is used to generate a row with valid DTT objects
1198
-     * and the default row that is used as the skeleton by the js.
1199
-     *
1200
-     * @param int           $datetime_row  The row number for the row being generated.
1201
-     * @param EE_Datetime   $datetime
1202
-     * @param bool          $default       Whether a default row is being generated or not.
1203
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1204
-     * @return string
1205
-     * @throws DomainException
1206
-     * @throws EE_Error
1207
-     */
1208
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1209
-    {
1210
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1211
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1212
-        $template_args = array(
1213
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1214
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1215
-            'edit_dtt_expanded'    => '',
1216
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1217
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1218
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1219
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1220
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1221
-            'DTT_reg_limit'        => $default
1222
-                ? ''
1223
-                : $datetime->get_pretty(
1224
-                    'DTT_reg_limit',
1225
-                    'input'
1226
-                ),
1227
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1228
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1229
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1230
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1231
-                ? ''
1232
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1233
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1234
-                ? 'ee-lock-icon'
1235
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1236
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1237
-                ? ''
1238
-                : EE_Admin_Page::add_query_args_and_nonce(
1239
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1240
-                    REG_ADMIN_URL
1241
-                ),
1242
-        );
1243
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1244
-            ? ' style="display:none"'
1245
-            : '';
1246
-        // allow filtering of template args at this point.
1247
-        $template_args = apply_filters(
1248
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1249
-            $template_args,
1250
-            $datetime_row,
1251
-            $datetime,
1252
-            $default,
1253
-            $all_datetimes,
1254
-            $this->_is_creating_event
1255
-        );
1256
-        return EEH_Template::display_template(
1257
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1258
-            $template_args,
1259
-            true
1260
-        );
1261
-    }
1195
+	/**
1196
+	 * This method is used to generate a dtt fields  edit row.
1197
+	 * The same row is used to generate a row with valid DTT objects
1198
+	 * and the default row that is used as the skeleton by the js.
1199
+	 *
1200
+	 * @param int           $datetime_row  The row number for the row being generated.
1201
+	 * @param EE_Datetime   $datetime
1202
+	 * @param bool          $default       Whether a default row is being generated or not.
1203
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1204
+	 * @return string
1205
+	 * @throws DomainException
1206
+	 * @throws EE_Error
1207
+	 */
1208
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1209
+	{
1210
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1211
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1212
+		$template_args = array(
1213
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1214
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1215
+			'edit_dtt_expanded'    => '',
1216
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1217
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1218
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1219
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1220
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1221
+			'DTT_reg_limit'        => $default
1222
+				? ''
1223
+				: $datetime->get_pretty(
1224
+					'DTT_reg_limit',
1225
+					'input'
1226
+				),
1227
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1228
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1229
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1230
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1231
+				? ''
1232
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1233
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1234
+				? 'ee-lock-icon'
1235
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1236
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1237
+				? ''
1238
+				: EE_Admin_Page::add_query_args_and_nonce(
1239
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1240
+					REG_ADMIN_URL
1241
+				),
1242
+		);
1243
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1244
+			? ' style="display:none"'
1245
+			: '';
1246
+		// allow filtering of template args at this point.
1247
+		$template_args = apply_filters(
1248
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1249
+			$template_args,
1250
+			$datetime_row,
1251
+			$datetime,
1252
+			$default,
1253
+			$all_datetimes,
1254
+			$this->_is_creating_event
1255
+		);
1256
+		return EEH_Template::display_template(
1257
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1258
+			$template_args,
1259
+			true
1260
+		);
1261
+	}
1262 1262
 
1263 1263
 
1264
-    /**
1265
-     * @param int         $datetime_row
1266
-     * @param EE_Datetime $datetime
1267
-     * @param array       $datetime_tickets
1268
-     * @param array       $all_tickets
1269
-     * @param bool        $default
1270
-     * @return mixed
1271
-     * @throws DomainException
1272
-     * @throws EE_Error
1273
-     */
1274
-    protected function _get_dtt_attached_tickets_row(
1275
-        $datetime_row,
1276
-        $datetime,
1277
-        $datetime_tickets = array(),
1278
-        $all_tickets = array(),
1279
-        $default
1280
-    ) {
1281
-        $template_args = array(
1282
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1283
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1284
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1285
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1286
-            'show_tickets_row'                  => ' style="display:none;"',
1287
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1288
-                'add_new_ticket_via_datetime',
1289
-                $this->_adminpage_obj->page_slug,
1290
-                $this->_adminpage_obj->get_req_action(),
1291
-                false,
1292
-                false
1293
-            ),
1294
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1295
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1296
-        );
1297
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1298
-        if (! $default) {
1299
-            $ticket_row = 1;
1300
-            foreach ($all_tickets as $ticket) {
1301
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1302
-                    $datetime_row,
1303
-                    $ticket_row,
1304
-                    $datetime,
1305
-                    $ticket,
1306
-                    $datetime_tickets,
1307
-                    $default
1308
-                );
1309
-                $ticket_row++;
1310
-            }
1311
-        }
1312
-        // filter template args at this point
1313
-        $template_args = apply_filters(
1314
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1315
-            $template_args,
1316
-            $datetime_row,
1317
-            $datetime,
1318
-            $datetime_tickets,
1319
-            $all_tickets,
1320
-            $default,
1321
-            $this->_is_creating_event
1322
-        );
1323
-        return EEH_Template::display_template(
1324
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1325
-            $template_args,
1326
-            true
1327
-        );
1328
-    }
1264
+	/**
1265
+	 * @param int         $datetime_row
1266
+	 * @param EE_Datetime $datetime
1267
+	 * @param array       $datetime_tickets
1268
+	 * @param array       $all_tickets
1269
+	 * @param bool        $default
1270
+	 * @return mixed
1271
+	 * @throws DomainException
1272
+	 * @throws EE_Error
1273
+	 */
1274
+	protected function _get_dtt_attached_tickets_row(
1275
+		$datetime_row,
1276
+		$datetime,
1277
+		$datetime_tickets = array(),
1278
+		$all_tickets = array(),
1279
+		$default
1280
+	) {
1281
+		$template_args = array(
1282
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1283
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1284
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1285
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1286
+			'show_tickets_row'                  => ' style="display:none;"',
1287
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1288
+				'add_new_ticket_via_datetime',
1289
+				$this->_adminpage_obj->page_slug,
1290
+				$this->_adminpage_obj->get_req_action(),
1291
+				false,
1292
+				false
1293
+			),
1294
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1295
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1296
+		);
1297
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1298
+		if (! $default) {
1299
+			$ticket_row = 1;
1300
+			foreach ($all_tickets as $ticket) {
1301
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1302
+					$datetime_row,
1303
+					$ticket_row,
1304
+					$datetime,
1305
+					$ticket,
1306
+					$datetime_tickets,
1307
+					$default
1308
+				);
1309
+				$ticket_row++;
1310
+			}
1311
+		}
1312
+		// filter template args at this point
1313
+		$template_args = apply_filters(
1314
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1315
+			$template_args,
1316
+			$datetime_row,
1317
+			$datetime,
1318
+			$datetime_tickets,
1319
+			$all_tickets,
1320
+			$default,
1321
+			$this->_is_creating_event
1322
+		);
1323
+		return EEH_Template::display_template(
1324
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1325
+			$template_args,
1326
+			true
1327
+		);
1328
+	}
1329 1329
 
1330 1330
 
1331
-    /**
1332
-     * @param int         $datetime_row
1333
-     * @param int         $ticket_row
1334
-     * @param EE_Datetime $datetime
1335
-     * @param EE_Ticket   $ticket
1336
-     * @param array       $datetime_tickets
1337
-     * @param bool        $default
1338
-     * @return mixed
1339
-     * @throws DomainException
1340
-     * @throws EE_Error
1341
-     */
1342
-    protected function _get_datetime_tickets_list_item(
1343
-        $datetime_row,
1344
-        $ticket_row,
1345
-        $datetime,
1346
-        $ticket,
1347
-        $datetime_tickets = array(),
1348
-        $default
1349
-    ) {
1350
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1351
-            ? $datetime_tickets[ $datetime->ID() ]
1352
-            : array();
1353
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1354
-        $no_ticket = $default && empty($ticket);
1355
-        $template_args = array(
1356
-            'dtt_row'                 => $default
1357
-                ? 'DTTNUM'
1358
-                : $datetime_row,
1359
-            'tkt_row'                 => $no_ticket
1360
-                ? 'TICKETNUM'
1361
-                : $ticket_row,
1362
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1363
-                ? ' checked="checked"'
1364
-                : '',
1365
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1366
-                ? ' ticket-selected'
1367
-                : '',
1368
-            'TKT_name'                => $no_ticket
1369
-                ? 'TKTNAME'
1370
-                : $ticket->get('TKT_name'),
1371
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1372
-                ? ' tkt-status-' . EE_Ticket::onsale
1373
-                : ' tkt-status-' . $ticket->ticket_status(),
1374
-        );
1375
-        // filter template args
1376
-        $template_args = apply_filters(
1377
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1378
-            $template_args,
1379
-            $datetime_row,
1380
-            $ticket_row,
1381
-            $datetime,
1382
-            $ticket,
1383
-            $datetime_tickets,
1384
-            $default,
1385
-            $this->_is_creating_event
1386
-        );
1387
-        return EEH_Template::display_template(
1388
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1389
-            $template_args,
1390
-            true
1391
-        );
1392
-    }
1331
+	/**
1332
+	 * @param int         $datetime_row
1333
+	 * @param int         $ticket_row
1334
+	 * @param EE_Datetime $datetime
1335
+	 * @param EE_Ticket   $ticket
1336
+	 * @param array       $datetime_tickets
1337
+	 * @param bool        $default
1338
+	 * @return mixed
1339
+	 * @throws DomainException
1340
+	 * @throws EE_Error
1341
+	 */
1342
+	protected function _get_datetime_tickets_list_item(
1343
+		$datetime_row,
1344
+		$ticket_row,
1345
+		$datetime,
1346
+		$ticket,
1347
+		$datetime_tickets = array(),
1348
+		$default
1349
+	) {
1350
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1351
+			? $datetime_tickets[ $datetime->ID() ]
1352
+			: array();
1353
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1354
+		$no_ticket = $default && empty($ticket);
1355
+		$template_args = array(
1356
+			'dtt_row'                 => $default
1357
+				? 'DTTNUM'
1358
+				: $datetime_row,
1359
+			'tkt_row'                 => $no_ticket
1360
+				? 'TICKETNUM'
1361
+				: $ticket_row,
1362
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1363
+				? ' checked="checked"'
1364
+				: '',
1365
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1366
+				? ' ticket-selected'
1367
+				: '',
1368
+			'TKT_name'                => $no_ticket
1369
+				? 'TKTNAME'
1370
+				: $ticket->get('TKT_name'),
1371
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1372
+				? ' tkt-status-' . EE_Ticket::onsale
1373
+				: ' tkt-status-' . $ticket->ticket_status(),
1374
+		);
1375
+		// filter template args
1376
+		$template_args = apply_filters(
1377
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1378
+			$template_args,
1379
+			$datetime_row,
1380
+			$ticket_row,
1381
+			$datetime,
1382
+			$ticket,
1383
+			$datetime_tickets,
1384
+			$default,
1385
+			$this->_is_creating_event
1386
+		);
1387
+		return EEH_Template::display_template(
1388
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1389
+			$template_args,
1390
+			true
1391
+		);
1392
+	}
1393 1393
 
1394 1394
 
1395
-    /**
1396
-     * This generates the ticket row for tickets.
1397
-     * This same method is used to generate both the actual rows and the js skeleton row
1398
-     * (when default === true)
1399
-     *
1400
-     * @param int           $ticket_row       Represents the row number being generated.
1401
-     * @param               $ticket
1402
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1403
-     *                                        or empty for default
1404
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1405
-     * @param bool          $default          Whether default row being generated or not.
1406
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1407
-     *                                        (or empty in the case of defaults)
1408
-     * @return mixed
1409
-     * @throws InvalidArgumentException
1410
-     * @throws InvalidInterfaceException
1411
-     * @throws InvalidDataTypeException
1412
-     * @throws DomainException
1413
-     * @throws EE_Error
1414
-     * @throws ReflectionException
1415
-     */
1416
-    protected function _get_ticket_row(
1417
-        $ticket_row,
1418
-        $ticket,
1419
-        $ticket_datetimes,
1420
-        $all_datetimes,
1421
-        $default = false,
1422
-        $all_tickets = array()
1423
-    ) {
1424
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1425
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1426
-        $prices = ! empty($ticket) && ! $default
1427
-            ? $ticket->get_many_related(
1428
-                'Price',
1429
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1430
-            )
1431
-            : array();
1432
-        // if there is only one price (which would be the base price)
1433
-        // or NO prices and this ticket is a default ticket,
1434
-        // let's just make sure there are no cached default prices on the object.
1435
-        // This is done by not including any query_params.
1436
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1437
-            $prices = $ticket->prices();
1438
-        }
1439
-        // check if we're dealing with a default ticket in which case
1440
-        // we don't want any starting_ticket_datetime_row values set
1441
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1442
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1443
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1444
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1445
-            ? $ticket_datetimes[ $ticket->ID() ]
1446
-            : array();
1447
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1448
-        $base_price = $default ? null : $ticket->base_price();
1449
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1450
-        // breaking out complicated condition for ticket_status
1451
-        if ($default) {
1452
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1453
-        } else {
1454
-            $ticket_status_class = $ticket->is_default()
1455
-                ? ' tkt-status-' . EE_Ticket::onsale
1456
-                : ' tkt-status-' . $ticket->ticket_status();
1457
-        }
1458
-        // breaking out complicated condition for TKT_taxable
1459
-        if ($default) {
1460
-            $TKT_taxable = '';
1461
-        } else {
1462
-            $TKT_taxable = $ticket->taxable()
1463
-                ? ' checked="checked"'
1464
-                : '';
1465
-        }
1466
-        if ($default) {
1467
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
-        } elseif ($ticket->is_default()) {
1469
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1470
-        } else {
1471
-            $TKT_status = $ticket->ticket_status(true);
1472
-        }
1473
-        if ($default) {
1474
-            $TKT_min = '';
1475
-        } else {
1476
-            $TKT_min = $ticket->min();
1477
-            if ($TKT_min === -1 || $TKT_min === 0) {
1478
-                $TKT_min = '';
1479
-            }
1480
-        }
1481
-        $template_args = array(
1482
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1483
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1484
-            // on initial page load this will always be the correct order.
1485
-            'tkt_status_class'              => $ticket_status_class,
1486
-            'display_edit_tkt_row'          => ' style="display:none;"',
1487
-            'edit_tkt_expanded'             => '',
1488
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1489
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1490
-            'TKT_start_date'                => $default
1491
-                ? ''
1492
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1493
-            'TKT_end_date'                  => $default
1494
-                ? ''
1495
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1496
-            'TKT_status'                    => $TKT_status,
1497
-            'TKT_price'                     => $default
1498
-                ? ''
1499
-                : EEH_Template::format_currency(
1500
-                    $ticket->get_ticket_total_with_taxes(),
1501
-                    false,
1502
-                    false
1503
-                ),
1504
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1505
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1506
-            'TKT_qty'                       => $default
1507
-                ? ''
1508
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1509
-            'TKT_qty_for_input'             => $default
1510
-                ? ''
1511
-                : $ticket->get_pretty('TKT_qty', 'input'),
1512
-            'TKT_uses'                      => $default
1513
-                ? ''
1514
-                : $ticket->get_pretty('TKT_uses', 'input'),
1515
-            'TKT_min'                       => $TKT_min,
1516
-            'TKT_max'                       => $default
1517
-                ? ''
1518
-                : $ticket->get_pretty('TKT_max', 'input'),
1519
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1520
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1521
-            'TKT_registrations'             => $default
1522
-                ? 0
1523
-                : $ticket->count_registrations(
1524
-                    array(
1525
-                        array(
1526
-                            'STS_ID' => array(
1527
-                                '!=',
1528
-                                EEM_Registration::status_id_incomplete,
1529
-                            ),
1530
-                        ),
1531
-                    )
1532
-                ),
1533
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1534
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1535
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1536
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1537
-            'TKT_is_default_selector'       => '',
1538
-            'ticket_price_rows'             => '',
1539
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1540
-                ? ''
1541
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1542
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1543
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1544
-                ? ''
1545
-                : ' style="display:none;"',
1546
-            'show_price_mod_button'         => count($prices) > 1
1547
-                                               || ($default && $count_price_mods > 0)
1548
-                                               || (! $default && $ticket->deleted())
1549
-                ? ' style="display:none;"'
1550
-                : '',
1551
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1552
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1553
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1554
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1555
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1556
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1557
-            'TKT_taxable'                   => $TKT_taxable,
1558
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1559
-                ? ''
1560
-                : ' style="display:none"',
1561
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1562
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1563
-                $ticket_subtotal,
1564
-                false,
1565
-                false
1566
-            ),
1567
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1568
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1569
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1570
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1571
-                ? ' ticket-archived'
1572
-                : '',
1573
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1574
-                                               && $ticket->deleted()
1575
-                                               && ! $ticket->is_permanently_deleteable()
1576
-                ? 'ee-lock-icon '
1577
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1578
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
-                ? ''
1580
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1581
-        );
1582
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1583
-            ? ' style="display:none"'
1584
-            : '';
1585
-        // handle rows that should NOT be empty
1586
-        if (empty($template_args['TKT_start_date'])) {
1587
-            // if empty then the start date will be now.
1588
-            $template_args['TKT_start_date'] = date(
1589
-                $this->_date_time_format,
1590
-                current_time('timestamp')
1591
-            );
1592
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1593
-        }
1594
-        if (empty($template_args['TKT_end_date'])) {
1595
-            // get the earliest datetime (if present);
1596
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1597
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1598
-                    'Datetime',
1599
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1600
-                )
1601
-                : null;
1602
-            if (! empty($earliest_dtt)) {
1603
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1604
-                    'DTT_EVT_start',
1605
-                    $this->_date_time_format
1606
-                );
1607
-            } else {
1608
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1609
-                $template_args['TKT_end_date'] = date(
1610
-                    $this->_date_time_format,
1611
-                    mktime(
1612
-                        24,
1613
-                        0,
1614
-                        0,
1615
-                        date('m'),
1616
-                        date('d') + 29,
1617
-                        date('Y')
1618
-                    )
1619
-                );
1620
-            }
1621
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1622
-        }
1623
-        // generate ticket_datetime items
1624
-        if (! $default) {
1625
-            $datetime_row = 1;
1626
-            foreach ($all_datetimes as $datetime) {
1627
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1628
-                    $datetime_row,
1629
-                    $ticket_row,
1630
-                    $datetime,
1631
-                    $ticket,
1632
-                    $ticket_datetimes,
1633
-                    $default
1634
-                );
1635
-                $datetime_row++;
1636
-            }
1637
-        }
1638
-        $price_row = 1;
1639
-        foreach ($prices as $price) {
1640
-            if (! $price instanceof EE_Price) {
1641
-                continue;
1642
-            }
1643
-            if ($price->is_base_price()) {
1644
-                $price_row++;
1645
-                continue;
1646
-            }
1647
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1648
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1649
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1650
-                $ticket_row,
1651
-                $price_row,
1652
-                $price,
1653
-                $default,
1654
-                $ticket,
1655
-                $show_trash,
1656
-                $show_create
1657
-            );
1658
-            $price_row++;
1659
-        }
1660
-        // filter $template_args
1661
-        $template_args = apply_filters(
1662
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1663
-            $template_args,
1664
-            $ticket_row,
1665
-            $ticket,
1666
-            $ticket_datetimes,
1667
-            $all_datetimes,
1668
-            $default,
1669
-            $all_tickets,
1670
-            $this->_is_creating_event
1671
-        );
1672
-        return EEH_Template::display_template(
1673
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1674
-            $template_args,
1675
-            true
1676
-        );
1677
-    }
1395
+	/**
1396
+	 * This generates the ticket row for tickets.
1397
+	 * This same method is used to generate both the actual rows and the js skeleton row
1398
+	 * (when default === true)
1399
+	 *
1400
+	 * @param int           $ticket_row       Represents the row number being generated.
1401
+	 * @param               $ticket
1402
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1403
+	 *                                        or empty for default
1404
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1405
+	 * @param bool          $default          Whether default row being generated or not.
1406
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1407
+	 *                                        (or empty in the case of defaults)
1408
+	 * @return mixed
1409
+	 * @throws InvalidArgumentException
1410
+	 * @throws InvalidInterfaceException
1411
+	 * @throws InvalidDataTypeException
1412
+	 * @throws DomainException
1413
+	 * @throws EE_Error
1414
+	 * @throws ReflectionException
1415
+	 */
1416
+	protected function _get_ticket_row(
1417
+		$ticket_row,
1418
+		$ticket,
1419
+		$ticket_datetimes,
1420
+		$all_datetimes,
1421
+		$default = false,
1422
+		$all_tickets = array()
1423
+	) {
1424
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1425
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1426
+		$prices = ! empty($ticket) && ! $default
1427
+			? $ticket->get_many_related(
1428
+				'Price',
1429
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1430
+			)
1431
+			: array();
1432
+		// if there is only one price (which would be the base price)
1433
+		// or NO prices and this ticket is a default ticket,
1434
+		// let's just make sure there are no cached default prices on the object.
1435
+		// This is done by not including any query_params.
1436
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1437
+			$prices = $ticket->prices();
1438
+		}
1439
+		// check if we're dealing with a default ticket in which case
1440
+		// we don't want any starting_ticket_datetime_row values set
1441
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1442
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1443
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1444
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1445
+			? $ticket_datetimes[ $ticket->ID() ]
1446
+			: array();
1447
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1448
+		$base_price = $default ? null : $ticket->base_price();
1449
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1450
+		// breaking out complicated condition for ticket_status
1451
+		if ($default) {
1452
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1453
+		} else {
1454
+			$ticket_status_class = $ticket->is_default()
1455
+				? ' tkt-status-' . EE_Ticket::onsale
1456
+				: ' tkt-status-' . $ticket->ticket_status();
1457
+		}
1458
+		// breaking out complicated condition for TKT_taxable
1459
+		if ($default) {
1460
+			$TKT_taxable = '';
1461
+		} else {
1462
+			$TKT_taxable = $ticket->taxable()
1463
+				? ' checked="checked"'
1464
+				: '';
1465
+		}
1466
+		if ($default) {
1467
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
+		} elseif ($ticket->is_default()) {
1469
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1470
+		} else {
1471
+			$TKT_status = $ticket->ticket_status(true);
1472
+		}
1473
+		if ($default) {
1474
+			$TKT_min = '';
1475
+		} else {
1476
+			$TKT_min = $ticket->min();
1477
+			if ($TKT_min === -1 || $TKT_min === 0) {
1478
+				$TKT_min = '';
1479
+			}
1480
+		}
1481
+		$template_args = array(
1482
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1483
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1484
+			// on initial page load this will always be the correct order.
1485
+			'tkt_status_class'              => $ticket_status_class,
1486
+			'display_edit_tkt_row'          => ' style="display:none;"',
1487
+			'edit_tkt_expanded'             => '',
1488
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1489
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1490
+			'TKT_start_date'                => $default
1491
+				? ''
1492
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1493
+			'TKT_end_date'                  => $default
1494
+				? ''
1495
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1496
+			'TKT_status'                    => $TKT_status,
1497
+			'TKT_price'                     => $default
1498
+				? ''
1499
+				: EEH_Template::format_currency(
1500
+					$ticket->get_ticket_total_with_taxes(),
1501
+					false,
1502
+					false
1503
+				),
1504
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1505
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1506
+			'TKT_qty'                       => $default
1507
+				? ''
1508
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1509
+			'TKT_qty_for_input'             => $default
1510
+				? ''
1511
+				: $ticket->get_pretty('TKT_qty', 'input'),
1512
+			'TKT_uses'                      => $default
1513
+				? ''
1514
+				: $ticket->get_pretty('TKT_uses', 'input'),
1515
+			'TKT_min'                       => $TKT_min,
1516
+			'TKT_max'                       => $default
1517
+				? ''
1518
+				: $ticket->get_pretty('TKT_max', 'input'),
1519
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1520
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1521
+			'TKT_registrations'             => $default
1522
+				? 0
1523
+				: $ticket->count_registrations(
1524
+					array(
1525
+						array(
1526
+							'STS_ID' => array(
1527
+								'!=',
1528
+								EEM_Registration::status_id_incomplete,
1529
+							),
1530
+						),
1531
+					)
1532
+				),
1533
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1534
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1535
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1536
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1537
+			'TKT_is_default_selector'       => '',
1538
+			'ticket_price_rows'             => '',
1539
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1540
+				? ''
1541
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1542
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1543
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1544
+				? ''
1545
+				: ' style="display:none;"',
1546
+			'show_price_mod_button'         => count($prices) > 1
1547
+											   || ($default && $count_price_mods > 0)
1548
+											   || (! $default && $ticket->deleted())
1549
+				? ' style="display:none;"'
1550
+				: '',
1551
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1552
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1553
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1554
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1555
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1556
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1557
+			'TKT_taxable'                   => $TKT_taxable,
1558
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1559
+				? ''
1560
+				: ' style="display:none"',
1561
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1562
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1563
+				$ticket_subtotal,
1564
+				false,
1565
+				false
1566
+			),
1567
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1568
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1569
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1570
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1571
+				? ' ticket-archived'
1572
+				: '',
1573
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1574
+											   && $ticket->deleted()
1575
+											   && ! $ticket->is_permanently_deleteable()
1576
+				? 'ee-lock-icon '
1577
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1578
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1579
+				? ''
1580
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1581
+		);
1582
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1583
+			? ' style="display:none"'
1584
+			: '';
1585
+		// handle rows that should NOT be empty
1586
+		if (empty($template_args['TKT_start_date'])) {
1587
+			// if empty then the start date will be now.
1588
+			$template_args['TKT_start_date'] = date(
1589
+				$this->_date_time_format,
1590
+				current_time('timestamp')
1591
+			);
1592
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1593
+		}
1594
+		if (empty($template_args['TKT_end_date'])) {
1595
+			// get the earliest datetime (if present);
1596
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1597
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1598
+					'Datetime',
1599
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1600
+				)
1601
+				: null;
1602
+			if (! empty($earliest_dtt)) {
1603
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1604
+					'DTT_EVT_start',
1605
+					$this->_date_time_format
1606
+				);
1607
+			} else {
1608
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1609
+				$template_args['TKT_end_date'] = date(
1610
+					$this->_date_time_format,
1611
+					mktime(
1612
+						24,
1613
+						0,
1614
+						0,
1615
+						date('m'),
1616
+						date('d') + 29,
1617
+						date('Y')
1618
+					)
1619
+				);
1620
+			}
1621
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1622
+		}
1623
+		// generate ticket_datetime items
1624
+		if (! $default) {
1625
+			$datetime_row = 1;
1626
+			foreach ($all_datetimes as $datetime) {
1627
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1628
+					$datetime_row,
1629
+					$ticket_row,
1630
+					$datetime,
1631
+					$ticket,
1632
+					$ticket_datetimes,
1633
+					$default
1634
+				);
1635
+				$datetime_row++;
1636
+			}
1637
+		}
1638
+		$price_row = 1;
1639
+		foreach ($prices as $price) {
1640
+			if (! $price instanceof EE_Price) {
1641
+				continue;
1642
+			}
1643
+			if ($price->is_base_price()) {
1644
+				$price_row++;
1645
+				continue;
1646
+			}
1647
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1648
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1649
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1650
+				$ticket_row,
1651
+				$price_row,
1652
+				$price,
1653
+				$default,
1654
+				$ticket,
1655
+				$show_trash,
1656
+				$show_create
1657
+			);
1658
+			$price_row++;
1659
+		}
1660
+		// filter $template_args
1661
+		$template_args = apply_filters(
1662
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1663
+			$template_args,
1664
+			$ticket_row,
1665
+			$ticket,
1666
+			$ticket_datetimes,
1667
+			$all_datetimes,
1668
+			$default,
1669
+			$all_tickets,
1670
+			$this->_is_creating_event
1671
+		);
1672
+		return EEH_Template::display_template(
1673
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1674
+			$template_args,
1675
+			true
1676
+		);
1677
+	}
1678 1678
 
1679 1679
 
1680
-    /**
1681
-     * @param int            $ticket_row
1682
-     * @param EE_Ticket|null $ticket
1683
-     * @return string
1684
-     * @throws DomainException
1685
-     * @throws EE_Error
1686
-     */
1687
-    protected function _get_tax_rows($ticket_row, $ticket)
1688
-    {
1689
-        $tax_rows = '';
1690
-        /** @var EE_Price[] $taxes */
1691
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1692
-        foreach ($taxes as $tax) {
1693
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1694
-            $template_args = array(
1695
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1696
-                    ? ''
1697
-                    : ' style="display:none;"',
1698
-                'tax_id'            => $tax->ID(),
1699
-                'tkt_row'           => $ticket_row,
1700
-                'tax_label'         => $tax->get('PRC_name'),
1701
-                'tax_added'         => $tax_added,
1702
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1703
-                'tax_amount'        => $tax->get('PRC_amount'),
1704
-            );
1705
-            $template_args = apply_filters(
1706
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1707
-                $template_args,
1708
-                $ticket_row,
1709
-                $ticket,
1710
-                $this->_is_creating_event
1711
-            );
1712
-            $tax_rows .= EEH_Template::display_template(
1713
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1714
-                $template_args,
1715
-                true
1716
-            );
1717
-        }
1718
-        return $tax_rows;
1719
-    }
1680
+	/**
1681
+	 * @param int            $ticket_row
1682
+	 * @param EE_Ticket|null $ticket
1683
+	 * @return string
1684
+	 * @throws DomainException
1685
+	 * @throws EE_Error
1686
+	 */
1687
+	protected function _get_tax_rows($ticket_row, $ticket)
1688
+	{
1689
+		$tax_rows = '';
1690
+		/** @var EE_Price[] $taxes */
1691
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1692
+		foreach ($taxes as $tax) {
1693
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1694
+			$template_args = array(
1695
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1696
+					? ''
1697
+					: ' style="display:none;"',
1698
+				'tax_id'            => $tax->ID(),
1699
+				'tkt_row'           => $ticket_row,
1700
+				'tax_label'         => $tax->get('PRC_name'),
1701
+				'tax_added'         => $tax_added,
1702
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1703
+				'tax_amount'        => $tax->get('PRC_amount'),
1704
+			);
1705
+			$template_args = apply_filters(
1706
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1707
+				$template_args,
1708
+				$ticket_row,
1709
+				$ticket,
1710
+				$this->_is_creating_event
1711
+			);
1712
+			$tax_rows .= EEH_Template::display_template(
1713
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1714
+				$template_args,
1715
+				true
1716
+			);
1717
+		}
1718
+		return $tax_rows;
1719
+	}
1720 1720
 
1721 1721
 
1722
-    /**
1723
-     * @param EE_Price       $tax
1724
-     * @param EE_Ticket|null $ticket
1725
-     * @return float|int
1726
-     * @throws EE_Error
1727
-     */
1728
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1729
-    {
1730
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1731
-        return $subtotal * $tax->get('PRC_amount') / 100;
1732
-    }
1722
+	/**
1723
+	 * @param EE_Price       $tax
1724
+	 * @param EE_Ticket|null $ticket
1725
+	 * @return float|int
1726
+	 * @throws EE_Error
1727
+	 */
1728
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1729
+	{
1730
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1731
+		return $subtotal * $tax->get('PRC_amount') / 100;
1732
+	}
1733 1733
 
1734 1734
 
1735
-    /**
1736
-     * @param int            $ticket_row
1737
-     * @param int            $price_row
1738
-     * @param EE_Price|null  $price
1739
-     * @param bool           $default
1740
-     * @param EE_Ticket|null $ticket
1741
-     * @param bool           $show_trash
1742
-     * @param bool           $show_create
1743
-     * @return mixed
1744
-     * @throws InvalidArgumentException
1745
-     * @throws InvalidInterfaceException
1746
-     * @throws InvalidDataTypeException
1747
-     * @throws DomainException
1748
-     * @throws EE_Error
1749
-     * @throws ReflectionException
1750
-     */
1751
-    protected function _get_ticket_price_row(
1752
-        $ticket_row,
1753
-        $price_row,
1754
-        $price,
1755
-        $default,
1756
-        $ticket,
1757
-        $show_trash = true,
1758
-        $show_create = true
1759
-    ) {
1760
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1761
-        $template_args = array(
1762
-            'tkt_row'               => $default && empty($ticket)
1763
-                ? 'TICKETNUM'
1764
-                : $ticket_row,
1765
-            'PRC_order'             => $default && empty($price)
1766
-                ? 'PRICENUM'
1767
-                : $price_row,
1768
-            'edit_prices_name'      => $default && empty($price)
1769
-                ? 'PRICENAMEATTR'
1770
-                : 'edit_prices',
1771
-            'price_type_selector'   => $default && empty($price)
1772
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1773
-                : $this->_get_price_type_selector(
1774
-                    $ticket_row,
1775
-                    $price_row,
1776
-                    $price,
1777
-                    $default,
1778
-                    $send_disabled
1779
-                ),
1780
-            'PRC_ID'                => $default && empty($price)
1781
-                ? 0
1782
-                : $price->ID(),
1783
-            'PRC_is_default'        => $default && empty($price)
1784
-                ? 0
1785
-                : $price->get('PRC_is_default'),
1786
-            'PRC_name'              => $default && empty($price)
1787
-                ? ''
1788
-                : $price->get('PRC_name'),
1789
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1790
-            'show_plus_or_minus'    => $default && empty($price)
1791
-                ? ''
1792
-                : ' style="display:none;"',
1793
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1794
-                ? ' style="display:none;"'
1795
-                : '',
1796
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1797
-                ? ' style="display:none;"'
1798
-                : '',
1799
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1800
-                ? ' style="display:none"'
1801
-                : '',
1802
-            'PRC_amount'            => $default && empty($price)
1803
-                ? 0
1804
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1805
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1806
-                ? ' style="display:none;"'
1807
-                : '',
1808
-            'show_trash_icon'       => $show_trash
1809
-                ? ''
1810
-                : ' style="display:none;"',
1811
-            'show_create_button'    => $show_create
1812
-                ? ''
1813
-                : ' style="display:none;"',
1814
-            'PRC_desc'              => $default && empty($price)
1815
-                ? ''
1816
-                : $price->get('PRC_desc'),
1817
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1818
-        );
1819
-        $template_args = apply_filters(
1820
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1821
-            $template_args,
1822
-            $ticket_row,
1823
-            $price_row,
1824
-            $price,
1825
-            $default,
1826
-            $ticket,
1827
-            $show_trash,
1828
-            $show_create,
1829
-            $this->_is_creating_event
1830
-        );
1831
-        return EEH_Template::display_template(
1832
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1833
-            $template_args,
1834
-            true
1835
-        );
1836
-    }
1735
+	/**
1736
+	 * @param int            $ticket_row
1737
+	 * @param int            $price_row
1738
+	 * @param EE_Price|null  $price
1739
+	 * @param bool           $default
1740
+	 * @param EE_Ticket|null $ticket
1741
+	 * @param bool           $show_trash
1742
+	 * @param bool           $show_create
1743
+	 * @return mixed
1744
+	 * @throws InvalidArgumentException
1745
+	 * @throws InvalidInterfaceException
1746
+	 * @throws InvalidDataTypeException
1747
+	 * @throws DomainException
1748
+	 * @throws EE_Error
1749
+	 * @throws ReflectionException
1750
+	 */
1751
+	protected function _get_ticket_price_row(
1752
+		$ticket_row,
1753
+		$price_row,
1754
+		$price,
1755
+		$default,
1756
+		$ticket,
1757
+		$show_trash = true,
1758
+		$show_create = true
1759
+	) {
1760
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1761
+		$template_args = array(
1762
+			'tkt_row'               => $default && empty($ticket)
1763
+				? 'TICKETNUM'
1764
+				: $ticket_row,
1765
+			'PRC_order'             => $default && empty($price)
1766
+				? 'PRICENUM'
1767
+				: $price_row,
1768
+			'edit_prices_name'      => $default && empty($price)
1769
+				? 'PRICENAMEATTR'
1770
+				: 'edit_prices',
1771
+			'price_type_selector'   => $default && empty($price)
1772
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1773
+				: $this->_get_price_type_selector(
1774
+					$ticket_row,
1775
+					$price_row,
1776
+					$price,
1777
+					$default,
1778
+					$send_disabled
1779
+				),
1780
+			'PRC_ID'                => $default && empty($price)
1781
+				? 0
1782
+				: $price->ID(),
1783
+			'PRC_is_default'        => $default && empty($price)
1784
+				? 0
1785
+				: $price->get('PRC_is_default'),
1786
+			'PRC_name'              => $default && empty($price)
1787
+				? ''
1788
+				: $price->get('PRC_name'),
1789
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1790
+			'show_plus_or_minus'    => $default && empty($price)
1791
+				? ''
1792
+				: ' style="display:none;"',
1793
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1794
+				? ' style="display:none;"'
1795
+				: '',
1796
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1797
+				? ' style="display:none;"'
1798
+				: '',
1799
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1800
+				? ' style="display:none"'
1801
+				: '',
1802
+			'PRC_amount'            => $default && empty($price)
1803
+				? 0
1804
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1805
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1806
+				? ' style="display:none;"'
1807
+				: '',
1808
+			'show_trash_icon'       => $show_trash
1809
+				? ''
1810
+				: ' style="display:none;"',
1811
+			'show_create_button'    => $show_create
1812
+				? ''
1813
+				: ' style="display:none;"',
1814
+			'PRC_desc'              => $default && empty($price)
1815
+				? ''
1816
+				: $price->get('PRC_desc'),
1817
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1818
+		);
1819
+		$template_args = apply_filters(
1820
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1821
+			$template_args,
1822
+			$ticket_row,
1823
+			$price_row,
1824
+			$price,
1825
+			$default,
1826
+			$ticket,
1827
+			$show_trash,
1828
+			$show_create,
1829
+			$this->_is_creating_event
1830
+		);
1831
+		return EEH_Template::display_template(
1832
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1833
+			$template_args,
1834
+			true
1835
+		);
1836
+	}
1837 1837
 
1838 1838
 
1839
-    /**
1840
-     * @param int      $ticket_row
1841
-     * @param int      $price_row
1842
-     * @param EE_Price $price
1843
-     * @param bool     $default
1844
-     * @param bool     $disabled
1845
-     * @return mixed
1846
-     * @throws ReflectionException
1847
-     * @throws InvalidArgumentException
1848
-     * @throws InvalidInterfaceException
1849
-     * @throws InvalidDataTypeException
1850
-     * @throws DomainException
1851
-     * @throws EE_Error
1852
-     */
1853
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1854
-    {
1855
-        if ($price->is_base_price()) {
1856
-            return $this->_get_base_price_template(
1857
-                $ticket_row,
1858
-                $price_row,
1859
-                $price,
1860
-                $default
1861
-            );
1862
-        }
1863
-        return $this->_get_price_modifier_template(
1864
-            $ticket_row,
1865
-            $price_row,
1866
-            $price,
1867
-            $default,
1868
-            $disabled
1869
-        );
1870
-    }
1839
+	/**
1840
+	 * @param int      $ticket_row
1841
+	 * @param int      $price_row
1842
+	 * @param EE_Price $price
1843
+	 * @param bool     $default
1844
+	 * @param bool     $disabled
1845
+	 * @return mixed
1846
+	 * @throws ReflectionException
1847
+	 * @throws InvalidArgumentException
1848
+	 * @throws InvalidInterfaceException
1849
+	 * @throws InvalidDataTypeException
1850
+	 * @throws DomainException
1851
+	 * @throws EE_Error
1852
+	 */
1853
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1854
+	{
1855
+		if ($price->is_base_price()) {
1856
+			return $this->_get_base_price_template(
1857
+				$ticket_row,
1858
+				$price_row,
1859
+				$price,
1860
+				$default
1861
+			);
1862
+		}
1863
+		return $this->_get_price_modifier_template(
1864
+			$ticket_row,
1865
+			$price_row,
1866
+			$price,
1867
+			$default,
1868
+			$disabled
1869
+		);
1870
+	}
1871 1871
 
1872 1872
 
1873
-    /**
1874
-     * @param int      $ticket_row
1875
-     * @param int      $price_row
1876
-     * @param EE_Price $price
1877
-     * @param bool     $default
1878
-     * @return mixed
1879
-     * @throws DomainException
1880
-     * @throws EE_Error
1881
-     */
1882
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1883
-    {
1884
-        $template_args = array(
1885
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1886
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1887
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1888
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1889
-            'price_selected_operator'   => '+',
1890
-            'price_selected_is_percent' => 0,
1891
-        );
1892
-        $template_args = apply_filters(
1893
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1894
-            $template_args,
1895
-            $ticket_row,
1896
-            $price_row,
1897
-            $price,
1898
-            $default,
1899
-            $this->_is_creating_event
1900
-        );
1901
-        return EEH_Template::display_template(
1902
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1903
-            $template_args,
1904
-            true
1905
-        );
1906
-    }
1873
+	/**
1874
+	 * @param int      $ticket_row
1875
+	 * @param int      $price_row
1876
+	 * @param EE_Price $price
1877
+	 * @param bool     $default
1878
+	 * @return mixed
1879
+	 * @throws DomainException
1880
+	 * @throws EE_Error
1881
+	 */
1882
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1883
+	{
1884
+		$template_args = array(
1885
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1886
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1887
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1888
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1889
+			'price_selected_operator'   => '+',
1890
+			'price_selected_is_percent' => 0,
1891
+		);
1892
+		$template_args = apply_filters(
1893
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1894
+			$template_args,
1895
+			$ticket_row,
1896
+			$price_row,
1897
+			$price,
1898
+			$default,
1899
+			$this->_is_creating_event
1900
+		);
1901
+		return EEH_Template::display_template(
1902
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1903
+			$template_args,
1904
+			true
1905
+		);
1906
+	}
1907 1907
 
1908 1908
 
1909
-    /**
1910
-     * @param int      $ticket_row
1911
-     * @param int      $price_row
1912
-     * @param EE_Price $price
1913
-     * @param bool     $default
1914
-     * @param bool     $disabled
1915
-     * @return mixed
1916
-     * @throws ReflectionException
1917
-     * @throws InvalidArgumentException
1918
-     * @throws InvalidInterfaceException
1919
-     * @throws InvalidDataTypeException
1920
-     * @throws DomainException
1921
-     * @throws EE_Error
1922
-     */
1923
-    protected function _get_price_modifier_template(
1924
-        $ticket_row,
1925
-        $price_row,
1926
-        $price,
1927
-        $default,
1928
-        $disabled = false
1929
-    ) {
1930
-        $select_name = $default && ! $price instanceof EE_Price
1931
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1932
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1933
-        /** @var EEM_Price_Type $price_type_model */
1934
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1935
-        $price_types = $price_type_model->get_all(array(
1936
-            array(
1937
-                'OR' => array(
1938
-                    'PBT_ID'  => '2',
1939
-                    'PBT_ID*' => '3',
1940
-                ),
1941
-            ),
1942
-        ));
1943
-        $all_price_types = $default && ! $price instanceof EE_Price
1944
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1945
-            : array();
1946
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1947
-        $price_option_spans = '';
1948
-        // setup price types for selector
1949
-        foreach ($price_types as $price_type) {
1950
-            if (! $price_type instanceof EE_Price_Type) {
1951
-                continue;
1952
-            }
1953
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1954
-            // while we're in the loop let's setup the option spans used by js
1955
-            $span_args = array(
1956
-                'PRT_ID'         => $price_type->ID(),
1957
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1958
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1959
-            );
1960
-            $price_option_spans .= EEH_Template::display_template(
1961
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1962
-                $span_args,
1963
-                true
1964
-            );
1965
-        }
1966
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1967
-            : $select_name;
1968
-        $select_input = new EE_Select_Input(
1969
-            $all_price_types,
1970
-            array(
1971
-                'default'               => $selected_price_type_id,
1972
-                'html_name'             => $select_name,
1973
-                'html_class'            => 'edit-price-PRT_ID',
1974
-                'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1975
-            )
1976
-        );
1977
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1978
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1979
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1980
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1981
-        $template_args = array(
1982
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1983
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1984
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1985
-            'main_name'                 => $select_name,
1986
-            'selected_price_type_id'    => $selected_price_type_id,
1987
-            'price_option_spans'        => $price_option_spans,
1988
-            'price_selected_operator'   => $price_selected_operator,
1989
-            'price_selected_is_percent' => $price_selected_is_percent,
1990
-            'disabled'                  => $disabled,
1991
-        );
1992
-        $template_args = apply_filters(
1993
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1994
-            $template_args,
1995
-            $ticket_row,
1996
-            $price_row,
1997
-            $price,
1998
-            $default,
1999
-            $disabled,
2000
-            $this->_is_creating_event
2001
-        );
2002
-        return EEH_Template::display_template(
2003
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2004
-            $template_args,
2005
-            true
2006
-        );
2007
-    }
1909
+	/**
1910
+	 * @param int      $ticket_row
1911
+	 * @param int      $price_row
1912
+	 * @param EE_Price $price
1913
+	 * @param bool     $default
1914
+	 * @param bool     $disabled
1915
+	 * @return mixed
1916
+	 * @throws ReflectionException
1917
+	 * @throws InvalidArgumentException
1918
+	 * @throws InvalidInterfaceException
1919
+	 * @throws InvalidDataTypeException
1920
+	 * @throws DomainException
1921
+	 * @throws EE_Error
1922
+	 */
1923
+	protected function _get_price_modifier_template(
1924
+		$ticket_row,
1925
+		$price_row,
1926
+		$price,
1927
+		$default,
1928
+		$disabled = false
1929
+	) {
1930
+		$select_name = $default && ! $price instanceof EE_Price
1931
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1932
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1933
+		/** @var EEM_Price_Type $price_type_model */
1934
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1935
+		$price_types = $price_type_model->get_all(array(
1936
+			array(
1937
+				'OR' => array(
1938
+					'PBT_ID'  => '2',
1939
+					'PBT_ID*' => '3',
1940
+				),
1941
+			),
1942
+		));
1943
+		$all_price_types = $default && ! $price instanceof EE_Price
1944
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1945
+			: array();
1946
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1947
+		$price_option_spans = '';
1948
+		// setup price types for selector
1949
+		foreach ($price_types as $price_type) {
1950
+			if (! $price_type instanceof EE_Price_Type) {
1951
+				continue;
1952
+			}
1953
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1954
+			// while we're in the loop let's setup the option spans used by js
1955
+			$span_args = array(
1956
+				'PRT_ID'         => $price_type->ID(),
1957
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1958
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1959
+			);
1960
+			$price_option_spans .= EEH_Template::display_template(
1961
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1962
+				$span_args,
1963
+				true
1964
+			);
1965
+		}
1966
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1967
+			: $select_name;
1968
+		$select_input = new EE_Select_Input(
1969
+			$all_price_types,
1970
+			array(
1971
+				'default'               => $selected_price_type_id,
1972
+				'html_name'             => $select_name,
1973
+				'html_class'            => 'edit-price-PRT_ID',
1974
+				'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1975
+			)
1976
+		);
1977
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1978
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1979
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1980
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1981
+		$template_args = array(
1982
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1983
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1984
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1985
+			'main_name'                 => $select_name,
1986
+			'selected_price_type_id'    => $selected_price_type_id,
1987
+			'price_option_spans'        => $price_option_spans,
1988
+			'price_selected_operator'   => $price_selected_operator,
1989
+			'price_selected_is_percent' => $price_selected_is_percent,
1990
+			'disabled'                  => $disabled,
1991
+		);
1992
+		$template_args = apply_filters(
1993
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1994
+			$template_args,
1995
+			$ticket_row,
1996
+			$price_row,
1997
+			$price,
1998
+			$default,
1999
+			$disabled,
2000
+			$this->_is_creating_event
2001
+		);
2002
+		return EEH_Template::display_template(
2003
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2004
+			$template_args,
2005
+			true
2006
+		);
2007
+	}
2008 2008
 
2009 2009
 
2010
-    /**
2011
-     * @param int              $datetime_row
2012
-     * @param int              $ticket_row
2013
-     * @param EE_Datetime|null $datetime
2014
-     * @param EE_Ticket|null   $ticket
2015
-     * @param array            $ticket_datetimes
2016
-     * @param bool             $default
2017
-     * @return mixed
2018
-     * @throws DomainException
2019
-     * @throws EE_Error
2020
-     */
2021
-    protected function _get_ticket_datetime_list_item(
2022
-        $datetime_row,
2023
-        $ticket_row,
2024
-        $datetime,
2025
-        $ticket,
2026
-        $ticket_datetimes = array(),
2027
-        $default
2028
-    ) {
2029
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2030
-            ? $ticket_datetimes[ $ticket->ID() ]
2031
-            : array();
2032
-        $template_args = array(
2033
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2034
-                ? 'DTTNUM'
2035
-                : $datetime_row,
2036
-            'tkt_row'                  => $default
2037
-                ? 'TICKETNUM'
2038
-                : $ticket_row,
2039
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2040
-                ? ' ticket-selected'
2041
-                : '',
2042
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2043
-                ? ' checked="checked"'
2044
-                : '',
2045
-            'DTT_name'                 => $default && empty($datetime)
2046
-                ? 'DTTNAME'
2047
-                : $datetime->get_dtt_display_name(true),
2048
-            'tkt_status_class'         => '',
2049
-        );
2050
-        $template_args = apply_filters(
2051
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2052
-            $template_args,
2053
-            $datetime_row,
2054
-            $ticket_row,
2055
-            $datetime,
2056
-            $ticket,
2057
-            $ticket_datetimes,
2058
-            $default,
2059
-            $this->_is_creating_event
2060
-        );
2061
-        return EEH_Template::display_template(
2062
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2063
-            $template_args,
2064
-            true
2065
-        );
2066
-    }
2010
+	/**
2011
+	 * @param int              $datetime_row
2012
+	 * @param int              $ticket_row
2013
+	 * @param EE_Datetime|null $datetime
2014
+	 * @param EE_Ticket|null   $ticket
2015
+	 * @param array            $ticket_datetimes
2016
+	 * @param bool             $default
2017
+	 * @return mixed
2018
+	 * @throws DomainException
2019
+	 * @throws EE_Error
2020
+	 */
2021
+	protected function _get_ticket_datetime_list_item(
2022
+		$datetime_row,
2023
+		$ticket_row,
2024
+		$datetime,
2025
+		$ticket,
2026
+		$ticket_datetimes = array(),
2027
+		$default
2028
+	) {
2029
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2030
+			? $ticket_datetimes[ $ticket->ID() ]
2031
+			: array();
2032
+		$template_args = array(
2033
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2034
+				? 'DTTNUM'
2035
+				: $datetime_row,
2036
+			'tkt_row'                  => $default
2037
+				? 'TICKETNUM'
2038
+				: $ticket_row,
2039
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2040
+				? ' ticket-selected'
2041
+				: '',
2042
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2043
+				? ' checked="checked"'
2044
+				: '',
2045
+			'DTT_name'                 => $default && empty($datetime)
2046
+				? 'DTTNAME'
2047
+				: $datetime->get_dtt_display_name(true),
2048
+			'tkt_status_class'         => '',
2049
+		);
2050
+		$template_args = apply_filters(
2051
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2052
+			$template_args,
2053
+			$datetime_row,
2054
+			$ticket_row,
2055
+			$datetime,
2056
+			$ticket,
2057
+			$ticket_datetimes,
2058
+			$default,
2059
+			$this->_is_creating_event
2060
+		);
2061
+		return EEH_Template::display_template(
2062
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2063
+			$template_args,
2064
+			true
2065
+		);
2066
+	}
2067 2067
 
2068 2068
 
2069
-    /**
2070
-     * @param array $all_datetimes
2071
-     * @param array $all_tickets
2072
-     * @return mixed
2073
-     * @throws ReflectionException
2074
-     * @throws InvalidArgumentException
2075
-     * @throws InvalidInterfaceException
2076
-     * @throws InvalidDataTypeException
2077
-     * @throws DomainException
2078
-     * @throws EE_Error
2079
-     */
2080
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2081
-    {
2082
-        $template_args = array(
2083
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2084
-                'DTTNUM',
2085
-                null,
2086
-                true,
2087
-                $all_datetimes
2088
-            ),
2089
-            'default_ticket_row'                       => $this->_get_ticket_row(
2090
-                'TICKETNUM',
2091
-                null,
2092
-                array(),
2093
-                array(),
2094
-                true
2095
-            ),
2096
-            'default_price_row'                        => $this->_get_ticket_price_row(
2097
-                'TICKETNUM',
2098
-                'PRICENUM',
2099
-                null,
2100
-                true,
2101
-                null
2102
-            ),
2103
-            'default_price_rows'                       => '',
2104
-            'default_base_price_amount'                => 0,
2105
-            'default_base_price_name'                  => '',
2106
-            'default_base_price_description'           => '',
2107
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
-                'TICKETNUM',
2109
-                'PRICENUM',
2110
-                null,
2111
-                true
2112
-            ),
2113
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
-                'DTTNUM',
2115
-                null,
2116
-                array(),
2117
-                array(),
2118
-                true
2119
-            ),
2120
-            'existing_available_datetime_tickets_list' => '',
2121
-            'existing_available_ticket_datetimes_list' => '',
2122
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
-                'DTTNUM',
2124
-                'TICKETNUM',
2125
-                null,
2126
-                null,
2127
-                array(),
2128
-                true
2129
-            ),
2130
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
-                'DTTNUM',
2132
-                'TICKETNUM',
2133
-                null,
2134
-                null,
2135
-                array(),
2136
-                true
2137
-            ),
2138
-        );
2139
-        $ticket_row = 1;
2140
-        foreach ($all_tickets as $ticket) {
2141
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
-                'DTTNUM',
2143
-                $ticket_row,
2144
-                null,
2145
-                $ticket,
2146
-                array(),
2147
-                true
2148
-            );
2149
-            $ticket_row++;
2150
-        }
2151
-        $datetime_row = 1;
2152
-        foreach ($all_datetimes as $datetime) {
2153
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
-                $datetime_row,
2155
-                'TICKETNUM',
2156
-                $datetime,
2157
-                null,
2158
-                array(),
2159
-                true
2160
-            );
2161
-            $datetime_row++;
2162
-        }
2163
-        /** @var EEM_Price $price_model */
2164
-        $price_model = EE_Registry::instance()->load_model('Price');
2165
-        $default_prices = $price_model->get_all_default_prices();
2166
-        $price_row = 1;
2167
-        foreach ($default_prices as $price) {
2168
-            if (! $price instanceof EE_Price) {
2169
-                continue;
2170
-            }
2171
-            if ($price->is_base_price()) {
2172
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2173
-                    'PRC_amount',
2174
-                    'localized_float'
2175
-                );
2176
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2177
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2178
-                $price_row++;
2179
-                continue;
2180
-            }
2181
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2182
-                             || count($default_prices) === 1);
2183
-            $show_create = ! (count($default_prices) > 1
2184
-                              && count($default_prices)
2185
-                                 !== $price_row);
2186
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2187
-                'TICKETNUM',
2188
-                $price_row,
2189
-                $price,
2190
-                true,
2191
-                null,
2192
-                $show_trash,
2193
-                $show_create
2194
-            );
2195
-            $price_row++;
2196
-        }
2197
-        $template_args = apply_filters(
2198
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2199
-            $template_args,
2200
-            $all_datetimes,
2201
-            $all_tickets,
2202
-            $this->_is_creating_event
2203
-        );
2204
-        return EEH_Template::display_template(
2205
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2206
-            $template_args,
2207
-            true
2208
-        );
2209
-    }
2069
+	/**
2070
+	 * @param array $all_datetimes
2071
+	 * @param array $all_tickets
2072
+	 * @return mixed
2073
+	 * @throws ReflectionException
2074
+	 * @throws InvalidArgumentException
2075
+	 * @throws InvalidInterfaceException
2076
+	 * @throws InvalidDataTypeException
2077
+	 * @throws DomainException
2078
+	 * @throws EE_Error
2079
+	 */
2080
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2081
+	{
2082
+		$template_args = array(
2083
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2084
+				'DTTNUM',
2085
+				null,
2086
+				true,
2087
+				$all_datetimes
2088
+			),
2089
+			'default_ticket_row'                       => $this->_get_ticket_row(
2090
+				'TICKETNUM',
2091
+				null,
2092
+				array(),
2093
+				array(),
2094
+				true
2095
+			),
2096
+			'default_price_row'                        => $this->_get_ticket_price_row(
2097
+				'TICKETNUM',
2098
+				'PRICENUM',
2099
+				null,
2100
+				true,
2101
+				null
2102
+			),
2103
+			'default_price_rows'                       => '',
2104
+			'default_base_price_amount'                => 0,
2105
+			'default_base_price_name'                  => '',
2106
+			'default_base_price_description'           => '',
2107
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2108
+				'TICKETNUM',
2109
+				'PRICENUM',
2110
+				null,
2111
+				true
2112
+			),
2113
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2114
+				'DTTNUM',
2115
+				null,
2116
+				array(),
2117
+				array(),
2118
+				true
2119
+			),
2120
+			'existing_available_datetime_tickets_list' => '',
2121
+			'existing_available_ticket_datetimes_list' => '',
2122
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2123
+				'DTTNUM',
2124
+				'TICKETNUM',
2125
+				null,
2126
+				null,
2127
+				array(),
2128
+				true
2129
+			),
2130
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2131
+				'DTTNUM',
2132
+				'TICKETNUM',
2133
+				null,
2134
+				null,
2135
+				array(),
2136
+				true
2137
+			),
2138
+		);
2139
+		$ticket_row = 1;
2140
+		foreach ($all_tickets as $ticket) {
2141
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2142
+				'DTTNUM',
2143
+				$ticket_row,
2144
+				null,
2145
+				$ticket,
2146
+				array(),
2147
+				true
2148
+			);
2149
+			$ticket_row++;
2150
+		}
2151
+		$datetime_row = 1;
2152
+		foreach ($all_datetimes as $datetime) {
2153
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2154
+				$datetime_row,
2155
+				'TICKETNUM',
2156
+				$datetime,
2157
+				null,
2158
+				array(),
2159
+				true
2160
+			);
2161
+			$datetime_row++;
2162
+		}
2163
+		/** @var EEM_Price $price_model */
2164
+		$price_model = EE_Registry::instance()->load_model('Price');
2165
+		$default_prices = $price_model->get_all_default_prices();
2166
+		$price_row = 1;
2167
+		foreach ($default_prices as $price) {
2168
+			if (! $price instanceof EE_Price) {
2169
+				continue;
2170
+			}
2171
+			if ($price->is_base_price()) {
2172
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2173
+					'PRC_amount',
2174
+					'localized_float'
2175
+				);
2176
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2177
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2178
+				$price_row++;
2179
+				continue;
2180
+			}
2181
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2182
+							 || count($default_prices) === 1);
2183
+			$show_create = ! (count($default_prices) > 1
2184
+							  && count($default_prices)
2185
+								 !== $price_row);
2186
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2187
+				'TICKETNUM',
2188
+				$price_row,
2189
+				$price,
2190
+				true,
2191
+				null,
2192
+				$show_trash,
2193
+				$show_create
2194
+			);
2195
+			$price_row++;
2196
+		}
2197
+		$template_args = apply_filters(
2198
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2199
+			$template_args,
2200
+			$all_datetimes,
2201
+			$all_tickets,
2202
+			$this->_is_creating_event
2203
+		);
2204
+		return EEH_Template::display_template(
2205
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2206
+			$template_args,
2207
+			true
2208
+		);
2209
+	}
2210 2210
 }
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3182 added lines, -3182 removed lines patch added patch discarded remove patch
@@ -14,2509 +14,2509 @@  discard block
 block discarded – undo
14 14
 final class EE_Config implements ResettableInterface
15 15
 {
16 16
 
17
-    const OPTION_NAME = 'ee_config';
18
-
19
-    const LOG_NAME = 'ee_config_log';
20
-
21
-    const LOG_LENGTH = 100;
22
-
23
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
-
25
-    /**
26
-     *    instance of the EE_Config object
27
-     *
28
-     * @var    EE_Config $_instance
29
-     * @access    private
30
-     */
31
-    private static $_instance;
32
-
33
-    /**
34
-     * @var boolean $_logging_enabled
35
-     */
36
-    private static $_logging_enabled = false;
37
-
38
-    /**
39
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
-     */
41
-    private $legacy_shortcodes_manager;
42
-
43
-    /**
44
-     * An StdClass whose property names are addon slugs,
45
-     * and values are their config classes
46
-     *
47
-     * @var StdClass
48
-     */
49
-    public $addons;
50
-
51
-    /**
52
-     * @var EE_Admin_Config
53
-     */
54
-    public $admin;
55
-
56
-    /**
57
-     * @var EE_Core_Config
58
-     */
59
-    public $core;
60
-
61
-    /**
62
-     * @var EE_Currency_Config
63
-     */
64
-    public $currency;
65
-
66
-    /**
67
-     * @var EE_Organization_Config
68
-     */
69
-    public $organization;
70
-
71
-    /**
72
-     * @var EE_Registration_Config
73
-     */
74
-    public $registration;
75
-
76
-    /**
77
-     * @var EE_Template_Config
78
-     */
79
-    public $template_settings;
80
-
81
-    /**
82
-     * Holds EE environment values.
83
-     *
84
-     * @var EE_Environment_Config
85
-     */
86
-    public $environment;
87
-
88
-    /**
89
-     * settings pertaining to Google maps
90
-     *
91
-     * @var EE_Map_Config
92
-     */
93
-    public $map_settings;
94
-
95
-    /**
96
-     * settings pertaining to Taxes
97
-     *
98
-     * @var EE_Tax_Config
99
-     */
100
-    public $tax_settings;
101
-
102
-    /**
103
-     * Settings pertaining to global messages settings.
104
-     *
105
-     * @var EE_Messages_Config
106
-     */
107
-    public $messages;
108
-
109
-    /**
110
-     * @deprecated
111
-     * @var EE_Gateway_Config
112
-     */
113
-    public $gateway;
114
-
115
-    /**
116
-     * @var    array $_addon_option_names
117
-     * @access    private
118
-     */
119
-    private $_addon_option_names = array();
120
-
121
-    /**
122
-     * @var    array $_module_route_map
123
-     * @access    private
124
-     */
125
-    private static $_module_route_map = array();
126
-
127
-    /**
128
-     * @var    array $_module_forward_map
129
-     * @access    private
130
-     */
131
-    private static $_module_forward_map = array();
132
-
133
-    /**
134
-     * @var    array $_module_view_map
135
-     * @access    private
136
-     */
137
-    private static $_module_view_map = array();
138
-
139
-
140
-    /**
141
-     * @singleton method used to instantiate class object
142
-     * @access    public
143
-     * @return EE_Config instance
144
-     */
145
-    public static function instance()
146
-    {
147
-        // check if class object is instantiated, and instantiated properly
148
-        if (! self::$_instance instanceof EE_Config) {
149
-            self::$_instance = new self();
150
-        }
151
-        return self::$_instance;
152
-    }
153
-
154
-
155
-    /**
156
-     * Resets the config
157
-     *
158
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
-     *                               reflect its state in the database
161
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
-     *                               site was put into maintenance mode)
165
-     * @return EE_Config
166
-     */
167
-    public static function reset($hard_reset = false, $reinstantiate = true)
168
-    {
169
-        if (self::$_instance instanceof EE_Config) {
170
-            if ($hard_reset) {
171
-                self::$_instance->legacy_shortcodes_manager = null;
172
-                self::$_instance->_addon_option_names = array();
173
-                self::$_instance->_initialize_config();
174
-                self::$_instance->update_espresso_config();
175
-            }
176
-            self::$_instance->update_addon_option_names();
177
-        }
178
-        self::$_instance = null;
179
-        // we don't need to reset the static properties imo because those should
180
-        // only change when a module is added or removed. Currently we don't
181
-        // support removing a module during a request when it previously existed
182
-        if ($reinstantiate) {
183
-            return self::instance();
184
-        } else {
185
-            return null;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     *    class constructor
192
-     *
193
-     * @access    private
194
-     */
195
-    private function __construct()
196
-    {
197
-        do_action('AHEE__EE_Config__construct__begin', $this);
198
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
-        // setup empty config classes
200
-        $this->_initialize_config();
201
-        // load existing EE site settings
202
-        $this->_load_core_config();
203
-        // confirm everything loaded correctly and set filtered defaults if not
204
-        $this->_verify_config();
205
-        //  register shortcodes and modules
206
-        add_action(
207
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
-            array($this, 'register_shortcodes_and_modules'),
209
-            999
210
-        );
211
-        //  initialize shortcodes and modules
212
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
-        // register widgets
214
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
215
-        // shutdown
216
-        add_action('shutdown', array($this, 'shutdown'), 10);
217
-        // construct__end hook
218
-        do_action('AHEE__EE_Config__construct__end', $this);
219
-        // hardcoded hack
220
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
-    }
222
-
223
-
224
-    /**
225
-     * @return boolean
226
-     */
227
-    public static function logging_enabled()
228
-    {
229
-        return self::$_logging_enabled;
230
-    }
231
-
232
-
233
-    /**
234
-     * use to get the current theme if needed from static context
235
-     *
236
-     * @return string current theme set.
237
-     */
238
-    public static function get_current_theme()
239
-    {
240
-        return isset(self::$_instance->template_settings->current_espresso_theme)
241
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
-    }
243
-
244
-
245
-    /**
246
-     *        _initialize_config
247
-     *
248
-     * @access private
249
-     * @return void
250
-     */
251
-    private function _initialize_config()
252
-    {
253
-        EE_Config::trim_log();
254
-        // set defaults
255
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
-        $this->addons = new stdClass();
257
-        // set _module_route_map
258
-        EE_Config::$_module_route_map = array();
259
-        // set _module_forward_map
260
-        EE_Config::$_module_forward_map = array();
261
-        // set _module_view_map
262
-        EE_Config::$_module_view_map = array();
263
-    }
264
-
265
-
266
-    /**
267
-     *        load core plugin configuration
268
-     *
269
-     * @access private
270
-     * @return void
271
-     */
272
-    private function _load_core_config()
273
-    {
274
-        // load_core_config__start hook
275
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
276
-        $espresso_config = $this->get_espresso_config();
277
-        foreach ($espresso_config as $config => $settings) {
278
-            // load_core_config__start hook
279
-            $settings = apply_filters(
280
-                'FHEE__EE_Config___load_core_config__config_settings',
281
-                $settings,
282
-                $config,
283
-                $this
284
-            );
285
-            if (is_object($settings) && property_exists($this, $config)) {
286
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
-                // call configs populate method to ensure any defaults are set for empty values.
288
-                if (method_exists($settings, 'populate')) {
289
-                    $this->{$config}->populate();
290
-                }
291
-                if (method_exists($settings, 'do_hooks')) {
292
-                    $this->{$config}->do_hooks();
293
-                }
294
-            }
295
-        }
296
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
-            $this->update_espresso_config();
298
-        }
299
-        // load_core_config__end hook
300
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
301
-    }
302
-
303
-
304
-    /**
305
-     *    _verify_config
306
-     *
307
-     * @access    protected
308
-     * @return    void
309
-     */
310
-    protected function _verify_config()
311
-    {
312
-        $this->core = $this->core instanceof EE_Core_Config
313
-            ? $this->core
314
-            : new EE_Core_Config();
315
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
-        $this->organization = $this->organization instanceof EE_Organization_Config
317
-            ? $this->organization
318
-            : new EE_Organization_Config();
319
-        $this->organization = apply_filters(
320
-            'FHEE__EE_Config___initialize_config__organization',
321
-            $this->organization
322
-        );
323
-        $this->currency = $this->currency instanceof EE_Currency_Config
324
-            ? $this->currency
325
-            : new EE_Currency_Config();
326
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
-        $this->registration = $this->registration instanceof EE_Registration_Config
328
-            ? $this->registration
329
-            : new EE_Registration_Config();
330
-        $this->registration = apply_filters(
331
-            'FHEE__EE_Config___initialize_config__registration',
332
-            $this->registration
333
-        );
334
-        $this->admin = $this->admin instanceof EE_Admin_Config
335
-            ? $this->admin
336
-            : new EE_Admin_Config();
337
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
339
-            ? $this->template_settings
340
-            : new EE_Template_Config();
341
-        $this->template_settings = apply_filters(
342
-            'FHEE__EE_Config___initialize_config__template_settings',
343
-            $this->template_settings
344
-        );
345
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
346
-            ? $this->map_settings
347
-            : new EE_Map_Config();
348
-        $this->map_settings = apply_filters(
349
-            'FHEE__EE_Config___initialize_config__map_settings',
350
-            $this->map_settings
351
-        );
352
-        $this->environment = $this->environment instanceof EE_Environment_Config
353
-            ? $this->environment
354
-            : new EE_Environment_Config();
355
-        $this->environment = apply_filters(
356
-            'FHEE__EE_Config___initialize_config__environment',
357
-            $this->environment
358
-        );
359
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
-            ? $this->tax_settings
361
-            : new EE_Tax_Config();
362
-        $this->tax_settings = apply_filters(
363
-            'FHEE__EE_Config___initialize_config__tax_settings',
364
-            $this->tax_settings
365
-        );
366
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
-        $this->messages = $this->messages instanceof EE_Messages_Config
368
-            ? $this->messages
369
-            : new EE_Messages_Config();
370
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
371
-            ? $this->gateway
372
-            : new EE_Gateway_Config();
373
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
-        $this->legacy_shortcodes_manager = null;
375
-    }
376
-
377
-
378
-    /**
379
-     *    get_espresso_config
380
-     *
381
-     * @access    public
382
-     * @return    array of espresso config stuff
383
-     */
384
-    public function get_espresso_config()
385
-    {
386
-        // grab espresso configuration
387
-        return apply_filters(
388
-            'FHEE__EE_Config__get_espresso_config__CFG',
389
-            get_option(EE_Config::OPTION_NAME, array())
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     *    double_check_config_comparison
396
-     *
397
-     * @access    public
398
-     * @param string $option
399
-     * @param        $old_value
400
-     * @param        $value
401
-     */
402
-    public function double_check_config_comparison($option = '', $old_value, $value)
403
-    {
404
-        // make sure we're checking the ee config
405
-        if ($option === EE_Config::OPTION_NAME) {
406
-            // run a loose comparison of the old value against the new value for type and properties,
407
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
-            if ($value != $old_value) {
409
-                // if they are NOT the same, then remove the hook,
410
-                // which means the subsequent update results will be based solely on the update query results
411
-                // the reason we do this is because, as stated above,
412
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
413
-                // this happens PRIOR to serialization and any subsequent update.
414
-                // If values are found to match their previous old value,
415
-                // then WP bails before performing any update.
416
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
-                // it just pulled from the db, with the one being passed to it (which will not match).
418
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
419
-                // MySQL MAY ALSO NOT perform the update because
420
-                // the string it sees in the db looks the same as the new one it has been passed!!!
421
-                // This results in the query returning an "affected rows" value of ZERO,
422
-                // which gets returned immediately by WP update_option and looks like an error.
423
-                remove_action('update_option', array($this, 'check_config_updated'));
424
-            }
425
-        }
426
-    }
427
-
428
-
429
-    /**
430
-     *    update_espresso_config
431
-     *
432
-     * @access   public
433
-     */
434
-    protected function _reset_espresso_addon_config()
435
-    {
436
-        $this->_addon_option_names = array();
437
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
438
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
439
-            if ($addon_config_obj instanceof EE_Config_Base) {
440
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
441
-            }
442
-            $this->addons->{$addon_name} = null;
443
-        }
444
-    }
445
-
446
-
447
-    /**
448
-     *    update_espresso_config
449
-     *
450
-     * @access   public
451
-     * @param   bool $add_success
452
-     * @param   bool $add_error
453
-     * @return   bool
454
-     */
455
-    public function update_espresso_config($add_success = false, $add_error = true)
456
-    {
457
-        // don't allow config updates during WP heartbeats
458
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
-            return false;
460
-        }
461
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
-        // $clone = clone( self::$_instance );
463
-        // self::$_instance = NULL;
464
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
-        $this->_reset_espresso_addon_config();
466
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
-        // but BEFORE the actual update occurs
468
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
-        $this->legacy_shortcodes_manager = null;
472
-        // now update "ee_config"
473
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
474
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
-        EE_Config::log(EE_Config::OPTION_NAME);
476
-        // if not saved... check if the hook we just added still exists;
477
-        // if it does, it means one of two things:
478
-        // that update_option bailed at the($value === $old_value) conditional,
479
-        // or...
480
-        // the db update query returned 0 rows affected
481
-        // (probably because the data  value was the same from it's perspective)
482
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
483
-        // but just means no update occurred, so don't display an error to the user.
484
-        // BUT... if update_option returns FALSE, AND the hook is missing,
485
-        // then it means that something truly went wrong
486
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
-        // remove our action since we don't want it in the system anymore
488
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
-        // self::$_instance = $clone;
491
-        // unset( $clone );
492
-        // if config remains the same or was updated successfully
493
-        if ($saved) {
494
-            if ($add_success) {
495
-                EE_Error::add_success(
496
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
-                    __FILE__,
498
-                    __FUNCTION__,
499
-                    __LINE__
500
-                );
501
-            }
502
-            return true;
503
-        } else {
504
-            if ($add_error) {
505
-                EE_Error::add_error(
506
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
-                    __FILE__,
508
-                    __FUNCTION__,
509
-                    __LINE__
510
-                );
511
-            }
512
-            return false;
513
-        }
514
-    }
515
-
516
-
517
-    /**
518
-     *    _verify_config_params
519
-     *
520
-     * @access    private
521
-     * @param    string         $section
522
-     * @param    string         $name
523
-     * @param    string         $config_class
524
-     * @param    EE_Config_Base $config_obj
525
-     * @param    array          $tests_to_run
526
-     * @param    bool           $display_errors
527
-     * @return    bool    TRUE on success, FALSE on fail
528
-     */
529
-    private function _verify_config_params(
530
-        $section = '',
531
-        $name = '',
532
-        $config_class = '',
533
-        $config_obj = null,
534
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
-        $display_errors = true
536
-    ) {
537
-        try {
538
-            foreach ($tests_to_run as $test) {
539
-                switch ($test) {
540
-                    // TEST #1 : check that section was set
541
-                    case 1:
542
-                        if (empty($section)) {
543
-                            if ($display_errors) {
544
-                                throw new EE_Error(
545
-                                    sprintf(
546
-                                        __(
547
-                                            'No configuration section has been provided while attempting to save "%s".',
548
-                                            'event_espresso'
549
-                                        ),
550
-                                        $config_class
551
-                                    )
552
-                                );
553
-                            }
554
-                            return false;
555
-                        }
556
-                        break;
557
-                    // TEST #2 : check that settings section exists
558
-                    case 2:
559
-                        if (! isset($this->{$section})) {
560
-                            if ($display_errors) {
561
-                                throw new EE_Error(
562
-                                    sprintf(
563
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
564
-                                        $section
565
-                                    )
566
-                                );
567
-                            }
568
-                            return false;
569
-                        }
570
-                        break;
571
-                    // TEST #3 : check that section is the proper format
572
-                    case 3:
573
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
-                        ) {
575
-                            if ($display_errors) {
576
-                                throw new EE_Error(
577
-                                    sprintf(
578
-                                        __(
579
-                                            'The "%s" configuration settings have not been formatted correctly.',
580
-                                            'event_espresso'
581
-                                        ),
582
-                                        $section
583
-                                    )
584
-                                );
585
-                            }
586
-                            return false;
587
-                        }
588
-                        break;
589
-                    // TEST #4 : check that config section name has been set
590
-                    case 4:
591
-                        if (empty($name)) {
592
-                            if ($display_errors) {
593
-                                throw new EE_Error(
594
-                                    __(
595
-                                        'No name has been provided for the specific configuration section.',
596
-                                        'event_espresso'
597
-                                    )
598
-                                );
599
-                            }
600
-                            return false;
601
-                        }
602
-                        break;
603
-                    // TEST #5 : check that a config class name has been set
604
-                    case 5:
605
-                        if (empty($config_class)) {
606
-                            if ($display_errors) {
607
-                                throw new EE_Error(
608
-                                    __(
609
-                                        'No class name has been provided for the specific configuration section.',
610
-                                        'event_espresso'
611
-                                    )
612
-                                );
613
-                            }
614
-                            return false;
615
-                        }
616
-                        break;
617
-                    // TEST #6 : verify config class is accessible
618
-                    case 6:
619
-                        if (! class_exists($config_class)) {
620
-                            if ($display_errors) {
621
-                                throw new EE_Error(
622
-                                    sprintf(
623
-                                        __(
624
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
-                                            'event_espresso'
626
-                                        ),
627
-                                        $config_class
628
-                                    )
629
-                                );
630
-                            }
631
-                            return false;
632
-                        }
633
-                        break;
634
-                    // TEST #7 : check that config has even been set
635
-                    case 7:
636
-                        if (! isset($this->{$section}->{$name})) {
637
-                            if ($display_errors) {
638
-                                throw new EE_Error(
639
-                                    sprintf(
640
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
-                                        $section,
642
-                                        $name
643
-                                    )
644
-                                );
645
-                            }
646
-                            return false;
647
-                        } else {
648
-                            // and make sure it's not serialized
649
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
-                        }
651
-                        break;
652
-                    // TEST #8 : check that config is the requested type
653
-                    case 8:
654
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
655
-                            if ($display_errors) {
656
-                                throw new EE_Error(
657
-                                    sprintf(
658
-                                        __(
659
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
-                                            'event_espresso'
661
-                                        ),
662
-                                        $section,
663
-                                        $name,
664
-                                        $config_class
665
-                                    )
666
-                                );
667
-                            }
668
-                            return false;
669
-                        }
670
-                        break;
671
-                    // TEST #9 : verify config object
672
-                    case 9:
673
-                        if (! $config_obj instanceof EE_Config_Base) {
674
-                            if ($display_errors) {
675
-                                throw new EE_Error(
676
-                                    sprintf(
677
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
-                                        print_r($config_obj, true)
679
-                                    )
680
-                                );
681
-                            }
682
-                            return false;
683
-                        }
684
-                        break;
685
-                }
686
-            }
687
-        } catch (EE_Error $e) {
688
-            $e->get_error();
689
-        }
690
-        // you have successfully run the gauntlet
691
-        return true;
692
-    }
693
-
694
-
695
-    /**
696
-     *    _generate_config_option_name
697
-     *
698
-     * @access        protected
699
-     * @param        string $section
700
-     * @param        string $name
701
-     * @return        string
702
-     */
703
-    private function _generate_config_option_name($section = '', $name = '')
704
-    {
705
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
-    }
707
-
708
-
709
-    /**
710
-     *    _set_config_class
711
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
712
-     *
713
-     * @access    private
714
-     * @param    string $config_class
715
-     * @param    string $name
716
-     * @return    string
717
-     */
718
-    private function _set_config_class($config_class = '', $name = '')
719
-    {
720
-        return ! empty($config_class)
721
-            ? $config_class
722
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
-    }
724
-
725
-
726
-    /**
727
-     *    set_config
728
-     *
729
-     * @access    protected
730
-     * @param    string         $section
731
-     * @param    string         $name
732
-     * @param    string         $config_class
733
-     * @param    EE_Config_Base $config_obj
734
-     * @return    EE_Config_Base
735
-     */
736
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
-    {
738
-        // ensure config class is set to something
739
-        $config_class = $this->_set_config_class($config_class, $name);
740
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
741
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
-            return null;
743
-        }
744
-        $config_option_name = $this->_generate_config_option_name($section, $name);
745
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
748
-            $this->update_addon_option_names();
749
-        }
750
-        // verify the incoming config object but suppress errors
751
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
-            $config_obj = new $config_class();
753
-        }
754
-        if (get_option($config_option_name)) {
755
-            EE_Config::log($config_option_name);
756
-            update_option($config_option_name, $config_obj);
757
-            $this->{$section}->{$name} = $config_obj;
758
-            return $this->{$section}->{$name};
759
-        } else {
760
-            // create a wp-option for this config
761
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
762
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
763
-                return $this->{$section}->{$name};
764
-            } else {
765
-                EE_Error::add_error(
766
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
-                    __FILE__,
768
-                    __FUNCTION__,
769
-                    __LINE__
770
-                );
771
-                return null;
772
-            }
773
-        }
774
-    }
775
-
776
-
777
-    /**
778
-     *    update_config
779
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
-     *
781
-     * @access    public
782
-     * @param    string                $section
783
-     * @param    string                $name
784
-     * @param    EE_Config_Base|string $config_obj
785
-     * @param    bool                  $throw_errors
786
-     * @return    bool
787
-     */
788
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
-    {
790
-        // don't allow config updates during WP heartbeats
791
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
-            return false;
793
-        }
794
-        $config_obj = maybe_unserialize($config_obj);
795
-        // get class name of the incoming object
796
-        $config_class = get_class($config_obj);
797
-        // run tests 1-5 and 9 to verify config
798
-        if (! $this->_verify_config_params(
799
-            $section,
800
-            $name,
801
-            $config_class,
802
-            $config_obj,
803
-            array(1, 2, 3, 4, 7, 9)
804
-        )
805
-        ) {
806
-            return false;
807
-        }
808
-        $config_option_name = $this->_generate_config_option_name($section, $name);
809
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
-            // save new config to db
812
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
-                return true;
814
-            }
815
-        } else {
816
-            // first check if the record already exists
817
-            $existing_config = get_option($config_option_name);
818
-            $config_obj = serialize($config_obj);
819
-            // just return if db record is already up to date (NOT type safe comparison)
820
-            if ($existing_config == $config_obj) {
821
-                $this->{$section}->{$name} = $config_obj;
822
-                return true;
823
-            } elseif (update_option($config_option_name, $config_obj)) {
824
-                EE_Config::log($config_option_name);
825
-                // update wp-option for this config class
826
-                $this->{$section}->{$name} = $config_obj;
827
-                return true;
828
-            } elseif ($throw_errors) {
829
-                EE_Error::add_error(
830
-                    sprintf(
831
-                        __(
832
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
-                            'event_espresso'
834
-                        ),
835
-                        $config_class,
836
-                        'EE_Config->' . $section . '->' . $name
837
-                    ),
838
-                    __FILE__,
839
-                    __FUNCTION__,
840
-                    __LINE__
841
-                );
842
-            }
843
-        }
844
-        return false;
845
-    }
846
-
847
-
848
-    /**
849
-     *    get_config
850
-     *
851
-     * @access    public
852
-     * @param    string $section
853
-     * @param    string $name
854
-     * @param    string $config_class
855
-     * @return    mixed EE_Config_Base | NULL
856
-     */
857
-    public function get_config($section = '', $name = '', $config_class = '')
858
-    {
859
-        // ensure config class is set to something
860
-        $config_class = $this->_set_config_class($config_class, $name);
861
-        // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
-            return null;
864
-        }
865
-        // now test if the requested config object exists, but suppress errors
866
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
-            // config already exists, so pass it back
868
-            return $this->{$section}->{$name};
869
-        }
870
-        // load config option from db if it exists
871
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
-        // verify the newly retrieved config object, but suppress errors
873
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
-            // config is good, so set it and pass it back
875
-            $this->{$section}->{$name} = $config_obj;
876
-            return $this->{$section}->{$name};
877
-        }
878
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
879
-        $config_obj = $this->set_config($section, $name, $config_class);
880
-        // verify the newly created config object
881
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
-            return $this->{$section}->{$name};
883
-        } else {
884
-            EE_Error::add_error(
885
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
-                __FILE__,
887
-                __FUNCTION__,
888
-                __LINE__
889
-            );
890
-        }
891
-        return null;
892
-    }
893
-
894
-
895
-    /**
896
-     *    get_config_option
897
-     *
898
-     * @access    public
899
-     * @param    string $config_option_name
900
-     * @return    mixed EE_Config_Base | FALSE
901
-     */
902
-    public function get_config_option($config_option_name = '')
903
-    {
904
-        // retrieve the wp-option for this config class.
905
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
906
-        if (empty($config_option)) {
907
-            EE_Config::log($config_option_name . '-NOT-FOUND');
908
-        }
909
-        return $config_option;
910
-    }
911
-
912
-
913
-    /**
914
-     * log
915
-     *
916
-     * @param string $config_option_name
917
-     */
918
-    public static function log($config_option_name = '')
919
-    {
920
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
-            $config_log = get_option(EE_Config::LOG_NAME, array());
922
-            // copy incoming $_REQUEST and sanitize it so we can save it
923
-            $_request = $_REQUEST;
924
-            array_walk_recursive($_request, 'sanitize_text_field');
925
-            $config_log[ (string) microtime(true) ] = array(
926
-                'config_name' => $config_option_name,
927
-                'request'     => $_request,
928
-            );
929
-            update_option(EE_Config::LOG_NAME, $config_log);
930
-        }
931
-    }
932
-
933
-
934
-    /**
935
-     * trim_log
936
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
-     */
938
-    public static function trim_log()
939
-    {
940
-        if (! EE_Config::logging_enabled()) {
941
-            return;
942
-        }
943
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
-        $log_length = count($config_log);
945
-        if ($log_length > EE_Config::LOG_LENGTH) {
946
-            ksort($config_log);
947
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
-            update_option(EE_Config::LOG_NAME, $config_log);
949
-        }
950
-    }
951
-
952
-
953
-    /**
954
-     *    get_page_for_posts
955
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
-     *    wp-option "page_for_posts", or "posts" if no page is selected
957
-     *
958
-     * @access    public
959
-     * @return    string
960
-     */
961
-    public static function get_page_for_posts()
962
-    {
963
-        $page_for_posts = get_option('page_for_posts');
964
-        if (! $page_for_posts) {
965
-            return 'posts';
966
-        }
967
-        /** @type WPDB $wpdb */
968
-        global $wpdb;
969
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
-    }
972
-
973
-
974
-    /**
975
-     *    register_shortcodes_and_modules.
976
-     *    At this point, it's too early to tell if we're maintenance mode or not.
977
-     *    In fact, this is where we give modules a chance to let core know they exist
978
-     *    so they can help trigger maintenance mode if it's needed
979
-     *
980
-     * @access    public
981
-     * @return    void
982
-     */
983
-    public function register_shortcodes_and_modules()
984
-    {
985
-        // allow modules to set hooks for the rest of the system
986
-        EE_Registry::instance()->modules = $this->_register_modules();
987
-    }
988
-
989
-
990
-    /**
991
-     *    initialize_shortcodes_and_modules
992
-     *    meaning they can start adding their hooks to get stuff done
993
-     *
994
-     * @access    public
995
-     * @return    void
996
-     */
997
-    public function initialize_shortcodes_and_modules()
998
-    {
999
-        // allow modules to set hooks for the rest of the system
1000
-        $this->_initialize_modules();
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     *    widgets_init
1006
-     *
1007
-     * @access private
1008
-     * @return void
1009
-     */
1010
-    public function widgets_init()
1011
-    {
1012
-        // only init widgets on admin pages when not in complete maintenance, and
1013
-        // on frontend when not in any maintenance mode
1014
-        if (! EE_Maintenance_Mode::instance()->level()
1015
-            || (
1016
-                is_admin()
1017
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
-            )
1019
-        ) {
1020
-            // grab list of installed widgets
1021
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
-            // filter list of modules to register
1023
-            $widgets_to_register = apply_filters(
1024
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
-                $widgets_to_register
1026
-            );
1027
-            if (! empty($widgets_to_register)) {
1028
-                // cycle thru widget folders
1029
-                foreach ($widgets_to_register as $widget_path) {
1030
-                    // add to list of installed widget modules
1031
-                    EE_Config::register_ee_widget($widget_path);
1032
-                }
1033
-            }
1034
-            // filter list of installed modules
1035
-            EE_Registry::instance()->widgets = apply_filters(
1036
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1037
-                EE_Registry::instance()->widgets
1038
-            );
1039
-        }
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     *    register_ee_widget - makes core aware of this widget
1045
-     *
1046
-     * @access    public
1047
-     * @param    string $widget_path - full path up to and including widget folder
1048
-     * @return    void
1049
-     */
1050
-    public static function register_ee_widget($widget_path = null)
1051
-    {
1052
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
-        $widget_ext = '.widget.php';
1054
-        // make all separators match
1055
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
-        // does the file path INCLUDE the actual file name as part of the path ?
1057
-        if (strpos($widget_path, $widget_ext) !== false) {
1058
-            // grab and shortcode file name from directory name and break apart at dots
1059
-            $file_name = explode('.', basename($widget_path));
1060
-            // take first segment from file name pieces and remove class prefix if it exists
1061
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
-            // sanitize shortcode directory name
1063
-            $widget = sanitize_key($widget);
1064
-            // now we need to rebuild the shortcode path
1065
-            $widget_path = explode(DS, $widget_path);
1066
-            // remove last segment
1067
-            array_pop($widget_path);
1068
-            // glue it back together
1069
-            $widget_path = implode(DS, $widget_path);
1070
-        } else {
1071
-            // grab and sanitize widget directory name
1072
-            $widget = sanitize_key(basename($widget_path));
1073
-        }
1074
-        // create classname from widget directory name
1075
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
-        // add class prefix
1077
-        $widget_class = 'EEW_' . $widget;
1078
-        // does the widget exist ?
1079
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1080
-            $msg = sprintf(
1081
-                __(
1082
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
-                    'event_espresso'
1084
-                ),
1085
-                $widget_class,
1086
-                $widget_path . DS . $widget_class . $widget_ext
1087
-            );
1088
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
-            return;
1090
-        }
1091
-        // load the widget class file
1092
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1093
-        // verify that class exists
1094
-        if (! class_exists($widget_class)) {
1095
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
-            return;
1098
-        }
1099
-        register_widget($widget_class);
1100
-        // add to array of registered widgets
1101
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     *        _register_modules
1107
-     *
1108
-     * @access private
1109
-     * @return array
1110
-     */
1111
-    private function _register_modules()
1112
-    {
1113
-        // grab list of installed modules
1114
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
-        // filter list of modules to register
1116
-        $modules_to_register = apply_filters(
1117
-            'FHEE__EE_Config__register_modules__modules_to_register',
1118
-            $modules_to_register
1119
-        );
1120
-        if (! empty($modules_to_register)) {
1121
-            // loop through folders
1122
-            foreach ($modules_to_register as $module_path) {
1123
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
-                if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
-                    && $module_path !== EE_MODULES . 'gateways'
1126
-                ) {
1127
-                    // add to list of installed modules
1128
-                    EE_Config::register_module($module_path);
1129
-                }
1130
-            }
1131
-        }
1132
-        // filter list of installed modules
1133
-        return apply_filters(
1134
-            'FHEE__EE_Config___register_modules__installed_modules',
1135
-            EE_Registry::instance()->modules
1136
-        );
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     *    register_module - makes core aware of this module
1142
-     *
1143
-     * @access    public
1144
-     * @param    string $module_path - full path up to and including module folder
1145
-     * @return    bool
1146
-     */
1147
-    public static function register_module($module_path = null)
1148
-    {
1149
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
-        $module_ext = '.module.php';
1151
-        // make all separators match
1152
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1153
-        // does the file path INCLUDE the actual file name as part of the path ?
1154
-        if (strpos($module_path, $module_ext) !== false) {
1155
-            // grab and shortcode file name from directory name and break apart at dots
1156
-            $module_file = explode('.', basename($module_path));
1157
-            // now we need to rebuild the shortcode path
1158
-            $module_path = explode(DS, $module_path);
1159
-            // remove last segment
1160
-            array_pop($module_path);
1161
-            // glue it back together
1162
-            $module_path = implode(DS, $module_path) . DS;
1163
-            // take first segment from file name pieces and sanitize it
1164
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
-            // ensure class prefix is added
1166
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
-        } else {
1168
-            // we need to generate the filename based off of the folder name
1169
-            // grab and sanitize module name
1170
-            $module = strtolower(basename($module_path));
1171
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
-            // like trailingslashit()
1173
-            $module_path = rtrim($module_path, DS) . DS;
1174
-            // create classname from module directory name
1175
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
-            // add class prefix
1177
-            $module_class = 'EED_' . $module;
1178
-        }
1179
-        // does the module exist ?
1180
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1181
-            $msg = sprintf(
1182
-                __(
1183
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1184
-                    'event_espresso'
1185
-                ),
1186
-                $module
1187
-            );
1188
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
-            return false;
1190
-        }
1191
-        // load the module class file
1192
-        require_once($module_path . $module_class . $module_ext);
1193
-        // verify that class exists
1194
-        if (! class_exists($module_class)) {
1195
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
-            return false;
1198
-        }
1199
-        // add to array of registered modules
1200
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
-        do_action(
1202
-            'AHEE__EE_Config__register_module__complete',
1203
-            $module_class,
1204
-            EE_Registry::instance()->modules->{$module_class}
1205
-        );
1206
-        return true;
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     *    _initialize_modules
1212
-     *    allow modules to set hooks for the rest of the system
1213
-     *
1214
-     * @access private
1215
-     * @return void
1216
-     */
1217
-    private function _initialize_modules()
1218
-    {
1219
-        // cycle thru shortcode folders
1220
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
-            // which set hooks ?
1223
-            if (is_admin()) {
1224
-                // fire immediately
1225
-                call_user_func(array($module_class, 'set_hooks_admin'));
1226
-            } else {
1227
-                // delay until other systems are online
1228
-                add_action(
1229
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
-                    array($module_class, 'set_hooks')
1231
-                );
1232
-            }
1233
-        }
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     *    register_route - adds module method routes to route_map
1239
-     *
1240
-     * @access    public
1241
-     * @param    string $route       - "pretty" public alias for module method
1242
-     * @param    string $module      - module name (classname without EED_ prefix)
1243
-     * @param    string $method_name - the actual module method to be routed to
1244
-     * @param    string $key         - url param key indicating a route is being called
1245
-     * @return    bool
1246
-     */
1247
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
-    {
1249
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
-        $module = str_replace('EED_', '', $module);
1251
-        $module_class = 'EED_' . $module;
1252
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
-            return false;
1256
-        }
1257
-        if (empty($route)) {
1258
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
-            return false;
1261
-        }
1262
-        if (! method_exists('EED_' . $module, $method_name)) {
1263
-            $msg = sprintf(
1264
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
-                $route
1266
-            );
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
-            return false;
1269
-        }
1270
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
-        return true;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     *    get_route - get module method route
1277
-     *
1278
-     * @access    public
1279
-     * @param    string $route - "pretty" public alias for module method
1280
-     * @param    string $key   - url param key indicating a route is being called
1281
-     * @return    string
1282
-     */
1283
-    public static function get_route($route = null, $key = 'ee')
1284
-    {
1285
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1286
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1289
-        }
1290
-        return null;
1291
-    }
1292
-
1293
-
1294
-    /**
1295
-     *    get_routes - get ALL module method routes
1296
-     *
1297
-     * @access    public
1298
-     * @return    array
1299
-     */
1300
-    public static function get_routes()
1301
-    {
1302
-        return EE_Config::$_module_route_map;
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     *    register_forward - allows modules to forward request to another module for further processing
1308
-     *
1309
-     * @access    public
1310
-     * @param    string       $route   - "pretty" public alias for module method
1311
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
-     *                                 class, allows different forwards to be served based on status
1313
-     * @param    array|string $forward - function name or array( class, method )
1314
-     * @param    string       $key     - url param key indicating a route is being called
1315
-     * @return    bool
1316
-     */
1317
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
-    {
1319
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
-            $msg = sprintf(
1322
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
-                $route
1324
-            );
1325
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
-            return false;
1327
-        }
1328
-        if (empty($forward)) {
1329
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
-            return false;
1332
-        }
1333
-        if (is_array($forward)) {
1334
-            if (! isset($forward[1])) {
1335
-                $msg = sprintf(
1336
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
-                    $route
1338
-                );
1339
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
-                return false;
1341
-            }
1342
-            if (! method_exists($forward[0], $forward[1])) {
1343
-                $msg = sprintf(
1344
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
-                    $forward[1],
1346
-                    $route
1347
-                );
1348
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
-                return false;
1350
-            }
1351
-        } elseif (! function_exists($forward)) {
1352
-            $msg = sprintf(
1353
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
-                $forward,
1355
-                $route
1356
-            );
1357
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
-            return false;
1359
-        }
1360
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
-        return true;
1362
-    }
1363
-
1364
-
1365
-    /**
1366
-     *    get_forward - get forwarding route
1367
-     *
1368
-     * @access    public
1369
-     * @param    string  $route  - "pretty" public alias for module method
1370
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
-     *                           allows different forwards to be served based on status
1372
-     * @param    string  $key    - url param key indicating a route is being called
1373
-     * @return    string
1374
-     */
1375
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
-    {
1377
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
-            return apply_filters(
1380
-                'FHEE__EE_Config__get_forward',
1381
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
-                $route,
1383
-                $status
1384
-            );
1385
-        }
1386
-        return null;
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1392
-     *    results
1393
-     *
1394
-     * @access    public
1395
-     * @param    string  $route  - "pretty" public alias for module method
1396
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
-     *                           allows different views to be served based on status
1398
-     * @param    string  $view
1399
-     * @param    string  $key    - url param key indicating a route is being called
1400
-     * @return    bool
1401
-     */
1402
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
-    {
1404
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
-            $msg = sprintf(
1407
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1408
-                $route
1409
-            );
1410
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
-            return false;
1412
-        }
1413
-        if (! is_readable($view)) {
1414
-            $msg = sprintf(
1415
-                __(
1416
-                    'The %s view file could not be found or is not readable due to file permissions.',
1417
-                    'event_espresso'
1418
-                ),
1419
-                $view
1420
-            );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
-            return false;
1423
-        }
1424
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
-        return true;
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     *    get_view - get view for route and status
1431
-     *
1432
-     * @access    public
1433
-     * @param    string  $route  - "pretty" public alias for module method
1434
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
-     *                           allows different views to be served based on status
1436
-     * @param    string  $key    - url param key indicating a route is being called
1437
-     * @return    string
1438
-     */
1439
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1440
-    {
1441
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
-            return apply_filters(
1444
-                'FHEE__EE_Config__get_view',
1445
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
-                $route,
1447
-                $status
1448
-            );
1449
-        }
1450
-        return null;
1451
-    }
1452
-
1453
-
1454
-    public function update_addon_option_names()
1455
-    {
1456
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
-    }
1458
-
1459
-
1460
-    public function shutdown()
1461
-    {
1462
-        $this->update_addon_option_names();
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     * @return LegacyShortcodesManager
1468
-     */
1469
-    public static function getLegacyShortcodesManager()
1470
-    {
1471
-
1472
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
-                EE_Registry::instance()
1475
-            );
1476
-        }
1477
-        return EE_Config::instance()->legacy_shortcodes_manager;
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * register_shortcode - makes core aware of this shortcode
1483
-     *
1484
-     * @deprecated 4.9.26
1485
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1486
-     * @return    bool
1487
-     */
1488
-    public static function register_shortcode($shortcode_path = null)
1489
-    {
1490
-        EE_Error::doing_it_wrong(
1491
-            __METHOD__,
1492
-            __(
1493
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
-                'event_espresso'
1495
-            ),
1496
-            '4.9.26'
1497
-        );
1498
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
-    }
1500
-}
1501
-
1502
-/**
1503
- * Base class used for config classes. These classes should generally not have
1504
- * magic functions in use, except we'll allow them to magically set and get stuff...
1505
- * basically, they should just be well-defined stdClasses
1506
- */
1507
-class EE_Config_Base
1508
-{
1509
-
1510
-    /**
1511
-     * Utility function for escaping the value of a property and returning.
1512
-     *
1513
-     * @param string $property property name (checks to see if exists).
1514
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
-     * @throws \EE_Error
1516
-     */
1517
-    public function get_pretty($property)
1518
-    {
1519
-        if (! property_exists($this, $property)) {
1520
-            throw new EE_Error(
1521
-                sprintf(
1522
-                    __(
1523
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
-                        'event_espresso'
1525
-                    ),
1526
-                    get_class($this),
1527
-                    $property
1528
-                )
1529
-            );
1530
-        }
1531
-        // just handling escaping of strings for now.
1532
-        if (is_string($this->{$property})) {
1533
-            return stripslashes($this->{$property});
1534
-        }
1535
-        return $this->{$property};
1536
-    }
1537
-
1538
-
1539
-    public function populate()
1540
-    {
1541
-        // grab defaults via a new instance of this class.
1542
-        $class_name = get_class($this);
1543
-        $defaults = new $class_name;
1544
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
-        // default from our $defaults object.
1546
-        foreach (get_object_vars($defaults) as $property => $value) {
1547
-            if ($this->{$property} === null) {
1548
-                $this->{$property} = $value;
1549
-            }
1550
-        }
1551
-        // cleanup
1552
-        unset($defaults);
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     *        __isset
1558
-     *
1559
-     * @param $a
1560
-     * @return bool
1561
-     */
1562
-    public function __isset($a)
1563
-    {
1564
-        return false;
1565
-    }
1566
-
1567
-
1568
-    /**
1569
-     *        __unset
1570
-     *
1571
-     * @param $a
1572
-     * @return bool
1573
-     */
1574
-    public function __unset($a)
1575
-    {
1576
-        return false;
1577
-    }
1578
-
1579
-
1580
-    /**
1581
-     *        __clone
1582
-     */
1583
-    public function __clone()
1584
-    {
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     *        __wakeup
1590
-     */
1591
-    public function __wakeup()
1592
-    {
1593
-    }
1594
-
1595
-
1596
-    /**
1597
-     *        __destruct
1598
-     */
1599
-    public function __destruct()
1600
-    {
1601
-    }
1602
-}
1603
-
1604
-/**
1605
- * Class for defining what's in the EE_Config relating to registration settings
1606
- */
1607
-class EE_Core_Config extends EE_Config_Base
1608
-{
1609
-
1610
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
-
1612
-
1613
-    public $current_blog_id;
1614
-
1615
-    public $ee_ueip_optin;
1616
-
1617
-    public $ee_ueip_has_notified;
1618
-
1619
-    /**
1620
-     * Not to be confused with the 4 critical page variables (See
1621
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
-     *
1625
-     * @var array
1626
-     */
1627
-    public $post_shortcodes;
1628
-
1629
-    public $module_route_map;
1630
-
1631
-    public $module_forward_map;
1632
-
1633
-    public $module_view_map;
1634
-
1635
-    /**
1636
-     * The next 4 vars are the IDs of critical EE pages.
1637
-     *
1638
-     * @var int
1639
-     */
1640
-    public $reg_page_id;
1641
-
1642
-    public $txn_page_id;
1643
-
1644
-    public $thank_you_page_id;
1645
-
1646
-    public $cancel_page_id;
1647
-
1648
-    /**
1649
-     * The next 4 vars are the URLs of critical EE pages.
1650
-     *
1651
-     * @var int
1652
-     */
1653
-    public $reg_page_url;
1654
-
1655
-    public $txn_page_url;
1656
-
1657
-    public $thank_you_page_url;
1658
-
1659
-    public $cancel_page_url;
1660
-
1661
-    /**
1662
-     * The next vars relate to the custom slugs for EE CPT routes
1663
-     */
1664
-    public $event_cpt_slug;
1665
-
1666
-    /**
1667
-     * This caches the _ee_ueip_option in case this config is reset in the same
1668
-     * request across blog switches in a multisite context.
1669
-     * Avoids extra queries to the db for this option.
1670
-     *
1671
-     * @var bool
1672
-     */
1673
-    public static $ee_ueip_option;
1674
-
1675
-
1676
-    /**
1677
-     *    class constructor
1678
-     *
1679
-     * @access    public
1680
-     */
1681
-    public function __construct()
1682
-    {
1683
-        // set default organization settings
1684
-        $this->current_blog_id = get_current_blog_id();
1685
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
-        $this->post_shortcodes = array();
1689
-        $this->module_route_map = array();
1690
-        $this->module_forward_map = array();
1691
-        $this->module_view_map = array();
1692
-        // critical EE page IDs
1693
-        $this->reg_page_id = 0;
1694
-        $this->txn_page_id = 0;
1695
-        $this->thank_you_page_id = 0;
1696
-        $this->cancel_page_id = 0;
1697
-        // critical EE page URLs
1698
-        $this->reg_page_url = '';
1699
-        $this->txn_page_url = '';
1700
-        $this->thank_you_page_url = '';
1701
-        $this->cancel_page_url = '';
1702
-        // cpt slugs
1703
-        $this->event_cpt_slug = __('events', 'event_espresso');
1704
-        // ueip constant check
1705
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
-            $this->ee_ueip_optin = false;
1707
-            $this->ee_ueip_has_notified = true;
1708
-        }
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @return array
1714
-     */
1715
-    public function get_critical_pages_array()
1716
-    {
1717
-        return array(
1718
-            $this->reg_page_id,
1719
-            $this->txn_page_id,
1720
-            $this->thank_you_page_id,
1721
-            $this->cancel_page_id,
1722
-        );
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * @return array
1728
-     */
1729
-    public function get_critical_pages_shortcodes_array()
1730
-    {
1731
-        return array(
1732
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
-        );
1737
-    }
1738
-
1739
-
1740
-    /**
1741
-     *  gets/returns URL for EE reg_page
1742
-     *
1743
-     * @access    public
1744
-     * @return    string
1745
-     */
1746
-    public function reg_page_url()
1747
-    {
1748
-        if (! $this->reg_page_url) {
1749
-            $this->reg_page_url = add_query_arg(
1750
-                array('uts' => time()),
1751
-                get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1753
-        }
1754
-        return $this->reg_page_url;
1755
-    }
1756
-
1757
-
1758
-    /**
1759
-     *  gets/returns URL for EE txn_page
1760
-     *
1761
-     * @param array $query_args like what gets passed to
1762
-     *                          add_query_arg() as the first argument
1763
-     * @access    public
1764
-     * @return    string
1765
-     */
1766
-    public function txn_page_url($query_args = array())
1767
-    {
1768
-        if (! $this->txn_page_url) {
1769
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1770
-        }
1771
-        if ($query_args) {
1772
-            return add_query_arg($query_args, $this->txn_page_url);
1773
-        } else {
1774
-            return $this->txn_page_url;
1775
-        }
1776
-    }
1777
-
1778
-
1779
-    /**
1780
-     *  gets/returns URL for EE thank_you_page
1781
-     *
1782
-     * @param array $query_args like what gets passed to
1783
-     *                          add_query_arg() as the first argument
1784
-     * @access    public
1785
-     * @return    string
1786
-     */
1787
-    public function thank_you_page_url($query_args = array())
1788
-    {
1789
-        if (! $this->thank_you_page_url) {
1790
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
-        }
1792
-        if ($query_args) {
1793
-            return add_query_arg($query_args, $this->thank_you_page_url);
1794
-        } else {
1795
-            return $this->thank_you_page_url;
1796
-        }
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     *  gets/returns URL for EE cancel_page
1802
-     *
1803
-     * @access    public
1804
-     * @return    string
1805
-     */
1806
-    public function cancel_page_url()
1807
-    {
1808
-        if (! $this->cancel_page_url) {
1809
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
-        }
1811
-        return $this->cancel_page_url;
1812
-    }
1813
-
1814
-
1815
-    /**
1816
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
-     *
1818
-     * @since 4.7.5
1819
-     */
1820
-    protected function _reset_urls()
1821
-    {
1822
-        $this->reg_page_url = '';
1823
-        $this->txn_page_url = '';
1824
-        $this->cancel_page_url = '';
1825
-        $this->thank_you_page_url = '';
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Used to return what the optin value is set for the EE User Experience Program.
1831
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
-     * on the main site only.
1833
-     *
1834
-     * @return bool
1835
-     */
1836
-    protected function _get_main_ee_ueip_optin()
1837
-    {
1838
-        // if this is the main site then we can just bypass our direct query.
1839
-        if (is_main_site()) {
1840
-            return get_option(self::OPTION_NAME_UXIP, false);
1841
-        }
1842
-        // is this already cached for this request?  If so use it.
1843
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1844
-            return EE_Core_Config::$ee_ueip_option;
1845
-        }
1846
-        global $wpdb;
1847
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1848
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
-        $option = self::OPTION_NAME_UXIP;
1850
-        // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
-        // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1858
-        if (false !== $pre) {
1859
-            EE_Core_Config::$ee_ueip_option = $pre;
1860
-            return EE_Core_Config::$ee_ueip_option;
1861
-        }
1862
-        $row = $wpdb->get_row(
1863
-            $wpdb->prepare(
1864
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
-                $option
1866
-            )
1867
-        );
1868
-        if (is_object($row)) {
1869
-            $value = $row->option_value;
1870
-        } else { // option does not exist so use default.
1871
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
-            return EE_Core_Config::$ee_ueip_option;
1873
-        }
1874
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
-        return EE_Core_Config::$ee_ueip_option;
1876
-    }
1877
-
1878
-
1879
-    /**
1880
-     * Utility function for escaping the value of a property and returning.
1881
-     *
1882
-     * @param string $property property name (checks to see if exists).
1883
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
-     * @throws \EE_Error
1885
-     */
1886
-    public function get_pretty($property)
1887
-    {
1888
-        if ($property === self::OPTION_NAME_UXIP) {
1889
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1890
-        }
1891
-        return parent::get_pretty($property);
1892
-    }
1893
-
1894
-
1895
-    /**
1896
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
-     * on the object.
1898
-     *
1899
-     * @return array
1900
-     */
1901
-    public function __sleep()
1902
-    {
1903
-        // reset all url properties
1904
-        $this->_reset_urls();
1905
-        // return what to save to db
1906
-        return array_keys(get_object_vars($this));
1907
-    }
1908
-}
1909
-
1910
-/**
1911
- * Config class for storing info on the Organization
1912
- */
1913
-class EE_Organization_Config extends EE_Config_Base
1914
-{
1915
-
1916
-    /**
1917
-     * @var string $name
1918
-     * eg EE4.1
1919
-     */
1920
-    public $name;
1921
-
1922
-    /**
1923
-     * @var string $address_1
1924
-     * eg 123 Onna Road
1925
-     */
1926
-    public $address_1 = '';
1927
-
1928
-    /**
1929
-     * @var string $address_2
1930
-     * eg PO Box 123
1931
-     */
1932
-    public $address_2 = '';
1933
-
1934
-    /**
1935
-     * @var string $city
1936
-     * eg Inna City
1937
-     */
1938
-    public $city = '';
1939
-
1940
-    /**
1941
-     * @var int $STA_ID
1942
-     * eg 4
1943
-     */
1944
-    public $STA_ID = 0;
1945
-
1946
-    /**
1947
-     * @var string $CNT_ISO
1948
-     * eg US
1949
-     */
1950
-    public $CNT_ISO = '';
1951
-
1952
-    /**
1953
-     * @var string $zip
1954
-     * eg 12345  or V1A 2B3
1955
-     */
1956
-    public $zip = '';
1957
-
1958
-    /**
1959
-     * @var string $email
1960
-     * eg [email protected]
1961
-     */
1962
-    public $email;
1963
-
1964
-    /**
1965
-     * @var string $phone
1966
-     * eg. 111-111-1111
1967
-     */
1968
-    public $phone = '';
1969
-
1970
-    /**
1971
-     * @var string $vat
1972
-     * VAT/Tax Number
1973
-     */
1974
-    public $vat = '';
1975
-
1976
-    /**
1977
-     * @var string $logo_url
1978
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
-     */
1980
-    public $logo_url = '';
1981
-
1982
-    /**
1983
-     * The below are all various properties for holding links to organization social network profiles
1984
-     *
1985
-     * @var string
1986
-     */
1987
-    /**
1988
-     * facebook (facebook.com/profile.name)
1989
-     *
1990
-     * @var string
1991
-     */
1992
-    public $facebook = '';
1993
-
1994
-    /**
1995
-     * twitter (twitter.com/twitter_handle)
1996
-     *
1997
-     * @var string
1998
-     */
1999
-    public $twitter = '';
2000
-
2001
-    /**
2002
-     * linkedin (linkedin.com/in/profile_name)
2003
-     *
2004
-     * @var string
2005
-     */
2006
-    public $linkedin = '';
2007
-
2008
-    /**
2009
-     * pinterest (www.pinterest.com/profile_name)
2010
-     *
2011
-     * @var string
2012
-     */
2013
-    public $pinterest = '';
2014
-
2015
-    /**
2016
-     * google+ (google.com/+profileName)
2017
-     *
2018
-     * @var string
2019
-     */
2020
-    public $google = '';
2021
-
2022
-    /**
2023
-     * instagram (instagram.com/handle)
2024
-     *
2025
-     * @var string
2026
-     */
2027
-    public $instagram = '';
2028
-
2029
-
2030
-    /**
2031
-     *    class constructor
2032
-     *
2033
-     * @access    public
2034
-     */
2035
-    public function __construct()
2036
-    {
2037
-        // set default organization settings
2038
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
-        $this->email = get_bloginfo('admin_email');
2041
-    }
2042
-}
2043
-
2044
-/**
2045
- * Class for defining what's in the EE_Config relating to currency
2046
- */
2047
-class EE_Currency_Config extends EE_Config_Base
2048
-{
2049
-
2050
-    /**
2051
-     * @var string $code
2052
-     * eg 'US'
2053
-     */
2054
-    public $code;
2055
-
2056
-    /**
2057
-     * @var string $name
2058
-     * eg 'Dollar'
2059
-     */
2060
-    public $name;
2061
-
2062
-    /**
2063
-     * plural name
2064
-     *
2065
-     * @var string $plural
2066
-     * eg 'Dollars'
2067
-     */
2068
-    public $plural;
2069
-
2070
-    /**
2071
-     * currency sign
2072
-     *
2073
-     * @var string $sign
2074
-     * eg '$'
2075
-     */
2076
-    public $sign;
2077
-
2078
-    /**
2079
-     * Whether the currency sign should come before the number or not
2080
-     *
2081
-     * @var boolean $sign_b4
2082
-     */
2083
-    public $sign_b4;
2084
-
2085
-    /**
2086
-     * How many digits should come after the decimal place
2087
-     *
2088
-     * @var int $dec_plc
2089
-     */
2090
-    public $dec_plc;
2091
-
2092
-    /**
2093
-     * Symbol to use for decimal mark
2094
-     *
2095
-     * @var string $dec_mrk
2096
-     * eg '.'
2097
-     */
2098
-    public $dec_mrk;
2099
-
2100
-    /**
2101
-     * Symbol to use for thousands
2102
-     *
2103
-     * @var string $thsnds
2104
-     * eg ','
2105
-     */
2106
-    public $thsnds;
2107
-
2108
-
2109
-    /**
2110
-     *    class constructor
2111
-     *
2112
-     * @access    public
2113
-     * @param string $CNT_ISO
2114
-     * @throws \EE_Error
2115
-     */
2116
-    public function __construct($CNT_ISO = '')
2117
-    {
2118
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
-        // get country code from organization settings or use default
2121
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
-            : '';
2125
-        // but override if requested
2126
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
-        if (! empty($CNT_ISO)
2129
-            && EE_Maintenance_Mode::instance()->models_can_query()
2130
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
-        ) {
2132
-            // retrieve the country settings from the db, just in case they have been customized
2133
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
-            if ($country instanceof EE_Country) {
2135
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
-                $this->name = $country->currency_name_single();    // Dollar
2137
-                $this->plural = $country->currency_name_plural();    // Dollars
2138
-                $this->sign = $country->currency_sign();            // currency sign: $
2139
-                $this->sign_b4 = $country->currency_sign_before(
2140
-                );        // currency sign before or after: $TRUE  or  FALSE$
2141
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
-                $this->dec_mrk = $country->currency_decimal_mark(
2143
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
-                $this->thsnds = $country->currency_thousands_separator(
2145
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
-            }
2147
-        }
2148
-        // fallback to hardcoded defaults, in case the above failed
2149
-        if (empty($this->code)) {
2150
-            // set default currency settings
2151
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2152
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2153
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
-            $this->sign = '$';    // currency sign: $
2155
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
-        }
2160
-    }
2161
-}
2162
-
2163
-/**
2164
- * Class for defining what's in the EE_Config relating to registration settings
2165
- */
2166
-class EE_Registration_Config extends EE_Config_Base
2167
-{
2168
-
2169
-    /**
2170
-     * Default registration status
2171
-     *
2172
-     * @var string $default_STS_ID
2173
-     * eg 'RPP'
2174
-     */
2175
-    public $default_STS_ID;
2176
-
2177
-    /**
2178
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
-     * registrations)
2180
-     *
2181
-     * @var int
2182
-     */
2183
-    public $default_maximum_number_of_tickets;
2184
-
2185
-    /**
2186
-     * level of validation to apply to email addresses
2187
-     *
2188
-     * @var string $email_validation_level
2189
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
-     */
2191
-    public $email_validation_level;
2192
-
2193
-    /**
2194
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
-     *
2196
-     * @var boolean $show_pending_payment_options
2197
-     */
2198
-    public $show_pending_payment_options;
2199
-
2200
-    /**
2201
-     * Whether to skip the registration confirmation page
2202
-     *
2203
-     * @var boolean $skip_reg_confirmation
2204
-     */
2205
-    public $skip_reg_confirmation;
2206
-
2207
-    /**
2208
-     * an array of SPCO reg steps where:
2209
-     *        the keys denotes the reg step order
2210
-     *        each element consists of an array with the following elements:
2211
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
-     *            "slug" => the URL param used to trigger the reg step
2214
-     *
2215
-     * @var array $reg_steps
2216
-     */
2217
-    public $reg_steps;
2218
-
2219
-    /**
2220
-     * Whether registration confirmation should be the last page of SPCO
2221
-     *
2222
-     * @var boolean $reg_confirmation_last
2223
-     */
2224
-    public $reg_confirmation_last;
2225
-
2226
-    /**
2227
-     * Whether or not to enable the EE Bot Trap
2228
-     *
2229
-     * @var boolean $use_bot_trap
2230
-     */
2231
-    public $use_bot_trap;
2232
-
2233
-    /**
2234
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2235
-     *
2236
-     * @var boolean $use_encryption
2237
-     */
2238
-    public $use_encryption;
2239
-
2240
-    /**
2241
-     * Whether or not to use ReCaptcha
2242
-     *
2243
-     * @var boolean $use_captcha
2244
-     */
2245
-    public $use_captcha;
2246
-
2247
-    /**
2248
-     * ReCaptcha Theme
2249
-     *
2250
-     * @var string $recaptcha_theme
2251
-     *    options: 'dark', 'light', 'invisible'
2252
-     */
2253
-    public $recaptcha_theme;
2254
-
2255
-    /**
2256
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
-     *
2258
-     * @var string $recaptcha_badge
2259
-     *    options: 'bottomright', 'bottomleft', 'inline'
2260
-     */
2261
-    public $recaptcha_badge;
17
+	const OPTION_NAME = 'ee_config';
18
+
19
+	const LOG_NAME = 'ee_config_log';
20
+
21
+	const LOG_LENGTH = 100;
22
+
23
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
+
25
+	/**
26
+	 *    instance of the EE_Config object
27
+	 *
28
+	 * @var    EE_Config $_instance
29
+	 * @access    private
30
+	 */
31
+	private static $_instance;
32
+
33
+	/**
34
+	 * @var boolean $_logging_enabled
35
+	 */
36
+	private static $_logging_enabled = false;
37
+
38
+	/**
39
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
+	 */
41
+	private $legacy_shortcodes_manager;
42
+
43
+	/**
44
+	 * An StdClass whose property names are addon slugs,
45
+	 * and values are their config classes
46
+	 *
47
+	 * @var StdClass
48
+	 */
49
+	public $addons;
50
+
51
+	/**
52
+	 * @var EE_Admin_Config
53
+	 */
54
+	public $admin;
55
+
56
+	/**
57
+	 * @var EE_Core_Config
58
+	 */
59
+	public $core;
60
+
61
+	/**
62
+	 * @var EE_Currency_Config
63
+	 */
64
+	public $currency;
65
+
66
+	/**
67
+	 * @var EE_Organization_Config
68
+	 */
69
+	public $organization;
70
+
71
+	/**
72
+	 * @var EE_Registration_Config
73
+	 */
74
+	public $registration;
75
+
76
+	/**
77
+	 * @var EE_Template_Config
78
+	 */
79
+	public $template_settings;
80
+
81
+	/**
82
+	 * Holds EE environment values.
83
+	 *
84
+	 * @var EE_Environment_Config
85
+	 */
86
+	public $environment;
87
+
88
+	/**
89
+	 * settings pertaining to Google maps
90
+	 *
91
+	 * @var EE_Map_Config
92
+	 */
93
+	public $map_settings;
94
+
95
+	/**
96
+	 * settings pertaining to Taxes
97
+	 *
98
+	 * @var EE_Tax_Config
99
+	 */
100
+	public $tax_settings;
101
+
102
+	/**
103
+	 * Settings pertaining to global messages settings.
104
+	 *
105
+	 * @var EE_Messages_Config
106
+	 */
107
+	public $messages;
108
+
109
+	/**
110
+	 * @deprecated
111
+	 * @var EE_Gateway_Config
112
+	 */
113
+	public $gateway;
114
+
115
+	/**
116
+	 * @var    array $_addon_option_names
117
+	 * @access    private
118
+	 */
119
+	private $_addon_option_names = array();
120
+
121
+	/**
122
+	 * @var    array $_module_route_map
123
+	 * @access    private
124
+	 */
125
+	private static $_module_route_map = array();
126
+
127
+	/**
128
+	 * @var    array $_module_forward_map
129
+	 * @access    private
130
+	 */
131
+	private static $_module_forward_map = array();
132
+
133
+	/**
134
+	 * @var    array $_module_view_map
135
+	 * @access    private
136
+	 */
137
+	private static $_module_view_map = array();
138
+
139
+
140
+	/**
141
+	 * @singleton method used to instantiate class object
142
+	 * @access    public
143
+	 * @return EE_Config instance
144
+	 */
145
+	public static function instance()
146
+	{
147
+		// check if class object is instantiated, and instantiated properly
148
+		if (! self::$_instance instanceof EE_Config) {
149
+			self::$_instance = new self();
150
+		}
151
+		return self::$_instance;
152
+	}
153
+
154
+
155
+	/**
156
+	 * Resets the config
157
+	 *
158
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
159
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
160
+	 *                               reflect its state in the database
161
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
162
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
163
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
164
+	 *                               site was put into maintenance mode)
165
+	 * @return EE_Config
166
+	 */
167
+	public static function reset($hard_reset = false, $reinstantiate = true)
168
+	{
169
+		if (self::$_instance instanceof EE_Config) {
170
+			if ($hard_reset) {
171
+				self::$_instance->legacy_shortcodes_manager = null;
172
+				self::$_instance->_addon_option_names = array();
173
+				self::$_instance->_initialize_config();
174
+				self::$_instance->update_espresso_config();
175
+			}
176
+			self::$_instance->update_addon_option_names();
177
+		}
178
+		self::$_instance = null;
179
+		// we don't need to reset the static properties imo because those should
180
+		// only change when a module is added or removed. Currently we don't
181
+		// support removing a module during a request when it previously existed
182
+		if ($reinstantiate) {
183
+			return self::instance();
184
+		} else {
185
+			return null;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 *    class constructor
192
+	 *
193
+	 * @access    private
194
+	 */
195
+	private function __construct()
196
+	{
197
+		do_action('AHEE__EE_Config__construct__begin', $this);
198
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
199
+		// setup empty config classes
200
+		$this->_initialize_config();
201
+		// load existing EE site settings
202
+		$this->_load_core_config();
203
+		// confirm everything loaded correctly and set filtered defaults if not
204
+		$this->_verify_config();
205
+		//  register shortcodes and modules
206
+		add_action(
207
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
208
+			array($this, 'register_shortcodes_and_modules'),
209
+			999
210
+		);
211
+		//  initialize shortcodes and modules
212
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
213
+		// register widgets
214
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
215
+		// shutdown
216
+		add_action('shutdown', array($this, 'shutdown'), 10);
217
+		// construct__end hook
218
+		do_action('AHEE__EE_Config__construct__end', $this);
219
+		// hardcoded hack
220
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return boolean
226
+	 */
227
+	public static function logging_enabled()
228
+	{
229
+		return self::$_logging_enabled;
230
+	}
231
+
232
+
233
+	/**
234
+	 * use to get the current theme if needed from static context
235
+	 *
236
+	 * @return string current theme set.
237
+	 */
238
+	public static function get_current_theme()
239
+	{
240
+		return isset(self::$_instance->template_settings->current_espresso_theme)
241
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
242
+	}
243
+
244
+
245
+	/**
246
+	 *        _initialize_config
247
+	 *
248
+	 * @access private
249
+	 * @return void
250
+	 */
251
+	private function _initialize_config()
252
+	{
253
+		EE_Config::trim_log();
254
+		// set defaults
255
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
256
+		$this->addons = new stdClass();
257
+		// set _module_route_map
258
+		EE_Config::$_module_route_map = array();
259
+		// set _module_forward_map
260
+		EE_Config::$_module_forward_map = array();
261
+		// set _module_view_map
262
+		EE_Config::$_module_view_map = array();
263
+	}
264
+
265
+
266
+	/**
267
+	 *        load core plugin configuration
268
+	 *
269
+	 * @access private
270
+	 * @return void
271
+	 */
272
+	private function _load_core_config()
273
+	{
274
+		// load_core_config__start hook
275
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
276
+		$espresso_config = $this->get_espresso_config();
277
+		foreach ($espresso_config as $config => $settings) {
278
+			// load_core_config__start hook
279
+			$settings = apply_filters(
280
+				'FHEE__EE_Config___load_core_config__config_settings',
281
+				$settings,
282
+				$config,
283
+				$this
284
+			);
285
+			if (is_object($settings) && property_exists($this, $config)) {
286
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
287
+				// call configs populate method to ensure any defaults are set for empty values.
288
+				if (method_exists($settings, 'populate')) {
289
+					$this->{$config}->populate();
290
+				}
291
+				if (method_exists($settings, 'do_hooks')) {
292
+					$this->{$config}->do_hooks();
293
+				}
294
+			}
295
+		}
296
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
297
+			$this->update_espresso_config();
298
+		}
299
+		// load_core_config__end hook
300
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
301
+	}
302
+
303
+
304
+	/**
305
+	 *    _verify_config
306
+	 *
307
+	 * @access    protected
308
+	 * @return    void
309
+	 */
310
+	protected function _verify_config()
311
+	{
312
+		$this->core = $this->core instanceof EE_Core_Config
313
+			? $this->core
314
+			: new EE_Core_Config();
315
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
316
+		$this->organization = $this->organization instanceof EE_Organization_Config
317
+			? $this->organization
318
+			: new EE_Organization_Config();
319
+		$this->organization = apply_filters(
320
+			'FHEE__EE_Config___initialize_config__organization',
321
+			$this->organization
322
+		);
323
+		$this->currency = $this->currency instanceof EE_Currency_Config
324
+			? $this->currency
325
+			: new EE_Currency_Config();
326
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
327
+		$this->registration = $this->registration instanceof EE_Registration_Config
328
+			? $this->registration
329
+			: new EE_Registration_Config();
330
+		$this->registration = apply_filters(
331
+			'FHEE__EE_Config___initialize_config__registration',
332
+			$this->registration
333
+		);
334
+		$this->admin = $this->admin instanceof EE_Admin_Config
335
+			? $this->admin
336
+			: new EE_Admin_Config();
337
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
339
+			? $this->template_settings
340
+			: new EE_Template_Config();
341
+		$this->template_settings = apply_filters(
342
+			'FHEE__EE_Config___initialize_config__template_settings',
343
+			$this->template_settings
344
+		);
345
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
346
+			? $this->map_settings
347
+			: new EE_Map_Config();
348
+		$this->map_settings = apply_filters(
349
+			'FHEE__EE_Config___initialize_config__map_settings',
350
+			$this->map_settings
351
+		);
352
+		$this->environment = $this->environment instanceof EE_Environment_Config
353
+			? $this->environment
354
+			: new EE_Environment_Config();
355
+		$this->environment = apply_filters(
356
+			'FHEE__EE_Config___initialize_config__environment',
357
+			$this->environment
358
+		);
359
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
360
+			? $this->tax_settings
361
+			: new EE_Tax_Config();
362
+		$this->tax_settings = apply_filters(
363
+			'FHEE__EE_Config___initialize_config__tax_settings',
364
+			$this->tax_settings
365
+		);
366
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
367
+		$this->messages = $this->messages instanceof EE_Messages_Config
368
+			? $this->messages
369
+			: new EE_Messages_Config();
370
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
371
+			? $this->gateway
372
+			: new EE_Gateway_Config();
373
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
374
+		$this->legacy_shortcodes_manager = null;
375
+	}
376
+
377
+
378
+	/**
379
+	 *    get_espresso_config
380
+	 *
381
+	 * @access    public
382
+	 * @return    array of espresso config stuff
383
+	 */
384
+	public function get_espresso_config()
385
+	{
386
+		// grab espresso configuration
387
+		return apply_filters(
388
+			'FHEE__EE_Config__get_espresso_config__CFG',
389
+			get_option(EE_Config::OPTION_NAME, array())
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 *    double_check_config_comparison
396
+	 *
397
+	 * @access    public
398
+	 * @param string $option
399
+	 * @param        $old_value
400
+	 * @param        $value
401
+	 */
402
+	public function double_check_config_comparison($option = '', $old_value, $value)
403
+	{
404
+		// make sure we're checking the ee config
405
+		if ($option === EE_Config::OPTION_NAME) {
406
+			// run a loose comparison of the old value against the new value for type and properties,
407
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
408
+			if ($value != $old_value) {
409
+				// if they are NOT the same, then remove the hook,
410
+				// which means the subsequent update results will be based solely on the update query results
411
+				// the reason we do this is because, as stated above,
412
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
413
+				// this happens PRIOR to serialization and any subsequent update.
414
+				// If values are found to match their previous old value,
415
+				// then WP bails before performing any update.
416
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
417
+				// it just pulled from the db, with the one being passed to it (which will not match).
418
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
419
+				// MySQL MAY ALSO NOT perform the update because
420
+				// the string it sees in the db looks the same as the new one it has been passed!!!
421
+				// This results in the query returning an "affected rows" value of ZERO,
422
+				// which gets returned immediately by WP update_option and looks like an error.
423
+				remove_action('update_option', array($this, 'check_config_updated'));
424
+			}
425
+		}
426
+	}
427
+
428
+
429
+	/**
430
+	 *    update_espresso_config
431
+	 *
432
+	 * @access   public
433
+	 */
434
+	protected function _reset_espresso_addon_config()
435
+	{
436
+		$this->_addon_option_names = array();
437
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
438
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
439
+			if ($addon_config_obj instanceof EE_Config_Base) {
440
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
441
+			}
442
+			$this->addons->{$addon_name} = null;
443
+		}
444
+	}
445
+
446
+
447
+	/**
448
+	 *    update_espresso_config
449
+	 *
450
+	 * @access   public
451
+	 * @param   bool $add_success
452
+	 * @param   bool $add_error
453
+	 * @return   bool
454
+	 */
455
+	public function update_espresso_config($add_success = false, $add_error = true)
456
+	{
457
+		// don't allow config updates during WP heartbeats
458
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
459
+			return false;
460
+		}
461
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
462
+		// $clone = clone( self::$_instance );
463
+		// self::$_instance = NULL;
464
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
465
+		$this->_reset_espresso_addon_config();
466
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
467
+		// but BEFORE the actual update occurs
468
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
469
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
470
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
471
+		$this->legacy_shortcodes_manager = null;
472
+		// now update "ee_config"
473
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
474
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
475
+		EE_Config::log(EE_Config::OPTION_NAME);
476
+		// if not saved... check if the hook we just added still exists;
477
+		// if it does, it means one of two things:
478
+		// that update_option bailed at the($value === $old_value) conditional,
479
+		// or...
480
+		// the db update query returned 0 rows affected
481
+		// (probably because the data  value was the same from it's perspective)
482
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
483
+		// but just means no update occurred, so don't display an error to the user.
484
+		// BUT... if update_option returns FALSE, AND the hook is missing,
485
+		// then it means that something truly went wrong
486
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
487
+		// remove our action since we don't want it in the system anymore
488
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
489
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
490
+		// self::$_instance = $clone;
491
+		// unset( $clone );
492
+		// if config remains the same or was updated successfully
493
+		if ($saved) {
494
+			if ($add_success) {
495
+				EE_Error::add_success(
496
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
497
+					__FILE__,
498
+					__FUNCTION__,
499
+					__LINE__
500
+				);
501
+			}
502
+			return true;
503
+		} else {
504
+			if ($add_error) {
505
+				EE_Error::add_error(
506
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
507
+					__FILE__,
508
+					__FUNCTION__,
509
+					__LINE__
510
+				);
511
+			}
512
+			return false;
513
+		}
514
+	}
515
+
516
+
517
+	/**
518
+	 *    _verify_config_params
519
+	 *
520
+	 * @access    private
521
+	 * @param    string         $section
522
+	 * @param    string         $name
523
+	 * @param    string         $config_class
524
+	 * @param    EE_Config_Base $config_obj
525
+	 * @param    array          $tests_to_run
526
+	 * @param    bool           $display_errors
527
+	 * @return    bool    TRUE on success, FALSE on fail
528
+	 */
529
+	private function _verify_config_params(
530
+		$section = '',
531
+		$name = '',
532
+		$config_class = '',
533
+		$config_obj = null,
534
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
535
+		$display_errors = true
536
+	) {
537
+		try {
538
+			foreach ($tests_to_run as $test) {
539
+				switch ($test) {
540
+					// TEST #1 : check that section was set
541
+					case 1:
542
+						if (empty($section)) {
543
+							if ($display_errors) {
544
+								throw new EE_Error(
545
+									sprintf(
546
+										__(
547
+											'No configuration section has been provided while attempting to save "%s".',
548
+											'event_espresso'
549
+										),
550
+										$config_class
551
+									)
552
+								);
553
+							}
554
+							return false;
555
+						}
556
+						break;
557
+					// TEST #2 : check that settings section exists
558
+					case 2:
559
+						if (! isset($this->{$section})) {
560
+							if ($display_errors) {
561
+								throw new EE_Error(
562
+									sprintf(
563
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
564
+										$section
565
+									)
566
+								);
567
+							}
568
+							return false;
569
+						}
570
+						break;
571
+					// TEST #3 : check that section is the proper format
572
+					case 3:
573
+						if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
574
+						) {
575
+							if ($display_errors) {
576
+								throw new EE_Error(
577
+									sprintf(
578
+										__(
579
+											'The "%s" configuration settings have not been formatted correctly.',
580
+											'event_espresso'
581
+										),
582
+										$section
583
+									)
584
+								);
585
+							}
586
+							return false;
587
+						}
588
+						break;
589
+					// TEST #4 : check that config section name has been set
590
+					case 4:
591
+						if (empty($name)) {
592
+							if ($display_errors) {
593
+								throw new EE_Error(
594
+									__(
595
+										'No name has been provided for the specific configuration section.',
596
+										'event_espresso'
597
+									)
598
+								);
599
+							}
600
+							return false;
601
+						}
602
+						break;
603
+					// TEST #5 : check that a config class name has been set
604
+					case 5:
605
+						if (empty($config_class)) {
606
+							if ($display_errors) {
607
+								throw new EE_Error(
608
+									__(
609
+										'No class name has been provided for the specific configuration section.',
610
+										'event_espresso'
611
+									)
612
+								);
613
+							}
614
+							return false;
615
+						}
616
+						break;
617
+					// TEST #6 : verify config class is accessible
618
+					case 6:
619
+						if (! class_exists($config_class)) {
620
+							if ($display_errors) {
621
+								throw new EE_Error(
622
+									sprintf(
623
+										__(
624
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
625
+											'event_espresso'
626
+										),
627
+										$config_class
628
+									)
629
+								);
630
+							}
631
+							return false;
632
+						}
633
+						break;
634
+					// TEST #7 : check that config has even been set
635
+					case 7:
636
+						if (! isset($this->{$section}->{$name})) {
637
+							if ($display_errors) {
638
+								throw new EE_Error(
639
+									sprintf(
640
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
641
+										$section,
642
+										$name
643
+									)
644
+								);
645
+							}
646
+							return false;
647
+						} else {
648
+							// and make sure it's not serialized
649
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
650
+						}
651
+						break;
652
+					// TEST #8 : check that config is the requested type
653
+					case 8:
654
+						if (! $this->{$section}->{$name} instanceof $config_class) {
655
+							if ($display_errors) {
656
+								throw new EE_Error(
657
+									sprintf(
658
+										__(
659
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
660
+											'event_espresso'
661
+										),
662
+										$section,
663
+										$name,
664
+										$config_class
665
+									)
666
+								);
667
+							}
668
+							return false;
669
+						}
670
+						break;
671
+					// TEST #9 : verify config object
672
+					case 9:
673
+						if (! $config_obj instanceof EE_Config_Base) {
674
+							if ($display_errors) {
675
+								throw new EE_Error(
676
+									sprintf(
677
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
678
+										print_r($config_obj, true)
679
+									)
680
+								);
681
+							}
682
+							return false;
683
+						}
684
+						break;
685
+				}
686
+			}
687
+		} catch (EE_Error $e) {
688
+			$e->get_error();
689
+		}
690
+		// you have successfully run the gauntlet
691
+		return true;
692
+	}
693
+
694
+
695
+	/**
696
+	 *    _generate_config_option_name
697
+	 *
698
+	 * @access        protected
699
+	 * @param        string $section
700
+	 * @param        string $name
701
+	 * @return        string
702
+	 */
703
+	private function _generate_config_option_name($section = '', $name = '')
704
+	{
705
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
706
+	}
707
+
708
+
709
+	/**
710
+	 *    _set_config_class
711
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
712
+	 *
713
+	 * @access    private
714
+	 * @param    string $config_class
715
+	 * @param    string $name
716
+	 * @return    string
717
+	 */
718
+	private function _set_config_class($config_class = '', $name = '')
719
+	{
720
+		return ! empty($config_class)
721
+			? $config_class
722
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
723
+	}
724
+
725
+
726
+	/**
727
+	 *    set_config
728
+	 *
729
+	 * @access    protected
730
+	 * @param    string         $section
731
+	 * @param    string         $name
732
+	 * @param    string         $config_class
733
+	 * @param    EE_Config_Base $config_obj
734
+	 * @return    EE_Config_Base
735
+	 */
736
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
737
+	{
738
+		// ensure config class is set to something
739
+		$config_class = $this->_set_config_class($config_class, $name);
740
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
741
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
742
+			return null;
743
+		}
744
+		$config_option_name = $this->_generate_config_option_name($section, $name);
745
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
746
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
747
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
748
+			$this->update_addon_option_names();
749
+		}
750
+		// verify the incoming config object but suppress errors
751
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
752
+			$config_obj = new $config_class();
753
+		}
754
+		if (get_option($config_option_name)) {
755
+			EE_Config::log($config_option_name);
756
+			update_option($config_option_name, $config_obj);
757
+			$this->{$section}->{$name} = $config_obj;
758
+			return $this->{$section}->{$name};
759
+		} else {
760
+			// create a wp-option for this config
761
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
762
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
763
+				return $this->{$section}->{$name};
764
+			} else {
765
+				EE_Error::add_error(
766
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
767
+					__FILE__,
768
+					__FUNCTION__,
769
+					__LINE__
770
+				);
771
+				return null;
772
+			}
773
+		}
774
+	}
775
+
776
+
777
+	/**
778
+	 *    update_config
779
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
780
+	 *
781
+	 * @access    public
782
+	 * @param    string                $section
783
+	 * @param    string                $name
784
+	 * @param    EE_Config_Base|string $config_obj
785
+	 * @param    bool                  $throw_errors
786
+	 * @return    bool
787
+	 */
788
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
789
+	{
790
+		// don't allow config updates during WP heartbeats
791
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
792
+			return false;
793
+		}
794
+		$config_obj = maybe_unserialize($config_obj);
795
+		// get class name of the incoming object
796
+		$config_class = get_class($config_obj);
797
+		// run tests 1-5 and 9 to verify config
798
+		if (! $this->_verify_config_params(
799
+			$section,
800
+			$name,
801
+			$config_class,
802
+			$config_obj,
803
+			array(1, 2, 3, 4, 7, 9)
804
+		)
805
+		) {
806
+			return false;
807
+		}
808
+		$config_option_name = $this->_generate_config_option_name($section, $name);
809
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
810
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
811
+			// save new config to db
812
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
813
+				return true;
814
+			}
815
+		} else {
816
+			// first check if the record already exists
817
+			$existing_config = get_option($config_option_name);
818
+			$config_obj = serialize($config_obj);
819
+			// just return if db record is already up to date (NOT type safe comparison)
820
+			if ($existing_config == $config_obj) {
821
+				$this->{$section}->{$name} = $config_obj;
822
+				return true;
823
+			} elseif (update_option($config_option_name, $config_obj)) {
824
+				EE_Config::log($config_option_name);
825
+				// update wp-option for this config class
826
+				$this->{$section}->{$name} = $config_obj;
827
+				return true;
828
+			} elseif ($throw_errors) {
829
+				EE_Error::add_error(
830
+					sprintf(
831
+						__(
832
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
833
+							'event_espresso'
834
+						),
835
+						$config_class,
836
+						'EE_Config->' . $section . '->' . $name
837
+					),
838
+					__FILE__,
839
+					__FUNCTION__,
840
+					__LINE__
841
+				);
842
+			}
843
+		}
844
+		return false;
845
+	}
846
+
847
+
848
+	/**
849
+	 *    get_config
850
+	 *
851
+	 * @access    public
852
+	 * @param    string $section
853
+	 * @param    string $name
854
+	 * @param    string $config_class
855
+	 * @return    mixed EE_Config_Base | NULL
856
+	 */
857
+	public function get_config($section = '', $name = '', $config_class = '')
858
+	{
859
+		// ensure config class is set to something
860
+		$config_class = $this->_set_config_class($config_class, $name);
861
+		// run tests 1-4, 6 and 7 to verify that all params have been set
862
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
+			return null;
864
+		}
865
+		// now test if the requested config object exists, but suppress errors
866
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
+			// config already exists, so pass it back
868
+			return $this->{$section}->{$name};
869
+		}
870
+		// load config option from db if it exists
871
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
+		// verify the newly retrieved config object, but suppress errors
873
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
+			// config is good, so set it and pass it back
875
+			$this->{$section}->{$name} = $config_obj;
876
+			return $this->{$section}->{$name};
877
+		}
878
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
879
+		$config_obj = $this->set_config($section, $name, $config_class);
880
+		// verify the newly created config object
881
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
+			return $this->{$section}->{$name};
883
+		} else {
884
+			EE_Error::add_error(
885
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
+				__FILE__,
887
+				__FUNCTION__,
888
+				__LINE__
889
+			);
890
+		}
891
+		return null;
892
+	}
893
+
894
+
895
+	/**
896
+	 *    get_config_option
897
+	 *
898
+	 * @access    public
899
+	 * @param    string $config_option_name
900
+	 * @return    mixed EE_Config_Base | FALSE
901
+	 */
902
+	public function get_config_option($config_option_name = '')
903
+	{
904
+		// retrieve the wp-option for this config class.
905
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
906
+		if (empty($config_option)) {
907
+			EE_Config::log($config_option_name . '-NOT-FOUND');
908
+		}
909
+		return $config_option;
910
+	}
911
+
912
+
913
+	/**
914
+	 * log
915
+	 *
916
+	 * @param string $config_option_name
917
+	 */
918
+	public static function log($config_option_name = '')
919
+	{
920
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
921
+			$config_log = get_option(EE_Config::LOG_NAME, array());
922
+			// copy incoming $_REQUEST and sanitize it so we can save it
923
+			$_request = $_REQUEST;
924
+			array_walk_recursive($_request, 'sanitize_text_field');
925
+			$config_log[ (string) microtime(true) ] = array(
926
+				'config_name' => $config_option_name,
927
+				'request'     => $_request,
928
+			);
929
+			update_option(EE_Config::LOG_NAME, $config_log);
930
+		}
931
+	}
932
+
933
+
934
+	/**
935
+	 * trim_log
936
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
937
+	 */
938
+	public static function trim_log()
939
+	{
940
+		if (! EE_Config::logging_enabled()) {
941
+			return;
942
+		}
943
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
944
+		$log_length = count($config_log);
945
+		if ($log_length > EE_Config::LOG_LENGTH) {
946
+			ksort($config_log);
947
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
948
+			update_option(EE_Config::LOG_NAME, $config_log);
949
+		}
950
+	}
951
+
952
+
953
+	/**
954
+	 *    get_page_for_posts
955
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
956
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
957
+	 *
958
+	 * @access    public
959
+	 * @return    string
960
+	 */
961
+	public static function get_page_for_posts()
962
+	{
963
+		$page_for_posts = get_option('page_for_posts');
964
+		if (! $page_for_posts) {
965
+			return 'posts';
966
+		}
967
+		/** @type WPDB $wpdb */
968
+		global $wpdb;
969
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
970
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
971
+	}
972
+
973
+
974
+	/**
975
+	 *    register_shortcodes_and_modules.
976
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
977
+	 *    In fact, this is where we give modules a chance to let core know they exist
978
+	 *    so they can help trigger maintenance mode if it's needed
979
+	 *
980
+	 * @access    public
981
+	 * @return    void
982
+	 */
983
+	public function register_shortcodes_and_modules()
984
+	{
985
+		// allow modules to set hooks for the rest of the system
986
+		EE_Registry::instance()->modules = $this->_register_modules();
987
+	}
988
+
989
+
990
+	/**
991
+	 *    initialize_shortcodes_and_modules
992
+	 *    meaning they can start adding their hooks to get stuff done
993
+	 *
994
+	 * @access    public
995
+	 * @return    void
996
+	 */
997
+	public function initialize_shortcodes_and_modules()
998
+	{
999
+		// allow modules to set hooks for the rest of the system
1000
+		$this->_initialize_modules();
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 *    widgets_init
1006
+	 *
1007
+	 * @access private
1008
+	 * @return void
1009
+	 */
1010
+	public function widgets_init()
1011
+	{
1012
+		// only init widgets on admin pages when not in complete maintenance, and
1013
+		// on frontend when not in any maintenance mode
1014
+		if (! EE_Maintenance_Mode::instance()->level()
1015
+			|| (
1016
+				is_admin()
1017
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1018
+			)
1019
+		) {
1020
+			// grab list of installed widgets
1021
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1022
+			// filter list of modules to register
1023
+			$widgets_to_register = apply_filters(
1024
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1025
+				$widgets_to_register
1026
+			);
1027
+			if (! empty($widgets_to_register)) {
1028
+				// cycle thru widget folders
1029
+				foreach ($widgets_to_register as $widget_path) {
1030
+					// add to list of installed widget modules
1031
+					EE_Config::register_ee_widget($widget_path);
1032
+				}
1033
+			}
1034
+			// filter list of installed modules
1035
+			EE_Registry::instance()->widgets = apply_filters(
1036
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1037
+				EE_Registry::instance()->widgets
1038
+			);
1039
+		}
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 *    register_ee_widget - makes core aware of this widget
1045
+	 *
1046
+	 * @access    public
1047
+	 * @param    string $widget_path - full path up to and including widget folder
1048
+	 * @return    void
1049
+	 */
1050
+	public static function register_ee_widget($widget_path = null)
1051
+	{
1052
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1053
+		$widget_ext = '.widget.php';
1054
+		// make all separators match
1055
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1056
+		// does the file path INCLUDE the actual file name as part of the path ?
1057
+		if (strpos($widget_path, $widget_ext) !== false) {
1058
+			// grab and shortcode file name from directory name and break apart at dots
1059
+			$file_name = explode('.', basename($widget_path));
1060
+			// take first segment from file name pieces and remove class prefix if it exists
1061
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1062
+			// sanitize shortcode directory name
1063
+			$widget = sanitize_key($widget);
1064
+			// now we need to rebuild the shortcode path
1065
+			$widget_path = explode(DS, $widget_path);
1066
+			// remove last segment
1067
+			array_pop($widget_path);
1068
+			// glue it back together
1069
+			$widget_path = implode(DS, $widget_path);
1070
+		} else {
1071
+			// grab and sanitize widget directory name
1072
+			$widget = sanitize_key(basename($widget_path));
1073
+		}
1074
+		// create classname from widget directory name
1075
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1076
+		// add class prefix
1077
+		$widget_class = 'EEW_' . $widget;
1078
+		// does the widget exist ?
1079
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1080
+			$msg = sprintf(
1081
+				__(
1082
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1083
+					'event_espresso'
1084
+				),
1085
+				$widget_class,
1086
+				$widget_path . DS . $widget_class . $widget_ext
1087
+			);
1088
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1089
+			return;
1090
+		}
1091
+		// load the widget class file
1092
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1093
+		// verify that class exists
1094
+		if (! class_exists($widget_class)) {
1095
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1096
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1097
+			return;
1098
+		}
1099
+		register_widget($widget_class);
1100
+		// add to array of registered widgets
1101
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 *        _register_modules
1107
+	 *
1108
+	 * @access private
1109
+	 * @return array
1110
+	 */
1111
+	private function _register_modules()
1112
+	{
1113
+		// grab list of installed modules
1114
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1115
+		// filter list of modules to register
1116
+		$modules_to_register = apply_filters(
1117
+			'FHEE__EE_Config__register_modules__modules_to_register',
1118
+			$modules_to_register
1119
+		);
1120
+		if (! empty($modules_to_register)) {
1121
+			// loop through folders
1122
+			foreach ($modules_to_register as $module_path) {
1123
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1124
+				if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1125
+					&& $module_path !== EE_MODULES . 'gateways'
1126
+				) {
1127
+					// add to list of installed modules
1128
+					EE_Config::register_module($module_path);
1129
+				}
1130
+			}
1131
+		}
1132
+		// filter list of installed modules
1133
+		return apply_filters(
1134
+			'FHEE__EE_Config___register_modules__installed_modules',
1135
+			EE_Registry::instance()->modules
1136
+		);
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 *    register_module - makes core aware of this module
1142
+	 *
1143
+	 * @access    public
1144
+	 * @param    string $module_path - full path up to and including module folder
1145
+	 * @return    bool
1146
+	 */
1147
+	public static function register_module($module_path = null)
1148
+	{
1149
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1150
+		$module_ext = '.module.php';
1151
+		// make all separators match
1152
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1153
+		// does the file path INCLUDE the actual file name as part of the path ?
1154
+		if (strpos($module_path, $module_ext) !== false) {
1155
+			// grab and shortcode file name from directory name and break apart at dots
1156
+			$module_file = explode('.', basename($module_path));
1157
+			// now we need to rebuild the shortcode path
1158
+			$module_path = explode(DS, $module_path);
1159
+			// remove last segment
1160
+			array_pop($module_path);
1161
+			// glue it back together
1162
+			$module_path = implode(DS, $module_path) . DS;
1163
+			// take first segment from file name pieces and sanitize it
1164
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1165
+			// ensure class prefix is added
1166
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1167
+		} else {
1168
+			// we need to generate the filename based off of the folder name
1169
+			// grab and sanitize module name
1170
+			$module = strtolower(basename($module_path));
1171
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1172
+			// like trailingslashit()
1173
+			$module_path = rtrim($module_path, DS) . DS;
1174
+			// create classname from module directory name
1175
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1176
+			// add class prefix
1177
+			$module_class = 'EED_' . $module;
1178
+		}
1179
+		// does the module exist ?
1180
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1181
+			$msg = sprintf(
1182
+				__(
1183
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1184
+					'event_espresso'
1185
+				),
1186
+				$module
1187
+			);
1188
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1189
+			return false;
1190
+		}
1191
+		// load the module class file
1192
+		require_once($module_path . $module_class . $module_ext);
1193
+		// verify that class exists
1194
+		if (! class_exists($module_class)) {
1195
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1196
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1197
+			return false;
1198
+		}
1199
+		// add to array of registered modules
1200
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1201
+		do_action(
1202
+			'AHEE__EE_Config__register_module__complete',
1203
+			$module_class,
1204
+			EE_Registry::instance()->modules->{$module_class}
1205
+		);
1206
+		return true;
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 *    _initialize_modules
1212
+	 *    allow modules to set hooks for the rest of the system
1213
+	 *
1214
+	 * @access private
1215
+	 * @return void
1216
+	 */
1217
+	private function _initialize_modules()
1218
+	{
1219
+		// cycle thru shortcode folders
1220
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1221
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1222
+			// which set hooks ?
1223
+			if (is_admin()) {
1224
+				// fire immediately
1225
+				call_user_func(array($module_class, 'set_hooks_admin'));
1226
+			} else {
1227
+				// delay until other systems are online
1228
+				add_action(
1229
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1230
+					array($module_class, 'set_hooks')
1231
+				);
1232
+			}
1233
+		}
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 *    register_route - adds module method routes to route_map
1239
+	 *
1240
+	 * @access    public
1241
+	 * @param    string $route       - "pretty" public alias for module method
1242
+	 * @param    string $module      - module name (classname without EED_ prefix)
1243
+	 * @param    string $method_name - the actual module method to be routed to
1244
+	 * @param    string $key         - url param key indicating a route is being called
1245
+	 * @return    bool
1246
+	 */
1247
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1248
+	{
1249
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1250
+		$module = str_replace('EED_', '', $module);
1251
+		$module_class = 'EED_' . $module;
1252
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1253
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1254
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1255
+			return false;
1256
+		}
1257
+		if (empty($route)) {
1258
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1259
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1260
+			return false;
1261
+		}
1262
+		if (! method_exists('EED_' . $module, $method_name)) {
1263
+			$msg = sprintf(
1264
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1265
+				$route
1266
+			);
1267
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1268
+			return false;
1269
+		}
1270
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1271
+		return true;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 *    get_route - get module method route
1277
+	 *
1278
+	 * @access    public
1279
+	 * @param    string $route - "pretty" public alias for module method
1280
+	 * @param    string $key   - url param key indicating a route is being called
1281
+	 * @return    string
1282
+	 */
1283
+	public static function get_route($route = null, $key = 'ee')
1284
+	{
1285
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1286
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1287
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1288
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1289
+		}
1290
+		return null;
1291
+	}
1292
+
1293
+
1294
+	/**
1295
+	 *    get_routes - get ALL module method routes
1296
+	 *
1297
+	 * @access    public
1298
+	 * @return    array
1299
+	 */
1300
+	public static function get_routes()
1301
+	{
1302
+		return EE_Config::$_module_route_map;
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 *    register_forward - allows modules to forward request to another module for further processing
1308
+	 *
1309
+	 * @access    public
1310
+	 * @param    string       $route   - "pretty" public alias for module method
1311
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1312
+	 *                                 class, allows different forwards to be served based on status
1313
+	 * @param    array|string $forward - function name or array( class, method )
1314
+	 * @param    string       $key     - url param key indicating a route is being called
1315
+	 * @return    bool
1316
+	 */
1317
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1318
+	{
1319
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1320
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1321
+			$msg = sprintf(
1322
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1323
+				$route
1324
+			);
1325
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1326
+			return false;
1327
+		}
1328
+		if (empty($forward)) {
1329
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1330
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1331
+			return false;
1332
+		}
1333
+		if (is_array($forward)) {
1334
+			if (! isset($forward[1])) {
1335
+				$msg = sprintf(
1336
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1337
+					$route
1338
+				);
1339
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1340
+				return false;
1341
+			}
1342
+			if (! method_exists($forward[0], $forward[1])) {
1343
+				$msg = sprintf(
1344
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1345
+					$forward[1],
1346
+					$route
1347
+				);
1348
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1349
+				return false;
1350
+			}
1351
+		} elseif (! function_exists($forward)) {
1352
+			$msg = sprintf(
1353
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1354
+				$forward,
1355
+				$route
1356
+			);
1357
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1358
+			return false;
1359
+		}
1360
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1361
+		return true;
1362
+	}
1363
+
1364
+
1365
+	/**
1366
+	 *    get_forward - get forwarding route
1367
+	 *
1368
+	 * @access    public
1369
+	 * @param    string  $route  - "pretty" public alias for module method
1370
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1371
+	 *                           allows different forwards to be served based on status
1372
+	 * @param    string  $key    - url param key indicating a route is being called
1373
+	 * @return    string
1374
+	 */
1375
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1376
+	{
1377
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1378
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1379
+			return apply_filters(
1380
+				'FHEE__EE_Config__get_forward',
1381
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1382
+				$route,
1383
+				$status
1384
+			);
1385
+		}
1386
+		return null;
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1392
+	 *    results
1393
+	 *
1394
+	 * @access    public
1395
+	 * @param    string  $route  - "pretty" public alias for module method
1396
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1397
+	 *                           allows different views to be served based on status
1398
+	 * @param    string  $view
1399
+	 * @param    string  $key    - url param key indicating a route is being called
1400
+	 * @return    bool
1401
+	 */
1402
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1403
+	{
1404
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1405
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1406
+			$msg = sprintf(
1407
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1408
+				$route
1409
+			);
1410
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
+			return false;
1412
+		}
1413
+		if (! is_readable($view)) {
1414
+			$msg = sprintf(
1415
+				__(
1416
+					'The %s view file could not be found or is not readable due to file permissions.',
1417
+					'event_espresso'
1418
+				),
1419
+				$view
1420
+			);
1421
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
+			return false;
1423
+		}
1424
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1425
+		return true;
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 *    get_view - get view for route and status
1431
+	 *
1432
+	 * @access    public
1433
+	 * @param    string  $route  - "pretty" public alias for module method
1434
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1435
+	 *                           allows different views to be served based on status
1436
+	 * @param    string  $key    - url param key indicating a route is being called
1437
+	 * @return    string
1438
+	 */
1439
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1440
+	{
1441
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1442
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1443
+			return apply_filters(
1444
+				'FHEE__EE_Config__get_view',
1445
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1446
+				$route,
1447
+				$status
1448
+			);
1449
+		}
1450
+		return null;
1451
+	}
1452
+
1453
+
1454
+	public function update_addon_option_names()
1455
+	{
1456
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1457
+	}
1458
+
1459
+
1460
+	public function shutdown()
1461
+	{
1462
+		$this->update_addon_option_names();
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 * @return LegacyShortcodesManager
1468
+	 */
1469
+	public static function getLegacyShortcodesManager()
1470
+	{
1471
+
1472
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1473
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1474
+				EE_Registry::instance()
1475
+			);
1476
+		}
1477
+		return EE_Config::instance()->legacy_shortcodes_manager;
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * register_shortcode - makes core aware of this shortcode
1483
+	 *
1484
+	 * @deprecated 4.9.26
1485
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1486
+	 * @return    bool
1487
+	 */
1488
+	public static function register_shortcode($shortcode_path = null)
1489
+	{
1490
+		EE_Error::doing_it_wrong(
1491
+			__METHOD__,
1492
+			__(
1493
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1494
+				'event_espresso'
1495
+			),
1496
+			'4.9.26'
1497
+		);
1498
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1499
+	}
1500
+}
2262 1501
 
2263
-    /**
2264
-     * ReCaptcha Type
2265
-     *
2266
-     * @var string $recaptcha_type
2267
-     *    options: 'audio', 'image'
2268
-     */
2269
-    public $recaptcha_type;
1502
+/**
1503
+ * Base class used for config classes. These classes should generally not have
1504
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1505
+ * basically, they should just be well-defined stdClasses
1506
+ */
1507
+class EE_Config_Base
1508
+{
2270 1509
 
2271
-    /**
2272
-     * ReCaptcha language
2273
-     *
2274
-     * @var string $recaptcha_language
2275
-     * eg 'en'
2276
-     */
2277
-    public $recaptcha_language;
1510
+	/**
1511
+	 * Utility function for escaping the value of a property and returning.
1512
+	 *
1513
+	 * @param string $property property name (checks to see if exists).
1514
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1515
+	 * @throws \EE_Error
1516
+	 */
1517
+	public function get_pretty($property)
1518
+	{
1519
+		if (! property_exists($this, $property)) {
1520
+			throw new EE_Error(
1521
+				sprintf(
1522
+					__(
1523
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1524
+						'event_espresso'
1525
+					),
1526
+					get_class($this),
1527
+					$property
1528
+				)
1529
+			);
1530
+		}
1531
+		// just handling escaping of strings for now.
1532
+		if (is_string($this->{$property})) {
1533
+			return stripslashes($this->{$property});
1534
+		}
1535
+		return $this->{$property};
1536
+	}
1537
+
1538
+
1539
+	public function populate()
1540
+	{
1541
+		// grab defaults via a new instance of this class.
1542
+		$class_name = get_class($this);
1543
+		$defaults = new $class_name;
1544
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1545
+		// default from our $defaults object.
1546
+		foreach (get_object_vars($defaults) as $property => $value) {
1547
+			if ($this->{$property} === null) {
1548
+				$this->{$property} = $value;
1549
+			}
1550
+		}
1551
+		// cleanup
1552
+		unset($defaults);
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 *        __isset
1558
+	 *
1559
+	 * @param $a
1560
+	 * @return bool
1561
+	 */
1562
+	public function __isset($a)
1563
+	{
1564
+		return false;
1565
+	}
1566
+
1567
+
1568
+	/**
1569
+	 *        __unset
1570
+	 *
1571
+	 * @param $a
1572
+	 * @return bool
1573
+	 */
1574
+	public function __unset($a)
1575
+	{
1576
+		return false;
1577
+	}
1578
+
1579
+
1580
+	/**
1581
+	 *        __clone
1582
+	 */
1583
+	public function __clone()
1584
+	{
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 *        __wakeup
1590
+	 */
1591
+	public function __wakeup()
1592
+	{
1593
+	}
1594
+
1595
+
1596
+	/**
1597
+	 *        __destruct
1598
+	 */
1599
+	public function __destruct()
1600
+	{
1601
+	}
1602
+}
2278 1603
 
2279
-    /**
2280
-     * ReCaptcha public key
2281
-     *
2282
-     * @var string $recaptcha_publickey
2283
-     */
2284
-    public $recaptcha_publickey;
1604
+/**
1605
+ * Class for defining what's in the EE_Config relating to registration settings
1606
+ */
1607
+class EE_Core_Config extends EE_Config_Base
1608
+{
2285 1609
 
2286
-    /**
2287
-     * ReCaptcha private key
2288
-     *
2289
-     * @var string $recaptcha_privatekey
2290
-     */
2291
-    public $recaptcha_privatekey;
1610
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1611
+
1612
+
1613
+	public $current_blog_id;
1614
+
1615
+	public $ee_ueip_optin;
1616
+
1617
+	public $ee_ueip_has_notified;
1618
+
1619
+	/**
1620
+	 * Not to be confused with the 4 critical page variables (See
1621
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1622
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1623
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1624
+	 *
1625
+	 * @var array
1626
+	 */
1627
+	public $post_shortcodes;
1628
+
1629
+	public $module_route_map;
1630
+
1631
+	public $module_forward_map;
1632
+
1633
+	public $module_view_map;
1634
+
1635
+	/**
1636
+	 * The next 4 vars are the IDs of critical EE pages.
1637
+	 *
1638
+	 * @var int
1639
+	 */
1640
+	public $reg_page_id;
1641
+
1642
+	public $txn_page_id;
1643
+
1644
+	public $thank_you_page_id;
1645
+
1646
+	public $cancel_page_id;
1647
+
1648
+	/**
1649
+	 * The next 4 vars are the URLs of critical EE pages.
1650
+	 *
1651
+	 * @var int
1652
+	 */
1653
+	public $reg_page_url;
1654
+
1655
+	public $txn_page_url;
1656
+
1657
+	public $thank_you_page_url;
1658
+
1659
+	public $cancel_page_url;
1660
+
1661
+	/**
1662
+	 * The next vars relate to the custom slugs for EE CPT routes
1663
+	 */
1664
+	public $event_cpt_slug;
1665
+
1666
+	/**
1667
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1668
+	 * request across blog switches in a multisite context.
1669
+	 * Avoids extra queries to the db for this option.
1670
+	 *
1671
+	 * @var bool
1672
+	 */
1673
+	public static $ee_ueip_option;
1674
+
1675
+
1676
+	/**
1677
+	 *    class constructor
1678
+	 *
1679
+	 * @access    public
1680
+	 */
1681
+	public function __construct()
1682
+	{
1683
+		// set default organization settings
1684
+		$this->current_blog_id = get_current_blog_id();
1685
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
+		$this->post_shortcodes = array();
1689
+		$this->module_route_map = array();
1690
+		$this->module_forward_map = array();
1691
+		$this->module_view_map = array();
1692
+		// critical EE page IDs
1693
+		$this->reg_page_id = 0;
1694
+		$this->txn_page_id = 0;
1695
+		$this->thank_you_page_id = 0;
1696
+		$this->cancel_page_id = 0;
1697
+		// critical EE page URLs
1698
+		$this->reg_page_url = '';
1699
+		$this->txn_page_url = '';
1700
+		$this->thank_you_page_url = '';
1701
+		$this->cancel_page_url = '';
1702
+		// cpt slugs
1703
+		$this->event_cpt_slug = __('events', 'event_espresso');
1704
+		// ueip constant check
1705
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
+			$this->ee_ueip_optin = false;
1707
+			$this->ee_ueip_has_notified = true;
1708
+		}
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @return array
1714
+	 */
1715
+	public function get_critical_pages_array()
1716
+	{
1717
+		return array(
1718
+			$this->reg_page_id,
1719
+			$this->txn_page_id,
1720
+			$this->thank_you_page_id,
1721
+			$this->cancel_page_id,
1722
+		);
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * @return array
1728
+	 */
1729
+	public function get_critical_pages_shortcodes_array()
1730
+	{
1731
+		return array(
1732
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
+		);
1737
+	}
1738
+
1739
+
1740
+	/**
1741
+	 *  gets/returns URL for EE reg_page
1742
+	 *
1743
+	 * @access    public
1744
+	 * @return    string
1745
+	 */
1746
+	public function reg_page_url()
1747
+	{
1748
+		if (! $this->reg_page_url) {
1749
+			$this->reg_page_url = add_query_arg(
1750
+				array('uts' => time()),
1751
+				get_permalink($this->reg_page_id)
1752
+			) . '#checkout';
1753
+		}
1754
+		return $this->reg_page_url;
1755
+	}
1756
+
1757
+
1758
+	/**
1759
+	 *  gets/returns URL for EE txn_page
1760
+	 *
1761
+	 * @param array $query_args like what gets passed to
1762
+	 *                          add_query_arg() as the first argument
1763
+	 * @access    public
1764
+	 * @return    string
1765
+	 */
1766
+	public function txn_page_url($query_args = array())
1767
+	{
1768
+		if (! $this->txn_page_url) {
1769
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1770
+		}
1771
+		if ($query_args) {
1772
+			return add_query_arg($query_args, $this->txn_page_url);
1773
+		} else {
1774
+			return $this->txn_page_url;
1775
+		}
1776
+	}
1777
+
1778
+
1779
+	/**
1780
+	 *  gets/returns URL for EE thank_you_page
1781
+	 *
1782
+	 * @param array $query_args like what gets passed to
1783
+	 *                          add_query_arg() as the first argument
1784
+	 * @access    public
1785
+	 * @return    string
1786
+	 */
1787
+	public function thank_you_page_url($query_args = array())
1788
+	{
1789
+		if (! $this->thank_you_page_url) {
1790
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
+		}
1792
+		if ($query_args) {
1793
+			return add_query_arg($query_args, $this->thank_you_page_url);
1794
+		} else {
1795
+			return $this->thank_you_page_url;
1796
+		}
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 *  gets/returns URL for EE cancel_page
1802
+	 *
1803
+	 * @access    public
1804
+	 * @return    string
1805
+	 */
1806
+	public function cancel_page_url()
1807
+	{
1808
+		if (! $this->cancel_page_url) {
1809
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
+		}
1811
+		return $this->cancel_page_url;
1812
+	}
1813
+
1814
+
1815
+	/**
1816
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
+	 *
1818
+	 * @since 4.7.5
1819
+	 */
1820
+	protected function _reset_urls()
1821
+	{
1822
+		$this->reg_page_url = '';
1823
+		$this->txn_page_url = '';
1824
+		$this->cancel_page_url = '';
1825
+		$this->thank_you_page_url = '';
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Used to return what the optin value is set for the EE User Experience Program.
1831
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
+	 * on the main site only.
1833
+	 *
1834
+	 * @return bool
1835
+	 */
1836
+	protected function _get_main_ee_ueip_optin()
1837
+	{
1838
+		// if this is the main site then we can just bypass our direct query.
1839
+		if (is_main_site()) {
1840
+			return get_option(self::OPTION_NAME_UXIP, false);
1841
+		}
1842
+		// is this already cached for this request?  If so use it.
1843
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1844
+			return EE_Core_Config::$ee_ueip_option;
1845
+		}
1846
+		global $wpdb;
1847
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1848
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
+		$option = self::OPTION_NAME_UXIP;
1850
+		// set correct table for query
1851
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
+		// for the purpose of caching.
1857
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1858
+		if (false !== $pre) {
1859
+			EE_Core_Config::$ee_ueip_option = $pre;
1860
+			return EE_Core_Config::$ee_ueip_option;
1861
+		}
1862
+		$row = $wpdb->get_row(
1863
+			$wpdb->prepare(
1864
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
+				$option
1866
+			)
1867
+		);
1868
+		if (is_object($row)) {
1869
+			$value = $row->option_value;
1870
+		} else { // option does not exist so use default.
1871
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1872
+			return EE_Core_Config::$ee_ueip_option;
1873
+		}
1874
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1875
+		return EE_Core_Config::$ee_ueip_option;
1876
+	}
1877
+
1878
+
1879
+	/**
1880
+	 * Utility function for escaping the value of a property and returning.
1881
+	 *
1882
+	 * @param string $property property name (checks to see if exists).
1883
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1884
+	 * @throws \EE_Error
1885
+	 */
1886
+	public function get_pretty($property)
1887
+	{
1888
+		if ($property === self::OPTION_NAME_UXIP) {
1889
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1890
+		}
1891
+		return parent::get_pretty($property);
1892
+	}
1893
+
1894
+
1895
+	/**
1896
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1897
+	 * on the object.
1898
+	 *
1899
+	 * @return array
1900
+	 */
1901
+	public function __sleep()
1902
+	{
1903
+		// reset all url properties
1904
+		$this->_reset_urls();
1905
+		// return what to save to db
1906
+		return array_keys(get_object_vars($this));
1907
+	}
1908
+}
2292 1909
 
2293
-    /**
2294
-     * array of form names protected by ReCaptcha
2295
-     *
2296
-     * @var array $recaptcha_protected_forms
2297
-     */
2298
-    public $recaptcha_protected_forms;
1910
+/**
1911
+ * Config class for storing info on the Organization
1912
+ */
1913
+class EE_Organization_Config extends EE_Config_Base
1914
+{
2299 1915
 
2300
-    /**
2301
-     * ReCaptcha width
2302
-     *
2303
-     * @var int $recaptcha_width
2304
-     * @deprecated
2305
-     */
2306
-    public $recaptcha_width;
1916
+	/**
1917
+	 * @var string $name
1918
+	 * eg EE4.1
1919
+	 */
1920
+	public $name;
1921
+
1922
+	/**
1923
+	 * @var string $address_1
1924
+	 * eg 123 Onna Road
1925
+	 */
1926
+	public $address_1 = '';
1927
+
1928
+	/**
1929
+	 * @var string $address_2
1930
+	 * eg PO Box 123
1931
+	 */
1932
+	public $address_2 = '';
1933
+
1934
+	/**
1935
+	 * @var string $city
1936
+	 * eg Inna City
1937
+	 */
1938
+	public $city = '';
1939
+
1940
+	/**
1941
+	 * @var int $STA_ID
1942
+	 * eg 4
1943
+	 */
1944
+	public $STA_ID = 0;
1945
+
1946
+	/**
1947
+	 * @var string $CNT_ISO
1948
+	 * eg US
1949
+	 */
1950
+	public $CNT_ISO = '';
1951
+
1952
+	/**
1953
+	 * @var string $zip
1954
+	 * eg 12345  or V1A 2B3
1955
+	 */
1956
+	public $zip = '';
1957
+
1958
+	/**
1959
+	 * @var string $email
1960
+	 * eg [email protected]
1961
+	 */
1962
+	public $email;
1963
+
1964
+	/**
1965
+	 * @var string $phone
1966
+	 * eg. 111-111-1111
1967
+	 */
1968
+	public $phone = '';
1969
+
1970
+	/**
1971
+	 * @var string $vat
1972
+	 * VAT/Tax Number
1973
+	 */
1974
+	public $vat = '';
1975
+
1976
+	/**
1977
+	 * @var string $logo_url
1978
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1979
+	 */
1980
+	public $logo_url = '';
1981
+
1982
+	/**
1983
+	 * The below are all various properties for holding links to organization social network profiles
1984
+	 *
1985
+	 * @var string
1986
+	 */
1987
+	/**
1988
+	 * facebook (facebook.com/profile.name)
1989
+	 *
1990
+	 * @var string
1991
+	 */
1992
+	public $facebook = '';
1993
+
1994
+	/**
1995
+	 * twitter (twitter.com/twitter_handle)
1996
+	 *
1997
+	 * @var string
1998
+	 */
1999
+	public $twitter = '';
2000
+
2001
+	/**
2002
+	 * linkedin (linkedin.com/in/profile_name)
2003
+	 *
2004
+	 * @var string
2005
+	 */
2006
+	public $linkedin = '';
2007
+
2008
+	/**
2009
+	 * pinterest (www.pinterest.com/profile_name)
2010
+	 *
2011
+	 * @var string
2012
+	 */
2013
+	public $pinterest = '';
2014
+
2015
+	/**
2016
+	 * google+ (google.com/+profileName)
2017
+	 *
2018
+	 * @var string
2019
+	 */
2020
+	public $google = '';
2021
+
2022
+	/**
2023
+	 * instagram (instagram.com/handle)
2024
+	 *
2025
+	 * @var string
2026
+	 */
2027
+	public $instagram = '';
2028
+
2029
+
2030
+	/**
2031
+	 *    class constructor
2032
+	 *
2033
+	 * @access    public
2034
+	 */
2035
+	public function __construct()
2036
+	{
2037
+		// set default organization settings
2038
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2039
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2040
+		$this->email = get_bloginfo('admin_email');
2041
+	}
2042
+}
2307 2043
 
2308
-    /**
2309
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
-     *
2311
-     * @var boolean $track_invalid_checkout_access
2312
-     */
2313
-    protected $track_invalid_checkout_access = true;
2044
+/**
2045
+ * Class for defining what's in the EE_Config relating to currency
2046
+ */
2047
+class EE_Currency_Config extends EE_Config_Base
2048
+{
2314 2049
 
2315
-    /**
2316
-     * Whether or not to show the privacy policy consent checkbox
2317
-     *
2318
-     * @var bool
2319
-     */
2320
-    public $consent_checkbox_enabled;
2050
+	/**
2051
+	 * @var string $code
2052
+	 * eg 'US'
2053
+	 */
2054
+	public $code;
2055
+
2056
+	/**
2057
+	 * @var string $name
2058
+	 * eg 'Dollar'
2059
+	 */
2060
+	public $name;
2061
+
2062
+	/**
2063
+	 * plural name
2064
+	 *
2065
+	 * @var string $plural
2066
+	 * eg 'Dollars'
2067
+	 */
2068
+	public $plural;
2069
+
2070
+	/**
2071
+	 * currency sign
2072
+	 *
2073
+	 * @var string $sign
2074
+	 * eg '$'
2075
+	 */
2076
+	public $sign;
2077
+
2078
+	/**
2079
+	 * Whether the currency sign should come before the number or not
2080
+	 *
2081
+	 * @var boolean $sign_b4
2082
+	 */
2083
+	public $sign_b4;
2084
+
2085
+	/**
2086
+	 * How many digits should come after the decimal place
2087
+	 *
2088
+	 * @var int $dec_plc
2089
+	 */
2090
+	public $dec_plc;
2091
+
2092
+	/**
2093
+	 * Symbol to use for decimal mark
2094
+	 *
2095
+	 * @var string $dec_mrk
2096
+	 * eg '.'
2097
+	 */
2098
+	public $dec_mrk;
2099
+
2100
+	/**
2101
+	 * Symbol to use for thousands
2102
+	 *
2103
+	 * @var string $thsnds
2104
+	 * eg ','
2105
+	 */
2106
+	public $thsnds;
2107
+
2108
+
2109
+	/**
2110
+	 *    class constructor
2111
+	 *
2112
+	 * @access    public
2113
+	 * @param string $CNT_ISO
2114
+	 * @throws \EE_Error
2115
+	 */
2116
+	public function __construct($CNT_ISO = '')
2117
+	{
2118
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2119
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2120
+		// get country code from organization settings or use default
2121
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2122
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2123
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2124
+			: '';
2125
+		// but override if requested
2126
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2127
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2128
+		if (! empty($CNT_ISO)
2129
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2130
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2131
+		) {
2132
+			// retrieve the country settings from the db, just in case they have been customized
2133
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2134
+			if ($country instanceof EE_Country) {
2135
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2136
+				$this->name = $country->currency_name_single();    // Dollar
2137
+				$this->plural = $country->currency_name_plural();    // Dollars
2138
+				$this->sign = $country->currency_sign();            // currency sign: $
2139
+				$this->sign_b4 = $country->currency_sign_before(
2140
+				);        // currency sign before or after: $TRUE  or  FALSE$
2141
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2142
+				$this->dec_mrk = $country->currency_decimal_mark(
2143
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2144
+				$this->thsnds = $country->currency_thousands_separator(
2145
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2146
+			}
2147
+		}
2148
+		// fallback to hardcoded defaults, in case the above failed
2149
+		if (empty($this->code)) {
2150
+			// set default currency settings
2151
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2152
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2153
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2154
+			$this->sign = '$';    // currency sign: $
2155
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2156
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2157
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2158
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
+		}
2160
+	}
2161
+}
2321 2162
 
2322
-    /**
2323
-     * Label text to show on the checkbox
2324
-     *
2325
-     * @var string
2326
-     */
2327
-    public $consent_checkbox_label_text;
2163
+/**
2164
+ * Class for defining what's in the EE_Config relating to registration settings
2165
+ */
2166
+class EE_Registration_Config extends EE_Config_Base
2167
+{
2328 2168
 
2329
-    /*
2169
+	/**
2170
+	 * Default registration status
2171
+	 *
2172
+	 * @var string $default_STS_ID
2173
+	 * eg 'RPP'
2174
+	 */
2175
+	public $default_STS_ID;
2176
+
2177
+	/**
2178
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2179
+	 * registrations)
2180
+	 *
2181
+	 * @var int
2182
+	 */
2183
+	public $default_maximum_number_of_tickets;
2184
+
2185
+	/**
2186
+	 * level of validation to apply to email addresses
2187
+	 *
2188
+	 * @var string $email_validation_level
2189
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2190
+	 */
2191
+	public $email_validation_level;
2192
+
2193
+	/**
2194
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2195
+	 *
2196
+	 * @var boolean $show_pending_payment_options
2197
+	 */
2198
+	public $show_pending_payment_options;
2199
+
2200
+	/**
2201
+	 * Whether to skip the registration confirmation page
2202
+	 *
2203
+	 * @var boolean $skip_reg_confirmation
2204
+	 */
2205
+	public $skip_reg_confirmation;
2206
+
2207
+	/**
2208
+	 * an array of SPCO reg steps where:
2209
+	 *        the keys denotes the reg step order
2210
+	 *        each element consists of an array with the following elements:
2211
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2212
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2213
+	 *            "slug" => the URL param used to trigger the reg step
2214
+	 *
2215
+	 * @var array $reg_steps
2216
+	 */
2217
+	public $reg_steps;
2218
+
2219
+	/**
2220
+	 * Whether registration confirmation should be the last page of SPCO
2221
+	 *
2222
+	 * @var boolean $reg_confirmation_last
2223
+	 */
2224
+	public $reg_confirmation_last;
2225
+
2226
+	/**
2227
+	 * Whether or not to enable the EE Bot Trap
2228
+	 *
2229
+	 * @var boolean $use_bot_trap
2230
+	 */
2231
+	public $use_bot_trap;
2232
+
2233
+	/**
2234
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2235
+	 *
2236
+	 * @var boolean $use_encryption
2237
+	 */
2238
+	public $use_encryption;
2239
+
2240
+	/**
2241
+	 * Whether or not to use ReCaptcha
2242
+	 *
2243
+	 * @var boolean $use_captcha
2244
+	 */
2245
+	public $use_captcha;
2246
+
2247
+	/**
2248
+	 * ReCaptcha Theme
2249
+	 *
2250
+	 * @var string $recaptcha_theme
2251
+	 *    options: 'dark', 'light', 'invisible'
2252
+	 */
2253
+	public $recaptcha_theme;
2254
+
2255
+	/**
2256
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2257
+	 *
2258
+	 * @var string $recaptcha_badge
2259
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2260
+	 */
2261
+	public $recaptcha_badge;
2262
+
2263
+	/**
2264
+	 * ReCaptcha Type
2265
+	 *
2266
+	 * @var string $recaptcha_type
2267
+	 *    options: 'audio', 'image'
2268
+	 */
2269
+	public $recaptcha_type;
2270
+
2271
+	/**
2272
+	 * ReCaptcha language
2273
+	 *
2274
+	 * @var string $recaptcha_language
2275
+	 * eg 'en'
2276
+	 */
2277
+	public $recaptcha_language;
2278
+
2279
+	/**
2280
+	 * ReCaptcha public key
2281
+	 *
2282
+	 * @var string $recaptcha_publickey
2283
+	 */
2284
+	public $recaptcha_publickey;
2285
+
2286
+	/**
2287
+	 * ReCaptcha private key
2288
+	 *
2289
+	 * @var string $recaptcha_privatekey
2290
+	 */
2291
+	public $recaptcha_privatekey;
2292
+
2293
+	/**
2294
+	 * array of form names protected by ReCaptcha
2295
+	 *
2296
+	 * @var array $recaptcha_protected_forms
2297
+	 */
2298
+	public $recaptcha_protected_forms;
2299
+
2300
+	/**
2301
+	 * ReCaptcha width
2302
+	 *
2303
+	 * @var int $recaptcha_width
2304
+	 * @deprecated
2305
+	 */
2306
+	public $recaptcha_width;
2307
+
2308
+	/**
2309
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2310
+	 *
2311
+	 * @var boolean $track_invalid_checkout_access
2312
+	 */
2313
+	protected $track_invalid_checkout_access = true;
2314
+
2315
+	/**
2316
+	 * Whether or not to show the privacy policy consent checkbox
2317
+	 *
2318
+	 * @var bool
2319
+	 */
2320
+	public $consent_checkbox_enabled;
2321
+
2322
+	/**
2323
+	 * Label text to show on the checkbox
2324
+	 *
2325
+	 * @var string
2326
+	 */
2327
+	public $consent_checkbox_label_text;
2328
+
2329
+	/*
2330 2330
      * String describing how long to keep payment logs. Passed into DateTime constructor
2331 2331
      * @var string
2332 2332
      */
2333
-    public $gateway_log_lifespan = '1 week';
2334
-
2335
-
2336
-    /**
2337
-     *    class constructor
2338
-     *
2339
-     * @access    public
2340
-     */
2341
-    public function __construct()
2342
-    {
2343
-        // set default registration settings
2344
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
-        $this->email_validation_level = 'wp_default';
2346
-        $this->show_pending_payment_options = true;
2347
-        $this->skip_reg_confirmation = true;
2348
-        $this->reg_steps = array();
2349
-        $this->reg_confirmation_last = false;
2350
-        $this->use_bot_trap = true;
2351
-        $this->use_encryption = true;
2352
-        $this->use_captcha = false;
2353
-        $this->recaptcha_theme = 'light';
2354
-        $this->recaptcha_badge = 'bottomleft';
2355
-        $this->recaptcha_type = 'image';
2356
-        $this->recaptcha_language = 'en';
2357
-        $this->recaptcha_publickey = null;
2358
-        $this->recaptcha_privatekey = null;
2359
-        $this->recaptcha_protected_forms = array();
2360
-        $this->recaptcha_width = 500;
2361
-        $this->default_maximum_number_of_tickets = 10;
2362
-        $this->consent_checkbox_enabled = false;
2363
-        $this->consent_checkbox_label_text = '';
2364
-        $this->gateway_log_lifespan = '7 days';
2365
-    }
2366
-
2367
-
2368
-    /**
2369
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
-     *
2371
-     * @since 4.8.8.rc.019
2372
-     */
2373
-    public function do_hooks()
2374
-    {
2375
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
-    }
2379
-
2380
-
2381
-    /**
2382
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
-     */
2385
-    public function set_default_reg_status_on_EEM_Event()
2386
-    {
2387
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
-    }
2389
-
2390
-
2391
-    /**
2392
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
-     * for Events matches the config setting for default_maximum_number_of_tickets
2394
-     */
2395
-    public function set_default_max_ticket_on_EEM_Event()
2396
-    {
2397
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
-     * constructed because that happens before we can get the privacy policy page's permalink.
2404
-     *
2405
-     * @throws InvalidArgumentException
2406
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
-     */
2409
-    public function setDefaultCheckboxLabelText()
2410
-    {
2411
-        if ($this->getConsentCheckboxLabelText() === null
2412
-            || $this->getConsentCheckboxLabelText() === '') {
2413
-            $opening_a_tag = '';
2414
-            $closing_a_tag = '';
2415
-            if (function_exists('get_privacy_policy_url')) {
2416
-                $privacy_page_url = get_privacy_policy_url();
2417
-                if (! empty($privacy_page_url)) {
2418
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
-                    $closing_a_tag = '</a>';
2420
-                }
2421
-            }
2422
-            $loader = LoaderFactory::getLoader();
2423
-            $org_config = $loader->getShared('EE_Organization_Config');
2424
-            /**
2425
-             * @var $org_config EE_Organization_Config
2426
-             */
2427
-
2428
-            $this->setConsentCheckboxLabelText(
2429
-                sprintf(
2430
-                    esc_html__(
2431
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
-                        'event_espresso'
2433
-                    ),
2434
-                    $org_config->name,
2435
-                    $opening_a_tag,
2436
-                    $closing_a_tag
2437
-                )
2438
-            );
2439
-        }
2440
-    }
2441
-
2442
-
2443
-    /**
2444
-     * @return boolean
2445
-     */
2446
-    public function track_invalid_checkout_access()
2447
-    {
2448
-        return $this->track_invalid_checkout_access;
2449
-    }
2450
-
2451
-
2452
-    /**
2453
-     * @param boolean $track_invalid_checkout_access
2454
-     */
2455
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
-    {
2457
-        $this->track_invalid_checkout_access = filter_var(
2458
-            $track_invalid_checkout_access,
2459
-            FILTER_VALIDATE_BOOLEAN
2460
-        );
2461
-    }
2462
-
2463
-
2464
-    /**
2465
-     * Gets the options to make availalbe for the gateway log lifespan
2466
-     * @return array
2467
-     */
2468
-    public function gatewayLogLifespanOptions()
2469
-    {
2470
-        return (array) apply_filters(
2471
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
-            array(
2473
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2475
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2476
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2477
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2478
-            )
2479
-        );
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * @return bool
2485
-     */
2486
-    public function isConsentCheckboxEnabled()
2487
-    {
2488
-        return $this->consent_checkbox_enabled;
2489
-    }
2490
-
2491
-
2492
-    /**
2493
-     * @param bool $consent_checkbox_enabled
2494
-     */
2495
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
-    {
2497
-        $this->consent_checkbox_enabled = filter_var(
2498
-            $consent_checkbox_enabled,
2499
-            FILTER_VALIDATE_BOOLEAN
2500
-        );
2501
-    }
2502
-
2503
-
2504
-    /**
2505
-     * @return string
2506
-     */
2507
-    public function getConsentCheckboxLabelText()
2508
-    {
2509
-        return $this->consent_checkbox_label_text;
2510
-    }
2511
-
2512
-
2513
-    /**
2514
-     * @param string $consent_checkbox_label_text
2515
-     */
2516
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
-    {
2518
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
-    }
2333
+	public $gateway_log_lifespan = '1 week';
2334
+
2335
+
2336
+	/**
2337
+	 *    class constructor
2338
+	 *
2339
+	 * @access    public
2340
+	 */
2341
+	public function __construct()
2342
+	{
2343
+		// set default registration settings
2344
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2345
+		$this->email_validation_level = 'wp_default';
2346
+		$this->show_pending_payment_options = true;
2347
+		$this->skip_reg_confirmation = true;
2348
+		$this->reg_steps = array();
2349
+		$this->reg_confirmation_last = false;
2350
+		$this->use_bot_trap = true;
2351
+		$this->use_encryption = true;
2352
+		$this->use_captcha = false;
2353
+		$this->recaptcha_theme = 'light';
2354
+		$this->recaptcha_badge = 'bottomleft';
2355
+		$this->recaptcha_type = 'image';
2356
+		$this->recaptcha_language = 'en';
2357
+		$this->recaptcha_publickey = null;
2358
+		$this->recaptcha_privatekey = null;
2359
+		$this->recaptcha_protected_forms = array();
2360
+		$this->recaptcha_width = 500;
2361
+		$this->default_maximum_number_of_tickets = 10;
2362
+		$this->consent_checkbox_enabled = false;
2363
+		$this->consent_checkbox_label_text = '';
2364
+		$this->gateway_log_lifespan = '7 days';
2365
+	}
2366
+
2367
+
2368
+	/**
2369
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2370
+	 *
2371
+	 * @since 4.8.8.rc.019
2372
+	 */
2373
+	public function do_hooks()
2374
+	{
2375
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2376
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2377
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2378
+	}
2379
+
2380
+
2381
+	/**
2382
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2383
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2384
+	 */
2385
+	public function set_default_reg_status_on_EEM_Event()
2386
+	{
2387
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2388
+	}
2389
+
2390
+
2391
+	/**
2392
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2393
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2394
+	 */
2395
+	public function set_default_max_ticket_on_EEM_Event()
2396
+	{
2397
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2403
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2404
+	 *
2405
+	 * @throws InvalidArgumentException
2406
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2407
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2408
+	 */
2409
+	public function setDefaultCheckboxLabelText()
2410
+	{
2411
+		if ($this->getConsentCheckboxLabelText() === null
2412
+			|| $this->getConsentCheckboxLabelText() === '') {
2413
+			$opening_a_tag = '';
2414
+			$closing_a_tag = '';
2415
+			if (function_exists('get_privacy_policy_url')) {
2416
+				$privacy_page_url = get_privacy_policy_url();
2417
+				if (! empty($privacy_page_url)) {
2418
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2419
+					$closing_a_tag = '</a>';
2420
+				}
2421
+			}
2422
+			$loader = LoaderFactory::getLoader();
2423
+			$org_config = $loader->getShared('EE_Organization_Config');
2424
+			/**
2425
+			 * @var $org_config EE_Organization_Config
2426
+			 */
2427
+
2428
+			$this->setConsentCheckboxLabelText(
2429
+				sprintf(
2430
+					esc_html__(
2431
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2432
+						'event_espresso'
2433
+					),
2434
+					$org_config->name,
2435
+					$opening_a_tag,
2436
+					$closing_a_tag
2437
+				)
2438
+			);
2439
+		}
2440
+	}
2441
+
2442
+
2443
+	/**
2444
+	 * @return boolean
2445
+	 */
2446
+	public function track_invalid_checkout_access()
2447
+	{
2448
+		return $this->track_invalid_checkout_access;
2449
+	}
2450
+
2451
+
2452
+	/**
2453
+	 * @param boolean $track_invalid_checkout_access
2454
+	 */
2455
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2456
+	{
2457
+		$this->track_invalid_checkout_access = filter_var(
2458
+			$track_invalid_checkout_access,
2459
+			FILTER_VALIDATE_BOOLEAN
2460
+		);
2461
+	}
2462
+
2463
+
2464
+	/**
2465
+	 * Gets the options to make availalbe for the gateway log lifespan
2466
+	 * @return array
2467
+	 */
2468
+	public function gatewayLogLifespanOptions()
2469
+	{
2470
+		return (array) apply_filters(
2471
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2472
+			array(
2473
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2474
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2475
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2476
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2477
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2478
+			)
2479
+		);
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * @return bool
2485
+	 */
2486
+	public function isConsentCheckboxEnabled()
2487
+	{
2488
+		return $this->consent_checkbox_enabled;
2489
+	}
2490
+
2491
+
2492
+	/**
2493
+	 * @param bool $consent_checkbox_enabled
2494
+	 */
2495
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2496
+	{
2497
+		$this->consent_checkbox_enabled = filter_var(
2498
+			$consent_checkbox_enabled,
2499
+			FILTER_VALIDATE_BOOLEAN
2500
+		);
2501
+	}
2502
+
2503
+
2504
+	/**
2505
+	 * @return string
2506
+	 */
2507
+	public function getConsentCheckboxLabelText()
2508
+	{
2509
+		return $this->consent_checkbox_label_text;
2510
+	}
2511
+
2512
+
2513
+	/**
2514
+	 * @param string $consent_checkbox_label_text
2515
+	 */
2516
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2517
+	{
2518
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2519
+	}
2520 2520
 }
2521 2521
 
2522 2522
 /**
@@ -2525,185 +2525,185 @@  discard block
 block discarded – undo
2525 2525
 class EE_Admin_Config extends EE_Config_Base
2526 2526
 {
2527 2527
 
2528
-    /**
2529
-     * @var boolean $useAdvancedEditor
2530
-     */
2531
-    private $useAdvancedEditor;
2532
-
2533
-    /**
2534
-     * @var boolean $use_personnel_manager
2535
-     */
2536
-    public $use_personnel_manager;
2537
-
2538
-    /**
2539
-     * @var boolean $use_dashboard_widget
2540
-     */
2541
-    public $use_dashboard_widget;
2542
-
2543
-    /**
2544
-     * @var int $events_in_dashboard
2545
-     */
2546
-    public $events_in_dashboard;
2547
-
2548
-    /**
2549
-     * @var boolean $use_event_timezones
2550
-     */
2551
-    public $use_event_timezones;
2552
-
2553
-    /**
2554
-     * @var boolean $use_full_logging
2555
-     */
2556
-    public $use_full_logging;
2557
-
2558
-    /**
2559
-     * @var string $log_file_name
2560
-     */
2561
-    public $log_file_name;
2562
-
2563
-    /**
2564
-     * @var string $debug_file_name
2565
-     */
2566
-    public $debug_file_name;
2567
-
2568
-    /**
2569
-     * @var boolean $use_remote_logging
2570
-     */
2571
-    public $use_remote_logging;
2572
-
2573
-    /**
2574
-     * @var string $remote_logging_url
2575
-     */
2576
-    public $remote_logging_url;
2577
-
2578
-    /**
2579
-     * @var boolean $show_reg_footer
2580
-     */
2581
-    public $show_reg_footer;
2582
-
2583
-    /**
2584
-     * @var string $affiliate_id
2585
-     */
2586
-    public $affiliate_id;
2587
-
2588
-    /**
2589
-     * help tours on or off (global setting)
2590
-     *
2591
-     * @var boolean
2592
-     */
2593
-    public $help_tour_activation;
2594
-
2595
-    /**
2596
-     * adds extra layer of encoding to session data to prevent serialization errors
2597
-     * but is incompatible with some server configuration errors
2598
-     * if you get "500 internal server errors" during registration, try turning this on
2599
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2600
-     *
2601
-     * @var boolean $encode_session_data
2602
-     */
2603
-    private $encode_session_data = false;
2604
-
2605
-
2606
-    /**
2607
-     *    class constructor
2608
-     *
2609
-     * @access    public
2610
-     */
2611
-    public function __construct()
2612
-    {
2613
-        // set default general admin settings
2614
-        $this->useAdvancedEditor = false;
2615
-        $this->use_personnel_manager = true;
2616
-        $this->use_dashboard_widget = true;
2617
-        $this->events_in_dashboard = 30;
2618
-        $this->use_event_timezones = false;
2619
-        $this->use_full_logging = false;
2620
-        $this->use_remote_logging = false;
2621
-        $this->remote_logging_url = null;
2622
-        $this->show_reg_footer = apply_filters(
2623
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2624
-            false
2625
-        );
2626
-        $this->affiliate_id = 'default';
2627
-        $this->help_tour_activation = true;
2628
-        $this->encode_session_data = false;
2629
-    }
2630
-
2631
-
2632
-    /**
2633
-     * @param bool $reset
2634
-     * @return string
2635
-     */
2636
-    public function log_file_name($reset = false)
2637
-    {
2638
-        if (empty($this->log_file_name) || $reset) {
2639
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2640
-            EE_Config::instance()->update_espresso_config(false, false);
2641
-        }
2642
-        return $this->log_file_name;
2643
-    }
2644
-
2645
-
2646
-    /**
2647
-     * @param bool $reset
2648
-     * @return string
2649
-     */
2650
-    public function debug_file_name($reset = false)
2651
-    {
2652
-        if (empty($this->debug_file_name) || $reset) {
2653
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2654
-            EE_Config::instance()->update_espresso_config(false, false);
2655
-        }
2656
-        return $this->debug_file_name;
2657
-    }
2658
-
2659
-
2660
-    /**
2661
-     * @return string
2662
-     */
2663
-    public function affiliate_id()
2664
-    {
2665
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2666
-    }
2667
-
2668
-
2669
-    /**
2670
-     * @return boolean
2671
-     */
2672
-    public function encode_session_data()
2673
-    {
2674
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2675
-    }
2676
-
2677
-
2678
-    /**
2679
-     * @param boolean $encode_session_data
2680
-     */
2681
-    public function set_encode_session_data($encode_session_data)
2682
-    {
2683
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2684
-    }
2685
-
2686
-    /**
2687
-     * @return boolean
2688
-     */
2689
-    public function useAdvancedEditor()
2690
-    {
2691
-        return $this->useAdvancedEditor;
2692
-    }
2693
-
2694
-    /**
2695
-     * @param boolean $use_advanced_editor
2696
-     */
2697
-    public function setUseAdvancedEditor($use_advanced_editor = true)
2698
-    {
2699
-        $this->useAdvancedEditor = filter_var(
2700
-            apply_filters(
2701
-                'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2702
-                $use_advanced_editor
2703
-            ),
2704
-            FILTER_VALIDATE_BOOLEAN
2705
-        );
2706
-    }
2528
+	/**
2529
+	 * @var boolean $useAdvancedEditor
2530
+	 */
2531
+	private $useAdvancedEditor;
2532
+
2533
+	/**
2534
+	 * @var boolean $use_personnel_manager
2535
+	 */
2536
+	public $use_personnel_manager;
2537
+
2538
+	/**
2539
+	 * @var boolean $use_dashboard_widget
2540
+	 */
2541
+	public $use_dashboard_widget;
2542
+
2543
+	/**
2544
+	 * @var int $events_in_dashboard
2545
+	 */
2546
+	public $events_in_dashboard;
2547
+
2548
+	/**
2549
+	 * @var boolean $use_event_timezones
2550
+	 */
2551
+	public $use_event_timezones;
2552
+
2553
+	/**
2554
+	 * @var boolean $use_full_logging
2555
+	 */
2556
+	public $use_full_logging;
2557
+
2558
+	/**
2559
+	 * @var string $log_file_name
2560
+	 */
2561
+	public $log_file_name;
2562
+
2563
+	/**
2564
+	 * @var string $debug_file_name
2565
+	 */
2566
+	public $debug_file_name;
2567
+
2568
+	/**
2569
+	 * @var boolean $use_remote_logging
2570
+	 */
2571
+	public $use_remote_logging;
2572
+
2573
+	/**
2574
+	 * @var string $remote_logging_url
2575
+	 */
2576
+	public $remote_logging_url;
2577
+
2578
+	/**
2579
+	 * @var boolean $show_reg_footer
2580
+	 */
2581
+	public $show_reg_footer;
2582
+
2583
+	/**
2584
+	 * @var string $affiliate_id
2585
+	 */
2586
+	public $affiliate_id;
2587
+
2588
+	/**
2589
+	 * help tours on or off (global setting)
2590
+	 *
2591
+	 * @var boolean
2592
+	 */
2593
+	public $help_tour_activation;
2594
+
2595
+	/**
2596
+	 * adds extra layer of encoding to session data to prevent serialization errors
2597
+	 * but is incompatible with some server configuration errors
2598
+	 * if you get "500 internal server errors" during registration, try turning this on
2599
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2600
+	 *
2601
+	 * @var boolean $encode_session_data
2602
+	 */
2603
+	private $encode_session_data = false;
2604
+
2605
+
2606
+	/**
2607
+	 *    class constructor
2608
+	 *
2609
+	 * @access    public
2610
+	 */
2611
+	public function __construct()
2612
+	{
2613
+		// set default general admin settings
2614
+		$this->useAdvancedEditor = false;
2615
+		$this->use_personnel_manager = true;
2616
+		$this->use_dashboard_widget = true;
2617
+		$this->events_in_dashboard = 30;
2618
+		$this->use_event_timezones = false;
2619
+		$this->use_full_logging = false;
2620
+		$this->use_remote_logging = false;
2621
+		$this->remote_logging_url = null;
2622
+		$this->show_reg_footer = apply_filters(
2623
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2624
+			false
2625
+		);
2626
+		$this->affiliate_id = 'default';
2627
+		$this->help_tour_activation = true;
2628
+		$this->encode_session_data = false;
2629
+	}
2630
+
2631
+
2632
+	/**
2633
+	 * @param bool $reset
2634
+	 * @return string
2635
+	 */
2636
+	public function log_file_name($reset = false)
2637
+	{
2638
+		if (empty($this->log_file_name) || $reset) {
2639
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2640
+			EE_Config::instance()->update_espresso_config(false, false);
2641
+		}
2642
+		return $this->log_file_name;
2643
+	}
2644
+
2645
+
2646
+	/**
2647
+	 * @param bool $reset
2648
+	 * @return string
2649
+	 */
2650
+	public function debug_file_name($reset = false)
2651
+	{
2652
+		if (empty($this->debug_file_name) || $reset) {
2653
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2654
+			EE_Config::instance()->update_espresso_config(false, false);
2655
+		}
2656
+		return $this->debug_file_name;
2657
+	}
2658
+
2659
+
2660
+	/**
2661
+	 * @return string
2662
+	 */
2663
+	public function affiliate_id()
2664
+	{
2665
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2666
+	}
2667
+
2668
+
2669
+	/**
2670
+	 * @return boolean
2671
+	 */
2672
+	public function encode_session_data()
2673
+	{
2674
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2675
+	}
2676
+
2677
+
2678
+	/**
2679
+	 * @param boolean $encode_session_data
2680
+	 */
2681
+	public function set_encode_session_data($encode_session_data)
2682
+	{
2683
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2684
+	}
2685
+
2686
+	/**
2687
+	 * @return boolean
2688
+	 */
2689
+	public function useAdvancedEditor()
2690
+	{
2691
+		return $this->useAdvancedEditor;
2692
+	}
2693
+
2694
+	/**
2695
+	 * @param boolean $use_advanced_editor
2696
+	 */
2697
+	public function setUseAdvancedEditor($use_advanced_editor = true)
2698
+	{
2699
+		$this->useAdvancedEditor = filter_var(
2700
+			apply_filters(
2701
+				'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2702
+				$use_advanced_editor
2703
+			),
2704
+			FILTER_VALIDATE_BOOLEAN
2705
+		);
2706
+	}
2707 2707
 }
2708 2708
 
2709 2709
 /**
@@ -2712,70 +2712,70 @@  discard block
 block discarded – undo
2712 2712
 class EE_Template_Config extends EE_Config_Base
2713 2713
 {
2714 2714
 
2715
-    /**
2716
-     * @var boolean $enable_default_style
2717
-     */
2718
-    public $enable_default_style;
2719
-
2720
-    /**
2721
-     * @var string $custom_style_sheet
2722
-     */
2723
-    public $custom_style_sheet;
2724
-
2725
-    /**
2726
-     * @var boolean $display_address_in_regform
2727
-     */
2728
-    public $display_address_in_regform;
2729
-
2730
-    /**
2731
-     * @var int $display_description_on_multi_reg_page
2732
-     */
2733
-    public $display_description_on_multi_reg_page;
2734
-
2735
-    /**
2736
-     * @var boolean $use_custom_templates
2737
-     */
2738
-    public $use_custom_templates;
2739
-
2740
-    /**
2741
-     * @var string $current_espresso_theme
2742
-     */
2743
-    public $current_espresso_theme;
2744
-
2745
-    /**
2746
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2747
-     */
2748
-    public $EED_Ticket_Selector;
2749
-
2750
-    /**
2751
-     * @var EE_Event_Single_Config $EED_Event_Single
2752
-     */
2753
-    public $EED_Event_Single;
2754
-
2755
-    /**
2756
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2757
-     */
2758
-    public $EED_Events_Archive;
2759
-
2760
-
2761
-    /**
2762
-     *    class constructor
2763
-     *
2764
-     * @access    public
2765
-     */
2766
-    public function __construct()
2767
-    {
2768
-        // set default template settings
2769
-        $this->enable_default_style = true;
2770
-        $this->custom_style_sheet = null;
2771
-        $this->display_address_in_regform = true;
2772
-        $this->display_description_on_multi_reg_page = false;
2773
-        $this->use_custom_templates = false;
2774
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2775
-        $this->EED_Event_Single = null;
2776
-        $this->EED_Events_Archive = null;
2777
-        $this->EED_Ticket_Selector = null;
2778
-    }
2715
+	/**
2716
+	 * @var boolean $enable_default_style
2717
+	 */
2718
+	public $enable_default_style;
2719
+
2720
+	/**
2721
+	 * @var string $custom_style_sheet
2722
+	 */
2723
+	public $custom_style_sheet;
2724
+
2725
+	/**
2726
+	 * @var boolean $display_address_in_regform
2727
+	 */
2728
+	public $display_address_in_regform;
2729
+
2730
+	/**
2731
+	 * @var int $display_description_on_multi_reg_page
2732
+	 */
2733
+	public $display_description_on_multi_reg_page;
2734
+
2735
+	/**
2736
+	 * @var boolean $use_custom_templates
2737
+	 */
2738
+	public $use_custom_templates;
2739
+
2740
+	/**
2741
+	 * @var string $current_espresso_theme
2742
+	 */
2743
+	public $current_espresso_theme;
2744
+
2745
+	/**
2746
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2747
+	 */
2748
+	public $EED_Ticket_Selector;
2749
+
2750
+	/**
2751
+	 * @var EE_Event_Single_Config $EED_Event_Single
2752
+	 */
2753
+	public $EED_Event_Single;
2754
+
2755
+	/**
2756
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2757
+	 */
2758
+	public $EED_Events_Archive;
2759
+
2760
+
2761
+	/**
2762
+	 *    class constructor
2763
+	 *
2764
+	 * @access    public
2765
+	 */
2766
+	public function __construct()
2767
+	{
2768
+		// set default template settings
2769
+		$this->enable_default_style = true;
2770
+		$this->custom_style_sheet = null;
2771
+		$this->display_address_in_regform = true;
2772
+		$this->display_description_on_multi_reg_page = false;
2773
+		$this->use_custom_templates = false;
2774
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2775
+		$this->EED_Event_Single = null;
2776
+		$this->EED_Events_Archive = null;
2777
+		$this->EED_Ticket_Selector = null;
2778
+	}
2779 2779
 }
2780 2780
 
2781 2781
 /**
@@ -2784,114 +2784,114 @@  discard block
 block discarded – undo
2784 2784
 class EE_Map_Config extends EE_Config_Base
2785 2785
 {
2786 2786
 
2787
-    /**
2788
-     * @var boolean $use_google_maps
2789
-     */
2790
-    public $use_google_maps;
2791
-
2792
-    /**
2793
-     * @var string $api_key
2794
-     */
2795
-    public $google_map_api_key;
2796
-
2797
-    /**
2798
-     * @var int $event_details_map_width
2799
-     */
2800
-    public $event_details_map_width;
2801
-
2802
-    /**
2803
-     * @var int $event_details_map_height
2804
-     */
2805
-    public $event_details_map_height;
2806
-
2807
-    /**
2808
-     * @var int $event_details_map_zoom
2809
-     */
2810
-    public $event_details_map_zoom;
2811
-
2812
-    /**
2813
-     * @var boolean $event_details_display_nav
2814
-     */
2815
-    public $event_details_display_nav;
2816
-
2817
-    /**
2818
-     * @var boolean $event_details_nav_size
2819
-     */
2820
-    public $event_details_nav_size;
2821
-
2822
-    /**
2823
-     * @var string $event_details_control_type
2824
-     */
2825
-    public $event_details_control_type;
2826
-
2827
-    /**
2828
-     * @var string $event_details_map_align
2829
-     */
2830
-    public $event_details_map_align;
2831
-
2832
-    /**
2833
-     * @var int $event_list_map_width
2834
-     */
2835
-    public $event_list_map_width;
2836
-
2837
-    /**
2838
-     * @var int $event_list_map_height
2839
-     */
2840
-    public $event_list_map_height;
2841
-
2842
-    /**
2843
-     * @var int $event_list_map_zoom
2844
-     */
2845
-    public $event_list_map_zoom;
2846
-
2847
-    /**
2848
-     * @var boolean $event_list_display_nav
2849
-     */
2850
-    public $event_list_display_nav;
2851
-
2852
-    /**
2853
-     * @var boolean $event_list_nav_size
2854
-     */
2855
-    public $event_list_nav_size;
2856
-
2857
-    /**
2858
-     * @var string $event_list_control_type
2859
-     */
2860
-    public $event_list_control_type;
2861
-
2862
-    /**
2863
-     * @var string $event_list_map_align
2864
-     */
2865
-    public $event_list_map_align;
2866
-
2867
-
2868
-    /**
2869
-     *    class constructor
2870
-     *
2871
-     * @access    public
2872
-     */
2873
-    public function __construct()
2874
-    {
2875
-        // set default map settings
2876
-        $this->use_google_maps = true;
2877
-        $this->google_map_api_key = '';
2878
-        // for event details pages (reg page)
2879
-        $this->event_details_map_width = 585;            // ee_map_width_single
2880
-        $this->event_details_map_height = 362;            // ee_map_height_single
2881
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2882
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2883
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2884
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2885
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2886
-        // for event list pages
2887
-        $this->event_list_map_width = 300;            // ee_map_width
2888
-        $this->event_list_map_height = 185;        // ee_map_height
2889
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2890
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2891
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2892
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2893
-        $this->event_list_map_align = 'center';            // ee_map_align
2894
-    }
2787
+	/**
2788
+	 * @var boolean $use_google_maps
2789
+	 */
2790
+	public $use_google_maps;
2791
+
2792
+	/**
2793
+	 * @var string $api_key
2794
+	 */
2795
+	public $google_map_api_key;
2796
+
2797
+	/**
2798
+	 * @var int $event_details_map_width
2799
+	 */
2800
+	public $event_details_map_width;
2801
+
2802
+	/**
2803
+	 * @var int $event_details_map_height
2804
+	 */
2805
+	public $event_details_map_height;
2806
+
2807
+	/**
2808
+	 * @var int $event_details_map_zoom
2809
+	 */
2810
+	public $event_details_map_zoom;
2811
+
2812
+	/**
2813
+	 * @var boolean $event_details_display_nav
2814
+	 */
2815
+	public $event_details_display_nav;
2816
+
2817
+	/**
2818
+	 * @var boolean $event_details_nav_size
2819
+	 */
2820
+	public $event_details_nav_size;
2821
+
2822
+	/**
2823
+	 * @var string $event_details_control_type
2824
+	 */
2825
+	public $event_details_control_type;
2826
+
2827
+	/**
2828
+	 * @var string $event_details_map_align
2829
+	 */
2830
+	public $event_details_map_align;
2831
+
2832
+	/**
2833
+	 * @var int $event_list_map_width
2834
+	 */
2835
+	public $event_list_map_width;
2836
+
2837
+	/**
2838
+	 * @var int $event_list_map_height
2839
+	 */
2840
+	public $event_list_map_height;
2841
+
2842
+	/**
2843
+	 * @var int $event_list_map_zoom
2844
+	 */
2845
+	public $event_list_map_zoom;
2846
+
2847
+	/**
2848
+	 * @var boolean $event_list_display_nav
2849
+	 */
2850
+	public $event_list_display_nav;
2851
+
2852
+	/**
2853
+	 * @var boolean $event_list_nav_size
2854
+	 */
2855
+	public $event_list_nav_size;
2856
+
2857
+	/**
2858
+	 * @var string $event_list_control_type
2859
+	 */
2860
+	public $event_list_control_type;
2861
+
2862
+	/**
2863
+	 * @var string $event_list_map_align
2864
+	 */
2865
+	public $event_list_map_align;
2866
+
2867
+
2868
+	/**
2869
+	 *    class constructor
2870
+	 *
2871
+	 * @access    public
2872
+	 */
2873
+	public function __construct()
2874
+	{
2875
+		// set default map settings
2876
+		$this->use_google_maps = true;
2877
+		$this->google_map_api_key = '';
2878
+		// for event details pages (reg page)
2879
+		$this->event_details_map_width = 585;            // ee_map_width_single
2880
+		$this->event_details_map_height = 362;            // ee_map_height_single
2881
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2882
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2883
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2884
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2885
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2886
+		// for event list pages
2887
+		$this->event_list_map_width = 300;            // ee_map_width
2888
+		$this->event_list_map_height = 185;        // ee_map_height
2889
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2890
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2891
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2892
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2893
+		$this->event_list_map_align = 'center';            // ee_map_align
2894
+	}
2895 2895
 }
2896 2896
 
2897 2897
 /**
@@ -2900,46 +2900,46 @@  discard block
 block discarded – undo
2900 2900
 class EE_Events_Archive_Config extends EE_Config_Base
2901 2901
 {
2902 2902
 
2903
-    public $display_status_banner;
2903
+	public $display_status_banner;
2904 2904
 
2905
-    public $display_description;
2905
+	public $display_description;
2906 2906
 
2907
-    public $display_ticket_selector;
2907
+	public $display_ticket_selector;
2908 2908
 
2909
-    public $display_datetimes;
2909
+	public $display_datetimes;
2910 2910
 
2911
-    public $display_venue;
2911
+	public $display_venue;
2912 2912
 
2913
-    public $display_expired_events;
2913
+	public $display_expired_events;
2914 2914
 
2915
-    public $use_sortable_display_order;
2915
+	public $use_sortable_display_order;
2916 2916
 
2917
-    public $display_order_tickets;
2917
+	public $display_order_tickets;
2918 2918
 
2919
-    public $display_order_datetimes;
2919
+	public $display_order_datetimes;
2920 2920
 
2921
-    public $display_order_event;
2921
+	public $display_order_event;
2922 2922
 
2923
-    public $display_order_venue;
2923
+	public $display_order_venue;
2924 2924
 
2925 2925
 
2926
-    /**
2927
-     *    class constructor
2928
-     */
2929
-    public function __construct()
2930
-    {
2931
-        $this->display_status_banner = 0;
2932
-        $this->display_description = 1;
2933
-        $this->display_ticket_selector = 0;
2934
-        $this->display_datetimes = 1;
2935
-        $this->display_venue = 0;
2936
-        $this->display_expired_events = 0;
2937
-        $this->use_sortable_display_order = false;
2938
-        $this->display_order_tickets = 100;
2939
-        $this->display_order_datetimes = 110;
2940
-        $this->display_order_event = 120;
2941
-        $this->display_order_venue = 130;
2942
-    }
2926
+	/**
2927
+	 *    class constructor
2928
+	 */
2929
+	public function __construct()
2930
+	{
2931
+		$this->display_status_banner = 0;
2932
+		$this->display_description = 1;
2933
+		$this->display_ticket_selector = 0;
2934
+		$this->display_datetimes = 1;
2935
+		$this->display_venue = 0;
2936
+		$this->display_expired_events = 0;
2937
+		$this->use_sortable_display_order = false;
2938
+		$this->display_order_tickets = 100;
2939
+		$this->display_order_datetimes = 110;
2940
+		$this->display_order_event = 120;
2941
+		$this->display_order_venue = 130;
2942
+	}
2943 2943
 }
2944 2944
 
2945 2945
 /**
@@ -2948,34 +2948,34 @@  discard block
 block discarded – undo
2948 2948
 class EE_Event_Single_Config extends EE_Config_Base
2949 2949
 {
2950 2950
 
2951
-    public $display_status_banner_single;
2951
+	public $display_status_banner_single;
2952 2952
 
2953
-    public $display_venue;
2953
+	public $display_venue;
2954 2954
 
2955
-    public $use_sortable_display_order;
2955
+	public $use_sortable_display_order;
2956 2956
 
2957
-    public $display_order_tickets;
2957
+	public $display_order_tickets;
2958 2958
 
2959
-    public $display_order_datetimes;
2959
+	public $display_order_datetimes;
2960 2960
 
2961
-    public $display_order_event;
2961
+	public $display_order_event;
2962 2962
 
2963
-    public $display_order_venue;
2963
+	public $display_order_venue;
2964 2964
 
2965 2965
 
2966
-    /**
2967
-     *    class constructor
2968
-     */
2969
-    public function __construct()
2970
-    {
2971
-        $this->display_status_banner_single = 0;
2972
-        $this->display_venue = 1;
2973
-        $this->use_sortable_display_order = false;
2974
-        $this->display_order_tickets = 100;
2975
-        $this->display_order_datetimes = 110;
2976
-        $this->display_order_event = 120;
2977
-        $this->display_order_venue = 130;
2978
-    }
2966
+	/**
2967
+	 *    class constructor
2968
+	 */
2969
+	public function __construct()
2970
+	{
2971
+		$this->display_status_banner_single = 0;
2972
+		$this->display_venue = 1;
2973
+		$this->use_sortable_display_order = false;
2974
+		$this->display_order_tickets = 100;
2975
+		$this->display_order_datetimes = 110;
2976
+		$this->display_order_event = 120;
2977
+		$this->display_order_venue = 130;
2978
+	}
2979 2979
 }
2980 2980
 
2981 2981
 /**
@@ -2984,172 +2984,172 @@  discard block
 block discarded – undo
2984 2984
 class EE_Ticket_Selector_Config extends EE_Config_Base
2985 2985
 {
2986 2986
 
2987
-    /**
2988
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2989
-     */
2990
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2991
-
2992
-    /**
2993
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2994
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2995
-     */
2996
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2997
-
2998
-    /**
2999
-     * @var boolean $show_ticket_sale_columns
3000
-     */
3001
-    public $show_ticket_sale_columns;
3002
-
3003
-    /**
3004
-     * @var boolean $show_ticket_details
3005
-     */
3006
-    public $show_ticket_details;
3007
-
3008
-    /**
3009
-     * @var boolean $show_expired_tickets
3010
-     */
3011
-    public $show_expired_tickets;
3012
-
3013
-    /**
3014
-     * whether or not to display a dropdown box populated with event datetimes
3015
-     * that toggles which tickets are displayed for a ticket selector.
3016
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3017
-     *
3018
-     * @var string $show_datetime_selector
3019
-     */
3020
-    private $show_datetime_selector = 'no_datetime_selector';
3021
-
3022
-    /**
3023
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3024
-     *
3025
-     * @var int $datetime_selector_threshold
3026
-     */
3027
-    private $datetime_selector_threshold = 3;
3028
-
3029
-    /**
3030
-     * determines the maximum number of "checked" dates in the date and time filter
3031
-     *
3032
-     * @var int $datetime_selector_checked
3033
-     */
3034
-    private $datetime_selector_max_checked = 10;
3035
-
3036
-
3037
-    /**
3038
-     *    class constructor
3039
-     */
3040
-    public function __construct()
3041
-    {
3042
-        $this->show_ticket_sale_columns = true;
3043
-        $this->show_ticket_details = true;
3044
-        $this->show_expired_tickets = true;
3045
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
-        $this->datetime_selector_threshold = 3;
3047
-        $this->datetime_selector_max_checked = 10;
3048
-    }
3049
-
3050
-
3051
-    /**
3052
-     * returns true if a datetime selector should be displayed
3053
-     *
3054
-     * @param array $datetimes
3055
-     * @return bool
3056
-     */
3057
-    public function showDatetimeSelector(array $datetimes)
3058
-    {
3059
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3060
-        return ! (
3061
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3062
-            || (
3063
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3064
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3065
-            )
3066
-        );
3067
-    }
3068
-
3069
-
3070
-    /**
3071
-     * @return string
3072
-     */
3073
-    public function getShowDatetimeSelector()
3074
-    {
3075
-        return $this->show_datetime_selector;
3076
-    }
3077
-
3078
-
3079
-    /**
3080
-     * @param bool $keys_only
3081
-     * @return array
3082
-     */
3083
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3084
-    {
3085
-        return $keys_only
3086
-            ? array(
3087
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3088
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3089
-            )
3090
-            : array(
3091
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3092
-                    'Do not show date & time filter',
3093
-                    'event_espresso'
3094
-                ),
3095
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3096
-                    'Maybe show date & time filter',
3097
-                    'event_espresso'
3098
-                ),
3099
-            );
3100
-    }
3101
-
3102
-
3103
-    /**
3104
-     * @param string $show_datetime_selector
3105
-     */
3106
-    public function setShowDatetimeSelector($show_datetime_selector)
3107
-    {
3108
-        $this->show_datetime_selector = in_array(
3109
-            $show_datetime_selector,
3110
-            $this->getShowDatetimeSelectorOptions(),
3111
-            true
3112
-        )
3113
-            ? $show_datetime_selector
3114
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3115
-    }
3116
-
3117
-
3118
-    /**
3119
-     * @return int
3120
-     */
3121
-    public function getDatetimeSelectorThreshold()
3122
-    {
3123
-        return $this->datetime_selector_threshold;
3124
-    }
3125
-
3126
-
3127
-    /**
3128
-     * @param int $datetime_selector_threshold
3129
-     */
3130
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3131
-    {
3132
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3133
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3134
-    }
3135
-
3136
-
3137
-    /**
3138
-     * @return int
3139
-     */
3140
-    public function getDatetimeSelectorMaxChecked()
3141
-    {
3142
-        return $this->datetime_selector_max_checked;
3143
-    }
3144
-
3145
-
3146
-    /**
3147
-     * @param int $datetime_selector_max_checked
3148
-     */
3149
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3150
-    {
3151
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3152
-    }
2987
+	/**
2988
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2989
+	 */
2990
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2991
+
2992
+	/**
2993
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2994
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2995
+	 */
2996
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2997
+
2998
+	/**
2999
+	 * @var boolean $show_ticket_sale_columns
3000
+	 */
3001
+	public $show_ticket_sale_columns;
3002
+
3003
+	/**
3004
+	 * @var boolean $show_ticket_details
3005
+	 */
3006
+	public $show_ticket_details;
3007
+
3008
+	/**
3009
+	 * @var boolean $show_expired_tickets
3010
+	 */
3011
+	public $show_expired_tickets;
3012
+
3013
+	/**
3014
+	 * whether or not to display a dropdown box populated with event datetimes
3015
+	 * that toggles which tickets are displayed for a ticket selector.
3016
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3017
+	 *
3018
+	 * @var string $show_datetime_selector
3019
+	 */
3020
+	private $show_datetime_selector = 'no_datetime_selector';
3021
+
3022
+	/**
3023
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3024
+	 *
3025
+	 * @var int $datetime_selector_threshold
3026
+	 */
3027
+	private $datetime_selector_threshold = 3;
3028
+
3029
+	/**
3030
+	 * determines the maximum number of "checked" dates in the date and time filter
3031
+	 *
3032
+	 * @var int $datetime_selector_checked
3033
+	 */
3034
+	private $datetime_selector_max_checked = 10;
3035
+
3036
+
3037
+	/**
3038
+	 *    class constructor
3039
+	 */
3040
+	public function __construct()
3041
+	{
3042
+		$this->show_ticket_sale_columns = true;
3043
+		$this->show_ticket_details = true;
3044
+		$this->show_expired_tickets = true;
3045
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
+		$this->datetime_selector_threshold = 3;
3047
+		$this->datetime_selector_max_checked = 10;
3048
+	}
3049
+
3050
+
3051
+	/**
3052
+	 * returns true if a datetime selector should be displayed
3053
+	 *
3054
+	 * @param array $datetimes
3055
+	 * @return bool
3056
+	 */
3057
+	public function showDatetimeSelector(array $datetimes)
3058
+	{
3059
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3060
+		return ! (
3061
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3062
+			|| (
3063
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3064
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3065
+			)
3066
+		);
3067
+	}
3068
+
3069
+
3070
+	/**
3071
+	 * @return string
3072
+	 */
3073
+	public function getShowDatetimeSelector()
3074
+	{
3075
+		return $this->show_datetime_selector;
3076
+	}
3077
+
3078
+
3079
+	/**
3080
+	 * @param bool $keys_only
3081
+	 * @return array
3082
+	 */
3083
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3084
+	{
3085
+		return $keys_only
3086
+			? array(
3087
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3088
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3089
+			)
3090
+			: array(
3091
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3092
+					'Do not show date & time filter',
3093
+					'event_espresso'
3094
+				),
3095
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3096
+					'Maybe show date & time filter',
3097
+					'event_espresso'
3098
+				),
3099
+			);
3100
+	}
3101
+
3102
+
3103
+	/**
3104
+	 * @param string $show_datetime_selector
3105
+	 */
3106
+	public function setShowDatetimeSelector($show_datetime_selector)
3107
+	{
3108
+		$this->show_datetime_selector = in_array(
3109
+			$show_datetime_selector,
3110
+			$this->getShowDatetimeSelectorOptions(),
3111
+			true
3112
+		)
3113
+			? $show_datetime_selector
3114
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3115
+	}
3116
+
3117
+
3118
+	/**
3119
+	 * @return int
3120
+	 */
3121
+	public function getDatetimeSelectorThreshold()
3122
+	{
3123
+		return $this->datetime_selector_threshold;
3124
+	}
3125
+
3126
+
3127
+	/**
3128
+	 * @param int $datetime_selector_threshold
3129
+	 */
3130
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3131
+	{
3132
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3133
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3134
+	}
3135
+
3136
+
3137
+	/**
3138
+	 * @return int
3139
+	 */
3140
+	public function getDatetimeSelectorMaxChecked()
3141
+	{
3142
+		return $this->datetime_selector_max_checked;
3143
+	}
3144
+
3145
+
3146
+	/**
3147
+	 * @param int $datetime_selector_max_checked
3148
+	 */
3149
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3150
+	{
3151
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3152
+	}
3153 3153
 }
3154 3154
 
3155 3155
 /**
@@ -3162,86 +3162,86 @@  discard block
 block discarded – undo
3162 3162
 class EE_Environment_Config extends EE_Config_Base
3163 3163
 {
3164 3164
 
3165
-    /**
3166
-     * Hold any php environment variables that we want to track.
3167
-     *
3168
-     * @var stdClass;
3169
-     */
3170
-    public $php;
3171
-
3172
-
3173
-    /**
3174
-     *    constructor
3175
-     */
3176
-    public function __construct()
3177
-    {
3178
-        $this->php = new stdClass();
3179
-        $this->_set_php_values();
3180
-    }
3181
-
3182
-
3183
-    /**
3184
-     * This sets the php environment variables.
3185
-     *
3186
-     * @since 4.4.0
3187
-     * @return void
3188
-     */
3189
-    protected function _set_php_values()
3190
-    {
3191
-        $this->php->max_input_vars = ini_get('max_input_vars');
3192
-        $this->php->version = phpversion();
3193
-    }
3194
-
3195
-
3196
-    /**
3197
-     * helper method for determining whether input_count is
3198
-     * reaching the potential maximum the server can handle
3199
-     * according to max_input_vars
3200
-     *
3201
-     * @param int   $input_count the count of input vars.
3202
-     * @return array {
3203
-     *                           An array that represents whether available space and if no available space the error
3204
-     *                           message.
3205
-     * @type bool   $has_space   whether more inputs can be added.
3206
-     * @type string $msg         Any message to be displayed.
3207
-     *                           }
3208
-     */
3209
-    public function max_input_vars_limit_check($input_count = 0)
3210
-    {
3211
-        if (! empty($this->php->max_input_vars)
3212
-            && ($input_count >= $this->php->max_input_vars)
3213
-        ) {
3214
-            // check the server setting because the config value could be stale
3215
-            $max_input_vars = ini_get('max_input_vars');
3216
-            if ($input_count >= $max_input_vars) {
3217
-                return sprintf(
3218
-                    esc_html__(
3219
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3220
-                        'event_espresso'
3221
-                    ),
3222
-                    '<br>',
3223
-                    $input_count,
3224
-                    $max_input_vars
3225
-                );
3226
-            } else {
3227
-                return '';
3228
-            }
3229
-        } else {
3230
-            return '';
3231
-        }
3232
-    }
3233
-
3234
-
3235
-    /**
3236
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3237
-     *
3238
-     * @since 4.4.1
3239
-     * @return void
3240
-     */
3241
-    public function recheck_values()
3242
-    {
3243
-        $this->_set_php_values();
3244
-    }
3165
+	/**
3166
+	 * Hold any php environment variables that we want to track.
3167
+	 *
3168
+	 * @var stdClass;
3169
+	 */
3170
+	public $php;
3171
+
3172
+
3173
+	/**
3174
+	 *    constructor
3175
+	 */
3176
+	public function __construct()
3177
+	{
3178
+		$this->php = new stdClass();
3179
+		$this->_set_php_values();
3180
+	}
3181
+
3182
+
3183
+	/**
3184
+	 * This sets the php environment variables.
3185
+	 *
3186
+	 * @since 4.4.0
3187
+	 * @return void
3188
+	 */
3189
+	protected function _set_php_values()
3190
+	{
3191
+		$this->php->max_input_vars = ini_get('max_input_vars');
3192
+		$this->php->version = phpversion();
3193
+	}
3194
+
3195
+
3196
+	/**
3197
+	 * helper method for determining whether input_count is
3198
+	 * reaching the potential maximum the server can handle
3199
+	 * according to max_input_vars
3200
+	 *
3201
+	 * @param int   $input_count the count of input vars.
3202
+	 * @return array {
3203
+	 *                           An array that represents whether available space and if no available space the error
3204
+	 *                           message.
3205
+	 * @type bool   $has_space   whether more inputs can be added.
3206
+	 * @type string $msg         Any message to be displayed.
3207
+	 *                           }
3208
+	 */
3209
+	public function max_input_vars_limit_check($input_count = 0)
3210
+	{
3211
+		if (! empty($this->php->max_input_vars)
3212
+			&& ($input_count >= $this->php->max_input_vars)
3213
+		) {
3214
+			// check the server setting because the config value could be stale
3215
+			$max_input_vars = ini_get('max_input_vars');
3216
+			if ($input_count >= $max_input_vars) {
3217
+				return sprintf(
3218
+					esc_html__(
3219
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3220
+						'event_espresso'
3221
+					),
3222
+					'<br>',
3223
+					$input_count,
3224
+					$max_input_vars
3225
+				);
3226
+			} else {
3227
+				return '';
3228
+			}
3229
+		} else {
3230
+			return '';
3231
+		}
3232
+	}
3233
+
3234
+
3235
+	/**
3236
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3237
+	 *
3238
+	 * @since 4.4.1
3239
+	 * @return void
3240
+	 */
3241
+	public function recheck_values()
3242
+	{
3243
+		$this->_set_php_values();
3244
+	}
3245 3245
 }
3246 3246
 
3247 3247
 /**
@@ -3254,21 +3254,21 @@  discard block
 block discarded – undo
3254 3254
 class EE_Tax_Config extends EE_Config_Base
3255 3255
 {
3256 3256
 
3257
-    /*
3257
+	/*
3258 3258
      * flag to indicate whether or not to display ticket prices with the taxes included
3259 3259
      *
3260 3260
      * @var boolean $prices_displayed_including_taxes
3261 3261
      */
3262
-    public $prices_displayed_including_taxes;
3262
+	public $prices_displayed_including_taxes;
3263 3263
 
3264 3264
 
3265
-    /**
3266
-     *    class constructor
3267
-     */
3268
-    public function __construct()
3269
-    {
3270
-        $this->prices_displayed_including_taxes = true;
3271
-    }
3265
+	/**
3266
+	 *    class constructor
3267
+	 */
3268
+	public function __construct()
3269
+	{
3270
+		$this->prices_displayed_including_taxes = true;
3271
+	}
3272 3272
 }
3273 3273
 
3274 3274
 /**
@@ -3282,19 +3282,19 @@  discard block
 block discarded – undo
3282 3282
 class EE_Messages_Config extends EE_Config_Base
3283 3283
 {
3284 3284
 
3285
-    /**
3286
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3287
-     * A value of 0 represents never deleting.  Default is 0.
3288
-     *
3289
-     * @var integer
3290
-     */
3291
-    public $delete_threshold;
3285
+	/**
3286
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3287
+	 * A value of 0 represents never deleting.  Default is 0.
3288
+	 *
3289
+	 * @var integer
3290
+	 */
3291
+	public $delete_threshold;
3292 3292
 
3293 3293
 
3294
-    public function __construct()
3295
-    {
3296
-        $this->delete_threshold = 0;
3297
-    }
3294
+	public function __construct()
3295
+	{
3296
+		$this->delete_threshold = 0;
3297
+	}
3298 3298
 }
3299 3299
 
3300 3300
 /**
@@ -3305,31 +3305,31 @@  discard block
 block discarded – undo
3305 3305
 class EE_Gateway_Config extends EE_Config_Base
3306 3306
 {
3307 3307
 
3308
-    /**
3309
-     * Array with keys that are payment gateways slugs, and values are arrays
3310
-     * with any config info the gateway wants to store
3311
-     *
3312
-     * @var array
3313
-     */
3314
-    public $payment_settings;
3315
-
3316
-    /**
3317
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3318
-     * the gateway is stored in the uploads directory
3319
-     *
3320
-     * @var array
3321
-     */
3322
-    public $active_gateways;
3323
-
3324
-
3325
-    /**
3326
-     *    class constructor
3327
-     *
3328
-     * @deprecated
3329
-     */
3330
-    public function __construct()
3331
-    {
3332
-        $this->payment_settings = array();
3333
-        $this->active_gateways = array('Invoice' => false);
3334
-    }
3308
+	/**
3309
+	 * Array with keys that are payment gateways slugs, and values are arrays
3310
+	 * with any config info the gateway wants to store
3311
+	 *
3312
+	 * @var array
3313
+	 */
3314
+	public $payment_settings;
3315
+
3316
+	/**
3317
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3318
+	 * the gateway is stored in the uploads directory
3319
+	 *
3320
+	 * @var array
3321
+	 */
3322
+	public $active_gateways;
3323
+
3324
+
3325
+	/**
3326
+	 *    class constructor
3327
+	 *
3328
+	 * @deprecated
3329
+	 */
3330
+	public function __construct()
3331
+	{
3332
+		$this->payment_settings = array();
3333
+		$this->active_gateways = array('Invoice' => false);
3334
+	}
3335 3335
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 2 patches
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     public function __construct($routing = true)
30 30
     {
31 31
         parent::__construct($routing);
32
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
32
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
34
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
35
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
36 36
         }
37 37
     }
38 38
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     protected function _extend_page_config()
44 44
     {
45
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
45
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
46 46
         // is there a evt_id in the request?
47 47
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48 48
             ? $this->_req_data['EVT_ID']
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
     {
264 264
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265 265
         // make sure this is only when editing
266
-        if (! empty($id)) {
266
+        if ( ! empty($id)) {
267 267
             $href = EE_Admin_Page::add_query_args_and_nonce(
268 268
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
269 269
                 $this->_admin_base_url
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     {
316 316
         wp_register_script(
317 317
             'ee-event-editor-heartbeat',
318
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
318
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
319 319
             array('ee_admin_js', 'heartbeat'),
320 320
             EVENT_ESPRESSO_VERSION,
321 321
             true
@@ -328,12 +328,12 @@  discard block
 block discarded – undo
328 328
         if ($this->admin_config->useAdvancedEditor()) {
329 329
             add_action(
330 330
                 'admin_footer',
331
-                function () {
331
+                function() {
332 332
                     $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333 333
                     if ($eventId) {
334 334
                         echo '
335 335
         <script type="text/javascript">
336
-            /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; /* ]]> */
336
+            /* <![CDATA[ */ var eeEditorEventId = ' . $eventId.'; /* ]]> */
337 337
         </script>';
338 338
                     }
339 339
                 }
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
     public function add_additional_datetime_button($template, $template_args)
354 354
     {
355 355
         return EEH_Template::display_template(
356
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
356
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
357 357
             $template_args,
358 358
             true
359 359
         );
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     public function add_datetime_clone_button($template, $template_args)
372 372
     {
373 373
         return EEH_Template::display_template(
374
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
374
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
375 375
             $template_args,
376 376
             true
377 377
         );
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
     public function datetime_timezones_template($template, $template_args)
390 390
     {
391 391
         return EEH_Template::display_template(
392
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
392
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
393 393
             $template_args,
394 394
             true
395 395
         );
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
     {
509 509
         // first make sure the ID for the event is in the request.
510 510
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
511
-        if (! isset($this->_req_data['EVT_ID'])) {
511
+        if ( ! isset($this->_req_data['EVT_ID'])) {
512 512
             EE_Error::add_error(
513 513
                 esc_html__(
514 514
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         }
524 524
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
525 525
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
526
-        if (! $orig_event instanceof EE_Event) {
526
+        if ( ! $orig_event instanceof EE_Event) {
527 527
             throw new EE_Error(
528 528
                 sprintf(
529 529
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         $orig_ven = $orig_event->get_many_related('Venue');
540 540
         // reset the ID and modify other details to make it clear this is a dupe
541 541
         $new_event->set('EVT_ID', 0);
542
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
542
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
543 543
         $new_event->set('EVT_name', $new_name);
544 544
         $new_event->set(
545 545
             'EVT_slug',
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
             'Question_Group',
569 569
             array(array('Event_Question_Group.EQG_primary' => 1))
570 570
         );
571
-        if (! empty($orig_primary_qgs)) {
571
+        if ( ! empty($orig_primary_qgs)) {
572 572
             foreach ($orig_primary_qgs as $id => $obj) {
573 573
                 if ($obj instanceof EE_Question_Group) {
574 574
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
             'Question_Group',
581 581
             array(array('Event_Question_Group.EQG_primary' => 0))
582 582
         );
583
-        if (! empty($orig_additional_qgs)) {
583
+        if ( ! empty($orig_additional_qgs)) {
584 584
             foreach ($orig_additional_qgs as $id => $obj) {
585 585
                 if ($obj instanceof EE_Question_Group) {
586 586
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
594 594
         $cloned_tickets = array();
595 595
         foreach ($orig_datetimes as $orig_dtt) {
596
-            if (! $orig_dtt instanceof EE_Datetime) {
596
+            if ( ! $orig_dtt instanceof EE_Datetime) {
597 597
                 continue;
598 598
             }
599 599
             $new_dtt = clone $orig_dtt;
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
             // now let's get the ticket relations setup.
609 609
             foreach ((array) $orig_tkts as $orig_tkt) {
610 610
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
611
-                if (! $orig_tkt instanceof EE_Ticket) {
611
+                if ( ! $orig_tkt instanceof EE_Ticket) {
612 612
                     continue;
613 613
                 }
614 614
                 // is this ticket archived?  If it is then let's skip
@@ -617,8 +617,8 @@  discard block
 block discarded – undo
617 617
                 }
618 618
                 // does this original ticket already exist in the clone_tickets cache?
619 619
                 //  If so we'll just use the new ticket from it.
620
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
621
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
620
+                if (isset($cloned_tickets[$orig_tkt->ID()])) {
621
+                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
622 622
                 } else {
623 623
                     $new_tkt = clone $orig_tkt;
624 624
                     // get relations on the $orig_tkt that we need to setup.
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
                 // for use with later datetimes that have the same ticket.
652 652
                 $new_dtt->_add_relation_to($new_tkt, 'Ticket');
653 653
                 $new_dtt->save();
654
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
654
+                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
655 655
             }
656 656
         }
657 657
         // clone taxonomy information
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             $this->_admin_base_url
735 735
         );
736 736
         $content = EEH_Template::display_template(
737
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
737
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
738 738
             $this->_template_args,
739 739
             true
740 740
         );
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
      */
752 752
     protected function _import_events()
753 753
     {
754
-        require_once(EE_CLASSES . 'EE_Import.class.php');
754
+        require_once(EE_CLASSES.'EE_Import.class.php');
755 755
         $success = EE_Import::instance()->import();
756 756
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
757 757
     }
@@ -780,8 +780,8 @@  discard block
 block discarded – undo
780 780
             'EVT_ID' => $event_ids,
781 781
         );
782 782
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
783
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
784
-            require_once(EE_CLASSES . 'EE_Export.class.php');
783
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
784
+            require_once(EE_CLASSES.'EE_Export.class.php');
785 785
             $EE_Export = EE_Export::instance($this->_req_data);
786 786
             $EE_Export->export();
787 787
         }
@@ -802,8 +802,8 @@  discard block
 block discarded – undo
802 802
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
803 803
         );
804 804
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
805
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
806
-            require_once(EE_CLASSES . 'EE_Export.class.php');
805
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
806
+            require_once(EE_CLASSES.'EE_Export.class.php');
807 807
             $EE_Export = EE_Export::instance($this->_req_data);
808 808
             $EE_Export->export();
809 809
         }
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         $this->_set_add_edit_form_tags('update_template_settings');
842 842
         $this->_set_publish_post_box_vars(null, false, false, null, false);
843 843
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
844
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
844
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
845 845
             $this->_template_args,
846 846
             true
847 847
         );
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
             $default_reg_status_values
969 969
         );
970 970
         EEH_Template::display_template(
971
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
971
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
972 972
             $template_args
973 973
         );
974 974
     }
@@ -1072,13 +1072,13 @@  discard block
 block discarded – undo
1072 1072
     {
1073 1073
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1074 1074
             'DTT_EVT_start',
1075
-            date('Y-m-d') . ' 00:00:00',
1075
+            date('Y-m-d').' 00:00:00',
1076 1076
             'Y-m-d H:i:s',
1077 1077
             'UTC'
1078 1078
         );
1079 1079
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1080 1080
             'DTT_EVT_start',
1081
-            date('Y-m-d') . ' 23:59:59',
1081
+            date('Y-m-d').' 23:59:59',
1082 1082
             'Y-m-d H:i:s',
1083 1083
             'UTC'
1084 1084
         );
@@ -1105,13 +1105,13 @@  discard block
 block discarded – undo
1105 1105
         $days_this_month = date('t');
1106 1106
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1107 1107
             'DTT_EVT_start',
1108
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1108
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1109 1109
             'Y-m-d H:i:s',
1110 1110
             'UTC'
1111 1111
         );
1112 1112
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1113 1113
             'DTT_EVT_start',
1114
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1114
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1115 1115
             'Y-m-d H:i:s',
1116 1116
             'UTC'
1117 1117
         );
@@ -1178,7 +1178,7 @@  discard block
 block discarded – undo
1178 1178
         $offset = ($current_page - 1) * $per_page;
1179 1179
         $limit = array($offset, $per_page);
1180 1180
         if (isset($this->_req_data['s'])) {
1181
-            $sstr = '%' . $this->_req_data['s'] . '%';
1181
+            $sstr = '%'.$this->_req_data['s'].'%';
1182 1182
             $_where['OR'] = array(
1183 1183
                 'TKT_name'        => array('LIKE', $sstr),
1184 1184
                 'TKT_description' => array('LIKE', $sstr),
@@ -1207,17 +1207,17 @@  discard block
 block discarded – undo
1207 1207
         $success = 1;
1208 1208
         $TKT = EEM_Ticket::instance();
1209 1209
         // checkboxes?
1210
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1210
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1211 1211
             // if array has more than one element then success message should be plural
1212 1212
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1213 1213
             // cycle thru the boxes
1214 1214
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1215 1215
                 if ($trash) {
1216
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1216
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1217 1217
                         $success = 0;
1218 1218
                     }
1219 1219
                 } else {
1220
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1220
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1221 1221
                         $success = 0;
1222 1222
                     }
1223 1223
                 }
@@ -1226,11 +1226,11 @@  discard block
 block discarded – undo
1226 1226
             // grab single id and trash
1227 1227
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1228 1228
             if ($trash) {
1229
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1229
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1230 1230
                     $success = 0;
1231 1231
                 }
1232 1232
             } else {
1233
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1233
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1234 1234
                     $success = 0;
1235 1235
                 }
1236 1236
             }
@@ -1251,20 +1251,20 @@  discard block
 block discarded – undo
1251 1251
     {
1252 1252
         $success = 1;
1253 1253
         // checkboxes?
1254
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1254
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1255 1255
             // if array has more than one element then success message should be plural
1256 1256
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1257 1257
             // cycle thru the boxes
1258 1258
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1259 1259
                 // delete
1260
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1260
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1261 1261
                     $success = 0;
1262 1262
                 }
1263 1263
             }
1264 1264
         } else {
1265 1265
             // grab single id and trash
1266 1266
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1267
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1267
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1268 1268
                 $success = 0;
1269 1269
             }
1270 1270
         }
Please login to merge, or discard this patch.
Indentation   +1338 added lines, -1338 removed lines patch added patch discarded remove patch
@@ -15,1345 +15,1345 @@
 block discarded – undo
15 15
 class Extend_Events_Admin_Page extends Events_Admin_Page
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Admin_Config
20
-     */
21
-    protected $admin_config;
22
-
23
-
24
-    /**
25
-     * Extend_Events_Admin_Page constructor.
26
-     *
27
-     * @param bool $routing
28
-     */
29
-    public function __construct($routing = true)
30
-    {
31
-        parent::__construct($routing);
32
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
36
-        }
37
-    }
38
-
39
-
40
-    /**
41
-     * Sets routes.
42
-     */
43
-    protected function _extend_page_config()
44
-    {
45
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
46
-        // is there a evt_id in the request?
47
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48
-            ? $this->_req_data['EVT_ID']
49
-            : 0;
50
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
51
-        // tkt_id?
52
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
53
-            ? $this->_req_data['TKT_ID']
54
-            : 0;
55
-        $new_page_routes = array(
56
-            'duplicate_event'          => array(
57
-                'func'       => '_duplicate_event',
58
-                'capability' => 'ee_edit_event',
59
-                'obj_id'     => $evt_id,
60
-                'noheader'   => true,
61
-            ),
62
-            'ticket_list_table'        => array(
63
-                'func'       => '_tickets_overview_list_table',
64
-                'capability' => 'ee_read_default_tickets',
65
-            ),
66
-            'trash_ticket'             => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_ticket',
69
-                'obj_id'     => $tkt_id,
70
-                'noheader'   => true,
71
-                'args'       => array('trash' => true),
72
-            ),
73
-            'trash_tickets'            => array(
74
-                'func'       => '_trash_or_restore_ticket',
75
-                'capability' => 'ee_delete_default_tickets',
76
-                'noheader'   => true,
77
-                'args'       => array('trash' => true),
78
-            ),
79
-            'restore_ticket'           => array(
80
-                'func'       => '_trash_or_restore_ticket',
81
-                'capability' => 'ee_delete_default_ticket',
82
-                'obj_id'     => $tkt_id,
83
-                'noheader'   => true,
84
-            ),
85
-            'restore_tickets'          => array(
86
-                'func'       => '_trash_or_restore_ticket',
87
-                'capability' => 'ee_delete_default_tickets',
88
-                'noheader'   => true,
89
-            ),
90
-            'delete_ticket'            => array(
91
-                'func'       => '_delete_ticket',
92
-                'capability' => 'ee_delete_default_ticket',
93
-                'obj_id'     => $tkt_id,
94
-                'noheader'   => true,
95
-            ),
96
-            'delete_tickets'           => array(
97
-                'func'       => '_delete_ticket',
98
-                'capability' => 'ee_delete_default_tickets',
99
-                'noheader'   => true,
100
-            ),
101
-            'import_page'              => array(
102
-                'func'       => '_import_page',
103
-                'capability' => 'import',
104
-            ),
105
-            'import'                   => array(
106
-                'func'       => '_import_events',
107
-                'capability' => 'import',
108
-                'noheader'   => true,
109
-            ),
110
-            'import_events'            => array(
111
-                'func'       => '_import_events',
112
-                'capability' => 'import',
113
-                'noheader'   => true,
114
-            ),
115
-            'export_events'            => array(
116
-                'func'       => '_events_export',
117
-                'capability' => 'export',
118
-                'noheader'   => true,
119
-            ),
120
-            'export_categories'        => array(
121
-                'func'       => '_categories_export',
122
-                'capability' => 'export',
123
-                'noheader'   => true,
124
-            ),
125
-            'sample_export_file'       => array(
126
-                'func'       => '_sample_export_file',
127
-                'capability' => 'export',
128
-                'noheader'   => true,
129
-            ),
130
-            'update_template_settings' => array(
131
-                'func'       => '_update_template_settings',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-        );
136
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
137
-        // partial route/config override
138
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
139
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
140
-        $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
141
-        $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
142
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
143
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
144
-        // add tickets tab but only if there are more than one default ticket!
145
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
146
-            array(array('TKT_is_default' => 1)),
147
-            'TKT_ID',
148
-            true
149
-        );
150
-        if ($tkt_count > 1) {
151
-            $new_page_config = array(
152
-                'ticket_list_table' => array(
153
-                    'nav'           => array(
154
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
155
-                        'order' => 60,
156
-                    ),
157
-                    'list_table'    => 'Tickets_List_Table',
158
-                    'require_nonce' => false,
159
-                ),
160
-            );
161
-        }
162
-        // template settings
163
-        $new_page_config['template_settings'] = array(
164
-            'nav'           => array(
165
-                'label' => esc_html__('Templates', 'event_espresso'),
166
-                'order' => 30,
167
-            ),
168
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
-            'help_tabs'     => array(
170
-                'general_settings_templates_help_tab' => array(
171
-                    'title'    => esc_html__('Templates', 'event_espresso'),
172
-                    'filename' => 'general_settings_templates',
173
-                ),
174
-            ),
175
-            'help_tour'     => array('Templates_Help_Tour'),
176
-            'require_nonce' => false,
177
-        );
178
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
179
-        // add filters and actions
180
-        // modifying _views
181
-        add_filter(
182
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
183
-            array($this, 'add_additional_datetime_button'),
184
-            10,
185
-            2
186
-        );
187
-        add_filter(
188
-            'FHEE_event_datetime_metabox_clone_button_template',
189
-            array($this, 'add_datetime_clone_button'),
190
-            10,
191
-            2
192
-        );
193
-        add_filter(
194
-            'FHEE_event_datetime_metabox_timezones_template',
195
-            array($this, 'datetime_timezones_template'),
196
-            10,
197
-            2
198
-        );
199
-        // filters for event list table
200
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
201
-        add_filter(
202
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
203
-            array($this, 'extra_list_table_actions'),
204
-            10,
205
-            2
206
-        );
207
-        // legend item
208
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
209
-        add_action('admin_init', array($this, 'admin_init'));
210
-        $this->admin_config = EE_Registry::instance()->CFG->admin;
211
-        add_filter(
212
-            'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
213
-            [$this, 'advancedEditorAdminFormSection']
214
-        );
215
-        add_action(
216
-            'AHEE__Events_Admin_Page___update_default_event_settings',
217
-            [$this, 'updateAdvancedEditorAdminFormSettings'],
218
-            10,
219
-            2
220
-        );
221
-    }
222
-
223
-
224
-    /**
225
-     * admin_init
226
-     */
227
-    public function admin_init()
228
-    {
229
-        EE_Registry::$i18n_js_strings = array_merge(
230
-            EE_Registry::$i18n_js_strings,
231
-            array(
232
-                'image_confirm'          => esc_html__(
233
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
234
-                    'event_espresso'
235
-                ),
236
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
237
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
238
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
239
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
240
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
241
-            )
242
-        );
243
-    }
244
-
245
-
246
-    /**
247
-     * Add per page screen options to the default ticket list table view.
248
-     */
249
-    protected function _add_screen_options_ticket_list_table()
250
-    {
251
-        $this->_per_page_screen_option();
252
-    }
253
-
254
-
255
-    /**
256
-     * @param string $return
257
-     * @param int    $id
258
-     * @param string $new_title
259
-     * @param string $new_slug
260
-     * @return string
261
-     */
262
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
263
-    {
264
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265
-        // make sure this is only when editing
266
-        if (! empty($id)) {
267
-            $href = EE_Admin_Page::add_query_args_and_nonce(
268
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
269
-                $this->_admin_base_url
270
-            );
271
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
272
-            $return .= '<a href="'
273
-                       . $href
274
-                       . '" title="'
275
-                       . $title
276
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
277
-                       . $title
278
-                       . '</a>';
279
-        }
280
-        return $return;
281
-    }
282
-
283
-
284
-    /**
285
-     * Set the list table views for the default ticket list table view.
286
-     */
287
-    public function _set_list_table_views_ticket_list_table()
288
-    {
289
-        $this->_views = array(
290
-            'all'     => array(
291
-                'slug'        => 'all',
292
-                'label'       => esc_html__('All', 'event_espresso'),
293
-                'count'       => 0,
294
-                'bulk_action' => array(
295
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
296
-                ),
297
-            ),
298
-            'trashed' => array(
299
-                'slug'        => 'trashed',
300
-                'label'       => esc_html__('Trash', 'event_espresso'),
301
-                'count'       => 0,
302
-                'bulk_action' => array(
303
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
304
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
305
-                ),
306
-            ),
307
-        );
308
-    }
309
-
310
-
311
-    /**
312
-     * Enqueue scripts and styles for the event editor.
313
-     */
314
-    public function load_scripts_styles_edit()
315
-    {
316
-        wp_register_script(
317
-            'ee-event-editor-heartbeat',
318
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
319
-            array('ee_admin_js', 'heartbeat'),
320
-            EVENT_ESPRESSO_VERSION,
321
-            true
322
-        );
323
-        wp_enqueue_script('ee-accounting');
324
-        // styles
325
-        wp_enqueue_style('espresso-ui-theme');
326
-        wp_enqueue_script('event_editor_js');
327
-        wp_enqueue_script('ee-event-editor-heartbeat');
328
-        if ($this->admin_config->useAdvancedEditor()) {
329
-            add_action(
330
-                'admin_footer',
331
-                function () {
332
-                    $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333
-                    if ($eventId) {
334
-                        echo '
18
+	/**
19
+	 * @var EE_Admin_Config
20
+	 */
21
+	protected $admin_config;
22
+
23
+
24
+	/**
25
+	 * Extend_Events_Admin_Page constructor.
26
+	 *
27
+	 * @param bool $routing
28
+	 */
29
+	public function __construct($routing = true)
30
+	{
31
+		parent::__construct($routing);
32
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
36
+		}
37
+	}
38
+
39
+
40
+	/**
41
+	 * Sets routes.
42
+	 */
43
+	protected function _extend_page_config()
44
+	{
45
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
46
+		// is there a evt_id in the request?
47
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48
+			? $this->_req_data['EVT_ID']
49
+			: 0;
50
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
51
+		// tkt_id?
52
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
53
+			? $this->_req_data['TKT_ID']
54
+			: 0;
55
+		$new_page_routes = array(
56
+			'duplicate_event'          => array(
57
+				'func'       => '_duplicate_event',
58
+				'capability' => 'ee_edit_event',
59
+				'obj_id'     => $evt_id,
60
+				'noheader'   => true,
61
+			),
62
+			'ticket_list_table'        => array(
63
+				'func'       => '_tickets_overview_list_table',
64
+				'capability' => 'ee_read_default_tickets',
65
+			),
66
+			'trash_ticket'             => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_ticket',
69
+				'obj_id'     => $tkt_id,
70
+				'noheader'   => true,
71
+				'args'       => array('trash' => true),
72
+			),
73
+			'trash_tickets'            => array(
74
+				'func'       => '_trash_or_restore_ticket',
75
+				'capability' => 'ee_delete_default_tickets',
76
+				'noheader'   => true,
77
+				'args'       => array('trash' => true),
78
+			),
79
+			'restore_ticket'           => array(
80
+				'func'       => '_trash_or_restore_ticket',
81
+				'capability' => 'ee_delete_default_ticket',
82
+				'obj_id'     => $tkt_id,
83
+				'noheader'   => true,
84
+			),
85
+			'restore_tickets'          => array(
86
+				'func'       => '_trash_or_restore_ticket',
87
+				'capability' => 'ee_delete_default_tickets',
88
+				'noheader'   => true,
89
+			),
90
+			'delete_ticket'            => array(
91
+				'func'       => '_delete_ticket',
92
+				'capability' => 'ee_delete_default_ticket',
93
+				'obj_id'     => $tkt_id,
94
+				'noheader'   => true,
95
+			),
96
+			'delete_tickets'           => array(
97
+				'func'       => '_delete_ticket',
98
+				'capability' => 'ee_delete_default_tickets',
99
+				'noheader'   => true,
100
+			),
101
+			'import_page'              => array(
102
+				'func'       => '_import_page',
103
+				'capability' => 'import',
104
+			),
105
+			'import'                   => array(
106
+				'func'       => '_import_events',
107
+				'capability' => 'import',
108
+				'noheader'   => true,
109
+			),
110
+			'import_events'            => array(
111
+				'func'       => '_import_events',
112
+				'capability' => 'import',
113
+				'noheader'   => true,
114
+			),
115
+			'export_events'            => array(
116
+				'func'       => '_events_export',
117
+				'capability' => 'export',
118
+				'noheader'   => true,
119
+			),
120
+			'export_categories'        => array(
121
+				'func'       => '_categories_export',
122
+				'capability' => 'export',
123
+				'noheader'   => true,
124
+			),
125
+			'sample_export_file'       => array(
126
+				'func'       => '_sample_export_file',
127
+				'capability' => 'export',
128
+				'noheader'   => true,
129
+			),
130
+			'update_template_settings' => array(
131
+				'func'       => '_update_template_settings',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+		);
136
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
137
+		// partial route/config override
138
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
139
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
140
+		$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
141
+		$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
142
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
143
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
144
+		// add tickets tab but only if there are more than one default ticket!
145
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
146
+			array(array('TKT_is_default' => 1)),
147
+			'TKT_ID',
148
+			true
149
+		);
150
+		if ($tkt_count > 1) {
151
+			$new_page_config = array(
152
+				'ticket_list_table' => array(
153
+					'nav'           => array(
154
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
155
+						'order' => 60,
156
+					),
157
+					'list_table'    => 'Tickets_List_Table',
158
+					'require_nonce' => false,
159
+				),
160
+			);
161
+		}
162
+		// template settings
163
+		$new_page_config['template_settings'] = array(
164
+			'nav'           => array(
165
+				'label' => esc_html__('Templates', 'event_espresso'),
166
+				'order' => 30,
167
+			),
168
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
+			'help_tabs'     => array(
170
+				'general_settings_templates_help_tab' => array(
171
+					'title'    => esc_html__('Templates', 'event_espresso'),
172
+					'filename' => 'general_settings_templates',
173
+				),
174
+			),
175
+			'help_tour'     => array('Templates_Help_Tour'),
176
+			'require_nonce' => false,
177
+		);
178
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
179
+		// add filters and actions
180
+		// modifying _views
181
+		add_filter(
182
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
183
+			array($this, 'add_additional_datetime_button'),
184
+			10,
185
+			2
186
+		);
187
+		add_filter(
188
+			'FHEE_event_datetime_metabox_clone_button_template',
189
+			array($this, 'add_datetime_clone_button'),
190
+			10,
191
+			2
192
+		);
193
+		add_filter(
194
+			'FHEE_event_datetime_metabox_timezones_template',
195
+			array($this, 'datetime_timezones_template'),
196
+			10,
197
+			2
198
+		);
199
+		// filters for event list table
200
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
201
+		add_filter(
202
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
203
+			array($this, 'extra_list_table_actions'),
204
+			10,
205
+			2
206
+		);
207
+		// legend item
208
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
209
+		add_action('admin_init', array($this, 'admin_init'));
210
+		$this->admin_config = EE_Registry::instance()->CFG->admin;
211
+		add_filter(
212
+			'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
213
+			[$this, 'advancedEditorAdminFormSection']
214
+		);
215
+		add_action(
216
+			'AHEE__Events_Admin_Page___update_default_event_settings',
217
+			[$this, 'updateAdvancedEditorAdminFormSettings'],
218
+			10,
219
+			2
220
+		);
221
+	}
222
+
223
+
224
+	/**
225
+	 * admin_init
226
+	 */
227
+	public function admin_init()
228
+	{
229
+		EE_Registry::$i18n_js_strings = array_merge(
230
+			EE_Registry::$i18n_js_strings,
231
+			array(
232
+				'image_confirm'          => esc_html__(
233
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
234
+					'event_espresso'
235
+				),
236
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
237
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
238
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
239
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
240
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
241
+			)
242
+		);
243
+	}
244
+
245
+
246
+	/**
247
+	 * Add per page screen options to the default ticket list table view.
248
+	 */
249
+	protected function _add_screen_options_ticket_list_table()
250
+	{
251
+		$this->_per_page_screen_option();
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param string $return
257
+	 * @param int    $id
258
+	 * @param string $new_title
259
+	 * @param string $new_slug
260
+	 * @return string
261
+	 */
262
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
263
+	{
264
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265
+		// make sure this is only when editing
266
+		if (! empty($id)) {
267
+			$href = EE_Admin_Page::add_query_args_and_nonce(
268
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
269
+				$this->_admin_base_url
270
+			);
271
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
272
+			$return .= '<a href="'
273
+					   . $href
274
+					   . '" title="'
275
+					   . $title
276
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
277
+					   . $title
278
+					   . '</a>';
279
+		}
280
+		return $return;
281
+	}
282
+
283
+
284
+	/**
285
+	 * Set the list table views for the default ticket list table view.
286
+	 */
287
+	public function _set_list_table_views_ticket_list_table()
288
+	{
289
+		$this->_views = array(
290
+			'all'     => array(
291
+				'slug'        => 'all',
292
+				'label'       => esc_html__('All', 'event_espresso'),
293
+				'count'       => 0,
294
+				'bulk_action' => array(
295
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
296
+				),
297
+			),
298
+			'trashed' => array(
299
+				'slug'        => 'trashed',
300
+				'label'       => esc_html__('Trash', 'event_espresso'),
301
+				'count'       => 0,
302
+				'bulk_action' => array(
303
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
304
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
305
+				),
306
+			),
307
+		);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Enqueue scripts and styles for the event editor.
313
+	 */
314
+	public function load_scripts_styles_edit()
315
+	{
316
+		wp_register_script(
317
+			'ee-event-editor-heartbeat',
318
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
319
+			array('ee_admin_js', 'heartbeat'),
320
+			EVENT_ESPRESSO_VERSION,
321
+			true
322
+		);
323
+		wp_enqueue_script('ee-accounting');
324
+		// styles
325
+		wp_enqueue_style('espresso-ui-theme');
326
+		wp_enqueue_script('event_editor_js');
327
+		wp_enqueue_script('ee-event-editor-heartbeat');
328
+		if ($this->admin_config->useAdvancedEditor()) {
329
+			add_action(
330
+				'admin_footer',
331
+				function () {
332
+					$eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333
+					if ($eventId) {
334
+						echo '
335 335
         <script type="text/javascript">
336 336
             /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; /* ]]> */
337 337
         </script>';
338
-                    }
339
-                }
340
-            );
341
-        }
342
-    }
343
-
344
-
345
-    /**
346
-     * Returns template for the additional datetime.
347
-     *
348
-     * @param $template
349
-     * @param $template_args
350
-     * @return mixed
351
-     * @throws DomainException
352
-     */
353
-    public function add_additional_datetime_button($template, $template_args)
354
-    {
355
-        return EEH_Template::display_template(
356
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
357
-            $template_args,
358
-            true
359
-        );
360
-    }
361
-
362
-
363
-    /**
364
-     * Returns the template for cloning a datetime.
365
-     *
366
-     * @param $template
367
-     * @param $template_args
368
-     * @return mixed
369
-     * @throws DomainException
370
-     */
371
-    public function add_datetime_clone_button($template, $template_args)
372
-    {
373
-        return EEH_Template::display_template(
374
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
375
-            $template_args,
376
-            true
377
-        );
378
-    }
379
-
380
-
381
-    /**
382
-     * Returns the template for datetime timezones.
383
-     *
384
-     * @param $template
385
-     * @param $template_args
386
-     * @return mixed
387
-     * @throws DomainException
388
-     */
389
-    public function datetime_timezones_template($template, $template_args)
390
-    {
391
-        return EEH_Template::display_template(
392
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
393
-            $template_args,
394
-            true
395
-        );
396
-    }
397
-
398
-
399
-    /**
400
-     * Sets the views for the default list table view.
401
-     */
402
-    protected function _set_list_table_views_default()
403
-    {
404
-        parent::_set_list_table_views_default();
405
-        $new_views = array(
406
-            'today' => array(
407
-                'slug'        => 'today',
408
-                'label'       => esc_html__('Today', 'event_espresso'),
409
-                'count'       => $this->total_events_today(),
410
-                'bulk_action' => array(
411
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
412
-                ),
413
-            ),
414
-            'month' => array(
415
-                'slug'        => 'month',
416
-                'label'       => esc_html__('This Month', 'event_espresso'),
417
-                'count'       => $this->total_events_this_month(),
418
-                'bulk_action' => array(
419
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
420
-                ),
421
-            ),
422
-        );
423
-        $this->_views = array_merge($this->_views, $new_views);
424
-    }
425
-
426
-
427
-    /**
428
-     * Returns the extra action links for the default list table view.
429
-     *
430
-     * @param array     $action_links
431
-     * @param \EE_Event $event
432
-     * @return array
433
-     * @throws EE_Error
434
-     */
435
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
436
-    {
437
-        if (EE_Registry::instance()->CAP->current_user_can(
438
-            'ee_read_registrations',
439
-            'espresso_registrations_reports',
440
-            $event->ID()
441
-        )
442
-        ) {
443
-            $reports_query_args = array(
444
-                'action' => 'reports',
445
-                'EVT_ID' => $event->ID(),
446
-            );
447
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
448
-            $action_links[] = '<a href="'
449
-                              . $reports_link
450
-                              . '" title="'
451
-                              . esc_attr__('View Report', 'event_espresso')
452
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
453
-                              . "\n\t";
454
-        }
455
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
456
-            EE_Registry::instance()->load_helper('MSG_Template');
457
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
458
-                'see_notifications_for',
459
-                null,
460
-                array('EVT_ID' => $event->ID())
461
-            );
462
-        }
463
-        return $action_links;
464
-    }
465
-
466
-
467
-    /**
468
-     * @param $items
469
-     * @return mixed
470
-     */
471
-    public function additional_legend_items($items)
472
-    {
473
-        if (EE_Registry::instance()->CAP->current_user_can(
474
-            'ee_read_registrations',
475
-            'espresso_registrations_reports'
476
-        )
477
-        ) {
478
-            $items['reports'] = array(
479
-                'class' => 'dashicons dashicons-chart-bar',
480
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
481
-            );
482
-        }
483
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
484
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
485
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
486
-                $items['view_related_messages'] = array(
487
-                    'class' => $related_for_icon['css_class'],
488
-                    'desc'  => $related_for_icon['label'],
489
-                );
490
-            }
491
-        }
492
-        return $items;
493
-    }
494
-
495
-
496
-    /**
497
-     * This is the callback method for the duplicate event route
498
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
499
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
500
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
501
-     * After duplication the redirect is to the new event edit page.
502
-     *
503
-     * @return void
504
-     * @access protected
505
-     * @throws EE_Error If EE_Event is not available with given ID
506
-     */
507
-    protected function _duplicate_event()
508
-    {
509
-        // first make sure the ID for the event is in the request.
510
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
511
-        if (! isset($this->_req_data['EVT_ID'])) {
512
-            EE_Error::add_error(
513
-                esc_html__(
514
-                    'In order to duplicate an event an Event ID is required.  None was given.',
515
-                    'event_espresso'
516
-                ),
517
-                __FILE__,
518
-                __FUNCTION__,
519
-                __LINE__
520
-            );
521
-            $this->_redirect_after_action(false, '', '', array(), true);
522
-            return;
523
-        }
524
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
525
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
526
-        if (! $orig_event instanceof EE_Event) {
527
-            throw new EE_Error(
528
-                sprintf(
529
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
530
-                    $this->_req_data['EVT_ID']
531
-                )
532
-            );
533
-        }
534
-        // k now let's clone the $orig_event before getting relations
535
-        $new_event = clone $orig_event;
536
-        // original datetimes
537
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
538
-        // other original relations
539
-        $orig_ven = $orig_event->get_many_related('Venue');
540
-        // reset the ID and modify other details to make it clear this is a dupe
541
-        $new_event->set('EVT_ID', 0);
542
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
543
-        $new_event->set('EVT_name', $new_name);
544
-        $new_event->set(
545
-            'EVT_slug',
546
-            wp_unique_post_slug(
547
-                sanitize_title($orig_event->name()),
548
-                0,
549
-                'publish',
550
-                'espresso_events',
551
-                0
552
-            )
553
-        );
554
-        $new_event->set('status', 'draft');
555
-        // duplicate discussion settings
556
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
557
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
558
-        // save the new event
559
-        $new_event->save();
560
-        // venues
561
-        foreach ($orig_ven as $ven) {
562
-            $new_event->_add_relation_to($ven, 'Venue');
563
-        }
564
-        $new_event->save();
565
-        // now we need to get the question group relations and handle that
566
-        // first primary question groups
567
-        $orig_primary_qgs = $orig_event->get_many_related(
568
-            'Question_Group',
569
-            array(array('Event_Question_Group.EQG_primary' => 1))
570
-        );
571
-        if (! empty($orig_primary_qgs)) {
572
-            foreach ($orig_primary_qgs as $id => $obj) {
573
-                if ($obj instanceof EE_Question_Group) {
574
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
575
-                }
576
-            }
577
-        }
578
-        // next additional attendee question groups
579
-        $orig_additional_qgs = $orig_event->get_many_related(
580
-            'Question_Group',
581
-            array(array('Event_Question_Group.EQG_primary' => 0))
582
-        );
583
-        if (! empty($orig_additional_qgs)) {
584
-            foreach ($orig_additional_qgs as $id => $obj) {
585
-                if ($obj instanceof EE_Question_Group) {
586
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
587
-                }
588
-            }
589
-        }
590
-
591
-        $new_event->save();
592
-
593
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
594
-        $cloned_tickets = array();
595
-        foreach ($orig_datetimes as $orig_dtt) {
596
-            if (! $orig_dtt instanceof EE_Datetime) {
597
-                continue;
598
-            }
599
-            $new_dtt = clone $orig_dtt;
600
-            $orig_tkts = $orig_dtt->tickets();
601
-            // save new dtt then add to event
602
-            $new_dtt->set('DTT_ID', 0);
603
-            $new_dtt->set('DTT_sold', 0);
604
-            $new_dtt->set_reserved(0);
605
-            $new_dtt->save();
606
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
607
-            $new_event->save();
608
-            // now let's get the ticket relations setup.
609
-            foreach ((array) $orig_tkts as $orig_tkt) {
610
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
611
-                if (! $orig_tkt instanceof EE_Ticket) {
612
-                    continue;
613
-                }
614
-                // is this ticket archived?  If it is then let's skip
615
-                if ($orig_tkt->get('TKT_deleted')) {
616
-                    continue;
617
-                }
618
-                // does this original ticket already exist in the clone_tickets cache?
619
-                //  If so we'll just use the new ticket from it.
620
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
621
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
622
-                } else {
623
-                    $new_tkt = clone $orig_tkt;
624
-                    // get relations on the $orig_tkt that we need to setup.
625
-                    $orig_prices = $orig_tkt->prices();
626
-                    $new_tkt->set('TKT_ID', 0);
627
-                    $new_tkt->set('TKT_sold', 0);
628
-                    $new_tkt->set('TKT_reserved', 0);
629
-                    $new_tkt->save(); // make sure new ticket has ID.
630
-                    // price relations on new ticket need to be setup.
631
-                    foreach ($orig_prices as $orig_price) {
632
-                        $new_price = clone $orig_price;
633
-                        $new_price->set('PRC_ID', 0);
634
-                        $new_price->save();
635
-                        $new_tkt->_add_relation_to($new_price, 'Price');
636
-                        $new_tkt->save();
637
-                    }
638
-
639
-                    do_action(
640
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
641
-                        $orig_tkt,
642
-                        $new_tkt,
643
-                        $orig_prices,
644
-                        $orig_event,
645
-                        $orig_dtt,
646
-                        $new_dtt
647
-                    );
648
-                }
649
-                // k now we can add the new ticket as a relation to the new datetime
650
-                // and make sure its added to our cached $cloned_tickets array
651
-                // for use with later datetimes that have the same ticket.
652
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
653
-                $new_dtt->save();
654
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
655
-            }
656
-        }
657
-        // clone taxonomy information
658
-        $taxonomies_to_clone_with = apply_filters(
659
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
660
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
661
-        );
662
-        // get terms for original event (notice)
663
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
664
-        // loop through terms and add them to new event.
665
-        foreach ($orig_terms as $term) {
666
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
667
-        }
668
-
669
-        // duplicate other core WP_Post items for this event.
670
-        // post thumbnail (feature image).
671
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
672
-        if ($feature_image_id) {
673
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
674
-        }
675
-
676
-        // duplicate page_template setting
677
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
678
-        if ($page_template) {
679
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
680
-        }
681
-
682
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
683
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
684
-        if ($new_event->ID()) {
685
-            $redirect_args = array(
686
-                'post'   => $new_event->ID(),
687
-                'action' => 'edit',
688
-            );
689
-            EE_Error::add_success(
690
-                esc_html__(
691
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
692
-                    'event_espresso'
693
-                )
694
-            );
695
-        } else {
696
-            $redirect_args = array(
697
-                'action' => 'default',
698
-            );
699
-            EE_Error::add_error(
700
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
701
-                __FILE__,
702
-                __FUNCTION__,
703
-                __LINE__
704
-            );
705
-        }
706
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
707
-    }
708
-
709
-
710
-    /**
711
-     * Generates output for the import page.
712
-     *
713
-     * @throws DomainException
714
-     */
715
-    protected function _import_page()
716
-    {
717
-        $title = esc_html__('Import', 'event_espresso');
718
-        $intro = esc_html__(
719
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
720
-            'event_espresso'
721
-        );
722
-        $form_url = EVENTS_ADMIN_URL;
723
-        $action = 'import_events';
724
-        $type = 'csv';
725
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
726
-            $title,
727
-            $intro,
728
-            $form_url,
729
-            $action,
730
-            $type
731
-        );
732
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
733
-            array('action' => 'sample_export_file'),
734
-            $this->_admin_base_url
735
-        );
736
-        $content = EEH_Template::display_template(
737
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
738
-            $this->_template_args,
739
-            true
740
-        );
741
-        $this->_template_args['admin_page_content'] = $content;
742
-        $this->display_admin_page_with_sidebar();
743
-    }
744
-
745
-
746
-    /**
747
-     * _import_events
748
-     * This handles displaying the screen and running imports for importing events.
749
-     *
750
-     * @return void
751
-     */
752
-    protected function _import_events()
753
-    {
754
-        require_once(EE_CLASSES . 'EE_Import.class.php');
755
-        $success = EE_Import::instance()->import();
756
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
757
-    }
758
-
759
-
760
-    /**
761
-     * _events_export
762
-     * Will export all (or just the given event) to a Excel compatible file.
763
-     *
764
-     * @access protected
765
-     * @return void
766
-     */
767
-    protected function _events_export()
768
-    {
769
-        if (isset($this->_req_data['EVT_ID'])) {
770
-            $event_ids = $this->_req_data['EVT_ID'];
771
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
772
-            $event_ids = $this->_req_data['EVT_IDs'];
773
-        } else {
774
-            $event_ids = null;
775
-        }
776
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
777
-        $new_request_args = array(
778
-            'export' => 'report',
779
-            'action' => 'all_event_data',
780
-            'EVT_ID' => $event_ids,
781
-        );
782
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
783
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
784
-            require_once(EE_CLASSES . 'EE_Export.class.php');
785
-            $EE_Export = EE_Export::instance($this->_req_data);
786
-            $EE_Export->export();
787
-        }
788
-    }
789
-
790
-
791
-    /**
792
-     * handle category exports()
793
-     *
794
-     * @return void
795
-     */
796
-    protected function _categories_export()
797
-    {
798
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
799
-        $new_request_args = array(
800
-            'export'       => 'report',
801
-            'action'       => 'categories',
802
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
803
-        );
804
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
805
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
806
-            require_once(EE_CLASSES . 'EE_Export.class.php');
807
-            $EE_Export = EE_Export::instance($this->_req_data);
808
-            $EE_Export->export();
809
-        }
810
-    }
811
-
812
-
813
-    /**
814
-     * Creates a sample CSV file for importing
815
-     */
816
-    protected function _sample_export_file()
817
-    {
818
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
819
-        EE_Export::instance()->export_sample();
820
-    }
821
-
822
-
823
-    /*************        Template Settings        *************/
824
-    /**
825
-     * Generates template settings page output
826
-     *
827
-     * @throws DomainException
828
-     * @throws EE_Error
829
-     */
830
-    protected function _template_settings()
831
-    {
832
-        $this->_template_args['values'] = $this->_yes_no_values;
833
-        /**
834
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
835
-         * from General_Settings_Admin_Page to here.
836
-         */
837
-        $this->_template_args = apply_filters(
838
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
839
-            $this->_template_args
840
-        );
841
-        $this->_set_add_edit_form_tags('update_template_settings');
842
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
843
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
844
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
845
-            $this->_template_args,
846
-            true
847
-        );
848
-        $this->display_admin_page_with_sidebar();
849
-    }
850
-
851
-
852
-    /**
853
-     * Handler for updating template settings.
854
-     *
855
-     * @throws InvalidInterfaceException
856
-     * @throws InvalidDataTypeException
857
-     * @throws InvalidArgumentException
858
-     */
859
-    protected function _update_template_settings()
860
-    {
861
-        /**
862
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
863
-         * from General_Settings_Admin_Page to here.
864
-         */
865
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
866
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
867
-            EE_Registry::instance()->CFG->template_settings,
868
-            $this->_req_data
869
-        );
870
-        // update custom post type slugs and detect if we need to flush rewrite rules
871
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
872
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
873
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
874
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
875
-        $what = 'Template Settings';
876
-        $success = $this->_update_espresso_configuration(
877
-            $what,
878
-            EE_Registry::instance()->CFG->template_settings,
879
-            __FILE__,
880
-            __FUNCTION__,
881
-            __LINE__
882
-        );
883
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
884
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
885
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
886
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
887
-            );
888
-            $rewrite_rules->flush();
889
-        }
890
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
891
-    }
892
-
893
-
894
-    /**
895
-     * _premium_event_editor_meta_boxes
896
-     * add all metaboxes related to the event_editor
897
-     *
898
-     * @access protected
899
-     * @return void
900
-     * @throws EE_Error
901
-     */
902
-    protected function _premium_event_editor_meta_boxes()
903
-    {
904
-        $this->verify_cpt_object();
905
-        add_meta_box(
906
-            'espresso_event_editor_event_options',
907
-            esc_html__('Event Registration Options', 'event_espresso'),
908
-            array($this, 'registration_options_meta_box'),
909
-            $this->page_slug,
910
-            'side',
911
-            'core'
912
-        );
913
-    }
914
-
915
-
916
-    /**
917
-     * override caf metabox
918
-     *
919
-     * @return void
920
-     * @throws DomainException
921
-     */
922
-    public function registration_options_meta_box()
923
-    {
924
-        $yes_no_values = array(
925
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
926
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
927
-        );
928
-        $default_reg_status_values = EEM_Registration::reg_status_array(
929
-            array(
930
-                EEM_Registration::status_id_cancelled,
931
-                EEM_Registration::status_id_declined,
932
-                EEM_Registration::status_id_incomplete,
933
-                EEM_Registration::status_id_wait_list,
934
-            ),
935
-            true
936
-        );
937
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
938
-        $template_args['_event'] = $this->_cpt_model_obj;
939
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
940
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
941
-            'default_reg_status',
942
-            $default_reg_status_values,
943
-            $this->_cpt_model_obj->default_registration_status()
944
-        );
945
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
946
-            'display_desc',
947
-            $yes_no_values,
948
-            $this->_cpt_model_obj->display_description()
949
-        );
950
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
951
-            'display_ticket_selector',
952
-            $yes_no_values,
953
-            $this->_cpt_model_obj->display_ticket_selector(),
954
-            '',
955
-            '',
956
-            false
957
-        );
958
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
959
-            'EVT_default_registration_status',
960
-            $default_reg_status_values,
961
-            $this->_cpt_model_obj->default_registration_status()
962
-        );
963
-        $template_args['additional_registration_options'] = apply_filters(
964
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
965
-            '',
966
-            $template_args,
967
-            $yes_no_values,
968
-            $default_reg_status_values
969
-        );
970
-        EEH_Template::display_template(
971
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
972
-            $template_args
973
-        );
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * wp_list_table_mods for caf
980
-     * ============================
981
-     */
982
-    /**
983
-     * hook into list table filters and provide filters for caffeinated list table
984
-     *
985
-     * @param  array $old_filters    any existing filters present
986
-     * @param  array $list_table_obj the list table object
987
-     * @return array                  new filters
988
-     */
989
-    public function list_table_filters($old_filters, $list_table_obj)
990
-    {
991
-        $filters = array();
992
-        // first month/year filters
993
-        $filters[] = $this->espresso_event_months_dropdown();
994
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
995
-        // active status dropdown
996
-        if ($status !== 'draft') {
997
-            $filters[] = $this->active_status_dropdown(
998
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
999
-            );
1000
-        }
1001
-        // category filter
1002
-        $filters[] = $this->category_dropdown();
1003
-        return array_merge($old_filters, $filters);
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * espresso_event_months_dropdown
1009
-     *
1010
-     * @access public
1011
-     * @return string                dropdown listing month/year selections for events.
1012
-     */
1013
-    public function espresso_event_months_dropdown()
1014
-    {
1015
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1016
-        // Note we need to include any other filters that are set!
1017
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1018
-        // categories?
1019
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1020
-            ? $this->_req_data['EVT_CAT']
1021
-            : null;
1022
-        // active status?
1023
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1024
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1025
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * returns a list of "active" statuses on the event
1031
-     *
1032
-     * @param  string $current_value whatever the current active status is
1033
-     * @return string
1034
-     */
1035
-    public function active_status_dropdown($current_value = '')
1036
-    {
1037
-        $select_name = 'active_status';
1038
-        $values = array(
1039
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1040
-            'active'   => esc_html__('Active', 'event_espresso'),
1041
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1042
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1043
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1044
-        );
1045
-        $id = 'id="espresso-active-status-dropdown-filter"';
1046
-        $class = 'wide';
1047
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     * output a dropdown of the categories for the category filter on the event admin list table
1053
-     *
1054
-     * @access  public
1055
-     * @return string html
1056
-     */
1057
-    public function category_dropdown()
1058
-    {
1059
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1060
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1061
-    }
1062
-
1063
-
1064
-    /**
1065
-     * get total number of events today
1066
-     *
1067
-     * @access public
1068
-     * @return int
1069
-     * @throws EE_Error
1070
-     */
1071
-    public function total_events_today()
1072
-    {
1073
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1074
-            'DTT_EVT_start',
1075
-            date('Y-m-d') . ' 00:00:00',
1076
-            'Y-m-d H:i:s',
1077
-            'UTC'
1078
-        );
1079
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1080
-            'DTT_EVT_start',
1081
-            date('Y-m-d') . ' 23:59:59',
1082
-            'Y-m-d H:i:s',
1083
-            'UTC'
1084
-        );
1085
-        $where = array(
1086
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1087
-        );
1088
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1089
-        return $count;
1090
-    }
1091
-
1092
-
1093
-    /**
1094
-     * get total number of events this month
1095
-     *
1096
-     * @access public
1097
-     * @return int
1098
-     * @throws EE_Error
1099
-     */
1100
-    public function total_events_this_month()
1101
-    {
1102
-        // Dates
1103
-        $this_year_r = date('Y');
1104
-        $this_month_r = date('m');
1105
-        $days_this_month = date('t');
1106
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1107
-            'DTT_EVT_start',
1108
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1109
-            'Y-m-d H:i:s',
1110
-            'UTC'
1111
-        );
1112
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1113
-            'DTT_EVT_start',
1114
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1115
-            'Y-m-d H:i:s',
1116
-            'UTC'
1117
-        );
1118
-        $where = array(
1119
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1120
-        );
1121
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1122
-        return $count;
1123
-    }
1124
-
1125
-
1126
-    /** DEFAULT TICKETS STUFF **/
1127
-
1128
-    /**
1129
-     * Output default tickets list table view.
1130
-     */
1131
-    public function _tickets_overview_list_table()
1132
-    {
1133
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1134
-        $this->display_admin_list_table_page_with_no_sidebar();
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * @param int  $per_page
1140
-     * @param bool $count
1141
-     * @param bool $trashed
1142
-     * @return \EE_Soft_Delete_Base_Class[]|int
1143
-     */
1144
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1145
-    {
1146
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1147
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1148
-        switch ($orderby) {
1149
-            case 'TKT_name':
1150
-                $orderby = array('TKT_name' => $order);
1151
-                break;
1152
-            case 'TKT_price':
1153
-                $orderby = array('TKT_price' => $order);
1154
-                break;
1155
-            case 'TKT_uses':
1156
-                $orderby = array('TKT_uses' => $order);
1157
-                break;
1158
-            case 'TKT_min':
1159
-                $orderby = array('TKT_min' => $order);
1160
-                break;
1161
-            case 'TKT_max':
1162
-                $orderby = array('TKT_max' => $order);
1163
-                break;
1164
-            case 'TKT_qty':
1165
-                $orderby = array('TKT_qty' => $order);
1166
-                break;
1167
-        }
1168
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1169
-            ? $this->_req_data['paged']
1170
-            : 1;
1171
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1172
-            ? $this->_req_data['perpage']
1173
-            : $per_page;
1174
-        $_where = array(
1175
-            'TKT_is_default' => 1,
1176
-            'TKT_deleted'    => $trashed,
1177
-        );
1178
-        $offset = ($current_page - 1) * $per_page;
1179
-        $limit = array($offset, $per_page);
1180
-        if (isset($this->_req_data['s'])) {
1181
-            $sstr = '%' . $this->_req_data['s'] . '%';
1182
-            $_where['OR'] = array(
1183
-                'TKT_name'        => array('LIKE', $sstr),
1184
-                'TKT_description' => array('LIKE', $sstr),
1185
-            );
1186
-        }
1187
-        $query_params = array(
1188
-            $_where,
1189
-            'order_by' => $orderby,
1190
-            'limit'    => $limit,
1191
-            'group_by' => 'TKT_ID',
1192
-        );
1193
-        if ($count) {
1194
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1195
-        } else {
1196
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1197
-        }
1198
-    }
1199
-
1200
-
1201
-    /**
1202
-     * @param bool $trash
1203
-     * @throws EE_Error
1204
-     */
1205
-    protected function _trash_or_restore_ticket($trash = false)
1206
-    {
1207
-        $success = 1;
1208
-        $TKT = EEM_Ticket::instance();
1209
-        // checkboxes?
1210
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1211
-            // if array has more than one element then success message should be plural
1212
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1213
-            // cycle thru the boxes
1214
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1215
-                if ($trash) {
1216
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1217
-                        $success = 0;
1218
-                    }
1219
-                } else {
1220
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1221
-                        $success = 0;
1222
-                    }
1223
-                }
1224
-            }
1225
-        } else {
1226
-            // grab single id and trash
1227
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1228
-            if ($trash) {
1229
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1230
-                    $success = 0;
1231
-                }
1232
-            } else {
1233
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1234
-                    $success = 0;
1235
-                }
1236
-            }
1237
-        }
1238
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1239
-        $query_args = array(
1240
-            'action' => 'ticket_list_table',
1241
-            'status' => $trash ? '' : 'trashed',
1242
-        );
1243
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     * Handles trashing default ticket.
1249
-     */
1250
-    protected function _delete_ticket()
1251
-    {
1252
-        $success = 1;
1253
-        // checkboxes?
1254
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1255
-            // if array has more than one element then success message should be plural
1256
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1257
-            // cycle thru the boxes
1258
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1259
-                // delete
1260
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1261
-                    $success = 0;
1262
-                }
1263
-            }
1264
-        } else {
1265
-            // grab single id and trash
1266
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1267
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1268
-                $success = 0;
1269
-            }
1270
-        }
1271
-        $action_desc = 'deleted';
1272
-        $query_args = array(
1273
-            'action' => 'ticket_list_table',
1274
-            'status' => 'trashed',
1275
-        );
1276
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1277
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1278
-            array(array('TKT_is_default' => 1)),
1279
-            'TKT_ID',
1280
-            true
1281
-        )
1282
-        ) {
1283
-            $query_args = array();
1284
-        }
1285
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1286
-    }
1287
-
1288
-
1289
-    /**
1290
-     * @param int $TKT_ID
1291
-     * @return bool|int
1292
-     * @throws EE_Error
1293
-     */
1294
-    protected function _delete_the_ticket($TKT_ID)
1295
-    {
1296
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1297
-        $tkt->_remove_relations('Datetime');
1298
-        // delete all related prices first
1299
-        $tkt->delete_related_permanently('Price');
1300
-        return $tkt->delete_permanently();
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     * @param array $default_event_settings_form_subsections
1306
-     * @return array
1307
-     * @since $VID:$
1308
-     */
1309
-    public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1310
-    {
1311
-        return [
1312
-            'use_advanced_editor'         => new EE_Select_Input(
1313
-                apply_filters(
1314
-                    'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_answer_options',
1315
-                    [
1316
-                        esc_html__('Legacy Editor', 'event_espresso'),
1317
-                        esc_html__('Advanced Editor', 'event_espresso'),
1318
-                    ]
1319
-                ),
1320
-                apply_filters(
1321
-                    'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_settings',
1322
-                    [
1323
-                        'default'         => $this->admin_config->useAdvancedEditor(),
1324
-                        'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1325
-                        'html_help_text'  => sprintf(
1326
-                            esc_html__(
1327
-                                'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
1328
-                                'event_espresso'
1329
-                            ),
1330
-                            '<br />'
1331
-                        ),
1332
-                    ]
1333
-                )
1334
-            ),
1335
-            'defaults_section_header' => new EE_Form_Section_HTML(
1336
-                EEH_HTML::h2(
1337
-                    esc_html__('Default Settings', 'event_espresso'),
1338
-                    '',
1339
-                    'ee-admin-settings-hdr'
1340
-                )
1341
-            ),
1342
-        ] + $default_event_settings_form_subsections;
1343
-    }
1344
-
1345
-
1346
-    /**
1347
-     * @param array     $valid_data
1348
-     * @param EE_Config $config
1349
-     * @since $VID:$
1350
-     */
1351
-    public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1352
-    {
1353
-        $config->admin->setUseAdvancedEditor(
1354
-            isset($valid_data['use_advanced_editor'])
1355
-                ? $valid_data['use_advanced_editor']
1356
-                : false
1357
-        );
1358
-    }
338
+					}
339
+				}
340
+			);
341
+		}
342
+	}
343
+
344
+
345
+	/**
346
+	 * Returns template for the additional datetime.
347
+	 *
348
+	 * @param $template
349
+	 * @param $template_args
350
+	 * @return mixed
351
+	 * @throws DomainException
352
+	 */
353
+	public function add_additional_datetime_button($template, $template_args)
354
+	{
355
+		return EEH_Template::display_template(
356
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
357
+			$template_args,
358
+			true
359
+		);
360
+	}
361
+
362
+
363
+	/**
364
+	 * Returns the template for cloning a datetime.
365
+	 *
366
+	 * @param $template
367
+	 * @param $template_args
368
+	 * @return mixed
369
+	 * @throws DomainException
370
+	 */
371
+	public function add_datetime_clone_button($template, $template_args)
372
+	{
373
+		return EEH_Template::display_template(
374
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
375
+			$template_args,
376
+			true
377
+		);
378
+	}
379
+
380
+
381
+	/**
382
+	 * Returns the template for datetime timezones.
383
+	 *
384
+	 * @param $template
385
+	 * @param $template_args
386
+	 * @return mixed
387
+	 * @throws DomainException
388
+	 */
389
+	public function datetime_timezones_template($template, $template_args)
390
+	{
391
+		return EEH_Template::display_template(
392
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
393
+			$template_args,
394
+			true
395
+		);
396
+	}
397
+
398
+
399
+	/**
400
+	 * Sets the views for the default list table view.
401
+	 */
402
+	protected function _set_list_table_views_default()
403
+	{
404
+		parent::_set_list_table_views_default();
405
+		$new_views = array(
406
+			'today' => array(
407
+				'slug'        => 'today',
408
+				'label'       => esc_html__('Today', 'event_espresso'),
409
+				'count'       => $this->total_events_today(),
410
+				'bulk_action' => array(
411
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
412
+				),
413
+			),
414
+			'month' => array(
415
+				'slug'        => 'month',
416
+				'label'       => esc_html__('This Month', 'event_espresso'),
417
+				'count'       => $this->total_events_this_month(),
418
+				'bulk_action' => array(
419
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
420
+				),
421
+			),
422
+		);
423
+		$this->_views = array_merge($this->_views, $new_views);
424
+	}
425
+
426
+
427
+	/**
428
+	 * Returns the extra action links for the default list table view.
429
+	 *
430
+	 * @param array     $action_links
431
+	 * @param \EE_Event $event
432
+	 * @return array
433
+	 * @throws EE_Error
434
+	 */
435
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
436
+	{
437
+		if (EE_Registry::instance()->CAP->current_user_can(
438
+			'ee_read_registrations',
439
+			'espresso_registrations_reports',
440
+			$event->ID()
441
+		)
442
+		) {
443
+			$reports_query_args = array(
444
+				'action' => 'reports',
445
+				'EVT_ID' => $event->ID(),
446
+			);
447
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
448
+			$action_links[] = '<a href="'
449
+							  . $reports_link
450
+							  . '" title="'
451
+							  . esc_attr__('View Report', 'event_espresso')
452
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
453
+							  . "\n\t";
454
+		}
455
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
456
+			EE_Registry::instance()->load_helper('MSG_Template');
457
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
458
+				'see_notifications_for',
459
+				null,
460
+				array('EVT_ID' => $event->ID())
461
+			);
462
+		}
463
+		return $action_links;
464
+	}
465
+
466
+
467
+	/**
468
+	 * @param $items
469
+	 * @return mixed
470
+	 */
471
+	public function additional_legend_items($items)
472
+	{
473
+		if (EE_Registry::instance()->CAP->current_user_can(
474
+			'ee_read_registrations',
475
+			'espresso_registrations_reports'
476
+		)
477
+		) {
478
+			$items['reports'] = array(
479
+				'class' => 'dashicons dashicons-chart-bar',
480
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
481
+			);
482
+		}
483
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
484
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
485
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
486
+				$items['view_related_messages'] = array(
487
+					'class' => $related_for_icon['css_class'],
488
+					'desc'  => $related_for_icon['label'],
489
+				);
490
+			}
491
+		}
492
+		return $items;
493
+	}
494
+
495
+
496
+	/**
497
+	 * This is the callback method for the duplicate event route
498
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
499
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
500
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
501
+	 * After duplication the redirect is to the new event edit page.
502
+	 *
503
+	 * @return void
504
+	 * @access protected
505
+	 * @throws EE_Error If EE_Event is not available with given ID
506
+	 */
507
+	protected function _duplicate_event()
508
+	{
509
+		// first make sure the ID for the event is in the request.
510
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
511
+		if (! isset($this->_req_data['EVT_ID'])) {
512
+			EE_Error::add_error(
513
+				esc_html__(
514
+					'In order to duplicate an event an Event ID is required.  None was given.',
515
+					'event_espresso'
516
+				),
517
+				__FILE__,
518
+				__FUNCTION__,
519
+				__LINE__
520
+			);
521
+			$this->_redirect_after_action(false, '', '', array(), true);
522
+			return;
523
+		}
524
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
525
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
526
+		if (! $orig_event instanceof EE_Event) {
527
+			throw new EE_Error(
528
+				sprintf(
529
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
530
+					$this->_req_data['EVT_ID']
531
+				)
532
+			);
533
+		}
534
+		// k now let's clone the $orig_event before getting relations
535
+		$new_event = clone $orig_event;
536
+		// original datetimes
537
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
538
+		// other original relations
539
+		$orig_ven = $orig_event->get_many_related('Venue');
540
+		// reset the ID and modify other details to make it clear this is a dupe
541
+		$new_event->set('EVT_ID', 0);
542
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
543
+		$new_event->set('EVT_name', $new_name);
544
+		$new_event->set(
545
+			'EVT_slug',
546
+			wp_unique_post_slug(
547
+				sanitize_title($orig_event->name()),
548
+				0,
549
+				'publish',
550
+				'espresso_events',
551
+				0
552
+			)
553
+		);
554
+		$new_event->set('status', 'draft');
555
+		// duplicate discussion settings
556
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
557
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
558
+		// save the new event
559
+		$new_event->save();
560
+		// venues
561
+		foreach ($orig_ven as $ven) {
562
+			$new_event->_add_relation_to($ven, 'Venue');
563
+		}
564
+		$new_event->save();
565
+		// now we need to get the question group relations and handle that
566
+		// first primary question groups
567
+		$orig_primary_qgs = $orig_event->get_many_related(
568
+			'Question_Group',
569
+			array(array('Event_Question_Group.EQG_primary' => 1))
570
+		);
571
+		if (! empty($orig_primary_qgs)) {
572
+			foreach ($orig_primary_qgs as $id => $obj) {
573
+				if ($obj instanceof EE_Question_Group) {
574
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
575
+				}
576
+			}
577
+		}
578
+		// next additional attendee question groups
579
+		$orig_additional_qgs = $orig_event->get_many_related(
580
+			'Question_Group',
581
+			array(array('Event_Question_Group.EQG_primary' => 0))
582
+		);
583
+		if (! empty($orig_additional_qgs)) {
584
+			foreach ($orig_additional_qgs as $id => $obj) {
585
+				if ($obj instanceof EE_Question_Group) {
586
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
587
+				}
588
+			}
589
+		}
590
+
591
+		$new_event->save();
592
+
593
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
594
+		$cloned_tickets = array();
595
+		foreach ($orig_datetimes as $orig_dtt) {
596
+			if (! $orig_dtt instanceof EE_Datetime) {
597
+				continue;
598
+			}
599
+			$new_dtt = clone $orig_dtt;
600
+			$orig_tkts = $orig_dtt->tickets();
601
+			// save new dtt then add to event
602
+			$new_dtt->set('DTT_ID', 0);
603
+			$new_dtt->set('DTT_sold', 0);
604
+			$new_dtt->set_reserved(0);
605
+			$new_dtt->save();
606
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
607
+			$new_event->save();
608
+			// now let's get the ticket relations setup.
609
+			foreach ((array) $orig_tkts as $orig_tkt) {
610
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
611
+				if (! $orig_tkt instanceof EE_Ticket) {
612
+					continue;
613
+				}
614
+				// is this ticket archived?  If it is then let's skip
615
+				if ($orig_tkt->get('TKT_deleted')) {
616
+					continue;
617
+				}
618
+				// does this original ticket already exist in the clone_tickets cache?
619
+				//  If so we'll just use the new ticket from it.
620
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
621
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
622
+				} else {
623
+					$new_tkt = clone $orig_tkt;
624
+					// get relations on the $orig_tkt that we need to setup.
625
+					$orig_prices = $orig_tkt->prices();
626
+					$new_tkt->set('TKT_ID', 0);
627
+					$new_tkt->set('TKT_sold', 0);
628
+					$new_tkt->set('TKT_reserved', 0);
629
+					$new_tkt->save(); // make sure new ticket has ID.
630
+					// price relations on new ticket need to be setup.
631
+					foreach ($orig_prices as $orig_price) {
632
+						$new_price = clone $orig_price;
633
+						$new_price->set('PRC_ID', 0);
634
+						$new_price->save();
635
+						$new_tkt->_add_relation_to($new_price, 'Price');
636
+						$new_tkt->save();
637
+					}
638
+
639
+					do_action(
640
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
641
+						$orig_tkt,
642
+						$new_tkt,
643
+						$orig_prices,
644
+						$orig_event,
645
+						$orig_dtt,
646
+						$new_dtt
647
+					);
648
+				}
649
+				// k now we can add the new ticket as a relation to the new datetime
650
+				// and make sure its added to our cached $cloned_tickets array
651
+				// for use with later datetimes that have the same ticket.
652
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
653
+				$new_dtt->save();
654
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
655
+			}
656
+		}
657
+		// clone taxonomy information
658
+		$taxonomies_to_clone_with = apply_filters(
659
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
660
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
661
+		);
662
+		// get terms for original event (notice)
663
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
664
+		// loop through terms and add them to new event.
665
+		foreach ($orig_terms as $term) {
666
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
667
+		}
668
+
669
+		// duplicate other core WP_Post items for this event.
670
+		// post thumbnail (feature image).
671
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
672
+		if ($feature_image_id) {
673
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
674
+		}
675
+
676
+		// duplicate page_template setting
677
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
678
+		if ($page_template) {
679
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
680
+		}
681
+
682
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
683
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
684
+		if ($new_event->ID()) {
685
+			$redirect_args = array(
686
+				'post'   => $new_event->ID(),
687
+				'action' => 'edit',
688
+			);
689
+			EE_Error::add_success(
690
+				esc_html__(
691
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
692
+					'event_espresso'
693
+				)
694
+			);
695
+		} else {
696
+			$redirect_args = array(
697
+				'action' => 'default',
698
+			);
699
+			EE_Error::add_error(
700
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
701
+				__FILE__,
702
+				__FUNCTION__,
703
+				__LINE__
704
+			);
705
+		}
706
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
707
+	}
708
+
709
+
710
+	/**
711
+	 * Generates output for the import page.
712
+	 *
713
+	 * @throws DomainException
714
+	 */
715
+	protected function _import_page()
716
+	{
717
+		$title = esc_html__('Import', 'event_espresso');
718
+		$intro = esc_html__(
719
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
720
+			'event_espresso'
721
+		);
722
+		$form_url = EVENTS_ADMIN_URL;
723
+		$action = 'import_events';
724
+		$type = 'csv';
725
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
726
+			$title,
727
+			$intro,
728
+			$form_url,
729
+			$action,
730
+			$type
731
+		);
732
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
733
+			array('action' => 'sample_export_file'),
734
+			$this->_admin_base_url
735
+		);
736
+		$content = EEH_Template::display_template(
737
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
738
+			$this->_template_args,
739
+			true
740
+		);
741
+		$this->_template_args['admin_page_content'] = $content;
742
+		$this->display_admin_page_with_sidebar();
743
+	}
744
+
745
+
746
+	/**
747
+	 * _import_events
748
+	 * This handles displaying the screen and running imports for importing events.
749
+	 *
750
+	 * @return void
751
+	 */
752
+	protected function _import_events()
753
+	{
754
+		require_once(EE_CLASSES . 'EE_Import.class.php');
755
+		$success = EE_Import::instance()->import();
756
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
757
+	}
758
+
759
+
760
+	/**
761
+	 * _events_export
762
+	 * Will export all (or just the given event) to a Excel compatible file.
763
+	 *
764
+	 * @access protected
765
+	 * @return void
766
+	 */
767
+	protected function _events_export()
768
+	{
769
+		if (isset($this->_req_data['EVT_ID'])) {
770
+			$event_ids = $this->_req_data['EVT_ID'];
771
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
772
+			$event_ids = $this->_req_data['EVT_IDs'];
773
+		} else {
774
+			$event_ids = null;
775
+		}
776
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
777
+		$new_request_args = array(
778
+			'export' => 'report',
779
+			'action' => 'all_event_data',
780
+			'EVT_ID' => $event_ids,
781
+		);
782
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
783
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
784
+			require_once(EE_CLASSES . 'EE_Export.class.php');
785
+			$EE_Export = EE_Export::instance($this->_req_data);
786
+			$EE_Export->export();
787
+		}
788
+	}
789
+
790
+
791
+	/**
792
+	 * handle category exports()
793
+	 *
794
+	 * @return void
795
+	 */
796
+	protected function _categories_export()
797
+	{
798
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
799
+		$new_request_args = array(
800
+			'export'       => 'report',
801
+			'action'       => 'categories',
802
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
803
+		);
804
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
805
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
806
+			require_once(EE_CLASSES . 'EE_Export.class.php');
807
+			$EE_Export = EE_Export::instance($this->_req_data);
808
+			$EE_Export->export();
809
+		}
810
+	}
811
+
812
+
813
+	/**
814
+	 * Creates a sample CSV file for importing
815
+	 */
816
+	protected function _sample_export_file()
817
+	{
818
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
819
+		EE_Export::instance()->export_sample();
820
+	}
821
+
822
+
823
+	/*************        Template Settings        *************/
824
+	/**
825
+	 * Generates template settings page output
826
+	 *
827
+	 * @throws DomainException
828
+	 * @throws EE_Error
829
+	 */
830
+	protected function _template_settings()
831
+	{
832
+		$this->_template_args['values'] = $this->_yes_no_values;
833
+		/**
834
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
835
+		 * from General_Settings_Admin_Page to here.
836
+		 */
837
+		$this->_template_args = apply_filters(
838
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
839
+			$this->_template_args
840
+		);
841
+		$this->_set_add_edit_form_tags('update_template_settings');
842
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
843
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
844
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
845
+			$this->_template_args,
846
+			true
847
+		);
848
+		$this->display_admin_page_with_sidebar();
849
+	}
850
+
851
+
852
+	/**
853
+	 * Handler for updating template settings.
854
+	 *
855
+	 * @throws InvalidInterfaceException
856
+	 * @throws InvalidDataTypeException
857
+	 * @throws InvalidArgumentException
858
+	 */
859
+	protected function _update_template_settings()
860
+	{
861
+		/**
862
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
863
+		 * from General_Settings_Admin_Page to here.
864
+		 */
865
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
866
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
867
+			EE_Registry::instance()->CFG->template_settings,
868
+			$this->_req_data
869
+		);
870
+		// update custom post type slugs and detect if we need to flush rewrite rules
871
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
872
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
873
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
874
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
875
+		$what = 'Template Settings';
876
+		$success = $this->_update_espresso_configuration(
877
+			$what,
878
+			EE_Registry::instance()->CFG->template_settings,
879
+			__FILE__,
880
+			__FUNCTION__,
881
+			__LINE__
882
+		);
883
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
884
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
885
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
886
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
887
+			);
888
+			$rewrite_rules->flush();
889
+		}
890
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
891
+	}
892
+
893
+
894
+	/**
895
+	 * _premium_event_editor_meta_boxes
896
+	 * add all metaboxes related to the event_editor
897
+	 *
898
+	 * @access protected
899
+	 * @return void
900
+	 * @throws EE_Error
901
+	 */
902
+	protected function _premium_event_editor_meta_boxes()
903
+	{
904
+		$this->verify_cpt_object();
905
+		add_meta_box(
906
+			'espresso_event_editor_event_options',
907
+			esc_html__('Event Registration Options', 'event_espresso'),
908
+			array($this, 'registration_options_meta_box'),
909
+			$this->page_slug,
910
+			'side',
911
+			'core'
912
+		);
913
+	}
914
+
915
+
916
+	/**
917
+	 * override caf metabox
918
+	 *
919
+	 * @return void
920
+	 * @throws DomainException
921
+	 */
922
+	public function registration_options_meta_box()
923
+	{
924
+		$yes_no_values = array(
925
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
926
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
927
+		);
928
+		$default_reg_status_values = EEM_Registration::reg_status_array(
929
+			array(
930
+				EEM_Registration::status_id_cancelled,
931
+				EEM_Registration::status_id_declined,
932
+				EEM_Registration::status_id_incomplete,
933
+				EEM_Registration::status_id_wait_list,
934
+			),
935
+			true
936
+		);
937
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
938
+		$template_args['_event'] = $this->_cpt_model_obj;
939
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
940
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
941
+			'default_reg_status',
942
+			$default_reg_status_values,
943
+			$this->_cpt_model_obj->default_registration_status()
944
+		);
945
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
946
+			'display_desc',
947
+			$yes_no_values,
948
+			$this->_cpt_model_obj->display_description()
949
+		);
950
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
951
+			'display_ticket_selector',
952
+			$yes_no_values,
953
+			$this->_cpt_model_obj->display_ticket_selector(),
954
+			'',
955
+			'',
956
+			false
957
+		);
958
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
959
+			'EVT_default_registration_status',
960
+			$default_reg_status_values,
961
+			$this->_cpt_model_obj->default_registration_status()
962
+		);
963
+		$template_args['additional_registration_options'] = apply_filters(
964
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
965
+			'',
966
+			$template_args,
967
+			$yes_no_values,
968
+			$default_reg_status_values
969
+		);
970
+		EEH_Template::display_template(
971
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
972
+			$template_args
973
+		);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * wp_list_table_mods for caf
980
+	 * ============================
981
+	 */
982
+	/**
983
+	 * hook into list table filters and provide filters for caffeinated list table
984
+	 *
985
+	 * @param  array $old_filters    any existing filters present
986
+	 * @param  array $list_table_obj the list table object
987
+	 * @return array                  new filters
988
+	 */
989
+	public function list_table_filters($old_filters, $list_table_obj)
990
+	{
991
+		$filters = array();
992
+		// first month/year filters
993
+		$filters[] = $this->espresso_event_months_dropdown();
994
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
995
+		// active status dropdown
996
+		if ($status !== 'draft') {
997
+			$filters[] = $this->active_status_dropdown(
998
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
999
+			);
1000
+		}
1001
+		// category filter
1002
+		$filters[] = $this->category_dropdown();
1003
+		return array_merge($old_filters, $filters);
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * espresso_event_months_dropdown
1009
+	 *
1010
+	 * @access public
1011
+	 * @return string                dropdown listing month/year selections for events.
1012
+	 */
1013
+	public function espresso_event_months_dropdown()
1014
+	{
1015
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1016
+		// Note we need to include any other filters that are set!
1017
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1018
+		// categories?
1019
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1020
+			? $this->_req_data['EVT_CAT']
1021
+			: null;
1022
+		// active status?
1023
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1024
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1025
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * returns a list of "active" statuses on the event
1031
+	 *
1032
+	 * @param  string $current_value whatever the current active status is
1033
+	 * @return string
1034
+	 */
1035
+	public function active_status_dropdown($current_value = '')
1036
+	{
1037
+		$select_name = 'active_status';
1038
+		$values = array(
1039
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1040
+			'active'   => esc_html__('Active', 'event_espresso'),
1041
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1042
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1043
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1044
+		);
1045
+		$id = 'id="espresso-active-status-dropdown-filter"';
1046
+		$class = 'wide';
1047
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1048
+	}
1049
+
1050
+
1051
+	/**
1052
+	 * output a dropdown of the categories for the category filter on the event admin list table
1053
+	 *
1054
+	 * @access  public
1055
+	 * @return string html
1056
+	 */
1057
+	public function category_dropdown()
1058
+	{
1059
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1060
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1061
+	}
1062
+
1063
+
1064
+	/**
1065
+	 * get total number of events today
1066
+	 *
1067
+	 * @access public
1068
+	 * @return int
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	public function total_events_today()
1072
+	{
1073
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1074
+			'DTT_EVT_start',
1075
+			date('Y-m-d') . ' 00:00:00',
1076
+			'Y-m-d H:i:s',
1077
+			'UTC'
1078
+		);
1079
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1080
+			'DTT_EVT_start',
1081
+			date('Y-m-d') . ' 23:59:59',
1082
+			'Y-m-d H:i:s',
1083
+			'UTC'
1084
+		);
1085
+		$where = array(
1086
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1087
+		);
1088
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1089
+		return $count;
1090
+	}
1091
+
1092
+
1093
+	/**
1094
+	 * get total number of events this month
1095
+	 *
1096
+	 * @access public
1097
+	 * @return int
1098
+	 * @throws EE_Error
1099
+	 */
1100
+	public function total_events_this_month()
1101
+	{
1102
+		// Dates
1103
+		$this_year_r = date('Y');
1104
+		$this_month_r = date('m');
1105
+		$days_this_month = date('t');
1106
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1107
+			'DTT_EVT_start',
1108
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1109
+			'Y-m-d H:i:s',
1110
+			'UTC'
1111
+		);
1112
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1113
+			'DTT_EVT_start',
1114
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1115
+			'Y-m-d H:i:s',
1116
+			'UTC'
1117
+		);
1118
+		$where = array(
1119
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1120
+		);
1121
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1122
+		return $count;
1123
+	}
1124
+
1125
+
1126
+	/** DEFAULT TICKETS STUFF **/
1127
+
1128
+	/**
1129
+	 * Output default tickets list table view.
1130
+	 */
1131
+	public function _tickets_overview_list_table()
1132
+	{
1133
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1134
+		$this->display_admin_list_table_page_with_no_sidebar();
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * @param int  $per_page
1140
+	 * @param bool $count
1141
+	 * @param bool $trashed
1142
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1143
+	 */
1144
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1145
+	{
1146
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1147
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1148
+		switch ($orderby) {
1149
+			case 'TKT_name':
1150
+				$orderby = array('TKT_name' => $order);
1151
+				break;
1152
+			case 'TKT_price':
1153
+				$orderby = array('TKT_price' => $order);
1154
+				break;
1155
+			case 'TKT_uses':
1156
+				$orderby = array('TKT_uses' => $order);
1157
+				break;
1158
+			case 'TKT_min':
1159
+				$orderby = array('TKT_min' => $order);
1160
+				break;
1161
+			case 'TKT_max':
1162
+				$orderby = array('TKT_max' => $order);
1163
+				break;
1164
+			case 'TKT_qty':
1165
+				$orderby = array('TKT_qty' => $order);
1166
+				break;
1167
+		}
1168
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1169
+			? $this->_req_data['paged']
1170
+			: 1;
1171
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1172
+			? $this->_req_data['perpage']
1173
+			: $per_page;
1174
+		$_where = array(
1175
+			'TKT_is_default' => 1,
1176
+			'TKT_deleted'    => $trashed,
1177
+		);
1178
+		$offset = ($current_page - 1) * $per_page;
1179
+		$limit = array($offset, $per_page);
1180
+		if (isset($this->_req_data['s'])) {
1181
+			$sstr = '%' . $this->_req_data['s'] . '%';
1182
+			$_where['OR'] = array(
1183
+				'TKT_name'        => array('LIKE', $sstr),
1184
+				'TKT_description' => array('LIKE', $sstr),
1185
+			);
1186
+		}
1187
+		$query_params = array(
1188
+			$_where,
1189
+			'order_by' => $orderby,
1190
+			'limit'    => $limit,
1191
+			'group_by' => 'TKT_ID',
1192
+		);
1193
+		if ($count) {
1194
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1195
+		} else {
1196
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1197
+		}
1198
+	}
1199
+
1200
+
1201
+	/**
1202
+	 * @param bool $trash
1203
+	 * @throws EE_Error
1204
+	 */
1205
+	protected function _trash_or_restore_ticket($trash = false)
1206
+	{
1207
+		$success = 1;
1208
+		$TKT = EEM_Ticket::instance();
1209
+		// checkboxes?
1210
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1211
+			// if array has more than one element then success message should be plural
1212
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1213
+			// cycle thru the boxes
1214
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1215
+				if ($trash) {
1216
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1217
+						$success = 0;
1218
+					}
1219
+				} else {
1220
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1221
+						$success = 0;
1222
+					}
1223
+				}
1224
+			}
1225
+		} else {
1226
+			// grab single id and trash
1227
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1228
+			if ($trash) {
1229
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1230
+					$success = 0;
1231
+				}
1232
+			} else {
1233
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1234
+					$success = 0;
1235
+				}
1236
+			}
1237
+		}
1238
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1239
+		$query_args = array(
1240
+			'action' => 'ticket_list_table',
1241
+			'status' => $trash ? '' : 'trashed',
1242
+		);
1243
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 * Handles trashing default ticket.
1249
+	 */
1250
+	protected function _delete_ticket()
1251
+	{
1252
+		$success = 1;
1253
+		// checkboxes?
1254
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1255
+			// if array has more than one element then success message should be plural
1256
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1257
+			// cycle thru the boxes
1258
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1259
+				// delete
1260
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1261
+					$success = 0;
1262
+				}
1263
+			}
1264
+		} else {
1265
+			// grab single id and trash
1266
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1267
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1268
+				$success = 0;
1269
+			}
1270
+		}
1271
+		$action_desc = 'deleted';
1272
+		$query_args = array(
1273
+			'action' => 'ticket_list_table',
1274
+			'status' => 'trashed',
1275
+		);
1276
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1277
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1278
+			array(array('TKT_is_default' => 1)),
1279
+			'TKT_ID',
1280
+			true
1281
+		)
1282
+		) {
1283
+			$query_args = array();
1284
+		}
1285
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1286
+	}
1287
+
1288
+
1289
+	/**
1290
+	 * @param int $TKT_ID
1291
+	 * @return bool|int
1292
+	 * @throws EE_Error
1293
+	 */
1294
+	protected function _delete_the_ticket($TKT_ID)
1295
+	{
1296
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1297
+		$tkt->_remove_relations('Datetime');
1298
+		// delete all related prices first
1299
+		$tkt->delete_related_permanently('Price');
1300
+		return $tkt->delete_permanently();
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 * @param array $default_event_settings_form_subsections
1306
+	 * @return array
1307
+	 * @since $VID:$
1308
+	 */
1309
+	public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1310
+	{
1311
+		return [
1312
+			'use_advanced_editor'         => new EE_Select_Input(
1313
+				apply_filters(
1314
+					'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_answer_options',
1315
+					[
1316
+						esc_html__('Legacy Editor', 'event_espresso'),
1317
+						esc_html__('Advanced Editor', 'event_espresso'),
1318
+					]
1319
+				),
1320
+				apply_filters(
1321
+					'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_settings',
1322
+					[
1323
+						'default'         => $this->admin_config->useAdvancedEditor(),
1324
+						'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1325
+						'html_help_text'  => sprintf(
1326
+							esc_html__(
1327
+								'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
1328
+								'event_espresso'
1329
+							),
1330
+							'<br />'
1331
+						),
1332
+					]
1333
+				)
1334
+			),
1335
+			'defaults_section_header' => new EE_Form_Section_HTML(
1336
+				EEH_HTML::h2(
1337
+					esc_html__('Default Settings', 'event_espresso'),
1338
+					'',
1339
+					'ee-admin-settings-hdr'
1340
+				)
1341
+			),
1342
+		] + $default_event_settings_form_subsections;
1343
+	}
1344
+
1345
+
1346
+	/**
1347
+	 * @param array     $valid_data
1348
+	 * @param EE_Config $config
1349
+	 * @since $VID:$
1350
+	 */
1351
+	public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1352
+	{
1353
+		$config->admin->setUseAdvancedEditor(
1354
+			isset($valid_data['use_advanced_editor'])
1355
+				? $valid_data['use_advanced_editor']
1356
+				: false
1357
+		);
1358
+	}
1359 1359
 }
Please login to merge, or discard this patch.