Completed
Pull Request — FET/editor-dates-tickets-refac... (#1368)
by
unknown
09:48
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
Indentation   +2137 added lines, -2137 removed lines patch added patch discarded remove patch
@@ -15,2197 +15,2197 @@
 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 (
52
-            EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
53
-            ! EE_Registry::instance()->CAP->current_user_can(
54
-                'ee_read_default_prices',
55
-                'advanced_ticket_datetime_metabox'
56
-            )
57
-        ) {
58
-            return;
59
-        }
60
-        $this->_setup_metaboxes();
61
-        $this->_set_date_time_formats();
62
-        $this->_validate_format_strings();
63
-        $this->_set_scripts_styles();
64
-        // commented out temporarily until logic is implemented in callback
65
-        // add_action(
66
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
67
-        //     array($this, 'autosave_handling')
68
-        // );
69
-        add_filter(
70
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
71
-            array($this, 'caf_updates')
72
-        );
73
-    }
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (
52
+			EE_Registry::instance()->CFG->admin->useAdvancedEditor() ||
53
+			! EE_Registry::instance()->CAP->current_user_can(
54
+				'ee_read_default_prices',
55
+				'advanced_ticket_datetime_metabox'
56
+			)
57
+		) {
58
+			return;
59
+		}
60
+		$this->_setup_metaboxes();
61
+		$this->_set_date_time_formats();
62
+		$this->_validate_format_strings();
63
+		$this->_set_scripts_styles();
64
+		// commented out temporarily until logic is implemented in callback
65
+		// add_action(
66
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
67
+		//     array($this, 'autosave_handling')
68
+		// );
69
+		add_filter(
70
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
71
+			array($this, 'caf_updates')
72
+		);
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * @return void
78
-     */
79
-    protected function _setup_metaboxes()
80
-    {
81
-        // if we were going to add our own metaboxes we'd use the below.
82
-        $this->_metaboxes = array(
83
-            0 => array(
84
-                'page_route' => array('edit', 'create_new'),
85
-                'func'       => 'pricing_metabox',
86
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
87
-                'priority'   => 'high',
88
-                'context'    => 'normal',
89
-            ),
90
-        );
91
-        $this->_remove_metaboxes = array(
92
-            0 => array(
93
-                'page_route' => array('edit', 'create_new'),
94
-                'id'         => 'espresso_event_editor_tickets',
95
-                'context'    => 'normal',
96
-            ),
97
-        );
98
-    }
76
+	/**
77
+	 * @return void
78
+	 */
79
+	protected function _setup_metaboxes()
80
+	{
81
+		// if we were going to add our own metaboxes we'd use the below.
82
+		$this->_metaboxes = array(
83
+			0 => array(
84
+				'page_route' => array('edit', 'create_new'),
85
+				'func'       => 'pricing_metabox',
86
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
87
+				'priority'   => 'high',
88
+				'context'    => 'normal',
89
+			),
90
+		);
91
+		$this->_remove_metaboxes = array(
92
+			0 => array(
93
+				'page_route' => array('edit', 'create_new'),
94
+				'id'         => 'espresso_event_editor_tickets',
95
+				'context'    => 'normal',
96
+			),
97
+		);
98
+	}
99 99
 
100 100
 
101
-    /**
102
-     * @return void
103
-     */
104
-    protected function _set_date_time_formats()
105
-    {
106
-        /**
107
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
108
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
109
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
110
-         *
111
-         * @since 4.6.7
112
-         * @var array  Expected an array returned with 'date' and 'time' keys.
113
-         */
114
-        $this->_date_format_strings = apply_filters(
115
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
116
-            array(
117
-                'date' => 'Y-m-d',
118
-                'time' => 'h:i a',
119
-            )
120
-        );
121
-        // validate
122
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
123
-            ? $this->_date_format_strings['date']
124
-            : null;
125
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
126
-            ? $this->_date_format_strings['time']
127
-            : null;
128
-        $this->_date_time_format = $this->_date_format_strings['date']
129
-                                   . ' '
130
-                                   . $this->_date_format_strings['time'];
131
-    }
101
+	/**
102
+	 * @return void
103
+	 */
104
+	protected function _set_date_time_formats()
105
+	{
106
+		/**
107
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
108
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
109
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
110
+		 *
111
+		 * @since 4.6.7
112
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
113
+		 */
114
+		$this->_date_format_strings = apply_filters(
115
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
116
+			array(
117
+				'date' => 'Y-m-d',
118
+				'time' => 'h:i a',
119
+			)
120
+		);
121
+		// validate
122
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
123
+			? $this->_date_format_strings['date']
124
+			: null;
125
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
126
+			? $this->_date_format_strings['time']
127
+			: null;
128
+		$this->_date_time_format = $this->_date_format_strings['date']
129
+								   . ' '
130
+								   . $this->_date_format_strings['time'];
131
+	}
132 132
 
133 133
 
134
-    /**
135
-     * @return void
136
-     */
137
-    protected function _validate_format_strings()
138
-    {
139
-        // validate format strings
140
-        $format_validation = EEH_DTT_Helper::validate_format_string(
141
-            $this->_date_time_format
142
-        );
143
-        if (is_array($format_validation)) {
144
-            $msg = '<p>';
145
-            $msg .= sprintf(
146
-                esc_html__(
147
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
148
-                    'event_espresso'
149
-                ),
150
-                $this->_date_time_format
151
-            );
152
-            $msg .= '</p><ul>';
153
-            foreach ($format_validation as $error) {
154
-                $msg .= '<li>' . $error . '</li>';
155
-            }
156
-            $msg .= '</ul><p>';
157
-            $msg .= sprintf(
158
-                esc_html__(
159
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
160
-                    'event_espresso'
161
-                ),
162
-                '<span style="color:#D54E21;">',
163
-                '</span>'
164
-            );
165
-            $msg .= '</p>';
166
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
167
-            $this->_date_format_strings = array(
168
-                'date' => 'Y-m-d',
169
-                'time' => 'h:i a',
170
-            );
171
-        }
172
-    }
134
+	/**
135
+	 * @return void
136
+	 */
137
+	protected function _validate_format_strings()
138
+	{
139
+		// validate format strings
140
+		$format_validation = EEH_DTT_Helper::validate_format_string(
141
+			$this->_date_time_format
142
+		);
143
+		if (is_array($format_validation)) {
144
+			$msg = '<p>';
145
+			$msg .= sprintf(
146
+				esc_html__(
147
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
148
+					'event_espresso'
149
+				),
150
+				$this->_date_time_format
151
+			);
152
+			$msg .= '</p><ul>';
153
+			foreach ($format_validation as $error) {
154
+				$msg .= '<li>' . $error . '</li>';
155
+			}
156
+			$msg .= '</ul><p>';
157
+			$msg .= sprintf(
158
+				esc_html__(
159
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
160
+					'event_espresso'
161
+				),
162
+				'<span style="color:#D54E21;">',
163
+				'</span>'
164
+			);
165
+			$msg .= '</p>';
166
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
167
+			$this->_date_format_strings = array(
168
+				'date' => 'Y-m-d',
169
+				'time' => 'h:i a',
170
+			);
171
+		}
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * @return void
177
-     */
178
-    protected function _set_scripts_styles()
179
-    {
180
-        $this->_scripts_styles = array(
181
-            'registers'   => array(
182
-                'ee-tickets-datetimes-css' => array(
183
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
184
-                    'type' => 'css',
185
-                ),
186
-                'ee-dtt-ticket-metabox'    => array(
187
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
188
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
189
-                ),
190
-            ),
191
-            'deregisters' => array(
192
-                'event-editor-css'       => array('type' => 'css'),
193
-                'event-datetime-metabox' => array('type' => 'js'),
194
-            ),
195
-            'enqueues'    => array(
196
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
197
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
198
-            ),
199
-            'localize'    => array(
200
-                'ee-dtt-ticket-metabox' => array(
201
-                    'DTT_TRASH_BLOCK'       => array(
202
-                        'main_warning'            => esc_html__(
203
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
204
-                            'event_espresso'
205
-                        ),
206
-                        'after_warning'           => esc_html__(
207
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
208
-                            'event_espresso'
209
-                        ),
210
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
211
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
212
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
213
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
214
-                        'single_warning_from_tkt' => esc_html__(
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
-                            'event_espresso'
217
-                        ),
218
-                        'single_warning_from_dtt' => esc_html__(
219
-                            '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.',
220
-                            'event_espresso'
221
-                        ),
222
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
223
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
224
-                    ),
225
-                    'DTT_ERROR_MSG'         => array(
226
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
227
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
228
-                                            . '<button class="button-secondary ee-modal-cancel">'
229
-                                            . esc_html__('Dismiss', 'event_espresso')
230
-                                            . '</button></div>',
231
-                    ),
232
-                    'DTT_OVERSELL_WARNING'  => array(
233
-                        'datetime_ticket' => esc_html__(
234
-                            '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.',
235
-                            'event_espresso'
236
-                        ),
237
-                        'ticket_datetime' => esc_html__(
238
-                            '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.',
239
-                            'event_espresso'
240
-                        ),
241
-                    ),
242
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
243
-                        $this->_date_format_strings['date'],
244
-                        $this->_date_format_strings['time']
245
-                    ),
246
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
247
-                ),
248
-            ),
249
-        );
250
-    }
175
+	/**
176
+	 * @return void
177
+	 */
178
+	protected function _set_scripts_styles()
179
+	{
180
+		$this->_scripts_styles = array(
181
+			'registers'   => array(
182
+				'ee-tickets-datetimes-css' => array(
183
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
184
+					'type' => 'css',
185
+				),
186
+				'ee-dtt-ticket-metabox'    => array(
187
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
188
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
189
+				),
190
+			),
191
+			'deregisters' => array(
192
+				'event-editor-css'       => array('type' => 'css'),
193
+				'event-datetime-metabox' => array('type' => 'js'),
194
+			),
195
+			'enqueues'    => array(
196
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
197
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
198
+			),
199
+			'localize'    => array(
200
+				'ee-dtt-ticket-metabox' => array(
201
+					'DTT_TRASH_BLOCK'       => array(
202
+						'main_warning'            => esc_html__(
203
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
204
+							'event_espresso'
205
+						),
206
+						'after_warning'           => esc_html__(
207
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
208
+							'event_espresso'
209
+						),
210
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
211
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
212
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
213
+													 . esc_html__('Close', 'event_espresso') . '</button>',
214
+						'single_warning_from_tkt' => esc_html__(
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
+							'event_espresso'
217
+						),
218
+						'single_warning_from_dtt' => esc_html__(
219
+							'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.',
220
+							'event_espresso'
221
+						),
222
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
223
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
224
+					),
225
+					'DTT_ERROR_MSG'         => array(
226
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
227
+						'dismiss_button' => '<div class="save-cancel-button-container">'
228
+											. '<button class="button-secondary ee-modal-cancel">'
229
+											. esc_html__('Dismiss', 'event_espresso')
230
+											. '</button></div>',
231
+					),
232
+					'DTT_OVERSELL_WARNING'  => array(
233
+						'datetime_ticket' => esc_html__(
234
+							'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.',
235
+							'event_espresso'
236
+						),
237
+						'ticket_datetime' => esc_html__(
238
+							'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.',
239
+							'event_espresso'
240
+						),
241
+					),
242
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
243
+						$this->_date_format_strings['date'],
244
+						$this->_date_format_strings['time']
245
+					),
246
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
247
+				),
248
+			),
249
+		);
250
+	}
251 251
 
252 252
 
253
-    /**
254
-     * @param array $update_callbacks
255
-     * @return array
256
-     */
257
-    public function caf_updates(array $update_callbacks)
258
-    {
259
-        foreach ($update_callbacks as $key => $callback) {
260
-            if ($callback[1] === '_default_tickets_update') {
261
-                unset($update_callbacks[ $key ]);
262
-            }
263
-        }
264
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
265
-        return $update_callbacks;
266
-    }
253
+	/**
254
+	 * @param array $update_callbacks
255
+	 * @return array
256
+	 */
257
+	public function caf_updates(array $update_callbacks)
258
+	{
259
+		foreach ($update_callbacks as $key => $callback) {
260
+			if ($callback[1] === '_default_tickets_update') {
261
+				unset($update_callbacks[ $key ]);
262
+			}
263
+		}
264
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
265
+		return $update_callbacks;
266
+	}
267 267
 
268 268
 
269
-    /**
270
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
271
-     *
272
-     * @param  EE_Event $event The Event object we're attaching data to
273
-     * @param  array    $data  The request data from the form
274
-     * @throws ReflectionException
275
-     * @throws Exception
276
-     * @throws InvalidInterfaceException
277
-     * @throws InvalidDataTypeException
278
-     * @throws EE_Error
279
-     * @throws InvalidArgumentException
280
-     */
281
-    public function datetime_and_tickets_caf_update($event, $data)
282
-    {
283
-        // first we need to start with datetimes cause they are the "root" items attached to events.
284
-        $saved_datetimes = $this->_update_datetimes($event, $data);
285
-        // next tackle the tickets (and prices?)
286
-        $this->_update_tickets($event, $saved_datetimes, $data);
287
-    }
269
+	/**
270
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
271
+	 *
272
+	 * @param  EE_Event $event The Event object we're attaching data to
273
+	 * @param  array    $data  The request data from the form
274
+	 * @throws ReflectionException
275
+	 * @throws Exception
276
+	 * @throws InvalidInterfaceException
277
+	 * @throws InvalidDataTypeException
278
+	 * @throws EE_Error
279
+	 * @throws InvalidArgumentException
280
+	 */
281
+	public function datetime_and_tickets_caf_update($event, $data)
282
+	{
283
+		// first we need to start with datetimes cause they are the "root" items attached to events.
284
+		$saved_datetimes = $this->_update_datetimes($event, $data);
285
+		// next tackle the tickets (and prices?)
286
+		$this->_update_tickets($event, $saved_datetimes, $data);
287
+	}
288 288
 
289 289
 
290
-    /**
291
-     * update event_datetimes
292
-     *
293
-     * @param  EE_Event $event Event being updated
294
-     * @param  array    $data  the request data from the form
295
-     * @return EE_Datetime[]
296
-     * @throws Exception
297
-     * @throws ReflectionException
298
-     * @throws InvalidInterfaceException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidArgumentException
301
-     * @throws EE_Error
302
-     */
303
-    protected function _update_datetimes($event, $data)
304
-    {
305
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
306
-        $saved_dtt_ids = array();
307
-        $saved_dtt_objs = array();
308
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
309
-            throw new InvalidArgumentException(
310
-                esc_html__(
311
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
312
-                    'event_espresso'
313
-                )
314
-            );
315
-        }
316
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
317
-            // trim all values to ensure any excess whitespace is removed.
318
-            $datetime_data = array_map(
319
-                function ($datetime_data) {
320
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
321
-                },
322
-                $datetime_data
323
-            );
324
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
325
-                                            && ! empty($datetime_data['DTT_EVT_end'])
326
-                ? $datetime_data['DTT_EVT_end']
327
-                : $datetime_data['DTT_EVT_start'];
328
-            $datetime_values = array(
329
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
330
-                    ? $datetime_data['DTT_ID']
331
-                    : null,
332
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
333
-                    ? $datetime_data['DTT_name']
334
-                    : '',
335
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
336
-                    ? $datetime_data['DTT_description']
337
-                    : '',
338
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
339
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
340
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
341
-                    ? EE_INF
342
-                    : $datetime_data['DTT_reg_limit'],
343
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
344
-                    ? $row
345
-                    : $datetime_data['DTT_order'],
346
-            );
347
-            // if we have an id then let's get existing object first and then set the new values.
348
-            // Otherwise we instantiate a new object for save.
349
-            if (! empty($datetime_data['DTT_ID'])) {
350
-                $datetime = EE_Registry::instance()
351
-                                       ->load_model('Datetime', array($timezone))
352
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
353
-                // set date and time format according to what is set in this class.
354
-                $datetime->set_date_format($this->_date_format_strings['date']);
355
-                $datetime->set_time_format($this->_date_format_strings['time']);
356
-                foreach ($datetime_values as $field => $value) {
357
-                    $datetime->set($field, $value);
358
-                }
359
-                // make sure the $dtt_id here is saved just in case
360
-                // after the add_relation_to() the autosave replaces it.
361
-                // We need to do this so we dont' TRASH the parent DTT.
362
-                // (save the ID for both key and value to avoid duplications)
363
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
364
-            } else {
365
-                $datetime = EE_Registry::instance()->load_class(
366
-                    'Datetime',
367
-                    array(
368
-                        $datetime_values,
369
-                        $timezone,
370
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
371
-                    ),
372
-                    false,
373
-                    false
374
-                );
375
-                foreach ($datetime_values as $field => $value) {
376
-                    $datetime->set($field, $value);
377
-                }
378
-            }
379
-            $datetime->save();
380
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
381
-            // before going any further make sure our dates are setup correctly
382
-            // so that the end date is always equal or greater than the start date.
383
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
384
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
385
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
386
-                $datetime->save();
387
-            }
388
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
389
-            // because it is possible there was a new one created for the autosave.
390
-            // (save the ID for both key and value to avoid duplications)
391
-            $DTT_ID = $datetime->ID();
392
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
393
-            $saved_dtt_objs[ $row ] = $datetime;
394
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
395
-        }
396
-        $event->save();
397
-        // now we need to REMOVE any datetimes that got deleted.
398
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
399
-        // So its safe to permanently delete at this point.
400
-        $old_datetimes = explode(',', $data['datetime_IDs']);
401
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
402
-        if (is_array($old_datetimes)) {
403
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
404
-            foreach ($datetimes_to_delete as $id) {
405
-                $id = absint($id);
406
-                if (empty($id)) {
407
-                    continue;
408
-                }
409
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
410
-                // remove tkt relationships.
411
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
412
-                foreach ($related_tickets as $tkt) {
413
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
414
-                }
415
-                $event->_remove_relation_to($id, 'Datetime');
416
-                $dtt_to_remove->refresh_cache_of_related_objects();
417
-            }
418
-        }
419
-        return $saved_dtt_objs;
420
-    }
290
+	/**
291
+	 * update event_datetimes
292
+	 *
293
+	 * @param  EE_Event $event Event being updated
294
+	 * @param  array    $data  the request data from the form
295
+	 * @return EE_Datetime[]
296
+	 * @throws Exception
297
+	 * @throws ReflectionException
298
+	 * @throws InvalidInterfaceException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidArgumentException
301
+	 * @throws EE_Error
302
+	 */
303
+	protected function _update_datetimes($event, $data)
304
+	{
305
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
306
+		$saved_dtt_ids = array();
307
+		$saved_dtt_objs = array();
308
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
309
+			throw new InvalidArgumentException(
310
+				esc_html__(
311
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
312
+					'event_espresso'
313
+				)
314
+			);
315
+		}
316
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
317
+			// trim all values to ensure any excess whitespace is removed.
318
+			$datetime_data = array_map(
319
+				function ($datetime_data) {
320
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
321
+				},
322
+				$datetime_data
323
+			);
324
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
325
+											&& ! empty($datetime_data['DTT_EVT_end'])
326
+				? $datetime_data['DTT_EVT_end']
327
+				: $datetime_data['DTT_EVT_start'];
328
+			$datetime_values = array(
329
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
330
+					? $datetime_data['DTT_ID']
331
+					: null,
332
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
333
+					? $datetime_data['DTT_name']
334
+					: '',
335
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
336
+					? $datetime_data['DTT_description']
337
+					: '',
338
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
339
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
340
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
341
+					? EE_INF
342
+					: $datetime_data['DTT_reg_limit'],
343
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
344
+					? $row
345
+					: $datetime_data['DTT_order'],
346
+			);
347
+			// if we have an id then let's get existing object first and then set the new values.
348
+			// Otherwise we instantiate a new object for save.
349
+			if (! empty($datetime_data['DTT_ID'])) {
350
+				$datetime = EE_Registry::instance()
351
+									   ->load_model('Datetime', array($timezone))
352
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
353
+				// set date and time format according to what is set in this class.
354
+				$datetime->set_date_format($this->_date_format_strings['date']);
355
+				$datetime->set_time_format($this->_date_format_strings['time']);
356
+				foreach ($datetime_values as $field => $value) {
357
+					$datetime->set($field, $value);
358
+				}
359
+				// make sure the $dtt_id here is saved just in case
360
+				// after the add_relation_to() the autosave replaces it.
361
+				// We need to do this so we dont' TRASH the parent DTT.
362
+				// (save the ID for both key and value to avoid duplications)
363
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
364
+			} else {
365
+				$datetime = EE_Registry::instance()->load_class(
366
+					'Datetime',
367
+					array(
368
+						$datetime_values,
369
+						$timezone,
370
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
371
+					),
372
+					false,
373
+					false
374
+				);
375
+				foreach ($datetime_values as $field => $value) {
376
+					$datetime->set($field, $value);
377
+				}
378
+			}
379
+			$datetime->save();
380
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
381
+			// before going any further make sure our dates are setup correctly
382
+			// so that the end date is always equal or greater than the start date.
383
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
384
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
385
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
386
+				$datetime->save();
387
+			}
388
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
389
+			// because it is possible there was a new one created for the autosave.
390
+			// (save the ID for both key and value to avoid duplications)
391
+			$DTT_ID = $datetime->ID();
392
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
393
+			$saved_dtt_objs[ $row ] = $datetime;
394
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
395
+		}
396
+		$event->save();
397
+		// now we need to REMOVE any datetimes that got deleted.
398
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
399
+		// So its safe to permanently delete at this point.
400
+		$old_datetimes = explode(',', $data['datetime_IDs']);
401
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
402
+		if (is_array($old_datetimes)) {
403
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
404
+			foreach ($datetimes_to_delete as $id) {
405
+				$id = absint($id);
406
+				if (empty($id)) {
407
+					continue;
408
+				}
409
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
410
+				// remove tkt relationships.
411
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
412
+				foreach ($related_tickets as $tkt) {
413
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
414
+				}
415
+				$event->_remove_relation_to($id, 'Datetime');
416
+				$dtt_to_remove->refresh_cache_of_related_objects();
417
+			}
418
+		}
419
+		return $saved_dtt_objs;
420
+	}
421 421
 
422 422
 
423
-    /**
424
-     * update tickets
425
-     *
426
-     * @param  EE_Event      $event           Event object being updated
427
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
428
-     * @param  array         $data            incoming request data
429
-     * @return EE_Ticket[]
430
-     * @throws Exception
431
-     * @throws ReflectionException
432
-     * @throws InvalidInterfaceException
433
-     * @throws InvalidDataTypeException
434
-     * @throws InvalidArgumentException
435
-     * @throws EE_Error
436
-     */
437
-    protected function _update_tickets($event, $saved_datetimes, $data)
438
-    {
439
-        $new_tkt = null;
440
-        $new_default = null;
441
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
442
-        $data = stripslashes_deep($data);
443
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
444
-        $saved_tickets = $datetimes_on_existing = array();
445
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
446
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
447
-            throw new InvalidArgumentException(
448
-                esc_html__(
449
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
450
-                    'event_espresso'
451
-                )
452
-            );
453
-        }
454
-        foreach ($data['edit_tickets'] as $row => $tkt) {
455
-            $update_prices = $create_new_TKT = false;
456
-            // figure out what datetimes were added to the ticket
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 ]);
460
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
461
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
462
-            // trim inputs to ensure any excess whitespace is removed.
463
-            $tkt = array_map(
464
-                function ($ticket_data) {
465
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
466
-                },
467
-                $tkt
468
-            );
469
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
470
-            // because we're doing calculations prior to using the models.
471
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
472
-            $ticket_price = isset($tkt['TKT_price'])
473
-                ? round((float) $tkt['TKT_price'], 3)
474
-                : 0;
475
-            // note incoming base price needs converted from localized value.
476
-            $base_price = isset($tkt['TKT_base_price'])
477
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
478
-                : 0;
479
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
480
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
481
-                ? $base_price
482
-                : $ticket_price;
483
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
484
-                ? $tkt['TKT_base_price_ID']
485
-                : 0;
486
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
487
-                ? $data['edit_prices'][ $row ]
488
-                : array();
489
-            $now = null;
490
-            if (empty($tkt['TKT_start_date'])) {
491
-                // lets' use now in the set timezone.
492
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
493
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
494
-            }
495
-            if (empty($tkt['TKT_end_date'])) {
496
-                /**
497
-                 * set the TKT_end_date to the first datetime attached to the ticket.
498
-                 */
499
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
500
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
501
-            }
502
-            $TKT_values = array(
503
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
504
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
505
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
506
-                'TKT_description' => ! empty($tkt['TKT_description'])
507
-                                     && $tkt['TKT_description'] !== esc_html__(
508
-                                         'You can modify this description',
509
-                                         'event_espresso'
510
-                                     )
511
-                    ? $tkt['TKT_description']
512
-                    : '',
513
-                'TKT_start_date'  => $tkt['TKT_start_date'],
514
-                'TKT_end_date'    => $tkt['TKT_end_date'],
515
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
516
-                    ? EE_INF
517
-                    : $tkt['TKT_qty'],
518
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
519
-                    ? EE_INF
520
-                    : $tkt['TKT_uses'],
521
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
522
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
523
-                'TKT_row'         => $row,
524
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
525
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
526
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
527
-                'TKT_price'       => $ticket_price,
528
-            );
529
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
530
-            // which means in turn that the prices will become new prices as well.
531
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
532
-                $TKT_values['TKT_ID'] = 0;
533
-                $TKT_values['TKT_is_default'] = 0;
534
-                $update_prices = true;
535
-            }
536
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
537
-            // we actually do our saves ahead of doing any add_relations to
538
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
539
-            // but DID have it's items modified.
540
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
541
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
542
-            if (absint($TKT_values['TKT_ID'])) {
543
-                $ticket = EE_Registry::instance()
544
-                                     ->load_model('Ticket', array($timezone))
545
-                                     ->get_one_by_ID($tkt['TKT_ID']);
546
-                if ($ticket instanceof EE_Ticket) {
547
-                    $ticket = $this->_update_ticket_datetimes(
548
-                        $ticket,
549
-                        $saved_datetimes,
550
-                        $datetimes_added,
551
-                        $datetimes_removed
552
-                    );
553
-                    // are there any registrations using this ticket ?
554
-                    $tickets_sold = $ticket->count_related(
555
-                        'Registration',
556
-                        array(
557
-                            array(
558
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
559
-                            ),
560
-                        )
561
-                    );
562
-                    // set ticket formats
563
-                    $ticket->set_date_format($this->_date_format_strings['date']);
564
-                    $ticket->set_time_format($this->_date_format_strings['time']);
565
-                    // let's just check the total price for the existing ticket
566
-                    // and determine if it matches the new total price.
567
-                    // if they are different then we create a new ticket (if tickets sold)
568
-                    // if they aren't different then we go ahead and modify existing ticket.
569
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
570
-                    // set new values
571
-                    foreach ($TKT_values as $field => $value) {
572
-                        if ($field === 'TKT_qty') {
573
-                            $ticket->set_qty($value);
574
-                        } else {
575
-                            $ticket->set($field, $value);
576
-                        }
577
-                    }
578
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
579
-                    // Otherwise we have to create a new ticket.
580
-                    if ($create_new_TKT) {
581
-                        $new_tkt = $this->_duplicate_ticket(
582
-                            $ticket,
583
-                            $price_rows,
584
-                            $ticket_price,
585
-                            $base_price,
586
-                            $base_price_id
587
-                        );
588
-                    }
589
-                }
590
-            } else {
591
-                // no TKT_id so a new TKT
592
-                $ticket = EE_Ticket::new_instance(
593
-                    $TKT_values,
594
-                    $timezone,
595
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
596
-                );
597
-                if ($ticket instanceof EE_Ticket) {
598
-                    // make sure ticket has an ID of setting relations won't work
599
-                    $ticket->save();
600
-                    $ticket = $this->_update_ticket_datetimes(
601
-                        $ticket,
602
-                        $saved_datetimes,
603
-                        $datetimes_added,
604
-                        $datetimes_removed
605
-                    );
606
-                    $update_prices = true;
607
-                }
608
-            }
609
-            // make sure any current values have been saved.
610
-            // $ticket->save();
611
-            // before going any further make sure our dates are setup correctly
612
-            // so that the end date is always equal or greater than the start date.
613
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
614
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
615
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
616
-            }
617
-            // let's make sure the base price is handled
618
-            $ticket = ! $create_new_TKT
619
-                ? $this->_add_prices_to_ticket(
620
-                    array(),
621
-                    $ticket,
622
-                    $update_prices,
623
-                    $base_price,
624
-                    $base_price_id
625
-                )
626
-                : $ticket;
627
-            // add/update price_modifiers
628
-            $ticket = ! $create_new_TKT
629
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
630
-                : $ticket;
631
-            // need to make sue that the TKT_price is accurate after saving the prices.
632
-            $ticket->ensure_TKT_Price_correct();
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'])) {
635
-                $update_prices = true;
636
-                $new_default = clone $ticket;
637
-                $new_default->set('TKT_ID', 0);
638
-                $new_default->set('TKT_is_default', 1);
639
-                $new_default->set('TKT_row', 1);
640
-                $new_default->set('TKT_price', $ticket_price);
641
-                // remove any dtt relations cause we DON'T want dtt relations attached
642
-                // (note this is just removing the cached relations in the object)
643
-                $new_default->_remove_relations('Datetime');
644
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
645
-                $new_default = $this->_add_prices_to_ticket(
646
-                    $price_rows,
647
-                    $new_default,
648
-                    $update_prices
649
-                );
650
-                // don't forget the base price!
651
-                $new_default = $this->_add_prices_to_ticket(
652
-                    array(),
653
-                    $new_default,
654
-                    $update_prices,
655
-                    $base_price,
656
-                    $base_price_id
657
-                );
658
-                $new_default->save();
659
-                do_action(
660
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
661
-                    $new_default,
662
-                    $row,
663
-                    $ticket,
664
-                    $data
665
-                );
666
-            }
667
-            // DO ALL dtt relationships for both current tickets and any archived tickets
668
-            // for the given dtt that are related to the current ticket.
669
-            // TODO... not sure exactly how we're going to do this considering we don't know
670
-            // what current ticket the archived tickets are related to
671
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
672
-            // let's assign any tickets that have been setup to the saved_tickets tracker
673
-            // save existing TKT
674
-            $ticket->save();
675
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
676
-                // save new TKT
677
-                $new_tkt->save();
678
-                // add new ticket to array
679
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
680
-                do_action(
681
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
682
-                    $new_tkt,
683
-                    $row,
684
-                    $tkt,
685
-                    $data
686
-                );
687
-            } else {
688
-                // add tkt to saved tkts
689
-                $saved_tickets[ $ticket->ID() ] = $ticket;
690
-                do_action(
691
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
692
-                    $ticket,
693
-                    $row,
694
-                    $tkt,
695
-                    $data
696
-                );
697
-            }
698
-        }
699
-        // now we need to handle tickets actually "deleted permanently".
700
-        // There are cases where we'd want this to happen
701
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
702
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
703
-        // No sense in keeping all the related data in the db!
704
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
705
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
706
-        foreach ($tickets_removed as $id) {
707
-            $id = absint($id);
708
-            // get the ticket for this id
709
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
710
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
711
-            if ($tkt_to_remove->get('TKT_is_default')) {
712
-                continue;
713
-            }
714
-            // if this tkt has any registrations attached so then we just ARCHIVE
715
-            // because we don't actually permanently delete these tickets.
716
-            if ($tkt_to_remove->count_related('Registration') > 0) {
717
-                $tkt_to_remove->delete();
718
-                continue;
719
-            }
720
-            // need to get all the related datetimes on this ticket and remove from every single one of them
721
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
722
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
723
-            foreach ($datetimes as $datetime) {
724
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
725
-            }
726
-            // need to do the same for prices (except these prices can also be deleted because again,
727
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
728
-            $tkt_to_remove->delete_related_permanently('Price');
729
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
730
-            // finally let's delete this ticket
731
-            // (which should not be blocked at this point b/c we've removed all our relationships)
732
-            $tkt_to_remove->delete_permanently();
733
-        }
734
-        return $saved_tickets;
735
-    }
423
+	/**
424
+	 * update tickets
425
+	 *
426
+	 * @param  EE_Event      $event           Event object being updated
427
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
428
+	 * @param  array         $data            incoming request data
429
+	 * @return EE_Ticket[]
430
+	 * @throws Exception
431
+	 * @throws ReflectionException
432
+	 * @throws InvalidInterfaceException
433
+	 * @throws InvalidDataTypeException
434
+	 * @throws InvalidArgumentException
435
+	 * @throws EE_Error
436
+	 */
437
+	protected function _update_tickets($event, $saved_datetimes, $data)
438
+	{
439
+		$new_tkt = null;
440
+		$new_default = null;
441
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
442
+		$data = stripslashes_deep($data);
443
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
444
+		$saved_tickets = $datetimes_on_existing = array();
445
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
446
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
447
+			throw new InvalidArgumentException(
448
+				esc_html__(
449
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
450
+					'event_espresso'
451
+				)
452
+			);
453
+		}
454
+		foreach ($data['edit_tickets'] as $row => $tkt) {
455
+			$update_prices = $create_new_TKT = false;
456
+			// figure out what datetimes were added to the ticket
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 ]);
460
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
461
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
462
+			// trim inputs to ensure any excess whitespace is removed.
463
+			$tkt = array_map(
464
+				function ($ticket_data) {
465
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
466
+				},
467
+				$tkt
468
+			);
469
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
470
+			// because we're doing calculations prior to using the models.
471
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
472
+			$ticket_price = isset($tkt['TKT_price'])
473
+				? round((float) $tkt['TKT_price'], 3)
474
+				: 0;
475
+			// note incoming base price needs converted from localized value.
476
+			$base_price = isset($tkt['TKT_base_price'])
477
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
478
+				: 0;
479
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
480
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
481
+				? $base_price
482
+				: $ticket_price;
483
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
484
+				? $tkt['TKT_base_price_ID']
485
+				: 0;
486
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
487
+				? $data['edit_prices'][ $row ]
488
+				: array();
489
+			$now = null;
490
+			if (empty($tkt['TKT_start_date'])) {
491
+				// lets' use now in the set timezone.
492
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
493
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
494
+			}
495
+			if (empty($tkt['TKT_end_date'])) {
496
+				/**
497
+				 * set the TKT_end_date to the first datetime attached to the ticket.
498
+				 */
499
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
500
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
501
+			}
502
+			$TKT_values = array(
503
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
504
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
505
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
506
+				'TKT_description' => ! empty($tkt['TKT_description'])
507
+									 && $tkt['TKT_description'] !== esc_html__(
508
+										 'You can modify this description',
509
+										 'event_espresso'
510
+									 )
511
+					? $tkt['TKT_description']
512
+					: '',
513
+				'TKT_start_date'  => $tkt['TKT_start_date'],
514
+				'TKT_end_date'    => $tkt['TKT_end_date'],
515
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
516
+					? EE_INF
517
+					: $tkt['TKT_qty'],
518
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
519
+					? EE_INF
520
+					: $tkt['TKT_uses'],
521
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
522
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
523
+				'TKT_row'         => $row,
524
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
525
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
526
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
527
+				'TKT_price'       => $ticket_price,
528
+			);
529
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
530
+			// which means in turn that the prices will become new prices as well.
531
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
532
+				$TKT_values['TKT_ID'] = 0;
533
+				$TKT_values['TKT_is_default'] = 0;
534
+				$update_prices = true;
535
+			}
536
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
537
+			// we actually do our saves ahead of doing any add_relations to
538
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
539
+			// but DID have it's items modified.
540
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
541
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
542
+			if (absint($TKT_values['TKT_ID'])) {
543
+				$ticket = EE_Registry::instance()
544
+									 ->load_model('Ticket', array($timezone))
545
+									 ->get_one_by_ID($tkt['TKT_ID']);
546
+				if ($ticket instanceof EE_Ticket) {
547
+					$ticket = $this->_update_ticket_datetimes(
548
+						$ticket,
549
+						$saved_datetimes,
550
+						$datetimes_added,
551
+						$datetimes_removed
552
+					);
553
+					// are there any registrations using this ticket ?
554
+					$tickets_sold = $ticket->count_related(
555
+						'Registration',
556
+						array(
557
+							array(
558
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
559
+							),
560
+						)
561
+					);
562
+					// set ticket formats
563
+					$ticket->set_date_format($this->_date_format_strings['date']);
564
+					$ticket->set_time_format($this->_date_format_strings['time']);
565
+					// let's just check the total price for the existing ticket
566
+					// and determine if it matches the new total price.
567
+					// if they are different then we create a new ticket (if tickets sold)
568
+					// if they aren't different then we go ahead and modify existing ticket.
569
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
570
+					// set new values
571
+					foreach ($TKT_values as $field => $value) {
572
+						if ($field === 'TKT_qty') {
573
+							$ticket->set_qty($value);
574
+						} else {
575
+							$ticket->set($field, $value);
576
+						}
577
+					}
578
+					// if $create_new_TKT is false then we can safely update the existing ticket.
579
+					// Otherwise we have to create a new ticket.
580
+					if ($create_new_TKT) {
581
+						$new_tkt = $this->_duplicate_ticket(
582
+							$ticket,
583
+							$price_rows,
584
+							$ticket_price,
585
+							$base_price,
586
+							$base_price_id
587
+						);
588
+					}
589
+				}
590
+			} else {
591
+				// no TKT_id so a new TKT
592
+				$ticket = EE_Ticket::new_instance(
593
+					$TKT_values,
594
+					$timezone,
595
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
596
+				);
597
+				if ($ticket instanceof EE_Ticket) {
598
+					// make sure ticket has an ID of setting relations won't work
599
+					$ticket->save();
600
+					$ticket = $this->_update_ticket_datetimes(
601
+						$ticket,
602
+						$saved_datetimes,
603
+						$datetimes_added,
604
+						$datetimes_removed
605
+					);
606
+					$update_prices = true;
607
+				}
608
+			}
609
+			// make sure any current values have been saved.
610
+			// $ticket->save();
611
+			// before going any further make sure our dates are setup correctly
612
+			// so that the end date is always equal or greater than the start date.
613
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
614
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
615
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
616
+			}
617
+			// let's make sure the base price is handled
618
+			$ticket = ! $create_new_TKT
619
+				? $this->_add_prices_to_ticket(
620
+					array(),
621
+					$ticket,
622
+					$update_prices,
623
+					$base_price,
624
+					$base_price_id
625
+				)
626
+				: $ticket;
627
+			// add/update price_modifiers
628
+			$ticket = ! $create_new_TKT
629
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
630
+				: $ticket;
631
+			// need to make sue that the TKT_price is accurate after saving the prices.
632
+			$ticket->ensure_TKT_Price_correct();
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'])) {
635
+				$update_prices = true;
636
+				$new_default = clone $ticket;
637
+				$new_default->set('TKT_ID', 0);
638
+				$new_default->set('TKT_is_default', 1);
639
+				$new_default->set('TKT_row', 1);
640
+				$new_default->set('TKT_price', $ticket_price);
641
+				// remove any dtt relations cause we DON'T want dtt relations attached
642
+				// (note this is just removing the cached relations in the object)
643
+				$new_default->_remove_relations('Datetime');
644
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
645
+				$new_default = $this->_add_prices_to_ticket(
646
+					$price_rows,
647
+					$new_default,
648
+					$update_prices
649
+				);
650
+				// don't forget the base price!
651
+				$new_default = $this->_add_prices_to_ticket(
652
+					array(),
653
+					$new_default,
654
+					$update_prices,
655
+					$base_price,
656
+					$base_price_id
657
+				);
658
+				$new_default->save();
659
+				do_action(
660
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
661
+					$new_default,
662
+					$row,
663
+					$ticket,
664
+					$data
665
+				);
666
+			}
667
+			// DO ALL dtt relationships for both current tickets and any archived tickets
668
+			// for the given dtt that are related to the current ticket.
669
+			// TODO... not sure exactly how we're going to do this considering we don't know
670
+			// what current ticket the archived tickets are related to
671
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
672
+			// let's assign any tickets that have been setup to the saved_tickets tracker
673
+			// save existing TKT
674
+			$ticket->save();
675
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
676
+				// save new TKT
677
+				$new_tkt->save();
678
+				// add new ticket to array
679
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
680
+				do_action(
681
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
682
+					$new_tkt,
683
+					$row,
684
+					$tkt,
685
+					$data
686
+				);
687
+			} else {
688
+				// add tkt to saved tkts
689
+				$saved_tickets[ $ticket->ID() ] = $ticket;
690
+				do_action(
691
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
692
+					$ticket,
693
+					$row,
694
+					$tkt,
695
+					$data
696
+				);
697
+			}
698
+		}
699
+		// now we need to handle tickets actually "deleted permanently".
700
+		// There are cases where we'd want this to happen
701
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
702
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
703
+		// No sense in keeping all the related data in the db!
704
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
705
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
706
+		foreach ($tickets_removed as $id) {
707
+			$id = absint($id);
708
+			// get the ticket for this id
709
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
710
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
711
+			if ($tkt_to_remove->get('TKT_is_default')) {
712
+				continue;
713
+			}
714
+			// if this tkt has any registrations attached so then we just ARCHIVE
715
+			// because we don't actually permanently delete these tickets.
716
+			if ($tkt_to_remove->count_related('Registration') > 0) {
717
+				$tkt_to_remove->delete();
718
+				continue;
719
+			}
720
+			// need to get all the related datetimes on this ticket and remove from every single one of them
721
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
722
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
723
+			foreach ($datetimes as $datetime) {
724
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
725
+			}
726
+			// need to do the same for prices (except these prices can also be deleted because again,
727
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
728
+			$tkt_to_remove->delete_related_permanently('Price');
729
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
730
+			// finally let's delete this ticket
731
+			// (which should not be blocked at this point b/c we've removed all our relationships)
732
+			$tkt_to_remove->delete_permanently();
733
+		}
734
+		return $saved_tickets;
735
+	}
736 736
 
737 737
 
738
-    /**
739
-     * @access  protected
740
-     * @param EE_Ticket      $ticket
741
-     * @param \EE_Datetime[] $saved_datetimes
742
-     * @param \EE_Datetime[] $added_datetimes
743
-     * @param \EE_Datetime[] $removed_datetimes
744
-     * @return EE_Ticket
745
-     * @throws EE_Error
746
-     */
747
-    protected function _update_ticket_datetimes(
748
-        EE_Ticket $ticket,
749
-        $saved_datetimes = array(),
750
-        $added_datetimes = array(),
751
-        $removed_datetimes = array()
752
-    ) {
753
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
754
-        // and removing the ticket from datetimes it got removed from.
755
-        // first let's add datetimes
756
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
757
-            foreach ($added_datetimes as $row_id) {
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');
761
-                    // Is this an existing ticket (has an ID) and does it have any sold?
762
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
763
-                    if ($ticket->ID() && $ticket->sold() > 0) {
764
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
765
-                    }
766
-                }
767
-            }
768
-        }
769
-        // then remove datetimes
770
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
771
-            foreach ($removed_datetimes as $row_id) {
772
-                $row_id = (int) $row_id;
773
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
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');
777
-                    // Is this an existing ticket (has an ID) and does it have any sold?
778
-                    // If so, then we need to remove it's sold from the DTT_sold.
779
-                    if ($ticket->ID() && $ticket->sold() > 0) {
780
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
781
-                    }
782
-                }
783
-            }
784
-        }
785
-        // cap ticket qty by datetime reg limits
786
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
787
-        return $ticket;
788
-    }
738
+	/**
739
+	 * @access  protected
740
+	 * @param EE_Ticket      $ticket
741
+	 * @param \EE_Datetime[] $saved_datetimes
742
+	 * @param \EE_Datetime[] $added_datetimes
743
+	 * @param \EE_Datetime[] $removed_datetimes
744
+	 * @return EE_Ticket
745
+	 * @throws EE_Error
746
+	 */
747
+	protected function _update_ticket_datetimes(
748
+		EE_Ticket $ticket,
749
+		$saved_datetimes = array(),
750
+		$added_datetimes = array(),
751
+		$removed_datetimes = array()
752
+	) {
753
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
754
+		// and removing the ticket from datetimes it got removed from.
755
+		// first let's add datetimes
756
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
757
+			foreach ($added_datetimes as $row_id) {
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');
761
+					// Is this an existing ticket (has an ID) and does it have any sold?
762
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
763
+					if ($ticket->ID() && $ticket->sold() > 0) {
764
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
765
+					}
766
+				}
767
+			}
768
+		}
769
+		// then remove datetimes
770
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
771
+			foreach ($removed_datetimes as $row_id) {
772
+				$row_id = (int) $row_id;
773
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
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');
777
+					// Is this an existing ticket (has an ID) and does it have any sold?
778
+					// If so, then we need to remove it's sold from the DTT_sold.
779
+					if ($ticket->ID() && $ticket->sold() > 0) {
780
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
781
+					}
782
+				}
783
+			}
784
+		}
785
+		// cap ticket qty by datetime reg limits
786
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
787
+		return $ticket;
788
+	}
789 789
 
790 790
 
791
-    /**
792
-     * @access  protected
793
-     * @param EE_Ticket $ticket
794
-     * @param array     $price_rows
795
-     * @param int       $ticket_price
796
-     * @param int       $base_price
797
-     * @param int       $base_price_id
798
-     * @return EE_Ticket
799
-     * @throws ReflectionException
800
-     * @throws InvalidArgumentException
801
-     * @throws InvalidInterfaceException
802
-     * @throws InvalidDataTypeException
803
-     * @throws EE_Error
804
-     */
805
-    protected function _duplicate_ticket(
806
-        EE_Ticket $ticket,
807
-        $price_rows = array(),
808
-        $ticket_price = 0,
809
-        $base_price = 0,
810
-        $base_price_id = 0
811
-    ) {
812
-        // create new ticket that's a copy of the existing
813
-        // except a new id of course (and not archived)
814
-        // AND has the new TKT_price associated with it.
815
-        $new_ticket = clone $ticket;
816
-        $new_ticket->set('TKT_ID', 0);
817
-        $new_ticket->set_deleted(0);
818
-        $new_ticket->set_price($ticket_price);
819
-        $new_ticket->set_sold(0);
820
-        // let's get a new ID for this ticket
821
-        $new_ticket->save();
822
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
823
-        $datetimes_on_existing = $ticket->datetimes();
824
-        $new_ticket = $this->_update_ticket_datetimes(
825
-            $new_ticket,
826
-            $datetimes_on_existing,
827
-            array_keys($datetimes_on_existing)
828
-        );
829
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
830
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
831
-        // available.
832
-        if ($ticket->sold() > 0) {
833
-            $new_qty = $ticket->qty() - $ticket->sold();
834
-            $new_ticket->set_qty($new_qty);
835
-        }
836
-        // now we update the prices just for this ticket
837
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
838
-        // and we update the base price
839
-        $new_ticket = $this->_add_prices_to_ticket(
840
-            array(),
841
-            $new_ticket,
842
-            true,
843
-            $base_price,
844
-            $base_price_id
845
-        );
846
-        return $new_ticket;
847
-    }
791
+	/**
792
+	 * @access  protected
793
+	 * @param EE_Ticket $ticket
794
+	 * @param array     $price_rows
795
+	 * @param int       $ticket_price
796
+	 * @param int       $base_price
797
+	 * @param int       $base_price_id
798
+	 * @return EE_Ticket
799
+	 * @throws ReflectionException
800
+	 * @throws InvalidArgumentException
801
+	 * @throws InvalidInterfaceException
802
+	 * @throws InvalidDataTypeException
803
+	 * @throws EE_Error
804
+	 */
805
+	protected function _duplicate_ticket(
806
+		EE_Ticket $ticket,
807
+		$price_rows = array(),
808
+		$ticket_price = 0,
809
+		$base_price = 0,
810
+		$base_price_id = 0
811
+	) {
812
+		// create new ticket that's a copy of the existing
813
+		// except a new id of course (and not archived)
814
+		// AND has the new TKT_price associated with it.
815
+		$new_ticket = clone $ticket;
816
+		$new_ticket->set('TKT_ID', 0);
817
+		$new_ticket->set_deleted(0);
818
+		$new_ticket->set_price($ticket_price);
819
+		$new_ticket->set_sold(0);
820
+		// let's get a new ID for this ticket
821
+		$new_ticket->save();
822
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
823
+		$datetimes_on_existing = $ticket->datetimes();
824
+		$new_ticket = $this->_update_ticket_datetimes(
825
+			$new_ticket,
826
+			$datetimes_on_existing,
827
+			array_keys($datetimes_on_existing)
828
+		);
829
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
830
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
831
+		// available.
832
+		if ($ticket->sold() > 0) {
833
+			$new_qty = $ticket->qty() - $ticket->sold();
834
+			$new_ticket->set_qty($new_qty);
835
+		}
836
+		// now we update the prices just for this ticket
837
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
838
+		// and we update the base price
839
+		$new_ticket = $this->_add_prices_to_ticket(
840
+			array(),
841
+			$new_ticket,
842
+			true,
843
+			$base_price,
844
+			$base_price_id
845
+		);
846
+		return $new_ticket;
847
+	}
848 848
 
849 849
 
850
-    /**
851
-     * This attaches a list of given prices to a ticket.
852
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
853
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
854
-     * price info and prices are automatically "archived" via the ticket.
855
-     *
856
-     * @access  private
857
-     * @param array     $prices        Array of prices from the form.
858
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
859
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
860
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
861
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
862
-     * @return EE_Ticket
863
-     * @throws ReflectionException
864
-     * @throws InvalidArgumentException
865
-     * @throws InvalidInterfaceException
866
-     * @throws InvalidDataTypeException
867
-     * @throws EE_Error
868
-     */
869
-    protected function _add_prices_to_ticket(
870
-        $prices = array(),
871
-        EE_Ticket $ticket,
872
-        $new_prices = false,
873
-        $base_price = false,
874
-        $base_price_id = false
875
-    ) {
876
-        // let's just get any current prices that may exist on the given ticket
877
-        // so we can remove any prices that got trashed in this session.
878
-        $current_prices_on_ticket = $base_price !== false
879
-            ? $ticket->base_price(true)
880
-            : $ticket->price_modifiers();
881
-        $updated_prices = array();
882
-        // if $base_price ! FALSE then updating a base price.
883
-        if ($base_price !== false) {
884
-            $prices[1] = array(
885
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
886
-                'PRT_ID'     => 1,
887
-                'PRC_amount' => $base_price,
888
-                'PRC_name'   => $ticket->get('TKT_name'),
889
-                'PRC_desc'   => $ticket->get('TKT_description'),
890
-            );
891
-        }
892
-        // possibly need to save tkt
893
-        if (! $ticket->ID()) {
894
-            $ticket->save();
895
-        }
896
-        foreach ($prices as $row => $prc) {
897
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
898
-            if (empty($prt_id)) {
899
-                continue;
900
-            } //prices MUST have a price type id.
901
-            $PRC_values = array(
902
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
903
-                'PRT_ID'         => $prt_id,
904
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
905
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
906
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
907
-                'PRC_is_default' => false,
908
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
909
-                'PRC_order'      => $row,
910
-            );
911
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
912
-                $PRC_values['PRC_ID'] = 0;
913
-                $price = EE_Registry::instance()->load_class(
914
-                    'Price',
915
-                    array($PRC_values),
916
-                    false,
917
-                    false
918
-                );
919
-            } else {
920
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
921
-                // update this price with new values
922
-                foreach ($PRC_values as $field => $value) {
923
-                    $price->set($field, $value);
924
-                }
925
-            }
926
-            $price->save();
927
-            $updated_prices[ $price->ID() ] = $price;
928
-            $ticket->_add_relation_to($price, 'Price');
929
-        }
930
-        // now let's remove any prices that got removed from the ticket
931
-        if (! empty($current_prices_on_ticket)) {
932
-            $current = array_keys($current_prices_on_ticket);
933
-            $updated = array_keys($updated_prices);
934
-            $prices_to_remove = array_diff($current, $updated);
935
-            if (! empty($prices_to_remove)) {
936
-                foreach ($prices_to_remove as $prc_id) {
937
-                    $p = $current_prices_on_ticket[ $prc_id ];
938
-                    $ticket->_remove_relation_to($p, 'Price');
939
-                    // delete permanently the price
940
-                    $p->delete_permanently();
941
-                }
942
-            }
943
-        }
944
-        return $ticket;
945
-    }
850
+	/**
851
+	 * This attaches a list of given prices to a ticket.
852
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
853
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
854
+	 * price info and prices are automatically "archived" via the ticket.
855
+	 *
856
+	 * @access  private
857
+	 * @param array     $prices        Array of prices from the form.
858
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
859
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
860
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
861
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
862
+	 * @return EE_Ticket
863
+	 * @throws ReflectionException
864
+	 * @throws InvalidArgumentException
865
+	 * @throws InvalidInterfaceException
866
+	 * @throws InvalidDataTypeException
867
+	 * @throws EE_Error
868
+	 */
869
+	protected function _add_prices_to_ticket(
870
+		$prices = array(),
871
+		EE_Ticket $ticket,
872
+		$new_prices = false,
873
+		$base_price = false,
874
+		$base_price_id = false
875
+	) {
876
+		// let's just get any current prices that may exist on the given ticket
877
+		// so we can remove any prices that got trashed in this session.
878
+		$current_prices_on_ticket = $base_price !== false
879
+			? $ticket->base_price(true)
880
+			: $ticket->price_modifiers();
881
+		$updated_prices = array();
882
+		// if $base_price ! FALSE then updating a base price.
883
+		if ($base_price !== false) {
884
+			$prices[1] = array(
885
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
886
+				'PRT_ID'     => 1,
887
+				'PRC_amount' => $base_price,
888
+				'PRC_name'   => $ticket->get('TKT_name'),
889
+				'PRC_desc'   => $ticket->get('TKT_description'),
890
+			);
891
+		}
892
+		// possibly need to save tkt
893
+		if (! $ticket->ID()) {
894
+			$ticket->save();
895
+		}
896
+		foreach ($prices as $row => $prc) {
897
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
898
+			if (empty($prt_id)) {
899
+				continue;
900
+			} //prices MUST have a price type id.
901
+			$PRC_values = array(
902
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
903
+				'PRT_ID'         => $prt_id,
904
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
905
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
906
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
907
+				'PRC_is_default' => false,
908
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
909
+				'PRC_order'      => $row,
910
+			);
911
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
912
+				$PRC_values['PRC_ID'] = 0;
913
+				$price = EE_Registry::instance()->load_class(
914
+					'Price',
915
+					array($PRC_values),
916
+					false,
917
+					false
918
+				);
919
+			} else {
920
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
921
+				// update this price with new values
922
+				foreach ($PRC_values as $field => $value) {
923
+					$price->set($field, $value);
924
+				}
925
+			}
926
+			$price->save();
927
+			$updated_prices[ $price->ID() ] = $price;
928
+			$ticket->_add_relation_to($price, 'Price');
929
+		}
930
+		// now let's remove any prices that got removed from the ticket
931
+		if (! empty($current_prices_on_ticket)) {
932
+			$current = array_keys($current_prices_on_ticket);
933
+			$updated = array_keys($updated_prices);
934
+			$prices_to_remove = array_diff($current, $updated);
935
+			if (! empty($prices_to_remove)) {
936
+				foreach ($prices_to_remove as $prc_id) {
937
+					$p = $current_prices_on_ticket[ $prc_id ];
938
+					$ticket->_remove_relation_to($p, 'Price');
939
+					// delete permanently the price
940
+					$p->delete_permanently();
941
+				}
942
+			}
943
+		}
944
+		return $ticket;
945
+	}
946 946
 
947 947
 
948
-    /**
949
-     * @param Events_Admin_Page $event_admin_obj
950
-     * @return Events_Admin_Page
951
-     */
952
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
953
-    {
954
-        return $event_admin_obj;
955
-        // doing nothing for the moment.
956
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
957
-        // (use the set_template_args() method)
958
-        /**
959
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
960
-         * 1. TKT_is_default_selector (visible)
961
-         * 2. TKT_is_default (hidden)
962
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
963
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
964
-         * this ticket to be saved as a default.
965
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
966
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
967
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
968
-         * the TKT HAS been saved as a default..
969
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
970
-         * On Autosave:
971
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
972
-         * then set the TKT_is_default to false.
973
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
974
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
975
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
976
-         */
977
-    }
948
+	/**
949
+	 * @param Events_Admin_Page $event_admin_obj
950
+	 * @return Events_Admin_Page
951
+	 */
952
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
953
+	{
954
+		return $event_admin_obj;
955
+		// doing nothing for the moment.
956
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
957
+		// (use the set_template_args() method)
958
+		/**
959
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
960
+		 * 1. TKT_is_default_selector (visible)
961
+		 * 2. TKT_is_default (hidden)
962
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
963
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
964
+		 * this ticket to be saved as a default.
965
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
966
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
967
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
968
+		 * the TKT HAS been saved as a default..
969
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
970
+		 * On Autosave:
971
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
972
+		 * then set the TKT_is_default to false.
973
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
974
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
975
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
976
+		 */
977
+	}
978 978
 
979 979
 
980
-    /**
981
-     * @throws ReflectionException
982
-     * @throws InvalidArgumentException
983
-     * @throws InvalidInterfaceException
984
-     * @throws InvalidDataTypeException
985
-     * @throws DomainException
986
-     * @throws EE_Error
987
-     */
988
-    public function pricing_metabox()
989
-    {
990
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
991
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
992
-        // set is_creating_event property.
993
-        $EVT_ID = $event->ID();
994
-        $this->_is_creating_event = empty($this->_req_data['post']);
995
-        // default main template args
996
-        $main_template_args = array(
997
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
998
-                'event_editor_event_datetimes_help_tab',
999
-                $this->_adminpage_obj->page_slug,
1000
-                $this->_adminpage_obj->get_req_action(),
1001
-                false,
1002
-                false
1003
-            ),
1004
-            // todo need to add a filter to the template for the help text
1005
-            // in the Events_Admin_Page core file so we can add further help
1006
-            'existing_datetime_ids'    => '',
1007
-            'total_dtt_rows'           => 1,
1008
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1009
-                'add_new_dtt_info',
1010
-                $this->_adminpage_obj->page_slug,
1011
-                $this->_adminpage_obj->get_req_action(),
1012
-                false,
1013
-                false
1014
-            ),
1015
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1016
-            'datetime_rows'            => '',
1017
-            'show_tickets_container'   => '',
1018
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1019
-            'ticket_rows'              => '',
1020
-            'existing_ticket_ids'      => '',
1021
-            'total_ticket_rows'        => 1,
1022
-            'ticket_js_structure'      => '',
1023
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1024
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1025
-        );
1026
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1027
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1028
-        /**
1029
-         * 1. Start with retrieving Datetimes
1030
-         * 2. For each datetime get related tickets
1031
-         * 3. For each ticket get related prices
1032
-         */
1033
-        /** @var EEM_Datetime $datetime_model */
1034
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1035
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1036
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1037
-        /**
1038
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1039
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1040
-         */
1041
-        $datetime_row = 1;
1042
-        foreach ($datetimes as $datetime) {
1043
-            $DTT_ID = $datetime->get('DTT_ID');
1044
-            $datetime->set('DTT_order', $datetime_row);
1045
-            $existing_datetime_ids[] = $DTT_ID;
1046
-            // tickets attached
1047
-            $related_tickets = $datetime->ID() > 0
1048
-                ? $datetime->get_many_related(
1049
-                    'Ticket',
1050
-                    array(
1051
-                        array(
1052
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1053
-                        ),
1054
-                        'default_where_conditions' => 'none',
1055
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1056
-                    )
1057
-                )
1058
-                : array();
1059
-            // if there are no related tickets this is likely a new event OR autodraft
1060
-            // event so we need to generate the default tickets because datetimes
1061
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1062
-            // datetime on the event.
1063
-            if (empty($related_tickets) && count($datetimes) < 2) {
1064
-                /** @var EEM_Ticket $ticket_model */
1065
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1066
-                $related_tickets = $ticket_model->get_all_default_tickets();
1067
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1068
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1069
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1070
-                $main_default_ticket = reset($related_tickets);
1071
-                if ($main_default_ticket instanceof EE_Ticket) {
1072
-                    foreach ($default_prices as $default_price) {
1073
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1074
-                            continue;
1075
-                        }
1076
-                        $main_default_ticket->cache('Price', $default_price);
1077
-                    }
1078
-                }
1079
-            }
1080
-            // we can't actually setup rows in this loop yet cause we don't know all
1081
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1082
-            // So we're going to temporarily cache some of that information.
1083
-            // loop through and setup the ticket rows and make sure the order is set.
1084
-            foreach ($related_tickets as $ticket) {
1085
-                $TKT_ID = $ticket->get('TKT_ID');
1086
-                $ticket_row = $ticket->get('TKT_row');
1087
-                // we only want unique tickets in our final display!!
1088
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1089
-                    $existing_ticket_ids[] = $TKT_ID;
1090
-                    $all_tickets[] = $ticket;
1091
-                }
1092
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1093
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
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)
1097
-                ) {
1098
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1099
-                }
1100
-            }
1101
-            $datetime_row++;
1102
-        }
1103
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1104
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1105
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1106
-        // sort $all_tickets by order
1107
-        usort(
1108
-            $all_tickets,
1109
-            function (EE_Ticket $a, EE_Ticket $b) {
1110
-                $a_order = (int) $a->get('TKT_order');
1111
-                $b_order = (int) $b->get('TKT_order');
1112
-                if ($a_order === $b_order) {
1113
-                    return 0;
1114
-                }
1115
-                return ($a_order < $b_order) ? -1 : 1;
1116
-            }
1117
-        );
1118
-        // k NOW we have all the data we need for setting up the dtt rows
1119
-        // and ticket rows so we start our dtt loop again.
1120
-        $datetime_row = 1;
1121
-        foreach ($datetimes as $datetime) {
1122
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1123
-                $datetime_row,
1124
-                $datetime,
1125
-                $datetime_tickets,
1126
-                $all_tickets,
1127
-                false,
1128
-                $datetimes
1129
-            );
1130
-            $datetime_row++;
1131
-        }
1132
-        // then loop through all tickets for the ticket rows.
1133
-        $ticket_row = 1;
1134
-        foreach ($all_tickets as $ticket) {
1135
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1136
-                $ticket_row,
1137
-                $ticket,
1138
-                $ticket_datetimes,
1139
-                $datetimes,
1140
-                false,
1141
-                $all_tickets
1142
-            );
1143
-            $ticket_row++;
1144
-        }
1145
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1146
-        EEH_Template::display_template(
1147
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1148
-            $main_template_args
1149
-        );
1150
-    }
980
+	/**
981
+	 * @throws ReflectionException
982
+	 * @throws InvalidArgumentException
983
+	 * @throws InvalidInterfaceException
984
+	 * @throws InvalidDataTypeException
985
+	 * @throws DomainException
986
+	 * @throws EE_Error
987
+	 */
988
+	public function pricing_metabox()
989
+	{
990
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
991
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
992
+		// set is_creating_event property.
993
+		$EVT_ID = $event->ID();
994
+		$this->_is_creating_event = empty($this->_req_data['post']);
995
+		// default main template args
996
+		$main_template_args = array(
997
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
998
+				'event_editor_event_datetimes_help_tab',
999
+				$this->_adminpage_obj->page_slug,
1000
+				$this->_adminpage_obj->get_req_action(),
1001
+				false,
1002
+				false
1003
+			),
1004
+			// todo need to add a filter to the template for the help text
1005
+			// in the Events_Admin_Page core file so we can add further help
1006
+			'existing_datetime_ids'    => '',
1007
+			'total_dtt_rows'           => 1,
1008
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1009
+				'add_new_dtt_info',
1010
+				$this->_adminpage_obj->page_slug,
1011
+				$this->_adminpage_obj->get_req_action(),
1012
+				false,
1013
+				false
1014
+			),
1015
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1016
+			'datetime_rows'            => '',
1017
+			'show_tickets_container'   => '',
1018
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1019
+			'ticket_rows'              => '',
1020
+			'existing_ticket_ids'      => '',
1021
+			'total_ticket_rows'        => 1,
1022
+			'ticket_js_structure'      => '',
1023
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1024
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1025
+		);
1026
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1027
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1028
+		/**
1029
+		 * 1. Start with retrieving Datetimes
1030
+		 * 2. For each datetime get related tickets
1031
+		 * 3. For each ticket get related prices
1032
+		 */
1033
+		/** @var EEM_Datetime $datetime_model */
1034
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1035
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1036
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1037
+		/**
1038
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1039
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1040
+		 */
1041
+		$datetime_row = 1;
1042
+		foreach ($datetimes as $datetime) {
1043
+			$DTT_ID = $datetime->get('DTT_ID');
1044
+			$datetime->set('DTT_order', $datetime_row);
1045
+			$existing_datetime_ids[] = $DTT_ID;
1046
+			// tickets attached
1047
+			$related_tickets = $datetime->ID() > 0
1048
+				? $datetime->get_many_related(
1049
+					'Ticket',
1050
+					array(
1051
+						array(
1052
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1053
+						),
1054
+						'default_where_conditions' => 'none',
1055
+						'order_by'                 => array('TKT_order' => 'ASC'),
1056
+					)
1057
+				)
1058
+				: array();
1059
+			// if there are no related tickets this is likely a new event OR autodraft
1060
+			// event so we need to generate the default tickets because datetimes
1061
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1062
+			// datetime on the event.
1063
+			if (empty($related_tickets) && count($datetimes) < 2) {
1064
+				/** @var EEM_Ticket $ticket_model */
1065
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1066
+				$related_tickets = $ticket_model->get_all_default_tickets();
1067
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1068
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1069
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1070
+				$main_default_ticket = reset($related_tickets);
1071
+				if ($main_default_ticket instanceof EE_Ticket) {
1072
+					foreach ($default_prices as $default_price) {
1073
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1074
+							continue;
1075
+						}
1076
+						$main_default_ticket->cache('Price', $default_price);
1077
+					}
1078
+				}
1079
+			}
1080
+			// we can't actually setup rows in this loop yet cause we don't know all
1081
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1082
+			// So we're going to temporarily cache some of that information.
1083
+			// loop through and setup the ticket rows and make sure the order is set.
1084
+			foreach ($related_tickets as $ticket) {
1085
+				$TKT_ID = $ticket->get('TKT_ID');
1086
+				$ticket_row = $ticket->get('TKT_row');
1087
+				// we only want unique tickets in our final display!!
1088
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1089
+					$existing_ticket_ids[] = $TKT_ID;
1090
+					$all_tickets[] = $ticket;
1091
+				}
1092
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1093
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
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)
1097
+				) {
1098
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1099
+				}
1100
+			}
1101
+			$datetime_row++;
1102
+		}
1103
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1104
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1105
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1106
+		// sort $all_tickets by order
1107
+		usort(
1108
+			$all_tickets,
1109
+			function (EE_Ticket $a, EE_Ticket $b) {
1110
+				$a_order = (int) $a->get('TKT_order');
1111
+				$b_order = (int) $b->get('TKT_order');
1112
+				if ($a_order === $b_order) {
1113
+					return 0;
1114
+				}
1115
+				return ($a_order < $b_order) ? -1 : 1;
1116
+			}
1117
+		);
1118
+		// k NOW we have all the data we need for setting up the dtt rows
1119
+		// and ticket rows so we start our dtt loop again.
1120
+		$datetime_row = 1;
1121
+		foreach ($datetimes as $datetime) {
1122
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1123
+				$datetime_row,
1124
+				$datetime,
1125
+				$datetime_tickets,
1126
+				$all_tickets,
1127
+				false,
1128
+				$datetimes
1129
+			);
1130
+			$datetime_row++;
1131
+		}
1132
+		// then loop through all tickets for the ticket rows.
1133
+		$ticket_row = 1;
1134
+		foreach ($all_tickets as $ticket) {
1135
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1136
+				$ticket_row,
1137
+				$ticket,
1138
+				$ticket_datetimes,
1139
+				$datetimes,
1140
+				false,
1141
+				$all_tickets
1142
+			);
1143
+			$ticket_row++;
1144
+		}
1145
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1146
+		EEH_Template::display_template(
1147
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1148
+			$main_template_args
1149
+		);
1150
+	}
1151 1151
 
1152 1152
 
1153
-    /**
1154
-     * @param int         $datetime_row
1155
-     * @param EE_Datetime $datetime
1156
-     * @param array       $datetime_tickets
1157
-     * @param array       $all_tickets
1158
-     * @param bool        $default
1159
-     * @param array       $all_datetimes
1160
-     * @return mixed
1161
-     * @throws DomainException
1162
-     * @throws EE_Error
1163
-     */
1164
-    protected function _get_datetime_row(
1165
-        $datetime_row,
1166
-        EE_Datetime $datetime,
1167
-        $datetime_tickets = array(),
1168
-        $all_tickets = array(),
1169
-        $default = false,
1170
-        $all_datetimes = array()
1171
-    ) {
1172
-        $dtt_display_template_args = array(
1173
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1174
-                $datetime_row,
1175
-                $datetime,
1176
-                $default,
1177
-                $all_datetimes
1178
-            ),
1179
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1180
-                $datetime_row,
1181
-                $datetime,
1182
-                $datetime_tickets,
1183
-                $all_tickets,
1184
-                $default
1185
-            ),
1186
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1187
-        );
1188
-        return EEH_Template::display_template(
1189
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1190
-            $dtt_display_template_args,
1191
-            true
1192
-        );
1193
-    }
1153
+	/**
1154
+	 * @param int         $datetime_row
1155
+	 * @param EE_Datetime $datetime
1156
+	 * @param array       $datetime_tickets
1157
+	 * @param array       $all_tickets
1158
+	 * @param bool        $default
1159
+	 * @param array       $all_datetimes
1160
+	 * @return mixed
1161
+	 * @throws DomainException
1162
+	 * @throws EE_Error
1163
+	 */
1164
+	protected function _get_datetime_row(
1165
+		$datetime_row,
1166
+		EE_Datetime $datetime,
1167
+		$datetime_tickets = array(),
1168
+		$all_tickets = array(),
1169
+		$default = false,
1170
+		$all_datetimes = array()
1171
+	) {
1172
+		$dtt_display_template_args = array(
1173
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1174
+				$datetime_row,
1175
+				$datetime,
1176
+				$default,
1177
+				$all_datetimes
1178
+			),
1179
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1180
+				$datetime_row,
1181
+				$datetime,
1182
+				$datetime_tickets,
1183
+				$all_tickets,
1184
+				$default
1185
+			),
1186
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1187
+		);
1188
+		return EEH_Template::display_template(
1189
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1190
+			$dtt_display_template_args,
1191
+			true
1192
+		);
1193
+	}
1194 1194
 
1195 1195
 
1196
-    /**
1197
-     * This method is used to generate a dtt fields  edit row.
1198
-     * The same row is used to generate a row with valid DTT objects
1199
-     * and the default row that is used as the skeleton by the js.
1200
-     *
1201
-     * @param int           $datetime_row  The row number for the row being generated.
1202
-     * @param EE_Datetime   $datetime
1203
-     * @param bool          $default       Whether a default row is being generated or not.
1204
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1205
-     * @return string
1206
-     * @throws DomainException
1207
-     * @throws EE_Error
1208
-     */
1209
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1210
-    {
1211
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1212
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1213
-        $template_args = array(
1214
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1215
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1216
-            'edit_dtt_expanded'    => '',
1217
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1218
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1219
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1220
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1221
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1222
-            'DTT_reg_limit'        => $default
1223
-                ? ''
1224
-                : $datetime->get_pretty(
1225
-                    'DTT_reg_limit',
1226
-                    'input'
1227
-                ),
1228
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1229
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1230
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1231
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1232
-                ? ''
1233
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1234
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1235
-                ? 'ee-lock-icon'
1236
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1237
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1238
-                ? ''
1239
-                : EE_Admin_Page::add_query_args_and_nonce(
1240
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1241
-                    REG_ADMIN_URL
1242
-                ),
1243
-        );
1244
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1245
-            ? ' style="display:none"'
1246
-            : '';
1247
-        // allow filtering of template args at this point.
1248
-        $template_args = apply_filters(
1249
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1250
-            $template_args,
1251
-            $datetime_row,
1252
-            $datetime,
1253
-            $default,
1254
-            $all_datetimes,
1255
-            $this->_is_creating_event
1256
-        );
1257
-        return EEH_Template::display_template(
1258
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1259
-            $template_args,
1260
-            true
1261
-        );
1262
-    }
1196
+	/**
1197
+	 * This method is used to generate a dtt fields  edit row.
1198
+	 * The same row is used to generate a row with valid DTT objects
1199
+	 * and the default row that is used as the skeleton by the js.
1200
+	 *
1201
+	 * @param int           $datetime_row  The row number for the row being generated.
1202
+	 * @param EE_Datetime   $datetime
1203
+	 * @param bool          $default       Whether a default row is being generated or not.
1204
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1205
+	 * @return string
1206
+	 * @throws DomainException
1207
+	 * @throws EE_Error
1208
+	 */
1209
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1210
+	{
1211
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1212
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1213
+		$template_args = array(
1214
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1215
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1216
+			'edit_dtt_expanded'    => '',
1217
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1218
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1219
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1220
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1221
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1222
+			'DTT_reg_limit'        => $default
1223
+				? ''
1224
+				: $datetime->get_pretty(
1225
+					'DTT_reg_limit',
1226
+					'input'
1227
+				),
1228
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1229
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1230
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1231
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1232
+				? ''
1233
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1234
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1235
+				? 'ee-lock-icon'
1236
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1237
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1238
+				? ''
1239
+				: EE_Admin_Page::add_query_args_and_nonce(
1240
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1241
+					REG_ADMIN_URL
1242
+				),
1243
+		);
1244
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1245
+			? ' style="display:none"'
1246
+			: '';
1247
+		// allow filtering of template args at this point.
1248
+		$template_args = apply_filters(
1249
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1250
+			$template_args,
1251
+			$datetime_row,
1252
+			$datetime,
1253
+			$default,
1254
+			$all_datetimes,
1255
+			$this->_is_creating_event
1256
+		);
1257
+		return EEH_Template::display_template(
1258
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1259
+			$template_args,
1260
+			true
1261
+		);
1262
+	}
1263 1263
 
1264 1264
 
1265
-    /**
1266
-     * @param int         $datetime_row
1267
-     * @param EE_Datetime $datetime
1268
-     * @param array       $datetime_tickets
1269
-     * @param array       $all_tickets
1270
-     * @param bool        $default
1271
-     * @return mixed
1272
-     * @throws DomainException
1273
-     * @throws EE_Error
1274
-     */
1275
-    protected function _get_dtt_attached_tickets_row(
1276
-        $datetime_row,
1277
-        $datetime,
1278
-        $datetime_tickets = array(),
1279
-        $all_tickets = array(),
1280
-        $default
1281
-    ) {
1282
-        $template_args = array(
1283
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1284
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1285
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1286
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1287
-            'show_tickets_row'                  => ' style="display:none;"',
1288
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1289
-                'add_new_ticket_via_datetime',
1290
-                $this->_adminpage_obj->page_slug,
1291
-                $this->_adminpage_obj->get_req_action(),
1292
-                false,
1293
-                false
1294
-            ),
1295
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1296
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1297
-        );
1298
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1299
-        if (! $default) {
1300
-            $ticket_row = 1;
1301
-            foreach ($all_tickets as $ticket) {
1302
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1303
-                    $datetime_row,
1304
-                    $ticket_row,
1305
-                    $datetime,
1306
-                    $ticket,
1307
-                    $datetime_tickets,
1308
-                    $default
1309
-                );
1310
-                $ticket_row++;
1311
-            }
1312
-        }
1313
-        // filter template args at this point
1314
-        $template_args = apply_filters(
1315
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1316
-            $template_args,
1317
-            $datetime_row,
1318
-            $datetime,
1319
-            $datetime_tickets,
1320
-            $all_tickets,
1321
-            $default,
1322
-            $this->_is_creating_event
1323
-        );
1324
-        return EEH_Template::display_template(
1325
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1326
-            $template_args,
1327
-            true
1328
-        );
1329
-    }
1265
+	/**
1266
+	 * @param int         $datetime_row
1267
+	 * @param EE_Datetime $datetime
1268
+	 * @param array       $datetime_tickets
1269
+	 * @param array       $all_tickets
1270
+	 * @param bool        $default
1271
+	 * @return mixed
1272
+	 * @throws DomainException
1273
+	 * @throws EE_Error
1274
+	 */
1275
+	protected function _get_dtt_attached_tickets_row(
1276
+		$datetime_row,
1277
+		$datetime,
1278
+		$datetime_tickets = array(),
1279
+		$all_tickets = array(),
1280
+		$default
1281
+	) {
1282
+		$template_args = array(
1283
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1284
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1285
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1286
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1287
+			'show_tickets_row'                  => ' style="display:none;"',
1288
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1289
+				'add_new_ticket_via_datetime',
1290
+				$this->_adminpage_obj->page_slug,
1291
+				$this->_adminpage_obj->get_req_action(),
1292
+				false,
1293
+				false
1294
+			),
1295
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1296
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1297
+		);
1298
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1299
+		if (! $default) {
1300
+			$ticket_row = 1;
1301
+			foreach ($all_tickets as $ticket) {
1302
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1303
+					$datetime_row,
1304
+					$ticket_row,
1305
+					$datetime,
1306
+					$ticket,
1307
+					$datetime_tickets,
1308
+					$default
1309
+				);
1310
+				$ticket_row++;
1311
+			}
1312
+		}
1313
+		// filter template args at this point
1314
+		$template_args = apply_filters(
1315
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1316
+			$template_args,
1317
+			$datetime_row,
1318
+			$datetime,
1319
+			$datetime_tickets,
1320
+			$all_tickets,
1321
+			$default,
1322
+			$this->_is_creating_event
1323
+		);
1324
+		return EEH_Template::display_template(
1325
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1326
+			$template_args,
1327
+			true
1328
+		);
1329
+	}
1330 1330
 
1331 1331
 
1332
-    /**
1333
-     * @param int         $datetime_row
1334
-     * @param int         $ticket_row
1335
-     * @param EE_Datetime $datetime
1336
-     * @param EE_Ticket   $ticket
1337
-     * @param array       $datetime_tickets
1338
-     * @param bool        $default
1339
-     * @return mixed
1340
-     * @throws DomainException
1341
-     * @throws EE_Error
1342
-     */
1343
-    protected function _get_datetime_tickets_list_item(
1344
-        $datetime_row,
1345
-        $ticket_row,
1346
-        $datetime,
1347
-        $ticket,
1348
-        $datetime_tickets = array(),
1349
-        $default
1350
-    ) {
1351
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1352
-            ? $datetime_tickets[ $datetime->ID() ]
1353
-            : array();
1354
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1355
-        $no_ticket = $default && empty($ticket);
1356
-        $template_args = array(
1357
-            'dtt_row'                 => $default
1358
-                ? 'DTTNUM'
1359
-                : $datetime_row,
1360
-            'tkt_row'                 => $no_ticket
1361
-                ? 'TICKETNUM'
1362
-                : $ticket_row,
1363
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1364
-                ? ' checked="checked"'
1365
-                : '',
1366
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1367
-                ? ' ticket-selected'
1368
-                : '',
1369
-            'TKT_name'                => $no_ticket
1370
-                ? 'TKTNAME'
1371
-                : $ticket->get('TKT_name'),
1372
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1373
-                ? ' tkt-status-' . EE_Ticket::onsale
1374
-                : ' tkt-status-' . $ticket->ticket_status(),
1375
-        );
1376
-        // filter template args
1377
-        $template_args = apply_filters(
1378
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1379
-            $template_args,
1380
-            $datetime_row,
1381
-            $ticket_row,
1382
-            $datetime,
1383
-            $ticket,
1384
-            $datetime_tickets,
1385
-            $default,
1386
-            $this->_is_creating_event
1387
-        );
1388
-        return EEH_Template::display_template(
1389
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1390
-            $template_args,
1391
-            true
1392
-        );
1393
-    }
1332
+	/**
1333
+	 * @param int         $datetime_row
1334
+	 * @param int         $ticket_row
1335
+	 * @param EE_Datetime $datetime
1336
+	 * @param EE_Ticket   $ticket
1337
+	 * @param array       $datetime_tickets
1338
+	 * @param bool        $default
1339
+	 * @return mixed
1340
+	 * @throws DomainException
1341
+	 * @throws EE_Error
1342
+	 */
1343
+	protected function _get_datetime_tickets_list_item(
1344
+		$datetime_row,
1345
+		$ticket_row,
1346
+		$datetime,
1347
+		$ticket,
1348
+		$datetime_tickets = array(),
1349
+		$default
1350
+	) {
1351
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1352
+			? $datetime_tickets[ $datetime->ID() ]
1353
+			: array();
1354
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1355
+		$no_ticket = $default && empty($ticket);
1356
+		$template_args = array(
1357
+			'dtt_row'                 => $default
1358
+				? 'DTTNUM'
1359
+				: $datetime_row,
1360
+			'tkt_row'                 => $no_ticket
1361
+				? 'TICKETNUM'
1362
+				: $ticket_row,
1363
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1364
+				? ' checked="checked"'
1365
+				: '',
1366
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1367
+				? ' ticket-selected'
1368
+				: '',
1369
+			'TKT_name'                => $no_ticket
1370
+				? 'TKTNAME'
1371
+				: $ticket->get('TKT_name'),
1372
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1373
+				? ' tkt-status-' . EE_Ticket::onsale
1374
+				: ' tkt-status-' . $ticket->ticket_status(),
1375
+		);
1376
+		// filter template args
1377
+		$template_args = apply_filters(
1378
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1379
+			$template_args,
1380
+			$datetime_row,
1381
+			$ticket_row,
1382
+			$datetime,
1383
+			$ticket,
1384
+			$datetime_tickets,
1385
+			$default,
1386
+			$this->_is_creating_event
1387
+		);
1388
+		return EEH_Template::display_template(
1389
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1390
+			$template_args,
1391
+			true
1392
+		);
1393
+	}
1394 1394
 
1395 1395
 
1396
-    /**
1397
-     * This generates the ticket row for tickets.
1398
-     * This same method is used to generate both the actual rows and the js skeleton row
1399
-     * (when default === true)
1400
-     *
1401
-     * @param int           $ticket_row       Represents the row number being generated.
1402
-     * @param               $ticket
1403
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1404
-     *                                        or empty for default
1405
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1406
-     * @param bool          $default          Whether default row being generated or not.
1407
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1408
-     *                                        (or empty in the case of defaults)
1409
-     * @return mixed
1410
-     * @throws InvalidArgumentException
1411
-     * @throws InvalidInterfaceException
1412
-     * @throws InvalidDataTypeException
1413
-     * @throws DomainException
1414
-     * @throws EE_Error
1415
-     * @throws ReflectionException
1416
-     */
1417
-    protected function _get_ticket_row(
1418
-        $ticket_row,
1419
-        $ticket,
1420
-        $ticket_datetimes,
1421
-        $all_datetimes,
1422
-        $default = false,
1423
-        $all_tickets = array()
1424
-    ) {
1425
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1426
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1427
-        $prices = ! empty($ticket) && ! $default
1428
-            ? $ticket->get_many_related(
1429
-                'Price',
1430
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1431
-            )
1432
-            : array();
1433
-        // if there is only one price (which would be the base price)
1434
-        // or NO prices and this ticket is a default ticket,
1435
-        // let's just make sure there are no cached default prices on the object.
1436
-        // This is done by not including any query_params.
1437
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1438
-            $prices = $ticket->prices();
1439
-        }
1440
-        // check if we're dealing with a default ticket in which case
1441
-        // we don't want any starting_ticket_datetime_row values set
1442
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1443
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
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() ]
1447
-            : array();
1448
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1449
-        $base_price = $default ? null : $ticket->base_price();
1450
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1451
-        // breaking out complicated condition for ticket_status
1452
-        if ($default) {
1453
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1454
-        } else {
1455
-            $ticket_status_class = $ticket->is_default()
1456
-                ? ' tkt-status-' . EE_Ticket::onsale
1457
-                : ' tkt-status-' . $ticket->ticket_status();
1458
-        }
1459
-        // breaking out complicated condition for TKT_taxable
1460
-        if ($default) {
1461
-            $TKT_taxable = '';
1462
-        } else {
1463
-            $TKT_taxable = $ticket->taxable()
1464
-                ? ' checked="checked"'
1465
-                : '';
1466
-        }
1467
-        if ($default) {
1468
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1469
-        } elseif ($ticket->is_default()) {
1470
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1471
-        } else {
1472
-            $TKT_status = $ticket->ticket_status(true);
1473
-        }
1474
-        if ($default) {
1475
-            $TKT_min = '';
1476
-        } else {
1477
-            $TKT_min = $ticket->min();
1478
-            if ($TKT_min === -1 || $TKT_min === 0) {
1479
-                $TKT_min = '';
1480
-            }
1481
-        }
1482
-        $template_args = array(
1483
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1484
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1485
-            // on initial page load this will always be the correct order.
1486
-            'tkt_status_class'              => $ticket_status_class,
1487
-            'display_edit_tkt_row'          => ' style="display:none;"',
1488
-            'edit_tkt_expanded'             => '',
1489
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1490
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1491
-            'TKT_start_date'                => $default
1492
-                ? ''
1493
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1494
-            'TKT_end_date'                  => $default
1495
-                ? ''
1496
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1497
-            'TKT_status'                    => $TKT_status,
1498
-            'TKT_price'                     => $default
1499
-                ? ''
1500
-                : EEH_Template::format_currency(
1501
-                    $ticket->get_ticket_total_with_taxes(),
1502
-                    false,
1503
-                    false
1504
-                ),
1505
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1506
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1507
-            'TKT_qty'                       => $default
1508
-                ? ''
1509
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1510
-            'TKT_qty_for_input'             => $default
1511
-                ? ''
1512
-                : $ticket->get_pretty('TKT_qty', 'input'),
1513
-            'TKT_uses'                      => $default
1514
-                ? ''
1515
-                : $ticket->get_pretty('TKT_uses', 'input'),
1516
-            'TKT_min'                       => $TKT_min,
1517
-            'TKT_max'                       => $default
1518
-                ? ''
1519
-                : $ticket->get_pretty('TKT_max', 'input'),
1520
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1521
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1522
-            'TKT_registrations'             => $default
1523
-                ? 0
1524
-                : $ticket->count_registrations(
1525
-                    array(
1526
-                        array(
1527
-                            'STS_ID' => array(
1528
-                                '!=',
1529
-                                EEM_Registration::status_id_incomplete,
1530
-                            ),
1531
-                        ),
1532
-                    )
1533
-                ),
1534
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1535
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1536
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1537
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1538
-            'TKT_is_default_selector'       => '',
1539
-            'ticket_price_rows'             => '',
1540
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1541
-                ? ''
1542
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1543
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1544
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1545
-                ? ''
1546
-                : ' style="display:none;"',
1547
-            'show_price_mod_button'         => count($prices) > 1
1548
-                                               || ($default && $count_price_mods > 0)
1549
-                                               || (! $default && $ticket->deleted())
1550
-                ? ' style="display:none;"'
1551
-                : '',
1552
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1553
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1554
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1555
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1556
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1557
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1558
-            'TKT_taxable'                   => $TKT_taxable,
1559
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1560
-                ? ''
1561
-                : ' style="display:none"',
1562
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1563
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1564
-                $ticket_subtotal,
1565
-                false,
1566
-                false
1567
-            ),
1568
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1569
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1570
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1571
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1572
-                ? ' ticket-archived'
1573
-                : '',
1574
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1575
-                                               && $ticket->deleted()
1576
-                                               && ! $ticket->is_permanently_deleteable()
1577
-                ? 'ee-lock-icon '
1578
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1579
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1580
-                ? ''
1581
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1582
-        );
1583
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1584
-            ? ' style="display:none"'
1585
-            : '';
1586
-        // handle rows that should NOT be empty
1587
-        if (empty($template_args['TKT_start_date'])) {
1588
-            // if empty then the start date will be now.
1589
-            $template_args['TKT_start_date'] = date(
1590
-                $this->_date_time_format,
1591
-                current_time('timestamp')
1592
-            );
1593
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1594
-        }
1595
-        if (empty($template_args['TKT_end_date'])) {
1596
-            // get the earliest datetime (if present);
1597
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1598
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1599
-                    'Datetime',
1600
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1601
-                )
1602
-                : null;
1603
-            if (! empty($earliest_dtt)) {
1604
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1605
-                    'DTT_EVT_start',
1606
-                    $this->_date_time_format
1607
-                );
1608
-            } else {
1609
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1610
-                $template_args['TKT_end_date'] = date(
1611
-                    $this->_date_time_format,
1612
-                    mktime(
1613
-                        24,
1614
-                        0,
1615
-                        0,
1616
-                        date('m'),
1617
-                        date('d') + 29,
1618
-                        date('Y')
1619
-                    )
1620
-                );
1621
-            }
1622
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1623
-        }
1624
-        // generate ticket_datetime items
1625
-        if (! $default) {
1626
-            $datetime_row = 1;
1627
-            foreach ($all_datetimes as $datetime) {
1628
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1629
-                    $datetime_row,
1630
-                    $ticket_row,
1631
-                    $datetime,
1632
-                    $ticket,
1633
-                    $ticket_datetimes,
1634
-                    $default
1635
-                );
1636
-                $datetime_row++;
1637
-            }
1638
-        }
1639
-        $price_row = 1;
1640
-        foreach ($prices as $price) {
1641
-            if (! $price instanceof EE_Price) {
1642
-                continue;
1643
-            }
1644
-            if ($price->is_base_price()) {
1645
-                $price_row++;
1646
-                continue;
1647
-            }
1648
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1649
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1650
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1651
-                $ticket_row,
1652
-                $price_row,
1653
-                $price,
1654
-                $default,
1655
-                $ticket,
1656
-                $show_trash,
1657
-                $show_create
1658
-            );
1659
-            $price_row++;
1660
-        }
1661
-        // filter $template_args
1662
-        $template_args = apply_filters(
1663
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1664
-            $template_args,
1665
-            $ticket_row,
1666
-            $ticket,
1667
-            $ticket_datetimes,
1668
-            $all_datetimes,
1669
-            $default,
1670
-            $all_tickets,
1671
-            $this->_is_creating_event
1672
-        );
1673
-        return EEH_Template::display_template(
1674
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1675
-            $template_args,
1676
-            true
1677
-        );
1678
-    }
1396
+	/**
1397
+	 * This generates the ticket row for tickets.
1398
+	 * This same method is used to generate both the actual rows and the js skeleton row
1399
+	 * (when default === true)
1400
+	 *
1401
+	 * @param int           $ticket_row       Represents the row number being generated.
1402
+	 * @param               $ticket
1403
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1404
+	 *                                        or empty for default
1405
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1406
+	 * @param bool          $default          Whether default row being generated or not.
1407
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1408
+	 *                                        (or empty in the case of defaults)
1409
+	 * @return mixed
1410
+	 * @throws InvalidArgumentException
1411
+	 * @throws InvalidInterfaceException
1412
+	 * @throws InvalidDataTypeException
1413
+	 * @throws DomainException
1414
+	 * @throws EE_Error
1415
+	 * @throws ReflectionException
1416
+	 */
1417
+	protected function _get_ticket_row(
1418
+		$ticket_row,
1419
+		$ticket,
1420
+		$ticket_datetimes,
1421
+		$all_datetimes,
1422
+		$default = false,
1423
+		$all_tickets = array()
1424
+	) {
1425
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1426
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1427
+		$prices = ! empty($ticket) && ! $default
1428
+			? $ticket->get_many_related(
1429
+				'Price',
1430
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1431
+			)
1432
+			: array();
1433
+		// if there is only one price (which would be the base price)
1434
+		// or NO prices and this ticket is a default ticket,
1435
+		// let's just make sure there are no cached default prices on the object.
1436
+		// This is done by not including any query_params.
1437
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1438
+			$prices = $ticket->prices();
1439
+		}
1440
+		// check if we're dealing with a default ticket in which case
1441
+		// we don't want any starting_ticket_datetime_row values set
1442
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1443
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
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() ]
1447
+			: array();
1448
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1449
+		$base_price = $default ? null : $ticket->base_price();
1450
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1451
+		// breaking out complicated condition for ticket_status
1452
+		if ($default) {
1453
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1454
+		} else {
1455
+			$ticket_status_class = $ticket->is_default()
1456
+				? ' tkt-status-' . EE_Ticket::onsale
1457
+				: ' tkt-status-' . $ticket->ticket_status();
1458
+		}
1459
+		// breaking out complicated condition for TKT_taxable
1460
+		if ($default) {
1461
+			$TKT_taxable = '';
1462
+		} else {
1463
+			$TKT_taxable = $ticket->taxable()
1464
+				? ' checked="checked"'
1465
+				: '';
1466
+		}
1467
+		if ($default) {
1468
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1469
+		} elseif ($ticket->is_default()) {
1470
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1471
+		} else {
1472
+			$TKT_status = $ticket->ticket_status(true);
1473
+		}
1474
+		if ($default) {
1475
+			$TKT_min = '';
1476
+		} else {
1477
+			$TKT_min = $ticket->min();
1478
+			if ($TKT_min === -1 || $TKT_min === 0) {
1479
+				$TKT_min = '';
1480
+			}
1481
+		}
1482
+		$template_args = array(
1483
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1484
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1485
+			// on initial page load this will always be the correct order.
1486
+			'tkt_status_class'              => $ticket_status_class,
1487
+			'display_edit_tkt_row'          => ' style="display:none;"',
1488
+			'edit_tkt_expanded'             => '',
1489
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1490
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1491
+			'TKT_start_date'                => $default
1492
+				? ''
1493
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1494
+			'TKT_end_date'                  => $default
1495
+				? ''
1496
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1497
+			'TKT_status'                    => $TKT_status,
1498
+			'TKT_price'                     => $default
1499
+				? ''
1500
+				: EEH_Template::format_currency(
1501
+					$ticket->get_ticket_total_with_taxes(),
1502
+					false,
1503
+					false
1504
+				),
1505
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1506
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1507
+			'TKT_qty'                       => $default
1508
+				? ''
1509
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1510
+			'TKT_qty_for_input'             => $default
1511
+				? ''
1512
+				: $ticket->get_pretty('TKT_qty', 'input'),
1513
+			'TKT_uses'                      => $default
1514
+				? ''
1515
+				: $ticket->get_pretty('TKT_uses', 'input'),
1516
+			'TKT_min'                       => $TKT_min,
1517
+			'TKT_max'                       => $default
1518
+				? ''
1519
+				: $ticket->get_pretty('TKT_max', 'input'),
1520
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1521
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1522
+			'TKT_registrations'             => $default
1523
+				? 0
1524
+				: $ticket->count_registrations(
1525
+					array(
1526
+						array(
1527
+							'STS_ID' => array(
1528
+								'!=',
1529
+								EEM_Registration::status_id_incomplete,
1530
+							),
1531
+						),
1532
+					)
1533
+				),
1534
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1535
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1536
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1537
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1538
+			'TKT_is_default_selector'       => '',
1539
+			'ticket_price_rows'             => '',
1540
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1541
+				? ''
1542
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1543
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1544
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1545
+				? ''
1546
+				: ' style="display:none;"',
1547
+			'show_price_mod_button'         => count($prices) > 1
1548
+											   || ($default && $count_price_mods > 0)
1549
+											   || (! $default && $ticket->deleted())
1550
+				? ' style="display:none;"'
1551
+				: '',
1552
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1553
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1554
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1555
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1556
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1557
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1558
+			'TKT_taxable'                   => $TKT_taxable,
1559
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1560
+				? ''
1561
+				: ' style="display:none"',
1562
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1563
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1564
+				$ticket_subtotal,
1565
+				false,
1566
+				false
1567
+			),
1568
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1569
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1570
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1571
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1572
+				? ' ticket-archived'
1573
+				: '',
1574
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1575
+											   && $ticket->deleted()
1576
+											   && ! $ticket->is_permanently_deleteable()
1577
+				? 'ee-lock-icon '
1578
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1579
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1580
+				? ''
1581
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1582
+		);
1583
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1584
+			? ' style="display:none"'
1585
+			: '';
1586
+		// handle rows that should NOT be empty
1587
+		if (empty($template_args['TKT_start_date'])) {
1588
+			// if empty then the start date will be now.
1589
+			$template_args['TKT_start_date'] = date(
1590
+				$this->_date_time_format,
1591
+				current_time('timestamp')
1592
+			);
1593
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1594
+		}
1595
+		if (empty($template_args['TKT_end_date'])) {
1596
+			// get the earliest datetime (if present);
1597
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1598
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1599
+					'Datetime',
1600
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1601
+				)
1602
+				: null;
1603
+			if (! empty($earliest_dtt)) {
1604
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1605
+					'DTT_EVT_start',
1606
+					$this->_date_time_format
1607
+				);
1608
+			} else {
1609
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1610
+				$template_args['TKT_end_date'] = date(
1611
+					$this->_date_time_format,
1612
+					mktime(
1613
+						24,
1614
+						0,
1615
+						0,
1616
+						date('m'),
1617
+						date('d') + 29,
1618
+						date('Y')
1619
+					)
1620
+				);
1621
+			}
1622
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1623
+		}
1624
+		// generate ticket_datetime items
1625
+		if (! $default) {
1626
+			$datetime_row = 1;
1627
+			foreach ($all_datetimes as $datetime) {
1628
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1629
+					$datetime_row,
1630
+					$ticket_row,
1631
+					$datetime,
1632
+					$ticket,
1633
+					$ticket_datetimes,
1634
+					$default
1635
+				);
1636
+				$datetime_row++;
1637
+			}
1638
+		}
1639
+		$price_row = 1;
1640
+		foreach ($prices as $price) {
1641
+			if (! $price instanceof EE_Price) {
1642
+				continue;
1643
+			}
1644
+			if ($price->is_base_price()) {
1645
+				$price_row++;
1646
+				continue;
1647
+			}
1648
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1649
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1650
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1651
+				$ticket_row,
1652
+				$price_row,
1653
+				$price,
1654
+				$default,
1655
+				$ticket,
1656
+				$show_trash,
1657
+				$show_create
1658
+			);
1659
+			$price_row++;
1660
+		}
1661
+		// filter $template_args
1662
+		$template_args = apply_filters(
1663
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1664
+			$template_args,
1665
+			$ticket_row,
1666
+			$ticket,
1667
+			$ticket_datetimes,
1668
+			$all_datetimes,
1669
+			$default,
1670
+			$all_tickets,
1671
+			$this->_is_creating_event
1672
+		);
1673
+		return EEH_Template::display_template(
1674
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1675
+			$template_args,
1676
+			true
1677
+		);
1678
+	}
1679 1679
 
1680 1680
 
1681
-    /**
1682
-     * @param int            $ticket_row
1683
-     * @param EE_Ticket|null $ticket
1684
-     * @return string
1685
-     * @throws DomainException
1686
-     * @throws EE_Error
1687
-     */
1688
-    protected function _get_tax_rows($ticket_row, $ticket)
1689
-    {
1690
-        $tax_rows = '';
1691
-        /** @var EE_Price[] $taxes */
1692
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1693
-        foreach ($taxes as $tax) {
1694
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1695
-            $template_args = array(
1696
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1697
-                    ? ''
1698
-                    : ' style="display:none;"',
1699
-                'tax_id'            => $tax->ID(),
1700
-                'tkt_row'           => $ticket_row,
1701
-                'tax_label'         => $tax->get('PRC_name'),
1702
-                'tax_added'         => $tax_added,
1703
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1704
-                'tax_amount'        => $tax->get('PRC_amount'),
1705
-            );
1706
-            $template_args = apply_filters(
1707
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1708
-                $template_args,
1709
-                $ticket_row,
1710
-                $ticket,
1711
-                $this->_is_creating_event
1712
-            );
1713
-            $tax_rows .= EEH_Template::display_template(
1714
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1715
-                $template_args,
1716
-                true
1717
-            );
1718
-        }
1719
-        return $tax_rows;
1720
-    }
1681
+	/**
1682
+	 * @param int            $ticket_row
1683
+	 * @param EE_Ticket|null $ticket
1684
+	 * @return string
1685
+	 * @throws DomainException
1686
+	 * @throws EE_Error
1687
+	 */
1688
+	protected function _get_tax_rows($ticket_row, $ticket)
1689
+	{
1690
+		$tax_rows = '';
1691
+		/** @var EE_Price[] $taxes */
1692
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1693
+		foreach ($taxes as $tax) {
1694
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1695
+			$template_args = array(
1696
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1697
+					? ''
1698
+					: ' style="display:none;"',
1699
+				'tax_id'            => $tax->ID(),
1700
+				'tkt_row'           => $ticket_row,
1701
+				'tax_label'         => $tax->get('PRC_name'),
1702
+				'tax_added'         => $tax_added,
1703
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1704
+				'tax_amount'        => $tax->get('PRC_amount'),
1705
+			);
1706
+			$template_args = apply_filters(
1707
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1708
+				$template_args,
1709
+				$ticket_row,
1710
+				$ticket,
1711
+				$this->_is_creating_event
1712
+			);
1713
+			$tax_rows .= EEH_Template::display_template(
1714
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1715
+				$template_args,
1716
+				true
1717
+			);
1718
+		}
1719
+		return $tax_rows;
1720
+	}
1721 1721
 
1722 1722
 
1723
-    /**
1724
-     * @param EE_Price       $tax
1725
-     * @param EE_Ticket|null $ticket
1726
-     * @return float|int
1727
-     * @throws EE_Error
1728
-     */
1729
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1730
-    {
1731
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1732
-        return $subtotal * $tax->get('PRC_amount') / 100;
1733
-    }
1723
+	/**
1724
+	 * @param EE_Price       $tax
1725
+	 * @param EE_Ticket|null $ticket
1726
+	 * @return float|int
1727
+	 * @throws EE_Error
1728
+	 */
1729
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1730
+	{
1731
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1732
+		return $subtotal * $tax->get('PRC_amount') / 100;
1733
+	}
1734 1734
 
1735 1735
 
1736
-    /**
1737
-     * @param int            $ticket_row
1738
-     * @param int            $price_row
1739
-     * @param EE_Price|null  $price
1740
-     * @param bool           $default
1741
-     * @param EE_Ticket|null $ticket
1742
-     * @param bool           $show_trash
1743
-     * @param bool           $show_create
1744
-     * @return mixed
1745
-     * @throws InvalidArgumentException
1746
-     * @throws InvalidInterfaceException
1747
-     * @throws InvalidDataTypeException
1748
-     * @throws DomainException
1749
-     * @throws EE_Error
1750
-     * @throws ReflectionException
1751
-     */
1752
-    protected function _get_ticket_price_row(
1753
-        $ticket_row,
1754
-        $price_row,
1755
-        $price,
1756
-        $default,
1757
-        $ticket,
1758
-        $show_trash = true,
1759
-        $show_create = true
1760
-    ) {
1761
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1762
-        $template_args = array(
1763
-            'tkt_row'               => $default && empty($ticket)
1764
-                ? 'TICKETNUM'
1765
-                : $ticket_row,
1766
-            'PRC_order'             => $default && empty($price)
1767
-                ? 'PRICENUM'
1768
-                : $price_row,
1769
-            'edit_prices_name'      => $default && empty($price)
1770
-                ? 'PRICENAMEATTR'
1771
-                : 'edit_prices',
1772
-            'price_type_selector'   => $default && empty($price)
1773
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1774
-                : $this->_get_price_type_selector(
1775
-                    $ticket_row,
1776
-                    $price_row,
1777
-                    $price,
1778
-                    $default,
1779
-                    $send_disabled
1780
-                ),
1781
-            'PRC_ID'                => $default && empty($price)
1782
-                ? 0
1783
-                : $price->ID(),
1784
-            'PRC_is_default'        => $default && empty($price)
1785
-                ? 0
1786
-                : $price->get('PRC_is_default'),
1787
-            'PRC_name'              => $default && empty($price)
1788
-                ? ''
1789
-                : $price->get('PRC_name'),
1790
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1791
-            'show_plus_or_minus'    => $default && empty($price)
1792
-                ? ''
1793
-                : ' style="display:none;"',
1794
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1795
-                ? ' style="display:none;"'
1796
-                : '',
1797
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1798
-                ? ' style="display:none;"'
1799
-                : '',
1800
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1801
-                ? ' style="display:none"'
1802
-                : '',
1803
-            'PRC_amount'            => $default && empty($price)
1804
-                ? 0
1805
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1806
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1807
-                ? ' style="display:none;"'
1808
-                : '',
1809
-            'show_trash_icon'       => $show_trash
1810
-                ? ''
1811
-                : ' style="display:none;"',
1812
-            'show_create_button'    => $show_create
1813
-                ? ''
1814
-                : ' style="display:none;"',
1815
-            'PRC_desc'              => $default && empty($price)
1816
-                ? ''
1817
-                : $price->get('PRC_desc'),
1818
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1819
-        );
1820
-        $template_args = apply_filters(
1821
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1822
-            $template_args,
1823
-            $ticket_row,
1824
-            $price_row,
1825
-            $price,
1826
-            $default,
1827
-            $ticket,
1828
-            $show_trash,
1829
-            $show_create,
1830
-            $this->_is_creating_event
1831
-        );
1832
-        return EEH_Template::display_template(
1833
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1834
-            $template_args,
1835
-            true
1836
-        );
1837
-    }
1736
+	/**
1737
+	 * @param int            $ticket_row
1738
+	 * @param int            $price_row
1739
+	 * @param EE_Price|null  $price
1740
+	 * @param bool           $default
1741
+	 * @param EE_Ticket|null $ticket
1742
+	 * @param bool           $show_trash
1743
+	 * @param bool           $show_create
1744
+	 * @return mixed
1745
+	 * @throws InvalidArgumentException
1746
+	 * @throws InvalidInterfaceException
1747
+	 * @throws InvalidDataTypeException
1748
+	 * @throws DomainException
1749
+	 * @throws EE_Error
1750
+	 * @throws ReflectionException
1751
+	 */
1752
+	protected function _get_ticket_price_row(
1753
+		$ticket_row,
1754
+		$price_row,
1755
+		$price,
1756
+		$default,
1757
+		$ticket,
1758
+		$show_trash = true,
1759
+		$show_create = true
1760
+	) {
1761
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1762
+		$template_args = array(
1763
+			'tkt_row'               => $default && empty($ticket)
1764
+				? 'TICKETNUM'
1765
+				: $ticket_row,
1766
+			'PRC_order'             => $default && empty($price)
1767
+				? 'PRICENUM'
1768
+				: $price_row,
1769
+			'edit_prices_name'      => $default && empty($price)
1770
+				? 'PRICENAMEATTR'
1771
+				: 'edit_prices',
1772
+			'price_type_selector'   => $default && empty($price)
1773
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1774
+				: $this->_get_price_type_selector(
1775
+					$ticket_row,
1776
+					$price_row,
1777
+					$price,
1778
+					$default,
1779
+					$send_disabled
1780
+				),
1781
+			'PRC_ID'                => $default && empty($price)
1782
+				? 0
1783
+				: $price->ID(),
1784
+			'PRC_is_default'        => $default && empty($price)
1785
+				? 0
1786
+				: $price->get('PRC_is_default'),
1787
+			'PRC_name'              => $default && empty($price)
1788
+				? ''
1789
+				: $price->get('PRC_name'),
1790
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1791
+			'show_plus_or_minus'    => $default && empty($price)
1792
+				? ''
1793
+				: ' style="display:none;"',
1794
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1795
+				? ' style="display:none;"'
1796
+				: '',
1797
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1798
+				? ' style="display:none;"'
1799
+				: '',
1800
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1801
+				? ' style="display:none"'
1802
+				: '',
1803
+			'PRC_amount'            => $default && empty($price)
1804
+				? 0
1805
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1806
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1807
+				? ' style="display:none;"'
1808
+				: '',
1809
+			'show_trash_icon'       => $show_trash
1810
+				? ''
1811
+				: ' style="display:none;"',
1812
+			'show_create_button'    => $show_create
1813
+				? ''
1814
+				: ' style="display:none;"',
1815
+			'PRC_desc'              => $default && empty($price)
1816
+				? ''
1817
+				: $price->get('PRC_desc'),
1818
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1819
+		);
1820
+		$template_args = apply_filters(
1821
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1822
+			$template_args,
1823
+			$ticket_row,
1824
+			$price_row,
1825
+			$price,
1826
+			$default,
1827
+			$ticket,
1828
+			$show_trash,
1829
+			$show_create,
1830
+			$this->_is_creating_event
1831
+		);
1832
+		return EEH_Template::display_template(
1833
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1834
+			$template_args,
1835
+			true
1836
+		);
1837
+	}
1838 1838
 
1839 1839
 
1840
-    /**
1841
-     * @param int      $ticket_row
1842
-     * @param int      $price_row
1843
-     * @param EE_Price $price
1844
-     * @param bool     $default
1845
-     * @param bool     $disabled
1846
-     * @return mixed
1847
-     * @throws ReflectionException
1848
-     * @throws InvalidArgumentException
1849
-     * @throws InvalidInterfaceException
1850
-     * @throws InvalidDataTypeException
1851
-     * @throws DomainException
1852
-     * @throws EE_Error
1853
-     */
1854
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1855
-    {
1856
-        if ($price->is_base_price()) {
1857
-            return $this->_get_base_price_template(
1858
-                $ticket_row,
1859
-                $price_row,
1860
-                $price,
1861
-                $default
1862
-            );
1863
-        }
1864
-        return $this->_get_price_modifier_template(
1865
-            $ticket_row,
1866
-            $price_row,
1867
-            $price,
1868
-            $default,
1869
-            $disabled
1870
-        );
1871
-    }
1840
+	/**
1841
+	 * @param int      $ticket_row
1842
+	 * @param int      $price_row
1843
+	 * @param EE_Price $price
1844
+	 * @param bool     $default
1845
+	 * @param bool     $disabled
1846
+	 * @return mixed
1847
+	 * @throws ReflectionException
1848
+	 * @throws InvalidArgumentException
1849
+	 * @throws InvalidInterfaceException
1850
+	 * @throws InvalidDataTypeException
1851
+	 * @throws DomainException
1852
+	 * @throws EE_Error
1853
+	 */
1854
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1855
+	{
1856
+		if ($price->is_base_price()) {
1857
+			return $this->_get_base_price_template(
1858
+				$ticket_row,
1859
+				$price_row,
1860
+				$price,
1861
+				$default
1862
+			);
1863
+		}
1864
+		return $this->_get_price_modifier_template(
1865
+			$ticket_row,
1866
+			$price_row,
1867
+			$price,
1868
+			$default,
1869
+			$disabled
1870
+		);
1871
+	}
1872 1872
 
1873 1873
 
1874
-    /**
1875
-     * @param int      $ticket_row
1876
-     * @param int      $price_row
1877
-     * @param EE_Price $price
1878
-     * @param bool     $default
1879
-     * @return mixed
1880
-     * @throws DomainException
1881
-     * @throws EE_Error
1882
-     */
1883
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1884
-    {
1885
-        $template_args = array(
1886
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1887
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1888
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1889
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1890
-            'price_selected_operator'   => '+',
1891
-            'price_selected_is_percent' => 0,
1892
-        );
1893
-        $template_args = apply_filters(
1894
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1895
-            $template_args,
1896
-            $ticket_row,
1897
-            $price_row,
1898
-            $price,
1899
-            $default,
1900
-            $this->_is_creating_event
1901
-        );
1902
-        return EEH_Template::display_template(
1903
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1904
-            $template_args,
1905
-            true
1906
-        );
1907
-    }
1874
+	/**
1875
+	 * @param int      $ticket_row
1876
+	 * @param int      $price_row
1877
+	 * @param EE_Price $price
1878
+	 * @param bool     $default
1879
+	 * @return mixed
1880
+	 * @throws DomainException
1881
+	 * @throws EE_Error
1882
+	 */
1883
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1884
+	{
1885
+		$template_args = array(
1886
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1887
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1888
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1889
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1890
+			'price_selected_operator'   => '+',
1891
+			'price_selected_is_percent' => 0,
1892
+		);
1893
+		$template_args = apply_filters(
1894
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1895
+			$template_args,
1896
+			$ticket_row,
1897
+			$price_row,
1898
+			$price,
1899
+			$default,
1900
+			$this->_is_creating_event
1901
+		);
1902
+		return EEH_Template::display_template(
1903
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1904
+			$template_args,
1905
+			true
1906
+		);
1907
+	}
1908 1908
 
1909 1909
 
1910
-    /**
1911
-     * @param int      $ticket_row
1912
-     * @param int      $price_row
1913
-     * @param EE_Price $price
1914
-     * @param bool     $default
1915
-     * @param bool     $disabled
1916
-     * @return mixed
1917
-     * @throws ReflectionException
1918
-     * @throws InvalidArgumentException
1919
-     * @throws InvalidInterfaceException
1920
-     * @throws InvalidDataTypeException
1921
-     * @throws DomainException
1922
-     * @throws EE_Error
1923
-     */
1924
-    protected function _get_price_modifier_template(
1925
-        $ticket_row,
1926
-        $price_row,
1927
-        $price,
1928
-        $default,
1929
-        $disabled = false
1930
-    ) {
1931
-        $select_name = $default && ! $price instanceof EE_Price
1932
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1933
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1934
-        /** @var EEM_Price_Type $price_type_model */
1935
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1936
-        $price_types = $price_type_model->get_all(array(
1937
-            array(
1938
-                'OR' => array(
1939
-                    'PBT_ID'  => '2',
1940
-                    'PBT_ID*' => '3',
1941
-                ),
1942
-            ),
1943
-        ));
1944
-        $all_price_types = $default && ! $price instanceof EE_Price
1945
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1946
-            : array();
1947
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1948
-        $price_option_spans = '';
1949
-        // setup price types for selector
1950
-        foreach ($price_types as $price_type) {
1951
-            if (! $price_type instanceof EE_Price_Type) {
1952
-                continue;
1953
-            }
1954
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1955
-            // while we're in the loop let's setup the option spans used by js
1956
-            $span_args = array(
1957
-                'PRT_ID'         => $price_type->ID(),
1958
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1959
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1960
-            );
1961
-            $price_option_spans .= EEH_Template::display_template(
1962
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1963
-                $span_args,
1964
-                true
1965
-            );
1966
-        }
1967
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1968
-            : $select_name;
1969
-        $select_input = new EE_Select_Input(
1970
-            $all_price_types,
1971
-            array(
1972
-                'default'               => $selected_price_type_id,
1973
-                'html_name'             => $select_name,
1974
-                'html_class'            => 'edit-price-PRT_ID',
1975
-                'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1976
-            )
1977
-        );
1978
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1979
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1980
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1981
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1982
-        $template_args = array(
1983
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1984
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1985
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1986
-            'main_name'                 => $select_name,
1987
-            'selected_price_type_id'    => $selected_price_type_id,
1988
-            'price_option_spans'        => $price_option_spans,
1989
-            'price_selected_operator'   => $price_selected_operator,
1990
-            'price_selected_is_percent' => $price_selected_is_percent,
1991
-            'disabled'                  => $disabled,
1992
-        );
1993
-        $template_args = apply_filters(
1994
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1995
-            $template_args,
1996
-            $ticket_row,
1997
-            $price_row,
1998
-            $price,
1999
-            $default,
2000
-            $disabled,
2001
-            $this->_is_creating_event
2002
-        );
2003
-        return EEH_Template::display_template(
2004
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2005
-            $template_args,
2006
-            true
2007
-        );
2008
-    }
1910
+	/**
1911
+	 * @param int      $ticket_row
1912
+	 * @param int      $price_row
1913
+	 * @param EE_Price $price
1914
+	 * @param bool     $default
1915
+	 * @param bool     $disabled
1916
+	 * @return mixed
1917
+	 * @throws ReflectionException
1918
+	 * @throws InvalidArgumentException
1919
+	 * @throws InvalidInterfaceException
1920
+	 * @throws InvalidDataTypeException
1921
+	 * @throws DomainException
1922
+	 * @throws EE_Error
1923
+	 */
1924
+	protected function _get_price_modifier_template(
1925
+		$ticket_row,
1926
+		$price_row,
1927
+		$price,
1928
+		$default,
1929
+		$disabled = false
1930
+	) {
1931
+		$select_name = $default && ! $price instanceof EE_Price
1932
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1933
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1934
+		/** @var EEM_Price_Type $price_type_model */
1935
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1936
+		$price_types = $price_type_model->get_all(array(
1937
+			array(
1938
+				'OR' => array(
1939
+					'PBT_ID'  => '2',
1940
+					'PBT_ID*' => '3',
1941
+				),
1942
+			),
1943
+		));
1944
+		$all_price_types = $default && ! $price instanceof EE_Price
1945
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1946
+			: array();
1947
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1948
+		$price_option_spans = '';
1949
+		// setup price types for selector
1950
+		foreach ($price_types as $price_type) {
1951
+			if (! $price_type instanceof EE_Price_Type) {
1952
+				continue;
1953
+			}
1954
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1955
+			// while we're in the loop let's setup the option spans used by js
1956
+			$span_args = array(
1957
+				'PRT_ID'         => $price_type->ID(),
1958
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1959
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1960
+			);
1961
+			$price_option_spans .= EEH_Template::display_template(
1962
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1963
+				$span_args,
1964
+				true
1965
+			);
1966
+		}
1967
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1968
+			: $select_name;
1969
+		$select_input = new EE_Select_Input(
1970
+			$all_price_types,
1971
+			array(
1972
+				'default'               => $selected_price_type_id,
1973
+				'html_name'             => $select_name,
1974
+				'html_class'            => 'edit-price-PRT_ID',
1975
+				'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1976
+			)
1977
+		);
1978
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1979
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1980
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1981
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1982
+		$template_args = array(
1983
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1984
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1985
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1986
+			'main_name'                 => $select_name,
1987
+			'selected_price_type_id'    => $selected_price_type_id,
1988
+			'price_option_spans'        => $price_option_spans,
1989
+			'price_selected_operator'   => $price_selected_operator,
1990
+			'price_selected_is_percent' => $price_selected_is_percent,
1991
+			'disabled'                  => $disabled,
1992
+		);
1993
+		$template_args = apply_filters(
1994
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1995
+			$template_args,
1996
+			$ticket_row,
1997
+			$price_row,
1998
+			$price,
1999
+			$default,
2000
+			$disabled,
2001
+			$this->_is_creating_event
2002
+		);
2003
+		return EEH_Template::display_template(
2004
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2005
+			$template_args,
2006
+			true
2007
+		);
2008
+	}
2009 2009
 
2010 2010
 
2011
-    /**
2012
-     * @param int              $datetime_row
2013
-     * @param int              $ticket_row
2014
-     * @param EE_Datetime|null $datetime
2015
-     * @param EE_Ticket|null   $ticket
2016
-     * @param array            $ticket_datetimes
2017
-     * @param bool             $default
2018
-     * @return mixed
2019
-     * @throws DomainException
2020
-     * @throws EE_Error
2021
-     */
2022
-    protected function _get_ticket_datetime_list_item(
2023
-        $datetime_row,
2024
-        $ticket_row,
2025
-        $datetime,
2026
-        $ticket,
2027
-        $ticket_datetimes = array(),
2028
-        $default
2029
-    ) {
2030
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2031
-            ? $ticket_datetimes[ $ticket->ID() ]
2032
-            : array();
2033
-        $template_args = array(
2034
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2035
-                ? 'DTTNUM'
2036
-                : $datetime_row,
2037
-            'tkt_row'                  => $default
2038
-                ? 'TICKETNUM'
2039
-                : $ticket_row,
2040
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2041
-                ? ' ticket-selected'
2042
-                : '',
2043
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2044
-                ? ' checked="checked"'
2045
-                : '',
2046
-            'DTT_name'                 => $default && empty($datetime)
2047
-                ? 'DTTNAME'
2048
-                : $datetime->get_dtt_display_name(true),
2049
-            'tkt_status_class'         => '',
2050
-        );
2051
-        $template_args = apply_filters(
2052
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2053
-            $template_args,
2054
-            $datetime_row,
2055
-            $ticket_row,
2056
-            $datetime,
2057
-            $ticket,
2058
-            $ticket_datetimes,
2059
-            $default,
2060
-            $this->_is_creating_event
2061
-        );
2062
-        return EEH_Template::display_template(
2063
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2064
-            $template_args,
2065
-            true
2066
-        );
2067
-    }
2011
+	/**
2012
+	 * @param int              $datetime_row
2013
+	 * @param int              $ticket_row
2014
+	 * @param EE_Datetime|null $datetime
2015
+	 * @param EE_Ticket|null   $ticket
2016
+	 * @param array            $ticket_datetimes
2017
+	 * @param bool             $default
2018
+	 * @return mixed
2019
+	 * @throws DomainException
2020
+	 * @throws EE_Error
2021
+	 */
2022
+	protected function _get_ticket_datetime_list_item(
2023
+		$datetime_row,
2024
+		$ticket_row,
2025
+		$datetime,
2026
+		$ticket,
2027
+		$ticket_datetimes = array(),
2028
+		$default
2029
+	) {
2030
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2031
+			? $ticket_datetimes[ $ticket->ID() ]
2032
+			: array();
2033
+		$template_args = array(
2034
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2035
+				? 'DTTNUM'
2036
+				: $datetime_row,
2037
+			'tkt_row'                  => $default
2038
+				? 'TICKETNUM'
2039
+				: $ticket_row,
2040
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2041
+				? ' ticket-selected'
2042
+				: '',
2043
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2044
+				? ' checked="checked"'
2045
+				: '',
2046
+			'DTT_name'                 => $default && empty($datetime)
2047
+				? 'DTTNAME'
2048
+				: $datetime->get_dtt_display_name(true),
2049
+			'tkt_status_class'         => '',
2050
+		);
2051
+		$template_args = apply_filters(
2052
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2053
+			$template_args,
2054
+			$datetime_row,
2055
+			$ticket_row,
2056
+			$datetime,
2057
+			$ticket,
2058
+			$ticket_datetimes,
2059
+			$default,
2060
+			$this->_is_creating_event
2061
+		);
2062
+		return EEH_Template::display_template(
2063
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2064
+			$template_args,
2065
+			true
2066
+		);
2067
+	}
2068 2068
 
2069 2069
 
2070
-    /**
2071
-     * @param array $all_datetimes
2072
-     * @param array $all_tickets
2073
-     * @return mixed
2074
-     * @throws ReflectionException
2075
-     * @throws InvalidArgumentException
2076
-     * @throws InvalidInterfaceException
2077
-     * @throws InvalidDataTypeException
2078
-     * @throws DomainException
2079
-     * @throws EE_Error
2080
-     */
2081
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2082
-    {
2083
-        $template_args = array(
2084
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2085
-                'DTTNUM',
2086
-                null,
2087
-                true,
2088
-                $all_datetimes
2089
-            ),
2090
-            'default_ticket_row'                       => $this->_get_ticket_row(
2091
-                'TICKETNUM',
2092
-                null,
2093
-                array(),
2094
-                array(),
2095
-                true
2096
-            ),
2097
-            'default_price_row'                        => $this->_get_ticket_price_row(
2098
-                'TICKETNUM',
2099
-                'PRICENUM',
2100
-                null,
2101
-                true,
2102
-                null
2103
-            ),
2104
-            'default_price_rows'                       => '',
2105
-            'default_base_price_amount'                => 0,
2106
-            'default_base_price_name'                  => '',
2107
-            'default_base_price_description'           => '',
2108
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2109
-                'TICKETNUM',
2110
-                'PRICENUM',
2111
-                null,
2112
-                true
2113
-            ),
2114
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2115
-                'DTTNUM',
2116
-                null,
2117
-                array(),
2118
-                array(),
2119
-                true
2120
-            ),
2121
-            'existing_available_datetime_tickets_list' => '',
2122
-            'existing_available_ticket_datetimes_list' => '',
2123
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2124
-                'DTTNUM',
2125
-                'TICKETNUM',
2126
-                null,
2127
-                null,
2128
-                array(),
2129
-                true
2130
-            ),
2131
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2132
-                'DTTNUM',
2133
-                'TICKETNUM',
2134
-                null,
2135
-                null,
2136
-                array(),
2137
-                true
2138
-            ),
2139
-        );
2140
-        $ticket_row = 1;
2141
-        foreach ($all_tickets as $ticket) {
2142
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2143
-                'DTTNUM',
2144
-                $ticket_row,
2145
-                null,
2146
-                $ticket,
2147
-                array(),
2148
-                true
2149
-            );
2150
-            $ticket_row++;
2151
-        }
2152
-        $datetime_row = 1;
2153
-        foreach ($all_datetimes as $datetime) {
2154
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2155
-                $datetime_row,
2156
-                'TICKETNUM',
2157
-                $datetime,
2158
-                null,
2159
-                array(),
2160
-                true
2161
-            );
2162
-            $datetime_row++;
2163
-        }
2164
-        /** @var EEM_Price $price_model */
2165
-        $price_model = EE_Registry::instance()->load_model('Price');
2166
-        $default_prices = $price_model->get_all_default_prices();
2167
-        $price_row = 1;
2168
-        foreach ($default_prices as $price) {
2169
-            if (! $price instanceof EE_Price) {
2170
-                continue;
2171
-            }
2172
-            if ($price->is_base_price()) {
2173
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2174
-                    'PRC_amount',
2175
-                    'localized_float'
2176
-                );
2177
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2178
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2179
-                $price_row++;
2180
-                continue;
2181
-            }
2182
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2183
-                             || count($default_prices) === 1);
2184
-            $show_create = ! (count($default_prices) > 1
2185
-                              && count($default_prices)
2186
-                                 !== $price_row);
2187
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2188
-                'TICKETNUM',
2189
-                $price_row,
2190
-                $price,
2191
-                true,
2192
-                null,
2193
-                $show_trash,
2194
-                $show_create
2195
-            );
2196
-            $price_row++;
2197
-        }
2198
-        $template_args = apply_filters(
2199
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2200
-            $template_args,
2201
-            $all_datetimes,
2202
-            $all_tickets,
2203
-            $this->_is_creating_event
2204
-        );
2205
-        return EEH_Template::display_template(
2206
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2207
-            $template_args,
2208
-            true
2209
-        );
2210
-    }
2070
+	/**
2071
+	 * @param array $all_datetimes
2072
+	 * @param array $all_tickets
2073
+	 * @return mixed
2074
+	 * @throws ReflectionException
2075
+	 * @throws InvalidArgumentException
2076
+	 * @throws InvalidInterfaceException
2077
+	 * @throws InvalidDataTypeException
2078
+	 * @throws DomainException
2079
+	 * @throws EE_Error
2080
+	 */
2081
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2082
+	{
2083
+		$template_args = array(
2084
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2085
+				'DTTNUM',
2086
+				null,
2087
+				true,
2088
+				$all_datetimes
2089
+			),
2090
+			'default_ticket_row'                       => $this->_get_ticket_row(
2091
+				'TICKETNUM',
2092
+				null,
2093
+				array(),
2094
+				array(),
2095
+				true
2096
+			),
2097
+			'default_price_row'                        => $this->_get_ticket_price_row(
2098
+				'TICKETNUM',
2099
+				'PRICENUM',
2100
+				null,
2101
+				true,
2102
+				null
2103
+			),
2104
+			'default_price_rows'                       => '',
2105
+			'default_base_price_amount'                => 0,
2106
+			'default_base_price_name'                  => '',
2107
+			'default_base_price_description'           => '',
2108
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2109
+				'TICKETNUM',
2110
+				'PRICENUM',
2111
+				null,
2112
+				true
2113
+			),
2114
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2115
+				'DTTNUM',
2116
+				null,
2117
+				array(),
2118
+				array(),
2119
+				true
2120
+			),
2121
+			'existing_available_datetime_tickets_list' => '',
2122
+			'existing_available_ticket_datetimes_list' => '',
2123
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2124
+				'DTTNUM',
2125
+				'TICKETNUM',
2126
+				null,
2127
+				null,
2128
+				array(),
2129
+				true
2130
+			),
2131
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2132
+				'DTTNUM',
2133
+				'TICKETNUM',
2134
+				null,
2135
+				null,
2136
+				array(),
2137
+				true
2138
+			),
2139
+		);
2140
+		$ticket_row = 1;
2141
+		foreach ($all_tickets as $ticket) {
2142
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2143
+				'DTTNUM',
2144
+				$ticket_row,
2145
+				null,
2146
+				$ticket,
2147
+				array(),
2148
+				true
2149
+			);
2150
+			$ticket_row++;
2151
+		}
2152
+		$datetime_row = 1;
2153
+		foreach ($all_datetimes as $datetime) {
2154
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2155
+				$datetime_row,
2156
+				'TICKETNUM',
2157
+				$datetime,
2158
+				null,
2159
+				array(),
2160
+				true
2161
+			);
2162
+			$datetime_row++;
2163
+		}
2164
+		/** @var EEM_Price $price_model */
2165
+		$price_model = EE_Registry::instance()->load_model('Price');
2166
+		$default_prices = $price_model->get_all_default_prices();
2167
+		$price_row = 1;
2168
+		foreach ($default_prices as $price) {
2169
+			if (! $price instanceof EE_Price) {
2170
+				continue;
2171
+			}
2172
+			if ($price->is_base_price()) {
2173
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2174
+					'PRC_amount',
2175
+					'localized_float'
2176
+				);
2177
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2178
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2179
+				$price_row++;
2180
+				continue;
2181
+			}
2182
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2183
+							 || count($default_prices) === 1);
2184
+			$show_create = ! (count($default_prices) > 1
2185
+							  && count($default_prices)
2186
+								 !== $price_row);
2187
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2188
+				'TICKETNUM',
2189
+				$price_row,
2190
+				$price,
2191
+				true,
2192
+				null,
2193
+				$show_trash,
2194
+				$show_create
2195
+			);
2196
+			$price_row++;
2197
+		}
2198
+		$template_args = apply_filters(
2199
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2200
+			$template_args,
2201
+			$all_datetimes,
2202
+			$all_tickets,
2203
+			$this->_is_creating_event
2204
+		);
2205
+		return EEH_Template::display_template(
2206
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2207
+			$template_args,
2208
+			true
2209
+		);
2210
+	}
2211 2211
 }
Please login to merge, or discard this patch.
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.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 2 patches
Indentation   +1394 added lines, -1394 removed lines patch added patch discarded remove patch
@@ -15,1401 +15,1401 @@
 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
-                        $view = $this->admin_config->advancedEditorView();
335
-                        $perPage = $this->admin_config->advancedEditorPerPage();
336
-                        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
+						$view = $this->admin_config->advancedEditorView();
335
+						$perPage = $this->admin_config->advancedEditorPerPage();
336
+						echo '
337 337
         <script type="text/javascript">
338 338
             /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; var eeEditorListView = "' . $view . '"; var eeEditorPerPage = ' . $perPage . '; /* ]]> */
339 339
         </script>';
340
-                    }
341
-                }
342
-            );
343
-        }
344
-    }
345
-
346
-
347
-    /**
348
-     * Returns template for the additional datetime.
349
-     *
350
-     * @param $template
351
-     * @param $template_args
352
-     * @return mixed
353
-     * @throws DomainException
354
-     */
355
-    public function add_additional_datetime_button($template, $template_args)
356
-    {
357
-        return EEH_Template::display_template(
358
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
359
-            $template_args,
360
-            true
361
-        );
362
-    }
363
-
364
-
365
-    /**
366
-     * Returns the template for cloning a datetime.
367
-     *
368
-     * @param $template
369
-     * @param $template_args
370
-     * @return mixed
371
-     * @throws DomainException
372
-     */
373
-    public function add_datetime_clone_button($template, $template_args)
374
-    {
375
-        return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
377
-            $template_args,
378
-            true
379
-        );
380
-    }
381
-
382
-
383
-    /**
384
-     * Returns the template for datetime timezones.
385
-     *
386
-     * @param $template
387
-     * @param $template_args
388
-     * @return mixed
389
-     * @throws DomainException
390
-     */
391
-    public function datetime_timezones_template($template, $template_args)
392
-    {
393
-        return EEH_Template::display_template(
394
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
395
-            $template_args,
396
-            true
397
-        );
398
-    }
399
-
400
-
401
-    /**
402
-     * Sets the views for the default list table view.
403
-     */
404
-    protected function _set_list_table_views_default()
405
-    {
406
-        parent::_set_list_table_views_default();
407
-        $new_views = array(
408
-            'today' => array(
409
-                'slug'        => 'today',
410
-                'label'       => esc_html__('Today', 'event_espresso'),
411
-                'count'       => $this->total_events_today(),
412
-                'bulk_action' => array(
413
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
414
-                ),
415
-            ),
416
-            'month' => array(
417
-                'slug'        => 'month',
418
-                'label'       => esc_html__('This Month', 'event_espresso'),
419
-                'count'       => $this->total_events_this_month(),
420
-                'bulk_action' => array(
421
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
422
-                ),
423
-            ),
424
-        );
425
-        $this->_views = array_merge($this->_views, $new_views);
426
-    }
427
-
428
-
429
-    /**
430
-     * Returns the extra action links for the default list table view.
431
-     *
432
-     * @param array     $action_links
433
-     * @param \EE_Event $event
434
-     * @return array
435
-     * @throws EE_Error
436
-     */
437
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
438
-    {
439
-        if (EE_Registry::instance()->CAP->current_user_can(
440
-            'ee_read_registrations',
441
-            'espresso_registrations_reports',
442
-            $event->ID()
443
-        )
444
-        ) {
445
-            $reports_query_args = array(
446
-                'action' => 'reports',
447
-                'EVT_ID' => $event->ID(),
448
-            );
449
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
450
-            $action_links[] = '<a href="'
451
-                              . $reports_link
452
-                              . '" title="'
453
-                              . esc_attr__('View Report', 'event_espresso')
454
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
455
-                              . "\n\t";
456
-        }
457
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
458
-            EE_Registry::instance()->load_helper('MSG_Template');
459
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
460
-                'see_notifications_for',
461
-                null,
462
-                array('EVT_ID' => $event->ID())
463
-            );
464
-        }
465
-        return $action_links;
466
-    }
467
-
468
-
469
-    /**
470
-     * @param $items
471
-     * @return mixed
472
-     */
473
-    public function additional_legend_items($items)
474
-    {
475
-        if (EE_Registry::instance()->CAP->current_user_can(
476
-            'ee_read_registrations',
477
-            'espresso_registrations_reports'
478
-        )
479
-        ) {
480
-            $items['reports'] = array(
481
-                'class' => 'dashicons dashicons-chart-bar',
482
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
483
-            );
484
-        }
485
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
486
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
487
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
488
-                $items['view_related_messages'] = array(
489
-                    'class' => $related_for_icon['css_class'],
490
-                    'desc'  => $related_for_icon['label'],
491
-                );
492
-            }
493
-        }
494
-        return $items;
495
-    }
496
-
497
-
498
-    /**
499
-     * This is the callback method for the duplicate event route
500
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
501
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
502
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
503
-     * After duplication the redirect is to the new event edit page.
504
-     *
505
-     * @return void
506
-     * @access protected
507
-     * @throws EE_Error If EE_Event is not available with given ID
508
-     */
509
-    protected function _duplicate_event()
510
-    {
511
-        // first make sure the ID for the event is in the request.
512
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
513
-        if (! isset($this->_req_data['EVT_ID'])) {
514
-            EE_Error::add_error(
515
-                esc_html__(
516
-                    'In order to duplicate an event an Event ID is required.  None was given.',
517
-                    'event_espresso'
518
-                ),
519
-                __FILE__,
520
-                __FUNCTION__,
521
-                __LINE__
522
-            );
523
-            $this->_redirect_after_action(false, '', '', array(), true);
524
-            return;
525
-        }
526
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
527
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
528
-        if (! $orig_event instanceof EE_Event) {
529
-            throw new EE_Error(
530
-                sprintf(
531
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
532
-                    $this->_req_data['EVT_ID']
533
-                )
534
-            );
535
-        }
536
-        // k now let's clone the $orig_event before getting relations
537
-        $new_event = clone $orig_event;
538
-        // original datetimes
539
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
540
-        // other original relations
541
-        $orig_ven = $orig_event->get_many_related('Venue');
542
-        // reset the ID and modify other details to make it clear this is a dupe
543
-        $new_event->set('EVT_ID', 0);
544
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
545
-        $new_event->set('EVT_name', $new_name);
546
-        $new_event->set(
547
-            'EVT_slug',
548
-            wp_unique_post_slug(
549
-                sanitize_title($orig_event->name()),
550
-                0,
551
-                'publish',
552
-                'espresso_events',
553
-                0
554
-            )
555
-        );
556
-        $new_event->set('status', 'draft');
557
-        // duplicate discussion settings
558
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
559
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
560
-        // save the new event
561
-        $new_event->save();
562
-        // venues
563
-        foreach ($orig_ven as $ven) {
564
-            $new_event->_add_relation_to($ven, 'Venue');
565
-        }
566
-        $new_event->save();
567
-        // now we need to get the question group relations and handle that
568
-        // first primary question groups
569
-        $orig_primary_qgs = $orig_event->get_many_related(
570
-            'Question_Group',
571
-            array(array('Event_Question_Group.EQG_primary' => 1))
572
-        );
573
-        if (! empty($orig_primary_qgs)) {
574
-            foreach ($orig_primary_qgs as $id => $obj) {
575
-                if ($obj instanceof EE_Question_Group) {
576
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
577
-                }
578
-            }
579
-        }
580
-        // next additional attendee question groups
581
-        $orig_additional_qgs = $orig_event->get_many_related(
582
-            'Question_Group',
583
-            array(array('Event_Question_Group.EQG_primary' => 0))
584
-        );
585
-        if (! empty($orig_additional_qgs)) {
586
-            foreach ($orig_additional_qgs as $id => $obj) {
587
-                if ($obj instanceof EE_Question_Group) {
588
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
589
-                }
590
-            }
591
-        }
592
-
593
-        $new_event->save();
594
-
595
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
596
-        $cloned_tickets = array();
597
-        foreach ($orig_datetimes as $orig_dtt) {
598
-            if (! $orig_dtt instanceof EE_Datetime) {
599
-                continue;
600
-            }
601
-            $new_dtt = clone $orig_dtt;
602
-            $orig_tkts = $orig_dtt->tickets();
603
-            // save new dtt then add to event
604
-            $new_dtt->set('DTT_ID', 0);
605
-            $new_dtt->set('DTT_sold', 0);
606
-            $new_dtt->set_reserved(0);
607
-            $new_dtt->save();
608
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
609
-            $new_event->save();
610
-            // now let's get the ticket relations setup.
611
-            foreach ((array) $orig_tkts as $orig_tkt) {
612
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
613
-                if (! $orig_tkt instanceof EE_Ticket) {
614
-                    continue;
615
-                }
616
-                // is this ticket archived?  If it is then let's skip
617
-                if ($orig_tkt->get('TKT_deleted')) {
618
-                    continue;
619
-                }
620
-                // does this original ticket already exist in the clone_tickets cache?
621
-                //  If so we'll just use the new ticket from it.
622
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
623
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
624
-                } else {
625
-                    $new_tkt = clone $orig_tkt;
626
-                    // get relations on the $orig_tkt that we need to setup.
627
-                    $orig_prices = $orig_tkt->prices();
628
-                    $new_tkt->set('TKT_ID', 0);
629
-                    $new_tkt->set('TKT_sold', 0);
630
-                    $new_tkt->set('TKT_reserved', 0);
631
-                    $new_tkt->save(); // make sure new ticket has ID.
632
-                    // price relations on new ticket need to be setup.
633
-                    foreach ($orig_prices as $orig_price) {
634
-                        $new_price = clone $orig_price;
635
-                        $new_price->set('PRC_ID', 0);
636
-                        $new_price->save();
637
-                        $new_tkt->_add_relation_to($new_price, 'Price');
638
-                        $new_tkt->save();
639
-                    }
640
-
641
-                    do_action(
642
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
643
-                        $orig_tkt,
644
-                        $new_tkt,
645
-                        $orig_prices,
646
-                        $orig_event,
647
-                        $orig_dtt,
648
-                        $new_dtt
649
-                    );
650
-                }
651
-                // k now we can add the new ticket as a relation to the new datetime
652
-                // and make sure its added to our cached $cloned_tickets array
653
-                // for use with later datetimes that have the same ticket.
654
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
655
-                $new_dtt->save();
656
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
657
-            }
658
-        }
659
-        // clone taxonomy information
660
-        $taxonomies_to_clone_with = apply_filters(
661
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
662
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
663
-        );
664
-        // get terms for original event (notice)
665
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
666
-        // loop through terms and add them to new event.
667
-        foreach ($orig_terms as $term) {
668
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
669
-        }
670
-
671
-        // duplicate other core WP_Post items for this event.
672
-        // post thumbnail (feature image).
673
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
674
-        if ($feature_image_id) {
675
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
676
-        }
677
-
678
-        // duplicate page_template setting
679
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
680
-        if ($page_template) {
681
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
682
-        }
683
-
684
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
685
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
686
-        if ($new_event->ID()) {
687
-            $redirect_args = array(
688
-                'post'   => $new_event->ID(),
689
-                'action' => 'edit',
690
-            );
691
-            EE_Error::add_success(
692
-                esc_html__(
693
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
694
-                    'event_espresso'
695
-                )
696
-            );
697
-        } else {
698
-            $redirect_args = array(
699
-                'action' => 'default',
700
-            );
701
-            EE_Error::add_error(
702
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
703
-                __FILE__,
704
-                __FUNCTION__,
705
-                __LINE__
706
-            );
707
-        }
708
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
709
-    }
710
-
711
-
712
-    /**
713
-     * Generates output for the import page.
714
-     *
715
-     * @throws DomainException
716
-     */
717
-    protected function _import_page()
718
-    {
719
-        $title = esc_html__('Import', 'event_espresso');
720
-        $intro = esc_html__(
721
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
722
-            'event_espresso'
723
-        );
724
-        $form_url = EVENTS_ADMIN_URL;
725
-        $action = 'import_events';
726
-        $type = 'csv';
727
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
728
-            $title,
729
-            $intro,
730
-            $form_url,
731
-            $action,
732
-            $type
733
-        );
734
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
735
-            array('action' => 'sample_export_file'),
736
-            $this->_admin_base_url
737
-        );
738
-        $content = EEH_Template::display_template(
739
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
740
-            $this->_template_args,
741
-            true
742
-        );
743
-        $this->_template_args['admin_page_content'] = $content;
744
-        $this->display_admin_page_with_sidebar();
745
-    }
746
-
747
-
748
-    /**
749
-     * _import_events
750
-     * This handles displaying the screen and running imports for importing events.
751
-     *
752
-     * @return void
753
-     */
754
-    protected function _import_events()
755
-    {
756
-        require_once(EE_CLASSES . 'EE_Import.class.php');
757
-        $success = EE_Import::instance()->import();
758
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
759
-    }
760
-
761
-
762
-    /**
763
-     * _events_export
764
-     * Will export all (or just the given event) to a Excel compatible file.
765
-     *
766
-     * @access protected
767
-     * @return void
768
-     */
769
-    protected function _events_export()
770
-    {
771
-        if (isset($this->_req_data['EVT_ID'])) {
772
-            $event_ids = $this->_req_data['EVT_ID'];
773
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
774
-            $event_ids = $this->_req_data['EVT_IDs'];
775
-        } else {
776
-            $event_ids = null;
777
-        }
778
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
779
-        $new_request_args = array(
780
-            'export' => 'report',
781
-            'action' => 'all_event_data',
782
-            'EVT_ID' => $event_ids,
783
-        );
784
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
785
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
-            require_once(EE_CLASSES . 'EE_Export.class.php');
787
-            $EE_Export = EE_Export::instance($this->_req_data);
788
-            $EE_Export->export();
789
-        }
790
-    }
791
-
792
-
793
-    /**
794
-     * handle category exports()
795
-     *
796
-     * @return void
797
-     */
798
-    protected function _categories_export()
799
-    {
800
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
801
-        $new_request_args = array(
802
-            'export'       => 'report',
803
-            'action'       => 'categories',
804
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
805
-        );
806
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
807
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
808
-            require_once(EE_CLASSES . 'EE_Export.class.php');
809
-            $EE_Export = EE_Export::instance($this->_req_data);
810
-            $EE_Export->export();
811
-        }
812
-    }
813
-
814
-
815
-    /**
816
-     * Creates a sample CSV file for importing
817
-     */
818
-    protected function _sample_export_file()
819
-    {
820
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
821
-        EE_Export::instance()->export_sample();
822
-    }
823
-
824
-
825
-    /*************        Template Settings        *************/
826
-    /**
827
-     * Generates template settings page output
828
-     *
829
-     * @throws DomainException
830
-     * @throws EE_Error
831
-     */
832
-    protected function _template_settings()
833
-    {
834
-        $this->_template_args['values'] = $this->_yes_no_values;
835
-        /**
836
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
837
-         * from General_Settings_Admin_Page to here.
838
-         */
839
-        $this->_template_args = apply_filters(
840
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
841
-            $this->_template_args
842
-        );
843
-        $this->_set_add_edit_form_tags('update_template_settings');
844
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
845
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
846
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
847
-            $this->_template_args,
848
-            true
849
-        );
850
-        $this->display_admin_page_with_sidebar();
851
-    }
852
-
853
-
854
-    /**
855
-     * Handler for updating template settings.
856
-     *
857
-     * @throws InvalidInterfaceException
858
-     * @throws InvalidDataTypeException
859
-     * @throws InvalidArgumentException
860
-     */
861
-    protected function _update_template_settings()
862
-    {
863
-        /**
864
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
865
-         * from General_Settings_Admin_Page to here.
866
-         */
867
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
868
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
869
-            EE_Registry::instance()->CFG->template_settings,
870
-            $this->_req_data
871
-        );
872
-        // update custom post type slugs and detect if we need to flush rewrite rules
873
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
874
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
875
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
876
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
877
-        $what = 'Template Settings';
878
-        $success = $this->_update_espresso_configuration(
879
-            $what,
880
-            EE_Registry::instance()->CFG->template_settings,
881
-            __FILE__,
882
-            __FUNCTION__,
883
-            __LINE__
884
-        );
885
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
886
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
887
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
888
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
889
-            );
890
-            $rewrite_rules->flush();
891
-        }
892
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
893
-    }
894
-
895
-
896
-    /**
897
-     * _premium_event_editor_meta_boxes
898
-     * add all metaboxes related to the event_editor
899
-     *
900
-     * @access protected
901
-     * @return void
902
-     * @throws EE_Error
903
-     */
904
-    protected function _premium_event_editor_meta_boxes()
905
-    {
906
-        $this->verify_cpt_object();
907
-        add_meta_box(
908
-            'espresso_event_editor_event_options',
909
-            esc_html__('Event Registration Options', 'event_espresso'),
910
-            array($this, 'registration_options_meta_box'),
911
-            $this->page_slug,
912
-            'side',
913
-            'core'
914
-        );
915
-    }
916
-
917
-
918
-    /**
919
-     * override caf metabox
920
-     *
921
-     * @return void
922
-     * @throws DomainException
923
-     */
924
-    public function registration_options_meta_box()
925
-    {
926
-        $yes_no_values = array(
927
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
928
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
929
-        );
930
-        $default_reg_status_values = EEM_Registration::reg_status_array(
931
-            array(
932
-                EEM_Registration::status_id_cancelled,
933
-                EEM_Registration::status_id_declined,
934
-                EEM_Registration::status_id_incomplete,
935
-                EEM_Registration::status_id_wait_list,
936
-            ),
937
-            true
938
-        );
939
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
940
-        $template_args['_event'] = $this->_cpt_model_obj;
941
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
942
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
943
-            'default_reg_status',
944
-            $default_reg_status_values,
945
-            $this->_cpt_model_obj->default_registration_status()
946
-        );
947
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
948
-            'display_desc',
949
-            $yes_no_values,
950
-            $this->_cpt_model_obj->display_description()
951
-        );
952
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
953
-            'display_ticket_selector',
954
-            $yes_no_values,
955
-            $this->_cpt_model_obj->display_ticket_selector(),
956
-            '',
957
-            '',
958
-            false
959
-        );
960
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
961
-            'EVT_default_registration_status',
962
-            $default_reg_status_values,
963
-            $this->_cpt_model_obj->default_registration_status()
964
-        );
965
-        $template_args['additional_registration_options'] = apply_filters(
966
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
967
-            '',
968
-            $template_args,
969
-            $yes_no_values,
970
-            $default_reg_status_values
971
-        );
972
-        EEH_Template::display_template(
973
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
974
-            $template_args
975
-        );
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * wp_list_table_mods for caf
982
-     * ============================
983
-     */
984
-    /**
985
-     * hook into list table filters and provide filters for caffeinated list table
986
-     *
987
-     * @param  array $old_filters    any existing filters present
988
-     * @param  array $list_table_obj the list table object
989
-     * @return array                  new filters
990
-     */
991
-    public function list_table_filters($old_filters, $list_table_obj)
992
-    {
993
-        $filters = array();
994
-        // first month/year filters
995
-        $filters[] = $this->espresso_event_months_dropdown();
996
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
997
-        // active status dropdown
998
-        if ($status !== 'draft') {
999
-            $filters[] = $this->active_status_dropdown(
1000
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1001
-            );
1002
-        }
1003
-        // category filter
1004
-        $filters[] = $this->category_dropdown();
1005
-        return array_merge($old_filters, $filters);
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * espresso_event_months_dropdown
1011
-     *
1012
-     * @access public
1013
-     * @return string                dropdown listing month/year selections for events.
1014
-     */
1015
-    public function espresso_event_months_dropdown()
1016
-    {
1017
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1018
-        // Note we need to include any other filters that are set!
1019
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1020
-        // categories?
1021
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1022
-            ? $this->_req_data['EVT_CAT']
1023
-            : null;
1024
-        // active status?
1025
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1026
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1027
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1028
-    }
1029
-
1030
-
1031
-    /**
1032
-     * returns a list of "active" statuses on the event
1033
-     *
1034
-     * @param  string $current_value whatever the current active status is
1035
-     * @return string
1036
-     */
1037
-    public function active_status_dropdown($current_value = '')
1038
-    {
1039
-        $select_name = 'active_status';
1040
-        $values = array(
1041
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1042
-            'active'   => esc_html__('Active', 'event_espresso'),
1043
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1044
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1045
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1046
-        );
1047
-        $id = 'id="espresso-active-status-dropdown-filter"';
1048
-        $class = 'wide';
1049
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1050
-    }
1051
-
1052
-
1053
-    /**
1054
-     * output a dropdown of the categories for the category filter on the event admin list table
1055
-     *
1056
-     * @access  public
1057
-     * @return string html
1058
-     */
1059
-    public function category_dropdown()
1060
-    {
1061
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1062
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * get total number of events today
1068
-     *
1069
-     * @access public
1070
-     * @return int
1071
-     * @throws EE_Error
1072
-     */
1073
-    public function total_events_today()
1074
-    {
1075
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1076
-            'DTT_EVT_start',
1077
-            date('Y-m-d') . ' 00:00:00',
1078
-            'Y-m-d H:i:s',
1079
-            'UTC'
1080
-        );
1081
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1082
-            'DTT_EVT_start',
1083
-            date('Y-m-d') . ' 23:59:59',
1084
-            'Y-m-d H:i:s',
1085
-            'UTC'
1086
-        );
1087
-        $where = array(
1088
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1089
-        );
1090
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1091
-        return $count;
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     * get total number of events this month
1097
-     *
1098
-     * @access public
1099
-     * @return int
1100
-     * @throws EE_Error
1101
-     */
1102
-    public function total_events_this_month()
1103
-    {
1104
-        // Dates
1105
-        $this_year_r = date('Y');
1106
-        $this_month_r = date('m');
1107
-        $days_this_month = date('t');
1108
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1109
-            'DTT_EVT_start',
1110
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1111
-            'Y-m-d H:i:s',
1112
-            'UTC'
1113
-        );
1114
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1115
-            'DTT_EVT_start',
1116
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1117
-            'Y-m-d H:i:s',
1118
-            'UTC'
1119
-        );
1120
-        $where = array(
1121
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1122
-        );
1123
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1124
-        return $count;
1125
-    }
1126
-
1127
-
1128
-    /** DEFAULT TICKETS STUFF **/
1129
-
1130
-    /**
1131
-     * Output default tickets list table view.
1132
-     */
1133
-    public function _tickets_overview_list_table()
1134
-    {
1135
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1136
-        $this->display_admin_list_table_page_with_no_sidebar();
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * @param int  $per_page
1142
-     * @param bool $count
1143
-     * @param bool $trashed
1144
-     * @return \EE_Soft_Delete_Base_Class[]|int
1145
-     */
1146
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1147
-    {
1148
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1149
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1150
-        switch ($orderby) {
1151
-            case 'TKT_name':
1152
-                $orderby = array('TKT_name' => $order);
1153
-                break;
1154
-            case 'TKT_price':
1155
-                $orderby = array('TKT_price' => $order);
1156
-                break;
1157
-            case 'TKT_uses':
1158
-                $orderby = array('TKT_uses' => $order);
1159
-                break;
1160
-            case 'TKT_min':
1161
-                $orderby = array('TKT_min' => $order);
1162
-                break;
1163
-            case 'TKT_max':
1164
-                $orderby = array('TKT_max' => $order);
1165
-                break;
1166
-            case 'TKT_qty':
1167
-                $orderby = array('TKT_qty' => $order);
1168
-                break;
1169
-        }
1170
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1171
-            ? $this->_req_data['paged']
1172
-            : 1;
1173
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1174
-            ? $this->_req_data['perpage']
1175
-            : $per_page;
1176
-        $_where = array(
1177
-            'TKT_is_default' => 1,
1178
-            'TKT_deleted'    => $trashed,
1179
-        );
1180
-        $offset = ($current_page - 1) * $per_page;
1181
-        $limit = array($offset, $per_page);
1182
-        if (isset($this->_req_data['s'])) {
1183
-            $sstr = '%' . $this->_req_data['s'] . '%';
1184
-            $_where['OR'] = array(
1185
-                'TKT_name'        => array('LIKE', $sstr),
1186
-                'TKT_description' => array('LIKE', $sstr),
1187
-            );
1188
-        }
1189
-        $query_params = array(
1190
-            $_where,
1191
-            'order_by' => $orderby,
1192
-            'limit'    => $limit,
1193
-            'group_by' => 'TKT_ID',
1194
-        );
1195
-        if ($count) {
1196
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1197
-        } else {
1198
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1199
-        }
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * @param bool $trash
1205
-     * @throws EE_Error
1206
-     */
1207
-    protected function _trash_or_restore_ticket($trash = false)
1208
-    {
1209
-        $success = 1;
1210
-        $TKT = EEM_Ticket::instance();
1211
-        // checkboxes?
1212
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1213
-            // if array has more than one element then success message should be plural
1214
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1215
-            // cycle thru the boxes
1216
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1217
-                if ($trash) {
1218
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1219
-                        $success = 0;
1220
-                    }
1221
-                } else {
1222
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1223
-                        $success = 0;
1224
-                    }
1225
-                }
1226
-            }
1227
-        } else {
1228
-            // grab single id and trash
1229
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1230
-            if ($trash) {
1231
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1232
-                    $success = 0;
1233
-                }
1234
-            } else {
1235
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1236
-                    $success = 0;
1237
-                }
1238
-            }
1239
-        }
1240
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1241
-        $query_args = array(
1242
-            'action' => 'ticket_list_table',
1243
-            'status' => $trash ? '' : 'trashed',
1244
-        );
1245
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1246
-    }
1247
-
1248
-
1249
-    /**
1250
-     * Handles trashing default ticket.
1251
-     */
1252
-    protected function _delete_ticket()
1253
-    {
1254
-        $success = 1;
1255
-        // checkboxes?
1256
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1257
-            // if array has more than one element then success message should be plural
1258
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1259
-            // cycle thru the boxes
1260
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1261
-                // delete
1262
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1263
-                    $success = 0;
1264
-                }
1265
-            }
1266
-        } else {
1267
-            // grab single id and trash
1268
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1269
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1270
-                $success = 0;
1271
-            }
1272
-        }
1273
-        $action_desc = 'deleted';
1274
-        $query_args = array(
1275
-            'action' => 'ticket_list_table',
1276
-            'status' => 'trashed',
1277
-        );
1278
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1279
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1280
-            array(array('TKT_is_default' => 1)),
1281
-            'TKT_ID',
1282
-            true
1283
-        )
1284
-        ) {
1285
-            $query_args = array();
1286
-        }
1287
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * @param int $TKT_ID
1293
-     * @return bool|int
1294
-     * @throws EE_Error
1295
-     */
1296
-    protected function _delete_the_ticket($TKT_ID)
1297
-    {
1298
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1299
-        $tkt->_remove_relations('Datetime');
1300
-        // delete all related prices first
1301
-        $tkt->delete_related_permanently('Price');
1302
-        return $tkt->delete_permanently();
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     * @param array $default_event_settings_form_subsections
1308
-     * @return array
1309
-     * @since $VID:$
1310
-     */
1311
-    public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1312
-    {
1313
-        return [
1314
-            'advanced_editor_header' => new EE_Form_Section_HTML(
1315
-               EEH_HTML::div(
1316
-                   EEH_HTML::div(
1317
-                       EEH_HTML::h2(
1318
-                           esc_html__('New Feature', 'event_espresso'),
1319
-                           '',
1320
-                           'ee-admin-settings-hdr ee-new-flag'
1321
-                       ),
1322
-                       '',
1323
-                       'ee-new-flag-wrap'
1324
-                   ),
1325
-                   '',
1326
-                   'ee-new-flag-shadow',
1327
-                   'margin: -25px 0 10px;'
1328
-               )
1329
-            ),
1330
-            'use_advanced_editor'         => new EE_Select_Input(
1331
-               apply_filters(
1332
-                   'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_options',
1333
-                   [
1334
-                       esc_html__('Legacy Editor', 'event_espresso'),
1335
-                       esc_html__('Advanced Editor', 'event_espresso'),
1336
-                   ]
1337
-               ),
1338
-               array(
1339
-                   'default'         => $this->admin_config->useAdvancedEditor(),
1340
-                   'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1341
-                   'html_help_text'  => sprintf(
1342
-                       esc_html__(
1343
-                           '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.',
1344
-                           'event_espresso'
1345
-                       ),
1346
-                       '<br />'
1347
-                   ),
1348
-               )
1349
-            ),
1350
-            'advanced_editor_view' => new EE_Select_Input(
1351
-                [
1352
-                    'list' => esc_html__('List View', 'event_espresso'),
1353
-                    'grid' => esc_html__('Grid View', 'event_espresso'),
1354
-                ],
1355
-               array(
1356
-                   'default'         => $this->admin_config->advancedEditorView(),
1357
-                   'html_label_text' => esc_html__('Default Editor View', 'event_espresso'),
1358
-                   'html_help_text'  => sprintf(
1359
-                       esc_html__(
1360
-                           'Controls how the new Advanced Editor displays Event Dates and Available Tickets.%1$s"List View" is a traditional table like view with data organized in rows and columns.%1$s"Grid View" displays the data in stylized blocks with with data organized in logical groupings that make it easier to understand at a glance.',
1361
-                           'event_espresso'
1362
-                       ),
1363
-                       '<br />'
1364
-                   ),
1365
-               )
1366
-            ),
1367
-            'advanced_editor_per_page' => new EE_Select_Input(
1368
-                [ 2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48 ],
1369
-               array(
1370
-                   'default'         => $this->admin_config->advancedEditorPerPage(),
1371
-                   'html_label_text' => esc_html__('Default Items Per Page', 'event_espresso'),
1372
-                   'html_help_text'  => sprintf(
1373
-                       esc_html__(
1374
-                           'The new Advanced Editor has filters that allow you to control the display of Event Dates and Available Tickets and includes pagination for long lists of data.%1$sThis option sets the default number of items to appear in paginated lists.',
1375
-                           'event_espresso'
1376
-                       ),
1377
-                       '<br />'
1378
-                   ),
1379
-               )
1380
-            ),
1381
-            'defaults_section_header' => new EE_Form_Section_HTML(
1382
-               EEH_HTML::h2(
1383
-                   esc_html__('Default Settings', 'event_espresso'),
1384
-                   '',
1385
-                   'ee-admin-settings-hdr'
1386
-               )
1387
-            ),
1388
-        ] + $default_event_settings_form_subsections;
1389
-    }
1390
-
1391
-
1392
-    /**
1393
-     * @param array     $valid_data
1394
-     * @param EE_Config $config
1395
-     * @since $VID:$
1396
-     */
1397
-    public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1398
-    {
1399
-        $config->admin->setUseAdvancedEditor(
1400
-            isset($valid_data['use_advanced_editor'])
1401
-                ? $valid_data['use_advanced_editor']
1402
-                : false
1403
-        );
1404
-        $config->admin->setAdvancedEditorView(
1405
-            isset($valid_data['advanced_editor_view'])
1406
-                ? $valid_data['advanced_editor_view']
1407
-                : 'grid'
1408
-        );
1409
-        $config->admin->setAdvancedEditorPerPage(
1410
-            isset($valid_data['advanced_editor_per_page'])
1411
-                ? $valid_data['advanced_editor_per_page']
1412
-                : 6
1413
-        );
1414
-    }
340
+					}
341
+				}
342
+			);
343
+		}
344
+	}
345
+
346
+
347
+	/**
348
+	 * Returns template for the additional datetime.
349
+	 *
350
+	 * @param $template
351
+	 * @param $template_args
352
+	 * @return mixed
353
+	 * @throws DomainException
354
+	 */
355
+	public function add_additional_datetime_button($template, $template_args)
356
+	{
357
+		return EEH_Template::display_template(
358
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
359
+			$template_args,
360
+			true
361
+		);
362
+	}
363
+
364
+
365
+	/**
366
+	 * Returns the template for cloning a datetime.
367
+	 *
368
+	 * @param $template
369
+	 * @param $template_args
370
+	 * @return mixed
371
+	 * @throws DomainException
372
+	 */
373
+	public function add_datetime_clone_button($template, $template_args)
374
+	{
375
+		return EEH_Template::display_template(
376
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
377
+			$template_args,
378
+			true
379
+		);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Returns the template for datetime timezones.
385
+	 *
386
+	 * @param $template
387
+	 * @param $template_args
388
+	 * @return mixed
389
+	 * @throws DomainException
390
+	 */
391
+	public function datetime_timezones_template($template, $template_args)
392
+	{
393
+		return EEH_Template::display_template(
394
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
395
+			$template_args,
396
+			true
397
+		);
398
+	}
399
+
400
+
401
+	/**
402
+	 * Sets the views for the default list table view.
403
+	 */
404
+	protected function _set_list_table_views_default()
405
+	{
406
+		parent::_set_list_table_views_default();
407
+		$new_views = array(
408
+			'today' => array(
409
+				'slug'        => 'today',
410
+				'label'       => esc_html__('Today', 'event_espresso'),
411
+				'count'       => $this->total_events_today(),
412
+				'bulk_action' => array(
413
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
414
+				),
415
+			),
416
+			'month' => array(
417
+				'slug'        => 'month',
418
+				'label'       => esc_html__('This Month', 'event_espresso'),
419
+				'count'       => $this->total_events_this_month(),
420
+				'bulk_action' => array(
421
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
422
+				),
423
+			),
424
+		);
425
+		$this->_views = array_merge($this->_views, $new_views);
426
+	}
427
+
428
+
429
+	/**
430
+	 * Returns the extra action links for the default list table view.
431
+	 *
432
+	 * @param array     $action_links
433
+	 * @param \EE_Event $event
434
+	 * @return array
435
+	 * @throws EE_Error
436
+	 */
437
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
438
+	{
439
+		if (EE_Registry::instance()->CAP->current_user_can(
440
+			'ee_read_registrations',
441
+			'espresso_registrations_reports',
442
+			$event->ID()
443
+		)
444
+		) {
445
+			$reports_query_args = array(
446
+				'action' => 'reports',
447
+				'EVT_ID' => $event->ID(),
448
+			);
449
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
450
+			$action_links[] = '<a href="'
451
+							  . $reports_link
452
+							  . '" title="'
453
+							  . esc_attr__('View Report', 'event_espresso')
454
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
455
+							  . "\n\t";
456
+		}
457
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
458
+			EE_Registry::instance()->load_helper('MSG_Template');
459
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
460
+				'see_notifications_for',
461
+				null,
462
+				array('EVT_ID' => $event->ID())
463
+			);
464
+		}
465
+		return $action_links;
466
+	}
467
+
468
+
469
+	/**
470
+	 * @param $items
471
+	 * @return mixed
472
+	 */
473
+	public function additional_legend_items($items)
474
+	{
475
+		if (EE_Registry::instance()->CAP->current_user_can(
476
+			'ee_read_registrations',
477
+			'espresso_registrations_reports'
478
+		)
479
+		) {
480
+			$items['reports'] = array(
481
+				'class' => 'dashicons dashicons-chart-bar',
482
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
483
+			);
484
+		}
485
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
486
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
487
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
488
+				$items['view_related_messages'] = array(
489
+					'class' => $related_for_icon['css_class'],
490
+					'desc'  => $related_for_icon['label'],
491
+				);
492
+			}
493
+		}
494
+		return $items;
495
+	}
496
+
497
+
498
+	/**
499
+	 * This is the callback method for the duplicate event route
500
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
501
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
502
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
503
+	 * After duplication the redirect is to the new event edit page.
504
+	 *
505
+	 * @return void
506
+	 * @access protected
507
+	 * @throws EE_Error If EE_Event is not available with given ID
508
+	 */
509
+	protected function _duplicate_event()
510
+	{
511
+		// first make sure the ID for the event is in the request.
512
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
513
+		if (! isset($this->_req_data['EVT_ID'])) {
514
+			EE_Error::add_error(
515
+				esc_html__(
516
+					'In order to duplicate an event an Event ID is required.  None was given.',
517
+					'event_espresso'
518
+				),
519
+				__FILE__,
520
+				__FUNCTION__,
521
+				__LINE__
522
+			);
523
+			$this->_redirect_after_action(false, '', '', array(), true);
524
+			return;
525
+		}
526
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
527
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
528
+		if (! $orig_event instanceof EE_Event) {
529
+			throw new EE_Error(
530
+				sprintf(
531
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
532
+					$this->_req_data['EVT_ID']
533
+				)
534
+			);
535
+		}
536
+		// k now let's clone the $orig_event before getting relations
537
+		$new_event = clone $orig_event;
538
+		// original datetimes
539
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
540
+		// other original relations
541
+		$orig_ven = $orig_event->get_many_related('Venue');
542
+		// reset the ID and modify other details to make it clear this is a dupe
543
+		$new_event->set('EVT_ID', 0);
544
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
545
+		$new_event->set('EVT_name', $new_name);
546
+		$new_event->set(
547
+			'EVT_slug',
548
+			wp_unique_post_slug(
549
+				sanitize_title($orig_event->name()),
550
+				0,
551
+				'publish',
552
+				'espresso_events',
553
+				0
554
+			)
555
+		);
556
+		$new_event->set('status', 'draft');
557
+		// duplicate discussion settings
558
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
559
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
560
+		// save the new event
561
+		$new_event->save();
562
+		// venues
563
+		foreach ($orig_ven as $ven) {
564
+			$new_event->_add_relation_to($ven, 'Venue');
565
+		}
566
+		$new_event->save();
567
+		// now we need to get the question group relations and handle that
568
+		// first primary question groups
569
+		$orig_primary_qgs = $orig_event->get_many_related(
570
+			'Question_Group',
571
+			array(array('Event_Question_Group.EQG_primary' => 1))
572
+		);
573
+		if (! empty($orig_primary_qgs)) {
574
+			foreach ($orig_primary_qgs as $id => $obj) {
575
+				if ($obj instanceof EE_Question_Group) {
576
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
577
+				}
578
+			}
579
+		}
580
+		// next additional attendee question groups
581
+		$orig_additional_qgs = $orig_event->get_many_related(
582
+			'Question_Group',
583
+			array(array('Event_Question_Group.EQG_primary' => 0))
584
+		);
585
+		if (! empty($orig_additional_qgs)) {
586
+			foreach ($orig_additional_qgs as $id => $obj) {
587
+				if ($obj instanceof EE_Question_Group) {
588
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
589
+				}
590
+			}
591
+		}
592
+
593
+		$new_event->save();
594
+
595
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
596
+		$cloned_tickets = array();
597
+		foreach ($orig_datetimes as $orig_dtt) {
598
+			if (! $orig_dtt instanceof EE_Datetime) {
599
+				continue;
600
+			}
601
+			$new_dtt = clone $orig_dtt;
602
+			$orig_tkts = $orig_dtt->tickets();
603
+			// save new dtt then add to event
604
+			$new_dtt->set('DTT_ID', 0);
605
+			$new_dtt->set('DTT_sold', 0);
606
+			$new_dtt->set_reserved(0);
607
+			$new_dtt->save();
608
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
609
+			$new_event->save();
610
+			// now let's get the ticket relations setup.
611
+			foreach ((array) $orig_tkts as $orig_tkt) {
612
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
613
+				if (! $orig_tkt instanceof EE_Ticket) {
614
+					continue;
615
+				}
616
+				// is this ticket archived?  If it is then let's skip
617
+				if ($orig_tkt->get('TKT_deleted')) {
618
+					continue;
619
+				}
620
+				// does this original ticket already exist in the clone_tickets cache?
621
+				//  If so we'll just use the new ticket from it.
622
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
623
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
624
+				} else {
625
+					$new_tkt = clone $orig_tkt;
626
+					// get relations on the $orig_tkt that we need to setup.
627
+					$orig_prices = $orig_tkt->prices();
628
+					$new_tkt->set('TKT_ID', 0);
629
+					$new_tkt->set('TKT_sold', 0);
630
+					$new_tkt->set('TKT_reserved', 0);
631
+					$new_tkt->save(); // make sure new ticket has ID.
632
+					// price relations on new ticket need to be setup.
633
+					foreach ($orig_prices as $orig_price) {
634
+						$new_price = clone $orig_price;
635
+						$new_price->set('PRC_ID', 0);
636
+						$new_price->save();
637
+						$new_tkt->_add_relation_to($new_price, 'Price');
638
+						$new_tkt->save();
639
+					}
640
+
641
+					do_action(
642
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
643
+						$orig_tkt,
644
+						$new_tkt,
645
+						$orig_prices,
646
+						$orig_event,
647
+						$orig_dtt,
648
+						$new_dtt
649
+					);
650
+				}
651
+				// k now we can add the new ticket as a relation to the new datetime
652
+				// and make sure its added to our cached $cloned_tickets array
653
+				// for use with later datetimes that have the same ticket.
654
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
655
+				$new_dtt->save();
656
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
657
+			}
658
+		}
659
+		// clone taxonomy information
660
+		$taxonomies_to_clone_with = apply_filters(
661
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
662
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
663
+		);
664
+		// get terms for original event (notice)
665
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
666
+		// loop through terms and add them to new event.
667
+		foreach ($orig_terms as $term) {
668
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
669
+		}
670
+
671
+		// duplicate other core WP_Post items for this event.
672
+		// post thumbnail (feature image).
673
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
674
+		if ($feature_image_id) {
675
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
676
+		}
677
+
678
+		// duplicate page_template setting
679
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
680
+		if ($page_template) {
681
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
682
+		}
683
+
684
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
685
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
686
+		if ($new_event->ID()) {
687
+			$redirect_args = array(
688
+				'post'   => $new_event->ID(),
689
+				'action' => 'edit',
690
+			);
691
+			EE_Error::add_success(
692
+				esc_html__(
693
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
694
+					'event_espresso'
695
+				)
696
+			);
697
+		} else {
698
+			$redirect_args = array(
699
+				'action' => 'default',
700
+			);
701
+			EE_Error::add_error(
702
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
703
+				__FILE__,
704
+				__FUNCTION__,
705
+				__LINE__
706
+			);
707
+		}
708
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
709
+	}
710
+
711
+
712
+	/**
713
+	 * Generates output for the import page.
714
+	 *
715
+	 * @throws DomainException
716
+	 */
717
+	protected function _import_page()
718
+	{
719
+		$title = esc_html__('Import', 'event_espresso');
720
+		$intro = esc_html__(
721
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
722
+			'event_espresso'
723
+		);
724
+		$form_url = EVENTS_ADMIN_URL;
725
+		$action = 'import_events';
726
+		$type = 'csv';
727
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
728
+			$title,
729
+			$intro,
730
+			$form_url,
731
+			$action,
732
+			$type
733
+		);
734
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
735
+			array('action' => 'sample_export_file'),
736
+			$this->_admin_base_url
737
+		);
738
+		$content = EEH_Template::display_template(
739
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
740
+			$this->_template_args,
741
+			true
742
+		);
743
+		$this->_template_args['admin_page_content'] = $content;
744
+		$this->display_admin_page_with_sidebar();
745
+	}
746
+
747
+
748
+	/**
749
+	 * _import_events
750
+	 * This handles displaying the screen and running imports for importing events.
751
+	 *
752
+	 * @return void
753
+	 */
754
+	protected function _import_events()
755
+	{
756
+		require_once(EE_CLASSES . 'EE_Import.class.php');
757
+		$success = EE_Import::instance()->import();
758
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
759
+	}
760
+
761
+
762
+	/**
763
+	 * _events_export
764
+	 * Will export all (or just the given event) to a Excel compatible file.
765
+	 *
766
+	 * @access protected
767
+	 * @return void
768
+	 */
769
+	protected function _events_export()
770
+	{
771
+		if (isset($this->_req_data['EVT_ID'])) {
772
+			$event_ids = $this->_req_data['EVT_ID'];
773
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
774
+			$event_ids = $this->_req_data['EVT_IDs'];
775
+		} else {
776
+			$event_ids = null;
777
+		}
778
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
779
+		$new_request_args = array(
780
+			'export' => 'report',
781
+			'action' => 'all_event_data',
782
+			'EVT_ID' => $event_ids,
783
+		);
784
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
785
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
+			require_once(EE_CLASSES . 'EE_Export.class.php');
787
+			$EE_Export = EE_Export::instance($this->_req_data);
788
+			$EE_Export->export();
789
+		}
790
+	}
791
+
792
+
793
+	/**
794
+	 * handle category exports()
795
+	 *
796
+	 * @return void
797
+	 */
798
+	protected function _categories_export()
799
+	{
800
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
801
+		$new_request_args = array(
802
+			'export'       => 'report',
803
+			'action'       => 'categories',
804
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
805
+		);
806
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
807
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
808
+			require_once(EE_CLASSES . 'EE_Export.class.php');
809
+			$EE_Export = EE_Export::instance($this->_req_data);
810
+			$EE_Export->export();
811
+		}
812
+	}
813
+
814
+
815
+	/**
816
+	 * Creates a sample CSV file for importing
817
+	 */
818
+	protected function _sample_export_file()
819
+	{
820
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
821
+		EE_Export::instance()->export_sample();
822
+	}
823
+
824
+
825
+	/*************        Template Settings        *************/
826
+	/**
827
+	 * Generates template settings page output
828
+	 *
829
+	 * @throws DomainException
830
+	 * @throws EE_Error
831
+	 */
832
+	protected function _template_settings()
833
+	{
834
+		$this->_template_args['values'] = $this->_yes_no_values;
835
+		/**
836
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
837
+		 * from General_Settings_Admin_Page to here.
838
+		 */
839
+		$this->_template_args = apply_filters(
840
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
841
+			$this->_template_args
842
+		);
843
+		$this->_set_add_edit_form_tags('update_template_settings');
844
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
845
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
846
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
847
+			$this->_template_args,
848
+			true
849
+		);
850
+		$this->display_admin_page_with_sidebar();
851
+	}
852
+
853
+
854
+	/**
855
+	 * Handler for updating template settings.
856
+	 *
857
+	 * @throws InvalidInterfaceException
858
+	 * @throws InvalidDataTypeException
859
+	 * @throws InvalidArgumentException
860
+	 */
861
+	protected function _update_template_settings()
862
+	{
863
+		/**
864
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
865
+		 * from General_Settings_Admin_Page to here.
866
+		 */
867
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
868
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
869
+			EE_Registry::instance()->CFG->template_settings,
870
+			$this->_req_data
871
+		);
872
+		// update custom post type slugs and detect if we need to flush rewrite rules
873
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
874
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
875
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
876
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
877
+		$what = 'Template Settings';
878
+		$success = $this->_update_espresso_configuration(
879
+			$what,
880
+			EE_Registry::instance()->CFG->template_settings,
881
+			__FILE__,
882
+			__FUNCTION__,
883
+			__LINE__
884
+		);
885
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
886
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
887
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
888
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
889
+			);
890
+			$rewrite_rules->flush();
891
+		}
892
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
893
+	}
894
+
895
+
896
+	/**
897
+	 * _premium_event_editor_meta_boxes
898
+	 * add all metaboxes related to the event_editor
899
+	 *
900
+	 * @access protected
901
+	 * @return void
902
+	 * @throws EE_Error
903
+	 */
904
+	protected function _premium_event_editor_meta_boxes()
905
+	{
906
+		$this->verify_cpt_object();
907
+		add_meta_box(
908
+			'espresso_event_editor_event_options',
909
+			esc_html__('Event Registration Options', 'event_espresso'),
910
+			array($this, 'registration_options_meta_box'),
911
+			$this->page_slug,
912
+			'side',
913
+			'core'
914
+		);
915
+	}
916
+
917
+
918
+	/**
919
+	 * override caf metabox
920
+	 *
921
+	 * @return void
922
+	 * @throws DomainException
923
+	 */
924
+	public function registration_options_meta_box()
925
+	{
926
+		$yes_no_values = array(
927
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
928
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
929
+		);
930
+		$default_reg_status_values = EEM_Registration::reg_status_array(
931
+			array(
932
+				EEM_Registration::status_id_cancelled,
933
+				EEM_Registration::status_id_declined,
934
+				EEM_Registration::status_id_incomplete,
935
+				EEM_Registration::status_id_wait_list,
936
+			),
937
+			true
938
+		);
939
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
940
+		$template_args['_event'] = $this->_cpt_model_obj;
941
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
942
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
943
+			'default_reg_status',
944
+			$default_reg_status_values,
945
+			$this->_cpt_model_obj->default_registration_status()
946
+		);
947
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
948
+			'display_desc',
949
+			$yes_no_values,
950
+			$this->_cpt_model_obj->display_description()
951
+		);
952
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
953
+			'display_ticket_selector',
954
+			$yes_no_values,
955
+			$this->_cpt_model_obj->display_ticket_selector(),
956
+			'',
957
+			'',
958
+			false
959
+		);
960
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
961
+			'EVT_default_registration_status',
962
+			$default_reg_status_values,
963
+			$this->_cpt_model_obj->default_registration_status()
964
+		);
965
+		$template_args['additional_registration_options'] = apply_filters(
966
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
967
+			'',
968
+			$template_args,
969
+			$yes_no_values,
970
+			$default_reg_status_values
971
+		);
972
+		EEH_Template::display_template(
973
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
974
+			$template_args
975
+		);
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * wp_list_table_mods for caf
982
+	 * ============================
983
+	 */
984
+	/**
985
+	 * hook into list table filters and provide filters for caffeinated list table
986
+	 *
987
+	 * @param  array $old_filters    any existing filters present
988
+	 * @param  array $list_table_obj the list table object
989
+	 * @return array                  new filters
990
+	 */
991
+	public function list_table_filters($old_filters, $list_table_obj)
992
+	{
993
+		$filters = array();
994
+		// first month/year filters
995
+		$filters[] = $this->espresso_event_months_dropdown();
996
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
997
+		// active status dropdown
998
+		if ($status !== 'draft') {
999
+			$filters[] = $this->active_status_dropdown(
1000
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1001
+			);
1002
+		}
1003
+		// category filter
1004
+		$filters[] = $this->category_dropdown();
1005
+		return array_merge($old_filters, $filters);
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * espresso_event_months_dropdown
1011
+	 *
1012
+	 * @access public
1013
+	 * @return string                dropdown listing month/year selections for events.
1014
+	 */
1015
+	public function espresso_event_months_dropdown()
1016
+	{
1017
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1018
+		// Note we need to include any other filters that are set!
1019
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1020
+		// categories?
1021
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1022
+			? $this->_req_data['EVT_CAT']
1023
+			: null;
1024
+		// active status?
1025
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1026
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1027
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1028
+	}
1029
+
1030
+
1031
+	/**
1032
+	 * returns a list of "active" statuses on the event
1033
+	 *
1034
+	 * @param  string $current_value whatever the current active status is
1035
+	 * @return string
1036
+	 */
1037
+	public function active_status_dropdown($current_value = '')
1038
+	{
1039
+		$select_name = 'active_status';
1040
+		$values = array(
1041
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1042
+			'active'   => esc_html__('Active', 'event_espresso'),
1043
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1044
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1045
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1046
+		);
1047
+		$id = 'id="espresso-active-status-dropdown-filter"';
1048
+		$class = 'wide';
1049
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1050
+	}
1051
+
1052
+
1053
+	/**
1054
+	 * output a dropdown of the categories for the category filter on the event admin list table
1055
+	 *
1056
+	 * @access  public
1057
+	 * @return string html
1058
+	 */
1059
+	public function category_dropdown()
1060
+	{
1061
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1062
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * get total number of events today
1068
+	 *
1069
+	 * @access public
1070
+	 * @return int
1071
+	 * @throws EE_Error
1072
+	 */
1073
+	public function total_events_today()
1074
+	{
1075
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1076
+			'DTT_EVT_start',
1077
+			date('Y-m-d') . ' 00:00:00',
1078
+			'Y-m-d H:i:s',
1079
+			'UTC'
1080
+		);
1081
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1082
+			'DTT_EVT_start',
1083
+			date('Y-m-d') . ' 23:59:59',
1084
+			'Y-m-d H:i:s',
1085
+			'UTC'
1086
+		);
1087
+		$where = array(
1088
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1089
+		);
1090
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1091
+		return $count;
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 * get total number of events this month
1097
+	 *
1098
+	 * @access public
1099
+	 * @return int
1100
+	 * @throws EE_Error
1101
+	 */
1102
+	public function total_events_this_month()
1103
+	{
1104
+		// Dates
1105
+		$this_year_r = date('Y');
1106
+		$this_month_r = date('m');
1107
+		$days_this_month = date('t');
1108
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1109
+			'DTT_EVT_start',
1110
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1111
+			'Y-m-d H:i:s',
1112
+			'UTC'
1113
+		);
1114
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1115
+			'DTT_EVT_start',
1116
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1117
+			'Y-m-d H:i:s',
1118
+			'UTC'
1119
+		);
1120
+		$where = array(
1121
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1122
+		);
1123
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1124
+		return $count;
1125
+	}
1126
+
1127
+
1128
+	/** DEFAULT TICKETS STUFF **/
1129
+
1130
+	/**
1131
+	 * Output default tickets list table view.
1132
+	 */
1133
+	public function _tickets_overview_list_table()
1134
+	{
1135
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1136
+		$this->display_admin_list_table_page_with_no_sidebar();
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * @param int  $per_page
1142
+	 * @param bool $count
1143
+	 * @param bool $trashed
1144
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1145
+	 */
1146
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1147
+	{
1148
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1149
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1150
+		switch ($orderby) {
1151
+			case 'TKT_name':
1152
+				$orderby = array('TKT_name' => $order);
1153
+				break;
1154
+			case 'TKT_price':
1155
+				$orderby = array('TKT_price' => $order);
1156
+				break;
1157
+			case 'TKT_uses':
1158
+				$orderby = array('TKT_uses' => $order);
1159
+				break;
1160
+			case 'TKT_min':
1161
+				$orderby = array('TKT_min' => $order);
1162
+				break;
1163
+			case 'TKT_max':
1164
+				$orderby = array('TKT_max' => $order);
1165
+				break;
1166
+			case 'TKT_qty':
1167
+				$orderby = array('TKT_qty' => $order);
1168
+				break;
1169
+		}
1170
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1171
+			? $this->_req_data['paged']
1172
+			: 1;
1173
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1174
+			? $this->_req_data['perpage']
1175
+			: $per_page;
1176
+		$_where = array(
1177
+			'TKT_is_default' => 1,
1178
+			'TKT_deleted'    => $trashed,
1179
+		);
1180
+		$offset = ($current_page - 1) * $per_page;
1181
+		$limit = array($offset, $per_page);
1182
+		if (isset($this->_req_data['s'])) {
1183
+			$sstr = '%' . $this->_req_data['s'] . '%';
1184
+			$_where['OR'] = array(
1185
+				'TKT_name'        => array('LIKE', $sstr),
1186
+				'TKT_description' => array('LIKE', $sstr),
1187
+			);
1188
+		}
1189
+		$query_params = array(
1190
+			$_where,
1191
+			'order_by' => $orderby,
1192
+			'limit'    => $limit,
1193
+			'group_by' => 'TKT_ID',
1194
+		);
1195
+		if ($count) {
1196
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1197
+		} else {
1198
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1199
+		}
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * @param bool $trash
1205
+	 * @throws EE_Error
1206
+	 */
1207
+	protected function _trash_or_restore_ticket($trash = false)
1208
+	{
1209
+		$success = 1;
1210
+		$TKT = EEM_Ticket::instance();
1211
+		// checkboxes?
1212
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1213
+			// if array has more than one element then success message should be plural
1214
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1215
+			// cycle thru the boxes
1216
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1217
+				if ($trash) {
1218
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1219
+						$success = 0;
1220
+					}
1221
+				} else {
1222
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1223
+						$success = 0;
1224
+					}
1225
+				}
1226
+			}
1227
+		} else {
1228
+			// grab single id and trash
1229
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1230
+			if ($trash) {
1231
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1232
+					$success = 0;
1233
+				}
1234
+			} else {
1235
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1236
+					$success = 0;
1237
+				}
1238
+			}
1239
+		}
1240
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1241
+		$query_args = array(
1242
+			'action' => 'ticket_list_table',
1243
+			'status' => $trash ? '' : 'trashed',
1244
+		);
1245
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1246
+	}
1247
+
1248
+
1249
+	/**
1250
+	 * Handles trashing default ticket.
1251
+	 */
1252
+	protected function _delete_ticket()
1253
+	{
1254
+		$success = 1;
1255
+		// checkboxes?
1256
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1257
+			// if array has more than one element then success message should be plural
1258
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1259
+			// cycle thru the boxes
1260
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1261
+				// delete
1262
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1263
+					$success = 0;
1264
+				}
1265
+			}
1266
+		} else {
1267
+			// grab single id and trash
1268
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1269
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1270
+				$success = 0;
1271
+			}
1272
+		}
1273
+		$action_desc = 'deleted';
1274
+		$query_args = array(
1275
+			'action' => 'ticket_list_table',
1276
+			'status' => 'trashed',
1277
+		);
1278
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1279
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1280
+			array(array('TKT_is_default' => 1)),
1281
+			'TKT_ID',
1282
+			true
1283
+		)
1284
+		) {
1285
+			$query_args = array();
1286
+		}
1287
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * @param int $TKT_ID
1293
+	 * @return bool|int
1294
+	 * @throws EE_Error
1295
+	 */
1296
+	protected function _delete_the_ticket($TKT_ID)
1297
+	{
1298
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1299
+		$tkt->_remove_relations('Datetime');
1300
+		// delete all related prices first
1301
+		$tkt->delete_related_permanently('Price');
1302
+		return $tkt->delete_permanently();
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 * @param array $default_event_settings_form_subsections
1308
+	 * @return array
1309
+	 * @since $VID:$
1310
+	 */
1311
+	public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1312
+	{
1313
+		return [
1314
+			'advanced_editor_header' => new EE_Form_Section_HTML(
1315
+			   EEH_HTML::div(
1316
+				   EEH_HTML::div(
1317
+					   EEH_HTML::h2(
1318
+						   esc_html__('New Feature', 'event_espresso'),
1319
+						   '',
1320
+						   'ee-admin-settings-hdr ee-new-flag'
1321
+					   ),
1322
+					   '',
1323
+					   'ee-new-flag-wrap'
1324
+				   ),
1325
+				   '',
1326
+				   'ee-new-flag-shadow',
1327
+				   'margin: -25px 0 10px;'
1328
+			   )
1329
+			),
1330
+			'use_advanced_editor'         => new EE_Select_Input(
1331
+			   apply_filters(
1332
+				   'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_options',
1333
+				   [
1334
+					   esc_html__('Legacy Editor', 'event_espresso'),
1335
+					   esc_html__('Advanced Editor', 'event_espresso'),
1336
+				   ]
1337
+			   ),
1338
+			   array(
1339
+				   'default'         => $this->admin_config->useAdvancedEditor(),
1340
+				   'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1341
+				   'html_help_text'  => sprintf(
1342
+					   esc_html__(
1343
+						   '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.',
1344
+						   'event_espresso'
1345
+					   ),
1346
+					   '<br />'
1347
+				   ),
1348
+			   )
1349
+			),
1350
+			'advanced_editor_view' => new EE_Select_Input(
1351
+				[
1352
+					'list' => esc_html__('List View', 'event_espresso'),
1353
+					'grid' => esc_html__('Grid View', 'event_espresso'),
1354
+				],
1355
+			   array(
1356
+				   'default'         => $this->admin_config->advancedEditorView(),
1357
+				   'html_label_text' => esc_html__('Default Editor View', 'event_espresso'),
1358
+				   'html_help_text'  => sprintf(
1359
+					   esc_html__(
1360
+						   'Controls how the new Advanced Editor displays Event Dates and Available Tickets.%1$s"List View" is a traditional table like view with data organized in rows and columns.%1$s"Grid View" displays the data in stylized blocks with with data organized in logical groupings that make it easier to understand at a glance.',
1361
+						   'event_espresso'
1362
+					   ),
1363
+					   '<br />'
1364
+				   ),
1365
+			   )
1366
+			),
1367
+			'advanced_editor_per_page' => new EE_Select_Input(
1368
+				[ 2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48 ],
1369
+			   array(
1370
+				   'default'         => $this->admin_config->advancedEditorPerPage(),
1371
+				   'html_label_text' => esc_html__('Default Items Per Page', 'event_espresso'),
1372
+				   'html_help_text'  => sprintf(
1373
+					   esc_html__(
1374
+						   'The new Advanced Editor has filters that allow you to control the display of Event Dates and Available Tickets and includes pagination for long lists of data.%1$sThis option sets the default number of items to appear in paginated lists.',
1375
+						   'event_espresso'
1376
+					   ),
1377
+					   '<br />'
1378
+				   ),
1379
+			   )
1380
+			),
1381
+			'defaults_section_header' => new EE_Form_Section_HTML(
1382
+			   EEH_HTML::h2(
1383
+				   esc_html__('Default Settings', 'event_espresso'),
1384
+				   '',
1385
+				   'ee-admin-settings-hdr'
1386
+			   )
1387
+			),
1388
+		] + $default_event_settings_form_subsections;
1389
+	}
1390
+
1391
+
1392
+	/**
1393
+	 * @param array     $valid_data
1394
+	 * @param EE_Config $config
1395
+	 * @since $VID:$
1396
+	 */
1397
+	public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1398
+	{
1399
+		$config->admin->setUseAdvancedEditor(
1400
+			isset($valid_data['use_advanced_editor'])
1401
+				? $valid_data['use_advanced_editor']
1402
+				: false
1403
+		);
1404
+		$config->admin->setAdvancedEditorView(
1405
+			isset($valid_data['advanced_editor_view'])
1406
+				? $valid_data['advanced_editor_view']
1407
+				: 'grid'
1408
+		);
1409
+		$config->admin->setAdvancedEditorPerPage(
1410
+			isset($valid_data['advanced_editor_per_page'])
1411
+				? $valid_data['advanced_editor_per_page']
1412
+				: 6
1413
+		);
1414
+	}
1415 1415
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 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,14 +328,14 @@  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
                         $view = $this->admin_config->advancedEditorView();
335 335
                         $perPage = $this->admin_config->advancedEditorPerPage();
336 336
                         echo '
337 337
         <script type="text/javascript">
338
-            /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; var eeEditorListView = "' . $view . '"; var eeEditorPerPage = ' . $perPage . '; /* ]]> */
338
+            /* <![CDATA[ */ var eeEditorEventId = ' . $eventId.'; var eeEditorListView = "'.$view.'"; var eeEditorPerPage = '.$perPage.'; /* ]]> */
339 339
         </script>';
340 340
                     }
341 341
                 }
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
     public function add_additional_datetime_button($template, $template_args)
356 356
     {
357 357
         return EEH_Template::display_template(
358
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
358
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
359 359
             $template_args,
360 360
             true
361 361
         );
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
     public function add_datetime_clone_button($template, $template_args)
374 374
     {
375 375
         return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
376
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
377 377
             $template_args,
378 378
             true
379 379
         );
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
     public function datetime_timezones_template($template, $template_args)
392 392
     {
393 393
         return EEH_Template::display_template(
394
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
394
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
395 395
             $template_args,
396 396
             true
397 397
         );
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
     {
511 511
         // first make sure the ID for the event is in the request.
512 512
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
513
-        if (! isset($this->_req_data['EVT_ID'])) {
513
+        if ( ! isset($this->_req_data['EVT_ID'])) {
514 514
             EE_Error::add_error(
515 515
                 esc_html__(
516 516
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
         }
526 526
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
527 527
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
528
-        if (! $orig_event instanceof EE_Event) {
528
+        if ( ! $orig_event instanceof EE_Event) {
529 529
             throw new EE_Error(
530 530
                 sprintf(
531 531
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
         $orig_ven = $orig_event->get_many_related('Venue');
542 542
         // reset the ID and modify other details to make it clear this is a dupe
543 543
         $new_event->set('EVT_ID', 0);
544
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
544
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
545 545
         $new_event->set('EVT_name', $new_name);
546 546
         $new_event->set(
547 547
             'EVT_slug',
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
             'Question_Group',
571 571
             array(array('Event_Question_Group.EQG_primary' => 1))
572 572
         );
573
-        if (! empty($orig_primary_qgs)) {
573
+        if ( ! empty($orig_primary_qgs)) {
574 574
             foreach ($orig_primary_qgs as $id => $obj) {
575 575
                 if ($obj instanceof EE_Question_Group) {
576 576
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
             'Question_Group',
583 583
             array(array('Event_Question_Group.EQG_primary' => 0))
584 584
         );
585
-        if (! empty($orig_additional_qgs)) {
585
+        if ( ! empty($orig_additional_qgs)) {
586 586
             foreach ($orig_additional_qgs as $id => $obj) {
587 587
                 if ($obj instanceof EE_Question_Group) {
588 588
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
596 596
         $cloned_tickets = array();
597 597
         foreach ($orig_datetimes as $orig_dtt) {
598
-            if (! $orig_dtt instanceof EE_Datetime) {
598
+            if ( ! $orig_dtt instanceof EE_Datetime) {
599 599
                 continue;
600 600
             }
601 601
             $new_dtt = clone $orig_dtt;
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
             // now let's get the ticket relations setup.
611 611
             foreach ((array) $orig_tkts as $orig_tkt) {
612 612
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
613
-                if (! $orig_tkt instanceof EE_Ticket) {
613
+                if ( ! $orig_tkt instanceof EE_Ticket) {
614 614
                     continue;
615 615
                 }
616 616
                 // is this ticket archived?  If it is then let's skip
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
                 }
620 620
                 // does this original ticket already exist in the clone_tickets cache?
621 621
                 //  If so we'll just use the new ticket from it.
622
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
623
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
622
+                if (isset($cloned_tickets[$orig_tkt->ID()])) {
623
+                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
624 624
                 } else {
625 625
                     $new_tkt = clone $orig_tkt;
626 626
                     // get relations on the $orig_tkt that we need to setup.
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
                 // for use with later datetimes that have the same ticket.
654 654
                 $new_dtt->_add_relation_to($new_tkt, 'Ticket');
655 655
                 $new_dtt->save();
656
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
656
+                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
657 657
             }
658 658
         }
659 659
         // clone taxonomy information
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
             $this->_admin_base_url
737 737
         );
738 738
         $content = EEH_Template::display_template(
739
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
739
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
740 740
             $this->_template_args,
741 741
             true
742 742
         );
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
      */
754 754
     protected function _import_events()
755 755
     {
756
-        require_once(EE_CLASSES . 'EE_Import.class.php');
756
+        require_once(EE_CLASSES.'EE_Import.class.php');
757 757
         $success = EE_Import::instance()->import();
758 758
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
759 759
     }
@@ -782,8 +782,8 @@  discard block
 block discarded – undo
782 782
             'EVT_ID' => $event_ids,
783 783
         );
784 784
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
785
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
-            require_once(EE_CLASSES . 'EE_Export.class.php');
785
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
786
+            require_once(EE_CLASSES.'EE_Export.class.php');
787 787
             $EE_Export = EE_Export::instance($this->_req_data);
788 788
             $EE_Export->export();
789 789
         }
@@ -804,8 +804,8 @@  discard block
 block discarded – undo
804 804
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
805 805
         );
806 806
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
807
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
808
-            require_once(EE_CLASSES . 'EE_Export.class.php');
807
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
808
+            require_once(EE_CLASSES.'EE_Export.class.php');
809 809
             $EE_Export = EE_Export::instance($this->_req_data);
810 810
             $EE_Export->export();
811 811
         }
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
         $this->_set_add_edit_form_tags('update_template_settings');
844 844
         $this->_set_publish_post_box_vars(null, false, false, null, false);
845 845
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
846
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
846
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
847 847
             $this->_template_args,
848 848
             true
849 849
         );
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
             $default_reg_status_values
971 971
         );
972 972
         EEH_Template::display_template(
973
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
973
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
974 974
             $template_args
975 975
         );
976 976
     }
@@ -1074,13 +1074,13 @@  discard block
 block discarded – undo
1074 1074
     {
1075 1075
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1076 1076
             'DTT_EVT_start',
1077
-            date('Y-m-d') . ' 00:00:00',
1077
+            date('Y-m-d').' 00:00:00',
1078 1078
             'Y-m-d H:i:s',
1079 1079
             'UTC'
1080 1080
         );
1081 1081
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1082 1082
             'DTT_EVT_start',
1083
-            date('Y-m-d') . ' 23:59:59',
1083
+            date('Y-m-d').' 23:59:59',
1084 1084
             'Y-m-d H:i:s',
1085 1085
             'UTC'
1086 1086
         );
@@ -1107,13 +1107,13 @@  discard block
 block discarded – undo
1107 1107
         $days_this_month = date('t');
1108 1108
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1109 1109
             'DTT_EVT_start',
1110
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1110
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1111 1111
             'Y-m-d H:i:s',
1112 1112
             'UTC'
1113 1113
         );
1114 1114
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1115 1115
             'DTT_EVT_start',
1116
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1116
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1117 1117
             'Y-m-d H:i:s',
1118 1118
             'UTC'
1119 1119
         );
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
         $offset = ($current_page - 1) * $per_page;
1181 1181
         $limit = array($offset, $per_page);
1182 1182
         if (isset($this->_req_data['s'])) {
1183
-            $sstr = '%' . $this->_req_data['s'] . '%';
1183
+            $sstr = '%'.$this->_req_data['s'].'%';
1184 1184
             $_where['OR'] = array(
1185 1185
                 'TKT_name'        => array('LIKE', $sstr),
1186 1186
                 'TKT_description' => array('LIKE', $sstr),
@@ -1209,17 +1209,17 @@  discard block
 block discarded – undo
1209 1209
         $success = 1;
1210 1210
         $TKT = EEM_Ticket::instance();
1211 1211
         // checkboxes?
1212
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1212
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1213 1213
             // if array has more than one element then success message should be plural
1214 1214
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1215 1215
             // cycle thru the boxes
1216 1216
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1217 1217
                 if ($trash) {
1218
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1218
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1219 1219
                         $success = 0;
1220 1220
                     }
1221 1221
                 } else {
1222
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1222
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1223 1223
                         $success = 0;
1224 1224
                     }
1225 1225
                 }
@@ -1228,11 +1228,11 @@  discard block
 block discarded – undo
1228 1228
             // grab single id and trash
1229 1229
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1230 1230
             if ($trash) {
1231
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1231
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1232 1232
                     $success = 0;
1233 1233
                 }
1234 1234
             } else {
1235
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1235
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1236 1236
                     $success = 0;
1237 1237
                 }
1238 1238
             }
@@ -1253,20 +1253,20 @@  discard block
 block discarded – undo
1253 1253
     {
1254 1254
         $success = 1;
1255 1255
         // checkboxes?
1256
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1256
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1257 1257
             // if array has more than one element then success message should be plural
1258 1258
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1259 1259
             // cycle thru the boxes
1260 1260
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1261 1261
                 // delete
1262
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1262
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1263 1263
                     $success = 0;
1264 1264
                 }
1265 1265
             }
1266 1266
         } else {
1267 1267
             // grab single id and trash
1268 1268
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1269
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1269
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1270 1270
                 $success = 0;
1271 1271
             }
1272 1272
         }
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
                )
1366 1366
             ),
1367 1367
             'advanced_editor_per_page' => new EE_Select_Input(
1368
-                [ 2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48 ],
1368
+                [2 => 2, 6 => 6, 12 => 12, 24 => 24, 48 => 48],
1369 1369
                array(
1370 1370
                    'default'         => $this->admin_config->advancedEditorPerPage(),
1371 1371
                    'html_label_text' => esc_html__('Default Items Per Page', 'event_espresso'),
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3224 added lines, -3224 removed lines patch added patch discarded remove patch
@@ -14,1489 +14,1489 @@  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
-    }
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 1500
 }
1501 1501
 
1502 1502
 /**
@@ -1505,1018 +1505,1018 @@  discard block
 block discarded – undo
1505 1505
  * basically, they should just be well-defined stdClasses
1506 1506
  */
1507 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;
2262
-
2263
-    /**
2264
-     * ReCaptcha Type
2265
-     *
2266
-     * @var string $recaptcha_type
2267
-     *    options: 'audio', 'image'
2268
-     */
2269
-    public $recaptcha_type;
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,234 +2525,234 @@  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 string $advancedEditorView
2535
-     */
2536
-    private $advancedEditorView;
2537
-
2538
-    /**
2539
-     * @var integer $advancedEditorPerPage
2540
-     */
2541
-    private $advancedEditorPerPage;
2542
-
2543
-    /**
2544
-     * @var boolean $use_personnel_manager
2545
-     */
2546
-    public $use_personnel_manager;
2547
-
2548
-    /**
2549
-     * @var boolean $use_dashboard_widget
2550
-     */
2551
-    public $use_dashboard_widget;
2552
-
2553
-    /**
2554
-     * @var int $events_in_dashboard
2555
-     */
2556
-    public $events_in_dashboard;
2557
-
2558
-    /**
2559
-     * @var boolean $use_event_timezones
2560
-     */
2561
-    public $use_event_timezones;
2562
-
2563
-    /**
2564
-     * @var boolean $use_full_logging
2565
-     */
2566
-    public $use_full_logging;
2567
-
2568
-    /**
2569
-     * @var string $log_file_name
2570
-     */
2571
-    public $log_file_name;
2572
-
2573
-    /**
2574
-     * @var string $debug_file_name
2575
-     */
2576
-    public $debug_file_name;
2577
-
2578
-    /**
2579
-     * @var boolean $use_remote_logging
2580
-     */
2581
-    public $use_remote_logging;
2582
-
2583
-    /**
2584
-     * @var string $remote_logging_url
2585
-     */
2586
-    public $remote_logging_url;
2587
-
2588
-    /**
2589
-     * @var boolean $show_reg_footer
2590
-     */
2591
-    public $show_reg_footer;
2592
-
2593
-    /**
2594
-     * @var string $affiliate_id
2595
-     */
2596
-    public $affiliate_id;
2597
-
2598
-    /**
2599
-     * help tours on or off (global setting)
2600
-     *
2601
-     * @var boolean
2602
-     */
2603
-    public $help_tour_activation;
2604
-
2605
-    /**
2606
-     * adds extra layer of encoding to session data to prevent serialization errors
2607
-     * but is incompatible with some server configuration errors
2608
-     * if you get "500 internal server errors" during registration, try turning this on
2609
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2610
-     *
2611
-     * @var boolean $encode_session_data
2612
-     */
2613
-    private $encode_session_data = false;
2614
-
2615
-
2616
-    /**
2617
-     *    class constructor
2618
-     *
2619
-     * @access    public
2620
-     */
2621
-    public function __construct()
2622
-    {
2623
-        // set default general admin settings
2624
-        $this->useAdvancedEditor = false;
2625
-        $this->advancedEditorView = 'grid';
2626
-        $this->advancedEditorPerPage = 6;
2627
-        $this->use_personnel_manager = true;
2628
-        $this->use_dashboard_widget = true;
2629
-        $this->events_in_dashboard = 30;
2630
-        $this->use_event_timezones = false;
2631
-        $this->use_full_logging = false;
2632
-        $this->use_remote_logging = false;
2633
-        $this->remote_logging_url = null;
2634
-        $this->show_reg_footer = apply_filters(
2635
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2636
-            false
2637
-        );
2638
-        $this->affiliate_id = 'default';
2639
-        $this->help_tour_activation = true;
2640
-        $this->encode_session_data = false;
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * @param bool $reset
2646
-     * @return string
2647
-     */
2648
-    public function log_file_name($reset = false)
2649
-    {
2650
-        if (empty($this->log_file_name) || $reset) {
2651
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2652
-            EE_Config::instance()->update_espresso_config(false, false);
2653
-        }
2654
-        return $this->log_file_name;
2655
-    }
2656
-
2657
-
2658
-    /**
2659
-     * @param bool $reset
2660
-     * @return string
2661
-     */
2662
-    public function debug_file_name($reset = false)
2663
-    {
2664
-        if (empty($this->debug_file_name) || $reset) {
2665
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2666
-            EE_Config::instance()->update_espresso_config(false, false);
2667
-        }
2668
-        return $this->debug_file_name;
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * @return string
2674
-     */
2675
-    public function affiliate_id()
2676
-    {
2677
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2678
-    }
2679
-
2680
-
2681
-    /**
2682
-     * @return boolean
2683
-     */
2684
-    public function encode_session_data()
2685
-    {
2686
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2687
-    }
2688
-
2689
-
2690
-    /**
2691
-     * @param boolean $encode_session_data
2692
-     */
2693
-    public function set_encode_session_data($encode_session_data)
2694
-    {
2695
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2696
-    }
2697
-
2698
-    /**
2699
-     * @return boolean
2700
-     */
2701
-    public function useAdvancedEditor()
2702
-    {
2703
-        return $this->useAdvancedEditor;
2704
-    }
2705
-
2706
-    /**
2707
-     * @param boolean $use_advanced_editor
2708
-     */
2709
-    public function setUseAdvancedEditor($use_advanced_editor = true)
2710
-    {
2711
-        $this->useAdvancedEditor = filter_var(
2712
-            apply_filters(
2713
-                'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2714
-                $use_advanced_editor
2715
-            ),
2716
-            FILTER_VALIDATE_BOOLEAN
2717
-        );
2718
-    }
2719
-
2720
-
2721
-    /**
2722
-     * @return string
2723
-     */
2724
-    public function advancedEditorView()
2725
-    {
2726
-        return $this->advancedEditorView;
2727
-    }
2728
-
2729
-
2730
-    /**
2731
-     * @param string $view
2732
-     */
2733
-    public function setAdvancedEditorView($view)
2734
-    {
2735
-        $this->advancedEditorView = $view === 'list' ? 'list' : 'grid';
2736
-    }
2737
-
2738
-
2739
-    /**
2740
-     * @return int
2741
-     */
2742
-    public function advancedEditorPerPage()
2743
-    {
2744
-        return $this->advancedEditorPerPage;
2745
-    }
2746
-
2747
-
2748
-    /**
2749
-     * @param int $perPage
2750
-     */
2751
-    public function setAdvancedEditorPerPage($perPage)
2752
-    {
2753
-        $perPage = absint($perPage);
2754
-        $this->advancedEditorPerPage = in_array($perPage, [2, 6, 12, 24, 48], true) ? $perPage : 6;
2755
-    }
2528
+	/**
2529
+	 * @var boolean $useAdvancedEditor
2530
+	 */
2531
+	private $useAdvancedEditor;
2532
+
2533
+	/**
2534
+	 * @var string $advancedEditorView
2535
+	 */
2536
+	private $advancedEditorView;
2537
+
2538
+	/**
2539
+	 * @var integer $advancedEditorPerPage
2540
+	 */
2541
+	private $advancedEditorPerPage;
2542
+
2543
+	/**
2544
+	 * @var boolean $use_personnel_manager
2545
+	 */
2546
+	public $use_personnel_manager;
2547
+
2548
+	/**
2549
+	 * @var boolean $use_dashboard_widget
2550
+	 */
2551
+	public $use_dashboard_widget;
2552
+
2553
+	/**
2554
+	 * @var int $events_in_dashboard
2555
+	 */
2556
+	public $events_in_dashboard;
2557
+
2558
+	/**
2559
+	 * @var boolean $use_event_timezones
2560
+	 */
2561
+	public $use_event_timezones;
2562
+
2563
+	/**
2564
+	 * @var boolean $use_full_logging
2565
+	 */
2566
+	public $use_full_logging;
2567
+
2568
+	/**
2569
+	 * @var string $log_file_name
2570
+	 */
2571
+	public $log_file_name;
2572
+
2573
+	/**
2574
+	 * @var string $debug_file_name
2575
+	 */
2576
+	public $debug_file_name;
2577
+
2578
+	/**
2579
+	 * @var boolean $use_remote_logging
2580
+	 */
2581
+	public $use_remote_logging;
2582
+
2583
+	/**
2584
+	 * @var string $remote_logging_url
2585
+	 */
2586
+	public $remote_logging_url;
2587
+
2588
+	/**
2589
+	 * @var boolean $show_reg_footer
2590
+	 */
2591
+	public $show_reg_footer;
2592
+
2593
+	/**
2594
+	 * @var string $affiliate_id
2595
+	 */
2596
+	public $affiliate_id;
2597
+
2598
+	/**
2599
+	 * help tours on or off (global setting)
2600
+	 *
2601
+	 * @var boolean
2602
+	 */
2603
+	public $help_tour_activation;
2604
+
2605
+	/**
2606
+	 * adds extra layer of encoding to session data to prevent serialization errors
2607
+	 * but is incompatible with some server configuration errors
2608
+	 * if you get "500 internal server errors" during registration, try turning this on
2609
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2610
+	 *
2611
+	 * @var boolean $encode_session_data
2612
+	 */
2613
+	private $encode_session_data = false;
2614
+
2615
+
2616
+	/**
2617
+	 *    class constructor
2618
+	 *
2619
+	 * @access    public
2620
+	 */
2621
+	public function __construct()
2622
+	{
2623
+		// set default general admin settings
2624
+		$this->useAdvancedEditor = false;
2625
+		$this->advancedEditorView = 'grid';
2626
+		$this->advancedEditorPerPage = 6;
2627
+		$this->use_personnel_manager = true;
2628
+		$this->use_dashboard_widget = true;
2629
+		$this->events_in_dashboard = 30;
2630
+		$this->use_event_timezones = false;
2631
+		$this->use_full_logging = false;
2632
+		$this->use_remote_logging = false;
2633
+		$this->remote_logging_url = null;
2634
+		$this->show_reg_footer = apply_filters(
2635
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2636
+			false
2637
+		);
2638
+		$this->affiliate_id = 'default';
2639
+		$this->help_tour_activation = true;
2640
+		$this->encode_session_data = false;
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * @param bool $reset
2646
+	 * @return string
2647
+	 */
2648
+	public function log_file_name($reset = false)
2649
+	{
2650
+		if (empty($this->log_file_name) || $reset) {
2651
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2652
+			EE_Config::instance()->update_espresso_config(false, false);
2653
+		}
2654
+		return $this->log_file_name;
2655
+	}
2656
+
2657
+
2658
+	/**
2659
+	 * @param bool $reset
2660
+	 * @return string
2661
+	 */
2662
+	public function debug_file_name($reset = false)
2663
+	{
2664
+		if (empty($this->debug_file_name) || $reset) {
2665
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2666
+			EE_Config::instance()->update_espresso_config(false, false);
2667
+		}
2668
+		return $this->debug_file_name;
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * @return string
2674
+	 */
2675
+	public function affiliate_id()
2676
+	{
2677
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2678
+	}
2679
+
2680
+
2681
+	/**
2682
+	 * @return boolean
2683
+	 */
2684
+	public function encode_session_data()
2685
+	{
2686
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2687
+	}
2688
+
2689
+
2690
+	/**
2691
+	 * @param boolean $encode_session_data
2692
+	 */
2693
+	public function set_encode_session_data($encode_session_data)
2694
+	{
2695
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2696
+	}
2697
+
2698
+	/**
2699
+	 * @return boolean
2700
+	 */
2701
+	public function useAdvancedEditor()
2702
+	{
2703
+		return $this->useAdvancedEditor;
2704
+	}
2705
+
2706
+	/**
2707
+	 * @param boolean $use_advanced_editor
2708
+	 */
2709
+	public function setUseAdvancedEditor($use_advanced_editor = true)
2710
+	{
2711
+		$this->useAdvancedEditor = filter_var(
2712
+			apply_filters(
2713
+				'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2714
+				$use_advanced_editor
2715
+			),
2716
+			FILTER_VALIDATE_BOOLEAN
2717
+		);
2718
+	}
2719
+
2720
+
2721
+	/**
2722
+	 * @return string
2723
+	 */
2724
+	public function advancedEditorView()
2725
+	{
2726
+		return $this->advancedEditorView;
2727
+	}
2728
+
2729
+
2730
+	/**
2731
+	 * @param string $view
2732
+	 */
2733
+	public function setAdvancedEditorView($view)
2734
+	{
2735
+		$this->advancedEditorView = $view === 'list' ? 'list' : 'grid';
2736
+	}
2737
+
2738
+
2739
+	/**
2740
+	 * @return int
2741
+	 */
2742
+	public function advancedEditorPerPage()
2743
+	{
2744
+		return $this->advancedEditorPerPage;
2745
+	}
2746
+
2747
+
2748
+	/**
2749
+	 * @param int $perPage
2750
+	 */
2751
+	public function setAdvancedEditorPerPage($perPage)
2752
+	{
2753
+		$perPage = absint($perPage);
2754
+		$this->advancedEditorPerPage = in_array($perPage, [2, 6, 12, 24, 48], true) ? $perPage : 6;
2755
+	}
2756 2756
 
2757 2757
 }
2758 2758
 
@@ -2762,70 +2762,70 @@  discard block
 block discarded – undo
2762 2762
 class EE_Template_Config extends EE_Config_Base
2763 2763
 {
2764 2764
 
2765
-    /**
2766
-     * @var boolean $enable_default_style
2767
-     */
2768
-    public $enable_default_style;
2769
-
2770
-    /**
2771
-     * @var string $custom_style_sheet
2772
-     */
2773
-    public $custom_style_sheet;
2774
-
2775
-    /**
2776
-     * @var boolean $display_address_in_regform
2777
-     */
2778
-    public $display_address_in_regform;
2779
-
2780
-    /**
2781
-     * @var int $display_description_on_multi_reg_page
2782
-     */
2783
-    public $display_description_on_multi_reg_page;
2784
-
2785
-    /**
2786
-     * @var boolean $use_custom_templates
2787
-     */
2788
-    public $use_custom_templates;
2789
-
2790
-    /**
2791
-     * @var string $current_espresso_theme
2792
-     */
2793
-    public $current_espresso_theme;
2794
-
2795
-    /**
2796
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2797
-     */
2798
-    public $EED_Ticket_Selector;
2799
-
2800
-    /**
2801
-     * @var EE_Event_Single_Config $EED_Event_Single
2802
-     */
2803
-    public $EED_Event_Single;
2804
-
2805
-    /**
2806
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2807
-     */
2808
-    public $EED_Events_Archive;
2809
-
2810
-
2811
-    /**
2812
-     *    class constructor
2813
-     *
2814
-     * @access    public
2815
-     */
2816
-    public function __construct()
2817
-    {
2818
-        // set default template settings
2819
-        $this->enable_default_style = true;
2820
-        $this->custom_style_sheet = null;
2821
-        $this->display_address_in_regform = true;
2822
-        $this->display_description_on_multi_reg_page = false;
2823
-        $this->use_custom_templates = false;
2824
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2825
-        $this->EED_Event_Single = null;
2826
-        $this->EED_Events_Archive = null;
2827
-        $this->EED_Ticket_Selector = null;
2828
-    }
2765
+	/**
2766
+	 * @var boolean $enable_default_style
2767
+	 */
2768
+	public $enable_default_style;
2769
+
2770
+	/**
2771
+	 * @var string $custom_style_sheet
2772
+	 */
2773
+	public $custom_style_sheet;
2774
+
2775
+	/**
2776
+	 * @var boolean $display_address_in_regform
2777
+	 */
2778
+	public $display_address_in_regform;
2779
+
2780
+	/**
2781
+	 * @var int $display_description_on_multi_reg_page
2782
+	 */
2783
+	public $display_description_on_multi_reg_page;
2784
+
2785
+	/**
2786
+	 * @var boolean $use_custom_templates
2787
+	 */
2788
+	public $use_custom_templates;
2789
+
2790
+	/**
2791
+	 * @var string $current_espresso_theme
2792
+	 */
2793
+	public $current_espresso_theme;
2794
+
2795
+	/**
2796
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2797
+	 */
2798
+	public $EED_Ticket_Selector;
2799
+
2800
+	/**
2801
+	 * @var EE_Event_Single_Config $EED_Event_Single
2802
+	 */
2803
+	public $EED_Event_Single;
2804
+
2805
+	/**
2806
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2807
+	 */
2808
+	public $EED_Events_Archive;
2809
+
2810
+
2811
+	/**
2812
+	 *    class constructor
2813
+	 *
2814
+	 * @access    public
2815
+	 */
2816
+	public function __construct()
2817
+	{
2818
+		// set default template settings
2819
+		$this->enable_default_style = true;
2820
+		$this->custom_style_sheet = null;
2821
+		$this->display_address_in_regform = true;
2822
+		$this->display_description_on_multi_reg_page = false;
2823
+		$this->use_custom_templates = false;
2824
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2825
+		$this->EED_Event_Single = null;
2826
+		$this->EED_Events_Archive = null;
2827
+		$this->EED_Ticket_Selector = null;
2828
+	}
2829 2829
 }
2830 2830
 
2831 2831
 /**
@@ -2834,114 +2834,114 @@  discard block
 block discarded – undo
2834 2834
 class EE_Map_Config extends EE_Config_Base
2835 2835
 {
2836 2836
 
2837
-    /**
2838
-     * @var boolean $use_google_maps
2839
-     */
2840
-    public $use_google_maps;
2841
-
2842
-    /**
2843
-     * @var string $api_key
2844
-     */
2845
-    public $google_map_api_key;
2846
-
2847
-    /**
2848
-     * @var int $event_details_map_width
2849
-     */
2850
-    public $event_details_map_width;
2851
-
2852
-    /**
2853
-     * @var int $event_details_map_height
2854
-     */
2855
-    public $event_details_map_height;
2856
-
2857
-    /**
2858
-     * @var int $event_details_map_zoom
2859
-     */
2860
-    public $event_details_map_zoom;
2861
-
2862
-    /**
2863
-     * @var boolean $event_details_display_nav
2864
-     */
2865
-    public $event_details_display_nav;
2866
-
2867
-    /**
2868
-     * @var boolean $event_details_nav_size
2869
-     */
2870
-    public $event_details_nav_size;
2871
-
2872
-    /**
2873
-     * @var string $event_details_control_type
2874
-     */
2875
-    public $event_details_control_type;
2876
-
2877
-    /**
2878
-     * @var string $event_details_map_align
2879
-     */
2880
-    public $event_details_map_align;
2881
-
2882
-    /**
2883
-     * @var int $event_list_map_width
2884
-     */
2885
-    public $event_list_map_width;
2886
-
2887
-    /**
2888
-     * @var int $event_list_map_height
2889
-     */
2890
-    public $event_list_map_height;
2891
-
2892
-    /**
2893
-     * @var int $event_list_map_zoom
2894
-     */
2895
-    public $event_list_map_zoom;
2896
-
2897
-    /**
2898
-     * @var boolean $event_list_display_nav
2899
-     */
2900
-    public $event_list_display_nav;
2901
-
2902
-    /**
2903
-     * @var boolean $event_list_nav_size
2904
-     */
2905
-    public $event_list_nav_size;
2906
-
2907
-    /**
2908
-     * @var string $event_list_control_type
2909
-     */
2910
-    public $event_list_control_type;
2911
-
2912
-    /**
2913
-     * @var string $event_list_map_align
2914
-     */
2915
-    public $event_list_map_align;
2916
-
2917
-
2918
-    /**
2919
-     *    class constructor
2920
-     *
2921
-     * @access    public
2922
-     */
2923
-    public function __construct()
2924
-    {
2925
-        // set default map settings
2926
-        $this->use_google_maps = true;
2927
-        $this->google_map_api_key = '';
2928
-        // for event details pages (reg page)
2929
-        $this->event_details_map_width = 585;            // ee_map_width_single
2930
-        $this->event_details_map_height = 362;            // ee_map_height_single
2931
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2932
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2933
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2934
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2935
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2936
-        // for event list pages
2937
-        $this->event_list_map_width = 300;            // ee_map_width
2938
-        $this->event_list_map_height = 185;        // ee_map_height
2939
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2940
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2941
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2942
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2943
-        $this->event_list_map_align = 'center';            // ee_map_align
2944
-    }
2837
+	/**
2838
+	 * @var boolean $use_google_maps
2839
+	 */
2840
+	public $use_google_maps;
2841
+
2842
+	/**
2843
+	 * @var string $api_key
2844
+	 */
2845
+	public $google_map_api_key;
2846
+
2847
+	/**
2848
+	 * @var int $event_details_map_width
2849
+	 */
2850
+	public $event_details_map_width;
2851
+
2852
+	/**
2853
+	 * @var int $event_details_map_height
2854
+	 */
2855
+	public $event_details_map_height;
2856
+
2857
+	/**
2858
+	 * @var int $event_details_map_zoom
2859
+	 */
2860
+	public $event_details_map_zoom;
2861
+
2862
+	/**
2863
+	 * @var boolean $event_details_display_nav
2864
+	 */
2865
+	public $event_details_display_nav;
2866
+
2867
+	/**
2868
+	 * @var boolean $event_details_nav_size
2869
+	 */
2870
+	public $event_details_nav_size;
2871
+
2872
+	/**
2873
+	 * @var string $event_details_control_type
2874
+	 */
2875
+	public $event_details_control_type;
2876
+
2877
+	/**
2878
+	 * @var string $event_details_map_align
2879
+	 */
2880
+	public $event_details_map_align;
2881
+
2882
+	/**
2883
+	 * @var int $event_list_map_width
2884
+	 */
2885
+	public $event_list_map_width;
2886
+
2887
+	/**
2888
+	 * @var int $event_list_map_height
2889
+	 */
2890
+	public $event_list_map_height;
2891
+
2892
+	/**
2893
+	 * @var int $event_list_map_zoom
2894
+	 */
2895
+	public $event_list_map_zoom;
2896
+
2897
+	/**
2898
+	 * @var boolean $event_list_display_nav
2899
+	 */
2900
+	public $event_list_display_nav;
2901
+
2902
+	/**
2903
+	 * @var boolean $event_list_nav_size
2904
+	 */
2905
+	public $event_list_nav_size;
2906
+
2907
+	/**
2908
+	 * @var string $event_list_control_type
2909
+	 */
2910
+	public $event_list_control_type;
2911
+
2912
+	/**
2913
+	 * @var string $event_list_map_align
2914
+	 */
2915
+	public $event_list_map_align;
2916
+
2917
+
2918
+	/**
2919
+	 *    class constructor
2920
+	 *
2921
+	 * @access    public
2922
+	 */
2923
+	public function __construct()
2924
+	{
2925
+		// set default map settings
2926
+		$this->use_google_maps = true;
2927
+		$this->google_map_api_key = '';
2928
+		// for event details pages (reg page)
2929
+		$this->event_details_map_width = 585;            // ee_map_width_single
2930
+		$this->event_details_map_height = 362;            // ee_map_height_single
2931
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2932
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2933
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2934
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2935
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2936
+		// for event list pages
2937
+		$this->event_list_map_width = 300;            // ee_map_width
2938
+		$this->event_list_map_height = 185;        // ee_map_height
2939
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2940
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2941
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2942
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2943
+		$this->event_list_map_align = 'center';            // ee_map_align
2944
+	}
2945 2945
 }
2946 2946
 
2947 2947
 /**
@@ -2950,46 +2950,46 @@  discard block
 block discarded – undo
2950 2950
 class EE_Events_Archive_Config extends EE_Config_Base
2951 2951
 {
2952 2952
 
2953
-    public $display_status_banner;
2953
+	public $display_status_banner;
2954 2954
 
2955
-    public $display_description;
2955
+	public $display_description;
2956 2956
 
2957
-    public $display_ticket_selector;
2957
+	public $display_ticket_selector;
2958 2958
 
2959
-    public $display_datetimes;
2959
+	public $display_datetimes;
2960 2960
 
2961
-    public $display_venue;
2961
+	public $display_venue;
2962 2962
 
2963
-    public $display_expired_events;
2963
+	public $display_expired_events;
2964 2964
 
2965
-    public $use_sortable_display_order;
2965
+	public $use_sortable_display_order;
2966 2966
 
2967
-    public $display_order_tickets;
2967
+	public $display_order_tickets;
2968 2968
 
2969
-    public $display_order_datetimes;
2969
+	public $display_order_datetimes;
2970 2970
 
2971
-    public $display_order_event;
2971
+	public $display_order_event;
2972 2972
 
2973
-    public $display_order_venue;
2973
+	public $display_order_venue;
2974 2974
 
2975 2975
 
2976
-    /**
2977
-     *    class constructor
2978
-     */
2979
-    public function __construct()
2980
-    {
2981
-        $this->display_status_banner = 0;
2982
-        $this->display_description = 1;
2983
-        $this->display_ticket_selector = 0;
2984
-        $this->display_datetimes = 1;
2985
-        $this->display_venue = 0;
2986
-        $this->display_expired_events = 0;
2987
-        $this->use_sortable_display_order = false;
2988
-        $this->display_order_tickets = 100;
2989
-        $this->display_order_datetimes = 110;
2990
-        $this->display_order_event = 120;
2991
-        $this->display_order_venue = 130;
2992
-    }
2976
+	/**
2977
+	 *    class constructor
2978
+	 */
2979
+	public function __construct()
2980
+	{
2981
+		$this->display_status_banner = 0;
2982
+		$this->display_description = 1;
2983
+		$this->display_ticket_selector = 0;
2984
+		$this->display_datetimes = 1;
2985
+		$this->display_venue = 0;
2986
+		$this->display_expired_events = 0;
2987
+		$this->use_sortable_display_order = false;
2988
+		$this->display_order_tickets = 100;
2989
+		$this->display_order_datetimes = 110;
2990
+		$this->display_order_event = 120;
2991
+		$this->display_order_venue = 130;
2992
+	}
2993 2993
 }
2994 2994
 
2995 2995
 /**
@@ -2998,34 +2998,34 @@  discard block
 block discarded – undo
2998 2998
 class EE_Event_Single_Config extends EE_Config_Base
2999 2999
 {
3000 3000
 
3001
-    public $display_status_banner_single;
3001
+	public $display_status_banner_single;
3002 3002
 
3003
-    public $display_venue;
3003
+	public $display_venue;
3004 3004
 
3005
-    public $use_sortable_display_order;
3005
+	public $use_sortable_display_order;
3006 3006
 
3007
-    public $display_order_tickets;
3007
+	public $display_order_tickets;
3008 3008
 
3009
-    public $display_order_datetimes;
3009
+	public $display_order_datetimes;
3010 3010
 
3011
-    public $display_order_event;
3011
+	public $display_order_event;
3012 3012
 
3013
-    public $display_order_venue;
3013
+	public $display_order_venue;
3014 3014
 
3015 3015
 
3016
-    /**
3017
-     *    class constructor
3018
-     */
3019
-    public function __construct()
3020
-    {
3021
-        $this->display_status_banner_single = 0;
3022
-        $this->display_venue = 1;
3023
-        $this->use_sortable_display_order = false;
3024
-        $this->display_order_tickets = 100;
3025
-        $this->display_order_datetimes = 110;
3026
-        $this->display_order_event = 120;
3027
-        $this->display_order_venue = 130;
3028
-    }
3016
+	/**
3017
+	 *    class constructor
3018
+	 */
3019
+	public function __construct()
3020
+	{
3021
+		$this->display_status_banner_single = 0;
3022
+		$this->display_venue = 1;
3023
+		$this->use_sortable_display_order = false;
3024
+		$this->display_order_tickets = 100;
3025
+		$this->display_order_datetimes = 110;
3026
+		$this->display_order_event = 120;
3027
+		$this->display_order_venue = 130;
3028
+	}
3029 3029
 }
3030 3030
 
3031 3031
 /**
@@ -3034,172 +3034,172 @@  discard block
 block discarded – undo
3034 3034
 class EE_Ticket_Selector_Config extends EE_Config_Base
3035 3035
 {
3036 3036
 
3037
-    /**
3038
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
3039
-     */
3040
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
3041
-
3042
-    /**
3043
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
3044
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
3045
-     */
3046
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3047
-
3048
-    /**
3049
-     * @var boolean $show_ticket_sale_columns
3050
-     */
3051
-    public $show_ticket_sale_columns;
3052
-
3053
-    /**
3054
-     * @var boolean $show_ticket_details
3055
-     */
3056
-    public $show_ticket_details;
3057
-
3058
-    /**
3059
-     * @var boolean $show_expired_tickets
3060
-     */
3061
-    public $show_expired_tickets;
3062
-
3063
-    /**
3064
-     * whether or not to display a dropdown box populated with event datetimes
3065
-     * that toggles which tickets are displayed for a ticket selector.
3066
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3067
-     *
3068
-     * @var string $show_datetime_selector
3069
-     */
3070
-    private $show_datetime_selector = 'no_datetime_selector';
3071
-
3072
-    /**
3073
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3074
-     *
3075
-     * @var int $datetime_selector_threshold
3076
-     */
3077
-    private $datetime_selector_threshold = 3;
3078
-
3079
-    /**
3080
-     * determines the maximum number of "checked" dates in the date and time filter
3081
-     *
3082
-     * @var int $datetime_selector_checked
3083
-     */
3084
-    private $datetime_selector_max_checked = 10;
3085
-
3086
-
3087
-    /**
3088
-     *    class constructor
3089
-     */
3090
-    public function __construct()
3091
-    {
3092
-        $this->show_ticket_sale_columns = true;
3093
-        $this->show_ticket_details = true;
3094
-        $this->show_expired_tickets = true;
3095
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3096
-        $this->datetime_selector_threshold = 3;
3097
-        $this->datetime_selector_max_checked = 10;
3098
-    }
3099
-
3100
-
3101
-    /**
3102
-     * returns true if a datetime selector should be displayed
3103
-     *
3104
-     * @param array $datetimes
3105
-     * @return bool
3106
-     */
3107
-    public function showDatetimeSelector(array $datetimes)
3108
-    {
3109
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3110
-        return ! (
3111
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3112
-            || (
3113
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3114
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3115
-            )
3116
-        );
3117
-    }
3118
-
3119
-
3120
-    /**
3121
-     * @return string
3122
-     */
3123
-    public function getShowDatetimeSelector()
3124
-    {
3125
-        return $this->show_datetime_selector;
3126
-    }
3127
-
3128
-
3129
-    /**
3130
-     * @param bool $keys_only
3131
-     * @return array
3132
-     */
3133
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3134
-    {
3135
-        return $keys_only
3136
-            ? array(
3137
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3138
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3139
-            )
3140
-            : array(
3141
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3142
-                    'Do not show date & time filter',
3143
-                    'event_espresso'
3144
-                ),
3145
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3146
-                    'Maybe show date & time filter',
3147
-                    'event_espresso'
3148
-                ),
3149
-            );
3150
-    }
3151
-
3152
-
3153
-    /**
3154
-     * @param string $show_datetime_selector
3155
-     */
3156
-    public function setShowDatetimeSelector($show_datetime_selector)
3157
-    {
3158
-        $this->show_datetime_selector = in_array(
3159
-            $show_datetime_selector,
3160
-            $this->getShowDatetimeSelectorOptions(),
3161
-            true
3162
-        )
3163
-            ? $show_datetime_selector
3164
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3165
-    }
3166
-
3167
-
3168
-    /**
3169
-     * @return int
3170
-     */
3171
-    public function getDatetimeSelectorThreshold()
3172
-    {
3173
-        return $this->datetime_selector_threshold;
3174
-    }
3175
-
3176
-
3177
-    /**
3178
-     * @param int $datetime_selector_threshold
3179
-     */
3180
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3181
-    {
3182
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3183
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3184
-    }
3185
-
3186
-
3187
-    /**
3188
-     * @return int
3189
-     */
3190
-    public function getDatetimeSelectorMaxChecked()
3191
-    {
3192
-        return $this->datetime_selector_max_checked;
3193
-    }
3194
-
3195
-
3196
-    /**
3197
-     * @param int $datetime_selector_max_checked
3198
-     */
3199
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3200
-    {
3201
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3202
-    }
3037
+	/**
3038
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
3039
+	 */
3040
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
3041
+
3042
+	/**
3043
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
3044
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
3045
+	 */
3046
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3047
+
3048
+	/**
3049
+	 * @var boolean $show_ticket_sale_columns
3050
+	 */
3051
+	public $show_ticket_sale_columns;
3052
+
3053
+	/**
3054
+	 * @var boolean $show_ticket_details
3055
+	 */
3056
+	public $show_ticket_details;
3057
+
3058
+	/**
3059
+	 * @var boolean $show_expired_tickets
3060
+	 */
3061
+	public $show_expired_tickets;
3062
+
3063
+	/**
3064
+	 * whether or not to display a dropdown box populated with event datetimes
3065
+	 * that toggles which tickets are displayed for a ticket selector.
3066
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3067
+	 *
3068
+	 * @var string $show_datetime_selector
3069
+	 */
3070
+	private $show_datetime_selector = 'no_datetime_selector';
3071
+
3072
+	/**
3073
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3074
+	 *
3075
+	 * @var int $datetime_selector_threshold
3076
+	 */
3077
+	private $datetime_selector_threshold = 3;
3078
+
3079
+	/**
3080
+	 * determines the maximum number of "checked" dates in the date and time filter
3081
+	 *
3082
+	 * @var int $datetime_selector_checked
3083
+	 */
3084
+	private $datetime_selector_max_checked = 10;
3085
+
3086
+
3087
+	/**
3088
+	 *    class constructor
3089
+	 */
3090
+	public function __construct()
3091
+	{
3092
+		$this->show_ticket_sale_columns = true;
3093
+		$this->show_ticket_details = true;
3094
+		$this->show_expired_tickets = true;
3095
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3096
+		$this->datetime_selector_threshold = 3;
3097
+		$this->datetime_selector_max_checked = 10;
3098
+	}
3099
+
3100
+
3101
+	/**
3102
+	 * returns true if a datetime selector should be displayed
3103
+	 *
3104
+	 * @param array $datetimes
3105
+	 * @return bool
3106
+	 */
3107
+	public function showDatetimeSelector(array $datetimes)
3108
+	{
3109
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3110
+		return ! (
3111
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3112
+			|| (
3113
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3114
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3115
+			)
3116
+		);
3117
+	}
3118
+
3119
+
3120
+	/**
3121
+	 * @return string
3122
+	 */
3123
+	public function getShowDatetimeSelector()
3124
+	{
3125
+		return $this->show_datetime_selector;
3126
+	}
3127
+
3128
+
3129
+	/**
3130
+	 * @param bool $keys_only
3131
+	 * @return array
3132
+	 */
3133
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3134
+	{
3135
+		return $keys_only
3136
+			? array(
3137
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3138
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3139
+			)
3140
+			: array(
3141
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3142
+					'Do not show date & time filter',
3143
+					'event_espresso'
3144
+				),
3145
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3146
+					'Maybe show date & time filter',
3147
+					'event_espresso'
3148
+				),
3149
+			);
3150
+	}
3151
+
3152
+
3153
+	/**
3154
+	 * @param string $show_datetime_selector
3155
+	 */
3156
+	public function setShowDatetimeSelector($show_datetime_selector)
3157
+	{
3158
+		$this->show_datetime_selector = in_array(
3159
+			$show_datetime_selector,
3160
+			$this->getShowDatetimeSelectorOptions(),
3161
+			true
3162
+		)
3163
+			? $show_datetime_selector
3164
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3165
+	}
3166
+
3167
+
3168
+	/**
3169
+	 * @return int
3170
+	 */
3171
+	public function getDatetimeSelectorThreshold()
3172
+	{
3173
+		return $this->datetime_selector_threshold;
3174
+	}
3175
+
3176
+
3177
+	/**
3178
+	 * @param int $datetime_selector_threshold
3179
+	 */
3180
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3181
+	{
3182
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3183
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3184
+	}
3185
+
3186
+
3187
+	/**
3188
+	 * @return int
3189
+	 */
3190
+	public function getDatetimeSelectorMaxChecked()
3191
+	{
3192
+		return $this->datetime_selector_max_checked;
3193
+	}
3194
+
3195
+
3196
+	/**
3197
+	 * @param int $datetime_selector_max_checked
3198
+	 */
3199
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3200
+	{
3201
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3202
+	}
3203 3203
 }
3204 3204
 
3205 3205
 /**
@@ -3212,86 +3212,86 @@  discard block
 block discarded – undo
3212 3212
 class EE_Environment_Config extends EE_Config_Base
3213 3213
 {
3214 3214
 
3215
-    /**
3216
-     * Hold any php environment variables that we want to track.
3217
-     *
3218
-     * @var stdClass;
3219
-     */
3220
-    public $php;
3221
-
3222
-
3223
-    /**
3224
-     *    constructor
3225
-     */
3226
-    public function __construct()
3227
-    {
3228
-        $this->php = new stdClass();
3229
-        $this->_set_php_values();
3230
-    }
3231
-
3232
-
3233
-    /**
3234
-     * This sets the php environment variables.
3235
-     *
3236
-     * @since 4.4.0
3237
-     * @return void
3238
-     */
3239
-    protected function _set_php_values()
3240
-    {
3241
-        $this->php->max_input_vars = ini_get('max_input_vars');
3242
-        $this->php->version = phpversion();
3243
-    }
3244
-
3245
-
3246
-    /**
3247
-     * helper method for determining whether input_count is
3248
-     * reaching the potential maximum the server can handle
3249
-     * according to max_input_vars
3250
-     *
3251
-     * @param int   $input_count the count of input vars.
3252
-     * @return array {
3253
-     *                           An array that represents whether available space and if no available space the error
3254
-     *                           message.
3255
-     * @type bool   $has_space   whether more inputs can be added.
3256
-     * @type string $msg         Any message to be displayed.
3257
-     *                           }
3258
-     */
3259
-    public function max_input_vars_limit_check($input_count = 0)
3260
-    {
3261
-        if (! empty($this->php->max_input_vars)
3262
-            && ($input_count >= $this->php->max_input_vars)
3263
-        ) {
3264
-            // check the server setting because the config value could be stale
3265
-            $max_input_vars = ini_get('max_input_vars');
3266
-            if ($input_count >= $max_input_vars) {
3267
-                return sprintf(
3268
-                    esc_html__(
3269
-                        '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.',
3270
-                        'event_espresso'
3271
-                    ),
3272
-                    '<br>',
3273
-                    $input_count,
3274
-                    $max_input_vars
3275
-                );
3276
-            } else {
3277
-                return '';
3278
-            }
3279
-        } else {
3280
-            return '';
3281
-        }
3282
-    }
3283
-
3284
-
3285
-    /**
3286
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3287
-     *
3288
-     * @since 4.4.1
3289
-     * @return void
3290
-     */
3291
-    public function recheck_values()
3292
-    {
3293
-        $this->_set_php_values();
3294
-    }
3215
+	/**
3216
+	 * Hold any php environment variables that we want to track.
3217
+	 *
3218
+	 * @var stdClass;
3219
+	 */
3220
+	public $php;
3221
+
3222
+
3223
+	/**
3224
+	 *    constructor
3225
+	 */
3226
+	public function __construct()
3227
+	{
3228
+		$this->php = new stdClass();
3229
+		$this->_set_php_values();
3230
+	}
3231
+
3232
+
3233
+	/**
3234
+	 * This sets the php environment variables.
3235
+	 *
3236
+	 * @since 4.4.0
3237
+	 * @return void
3238
+	 */
3239
+	protected function _set_php_values()
3240
+	{
3241
+		$this->php->max_input_vars = ini_get('max_input_vars');
3242
+		$this->php->version = phpversion();
3243
+	}
3244
+
3245
+
3246
+	/**
3247
+	 * helper method for determining whether input_count is
3248
+	 * reaching the potential maximum the server can handle
3249
+	 * according to max_input_vars
3250
+	 *
3251
+	 * @param int   $input_count the count of input vars.
3252
+	 * @return array {
3253
+	 *                           An array that represents whether available space and if no available space the error
3254
+	 *                           message.
3255
+	 * @type bool   $has_space   whether more inputs can be added.
3256
+	 * @type string $msg         Any message to be displayed.
3257
+	 *                           }
3258
+	 */
3259
+	public function max_input_vars_limit_check($input_count = 0)
3260
+	{
3261
+		if (! empty($this->php->max_input_vars)
3262
+			&& ($input_count >= $this->php->max_input_vars)
3263
+		) {
3264
+			// check the server setting because the config value could be stale
3265
+			$max_input_vars = ini_get('max_input_vars');
3266
+			if ($input_count >= $max_input_vars) {
3267
+				return sprintf(
3268
+					esc_html__(
3269
+						'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.',
3270
+						'event_espresso'
3271
+					),
3272
+					'<br>',
3273
+					$input_count,
3274
+					$max_input_vars
3275
+				);
3276
+			} else {
3277
+				return '';
3278
+			}
3279
+		} else {
3280
+			return '';
3281
+		}
3282
+	}
3283
+
3284
+
3285
+	/**
3286
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3287
+	 *
3288
+	 * @since 4.4.1
3289
+	 * @return void
3290
+	 */
3291
+	public function recheck_values()
3292
+	{
3293
+		$this->_set_php_values();
3294
+	}
3295 3295
 }
3296 3296
 
3297 3297
 /**
@@ -3304,21 +3304,21 @@  discard block
 block discarded – undo
3304 3304
 class EE_Tax_Config extends EE_Config_Base
3305 3305
 {
3306 3306
 
3307
-    /*
3307
+	/*
3308 3308
      * flag to indicate whether or not to display ticket prices with the taxes included
3309 3309
      *
3310 3310
      * @var boolean $prices_displayed_including_taxes
3311 3311
      */
3312
-    public $prices_displayed_including_taxes;
3312
+	public $prices_displayed_including_taxes;
3313 3313
 
3314 3314
 
3315
-    /**
3316
-     *    class constructor
3317
-     */
3318
-    public function __construct()
3319
-    {
3320
-        $this->prices_displayed_including_taxes = true;
3321
-    }
3315
+	/**
3316
+	 *    class constructor
3317
+	 */
3318
+	public function __construct()
3319
+	{
3320
+		$this->prices_displayed_including_taxes = true;
3321
+	}
3322 3322
 }
3323 3323
 
3324 3324
 /**
@@ -3332,19 +3332,19 @@  discard block
 block discarded – undo
3332 3332
 class EE_Messages_Config extends EE_Config_Base
3333 3333
 {
3334 3334
 
3335
-    /**
3336
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3337
-     * A value of 0 represents never deleting.  Default is 0.
3338
-     *
3339
-     * @var integer
3340
-     */
3341
-    public $delete_threshold;
3335
+	/**
3336
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3337
+	 * A value of 0 represents never deleting.  Default is 0.
3338
+	 *
3339
+	 * @var integer
3340
+	 */
3341
+	public $delete_threshold;
3342 3342
 
3343 3343
 
3344
-    public function __construct()
3345
-    {
3346
-        $this->delete_threshold = 0;
3347
-    }
3344
+	public function __construct()
3345
+	{
3346
+		$this->delete_threshold = 0;
3347
+	}
3348 3348
 }
3349 3349
 
3350 3350
 /**
@@ -3355,31 +3355,31 @@  discard block
 block discarded – undo
3355 3355
 class EE_Gateway_Config extends EE_Config_Base
3356 3356
 {
3357 3357
 
3358
-    /**
3359
-     * Array with keys that are payment gateways slugs, and values are arrays
3360
-     * with any config info the gateway wants to store
3361
-     *
3362
-     * @var array
3363
-     */
3364
-    public $payment_settings;
3365
-
3366
-    /**
3367
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3368
-     * the gateway is stored in the uploads directory
3369
-     *
3370
-     * @var array
3371
-     */
3372
-    public $active_gateways;
3373
-
3374
-
3375
-    /**
3376
-     *    class constructor
3377
-     *
3378
-     * @deprecated
3379
-     */
3380
-    public function __construct()
3381
-    {
3382
-        $this->payment_settings = array();
3383
-        $this->active_gateways = array('Invoice' => false);
3384
-    }
3358
+	/**
3359
+	 * Array with keys that are payment gateways slugs, and values are arrays
3360
+	 * with any config info the gateway wants to store
3361
+	 *
3362
+	 * @var array
3363
+	 */
3364
+	public $payment_settings;
3365
+
3366
+	/**
3367
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3368
+	 * the gateway is stored in the uploads directory
3369
+	 *
3370
+	 * @var array
3371
+	 */
3372
+	public $active_gateways;
3373
+
3374
+
3375
+	/**
3376
+	 *    class constructor
3377
+	 *
3378
+	 * @deprecated
3379
+	 */
3380
+	public function __construct()
3381
+	{
3382
+		$this->payment_settings = array();
3383
+		$this->active_gateways = array('Invoice' => false);
3384
+	}
3385 3385
 }
Please login to merge, or discard this patch.