Completed
Branch models-cleanup/main (de94a1)
by
unknown
14:03 queued 11:37
created
core/db_models/EEM_Event_Message_Template.model.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -12,117 +12,117 @@
 block discarded – undo
12 12
 class EEM_Event_Message_Template extends EEM_Base
13 13
 {
14 14
 
15
-    // private instance of the EEM_Event_Message_Template object
16
-    protected static $_instance;
15
+	// private instance of the EEM_Event_Message_Template object
16
+	protected static $_instance;
17 17
 
18 18
 
19
-    /**
20
-     * protected constructor to prevent direct creation
21
-     *
22
-     * @param null $timezone
23
-     * @throws EE_Error
24
-     */
25
-    protected function __construct(string $timezone = '')
26
-    {
27
-        $this->singular_item = esc_html__('Event Message Template', 'event_espresso');
28
-        $this->plural_item   = esc_html__('Event Message Templates', 'event_espresso');
19
+	/**
20
+	 * protected constructor to prevent direct creation
21
+	 *
22
+	 * @param null $timezone
23
+	 * @throws EE_Error
24
+	 */
25
+	protected function __construct(string $timezone = '')
26
+	{
27
+		$this->singular_item = esc_html__('Event Message Template', 'event_espresso');
28
+		$this->plural_item   = esc_html__('Event Message Templates', 'event_espresso');
29 29
 
30
-        $this->_tables          = [
31
-            'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'),
32
-        ];
33
-        $this->_fields          = [
34
-            'Event_Message_Template' => [
35
-                'EMT_ID' => new EE_Primary_Key_Int_Field(
36
-                    'EMT_ID',
37
-                    esc_html__('Event Message Template ID', 'event_espresso')
38
-                ),
39
-                'EVT_ID' => new EE_Foreign_Key_Int_Field(
40
-                    'EVT_ID',
41
-                    esc_html__('The ID to the Event', 'event_espresso'),
42
-                    false,
43
-                    0,
44
-                    'Event'
45
-                ),
46
-                'GRP_ID' => new EE_Foreign_Key_Int_Field(
47
-                    'GRP_ID',
48
-                    esc_html__('The ID to the Message Template Group', 'event_espresso'),
49
-                    false,
50
-                    0,
51
-                    'Message_Template_Group'
52
-                ),
53
-            ],
54
-        ];
55
-        $this->_model_relations = [
56
-            'Event'                  => new EE_Belongs_To_Relation(),
57
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
58
-        ];
59
-        $path_to_event          = 'Event';
60
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
61
-            $path_to_event
62
-        );
63
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
64
-            $path_to_event
65
-        );
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
67
-            $path_to_event
68
-        );
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected(
70
-            $path_to_event,
71
-            EEM_Base::caps_edit
72
-        );
73
-        parent::__construct($timezone);
74
-    }
30
+		$this->_tables          = [
31
+			'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'),
32
+		];
33
+		$this->_fields          = [
34
+			'Event_Message_Template' => [
35
+				'EMT_ID' => new EE_Primary_Key_Int_Field(
36
+					'EMT_ID',
37
+					esc_html__('Event Message Template ID', 'event_espresso')
38
+				),
39
+				'EVT_ID' => new EE_Foreign_Key_Int_Field(
40
+					'EVT_ID',
41
+					esc_html__('The ID to the Event', 'event_espresso'),
42
+					false,
43
+					0,
44
+					'Event'
45
+				),
46
+				'GRP_ID' => new EE_Foreign_Key_Int_Field(
47
+					'GRP_ID',
48
+					esc_html__('The ID to the Message Template Group', 'event_espresso'),
49
+					false,
50
+					0,
51
+					'Message_Template_Group'
52
+				),
53
+			],
54
+		];
55
+		$this->_model_relations = [
56
+			'Event'                  => new EE_Belongs_To_Relation(),
57
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
58
+		];
59
+		$path_to_event          = 'Event';
60
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
61
+			$path_to_event
62
+		);
63
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
64
+			$path_to_event
65
+		);
66
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
67
+			$path_to_event
68
+		);
69
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected(
70
+			$path_to_event,
71
+			EEM_Base::caps_edit
72
+		);
73
+		parent::__construct($timezone);
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * helper method to simply return an array of event ids for events attached to the given
79
-     * message template group.
80
-     *
81
-     * @param int $GRP_ID The MTP group we want attached events for.
82
-     * @return  array               An array of event ids.
83
-     * @throws EE_Error
84
-     * @throws ReflectionException
85
-     * @since 4.3.0
86
-     */
87
-    public function get_attached_event_ids(int $GRP_ID): array
88
-    {
89
-        $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID');
90
-        return call_user_func_array('array_merge', $event_ids);
91
-    }
77
+	/**
78
+	 * helper method to simply return an array of event ids for events attached to the given
79
+	 * message template group.
80
+	 *
81
+	 * @param int $GRP_ID The MTP group we want attached events for.
82
+	 * @return  array               An array of event ids.
83
+	 * @throws EE_Error
84
+	 * @throws ReflectionException
85
+	 * @since 4.3.0
86
+	 */
87
+	public function get_attached_event_ids(int $GRP_ID): array
88
+	{
89
+		$event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID');
90
+		return call_user_func_array('array_merge', $event_ids);
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * helper method for clearing event/group relations for the given event ids and grp ids.
96
-     *
97
-     * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs.
98
-     * @param array $EVT_IDs An array of EVT_IDs.  Optional. If empty then there must be GRP IDs.
99
-     * @return int             How many rows were deleted.
100
-     * @throws EE_Error
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    public function delete_event_group_relations(array $GRP_IDs = [], array $EVT_IDs = []): int
105
-    {
106
-        if (empty($GRP_IDs) && empty($EVT_IDs)) {
107
-            throw new EE_Error(
108
-                sprintf(
109
-                    esc_html__(
110
-                        '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.',
111
-                        'event_espresso'
112
-                    ),
113
-                    __METHOD__
114
-                )
115
-            );
116
-        }
94
+	/**
95
+	 * helper method for clearing event/group relations for the given event ids and grp ids.
96
+	 *
97
+	 * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs.
98
+	 * @param array $EVT_IDs An array of EVT_IDs.  Optional. If empty then there must be GRP IDs.
99
+	 * @return int             How many rows were deleted.
100
+	 * @throws EE_Error
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	public function delete_event_group_relations(array $GRP_IDs = [], array $EVT_IDs = []): int
105
+	{
106
+		if (empty($GRP_IDs) && empty($EVT_IDs)) {
107
+			throw new EE_Error(
108
+				sprintf(
109
+					esc_html__(
110
+						'%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.',
111
+						'event_espresso'
112
+					),
113
+					__METHOD__
114
+				)
115
+			);
116
+		}
117 117
 
118
-        $where = [];
119
-        if (! empty($GRP_IDs)) {
120
-            $where['GRP_ID'] = ['IN', $GRP_IDs];
121
-        }
122
-        if (! empty($EVT_IDs)) {
123
-            $where['EVT_ID'] = ['IN', $EVT_IDs];
124
-        }
118
+		$where = [];
119
+		if (! empty($GRP_IDs)) {
120
+			$where['GRP_ID'] = ['IN', $GRP_IDs];
121
+		}
122
+		if (! empty($EVT_IDs)) {
123
+			$where['EVT_ID'] = ['IN', $EVT_IDs];
124
+		}
125 125
 
126
-        return $this->delete([$where], false);
127
-    }
126
+		return $this->delete([$where], false);
127
+	}
128 128
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
             'Event'                  => new EE_Belongs_To_Relation(),
57 57
             'Message_Template_Group' => new EE_Belongs_To_Relation(),
58 58
         ];
59
-        $path_to_event          = 'Event';
60
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
59
+        $path_to_event = 'Event';
60
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public(
61 61
             $path_to_event
62 62
         );
63
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
63
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected(
64 64
             $path_to_event
65 65
         );
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
66
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected(
67 67
             $path_to_event
68 68
         );
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected(
69
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected(
70 70
             $path_to_event,
71 71
             EEM_Base::caps_edit
72 72
         );
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
         }
117 117
 
118 118
         $where = [];
119
-        if (! empty($GRP_IDs)) {
119
+        if ( ! empty($GRP_IDs)) {
120 120
             $where['GRP_ID'] = ['IN', $GRP_IDs];
121 121
         }
122
-        if (! empty($EVT_IDs)) {
122
+        if ( ! empty($EVT_IDs)) {
123 123
             $where['EVT_ID'] = ['IN', $EVT_IDs];
124 124
         }
125 125
 
Please login to merge, or discard this patch.
core/db_models/EEM_Currency.model.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -9,104 +9,104 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Currency extends EEM_Base
11 11
 {
12
-    // private instance of the Attendee object
13
-    protected static $_instance;
12
+	// private instance of the Attendee object
13
+	protected static $_instance;
14 14
 
15
-    protected function __construct(string $timezone = '')
16
-    {
17
-        $this->singular_item    = esc_html__('Currency', 'event_espresso');
18
-        $this->plural_item      = esc_html__('Currencies', 'event_espresso');
19
-        $this->_tables          = [
20
-            'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code'),
21
-        ];
22
-        $this->_fields          = [
23
-            'Currency' => [
24
-                'CUR_code'    => new EE_Primary_Key_String_Field(
25
-                    'CUR_code',
26
-                    esc_html__('Currency Code', 'event_espresso')
27
-                ),
28
-                'CUR_single'  => new EE_Plain_Text_Field(
29
-                    'CUR_single',
30
-                    esc_html__('Currency Name Singular', 'event_espresso'),
31
-                    false
32
-                ),
33
-                'CUR_plural'  => new EE_Plain_Text_Field(
34
-                    'CUR_plural',
35
-                    esc_html__('Currency Name Plural', 'event_espresso'),
36
-                    false
37
-                ),
38
-                'CUR_sign'    => new EE_Plain_Text_Field(
39
-                    'CUR_sign',
40
-                    esc_html__('Currency Sign', 'event_espresso'),
41
-                    false
42
-                ),
43
-                'CUR_dec_plc' => new EE_Integer_Field(
44
-                    'CUR_dec_plc',
45
-                    esc_html__('Currency Decimal Places', 'event_espresso'),
46
-                    false,
47
-                    2
48
-                ),
49
-                'CUR_active'  => new EE_Boolean_Field(
50
-                    'CUR_active',
51
-                    esc_html__('Active?', 'event_espresso'),
52
-                    false,
53
-                    true
54
-                ),
55
-            ],
56
-        ];
57
-        $this->_model_relations = [
58
-            'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
59
-        ];
60
-        // this model is generally available for reading
61
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
15
+	protected function __construct(string $timezone = '')
16
+	{
17
+		$this->singular_item    = esc_html__('Currency', 'event_espresso');
18
+		$this->plural_item      = esc_html__('Currencies', 'event_espresso');
19
+		$this->_tables          = [
20
+			'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code'),
21
+		];
22
+		$this->_fields          = [
23
+			'Currency' => [
24
+				'CUR_code'    => new EE_Primary_Key_String_Field(
25
+					'CUR_code',
26
+					esc_html__('Currency Code', 'event_espresso')
27
+				),
28
+				'CUR_single'  => new EE_Plain_Text_Field(
29
+					'CUR_single',
30
+					esc_html__('Currency Name Singular', 'event_espresso'),
31
+					false
32
+				),
33
+				'CUR_plural'  => new EE_Plain_Text_Field(
34
+					'CUR_plural',
35
+					esc_html__('Currency Name Plural', 'event_espresso'),
36
+					false
37
+				),
38
+				'CUR_sign'    => new EE_Plain_Text_Field(
39
+					'CUR_sign',
40
+					esc_html__('Currency Sign', 'event_espresso'),
41
+					false
42
+				),
43
+				'CUR_dec_plc' => new EE_Integer_Field(
44
+					'CUR_dec_plc',
45
+					esc_html__('Currency Decimal Places', 'event_espresso'),
46
+					false,
47
+					2
48
+				),
49
+				'CUR_active'  => new EE_Boolean_Field(
50
+					'CUR_active',
51
+					esc_html__('Active?', 'event_espresso'),
52
+					false,
53
+					true
54
+				),
55
+			],
56
+		];
57
+		$this->_model_relations = [
58
+			'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
59
+		];
60
+		// this model is generally available for reading
61
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
62 62
 
63
-        parent::__construct($timezone);
64
-    }
63
+		parent::__construct($timezone);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * Gets all the active currencies, and orders them by their singular name, and then their code
69
-     * (may be overridden)
70
-     *
71
-     * @param array $query_params @see
72
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
73
-     * @return EE_Currency[]
74
-     * @throws EE_Error
75
-     * @throws ReflectionException
76
-     */
77
-    public function get_all_active(array $query_params = []): array
78
-    {
79
-        $query_params[0]['CUR_active'] = true;
80
-        if (! isset($query_params['order_by'])) {
81
-            $query_params['order_by'] = ['CUR_code' => 'ASC', 'CUR_single' => 'ASC'];
82
-        }
83
-        return $this->get_all($query_params);
84
-    }
67
+	/**
68
+	 * Gets all the active currencies, and orders them by their singular name, and then their code
69
+	 * (may be overridden)
70
+	 *
71
+	 * @param array $query_params @see
72
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
73
+	 * @return EE_Currency[]
74
+	 * @throws EE_Error
75
+	 * @throws ReflectionException
76
+	 */
77
+	public function get_all_active(array $query_params = []): array
78
+	{
79
+		$query_params[0]['CUR_active'] = true;
80
+		if (! isset($query_params['order_by'])) {
81
+			$query_params['order_by'] = ['CUR_code' => 'ASC', 'CUR_single' => 'ASC'];
82
+		}
83
+		return $this->get_all($query_params);
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * Gets all the currencies which can be used by that payment method type
89
-     *
90
-     * @param EE_PMT_Base $payment_method_type
91
-     * @return EE_Currency[]
92
-     * @throws EE_Error
93
-     * @throws ReflectionException
94
-     */
95
-    public function get_all_currencies_usable_by(EE_PMT_Base $payment_method_type): array
96
-    {
97
-        if (
98
-            $payment_method_type instanceof EE_PMT_Base
99
-            && $payment_method_type->get_gateway()
100
-        ) {
101
-            $currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
102
-        } else {
103
-            $currencies_supported = EE_Gateway::all_currencies_supported;
104
-        }
105
-        if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
106
-            $currencies = $this->get_all_active();
107
-        } else {
108
-            $currencies = $this->get_all_active([['CUR_code' => ['IN', $currencies_supported]]]);
109
-        }
110
-        return $currencies;
111
-    }
87
+	/**
88
+	 * Gets all the currencies which can be used by that payment method type
89
+	 *
90
+	 * @param EE_PMT_Base $payment_method_type
91
+	 * @return EE_Currency[]
92
+	 * @throws EE_Error
93
+	 * @throws ReflectionException
94
+	 */
95
+	public function get_all_currencies_usable_by(EE_PMT_Base $payment_method_type): array
96
+	{
97
+		if (
98
+			$payment_method_type instanceof EE_PMT_Base
99
+			&& $payment_method_type->get_gateway()
100
+		) {
101
+			$currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
102
+		} else {
103
+			$currencies_supported = EE_Gateway::all_currencies_supported;
104
+		}
105
+		if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
106
+			$currencies = $this->get_all_active();
107
+		} else {
108
+			$currencies = $this->get_all_active([['CUR_code' => ['IN', $currencies_supported]]]);
109
+		}
110
+		return $currencies;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
59 59
         ];
60 60
         // this model is generally available for reading
61
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
61
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
62 62
 
63 63
         parent::__construct($timezone);
64 64
     }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     public function get_all_active(array $query_params = []): array
78 78
     {
79 79
         $query_params[0]['CUR_active'] = true;
80
-        if (! isset($query_params['order_by'])) {
80
+        if ( ! isset($query_params['order_by'])) {
81 81
             $query_params['order_by'] = ['CUR_code' => 'ASC', 'CUR_single' => 'ASC'];
82 82
         }
83 83
         return $this->get_all($query_params);
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Price.model.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -10,73 +10,73 @@
 block discarded – undo
10 10
 class EEM_Ticket_Price extends EEM_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @var EEM_Ticket_Price
15
-     */
16
-    protected static $_instance;
13
+	/**
14
+	 * @var EEM_Ticket_Price
15
+	 */
16
+	protected static $_instance;
17 17
 
18 18
 
19
-    /**
20
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
21
-     *                         (and any incoming timezone data that gets saved).
22
-     *                         Note this just sends the timezone info to the date time model field objects.
23
-     *                         Will use 'timezone_string' wp option if no value is provided
24
-     * @throws EE_Error
25
-     */
26
-    protected function __construct(string $timezone = '')
27
-    {
28
-        $this->singular_item = esc_html__('Ticket Price', 'event_espresso');
29
-        $this->plural_item = esc_html__('Ticket Prices', 'event_espresso');
19
+	/**
20
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
21
+	 *                         (and any incoming timezone data that gets saved).
22
+	 *                         Note this just sends the timezone info to the date time model field objects.
23
+	 *                         Will use 'timezone_string' wp option if no value is provided
24
+	 * @throws EE_Error
25
+	 */
26
+	protected function __construct(string $timezone = '')
27
+	{
28
+		$this->singular_item = esc_html__('Ticket Price', 'event_espresso');
29
+		$this->plural_item = esc_html__('Ticket Prices', 'event_espresso');
30 30
 
31
-        $this->_tables = array(
32
-            'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
33
-        );
34
-        $this->_fields = array(
35
-            'Ticket_Price' => array(
36
-                'TKP_ID' => new EE_Primary_Key_Int_Field(
37
-                    'TKP_ID',
38
-                    esc_html__('Ticket Price ID', 'event_espresso')
39
-                ),
40
-                'TKT_ID' => new EE_Foreign_Key_Int_Field(
41
-                    'TKT_ID',
42
-                    esc_html__('Ticket Id', 'event_espresso'),
43
-                    false,
44
-                    0,
45
-                    'Ticket'
46
-                ),
47
-                'PRC_ID' => new EE_Foreign_Key_Int_Field(
48
-                    'PRC_ID',
49
-                    esc_html__('Price ID', 'event_espresso'),
50
-                    false,
51
-                    0,
52
-                    'Price'
53
-                ),
54
-            )
55
-        );
56
-        $this->_model_relations = array(
57
-            'Ticket' => new EE_Belongs_To_Relation(),
58
-            'Price' => new EE_Belongs_To_Relation()
59
-        );
60
-        $this->_model_chain_to_wp_user = 'Ticket';
61
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
62
-            'Ticket.TKT_is_default',
63
-            'Ticket.Datetime.Event'
64
-        );
65
-        // account for default tickets in the caps
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
67
-            'Ticket.TKT_is_default',
68
-            'Ticket.Datetime.Event'
69
-        );
70
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
71
-            'Ticket.TKT_is_default',
72
-            'Ticket.Datetime.Event'
73
-        );
74
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
75
-            'Ticket.TKT_is_default',
76
-            'Ticket.Datetime.Event'
77
-        );
78
-        // follow the caps of the ticket
79
-        $this->_caps_slug = 'tickets';
80
-        parent::__construct($timezone);
81
-    }
31
+		$this->_tables = array(
32
+			'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
33
+		);
34
+		$this->_fields = array(
35
+			'Ticket_Price' => array(
36
+				'TKP_ID' => new EE_Primary_Key_Int_Field(
37
+					'TKP_ID',
38
+					esc_html__('Ticket Price ID', 'event_espresso')
39
+				),
40
+				'TKT_ID' => new EE_Foreign_Key_Int_Field(
41
+					'TKT_ID',
42
+					esc_html__('Ticket Id', 'event_espresso'),
43
+					false,
44
+					0,
45
+					'Ticket'
46
+				),
47
+				'PRC_ID' => new EE_Foreign_Key_Int_Field(
48
+					'PRC_ID',
49
+					esc_html__('Price ID', 'event_espresso'),
50
+					false,
51
+					0,
52
+					'Price'
53
+				),
54
+			)
55
+		);
56
+		$this->_model_relations = array(
57
+			'Ticket' => new EE_Belongs_To_Relation(),
58
+			'Price' => new EE_Belongs_To_Relation()
59
+		);
60
+		$this->_model_chain_to_wp_user = 'Ticket';
61
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
62
+			'Ticket.TKT_is_default',
63
+			'Ticket.Datetime.Event'
64
+		);
65
+		// account for default tickets in the caps
66
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
67
+			'Ticket.TKT_is_default',
68
+			'Ticket.Datetime.Event'
69
+		);
70
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
71
+			'Ticket.TKT_is_default',
72
+			'Ticket.Datetime.Event'
73
+		);
74
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
75
+			'Ticket.TKT_is_default',
76
+			'Ticket.Datetime.Event'
77
+		);
78
+		// follow the caps of the ticket
79
+		$this->_caps_slug = 'tickets';
80
+		parent::__construct($timezone);
81
+	}
82 82
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,20 +58,20 @@
 block discarded – undo
58 58
             'Price' => new EE_Belongs_To_Relation()
59 59
         );
60 60
         $this->_model_chain_to_wp_user = 'Ticket';
61
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
61
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public(
62 62
             'Ticket.TKT_is_default',
63 63
             'Ticket.Datetime.Event'
64 64
         );
65 65
         // account for default tickets in the caps
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
66
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected(
67 67
             'Ticket.TKT_is_default',
68 68
             'Ticket.Datetime.Event'
69 69
         );
70
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
70
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected(
71 71
             'Ticket.TKT_is_default',
72 72
             'Ticket.Datetime.Event'
73 73
         );
74
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
74
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected(
75 75
             'Ticket.TKT_is_default',
76 76
             'Ticket.Datetime.Event'
77 77
         );
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Template.model.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -10,72 +10,72 @@
 block discarded – undo
10 10
 class EEM_Ticket_Template extends EEM_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @var EEM_Ticket_Template
15
-     */
16
-    protected static $_instance;
13
+	/**
14
+	 * @var EEM_Ticket_Template
15
+	 */
16
+	protected static $_instance;
17 17
 
18
-    /**
19
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
20
-     *                         (and any incoming timezone data that gets saved).
21
-     *                         Note this just sends the timezone info to the date time model field objects.
22
-     *                         Will use 'timezone_string' wp option if no value is provided
23
-     * @throws EE_Error
24
-     */
25
-    protected function __construct(string $timezone = '')
26
-    {
27
-        $this->singular_item = esc_html__('Ticket Template', 'event_espresso');
28
-        $this->plural_item = esc_html__('Ticket Templates', 'event_espresso');
18
+	/**
19
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
20
+	 *                         (and any incoming timezone data that gets saved).
21
+	 *                         Note this just sends the timezone info to the date time model field objects.
22
+	 *                         Will use 'timezone_string' wp option if no value is provided
23
+	 * @throws EE_Error
24
+	 */
25
+	protected function __construct(string $timezone = '')
26
+	{
27
+		$this->singular_item = esc_html__('Ticket Template', 'event_espresso');
28
+		$this->plural_item = esc_html__('Ticket Templates', 'event_espresso');
29 29
 
30
-        $this->_tables = array(
31
-            'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
32
-        );
33
-        $this->_fields = array(
34
-            'Ticket_Template' => array(
35
-                'TTM_ID' => new EE_Primary_Key_Int_Field(
36
-                    'TTM_ID',
37
-                    esc_html__('Ticket Template ID', 'event_espresso')
38
-                ),
39
-                'TTM_name' => new EE_Plain_Text_Field(
40
-                    'TTM_name',
41
-                    esc_html__('The name of the ticket template', 'event_espresso'),
42
-                    false,
43
-                    ''
44
-                ),
45
-                'TTM_description' => new EE_Plain_Text_Field(
46
-                    'TTM_description',
47
-                    esc_html__('The description for the ticket template', 'event_espresso'),
48
-                    true,
49
-                    ''
50
-                ),
51
-                'TTM_file' => new EE_Plain_Text_Field(
52
-                    'TTM_file',
53
-                    esc_html__('The file name for the actual template file saved on disk', 'event_espresso'),
54
-                    true,
55
-                    ''
56
-                ),
57
-            ));
58
-        $this->_model_relations = array(
59
-            'Ticket' => new EE_Has_Many_Relation()
60
-        );
61
-        $this->_model_chain_to_wp_user = 'Ticket';
62
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
63
-            'Ticket.TKT_is_default',
64
-            'Ticket.Datetime.Event'
65
-        );
66
-        // account for default tickets in the caps
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
68
-            'Ticket.TKT_is_default',
69
-            'Ticket.Datetime.Event'
70
-        );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
72
-            'Ticket.TKT_is_default',
73
-            'Ticket.Datetime.Event'
74
-        );
75
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
76
-            'Ticket.TKT_is_default',
77
-            'Ticket.Datetime.Event'
78
-        );
79
-        parent::__construct($timezone);
80
-    }
30
+		$this->_tables = array(
31
+			'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
32
+		);
33
+		$this->_fields = array(
34
+			'Ticket_Template' => array(
35
+				'TTM_ID' => new EE_Primary_Key_Int_Field(
36
+					'TTM_ID',
37
+					esc_html__('Ticket Template ID', 'event_espresso')
38
+				),
39
+				'TTM_name' => new EE_Plain_Text_Field(
40
+					'TTM_name',
41
+					esc_html__('The name of the ticket template', 'event_espresso'),
42
+					false,
43
+					''
44
+				),
45
+				'TTM_description' => new EE_Plain_Text_Field(
46
+					'TTM_description',
47
+					esc_html__('The description for the ticket template', 'event_espresso'),
48
+					true,
49
+					''
50
+				),
51
+				'TTM_file' => new EE_Plain_Text_Field(
52
+					'TTM_file',
53
+					esc_html__('The file name for the actual template file saved on disk', 'event_espresso'),
54
+					true,
55
+					''
56
+				),
57
+			));
58
+		$this->_model_relations = array(
59
+			'Ticket' => new EE_Has_Many_Relation()
60
+		);
61
+		$this->_model_chain_to_wp_user = 'Ticket';
62
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
63
+			'Ticket.TKT_is_default',
64
+			'Ticket.Datetime.Event'
65
+		);
66
+		// account for default tickets in the caps
67
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
68
+			'Ticket.TKT_is_default',
69
+			'Ticket.Datetime.Event'
70
+		);
71
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
72
+			'Ticket.TKT_is_default',
73
+			'Ticket.Datetime.Event'
74
+		);
75
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
76
+			'Ticket.TKT_is_default',
77
+			'Ticket.Datetime.Event'
78
+		);
79
+		parent::__construct($timezone);
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,20 +59,20 @@
 block discarded – undo
59 59
             'Ticket' => new EE_Has_Many_Relation()
60 60
         );
61 61
         $this->_model_chain_to_wp_user = 'Ticket';
62
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
62
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public(
63 63
             'Ticket.TKT_is_default',
64 64
             'Ticket.Datetime.Event'
65 65
         );
66 66
         // account for default tickets in the caps
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
67
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected(
68 68
             'Ticket.TKT_is_default',
69 69
             'Ticket.Datetime.Event'
70 70
         );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
71
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected(
72 72
             'Ticket.TKT_is_default',
73 73
             'Ticket.Datetime.Event'
74 74
         );
75
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
75
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected(
76 76
             'Ticket.TKT_is_default',
77 77
             'Ticket.Datetime.Event'
78 78
         );
Please login to merge, or discard this patch.
core/db_models/EEM_Message_Template.model.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -9,65 +9,65 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Message_Template extends EEM_Base
11 11
 {
12
-    /**
13
-     * @var EEM_Message_Template
14
-     */
15
-    protected static $_instance;
12
+	/**
13
+	 * @var EEM_Message_Template
14
+	 */
15
+	protected static $_instance;
16 16
 
17 17
 
18
-    /**
19
-     * private constructor to prevent direct creation
20
-     *
21
-     * @param string $timezone
22
-     * @throws EE_Error
23
-     */
24
-    protected function __construct(string $timezone = '')
25
-    {
26
-        $this->singular_item = esc_html__('Message Template', 'event_espresso');
27
-        $this->plural_item   = esc_html__('Message Templates', 'event_espresso');
18
+	/**
19
+	 * private constructor to prevent direct creation
20
+	 *
21
+	 * @param string $timezone
22
+	 * @throws EE_Error
23
+	 */
24
+	protected function __construct(string $timezone = '')
25
+	{
26
+		$this->singular_item = esc_html__('Message Template', 'event_espresso');
27
+		$this->plural_item   = esc_html__('Message Templates', 'event_espresso');
28 28
 
29
-        $this->_tables = [
30
-            'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID'),
31
-        ];
32
-        $this->_fields = [
33
-            'Message_Template' => [
34
-                'MTP_ID'             => new EE_Primary_Key_Int_Field(
35
-                    'MTP_ID',
36
-                    esc_html__('Message Template ID', 'event_espresso')),
37
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
38
-                    'GRP_ID',
39
-                    esc_html__('Message Template Group ID', 'event_espresso'),
40
-                    false, 0, 'Message_Template_Group'
41
-                ),
42
-                'MTP_template_field' => new EE_Plain_Text_Field(
43
-                    'MTP_template_field',
44
-                    esc_html__('Field Name for this Template', 'event_espresso'),
45
-                    false,
46
-                    'default'
47
-                ),
48
-                'MTP_context'        => new EE_Plain_Text_Field(
49
-                    'MTP_context',
50
-                    esc_html__('Message Type Context for this field', 'event_espresso'),
51
-                    false,
52
-                    'admin'
53
-                ),
54
-                'MTP_content'        => new EE_Serialized_Text_Field(
55
-                    'MTP_content',
56
-                    esc_html__('The field content for the template', 'event_espresso'),
57
-                    false,
58
-                    ''
59
-                ),
60
-            ],
61
-        ];
29
+		$this->_tables = [
30
+			'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID'),
31
+		];
32
+		$this->_fields = [
33
+			'Message_Template' => [
34
+				'MTP_ID'             => new EE_Primary_Key_Int_Field(
35
+					'MTP_ID',
36
+					esc_html__('Message Template ID', 'event_espresso')),
37
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
38
+					'GRP_ID',
39
+					esc_html__('Message Template Group ID', 'event_espresso'),
40
+					false, 0, 'Message_Template_Group'
41
+				),
42
+				'MTP_template_field' => new EE_Plain_Text_Field(
43
+					'MTP_template_field',
44
+					esc_html__('Field Name for this Template', 'event_espresso'),
45
+					false,
46
+					'default'
47
+				),
48
+				'MTP_context'        => new EE_Plain_Text_Field(
49
+					'MTP_context',
50
+					esc_html__('Message Type Context for this field', 'event_espresso'),
51
+					false,
52
+					'admin'
53
+				),
54
+				'MTP_content'        => new EE_Serialized_Text_Field(
55
+					'MTP_content',
56
+					esc_html__('The field content for the template', 'event_espresso'),
57
+					false,
58
+					''
59
+				),
60
+			],
61
+		];
62 62
 
63
-        $this->_model_chain_to_wp_user = 'Message_Template_Group';
64
-        $this->_model_relations        = ['Message_Template_Group' => new EE_Belongs_To_Relation()];
65
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
66
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global(
67
-                'Message_Template_Group.MTP_is_global'
68
-            );
69
-        }
70
-        $this->_caps_slug = 'messages';
71
-        parent::__construct($timezone);
72
-    }
63
+		$this->_model_chain_to_wp_user = 'Message_Template_Group';
64
+		$this->_model_relations        = ['Message_Template_Group' => new EE_Belongs_To_Relation()];
65
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
66
+			$this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global(
67
+				'Message_Template_Group.MTP_is_global'
68
+			);
69
+		}
70
+		$this->_caps_slug = 'messages';
71
+		parent::__construct($timezone);
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
         $this->_model_chain_to_wp_user = 'Message_Template_Group';
64 64
         $this->_model_relations        = ['Message_Template_Group' => new EE_Belongs_To_Relation()];
65 65
         foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
66
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global(
66
+            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global(
67 67
                 'Message_Template_Group.MTP_is_global'
68 68
             );
69 69
         }
Please login to merge, or discard this patch.
core/EE_Deprecated.core.php 2 patches
Indentation   +1215 added lines, -1215 removed lines patch added patch discarded remove patch
@@ -39,31 +39,31 @@  discard block
 block discarded – undo
39 39
  * @param string $action_or_filter
40 40
  */
41 41
 function deprecated_espresso_action_or_filter_doing_it_wrong(
42
-    $deprecated_filter,
43
-    $replacement,
44
-    $replacement_location,
45
-    $version_deprecated,
46
-    $version_applies,
47
-    $action_or_filter = 'action'
42
+	$deprecated_filter,
43
+	$replacement,
44
+	$replacement_location,
45
+	$version_deprecated,
46
+	$version_applies,
47
+	$action_or_filter = 'action'
48 48
 ) {
49
-    $action_or_filter = $action_or_filter === 'action'
50
-        ? esc_html__('action', 'event_espresso')
51
-        : esc_html__('filter', 'event_espresso');
52
-    EE_Error::doing_it_wrong(
53
-        $deprecated_filter,
54
-        sprintf(
55
-            __(
56
-                'This %1$s is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"',
57
-                'event_espresso'
58
-            ),
59
-            $action_or_filter,
60
-            $replacement,
61
-            $replacement_location,
62
-            '<br />'
63
-        ),
64
-        $version_deprecated,
65
-        $version_applies
66
-    );
49
+	$action_or_filter = $action_or_filter === 'action'
50
+		? esc_html__('action', 'event_espresso')
51
+		: esc_html__('filter', 'event_espresso');
52
+	EE_Error::doing_it_wrong(
53
+		$deprecated_filter,
54
+		sprintf(
55
+			__(
56
+				'This %1$s is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"',
57
+				'event_espresso'
58
+			),
59
+			$action_or_filter,
60
+			$replacement,
61
+			$replacement_location,
62
+			'<br />'
63
+		),
64
+		$version_deprecated,
65
+		$version_applies
66
+	);
67 67
 }
68 68
 
69 69
 /**
@@ -75,90 +75,90 @@  discard block
 block discarded – undo
75 75
  */
76 76
 function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout)
77 77
 {
78
-    // list of old filters
79
-    $deprecated_filters = array(
80
-        'update_registration_details' => true,
81
-        'process_payment'             => true,
82
-        'finalize_registration'       => true,
83
-        'and_proceed_to_payment'      => true,
84
-        'proceed_to'                  => true,
85
-    );
86
-    // loop thru and call doing_it_wrong() or remove any that aren't being used
87
-    foreach ($deprecated_filters as $deprecated_filter => $on) {
88
-        // was this filter called ?
89
-        if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) {
90
-            // only display doing_it_wrong() notice to Event Admins during non-AJAX requests
91
-            if (EE_Registry::instance()->CAP->current_user_can(
92
-                    'ee_read_ee',
93
-                    'hide_doing_it_wrong_for_deprecated_SPCO_filter'
94
-                ) && ! defined('DOING_AJAX')) {
95
-                EE_Error::doing_it_wrong(
96
-                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
97
-                    sprintf(
98
-                        __(
99
-                            'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"',
100
-                            'event_espresso'
101
-                        ),
102
-                        'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
103
-                        '<br />',
104
-                        'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
105
-                        '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
106
-                    ),
107
-                    '4.6.10'
108
-                );
109
-            }
110
-        } else {
111
-            unset($deprecated_filters[ $deprecated_filter ]);
112
-        }
113
-    }
114
-    if (! empty($deprecated_filters)) {
115
-
116
-        if ($checkout->current_step->slug(
117
-            ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
118
-            $submit_button_text = apply_filters(
119
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details',
120
-                $submit_button_text
121
-            );
122
-        } elseif ($checkout->current_step->slug(
123
-            ) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
124
-            $submit_button_text = apply_filters(
125
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment',
126
-                $submit_button_text
127
-            );
128
-        } elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug(
129
-            ) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
130
-            $submit_button_text = apply_filters(
131
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration',
132
-                $submit_button_text
133
-            );
134
-        }
135
-        if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
136
-            if ($checkout->payment_required() && $checkout->next_step->slug(
137
-                ) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
138
-                $submit_button_text .= apply_filters(
139
-                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment',
140
-                    $submit_button_text
141
-                );
142
-            }
143
-            if ($checkout->next_step->slug(
144
-                ) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
145
-                $submit_button_text = apply_filters(
146
-                                          'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to',
147
-                                          $submit_button_text
148
-                                      ) . $checkout->next_step->name();
149
-            }
150
-        }
151
-
152
-    }
153
-    return $submit_button_text;
78
+	// list of old filters
79
+	$deprecated_filters = array(
80
+		'update_registration_details' => true,
81
+		'process_payment'             => true,
82
+		'finalize_registration'       => true,
83
+		'and_proceed_to_payment'      => true,
84
+		'proceed_to'                  => true,
85
+	);
86
+	// loop thru and call doing_it_wrong() or remove any that aren't being used
87
+	foreach ($deprecated_filters as $deprecated_filter => $on) {
88
+		// was this filter called ?
89
+		if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) {
90
+			// only display doing_it_wrong() notice to Event Admins during non-AJAX requests
91
+			if (EE_Registry::instance()->CAP->current_user_can(
92
+					'ee_read_ee',
93
+					'hide_doing_it_wrong_for_deprecated_SPCO_filter'
94
+				) && ! defined('DOING_AJAX')) {
95
+				EE_Error::doing_it_wrong(
96
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
97
+					sprintf(
98
+						__(
99
+							'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"',
100
+							'event_espresso'
101
+						),
102
+						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
103
+						'<br />',
104
+						'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
105
+						'/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
106
+					),
107
+					'4.6.10'
108
+				);
109
+			}
110
+		} else {
111
+			unset($deprecated_filters[ $deprecated_filter ]);
112
+		}
113
+	}
114
+	if (! empty($deprecated_filters)) {
115
+
116
+		if ($checkout->current_step->slug(
117
+			) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
118
+			$submit_button_text = apply_filters(
119
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details',
120
+				$submit_button_text
121
+			);
122
+		} elseif ($checkout->current_step->slug(
123
+			) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
124
+			$submit_button_text = apply_filters(
125
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment',
126
+				$submit_button_text
127
+			);
128
+		} elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug(
129
+			) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
130
+			$submit_button_text = apply_filters(
131
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration',
132
+				$submit_button_text
133
+			);
134
+		}
135
+		if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
136
+			if ($checkout->payment_required() && $checkout->next_step->slug(
137
+				) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
138
+				$submit_button_text .= apply_filters(
139
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment',
140
+					$submit_button_text
141
+				);
142
+			}
143
+			if ($checkout->next_step->slug(
144
+				) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
145
+				$submit_button_text = apply_filters(
146
+										  'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to',
147
+										  $submit_button_text
148
+									  ) . $checkout->next_step->name();
149
+			}
150
+		}
151
+
152
+	}
153
+	return $submit_button_text;
154 154
 
155 155
 }
156 156
 
157 157
 add_filter(
158
-    'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
159
-    'ee_deprecated__registration_checkout__button_text',
160
-    10,
161
-    2
158
+	'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
159
+	'ee_deprecated__registration_checkout__button_text',
160
+	10,
161
+	2
162 162
 );
163 163
 
164 164
 
@@ -170,54 +170,54 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates)
172 172
 {
173
-    $action_ref = null;
174
-    $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction')
175
-        ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
176
-    $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction')
177
-        ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
178
-    if ($action_ref) {
179
-
180
-        EE_Error::doing_it_wrong(
181
-            $action_ref,
182
-            sprintf(
183
-                __(
184
-                    'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"',
185
-                    'event_espresso'
186
-                ),
187
-                '<br />',
188
-                '/core/business/EE_Transaction_Processor.class.php',
189
-                'AHEE__EE_Transaction_Processor__finalize',
190
-                'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
191
-                'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
192
-                'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing'
193
-            ),
194
-            '4.6.0'
195
-        );
196
-        switch ($action_ref) {
197
-            case 'AHEE__EE_Transaction__finalize__new_transaction' :
198
-                do_action(
199
-                    'AHEE__EE_Transaction__finalize__new_transaction',
200
-                    $checkout->transaction,
201
-                    $checkout->admin_request
202
-                );
203
-                break;
204
-            case 'AHEE__EE_Transaction__finalize__all_transaction' :
205
-                do_action(
206
-                    'AHEE__EE_Transaction__finalize__new_transaction',
207
-                    $checkout->transaction,
208
-                    array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates),
209
-                    $checkout->admin_request
210
-                );
211
-                break;
212
-        }
213
-    }
173
+	$action_ref = null;
174
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction')
175
+		? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
176
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction')
177
+		? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
178
+	if ($action_ref) {
179
+
180
+		EE_Error::doing_it_wrong(
181
+			$action_ref,
182
+			sprintf(
183
+				__(
184
+					'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"',
185
+					'event_espresso'
186
+				),
187
+				'<br />',
188
+				'/core/business/EE_Transaction_Processor.class.php',
189
+				'AHEE__EE_Transaction_Processor__finalize',
190
+				'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
191
+				'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
192
+				'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing'
193
+			),
194
+			'4.6.0'
195
+		);
196
+		switch ($action_ref) {
197
+			case 'AHEE__EE_Transaction__finalize__new_transaction' :
198
+				do_action(
199
+					'AHEE__EE_Transaction__finalize__new_transaction',
200
+					$checkout->transaction,
201
+					$checkout->admin_request
202
+				);
203
+				break;
204
+			case 'AHEE__EE_Transaction__finalize__all_transaction' :
205
+				do_action(
206
+					'AHEE__EE_Transaction__finalize__new_transaction',
207
+					$checkout->transaction,
208
+					array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates),
209
+					$checkout->admin_request
210
+				);
211
+				break;
212
+		}
213
+	}
214 214
 }
215 215
 
216 216
 add_action(
217
-    'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
218
-    'ee_deprecated_finalize_transaction',
219
-    10,
220
-    2
217
+	'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
218
+	'ee_deprecated_finalize_transaction',
219
+	10,
220
+	2
221 221
 );
222 222
 /**
223 223
  * ee_deprecated_finalize_registration
@@ -226,35 +226,35 @@  discard block
 block discarded – undo
226 226
  */
227 227
 function ee_deprecated_finalize_registration(EE_Registration $registration)
228 228
 {
229
-    $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg')
230
-        ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null;
231
-    if ($action_ref) {
232
-        EE_Error::doing_it_wrong(
233
-            $action_ref,
234
-            sprintf(
235
-                __(
236
-                    'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"',
237
-                    'event_espresso'
238
-                ),
239
-                '<br />',
240
-                '/core/business/EE_Registration_Processor.class.php',
241
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications'
242
-            ),
243
-            '4.6.0'
244
-        );
245
-        do_action(
246
-            'AHEE__EE_Registration__finalize__update_and_new_reg',
247
-            $registration,
248
-            (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))
249
-        );
250
-    }
229
+	$action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg')
230
+		? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null;
231
+	if ($action_ref) {
232
+		EE_Error::doing_it_wrong(
233
+			$action_ref,
234
+			sprintf(
235
+				__(
236
+					'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"',
237
+					'event_espresso'
238
+				),
239
+				'<br />',
240
+				'/core/business/EE_Registration_Processor.class.php',
241
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications'
242
+			),
243
+			'4.6.0'
244
+		);
245
+		do_action(
246
+			'AHEE__EE_Registration__finalize__update_and_new_reg',
247
+			$registration,
248
+			(is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))
249
+		);
250
+	}
251 251
 }
252 252
 
253 253
 add_action(
254
-    'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
255
-    'ee_deprecated_finalize_registration',
256
-    10,
257
-    1
254
+	'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
255
+	'ee_deprecated_finalize_registration',
256
+	10,
257
+	1
258 258
 );
259 259
 
260 260
 
@@ -264,44 +264,44 @@  discard block
 block discarded – undo
264 264
  */
265 265
 function ee_deprecated_hooks()
266 266
 {
267
-    /**
268
-     * @var          $hooks       array where keys are hook names, and their values are array{
269
-     * @type string  $version     when deprecated
270
-     * @type string  $alternative saying what to use instead
271
-     * @type boolean $still_works whether or not the hook still works
272
-     *        }
273
-     */
274
-    $hooks = array(
275
-        'AHEE__EE_System___do_setup_validations' => array(
276
-            'version'     => '4.6.0',
277
-            'alternative' => __(
278
-                'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)',
279
-                'event_espresso'
280
-            ),
281
-            'still_works' => false,
282
-        ),
283
-    );
284
-    foreach ($hooks as $name => $deprecation_info) {
285
-        if (has_action($name)) {
286
-            EE_Error::doing_it_wrong(
287
-                $name,
288
-                sprintf(
289
-                    __('This filter is deprecated. %1$s%2$s', 'event_espresso'),
290
-                    $deprecation_info['still_works'] ? __(
291
-                        'It *may* work as an attempt to build in backwards compatibility.',
292
-                        'event_espresso'
293
-                    ) : __('It has been completely removed.', 'event_espresso'),
294
-                    isset($deprecation_info['alternative'])
295
-                        ? $deprecation_info['alternative']
296
-                        : __(
297
-                        'Please read the current EE4 documentation further or contact Support.',
298
-                        'event_espresso'
299
-                    )
300
-                ),
301
-                isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
302
-            );
303
-        }
304
-    }
267
+	/**
268
+	 * @var          $hooks       array where keys are hook names, and their values are array{
269
+	 * @type string  $version     when deprecated
270
+	 * @type string  $alternative saying what to use instead
271
+	 * @type boolean $still_works whether or not the hook still works
272
+	 *        }
273
+	 */
274
+	$hooks = array(
275
+		'AHEE__EE_System___do_setup_validations' => array(
276
+			'version'     => '4.6.0',
277
+			'alternative' => __(
278
+				'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)',
279
+				'event_espresso'
280
+			),
281
+			'still_works' => false,
282
+		),
283
+	);
284
+	foreach ($hooks as $name => $deprecation_info) {
285
+		if (has_action($name)) {
286
+			EE_Error::doing_it_wrong(
287
+				$name,
288
+				sprintf(
289
+					__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
290
+					$deprecation_info['still_works'] ? __(
291
+						'It *may* work as an attempt to build in backwards compatibility.',
292
+						'event_espresso'
293
+					) : __('It has been completely removed.', 'event_espresso'),
294
+					isset($deprecation_info['alternative'])
295
+						? $deprecation_info['alternative']
296
+						: __(
297
+						'Please read the current EE4 documentation further or contact Support.',
298
+						'event_espresso'
299
+					)
300
+				),
301
+				isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
302
+			);
303
+		}
304
+	}
305 305
 }
306 306
 
307 307
 add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks');
@@ -316,34 +316,34 @@  discard block
 block discarded – undo
316 316
  */
317 317
 function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
318 318
 {
319
-    $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
320
-              || has_action(
321
-                  'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'
322
-              );
323
-    if ($in_use) {
324
-        $msg = __(
325
-            'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
326
-            . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
327
-            . 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end '
328
-            . 'to add other actions after a form submission has been received.',
329
-            'event_espresso'
330
-        );
331
-        EE_Error::doing_it_wrong(
332
-            __CLASS__ . '::' . __FUNCTION__,
333
-            $msg,
334
-            '4.8.32.rc.000'
335
-        );
336
-        // it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
337
-        if (is_admin() && ! defined('DOING_AJAX')) {
338
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
339
-        }
340
-    }
341
-    return $in_use;
319
+	$in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
320
+			  || has_action(
321
+				  'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'
322
+			  );
323
+	if ($in_use) {
324
+		$msg = __(
325
+			'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
326
+			. 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
327
+			. 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end '
328
+			. 'to add other actions after a form submission has been received.',
329
+			'event_espresso'
330
+		);
331
+		EE_Error::doing_it_wrong(
332
+			__CLASS__ . '::' . __FUNCTION__,
333
+			$msg,
334
+			'4.8.32.rc.000'
335
+		);
336
+		// it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
337
+		if (is_admin() && ! defined('DOING_AJAX')) {
338
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
339
+		}
340
+	}
341
+	return $in_use;
342 342
 }
343 343
 
344 344
 add_action(
345
-    'AHEE__Registrations_Admin_Page___registration_details_metabox__start',
346
-    'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'
345
+	'AHEE__Registrations_Admin_Page___registration_details_metabox__start',
346
+	'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'
347 347
 );
348 348
 
349 349
 /**
@@ -355,77 +355,77 @@  discard block
 block discarded – undo
355 355
  */
356 356
 function ee_deprecated_update_attendee_registration_form_old($admin_page)
357 357
 {
358
-    // check if the old hooks are in use. If not, do the default
359
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
360
-        || ! $admin_page instanceof EE_Admin_Page) {
361
-        return;
362
-    }
363
-    $req_data = $admin_page->get_request_data();
364
-    $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false;
365
-    $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false;
366
-    $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
367
-    if (! $REG_ID || ! $qstns) {
368
-        EE_Error::add_error(
369
-            __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'),
370
-            __FILE__,
371
-            __FUNCTION__,
372
-            __LINE__
373
-        );
374
-    }
375
-    $success = true;
376
-
377
-    // allow others to get in on this awesome fun   :D
378
-    do_action(
379
-        'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save',
380
-        $REG_ID,
381
-        $qstns
382
-    );
383
-    // loop thru questions... FINALLY!!!
384
-
385
-    foreach ($qstns as $QST_ID => $qstn) {
386
-        // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
387
-        if (! is_array($qstn)) {
388
-            $success = EE_Answer::new_instance([ 'QST_ID' => $QST_ID, 'REG_ID' => $REG_ID ]);
389
-            continue;
390
-        }
391
-
392
-
393
-        foreach ($qstn as $ANS_ID => $ANS_value) {
394
-            // get answer
395
-            $query_params = array(
396
-                0 => array(
397
-                    'ANS_ID' => $ANS_ID,
398
-                    'REG_ID' => $REG_ID,
399
-                    'QST_ID' => $QST_ID,
400
-                ),
401
-            );
402
-            $answer = EEM_Answer::instance()->get_one($query_params);
403
-            // this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
404
-            if (! $answer instanceof EE_Answer) {
405
-                $set_values = array(
406
-                    'QST_ID'    => $QST_ID,
407
-                    'REG_ID'    => $REG_ID,
408
-                    'ANS_value' => $qstn,
409
-                );
410
-                $success = EEM_Answer::instance()->insert($set_values);
411
-                continue 2;
412
-            }
413
-
414
-            $answer->set('ANS_value', $ANS_value);
415
-            $success = $answer->save();
416
-        }
417
-    }
418
-    $what = __('Registration Form', 'event_espresso');
419
-    $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
420
-    $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
421
-    exit;
358
+	// check if the old hooks are in use. If not, do the default
359
+	if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
360
+		|| ! $admin_page instanceof EE_Admin_Page) {
361
+		return;
362
+	}
363
+	$req_data = $admin_page->get_request_data();
364
+	$qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false;
365
+	$REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false;
366
+	$qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
367
+	if (! $REG_ID || ! $qstns) {
368
+		EE_Error::add_error(
369
+			__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'),
370
+			__FILE__,
371
+			__FUNCTION__,
372
+			__LINE__
373
+		);
374
+	}
375
+	$success = true;
376
+
377
+	// allow others to get in on this awesome fun   :D
378
+	do_action(
379
+		'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save',
380
+		$REG_ID,
381
+		$qstns
382
+	);
383
+	// loop thru questions... FINALLY!!!
384
+
385
+	foreach ($qstns as $QST_ID => $qstn) {
386
+		// if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
387
+		if (! is_array($qstn)) {
388
+			$success = EE_Answer::new_instance([ 'QST_ID' => $QST_ID, 'REG_ID' => $REG_ID ]);
389
+			continue;
390
+		}
391
+
392
+
393
+		foreach ($qstn as $ANS_ID => $ANS_value) {
394
+			// get answer
395
+			$query_params = array(
396
+				0 => array(
397
+					'ANS_ID' => $ANS_ID,
398
+					'REG_ID' => $REG_ID,
399
+					'QST_ID' => $QST_ID,
400
+				),
401
+			);
402
+			$answer = EEM_Answer::instance()->get_one($query_params);
403
+			// this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
404
+			if (! $answer instanceof EE_Answer) {
405
+				$set_values = array(
406
+					'QST_ID'    => $QST_ID,
407
+					'REG_ID'    => $REG_ID,
408
+					'ANS_value' => $qstn,
409
+				);
410
+				$success = EEM_Answer::instance()->insert($set_values);
411
+				continue 2;
412
+			}
413
+
414
+			$answer->set('ANS_value', $ANS_value);
415
+			$success = $answer->save();
416
+		}
417
+	}
418
+	$what = __('Registration Form', 'event_espresso');
419
+	$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
420
+	$admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
421
+	exit;
422 422
 }
423 423
 
424 424
 add_action(
425
-    'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start',
426
-    'ee_deprecated_update_attendee_registration_form_old',
427
-    10,
428
-    1
425
+	'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start',
426
+	'ee_deprecated_update_attendee_registration_form_old',
427
+	10,
428
+	1
429 429
 );
430 430
 /**
431 431
  * Render the registration admin page's custom questions area in the old fashion
@@ -441,48 +441,48 @@  discard block
 block discarded – undo
441 441
  */
442 442
 function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration)
443 443
 {
444
-    // check if the old hooks are in use. If not, do the default
445
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
446
-        || ! $admin_page instanceof EE_Admin_Page) {
447
-        return $do_default_action;
448
-    }
449
-    add_filter(
450
-        'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
451
-        array($admin_page, 'form_before_question_group'),
452
-        10,
453
-        1
454
-    );
455
-    add_filter(
456
-        'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
457
-        array($admin_page, 'form_after_question_group'),
458
-        10,
459
-        1
460
-    );
461
-    add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
462
-    add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
463
-
464
-    $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options(
465
-        $registration,
466
-        $registration->get('EVT_ID')
467
-    );
468
-
469
-    EE_Registry::instance()->load_helper('Form_Fields');
470
-    $template_args = array(
471
-        'att_questions'             => EEH_Form_Fields::generate_question_groups_html($question_groups),
472
-        'reg_questions_form_action' => 'edit_registration',
473
-        'REG_ID'                    => $registration->ID(),
474
-    );
475
-    $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
476
-    echo EEH_Template::display_template($template_path, $template_args, true);
477
-    // indicate that we should not do the default admin page code
478
-    return false;
444
+	// check if the old hooks are in use. If not, do the default
445
+	if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
446
+		|| ! $admin_page instanceof EE_Admin_Page) {
447
+		return $do_default_action;
448
+	}
449
+	add_filter(
450
+		'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
451
+		array($admin_page, 'form_before_question_group'),
452
+		10,
453
+		1
454
+	);
455
+	add_filter(
456
+		'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
457
+		array($admin_page, 'form_after_question_group'),
458
+		10,
459
+		1
460
+	);
461
+	add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
462
+	add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
463
+
464
+	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options(
465
+		$registration,
466
+		$registration->get('EVT_ID')
467
+	);
468
+
469
+	EE_Registry::instance()->load_helper('Form_Fields');
470
+	$template_args = array(
471
+		'att_questions'             => EEH_Form_Fields::generate_question_groups_html($question_groups),
472
+		'reg_questions_form_action' => 'edit_registration',
473
+		'REG_ID'                    => $registration->ID(),
474
+	);
475
+	$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
476
+	echo EEH_Template::display_template($template_path, $template_args, true);
477
+	// indicate that we should not do the default admin page code
478
+	return false;
479 479
 }
480 480
 
481 481
 add_action(
482
-    'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
483
-    'ee_deprecated_reg_questions_meta_box_old',
484
-    10,
485
-    3
482
+	'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
483
+	'ee_deprecated_reg_questions_meta_box_old',
484
+	10,
485
+	3
486 486
 );
487 487
 
488 488
 
@@ -499,42 +499,42 @@  discard block
 block discarded – undo
499 499
 class EE_Message_Template_Defaults extends EE_Base
500 500
 {
501 501
 
502
-    /**
503
-     * EE_Message_Template_Defaults constructor.
504
-     *
505
-     * @param EE_messages $messages
506
-     * @param             $messenger_name
507
-     * @param             $message_type_name
508
-     * @param int         $GRP_ID
509
-     * @return EE_Messages_Template_Defaults
510
-     */
511
-    public function __construct(
512
-        EE_messages $messages,
513
-        $messenger_name,
514
-        $message_type_name,
515
-        $GRP_ID = 0
516
-    ) {
517
-        EE_Error::doing_it_wrong(
518
-            __FUNCTION__,
519
-            __(
520
-                'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.',
521
-                'event_espresso'
522
-            ),
523
-            '4.9.0'
524
-        );
525
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
526
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
527
-        $messenger = $message_resource_manager->get_messenger($messenger_name);
528
-        $message_type = $message_resource_manager->get_message_type($message_type_name);
529
-        return EE_Registry::instance()->load_lib(
530
-            'Messages_Template_Defaults',
531
-            array(
532
-                $GRP_ID,
533
-                $messenger,
534
-                $message_type,
535
-            )
536
-        );
537
-    }
502
+	/**
503
+	 * EE_Message_Template_Defaults constructor.
504
+	 *
505
+	 * @param EE_messages $messages
506
+	 * @param             $messenger_name
507
+	 * @param             $message_type_name
508
+	 * @param int         $GRP_ID
509
+	 * @return EE_Messages_Template_Defaults
510
+	 */
511
+	public function __construct(
512
+		EE_messages $messages,
513
+		$messenger_name,
514
+		$message_type_name,
515
+		$GRP_ID = 0
516
+	) {
517
+		EE_Error::doing_it_wrong(
518
+			__FUNCTION__,
519
+			__(
520
+				'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.',
521
+				'event_espresso'
522
+			),
523
+			'4.9.0'
524
+		);
525
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
526
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
527
+		$messenger = $message_resource_manager->get_messenger($messenger_name);
528
+		$message_type = $message_resource_manager->get_message_type($message_type_name);
529
+		return EE_Registry::instance()->load_lib(
530
+			'Messages_Template_Defaults',
531
+			array(
532
+				$GRP_ID,
533
+				$messenger,
534
+				$message_type,
535
+			)
536
+		);
537
+	}
538 538
 }
539 539
 
540 540
 
@@ -552,525 +552,525 @@  discard block
 block discarded – undo
552 552
 class EE_messages
553 553
 {
554 554
 
555
-    /** @type EE_messenger[] */
556
-    protected $_active_messengers = array();
557
-
558
-    /** @type array */
559
-    protected $_active_message_types = array();
560
-
561
-    /** @type EE_message_type[] */
562
-    protected $_installed_message_types = array();
563
-
564
-    /** @type EE_messenger */
565
-    protected $_messenger;
566
-
567
-    /** @type EE_message_type */
568
-    protected $_message_type;
569
-
570
-    /** @type array */
571
-    protected $_contexts = array();
572
-
573
-    /** @type EE_Message_Resource_Manager $_message_resource_manager */
574
-    protected $_message_resource_manager;
575
-
576
-
577
-    /**
578
-     * EE_messages constructor.
579
-     *
580
-     * @deprecated 4.9.0
581
-     */
582
-    public function __construct()
583
-    {
584
-    }
585
-
586
-
587
-    /**
588
-     * @param string $method
589
-     */
590
-    public function _class_is_deprecated($method)
591
-    {
592
-        EE_Error::doing_it_wrong(
593
-            'EE_messages::' . $method,
594
-            __('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
595
-            '4.9.0',
596
-            '4.10.0.p'
597
-        );
598
-        // Please use EE_Message_Resource_Manager instead
599
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
600
-    }
601
-
602
-
603
-    /**
604
-     * @deprecated 4.9.0
605
-     * @param string $messenger_name
606
-     * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
607
-     */
608
-    public function ensure_messenger_is_active($messenger_name)
609
-    {
610
-        // EE_messages has been deprecated
611
-        $this->_class_is_deprecated(__FUNCTION__);
612
-        return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
613
-    }
614
-
615
-
616
-    /**
617
-     * @deprecated 4.9.0
618
-     * @param string $message_type message type name
619
-     * @param        $messenger
620
-     * @return bool true if it got activated (or was active) and false if not.
621
-     * @throws \EE_Error
622
-     */
623
-    public function ensure_message_type_is_active($message_type, $messenger)
624
-    {
625
-        // EE_messages has been deprecated
626
-        $this->_class_is_deprecated(__FUNCTION__);
627
-        return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
628
-    }
629
-
630
-
631
-    /**
632
-     * @deprecated 4.9.0
633
-     * @param string $messenger_name
634
-     * @param array  $mts_to_activate             (optional) An array of message types to activate with this messenger.
635
-     *                                             If included we do NOT setup the default message types (assuming they
636
-     *                                             are already setup.)
637
-     * @return boolean an array of generated templates or false if nothing generated/activated.
638
-     */
639
-    public function activate_messenger($messenger_name, $mts_to_activate = array())
640
-    {
641
-        // EE_messages has been deprecated
642
-        $this->_class_is_deprecated(__FUNCTION__);
643
-        return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
644
-    }
645
-
646
-
647
-    /**
648
-     * @deprecated 4.9.0
649
-     * @param EE_messenger    $messenger    messenger used in trigger
650
-     * @param EE_message_type $message_type message type used in trigger
651
-     *
652
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
653
-     */
654
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
655
-    {
656
-        // EE_messages has been deprecated
657
-        $this->_class_is_deprecated(__FUNCTION__);
658
-        return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
659
-    }
660
-
661
-
662
-    /**
663
-     * @deprecated 4.9.0
664
-     * @param string $messenger
665
-     * @return EE_messenger | null
666
-     */
667
-    public function get_messenger_if_active($messenger)
668
-    {
669
-        // EE_messages has been deprecated
670
-        $this->_class_is_deprecated(__FUNCTION__);
671
-        return $this->_message_resource_manager->get_active_messenger($messenger);
672
-    }
673
-
674
-
675
-    /**
676
-     * @deprecated 4.9.0
677
-     * @param EE_Message $message
678
-     * @return array  An array with 'messenger' and 'message_type' as the index and the corresponding valid object if
679
-     *                  available.
680
-     *                  Eg. Valid Messenger and Message Type:
681
-     *                  array(
682
-     *                  'messenger' => new EE_Email_messenger(),
683
-     *                  'message_type' => new EE_Registration_Approved_message_type()
684
-     *                  )
685
-     *                  Valid Messenger and Invalid Message Type:
686
-     *                  array(
687
-     *                  'messenger' => new EE_Email_messenger(),
688
-     *                  'message_type' => null
689
-     *                  )
690
-     */
691
-    public function validate_for_use(EE_Message $message)
692
-    {
693
-        // EE_messages has been deprecated
694
-        $this->_class_is_deprecated(__FUNCTION__);
695
-        return array(
696
-            'messenger'    => $message->messenger_object(),
697
-            'message_type' => $message->message_type_object(),
698
-        );
699
-    }
700
-
701
-
702
-    /**
703
-     * @deprecated 4.9.0
704
-     * @param  string $type                 What type of message are we sending (corresponds to message types)
705
-     * @param  mixed  $vars                 Data being sent for parsing in the message
706
-     * @param  string $sending_messenger    if included then we ONLY use the specified messenger for delivery.
707
-     *                                      Otherwise we cycle through all active messengers.
708
-     * @param string  $generating_messenger if included then this messenger is used for generating the message
709
-     *                                      templates (but not for sending).
710
-     * @param string  $context              If included then only a message type for a specific context will be
711
-     *                                      generated.
712
-     * @param bool    $send                 Default TRUE.  If false, then this will just return the generated
713
-     *                                      EE_messages objects which might be used by the trigger to setup a batch
714
-     *                                      message (typically html messenger uses it).
715
-     * @return bool
716
-     */
717
-    public function send_message(
718
-        $type,
719
-        $vars,
720
-        $sending_messenger = '',
721
-        $generating_messenger = '',
722
-        $context = '',
723
-        $send = true
724
-    ) {
725
-        // EE_messages has been deprecated
726
-        $this->_class_is_deprecated(__FUNCTION__);
727
-        /** @type EE_Messages_Processor $processor */
728
-        $processor = EE_Registry::instance()->load_lib('Messages_Processor');
729
-        $error = false;
730
-        // try to intelligently determine what method we'll call based on the incoming data.
731
-        // if generating and sending are different then generate and send immediately.
732
-        if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
733
-            // in the legacy system, when generating and sending were different, that means all the
734
-            // vars are already in the request object.  So let's just use that.
735
-            try {
736
-                /** @type EE_Message_To_Generate_From_Request $mtg */
737
-                $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
738
-                $processor->generate_and_send_now($mtg);
739
-            } catch (EE_Error $e) {
740
-                $error_msg = __(
741
-                    'Please note that a system message failed to send due to a technical issue.',
742
-                    'event_espresso'
743
-                );
744
-                // add specific message for developers if WP_DEBUG in on
745
-                $error_msg .= '||' . $e->getMessage();
746
-                EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
747
-                $error = true;
748
-            }
749
-        } else {
750
-            $processor->generate_for_all_active_messengers($type, $vars, $send);
751
-            // let's find out if there were any errors and how many successfully were queued.
752
-            $count_errors = $processor->get_queue()->count_STS_in_queue(
753
-                array(EEM_Message::status_failed, EEM_Message::status_debug_only)
754
-            );
755
-            $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
756
-            $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
757
-            $count_errors = $count_errors + $count_retry;
758
-            if ($count_errors > 0) {
759
-                $error = true;
760
-                if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
761
-                    $message = sprintf(
762
-                        __(
763
-                            'There were %d errors and %d messages successfully queued for generation and sending',
764
-                            'event_espresso'
765
-                        ),
766
-                        $count_errors,
767
-                        $count_queued
768
-                    );
769
-                } elseif ($count_errors > 1 && $count_queued === 1) {
770
-                    $message = sprintf(
771
-                        __(
772
-                            'There were %d errors and %d message successfully queued for generation.',
773
-                            'event_espresso'
774
-                        ),
775
-                        $count_errors,
776
-                        $count_queued
777
-                    );
778
-                } elseif ($count_errors === 1 && $count_queued > 1) {
779
-                    $message = sprintf(
780
-                        __(
781
-                            'There was %d error and %d messages successfully queued for generation.',
782
-                            'event_espresso'
783
-                        ),
784
-                        $count_errors,
785
-                        $count_queued
786
-                    );
787
-                } else {
788
-                    $message = sprintf(
789
-                        __(
790
-                            'There was %d message that failed to be queued for generation.',
791
-                            'event_espresso'
792
-                        ),
793
-                        $count_errors
794
-                    );
795
-                }
796
-                EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
797
-            } else {
798
-                if ($count_queued === 1) {
799
-                    $message = sprintf(
800
-                        __(
801
-                            '%d message successfully queued for generation.',
802
-                            'event_espresso'
803
-                        ),
804
-                        $count_queued
805
-                    );
806
-                } else {
807
-                    $message = sprintf(
808
-                        __(
809
-                            '%d messages were successfully queued for generation.',
810
-                            'event_espresso'
811
-                        ),
812
-                        $count_queued
813
-                    );
814
-                }
815
-                EE_Error::add_success($message);
816
-            }
817
-        }
818
-        // if no error then return the generated message(s).
819
-        if (! $error && ! $send) {
820
-            $generated_queue = $processor->generate_queue(false);
821
-            // get message and return.
822
-            $generated_queue->get_message_repository()->rewind();
823
-            $messages = array();
824
-            while ($generated_queue->get_message_repository()->valid()) {
825
-                $message = $generated_queue->get_message_repository()->current();
826
-                if ($message instanceof EE_Message) {
827
-                    // set properties that might be expected by add-ons (backward compat)
828
-                    $message->content = $message->content();
829
-                    $message->template_pack = $message->get_template_pack();
830
-                    $message->template_variation = $message->get_template_pack_variation();
831
-                    $messages[] = $message;
832
-                }
833
-                $generated_queue->get_message_repository()->next();
834
-            }
835
-            return $messages;
836
-        }
837
-        return $error ? false
838
-            : true; // yeah backwards eh?  Really what we're returning is if there is a total success for all the messages or not.  We'll modify this once we get message recording in place.
839
-    }
840
-
841
-
842
-    /**
843
-     * @deprecated 4.9.0
844
-     * @param  string $type      This should correspond with a valid message type
845
-     * @param  string $context   This should correspond with a valid context for the message type
846
-     * @param  string $messenger This should correspond with a valid messenger.
847
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
848
-     *                           preview
849
-     * @return string          The body of the message.
850
-     */
851
-    public function preview_message($type, $context, $messenger, $send = false)
852
-    {
853
-        // EE_messages has been deprecated
854
-        $this->_class_is_deprecated(__FUNCTION__);
855
-        return EED_Messages::preview_message($type, $context, $messenger, $send);
856
-    }
857
-
858
-
859
-    /**
860
-     * @since      4.5.0
861
-     * @deprecated 4.9.0   Moved to EED_Messages Module
862
-     * @param string   $messenger    a string matching a valid active messenger in the system
863
-     * @param string   $message_type Although it seems contrary to the name of the method, a message type name is still
864
-     *                               required to send along the message type to the messenger because this is used for
865
-     *                               determining what specific variations might be loaded for the generated message.
866
-     * @param stdClass $message      a stdClass object in the format expected by the messenger.
867
-     *
868
-     * @return bool          success or fail.
869
-     */
870
-    public function send_message_with_messenger_only($messenger, $message_type, $message)
871
-    {
872
-        // EE_messages has been deprecated
873
-        $this->_class_is_deprecated(__FUNCTION__);
874
-        // setup for sending to new method.
875
-        /** @type EE_Messages_Queue $queue */
876
-        $queue = EE_Registry::instance()->load_lib('Messages_Queue');
877
-        // make sure we have a proper message object
878
-        if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
879
-            $msg = EE_Message_Factory::create(
880
-                array(
881
-                    'MSG_messenger'    => $messenger,
882
-                    'MSG_message_type' => $message_type,
883
-                    'MSG_content'      => $message->content,
884
-                    'MSG_subject'      => $message->subject,
885
-                )
886
-            );
887
-        } else {
888
-            $msg = $message;
889
-        }
890
-        if (! $msg instanceof EE_Message) {
891
-            return false;
892
-        }
893
-        // make sure any content in a content property (if not empty) is set on the MSG_content.
894
-        if (! empty($msg->content)) {
895
-            $msg->set('MSG_content', $msg->content);
896
-        }
897
-        $queue->add($msg);
898
-        return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
899
-    }
900
-
901
-
902
-    /**
903
-     * @deprecated 4.9.0
904
-     * @param         $messenger
905
-     * @param  string $message_type message type that the templates are being created for
906
-     * @param int     $GRP_ID
907
-     * @param bool    $is_global
908
-     * @return array|object if creation is successful then we return an array of info, otherwise an error_object is
909
-     *                      returned.
910
-     * @throws \EE_Error
911
-     */
912
-    public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false)
913
-    {
914
-        // EE_messages has been deprecated
915
-        $this->_class_is_deprecated(__FUNCTION__);
916
-        EE_Registry::instance()->load_helper('MSG_Template');
917
-        return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
918
-    }
919
-
920
-
921
-    /**
922
-     * @deprecated 4.9.0
923
-     * @param  string $messenger_name    name of EE_messenger
924
-     * @param  string $message_type_name name of EE_message_type
925
-     * @return array
926
-     */
927
-    public function get_fields($messenger_name, $message_type_name)
928
-    {
929
-        // EE_messages has been deprecated
930
-        $this->_class_is_deprecated(__FUNCTION__);
931
-        EE_Registry::instance()->load_helper('MSG_Template');
932
-        return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
933
-    }
934
-
935
-
936
-    /**
937
-     * @deprecated 4.9.0
938
-     * @access     public
939
-     * @param string $type                we can indicate just returning installed message types
940
-     *                                    or messengers (or both) via this parameter.
941
-     * @param bool   $skip_cache          if true then we skip the cache and retrieve via files.
942
-     * @return array                    multidimensional array of messenger and message_type objects
943
-     *                                    (messengers index, and message_type index);
944
-     */
945
-    public function get_installed($type = 'all', $skip_cache = false)
946
-    {
947
-        // EE_messages has been deprecated
948
-        $this->_class_is_deprecated(__FUNCTION__);
949
-        if ($skip_cache) {
950
-            $this->_message_resource_manager->reset_active_messengers_and_message_types();
951
-        }
952
-        switch ($type) {
953
-            case 'messengers' :
954
-                return array(
955
-                    'messenger' => $this->_message_resource_manager->installed_messengers(),
956
-                );
957
-                break;
958
-            case 'message_types' :
959
-                return array(
960
-                    'message_type' => $this->_message_resource_manager->installed_message_types(),
961
-                );
962
-                break;
963
-            case 'all' :
964
-            default :
965
-                return array(
966
-                    'messenger'    => $this->_message_resource_manager->installed_messengers(),
967
-                    'message_type' => $this->_message_resource_manager->installed_message_types(),
968
-                );
969
-                break;
970
-        }
971
-    }
972
-
973
-
974
-    /**
975
-     * @deprecated 4.9.0
976
-     * @return \EE_messenger[]
977
-     */
978
-    public function get_active_messengers()
979
-    {
980
-        // EE_messages has been deprecated
981
-        $this->_class_is_deprecated(__FUNCTION__);
982
-        return $this->_message_resource_manager->active_messengers();
983
-    }
984
-
985
-
986
-    /**
987
-     * @deprecated 4.9.0
988
-     * @return array array of message_type references (string)
989
-     */
990
-    public function get_active_message_types()
991
-    {
992
-        // EE_messages has been deprecated
993
-        $this->_class_is_deprecated(__FUNCTION__);
994
-        return $this->_message_resource_manager->list_of_active_message_types();
995
-    }
996
-
997
-
998
-    /**
999
-     * @deprecated 4.9.0
1000
-     * @return EE_message_type[]
1001
-     */
1002
-    public function get_active_message_type_objects()
1003
-    {
1004
-        // EE_messages has been deprecated
1005
-        $this->_class_is_deprecated(__FUNCTION__);
1006
-        return $this->_message_resource_manager->get_active_message_type_objects();
1007
-    }
1008
-
1009
-
1010
-    /**
1011
-     * @deprecated 4.9.0
1012
-     * @since      4.5.0
1013
-     * @param string $messenger The messenger being checked
1014
-     * @return EE_message_type[]    (or empty array if none present)
1015
-     */
1016
-    public function get_active_message_types_per_messenger($messenger)
1017
-    {
1018
-        // EE_messages has been deprecated
1019
-        $this->_class_is_deprecated(__FUNCTION__);
1020
-        return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * @deprecated 4.9.0
1026
-     * @param string $messenger    The string should correspond to the messenger (message types are
1027
-     * @param string $message_type The string should correspond to a message type.
1028
-     * @return EE_message_type|null
1029
-     */
1030
-    public function get_active_message_type($messenger, $message_type)
1031
-    {
1032
-        // EE_messages has been deprecated
1033
-        $this->_class_is_deprecated(__FUNCTION__);
1034
-        return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * @deprecated 4.9.0
1040
-     * @return array|\EE_message_type[]
1041
-     */
1042
-    public function get_installed_message_types()
1043
-    {
1044
-        // EE_messages has been deprecated
1045
-        $this->_class_is_deprecated(__FUNCTION__);
1046
-        return $this->_message_resource_manager->installed_message_types();
1047
-    }
1048
-
1049
-
1050
-    /**
1051
-     * @deprecated 4.9.0
1052
-     * @return array
1053
-     */
1054
-    public function get_installed_messengers()
1055
-    {
1056
-        // EE_messages has been deprecated
1057
-        $this->_class_is_deprecated(__FUNCTION__);
1058
-        return $this->_message_resource_manager->installed_messengers();
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * @deprecated 4.9.0
1064
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by
1065
-     *                           message type.
1066
-     * @return array
1067
-     */
1068
-    public function get_all_contexts($slugs_only = true)
1069
-    {
1070
-        // EE_messages has been deprecated
1071
-        $this->_class_is_deprecated(__FUNCTION__);
1072
-        return $this->_message_resource_manager->get_all_contexts($slugs_only);
1073
-    }
555
+	/** @type EE_messenger[] */
556
+	protected $_active_messengers = array();
557
+
558
+	/** @type array */
559
+	protected $_active_message_types = array();
560
+
561
+	/** @type EE_message_type[] */
562
+	protected $_installed_message_types = array();
563
+
564
+	/** @type EE_messenger */
565
+	protected $_messenger;
566
+
567
+	/** @type EE_message_type */
568
+	protected $_message_type;
569
+
570
+	/** @type array */
571
+	protected $_contexts = array();
572
+
573
+	/** @type EE_Message_Resource_Manager $_message_resource_manager */
574
+	protected $_message_resource_manager;
575
+
576
+
577
+	/**
578
+	 * EE_messages constructor.
579
+	 *
580
+	 * @deprecated 4.9.0
581
+	 */
582
+	public function __construct()
583
+	{
584
+	}
585
+
586
+
587
+	/**
588
+	 * @param string $method
589
+	 */
590
+	public function _class_is_deprecated($method)
591
+	{
592
+		EE_Error::doing_it_wrong(
593
+			'EE_messages::' . $method,
594
+			__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
595
+			'4.9.0',
596
+			'4.10.0.p'
597
+		);
598
+		// Please use EE_Message_Resource_Manager instead
599
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
600
+	}
601
+
602
+
603
+	/**
604
+	 * @deprecated 4.9.0
605
+	 * @param string $messenger_name
606
+	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
607
+	 */
608
+	public function ensure_messenger_is_active($messenger_name)
609
+	{
610
+		// EE_messages has been deprecated
611
+		$this->_class_is_deprecated(__FUNCTION__);
612
+		return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
613
+	}
614
+
615
+
616
+	/**
617
+	 * @deprecated 4.9.0
618
+	 * @param string $message_type message type name
619
+	 * @param        $messenger
620
+	 * @return bool true if it got activated (or was active) and false if not.
621
+	 * @throws \EE_Error
622
+	 */
623
+	public function ensure_message_type_is_active($message_type, $messenger)
624
+	{
625
+		// EE_messages has been deprecated
626
+		$this->_class_is_deprecated(__FUNCTION__);
627
+		return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
628
+	}
629
+
630
+
631
+	/**
632
+	 * @deprecated 4.9.0
633
+	 * @param string $messenger_name
634
+	 * @param array  $mts_to_activate             (optional) An array of message types to activate with this messenger.
635
+	 *                                             If included we do NOT setup the default message types (assuming they
636
+	 *                                             are already setup.)
637
+	 * @return boolean an array of generated templates or false if nothing generated/activated.
638
+	 */
639
+	public function activate_messenger($messenger_name, $mts_to_activate = array())
640
+	{
641
+		// EE_messages has been deprecated
642
+		$this->_class_is_deprecated(__FUNCTION__);
643
+		return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
644
+	}
645
+
646
+
647
+	/**
648
+	 * @deprecated 4.9.0
649
+	 * @param EE_messenger    $messenger    messenger used in trigger
650
+	 * @param EE_message_type $message_type message type used in trigger
651
+	 *
652
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
653
+	 */
654
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
655
+	{
656
+		// EE_messages has been deprecated
657
+		$this->_class_is_deprecated(__FUNCTION__);
658
+		return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
659
+	}
660
+
661
+
662
+	/**
663
+	 * @deprecated 4.9.0
664
+	 * @param string $messenger
665
+	 * @return EE_messenger | null
666
+	 */
667
+	public function get_messenger_if_active($messenger)
668
+	{
669
+		// EE_messages has been deprecated
670
+		$this->_class_is_deprecated(__FUNCTION__);
671
+		return $this->_message_resource_manager->get_active_messenger($messenger);
672
+	}
673
+
674
+
675
+	/**
676
+	 * @deprecated 4.9.0
677
+	 * @param EE_Message $message
678
+	 * @return array  An array with 'messenger' and 'message_type' as the index and the corresponding valid object if
679
+	 *                  available.
680
+	 *                  Eg. Valid Messenger and Message Type:
681
+	 *                  array(
682
+	 *                  'messenger' => new EE_Email_messenger(),
683
+	 *                  'message_type' => new EE_Registration_Approved_message_type()
684
+	 *                  )
685
+	 *                  Valid Messenger and Invalid Message Type:
686
+	 *                  array(
687
+	 *                  'messenger' => new EE_Email_messenger(),
688
+	 *                  'message_type' => null
689
+	 *                  )
690
+	 */
691
+	public function validate_for_use(EE_Message $message)
692
+	{
693
+		// EE_messages has been deprecated
694
+		$this->_class_is_deprecated(__FUNCTION__);
695
+		return array(
696
+			'messenger'    => $message->messenger_object(),
697
+			'message_type' => $message->message_type_object(),
698
+		);
699
+	}
700
+
701
+
702
+	/**
703
+	 * @deprecated 4.9.0
704
+	 * @param  string $type                 What type of message are we sending (corresponds to message types)
705
+	 * @param  mixed  $vars                 Data being sent for parsing in the message
706
+	 * @param  string $sending_messenger    if included then we ONLY use the specified messenger for delivery.
707
+	 *                                      Otherwise we cycle through all active messengers.
708
+	 * @param string  $generating_messenger if included then this messenger is used for generating the message
709
+	 *                                      templates (but not for sending).
710
+	 * @param string  $context              If included then only a message type for a specific context will be
711
+	 *                                      generated.
712
+	 * @param bool    $send                 Default TRUE.  If false, then this will just return the generated
713
+	 *                                      EE_messages objects which might be used by the trigger to setup a batch
714
+	 *                                      message (typically html messenger uses it).
715
+	 * @return bool
716
+	 */
717
+	public function send_message(
718
+		$type,
719
+		$vars,
720
+		$sending_messenger = '',
721
+		$generating_messenger = '',
722
+		$context = '',
723
+		$send = true
724
+	) {
725
+		// EE_messages has been deprecated
726
+		$this->_class_is_deprecated(__FUNCTION__);
727
+		/** @type EE_Messages_Processor $processor */
728
+		$processor = EE_Registry::instance()->load_lib('Messages_Processor');
729
+		$error = false;
730
+		// try to intelligently determine what method we'll call based on the incoming data.
731
+		// if generating and sending are different then generate and send immediately.
732
+		if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
733
+			// in the legacy system, when generating and sending were different, that means all the
734
+			// vars are already in the request object.  So let's just use that.
735
+			try {
736
+				/** @type EE_Message_To_Generate_From_Request $mtg */
737
+				$mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
738
+				$processor->generate_and_send_now($mtg);
739
+			} catch (EE_Error $e) {
740
+				$error_msg = __(
741
+					'Please note that a system message failed to send due to a technical issue.',
742
+					'event_espresso'
743
+				);
744
+				// add specific message for developers if WP_DEBUG in on
745
+				$error_msg .= '||' . $e->getMessage();
746
+				EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
747
+				$error = true;
748
+			}
749
+		} else {
750
+			$processor->generate_for_all_active_messengers($type, $vars, $send);
751
+			// let's find out if there were any errors and how many successfully were queued.
752
+			$count_errors = $processor->get_queue()->count_STS_in_queue(
753
+				array(EEM_Message::status_failed, EEM_Message::status_debug_only)
754
+			);
755
+			$count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
756
+			$count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
757
+			$count_errors = $count_errors + $count_retry;
758
+			if ($count_errors > 0) {
759
+				$error = true;
760
+				if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
761
+					$message = sprintf(
762
+						__(
763
+							'There were %d errors and %d messages successfully queued for generation and sending',
764
+							'event_espresso'
765
+						),
766
+						$count_errors,
767
+						$count_queued
768
+					);
769
+				} elseif ($count_errors > 1 && $count_queued === 1) {
770
+					$message = sprintf(
771
+						__(
772
+							'There were %d errors and %d message successfully queued for generation.',
773
+							'event_espresso'
774
+						),
775
+						$count_errors,
776
+						$count_queued
777
+					);
778
+				} elseif ($count_errors === 1 && $count_queued > 1) {
779
+					$message = sprintf(
780
+						__(
781
+							'There was %d error and %d messages successfully queued for generation.',
782
+							'event_espresso'
783
+						),
784
+						$count_errors,
785
+						$count_queued
786
+					);
787
+				} else {
788
+					$message = sprintf(
789
+						__(
790
+							'There was %d message that failed to be queued for generation.',
791
+							'event_espresso'
792
+						),
793
+						$count_errors
794
+					);
795
+				}
796
+				EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
797
+			} else {
798
+				if ($count_queued === 1) {
799
+					$message = sprintf(
800
+						__(
801
+							'%d message successfully queued for generation.',
802
+							'event_espresso'
803
+						),
804
+						$count_queued
805
+					);
806
+				} else {
807
+					$message = sprintf(
808
+						__(
809
+							'%d messages were successfully queued for generation.',
810
+							'event_espresso'
811
+						),
812
+						$count_queued
813
+					);
814
+				}
815
+				EE_Error::add_success($message);
816
+			}
817
+		}
818
+		// if no error then return the generated message(s).
819
+		if (! $error && ! $send) {
820
+			$generated_queue = $processor->generate_queue(false);
821
+			// get message and return.
822
+			$generated_queue->get_message_repository()->rewind();
823
+			$messages = array();
824
+			while ($generated_queue->get_message_repository()->valid()) {
825
+				$message = $generated_queue->get_message_repository()->current();
826
+				if ($message instanceof EE_Message) {
827
+					// set properties that might be expected by add-ons (backward compat)
828
+					$message->content = $message->content();
829
+					$message->template_pack = $message->get_template_pack();
830
+					$message->template_variation = $message->get_template_pack_variation();
831
+					$messages[] = $message;
832
+				}
833
+				$generated_queue->get_message_repository()->next();
834
+			}
835
+			return $messages;
836
+		}
837
+		return $error ? false
838
+			: true; // yeah backwards eh?  Really what we're returning is if there is a total success for all the messages or not.  We'll modify this once we get message recording in place.
839
+	}
840
+
841
+
842
+	/**
843
+	 * @deprecated 4.9.0
844
+	 * @param  string $type      This should correspond with a valid message type
845
+	 * @param  string $context   This should correspond with a valid context for the message type
846
+	 * @param  string $messenger This should correspond with a valid messenger.
847
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
848
+	 *                           preview
849
+	 * @return string          The body of the message.
850
+	 */
851
+	public function preview_message($type, $context, $messenger, $send = false)
852
+	{
853
+		// EE_messages has been deprecated
854
+		$this->_class_is_deprecated(__FUNCTION__);
855
+		return EED_Messages::preview_message($type, $context, $messenger, $send);
856
+	}
857
+
858
+
859
+	/**
860
+	 * @since      4.5.0
861
+	 * @deprecated 4.9.0   Moved to EED_Messages Module
862
+	 * @param string   $messenger    a string matching a valid active messenger in the system
863
+	 * @param string   $message_type Although it seems contrary to the name of the method, a message type name is still
864
+	 *                               required to send along the message type to the messenger because this is used for
865
+	 *                               determining what specific variations might be loaded for the generated message.
866
+	 * @param stdClass $message      a stdClass object in the format expected by the messenger.
867
+	 *
868
+	 * @return bool          success or fail.
869
+	 */
870
+	public function send_message_with_messenger_only($messenger, $message_type, $message)
871
+	{
872
+		// EE_messages has been deprecated
873
+		$this->_class_is_deprecated(__FUNCTION__);
874
+		// setup for sending to new method.
875
+		/** @type EE_Messages_Queue $queue */
876
+		$queue = EE_Registry::instance()->load_lib('Messages_Queue');
877
+		// make sure we have a proper message object
878
+		if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
879
+			$msg = EE_Message_Factory::create(
880
+				array(
881
+					'MSG_messenger'    => $messenger,
882
+					'MSG_message_type' => $message_type,
883
+					'MSG_content'      => $message->content,
884
+					'MSG_subject'      => $message->subject,
885
+				)
886
+			);
887
+		} else {
888
+			$msg = $message;
889
+		}
890
+		if (! $msg instanceof EE_Message) {
891
+			return false;
892
+		}
893
+		// make sure any content in a content property (if not empty) is set on the MSG_content.
894
+		if (! empty($msg->content)) {
895
+			$msg->set('MSG_content', $msg->content);
896
+		}
897
+		$queue->add($msg);
898
+		return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
899
+	}
900
+
901
+
902
+	/**
903
+	 * @deprecated 4.9.0
904
+	 * @param         $messenger
905
+	 * @param  string $message_type message type that the templates are being created for
906
+	 * @param int     $GRP_ID
907
+	 * @param bool    $is_global
908
+	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is
909
+	 *                      returned.
910
+	 * @throws \EE_Error
911
+	 */
912
+	public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false)
913
+	{
914
+		// EE_messages has been deprecated
915
+		$this->_class_is_deprecated(__FUNCTION__);
916
+		EE_Registry::instance()->load_helper('MSG_Template');
917
+		return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
918
+	}
919
+
920
+
921
+	/**
922
+	 * @deprecated 4.9.0
923
+	 * @param  string $messenger_name    name of EE_messenger
924
+	 * @param  string $message_type_name name of EE_message_type
925
+	 * @return array
926
+	 */
927
+	public function get_fields($messenger_name, $message_type_name)
928
+	{
929
+		// EE_messages has been deprecated
930
+		$this->_class_is_deprecated(__FUNCTION__);
931
+		EE_Registry::instance()->load_helper('MSG_Template');
932
+		return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
933
+	}
934
+
935
+
936
+	/**
937
+	 * @deprecated 4.9.0
938
+	 * @access     public
939
+	 * @param string $type                we can indicate just returning installed message types
940
+	 *                                    or messengers (or both) via this parameter.
941
+	 * @param bool   $skip_cache          if true then we skip the cache and retrieve via files.
942
+	 * @return array                    multidimensional array of messenger and message_type objects
943
+	 *                                    (messengers index, and message_type index);
944
+	 */
945
+	public function get_installed($type = 'all', $skip_cache = false)
946
+	{
947
+		// EE_messages has been deprecated
948
+		$this->_class_is_deprecated(__FUNCTION__);
949
+		if ($skip_cache) {
950
+			$this->_message_resource_manager->reset_active_messengers_and_message_types();
951
+		}
952
+		switch ($type) {
953
+			case 'messengers' :
954
+				return array(
955
+					'messenger' => $this->_message_resource_manager->installed_messengers(),
956
+				);
957
+				break;
958
+			case 'message_types' :
959
+				return array(
960
+					'message_type' => $this->_message_resource_manager->installed_message_types(),
961
+				);
962
+				break;
963
+			case 'all' :
964
+			default :
965
+				return array(
966
+					'messenger'    => $this->_message_resource_manager->installed_messengers(),
967
+					'message_type' => $this->_message_resource_manager->installed_message_types(),
968
+				);
969
+				break;
970
+		}
971
+	}
972
+
973
+
974
+	/**
975
+	 * @deprecated 4.9.0
976
+	 * @return \EE_messenger[]
977
+	 */
978
+	public function get_active_messengers()
979
+	{
980
+		// EE_messages has been deprecated
981
+		$this->_class_is_deprecated(__FUNCTION__);
982
+		return $this->_message_resource_manager->active_messengers();
983
+	}
984
+
985
+
986
+	/**
987
+	 * @deprecated 4.9.0
988
+	 * @return array array of message_type references (string)
989
+	 */
990
+	public function get_active_message_types()
991
+	{
992
+		// EE_messages has been deprecated
993
+		$this->_class_is_deprecated(__FUNCTION__);
994
+		return $this->_message_resource_manager->list_of_active_message_types();
995
+	}
996
+
997
+
998
+	/**
999
+	 * @deprecated 4.9.0
1000
+	 * @return EE_message_type[]
1001
+	 */
1002
+	public function get_active_message_type_objects()
1003
+	{
1004
+		// EE_messages has been deprecated
1005
+		$this->_class_is_deprecated(__FUNCTION__);
1006
+		return $this->_message_resource_manager->get_active_message_type_objects();
1007
+	}
1008
+
1009
+
1010
+	/**
1011
+	 * @deprecated 4.9.0
1012
+	 * @since      4.5.0
1013
+	 * @param string $messenger The messenger being checked
1014
+	 * @return EE_message_type[]    (or empty array if none present)
1015
+	 */
1016
+	public function get_active_message_types_per_messenger($messenger)
1017
+	{
1018
+		// EE_messages has been deprecated
1019
+		$this->_class_is_deprecated(__FUNCTION__);
1020
+		return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * @deprecated 4.9.0
1026
+	 * @param string $messenger    The string should correspond to the messenger (message types are
1027
+	 * @param string $message_type The string should correspond to a message type.
1028
+	 * @return EE_message_type|null
1029
+	 */
1030
+	public function get_active_message_type($messenger, $message_type)
1031
+	{
1032
+		// EE_messages has been deprecated
1033
+		$this->_class_is_deprecated(__FUNCTION__);
1034
+		return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * @deprecated 4.9.0
1040
+	 * @return array|\EE_message_type[]
1041
+	 */
1042
+	public function get_installed_message_types()
1043
+	{
1044
+		// EE_messages has been deprecated
1045
+		$this->_class_is_deprecated(__FUNCTION__);
1046
+		return $this->_message_resource_manager->installed_message_types();
1047
+	}
1048
+
1049
+
1050
+	/**
1051
+	 * @deprecated 4.9.0
1052
+	 * @return array
1053
+	 */
1054
+	public function get_installed_messengers()
1055
+	{
1056
+		// EE_messages has been deprecated
1057
+		$this->_class_is_deprecated(__FUNCTION__);
1058
+		return $this->_message_resource_manager->installed_messengers();
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * @deprecated 4.9.0
1064
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by
1065
+	 *                           message type.
1066
+	 * @return array
1067
+	 */
1068
+	public function get_all_contexts($slugs_only = true)
1069
+	{
1070
+		// EE_messages has been deprecated
1071
+		$this->_class_is_deprecated(__FUNCTION__);
1072
+		return $this->_message_resource_manager->get_all_contexts($slugs_only);
1073
+	}
1074 1074
 
1075 1075
 
1076 1076
 }
@@ -1129,88 +1129,88 @@  discard block
 block discarded – undo
1129 1129
 
1130 1130
 
1131 1131
 add_filter(
1132
-    'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1133
-    function ($event_list_iframe_css) {
1134
-        if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1135
-            return $event_list_iframe_css;
1136
-        }
1137
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1138
-            'FHEE__EventsArchiveIframe__event_list_iframe__css',
1139
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1140
-            '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1141
-            '4.9.14',
1142
-            '5.0.0',
1143
-            'filter'
1144
-        );
1145
-        return apply_filters(
1146
-            'FHEE__EventsArchiveIframe__event_list_iframe__css',
1147
-            $event_list_iframe_css
1148
-        );
1149
-    }
1132
+	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1133
+	function ($event_list_iframe_css) {
1134
+		if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1135
+			return $event_list_iframe_css;
1136
+		}
1137
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1138
+			'FHEE__EventsArchiveIframe__event_list_iframe__css',
1139
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1140
+			'\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1141
+			'4.9.14',
1142
+			'5.0.0',
1143
+			'filter'
1144
+		);
1145
+		return apply_filters(
1146
+			'FHEE__EventsArchiveIframe__event_list_iframe__css',
1147
+			$event_list_iframe_css
1148
+		);
1149
+	}
1150 1150
 );
1151 1151
 add_filter(
1152
-    'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1153
-    function ($event_list_iframe_js) {
1154
-        if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1155
-            return $event_list_iframe_js;
1156
-        }
1157
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1158
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1159
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1160
-            '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1161
-            '4.9.14',
1162
-            '5.0.0',
1163
-            'filter'
1164
-        );
1165
-        return apply_filters(
1166
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1167
-            $event_list_iframe_js
1168
-        );
1169
-    }
1152
+	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1153
+	function ($event_list_iframe_js) {
1154
+		if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1155
+			return $event_list_iframe_js;
1156
+		}
1157
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1158
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1159
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1160
+			'\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1161
+			'4.9.14',
1162
+			'5.0.0',
1163
+			'filter'
1164
+		);
1165
+		return apply_filters(
1166
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1167
+			$event_list_iframe_js
1168
+		);
1169
+	}
1170 1170
 );
1171 1171
 add_action(
1172
-    'AHEE__EE_Capabilities__addCaps__complete',
1173
-    function ($capabilities_map) {
1174
-        if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1175
-            return;
1176
-        }
1177
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1178
-            'AHEE__EE_Capabilities__init_role_caps__complete',
1179
-            'AHEE__EE_Capabilities__addCaps__complete',
1180
-            '\EE_Capabilities::addCaps()',
1181
-            '4.9.42',
1182
-            '5.0.0'
1183
-        );
1184
-        do_action(
1185
-            'AHEE__EE_Capabilities__init_role_caps__complete',
1186
-            $capabilities_map
1187
-        );
1188
-    }
1172
+	'AHEE__EE_Capabilities__addCaps__complete',
1173
+	function ($capabilities_map) {
1174
+		if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1175
+			return;
1176
+		}
1177
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1178
+			'AHEE__EE_Capabilities__init_role_caps__complete',
1179
+			'AHEE__EE_Capabilities__addCaps__complete',
1180
+			'\EE_Capabilities::addCaps()',
1181
+			'4.9.42',
1182
+			'5.0.0'
1183
+		);
1184
+		do_action(
1185
+			'AHEE__EE_Capabilities__init_role_caps__complete',
1186
+			$capabilities_map
1187
+		);
1188
+	}
1189 1189
 );
1190 1190
 
1191 1191
 add_filter(
1192
-    'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1193
-    function ($existing_attendee, $registration, $attendee_data) {
1194
-        if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1195
-            return $existing_attendee;
1196
-        }
1197
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1198
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1199
-            'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1200
-            '\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()',
1201
-            '4.9.34',
1202
-            '5.0.0',
1203
-            'filter'
1204
-        );
1205
-        return apply_filters(
1206
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1207
-            $existing_attendee,
1208
-            $registration,
1209
-            $attendee_data
1210
-        );
1211
-    },
1212
-    10,
1213
-    3
1192
+	'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1193
+	function ($existing_attendee, $registration, $attendee_data) {
1194
+		if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1195
+			return $existing_attendee;
1196
+		}
1197
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1198
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1199
+			'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1200
+			'\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()',
1201
+			'4.9.34',
1202
+			'5.0.0',
1203
+			'filter'
1204
+		);
1205
+		return apply_filters(
1206
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1207
+			$existing_attendee,
1208
+			$registration,
1209
+			$attendee_data
1210
+		);
1211
+	},
1212
+	10,
1213
+	3
1214 1214
 );
1215 1215
 
1216 1216
 /**
@@ -1221,88 +1221,88 @@  discard block
 block discarded – undo
1221 1221
 class EE_Event_List_Query extends WP_Query
1222 1222
 {
1223 1223
 
1224
-    private $title;
1225
-
1226
-    private $css_class;
1227
-
1228
-    private $category_slug;
1229
-
1230
-    /**
1231
-     * EE_Event_List_Query constructor.
1232
-     *
1233
-     * @param array $args
1234
-     */
1235
-    public function __construct($args = array())
1236
-    {
1237
-        \EE_Error::doing_it_wrong(
1238
-            __METHOD__,
1239
-            __(
1240
-                'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1241
-                'event_espresso'
1242
-            ),
1243
-            '4.9.27',
1244
-            '5.0.0'
1245
-        );
1246
-        $this->title = isset($args['title']) ? $args['title'] : '';
1247
-        $this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1248
-        $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1249
-        $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1250
-        // the current "page" we are viewing
1251
-        $paged = max(1, get_query_var('paged'));
1252
-        // Force these args
1253
-        $args = array_merge(
1254
-            $args,
1255
-            array(
1256
-                'post_type'              => 'espresso_events',
1257
-                'posts_per_page'         => $limit,
1258
-                'update_post_term_cache' => false,
1259
-                'update_post_meta_cache' => false,
1260
-                'paged'                  => $paged,
1261
-                'offset'                 => ($paged - 1) * $limit,
1262
-            )
1263
-        );
1264
-        // run the query
1265
-        parent::__construct($args);
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     * event_list_title
1271
-     *
1272
-     * @param string $event_list_title
1273
-     * @return string
1274
-     */
1275
-    public function event_list_title($event_list_title = '')
1276
-    {
1277
-        if (! empty($this->title)) {
1278
-            return $this->title;
1279
-        }
1280
-        return $event_list_title;
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * event_list_css
1286
-     *
1287
-     * @param string $event_list_css
1288
-     * @return string
1289
-     */
1290
-    public function event_list_css($event_list_css = '')
1291
-    {
1292
-        $event_list_css .= ! empty($event_list_css)
1293
-            ? ' '
1294
-            : '';
1295
-        $event_list_css .= ! empty($this->css_class)
1296
-            ? $this->css_class
1297
-            : '';
1298
-        $event_list_css .= ! empty($event_list_css)
1299
-            ? ' '
1300
-            : '';
1301
-        $event_list_css .= ! empty($this->category_slug)
1302
-            ? $this->category_slug
1303
-            : '';
1304
-        return $event_list_css;
1305
-    }
1224
+	private $title;
1225
+
1226
+	private $css_class;
1227
+
1228
+	private $category_slug;
1229
+
1230
+	/**
1231
+	 * EE_Event_List_Query constructor.
1232
+	 *
1233
+	 * @param array $args
1234
+	 */
1235
+	public function __construct($args = array())
1236
+	{
1237
+		\EE_Error::doing_it_wrong(
1238
+			__METHOD__,
1239
+			__(
1240
+				'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1241
+				'event_espresso'
1242
+			),
1243
+			'4.9.27',
1244
+			'5.0.0'
1245
+		);
1246
+		$this->title = isset($args['title']) ? $args['title'] : '';
1247
+		$this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1248
+		$this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1249
+		$limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1250
+		// the current "page" we are viewing
1251
+		$paged = max(1, get_query_var('paged'));
1252
+		// Force these args
1253
+		$args = array_merge(
1254
+			$args,
1255
+			array(
1256
+				'post_type'              => 'espresso_events',
1257
+				'posts_per_page'         => $limit,
1258
+				'update_post_term_cache' => false,
1259
+				'update_post_meta_cache' => false,
1260
+				'paged'                  => $paged,
1261
+				'offset'                 => ($paged - 1) * $limit,
1262
+			)
1263
+		);
1264
+		// run the query
1265
+		parent::__construct($args);
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 * event_list_title
1271
+	 *
1272
+	 * @param string $event_list_title
1273
+	 * @return string
1274
+	 */
1275
+	public function event_list_title($event_list_title = '')
1276
+	{
1277
+		if (! empty($this->title)) {
1278
+			return $this->title;
1279
+		}
1280
+		return $event_list_title;
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * event_list_css
1286
+	 *
1287
+	 * @param string $event_list_css
1288
+	 * @return string
1289
+	 */
1290
+	public function event_list_css($event_list_css = '')
1291
+	{
1292
+		$event_list_css .= ! empty($event_list_css)
1293
+			? ' '
1294
+			: '';
1295
+		$event_list_css .= ! empty($this->css_class)
1296
+			? $this->css_class
1297
+			: '';
1298
+		$event_list_css .= ! empty($event_list_css)
1299
+			? ' '
1300
+			: '';
1301
+		$event_list_css .= ! empty($this->category_slug)
1302
+			? $this->category_slug
1303
+			: '';
1304
+		return $event_list_css;
1305
+	}
1306 1306
 
1307 1307
 }
1308 1308
 
@@ -1319,75 +1319,75 @@  discard block
 block discarded – undo
1319 1319
 {
1320 1320
 
1321 1321
 
1322
-    /**
1323
-     *    class constructor
1324
-     *
1325
-     * @deprecated 4.9.59.p
1326
-     */
1327
-    public function __construct()
1328
-    {
1329
-        EE_Error::doing_it_wrong(
1330
-            __METHOD__,
1331
-            sprintf(
1332
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1333
-                __CLASS__,
1334
-                'EventEspresso\core\services\licensing\LicenseServices'
1335
-            ),
1336
-            '4.9.59.p'
1337
-        );
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * The purpose of this function is to display information about Event Espresso data collection
1343
-     * and a optin selection for extra data collecting by users.
1344
-     *
1345
-     * @param bool $extra
1346
-     * @return string html.
1347
-     * @deprecated 4.9.59.p
1348
-     */
1349
-    public static function espresso_data_collection_optin_text($extra = true)
1350
-    {
1351
-        EE_Error::doing_it_wrong(
1352
-            __METHOD__,
1353
-            sprintf(
1354
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1355
-                __METHOD__,
1356
-                'EventEspresso\core\domain\services\Stats::optinText'
1357
-            ),
1358
-            '4.9.59.p'
1359
-        );
1360
-        Stats::optinText($extra);
1361
-    }
1362
-
1363
-    /**
1364
-     * This is a handy helper method for retrieving whether there is an update available for the given plugin.
1365
-     *
1366
-     * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
1367
-     *                          identify plugins. Defaults to core update
1368
-     * @return boolean           True if update available, false if not.
1369
-     * @deprecated 4.9.59.p
1370
-     */
1371
-    public static function is_update_available($basename = '')
1372
-    {
1373
-        EE_Error::doing_it_wrong(
1374
-            __METHOD__,
1375
-            sprintf(
1376
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1377
-                __METHOD__,
1378
-                'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable'
1379
-            ),
1380
-            '4.9.59.p'
1381
-        );
1382
-        return LicenseService::isUpdateAvailable($basename);
1383
-    }
1322
+	/**
1323
+	 *    class constructor
1324
+	 *
1325
+	 * @deprecated 4.9.59.p
1326
+	 */
1327
+	public function __construct()
1328
+	{
1329
+		EE_Error::doing_it_wrong(
1330
+			__METHOD__,
1331
+			sprintf(
1332
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1333
+				__CLASS__,
1334
+				'EventEspresso\core\services\licensing\LicenseServices'
1335
+			),
1336
+			'4.9.59.p'
1337
+		);
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * The purpose of this function is to display information about Event Espresso data collection
1343
+	 * and a optin selection for extra data collecting by users.
1344
+	 *
1345
+	 * @param bool $extra
1346
+	 * @return string html.
1347
+	 * @deprecated 4.9.59.p
1348
+	 */
1349
+	public static function espresso_data_collection_optin_text($extra = true)
1350
+	{
1351
+		EE_Error::doing_it_wrong(
1352
+			__METHOD__,
1353
+			sprintf(
1354
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1355
+				__METHOD__,
1356
+				'EventEspresso\core\domain\services\Stats::optinText'
1357
+			),
1358
+			'4.9.59.p'
1359
+		);
1360
+		Stats::optinText($extra);
1361
+	}
1362
+
1363
+	/**
1364
+	 * This is a handy helper method for retrieving whether there is an update available for the given plugin.
1365
+	 *
1366
+	 * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
1367
+	 *                          identify plugins. Defaults to core update
1368
+	 * @return boolean           True if update available, false if not.
1369
+	 * @deprecated 4.9.59.p
1370
+	 */
1371
+	public static function is_update_available($basename = '')
1372
+	{
1373
+		EE_Error::doing_it_wrong(
1374
+			__METHOD__,
1375
+			sprintf(
1376
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1377
+				__METHOD__,
1378
+				'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable'
1379
+			),
1380
+			'4.9.59.p'
1381
+		);
1382
+		return LicenseService::isUpdateAvailable($basename);
1383
+	}
1384 1384
 }
1385 1385
 
1386 1386
 add_filter(
1387
-    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
1388
-    'ee_deprecated_registrations_report_csv_legacy_fields',
1389
-    10,
1390
-    2
1387
+	'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
1388
+	'ee_deprecated_registrations_report_csv_legacy_fields',
1389
+	10,
1390
+	2
1391 1391
 );
1392 1392
 /**
1393 1393
  * Filters the CSV row to make it appear like the old labels (which were "$pretty_name[$field_name]").
@@ -1404,96 +1404,96 @@  discard block
 block discarded – undo
1404 1404
  */
1405 1405
 function ee_deprecated_registrations_report_csv_legacy_fields($csv_row_data, $reg_row)
1406 1406
 {
1407
-    // no need for all this if nobody is using the deprecated filter
1408
-    if (has_filter('FHEE__EE_Export__report_registrations__reg_csv_array')) {
1409
-        EE_Error::doing_it_wrong(
1410
-            __FUNCTION__,
1411
-            sprintf(
1412
-                // EE_Error::doing_it_wrong with escape HTML, so don't escape it twice by doing it here too.
1413
-                _x(
1414
-                    'The filter "%1$s" has been deprecated. Please use "%2$s" instead.',
1415
-                    'The filter "FHEE__EE_Export__report_registrations__reg_csv_array" has been deprecated. Please use "FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array" instead.',
1416
-                    'event_espresso'
1417
-                ),
1418
-                'FHEE__EE_Export__report_registrations__reg_csv_array',
1419
-                'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array'
1420
-            ),
1421
-            '4.9.69.p',
1422
-            '4.9.75.p'
1423
-        );
1424
-        // there's code that expected the old csv column headers/labels. Let's oblige. Put it back in the old format!
1425
-        // first: what model fields might be used as column headers? (whose format we need to change)
1426
-        $model_fields = array_merge(
1427
-            EEM_Registration::instance()->field_settings(),
1428
-            EEM_Attendee::instance()->field_settings()
1429
-        );
1430
-        // create an array that uses the legacy column headers/labels.
1431
-        $new_csv_row = array();
1432
-        foreach ($csv_row_data as $label => $value) {
1433
-            $new_label = $label;
1434
-            foreach ($model_fields as $field) {
1435
-                if ($label === EEH_Export::get_column_name_for_field($field)) {
1436
-                    // re-add the old field name
1437
-                    $new_label = $label . '[' . $field->get_name() . ']';
1438
-                    break;
1439
-                }
1440
-            }
1441
-            $new_csv_row[$new_label] = $value;
1442
-        }
1443
-        // before we run it through the deprecated filter, set the method `EEH_Export::get_column_name_for_field()`
1444
-        // to create the old column names, because that's what's in the row temporarily
1445
-        add_filter(
1446
-            'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1447
-            '__return_true',
1448
-            777
1449
-        );
1450
-        // now, those old filters can be run on this data. Have fun!
1451
-        /**
1452
-         * Deprecated. Use FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array instead.
1453
-         *
1454
-         * Filter to change the contents of each row of the registrations report CSV file.
1455
-         * This can be used to add or remote columns from the CSV file, or change their values.                 *
1456
-         * Note: it has this name because originally that's where this filter resided,
1457
-         * and we've left its name as-is for backward compatibility.
1458
-         * Note when using: all rows in the CSV should have the same columns.
1459
-         *
1460
-         * @param array $reg_csv_array keys are column-header names, and values are that columns' value
1461
-         *                             in this row
1462
-         * @param array $reg_row is the row from the database's wp_esp_registration table
1463
-         */
1464
-        $updated_row = apply_filters(
1465
-            'FHEE__EE_Export__report_registrations__reg_csv_array',
1466
-            $new_csv_row,
1467
-            $reg_row
1468
-        );
1469
-
1470
-        // ok now we can revert to normal for EEH_Export::get_column_name_for_field().
1471
-        remove_filter(
1472
-            'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1473
-            '__return_true',
1474
-            777
1475
-        );
1476
-
1477
-        // great. Now that the old filters are done, we can remove the ugly square brackets from column headers/labels.
1478
-        $updated_and_restored_row = array();
1479
-        foreach ($updated_row as $label => $value) {
1480
-            $matches = array();
1481
-            if (preg_match(
1482
-                    '~([^\[]*)\[(.*)\]~',
1483
-                    $label,
1484
-                    $matches
1485
-                )
1486
-                && isset(
1487
-                    $matches[0],
1488
-                    $matches[1],
1489
-                    $matches[2]
1490
-                )
1491
-            ) {
1492
-                $label = $matches[1];
1493
-            }
1494
-            $updated_and_restored_row[$label] = $value;
1495
-        }
1496
-        $csv_row_data = $updated_and_restored_row;
1497
-    }
1498
-    return $csv_row_data;
1407
+	// no need for all this if nobody is using the deprecated filter
1408
+	if (has_filter('FHEE__EE_Export__report_registrations__reg_csv_array')) {
1409
+		EE_Error::doing_it_wrong(
1410
+			__FUNCTION__,
1411
+			sprintf(
1412
+				// EE_Error::doing_it_wrong with escape HTML, so don't escape it twice by doing it here too.
1413
+				_x(
1414
+					'The filter "%1$s" has been deprecated. Please use "%2$s" instead.',
1415
+					'The filter "FHEE__EE_Export__report_registrations__reg_csv_array" has been deprecated. Please use "FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array" instead.',
1416
+					'event_espresso'
1417
+				),
1418
+				'FHEE__EE_Export__report_registrations__reg_csv_array',
1419
+				'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array'
1420
+			),
1421
+			'4.9.69.p',
1422
+			'4.9.75.p'
1423
+		);
1424
+		// there's code that expected the old csv column headers/labels. Let's oblige. Put it back in the old format!
1425
+		// first: what model fields might be used as column headers? (whose format we need to change)
1426
+		$model_fields = array_merge(
1427
+			EEM_Registration::instance()->field_settings(),
1428
+			EEM_Attendee::instance()->field_settings()
1429
+		);
1430
+		// create an array that uses the legacy column headers/labels.
1431
+		$new_csv_row = array();
1432
+		foreach ($csv_row_data as $label => $value) {
1433
+			$new_label = $label;
1434
+			foreach ($model_fields as $field) {
1435
+				if ($label === EEH_Export::get_column_name_for_field($field)) {
1436
+					// re-add the old field name
1437
+					$new_label = $label . '[' . $field->get_name() . ']';
1438
+					break;
1439
+				}
1440
+			}
1441
+			$new_csv_row[$new_label] = $value;
1442
+		}
1443
+		// before we run it through the deprecated filter, set the method `EEH_Export::get_column_name_for_field()`
1444
+		// to create the old column names, because that's what's in the row temporarily
1445
+		add_filter(
1446
+			'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1447
+			'__return_true',
1448
+			777
1449
+		);
1450
+		// now, those old filters can be run on this data. Have fun!
1451
+		/**
1452
+		 * Deprecated. Use FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array instead.
1453
+		 *
1454
+		 * Filter to change the contents of each row of the registrations report CSV file.
1455
+		 * This can be used to add or remote columns from the CSV file, or change their values.                 *
1456
+		 * Note: it has this name because originally that's where this filter resided,
1457
+		 * and we've left its name as-is for backward compatibility.
1458
+		 * Note when using: all rows in the CSV should have the same columns.
1459
+		 *
1460
+		 * @param array $reg_csv_array keys are column-header names, and values are that columns' value
1461
+		 *                             in this row
1462
+		 * @param array $reg_row is the row from the database's wp_esp_registration table
1463
+		 */
1464
+		$updated_row = apply_filters(
1465
+			'FHEE__EE_Export__report_registrations__reg_csv_array',
1466
+			$new_csv_row,
1467
+			$reg_row
1468
+		);
1469
+
1470
+		// ok now we can revert to normal for EEH_Export::get_column_name_for_field().
1471
+		remove_filter(
1472
+			'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1473
+			'__return_true',
1474
+			777
1475
+		);
1476
+
1477
+		// great. Now that the old filters are done, we can remove the ugly square brackets from column headers/labels.
1478
+		$updated_and_restored_row = array();
1479
+		foreach ($updated_row as $label => $value) {
1480
+			$matches = array();
1481
+			if (preg_match(
1482
+					'~([^\[]*)\[(.*)\]~',
1483
+					$label,
1484
+					$matches
1485
+				)
1486
+				&& isset(
1487
+					$matches[0],
1488
+					$matches[1],
1489
+					$matches[2]
1490
+				)
1491
+			) {
1492
+				$label = $matches[1];
1493
+			}
1494
+			$updated_and_restored_row[$label] = $value;
1495
+		}
1496
+		$csv_row_data = $updated_and_restored_row;
1497
+	}
1498
+	return $csv_row_data;
1499 1499
 }
1500 1500
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -86,20 +86,20 @@  discard block
 block discarded – undo
86 86
     // loop thru and call doing_it_wrong() or remove any that aren't being used
87 87
     foreach ($deprecated_filters as $deprecated_filter => $on) {
88 88
         // was this filter called ?
89
-        if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) {
89
+        if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) {
90 90
             // only display doing_it_wrong() notice to Event Admins during non-AJAX requests
91 91
             if (EE_Registry::instance()->CAP->current_user_can(
92 92
                     'ee_read_ee',
93 93
                     'hide_doing_it_wrong_for_deprecated_SPCO_filter'
94 94
                 ) && ! defined('DOING_AJAX')) {
95 95
                 EE_Error::doing_it_wrong(
96
-                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
96
+                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
97 97
                     sprintf(
98 98
                         __(
99 99
                             'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"',
100 100
                             'event_espresso'
101 101
                         ),
102
-                        'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
102
+                        'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
103 103
                         '<br />',
104 104
                         'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
105 105
                         '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
                 );
109 109
             }
110 110
         } else {
111
-            unset($deprecated_filters[ $deprecated_filter ]);
111
+            unset($deprecated_filters[$deprecated_filter]);
112 112
         }
113 113
     }
114
-    if (! empty($deprecated_filters)) {
114
+    if ( ! empty($deprecated_filters)) {
115 115
 
116 116
         if ($checkout->current_step->slug(
117 117
             ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                 $submit_button_text = apply_filters(
146 146
                                           'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to',
147 147
                                           $submit_button_text
148
-                                      ) . $checkout->next_step->name();
148
+                                      ).$checkout->next_step->name();
149 149
             }
150 150
         }
151 151
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
             'event_espresso'
330 330
         );
331 331
         EE_Error::doing_it_wrong(
332
-            __CLASS__ . '::' . __FUNCTION__,
332
+            __CLASS__.'::'.__FUNCTION__,
333 333
             $msg,
334 334
             '4.8.32.rc.000'
335 335
         );
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 function ee_deprecated_update_attendee_registration_form_old($admin_page)
357 357
 {
358 358
     // check if the old hooks are in use. If not, do the default
359
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
359
+    if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
360 360
         || ! $admin_page instanceof EE_Admin_Page) {
361 361
         return;
362 362
     }
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
     $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false;
365 365
     $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false;
366 366
     $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
367
-    if (! $REG_ID || ! $qstns) {
367
+    if ( ! $REG_ID || ! $qstns) {
368 368
         EE_Error::add_error(
369 369
             __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'),
370 370
             __FILE__,
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 
385 385
     foreach ($qstns as $QST_ID => $qstn) {
386 386
         // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
387
-        if (! is_array($qstn)) {
388
-            $success = EE_Answer::new_instance([ 'QST_ID' => $QST_ID, 'REG_ID' => $REG_ID ]);
387
+        if ( ! is_array($qstn)) {
388
+            $success = EE_Answer::new_instance(['QST_ID' => $QST_ID, 'REG_ID' => $REG_ID]);
389 389
             continue;
390 390
         }
391 391
 
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
             );
402 402
             $answer = EEM_Answer::instance()->get_one($query_params);
403 403
             // this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
404
-            if (! $answer instanceof EE_Answer) {
404
+            if ( ! $answer instanceof EE_Answer) {
405 405
                 $set_values = array(
406 406
                     'QST_ID'    => $QST_ID,
407 407
                     'REG_ID'    => $REG_ID,
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration)
443 443
 {
444 444
     // check if the old hooks are in use. If not, do the default
445
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
445
+    if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
446 446
         || ! $admin_page instanceof EE_Admin_Page) {
447 447
         return $do_default_action;
448 448
     }
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
         'reg_questions_form_action' => 'edit_registration',
473 473
         'REG_ID'                    => $registration->ID(),
474 474
     );
475
-    $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
475
+    $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
476 476
     echo EEH_Template::display_template($template_path, $template_args, true);
477 477
     // indicate that we should not do the default admin page code
478 478
     return false;
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
     public function _class_is_deprecated($method)
591 591
     {
592 592
         EE_Error::doing_it_wrong(
593
-            'EE_messages::' . $method,
593
+            'EE_messages::'.$method,
594 594
             __('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
595 595
             '4.9.0',
596 596
             '4.10.0.p'
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
         $error = false;
730 730
         // try to intelligently determine what method we'll call based on the incoming data.
731 731
         // if generating and sending are different then generate and send immediately.
732
-        if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
732
+        if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
733 733
             // in the legacy system, when generating and sending were different, that means all the
734 734
             // vars are already in the request object.  So let's just use that.
735 735
             try {
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
                     'event_espresso'
743 743
                 );
744 744
                 // add specific message for developers if WP_DEBUG in on
745
-                $error_msg .= '||' . $e->getMessage();
745
+                $error_msg .= '||'.$e->getMessage();
746 746
                 EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
747 747
                 $error = true;
748 748
             }
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
             }
817 817
         }
818 818
         // if no error then return the generated message(s).
819
-        if (! $error && ! $send) {
819
+        if ( ! $error && ! $send) {
820 820
             $generated_queue = $processor->generate_queue(false);
821 821
             // get message and return.
822 822
             $generated_queue->get_message_repository()->rewind();
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
         /** @type EE_Messages_Queue $queue */
876 876
         $queue = EE_Registry::instance()->load_lib('Messages_Queue');
877 877
         // make sure we have a proper message object
878
-        if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
878
+        if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
879 879
             $msg = EE_Message_Factory::create(
880 880
                 array(
881 881
                     'MSG_messenger'    => $messenger,
@@ -887,11 +887,11 @@  discard block
 block discarded – undo
887 887
         } else {
888 888
             $msg = $message;
889 889
         }
890
-        if (! $msg instanceof EE_Message) {
890
+        if ( ! $msg instanceof EE_Message) {
891 891
             return false;
892 892
         }
893 893
         // make sure any content in a content property (if not empty) is set on the MSG_content.
894
-        if (! empty($msg->content)) {
894
+        if ( ! empty($msg->content)) {
895 895
             $msg->set('MSG_content', $msg->content);
896 896
         }
897 897
         $queue->add($msg);
@@ -1130,8 +1130,8 @@  discard block
 block discarded – undo
1130 1130
 
1131 1131
 add_filter(
1132 1132
     'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1133
-    function ($event_list_iframe_css) {
1134
-        if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1133
+    function($event_list_iframe_css) {
1134
+        if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1135 1135
             return $event_list_iframe_css;
1136 1136
         }
1137 1137
         deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1150,8 +1150,8 @@  discard block
 block discarded – undo
1150 1150
 );
1151 1151
 add_filter(
1152 1152
     'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1153
-    function ($event_list_iframe_js) {
1154
-        if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1153
+    function($event_list_iframe_js) {
1154
+        if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1155 1155
             return $event_list_iframe_js;
1156 1156
         }
1157 1157
         deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1170,8 +1170,8 @@  discard block
 block discarded – undo
1170 1170
 );
1171 1171
 add_action(
1172 1172
     'AHEE__EE_Capabilities__addCaps__complete',
1173
-    function ($capabilities_map) {
1174
-        if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1173
+    function($capabilities_map) {
1174
+        if ( ! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1175 1175
             return;
1176 1176
         }
1177 1177
         deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1190,8 +1190,8 @@  discard block
 block discarded – undo
1190 1190
 
1191 1191
 add_filter(
1192 1192
     'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1193
-    function ($existing_attendee, $registration, $attendee_data) {
1194
-        if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1193
+    function($existing_attendee, $registration, $attendee_data) {
1194
+        if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1195 1195
             return $existing_attendee;
1196 1196
         }
1197 1197
         deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1274,7 +1274,7 @@  discard block
 block discarded – undo
1274 1274
      */
1275 1275
     public function event_list_title($event_list_title = '')
1276 1276
     {
1277
-        if (! empty($this->title)) {
1277
+        if ( ! empty($this->title)) {
1278 1278
             return $this->title;
1279 1279
         }
1280 1280
         return $event_list_title;
@@ -1434,7 +1434,7 @@  discard block
 block discarded – undo
1434 1434
             foreach ($model_fields as $field) {
1435 1435
                 if ($label === EEH_Export::get_column_name_for_field($field)) {
1436 1436
                     // re-add the old field name
1437
-                    $new_label = $label . '[' . $field->get_name() . ']';
1437
+                    $new_label = $label.'['.$field->get_name().']';
1438 1438
                     break;
1439 1439
                 }
1440 1440
             }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1414 added lines, -1414 removed lines patch added patch discarded remove patch
@@ -17,1418 +17,1418 @@
 block discarded – undo
17 17
 class Extend_Events_Admin_Page extends Events_Admin_Page
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Admin_Config
22
-     */
23
-    protected $admin_config;
24
-
25
-    /**
26
-     * @var AdvancedEditorAdminFormSection
27
-     */
28
-    protected $advanced_editor_admin_form;
29
-
30
-
31
-    /**
32
-     * Extend_Events_Admin_Page constructor.
33
-     *
34
-     * @param bool $routing
35
-     * @throws ReflectionException
36
-     */
37
-    public function __construct($routing = true)
38
-    {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
-        }
44
-        parent::__construct($routing);
45
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
-    }
47
-
48
-
49
-    /**
50
-     * Sets routes.
51
-     *
52
-     * @throws EE_Error
53
-     * @throws InvalidArgumentException
54
-     * @throws InvalidDataTypeException
55
-     * @throws InvalidInterfaceException
56
-     * @throws Exception
57
-     */
58
-    protected function _extend_page_config()
59
-    {
60
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
61
-        // is there a evt_id in the request?
62
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
63
-            ? $this->_req_data['EVT_ID']
64
-            : 0;
65
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
66
-        // tkt_id?
67
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
68
-            ? $this->_req_data['TKT_ID']
69
-            : 0;
70
-        $new_page_routes = [
71
-            'duplicate_event'          => [
72
-                'func'       => '_duplicate_event',
73
-                'capability' => 'ee_edit_event',
74
-                'obj_id'     => $evt_id,
75
-                'noheader'   => true,
76
-            ],
77
-            'import_page'              => [
78
-                'func'       => '_import_page',
79
-                'capability' => 'import',
80
-            ],
81
-            'import'                   => [
82
-                'func'       => '_import_events',
83
-                'capability' => 'import',
84
-                'noheader'   => true,
85
-            ],
86
-            'import_events'            => [
87
-                'func'       => '_import_events',
88
-                'capability' => 'import',
89
-                'noheader'   => true,
90
-            ],
91
-            'export_events'            => [
92
-                'func'       => '_events_export',
93
-                'capability' => 'export',
94
-                'noheader'   => true,
95
-            ],
96
-            'export_categories'        => [
97
-                'func'       => '_categories_export',
98
-                'capability' => 'export',
99
-                'noheader'   => true,
100
-            ],
101
-            'sample_export_file'       => [
102
-                'func'       => '_sample_export_file',
103
-                'capability' => 'export',
104
-                'noheader'   => true,
105
-            ],
106
-            'update_template_settings' => [
107
-                'func'       => '_update_template_settings',
108
-                'capability' => 'manage_options',
109
-                'noheader'   => true,
110
-            ],
111
-        ];        // don't load these meta boxes if using the advanced editor
112
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
113
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
114
-        if (! $this->admin_config->useAdvancedEditor()) {
115
-            $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
116
-            $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
117
-
118
-            $legacy_editor_page_routes = [
119
-                'ticket_list_table' => [
120
-                    'func'       => '_tickets_overview_list_table',
121
-                    'capability' => 'ee_read_default_tickets',
122
-                ],
123
-                'trash_ticket'      => [
124
-                    'func'       => '_trash_or_restore_ticket',
125
-                    'capability' => 'ee_delete_default_ticket',
126
-                    'obj_id'     => $tkt_id,
127
-                    'noheader'   => true,
128
-                    'args'       => ['trash' => true],
129
-                ],
130
-                'trash_tickets'     => [
131
-                    'func'       => '_trash_or_restore_ticket',
132
-                    'capability' => 'ee_delete_default_tickets',
133
-                    'noheader'   => true,
134
-                    'args'       => ['trash' => true],
135
-                ],
136
-                'restore_ticket'    => [
137
-                    'func'       => '_trash_or_restore_ticket',
138
-                    'capability' => 'ee_delete_default_ticket',
139
-                    'obj_id'     => $tkt_id,
140
-                    'noheader'   => true,
141
-                ],
142
-                'restore_tickets'   => [
143
-                    'func'       => '_trash_or_restore_ticket',
144
-                    'capability' => 'ee_delete_default_tickets',
145
-                    'noheader'   => true,
146
-                ],
147
-                'delete_ticket'     => [
148
-                    'func'       => '_delete_ticket',
149
-                    'capability' => 'ee_delete_default_ticket',
150
-                    'obj_id'     => $tkt_id,
151
-                    'noheader'   => true,
152
-                ],
153
-                'delete_tickets'    => [
154
-                    'func'       => '_delete_ticket',
155
-                    'capability' => 'ee_delete_default_tickets',
156
-                    'noheader'   => true,
157
-                ],
158
-            ];
159
-            $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes);
160
-        }
161
-
162
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
163
-        // partial route/config override
164
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
165
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
166
-        // add tickets tab but only if there are more than one default ticket!
167
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
168
-            [['TKT_is_default' => 1]],
169
-            'TKT_ID',
170
-            true
171
-        );
172
-        if ($tkt_count > 1) {
173
-            $new_page_config = [
174
-                'ticket_list_table' => [
175
-                    'nav'           => [
176
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
177
-                        'order' => 60,
178
-                    ],
179
-                    'list_table'    => 'Tickets_List_Table',
180
-                    'require_nonce' => false,
181
-                ],
182
-            ];
183
-        }
184
-        // template settings
185
-        $new_page_config['template_settings'] = [
186
-            'nav'           => [
187
-                'label' => esc_html__('Templates', 'event_espresso'),
188
-                'order' => 30,
189
-            ],
190
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
191
-            'help_tabs'     => [
192
-                'general_settings_templates_help_tab' => [
193
-                    'title'    => esc_html__('Templates', 'event_espresso'),
194
-                    'filename' => 'general_settings_templates',
195
-                ],
196
-            ],
197
-           // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
198
-            // 'help_tour'     => ['Templates_Help_Tour'],
199
-            'require_nonce' => false,
200
-        ];
201
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
202
-        // add filters and actions
203
-        // modifying _views
204
-        add_filter(
205
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
206
-            [$this, 'add_additional_datetime_button'],
207
-            10,
208
-            2
209
-        );
210
-        add_filter(
211
-            'FHEE_event_datetime_metabox_clone_button_template',
212
-            [$this, 'add_datetime_clone_button'],
213
-            10,
214
-            2
215
-        );
216
-        add_filter(
217
-            'FHEE_event_datetime_metabox_timezones_template',
218
-            [$this, 'datetime_timezones_template'],
219
-            10,
220
-            2
221
-        );
222
-        // filters for event list table
223
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
224
-        add_filter(
225
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
226
-            [$this, 'extra_list_table_actions'],
227
-            10,
228
-            2
229
-        );
230
-        // legend item
231
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
232
-        add_action('admin_init', [$this, 'admin_init']);
233
-        // load additional handlers
234
-        $this->handleActionRequest();
235
-    }
236
-
237
-
238
-    private function getRequestAction()
239
-    {
240
-        return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null;
241
-    }
242
-
243
-
244
-    /**
245
-     * @throws Exception
246
-     */
247
-    private function handleActionRequest()
248
-    {
249
-        $action = $this->getRequestAction();
250
-        if ($action) {
251
-            // setup Advanced Editor ???
252
-            if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
253
-                $this->advanced_editor_admin_form = $this->loader->getShared(
254
-                    'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
255
-                );
256
-            }
257
-        }
258
-    }
259
-
260
-
261
-    /**
262
-     * admin_init
263
-     */
264
-    public function admin_init()
265
-    {
266
-        EE_Registry::$i18n_js_strings = array_merge(
267
-            EE_Registry::$i18n_js_strings,
268
-            [
269
-                'image_confirm'          => esc_html__(
270
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
271
-                    'event_espresso'
272
-                ),
273
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
274
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
275
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
276
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
277
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
278
-            ]
279
-        );
280
-    }
281
-
282
-
283
-    /**
284
-     * Add per page screen options to the default ticket list table view.
285
-     *
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidDataTypeException
288
-     * @throws InvalidInterfaceException
289
-     */
290
-    protected function _add_screen_options_ticket_list_table()
291
-    {
292
-        $this->_per_page_screen_option();
293
-    }
294
-
295
-
296
-    /**
297
-     * @param string $return
298
-     * @param int    $id
299
-     * @param string $new_title
300
-     * @param string $new_slug
301
-     * @return string
302
-     */
303
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
304
-    {
305
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
306
-        // make sure this is only when editing
307
-        if (! empty($id)) {
308
-            $href = EE_Admin_Page::add_query_args_and_nonce(
309
-                ['action' => 'duplicate_event', 'EVT_ID' => $id],
310
-                $this->_admin_base_url
311
-            );
312
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
313
-            $return .= '<a href="'
314
-                       . $href
315
-                       . '" title="'
316
-                       . $title
317
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
318
-                       . $title
319
-                       . '</a>';
320
-        }
321
-        return $return;
322
-    }
323
-
324
-
325
-    /**
326
-     * Set the list table views for the default ticket list table view.
327
-     */
328
-    public function _set_list_table_views_ticket_list_table()
329
-    {
330
-        $this->_views = [
331
-            'all'     => [
332
-                'slug'        => 'all',
333
-                'label'       => esc_html__('All', 'event_espresso'),
334
-                'count'       => 0,
335
-                'bulk_action' => [
336
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
337
-                ],
338
-            ],
339
-            'trashed' => [
340
-                'slug'        => 'trashed',
341
-                'label'       => esc_html__('Trash', 'event_espresso'),
342
-                'count'       => 0,
343
-                'bulk_action' => [
344
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
345
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
346
-                ],
347
-            ],
348
-        ];
349
-    }
350
-
351
-
352
-    /**
353
-     * Enqueue scripts and styles for the event editor.
354
-     */
355
-    public function load_scripts_styles_edit()
356
-    {
357
-        if (! $this->admin_config->useAdvancedEditor()) {
358
-            wp_register_script(
359
-                'ee-event-editor-heartbeat',
360
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
361
-                ['ee_admin_js', 'heartbeat'],
362
-                EVENT_ESPRESSO_VERSION,
363
-                true
364
-            );
365
-            wp_enqueue_script('ee-accounting');
366
-            wp_enqueue_script('ee-event-editor-heartbeat');
367
-        }
368
-        wp_enqueue_script('event_editor_js');
369
-        // styles
370
-        wp_enqueue_style('espresso-ui-theme');
371
-    }
372
-
373
-
374
-    /**
375
-     * Returns template for the additional datetime.
376
-     *
377
-     * @param $template
378
-     * @param $template_args
379
-     * @return mixed
380
-     * @throws DomainException
381
-     */
382
-    public function add_additional_datetime_button($template, $template_args)
383
-    {
384
-        return EEH_Template::display_template(
385
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
386
-            $template_args,
387
-            true
388
-        );
389
-    }
390
-
391
-
392
-    /**
393
-     * Returns the template for cloning a datetime.
394
-     *
395
-     * @param $template
396
-     * @param $template_args
397
-     * @return mixed
398
-     * @throws DomainException
399
-     */
400
-    public function add_datetime_clone_button($template, $template_args)
401
-    {
402
-        return EEH_Template::display_template(
403
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
404
-            $template_args,
405
-            true
406
-        );
407
-    }
408
-
409
-
410
-    /**
411
-     * Returns the template for datetime timezones.
412
-     *
413
-     * @param $template
414
-     * @param $template_args
415
-     * @return mixed
416
-     * @throws DomainException
417
-     */
418
-    public function datetime_timezones_template($template, $template_args)
419
-    {
420
-        return EEH_Template::display_template(
421
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
422
-            $template_args,
423
-            true
424
-        );
425
-    }
426
-
427
-
428
-    /**
429
-     * Sets the views for the default list table view.
430
-     *
431
-     * @throws EE_Error
432
-     */
433
-    protected function _set_list_table_views_default()
434
-    {
435
-        parent::_set_list_table_views_default();
436
-        $new_views = [
437
-            'today' => [
438
-                'slug'        => 'today',
439
-                'label'       => esc_html__('Today', 'event_espresso'),
440
-                'count'       => $this->total_events_today(),
441
-                'bulk_action' => [
442
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
443
-                ],
444
-            ],
445
-            'month' => [
446
-                'slug'        => 'month',
447
-                'label'       => esc_html__('This Month', 'event_espresso'),
448
-                'count'       => $this->total_events_this_month(),
449
-                'bulk_action' => [
450
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
451
-                ],
452
-            ],
453
-        ];
454
-        $this->_views = array_merge($this->_views, $new_views);
455
-    }
456
-
457
-
458
-    /**
459
-     * Returns the extra action links for the default list table view.
460
-     *
461
-     * @param array    $action_links
462
-     * @param EE_Event $event
463
-     * @return array
464
-     * @throws EE_Error
465
-     * @throws InvalidArgumentException
466
-     * @throws InvalidDataTypeException
467
-     * @throws InvalidInterfaceException
468
-     * @throws ReflectionException
469
-     */
470
-    public function extra_list_table_actions(array $action_links, EE_Event $event)
471
-    {
472
-        if (
473
-            EE_Registry::instance()->CAP->current_user_can(
474
-                'ee_read_registrations',
475
-                'espresso_registrations_reports',
476
-                $event->ID()
477
-            )
478
-        ) {
479
-            $reports_query_args = [
480
-                'action' => 'reports',
481
-                'EVT_ID' => $event->ID(),
482
-            ];
483
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
484
-            $action_links[] = '<a href="'
485
-                              . $reports_link
486
-                              . '" title="'
487
-                              . esc_attr__('View Report', 'event_espresso')
488
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
489
-                              . "\n\t";
490
-        }
491
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
492
-            EE_Registry::instance()->load_helper('MSG_Template');
493
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
494
-                'see_notifications_for',
495
-                null,
496
-                ['EVT_ID' => $event->ID()]
497
-            );
498
-        }
499
-        return $action_links;
500
-    }
501
-
502
-
503
-    /**
504
-     * @param $items
505
-     * @return mixed
506
-     */
507
-    public function additional_legend_items($items)
508
-    {
509
-        if (
510
-            EE_Registry::instance()->CAP->current_user_can(
511
-                'ee_read_registrations',
512
-                'espresso_registrations_reports'
513
-            )
514
-        ) {
515
-            $items['reports'] = [
516
-                'class' => 'dashicons dashicons-chart-bar',
517
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
518
-            ];
519
-        }
520
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
521
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
522
-            // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
523
-            // (can only use numeric offsets when treating strings as arrays)
524
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
525
-                $items['view_related_messages'] = [
526
-                    'class' => $related_for_icon['css_class'],
527
-                    'desc'  => $related_for_icon['label'],
528
-                ];
529
-            }
530
-        }
531
-        return $items;
532
-    }
533
-
534
-
535
-    /**
536
-     * This is the callback method for the duplicate event route
537
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
538
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
539
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
540
-     * After duplication the redirect is to the new event edit page.
541
-     *
542
-     * @return void
543
-     * @throws EE_Error If EE_Event is not available with given ID
544
-     * @throws InvalidArgumentException
545
-     * @throws InvalidDataTypeException
546
-     * @throws InvalidInterfaceException
547
-     * @throws ReflectionException
548
-     * @access protected
549
-     */
550
-    protected function _duplicate_event()
551
-    {
552
-        // first make sure the ID for the event is in the request.
553
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
554
-        if (! isset($this->_req_data['EVT_ID'])) {
555
-            EE_Error::add_error(
556
-                esc_html__(
557
-                    'In order to duplicate an event an Event ID is required.  None was given.',
558
-                    'event_espresso'
559
-                ),
560
-                __FILE__,
561
-                __FUNCTION__,
562
-                __LINE__
563
-            );
564
-            $this->_redirect_after_action(false, '', '', [], true);
565
-            return;
566
-        }
567
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
568
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
569
-        if (! $orig_event instanceof EE_Event) {
570
-            throw new EE_Error(
571
-                sprintf(
572
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
573
-                    $this->_req_data['EVT_ID']
574
-                )
575
-            );
576
-        }
577
-        // k now let's clone the $orig_event before getting relations
578
-        $new_event = clone $orig_event;
579
-        // original datetimes
580
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
581
-        // other original relations
582
-        $orig_ven = $orig_event->get_many_related('Venue');
583
-        // reset the ID and modify other details to make it clear this is a dupe
584
-        $new_event->set('EVT_ID', 0);
585
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
586
-        $new_event->set('EVT_name', $new_name);
587
-        $new_event->set(
588
-            'EVT_slug',
589
-            wp_unique_post_slug(
590
-                sanitize_title($orig_event->name()),
591
-                0,
592
-                'publish',
593
-                'espresso_events',
594
-                0
595
-            )
596
-        );
597
-        $new_event->set('status', 'draft');
598
-        // duplicate discussion settings
599
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
600
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
601
-        // save the new event
602
-        $new_event->save();
603
-        // venues
604
-        foreach ($orig_ven as $ven) {
605
-            $new_event->_add_relation_to($ven, 'Venue');
606
-        }
607
-        $new_event->save();
608
-        // now we need to get the question group relations and handle that
609
-        // first primary question groups
610
-        $orig_primary_qgs = $orig_event->get_many_related(
611
-            'Question_Group',
612
-            [['Event_Question_Group.EQG_primary' => true]]
613
-        );
614
-        if (! empty($orig_primary_qgs)) {
615
-            foreach ($orig_primary_qgs as $id => $obj) {
616
-                if ($obj instanceof EE_Question_Group) {
617
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
618
-                }
619
-            }
620
-        }
621
-        // next additional attendee question groups
622
-        $orig_additional_qgs = $orig_event->get_many_related(
623
-            'Question_Group',
624
-            [['Event_Question_Group.EQG_additional' => true]]
625
-        );
626
-        if (! empty($orig_additional_qgs)) {
627
-            foreach ($orig_additional_qgs as $id => $obj) {
628
-                if ($obj instanceof EE_Question_Group) {
629
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
630
-                }
631
-            }
632
-        }
633
-
634
-        $new_event->save();
635
-
636
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
637
-        $cloned_tickets = [];
638
-        foreach ($orig_datetimes as $orig_dtt) {
639
-            if (! $orig_dtt instanceof EE_Datetime) {
640
-                continue;
641
-            }
642
-            $new_dtt = clone $orig_dtt;
643
-            $orig_tkts = $orig_dtt->tickets();
644
-            // save new dtt then add to event
645
-            $new_dtt->set('DTT_ID', 0);
646
-            $new_dtt->set('DTT_sold', 0);
647
-            $new_dtt->set_reserved(0);
648
-            $new_dtt->save();
649
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
650
-            $new_event->save();
651
-            // now let's get the ticket relations setup.
652
-            foreach ((array) $orig_tkts as $orig_tkt) {
653
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
654
-                if (! $orig_tkt instanceof EE_Ticket) {
655
-                    continue;
656
-                }
657
-                // is this ticket archived?  If it is then let's skip
658
-                if ($orig_tkt->get('TKT_deleted')) {
659
-                    continue;
660
-                }
661
-                // does this original ticket already exist in the clone_tickets cache?
662
-                //  If so we'll just use the new ticket from it.
663
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
664
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
665
-                } else {
666
-                    $new_tkt = clone $orig_tkt;
667
-                    // get relations on the $orig_tkt that we need to setup.
668
-                    $orig_prices = $orig_tkt->prices();
669
-                    $new_tkt->set('TKT_ID', 0);
670
-                    $new_tkt->set('TKT_sold', 0);
671
-                    $new_tkt->set('TKT_reserved', 0);
672
-                    $new_tkt->save(); // make sure new ticket has ID.
673
-                    // price relations on new ticket need to be setup.
674
-                    foreach ($orig_prices as $orig_price) {
675
-                        $new_price = clone $orig_price;
676
-                        $new_price->set('PRC_ID', 0);
677
-                        $new_price->save();
678
-                        $new_tkt->_add_relation_to($new_price, 'Price');
679
-                        $new_tkt->save();
680
-                    }
681
-
682
-                    do_action(
683
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
684
-                        $orig_tkt,
685
-                        $new_tkt,
686
-                        $orig_prices,
687
-                        $orig_event,
688
-                        $orig_dtt,
689
-                        $new_dtt
690
-                    );
691
-                }
692
-                // k now we can add the new ticket as a relation to the new datetime
693
-                // and make sure its added to our cached $cloned_tickets array
694
-                // for use with later datetimes that have the same ticket.
695
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
696
-                $new_dtt->save();
697
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
698
-            }
699
-        }
700
-        // clone taxonomy information
701
-        $taxonomies_to_clone_with = apply_filters(
702
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
703
-            ['espresso_event_categories', 'espresso_event_type', 'post_tag']
704
-        );
705
-        // get terms for original event (notice)
706
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
707
-        // loop through terms and add them to new event.
708
-        foreach ($orig_terms as $term) {
709
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
710
-        }
711
-
712
-        // duplicate other core WP_Post items for this event.
713
-        // post thumbnail (feature image).
714
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
715
-        if ($feature_image_id) {
716
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
717
-        }
718
-
719
-        // duplicate page_template setting
720
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
721
-        if ($page_template) {
722
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
723
-        }
724
-
725
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
726
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
727
-        if ($new_event->ID()) {
728
-            $redirect_args = [
729
-                'post'   => $new_event->ID(),
730
-                'action' => 'edit',
731
-            ];
732
-            EE_Error::add_success(
733
-                esc_html__(
734
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
735
-                    'event_espresso'
736
-                )
737
-            );
738
-        } else {
739
-            $redirect_args = [
740
-                'action' => 'default',
741
-            ];
742
-            EE_Error::add_error(
743
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
744
-                __FILE__,
745
-                __FUNCTION__,
746
-                __LINE__
747
-            );
748
-        }
749
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
750
-    }
751
-
752
-
753
-    /**
754
-     * Generates output for the import page.
755
-     *
756
-     * @throws DomainException
757
-     * @throws EE_Error
758
-     * @throws InvalidArgumentException
759
-     * @throws InvalidDataTypeException
760
-     * @throws InvalidInterfaceException
761
-     */
762
-    protected function _import_page()
763
-    {
764
-        $title = esc_html__('Import', 'event_espresso');
765
-        $intro = esc_html__(
766
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
767
-            'event_espresso'
768
-        );
769
-        $form_url = EVENTS_ADMIN_URL;
770
-        $action = 'import_events';
771
-        $type = 'csv';
772
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
773
-            $title,
774
-            $intro,
775
-            $form_url,
776
-            $action,
777
-            $type
778
-        );
779
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
780
-            ['action' => 'sample_export_file'],
781
-            $this->_admin_base_url
782
-        );
783
-        $content = EEH_Template::display_template(
784
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
785
-            $this->_template_args,
786
-            true
787
-        );
788
-        $this->_template_args['admin_page_content'] = $content;
789
-        $this->display_admin_page_with_sidebar();
790
-    }
791
-
792
-
793
-    /**
794
-     * _import_events
795
-     * This handles displaying the screen and running imports for importing events.
796
-     *
797
-     * @return void
798
-     * @throws EE_Error
799
-     * @throws InvalidArgumentException
800
-     * @throws InvalidDataTypeException
801
-     * @throws InvalidInterfaceException
802
-     */
803
-    protected function _import_events()
804
-    {
805
-        require_once(EE_CLASSES . 'EE_Import.class.php');
806
-        $success = EE_Import::instance()->import();
807
-        $this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true);
808
-    }
809
-
810
-
811
-    /**
812
-     * _events_export
813
-     * Will export all (or just the given event) to a Excel compatible file.
814
-     *
815
-     * @access protected
816
-     * @return void
817
-     */
818
-    protected function _events_export()
819
-    {
820
-        if (isset($this->_req_data['EVT_ID'])) {
821
-            $event_ids = $this->_req_data['EVT_ID'];
822
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
823
-            $event_ids = $this->_req_data['EVT_IDs'];
824
-        } else {
825
-            $event_ids = null;
826
-        }
827
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
828
-        $new_request_args = [
829
-            'export' => 'report',
830
-            'action' => 'all_event_data',
831
-            'EVT_ID' => $event_ids,
832
-        ];
833
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
834
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
835
-            require_once(EE_CLASSES . 'EE_Export.class.php');
836
-            $EE_Export = EE_Export::instance($this->_req_data);
837
-            if ($EE_Export instanceof EE_Export) {
838
-                $EE_Export->export();
839
-            }
840
-        }
841
-    }
842
-
843
-
844
-    /**
845
-     * handle category exports()
846
-     *
847
-     * @return void
848
-     */
849
-    protected function _categories_export()
850
-    {
851
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
852
-        $new_request_args = [
853
-            'export'       => 'report',
854
-            'action'       => 'categories',
855
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
856
-        ];
857
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
858
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
859
-            require_once(EE_CLASSES . 'EE_Export.class.php');
860
-            $EE_Export = EE_Export::instance($this->_req_data);
861
-            if ($EE_Export instanceof EE_Export) {
862
-                $EE_Export->export();
863
-            }
864
-        }
865
-    }
866
-
867
-
868
-    /**
869
-     * Creates a sample CSV file for importing
870
-     */
871
-    protected function _sample_export_file()
872
-    {
873
-        $EE_Export = EE_Export::instance();
874
-        if ($EE_Export instanceof EE_Export) {
875
-            $EE_Export->export();
876
-        }
877
-    }
878
-
879
-
880
-    /*************        Template Settings        *************/
881
-    /**
882
-     * Generates template settings page output
883
-     *
884
-     * @throws DomainException
885
-     * @throws EE_Error
886
-     * @throws InvalidArgumentException
887
-     * @throws InvalidDataTypeException
888
-     * @throws InvalidInterfaceException
889
-     */
890
-    protected function _template_settings()
891
-    {
892
-        $this->_template_args['values'] = $this->_yes_no_values;
893
-        /**
894
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
895
-         * from General_Settings_Admin_Page to here.
896
-         */
897
-        $this->_template_args = apply_filters(
898
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
899
-            $this->_template_args
900
-        );
901
-        $this->_set_add_edit_form_tags('update_template_settings');
902
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
903
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
904
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
905
-            $this->_template_args,
906
-            true
907
-        );
908
-        $this->display_admin_page_with_sidebar();
909
-    }
910
-
911
-
912
-    /**
913
-     * Handler for updating template settings.
914
-     *
915
-     * @throws EE_Error
916
-     * @throws InvalidArgumentException
917
-     * @throws InvalidDataTypeException
918
-     * @throws InvalidInterfaceException
919
-     */
920
-    protected function _update_template_settings()
921
-    {
922
-        /**
923
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
924
-         * from General_Settings_Admin_Page to here.
925
-         */
926
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
927
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
928
-            EE_Registry::instance()->CFG->template_settings,
929
-            $this->_req_data
930
-        );
931
-        // update custom post type slugs and detect if we need to flush rewrite rules
932
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
933
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
934
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
935
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
936
-        $what = 'Template Settings';
937
-        $success = $this->_update_espresso_configuration(
938
-            $what,
939
-            EE_Registry::instance()->CFG->template_settings,
940
-            __FILE__,
941
-            __FUNCTION__,
942
-            __LINE__
943
-        );
944
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
945
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
946
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
947
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
948
-            );
949
-            $rewrite_rules->flush();
950
-        }
951
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
952
-    }
953
-
954
-
955
-    /**
956
-     * _premium_event_editor_meta_boxes
957
-     * add all metaboxes related to the event_editor
958
-     *
959
-     * @access protected
960
-     * @return void
961
-     * @throws EE_Error
962
-     * @throws InvalidArgumentException
963
-     * @throws InvalidDataTypeException
964
-     * @throws InvalidInterfaceException
965
-     * @throws ReflectionException
966
-     */
967
-    protected function _premium_event_editor_meta_boxes()
968
-    {
969
-        $this->verify_cpt_object();
970
-        /** @var FeatureFlags $flags */
971
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
972
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
973
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
974
-            add_meta_box(
975
-                'espresso_event_editor_event_options',
976
-                esc_html__('Event Registration Options', 'event_espresso'),
977
-                [$this, 'registration_options_meta_box'],
978
-                $this->page_slug,
979
-                'side',
980
-                'core'
981
-            );
982
-        }
983
-    }
984
-
985
-
986
-    /**
987
-     * override caf metabox
988
-     *
989
-     * @return void
990
-     * @throws DomainException
991
-     * @throws EE_Error
992
-     */
993
-    public function registration_options_meta_box()
994
-    {
995
-        $yes_no_values = [
996
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
997
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
998
-        ];
999
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1000
-            [
1001
-                EEM_Registration::status_id_cancelled,
1002
-                EEM_Registration::status_id_declined,
1003
-                EEM_Registration::status_id_incomplete,
1004
-                EEM_Registration::status_id_wait_list,
1005
-            ],
1006
-            true
1007
-        );
1008
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1009
-        $template_args['_event'] = $this->_cpt_model_obj;
1010
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1011
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1012
-            'default_reg_status',
1013
-            $default_reg_status_values,
1014
-            $this->_cpt_model_obj->default_registration_status()
1015
-        );
1016
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1017
-            'display_desc',
1018
-            $yes_no_values,
1019
-            $this->_cpt_model_obj->display_description()
1020
-        );
1021
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1022
-            'display_ticket_selector',
1023
-            $yes_no_values,
1024
-            $this->_cpt_model_obj->display_ticket_selector(),
1025
-            '',
1026
-            '',
1027
-            false
1028
-        );
1029
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1030
-            'EVT_default_registration_status',
1031
-            $default_reg_status_values,
1032
-            $this->_cpt_model_obj->default_registration_status()
1033
-        );
1034
-        $template_args['additional_registration_options'] = apply_filters(
1035
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1036
-            '',
1037
-            $template_args,
1038
-            $yes_no_values,
1039
-            $default_reg_status_values
1040
-        );
1041
-        EEH_Template::display_template(
1042
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1043
-            $template_args
1044
-        );
1045
-    }
1046
-
1047
-
1048
-
1049
-    /**
1050
-     * wp_list_table_mods for caf
1051
-     * ============================
1052
-     */
1053
-    /**
1054
-     * hook into list table filters and provide filters for caffeinated list table
1055
-     *
1056
-     * @param array $old_filters    any existing filters present
1057
-     * @param array $list_table_obj the list table object
1058
-     * @return array                  new filters
1059
-     * @throws EE_Error
1060
-     * @throws InvalidArgumentException
1061
-     * @throws InvalidDataTypeException
1062
-     * @throws InvalidInterfaceException
1063
-     * @throws ReflectionException
1064
-     */
1065
-    public function list_table_filters($old_filters, $list_table_obj)
1066
-    {
1067
-        $filters = [];
1068
-        // first month/year filters
1069
-        $filters[] = $this->espresso_event_months_dropdown();
1070
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1071
-        // active status dropdown
1072
-        if ($status !== 'draft') {
1073
-            $filters[] = $this->active_status_dropdown(
1074
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1075
-            );
1076
-            $filters[] = $this->venuesDropdown(
1077
-                isset($this->_req_data['venue']) ? $this->_req_data['venue'] : ''
1078
-            );
1079
-        }
1080
-        // category filter
1081
-        $filters[] = $this->category_dropdown();
1082
-        return array_merge($old_filters, $filters);
1083
-    }
1084
-
1085
-
1086
-    /**
1087
-     * espresso_event_months_dropdown
1088
-     *
1089
-     * @access public
1090
-     * @return string                dropdown listing month/year selections for events.
1091
-     */
1092
-    public function espresso_event_months_dropdown()
1093
-    {
1094
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1095
-        // Note we need to include any other filters that are set!
1096
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : '';
1097
-        // categories?
1098
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1099
-            ? $this->_req_data['EVT_CAT']
1100
-            : '';
1101
-        // active status?
1102
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '';
1103
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1104
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * returns a list of "active" statuses on the event
1110
-     *
1111
-     * @param string $current_value whatever the current active status is
1112
-     * @return string
1113
-     */
1114
-    public function active_status_dropdown($current_value = '')
1115
-    {
1116
-        $select_name = 'active_status';
1117
-        $values = [
1118
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1119
-            'active'   => esc_html__('Active', 'event_espresso'),
1120
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1121
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1122
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1123
-        ];
1124
-
1125
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1126
-    }
1127
-
1128
-
1129
-
1130
-    /**
1131
-     * returns a list of "venues"
1132
-     *
1133
-     * @param string $current_value whatever the current active status is
1134
-     * @return string
1135
-     * @throws EE_Error
1136
-     * @throws InvalidArgumentException
1137
-     * @throws InvalidDataTypeException
1138
-     * @throws InvalidInterfaceException
1139
-     * @throws ReflectionException
1140
-     */
1141
-    protected function venuesDropdown($current_value = '')
1142
-    {
1143
-        $select_name = 'venue';
1144
-        $values = [
1145
-            '' => esc_html__('All Venues', 'event_espresso'),
1146
-        ];
1147
-        // populate the list of venues.
1148
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1149
-        $venues = $venue_model->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1150
-
1151
-        foreach ($venues as $venue) {
1152
-            $values[ $venue->ID() ] = $venue->name();
1153
-        }
1154
-
1155
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * output a dropdown of the categories for the category filter on the event admin list table
1161
-     *
1162
-     * @access  public
1163
-     * @return string html
1164
-     */
1165
-    public function category_dropdown()
1166
-    {
1167
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1168
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1169
-    }
1170
-
1171
-
1172
-    /**
1173
-     * get total number of events today
1174
-     *
1175
-     * @access public
1176
-     * @return int
1177
-     * @throws EE_Error
1178
-     * @throws InvalidArgumentException
1179
-     * @throws InvalidDataTypeException
1180
-     * @throws InvalidInterfaceException
1181
-     */
1182
-    public function total_events_today()
1183
-    {
1184
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1185
-            'DTT_EVT_start',
1186
-            date('Y-m-d') . ' 00:00:00',
1187
-            'Y-m-d H:i:s',
1188
-            'UTC'
1189
-        );
1190
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1191
-            'DTT_EVT_start',
1192
-            date('Y-m-d') . ' 23:59:59',
1193
-            'Y-m-d H:i:s',
1194
-            'UTC'
1195
-        );
1196
-        $where = [
1197
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1198
-        ];
1199
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * get total number of events this month
1205
-     *
1206
-     * @access public
1207
-     * @return int
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws InvalidDataTypeException
1211
-     * @throws InvalidInterfaceException
1212
-     */
1213
-    public function total_events_this_month()
1214
-    {
1215
-        // Dates
1216
-        $this_year_r = date('Y');
1217
-        $this_month_r = date('m');
1218
-        $days_this_month = date('t');
1219
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1220
-            'DTT_EVT_start',
1221
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1222
-            'Y-m-d H:i:s',
1223
-            'UTC'
1224
-        );
1225
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1226
-            'DTT_EVT_start',
1227
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1228
-            'Y-m-d H:i:s',
1229
-            'UTC'
1230
-        );
1231
-        $where = [
1232
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1233
-        ];
1234
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1235
-    }
1236
-
1237
-
1238
-    /** DEFAULT TICKETS STUFF **/
1239
-
1240
-    /**
1241
-     * Output default tickets list table view.
1242
-     *
1243
-     * @throws DomainException
1244
-     * @throws EE_Error
1245
-     * @throws InvalidArgumentException
1246
-     * @throws InvalidDataTypeException
1247
-     * @throws InvalidInterfaceException
1248
-     */
1249
-    public function _tickets_overview_list_table()
1250
-    {
1251
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1252
-        $this->display_admin_list_table_page_with_no_sidebar();
1253
-    }
1254
-
1255
-
1256
-    /**
1257
-     * @param int  $per_page
1258
-     * @param bool $count
1259
-     * @param bool $trashed
1260
-     * @return EE_Soft_Delete_Base_Class[]|int
1261
-     * @throws EE_Error
1262
-     * @throws InvalidArgumentException
1263
-     * @throws InvalidDataTypeException
1264
-     * @throws InvalidInterfaceException
1265
-     */
1266
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1267
-    {
1268
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1269
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1270
-        switch ($orderby) {
1271
-            case 'TKT_name':
1272
-                $orderby = ['TKT_name' => $order];
1273
-                break;
1274
-            case 'TKT_price':
1275
-                $orderby = ['TKT_price' => $order];
1276
-                break;
1277
-            case 'TKT_uses':
1278
-                $orderby = ['TKT_uses' => $order];
1279
-                break;
1280
-            case 'TKT_min':
1281
-                $orderby = ['TKT_min' => $order];
1282
-                break;
1283
-            case 'TKT_max':
1284
-                $orderby = ['TKT_max' => $order];
1285
-                break;
1286
-            case 'TKT_qty':
1287
-                $orderby = ['TKT_qty' => $order];
1288
-                break;
1289
-        }
1290
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1291
-            ? $this->_req_data['paged']
1292
-            : 1;
1293
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1294
-            ? $this->_req_data['perpage']
1295
-            : $per_page;
1296
-        $_where = [
1297
-            'TKT_is_default' => 1,
1298
-            'TKT_deleted'    => $trashed,
1299
-        ];
1300
-        $offset = ($current_page - 1) * $per_page;
1301
-        $limit = [$offset, $per_page];
1302
-        if (isset($this->_req_data['s'])) {
1303
-            $sstr = '%' . $this->_req_data['s'] . '%';
1304
-            $_where['OR'] = [
1305
-                'TKT_name'        => ['LIKE', $sstr],
1306
-                'TKT_description' => ['LIKE', $sstr],
1307
-            ];
1308
-        }
1309
-        $query_params = [
1310
-            $_where,
1311
-            'order_by' => $orderby,
1312
-            'limit'    => $limit,
1313
-            'group_by' => 'TKT_ID',
1314
-        ];
1315
-        if ($count) {
1316
-            return EEM_Ticket::instance()->count_deleted_and_undeleted([$_where]);
1317
-        }
1318
-        return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1319
-    }
1320
-
1321
-
1322
-    /**
1323
-     * @param bool $trash
1324
-     * @throws EE_Error
1325
-     * @throws InvalidArgumentException
1326
-     * @throws InvalidDataTypeException
1327
-     * @throws InvalidInterfaceException
1328
-     */
1329
-    protected function _trash_or_restore_ticket($trash = false)
1330
-    {
1331
-        $success = 1;
1332
-        $TKT = EEM_Ticket::instance();
1333
-        // checkboxes?
1334
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1335
-            // if array has more than one element then success message should be plural
1336
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1337
-            // cycle thru the boxes
1338
-            foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1339
-                if ($trash) {
1340
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1341
-                        $success = 0;
1342
-                    }
1343
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1344
-                    $success = 0;
1345
-                }
1346
-            }
1347
-        } else {
1348
-            // grab single id and trash
1349
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1350
-            if ($trash) {
1351
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1352
-                    $success = 0;
1353
-                }
1354
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1355
-                $success = 0;
1356
-            }
1357
-        }
1358
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1359
-        $query_args = [
1360
-            'action' => 'ticket_list_table',
1361
-            'status' => $trash ? '' : 'trashed',
1362
-        ];
1363
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1364
-    }
1365
-
1366
-
1367
-    /**
1368
-     * Handles trashing default ticket.
1369
-     *
1370
-     * @throws EE_Error
1371
-     * @throws InvalidArgumentException
1372
-     * @throws InvalidDataTypeException
1373
-     * @throws InvalidInterfaceException
1374
-     * @throws ReflectionException
1375
-     */
1376
-    protected function _delete_ticket()
1377
-    {
1378
-        $success = 1;
1379
-        // checkboxes?
1380
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1381
-            // if array has more than one element then success message should be plural
1382
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1383
-            // cycle thru the boxes
1384
-            foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1385
-                // delete
1386
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1387
-                    $success = 0;
1388
-                }
1389
-            }
1390
-        } else {
1391
-            // grab single id and trash
1392
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1393
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1394
-                $success = 0;
1395
-            }
1396
-        }
1397
-        $action_desc = 'deleted';
1398
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1399
-        $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
1400
-            [['TKT_is_default' => 1]],
1401
-            'TKT_ID',
1402
-            true
1403
-        );
1404
-        $query_args = $ticket_count
1405
-            ? []
1406
-            : [
1407
-                'action' => 'ticket_list_table',
1408
-                'status' => 'trashed',
1409
-            ];
1410
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1411
-    }
1412
-
1413
-
1414
-    /**
1415
-     * @param int $TKT_ID
1416
-     * @return bool|int
1417
-     * @throws EE_Error
1418
-     * @throws InvalidArgumentException
1419
-     * @throws InvalidDataTypeException
1420
-     * @throws InvalidInterfaceException
1421
-     * @throws ReflectionException
1422
-     */
1423
-    protected function _delete_the_ticket($TKT_ID)
1424
-    {
1425
-        $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1426
-        if (! $ticket instanceof EE_Ticket) {
1427
-            return false;
1428
-        }
1429
-        $ticket->_remove_relations('Datetime');
1430
-        // delete all related prices first
1431
-        $ticket->delete_related_permanently('Price');
1432
-        return $ticket->delete_permanently();
1433
-    }
20
+	/**
21
+	 * @var EE_Admin_Config
22
+	 */
23
+	protected $admin_config;
24
+
25
+	/**
26
+	 * @var AdvancedEditorAdminFormSection
27
+	 */
28
+	protected $advanced_editor_admin_form;
29
+
30
+
31
+	/**
32
+	 * Extend_Events_Admin_Page constructor.
33
+	 *
34
+	 * @param bool $routing
35
+	 * @throws ReflectionException
36
+	 */
37
+	public function __construct($routing = true)
38
+	{
39
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
+		}
44
+		parent::__construct($routing);
45
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
+	}
47
+
48
+
49
+	/**
50
+	 * Sets routes.
51
+	 *
52
+	 * @throws EE_Error
53
+	 * @throws InvalidArgumentException
54
+	 * @throws InvalidDataTypeException
55
+	 * @throws InvalidInterfaceException
56
+	 * @throws Exception
57
+	 */
58
+	protected function _extend_page_config()
59
+	{
60
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
61
+		// is there a evt_id in the request?
62
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
63
+			? $this->_req_data['EVT_ID']
64
+			: 0;
65
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
66
+		// tkt_id?
67
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
68
+			? $this->_req_data['TKT_ID']
69
+			: 0;
70
+		$new_page_routes = [
71
+			'duplicate_event'          => [
72
+				'func'       => '_duplicate_event',
73
+				'capability' => 'ee_edit_event',
74
+				'obj_id'     => $evt_id,
75
+				'noheader'   => true,
76
+			],
77
+			'import_page'              => [
78
+				'func'       => '_import_page',
79
+				'capability' => 'import',
80
+			],
81
+			'import'                   => [
82
+				'func'       => '_import_events',
83
+				'capability' => 'import',
84
+				'noheader'   => true,
85
+			],
86
+			'import_events'            => [
87
+				'func'       => '_import_events',
88
+				'capability' => 'import',
89
+				'noheader'   => true,
90
+			],
91
+			'export_events'            => [
92
+				'func'       => '_events_export',
93
+				'capability' => 'export',
94
+				'noheader'   => true,
95
+			],
96
+			'export_categories'        => [
97
+				'func'       => '_categories_export',
98
+				'capability' => 'export',
99
+				'noheader'   => true,
100
+			],
101
+			'sample_export_file'       => [
102
+				'func'       => '_sample_export_file',
103
+				'capability' => 'export',
104
+				'noheader'   => true,
105
+			],
106
+			'update_template_settings' => [
107
+				'func'       => '_update_template_settings',
108
+				'capability' => 'manage_options',
109
+				'noheader'   => true,
110
+			],
111
+		];        // don't load these meta boxes if using the advanced editor
112
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
113
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
114
+		if (! $this->admin_config->useAdvancedEditor()) {
115
+			$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
116
+			$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
117
+
118
+			$legacy_editor_page_routes = [
119
+				'ticket_list_table' => [
120
+					'func'       => '_tickets_overview_list_table',
121
+					'capability' => 'ee_read_default_tickets',
122
+				],
123
+				'trash_ticket'      => [
124
+					'func'       => '_trash_or_restore_ticket',
125
+					'capability' => 'ee_delete_default_ticket',
126
+					'obj_id'     => $tkt_id,
127
+					'noheader'   => true,
128
+					'args'       => ['trash' => true],
129
+				],
130
+				'trash_tickets'     => [
131
+					'func'       => '_trash_or_restore_ticket',
132
+					'capability' => 'ee_delete_default_tickets',
133
+					'noheader'   => true,
134
+					'args'       => ['trash' => true],
135
+				],
136
+				'restore_ticket'    => [
137
+					'func'       => '_trash_or_restore_ticket',
138
+					'capability' => 'ee_delete_default_ticket',
139
+					'obj_id'     => $tkt_id,
140
+					'noheader'   => true,
141
+				],
142
+				'restore_tickets'   => [
143
+					'func'       => '_trash_or_restore_ticket',
144
+					'capability' => 'ee_delete_default_tickets',
145
+					'noheader'   => true,
146
+				],
147
+				'delete_ticket'     => [
148
+					'func'       => '_delete_ticket',
149
+					'capability' => 'ee_delete_default_ticket',
150
+					'obj_id'     => $tkt_id,
151
+					'noheader'   => true,
152
+				],
153
+				'delete_tickets'    => [
154
+					'func'       => '_delete_ticket',
155
+					'capability' => 'ee_delete_default_tickets',
156
+					'noheader'   => true,
157
+				],
158
+			];
159
+			$new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes);
160
+		}
161
+
162
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
163
+		// partial route/config override
164
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
165
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
166
+		// add tickets tab but only if there are more than one default ticket!
167
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
168
+			[['TKT_is_default' => 1]],
169
+			'TKT_ID',
170
+			true
171
+		);
172
+		if ($tkt_count > 1) {
173
+			$new_page_config = [
174
+				'ticket_list_table' => [
175
+					'nav'           => [
176
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
177
+						'order' => 60,
178
+					],
179
+					'list_table'    => 'Tickets_List_Table',
180
+					'require_nonce' => false,
181
+				],
182
+			];
183
+		}
184
+		// template settings
185
+		$new_page_config['template_settings'] = [
186
+			'nav'           => [
187
+				'label' => esc_html__('Templates', 'event_espresso'),
188
+				'order' => 30,
189
+			],
190
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
191
+			'help_tabs'     => [
192
+				'general_settings_templates_help_tab' => [
193
+					'title'    => esc_html__('Templates', 'event_espresso'),
194
+					'filename' => 'general_settings_templates',
195
+				],
196
+			],
197
+		   // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
198
+			// 'help_tour'     => ['Templates_Help_Tour'],
199
+			'require_nonce' => false,
200
+		];
201
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
202
+		// add filters and actions
203
+		// modifying _views
204
+		add_filter(
205
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
206
+			[$this, 'add_additional_datetime_button'],
207
+			10,
208
+			2
209
+		);
210
+		add_filter(
211
+			'FHEE_event_datetime_metabox_clone_button_template',
212
+			[$this, 'add_datetime_clone_button'],
213
+			10,
214
+			2
215
+		);
216
+		add_filter(
217
+			'FHEE_event_datetime_metabox_timezones_template',
218
+			[$this, 'datetime_timezones_template'],
219
+			10,
220
+			2
221
+		);
222
+		// filters for event list table
223
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
224
+		add_filter(
225
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
226
+			[$this, 'extra_list_table_actions'],
227
+			10,
228
+			2
229
+		);
230
+		// legend item
231
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
232
+		add_action('admin_init', [$this, 'admin_init']);
233
+		// load additional handlers
234
+		$this->handleActionRequest();
235
+	}
236
+
237
+
238
+	private function getRequestAction()
239
+	{
240
+		return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null;
241
+	}
242
+
243
+
244
+	/**
245
+	 * @throws Exception
246
+	 */
247
+	private function handleActionRequest()
248
+	{
249
+		$action = $this->getRequestAction();
250
+		if ($action) {
251
+			// setup Advanced Editor ???
252
+			if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
253
+				$this->advanced_editor_admin_form = $this->loader->getShared(
254
+					'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
255
+				);
256
+			}
257
+		}
258
+	}
259
+
260
+
261
+	/**
262
+	 * admin_init
263
+	 */
264
+	public function admin_init()
265
+	{
266
+		EE_Registry::$i18n_js_strings = array_merge(
267
+			EE_Registry::$i18n_js_strings,
268
+			[
269
+				'image_confirm'          => esc_html__(
270
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
271
+					'event_espresso'
272
+				),
273
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
274
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
275
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
276
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
277
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
278
+			]
279
+		);
280
+	}
281
+
282
+
283
+	/**
284
+	 * Add per page screen options to the default ticket list table view.
285
+	 *
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidDataTypeException
288
+	 * @throws InvalidInterfaceException
289
+	 */
290
+	protected function _add_screen_options_ticket_list_table()
291
+	{
292
+		$this->_per_page_screen_option();
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param string $return
298
+	 * @param int    $id
299
+	 * @param string $new_title
300
+	 * @param string $new_slug
301
+	 * @return string
302
+	 */
303
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
304
+	{
305
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
306
+		// make sure this is only when editing
307
+		if (! empty($id)) {
308
+			$href = EE_Admin_Page::add_query_args_and_nonce(
309
+				['action' => 'duplicate_event', 'EVT_ID' => $id],
310
+				$this->_admin_base_url
311
+			);
312
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
313
+			$return .= '<a href="'
314
+					   . $href
315
+					   . '" title="'
316
+					   . $title
317
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
318
+					   . $title
319
+					   . '</a>';
320
+		}
321
+		return $return;
322
+	}
323
+
324
+
325
+	/**
326
+	 * Set the list table views for the default ticket list table view.
327
+	 */
328
+	public function _set_list_table_views_ticket_list_table()
329
+	{
330
+		$this->_views = [
331
+			'all'     => [
332
+				'slug'        => 'all',
333
+				'label'       => esc_html__('All', 'event_espresso'),
334
+				'count'       => 0,
335
+				'bulk_action' => [
336
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
337
+				],
338
+			],
339
+			'trashed' => [
340
+				'slug'        => 'trashed',
341
+				'label'       => esc_html__('Trash', 'event_espresso'),
342
+				'count'       => 0,
343
+				'bulk_action' => [
344
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
345
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
346
+				],
347
+			],
348
+		];
349
+	}
350
+
351
+
352
+	/**
353
+	 * Enqueue scripts and styles for the event editor.
354
+	 */
355
+	public function load_scripts_styles_edit()
356
+	{
357
+		if (! $this->admin_config->useAdvancedEditor()) {
358
+			wp_register_script(
359
+				'ee-event-editor-heartbeat',
360
+				EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
361
+				['ee_admin_js', 'heartbeat'],
362
+				EVENT_ESPRESSO_VERSION,
363
+				true
364
+			);
365
+			wp_enqueue_script('ee-accounting');
366
+			wp_enqueue_script('ee-event-editor-heartbeat');
367
+		}
368
+		wp_enqueue_script('event_editor_js');
369
+		// styles
370
+		wp_enqueue_style('espresso-ui-theme');
371
+	}
372
+
373
+
374
+	/**
375
+	 * Returns template for the additional datetime.
376
+	 *
377
+	 * @param $template
378
+	 * @param $template_args
379
+	 * @return mixed
380
+	 * @throws DomainException
381
+	 */
382
+	public function add_additional_datetime_button($template, $template_args)
383
+	{
384
+		return EEH_Template::display_template(
385
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
386
+			$template_args,
387
+			true
388
+		);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Returns the template for cloning a datetime.
394
+	 *
395
+	 * @param $template
396
+	 * @param $template_args
397
+	 * @return mixed
398
+	 * @throws DomainException
399
+	 */
400
+	public function add_datetime_clone_button($template, $template_args)
401
+	{
402
+		return EEH_Template::display_template(
403
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
404
+			$template_args,
405
+			true
406
+		);
407
+	}
408
+
409
+
410
+	/**
411
+	 * Returns the template for datetime timezones.
412
+	 *
413
+	 * @param $template
414
+	 * @param $template_args
415
+	 * @return mixed
416
+	 * @throws DomainException
417
+	 */
418
+	public function datetime_timezones_template($template, $template_args)
419
+	{
420
+		return EEH_Template::display_template(
421
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
422
+			$template_args,
423
+			true
424
+		);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Sets the views for the default list table view.
430
+	 *
431
+	 * @throws EE_Error
432
+	 */
433
+	protected function _set_list_table_views_default()
434
+	{
435
+		parent::_set_list_table_views_default();
436
+		$new_views = [
437
+			'today' => [
438
+				'slug'        => 'today',
439
+				'label'       => esc_html__('Today', 'event_espresso'),
440
+				'count'       => $this->total_events_today(),
441
+				'bulk_action' => [
442
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
443
+				],
444
+			],
445
+			'month' => [
446
+				'slug'        => 'month',
447
+				'label'       => esc_html__('This Month', 'event_espresso'),
448
+				'count'       => $this->total_events_this_month(),
449
+				'bulk_action' => [
450
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
451
+				],
452
+			],
453
+		];
454
+		$this->_views = array_merge($this->_views, $new_views);
455
+	}
456
+
457
+
458
+	/**
459
+	 * Returns the extra action links for the default list table view.
460
+	 *
461
+	 * @param array    $action_links
462
+	 * @param EE_Event $event
463
+	 * @return array
464
+	 * @throws EE_Error
465
+	 * @throws InvalidArgumentException
466
+	 * @throws InvalidDataTypeException
467
+	 * @throws InvalidInterfaceException
468
+	 * @throws ReflectionException
469
+	 */
470
+	public function extra_list_table_actions(array $action_links, EE_Event $event)
471
+	{
472
+		if (
473
+			EE_Registry::instance()->CAP->current_user_can(
474
+				'ee_read_registrations',
475
+				'espresso_registrations_reports',
476
+				$event->ID()
477
+			)
478
+		) {
479
+			$reports_query_args = [
480
+				'action' => 'reports',
481
+				'EVT_ID' => $event->ID(),
482
+			];
483
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
484
+			$action_links[] = '<a href="'
485
+							  . $reports_link
486
+							  . '" title="'
487
+							  . esc_attr__('View Report', 'event_espresso')
488
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
489
+							  . "\n\t";
490
+		}
491
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
492
+			EE_Registry::instance()->load_helper('MSG_Template');
493
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
494
+				'see_notifications_for',
495
+				null,
496
+				['EVT_ID' => $event->ID()]
497
+			);
498
+		}
499
+		return $action_links;
500
+	}
501
+
502
+
503
+	/**
504
+	 * @param $items
505
+	 * @return mixed
506
+	 */
507
+	public function additional_legend_items($items)
508
+	{
509
+		if (
510
+			EE_Registry::instance()->CAP->current_user_can(
511
+				'ee_read_registrations',
512
+				'espresso_registrations_reports'
513
+			)
514
+		) {
515
+			$items['reports'] = [
516
+				'class' => 'dashicons dashicons-chart-bar',
517
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
518
+			];
519
+		}
520
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
521
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
522
+			// $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
523
+			// (can only use numeric offsets when treating strings as arrays)
524
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
525
+				$items['view_related_messages'] = [
526
+					'class' => $related_for_icon['css_class'],
527
+					'desc'  => $related_for_icon['label'],
528
+				];
529
+			}
530
+		}
531
+		return $items;
532
+	}
533
+
534
+
535
+	/**
536
+	 * This is the callback method for the duplicate event route
537
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
538
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
539
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
540
+	 * After duplication the redirect is to the new event edit page.
541
+	 *
542
+	 * @return void
543
+	 * @throws EE_Error If EE_Event is not available with given ID
544
+	 * @throws InvalidArgumentException
545
+	 * @throws InvalidDataTypeException
546
+	 * @throws InvalidInterfaceException
547
+	 * @throws ReflectionException
548
+	 * @access protected
549
+	 */
550
+	protected function _duplicate_event()
551
+	{
552
+		// first make sure the ID for the event is in the request.
553
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
554
+		if (! isset($this->_req_data['EVT_ID'])) {
555
+			EE_Error::add_error(
556
+				esc_html__(
557
+					'In order to duplicate an event an Event ID is required.  None was given.',
558
+					'event_espresso'
559
+				),
560
+				__FILE__,
561
+				__FUNCTION__,
562
+				__LINE__
563
+			);
564
+			$this->_redirect_after_action(false, '', '', [], true);
565
+			return;
566
+		}
567
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
568
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
569
+		if (! $orig_event instanceof EE_Event) {
570
+			throw new EE_Error(
571
+				sprintf(
572
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
573
+					$this->_req_data['EVT_ID']
574
+				)
575
+			);
576
+		}
577
+		// k now let's clone the $orig_event before getting relations
578
+		$new_event = clone $orig_event;
579
+		// original datetimes
580
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
581
+		// other original relations
582
+		$orig_ven = $orig_event->get_many_related('Venue');
583
+		// reset the ID and modify other details to make it clear this is a dupe
584
+		$new_event->set('EVT_ID', 0);
585
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
586
+		$new_event->set('EVT_name', $new_name);
587
+		$new_event->set(
588
+			'EVT_slug',
589
+			wp_unique_post_slug(
590
+				sanitize_title($orig_event->name()),
591
+				0,
592
+				'publish',
593
+				'espresso_events',
594
+				0
595
+			)
596
+		);
597
+		$new_event->set('status', 'draft');
598
+		// duplicate discussion settings
599
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
600
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
601
+		// save the new event
602
+		$new_event->save();
603
+		// venues
604
+		foreach ($orig_ven as $ven) {
605
+			$new_event->_add_relation_to($ven, 'Venue');
606
+		}
607
+		$new_event->save();
608
+		// now we need to get the question group relations and handle that
609
+		// first primary question groups
610
+		$orig_primary_qgs = $orig_event->get_many_related(
611
+			'Question_Group',
612
+			[['Event_Question_Group.EQG_primary' => true]]
613
+		);
614
+		if (! empty($orig_primary_qgs)) {
615
+			foreach ($orig_primary_qgs as $id => $obj) {
616
+				if ($obj instanceof EE_Question_Group) {
617
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
618
+				}
619
+			}
620
+		}
621
+		// next additional attendee question groups
622
+		$orig_additional_qgs = $orig_event->get_many_related(
623
+			'Question_Group',
624
+			[['Event_Question_Group.EQG_additional' => true]]
625
+		);
626
+		if (! empty($orig_additional_qgs)) {
627
+			foreach ($orig_additional_qgs as $id => $obj) {
628
+				if ($obj instanceof EE_Question_Group) {
629
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
630
+				}
631
+			}
632
+		}
633
+
634
+		$new_event->save();
635
+
636
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
637
+		$cloned_tickets = [];
638
+		foreach ($orig_datetimes as $orig_dtt) {
639
+			if (! $orig_dtt instanceof EE_Datetime) {
640
+				continue;
641
+			}
642
+			$new_dtt = clone $orig_dtt;
643
+			$orig_tkts = $orig_dtt->tickets();
644
+			// save new dtt then add to event
645
+			$new_dtt->set('DTT_ID', 0);
646
+			$new_dtt->set('DTT_sold', 0);
647
+			$new_dtt->set_reserved(0);
648
+			$new_dtt->save();
649
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
650
+			$new_event->save();
651
+			// now let's get the ticket relations setup.
652
+			foreach ((array) $orig_tkts as $orig_tkt) {
653
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
654
+				if (! $orig_tkt instanceof EE_Ticket) {
655
+					continue;
656
+				}
657
+				// is this ticket archived?  If it is then let's skip
658
+				if ($orig_tkt->get('TKT_deleted')) {
659
+					continue;
660
+				}
661
+				// does this original ticket already exist in the clone_tickets cache?
662
+				//  If so we'll just use the new ticket from it.
663
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
664
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
665
+				} else {
666
+					$new_tkt = clone $orig_tkt;
667
+					// get relations on the $orig_tkt that we need to setup.
668
+					$orig_prices = $orig_tkt->prices();
669
+					$new_tkt->set('TKT_ID', 0);
670
+					$new_tkt->set('TKT_sold', 0);
671
+					$new_tkt->set('TKT_reserved', 0);
672
+					$new_tkt->save(); // make sure new ticket has ID.
673
+					// price relations on new ticket need to be setup.
674
+					foreach ($orig_prices as $orig_price) {
675
+						$new_price = clone $orig_price;
676
+						$new_price->set('PRC_ID', 0);
677
+						$new_price->save();
678
+						$new_tkt->_add_relation_to($new_price, 'Price');
679
+						$new_tkt->save();
680
+					}
681
+
682
+					do_action(
683
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
684
+						$orig_tkt,
685
+						$new_tkt,
686
+						$orig_prices,
687
+						$orig_event,
688
+						$orig_dtt,
689
+						$new_dtt
690
+					);
691
+				}
692
+				// k now we can add the new ticket as a relation to the new datetime
693
+				// and make sure its added to our cached $cloned_tickets array
694
+				// for use with later datetimes that have the same ticket.
695
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
696
+				$new_dtt->save();
697
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
698
+			}
699
+		}
700
+		// clone taxonomy information
701
+		$taxonomies_to_clone_with = apply_filters(
702
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
703
+			['espresso_event_categories', 'espresso_event_type', 'post_tag']
704
+		);
705
+		// get terms for original event (notice)
706
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
707
+		// loop through terms and add them to new event.
708
+		foreach ($orig_terms as $term) {
709
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
710
+		}
711
+
712
+		// duplicate other core WP_Post items for this event.
713
+		// post thumbnail (feature image).
714
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
715
+		if ($feature_image_id) {
716
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
717
+		}
718
+
719
+		// duplicate page_template setting
720
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
721
+		if ($page_template) {
722
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
723
+		}
724
+
725
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
726
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
727
+		if ($new_event->ID()) {
728
+			$redirect_args = [
729
+				'post'   => $new_event->ID(),
730
+				'action' => 'edit',
731
+			];
732
+			EE_Error::add_success(
733
+				esc_html__(
734
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
735
+					'event_espresso'
736
+				)
737
+			);
738
+		} else {
739
+			$redirect_args = [
740
+				'action' => 'default',
741
+			];
742
+			EE_Error::add_error(
743
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
744
+				__FILE__,
745
+				__FUNCTION__,
746
+				__LINE__
747
+			);
748
+		}
749
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
750
+	}
751
+
752
+
753
+	/**
754
+	 * Generates output for the import page.
755
+	 *
756
+	 * @throws DomainException
757
+	 * @throws EE_Error
758
+	 * @throws InvalidArgumentException
759
+	 * @throws InvalidDataTypeException
760
+	 * @throws InvalidInterfaceException
761
+	 */
762
+	protected function _import_page()
763
+	{
764
+		$title = esc_html__('Import', 'event_espresso');
765
+		$intro = esc_html__(
766
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
767
+			'event_espresso'
768
+		);
769
+		$form_url = EVENTS_ADMIN_URL;
770
+		$action = 'import_events';
771
+		$type = 'csv';
772
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
773
+			$title,
774
+			$intro,
775
+			$form_url,
776
+			$action,
777
+			$type
778
+		);
779
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
780
+			['action' => 'sample_export_file'],
781
+			$this->_admin_base_url
782
+		);
783
+		$content = EEH_Template::display_template(
784
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
785
+			$this->_template_args,
786
+			true
787
+		);
788
+		$this->_template_args['admin_page_content'] = $content;
789
+		$this->display_admin_page_with_sidebar();
790
+	}
791
+
792
+
793
+	/**
794
+	 * _import_events
795
+	 * This handles displaying the screen and running imports for importing events.
796
+	 *
797
+	 * @return void
798
+	 * @throws EE_Error
799
+	 * @throws InvalidArgumentException
800
+	 * @throws InvalidDataTypeException
801
+	 * @throws InvalidInterfaceException
802
+	 */
803
+	protected function _import_events()
804
+	{
805
+		require_once(EE_CLASSES . 'EE_Import.class.php');
806
+		$success = EE_Import::instance()->import();
807
+		$this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true);
808
+	}
809
+
810
+
811
+	/**
812
+	 * _events_export
813
+	 * Will export all (or just the given event) to a Excel compatible file.
814
+	 *
815
+	 * @access protected
816
+	 * @return void
817
+	 */
818
+	protected function _events_export()
819
+	{
820
+		if (isset($this->_req_data['EVT_ID'])) {
821
+			$event_ids = $this->_req_data['EVT_ID'];
822
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
823
+			$event_ids = $this->_req_data['EVT_IDs'];
824
+		} else {
825
+			$event_ids = null;
826
+		}
827
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
828
+		$new_request_args = [
829
+			'export' => 'report',
830
+			'action' => 'all_event_data',
831
+			'EVT_ID' => $event_ids,
832
+		];
833
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
834
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
835
+			require_once(EE_CLASSES . 'EE_Export.class.php');
836
+			$EE_Export = EE_Export::instance($this->_req_data);
837
+			if ($EE_Export instanceof EE_Export) {
838
+				$EE_Export->export();
839
+			}
840
+		}
841
+	}
842
+
843
+
844
+	/**
845
+	 * handle category exports()
846
+	 *
847
+	 * @return void
848
+	 */
849
+	protected function _categories_export()
850
+	{
851
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
852
+		$new_request_args = [
853
+			'export'       => 'report',
854
+			'action'       => 'categories',
855
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
856
+		];
857
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
858
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
859
+			require_once(EE_CLASSES . 'EE_Export.class.php');
860
+			$EE_Export = EE_Export::instance($this->_req_data);
861
+			if ($EE_Export instanceof EE_Export) {
862
+				$EE_Export->export();
863
+			}
864
+		}
865
+	}
866
+
867
+
868
+	/**
869
+	 * Creates a sample CSV file for importing
870
+	 */
871
+	protected function _sample_export_file()
872
+	{
873
+		$EE_Export = EE_Export::instance();
874
+		if ($EE_Export instanceof EE_Export) {
875
+			$EE_Export->export();
876
+		}
877
+	}
878
+
879
+
880
+	/*************        Template Settings        *************/
881
+	/**
882
+	 * Generates template settings page output
883
+	 *
884
+	 * @throws DomainException
885
+	 * @throws EE_Error
886
+	 * @throws InvalidArgumentException
887
+	 * @throws InvalidDataTypeException
888
+	 * @throws InvalidInterfaceException
889
+	 */
890
+	protected function _template_settings()
891
+	{
892
+		$this->_template_args['values'] = $this->_yes_no_values;
893
+		/**
894
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
895
+		 * from General_Settings_Admin_Page to here.
896
+		 */
897
+		$this->_template_args = apply_filters(
898
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
899
+			$this->_template_args
900
+		);
901
+		$this->_set_add_edit_form_tags('update_template_settings');
902
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
903
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
904
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
905
+			$this->_template_args,
906
+			true
907
+		);
908
+		$this->display_admin_page_with_sidebar();
909
+	}
910
+
911
+
912
+	/**
913
+	 * Handler for updating template settings.
914
+	 *
915
+	 * @throws EE_Error
916
+	 * @throws InvalidArgumentException
917
+	 * @throws InvalidDataTypeException
918
+	 * @throws InvalidInterfaceException
919
+	 */
920
+	protected function _update_template_settings()
921
+	{
922
+		/**
923
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
924
+		 * from General_Settings_Admin_Page to here.
925
+		 */
926
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
927
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
928
+			EE_Registry::instance()->CFG->template_settings,
929
+			$this->_req_data
930
+		);
931
+		// update custom post type slugs and detect if we need to flush rewrite rules
932
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
933
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
934
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
935
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
936
+		$what = 'Template Settings';
937
+		$success = $this->_update_espresso_configuration(
938
+			$what,
939
+			EE_Registry::instance()->CFG->template_settings,
940
+			__FILE__,
941
+			__FUNCTION__,
942
+			__LINE__
943
+		);
944
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
945
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
946
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
947
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
948
+			);
949
+			$rewrite_rules->flush();
950
+		}
951
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
952
+	}
953
+
954
+
955
+	/**
956
+	 * _premium_event_editor_meta_boxes
957
+	 * add all metaboxes related to the event_editor
958
+	 *
959
+	 * @access protected
960
+	 * @return void
961
+	 * @throws EE_Error
962
+	 * @throws InvalidArgumentException
963
+	 * @throws InvalidDataTypeException
964
+	 * @throws InvalidInterfaceException
965
+	 * @throws ReflectionException
966
+	 */
967
+	protected function _premium_event_editor_meta_boxes()
968
+	{
969
+		$this->verify_cpt_object();
970
+		/** @var FeatureFlags $flags */
971
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
972
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
973
+		if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
974
+			add_meta_box(
975
+				'espresso_event_editor_event_options',
976
+				esc_html__('Event Registration Options', 'event_espresso'),
977
+				[$this, 'registration_options_meta_box'],
978
+				$this->page_slug,
979
+				'side',
980
+				'core'
981
+			);
982
+		}
983
+	}
984
+
985
+
986
+	/**
987
+	 * override caf metabox
988
+	 *
989
+	 * @return void
990
+	 * @throws DomainException
991
+	 * @throws EE_Error
992
+	 */
993
+	public function registration_options_meta_box()
994
+	{
995
+		$yes_no_values = [
996
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
997
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
998
+		];
999
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1000
+			[
1001
+				EEM_Registration::status_id_cancelled,
1002
+				EEM_Registration::status_id_declined,
1003
+				EEM_Registration::status_id_incomplete,
1004
+				EEM_Registration::status_id_wait_list,
1005
+			],
1006
+			true
1007
+		);
1008
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1009
+		$template_args['_event'] = $this->_cpt_model_obj;
1010
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1011
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1012
+			'default_reg_status',
1013
+			$default_reg_status_values,
1014
+			$this->_cpt_model_obj->default_registration_status()
1015
+		);
1016
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1017
+			'display_desc',
1018
+			$yes_no_values,
1019
+			$this->_cpt_model_obj->display_description()
1020
+		);
1021
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1022
+			'display_ticket_selector',
1023
+			$yes_no_values,
1024
+			$this->_cpt_model_obj->display_ticket_selector(),
1025
+			'',
1026
+			'',
1027
+			false
1028
+		);
1029
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1030
+			'EVT_default_registration_status',
1031
+			$default_reg_status_values,
1032
+			$this->_cpt_model_obj->default_registration_status()
1033
+		);
1034
+		$template_args['additional_registration_options'] = apply_filters(
1035
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1036
+			'',
1037
+			$template_args,
1038
+			$yes_no_values,
1039
+			$default_reg_status_values
1040
+		);
1041
+		EEH_Template::display_template(
1042
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1043
+			$template_args
1044
+		);
1045
+	}
1046
+
1047
+
1048
+
1049
+	/**
1050
+	 * wp_list_table_mods for caf
1051
+	 * ============================
1052
+	 */
1053
+	/**
1054
+	 * hook into list table filters and provide filters for caffeinated list table
1055
+	 *
1056
+	 * @param array $old_filters    any existing filters present
1057
+	 * @param array $list_table_obj the list table object
1058
+	 * @return array                  new filters
1059
+	 * @throws EE_Error
1060
+	 * @throws InvalidArgumentException
1061
+	 * @throws InvalidDataTypeException
1062
+	 * @throws InvalidInterfaceException
1063
+	 * @throws ReflectionException
1064
+	 */
1065
+	public function list_table_filters($old_filters, $list_table_obj)
1066
+	{
1067
+		$filters = [];
1068
+		// first month/year filters
1069
+		$filters[] = $this->espresso_event_months_dropdown();
1070
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1071
+		// active status dropdown
1072
+		if ($status !== 'draft') {
1073
+			$filters[] = $this->active_status_dropdown(
1074
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
1075
+			);
1076
+			$filters[] = $this->venuesDropdown(
1077
+				isset($this->_req_data['venue']) ? $this->_req_data['venue'] : ''
1078
+			);
1079
+		}
1080
+		// category filter
1081
+		$filters[] = $this->category_dropdown();
1082
+		return array_merge($old_filters, $filters);
1083
+	}
1084
+
1085
+
1086
+	/**
1087
+	 * espresso_event_months_dropdown
1088
+	 *
1089
+	 * @access public
1090
+	 * @return string                dropdown listing month/year selections for events.
1091
+	 */
1092
+	public function espresso_event_months_dropdown()
1093
+	{
1094
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1095
+		// Note we need to include any other filters that are set!
1096
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : '';
1097
+		// categories?
1098
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1099
+			? $this->_req_data['EVT_CAT']
1100
+			: '';
1101
+		// active status?
1102
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '';
1103
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1104
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * returns a list of "active" statuses on the event
1110
+	 *
1111
+	 * @param string $current_value whatever the current active status is
1112
+	 * @return string
1113
+	 */
1114
+	public function active_status_dropdown($current_value = '')
1115
+	{
1116
+		$select_name = 'active_status';
1117
+		$values = [
1118
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1119
+			'active'   => esc_html__('Active', 'event_espresso'),
1120
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1121
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1122
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1123
+		];
1124
+
1125
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1126
+	}
1127
+
1128
+
1129
+
1130
+	/**
1131
+	 * returns a list of "venues"
1132
+	 *
1133
+	 * @param string $current_value whatever the current active status is
1134
+	 * @return string
1135
+	 * @throws EE_Error
1136
+	 * @throws InvalidArgumentException
1137
+	 * @throws InvalidDataTypeException
1138
+	 * @throws InvalidInterfaceException
1139
+	 * @throws ReflectionException
1140
+	 */
1141
+	protected function venuesDropdown($current_value = '')
1142
+	{
1143
+		$select_name = 'venue';
1144
+		$values = [
1145
+			'' => esc_html__('All Venues', 'event_espresso'),
1146
+		];
1147
+		// populate the list of venues.
1148
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1149
+		$venues = $venue_model->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1150
+
1151
+		foreach ($venues as $venue) {
1152
+			$values[ $venue->ID() ] = $venue->name();
1153
+		}
1154
+
1155
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * output a dropdown of the categories for the category filter on the event admin list table
1161
+	 *
1162
+	 * @access  public
1163
+	 * @return string html
1164
+	 */
1165
+	public function category_dropdown()
1166
+	{
1167
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1168
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1169
+	}
1170
+
1171
+
1172
+	/**
1173
+	 * get total number of events today
1174
+	 *
1175
+	 * @access public
1176
+	 * @return int
1177
+	 * @throws EE_Error
1178
+	 * @throws InvalidArgumentException
1179
+	 * @throws InvalidDataTypeException
1180
+	 * @throws InvalidInterfaceException
1181
+	 */
1182
+	public function total_events_today()
1183
+	{
1184
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1185
+			'DTT_EVT_start',
1186
+			date('Y-m-d') . ' 00:00:00',
1187
+			'Y-m-d H:i:s',
1188
+			'UTC'
1189
+		);
1190
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1191
+			'DTT_EVT_start',
1192
+			date('Y-m-d') . ' 23:59:59',
1193
+			'Y-m-d H:i:s',
1194
+			'UTC'
1195
+		);
1196
+		$where = [
1197
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1198
+		];
1199
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * get total number of events this month
1205
+	 *
1206
+	 * @access public
1207
+	 * @return int
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws InvalidDataTypeException
1211
+	 * @throws InvalidInterfaceException
1212
+	 */
1213
+	public function total_events_this_month()
1214
+	{
1215
+		// Dates
1216
+		$this_year_r = date('Y');
1217
+		$this_month_r = date('m');
1218
+		$days_this_month = date('t');
1219
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1220
+			'DTT_EVT_start',
1221
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1222
+			'Y-m-d H:i:s',
1223
+			'UTC'
1224
+		);
1225
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1226
+			'DTT_EVT_start',
1227
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1228
+			'Y-m-d H:i:s',
1229
+			'UTC'
1230
+		);
1231
+		$where = [
1232
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1233
+		];
1234
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1235
+	}
1236
+
1237
+
1238
+	/** DEFAULT TICKETS STUFF **/
1239
+
1240
+	/**
1241
+	 * Output default tickets list table view.
1242
+	 *
1243
+	 * @throws DomainException
1244
+	 * @throws EE_Error
1245
+	 * @throws InvalidArgumentException
1246
+	 * @throws InvalidDataTypeException
1247
+	 * @throws InvalidInterfaceException
1248
+	 */
1249
+	public function _tickets_overview_list_table()
1250
+	{
1251
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1252
+		$this->display_admin_list_table_page_with_no_sidebar();
1253
+	}
1254
+
1255
+
1256
+	/**
1257
+	 * @param int  $per_page
1258
+	 * @param bool $count
1259
+	 * @param bool $trashed
1260
+	 * @return EE_Soft_Delete_Base_Class[]|int
1261
+	 * @throws EE_Error
1262
+	 * @throws InvalidArgumentException
1263
+	 * @throws InvalidDataTypeException
1264
+	 * @throws InvalidInterfaceException
1265
+	 */
1266
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1267
+	{
1268
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1269
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1270
+		switch ($orderby) {
1271
+			case 'TKT_name':
1272
+				$orderby = ['TKT_name' => $order];
1273
+				break;
1274
+			case 'TKT_price':
1275
+				$orderby = ['TKT_price' => $order];
1276
+				break;
1277
+			case 'TKT_uses':
1278
+				$orderby = ['TKT_uses' => $order];
1279
+				break;
1280
+			case 'TKT_min':
1281
+				$orderby = ['TKT_min' => $order];
1282
+				break;
1283
+			case 'TKT_max':
1284
+				$orderby = ['TKT_max' => $order];
1285
+				break;
1286
+			case 'TKT_qty':
1287
+				$orderby = ['TKT_qty' => $order];
1288
+				break;
1289
+		}
1290
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1291
+			? $this->_req_data['paged']
1292
+			: 1;
1293
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1294
+			? $this->_req_data['perpage']
1295
+			: $per_page;
1296
+		$_where = [
1297
+			'TKT_is_default' => 1,
1298
+			'TKT_deleted'    => $trashed,
1299
+		];
1300
+		$offset = ($current_page - 1) * $per_page;
1301
+		$limit = [$offset, $per_page];
1302
+		if (isset($this->_req_data['s'])) {
1303
+			$sstr = '%' . $this->_req_data['s'] . '%';
1304
+			$_where['OR'] = [
1305
+				'TKT_name'        => ['LIKE', $sstr],
1306
+				'TKT_description' => ['LIKE', $sstr],
1307
+			];
1308
+		}
1309
+		$query_params = [
1310
+			$_where,
1311
+			'order_by' => $orderby,
1312
+			'limit'    => $limit,
1313
+			'group_by' => 'TKT_ID',
1314
+		];
1315
+		if ($count) {
1316
+			return EEM_Ticket::instance()->count_deleted_and_undeleted([$_where]);
1317
+		}
1318
+		return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1319
+	}
1320
+
1321
+
1322
+	/**
1323
+	 * @param bool $trash
1324
+	 * @throws EE_Error
1325
+	 * @throws InvalidArgumentException
1326
+	 * @throws InvalidDataTypeException
1327
+	 * @throws InvalidInterfaceException
1328
+	 */
1329
+	protected function _trash_or_restore_ticket($trash = false)
1330
+	{
1331
+		$success = 1;
1332
+		$TKT = EEM_Ticket::instance();
1333
+		// checkboxes?
1334
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1335
+			// if array has more than one element then success message should be plural
1336
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1337
+			// cycle thru the boxes
1338
+			foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1339
+				if ($trash) {
1340
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1341
+						$success = 0;
1342
+					}
1343
+				} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1344
+					$success = 0;
1345
+				}
1346
+			}
1347
+		} else {
1348
+			// grab single id and trash
1349
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1350
+			if ($trash) {
1351
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1352
+					$success = 0;
1353
+				}
1354
+			} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1355
+				$success = 0;
1356
+			}
1357
+		}
1358
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1359
+		$query_args = [
1360
+			'action' => 'ticket_list_table',
1361
+			'status' => $trash ? '' : 'trashed',
1362
+		];
1363
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1364
+	}
1365
+
1366
+
1367
+	/**
1368
+	 * Handles trashing default ticket.
1369
+	 *
1370
+	 * @throws EE_Error
1371
+	 * @throws InvalidArgumentException
1372
+	 * @throws InvalidDataTypeException
1373
+	 * @throws InvalidInterfaceException
1374
+	 * @throws ReflectionException
1375
+	 */
1376
+	protected function _delete_ticket()
1377
+	{
1378
+		$success = 1;
1379
+		// checkboxes?
1380
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1381
+			// if array has more than one element then success message should be plural
1382
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1383
+			// cycle thru the boxes
1384
+			foreach ($this->_req_data['checkbox'] as $TKT_ID) {
1385
+				// delete
1386
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1387
+					$success = 0;
1388
+				}
1389
+			}
1390
+		} else {
1391
+			// grab single id and trash
1392
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1393
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1394
+				$success = 0;
1395
+			}
1396
+		}
1397
+		$action_desc = 'deleted';
1398
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1399
+		$ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
1400
+			[['TKT_is_default' => 1]],
1401
+			'TKT_ID',
1402
+			true
1403
+		);
1404
+		$query_args = $ticket_count
1405
+			? []
1406
+			: [
1407
+				'action' => 'ticket_list_table',
1408
+				'status' => 'trashed',
1409
+			];
1410
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1411
+	}
1412
+
1413
+
1414
+	/**
1415
+	 * @param int $TKT_ID
1416
+	 * @return bool|int
1417
+	 * @throws EE_Error
1418
+	 * @throws InvalidArgumentException
1419
+	 * @throws InvalidDataTypeException
1420
+	 * @throws InvalidInterfaceException
1421
+	 * @throws ReflectionException
1422
+	 */
1423
+	protected function _delete_the_ticket($TKT_ID)
1424
+	{
1425
+		$ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1426
+		if (! $ticket instanceof EE_Ticket) {
1427
+			return false;
1428
+		}
1429
+		$ticket->_remove_relations('Datetime');
1430
+		// delete all related prices first
1431
+		$ticket->delete_related_permanently('Price');
1432
+		return $ticket->delete_permanently();
1433
+	}
1434 1434
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2873 added lines, -2873 removed lines patch added patch discarded remove patch
@@ -20,2877 +20,2877 @@
 block discarded – undo
20 20
 class Events_Admin_Page extends EE_Admin_Page_CPT
21 21
 {
22 22
 
23
-    /**
24
-     * This will hold the event object for event_details screen.
25
-     *
26
-     * @var EE_Event $_event
27
-     */
28
-    protected $_event;
29
-
30
-
31
-    /**
32
-     * This will hold the category object for category_details screen.
33
-     *
34
-     * @var stdClass $_category
35
-     */
36
-    protected $_category;
37
-
38
-
39
-    /**
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-    /**
45
-     * @var EEM_Datetime $datetime_model
46
-     */
47
-    protected $datetime_model;
48
-
49
-    /**
50
-     * @var EEM_Ticket $ticket_model
51
-     */
52
-    protected $ticket_model;
53
-
54
-
55
-    /**
56
-     * @var EE_Event
57
-     */
58
-    protected $_cpt_model_obj;
59
-
60
-
61
-    /**
62
-     * @var NodeGroupDao
63
-     */
64
-    protected $model_obj_node_group_persister;
65
-
66
-    /**
67
-     * Initialize page props for this admin page group.
68
-     */
69
-    protected function _init_page_props()
70
-    {
71
-        $this->page_slug = EVENTS_PG_SLUG;
72
-        $this->page_label = EVENTS_LABEL;
73
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
74
-        $this->_admin_base_path = EVENTS_ADMIN;
75
-        $this->_cpt_model_names = [
76
-            'create_new' => 'EEM_Event',
77
-            'edit'       => 'EEM_Event',
78
-        ];
79
-        $this->_cpt_edit_routes = [
80
-            'espresso_events' => 'edit',
81
-        ];
82
-        add_action(
83
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
84
-            [$this, 'verify_event_edit'],
85
-            10,
86
-            2
87
-        );
88
-    }
89
-
90
-
91
-    /**
92
-     * Sets the ajax hooks used for this admin page group.
93
-     */
94
-    protected function _ajax_hooks()
95
-    {
96
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
97
-    }
98
-
99
-
100
-    /**
101
-     * Sets the page properties for this admin page group.
102
-     */
103
-    protected function _define_page_props()
104
-    {
105
-        $this->_admin_page_title = EVENTS_LABEL;
106
-        $this->_labels = [
107
-            'buttons'      => [
108
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
109
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
110
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
111
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
112
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
113
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
114
-            ],
115
-            'editor_title' => [
116
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
117
-            ],
118
-            'publishbox'   => [
119
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
120
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
121
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
122
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
123
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
124
-            ],
125
-        ];
126
-    }
127
-
128
-
129
-    /**
130
-     * Sets the page routes property for this admin page group.
131
-     */
132
-    protected function _set_page_routes()
133
-    {
134
-        // load formatter helper
135
-        // load field generator helper
136
-        // is there a evt_id in the request?
137
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
138
-            ? $this->_req_data['EVT_ID']
139
-            : 0;
140
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
141
-        $this->_page_routes = [
142
-            'default'                       => [
143
-                'func'       => '_events_overview_list_table',
144
-                'capability' => 'ee_read_events',
145
-            ],
146
-            'create_new'                    => [
147
-                'func'       => '_create_new_cpt_item',
148
-                'capability' => 'ee_edit_events',
149
-            ],
150
-            'edit'                          => [
151
-                'func'       => '_edit_cpt_item',
152
-                'capability' => 'ee_edit_event',
153
-                'obj_id'     => $evt_id,
154
-            ],
155
-            'copy_event'                    => [
156
-                'func'       => '_copy_events',
157
-                'capability' => 'ee_edit_event',
158
-                'obj_id'     => $evt_id,
159
-                'noheader'   => true,
160
-            ],
161
-            'trash_event'                   => [
162
-                'func'       => '_trash_or_restore_event',
163
-                'args'       => ['event_status' => 'trash'],
164
-                'capability' => 'ee_delete_event',
165
-                'obj_id'     => $evt_id,
166
-                'noheader'   => true,
167
-            ],
168
-            'trash_events'                  => [
169
-                'func'       => '_trash_or_restore_events',
170
-                'args'       => ['event_status' => 'trash'],
171
-                'capability' => 'ee_delete_events',
172
-                'noheader'   => true,
173
-            ],
174
-            'restore_event'                 => [
175
-                'func'       => '_trash_or_restore_event',
176
-                'args'       => ['event_status' => 'draft'],
177
-                'capability' => 'ee_delete_event',
178
-                'obj_id'     => $evt_id,
179
-                'noheader'   => true,
180
-            ],
181
-            'restore_events'                => [
182
-                'func'       => '_trash_or_restore_events',
183
-                'args'       => ['event_status' => 'draft'],
184
-                'capability' => 'ee_delete_events',
185
-                'noheader'   => true,
186
-            ],
187
-            'delete_event'                  => [
188
-                'func'       => '_delete_event',
189
-                'capability' => 'ee_delete_event',
190
-                'obj_id'     => $evt_id,
191
-                'noheader'   => true,
192
-            ],
193
-            'delete_events'                 => [
194
-                'func'       => '_delete_events',
195
-                'capability' => 'ee_delete_events',
196
-                'noheader'   => true,
197
-            ],
198
-            'view_report'                   => [
199
-                'func'       => '_view_report',
200
-                'capability' => 'ee_edit_events',
201
-            ],
202
-            'default_event_settings'        => [
203
-                'func'       => '_default_event_settings',
204
-                'capability' => 'manage_options',
205
-            ],
206
-            'update_default_event_settings' => [
207
-                'func'       => '_update_default_event_settings',
208
-                'capability' => 'manage_options',
209
-                'noheader'   => true,
210
-            ],
211
-            'template_settings'             => [
212
-                'func'       => '_template_settings',
213
-                'capability' => 'manage_options',
214
-            ],
215
-            // event category tab related
216
-            'add_category'                  => [
217
-                'func'       => '_category_details',
218
-                'capability' => 'ee_edit_event_category',
219
-                'args'       => ['add'],
220
-            ],
221
-            'edit_category'                 => [
222
-                'func'       => '_category_details',
223
-                'capability' => 'ee_edit_event_category',
224
-                'args'       => ['edit'],
225
-            ],
226
-            'delete_categories'             => [
227
-                'func'       => '_delete_categories',
228
-                'capability' => 'ee_delete_event_category',
229
-                'noheader'   => true,
230
-            ],
231
-            'delete_category'               => [
232
-                'func'       => '_delete_categories',
233
-                'capability' => 'ee_delete_event_category',
234
-                'noheader'   => true,
235
-            ],
236
-            'insert_category'               => [
237
-                'func'       => '_insert_or_update_category',
238
-                'args'       => ['new_category' => true],
239
-                'capability' => 'ee_edit_event_category',
240
-                'noheader'   => true,
241
-            ],
242
-            'update_category'               => [
243
-                'func'       => '_insert_or_update_category',
244
-                'args'       => ['new_category' => false],
245
-                'capability' => 'ee_edit_event_category',
246
-                'noheader'   => true,
247
-            ],
248
-            'category_list'                 => [
249
-                'func'       => '_category_list_table',
250
-                'capability' => 'ee_manage_event_categories',
251
-            ],
252
-            'preview_deletion' => [
253
-                'func' => 'previewDeletion',
254
-                'capability' => 'ee_delete_events',
255
-            ],
256
-            'confirm_deletion' => [
257
-                'func' => 'confirmDeletion',
258
-                'capability' => 'ee_delete_events',
259
-                'noheader' => true,
260
-            ]
261
-        ];
262
-    }
263
-
264
-
265
-    /**
266
-     * Set the _page_config property for this admin page group.
267
-     */
268
-    protected function _set_page_config()
269
-    {
270
-        $this->_page_config = [
271
-            'default'                => [
272
-                'nav'           => [
273
-                    'label' => esc_html__('Overview', 'event_espresso'),
274
-                    'order' => 10,
275
-                ],
276
-                'list_table'    => 'Events_Admin_List_Table',
277
-                'help_tabs'     => [
278
-                    'events_overview_help_tab'                       => [
279
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
280
-                        'filename' => 'events_overview',
281
-                    ],
282
-                    'events_overview_table_column_headings_help_tab' => [
283
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
284
-                        'filename' => 'events_overview_table_column_headings',
285
-                    ],
286
-                    'events_overview_filters_help_tab'               => [
287
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
288
-                        'filename' => 'events_overview_filters',
289
-                    ],
290
-                    'events_overview_view_help_tab'                  => [
291
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
292
-                        'filename' => 'events_overview_views',
293
-                    ],
294
-                    'events_overview_other_help_tab'                 => [
295
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
296
-                        'filename' => 'events_overview_other',
297
-                    ],
298
-                ],
299
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
300
-                // 'help_tour'     => [
301
-                //     'Event_Overview_Help_Tour',
302
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
303
-                // ],
304
-                'require_nonce' => false,
305
-                'qtips'         => ['EE_Event_List_Table_Tips'],
306
-            ],
307
-            'create_new'             => [
308
-                'nav'           => [
309
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
310
-                    'order'      => 5,
311
-                    'persistent' => false,
312
-                ],
313
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
314
-                'help_tabs'     => [
315
-                    'event_editor_help_tab'                            => [
316
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
317
-                        'filename' => 'event_editor',
318
-                    ],
319
-                    'event_editor_title_richtexteditor_help_tab'       => [
320
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
321
-                        'filename' => 'event_editor_title_richtexteditor',
322
-                    ],
323
-                    'event_editor_venue_details_help_tab'              => [
324
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
325
-                        'filename' => 'event_editor_venue_details',
326
-                    ],
327
-                    'event_editor_event_datetimes_help_tab'            => [
328
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
329
-                        'filename' => 'event_editor_event_datetimes',
330
-                    ],
331
-                    'event_editor_event_tickets_help_tab'              => [
332
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
333
-                        'filename' => 'event_editor_event_tickets',
334
-                    ],
335
-                    'event_editor_event_registration_options_help_tab' => [
336
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
337
-                        'filename' => 'event_editor_event_registration_options',
338
-                    ],
339
-                    'event_editor_tags_categories_help_tab'            => [
340
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
341
-                        'filename' => 'event_editor_tags_categories',
342
-                    ],
343
-                    'event_editor_questions_registrants_help_tab'      => [
344
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
345
-                        'filename' => 'event_editor_questions_registrants',
346
-                    ],
347
-                    'event_editor_save_new_event_help_tab'             => [
348
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
349
-                        'filename' => 'event_editor_save_new_event',
350
-                    ],
351
-                    'event_editor_other_help_tab'                      => [
352
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
353
-                        'filename' => 'event_editor_other',
354
-                    ],
355
-                ],
356
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
357
-                // 'help_tour'     => [
358
-                //     'Event_Editor_Help_Tour',
359
-                // ],
360
-                'require_nonce' => false,
361
-            ],
362
-            'edit'                   => [
363
-                'nav'           => [
364
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
365
-                    'order'      => 5,
366
-                    'persistent' => false,
367
-                    'url'        => isset($this->_req_data['post'])
368
-                        ? EE_Admin_Page::add_query_args_and_nonce(
369
-                            ['post' => $this->_req_data['post'], 'action' => 'edit'],
370
-                            $this->_current_page_view_url
371
-                        )
372
-                        : $this->_admin_base_url,
373
-                ],
374
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
375
-                'help_tabs'     => [
376
-                    'event_editor_help_tab'                            => [
377
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
378
-                        'filename' => 'event_editor',
379
-                    ],
380
-                    'event_editor_title_richtexteditor_help_tab'       => [
381
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
382
-                        'filename' => 'event_editor_title_richtexteditor',
383
-                    ],
384
-                    'event_editor_venue_details_help_tab'              => [
385
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
386
-                        'filename' => 'event_editor_venue_details',
387
-                    ],
388
-                    'event_editor_event_datetimes_help_tab'            => [
389
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
390
-                        'filename' => 'event_editor_event_datetimes',
391
-                    ],
392
-                    'event_editor_event_tickets_help_tab'              => [
393
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
394
-                        'filename' => 'event_editor_event_tickets',
395
-                    ],
396
-                    'event_editor_event_registration_options_help_tab' => [
397
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
398
-                        'filename' => 'event_editor_event_registration_options',
399
-                    ],
400
-                    'event_editor_tags_categories_help_tab'            => [
401
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
402
-                        'filename' => 'event_editor_tags_categories',
403
-                    ],
404
-                    'event_editor_questions_registrants_help_tab'      => [
405
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
406
-                        'filename' => 'event_editor_questions_registrants',
407
-                    ],
408
-                    'event_editor_save_new_event_help_tab'             => [
409
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
410
-                        'filename' => 'event_editor_save_new_event',
411
-                    ],
412
-                    'event_editor_other_help_tab'                      => [
413
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
414
-                        'filename' => 'event_editor_other',
415
-                    ],
416
-                ],
417
-                'require_nonce' => false,
418
-            ],
419
-            'default_event_settings' => [
420
-                'nav'           => [
421
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
422
-                    'order' => 40,
423
-                ],
424
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
425
-                'labels'        => [
426
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
427
-                ],
428
-                'help_tabs'     => [
429
-                    'default_settings_help_tab'        => [
430
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
431
-                        'filename' => 'events_default_settings',
432
-                    ],
433
-                    'default_settings_status_help_tab' => [
434
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
435
-                        'filename' => 'events_default_settings_status',
436
-                    ],
437
-                    'default_maximum_tickets_help_tab' => [
438
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
439
-                        'filename' => 'events_default_settings_max_tickets',
440
-                    ],
441
-                ],
442
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
443
-                // 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
444
-                'require_nonce' => false,
445
-            ],
446
-            // template settings
447
-            'template_settings'      => [
448
-                'nav'           => [
449
-                    'label' => esc_html__('Templates', 'event_espresso'),
450
-                    'order' => 30,
451
-                ],
452
-                'metaboxes'     => $this->_default_espresso_metaboxes,
453
-                'help_tabs'     => [
454
-                    'general_settings_templates_help_tab' => [
455
-                        'title'    => esc_html__('Templates', 'event_espresso'),
456
-                        'filename' => 'general_settings_templates',
457
-                    ],
458
-                ],
459
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
460
-                // 'help_tour'     => ['Templates_Help_Tour'],
461
-                'require_nonce' => false,
462
-            ],
463
-            // event category stuff
464
-            'add_category'           => [
465
-                'nav'           => [
466
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
467
-                    'order'      => 15,
468
-                    'persistent' => false,
469
-                ],
470
-                'help_tabs'     => [
471
-                    'add_category_help_tab' => [
472
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
473
-                        'filename' => 'events_add_category',
474
-                    ],
475
-                ],
476
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
477
-                // 'help_tour'     => ['Event_Add_Category_Help_Tour'],
478
-                'metaboxes'     => ['_publish_post_box'],
479
-                'require_nonce' => false,
480
-            ],
481
-            'edit_category'          => [
482
-                'nav'           => [
483
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
484
-                    'order'      => 15,
485
-                    'persistent' => false,
486
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
487
-                        ? add_query_arg(
488
-                            ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
489
-                            $this->_current_page_view_url
490
-                        )
491
-                        : $this->_admin_base_url,
492
-                ],
493
-                'help_tabs'     => [
494
-                    'edit_category_help_tab' => [
495
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
496
-                        'filename' => 'events_edit_category',
497
-                    ],
498
-                ],
499
-                /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
500
-                'metaboxes'     => ['_publish_post_box'],
501
-                'require_nonce' => false,
502
-            ],
503
-            'category_list'          => [
504
-                'nav'           => [
505
-                    'label' => esc_html__('Categories', 'event_espresso'),
506
-                    'order' => 20,
507
-                ],
508
-                'list_table'    => 'Event_Categories_Admin_List_Table',
509
-                'help_tabs'     => [
510
-                    'events_categories_help_tab'                       => [
511
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
512
-                        'filename' => 'events_categories',
513
-                    ],
514
-                    'events_categories_table_column_headings_help_tab' => [
515
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
516
-                        'filename' => 'events_categories_table_column_headings',
517
-                    ],
518
-                    'events_categories_view_help_tab'                  => [
519
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
520
-                        'filename' => 'events_categories_views',
521
-                    ],
522
-                    'events_categories_other_help_tab'                 => [
523
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
524
-                        'filename' => 'events_categories_other',
525
-                    ],
526
-                ],
527
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
528
-                // 'help_tour'     => [
529
-                //     'Event_Categories_Help_Tour',
530
-                // ],
531
-                'metaboxes'     => $this->_default_espresso_metaboxes,
532
-                'require_nonce' => false,
533
-            ],
534
-            'preview_deletion'       => [
535
-                'nav'           => [
536
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
537
-                    'order'      => 15,
538
-                    'persistent' => false,
539
-                    'url'        => '',
540
-                ],
541
-                'require_nonce' => false,
542
-            ],
543
-        ];
544
-        // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
545
-        $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
546
-        if (! $domain->isCaffeinated()) {
547
-            $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
548
-            $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
549
-        }
550
-    }
551
-
552
-
553
-    /**
554
-     * Used to register any global screen options if necessary for every route in this admin page group.
555
-     */
556
-    protected function _add_screen_options()
557
-    {
558
-    }
559
-
560
-
561
-    /**
562
-     * Implementing the screen options for the 'default' route.
563
-     *
564
-     * @throws InvalidArgumentException
565
-     * @throws InvalidDataTypeException
566
-     * @throws InvalidInterfaceException
567
-     */
568
-    protected function _add_screen_options_default()
569
-    {
570
-        $this->_per_page_screen_option();
571
-    }
572
-
573
-
574
-    /**
575
-     * Implementing screen options for the category list route.
576
-     *
577
-     * @throws InvalidArgumentException
578
-     * @throws InvalidDataTypeException
579
-     * @throws InvalidInterfaceException
580
-     */
581
-    protected function _add_screen_options_category_list()
582
-    {
583
-        $page_title = $this->_admin_page_title;
584
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
585
-        $this->_per_page_screen_option();
586
-        $this->_admin_page_title = $page_title;
587
-    }
588
-
589
-
590
-    /**
591
-     * Used to register any global feature pointers for the admin page group.
592
-     */
593
-    protected function _add_feature_pointers()
594
-    {
595
-    }
596
-
597
-
598
-    /**
599
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
600
-     */
601
-    public function load_scripts_styles()
602
-    {
603
-        wp_register_style(
604
-            'events-admin-css',
605
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
606
-            [],
607
-            EVENT_ESPRESSO_VERSION
608
-        );
609
-        wp_register_style(
610
-            'ee-cat-admin',
611
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
612
-            [],
613
-            EVENT_ESPRESSO_VERSION
614
-        );
615
-        wp_enqueue_style('events-admin-css');
616
-        wp_enqueue_style('ee-cat-admin');
617
-        // scripts
618
-        wp_register_script(
619
-            'event_editor_js',
620
-            EVENTS_ASSETS_URL . 'event_editor.js',
621
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
622
-            EVENT_ESPRESSO_VERSION,
623
-            true
624
-        );
625
-    }
626
-
627
-
628
-    /**
629
-     * Enqueuing scripts and styles specific to this view
630
-     */
631
-    public function load_scripts_styles_create_new()
632
-    {
633
-        $this->load_scripts_styles_edit();
634
-    }
635
-
636
-
637
-    /**
638
-     * Enqueuing scripts and styles specific to this view
639
-     */
640
-    public function load_scripts_styles_edit()
641
-    {
642
-        // styles
643
-        wp_enqueue_style('espresso-ui-theme');
644
-        wp_register_style(
645
-            'event-editor-css',
646
-            EVENTS_ASSETS_URL . 'event-editor.css',
647
-            ['ee-admin-css'],
648
-            EVENT_ESPRESSO_VERSION
649
-        );
650
-        wp_enqueue_style('event-editor-css');
651
-        // scripts
652
-        if (! $this->admin_config->useAdvancedEditor()) {
653
-            wp_register_script(
654
-                'event-datetime-metabox',
655
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
656
-                ['event_editor_js', 'ee-datepicker'],
657
-                EVENT_ESPRESSO_VERSION
658
-            );
659
-            wp_enqueue_script('event-datetime-metabox');
660
-        }
661
-    }
662
-
663
-
664
-    /**
665
-     * Populating the _views property for the category list table view.
666
-     */
667
-    protected function _set_list_table_views_category_list()
668
-    {
669
-        $this->_views = [
670
-            'all' => [
671
-                'slug'        => 'all',
672
-                'label'       => esc_html__('All', 'event_espresso'),
673
-                'count'       => 0,
674
-                'bulk_action' => [
675
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
676
-                ],
677
-            ],
678
-        ];
679
-    }
680
-
681
-
682
-    /**
683
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
684
-     */
685
-    public function admin_init()
686
-    {
687
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
688
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
689
-            'event_espresso'
690
-        );
691
-    }
692
-
693
-
694
-    /**
695
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
696
-     * group.
697
-     */
698
-    public function admin_notices()
699
-    {
700
-    }
701
-
702
-
703
-    /**
704
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
705
-     * this admin page group.
706
-     */
707
-    public function admin_footer_scripts()
708
-    {
709
-    }
710
-
711
-
712
-    /**
713
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
714
-     * warning (via EE_Error::add_error());
715
-     *
716
-     * @param EE_Event $event Event object
717
-     * @param string   $req_type
718
-     * @return void
719
-     * @throws EE_Error
720
-     */
721
-    public function verify_event_edit($event = null, $req_type = '')
722
-    {
723
-        // don't need to do this when processing
724
-        if (! empty($req_type)) {
725
-            return;
726
-        }
727
-        // no event?
728
-        if (! $event instanceof EE_Event) {
729
-            $event = $this->_cpt_model_obj;
730
-        }
731
-        // STILL no event?
732
-        if (! $event instanceof EE_Event) {
733
-            return;
734
-        }
735
-        $orig_status = $event->status();
736
-        // first check if event is active.
737
-        if (
738
-            $orig_status === EEM_Event::cancelled
739
-            || $orig_status === EEM_Event::postponed
740
-            || $event->is_expired()
741
-            || $event->is_inactive()
742
-        ) {
743
-            return;
744
-        }
745
-        // made it here so it IS active... next check that any of the tickets are sold.
746
-        if ($event->is_sold_out(true)) {
747
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
748
-                EE_Error::add_attention(
749
-                    sprintf(
750
-                        esc_html__(
751
-                            '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.',
752
-                            'event_espresso'
753
-                        ),
754
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
755
-                    )
756
-                );
757
-            }
758
-            return;
759
-        }
760
-        if ($orig_status === EEM_Event::sold_out) {
761
-            EE_Error::add_attention(
762
-                sprintf(
763
-                    esc_html__(
764
-                        '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.',
765
-                        'event_espresso'
766
-                    ),
767
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
768
-                )
769
-            );
770
-        }
771
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
772
-        if (! $event->tickets_on_sale()) {
773
-            return;
774
-        }
775
-        // made it here so show warning
776
-        $this->_edit_event_warning();
777
-    }
778
-
779
-
780
-    /**
781
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
782
-     * When needed, hook this into a EE_Error::add_error() notice.
783
-     *
784
-     * @return void
785
-     */
786
-    protected function _edit_event_warning()
787
-    {
788
-        // we don't want to add warnings during these requests
789
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
790
-            return;
791
-        }
792
-        EE_Error::add_attention(
793
-            sprintf(
794
-                esc_html__(
795
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
796
-                    'event_espresso'
797
-                ),
798
-                '<a class="espresso-help-tab-lnk">',
799
-                '</a>'
800
-            )
801
-        );
802
-    }
803
-
804
-
805
-    /**
806
-     * When a user is creating a new event, notify them if they haven't set their timezone.
807
-     * Otherwise, do the normal logic
808
-     *
809
-     * @throws EE_Error
810
-     * @throws InvalidArgumentException
811
-     * @throws InvalidDataTypeException
812
-     */
813
-    protected function _create_new_cpt_item()
814
-    {
815
-        $has_timezone_string = get_option('timezone_string');
816
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
817
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
818
-            EE_Error::add_attention(
819
-                sprintf(
820
-                    __(
821
-                        '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',
822
-                        'event_espresso'
823
-                    ),
824
-                    '<br>',
825
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
826
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
827
-                    . '</select>',
828
-                    '<button class="button button-secondary timezone-submit">',
829
-                    '</button><span class="spinner"></span>'
830
-                ),
831
-                __FILE__,
832
-                __FUNCTION__,
833
-                __LINE__
834
-            );
835
-        }
836
-        parent::_create_new_cpt_item();
837
-    }
838
-
839
-
840
-    /**
841
-     * Sets the _views property for the default route in this admin page group.
842
-     */
843
-    protected function _set_list_table_views_default()
844
-    {
845
-        $this->_views = [
846
-            'all'   => [
847
-                'slug'        => 'all',
848
-                'label'       => esc_html__('View All Events', 'event_espresso'),
849
-                'count'       => 0,
850
-                'bulk_action' => [
851
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
852
-                ],
853
-            ],
854
-            'draft' => [
855
-                'slug'        => 'draft',
856
-                'label'       => esc_html__('Draft', 'event_espresso'),
857
-                'count'       => 0,
858
-                'bulk_action' => [
859
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
860
-                ],
861
-            ],
862
-        ];
863
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
864
-            $this->_views['trash'] = [
865
-                'slug'        => 'trash',
866
-                'label'       => esc_html__('Trash', 'event_espresso'),
867
-                'count'       => 0,
868
-                'bulk_action' => [
869
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
870
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
871
-                ],
872
-            ];
873
-        }
874
-    }
875
-
876
-
877
-    /**
878
-     * Provides the legend item array for the default list table view.
879
-     *
880
-     * @return array
881
-     */
882
-    protected function _event_legend_items()
883
-    {
884
-        $items = [
885
-            'view_details'   => [
886
-                'class' => 'dashicons dashicons-search',
887
-                'desc'  => esc_html__('View Event', 'event_espresso'),
888
-            ],
889
-            'edit_event'     => [
890
-                'class' => 'ee-icon ee-icon-calendar-edit',
891
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
892
-            ],
893
-            'view_attendees' => [
894
-                'class' => 'dashicons dashicons-groups',
895
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
896
-            ],
897
-        ];
898
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
899
-        $statuses = [
900
-            'sold_out_status'  => [
901
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
902
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
903
-            ],
904
-            'active_status'    => [
905
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
906
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
907
-            ],
908
-            'upcoming_status'  => [
909
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
910
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
911
-            ],
912
-            'postponed_status' => [
913
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
914
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
915
-            ],
916
-            'cancelled_status' => [
917
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
918
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
919
-            ],
920
-            'expired_status'   => [
921
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
922
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
923
-            ],
924
-            'inactive_status'  => [
925
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
926
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
927
-            ],
928
-        ];
929
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
930
-        return array_merge($items, $statuses);
931
-    }
932
-
933
-
934
-    /**
935
-     * @return EEM_Event
936
-     * @throws EE_Error
937
-     */
938
-    private function eventModel()
939
-    {
940
-        if (! $this->_event_model instanceof EEM_Event) {
941
-            $this->_event_model = EEM_Event::instance();
942
-        }
943
-        return $this->_event_model;
944
-    }
945
-
946
-
947
-    /**
948
-     * @param string $event_timezone_string
949
-     * @return EEM_Datetime
950
-     * @throws EE_Error
951
-     */
952
-    private function datetimeModel($event_timezone_string = '')
953
-    {
954
-        if (! $this->datetime_model instanceof EEM_Datetime) {
955
-            $this->datetime_model = EEM_Datetime::instance($event_timezone_string);
956
-        }
957
-        return $this->datetime_model;
958
-    }
959
-
960
-
961
-    /**
962
-     * @param string $event_timezone_string
963
-     * @return EEM_Ticket
964
-     * @throws EE_Error
965
-     */
966
-    private function ticketModel($event_timezone_string = '')
967
-    {
968
-        if (! $this->ticket_model instanceof EEM_Ticket) {
969
-            $this->ticket_model = EEM_Ticket::instance($event_timezone_string);
970
-        }
971
-        return $this->ticket_model;
972
-    }
973
-
974
-
975
-    /**
976
-     * Adds extra buttons to the WP CPT permalink field row.
977
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
978
-     *
979
-     * @param string $return    the current html
980
-     * @param int    $id        the post id for the page
981
-     * @param string $new_title What the title is
982
-     * @param string $new_slug  what the slug is
983
-     * @return string            The new html string for the permalink area
984
-     */
985
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
986
-    {
987
-        // make sure this is only when editing
988
-        if (! empty($id)) {
989
-            $post = get_post($id);
990
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
991
-                       . esc_html__('Shortcode', 'event_espresso')
992
-                       . '</a> ';
993
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
994
-                       . $post->ID
995
-                       . ']">';
996
-        }
997
-        return $return;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * _events_overview_list_table
1003
-     * This contains the logic for showing the events_overview list
1004
-     *
1005
-     * @return void
1006
-     * @throws DomainException
1007
-     * @throws EE_Error
1008
-     * @throws InvalidArgumentException
1009
-     * @throws InvalidDataTypeException
1010
-     * @throws InvalidInterfaceException
1011
-     */
1012
-    protected function _events_overview_list_table()
1013
-    {
1014
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1015
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
1016
-            ? (array) $this->_template_args['after_list_table']
1017
-            : [];
1018
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
1019
-                                                                              . EEH_Template::get_button_or_link(
1020
-                                                                                  get_post_type_archive_link('espresso_events'),
1021
-                                                                                  esc_html__('View Event Archive Page', 'event_espresso'),
1022
-                                                                                  'button'
1023
-                                                                              );
1024
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
1025
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1026
-            'create_new',
1027
-            'add',
1028
-            [],
1029
-            'add-new-h2'
1030
-        );
1031
-        $this->display_admin_list_table_page_with_no_sidebar();
1032
-    }
1033
-
1034
-
1035
-    /**
1036
-     * this allows for extra misc actions in the default WP publish box
1037
-     *
1038
-     * @return void
1039
-     * @throws DomainException
1040
-     * @throws EE_Error
1041
-     * @throws InvalidArgumentException
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidInterfaceException
1044
-     * @throws ReflectionException
1045
-     */
1046
-    public function extra_misc_actions_publish_box()
1047
-    {
1048
-        $this->_generate_publish_box_extra_content();
1049
-    }
1050
-
1051
-
1052
-    /**
1053
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1054
-     * saved.
1055
-     * Typically you would use this to save any additional data.
1056
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1057
-     * ALSO very important.  When a post transitions from scheduled to published,
1058
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1059
-     * other meta saves. So MAKE sure that you handle this accordingly.
1060
-     *
1061
-     * @abstract
1062
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1063
-     * @param object $post    The post object of the cpt that was saved.
1064
-     * @return void
1065
-     * @throws EE_Error
1066
-     * @throws InvalidArgumentException
1067
-     * @throws InvalidDataTypeException
1068
-     * @throws InvalidInterfaceException
1069
-     * @throws ReflectionException
1070
-     */
1071
-    protected function _insert_update_cpt_item($post_id, $post)
1072
-    {
1073
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1074
-            // get out we're not processing an event save.
1075
-            return;
1076
-        }
1077
-        $event_values = [
1078
-            'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1079
-            'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1080
-            'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1081
-                ? sanitize_text_field($this->_req_data['timezone_string'])
1082
-                : null,
1083
-        ];
1084
-        /** @var FeatureFlags $flags */
1085
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1086
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1087
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1088
-            $event_values['EVT_display_ticket_selector'] =
1089
-                ! empty($this->_req_data['display_ticket_selector'])
1090
-                    ? 1
1091
-                    : 0;
1092
-            $event_values['EVT_additional_limit'] = min(
1093
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1094
-                ! empty($this->_req_data['additional_limit'])
1095
-                    ? absint($this->_req_data['additional_limit'])
1096
-                    : null
1097
-            );
1098
-            $event_values['EVT_default_registration_status'] =
1099
-                ! empty($this->_req_data['EVT_default_registration_status'])
1100
-                    ? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1101
-                    : EE_Registry::instance()->CFG->registration->default_STS_ID;
1102
-            $event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL'])
1103
-                ? esc_url_raw($this->_req_data['externalURL'])
1104
-                : null;
1105
-            $event_values['EVT_phone'] = ! empty($this->_req_data['event_phone'])
1106
-                ? sanitize_text_field($this->_req_data['event_phone'])
1107
-                : null;
1108
-        }
1109
-        // update event
1110
-        $success = $this->eventModel()->update_by_ID($event_values, $post_id);
1111
-        // get event_object for other metaboxes...
1112
-        // though it would seem to make sense to just use $this->eventModel()->get_one_by_ID( $post_id )..
1113
-        // i have to setup where conditions to override the filters in the model
1114
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1115
-        $get_one_where = [
1116
-            $this->eventModel()->primary_key_name() => $post_id,
1117
-            'OR'                                    => [
1118
-                'status'   => $post->post_status,
1119
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1120
-                // but the returned object here has a status of "publish", so use the original post status as well
1121
-                'status*1' => $this->_req_data['original_post_status'],
1122
-            ],
1123
-        ];
1124
-        $event = $this->eventModel()->get_one([$get_one_where]);
1125
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1126
-        $event_update_callbacks = apply_filters(
1127
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1128
-            [
1129
-                [$this, '_default_venue_update'],
1130
-                [$this, '_default_tickets_update'],
1131
-            ]
1132
-        );
1133
-        $att_success = true;
1134
-        foreach ($event_update_callbacks as $e_callback) {
1135
-            $_success = is_callable($e_callback)
1136
-                ? $e_callback($event, $this->_req_data)
1137
-                : false;
1138
-            // if ANY of these updates fail then we want the appropriate global error message
1139
-            $att_success = ! $att_success ? $att_success : $_success;
1140
-        }
1141
-        // any errors?
1142
-        if ($success && false === $att_success) {
1143
-            EE_Error::add_error(
1144
-                esc_html__(
1145
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1146
-                    'event_espresso'
1147
-                ),
1148
-                __FILE__,
1149
-                __FUNCTION__,
1150
-                __LINE__
1151
-            );
1152
-        } elseif ($success === false) {
1153
-            EE_Error::add_error(
1154
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1155
-                __FILE__,
1156
-                __FUNCTION__,
1157
-                __LINE__
1158
-            );
1159
-        }
1160
-    }
1161
-
1162
-
1163
-    /**
1164
-     * @param int $post_id
1165
-     * @param int $revision_id
1166
-     * @throws EE_Error
1167
-     * @throws InvalidArgumentException
1168
-     * @throws InvalidDataTypeException
1169
-     * @throws InvalidInterfaceException
1170
-     * @throws ReflectionException
1171
-     * @see parent::restore_item()
1172
-     */
1173
-    protected function _restore_cpt_item($post_id, $revision_id)
1174
-    {
1175
-        // copy existing event meta to new post
1176
-        $post_evt = $this->eventModel()->get_one_by_ID($post_id);
1177
-        if ($post_evt instanceof EE_Event) {
1178
-            // meta revision restore
1179
-            $post_evt->restore_revision($revision_id);
1180
-            // related objs restore
1181
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1182
-        }
1183
-    }
1184
-
1185
-
1186
-    /**
1187
-     * Attach the venue to the Event
1188
-     *
1189
-     * @param EE_Event $evtobj Event Object to add the venue to
1190
-     * @param array    $data   The request data from the form
1191
-     * @return bool           Success or fail.
1192
-     * @throws EE_Error
1193
-     * @throws InvalidArgumentException
1194
-     * @throws InvalidDataTypeException
1195
-     * @throws InvalidInterfaceException
1196
-     * @throws ReflectionException
1197
-     */
1198
-    protected function _default_venue_update(EE_Event $evtobj, $data)
1199
-    {
1200
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1201
-        $venue_model = EEM_Venue::instance();
1202
-        $rows_affected = null;
1203
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1204
-        // very important.  If we don't have a venue name...
1205
-        // then we'll get out because not necessary to create empty venue
1206
-        if (empty($data['venue_title'])) {
1207
-            return false;
1208
-        }
1209
-        $venue_array = [
1210
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1211
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1212
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1213
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1214
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1215
-                : null,
1216
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1217
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1218
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1219
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1220
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1221
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1222
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1223
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1224
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1225
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1226
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1227
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1228
-            'status'              => 'publish',
1229
-        ];
1230
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1231
-        if (! empty($venue_id)) {
1232
-            $update_where = [$venue_model->primary_key_name() => $venue_id];
1233
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1234
-            // 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.
1235
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1236
-            return $rows_affected > 0;
1237
-        }
1238
-        // we insert the venue
1239
-        $venue_id = $venue_model->insert($venue_array);
1240
-        $evtobj->_add_relation_to($venue_id, 'Venue');
1241
-        return ! empty($venue_id) ? true : false;
1242
-        // when we have the ancestor come in it's already been handled by the revision save.
1243
-    }
1244
-
1245
-
1246
-    /**
1247
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1248
-     *
1249
-     * @param EE_Event $evtobj The Event object we're attaching data to
1250
-     * @param array    $data   The request data from the form
1251
-     * @return array
1252
-     * @throws EE_Error
1253
-     * @throws InvalidArgumentException
1254
-     * @throws InvalidDataTypeException
1255
-     * @throws InvalidInterfaceException
1256
-     * @throws ReflectionException
1257
-     * @throws Exception
1258
-     */
1259
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1260
-    {
1261
-        if ($this->admin_config->useAdvancedEditor()) {
1262
-            return [];
1263
-        }
1264
-        $saved_dtt = null;
1265
-        $saved_tickets = [];
1266
-        $incoming_date_formats = ['Y-m-d', 'h:i a'];
1267
-        $event_timezone_string = $evtobj->get_timezone();
1268
-        $event_timezone = new DateTimeZone($event_timezone_string);
1269
-        // let's use now in the set timezone.
1270
-        $now = new DateTime('now', $event_timezone);
1271
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1272
-            // trim all values to ensure any excess whitespace is removed.
1273
-            $dtt = array_map('trim', $dtt);
1274
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end'])
1275
-                ? $dtt['DTT_EVT_end']
1276
-                : $dtt['DTT_EVT_start'];
1277
-            $datetime_values = [
1278
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1279
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1280
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1281
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1282
-                'DTT_order'     => $row,
1283
-            ];
1284
-            // 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.
1285
-            if (! empty($dtt['DTT_ID'])) {
1286
-                $DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']);
1287
-                $DTM->set_date_format($incoming_date_formats[0]);
1288
-                $DTM->set_time_format($incoming_date_formats[1]);
1289
-                foreach ($datetime_values as $field => $value) {
1290
-                    $DTM->set($field, $value);
1291
-                }
1292
-                // 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.
1293
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1294
-            } else {
1295
-                $DTM = EE_Registry::instance()->load_class(
1296
-                    'Datetime',
1297
-                    [$datetime_values, $event_timezone_string, $incoming_date_formats],
1298
-                    false,
1299
-                    false
1300
-                );
1301
-                foreach ($datetime_values as $field => $value) {
1302
-                    $DTM->set($field, $value);
1303
-                }
1304
-            }
1305
-            $DTM->save();
1306
-            $DTM = $evtobj->_add_relation_to($DTM, 'Datetime');
1307
-            // load DTT helper
1308
-            // 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.
1309
-            if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
1310
-                $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
1311
-                $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
1312
-                $DTM->save();
1313
-            }
1314
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array
1315
-            //  because it is possible there was a new one created for the autosave.
1316
-            $saved_dtt = $DTM;
1317
-            // if ANY of these updates fail then we want the appropriate global error message.
1318
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1319
-        }
1320
-        // no dtts get deleted so we don't do any of that logic here.
1321
-        // update tickets next
1322
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1323
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1324
-            $incoming_date_formats = ['Y-m-d', 'h:i a'];
1325
-            $update_prices = false;
1326
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1327
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1328
-            // trim inputs to ensure any excess whitespace is removed.
1329
-            $tkt = array_map('trim', $tkt);
1330
-            if (empty($tkt['TKT_start_date'])) {
1331
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1332
-            }
1333
-            if (empty($tkt['TKT_end_date'])) {
1334
-                // use the start date of the first datetime
1335
-                $dtt = $evtobj->first_datetime();
1336
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1337
-                    $incoming_date_formats[0],
1338
-                    $incoming_date_formats[1]
1339
-                );
1340
-            }
1341
-            $TKT_values = [
1342
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1343
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1344
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1345
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1346
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1347
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1348
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1349
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1350
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1351
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1352
-                'TKT_row'         => $row,
1353
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1354
-                'TKT_price'       => $ticket_price,
1355
-            ];
1356
-            // 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.
1357
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1358
-                $TKT_values['TKT_ID'] = 0;
1359
-                $TKT_values['TKT_is_default'] = 0;
1360
-                $TKT_values['TKT_price'] = $ticket_price;
1361
-                $update_prices = true;
1362
-            }
1363
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1364
-            // 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.
1365
-            // 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.
1366
-            if (! empty($tkt['TKT_ID'])) {
1367
-                $TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']);
1368
-                if ($TKT instanceof EE_Ticket) {
1369
-                    $ticket_sold = $TKT->count_related(
1370
-                        'Registration',
1371
-                        [
1372
-                                [
1373
-                                    'STS_ID' => [
1374
-                                        'NOT IN',
1375
-                                        [EEM_Registration::status_id_incomplete],
1376
-                                    ],
1377
-                                ],
1378
-                            ]
1379
-                    ) > 0;
1380
-                    // let's just check the total price for the existing ticket and determine if it matches the new
1381
-                    // total price.  if they are different then we create a new ticket (if tickets sold)
1382
-                    // if they aren't different then we go ahead and modify existing ticket.
1383
-                    $create_new_TKT = $ticket_sold && ! $TKT->deleted()
1384
-                                      && EEH_Money::compare_floats(
1385
-                                          $ticket_price,
1386
-                                          $TKT->get('TKT_price'),
1387
-                                          '!=='
1388
-                                      );
1389
-                    $TKT->set_date_format($incoming_date_formats[0]);
1390
-                    $TKT->set_time_format($incoming_date_formats[1]);
1391
-                    // set new values
1392
-                    foreach ($TKT_values as $field => $value) {
1393
-                        if ($field === 'TKT_qty') {
1394
-                            $TKT->set_qty($value);
1395
-                        } else {
1396
-                            $TKT->set($field, $value);
1397
-                        }
1398
-                    }
1399
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1400
-                    if ($create_new_TKT) {
1401
-                        // archive the old ticket first
1402
-                        $TKT->set('TKT_deleted', 1);
1403
-                        $TKT->save();
1404
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1405
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1406
-                        // 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.
1407
-                        $TKT = clone $TKT;
1408
-                        $TKT->set('TKT_ID', 0);
1409
-                        $TKT->set('TKT_deleted', 0);
1410
-                        $TKT->set('TKT_price', $ticket_price);
1411
-                        $TKT->set('TKT_sold', 0);
1412
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1413
-                        $update_prices = true;
1414
-                    }
1415
-                    // make sure price is set if it hasn't been already
1416
-                    $TKT->set('TKT_price', $ticket_price);
1417
-                }
1418
-            } else {
1419
-                // no TKT_id so a new TKT
1420
-                $TKT_values['TKT_price'] = $ticket_price;
1421
-                $TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1422
-                if ($TKT instanceof EE_Ticket) {
1423
-                    // need to reset values to properly account for the date formats
1424
-                    $TKT->set_date_format($incoming_date_formats[0]);
1425
-                    $TKT->set_time_format($incoming_date_formats[1]);
1426
-                    $TKT->set_timezone($evtobj->get_timezone());
1427
-                    // set new values
1428
-                    foreach ($TKT_values as $field => $value) {
1429
-                        if ($field === 'TKT_qty') {
1430
-                            $TKT->set_qty($value);
1431
-                        } else {
1432
-                            $TKT->set($field, $value);
1433
-                        }
1434
-                    }
1435
-                    $update_prices = true;
1436
-                }
1437
-            }
1438
-            // cap ticket qty by datetime reg limits
1439
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1440
-            // update ticket.
1441
-            $TKT->save();
1442
-            // 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.
1443
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1444
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1445
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1446
-                $TKT->save();
1447
-            }
1448
-            // initially let's add the ticket to the dtt
1449
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1450
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1451
-            // add prices to ticket
1452
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1453
-        }
1454
-        // 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.
1455
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1456
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1457
-        foreach ($tickets_removed as $id) {
1458
-            $id = absint($id);
1459
-            // get the ticket for this id
1460
-            $tkt_to_remove = $this->ticketModel($event_timezone_string)->get_one_by_ID($id);
1461
-            // 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)
1462
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1463
-            foreach ($dtts as $dtt) {
1464
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1465
-            }
1466
-            // 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))
1467
-            $tkt_to_remove->delete_related_permanently('Price');
1468
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1469
-            $tkt_to_remove->delete_permanently();
1470
-        }
1471
-        return [$saved_dtt, $saved_tickets];
1472
-    }
1473
-
1474
-
1475
-    /**
1476
-     * This attaches a list of given prices to a ticket.
1477
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1478
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1479
-     * price info and prices are automatically "archived" via the ticket.
1480
-     *
1481
-     * @param array     $prices     Array of prices from the form.
1482
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1483
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1484
-     * @return  void
1485
-     * @throws EE_Error
1486
-     * @throws InvalidArgumentException
1487
-     * @throws InvalidDataTypeException
1488
-     * @throws InvalidInterfaceException
1489
-     * @throws ReflectionException
1490
-     */
1491
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1492
-    {
1493
-        foreach ($prices as $row => $prc) {
1494
-            $PRC_values = [
1495
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1496
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1497
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1498
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1499
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1500
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1501
-                'PRC_order'      => $row,
1502
-            ];
1503
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1504
-                $PRC_values['PRC_ID'] = 0;
1505
-                $PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1506
-            } else {
1507
-                $PRC = EEM_Price::instance()->get_one_by_ID($prc['PRC_ID']);
1508
-                // update this price with new values
1509
-                foreach ($PRC_values as $field => $newprc) {
1510
-                    $PRC->set($field, $newprc);
1511
-                }
1512
-                $PRC->save();
1513
-            }
1514
-            $ticket->_add_relation_to($PRC, 'Price');
1515
-        }
1516
-    }
1517
-
1518
-
1519
-    /**
1520
-     * Add in our autosave ajax handlers
1521
-     *
1522
-     */
1523
-    protected function _ee_autosave_create_new()
1524
-    {
1525
-    }
1526
-
1527
-
1528
-    /**
1529
-     * More autosave handlers.
1530
-     */
1531
-    protected function _ee_autosave_edit()
1532
-    {
1533
-    }
1534
-
1535
-
1536
-    /**
1537
-     *    _generate_publish_box_extra_content
1538
-     *
1539
-     * @throws DomainException
1540
-     * @throws EE_Error
1541
-     * @throws InvalidArgumentException
1542
-     * @throws InvalidDataTypeException
1543
-     * @throws InvalidInterfaceException
1544
-     * @throws ReflectionException
1545
-     */
1546
-    private function _generate_publish_box_extra_content()
1547
-    {
1548
-        // load formatter helper
1549
-        // args for getting related registrations
1550
-        $approved_query_args = [
1551
-            [
1552
-                'REG_deleted' => 0,
1553
-                'STS_ID'      => EEM_Registration::status_id_approved,
1554
-            ],
1555
-        ];
1556
-        $not_approved_query_args = [
1557
-            [
1558
-                'REG_deleted' => 0,
1559
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1560
-            ],
1561
-        ];
1562
-        $pending_payment_query_args = [
1563
-            [
1564
-                'REG_deleted' => 0,
1565
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1566
-            ],
1567
-        ];
1568
-        // publish box
1569
-        $publish_box_extra_args = [
1570
-            'view_approved_reg_url'        => add_query_arg(
1571
-                [
1572
-                    'action'      => 'default',
1573
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1574
-                    '_reg_status' => EEM_Registration::status_id_approved,
1575
-                ],
1576
-                REG_ADMIN_URL
1577
-            ),
1578
-            'view_not_approved_reg_url'    => add_query_arg(
1579
-                [
1580
-                    'action'      => 'default',
1581
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1582
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1583
-                ],
1584
-                REG_ADMIN_URL
1585
-            ),
1586
-            'view_pending_payment_reg_url' => add_query_arg(
1587
-                [
1588
-                    'action'      => 'default',
1589
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1590
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1591
-                ],
1592
-                REG_ADMIN_URL
1593
-            ),
1594
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1595
-                'Registration',
1596
-                $approved_query_args
1597
-            ),
1598
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1599
-                'Registration',
1600
-                $not_approved_query_args
1601
-            ),
1602
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1603
-                'Registration',
1604
-                $pending_payment_query_args
1605
-            ),
1606
-            'misc_pub_section_class'       => apply_filters(
1607
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1608
-                'misc-pub-section'
1609
-            ),
1610
-        ];
1611
-        ob_start();
1612
-        do_action(
1613
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1614
-            $this->_cpt_model_obj
1615
-        );
1616
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1617
-        // load template
1618
-        EEH_Template::display_template(
1619
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1620
-            $publish_box_extra_args
1621
-        );
1622
-    }
1623
-
1624
-
1625
-    /**
1626
-     * @return EE_Event
1627
-     */
1628
-    public function get_event_object()
1629
-    {
1630
-        return $this->_cpt_model_obj;
1631
-    }
1632
-
1633
-
1634
-
1635
-
1636
-    /** METABOXES * */
1637
-    /**
1638
-     * _register_event_editor_meta_boxes
1639
-     * add all metaboxes related to the event_editor
1640
-     *
1641
-     * @return void
1642
-     * @throws EE_Error
1643
-     * @throws InvalidArgumentException
1644
-     * @throws InvalidDataTypeException
1645
-     * @throws InvalidInterfaceException
1646
-     * @throws ReflectionException
1647
-     */
1648
-    protected function _register_event_editor_meta_boxes()
1649
-    {
1650
-        $this->verify_cpt_object();
1651
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1652
-        /** @var FeatureFlags $flags */
1653
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1654
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1655
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1656
-            add_meta_box(
1657
-                'espresso_event_editor_event_options',
1658
-                esc_html__('Event Registration Options', 'event_espresso'),
1659
-                [$this, 'registration_options_meta_box'],
1660
-                $this->page_slug,
1661
-                'side'
1662
-            );
1663
-        }
1664
-        if (! $use_advanced_editor) {
1665
-            add_meta_box(
1666
-                'espresso_event_editor_tickets',
1667
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1668
-                [$this, 'ticket_metabox'],
1669
-                $this->page_slug,
1670
-                'normal',
1671
-                'high'
1672
-            );
1673
-        } else {
1674
-            if ($flags->featureAllowed('use_reg_options_meta_box')) {
1675
-                add_action(
1676
-                    'add_meta_boxes_espresso_events',
1677
-                    function () {
1678
-                        global $current_screen;
1679
-                        remove_meta_box('authordiv', $current_screen, 'normal');
1680
-                    },
1681
-                    99
1682
-                );
1683
-            }
1684
-        }
1685
-        // NOTE: if you're looking for other metaboxes in here,
1686
-        // where a metabox has a related management page in the admin
1687
-        // you will find it setup in the related management page's "_Hooks" file.
1688
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1689
-    }
1690
-
1691
-
1692
-    /**
1693
-     * @throws DomainException
1694
-     * @throws EE_Error
1695
-     * @throws InvalidArgumentException
1696
-     * @throws InvalidDataTypeException
1697
-     * @throws InvalidInterfaceException
1698
-     * @throws ReflectionException
1699
-     */
1700
-    public function ticket_metabox()
1701
-    {
1702
-        $existing_datetime_ids = $existing_ticket_ids = [];
1703
-        // defaults for template args
1704
-        $template_args = [
1705
-            'existing_datetime_ids'    => '',
1706
-            'event_datetime_help_link' => '',
1707
-            'ticket_options_help_link' => '',
1708
-            'time'                     => null,
1709
-            'ticket_rows'              => '',
1710
-            'existing_ticket_ids'      => '',
1711
-            'total_ticket_rows'        => 1,
1712
-            'ticket_js_structure'      => '',
1713
-            'trash_icon'               => 'ee-lock-icon',
1714
-            'disabled'                 => '',
1715
-        ];
1716
-        $event_id = $this->_cpt_model_obj instanceof EE_Event ? $this->_cpt_model_obj->ID() : 0;
1717
-        $event_timezone_string = $this->_cpt_model_obj instanceof EE_Event
1718
-            ? $this->_cpt_model_obj->timezone_string()
1719
-            : '';
1720
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1721
-        /**
1722
-         * 1. Start with retrieving Datetimes
1723
-         * 2. Fore each datetime get related tickets
1724
-         * 3. For each ticket get related prices
1725
-         */
1726
-        $times = $this->datetimeModel($event_timezone_string)->get_all_event_dates($event_id);
1727
-        /** @type EE_Datetime $first_datetime */
1728
-        $first_datetime = reset($times);
1729
-        // do we get related tickets?
1730
-        if (
1731
-            $first_datetime instanceof EE_Datetime
1732
-            && $first_datetime->ID() !== 0
1733
-        ) {
1734
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1735
-            $template_args['time'] = $first_datetime;
1736
-            $related_tickets = $first_datetime->tickets(
1737
-                [
1738
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1739
-                    'default_where_conditions' => 'none',
1740
-                ]
1741
-            );
1742
-            if (! empty($related_tickets)) {
1743
-                $template_args['total_ticket_rows'] = count($related_tickets);
1744
-                $row = 0;
1745
-                foreach ($related_tickets as $ticket) {
1746
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1747
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1748
-                    $row++;
1749
-                }
1750
-            } else {
1751
-                $template_args['total_ticket_rows'] = 1;
1752
-                /** @type EE_Ticket $ticket */
1753
-                $ticket = $this->ticketModel($event_timezone_string)->create_default_object();
1754
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1755
-            }
1756
-        } else {
1757
-            $template_args['time'] = $times[0];
1758
-            /** @type EE_Ticket $ticket */
1759
-            $ticket = $this->ticketModel($event_timezone_string)->get_all_default_tickets();
1760
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1761
-            // NOTE: we're just sending the first default row
1762
-            // (decaf can't manage default tickets so this should be sufficient);
1763
-        }
1764
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1765
-            'event_editor_event_datetimes_help_tab'
1766
-        );
1767
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1768
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1769
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1770
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1771
-            $this->ticketModel($event_timezone_string)->create_default_object(),
1772
-            true
1773
-        );
1774
-        $template = apply_filters(
1775
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1776
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1777
-        );
1778
-        EEH_Template::display_template($template, $template_args);
1779
-    }
1780
-
1781
-
1782
-    /**
1783
-     * Setup an individual ticket form for the decaf event editor page
1784
-     *
1785
-     * @param EE_Ticket $ticket   the ticket object
1786
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1787
-     * @param int       $row
1788
-     * @return string generated html for the ticket row.
1789
-     * @throws DomainException
1790
-     * @throws EE_Error
1791
-     * @throws InvalidArgumentException
1792
-     * @throws InvalidDataTypeException
1793
-     * @throws InvalidInterfaceException
1794
-     * @throws ReflectionException
1795
-     */
1796
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1797
-    {
1798
-        $template_args = [
1799
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1800
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1801
-                : '',
1802
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1803
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1804
-            'TKT_name'            => $ticket->get('TKT_name'),
1805
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1806
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1807
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1808
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1809
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1810
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1811
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1812
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1813
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1814
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1815
-                : ' disabled=disabled',
1816
-        ];
1817
-        $price = $ticket->ID() !== 0
1818
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1819
-            : EEM_Price::instance()->create_default_object();
1820
-        $price_args = [
1821
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1822
-            'PRC_amount'            => $price->get('PRC_amount'),
1823
-            'PRT_ID'                => $price->get('PRT_ID'),
1824
-            'PRC_ID'                => $price->get('PRC_ID'),
1825
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1826
-        ];
1827
-        // make sure we have default start and end dates if skeleton
1828
-        // handle rows that should NOT be empty
1829
-        if (empty($template_args['TKT_start_date'])) {
1830
-            // if empty then the start date will be now.
1831
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1832
-        }
1833
-        if (empty($template_args['TKT_end_date'])) {
1834
-            // get the earliest datetime (if present);
1835
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1836
-                ? $this->_cpt_model_obj->get_first_related(
1837
-                    'Datetime',
1838
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1839
-                )
1840
-                : null;
1841
-            if (! empty($earliest_dtt)) {
1842
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1843
-            } else {
1844
-                $template_args['TKT_end_date'] = date(
1845
-                    'Y-m-d h:i a',
1846
-                    mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1847
-                );
1848
-            }
1849
-        }
1850
-        $template_args = array_merge($template_args, $price_args);
1851
-        $template = apply_filters(
1852
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1853
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1854
-            $ticket
1855
-        );
1856
-        return EEH_Template::display_template($template, $template_args, true);
1857
-    }
1858
-
1859
-
1860
-    /**
1861
-     * @throws DomainException
1862
-     * @throws EE_Error
1863
-     */
1864
-    public function registration_options_meta_box()
1865
-    {
1866
-        $yes_no_values = [
1867
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1868
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1869
-        ];
1870
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1871
-            [
1872
-                EEM_Registration::status_id_cancelled,
1873
-                EEM_Registration::status_id_declined,
1874
-                EEM_Registration::status_id_incomplete,
1875
-            ],
1876
-            true
1877
-        );
1878
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1879
-        $template_args['_event'] = $this->_cpt_model_obj;
1880
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1881
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1882
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1883
-            'default_reg_status',
1884
-            $default_reg_status_values,
1885
-            $this->_cpt_model_obj->default_registration_status()
1886
-        );
1887
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1888
-            'display_desc',
1889
-            $yes_no_values,
1890
-            $this->_cpt_model_obj->display_description()
1891
-        );
1892
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1893
-            'display_ticket_selector',
1894
-            $yes_no_values,
1895
-            $this->_cpt_model_obj->display_ticket_selector(),
1896
-            '',
1897
-            '',
1898
-            false
1899
-        );
1900
-        $template_args['additional_registration_options'] = apply_filters(
1901
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1902
-            '',
1903
-            $template_args,
1904
-            $yes_no_values,
1905
-            $default_reg_status_values
1906
-        );
1907
-        EEH_Template::display_template(
1908
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1909
-            $template_args
1910
-        );
1911
-    }
1912
-
1913
-
1914
-    /**
1915
-     * _get_events()
1916
-     * This method simply returns all the events (for the given _view and paging)
1917
-     *
1918
-     * @param int  $per_page     count of items per page (20 default);
1919
-     * @param int  $current_page what is the current page being viewed.
1920
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1921
-     *                           If FALSE then we return an array of event objects
1922
-     *                           that match the given _view and paging parameters.
1923
-     * @return array|int         an array of event objects or count of how many events.
1924
-     * @throws EE_Error
1925
-     * @throws InvalidArgumentException
1926
-     * @throws InvalidDataTypeException
1927
-     * @throws InvalidInterfaceException
1928
-     * @throws ReflectionException
1929
-     * @throws Exception
1930
-     * @throws Exception
1931
-     * @throws Exception
1932
-     */
1933
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1934
-    {
1935
-        $EEME = $this->eventModel();
1936
-        $offset = ($current_page - 1) * $per_page;
1937
-        $limit = $count ? null : $offset . ',' . $per_page;
1938
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1939
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1940
-        if (isset($this->_req_data['month_range'])) {
1941
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1942
-            // simulate the FIRST day of the month, that fixes issues for months like February
1943
-            // where PHP doesn't know what to assume for date.
1944
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1945
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1946
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1947
-        }
1948
-        $where = [];
1949
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1950
-        // determine what post_status our condition will have for the query.
1951
-        switch ($status) {
1952
-            case 'month':
1953
-            case 'today':
1954
-            case null:
1955
-            case 'all':
1956
-                break;
1957
-            case 'draft':
1958
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1959
-                break;
1960
-            default:
1961
-                $where['status'] = $status;
1962
-        }
1963
-        // categories?
1964
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1965
-            ? $this->_req_data['EVT_CAT'] : null;
1966
-        if (! empty($category)) {
1967
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968
-            $where['Term_Taxonomy.term_id'] = $category;
1969
-        }
1970
-        // date where conditions
1971
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1973
-            $DateTime = new DateTime(
1974
-                $year_r . '-' . $month_r . '-01 00:00:00',
1975
-                new DateTimeZone('UTC')
1976
-            );
1977
-            $start = $DateTime->getTimestamp();
1978
-            // set the datetime to be the end of the month
1979
-            $DateTime->setDate(
1980
-                $year_r,
1981
-                $month_r,
1982
-                $DateTime->format('t')
1983
-            )->setTime(23, 59, 59);
1984
-            $end = $DateTime->getTimestamp();
1985
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1987
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1988
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1989
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1990
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1991
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1992
-            $now = date('Y-m-01');
1993
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1994
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1995
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1996
-                            ->setTime(23, 59, 59)
1997
-                            ->format(implode(' ', $start_formats));
1998
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1999
-        }
2000
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2001
-            $where['EVT_wp_user'] = get_current_user_id();
2002
-        } elseif (
2003
-            ! isset($where['status'])
2004
-                  && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2005
-        ) {
2006
-            $where['OR'] = [
2007
-                'status*restrict_private' => ['!=', 'private'],
2008
-                'AND'                     => [
2009
-                    'status*inclusive' => ['=', 'private'],
2010
-                    'EVT_wp_user'      => get_current_user_id(),
2011
-                ],
2012
-            ];
2013
-        }
2014
-
2015
-        if (
2016
-            isset($this->_req_data['EVT_wp_user'])
2017
-            && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2018
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2019
-        ) {
2020
-            $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2021
-        }
2022
-        // search query handling
2023
-        if (isset($this->_req_data['s'])) {
2024
-            $search_string = '%' . $this->_req_data['s'] . '%';
2025
-            $where['OR'] = [
2026
-                'EVT_name'       => ['LIKE', $search_string],
2027
-                'EVT_desc'       => ['LIKE', $search_string],
2028
-                'EVT_short_desc' => ['LIKE', $search_string],
2029
-            ];
2030
-        }
2031
-        // filter events by venue.
2032
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2033
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2034
-        }
2035
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2036
-        $query_params = apply_filters(
2037
-            'FHEE__Events_Admin_Page__get_events__query_params',
2038
-            [
2039
-                $where,
2040
-                'limit'    => $limit,
2041
-                'order_by' => $orderby,
2042
-                'order'    => $order,
2043
-                'group_by' => 'EVT_ID',
2044
-            ],
2045
-            $this->_req_data
2046
-        );
2047
-
2048
-        // let's first check if we have special requests coming in.
2049
-        if (isset($this->_req_data['active_status'])) {
2050
-            switch ($this->_req_data['active_status']) {
2051
-                case 'upcoming':
2052
-                    return $EEME->get_upcoming_events($query_params, $count);
2053
-                    break;
2054
-                case 'expired':
2055
-                    return $EEME->get_expired_events($query_params, $count);
2056
-                    break;
2057
-                case 'active':
2058
-                    return $EEME->get_active_events($query_params, $count);
2059
-                    break;
2060
-                case 'inactive':
2061
-                    return $EEME->get_inactive_events($query_params, $count);
2062
-                    break;
2063
-            }
2064
-        }
2065
-        return $count
2066
-            ? $EEME->count([$where], 'EVT_ID', true)
2067
-            : $EEME->get_all($query_params);
2068
-    }
2069
-
2070
-
2071
-    /**
2072
-     * handling for WordPress CPT actions (trash, restore, delete)
2073
-     *
2074
-     * @param string $post_id
2075
-     * @throws EE_Error
2076
-     * @throws InvalidArgumentException
2077
-     * @throws InvalidDataTypeException
2078
-     * @throws InvalidInterfaceException
2079
-     * @throws ReflectionException
2080
-     */
2081
-    public function trash_cpt_item($post_id)
2082
-    {
2083
-        $this->_req_data['EVT_ID'] = $post_id;
2084
-        $this->_trash_or_restore_event('trash', false);
2085
-    }
2086
-
2087
-
2088
-    /**
2089
-     * @param string $post_id
2090
-     * @throws EE_Error
2091
-     * @throws InvalidArgumentException
2092
-     * @throws InvalidDataTypeException
2093
-     * @throws InvalidInterfaceException
2094
-     * @throws ReflectionException
2095
-     */
2096
-    public function restore_cpt_item($post_id)
2097
-    {
2098
-        $this->_req_data['EVT_ID'] = $post_id;
2099
-        $this->_trash_or_restore_event('draft', false);
2100
-    }
2101
-
2102
-
2103
-    /**
2104
-     * @param string $post_id
2105
-     * @throws EE_Error
2106
-     * @throws InvalidArgumentException
2107
-     * @throws InvalidDataTypeException
2108
-     * @throws InvalidInterfaceException
2109
-     * @throws ReflectionException
2110
-     */
2111
-    public function delete_cpt_item($post_id)
2112
-    {
2113
-        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
2114
-        $this->_req_data['EVT_ID'] = $post_id;
2115
-        $this->_delete_event();
2116
-    }
2117
-
2118
-
2119
-    /**
2120
-     * _trash_or_restore_event
2121
-     *
2122
-     * @param string $event_status
2123
-     * @param bool   $redirect_after
2124
-     * @throws EE_Error
2125
-     * @throws InvalidArgumentException
2126
-     * @throws InvalidDataTypeException
2127
-     * @throws InvalidInterfaceException
2128
-     * @throws ReflectionException
2129
-     */
2130
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2131
-    {
2132
-        // determine the event id and set to array.
2133
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2134
-        // loop thru events
2135
-        if ($EVT_ID) {
2136
-            // clean status
2137
-            $event_status = sanitize_key($event_status);
2138
-            // grab status
2139
-            if (! empty($event_status)) {
2140
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2141
-            } else {
2142
-                $success = false;
2143
-                $msg = esc_html__(
2144
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2145
-                    'event_espresso'
2146
-                );
2147
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2148
-            }
2149
-        } else {
2150
-            $success = false;
2151
-            $msg = esc_html__(
2152
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2153
-                'event_espresso'
2154
-            );
2155
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2156
-        }
2157
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2158
-        if ($redirect_after) {
2159
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2160
-        }
2161
-    }
2162
-
2163
-
2164
-    /**
2165
-     * _trash_or_restore_events
2166
-     *
2167
-     * @param string $event_status
2168
-     * @return void
2169
-     * @throws EE_Error
2170
-     * @throws InvalidArgumentException
2171
-     * @throws InvalidDataTypeException
2172
-     * @throws InvalidInterfaceException
2173
-     * @throws ReflectionException
2174
-     */
2175
-    protected function _trash_or_restore_events($event_status = 'trash')
2176
-    {
2177
-        // clean status
2178
-        $event_status = sanitize_key($event_status);
2179
-        // grab status
2180
-        if (! empty($event_status)) {
2181
-            $success = true;
2182
-            // determine the event id and set to array.
2183
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2184
-            // loop thru events
2185
-            foreach ($EVT_IDs as $EVT_ID) {
2186
-                if ($EVT_ID = absint($EVT_ID)) {
2187
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2188
-                    $success = $results !== false ? $success : false;
2189
-                } else {
2190
-                    $msg = sprintf(
2191
-                        esc_html__(
2192
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2193
-                            'event_espresso'
2194
-                        ),
2195
-                        $EVT_ID
2196
-                    );
2197
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2198
-                    $success = false;
2199
-                }
2200
-            }
2201
-        } else {
2202
-            $success = false;
2203
-            $msg = esc_html__(
2204
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2205
-                'event_espresso'
2206
-            );
2207
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2208
-        }
2209
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2210
-        $success = $success ? 2 : false;
2211
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2212
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2213
-    }
2214
-
2215
-
2216
-    /**
2217
-     * _trash_or_restore_events
2218
-     *
2219
-     * @param int    $EVT_ID
2220
-     * @param string $event_status
2221
-     * @return bool
2222
-     * @throws EE_Error
2223
-     * @throws InvalidArgumentException
2224
-     * @throws InvalidDataTypeException
2225
-     * @throws InvalidInterfaceException
2226
-     * @throws ReflectionException
2227
-     */
2228
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2229
-    {
2230
-        // grab event id
2231
-        if (! $EVT_ID) {
2232
-            $msg = esc_html__(
2233
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2234
-                'event_espresso'
2235
-            );
2236
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2237
-            return false;
2238
-        }
2239
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2240
-        // clean status
2241
-        $event_status = sanitize_key($event_status);
2242
-        // grab status
2243
-        if (empty($event_status)) {
2244
-            $msg = esc_html__(
2245
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2246
-                'event_espresso'
2247
-            );
2248
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2249
-            return false;
2250
-        }
2251
-        // was event trashed or restored ?
2252
-        switch ($event_status) {
2253
-            case 'draft':
2254
-                $action = 'restored from the trash';
2255
-                $hook = 'AHEE_event_restored_from_trash';
2256
-                break;
2257
-            case 'trash':
2258
-                $action = 'moved to the trash';
2259
-                $hook = 'AHEE_event_moved_to_trash';
2260
-                break;
2261
-            default:
2262
-                $action = 'updated';
2263
-                $hook = false;
2264
-        }
2265
-        // use class to change status
2266
-        $this->_cpt_model_obj->set_status($event_status);
2267
-        $success = $this->_cpt_model_obj->save();
2268
-        if ($success === false) {
2269
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2270
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2271
-            return false;
2272
-        }
2273
-        if ($hook) {
2274
-            do_action($hook);
2275
-        }
2276
-        return true;
2277
-    }
2278
-
2279
-
2280
-    /**
2281
-     * _delete_event
2282
-     *
2283
-     * @param bool $redirect_after
2284
-     * @throws EE_Error
2285
-     * @throws InvalidArgumentException
2286
-     * @throws InvalidDataTypeException
2287
-     * @throws InvalidInterfaceException
2288
-     * @throws ReflectionException
2289
-     */
2290
-    protected function _delete_event()
2291
-    {
2292
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2293
-    }
2294
-
2295
-    /**
2296
-     * Gets the tree traversal batch persister.
2297
-     * @since $VID:$
2298
-     * @return NodeGroupDao
2299
-     * @throws InvalidArgumentException
2300
-     * @throws InvalidDataTypeException
2301
-     * @throws InvalidInterfaceException
2302
-     */
2303
-    protected function getModelObjNodeGroupPersister()
2304
-    {
2305
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2306
-            $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2307
-        }
2308
-        return $this->model_obj_node_group_persister;
2309
-    }
2310
-
2311
-    /**
2312
-     * _delete_events
2313
-     *
2314
-     * @return void
2315
-     * @throws EE_Error
2316
-     * @throws InvalidArgumentException
2317
-     * @throws InvalidDataTypeException
2318
-     * @throws InvalidInterfaceException
2319
-     * @throws ReflectionException
2320
-     */
2321
-    protected function _delete_events()
2322
-    {
2323
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2324
-    }
2325
-
2326
-    protected function generateDeletionPreview($event_ids)
2327
-    {
2328
-        $event_ids = (array) $event_ids;
2329
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2330
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2331
-        $return_url = EE_Admin_Page::add_query_args_and_nonce(
2332
-            [
2333
-                'action' => 'preview_deletion',
2334
-                'deletion_job_code' => $deletion_job_code,
2335
-            ],
2336
-            $this->_admin_base_url
2337
-        );
2338
-        $event_ids = array_map(
2339
-            'intval',
2340
-            $event_ids
2341
-        );
2342
-
2343
-        EEH_URL::safeRedirectAndExit(
2344
-            EE_Admin_Page::add_query_args_and_nonce(
2345
-                [
2346
-                    'page'              => 'espresso_batch',
2347
-                    'batch'             => EED_Batch::batch_job,
2348
-                    'EVT_IDs'           => $event_ids,
2349
-                    'deletion_job_code' => $deletion_job_code,
2350
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2351
-                    'return_url'        => urlencode($return_url),
2352
-                ],
2353
-                admin_url()
2354
-            )
2355
-        );
2356
-    }
2357
-
2358
-    /**
2359
-     * Checks for a POST submission
2360
-     * @since $VID:$
2361
-     */
2362
-    protected function confirmDeletion()
2363
-    {
2364
-        $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2365
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2366
-    }
2367
-
2368
-    /**
2369
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2370
-     * @since $VID:$
2371
-     * @throws EE_Error
2372
-     */
2373
-    protected function previewDeletion()
2374
-    {
2375
-        $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2376
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2377
-        $this->display_admin_page_with_no_sidebar();
2378
-    }
2379
-
2380
-    /**
2381
-     * get total number of events
2382
-     *
2383
-     * @return int
2384
-     * @throws EE_Error
2385
-     * @throws InvalidArgumentException
2386
-     * @throws InvalidDataTypeException
2387
-     * @throws InvalidInterfaceException
2388
-     */
2389
-    public function total_events()
2390
-    {
2391
-        $count = EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2392
-        return $count;
2393
-    }
2394
-
2395
-
2396
-    /**
2397
-     * get total number of draft events
2398
-     *
2399
-     * @return int
2400
-     * @throws EE_Error
2401
-     * @throws InvalidArgumentException
2402
-     * @throws InvalidDataTypeException
2403
-     * @throws InvalidInterfaceException
2404
-     */
2405
-    public function total_events_draft()
2406
-    {
2407
-        $where = [
2408
-            'status' => ['IN', ['draft', 'auto-draft']],
2409
-        ];
2410
-        $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2411
-        return $count;
2412
-    }
2413
-
2414
-
2415
-    /**
2416
-     * get total number of trashed events
2417
-     *
2418
-     * @return int
2419
-     * @throws EE_Error
2420
-     * @throws InvalidArgumentException
2421
-     * @throws InvalidDataTypeException
2422
-     * @throws InvalidInterfaceException
2423
-     */
2424
-    public function total_trashed_events()
2425
-    {
2426
-        $where = [
2427
-            'status' => 'trash',
2428
-        ];
2429
-        $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2430
-        return $count;
2431
-    }
2432
-
2433
-
2434
-    /**
2435
-     *    _default_event_settings
2436
-     *    This generates the Default Settings Tab
2437
-     *
2438
-     * @return void
2439
-     * @throws DomainException
2440
-     * @throws EE_Error
2441
-     * @throws InvalidArgumentException
2442
-     * @throws InvalidDataTypeException
2443
-     * @throws InvalidInterfaceException
2444
-     */
2445
-    protected function _default_event_settings()
2446
-    {
2447
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2448
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2449
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2450
-        $this->display_admin_page_with_sidebar();
2451
-    }
2452
-
2453
-
2454
-    /**
2455
-     * Return the form for event settings.
2456
-     *
2457
-     * @return EE_Form_Section_Proper
2458
-     * @throws EE_Error
2459
-     */
2460
-    protected function _default_event_settings_form()
2461
-    {
2462
-        $registration_config = EE_Registry::instance()->CFG->registration;
2463
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2464
-        // exclude
2465
-            [
2466
-                EEM_Registration::status_id_cancelled,
2467
-                EEM_Registration::status_id_declined,
2468
-                EEM_Registration::status_id_incomplete,
2469
-                EEM_Registration::status_id_wait_list,
2470
-            ],
2471
-            true
2472
-        );
2473
-        return new EE_Form_Section_Proper(
2474
-            [
2475
-                'name'            => 'update_default_event_settings',
2476
-                'html_id'         => 'update_default_event_settings',
2477
-                'html_class'      => 'form-table',
2478
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2479
-                'subsections'     => apply_filters(
2480
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2481
-                    [
2482
-                        'default_reg_status'  => new EE_Select_Input(
2483
-                            $registration_stati_for_selection,
2484
-                            [
2485
-                                'default'         => isset($registration_config->default_STS_ID)
2486
-                                                     && array_key_exists(
2487
-                                                         $registration_config->default_STS_ID,
2488
-                                                         $registration_stati_for_selection
2489
-                                                     )
2490
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2491
-                                    : EEM_Registration::status_id_pending_payment,
2492
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2493
-                                                     . EEH_Template::get_help_tab_link(
2494
-                                                         'default_settings_status_help_tab'
2495
-                                                     ),
2496
-                                'html_help_text'  => esc_html__(
2497
-                                    '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.',
2498
-                                    'event_espresso'
2499
-                                ),
2500
-                            ]
2501
-                        ),
2502
-                        'default_max_tickets' => new EE_Integer_Input(
2503
-                            [
2504
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2505
-                                    ? $registration_config->default_maximum_number_of_tickets
2506
-                                    : EEM_Event::get_default_additional_limit(),
2507
-                                'html_label_text' => esc_html__(
2508
-                                    'Default Maximum Tickets Allowed Per Order:',
2509
-                                    'event_espresso'
2510
-                                )
2511
-                                                     . EEH_Template::get_help_tab_link(
2512
-                                                         'default_maximum_tickets_help_tab"'
2513
-                                                     ),
2514
-                                'html_help_text'  => esc_html__(
2515
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2516
-                                    'event_espresso'
2517
-                                ),
2518
-                            ]
2519
-                        ),
2520
-                    ]
2521
-                ),
2522
-            ]
2523
-        );
2524
-    }
2525
-
2526
-
2527
-    /**
2528
-     * @return void
2529
-     * @throws EE_Error
2530
-     * @throws InvalidArgumentException
2531
-     * @throws InvalidDataTypeException
2532
-     * @throws InvalidInterfaceException
2533
-     */
2534
-    protected function _update_default_event_settings()
2535
-    {
2536
-        $form = $this->_default_event_settings_form();
2537
-        if ($form->was_submitted()) {
2538
-            $form->receive_form_submission();
2539
-            if ($form->is_valid()) {
2540
-                $registration_config = EE_Registry::instance()->CFG->registration;
2541
-                $valid_data = $form->valid_data();
2542
-                if (isset($valid_data['default_reg_status'])) {
2543
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2544
-                }
2545
-                if (isset($valid_data['default_max_tickets'])) {
2546
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2547
-                }
2548
-                do_action(
2549
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2550
-                    $valid_data,
2551
-                    EE_Registry::instance()->CFG,
2552
-                    $this
2553
-                );
2554
-                // update because data was valid!
2555
-                EE_Registry::instance()->CFG->update_espresso_config();
2556
-                EE_Error::overwrite_success();
2557
-                EE_Error::add_success(
2558
-                    __('Default Event Settings were updated', 'event_espresso')
2559
-                );
2560
-            }
2561
-        }
2562
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2563
-    }
2564
-
2565
-
2566
-    /*************        Templates        *************/
2567
-    protected function _template_settings()
2568
-    {
2569
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2570
-        $this->_template_args['preview_img'] = '<img src="'
2571
-                                               . EVENTS_ASSETS_URL
2572
-                                               . '/images/'
2573
-                                               . 'caffeinated_template_features.jpg" alt="'
2574
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2575
-                                               . '" />';
2576
-        $this->_template_args['preview_text'] = '<strong>'
2577
-                                                . esc_html__(
2578
-                                                    '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.',
2579
-                                                    'event_espresso'
2580
-                                                ) . '</strong>';
2581
-        $this->display_admin_caf_preview_page('template_settings_tab');
2582
-    }
2583
-
2584
-
2585
-    /** Event Category Stuff **/
2586
-    /**
2587
-     * set the _category property with the category object for the loaded page.
2588
-     *
2589
-     * @return void
2590
-     */
2591
-    private function _set_category_object()
2592
-    {
2593
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2594
-            return;
2595
-        } //already have the category object so get out.
2596
-        // set default category object
2597
-        $this->_set_empty_category_object();
2598
-        // only set if we've got an id
2599
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2600
-            return;
2601
-        }
2602
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2603
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2604
-        if (! empty($term)) {
2605
-            $this->_category->category_name = $term->name;
2606
-            $this->_category->category_identifier = $term->slug;
2607
-            $this->_category->category_desc = $term->description;
2608
-            $this->_category->id = $term->term_id;
2609
-            $this->_category->parent = $term->parent;
2610
-        }
2611
-    }
2612
-
2613
-
2614
-    /**
2615
-     * Clears out category properties.
2616
-     */
2617
-    private function _set_empty_category_object()
2618
-    {
2619
-        $this->_category = new stdClass();
2620
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2621
-        $this->_category->id = $this->_category->parent = 0;
2622
-    }
2623
-
2624
-
2625
-    /**
2626
-     * @throws DomainException
2627
-     * @throws EE_Error
2628
-     * @throws InvalidArgumentException
2629
-     * @throws InvalidDataTypeException
2630
-     * @throws InvalidInterfaceException
2631
-     */
2632
-    protected function _category_list_table()
2633
-    {
2634
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2635
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2636
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2637
-            'add_category',
2638
-            'add_category',
2639
-            [],
2640
-            'add-new-h2'
2641
-        );
2642
-        $this->display_admin_list_table_page_with_sidebar();
2643
-    }
2644
-
2645
-
2646
-    /**
2647
-     * Output category details view.
2648
-     *
2649
-     * @param string $view
2650
-     * @throws DomainException
2651
-     * @throws EE_Error
2652
-     * @throws InvalidArgumentException
2653
-     * @throws InvalidDataTypeException
2654
-     * @throws InvalidInterfaceException
2655
-     */
2656
-    protected function _category_details($view)
2657
-    {
2658
-        // load formatter helper
2659
-        // load field generator helper
2660
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2661
-        $this->_set_add_edit_form_tags($route);
2662
-        $this->_set_category_object();
2663
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2664
-        $delete_action = 'delete_category';
2665
-        // custom redirect
2666
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2667
-            ['action' => 'category_list'],
2668
-            $this->_admin_base_url
2669
-        );
2670
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2671
-        // take care of contents
2672
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2673
-        $this->display_admin_page_with_sidebar();
2674
-    }
2675
-
2676
-
2677
-    /**
2678
-     * Output category details content.
2679
-     *
2680
-     * @throws DomainException
2681
-     */
2682
-    protected function _category_details_content()
2683
-    {
2684
-        $editor_args['category_desc'] = [
2685
-            'type'          => 'wp_editor',
2686
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2687
-            'class'         => 'my_editor_custom',
2688
-            'wpeditor_args' => ['media_buttons' => false],
2689
-        ];
2690
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2691
-        $all_terms = get_terms(
2692
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2693
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2694
-        );
2695
-        // setup category select for term parents.
2696
-        $category_select_values[] = [
2697
-            'text' => esc_html__('No Parent', 'event_espresso'),
2698
-            'id'   => 0,
2699
-        ];
2700
-        foreach ($all_terms as $term) {
2701
-            $category_select_values[] = [
2702
-                'text' => $term->name,
2703
-                'id'   => $term->term_id,
2704
-            ];
2705
-        }
2706
-        $category_select = EEH_Form_Fields::select_input(
2707
-            'category_parent',
2708
-            $category_select_values,
2709
-            $this->_category->parent
2710
-        );
2711
-        $template_args = [
2712
-            'category'                 => $this->_category,
2713
-            'category_select'          => $category_select,
2714
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2715
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2716
-            'disable'                  => '',
2717
-            'disabled_message'         => false,
2718
-        ];
2719
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2720
-        return EEH_Template::display_template($template, $template_args, true);
2721
-    }
2722
-
2723
-
2724
-    /**
2725
-     * Handles deleting categories.
2726
-     */
2727
-    protected function _delete_categories()
2728
-    {
2729
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2730
-            : (array) $this->_req_data['category_id'];
2731
-        foreach ($cat_ids as $cat_id) {
2732
-            $this->_delete_category($cat_id);
2733
-        }
2734
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2735
-        $query_args = [
2736
-            'action' => 'category_list',
2737
-        ];
2738
-        $this->_redirect_after_action(0, '', '', $query_args);
2739
-    }
2740
-
2741
-
2742
-    /**
2743
-     * Handles deleting specific category.
2744
-     *
2745
-     * @param int $cat_id
2746
-     */
2747
-    protected function _delete_category($cat_id)
2748
-    {
2749
-        $cat_id = absint($cat_id);
2750
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2751
-    }
2752
-
2753
-
2754
-    /**
2755
-     * Handles triggering the update or insertion of a new category.
2756
-     *
2757
-     * @param bool $new_category true means we're triggering the insert of a new category.
2758
-     * @throws EE_Error
2759
-     * @throws InvalidArgumentException
2760
-     * @throws InvalidDataTypeException
2761
-     * @throws InvalidInterfaceException
2762
-     */
2763
-    protected function _insert_or_update_category($new_category)
2764
-    {
2765
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2766
-        $success = 0; // we already have a success message so lets not send another.
2767
-        if ($cat_id) {
2768
-            $query_args = [
2769
-                'action'     => 'edit_category',
2770
-                'EVT_CAT_ID' => $cat_id,
2771
-            ];
2772
-        } else {
2773
-            $query_args = ['action' => 'add_category'];
2774
-        }
2775
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2776
-    }
2777
-
2778
-
2779
-    /**
2780
-     * Inserts or updates category
2781
-     *
2782
-     * @param bool $update (true indicates we're updating a category).
2783
-     * @return bool|mixed|string
2784
-     */
2785
-    private function _insert_category($update = false)
2786
-    {
2787
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2788
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2789
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2790
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2791
-        if (empty($category_name)) {
2792
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2793
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2794
-            return false;
2795
-        }
2796
-        $term_args = [
2797
-            'name'        => $category_name,
2798
-            'description' => $category_desc,
2799
-            'parent'      => $category_parent,
2800
-        ];
2801
-        // was the category_identifier input disabled?
2802
-        if (isset($this->_req_data['category_identifier'])) {
2803
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2804
-        }
2805
-        $insert_ids = $update
2806
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2807
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2808
-        if (! is_array($insert_ids)) {
2809
-            $msg = esc_html__(
2810
-                'An error occurred and the category has not been saved to the database.',
2811
-                'event_espresso'
2812
-            );
2813
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2814
-        } else {
2815
-            $cat_id = $insert_ids['term_id'];
2816
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2817
-            EE_Error::add_success($msg);
2818
-        }
2819
-        return $cat_id;
2820
-    }
2821
-
2822
-
2823
-    /**
2824
-     * Gets categories or count of categories matching the arguments in the request.
2825
-     *
2826
-     * @param int  $per_page
2827
-     * @param int  $current_page
2828
-     * @param bool $count
2829
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2830
-     * @throws EE_Error
2831
-     * @throws InvalidArgumentException
2832
-     * @throws InvalidDataTypeException
2833
-     * @throws InvalidInterfaceException
2834
-     */
2835
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2836
-    {
2837
-        // testing term stuff
2838
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2839
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2840
-        $limit = ($current_page - 1) * $per_page;
2841
-        $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2842
-        if (isset($this->_req_data['s'])) {
2843
-            $sstr = '%' . $this->_req_data['s'] . '%';
2844
-            $where['OR'] = [
2845
-                'Term.name'   => ['LIKE', $sstr],
2846
-                'description' => ['LIKE', $sstr],
2847
-            ];
2848
-        }
2849
-        $query_params = [
2850
-            $where,
2851
-            'order_by'   => [$orderby => $order],
2852
-            'limit'      => $limit . ',' . $per_page,
2853
-            'force_join' => ['Term'],
2854
-        ];
2855
-        $categories = $count
2856
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2857
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2858
-        return $categories;
2859
-    }
2860
-
2861
-    /* end category stuff */
2862
-    /**************/
2863
-
2864
-
2865
-    /**
2866
-     * Callback for the `ee_save_timezone_setting` ajax action.
2867
-     *
2868
-     * @throws EE_Error
2869
-     * @throws InvalidArgumentException
2870
-     * @throws InvalidDataTypeException
2871
-     * @throws InvalidInterfaceException
2872
-     */
2873
-    public function save_timezonestring_setting()
2874
-    {
2875
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2876
-            ? $this->_req_data['timezone_selected']
2877
-            : '';
2878
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2879
-            EE_Error::add_error(
2880
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2881
-                __FILE__,
2882
-                __FUNCTION__,
2883
-                __LINE__
2884
-            );
2885
-            $this->_template_args['error'] = true;
2886
-            $this->_return_json();
2887
-        }
2888
-
2889
-        update_option('timezone_string', $timezone_string);
2890
-        EE_Error::add_success(
2891
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2892
-        );
2893
-        $this->_template_args['success'] = true;
2894
-        $this->_return_json(true, ['action' => 'create_new']);
2895
-    }
23
+	/**
24
+	 * This will hold the event object for event_details screen.
25
+	 *
26
+	 * @var EE_Event $_event
27
+	 */
28
+	protected $_event;
29
+
30
+
31
+	/**
32
+	 * This will hold the category object for category_details screen.
33
+	 *
34
+	 * @var stdClass $_category
35
+	 */
36
+	protected $_category;
37
+
38
+
39
+	/**
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+	/**
45
+	 * @var EEM_Datetime $datetime_model
46
+	 */
47
+	protected $datetime_model;
48
+
49
+	/**
50
+	 * @var EEM_Ticket $ticket_model
51
+	 */
52
+	protected $ticket_model;
53
+
54
+
55
+	/**
56
+	 * @var EE_Event
57
+	 */
58
+	protected $_cpt_model_obj;
59
+
60
+
61
+	/**
62
+	 * @var NodeGroupDao
63
+	 */
64
+	protected $model_obj_node_group_persister;
65
+
66
+	/**
67
+	 * Initialize page props for this admin page group.
68
+	 */
69
+	protected function _init_page_props()
70
+	{
71
+		$this->page_slug = EVENTS_PG_SLUG;
72
+		$this->page_label = EVENTS_LABEL;
73
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
74
+		$this->_admin_base_path = EVENTS_ADMIN;
75
+		$this->_cpt_model_names = [
76
+			'create_new' => 'EEM_Event',
77
+			'edit'       => 'EEM_Event',
78
+		];
79
+		$this->_cpt_edit_routes = [
80
+			'espresso_events' => 'edit',
81
+		];
82
+		add_action(
83
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
84
+			[$this, 'verify_event_edit'],
85
+			10,
86
+			2
87
+		);
88
+	}
89
+
90
+
91
+	/**
92
+	 * Sets the ajax hooks used for this admin page group.
93
+	 */
94
+	protected function _ajax_hooks()
95
+	{
96
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
97
+	}
98
+
99
+
100
+	/**
101
+	 * Sets the page properties for this admin page group.
102
+	 */
103
+	protected function _define_page_props()
104
+	{
105
+		$this->_admin_page_title = EVENTS_LABEL;
106
+		$this->_labels = [
107
+			'buttons'      => [
108
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
109
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
110
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
111
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
112
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
113
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
114
+			],
115
+			'editor_title' => [
116
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
117
+			],
118
+			'publishbox'   => [
119
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
120
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
121
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
122
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
123
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
124
+			],
125
+		];
126
+	}
127
+
128
+
129
+	/**
130
+	 * Sets the page routes property for this admin page group.
131
+	 */
132
+	protected function _set_page_routes()
133
+	{
134
+		// load formatter helper
135
+		// load field generator helper
136
+		// is there a evt_id in the request?
137
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
138
+			? $this->_req_data['EVT_ID']
139
+			: 0;
140
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
141
+		$this->_page_routes = [
142
+			'default'                       => [
143
+				'func'       => '_events_overview_list_table',
144
+				'capability' => 'ee_read_events',
145
+			],
146
+			'create_new'                    => [
147
+				'func'       => '_create_new_cpt_item',
148
+				'capability' => 'ee_edit_events',
149
+			],
150
+			'edit'                          => [
151
+				'func'       => '_edit_cpt_item',
152
+				'capability' => 'ee_edit_event',
153
+				'obj_id'     => $evt_id,
154
+			],
155
+			'copy_event'                    => [
156
+				'func'       => '_copy_events',
157
+				'capability' => 'ee_edit_event',
158
+				'obj_id'     => $evt_id,
159
+				'noheader'   => true,
160
+			],
161
+			'trash_event'                   => [
162
+				'func'       => '_trash_or_restore_event',
163
+				'args'       => ['event_status' => 'trash'],
164
+				'capability' => 'ee_delete_event',
165
+				'obj_id'     => $evt_id,
166
+				'noheader'   => true,
167
+			],
168
+			'trash_events'                  => [
169
+				'func'       => '_trash_or_restore_events',
170
+				'args'       => ['event_status' => 'trash'],
171
+				'capability' => 'ee_delete_events',
172
+				'noheader'   => true,
173
+			],
174
+			'restore_event'                 => [
175
+				'func'       => '_trash_or_restore_event',
176
+				'args'       => ['event_status' => 'draft'],
177
+				'capability' => 'ee_delete_event',
178
+				'obj_id'     => $evt_id,
179
+				'noheader'   => true,
180
+			],
181
+			'restore_events'                => [
182
+				'func'       => '_trash_or_restore_events',
183
+				'args'       => ['event_status' => 'draft'],
184
+				'capability' => 'ee_delete_events',
185
+				'noheader'   => true,
186
+			],
187
+			'delete_event'                  => [
188
+				'func'       => '_delete_event',
189
+				'capability' => 'ee_delete_event',
190
+				'obj_id'     => $evt_id,
191
+				'noheader'   => true,
192
+			],
193
+			'delete_events'                 => [
194
+				'func'       => '_delete_events',
195
+				'capability' => 'ee_delete_events',
196
+				'noheader'   => true,
197
+			],
198
+			'view_report'                   => [
199
+				'func'       => '_view_report',
200
+				'capability' => 'ee_edit_events',
201
+			],
202
+			'default_event_settings'        => [
203
+				'func'       => '_default_event_settings',
204
+				'capability' => 'manage_options',
205
+			],
206
+			'update_default_event_settings' => [
207
+				'func'       => '_update_default_event_settings',
208
+				'capability' => 'manage_options',
209
+				'noheader'   => true,
210
+			],
211
+			'template_settings'             => [
212
+				'func'       => '_template_settings',
213
+				'capability' => 'manage_options',
214
+			],
215
+			// event category tab related
216
+			'add_category'                  => [
217
+				'func'       => '_category_details',
218
+				'capability' => 'ee_edit_event_category',
219
+				'args'       => ['add'],
220
+			],
221
+			'edit_category'                 => [
222
+				'func'       => '_category_details',
223
+				'capability' => 'ee_edit_event_category',
224
+				'args'       => ['edit'],
225
+			],
226
+			'delete_categories'             => [
227
+				'func'       => '_delete_categories',
228
+				'capability' => 'ee_delete_event_category',
229
+				'noheader'   => true,
230
+			],
231
+			'delete_category'               => [
232
+				'func'       => '_delete_categories',
233
+				'capability' => 'ee_delete_event_category',
234
+				'noheader'   => true,
235
+			],
236
+			'insert_category'               => [
237
+				'func'       => '_insert_or_update_category',
238
+				'args'       => ['new_category' => true],
239
+				'capability' => 'ee_edit_event_category',
240
+				'noheader'   => true,
241
+			],
242
+			'update_category'               => [
243
+				'func'       => '_insert_or_update_category',
244
+				'args'       => ['new_category' => false],
245
+				'capability' => 'ee_edit_event_category',
246
+				'noheader'   => true,
247
+			],
248
+			'category_list'                 => [
249
+				'func'       => '_category_list_table',
250
+				'capability' => 'ee_manage_event_categories',
251
+			],
252
+			'preview_deletion' => [
253
+				'func' => 'previewDeletion',
254
+				'capability' => 'ee_delete_events',
255
+			],
256
+			'confirm_deletion' => [
257
+				'func' => 'confirmDeletion',
258
+				'capability' => 'ee_delete_events',
259
+				'noheader' => true,
260
+			]
261
+		];
262
+	}
263
+
264
+
265
+	/**
266
+	 * Set the _page_config property for this admin page group.
267
+	 */
268
+	protected function _set_page_config()
269
+	{
270
+		$this->_page_config = [
271
+			'default'                => [
272
+				'nav'           => [
273
+					'label' => esc_html__('Overview', 'event_espresso'),
274
+					'order' => 10,
275
+				],
276
+				'list_table'    => 'Events_Admin_List_Table',
277
+				'help_tabs'     => [
278
+					'events_overview_help_tab'                       => [
279
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
280
+						'filename' => 'events_overview',
281
+					],
282
+					'events_overview_table_column_headings_help_tab' => [
283
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
284
+						'filename' => 'events_overview_table_column_headings',
285
+					],
286
+					'events_overview_filters_help_tab'               => [
287
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
288
+						'filename' => 'events_overview_filters',
289
+					],
290
+					'events_overview_view_help_tab'                  => [
291
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
292
+						'filename' => 'events_overview_views',
293
+					],
294
+					'events_overview_other_help_tab'                 => [
295
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
296
+						'filename' => 'events_overview_other',
297
+					],
298
+				],
299
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
300
+				// 'help_tour'     => [
301
+				//     'Event_Overview_Help_Tour',
302
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
303
+				// ],
304
+				'require_nonce' => false,
305
+				'qtips'         => ['EE_Event_List_Table_Tips'],
306
+			],
307
+			'create_new'             => [
308
+				'nav'           => [
309
+					'label'      => esc_html__('Add Event', 'event_espresso'),
310
+					'order'      => 5,
311
+					'persistent' => false,
312
+				],
313
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
314
+				'help_tabs'     => [
315
+					'event_editor_help_tab'                            => [
316
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
317
+						'filename' => 'event_editor',
318
+					],
319
+					'event_editor_title_richtexteditor_help_tab'       => [
320
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
321
+						'filename' => 'event_editor_title_richtexteditor',
322
+					],
323
+					'event_editor_venue_details_help_tab'              => [
324
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
325
+						'filename' => 'event_editor_venue_details',
326
+					],
327
+					'event_editor_event_datetimes_help_tab'            => [
328
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
329
+						'filename' => 'event_editor_event_datetimes',
330
+					],
331
+					'event_editor_event_tickets_help_tab'              => [
332
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
333
+						'filename' => 'event_editor_event_tickets',
334
+					],
335
+					'event_editor_event_registration_options_help_tab' => [
336
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
337
+						'filename' => 'event_editor_event_registration_options',
338
+					],
339
+					'event_editor_tags_categories_help_tab'            => [
340
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
341
+						'filename' => 'event_editor_tags_categories',
342
+					],
343
+					'event_editor_questions_registrants_help_tab'      => [
344
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
345
+						'filename' => 'event_editor_questions_registrants',
346
+					],
347
+					'event_editor_save_new_event_help_tab'             => [
348
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
349
+						'filename' => 'event_editor_save_new_event',
350
+					],
351
+					'event_editor_other_help_tab'                      => [
352
+						'title'    => esc_html__('Event Other', 'event_espresso'),
353
+						'filename' => 'event_editor_other',
354
+					],
355
+				],
356
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
357
+				// 'help_tour'     => [
358
+				//     'Event_Editor_Help_Tour',
359
+				// ],
360
+				'require_nonce' => false,
361
+			],
362
+			'edit'                   => [
363
+				'nav'           => [
364
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
365
+					'order'      => 5,
366
+					'persistent' => false,
367
+					'url'        => isset($this->_req_data['post'])
368
+						? EE_Admin_Page::add_query_args_and_nonce(
369
+							['post' => $this->_req_data['post'], 'action' => 'edit'],
370
+							$this->_current_page_view_url
371
+						)
372
+						: $this->_admin_base_url,
373
+				],
374
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
375
+				'help_tabs'     => [
376
+					'event_editor_help_tab'                            => [
377
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
378
+						'filename' => 'event_editor',
379
+					],
380
+					'event_editor_title_richtexteditor_help_tab'       => [
381
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
382
+						'filename' => 'event_editor_title_richtexteditor',
383
+					],
384
+					'event_editor_venue_details_help_tab'              => [
385
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
386
+						'filename' => 'event_editor_venue_details',
387
+					],
388
+					'event_editor_event_datetimes_help_tab'            => [
389
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
390
+						'filename' => 'event_editor_event_datetimes',
391
+					],
392
+					'event_editor_event_tickets_help_tab'              => [
393
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
394
+						'filename' => 'event_editor_event_tickets',
395
+					],
396
+					'event_editor_event_registration_options_help_tab' => [
397
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
398
+						'filename' => 'event_editor_event_registration_options',
399
+					],
400
+					'event_editor_tags_categories_help_tab'            => [
401
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
402
+						'filename' => 'event_editor_tags_categories',
403
+					],
404
+					'event_editor_questions_registrants_help_tab'      => [
405
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
406
+						'filename' => 'event_editor_questions_registrants',
407
+					],
408
+					'event_editor_save_new_event_help_tab'             => [
409
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
410
+						'filename' => 'event_editor_save_new_event',
411
+					],
412
+					'event_editor_other_help_tab'                      => [
413
+						'title'    => esc_html__('Event Other', 'event_espresso'),
414
+						'filename' => 'event_editor_other',
415
+					],
416
+				],
417
+				'require_nonce' => false,
418
+			],
419
+			'default_event_settings' => [
420
+				'nav'           => [
421
+					'label' => esc_html__('Default Settings', 'event_espresso'),
422
+					'order' => 40,
423
+				],
424
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
425
+				'labels'        => [
426
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
427
+				],
428
+				'help_tabs'     => [
429
+					'default_settings_help_tab'        => [
430
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
431
+						'filename' => 'events_default_settings',
432
+					],
433
+					'default_settings_status_help_tab' => [
434
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
435
+						'filename' => 'events_default_settings_status',
436
+					],
437
+					'default_maximum_tickets_help_tab' => [
438
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
439
+						'filename' => 'events_default_settings_max_tickets',
440
+					],
441
+				],
442
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
443
+				// 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
444
+				'require_nonce' => false,
445
+			],
446
+			// template settings
447
+			'template_settings'      => [
448
+				'nav'           => [
449
+					'label' => esc_html__('Templates', 'event_espresso'),
450
+					'order' => 30,
451
+				],
452
+				'metaboxes'     => $this->_default_espresso_metaboxes,
453
+				'help_tabs'     => [
454
+					'general_settings_templates_help_tab' => [
455
+						'title'    => esc_html__('Templates', 'event_espresso'),
456
+						'filename' => 'general_settings_templates',
457
+					],
458
+				],
459
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
460
+				// 'help_tour'     => ['Templates_Help_Tour'],
461
+				'require_nonce' => false,
462
+			],
463
+			// event category stuff
464
+			'add_category'           => [
465
+				'nav'           => [
466
+					'label'      => esc_html__('Add Category', 'event_espresso'),
467
+					'order'      => 15,
468
+					'persistent' => false,
469
+				],
470
+				'help_tabs'     => [
471
+					'add_category_help_tab' => [
472
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
473
+						'filename' => 'events_add_category',
474
+					],
475
+				],
476
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
477
+				// 'help_tour'     => ['Event_Add_Category_Help_Tour'],
478
+				'metaboxes'     => ['_publish_post_box'],
479
+				'require_nonce' => false,
480
+			],
481
+			'edit_category'          => [
482
+				'nav'           => [
483
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
484
+					'order'      => 15,
485
+					'persistent' => false,
486
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
487
+						? add_query_arg(
488
+							['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
489
+							$this->_current_page_view_url
490
+						)
491
+						: $this->_admin_base_url,
492
+				],
493
+				'help_tabs'     => [
494
+					'edit_category_help_tab' => [
495
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
496
+						'filename' => 'events_edit_category',
497
+					],
498
+				],
499
+				/*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
500
+				'metaboxes'     => ['_publish_post_box'],
501
+				'require_nonce' => false,
502
+			],
503
+			'category_list'          => [
504
+				'nav'           => [
505
+					'label' => esc_html__('Categories', 'event_espresso'),
506
+					'order' => 20,
507
+				],
508
+				'list_table'    => 'Event_Categories_Admin_List_Table',
509
+				'help_tabs'     => [
510
+					'events_categories_help_tab'                       => [
511
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
512
+						'filename' => 'events_categories',
513
+					],
514
+					'events_categories_table_column_headings_help_tab' => [
515
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
516
+						'filename' => 'events_categories_table_column_headings',
517
+					],
518
+					'events_categories_view_help_tab'                  => [
519
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
520
+						'filename' => 'events_categories_views',
521
+					],
522
+					'events_categories_other_help_tab'                 => [
523
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
524
+						'filename' => 'events_categories_other',
525
+					],
526
+				],
527
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
528
+				// 'help_tour'     => [
529
+				//     'Event_Categories_Help_Tour',
530
+				// ],
531
+				'metaboxes'     => $this->_default_espresso_metaboxes,
532
+				'require_nonce' => false,
533
+			],
534
+			'preview_deletion'       => [
535
+				'nav'           => [
536
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
537
+					'order'      => 15,
538
+					'persistent' => false,
539
+					'url'        => '',
540
+				],
541
+				'require_nonce' => false,
542
+			],
543
+		];
544
+		// only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
545
+		$domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
546
+		if (! $domain->isCaffeinated()) {
547
+			$this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
548
+			$this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
549
+		}
550
+	}
551
+
552
+
553
+	/**
554
+	 * Used to register any global screen options if necessary for every route in this admin page group.
555
+	 */
556
+	protected function _add_screen_options()
557
+	{
558
+	}
559
+
560
+
561
+	/**
562
+	 * Implementing the screen options for the 'default' route.
563
+	 *
564
+	 * @throws InvalidArgumentException
565
+	 * @throws InvalidDataTypeException
566
+	 * @throws InvalidInterfaceException
567
+	 */
568
+	protected function _add_screen_options_default()
569
+	{
570
+		$this->_per_page_screen_option();
571
+	}
572
+
573
+
574
+	/**
575
+	 * Implementing screen options for the category list route.
576
+	 *
577
+	 * @throws InvalidArgumentException
578
+	 * @throws InvalidDataTypeException
579
+	 * @throws InvalidInterfaceException
580
+	 */
581
+	protected function _add_screen_options_category_list()
582
+	{
583
+		$page_title = $this->_admin_page_title;
584
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
585
+		$this->_per_page_screen_option();
586
+		$this->_admin_page_title = $page_title;
587
+	}
588
+
589
+
590
+	/**
591
+	 * Used to register any global feature pointers for the admin page group.
592
+	 */
593
+	protected function _add_feature_pointers()
594
+	{
595
+	}
596
+
597
+
598
+	/**
599
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
600
+	 */
601
+	public function load_scripts_styles()
602
+	{
603
+		wp_register_style(
604
+			'events-admin-css',
605
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
606
+			[],
607
+			EVENT_ESPRESSO_VERSION
608
+		);
609
+		wp_register_style(
610
+			'ee-cat-admin',
611
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
612
+			[],
613
+			EVENT_ESPRESSO_VERSION
614
+		);
615
+		wp_enqueue_style('events-admin-css');
616
+		wp_enqueue_style('ee-cat-admin');
617
+		// scripts
618
+		wp_register_script(
619
+			'event_editor_js',
620
+			EVENTS_ASSETS_URL . 'event_editor.js',
621
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
622
+			EVENT_ESPRESSO_VERSION,
623
+			true
624
+		);
625
+	}
626
+
627
+
628
+	/**
629
+	 * Enqueuing scripts and styles specific to this view
630
+	 */
631
+	public function load_scripts_styles_create_new()
632
+	{
633
+		$this->load_scripts_styles_edit();
634
+	}
635
+
636
+
637
+	/**
638
+	 * Enqueuing scripts and styles specific to this view
639
+	 */
640
+	public function load_scripts_styles_edit()
641
+	{
642
+		// styles
643
+		wp_enqueue_style('espresso-ui-theme');
644
+		wp_register_style(
645
+			'event-editor-css',
646
+			EVENTS_ASSETS_URL . 'event-editor.css',
647
+			['ee-admin-css'],
648
+			EVENT_ESPRESSO_VERSION
649
+		);
650
+		wp_enqueue_style('event-editor-css');
651
+		// scripts
652
+		if (! $this->admin_config->useAdvancedEditor()) {
653
+			wp_register_script(
654
+				'event-datetime-metabox',
655
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
656
+				['event_editor_js', 'ee-datepicker'],
657
+				EVENT_ESPRESSO_VERSION
658
+			);
659
+			wp_enqueue_script('event-datetime-metabox');
660
+		}
661
+	}
662
+
663
+
664
+	/**
665
+	 * Populating the _views property for the category list table view.
666
+	 */
667
+	protected function _set_list_table_views_category_list()
668
+	{
669
+		$this->_views = [
670
+			'all' => [
671
+				'slug'        => 'all',
672
+				'label'       => esc_html__('All', 'event_espresso'),
673
+				'count'       => 0,
674
+				'bulk_action' => [
675
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
676
+				],
677
+			],
678
+		];
679
+	}
680
+
681
+
682
+	/**
683
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
684
+	 */
685
+	public function admin_init()
686
+	{
687
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
688
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
689
+			'event_espresso'
690
+		);
691
+	}
692
+
693
+
694
+	/**
695
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
696
+	 * group.
697
+	 */
698
+	public function admin_notices()
699
+	{
700
+	}
701
+
702
+
703
+	/**
704
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
705
+	 * this admin page group.
706
+	 */
707
+	public function admin_footer_scripts()
708
+	{
709
+	}
710
+
711
+
712
+	/**
713
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
714
+	 * warning (via EE_Error::add_error());
715
+	 *
716
+	 * @param EE_Event $event Event object
717
+	 * @param string   $req_type
718
+	 * @return void
719
+	 * @throws EE_Error
720
+	 */
721
+	public function verify_event_edit($event = null, $req_type = '')
722
+	{
723
+		// don't need to do this when processing
724
+		if (! empty($req_type)) {
725
+			return;
726
+		}
727
+		// no event?
728
+		if (! $event instanceof EE_Event) {
729
+			$event = $this->_cpt_model_obj;
730
+		}
731
+		// STILL no event?
732
+		if (! $event instanceof EE_Event) {
733
+			return;
734
+		}
735
+		$orig_status = $event->status();
736
+		// first check if event is active.
737
+		if (
738
+			$orig_status === EEM_Event::cancelled
739
+			|| $orig_status === EEM_Event::postponed
740
+			|| $event->is_expired()
741
+			|| $event->is_inactive()
742
+		) {
743
+			return;
744
+		}
745
+		// made it here so it IS active... next check that any of the tickets are sold.
746
+		if ($event->is_sold_out(true)) {
747
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
748
+				EE_Error::add_attention(
749
+					sprintf(
750
+						esc_html__(
751
+							'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.',
752
+							'event_espresso'
753
+						),
754
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
755
+					)
756
+				);
757
+			}
758
+			return;
759
+		}
760
+		if ($orig_status === EEM_Event::sold_out) {
761
+			EE_Error::add_attention(
762
+				sprintf(
763
+					esc_html__(
764
+						'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.',
765
+						'event_espresso'
766
+					),
767
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
768
+				)
769
+			);
770
+		}
771
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
772
+		if (! $event->tickets_on_sale()) {
773
+			return;
774
+		}
775
+		// made it here so show warning
776
+		$this->_edit_event_warning();
777
+	}
778
+
779
+
780
+	/**
781
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
782
+	 * When needed, hook this into a EE_Error::add_error() notice.
783
+	 *
784
+	 * @return void
785
+	 */
786
+	protected function _edit_event_warning()
787
+	{
788
+		// we don't want to add warnings during these requests
789
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
790
+			return;
791
+		}
792
+		EE_Error::add_attention(
793
+			sprintf(
794
+				esc_html__(
795
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
796
+					'event_espresso'
797
+				),
798
+				'<a class="espresso-help-tab-lnk">',
799
+				'</a>'
800
+			)
801
+		);
802
+	}
803
+
804
+
805
+	/**
806
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
807
+	 * Otherwise, do the normal logic
808
+	 *
809
+	 * @throws EE_Error
810
+	 * @throws InvalidArgumentException
811
+	 * @throws InvalidDataTypeException
812
+	 */
813
+	protected function _create_new_cpt_item()
814
+	{
815
+		$has_timezone_string = get_option('timezone_string');
816
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
817
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
818
+			EE_Error::add_attention(
819
+				sprintf(
820
+					__(
821
+						'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',
822
+						'event_espresso'
823
+					),
824
+					'<br>',
825
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
826
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
827
+					. '</select>',
828
+					'<button class="button button-secondary timezone-submit">',
829
+					'</button><span class="spinner"></span>'
830
+				),
831
+				__FILE__,
832
+				__FUNCTION__,
833
+				__LINE__
834
+			);
835
+		}
836
+		parent::_create_new_cpt_item();
837
+	}
838
+
839
+
840
+	/**
841
+	 * Sets the _views property for the default route in this admin page group.
842
+	 */
843
+	protected function _set_list_table_views_default()
844
+	{
845
+		$this->_views = [
846
+			'all'   => [
847
+				'slug'        => 'all',
848
+				'label'       => esc_html__('View All Events', 'event_espresso'),
849
+				'count'       => 0,
850
+				'bulk_action' => [
851
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
852
+				],
853
+			],
854
+			'draft' => [
855
+				'slug'        => 'draft',
856
+				'label'       => esc_html__('Draft', 'event_espresso'),
857
+				'count'       => 0,
858
+				'bulk_action' => [
859
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
860
+				],
861
+			],
862
+		];
863
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
864
+			$this->_views['trash'] = [
865
+				'slug'        => 'trash',
866
+				'label'       => esc_html__('Trash', 'event_espresso'),
867
+				'count'       => 0,
868
+				'bulk_action' => [
869
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
870
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
871
+				],
872
+			];
873
+		}
874
+	}
875
+
876
+
877
+	/**
878
+	 * Provides the legend item array for the default list table view.
879
+	 *
880
+	 * @return array
881
+	 */
882
+	protected function _event_legend_items()
883
+	{
884
+		$items = [
885
+			'view_details'   => [
886
+				'class' => 'dashicons dashicons-search',
887
+				'desc'  => esc_html__('View Event', 'event_espresso'),
888
+			],
889
+			'edit_event'     => [
890
+				'class' => 'ee-icon ee-icon-calendar-edit',
891
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
892
+			],
893
+			'view_attendees' => [
894
+				'class' => 'dashicons dashicons-groups',
895
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
896
+			],
897
+		];
898
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
899
+		$statuses = [
900
+			'sold_out_status'  => [
901
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
902
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
903
+			],
904
+			'active_status'    => [
905
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
906
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
907
+			],
908
+			'upcoming_status'  => [
909
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
910
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
911
+			],
912
+			'postponed_status' => [
913
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
914
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
915
+			],
916
+			'cancelled_status' => [
917
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
918
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
919
+			],
920
+			'expired_status'   => [
921
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
922
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
923
+			],
924
+			'inactive_status'  => [
925
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
926
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
927
+			],
928
+		];
929
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
930
+		return array_merge($items, $statuses);
931
+	}
932
+
933
+
934
+	/**
935
+	 * @return EEM_Event
936
+	 * @throws EE_Error
937
+	 */
938
+	private function eventModel()
939
+	{
940
+		if (! $this->_event_model instanceof EEM_Event) {
941
+			$this->_event_model = EEM_Event::instance();
942
+		}
943
+		return $this->_event_model;
944
+	}
945
+
946
+
947
+	/**
948
+	 * @param string $event_timezone_string
949
+	 * @return EEM_Datetime
950
+	 * @throws EE_Error
951
+	 */
952
+	private function datetimeModel($event_timezone_string = '')
953
+	{
954
+		if (! $this->datetime_model instanceof EEM_Datetime) {
955
+			$this->datetime_model = EEM_Datetime::instance($event_timezone_string);
956
+		}
957
+		return $this->datetime_model;
958
+	}
959
+
960
+
961
+	/**
962
+	 * @param string $event_timezone_string
963
+	 * @return EEM_Ticket
964
+	 * @throws EE_Error
965
+	 */
966
+	private function ticketModel($event_timezone_string = '')
967
+	{
968
+		if (! $this->ticket_model instanceof EEM_Ticket) {
969
+			$this->ticket_model = EEM_Ticket::instance($event_timezone_string);
970
+		}
971
+		return $this->ticket_model;
972
+	}
973
+
974
+
975
+	/**
976
+	 * Adds extra buttons to the WP CPT permalink field row.
977
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
978
+	 *
979
+	 * @param string $return    the current html
980
+	 * @param int    $id        the post id for the page
981
+	 * @param string $new_title What the title is
982
+	 * @param string $new_slug  what the slug is
983
+	 * @return string            The new html string for the permalink area
984
+	 */
985
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
986
+	{
987
+		// make sure this is only when editing
988
+		if (! empty($id)) {
989
+			$post = get_post($id);
990
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
991
+					   . esc_html__('Shortcode', 'event_espresso')
992
+					   . '</a> ';
993
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
994
+					   . $post->ID
995
+					   . ']">';
996
+		}
997
+		return $return;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * _events_overview_list_table
1003
+	 * This contains the logic for showing the events_overview list
1004
+	 *
1005
+	 * @return void
1006
+	 * @throws DomainException
1007
+	 * @throws EE_Error
1008
+	 * @throws InvalidArgumentException
1009
+	 * @throws InvalidDataTypeException
1010
+	 * @throws InvalidInterfaceException
1011
+	 */
1012
+	protected function _events_overview_list_table()
1013
+	{
1014
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1015
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
1016
+			? (array) $this->_template_args['after_list_table']
1017
+			: [];
1018
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
1019
+																			  . EEH_Template::get_button_or_link(
1020
+																				  get_post_type_archive_link('espresso_events'),
1021
+																				  esc_html__('View Event Archive Page', 'event_espresso'),
1022
+																				  'button'
1023
+																			  );
1024
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
1025
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1026
+			'create_new',
1027
+			'add',
1028
+			[],
1029
+			'add-new-h2'
1030
+		);
1031
+		$this->display_admin_list_table_page_with_no_sidebar();
1032
+	}
1033
+
1034
+
1035
+	/**
1036
+	 * this allows for extra misc actions in the default WP publish box
1037
+	 *
1038
+	 * @return void
1039
+	 * @throws DomainException
1040
+	 * @throws EE_Error
1041
+	 * @throws InvalidArgumentException
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidInterfaceException
1044
+	 * @throws ReflectionException
1045
+	 */
1046
+	public function extra_misc_actions_publish_box()
1047
+	{
1048
+		$this->_generate_publish_box_extra_content();
1049
+	}
1050
+
1051
+
1052
+	/**
1053
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1054
+	 * saved.
1055
+	 * Typically you would use this to save any additional data.
1056
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1057
+	 * ALSO very important.  When a post transitions from scheduled to published,
1058
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1059
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1060
+	 *
1061
+	 * @abstract
1062
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1063
+	 * @param object $post    The post object of the cpt that was saved.
1064
+	 * @return void
1065
+	 * @throws EE_Error
1066
+	 * @throws InvalidArgumentException
1067
+	 * @throws InvalidDataTypeException
1068
+	 * @throws InvalidInterfaceException
1069
+	 * @throws ReflectionException
1070
+	 */
1071
+	protected function _insert_update_cpt_item($post_id, $post)
1072
+	{
1073
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1074
+			// get out we're not processing an event save.
1075
+			return;
1076
+		}
1077
+		$event_values = [
1078
+			'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1079
+			'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1080
+			'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1081
+				? sanitize_text_field($this->_req_data['timezone_string'])
1082
+				: null,
1083
+		];
1084
+		/** @var FeatureFlags $flags */
1085
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1086
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1087
+		if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1088
+			$event_values['EVT_display_ticket_selector'] =
1089
+				! empty($this->_req_data['display_ticket_selector'])
1090
+					? 1
1091
+					: 0;
1092
+			$event_values['EVT_additional_limit'] = min(
1093
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1094
+				! empty($this->_req_data['additional_limit'])
1095
+					? absint($this->_req_data['additional_limit'])
1096
+					: null
1097
+			);
1098
+			$event_values['EVT_default_registration_status'] =
1099
+				! empty($this->_req_data['EVT_default_registration_status'])
1100
+					? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1101
+					: EE_Registry::instance()->CFG->registration->default_STS_ID;
1102
+			$event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL'])
1103
+				? esc_url_raw($this->_req_data['externalURL'])
1104
+				: null;
1105
+			$event_values['EVT_phone'] = ! empty($this->_req_data['event_phone'])
1106
+				? sanitize_text_field($this->_req_data['event_phone'])
1107
+				: null;
1108
+		}
1109
+		// update event
1110
+		$success = $this->eventModel()->update_by_ID($event_values, $post_id);
1111
+		// get event_object for other metaboxes...
1112
+		// though it would seem to make sense to just use $this->eventModel()->get_one_by_ID( $post_id )..
1113
+		// i have to setup where conditions to override the filters in the model
1114
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1115
+		$get_one_where = [
1116
+			$this->eventModel()->primary_key_name() => $post_id,
1117
+			'OR'                                    => [
1118
+				'status'   => $post->post_status,
1119
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1120
+				// but the returned object here has a status of "publish", so use the original post status as well
1121
+				'status*1' => $this->_req_data['original_post_status'],
1122
+			],
1123
+		];
1124
+		$event = $this->eventModel()->get_one([$get_one_where]);
1125
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1126
+		$event_update_callbacks = apply_filters(
1127
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1128
+			[
1129
+				[$this, '_default_venue_update'],
1130
+				[$this, '_default_tickets_update'],
1131
+			]
1132
+		);
1133
+		$att_success = true;
1134
+		foreach ($event_update_callbacks as $e_callback) {
1135
+			$_success = is_callable($e_callback)
1136
+				? $e_callback($event, $this->_req_data)
1137
+				: false;
1138
+			// if ANY of these updates fail then we want the appropriate global error message
1139
+			$att_success = ! $att_success ? $att_success : $_success;
1140
+		}
1141
+		// any errors?
1142
+		if ($success && false === $att_success) {
1143
+			EE_Error::add_error(
1144
+				esc_html__(
1145
+					'Event Details saved successfully but something went wrong with saving attachments.',
1146
+					'event_espresso'
1147
+				),
1148
+				__FILE__,
1149
+				__FUNCTION__,
1150
+				__LINE__
1151
+			);
1152
+		} elseif ($success === false) {
1153
+			EE_Error::add_error(
1154
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1155
+				__FILE__,
1156
+				__FUNCTION__,
1157
+				__LINE__
1158
+			);
1159
+		}
1160
+	}
1161
+
1162
+
1163
+	/**
1164
+	 * @param int $post_id
1165
+	 * @param int $revision_id
1166
+	 * @throws EE_Error
1167
+	 * @throws InvalidArgumentException
1168
+	 * @throws InvalidDataTypeException
1169
+	 * @throws InvalidInterfaceException
1170
+	 * @throws ReflectionException
1171
+	 * @see parent::restore_item()
1172
+	 */
1173
+	protected function _restore_cpt_item($post_id, $revision_id)
1174
+	{
1175
+		// copy existing event meta to new post
1176
+		$post_evt = $this->eventModel()->get_one_by_ID($post_id);
1177
+		if ($post_evt instanceof EE_Event) {
1178
+			// meta revision restore
1179
+			$post_evt->restore_revision($revision_id);
1180
+			// related objs restore
1181
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1182
+		}
1183
+	}
1184
+
1185
+
1186
+	/**
1187
+	 * Attach the venue to the Event
1188
+	 *
1189
+	 * @param EE_Event $evtobj Event Object to add the venue to
1190
+	 * @param array    $data   The request data from the form
1191
+	 * @return bool           Success or fail.
1192
+	 * @throws EE_Error
1193
+	 * @throws InvalidArgumentException
1194
+	 * @throws InvalidDataTypeException
1195
+	 * @throws InvalidInterfaceException
1196
+	 * @throws ReflectionException
1197
+	 */
1198
+	protected function _default_venue_update(EE_Event $evtobj, $data)
1199
+	{
1200
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1201
+		$venue_model = EEM_Venue::instance();
1202
+		$rows_affected = null;
1203
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1204
+		// very important.  If we don't have a venue name...
1205
+		// then we'll get out because not necessary to create empty venue
1206
+		if (empty($data['venue_title'])) {
1207
+			return false;
1208
+		}
1209
+		$venue_array = [
1210
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1211
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1212
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1213
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1214
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1215
+				: null,
1216
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1217
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1218
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1219
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1220
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1221
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1222
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1223
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1224
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1225
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1226
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1227
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1228
+			'status'              => 'publish',
1229
+		];
1230
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1231
+		if (! empty($venue_id)) {
1232
+			$update_where = [$venue_model->primary_key_name() => $venue_id];
1233
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1234
+			// 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.
1235
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1236
+			return $rows_affected > 0;
1237
+		}
1238
+		// we insert the venue
1239
+		$venue_id = $venue_model->insert($venue_array);
1240
+		$evtobj->_add_relation_to($venue_id, 'Venue');
1241
+		return ! empty($venue_id) ? true : false;
1242
+		// when we have the ancestor come in it's already been handled by the revision save.
1243
+	}
1244
+
1245
+
1246
+	/**
1247
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1248
+	 *
1249
+	 * @param EE_Event $evtobj The Event object we're attaching data to
1250
+	 * @param array    $data   The request data from the form
1251
+	 * @return array
1252
+	 * @throws EE_Error
1253
+	 * @throws InvalidArgumentException
1254
+	 * @throws InvalidDataTypeException
1255
+	 * @throws InvalidInterfaceException
1256
+	 * @throws ReflectionException
1257
+	 * @throws Exception
1258
+	 */
1259
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1260
+	{
1261
+		if ($this->admin_config->useAdvancedEditor()) {
1262
+			return [];
1263
+		}
1264
+		$saved_dtt = null;
1265
+		$saved_tickets = [];
1266
+		$incoming_date_formats = ['Y-m-d', 'h:i a'];
1267
+		$event_timezone_string = $evtobj->get_timezone();
1268
+		$event_timezone = new DateTimeZone($event_timezone_string);
1269
+		// let's use now in the set timezone.
1270
+		$now = new DateTime('now', $event_timezone);
1271
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1272
+			// trim all values to ensure any excess whitespace is removed.
1273
+			$dtt = array_map('trim', $dtt);
1274
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end'])
1275
+				? $dtt['DTT_EVT_end']
1276
+				: $dtt['DTT_EVT_start'];
1277
+			$datetime_values = [
1278
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1279
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1280
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1281
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1282
+				'DTT_order'     => $row,
1283
+			];
1284
+			// 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.
1285
+			if (! empty($dtt['DTT_ID'])) {
1286
+				$DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']);
1287
+				$DTM->set_date_format($incoming_date_formats[0]);
1288
+				$DTM->set_time_format($incoming_date_formats[1]);
1289
+				foreach ($datetime_values as $field => $value) {
1290
+					$DTM->set($field, $value);
1291
+				}
1292
+				// 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.
1293
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1294
+			} else {
1295
+				$DTM = EE_Registry::instance()->load_class(
1296
+					'Datetime',
1297
+					[$datetime_values, $event_timezone_string, $incoming_date_formats],
1298
+					false,
1299
+					false
1300
+				);
1301
+				foreach ($datetime_values as $field => $value) {
1302
+					$DTM->set($field, $value);
1303
+				}
1304
+			}
1305
+			$DTM->save();
1306
+			$DTM = $evtobj->_add_relation_to($DTM, 'Datetime');
1307
+			// load DTT helper
1308
+			// 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.
1309
+			if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
1310
+				$DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
1311
+				$DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
1312
+				$DTM->save();
1313
+			}
1314
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array
1315
+			//  because it is possible there was a new one created for the autosave.
1316
+			$saved_dtt = $DTM;
1317
+			// if ANY of these updates fail then we want the appropriate global error message.
1318
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1319
+		}
1320
+		// no dtts get deleted so we don't do any of that logic here.
1321
+		// update tickets next
1322
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1323
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1324
+			$incoming_date_formats = ['Y-m-d', 'h:i a'];
1325
+			$update_prices = false;
1326
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1327
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1328
+			// trim inputs to ensure any excess whitespace is removed.
1329
+			$tkt = array_map('trim', $tkt);
1330
+			if (empty($tkt['TKT_start_date'])) {
1331
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1332
+			}
1333
+			if (empty($tkt['TKT_end_date'])) {
1334
+				// use the start date of the first datetime
1335
+				$dtt = $evtobj->first_datetime();
1336
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1337
+					$incoming_date_formats[0],
1338
+					$incoming_date_formats[1]
1339
+				);
1340
+			}
1341
+			$TKT_values = [
1342
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1343
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1344
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1345
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1346
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1347
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1348
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1349
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1350
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1351
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1352
+				'TKT_row'         => $row,
1353
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1354
+				'TKT_price'       => $ticket_price,
1355
+			];
1356
+			// 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.
1357
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1358
+				$TKT_values['TKT_ID'] = 0;
1359
+				$TKT_values['TKT_is_default'] = 0;
1360
+				$TKT_values['TKT_price'] = $ticket_price;
1361
+				$update_prices = true;
1362
+			}
1363
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1364
+			// 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.
1365
+			// 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.
1366
+			if (! empty($tkt['TKT_ID'])) {
1367
+				$TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']);
1368
+				if ($TKT instanceof EE_Ticket) {
1369
+					$ticket_sold = $TKT->count_related(
1370
+						'Registration',
1371
+						[
1372
+								[
1373
+									'STS_ID' => [
1374
+										'NOT IN',
1375
+										[EEM_Registration::status_id_incomplete],
1376
+									],
1377
+								],
1378
+							]
1379
+					) > 0;
1380
+					// let's just check the total price for the existing ticket and determine if it matches the new
1381
+					// total price.  if they are different then we create a new ticket (if tickets sold)
1382
+					// if they aren't different then we go ahead and modify existing ticket.
1383
+					$create_new_TKT = $ticket_sold && ! $TKT->deleted()
1384
+									  && EEH_Money::compare_floats(
1385
+										  $ticket_price,
1386
+										  $TKT->get('TKT_price'),
1387
+										  '!=='
1388
+									  );
1389
+					$TKT->set_date_format($incoming_date_formats[0]);
1390
+					$TKT->set_time_format($incoming_date_formats[1]);
1391
+					// set new values
1392
+					foreach ($TKT_values as $field => $value) {
1393
+						if ($field === 'TKT_qty') {
1394
+							$TKT->set_qty($value);
1395
+						} else {
1396
+							$TKT->set($field, $value);
1397
+						}
1398
+					}
1399
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1400
+					if ($create_new_TKT) {
1401
+						// archive the old ticket first
1402
+						$TKT->set('TKT_deleted', 1);
1403
+						$TKT->save();
1404
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1405
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1406
+						// 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.
1407
+						$TKT = clone $TKT;
1408
+						$TKT->set('TKT_ID', 0);
1409
+						$TKT->set('TKT_deleted', 0);
1410
+						$TKT->set('TKT_price', $ticket_price);
1411
+						$TKT->set('TKT_sold', 0);
1412
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1413
+						$update_prices = true;
1414
+					}
1415
+					// make sure price is set if it hasn't been already
1416
+					$TKT->set('TKT_price', $ticket_price);
1417
+				}
1418
+			} else {
1419
+				// no TKT_id so a new TKT
1420
+				$TKT_values['TKT_price'] = $ticket_price;
1421
+				$TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1422
+				if ($TKT instanceof EE_Ticket) {
1423
+					// need to reset values to properly account for the date formats
1424
+					$TKT->set_date_format($incoming_date_formats[0]);
1425
+					$TKT->set_time_format($incoming_date_formats[1]);
1426
+					$TKT->set_timezone($evtobj->get_timezone());
1427
+					// set new values
1428
+					foreach ($TKT_values as $field => $value) {
1429
+						if ($field === 'TKT_qty') {
1430
+							$TKT->set_qty($value);
1431
+						} else {
1432
+							$TKT->set($field, $value);
1433
+						}
1434
+					}
1435
+					$update_prices = true;
1436
+				}
1437
+			}
1438
+			// cap ticket qty by datetime reg limits
1439
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1440
+			// update ticket.
1441
+			$TKT->save();
1442
+			// 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.
1443
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1444
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1445
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1446
+				$TKT->save();
1447
+			}
1448
+			// initially let's add the ticket to the dtt
1449
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1450
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1451
+			// add prices to ticket
1452
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1453
+		}
1454
+		// 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.
1455
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1456
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1457
+		foreach ($tickets_removed as $id) {
1458
+			$id = absint($id);
1459
+			// get the ticket for this id
1460
+			$tkt_to_remove = $this->ticketModel($event_timezone_string)->get_one_by_ID($id);
1461
+			// 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)
1462
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1463
+			foreach ($dtts as $dtt) {
1464
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1465
+			}
1466
+			// 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))
1467
+			$tkt_to_remove->delete_related_permanently('Price');
1468
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1469
+			$tkt_to_remove->delete_permanently();
1470
+		}
1471
+		return [$saved_dtt, $saved_tickets];
1472
+	}
1473
+
1474
+
1475
+	/**
1476
+	 * This attaches a list of given prices to a ticket.
1477
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1478
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1479
+	 * price info and prices are automatically "archived" via the ticket.
1480
+	 *
1481
+	 * @param array     $prices     Array of prices from the form.
1482
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1483
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1484
+	 * @return  void
1485
+	 * @throws EE_Error
1486
+	 * @throws InvalidArgumentException
1487
+	 * @throws InvalidDataTypeException
1488
+	 * @throws InvalidInterfaceException
1489
+	 * @throws ReflectionException
1490
+	 */
1491
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1492
+	{
1493
+		foreach ($prices as $row => $prc) {
1494
+			$PRC_values = [
1495
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1496
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1497
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1498
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1499
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1500
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1501
+				'PRC_order'      => $row,
1502
+			];
1503
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1504
+				$PRC_values['PRC_ID'] = 0;
1505
+				$PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1506
+			} else {
1507
+				$PRC = EEM_Price::instance()->get_one_by_ID($prc['PRC_ID']);
1508
+				// update this price with new values
1509
+				foreach ($PRC_values as $field => $newprc) {
1510
+					$PRC->set($field, $newprc);
1511
+				}
1512
+				$PRC->save();
1513
+			}
1514
+			$ticket->_add_relation_to($PRC, 'Price');
1515
+		}
1516
+	}
1517
+
1518
+
1519
+	/**
1520
+	 * Add in our autosave ajax handlers
1521
+	 *
1522
+	 */
1523
+	protected function _ee_autosave_create_new()
1524
+	{
1525
+	}
1526
+
1527
+
1528
+	/**
1529
+	 * More autosave handlers.
1530
+	 */
1531
+	protected function _ee_autosave_edit()
1532
+	{
1533
+	}
1534
+
1535
+
1536
+	/**
1537
+	 *    _generate_publish_box_extra_content
1538
+	 *
1539
+	 * @throws DomainException
1540
+	 * @throws EE_Error
1541
+	 * @throws InvalidArgumentException
1542
+	 * @throws InvalidDataTypeException
1543
+	 * @throws InvalidInterfaceException
1544
+	 * @throws ReflectionException
1545
+	 */
1546
+	private function _generate_publish_box_extra_content()
1547
+	{
1548
+		// load formatter helper
1549
+		// args for getting related registrations
1550
+		$approved_query_args = [
1551
+			[
1552
+				'REG_deleted' => 0,
1553
+				'STS_ID'      => EEM_Registration::status_id_approved,
1554
+			],
1555
+		];
1556
+		$not_approved_query_args = [
1557
+			[
1558
+				'REG_deleted' => 0,
1559
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1560
+			],
1561
+		];
1562
+		$pending_payment_query_args = [
1563
+			[
1564
+				'REG_deleted' => 0,
1565
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1566
+			],
1567
+		];
1568
+		// publish box
1569
+		$publish_box_extra_args = [
1570
+			'view_approved_reg_url'        => add_query_arg(
1571
+				[
1572
+					'action'      => 'default',
1573
+					'event_id'    => $this->_cpt_model_obj->ID(),
1574
+					'_reg_status' => EEM_Registration::status_id_approved,
1575
+				],
1576
+				REG_ADMIN_URL
1577
+			),
1578
+			'view_not_approved_reg_url'    => add_query_arg(
1579
+				[
1580
+					'action'      => 'default',
1581
+					'event_id'    => $this->_cpt_model_obj->ID(),
1582
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1583
+				],
1584
+				REG_ADMIN_URL
1585
+			),
1586
+			'view_pending_payment_reg_url' => add_query_arg(
1587
+				[
1588
+					'action'      => 'default',
1589
+					'event_id'    => $this->_cpt_model_obj->ID(),
1590
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1591
+				],
1592
+				REG_ADMIN_URL
1593
+			),
1594
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1595
+				'Registration',
1596
+				$approved_query_args
1597
+			),
1598
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1599
+				'Registration',
1600
+				$not_approved_query_args
1601
+			),
1602
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1603
+				'Registration',
1604
+				$pending_payment_query_args
1605
+			),
1606
+			'misc_pub_section_class'       => apply_filters(
1607
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1608
+				'misc-pub-section'
1609
+			),
1610
+		];
1611
+		ob_start();
1612
+		do_action(
1613
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1614
+			$this->_cpt_model_obj
1615
+		);
1616
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1617
+		// load template
1618
+		EEH_Template::display_template(
1619
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1620
+			$publish_box_extra_args
1621
+		);
1622
+	}
1623
+
1624
+
1625
+	/**
1626
+	 * @return EE_Event
1627
+	 */
1628
+	public function get_event_object()
1629
+	{
1630
+		return $this->_cpt_model_obj;
1631
+	}
1632
+
1633
+
1634
+
1635
+
1636
+	/** METABOXES * */
1637
+	/**
1638
+	 * _register_event_editor_meta_boxes
1639
+	 * add all metaboxes related to the event_editor
1640
+	 *
1641
+	 * @return void
1642
+	 * @throws EE_Error
1643
+	 * @throws InvalidArgumentException
1644
+	 * @throws InvalidDataTypeException
1645
+	 * @throws InvalidInterfaceException
1646
+	 * @throws ReflectionException
1647
+	 */
1648
+	protected function _register_event_editor_meta_boxes()
1649
+	{
1650
+		$this->verify_cpt_object();
1651
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1652
+		/** @var FeatureFlags $flags */
1653
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1654
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1655
+		if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1656
+			add_meta_box(
1657
+				'espresso_event_editor_event_options',
1658
+				esc_html__('Event Registration Options', 'event_espresso'),
1659
+				[$this, 'registration_options_meta_box'],
1660
+				$this->page_slug,
1661
+				'side'
1662
+			);
1663
+		}
1664
+		if (! $use_advanced_editor) {
1665
+			add_meta_box(
1666
+				'espresso_event_editor_tickets',
1667
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1668
+				[$this, 'ticket_metabox'],
1669
+				$this->page_slug,
1670
+				'normal',
1671
+				'high'
1672
+			);
1673
+		} else {
1674
+			if ($flags->featureAllowed('use_reg_options_meta_box')) {
1675
+				add_action(
1676
+					'add_meta_boxes_espresso_events',
1677
+					function () {
1678
+						global $current_screen;
1679
+						remove_meta_box('authordiv', $current_screen, 'normal');
1680
+					},
1681
+					99
1682
+				);
1683
+			}
1684
+		}
1685
+		// NOTE: if you're looking for other metaboxes in here,
1686
+		// where a metabox has a related management page in the admin
1687
+		// you will find it setup in the related management page's "_Hooks" file.
1688
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1689
+	}
1690
+
1691
+
1692
+	/**
1693
+	 * @throws DomainException
1694
+	 * @throws EE_Error
1695
+	 * @throws InvalidArgumentException
1696
+	 * @throws InvalidDataTypeException
1697
+	 * @throws InvalidInterfaceException
1698
+	 * @throws ReflectionException
1699
+	 */
1700
+	public function ticket_metabox()
1701
+	{
1702
+		$existing_datetime_ids = $existing_ticket_ids = [];
1703
+		// defaults for template args
1704
+		$template_args = [
1705
+			'existing_datetime_ids'    => '',
1706
+			'event_datetime_help_link' => '',
1707
+			'ticket_options_help_link' => '',
1708
+			'time'                     => null,
1709
+			'ticket_rows'              => '',
1710
+			'existing_ticket_ids'      => '',
1711
+			'total_ticket_rows'        => 1,
1712
+			'ticket_js_structure'      => '',
1713
+			'trash_icon'               => 'ee-lock-icon',
1714
+			'disabled'                 => '',
1715
+		];
1716
+		$event_id = $this->_cpt_model_obj instanceof EE_Event ? $this->_cpt_model_obj->ID() : 0;
1717
+		$event_timezone_string = $this->_cpt_model_obj instanceof EE_Event
1718
+			? $this->_cpt_model_obj->timezone_string()
1719
+			: '';
1720
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1721
+		/**
1722
+		 * 1. Start with retrieving Datetimes
1723
+		 * 2. Fore each datetime get related tickets
1724
+		 * 3. For each ticket get related prices
1725
+		 */
1726
+		$times = $this->datetimeModel($event_timezone_string)->get_all_event_dates($event_id);
1727
+		/** @type EE_Datetime $first_datetime */
1728
+		$first_datetime = reset($times);
1729
+		// do we get related tickets?
1730
+		if (
1731
+			$first_datetime instanceof EE_Datetime
1732
+			&& $first_datetime->ID() !== 0
1733
+		) {
1734
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1735
+			$template_args['time'] = $first_datetime;
1736
+			$related_tickets = $first_datetime->tickets(
1737
+				[
1738
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1739
+					'default_where_conditions' => 'none',
1740
+				]
1741
+			);
1742
+			if (! empty($related_tickets)) {
1743
+				$template_args['total_ticket_rows'] = count($related_tickets);
1744
+				$row = 0;
1745
+				foreach ($related_tickets as $ticket) {
1746
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1747
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1748
+					$row++;
1749
+				}
1750
+			} else {
1751
+				$template_args['total_ticket_rows'] = 1;
1752
+				/** @type EE_Ticket $ticket */
1753
+				$ticket = $this->ticketModel($event_timezone_string)->create_default_object();
1754
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1755
+			}
1756
+		} else {
1757
+			$template_args['time'] = $times[0];
1758
+			/** @type EE_Ticket $ticket */
1759
+			$ticket = $this->ticketModel($event_timezone_string)->get_all_default_tickets();
1760
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1761
+			// NOTE: we're just sending the first default row
1762
+			// (decaf can't manage default tickets so this should be sufficient);
1763
+		}
1764
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1765
+			'event_editor_event_datetimes_help_tab'
1766
+		);
1767
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1768
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1769
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1770
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1771
+			$this->ticketModel($event_timezone_string)->create_default_object(),
1772
+			true
1773
+		);
1774
+		$template = apply_filters(
1775
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1776
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1777
+		);
1778
+		EEH_Template::display_template($template, $template_args);
1779
+	}
1780
+
1781
+
1782
+	/**
1783
+	 * Setup an individual ticket form for the decaf event editor page
1784
+	 *
1785
+	 * @param EE_Ticket $ticket   the ticket object
1786
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1787
+	 * @param int       $row
1788
+	 * @return string generated html for the ticket row.
1789
+	 * @throws DomainException
1790
+	 * @throws EE_Error
1791
+	 * @throws InvalidArgumentException
1792
+	 * @throws InvalidDataTypeException
1793
+	 * @throws InvalidInterfaceException
1794
+	 * @throws ReflectionException
1795
+	 */
1796
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1797
+	{
1798
+		$template_args = [
1799
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1800
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1801
+				: '',
1802
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1803
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1804
+			'TKT_name'            => $ticket->get('TKT_name'),
1805
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1806
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1807
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1808
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1809
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1810
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1811
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1812
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1813
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1814
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1815
+				: ' disabled=disabled',
1816
+		];
1817
+		$price = $ticket->ID() !== 0
1818
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1819
+			: EEM_Price::instance()->create_default_object();
1820
+		$price_args = [
1821
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1822
+			'PRC_amount'            => $price->get('PRC_amount'),
1823
+			'PRT_ID'                => $price->get('PRT_ID'),
1824
+			'PRC_ID'                => $price->get('PRC_ID'),
1825
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1826
+		];
1827
+		// make sure we have default start and end dates if skeleton
1828
+		// handle rows that should NOT be empty
1829
+		if (empty($template_args['TKT_start_date'])) {
1830
+			// if empty then the start date will be now.
1831
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1832
+		}
1833
+		if (empty($template_args['TKT_end_date'])) {
1834
+			// get the earliest datetime (if present);
1835
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1836
+				? $this->_cpt_model_obj->get_first_related(
1837
+					'Datetime',
1838
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1839
+				)
1840
+				: null;
1841
+			if (! empty($earliest_dtt)) {
1842
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1843
+			} else {
1844
+				$template_args['TKT_end_date'] = date(
1845
+					'Y-m-d h:i a',
1846
+					mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1847
+				);
1848
+			}
1849
+		}
1850
+		$template_args = array_merge($template_args, $price_args);
1851
+		$template = apply_filters(
1852
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1853
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1854
+			$ticket
1855
+		);
1856
+		return EEH_Template::display_template($template, $template_args, true);
1857
+	}
1858
+
1859
+
1860
+	/**
1861
+	 * @throws DomainException
1862
+	 * @throws EE_Error
1863
+	 */
1864
+	public function registration_options_meta_box()
1865
+	{
1866
+		$yes_no_values = [
1867
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1868
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1869
+		];
1870
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1871
+			[
1872
+				EEM_Registration::status_id_cancelled,
1873
+				EEM_Registration::status_id_declined,
1874
+				EEM_Registration::status_id_incomplete,
1875
+			],
1876
+			true
1877
+		);
1878
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1879
+		$template_args['_event'] = $this->_cpt_model_obj;
1880
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1881
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1882
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1883
+			'default_reg_status',
1884
+			$default_reg_status_values,
1885
+			$this->_cpt_model_obj->default_registration_status()
1886
+		);
1887
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1888
+			'display_desc',
1889
+			$yes_no_values,
1890
+			$this->_cpt_model_obj->display_description()
1891
+		);
1892
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1893
+			'display_ticket_selector',
1894
+			$yes_no_values,
1895
+			$this->_cpt_model_obj->display_ticket_selector(),
1896
+			'',
1897
+			'',
1898
+			false
1899
+		);
1900
+		$template_args['additional_registration_options'] = apply_filters(
1901
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1902
+			'',
1903
+			$template_args,
1904
+			$yes_no_values,
1905
+			$default_reg_status_values
1906
+		);
1907
+		EEH_Template::display_template(
1908
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1909
+			$template_args
1910
+		);
1911
+	}
1912
+
1913
+
1914
+	/**
1915
+	 * _get_events()
1916
+	 * This method simply returns all the events (for the given _view and paging)
1917
+	 *
1918
+	 * @param int  $per_page     count of items per page (20 default);
1919
+	 * @param int  $current_page what is the current page being viewed.
1920
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1921
+	 *                           If FALSE then we return an array of event objects
1922
+	 *                           that match the given _view and paging parameters.
1923
+	 * @return array|int         an array of event objects or count of how many events.
1924
+	 * @throws EE_Error
1925
+	 * @throws InvalidArgumentException
1926
+	 * @throws InvalidDataTypeException
1927
+	 * @throws InvalidInterfaceException
1928
+	 * @throws ReflectionException
1929
+	 * @throws Exception
1930
+	 * @throws Exception
1931
+	 * @throws Exception
1932
+	 */
1933
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1934
+	{
1935
+		$EEME = $this->eventModel();
1936
+		$offset = ($current_page - 1) * $per_page;
1937
+		$limit = $count ? null : $offset . ',' . $per_page;
1938
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1939
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1940
+		if (isset($this->_req_data['month_range'])) {
1941
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1942
+			// simulate the FIRST day of the month, that fixes issues for months like February
1943
+			// where PHP doesn't know what to assume for date.
1944
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1945
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1946
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1947
+		}
1948
+		$where = [];
1949
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1950
+		// determine what post_status our condition will have for the query.
1951
+		switch ($status) {
1952
+			case 'month':
1953
+			case 'today':
1954
+			case null:
1955
+			case 'all':
1956
+				break;
1957
+			case 'draft':
1958
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1959
+				break;
1960
+			default:
1961
+				$where['status'] = $status;
1962
+		}
1963
+		// categories?
1964
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1965
+			? $this->_req_data['EVT_CAT'] : null;
1966
+		if (! empty($category)) {
1967
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968
+			$where['Term_Taxonomy.term_id'] = $category;
1969
+		}
1970
+		// date where conditions
1971
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1973
+			$DateTime = new DateTime(
1974
+				$year_r . '-' . $month_r . '-01 00:00:00',
1975
+				new DateTimeZone('UTC')
1976
+			);
1977
+			$start = $DateTime->getTimestamp();
1978
+			// set the datetime to be the end of the month
1979
+			$DateTime->setDate(
1980
+				$year_r,
1981
+				$month_r,
1982
+				$DateTime->format('t')
1983
+			)->setTime(23, 59, 59);
1984
+			$end = $DateTime->getTimestamp();
1985
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1987
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1988
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1989
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1990
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1991
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1992
+			$now = date('Y-m-01');
1993
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1994
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1995
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1996
+							->setTime(23, 59, 59)
1997
+							->format(implode(' ', $start_formats));
1998
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1999
+		}
2000
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2001
+			$where['EVT_wp_user'] = get_current_user_id();
2002
+		} elseif (
2003
+			! isset($where['status'])
2004
+				  && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2005
+		) {
2006
+			$where['OR'] = [
2007
+				'status*restrict_private' => ['!=', 'private'],
2008
+				'AND'                     => [
2009
+					'status*inclusive' => ['=', 'private'],
2010
+					'EVT_wp_user'      => get_current_user_id(),
2011
+				],
2012
+			];
2013
+		}
2014
+
2015
+		if (
2016
+			isset($this->_req_data['EVT_wp_user'])
2017
+			&& (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2018
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2019
+		) {
2020
+			$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2021
+		}
2022
+		// search query handling
2023
+		if (isset($this->_req_data['s'])) {
2024
+			$search_string = '%' . $this->_req_data['s'] . '%';
2025
+			$where['OR'] = [
2026
+				'EVT_name'       => ['LIKE', $search_string],
2027
+				'EVT_desc'       => ['LIKE', $search_string],
2028
+				'EVT_short_desc' => ['LIKE', $search_string],
2029
+			];
2030
+		}
2031
+		// filter events by venue.
2032
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2033
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2034
+		}
2035
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2036
+		$query_params = apply_filters(
2037
+			'FHEE__Events_Admin_Page__get_events__query_params',
2038
+			[
2039
+				$where,
2040
+				'limit'    => $limit,
2041
+				'order_by' => $orderby,
2042
+				'order'    => $order,
2043
+				'group_by' => 'EVT_ID',
2044
+			],
2045
+			$this->_req_data
2046
+		);
2047
+
2048
+		// let's first check if we have special requests coming in.
2049
+		if (isset($this->_req_data['active_status'])) {
2050
+			switch ($this->_req_data['active_status']) {
2051
+				case 'upcoming':
2052
+					return $EEME->get_upcoming_events($query_params, $count);
2053
+					break;
2054
+				case 'expired':
2055
+					return $EEME->get_expired_events($query_params, $count);
2056
+					break;
2057
+				case 'active':
2058
+					return $EEME->get_active_events($query_params, $count);
2059
+					break;
2060
+				case 'inactive':
2061
+					return $EEME->get_inactive_events($query_params, $count);
2062
+					break;
2063
+			}
2064
+		}
2065
+		return $count
2066
+			? $EEME->count([$where], 'EVT_ID', true)
2067
+			: $EEME->get_all($query_params);
2068
+	}
2069
+
2070
+
2071
+	/**
2072
+	 * handling for WordPress CPT actions (trash, restore, delete)
2073
+	 *
2074
+	 * @param string $post_id
2075
+	 * @throws EE_Error
2076
+	 * @throws InvalidArgumentException
2077
+	 * @throws InvalidDataTypeException
2078
+	 * @throws InvalidInterfaceException
2079
+	 * @throws ReflectionException
2080
+	 */
2081
+	public function trash_cpt_item($post_id)
2082
+	{
2083
+		$this->_req_data['EVT_ID'] = $post_id;
2084
+		$this->_trash_or_restore_event('trash', false);
2085
+	}
2086
+
2087
+
2088
+	/**
2089
+	 * @param string $post_id
2090
+	 * @throws EE_Error
2091
+	 * @throws InvalidArgumentException
2092
+	 * @throws InvalidDataTypeException
2093
+	 * @throws InvalidInterfaceException
2094
+	 * @throws ReflectionException
2095
+	 */
2096
+	public function restore_cpt_item($post_id)
2097
+	{
2098
+		$this->_req_data['EVT_ID'] = $post_id;
2099
+		$this->_trash_or_restore_event('draft', false);
2100
+	}
2101
+
2102
+
2103
+	/**
2104
+	 * @param string $post_id
2105
+	 * @throws EE_Error
2106
+	 * @throws InvalidArgumentException
2107
+	 * @throws InvalidDataTypeException
2108
+	 * @throws InvalidInterfaceException
2109
+	 * @throws ReflectionException
2110
+	 */
2111
+	public function delete_cpt_item($post_id)
2112
+	{
2113
+		throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
2114
+		$this->_req_data['EVT_ID'] = $post_id;
2115
+		$this->_delete_event();
2116
+	}
2117
+
2118
+
2119
+	/**
2120
+	 * _trash_or_restore_event
2121
+	 *
2122
+	 * @param string $event_status
2123
+	 * @param bool   $redirect_after
2124
+	 * @throws EE_Error
2125
+	 * @throws InvalidArgumentException
2126
+	 * @throws InvalidDataTypeException
2127
+	 * @throws InvalidInterfaceException
2128
+	 * @throws ReflectionException
2129
+	 */
2130
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2131
+	{
2132
+		// determine the event id and set to array.
2133
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2134
+		// loop thru events
2135
+		if ($EVT_ID) {
2136
+			// clean status
2137
+			$event_status = sanitize_key($event_status);
2138
+			// grab status
2139
+			if (! empty($event_status)) {
2140
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2141
+			} else {
2142
+				$success = false;
2143
+				$msg = esc_html__(
2144
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2145
+					'event_espresso'
2146
+				);
2147
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2148
+			}
2149
+		} else {
2150
+			$success = false;
2151
+			$msg = esc_html__(
2152
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2153
+				'event_espresso'
2154
+			);
2155
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2156
+		}
2157
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2158
+		if ($redirect_after) {
2159
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2160
+		}
2161
+	}
2162
+
2163
+
2164
+	/**
2165
+	 * _trash_or_restore_events
2166
+	 *
2167
+	 * @param string $event_status
2168
+	 * @return void
2169
+	 * @throws EE_Error
2170
+	 * @throws InvalidArgumentException
2171
+	 * @throws InvalidDataTypeException
2172
+	 * @throws InvalidInterfaceException
2173
+	 * @throws ReflectionException
2174
+	 */
2175
+	protected function _trash_or_restore_events($event_status = 'trash')
2176
+	{
2177
+		// clean status
2178
+		$event_status = sanitize_key($event_status);
2179
+		// grab status
2180
+		if (! empty($event_status)) {
2181
+			$success = true;
2182
+			// determine the event id and set to array.
2183
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2184
+			// loop thru events
2185
+			foreach ($EVT_IDs as $EVT_ID) {
2186
+				if ($EVT_ID = absint($EVT_ID)) {
2187
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2188
+					$success = $results !== false ? $success : false;
2189
+				} else {
2190
+					$msg = sprintf(
2191
+						esc_html__(
2192
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2193
+							'event_espresso'
2194
+						),
2195
+						$EVT_ID
2196
+					);
2197
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2198
+					$success = false;
2199
+				}
2200
+			}
2201
+		} else {
2202
+			$success = false;
2203
+			$msg = esc_html__(
2204
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2205
+				'event_espresso'
2206
+			);
2207
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2208
+		}
2209
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2210
+		$success = $success ? 2 : false;
2211
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2212
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2213
+	}
2214
+
2215
+
2216
+	/**
2217
+	 * _trash_or_restore_events
2218
+	 *
2219
+	 * @param int    $EVT_ID
2220
+	 * @param string $event_status
2221
+	 * @return bool
2222
+	 * @throws EE_Error
2223
+	 * @throws InvalidArgumentException
2224
+	 * @throws InvalidDataTypeException
2225
+	 * @throws InvalidInterfaceException
2226
+	 * @throws ReflectionException
2227
+	 */
2228
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2229
+	{
2230
+		// grab event id
2231
+		if (! $EVT_ID) {
2232
+			$msg = esc_html__(
2233
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2234
+				'event_espresso'
2235
+			);
2236
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2237
+			return false;
2238
+		}
2239
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2240
+		// clean status
2241
+		$event_status = sanitize_key($event_status);
2242
+		// grab status
2243
+		if (empty($event_status)) {
2244
+			$msg = esc_html__(
2245
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2246
+				'event_espresso'
2247
+			);
2248
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2249
+			return false;
2250
+		}
2251
+		// was event trashed or restored ?
2252
+		switch ($event_status) {
2253
+			case 'draft':
2254
+				$action = 'restored from the trash';
2255
+				$hook = 'AHEE_event_restored_from_trash';
2256
+				break;
2257
+			case 'trash':
2258
+				$action = 'moved to the trash';
2259
+				$hook = 'AHEE_event_moved_to_trash';
2260
+				break;
2261
+			default:
2262
+				$action = 'updated';
2263
+				$hook = false;
2264
+		}
2265
+		// use class to change status
2266
+		$this->_cpt_model_obj->set_status($event_status);
2267
+		$success = $this->_cpt_model_obj->save();
2268
+		if ($success === false) {
2269
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2270
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2271
+			return false;
2272
+		}
2273
+		if ($hook) {
2274
+			do_action($hook);
2275
+		}
2276
+		return true;
2277
+	}
2278
+
2279
+
2280
+	/**
2281
+	 * _delete_event
2282
+	 *
2283
+	 * @param bool $redirect_after
2284
+	 * @throws EE_Error
2285
+	 * @throws InvalidArgumentException
2286
+	 * @throws InvalidDataTypeException
2287
+	 * @throws InvalidInterfaceException
2288
+	 * @throws ReflectionException
2289
+	 */
2290
+	protected function _delete_event()
2291
+	{
2292
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2293
+	}
2294
+
2295
+	/**
2296
+	 * Gets the tree traversal batch persister.
2297
+	 * @since $VID:$
2298
+	 * @return NodeGroupDao
2299
+	 * @throws InvalidArgumentException
2300
+	 * @throws InvalidDataTypeException
2301
+	 * @throws InvalidInterfaceException
2302
+	 */
2303
+	protected function getModelObjNodeGroupPersister()
2304
+	{
2305
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2306
+			$this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2307
+		}
2308
+		return $this->model_obj_node_group_persister;
2309
+	}
2310
+
2311
+	/**
2312
+	 * _delete_events
2313
+	 *
2314
+	 * @return void
2315
+	 * @throws EE_Error
2316
+	 * @throws InvalidArgumentException
2317
+	 * @throws InvalidDataTypeException
2318
+	 * @throws InvalidInterfaceException
2319
+	 * @throws ReflectionException
2320
+	 */
2321
+	protected function _delete_events()
2322
+	{
2323
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2324
+	}
2325
+
2326
+	protected function generateDeletionPreview($event_ids)
2327
+	{
2328
+		$event_ids = (array) $event_ids;
2329
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2330
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2331
+		$return_url = EE_Admin_Page::add_query_args_and_nonce(
2332
+			[
2333
+				'action' => 'preview_deletion',
2334
+				'deletion_job_code' => $deletion_job_code,
2335
+			],
2336
+			$this->_admin_base_url
2337
+		);
2338
+		$event_ids = array_map(
2339
+			'intval',
2340
+			$event_ids
2341
+		);
2342
+
2343
+		EEH_URL::safeRedirectAndExit(
2344
+			EE_Admin_Page::add_query_args_and_nonce(
2345
+				[
2346
+					'page'              => 'espresso_batch',
2347
+					'batch'             => EED_Batch::batch_job,
2348
+					'EVT_IDs'           => $event_ids,
2349
+					'deletion_job_code' => $deletion_job_code,
2350
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2351
+					'return_url'        => urlencode($return_url),
2352
+				],
2353
+				admin_url()
2354
+			)
2355
+		);
2356
+	}
2357
+
2358
+	/**
2359
+	 * Checks for a POST submission
2360
+	 * @since $VID:$
2361
+	 */
2362
+	protected function confirmDeletion()
2363
+	{
2364
+		$deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2365
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2366
+	}
2367
+
2368
+	/**
2369
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2370
+	 * @since $VID:$
2371
+	 * @throws EE_Error
2372
+	 */
2373
+	protected function previewDeletion()
2374
+	{
2375
+		$preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2376
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2377
+		$this->display_admin_page_with_no_sidebar();
2378
+	}
2379
+
2380
+	/**
2381
+	 * get total number of events
2382
+	 *
2383
+	 * @return int
2384
+	 * @throws EE_Error
2385
+	 * @throws InvalidArgumentException
2386
+	 * @throws InvalidDataTypeException
2387
+	 * @throws InvalidInterfaceException
2388
+	 */
2389
+	public function total_events()
2390
+	{
2391
+		$count = EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2392
+		return $count;
2393
+	}
2394
+
2395
+
2396
+	/**
2397
+	 * get total number of draft events
2398
+	 *
2399
+	 * @return int
2400
+	 * @throws EE_Error
2401
+	 * @throws InvalidArgumentException
2402
+	 * @throws InvalidDataTypeException
2403
+	 * @throws InvalidInterfaceException
2404
+	 */
2405
+	public function total_events_draft()
2406
+	{
2407
+		$where = [
2408
+			'status' => ['IN', ['draft', 'auto-draft']],
2409
+		];
2410
+		$count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2411
+		return $count;
2412
+	}
2413
+
2414
+
2415
+	/**
2416
+	 * get total number of trashed events
2417
+	 *
2418
+	 * @return int
2419
+	 * @throws EE_Error
2420
+	 * @throws InvalidArgumentException
2421
+	 * @throws InvalidDataTypeException
2422
+	 * @throws InvalidInterfaceException
2423
+	 */
2424
+	public function total_trashed_events()
2425
+	{
2426
+		$where = [
2427
+			'status' => 'trash',
2428
+		];
2429
+		$count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2430
+		return $count;
2431
+	}
2432
+
2433
+
2434
+	/**
2435
+	 *    _default_event_settings
2436
+	 *    This generates the Default Settings Tab
2437
+	 *
2438
+	 * @return void
2439
+	 * @throws DomainException
2440
+	 * @throws EE_Error
2441
+	 * @throws InvalidArgumentException
2442
+	 * @throws InvalidDataTypeException
2443
+	 * @throws InvalidInterfaceException
2444
+	 */
2445
+	protected function _default_event_settings()
2446
+	{
2447
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2448
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2449
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2450
+		$this->display_admin_page_with_sidebar();
2451
+	}
2452
+
2453
+
2454
+	/**
2455
+	 * Return the form for event settings.
2456
+	 *
2457
+	 * @return EE_Form_Section_Proper
2458
+	 * @throws EE_Error
2459
+	 */
2460
+	protected function _default_event_settings_form()
2461
+	{
2462
+		$registration_config = EE_Registry::instance()->CFG->registration;
2463
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2464
+		// exclude
2465
+			[
2466
+				EEM_Registration::status_id_cancelled,
2467
+				EEM_Registration::status_id_declined,
2468
+				EEM_Registration::status_id_incomplete,
2469
+				EEM_Registration::status_id_wait_list,
2470
+			],
2471
+			true
2472
+		);
2473
+		return new EE_Form_Section_Proper(
2474
+			[
2475
+				'name'            => 'update_default_event_settings',
2476
+				'html_id'         => 'update_default_event_settings',
2477
+				'html_class'      => 'form-table',
2478
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2479
+				'subsections'     => apply_filters(
2480
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2481
+					[
2482
+						'default_reg_status'  => new EE_Select_Input(
2483
+							$registration_stati_for_selection,
2484
+							[
2485
+								'default'         => isset($registration_config->default_STS_ID)
2486
+													 && array_key_exists(
2487
+														 $registration_config->default_STS_ID,
2488
+														 $registration_stati_for_selection
2489
+													 )
2490
+									? sanitize_text_field($registration_config->default_STS_ID)
2491
+									: EEM_Registration::status_id_pending_payment,
2492
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2493
+													 . EEH_Template::get_help_tab_link(
2494
+														 'default_settings_status_help_tab'
2495
+													 ),
2496
+								'html_help_text'  => esc_html__(
2497
+									'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.',
2498
+									'event_espresso'
2499
+								),
2500
+							]
2501
+						),
2502
+						'default_max_tickets' => new EE_Integer_Input(
2503
+							[
2504
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2505
+									? $registration_config->default_maximum_number_of_tickets
2506
+									: EEM_Event::get_default_additional_limit(),
2507
+								'html_label_text' => esc_html__(
2508
+									'Default Maximum Tickets Allowed Per Order:',
2509
+									'event_espresso'
2510
+								)
2511
+													 . EEH_Template::get_help_tab_link(
2512
+														 'default_maximum_tickets_help_tab"'
2513
+													 ),
2514
+								'html_help_text'  => esc_html__(
2515
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2516
+									'event_espresso'
2517
+								),
2518
+							]
2519
+						),
2520
+					]
2521
+				),
2522
+			]
2523
+		);
2524
+	}
2525
+
2526
+
2527
+	/**
2528
+	 * @return void
2529
+	 * @throws EE_Error
2530
+	 * @throws InvalidArgumentException
2531
+	 * @throws InvalidDataTypeException
2532
+	 * @throws InvalidInterfaceException
2533
+	 */
2534
+	protected function _update_default_event_settings()
2535
+	{
2536
+		$form = $this->_default_event_settings_form();
2537
+		if ($form->was_submitted()) {
2538
+			$form->receive_form_submission();
2539
+			if ($form->is_valid()) {
2540
+				$registration_config = EE_Registry::instance()->CFG->registration;
2541
+				$valid_data = $form->valid_data();
2542
+				if (isset($valid_data['default_reg_status'])) {
2543
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2544
+				}
2545
+				if (isset($valid_data['default_max_tickets'])) {
2546
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2547
+				}
2548
+				do_action(
2549
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2550
+					$valid_data,
2551
+					EE_Registry::instance()->CFG,
2552
+					$this
2553
+				);
2554
+				// update because data was valid!
2555
+				EE_Registry::instance()->CFG->update_espresso_config();
2556
+				EE_Error::overwrite_success();
2557
+				EE_Error::add_success(
2558
+					__('Default Event Settings were updated', 'event_espresso')
2559
+				);
2560
+			}
2561
+		}
2562
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2563
+	}
2564
+
2565
+
2566
+	/*************        Templates        *************/
2567
+	protected function _template_settings()
2568
+	{
2569
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2570
+		$this->_template_args['preview_img'] = '<img src="'
2571
+											   . EVENTS_ASSETS_URL
2572
+											   . '/images/'
2573
+											   . 'caffeinated_template_features.jpg" alt="'
2574
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2575
+											   . '" />';
2576
+		$this->_template_args['preview_text'] = '<strong>'
2577
+												. esc_html__(
2578
+													'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.',
2579
+													'event_espresso'
2580
+												) . '</strong>';
2581
+		$this->display_admin_caf_preview_page('template_settings_tab');
2582
+	}
2583
+
2584
+
2585
+	/** Event Category Stuff **/
2586
+	/**
2587
+	 * set the _category property with the category object for the loaded page.
2588
+	 *
2589
+	 * @return void
2590
+	 */
2591
+	private function _set_category_object()
2592
+	{
2593
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2594
+			return;
2595
+		} //already have the category object so get out.
2596
+		// set default category object
2597
+		$this->_set_empty_category_object();
2598
+		// only set if we've got an id
2599
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2600
+			return;
2601
+		}
2602
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2603
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2604
+		if (! empty($term)) {
2605
+			$this->_category->category_name = $term->name;
2606
+			$this->_category->category_identifier = $term->slug;
2607
+			$this->_category->category_desc = $term->description;
2608
+			$this->_category->id = $term->term_id;
2609
+			$this->_category->parent = $term->parent;
2610
+		}
2611
+	}
2612
+
2613
+
2614
+	/**
2615
+	 * Clears out category properties.
2616
+	 */
2617
+	private function _set_empty_category_object()
2618
+	{
2619
+		$this->_category = new stdClass();
2620
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2621
+		$this->_category->id = $this->_category->parent = 0;
2622
+	}
2623
+
2624
+
2625
+	/**
2626
+	 * @throws DomainException
2627
+	 * @throws EE_Error
2628
+	 * @throws InvalidArgumentException
2629
+	 * @throws InvalidDataTypeException
2630
+	 * @throws InvalidInterfaceException
2631
+	 */
2632
+	protected function _category_list_table()
2633
+	{
2634
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2635
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2636
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2637
+			'add_category',
2638
+			'add_category',
2639
+			[],
2640
+			'add-new-h2'
2641
+		);
2642
+		$this->display_admin_list_table_page_with_sidebar();
2643
+	}
2644
+
2645
+
2646
+	/**
2647
+	 * Output category details view.
2648
+	 *
2649
+	 * @param string $view
2650
+	 * @throws DomainException
2651
+	 * @throws EE_Error
2652
+	 * @throws InvalidArgumentException
2653
+	 * @throws InvalidDataTypeException
2654
+	 * @throws InvalidInterfaceException
2655
+	 */
2656
+	protected function _category_details($view)
2657
+	{
2658
+		// load formatter helper
2659
+		// load field generator helper
2660
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2661
+		$this->_set_add_edit_form_tags($route);
2662
+		$this->_set_category_object();
2663
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2664
+		$delete_action = 'delete_category';
2665
+		// custom redirect
2666
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2667
+			['action' => 'category_list'],
2668
+			$this->_admin_base_url
2669
+		);
2670
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2671
+		// take care of contents
2672
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2673
+		$this->display_admin_page_with_sidebar();
2674
+	}
2675
+
2676
+
2677
+	/**
2678
+	 * Output category details content.
2679
+	 *
2680
+	 * @throws DomainException
2681
+	 */
2682
+	protected function _category_details_content()
2683
+	{
2684
+		$editor_args['category_desc'] = [
2685
+			'type'          => 'wp_editor',
2686
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2687
+			'class'         => 'my_editor_custom',
2688
+			'wpeditor_args' => ['media_buttons' => false],
2689
+		];
2690
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2691
+		$all_terms = get_terms(
2692
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2693
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2694
+		);
2695
+		// setup category select for term parents.
2696
+		$category_select_values[] = [
2697
+			'text' => esc_html__('No Parent', 'event_espresso'),
2698
+			'id'   => 0,
2699
+		];
2700
+		foreach ($all_terms as $term) {
2701
+			$category_select_values[] = [
2702
+				'text' => $term->name,
2703
+				'id'   => $term->term_id,
2704
+			];
2705
+		}
2706
+		$category_select = EEH_Form_Fields::select_input(
2707
+			'category_parent',
2708
+			$category_select_values,
2709
+			$this->_category->parent
2710
+		);
2711
+		$template_args = [
2712
+			'category'                 => $this->_category,
2713
+			'category_select'          => $category_select,
2714
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2715
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2716
+			'disable'                  => '',
2717
+			'disabled_message'         => false,
2718
+		];
2719
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2720
+		return EEH_Template::display_template($template, $template_args, true);
2721
+	}
2722
+
2723
+
2724
+	/**
2725
+	 * Handles deleting categories.
2726
+	 */
2727
+	protected function _delete_categories()
2728
+	{
2729
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2730
+			: (array) $this->_req_data['category_id'];
2731
+		foreach ($cat_ids as $cat_id) {
2732
+			$this->_delete_category($cat_id);
2733
+		}
2734
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2735
+		$query_args = [
2736
+			'action' => 'category_list',
2737
+		];
2738
+		$this->_redirect_after_action(0, '', '', $query_args);
2739
+	}
2740
+
2741
+
2742
+	/**
2743
+	 * Handles deleting specific category.
2744
+	 *
2745
+	 * @param int $cat_id
2746
+	 */
2747
+	protected function _delete_category($cat_id)
2748
+	{
2749
+		$cat_id = absint($cat_id);
2750
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2751
+	}
2752
+
2753
+
2754
+	/**
2755
+	 * Handles triggering the update or insertion of a new category.
2756
+	 *
2757
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2758
+	 * @throws EE_Error
2759
+	 * @throws InvalidArgumentException
2760
+	 * @throws InvalidDataTypeException
2761
+	 * @throws InvalidInterfaceException
2762
+	 */
2763
+	protected function _insert_or_update_category($new_category)
2764
+	{
2765
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2766
+		$success = 0; // we already have a success message so lets not send another.
2767
+		if ($cat_id) {
2768
+			$query_args = [
2769
+				'action'     => 'edit_category',
2770
+				'EVT_CAT_ID' => $cat_id,
2771
+			];
2772
+		} else {
2773
+			$query_args = ['action' => 'add_category'];
2774
+		}
2775
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2776
+	}
2777
+
2778
+
2779
+	/**
2780
+	 * Inserts or updates category
2781
+	 *
2782
+	 * @param bool $update (true indicates we're updating a category).
2783
+	 * @return bool|mixed|string
2784
+	 */
2785
+	private function _insert_category($update = false)
2786
+	{
2787
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2788
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2789
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2790
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2791
+		if (empty($category_name)) {
2792
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2793
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2794
+			return false;
2795
+		}
2796
+		$term_args = [
2797
+			'name'        => $category_name,
2798
+			'description' => $category_desc,
2799
+			'parent'      => $category_parent,
2800
+		];
2801
+		// was the category_identifier input disabled?
2802
+		if (isset($this->_req_data['category_identifier'])) {
2803
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2804
+		}
2805
+		$insert_ids = $update
2806
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2807
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2808
+		if (! is_array($insert_ids)) {
2809
+			$msg = esc_html__(
2810
+				'An error occurred and the category has not been saved to the database.',
2811
+				'event_espresso'
2812
+			);
2813
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2814
+		} else {
2815
+			$cat_id = $insert_ids['term_id'];
2816
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2817
+			EE_Error::add_success($msg);
2818
+		}
2819
+		return $cat_id;
2820
+	}
2821
+
2822
+
2823
+	/**
2824
+	 * Gets categories or count of categories matching the arguments in the request.
2825
+	 *
2826
+	 * @param int  $per_page
2827
+	 * @param int  $current_page
2828
+	 * @param bool $count
2829
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2830
+	 * @throws EE_Error
2831
+	 * @throws InvalidArgumentException
2832
+	 * @throws InvalidDataTypeException
2833
+	 * @throws InvalidInterfaceException
2834
+	 */
2835
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2836
+	{
2837
+		// testing term stuff
2838
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2839
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2840
+		$limit = ($current_page - 1) * $per_page;
2841
+		$where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2842
+		if (isset($this->_req_data['s'])) {
2843
+			$sstr = '%' . $this->_req_data['s'] . '%';
2844
+			$where['OR'] = [
2845
+				'Term.name'   => ['LIKE', $sstr],
2846
+				'description' => ['LIKE', $sstr],
2847
+			];
2848
+		}
2849
+		$query_params = [
2850
+			$where,
2851
+			'order_by'   => [$orderby => $order],
2852
+			'limit'      => $limit . ',' . $per_page,
2853
+			'force_join' => ['Term'],
2854
+		];
2855
+		$categories = $count
2856
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2857
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2858
+		return $categories;
2859
+	}
2860
+
2861
+	/* end category stuff */
2862
+	/**************/
2863
+
2864
+
2865
+	/**
2866
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2867
+	 *
2868
+	 * @throws EE_Error
2869
+	 * @throws InvalidArgumentException
2870
+	 * @throws InvalidDataTypeException
2871
+	 * @throws InvalidInterfaceException
2872
+	 */
2873
+	public function save_timezonestring_setting()
2874
+	{
2875
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2876
+			? $this->_req_data['timezone_selected']
2877
+			: '';
2878
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2879
+			EE_Error::add_error(
2880
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2881
+				__FILE__,
2882
+				__FUNCTION__,
2883
+				__LINE__
2884
+			);
2885
+			$this->_template_args['error'] = true;
2886
+			$this->_return_json();
2887
+		}
2888
+
2889
+		update_option('timezone_string', $timezone_string);
2890
+		EE_Error::add_success(
2891
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2892
+		);
2893
+		$this->_template_args['success'] = true;
2894
+		$this->_return_json(true, ['action' => 'create_new']);
2895
+	}
2896 2896
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
         ];
544 544
         // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
545 545
         $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
546
-        if (! $domain->isCaffeinated()) {
546
+        if ( ! $domain->isCaffeinated()) {
547 547
             $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
548 548
             $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
549 549
         }
@@ -602,13 +602,13 @@  discard block
 block discarded – undo
602 602
     {
603 603
         wp_register_style(
604 604
             'events-admin-css',
605
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
605
+            EVENTS_ASSETS_URL.'events-admin-page.css',
606 606
             [],
607 607
             EVENT_ESPRESSO_VERSION
608 608
         );
609 609
         wp_register_style(
610 610
             'ee-cat-admin',
611
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
611
+            EVENTS_ASSETS_URL.'ee-cat-admin.css',
612 612
             [],
613 613
             EVENT_ESPRESSO_VERSION
614 614
         );
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
         // scripts
618 618
         wp_register_script(
619 619
             'event_editor_js',
620
-            EVENTS_ASSETS_URL . 'event_editor.js',
620
+            EVENTS_ASSETS_URL.'event_editor.js',
621 621
             ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
622 622
             EVENT_ESPRESSO_VERSION,
623 623
             true
@@ -643,16 +643,16 @@  discard block
 block discarded – undo
643 643
         wp_enqueue_style('espresso-ui-theme');
644 644
         wp_register_style(
645 645
             'event-editor-css',
646
-            EVENTS_ASSETS_URL . 'event-editor.css',
646
+            EVENTS_ASSETS_URL.'event-editor.css',
647 647
             ['ee-admin-css'],
648 648
             EVENT_ESPRESSO_VERSION
649 649
         );
650 650
         wp_enqueue_style('event-editor-css');
651 651
         // scripts
652
-        if (! $this->admin_config->useAdvancedEditor()) {
652
+        if ( ! $this->admin_config->useAdvancedEditor()) {
653 653
             wp_register_script(
654 654
                 'event-datetime-metabox',
655
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
655
+                EVENTS_ASSETS_URL.'event-datetime-metabox.js',
656 656
                 ['event_editor_js', 'ee-datepicker'],
657 657
                 EVENT_ESPRESSO_VERSION
658 658
             );
@@ -721,15 +721,15 @@  discard block
 block discarded – undo
721 721
     public function verify_event_edit($event = null, $req_type = '')
722 722
     {
723 723
         // don't need to do this when processing
724
-        if (! empty($req_type)) {
724
+        if ( ! empty($req_type)) {
725 725
             return;
726 726
         }
727 727
         // no event?
728
-        if (! $event instanceof EE_Event) {
728
+        if ( ! $event instanceof EE_Event) {
729 729
             $event = $this->_cpt_model_obj;
730 730
         }
731 731
         // STILL no event?
732
-        if (! $event instanceof EE_Event) {
732
+        if ( ! $event instanceof EE_Event) {
733 733
             return;
734 734
         }
735 735
         $orig_status = $event->status();
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
             );
770 770
         }
771 771
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
772
-        if (! $event->tickets_on_sale()) {
772
+        if ( ! $event->tickets_on_sale()) {
773 773
             return;
774 774
         }
775 775
         // made it here so show warning
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
     {
815 815
         $has_timezone_string = get_option('timezone_string');
816 816
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
817
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
817
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
818 818
             EE_Error::add_attention(
819 819
                 sprintf(
820 820
                     __(
@@ -898,31 +898,31 @@  discard block
 block discarded – undo
898 898
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
899 899
         $statuses = [
900 900
             'sold_out_status'  => [
901
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
901
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
902 902
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
903 903
             ],
904 904
             'active_status'    => [
905
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
905
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
906 906
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
907 907
             ],
908 908
             'upcoming_status'  => [
909
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
909
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
910 910
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
911 911
             ],
912 912
             'postponed_status' => [
913
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
913
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
914 914
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
915 915
             ],
916 916
             'cancelled_status' => [
917
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
917
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
918 918
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
919 919
             ],
920 920
             'expired_status'   => [
921
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
921
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
922 922
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
923 923
             ],
924 924
             'inactive_status'  => [
925
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
925
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
926 926
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
927 927
             ],
928 928
         ];
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      */
938 938
     private function eventModel()
939 939
     {
940
-        if (! $this->_event_model instanceof EEM_Event) {
940
+        if ( ! $this->_event_model instanceof EEM_Event) {
941 941
             $this->_event_model = EEM_Event::instance();
942 942
         }
943 943
         return $this->_event_model;
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
      */
952 952
     private function datetimeModel($event_timezone_string = '')
953 953
     {
954
-        if (! $this->datetime_model instanceof EEM_Datetime) {
954
+        if ( ! $this->datetime_model instanceof EEM_Datetime) {
955 955
             $this->datetime_model = EEM_Datetime::instance($event_timezone_string);
956 956
         }
957 957
         return $this->datetime_model;
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
      */
966 966
     private function ticketModel($event_timezone_string = '')
967 967
     {
968
-        if (! $this->ticket_model instanceof EEM_Ticket) {
968
+        if ( ! $this->ticket_model instanceof EEM_Ticket) {
969 969
             $this->ticket_model = EEM_Ticket::instance($event_timezone_string);
970 970
         }
971 971
         return $this->ticket_model;
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
986 986
     {
987 987
         // make sure this is only when editing
988
-        if (! empty($id)) {
988
+        if ( ! empty($id)) {
989 989
             $post = get_post($id);
990 990
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
991 991
                        . esc_html__('Shortcode', 'event_espresso')
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
                                                                                   'button'
1023 1023
                                                                               );
1024 1024
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
1025
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1025
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1026 1026
             'create_new',
1027 1027
             'add',
1028 1028
             [],
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
         /** @var FeatureFlags $flags */
1085 1085
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1086 1086
         // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1087
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1087
+        if ( ! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1088 1088
             $event_values['EVT_display_ticket_selector'] =
1089 1089
                 ! empty($this->_req_data['display_ticket_selector'])
1090 1090
                     ? 1
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
      */
1198 1198
     protected function _default_venue_update(EE_Event $evtobj, $data)
1199 1199
     {
1200
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1200
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1201 1201
         $venue_model = EEM_Venue::instance();
1202 1202
         $rows_affected = null;
1203 1203
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
             'status'              => 'publish',
1229 1229
         ];
1230 1230
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1231
-        if (! empty($venue_id)) {
1231
+        if ( ! empty($venue_id)) {
1232 1232
             $update_where = [$venue_model->primary_key_name() => $venue_id];
1233 1233
             $rows_affected = $venue_model->update($venue_array, [$update_where]);
1234 1234
             // 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.
@@ -1282,7 +1282,7 @@  discard block
 block discarded – undo
1282 1282
                 'DTT_order'     => $row,
1283 1283
             ];
1284 1284
             // 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.
1285
-            if (! empty($dtt['DTT_ID'])) {
1285
+            if ( ! empty($dtt['DTT_ID'])) {
1286 1286
                 $DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']);
1287 1287
                 $DTM->set_date_format($incoming_date_formats[0]);
1288 1288
                 $DTM->set_time_format($incoming_date_formats[1]);
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
                     $DTM->set($field, $value);
1291 1291
                 }
1292 1292
                 // 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.
1293
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1293
+                $saved_dtts[$DTM->ID()] = $DTM;
1294 1294
             } else {
1295 1295
                 $DTM = EE_Registry::instance()->load_class(
1296 1296
                     'Datetime',
@@ -1323,12 +1323,12 @@  discard block
 block discarded – undo
1323 1323
         foreach ($data['edit_tickets'] as $row => $tkt) {
1324 1324
             $incoming_date_formats = ['Y-m-d', 'h:i a'];
1325 1325
             $update_prices = false;
1326
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1327
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1326
+            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1327
+                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1328 1328
             // trim inputs to ensure any excess whitespace is removed.
1329 1329
             $tkt = array_map('trim', $tkt);
1330 1330
             if (empty($tkt['TKT_start_date'])) {
1331
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1331
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1332 1332
             }
1333 1333
             if (empty($tkt['TKT_end_date'])) {
1334 1334
                 // use the start date of the first datetime
@@ -1363,7 +1363,7 @@  discard block
 block discarded – undo
1363 1363
             // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1364 1364
             // 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.
1365 1365
             // 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.
1366
-            if (! empty($tkt['TKT_ID'])) {
1366
+            if ( ! empty($tkt['TKT_ID'])) {
1367 1367
                 $TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']);
1368 1368
                 if ($TKT instanceof EE_Ticket) {
1369 1369
                     $ticket_sold = $TKT->count_related(
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
                         $TKT->set('TKT_deleted', 1);
1403 1403
                         $TKT->save();
1404 1404
                         // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1405
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1405
+                        $saved_tickets[$TKT->ID()] = $TKT;
1406 1406
                         // 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.
1407 1407
                         $TKT = clone $TKT;
1408 1408
                         $TKT->set('TKT_ID', 0);
@@ -1447,9 +1447,9 @@  discard block
 block discarded – undo
1447 1447
             }
1448 1448
             // initially let's add the ticket to the dtt
1449 1449
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1450
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1450
+            $saved_tickets[$TKT->ID()] = $TKT;
1451 1451
             // add prices to ticket
1452
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1452
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1453 1453
         }
1454 1454
         // 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.
1455 1455
         $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
@@ -1616,7 +1616,7 @@  discard block
 block discarded – undo
1616 1616
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1617 1617
         // load template
1618 1618
         EEH_Template::display_template(
1619
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1619
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1620 1620
             $publish_box_extra_args
1621 1621
         );
1622 1622
     }
@@ -1652,7 +1652,7 @@  discard block
 block discarded – undo
1652 1652
         /** @var FeatureFlags $flags */
1653 1653
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1654 1654
         // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1655
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1655
+        if ( ! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1656 1656
             add_meta_box(
1657 1657
                 'espresso_event_editor_event_options',
1658 1658
                 esc_html__('Event Registration Options', 'event_espresso'),
@@ -1661,7 +1661,7 @@  discard block
 block discarded – undo
1661 1661
                 'side'
1662 1662
             );
1663 1663
         }
1664
-        if (! $use_advanced_editor) {
1664
+        if ( ! $use_advanced_editor) {
1665 1665
             add_meta_box(
1666 1666
                 'espresso_event_editor_tickets',
1667 1667
                 esc_html__('Event Datetime & Ticket', 'event_espresso'),
@@ -1674,7 +1674,7 @@  discard block
 block discarded – undo
1674 1674
             if ($flags->featureAllowed('use_reg_options_meta_box')) {
1675 1675
                 add_action(
1676 1676
                     'add_meta_boxes_espresso_events',
1677
-                    function () {
1677
+                    function() {
1678 1678
                         global $current_screen;
1679 1679
                         remove_meta_box('authordiv', $current_screen, 'normal');
1680 1680
                     },
@@ -1739,7 +1739,7 @@  discard block
 block discarded – undo
1739 1739
                     'default_where_conditions' => 'none',
1740 1740
                 ]
1741 1741
             );
1742
-            if (! empty($related_tickets)) {
1742
+            if ( ! empty($related_tickets)) {
1743 1743
                 $template_args['total_ticket_rows'] = count($related_tickets);
1744 1744
                 $row = 0;
1745 1745
                 foreach ($related_tickets as $ticket) {
@@ -1773,7 +1773,7 @@  discard block
 block discarded – undo
1773 1773
         );
1774 1774
         $template = apply_filters(
1775 1775
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1776
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1776
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1777 1777
         );
1778 1778
         EEH_Template::display_template($template, $template_args);
1779 1779
     }
@@ -1796,7 +1796,7 @@  discard block
 block discarded – undo
1796 1796
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1797 1797
     {
1798 1798
         $template_args = [
1799
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1799
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1800 1800
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1801 1801
                 : '',
1802 1802
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1808,10 +1808,10 @@  discard block
 block discarded – undo
1808 1808
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1809 1809
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1810 1810
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1811
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1812
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1811
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1812
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1813 1813
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1814
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1814
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1815 1815
                 : ' disabled=disabled',
1816 1816
         ];
1817 1817
         $price = $ticket->ID() !== 0
@@ -1838,7 +1838,7 @@  discard block
 block discarded – undo
1838 1838
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
1839 1839
                 )
1840 1840
                 : null;
1841
-            if (! empty($earliest_dtt)) {
1841
+            if ( ! empty($earliest_dtt)) {
1842 1842
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1843 1843
             } else {
1844 1844
                 $template_args['TKT_end_date'] = date(
@@ -1850,7 +1850,7 @@  discard block
 block discarded – undo
1850 1850
         $template_args = array_merge($template_args, $price_args);
1851 1851
         $template = apply_filters(
1852 1852
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1853
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1853
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1854 1854
             $ticket
1855 1855
         );
1856 1856
         return EEH_Template::display_template($template, $template_args, true);
@@ -1905,7 +1905,7 @@  discard block
 block discarded – undo
1905 1905
             $default_reg_status_values
1906 1906
         );
1907 1907
         EEH_Template::display_template(
1908
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1908
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1909 1909
             $template_args
1910 1910
         );
1911 1911
     }
@@ -1934,7 +1934,7 @@  discard block
 block discarded – undo
1934 1934
     {
1935 1935
         $EEME = $this->eventModel();
1936 1936
         $offset = ($current_page - 1) * $per_page;
1937
-        $limit = $count ? null : $offset . ',' . $per_page;
1937
+        $limit = $count ? null : $offset.','.$per_page;
1938 1938
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1939 1939
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1940 1940
         if (isset($this->_req_data['month_range'])) {
@@ -1963,7 +1963,7 @@  discard block
 block discarded – undo
1963 1963
         // categories?
1964 1964
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1965 1965
             ? $this->_req_data['EVT_CAT'] : null;
1966
-        if (! empty($category)) {
1966
+        if ( ! empty($category)) {
1967 1967
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968 1968
             $where['Term_Taxonomy.term_id'] = $category;
1969 1969
         }
@@ -1971,7 +1971,7 @@  discard block
 block discarded – undo
1971 1971
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972 1972
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1973 1973
             $DateTime = new DateTime(
1974
-                $year_r . '-' . $month_r . '-01 00:00:00',
1974
+                $year_r.'-'.$month_r.'-01 00:00:00',
1975 1975
                 new DateTimeZone('UTC')
1976 1976
             );
1977 1977
             $start = $DateTime->getTimestamp();
@@ -1997,7 +1997,7 @@  discard block
 block discarded – undo
1997 1997
                             ->format(implode(' ', $start_formats));
1998 1998
             $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1999 1999
         }
2000
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2000
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2001 2001
             $where['EVT_wp_user'] = get_current_user_id();
2002 2002
         } elseif (
2003 2003
             ! isset($where['status'])
@@ -2021,7 +2021,7 @@  discard block
 block discarded – undo
2021 2021
         }
2022 2022
         // search query handling
2023 2023
         if (isset($this->_req_data['s'])) {
2024
-            $search_string = '%' . $this->_req_data['s'] . '%';
2024
+            $search_string = '%'.$this->_req_data['s'].'%';
2025 2025
             $where['OR'] = [
2026 2026
                 'EVT_name'       => ['LIKE', $search_string],
2027 2027
                 'EVT_desc'       => ['LIKE', $search_string],
@@ -2136,7 +2136,7 @@  discard block
 block discarded – undo
2136 2136
             // clean status
2137 2137
             $event_status = sanitize_key($event_status);
2138 2138
             // grab status
2139
-            if (! empty($event_status)) {
2139
+            if ( ! empty($event_status)) {
2140 2140
                 $success = $this->_change_event_status($EVT_ID, $event_status);
2141 2141
             } else {
2142 2142
                 $success = false;
@@ -2177,7 +2177,7 @@  discard block
 block discarded – undo
2177 2177
         // clean status
2178 2178
         $event_status = sanitize_key($event_status);
2179 2179
         // grab status
2180
-        if (! empty($event_status)) {
2180
+        if ( ! empty($event_status)) {
2181 2181
             $success = true;
2182 2182
             // determine the event id and set to array.
2183 2183
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
@@ -2228,7 +2228,7 @@  discard block
 block discarded – undo
2228 2228
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2229 2229
     {
2230 2230
         // grab event id
2231
-        if (! $EVT_ID) {
2231
+        if ( ! $EVT_ID) {
2232 2232
             $msg = esc_html__(
2233 2233
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2234 2234
                 'event_espresso'
@@ -2302,7 +2302,7 @@  discard block
 block discarded – undo
2302 2302
      */
2303 2303
     protected function getModelObjNodeGroupPersister()
2304 2304
     {
2305
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2305
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2306 2306
             $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2307 2307
         }
2308 2308
         return $this->model_obj_node_group_persister;
@@ -2577,7 +2577,7 @@  discard block
 block discarded – undo
2577 2577
                                                 . esc_html__(
2578 2578
                                                     '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.',
2579 2579
                                                     'event_espresso'
2580
-                                                ) . '</strong>';
2580
+                                                ).'</strong>';
2581 2581
         $this->display_admin_caf_preview_page('template_settings_tab');
2582 2582
     }
2583 2583
 
@@ -2596,12 +2596,12 @@  discard block
 block discarded – undo
2596 2596
         // set default category object
2597 2597
         $this->_set_empty_category_object();
2598 2598
         // only set if we've got an id
2599
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2599
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2600 2600
             return;
2601 2601
         }
2602 2602
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2603 2603
         $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2604
-        if (! empty($term)) {
2604
+        if ( ! empty($term)) {
2605 2605
             $this->_category->category_name = $term->name;
2606 2606
             $this->_category->category_identifier = $term->slug;
2607 2607
             $this->_category->category_desc = $term->description;
@@ -2633,7 +2633,7 @@  discard block
 block discarded – undo
2633 2633
     {
2634 2634
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2635 2635
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2636
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2636
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2637 2637
             'add_category',
2638 2638
             'add_category',
2639 2639
             [],
@@ -2716,7 +2716,7 @@  discard block
 block discarded – undo
2716 2716
             'disable'                  => '',
2717 2717
             'disabled_message'         => false,
2718 2718
         ];
2719
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2719
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2720 2720
         return EEH_Template::display_template($template, $template_args, true);
2721 2721
     }
2722 2722
 
@@ -2805,7 +2805,7 @@  discard block
 block discarded – undo
2805 2805
         $insert_ids = $update
2806 2806
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2807 2807
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2808
-        if (! is_array($insert_ids)) {
2808
+        if ( ! is_array($insert_ids)) {
2809 2809
             $msg = esc_html__(
2810 2810
                 'An error occurred and the category has not been saved to the database.',
2811 2811
                 'event_espresso'
@@ -2840,7 +2840,7 @@  discard block
 block discarded – undo
2840 2840
         $limit = ($current_page - 1) * $per_page;
2841 2841
         $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2842 2842
         if (isset($this->_req_data['s'])) {
2843
-            $sstr = '%' . $this->_req_data['s'] . '%';
2843
+            $sstr = '%'.$this->_req_data['s'].'%';
2844 2844
             $where['OR'] = [
2845 2845
                 'Term.name'   => ['LIKE', $sstr],
2846 2846
                 'description' => ['LIKE', $sstr],
@@ -2849,7 +2849,7 @@  discard block
 block discarded – undo
2849 2849
         $query_params = [
2850 2850
             $where,
2851 2851
             'order_by'   => [$orderby => $order],
2852
-            'limit'      => $limit . ',' . $per_page,
2852
+            'limit'      => $limit.','.$per_page,
2853 2853
             'force_join' => ['Term'],
2854 2854
         ];
2855 2855
         $categories = $count
Please login to merge, or discard this patch.