Completed
Branch BUG/escape-localized-variables (9e8bda)
by
unknown
02:24 queued 24s
created
admin/extend/transactions/Extend_Transactions_Admin_Page.core.php 2 patches
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -16,247 +16,247 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
25
-
26
-    /**
27
-     * @Constructor
28
-     * @access public
29
-     *
30
-     * @param bool $routing
31
-     *
32
-     * @return \Extend_Transactions_Admin_Page
33
-     */
34
-    public function __construct($routing = true)
35
-    {
36
-        parent::__construct($routing);
37
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
40
-    }
41
-
42
-
43
-    /**
44
-     *    _extend_page_config
45
-     *
46
-     * @access protected
47
-     * @return void
48
-     */
49
-    protected function _extend_page_config()
50
-    {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
52
-
53
-        $new_page_routes = array(
54
-            'reports' => array(
55
-                'func'       => '_transaction_reports',
56
-                'capability' => 'ee_read_transactions',
57
-            ),
58
-        );
59
-
60
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
61
-
62
-        $new_page_config = array(
63
-            'reports' => array(
64
-                'nav'           => array(
65
-                    'label' => __('Reports', 'event_espresso'),
66
-                    'order' => 20,
67
-                ),
68
-                'help_tabs'     => array(
69
-                    'transactions_reports_help_tab' => array(
70
-                        'title'    => __('Transaction Reports', 'event_espresso'),
71
-                        'filename' => 'transactions_reports',
72
-                    ),
73
-                ),
74
-                /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
75
-                'require_nonce' => false,
76
-            ),
77
-        );
78
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
79
-    }
80
-
81
-
82
-    /**
83
-     *    load_scripts_styles_reports
84
-     *
85
-     * @access public
86
-     * @return void
87
-     */
88
-    public function load_scripts_styles_reports()
89
-    {
90
-        wp_register_script(
91
-            'ee-txn-reports-js',
92
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
93
-            array('google-charts'),
94
-            EVENT_ESPRESSO_VERSION,
95
-            true
96
-        );
97
-        wp_enqueue_script('ee-txn-reports-js');
98
-        $this->_transaction_reports_js_setup();
99
-        EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
100
-    }
101
-
102
-
103
-    /**
104
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
105
-     * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
106
-     */
107
-    protected function _transaction_reports_js_setup()
108
-    {
109
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
-    }
112
-
113
-
114
-    /**
115
-     * _transaction_reports
116
-     *    generates Business Reports regarding Transactions
117
-     *
118
-     * @return void
119
-     */
120
-    protected function _transaction_reports()
121
-    {
122
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
123
-        $this->_admin_page_title = __('Transactions', 'event_espresso');
124
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
125
-            $template_path,
126
-            $this->_reports_template_data,
127
-            true
128
-        );
129
-
130
-        // the final template wrapper
131
-        $this->display_admin_page_with_no_sidebar();
132
-    }
133
-
134
-
135
-    /**
136
-     * _revenue_per_day_report
137
-     * generates Business Report showing Total Revenue per Day.
138
-     *
139
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
140
-     *
141
-     * @return string
142
-     */
143
-    private function _revenue_per_day_report($period = '-1 month')
144
-    {
145
-
146
-        $report_ID = 'txn-admin-revenue-per-day-report-dv';
147
-
148
-        $TXN = EEM_Transaction::instance();
149
-
150
-        $results = $TXN->get_revenue_per_day_report($period);
151
-        $results = (array) $results;
152
-        $revenue = array();
153
-        $subtitle = '';
154
-
155
-        if ($results) {
156
-            $revenue[] = array(
157
-                __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
158
-                __('Total Revenue', 'event_espresso'),
159
-            );
160
-            foreach ($results as $result) {
161
-                $revenue[] = array($result->txnDate, (float) $result->revenue);
162
-            }
163
-
164
-            // setup the date range.
165
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166
-            $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167
-            $subtitle = sprintf(
168
-                wp_strip_all_tags(
169
-                    _x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
170
-                ),
171
-                $beginning_date->format('Y-m-d'),
172
-                $ending_date->format('Y-m-d')
173
-            );
174
-        }
175
-
176
-        $report_title = wp_strip_all_tags(__('Total Revenue per Day', 'event_espresso'));
177
-
178
-        $report_params = array(
179
-            'title'     => $report_title,
180
-            'subtitle'  => $subtitle,
181
-            'id'        => $report_ID,
182
-            'revenue'   => $revenue,
183
-            'noResults' => empty($revenue) || count($revenue) === 1,
184
-            'noTxnMsg'  => sprintf(
185
-                wp_strip_all_tags(
186
-                    __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
187
-                ),
188
-                '<h2>' . $report_title . '</h2><p>',
189
-                '</p>'
190
-            ),
191
-        );
192
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
193
-
194
-        return $report_ID;
195
-    }
196
-
197
-
198
-    /**
199
-     * _revenue_per_event_report
200
-     * generates Business Report showing total revenue per event.
201
-     *
202
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
203
-     *
204
-     * @return int
205
-     */
206
-    private function _revenue_per_event_report($period = '-1 month')
207
-    {
208
-
209
-        $report_ID = 'txn-admin-revenue-per-event-report-dv';
210
-
211
-        $TXN = EEM_Transaction::instance();
212
-        $results = $TXN->get_revenue_per_event_report($period);
213
-        $results = (array) $results;
214
-        $revenue = array();
215
-        $subtitle = '';
216
-
217
-        if ($results) {
218
-            $revenue[] = array(
219
-                __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
220
-                __('Total Revenue', 'event_espresso'),
221
-            );
222
-            foreach ($results as $result) {
223
-                if ($result->revenue > 1) {
224
-                    $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
225
-                    $event_name = wp_trim_words($event_name, 5, '...');
226
-                    $revenue[] = array($event_name, (float) $result->revenue);
227
-                }
228
-            }
229
-
230
-            // setup the date range.
231
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
232
-            $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
233
-            $subtitle = sprintf(
234
-                wp_strip_all_tags(
235
-                    _x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
236
-                ),
237
-                $beginning_date->format('Y-m-d'),
238
-                $ending_date->format('Y-m-d')
239
-            );
240
-        }
241
-
242
-        $report_title = wp_strip_all_tags(__('Total Revenue per Event', 'event_espresso'));
243
-
244
-        $report_params = array(
245
-            'title'     => $report_title,
246
-            'subtitle'  => $subtitle,
247
-            'id'        => $report_ID,
248
-            'revenue'   => $revenue,
249
-            'noResults' => empty($revenue),
250
-            'noTxnMsg'  => sprintf(
251
-                wp_strip_all_tags(
252
-                    __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
253
-                ),
254
-                '<h2>' . $report_title . '</h2><p>',
255
-                '</p>'
256
-            ),
257
-        );
258
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
259
-
260
-        return $report_ID;
261
-    }
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25
+
26
+	/**
27
+	 * @Constructor
28
+	 * @access public
29
+	 *
30
+	 * @param bool $routing
31
+	 *
32
+	 * @return \Extend_Transactions_Admin_Page
33
+	 */
34
+	public function __construct($routing = true)
35
+	{
36
+		parent::__construct($routing);
37
+		define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
+		define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
+		define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
40
+	}
41
+
42
+
43
+	/**
44
+	 *    _extend_page_config
45
+	 *
46
+	 * @access protected
47
+	 * @return void
48
+	 */
49
+	protected function _extend_page_config()
50
+	{
51
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
52
+
53
+		$new_page_routes = array(
54
+			'reports' => array(
55
+				'func'       => '_transaction_reports',
56
+				'capability' => 'ee_read_transactions',
57
+			),
58
+		);
59
+
60
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
61
+
62
+		$new_page_config = array(
63
+			'reports' => array(
64
+				'nav'           => array(
65
+					'label' => __('Reports', 'event_espresso'),
66
+					'order' => 20,
67
+				),
68
+				'help_tabs'     => array(
69
+					'transactions_reports_help_tab' => array(
70
+						'title'    => __('Transaction Reports', 'event_espresso'),
71
+						'filename' => 'transactions_reports',
72
+					),
73
+				),
74
+				/*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
75
+				'require_nonce' => false,
76
+			),
77
+		);
78
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
79
+	}
80
+
81
+
82
+	/**
83
+	 *    load_scripts_styles_reports
84
+	 *
85
+	 * @access public
86
+	 * @return void
87
+	 */
88
+	public function load_scripts_styles_reports()
89
+	{
90
+		wp_register_script(
91
+			'ee-txn-reports-js',
92
+			TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
93
+			array('google-charts'),
94
+			EVENT_ESPRESSO_VERSION,
95
+			true
96
+		);
97
+		wp_enqueue_script('ee-txn-reports-js');
98
+		$this->_transaction_reports_js_setup();
99
+		EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
100
+	}
101
+
102
+
103
+	/**
104
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
105
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
106
+	 */
107
+	protected function _transaction_reports_js_setup()
108
+	{
109
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
+	}
112
+
113
+
114
+	/**
115
+	 * _transaction_reports
116
+	 *    generates Business Reports regarding Transactions
117
+	 *
118
+	 * @return void
119
+	 */
120
+	protected function _transaction_reports()
121
+	{
122
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
123
+		$this->_admin_page_title = __('Transactions', 'event_espresso');
124
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
125
+			$template_path,
126
+			$this->_reports_template_data,
127
+			true
128
+		);
129
+
130
+		// the final template wrapper
131
+		$this->display_admin_page_with_no_sidebar();
132
+	}
133
+
134
+
135
+	/**
136
+	 * _revenue_per_day_report
137
+	 * generates Business Report showing Total Revenue per Day.
138
+	 *
139
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
140
+	 *
141
+	 * @return string
142
+	 */
143
+	private function _revenue_per_day_report($period = '-1 month')
144
+	{
145
+
146
+		$report_ID = 'txn-admin-revenue-per-day-report-dv';
147
+
148
+		$TXN = EEM_Transaction::instance();
149
+
150
+		$results = $TXN->get_revenue_per_day_report($period);
151
+		$results = (array) $results;
152
+		$revenue = array();
153
+		$subtitle = '';
154
+
155
+		if ($results) {
156
+			$revenue[] = array(
157
+				__('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
158
+				__('Total Revenue', 'event_espresso'),
159
+			);
160
+			foreach ($results as $result) {
161
+				$revenue[] = array($result->txnDate, (float) $result->revenue);
162
+			}
163
+
164
+			// setup the date range.
165
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166
+			$ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167
+			$subtitle = sprintf(
168
+				wp_strip_all_tags(
169
+					_x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
170
+				),
171
+				$beginning_date->format('Y-m-d'),
172
+				$ending_date->format('Y-m-d')
173
+			);
174
+		}
175
+
176
+		$report_title = wp_strip_all_tags(__('Total Revenue per Day', 'event_espresso'));
177
+
178
+		$report_params = array(
179
+			'title'     => $report_title,
180
+			'subtitle'  => $subtitle,
181
+			'id'        => $report_ID,
182
+			'revenue'   => $revenue,
183
+			'noResults' => empty($revenue) || count($revenue) === 1,
184
+			'noTxnMsg'  => sprintf(
185
+				wp_strip_all_tags(
186
+					__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
187
+				),
188
+				'<h2>' . $report_title . '</h2><p>',
189
+				'</p>'
190
+			),
191
+		);
192
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
193
+
194
+		return $report_ID;
195
+	}
196
+
197
+
198
+	/**
199
+	 * _revenue_per_event_report
200
+	 * generates Business Report showing total revenue per event.
201
+	 *
202
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
203
+	 *
204
+	 * @return int
205
+	 */
206
+	private function _revenue_per_event_report($period = '-1 month')
207
+	{
208
+
209
+		$report_ID = 'txn-admin-revenue-per-event-report-dv';
210
+
211
+		$TXN = EEM_Transaction::instance();
212
+		$results = $TXN->get_revenue_per_event_report($period);
213
+		$results = (array) $results;
214
+		$revenue = array();
215
+		$subtitle = '';
216
+
217
+		if ($results) {
218
+			$revenue[] = array(
219
+				__('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
220
+				__('Total Revenue', 'event_espresso'),
221
+			);
222
+			foreach ($results as $result) {
223
+				if ($result->revenue > 1) {
224
+					$event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
225
+					$event_name = wp_trim_words($event_name, 5, '...');
226
+					$revenue[] = array($event_name, (float) $result->revenue);
227
+				}
228
+			}
229
+
230
+			// setup the date range.
231
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
232
+			$ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
233
+			$subtitle = sprintf(
234
+				wp_strip_all_tags(
235
+					_x('For the period: %s to %s', 'Used to give date range', 'event_espresso')
236
+				),
237
+				$beginning_date->format('Y-m-d'),
238
+				$ending_date->format('Y-m-d')
239
+			);
240
+		}
241
+
242
+		$report_title = wp_strip_all_tags(__('Total Revenue per Event', 'event_espresso'));
243
+
244
+		$report_params = array(
245
+			'title'     => $report_title,
246
+			'subtitle'  => $subtitle,
247
+			'id'        => $report_ID,
248
+			'revenue'   => $revenue,
249
+			'noResults' => empty($revenue),
250
+			'noTxnMsg'  => sprintf(
251
+				wp_strip_all_tags(
252
+					__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
253
+				),
254
+				'<h2>' . $report_title . '</h2><p>',
255
+				'</p>'
256
+			),
257
+		);
258
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
259
+
260
+		return $report_ID;
261
+	}
262 262
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
     public function __construct($routing = true)
35 35
     {
36 36
         parent::__construct($routing);
37
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
37
+        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'transactions/templates/');
38
+        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'transactions/assets/');
39
+        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'transactions/assets/');
40 40
     }
41 41
 
42 42
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     protected function _extend_page_config()
50 50
     {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
51
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'transactions';
52 52
 
53 53
         $new_page_routes = array(
54 54
             'reports' => array(
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     {
90 90
         wp_register_script(
91 91
             'ee-txn-reports-js',
92
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
92
+            TXN_CAF_ASSETS_URL.'ee-transaction-admin-reports.js',
93 93
             array('google-charts'),
94 94
             EVENT_ESPRESSO_VERSION,
95 95
             true
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     protected function _transaction_reports()
121 121
     {
122
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
122
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
123 123
         $this->_admin_page_title = __('Transactions', 'event_espresso');
124 124
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
125 125
             $template_path,
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             }
163 163
 
164 164
             // setup the date range.
165
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
165
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166 166
             $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167 167
             $subtitle = sprintf(
168 168
                 wp_strip_all_tags(
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                 wp_strip_all_tags(
186 186
                     __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
187 187
                 ),
188
-                '<h2>' . $report_title . '</h2><p>',
188
+                '<h2>'.$report_title.'</h2><p>',
189 189
                 '</p>'
190 190
             ),
191 191
         );
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
             }
229 229
 
230 230
             // setup the date range.
231
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
231
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
232 232
             $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
233 233
             $subtitle = sprintf(
234 234
                 wp_strip_all_tags(
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
                 wp_strip_all_tags(
252 252
                     __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso')
253 253
                 ),
254
-                '<h2>' . $report_title . '</h2><p>',
254
+                '<h2>'.$report_title.'</h2><p>',
255 255
                 '</p>'
256 256
             ),
257 257
         );
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT_Init.core.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -14,45 +14,45 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    public function do_initial_loads()
18
-    {
19
-        // we want to use the corresponding admin page object (but not route it!).  To do this we just set _routing to false.  That way this page object is being loaded on all pages to make sure we hook into admin properly.  But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
20
-        // This is important because we have hooks that help redirect custom post type saves
21
-        if (! isset($_REQUEST['page'])
22
-            || (isset($_REQUEST['page'])
23
-                && $_REQUEST['page']
24
-                   != $this->_menu_map->menu_slug)) {
25
-            $this->_routing = false;
26
-            $this->_initialize_admin_page();
27
-        } else {
28
-            // normal init loads
29
-            $this->_initialize_admin_page();
30
-            // added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality
31
-            remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
32
-            add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100);
33
-            // end removal of autosave functionality.
34
-        }
35
-    }
17
+	public function do_initial_loads()
18
+	{
19
+		// we want to use the corresponding admin page object (but not route it!).  To do this we just set _routing to false.  That way this page object is being loaded on all pages to make sure we hook into admin properly.  But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
20
+		// This is important because we have hooks that help redirect custom post type saves
21
+		if (! isset($_REQUEST['page'])
22
+			|| (isset($_REQUEST['page'])
23
+				&& $_REQUEST['page']
24
+				   != $this->_menu_map->menu_slug)) {
25
+			$this->_routing = false;
26
+			$this->_initialize_admin_page();
27
+		} else {
28
+			// normal init loads
29
+			$this->_initialize_admin_page();
30
+			// added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality
31
+			remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
32
+			add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100);
33
+			// end removal of autosave functionality.
34
+		}
35
+	}
36 36
 
37 37
 
38
-    public function wp_just_in_time_script_localization()
39
-    {
40
-        wp_localize_script(
41
-            'autosave',
42
-            'autosaveL10n',
43
-            array(
44
-                'autosaveInterval' => 172800,
45
-                'savingText'       => wp_strip_all_tags(__('Saving Draft&#8230;', 'event_espresso')),
46
-                'saveAlert'        => wp_strip_all_tags(
47
-                    __('The changes you made will be lost if you navigate away from this page.', 'event_espresso')
48
-                ),
49
-            )
50
-        );
51
-    }
38
+	public function wp_just_in_time_script_localization()
39
+	{
40
+		wp_localize_script(
41
+			'autosave',
42
+			'autosaveL10n',
43
+			array(
44
+				'autosaveInterval' => 172800,
45
+				'savingText'       => wp_strip_all_tags(__('Saving Draft&#8230;', 'event_espresso')),
46
+				'saveAlert'        => wp_strip_all_tags(
47
+					__('The changes you made will be lost if you navigate away from this page.', 'event_espresso')
48
+				),
49
+			)
50
+		);
51
+	}
52 52
 
53 53
 
54
-    public function adjust_post_lock_window($interval)
55
-    {
56
-        return 172800;
57
-    }
54
+	public function adjust_post_lock_window($interval)
55
+	{
56
+		return 172800;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 1 patch
Indentation   +882 added lines, -882 removed lines patch added patch discarded remove patch
@@ -17,886 +17,886 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @var EE_Form_Section_Proper
22
-     */
23
-    protected $datetime_fix_offset_form;
24
-
25
-
26
-    protected function _init_page_props()
27
-    {
28
-        $this->page_slug = EE_MAINTENANCE_PG_SLUG;
29
-        $this->page_label = EE_MAINTENANCE_LABEL;
30
-        $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
31
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
32
-    }
33
-
34
-
35
-    protected function _ajax_hooks()
36
-    {
37
-        add_action('wp_ajax_migration_step', array($this, 'migration_step'));
38
-        add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
39
-    }
40
-
41
-
42
-    protected function _define_page_props()
43
-    {
44
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
45
-        $this->_labels = array(
46
-            'buttons' => array(
47
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
48
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
49
-            ),
50
-        );
51
-    }
52
-
53
-
54
-    protected function _set_page_routes()
55
-    {
56
-        $this->_page_routes = array(
57
-            'default'                             => array(
58
-                'func'       => '_maintenance',
59
-                'capability' => 'manage_options',
60
-            ),
61
-            'change_maintenance_level'            => array(
62
-                'func'       => '_change_maintenance_level',
63
-                'capability' => 'manage_options',
64
-                'noheader'   => true,
65
-            ),
66
-            'system_status'                       => array(
67
-                'func'       => '_system_status',
68
-                'capability' => 'manage_options',
69
-            ),
70
-            'download_system_status'              => array(
71
-                'func'       => '_download_system_status',
72
-                'capability' => 'manage_options',
73
-                'noheader'   => true,
74
-            ),
75
-            'send_migration_crash_report'         => array(
76
-                'func'       => '_send_migration_crash_report',
77
-                'capability' => 'manage_options',
78
-                'noheader'   => true,
79
-            ),
80
-            'confirm_migration_crash_report_sent' => array(
81
-                'func'       => '_confirm_migration_crash_report_sent',
82
-                'capability' => 'manage_options',
83
-            ),
84
-            'data_reset'                          => array(
85
-                'func'       => '_data_reset_and_delete',
86
-                'capability' => 'manage_options',
87
-            ),
88
-            'reset_db'                            => array(
89
-                'func'       => '_reset_db',
90
-                'capability' => 'manage_options',
91
-                'noheader'   => true,
92
-                'args'       => array('nuke_old_ee4_data' => true),
93
-            ),
94
-            'start_with_fresh_ee4_db'             => array(
95
-                'func'       => '_reset_db',
96
-                'capability' => 'manage_options',
97
-                'noheader'   => true,
98
-                'args'       => array('nuke_old_ee4_data' => false),
99
-            ),
100
-            'delete_db'                           => array(
101
-                'func'       => '_delete_db',
102
-                'capability' => 'manage_options',
103
-                'noheader'   => true,
104
-            ),
105
-            'rerun_migration_from_ee3'            => array(
106
-                'func'       => '_rerun_migration_from_ee3',
107
-                'capability' => 'manage_options',
108
-                'noheader'   => true,
109
-            ),
110
-            'reset_reservations'                  => array(
111
-                'func'       => '_reset_reservations',
112
-                'capability' => 'manage_options',
113
-                'noheader'   => true,
114
-            ),
115
-            'reset_capabilities'                  => array(
116
-                'func'       => '_reset_capabilities',
117
-                'capability' => 'manage_options',
118
-                'noheader'   => true,
119
-            ),
120
-            'reattempt_migration'                 => array(
121
-                'func'       => '_reattempt_migration',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ),
125
-            'datetime_tools'                      => array(
126
-                'func'       => '_datetime_tools',
127
-                'capability' => 'manage_options',
128
-            ),
129
-            'run_datetime_offset_fix'             => array(
130
-                'func'               => '_apply_datetime_offset',
131
-                'noheader'           => true,
132
-                'headers_sent_route' => 'datetime_tools',
133
-                'capability'         => 'manage_options',
134
-            ),
135
-        );
136
-    }
137
-
138
-
139
-    protected function _set_page_config()
140
-    {
141
-        $this->_page_config = array(
142
-            'default'        => array(
143
-                'nav'           => array(
144
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
145
-                    'order' => 10,
146
-                ),
147
-                'require_nonce' => false,
148
-            ),
149
-            'data_reset'     => array(
150
-                'nav'           => array(
151
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
152
-                    'order' => 20,
153
-                ),
154
-                'require_nonce' => false,
155
-            ),
156
-            'datetime_tools' => array(
157
-                'nav'           => array(
158
-                    'label' => esc_html__('Datetime Utilities', 'event_espresso'),
159
-                    'order' => 25,
160
-                ),
161
-                'require_nonce' => false,
162
-            ),
163
-            'system_status'  => array(
164
-                'nav'           => array(
165
-                    'label' => esc_html__("System Information", "event_espresso"),
166
-                    'order' => 30,
167
-                ),
168
-                'require_nonce' => false,
169
-            ),
170
-        );
171
-    }
172
-
173
-
174
-    /**
175
-     * default maintenance page. If we're in maintenance mode level 2, then we need to show
176
-     * the migration scripts and all that UI.
177
-     */
178
-    public function _maintenance()
179
-    {
180
-        // it all depends if we're in maintenance model level 1 (frontend-only) or
181
-        // level 2 (everything except maintenance page)
182
-        try {
183
-            // get the current maintenance level and check if
184
-            // we are removed
185
-            $mm = EE_Maintenance_Mode::instance()->level();
186
-            $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
187
-            if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
188
-                // we just took the site out of maintenance mode, so notify the user.
189
-                // unfortunately this message appears to be echoed on the NEXT page load...
190
-                // oh well, we should really be checking for this on addon deactivation anyways
191
-                EE_Error::add_attention(
192
-                    __(
193
-                        'Site taken out of maintenance mode because no data migration scripts are required',
194
-                        'event_espresso'
195
-                    )
196
-                );
197
-                $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
198
-            }
199
-            // in case an exception is thrown while trying to handle migrations
200
-            switch (EE_Maintenance_Mode::instance()->level()) {
201
-                case EE_Maintenance_Mode::level_0_not_in_maintenance:
202
-                case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
203
-                    $show_maintenance_switch = true;
204
-                    $show_backup_db_text = false;
205
-                    $show_migration_progress = false;
206
-                    $script_names = array();
207
-                    $addons_should_be_upgraded_first = false;
208
-                    break;
209
-                case EE_Maintenance_Mode::level_2_complete_maintenance:
210
-                    $show_maintenance_switch = false;
211
-                    $show_migration_progress = true;
212
-                    if (isset($this->_req_data['continue_migration'])) {
213
-                        $show_backup_db_text = false;
214
-                    } else {
215
-                        $show_backup_db_text = true;
216
-                    }
217
-                    $scripts_needing_to_run = EE_Data_Migration_Manager::instance()
218
-                                                                       ->check_for_applicable_data_migration_scripts();
219
-                    $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
220
-                    $script_names = array();
221
-                    $current_script = null;
222
-                    foreach ($scripts_needing_to_run as $script) {
223
-                        if ($script instanceof EE_Data_Migration_Script_Base) {
224
-                            if (! $current_script) {
225
-                                $current_script = $script;
226
-                                $current_script->migration_page_hooks();
227
-                            }
228
-                            $script_names[] = $script->pretty_name();
229
-                        }
230
-                    }
231
-                    break;
232
-            }
233
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
234
-            $exception_thrown = false;
235
-        } catch (EE_Error $e) {
236
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
237
-            // now, just so we can display the page correctly, make a error migration script stage object
238
-            // and also put the error on it. It only persists for the duration of this request
239
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
240
-            $most_recent_migration->add_error($e->getMessage());
241
-            $exception_thrown = true;
242
-        }
243
-        $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
244
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
245
-        if ($exception_thrown
246
-            || ($most_recent_migration
247
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
248
-                && $most_recent_migration->is_broken()
249
-            )
250
-        ) {
251
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
252
-            $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
253
-            $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(
254
-                array(
255
-                    'action'  => 'confirm_migration_crash_report_sent',
256
-                    'success' => '0',
257
-                ),
258
-                EE_MAINTENANCE_ADMIN_URL
259
-            );
260
-        } elseif ($addons_should_be_upgraded_first) {
261
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
262
-        } else {
263
-            if ($most_recent_migration
264
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
265
-                && $most_recent_migration->can_continue()
266
-            ) {
267
-                $show_backup_db_text = false;
268
-                $show_continue_current_migration_script = true;
269
-                $show_most_recent_migration = true;
270
-            } elseif (isset($this->_req_data['continue_migration'])) {
271
-                $show_most_recent_migration = true;
272
-                $show_continue_current_migration_script = false;
273
-            } else {
274
-                $show_most_recent_migration = false;
275
-                $show_continue_current_migration_script = false;
276
-            }
277
-            if (isset($current_script)) {
278
-                $migrates_to = $current_script->migrates_to_version();
279
-                $plugin_slug = $migrates_to['slug'];
280
-                $new_version = $migrates_to['version'];
281
-                $this->_template_args = array_merge(
282
-                    $this->_template_args,
283
-                    array(
284
-                        'current_db_state' => sprintf(
285
-                            __("EE%s (%s)", "event_espresso"),
286
-                            isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
287
-                            $plugin_slug
288
-                        ),
289
-                        'next_db_state'    => isset($current_script) ? sprintf(
290
-                            __("EE%s (%s)", 'event_espresso'),
291
-                            $new_version,
292
-                            $plugin_slug
293
-                        ) : null,
294
-                    )
295
-                );
296
-            } else {
297
-                $this->_template_args['current_db_state'] = null;
298
-                $this->_template_args['next_db_state'] = null;
299
-            }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
-            $this->_template_args = array_merge(
302
-                $this->_template_args,
303
-                array(
304
-                    'show_most_recent_migration'             => $show_most_recent_migration,
305
-                    // flag for showing the most recent migration's status and/or errors
306
-                    'show_migration_progress'                => $show_migration_progress,
307
-                    // flag for showing the option to run migrations and see their progress
308
-                    'show_backup_db_text'                    => $show_backup_db_text,
309
-                    // flag for showing text telling the user to backup their DB
310
-                    'show_maintenance_switch'                => $show_maintenance_switch,
311
-                    // flag for showing the option to change maintenance mode between levels 0 and 1
312
-                    'script_names'                           => $script_names,
313
-                    // array of names of scripts that have run
314
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
-                    // flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
317
-                        array('action' => 'reset_db'),
318
-                        EE_MAINTENANCE_ADMIN_URL
319
-                    ),
320
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
321
-                        array('action' => 'data_reset'),
322
-                        EE_MAINTENANCE_ADMIN_URL
323
-                    ),
324
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
325
-                        array('action' => 'change_maintenance_level'),
326
-                        EE_MAINTENANCE_ADMIN_URL
327
-                    ),
328
-                    'ultimate_db_state'                      => sprintf(
329
-                        __("EE%s", 'event_espresso'),
330
-                        espresso_version()
331
-                    ),
332
-                )
333
-            );
334
-            // make sure we have the form fields helper available. It usually is, but sometimes it isn't
335
-        }
336
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;// the actual most recently ran migration
337
-        // now render the migration options part, and put it in a variable
338
-        $migration_options_template_file = apply_filters(
339
-            'FHEE__ee_migration_page__migration_options_template',
340
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
341
-        );
342
-        $migration_options_html = EEH_Template::display_template(
343
-            $migration_options_template_file,
344
-            $this->_template_args,
345
-            true
346
-        );
347
-        $this->_template_args['migration_options_html'] = $migration_options_html;
348
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
349
-            $this->_template_path,
350
-            $this->_template_args,
351
-            true
352
-        );
353
-        $this->display_admin_page_with_sidebar();
354
-    }
355
-
356
-
357
-    /**
358
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
359
-     */
360
-    public function migration_step()
361
-    {
362
-        $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
363
-        $this->_return_json();
364
-    }
365
-
366
-
367
-    /**
368
-     * Can be used by js when it notices a response with HTML in it in order
369
-     * to log the malformed response
370
-     */
371
-    public function add_error_to_migrations_ran()
372
-    {
373
-        EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
374
-        $this->_template_args['data'] = array('ok' => true);
375
-        $this->_return_json();
376
-    }
377
-
378
-
379
-    /**
380
-     * changes the maintenance level, provided there are still no migration scripts that should run
381
-     */
382
-    public function _change_maintenance_level()
383
-    {
384
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
385
-        if (! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
386
-            EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
387
-            $success = true;
388
-        } else {
389
-            EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
390
-            $success = false;
391
-        }
392
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
393
-    }
394
-
395
-
396
-    /**
397
-     * a tab with options for resetting and/or deleting EE data
398
-     *
399
-     * @throws \EE_Error
400
-     * @throws \DomainException
401
-     */
402
-    public function _data_reset_and_delete()
403
-    {
404
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
405
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406
-            'reset_reservations',
407
-            'reset_reservations',
408
-            array(),
409
-            'button button-primary ee-confirm',
410
-            '',
411
-            false
412
-        );
413
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
414
-            'reset_capabilities',
415
-            'reset_capabilities',
416
-            array(),
417
-            'button button-primary ee-confirm',
418
-            '',
419
-            false
420
-        );
421
-        $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
422
-            array('action' => 'delete_db'),
423
-            EE_MAINTENANCE_ADMIN_URL
424
-        );
425
-        $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
426
-            array('action' => 'reset_db'),
427
-            EE_MAINTENANCE_ADMIN_URL
428
-        );
429
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
430
-            $this->_template_path,
431
-            $this->_template_args,
432
-            true
433
-        );
434
-        $this->display_admin_page_with_sidebar();
435
-    }
436
-
437
-
438
-    protected function _reset_reservations()
439
-    {
440
-        if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
441
-            EE_Error::add_success(
442
-                __(
443
-                    'Ticket and datetime reserved counts have been successfully reset.',
444
-                    'event_espresso'
445
-                )
446
-            );
447
-        } else {
448
-            EE_Error::add_success(
449
-                __(
450
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
451
-                    'event_espresso'
452
-                )
453
-            );
454
-        }
455
-        $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
456
-    }
457
-
458
-
459
-    protected function _reset_capabilities()
460
-    {
461
-        EE_Registry::instance()->CAP->init_caps(true);
462
-        EE_Error::add_success(
463
-            __(
464
-                'Default Event Espresso capabilities have been restored for all current roles.',
465
-                'event_espresso'
466
-            )
467
-        );
468
-        $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
469
-    }
470
-
471
-
472
-    /**
473
-     * resets the DMSs so we can attempt to continue migrating after a fatal error
474
-     * (only a good idea when someone has somehow tried ot fix whatever caused
475
-     * the fatal error in teh first place)
476
-     */
477
-    protected function _reattempt_migration()
478
-    {
479
-        EE_Data_Migration_Manager::instance()->reattempt();
480
-        $this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
481
-    }
482
-
483
-
484
-    /**
485
-     * shows the big ol' System Information page
486
-     */
487
-    public function _system_status()
488
-    {
489
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
490
-        $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492
-            array(
493
-                'action' => 'download_system_status',
494
-            ),
495
-            EE_MAINTENANCE_ADMIN_URL
496
-        );
497
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
498
-            $this->_template_path,
499
-            $this->_template_args,
500
-            true
501
-        );
502
-        $this->display_admin_page_with_sidebar();
503
-    }
504
-
505
-    /**
506
-     * Downloads an HTML file of the system status that can be easily stored or emailed
507
-     */
508
-    public function _download_system_status()
509
-    {
510
-        $status_info = EEM_System_Status::instance()->get_system_stati();
511
-        header('Content-Disposition: attachment');
512
-        header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
513
-        echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
514
-        echo "<h1>System Information for " . site_url() . "</h1>";
515
-        echo EEH_Template::layout_array_as_table($status_info);
516
-        die;
517
-    }
518
-
519
-
520
-    public function _send_migration_crash_report()
521
-    {
522
-        $from = $this->_req_data['from'];
523
-        $from_name = $this->_req_data['from_name'];
524
-        $body = $this->_req_data['body'];
525
-        try {
526
-            $success = wp_mail(
527
-                EE_SUPPORT_EMAIL,
528
-                'Migration Crash Report',
529
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
530
-                array(
531
-                    "from:$from_name<$from>",
532
-                )
533
-            );
534
-        } catch (Exception $e) {
535
-            $success = false;
536
-        }
537
-        $this->_redirect_after_action(
538
-            $success,
539
-            esc_html__("Migration Crash Report", "event_espresso"),
540
-            esc_html__("sent", "event_espresso"),
541
-            array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')
542
-        );
543
-    }
544
-
545
-
546
-    public function _confirm_migration_crash_report_sent()
547
-    {
548
-        try {
549
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
550
-        } catch (EE_Error $e) {
551
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
552
-            // now, just so we can display the page correctly, make a error migration script stage object
553
-            // and also put the error on it. It only persists for the duration of this request
554
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
555
-            $most_recent_migration->add_error($e->getMessage());
556
-        }
557
-        $success = $this->_req_data['success'] == '1' ? true : false;
558
-        $this->_template_args['success'] = $success;
559
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
560
-        $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(
561
-            array('action' => 'reset_db'),
562
-            EE_MAINTENANCE_ADMIN_URL
563
-        );
564
-        $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(
565
-            array('action' => 'data_reset'),
566
-            EE_MAINTENANCE_ADMIN_URL
567
-        );
568
-        $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(
569
-            array('action' => 'reattempt_migration'),
570
-            EE_MAINTENANCE_ADMIN_URL
571
-        );
572
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
573
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
574
-            $this->_template_path,
575
-            $this->_template_args,
576
-            true
577
-        );
578
-        $this->display_admin_page_with_sidebar();
579
-    }
580
-
581
-
582
-    /**
583
-     * Resets the entire EE4 database.
584
-     * Currently basically only sets up ee4 database for a fresh install- doesn't
585
-     * actually clean out the old wp options, or cpts (although does erase old ee table data)
586
-     *
587
-     * @param boolean $nuke_old_ee4_data controls whether or not we
588
-     *                                   destroy the old ee4 data, or just try initializing ee4 default data
589
-     */
590
-    public function _reset_db($nuke_old_ee4_data = true)
591
-    {
592
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
593
-        if ($nuke_old_ee4_data) {
594
-            EEH_Activation::delete_all_espresso_cpt_data();
595
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
596
-            EEH_Activation::remove_cron_tasks();
597
-        }
598
-        // make sure when we reset the registry's config that it
599
-        // switches to using the new singleton
600
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
601
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
602
-        EE_System::instance()->redirect_to_about_ee();
603
-    }
604
-
605
-
606
-    /**
607
-     * Deletes ALL EE tables, Records, and Options from the database.
608
-     */
609
-    public function _delete_db()
610
-    {
611
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
612
-        EEH_Activation::delete_all_espresso_cpt_data();
613
-        EEH_Activation::delete_all_espresso_tables_and_data();
614
-        EEH_Activation::remove_cron_tasks();
615
-        EEH_Activation::deactivate_event_espresso();
616
-        wp_safe_redirect(admin_url('plugins.php'));
617
-        exit;
618
-    }
619
-
620
-
621
-    /**
622
-     * sets up EE4 to rerun the migrations from ee3 to ee4
623
-     */
624
-    public function _rerun_migration_from_ee3()
625
-    {
626
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
627
-        EEH_Activation::delete_all_espresso_cpt_data();
628
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
629
-        // set the db state to something that will require migrations
630
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
631
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
632
-        $this->_redirect_after_action(
633
-            true,
634
-            esc_html__("Database", 'event_espresso'),
635
-            esc_html__("reset", 'event_espresso')
636
-        );
637
-    }
638
-
639
-
640
-    // none of the below group are currently used for Gateway Settings
641
-    protected function _add_screen_options()
642
-    {
643
-    }
644
-
645
-
646
-    protected function _add_feature_pointers()
647
-    {
648
-    }
649
-
650
-
651
-    public function admin_init()
652
-    {
653
-    }
654
-
655
-
656
-    public function admin_notices()
657
-    {
658
-    }
659
-
660
-
661
-    public function admin_footer_scripts()
662
-    {
663
-    }
664
-
665
-
666
-    public function load_scripts_styles()
667
-    {
668
-        wp_enqueue_script('ee_admin_js');
669
-        wp_enqueue_script(
670
-            'ee-maintenance',
671
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
672
-            array('jquery'),
673
-            EVENT_ESPRESSO_VERSION,
674
-            true
675
-        );
676
-        wp_register_style(
677
-            'espresso_maintenance',
678
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
679
-            array(),
680
-            EVENT_ESPRESSO_VERSION
681
-        );
682
-        wp_enqueue_style('espresso_maintenance');
683
-        // localize script stuff
684
-        wp_localize_script(
685
-            'ee-maintenance',
686
-            'ee_maintenance',
687
-            array(
688
-                'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
689
-                'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
690
-                'fatal_error'                      => wp_strip_all_tags(__("A Fatal Error Has Occurred", "event_espresso")),
691
-                'click_next_when_ready'            => wp_strip_all_tags(
692
-                    __(
693
-                        "The current Database Update has ended. Click 'next' when ready to proceed",
694
-                        "event_espresso"
695
-                    )
696
-                ),
697
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
698
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
699
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
700
-                'confirm'                          => wp_strip_all_tags(
701
-                    __(
702
-                        'Are you sure you want to do this? It CANNOT be undone!',
703
-                        'event_espresso'
704
-                    )
705
-                ),
706
-                'confirm_skip_migration'           => wp_strip_all_tags(
707
-                    __(
708
-                        'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
709
-                        'event_espresso'
710
-                    )
711
-                ),
712
-            )
713
-        );
714
-    }
715
-
716
-
717
-    public function load_scripts_styles_default()
718
-    {
719
-    }
720
-
721
-
722
-    /**
723
-     * Enqueue scripts and styles for the datetime tools page.
724
-     */
725
-    public function load_scripts_styles_datetime_tools()
726
-    {
727
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
728
-    }
729
-
730
-
731
-    protected function _datetime_tools()
732
-    {
733
-        $form_action = EE_Admin_Page::add_query_args_and_nonce(
734
-            array(
735
-                'action'        => 'run_datetime_offset_fix',
736
-                'return_action' => $this->_req_action,
737
-            ),
738
-            EE_MAINTENANCE_ADMIN_URL
739
-        );
740
-        $form = $this->_get_datetime_offset_fix_form();
741
-        $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
742
-        $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
743
-                                                      . $form->get_html_and_js()
744
-                                                      . $form->form_close();
745
-        $this->display_admin_page_with_no_sidebar();
746
-    }
747
-
748
-
749
-    protected function _get_datetime_offset_fix_form()
750
-    {
751
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
752
-            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
753
-                array(
754
-                    'name'            => 'datetime_offset_fix_option',
755
-                    'layout_strategy' => new EE_Admin_Two_Column_Layout(),
756
-                    'subsections'     => array(
757
-                        'title'                  => new EE_Form_Section_HTML(
758
-                            EEH_HTML::h2(
759
-                                esc_html__('Datetime Offset Tool', 'event_espresso')
760
-                            )
761
-                        ),
762
-                        'explanation'            => new EE_Form_Section_HTML(
763
-                            EEH_HTML::p(
764
-                                esc_html__(
765
-                                    'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
766
-                                    'event_espresso'
767
-                                )
768
-                            )
769
-                            . EEH_HTML::p(
770
-                                esc_html__(
771
-                                    'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
772
-                                    'event_espresso'
773
-                                )
774
-                            )
775
-                        ),
776
-                        'offset_input'           => new EE_Float_Input(
777
-                            array(
778
-                                'html_name'       => 'offset_for_datetimes',
779
-                                'html_label_text' => esc_html__(
780
-                                    'Offset to apply (in hours):',
781
-                                    'event_espresso'
782
-                                ),
783
-                                'min_value'       => '-12',
784
-                                'max_value'       => '14',
785
-                                'step_value'      => '.25',
786
-                                'default'         => DatetimeOffsetFix::getOffset(),
787
-                            )
788
-                        ),
789
-                        'date_range_explanation' => new EE_Form_Section_HTML(
790
-                            EEH_HTML::p(
791
-                                esc_html__(
792
-                                    'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
793
-                                    'event_espresso'
794
-                                )
795
-                            )
796
-                            . EEH_HTML::p(
797
-                                EEH_HTML::strong(
798
-                                    sprintf(
799
-                                        esc_html__(
800
-                                            'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
801
-                                            'event_espresso'
802
-                                        ),
803
-                                        '<a href="https://www.timeanddate.com/worldclock/converter.html">',
804
-                                        '</a>'
805
-                                    )
806
-                                )
807
-                            )
808
-                        ),
809
-                        'date_range_start_date'  => new EE_Datepicker_Input(
810
-                            array(
811
-                                'html_name'       => 'offset_date_start_range',
812
-                                'html_label_text' => esc_html__(
813
-                                    'Start Date for dates the offset applied to:',
814
-                                    'event_espresso'
815
-                                ),
816
-                            )
817
-                        ),
818
-                        'date_range_end_date'    => new EE_Datepicker_Input(
819
-                            array(
820
-                                'html_name'       => 'offset_date_end_range',
821
-                                'html_label_text' => esc_html__(
822
-                                    'End Date for dates the offset is applied to:',
823
-                                    'event_espresso'
824
-                                ),
825
-                            )
826
-                        ),
827
-                        'submit'                 => new EE_Submit_Input(
828
-                            array(
829
-                                'html_label_text' => '',
830
-                                'default'         => esc_html__('Apply Offset', 'event_espresso'),
831
-                            )
832
-                        ),
833
-                    ),
834
-                )
835
-            );
836
-        }
837
-        return $this->datetime_fix_offset_form;
838
-    }
839
-
840
-
841
-    /**
842
-     * Callback for the run_datetime_offset_fix route.
843
-     *
844
-     * @throws EE_Error
845
-     */
846
-    protected function _apply_datetime_offset()
847
-    {
848
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
849
-            $form = $this->_get_datetime_offset_fix_form();
850
-            $form->receive_form_submission($this->_req_data);
851
-            if ($form->is_valid()) {
852
-                // save offset data so batch processor can get it.
853
-                DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
854
-                $utc_timezone = new DateTimeZone('UTC');
855
-                $date_range_start_date = DateTime::createFromFormat(
856
-                    'm/d/Y H:i:s',
857
-                    $form->get_input_value('date_range_start_date') . ' 00:00:00',
858
-                    $utc_timezone
859
-                );
860
-                $date_range_end_date = DateTime::createFromFormat(
861
-                    'm/d/Y H:i:s',
862
-                    $form->get_input_value('date_range_end_date') . ' 23:59:59',
863
-                    $utc_timezone
864
-                );
865
-                if ($date_range_start_date instanceof DateTime) {
866
-                    DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
867
-                }
868
-                if ($date_range_end_date instanceof DateTime) {
869
-                    DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
870
-                }
871
-                // redirect to batch tool
872
-                wp_redirect(
873
-                    EE_Admin_Page::add_query_args_and_nonce(
874
-                        array(
875
-                            'page'        => 'espresso_batch',
876
-                            'batch'       => 'job',
877
-                            'label'       => esc_html__('Applying Offset', 'event_espresso'),
878
-                            'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
879
-                            'return_url'  => urlencode(
880
-                                add_query_arg(
881
-                                    array(
882
-                                        'action' => 'datetime_tools',
883
-                                    ),
884
-                                    EEH_URL::current_url_without_query_paramaters(
885
-                                        array(
886
-                                            'return_action',
887
-                                            'run_datetime_offset_fix_nonce',
888
-                                            'return',
889
-                                            'datetime_tools_nonce',
890
-                                        )
891
-                                    )
892
-                                )
893
-                            ),
894
-                        ),
895
-                        admin_url()
896
-                    )
897
-                );
898
-                exit;
899
-            }
900
-        }
901
-    }
20
+	/**
21
+	 * @var EE_Form_Section_Proper
22
+	 */
23
+	protected $datetime_fix_offset_form;
24
+
25
+
26
+	protected function _init_page_props()
27
+	{
28
+		$this->page_slug = EE_MAINTENANCE_PG_SLUG;
29
+		$this->page_label = EE_MAINTENANCE_LABEL;
30
+		$this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
31
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
32
+	}
33
+
34
+
35
+	protected function _ajax_hooks()
36
+	{
37
+		add_action('wp_ajax_migration_step', array($this, 'migration_step'));
38
+		add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
39
+	}
40
+
41
+
42
+	protected function _define_page_props()
43
+	{
44
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
45
+		$this->_labels = array(
46
+			'buttons' => array(
47
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
48
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
49
+			),
50
+		);
51
+	}
52
+
53
+
54
+	protected function _set_page_routes()
55
+	{
56
+		$this->_page_routes = array(
57
+			'default'                             => array(
58
+				'func'       => '_maintenance',
59
+				'capability' => 'manage_options',
60
+			),
61
+			'change_maintenance_level'            => array(
62
+				'func'       => '_change_maintenance_level',
63
+				'capability' => 'manage_options',
64
+				'noheader'   => true,
65
+			),
66
+			'system_status'                       => array(
67
+				'func'       => '_system_status',
68
+				'capability' => 'manage_options',
69
+			),
70
+			'download_system_status'              => array(
71
+				'func'       => '_download_system_status',
72
+				'capability' => 'manage_options',
73
+				'noheader'   => true,
74
+			),
75
+			'send_migration_crash_report'         => array(
76
+				'func'       => '_send_migration_crash_report',
77
+				'capability' => 'manage_options',
78
+				'noheader'   => true,
79
+			),
80
+			'confirm_migration_crash_report_sent' => array(
81
+				'func'       => '_confirm_migration_crash_report_sent',
82
+				'capability' => 'manage_options',
83
+			),
84
+			'data_reset'                          => array(
85
+				'func'       => '_data_reset_and_delete',
86
+				'capability' => 'manage_options',
87
+			),
88
+			'reset_db'                            => array(
89
+				'func'       => '_reset_db',
90
+				'capability' => 'manage_options',
91
+				'noheader'   => true,
92
+				'args'       => array('nuke_old_ee4_data' => true),
93
+			),
94
+			'start_with_fresh_ee4_db'             => array(
95
+				'func'       => '_reset_db',
96
+				'capability' => 'manage_options',
97
+				'noheader'   => true,
98
+				'args'       => array('nuke_old_ee4_data' => false),
99
+			),
100
+			'delete_db'                           => array(
101
+				'func'       => '_delete_db',
102
+				'capability' => 'manage_options',
103
+				'noheader'   => true,
104
+			),
105
+			'rerun_migration_from_ee3'            => array(
106
+				'func'       => '_rerun_migration_from_ee3',
107
+				'capability' => 'manage_options',
108
+				'noheader'   => true,
109
+			),
110
+			'reset_reservations'                  => array(
111
+				'func'       => '_reset_reservations',
112
+				'capability' => 'manage_options',
113
+				'noheader'   => true,
114
+			),
115
+			'reset_capabilities'                  => array(
116
+				'func'       => '_reset_capabilities',
117
+				'capability' => 'manage_options',
118
+				'noheader'   => true,
119
+			),
120
+			'reattempt_migration'                 => array(
121
+				'func'       => '_reattempt_migration',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			),
125
+			'datetime_tools'                      => array(
126
+				'func'       => '_datetime_tools',
127
+				'capability' => 'manage_options',
128
+			),
129
+			'run_datetime_offset_fix'             => array(
130
+				'func'               => '_apply_datetime_offset',
131
+				'noheader'           => true,
132
+				'headers_sent_route' => 'datetime_tools',
133
+				'capability'         => 'manage_options',
134
+			),
135
+		);
136
+	}
137
+
138
+
139
+	protected function _set_page_config()
140
+	{
141
+		$this->_page_config = array(
142
+			'default'        => array(
143
+				'nav'           => array(
144
+					'label' => esc_html__('Maintenance', 'event_espresso'),
145
+					'order' => 10,
146
+				),
147
+				'require_nonce' => false,
148
+			),
149
+			'data_reset'     => array(
150
+				'nav'           => array(
151
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
152
+					'order' => 20,
153
+				),
154
+				'require_nonce' => false,
155
+			),
156
+			'datetime_tools' => array(
157
+				'nav'           => array(
158
+					'label' => esc_html__('Datetime Utilities', 'event_espresso'),
159
+					'order' => 25,
160
+				),
161
+				'require_nonce' => false,
162
+			),
163
+			'system_status'  => array(
164
+				'nav'           => array(
165
+					'label' => esc_html__("System Information", "event_espresso"),
166
+					'order' => 30,
167
+				),
168
+				'require_nonce' => false,
169
+			),
170
+		);
171
+	}
172
+
173
+
174
+	/**
175
+	 * default maintenance page. If we're in maintenance mode level 2, then we need to show
176
+	 * the migration scripts and all that UI.
177
+	 */
178
+	public function _maintenance()
179
+	{
180
+		// it all depends if we're in maintenance model level 1 (frontend-only) or
181
+		// level 2 (everything except maintenance page)
182
+		try {
183
+			// get the current maintenance level and check if
184
+			// we are removed
185
+			$mm = EE_Maintenance_Mode::instance()->level();
186
+			$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
187
+			if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
188
+				// we just took the site out of maintenance mode, so notify the user.
189
+				// unfortunately this message appears to be echoed on the NEXT page load...
190
+				// oh well, we should really be checking for this on addon deactivation anyways
191
+				EE_Error::add_attention(
192
+					__(
193
+						'Site taken out of maintenance mode because no data migration scripts are required',
194
+						'event_espresso'
195
+					)
196
+				);
197
+				$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
198
+			}
199
+			// in case an exception is thrown while trying to handle migrations
200
+			switch (EE_Maintenance_Mode::instance()->level()) {
201
+				case EE_Maintenance_Mode::level_0_not_in_maintenance:
202
+				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
203
+					$show_maintenance_switch = true;
204
+					$show_backup_db_text = false;
205
+					$show_migration_progress = false;
206
+					$script_names = array();
207
+					$addons_should_be_upgraded_first = false;
208
+					break;
209
+				case EE_Maintenance_Mode::level_2_complete_maintenance:
210
+					$show_maintenance_switch = false;
211
+					$show_migration_progress = true;
212
+					if (isset($this->_req_data['continue_migration'])) {
213
+						$show_backup_db_text = false;
214
+					} else {
215
+						$show_backup_db_text = true;
216
+					}
217
+					$scripts_needing_to_run = EE_Data_Migration_Manager::instance()
218
+																	   ->check_for_applicable_data_migration_scripts();
219
+					$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
220
+					$script_names = array();
221
+					$current_script = null;
222
+					foreach ($scripts_needing_to_run as $script) {
223
+						if ($script instanceof EE_Data_Migration_Script_Base) {
224
+							if (! $current_script) {
225
+								$current_script = $script;
226
+								$current_script->migration_page_hooks();
227
+							}
228
+							$script_names[] = $script->pretty_name();
229
+						}
230
+					}
231
+					break;
232
+			}
233
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
234
+			$exception_thrown = false;
235
+		} catch (EE_Error $e) {
236
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
237
+			// now, just so we can display the page correctly, make a error migration script stage object
238
+			// and also put the error on it. It only persists for the duration of this request
239
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
240
+			$most_recent_migration->add_error($e->getMessage());
241
+			$exception_thrown = true;
242
+		}
243
+		$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
244
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
245
+		if ($exception_thrown
246
+			|| ($most_recent_migration
247
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
248
+				&& $most_recent_migration->is_broken()
249
+			)
250
+		) {
251
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
252
+			$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
253
+			$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(
254
+				array(
255
+					'action'  => 'confirm_migration_crash_report_sent',
256
+					'success' => '0',
257
+				),
258
+				EE_MAINTENANCE_ADMIN_URL
259
+			);
260
+		} elseif ($addons_should_be_upgraded_first) {
261
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
262
+		} else {
263
+			if ($most_recent_migration
264
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
265
+				&& $most_recent_migration->can_continue()
266
+			) {
267
+				$show_backup_db_text = false;
268
+				$show_continue_current_migration_script = true;
269
+				$show_most_recent_migration = true;
270
+			} elseif (isset($this->_req_data['continue_migration'])) {
271
+				$show_most_recent_migration = true;
272
+				$show_continue_current_migration_script = false;
273
+			} else {
274
+				$show_most_recent_migration = false;
275
+				$show_continue_current_migration_script = false;
276
+			}
277
+			if (isset($current_script)) {
278
+				$migrates_to = $current_script->migrates_to_version();
279
+				$plugin_slug = $migrates_to['slug'];
280
+				$new_version = $migrates_to['version'];
281
+				$this->_template_args = array_merge(
282
+					$this->_template_args,
283
+					array(
284
+						'current_db_state' => sprintf(
285
+							__("EE%s (%s)", "event_espresso"),
286
+							isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
287
+							$plugin_slug
288
+						),
289
+						'next_db_state'    => isset($current_script) ? sprintf(
290
+							__("EE%s (%s)", 'event_espresso'),
291
+							$new_version,
292
+							$plugin_slug
293
+						) : null,
294
+					)
295
+				);
296
+			} else {
297
+				$this->_template_args['current_db_state'] = null;
298
+				$this->_template_args['next_db_state'] = null;
299
+			}
300
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
+			$this->_template_args = array_merge(
302
+				$this->_template_args,
303
+				array(
304
+					'show_most_recent_migration'             => $show_most_recent_migration,
305
+					// flag for showing the most recent migration's status and/or errors
306
+					'show_migration_progress'                => $show_migration_progress,
307
+					// flag for showing the option to run migrations and see their progress
308
+					'show_backup_db_text'                    => $show_backup_db_text,
309
+					// flag for showing text telling the user to backup their DB
310
+					'show_maintenance_switch'                => $show_maintenance_switch,
311
+					// flag for showing the option to change maintenance mode between levels 0 and 1
312
+					'script_names'                           => $script_names,
313
+					// array of names of scripts that have run
314
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
+					// flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
317
+						array('action' => 'reset_db'),
318
+						EE_MAINTENANCE_ADMIN_URL
319
+					),
320
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
321
+						array('action' => 'data_reset'),
322
+						EE_MAINTENANCE_ADMIN_URL
323
+					),
324
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
325
+						array('action' => 'change_maintenance_level'),
326
+						EE_MAINTENANCE_ADMIN_URL
327
+					),
328
+					'ultimate_db_state'                      => sprintf(
329
+						__("EE%s", 'event_espresso'),
330
+						espresso_version()
331
+					),
332
+				)
333
+			);
334
+			// make sure we have the form fields helper available. It usually is, but sometimes it isn't
335
+		}
336
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;// the actual most recently ran migration
337
+		// now render the migration options part, and put it in a variable
338
+		$migration_options_template_file = apply_filters(
339
+			'FHEE__ee_migration_page__migration_options_template',
340
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
341
+		);
342
+		$migration_options_html = EEH_Template::display_template(
343
+			$migration_options_template_file,
344
+			$this->_template_args,
345
+			true
346
+		);
347
+		$this->_template_args['migration_options_html'] = $migration_options_html;
348
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
349
+			$this->_template_path,
350
+			$this->_template_args,
351
+			true
352
+		);
353
+		$this->display_admin_page_with_sidebar();
354
+	}
355
+
356
+
357
+	/**
358
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
359
+	 */
360
+	public function migration_step()
361
+	{
362
+		$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
363
+		$this->_return_json();
364
+	}
365
+
366
+
367
+	/**
368
+	 * Can be used by js when it notices a response with HTML in it in order
369
+	 * to log the malformed response
370
+	 */
371
+	public function add_error_to_migrations_ran()
372
+	{
373
+		EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
374
+		$this->_template_args['data'] = array('ok' => true);
375
+		$this->_return_json();
376
+	}
377
+
378
+
379
+	/**
380
+	 * changes the maintenance level, provided there are still no migration scripts that should run
381
+	 */
382
+	public function _change_maintenance_level()
383
+	{
384
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
385
+		if (! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
386
+			EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
387
+			$success = true;
388
+		} else {
389
+			EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
390
+			$success = false;
391
+		}
392
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
393
+	}
394
+
395
+
396
+	/**
397
+	 * a tab with options for resetting and/or deleting EE data
398
+	 *
399
+	 * @throws \EE_Error
400
+	 * @throws \DomainException
401
+	 */
402
+	public function _data_reset_and_delete()
403
+	{
404
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
405
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406
+			'reset_reservations',
407
+			'reset_reservations',
408
+			array(),
409
+			'button button-primary ee-confirm',
410
+			'',
411
+			false
412
+		);
413
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
414
+			'reset_capabilities',
415
+			'reset_capabilities',
416
+			array(),
417
+			'button button-primary ee-confirm',
418
+			'',
419
+			false
420
+		);
421
+		$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
422
+			array('action' => 'delete_db'),
423
+			EE_MAINTENANCE_ADMIN_URL
424
+		);
425
+		$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
426
+			array('action' => 'reset_db'),
427
+			EE_MAINTENANCE_ADMIN_URL
428
+		);
429
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
430
+			$this->_template_path,
431
+			$this->_template_args,
432
+			true
433
+		);
434
+		$this->display_admin_page_with_sidebar();
435
+	}
436
+
437
+
438
+	protected function _reset_reservations()
439
+	{
440
+		if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
441
+			EE_Error::add_success(
442
+				__(
443
+					'Ticket and datetime reserved counts have been successfully reset.',
444
+					'event_espresso'
445
+				)
446
+			);
447
+		} else {
448
+			EE_Error::add_success(
449
+				__(
450
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
451
+					'event_espresso'
452
+				)
453
+			);
454
+		}
455
+		$this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
456
+	}
457
+
458
+
459
+	protected function _reset_capabilities()
460
+	{
461
+		EE_Registry::instance()->CAP->init_caps(true);
462
+		EE_Error::add_success(
463
+			__(
464
+				'Default Event Espresso capabilities have been restored for all current roles.',
465
+				'event_espresso'
466
+			)
467
+		);
468
+		$this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
469
+	}
470
+
471
+
472
+	/**
473
+	 * resets the DMSs so we can attempt to continue migrating after a fatal error
474
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
475
+	 * the fatal error in teh first place)
476
+	 */
477
+	protected function _reattempt_migration()
478
+	{
479
+		EE_Data_Migration_Manager::instance()->reattempt();
480
+		$this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
481
+	}
482
+
483
+
484
+	/**
485
+	 * shows the big ol' System Information page
486
+	 */
487
+	public function _system_status()
488
+	{
489
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
490
+		$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492
+			array(
493
+				'action' => 'download_system_status',
494
+			),
495
+			EE_MAINTENANCE_ADMIN_URL
496
+		);
497
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
498
+			$this->_template_path,
499
+			$this->_template_args,
500
+			true
501
+		);
502
+		$this->display_admin_page_with_sidebar();
503
+	}
504
+
505
+	/**
506
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
507
+	 */
508
+	public function _download_system_status()
509
+	{
510
+		$status_info = EEM_System_Status::instance()->get_system_stati();
511
+		header('Content-Disposition: attachment');
512
+		header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
513
+		echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
514
+		echo "<h1>System Information for " . site_url() . "</h1>";
515
+		echo EEH_Template::layout_array_as_table($status_info);
516
+		die;
517
+	}
518
+
519
+
520
+	public function _send_migration_crash_report()
521
+	{
522
+		$from = $this->_req_data['from'];
523
+		$from_name = $this->_req_data['from_name'];
524
+		$body = $this->_req_data['body'];
525
+		try {
526
+			$success = wp_mail(
527
+				EE_SUPPORT_EMAIL,
528
+				'Migration Crash Report',
529
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
530
+				array(
531
+					"from:$from_name<$from>",
532
+				)
533
+			);
534
+		} catch (Exception $e) {
535
+			$success = false;
536
+		}
537
+		$this->_redirect_after_action(
538
+			$success,
539
+			esc_html__("Migration Crash Report", "event_espresso"),
540
+			esc_html__("sent", "event_espresso"),
541
+			array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')
542
+		);
543
+	}
544
+
545
+
546
+	public function _confirm_migration_crash_report_sent()
547
+	{
548
+		try {
549
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
550
+		} catch (EE_Error $e) {
551
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
552
+			// now, just so we can display the page correctly, make a error migration script stage object
553
+			// and also put the error on it. It only persists for the duration of this request
554
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
555
+			$most_recent_migration->add_error($e->getMessage());
556
+		}
557
+		$success = $this->_req_data['success'] == '1' ? true : false;
558
+		$this->_template_args['success'] = $success;
559
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
560
+		$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(
561
+			array('action' => 'reset_db'),
562
+			EE_MAINTENANCE_ADMIN_URL
563
+		);
564
+		$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(
565
+			array('action' => 'data_reset'),
566
+			EE_MAINTENANCE_ADMIN_URL
567
+		);
568
+		$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(
569
+			array('action' => 'reattempt_migration'),
570
+			EE_MAINTENANCE_ADMIN_URL
571
+		);
572
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
573
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
574
+			$this->_template_path,
575
+			$this->_template_args,
576
+			true
577
+		);
578
+		$this->display_admin_page_with_sidebar();
579
+	}
580
+
581
+
582
+	/**
583
+	 * Resets the entire EE4 database.
584
+	 * Currently basically only sets up ee4 database for a fresh install- doesn't
585
+	 * actually clean out the old wp options, or cpts (although does erase old ee table data)
586
+	 *
587
+	 * @param boolean $nuke_old_ee4_data controls whether or not we
588
+	 *                                   destroy the old ee4 data, or just try initializing ee4 default data
589
+	 */
590
+	public function _reset_db($nuke_old_ee4_data = true)
591
+	{
592
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
593
+		if ($nuke_old_ee4_data) {
594
+			EEH_Activation::delete_all_espresso_cpt_data();
595
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
596
+			EEH_Activation::remove_cron_tasks();
597
+		}
598
+		// make sure when we reset the registry's config that it
599
+		// switches to using the new singleton
600
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
601
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
602
+		EE_System::instance()->redirect_to_about_ee();
603
+	}
604
+
605
+
606
+	/**
607
+	 * Deletes ALL EE tables, Records, and Options from the database.
608
+	 */
609
+	public function _delete_db()
610
+	{
611
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
612
+		EEH_Activation::delete_all_espresso_cpt_data();
613
+		EEH_Activation::delete_all_espresso_tables_and_data();
614
+		EEH_Activation::remove_cron_tasks();
615
+		EEH_Activation::deactivate_event_espresso();
616
+		wp_safe_redirect(admin_url('plugins.php'));
617
+		exit;
618
+	}
619
+
620
+
621
+	/**
622
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
623
+	 */
624
+	public function _rerun_migration_from_ee3()
625
+	{
626
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
627
+		EEH_Activation::delete_all_espresso_cpt_data();
628
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
629
+		// set the db state to something that will require migrations
630
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
631
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
632
+		$this->_redirect_after_action(
633
+			true,
634
+			esc_html__("Database", 'event_espresso'),
635
+			esc_html__("reset", 'event_espresso')
636
+		);
637
+	}
638
+
639
+
640
+	// none of the below group are currently used for Gateway Settings
641
+	protected function _add_screen_options()
642
+	{
643
+	}
644
+
645
+
646
+	protected function _add_feature_pointers()
647
+	{
648
+	}
649
+
650
+
651
+	public function admin_init()
652
+	{
653
+	}
654
+
655
+
656
+	public function admin_notices()
657
+	{
658
+	}
659
+
660
+
661
+	public function admin_footer_scripts()
662
+	{
663
+	}
664
+
665
+
666
+	public function load_scripts_styles()
667
+	{
668
+		wp_enqueue_script('ee_admin_js');
669
+		wp_enqueue_script(
670
+			'ee-maintenance',
671
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
672
+			array('jquery'),
673
+			EVENT_ESPRESSO_VERSION,
674
+			true
675
+		);
676
+		wp_register_style(
677
+			'espresso_maintenance',
678
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
679
+			array(),
680
+			EVENT_ESPRESSO_VERSION
681
+		);
682
+		wp_enqueue_style('espresso_maintenance');
683
+		// localize script stuff
684
+		wp_localize_script(
685
+			'ee-maintenance',
686
+			'ee_maintenance',
687
+			array(
688
+				'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
689
+				'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
690
+				'fatal_error'                      => wp_strip_all_tags(__("A Fatal Error Has Occurred", "event_espresso")),
691
+				'click_next_when_ready'            => wp_strip_all_tags(
692
+					__(
693
+						"The current Database Update has ended. Click 'next' when ready to proceed",
694
+						"event_espresso"
695
+					)
696
+				),
697
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
698
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
699
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
700
+				'confirm'                          => wp_strip_all_tags(
701
+					__(
702
+						'Are you sure you want to do this? It CANNOT be undone!',
703
+						'event_espresso'
704
+					)
705
+				),
706
+				'confirm_skip_migration'           => wp_strip_all_tags(
707
+					__(
708
+						'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
709
+						'event_espresso'
710
+					)
711
+				),
712
+			)
713
+		);
714
+	}
715
+
716
+
717
+	public function load_scripts_styles_default()
718
+	{
719
+	}
720
+
721
+
722
+	/**
723
+	 * Enqueue scripts and styles for the datetime tools page.
724
+	 */
725
+	public function load_scripts_styles_datetime_tools()
726
+	{
727
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
728
+	}
729
+
730
+
731
+	protected function _datetime_tools()
732
+	{
733
+		$form_action = EE_Admin_Page::add_query_args_and_nonce(
734
+			array(
735
+				'action'        => 'run_datetime_offset_fix',
736
+				'return_action' => $this->_req_action,
737
+			),
738
+			EE_MAINTENANCE_ADMIN_URL
739
+		);
740
+		$form = $this->_get_datetime_offset_fix_form();
741
+		$this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
742
+		$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
743
+													  . $form->get_html_and_js()
744
+													  . $form->form_close();
745
+		$this->display_admin_page_with_no_sidebar();
746
+	}
747
+
748
+
749
+	protected function _get_datetime_offset_fix_form()
750
+	{
751
+		if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
752
+			$this->datetime_fix_offset_form = new EE_Form_Section_Proper(
753
+				array(
754
+					'name'            => 'datetime_offset_fix_option',
755
+					'layout_strategy' => new EE_Admin_Two_Column_Layout(),
756
+					'subsections'     => array(
757
+						'title'                  => new EE_Form_Section_HTML(
758
+							EEH_HTML::h2(
759
+								esc_html__('Datetime Offset Tool', 'event_espresso')
760
+							)
761
+						),
762
+						'explanation'            => new EE_Form_Section_HTML(
763
+							EEH_HTML::p(
764
+								esc_html__(
765
+									'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
766
+									'event_espresso'
767
+								)
768
+							)
769
+							. EEH_HTML::p(
770
+								esc_html__(
771
+									'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
772
+									'event_espresso'
773
+								)
774
+							)
775
+						),
776
+						'offset_input'           => new EE_Float_Input(
777
+							array(
778
+								'html_name'       => 'offset_for_datetimes',
779
+								'html_label_text' => esc_html__(
780
+									'Offset to apply (in hours):',
781
+									'event_espresso'
782
+								),
783
+								'min_value'       => '-12',
784
+								'max_value'       => '14',
785
+								'step_value'      => '.25',
786
+								'default'         => DatetimeOffsetFix::getOffset(),
787
+							)
788
+						),
789
+						'date_range_explanation' => new EE_Form_Section_HTML(
790
+							EEH_HTML::p(
791
+								esc_html__(
792
+									'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
793
+									'event_espresso'
794
+								)
795
+							)
796
+							. EEH_HTML::p(
797
+								EEH_HTML::strong(
798
+									sprintf(
799
+										esc_html__(
800
+											'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
801
+											'event_espresso'
802
+										),
803
+										'<a href="https://www.timeanddate.com/worldclock/converter.html">',
804
+										'</a>'
805
+									)
806
+								)
807
+							)
808
+						),
809
+						'date_range_start_date'  => new EE_Datepicker_Input(
810
+							array(
811
+								'html_name'       => 'offset_date_start_range',
812
+								'html_label_text' => esc_html__(
813
+									'Start Date for dates the offset applied to:',
814
+									'event_espresso'
815
+								),
816
+							)
817
+						),
818
+						'date_range_end_date'    => new EE_Datepicker_Input(
819
+							array(
820
+								'html_name'       => 'offset_date_end_range',
821
+								'html_label_text' => esc_html__(
822
+									'End Date for dates the offset is applied to:',
823
+									'event_espresso'
824
+								),
825
+							)
826
+						),
827
+						'submit'                 => new EE_Submit_Input(
828
+							array(
829
+								'html_label_text' => '',
830
+								'default'         => esc_html__('Apply Offset', 'event_espresso'),
831
+							)
832
+						),
833
+					),
834
+				)
835
+			);
836
+		}
837
+		return $this->datetime_fix_offset_form;
838
+	}
839
+
840
+
841
+	/**
842
+	 * Callback for the run_datetime_offset_fix route.
843
+	 *
844
+	 * @throws EE_Error
845
+	 */
846
+	protected function _apply_datetime_offset()
847
+	{
848
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
849
+			$form = $this->_get_datetime_offset_fix_form();
850
+			$form->receive_form_submission($this->_req_data);
851
+			if ($form->is_valid()) {
852
+				// save offset data so batch processor can get it.
853
+				DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
854
+				$utc_timezone = new DateTimeZone('UTC');
855
+				$date_range_start_date = DateTime::createFromFormat(
856
+					'm/d/Y H:i:s',
857
+					$form->get_input_value('date_range_start_date') . ' 00:00:00',
858
+					$utc_timezone
859
+				);
860
+				$date_range_end_date = DateTime::createFromFormat(
861
+					'm/d/Y H:i:s',
862
+					$form->get_input_value('date_range_end_date') . ' 23:59:59',
863
+					$utc_timezone
864
+				);
865
+				if ($date_range_start_date instanceof DateTime) {
866
+					DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
867
+				}
868
+				if ($date_range_end_date instanceof DateTime) {
869
+					DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
870
+				}
871
+				// redirect to batch tool
872
+				wp_redirect(
873
+					EE_Admin_Page::add_query_args_and_nonce(
874
+						array(
875
+							'page'        => 'espresso_batch',
876
+							'batch'       => 'job',
877
+							'label'       => esc_html__('Applying Offset', 'event_espresso'),
878
+							'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
879
+							'return_url'  => urlencode(
880
+								add_query_arg(
881
+									array(
882
+										'action' => 'datetime_tools',
883
+									),
884
+									EEH_URL::current_url_without_query_paramaters(
885
+										array(
886
+											'return_action',
887
+											'run_datetime_offset_fix_nonce',
888
+											'return',
889
+											'datetime_tools_nonce',
890
+										)
891
+									)
892
+								)
893
+							),
894
+						),
895
+						admin_url()
896
+					)
897
+				);
898
+				exit;
899
+			}
900
+		}
901
+	}
902 902
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/InvisibleRecaptcha.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -27,270 +27,270 @@
 block discarded – undo
27 27
 class InvisibleRecaptcha
28 28
 {
29 29
 
30
-    const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
30
+	const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
31 31
 
32
-    const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
32
+	const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
33 33
 
34
-    /**
35
-     * @var EE_Registration_Config $config
36
-     */
37
-    private $config;
34
+	/**
35
+	 * @var EE_Registration_Config $config
36
+	 */
37
+	private $config;
38 38
 
39
-    /**
40
-     * @var EE_Session $session
41
-     */
42
-    private $session;
39
+	/**
40
+	 * @var EE_Session $session
41
+	 */
42
+	private $session;
43 43
 
44
-    /**
45
-     * @var boolean $recaptcha_passed
46
-     */
47
-    private $recaptcha_passed;
44
+	/**
45
+	 * @var boolean $recaptcha_passed
46
+	 */
47
+	private $recaptcha_passed;
48 48
 
49 49
 
50
-    /**
51
-     * InvisibleRecaptcha constructor.
52
-     *
53
-     * @param EE_Registration_Config $registration_config
54
-     * @param EE_Session             $session
55
-     */
56
-    public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
-    {
58
-        $this->config = $registration_config;
59
-        $this->session = $session;
60
-    }
50
+	/**
51
+	 * InvisibleRecaptcha constructor.
52
+	 *
53
+	 * @param EE_Registration_Config $registration_config
54
+	 * @param EE_Session             $session
55
+	 */
56
+	public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
+	{
58
+		$this->config = $registration_config;
59
+		$this->session = $session;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return boolean
65
-     */
66
-    public function useInvisibleRecaptcha()
67
-    {
68
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
-    }
63
+	/**
64
+	 * @return boolean
65
+	 */
66
+	public function useInvisibleRecaptcha()
67
+	{
68
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * @param array $input_settings
74
-     * @return EE_Invisible_Recaptcha_Input
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws InvalidArgumentException
78
-     * @throws DomainException
79
-     */
80
-    public function getInput(array $input_settings = array())
81
-    {
82
-        return new EE_Invisible_Recaptcha_Input(
83
-            $input_settings,
84
-            $this->config
85
-        );
86
-    }
72
+	/**
73
+	 * @param array $input_settings
74
+	 * @return EE_Invisible_Recaptcha_Input
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws InvalidArgumentException
78
+	 * @throws DomainException
79
+	 */
80
+	public function getInput(array $input_settings = array())
81
+	{
82
+		return new EE_Invisible_Recaptcha_Input(
83
+			$input_settings,
84
+			$this->config
85
+		);
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * @param array $input_settings
91
-     * @return string
92
-     * @throws EE_Error
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws InvalidArgumentException
96
-     * @throws DomainException
97
-     */
98
-    public function getInputHtml(array $input_settings = array())
99
-    {
100
-        return $this->getInput($input_settings)->get_html_for_input();
101
-    }
89
+	/**
90
+	 * @param array $input_settings
91
+	 * @return string
92
+	 * @throws EE_Error
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws InvalidArgumentException
96
+	 * @throws DomainException
97
+	 */
98
+	public function getInputHtml(array $input_settings = array())
99
+	{
100
+		return $this->getInput($input_settings)->get_html_for_input();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @param EE_Form_Section_Proper $form
106
-     * @param array                  $input_settings
107
-     * @throws EE_Error
108
-     * @throws InvalidArgumentException
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     * @throws DomainException
112
-     */
113
-    public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
-    {
115
-        $form->add_subsections(
116
-            array(
117
-                'espresso_recaptcha' => $this->getInput($input_settings),
118
-            ),
119
-            null,
120
-            false
121
-        );
122
-    }
104
+	/**
105
+	 * @param EE_Form_Section_Proper $form
106
+	 * @param array                  $input_settings
107
+	 * @throws EE_Error
108
+	 * @throws InvalidArgumentException
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 * @throws DomainException
112
+	 */
113
+	public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
+	{
115
+		$form->add_subsections(
116
+			array(
117
+				'espresso_recaptcha' => $this->getInput($input_settings),
118
+			),
119
+			null,
120
+			false
121
+		);
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * @param RequestInterface $request
127
-     * @return boolean
128
-     * @throws InvalidArgumentException
129
-     * @throws InvalidDataTypeException
130
-     * @throws InvalidInterfaceException
131
-     * @throws RuntimeException
132
-     */
133
-    public function verifyToken(RequestInterface $request)
134
-    {
135
-        static $previous_recaptcha_response = array();
136
-        $grecaptcha_response = $request->getRequestParam('g-recaptcha-response');
137
-        // if this token has already been verified, then return previous response
138
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
139
-            return $previous_recaptcha_response[ $grecaptcha_response ];
140
-        }
141
-        // still here but no g-recaptcha-response ? - verification failed
142
-        if (! $grecaptcha_response) {
143
-            EE_Error::add_error(
144
-                sprintf(
145
-                    /* translators: 1: missing parameter */
146
-                    esc_html__(
147
-                        // @codingStandardsIgnoreStart
148
-                        'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.',
149
-                        // @codingStandardsIgnoreEnd
150
-                        'event_espresso'
151
-                    ),
152
-                    'g-recaptcha-response'
153
-                ),
154
-                __FILE__,
155
-                __FUNCTION__,
156
-                __LINE__
157
-            );
158
-            return false;
159
-        }
160
-        // will update to true if everything passes
161
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
162
-        $response                                            = wp_safe_remote_post(
163
-            InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
164
-            array(
165
-                'body' => array(
166
-                    'secret'   => $this->config->recaptcha_privatekey,
167
-                    'response' => $grecaptcha_response,
168
-                    'remoteip' => $request->ipAddress(),
169
-                ),
170
-            )
171
-        );
172
-        if ($response instanceof WP_Error) {
173
-            $this->generateError($response->get_error_messages());
174
-            return false;
175
-        }
176
-        $results = json_decode(wp_remote_retrieve_body($response), true);
177
-        if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
178
-            $errors   = array_map(
179
-                array($this, 'getErrorCode'),
180
-                $results['error-codes']
181
-            );
182
-            if (isset($results['challenge_ts'])) {
183
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
184
-            }
185
-            $this->generateError(implode(' ', $errors), true);
186
-        }
187
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
188
-        add_action('shutdown', array($this, 'setSessionData'));
189
-        return true;
190
-    }
125
+	/**
126
+	 * @param RequestInterface $request
127
+	 * @return boolean
128
+	 * @throws InvalidArgumentException
129
+	 * @throws InvalidDataTypeException
130
+	 * @throws InvalidInterfaceException
131
+	 * @throws RuntimeException
132
+	 */
133
+	public function verifyToken(RequestInterface $request)
134
+	{
135
+		static $previous_recaptcha_response = array();
136
+		$grecaptcha_response = $request->getRequestParam('g-recaptcha-response');
137
+		// if this token has already been verified, then return previous response
138
+		if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
139
+			return $previous_recaptcha_response[ $grecaptcha_response ];
140
+		}
141
+		// still here but no g-recaptcha-response ? - verification failed
142
+		if (! $grecaptcha_response) {
143
+			EE_Error::add_error(
144
+				sprintf(
145
+					/* translators: 1: missing parameter */
146
+					esc_html__(
147
+						// @codingStandardsIgnoreStart
148
+						'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.',
149
+						// @codingStandardsIgnoreEnd
150
+						'event_espresso'
151
+					),
152
+					'g-recaptcha-response'
153
+				),
154
+				__FILE__,
155
+				__FUNCTION__,
156
+				__LINE__
157
+			);
158
+			return false;
159
+		}
160
+		// will update to true if everything passes
161
+		$previous_recaptcha_response[ $grecaptcha_response ] = false;
162
+		$response                                            = wp_safe_remote_post(
163
+			InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
164
+			array(
165
+				'body' => array(
166
+					'secret'   => $this->config->recaptcha_privatekey,
167
+					'response' => $grecaptcha_response,
168
+					'remoteip' => $request->ipAddress(),
169
+				),
170
+			)
171
+		);
172
+		if ($response instanceof WP_Error) {
173
+			$this->generateError($response->get_error_messages());
174
+			return false;
175
+		}
176
+		$results = json_decode(wp_remote_retrieve_body($response), true);
177
+		if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
178
+			$errors   = array_map(
179
+				array($this, 'getErrorCode'),
180
+				$results['error-codes']
181
+			);
182
+			if (isset($results['challenge_ts'])) {
183
+				$errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
184
+			}
185
+			$this->generateError(implode(' ', $errors), true);
186
+		}
187
+		$previous_recaptcha_response[ $grecaptcha_response ] = true;
188
+		add_action('shutdown', array($this, 'setSessionData'));
189
+		return true;
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * @param string $error_response
195
-     * @param bool   $show_errors
196
-     * @return void
197
-     * @throws RuntimeException
198
-     */
199
-    public function generateError($error_response = '', $show_errors = false)
200
-    {
201
-        throw new RuntimeException(
202
-            sprintf(
203
-                esc_html__(
204
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
205
-                    'event_espresso'
206
-                ),
207
-                '<br />',
208
-                $show_errors || current_user_can('manage_options') ? $error_response : ''
209
-            )
210
-        );
211
-    }
193
+	/**
194
+	 * @param string $error_response
195
+	 * @param bool   $show_errors
196
+	 * @return void
197
+	 * @throws RuntimeException
198
+	 */
199
+	public function generateError($error_response = '', $show_errors = false)
200
+	{
201
+		throw new RuntimeException(
202
+			sprintf(
203
+				esc_html__(
204
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
205
+					'event_espresso'
206
+				),
207
+				'<br />',
208
+				$show_errors || current_user_can('manage_options') ? $error_response : ''
209
+			)
210
+		);
211
+	}
212 212
 
213 213
 
214
-    /**
215
-     * @param string $error_code
216
-     * @return string
217
-     */
218
-    public function getErrorCode(&$error_code)
219
-    {
220
-        $error_codes = array(
221
-            'missing-input-secret'   => 'The secret parameter is missing.',
222
-            'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
223
-            'missing-input-response' => 'The response parameter is missing.',
224
-            'invalid-input-response' => 'The response parameter is invalid or malformed.',
225
-            'bad-request'            => 'The request is invalid or malformed.',
226
-            'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
227
-        );
228
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
229
-    }
214
+	/**
215
+	 * @param string $error_code
216
+	 * @return string
217
+	 */
218
+	public function getErrorCode(&$error_code)
219
+	{
220
+		$error_codes = array(
221
+			'missing-input-secret'   => 'The secret parameter is missing.',
222
+			'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
223
+			'missing-input-response' => 'The response parameter is missing.',
224
+			'invalid-input-response' => 'The response parameter is invalid or malformed.',
225
+			'bad-request'            => 'The request is invalid or malformed.',
226
+			'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
227
+		);
228
+		return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
229
+	}
230 230
 
231 231
 
232
-    /**
233
-     * @return array
234
-     * @throws InvalidInterfaceException
235
-     * @throws InvalidDataTypeException
236
-     * @throws InvalidArgumentException
237
-     */
238
-    public function getLocalizedVars()
239
-    {
240
-        return (array) apply_filters(
241
-            'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
242
-            array(
243
-                'siteKey'          => $this->config->recaptcha_publickey,
244
-                'recaptcha_passed' => $this->recaptchaPassed(),
245
-                'wp_debug'         => WP_DEBUG,
246
-                'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
247
-                'failed_message'   => wp_strip_all_tags(
248
-                    __(
249
-                        'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.',
250
-                        'event_espresso'
251
-                    )
252
-                )
253
-            )
254
-        );
255
-    }
232
+	/**
233
+	 * @return array
234
+	 * @throws InvalidInterfaceException
235
+	 * @throws InvalidDataTypeException
236
+	 * @throws InvalidArgumentException
237
+	 */
238
+	public function getLocalizedVars()
239
+	{
240
+		return (array) apply_filters(
241
+			'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
242
+			array(
243
+				'siteKey'          => $this->config->recaptcha_publickey,
244
+				'recaptcha_passed' => $this->recaptchaPassed(),
245
+				'wp_debug'         => WP_DEBUG,
246
+				'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
247
+				'failed_message'   => wp_strip_all_tags(
248
+					__(
249
+						'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.',
250
+						'event_espresso'
251
+					)
252
+				)
253
+			)
254
+		);
255
+	}
256 256
 
257 257
 
258
-    /**
259
-     * @return boolean
260
-     * @throws InvalidInterfaceException
261
-     * @throws InvalidDataTypeException
262
-     * @throws InvalidArgumentException
263
-     */
264
-    public function recaptchaPassed()
265
-    {
266
-        if ($this->recaptcha_passed !== null) {
267
-            return $this->recaptcha_passed;
268
-        }
269
-        // logged in means you have already passed a turing test of sorts
270
-        if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
271
-            $this->recaptcha_passed = true;
272
-            return $this->recaptcha_passed;
273
-        }
274
-        // was test already passed?
275
-        $this->recaptcha_passed = filter_var(
276
-            $this->session->get_session_data(
277
-                InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
278
-            ),
279
-            FILTER_VALIDATE_BOOLEAN
280
-        );
281
-        return $this->recaptcha_passed;
282
-    }
258
+	/**
259
+	 * @return boolean
260
+	 * @throws InvalidInterfaceException
261
+	 * @throws InvalidDataTypeException
262
+	 * @throws InvalidArgumentException
263
+	 */
264
+	public function recaptchaPassed()
265
+	{
266
+		if ($this->recaptcha_passed !== null) {
267
+			return $this->recaptcha_passed;
268
+		}
269
+		// logged in means you have already passed a turing test of sorts
270
+		if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
271
+			$this->recaptcha_passed = true;
272
+			return $this->recaptcha_passed;
273
+		}
274
+		// was test already passed?
275
+		$this->recaptcha_passed = filter_var(
276
+			$this->session->get_session_data(
277
+				InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
278
+			),
279
+			FILTER_VALIDATE_BOOLEAN
280
+		);
281
+		return $this->recaptcha_passed;
282
+	}
283 283
 
284 284
 
285
-    /**
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidDataTypeException
288
-     * @throws InvalidInterfaceException
289
-     */
290
-    public function setSessionData()
291
-    {
292
-        $this->session->set_session_data(
293
-            array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
294
-        );
295
-    }
285
+	/**
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidDataTypeException
288
+	 * @throws InvalidInterfaceException
289
+	 */
290
+	public function setSessionData()
291
+	{
292
+		$this->session->set_session_data(
293
+			array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
294
+		);
295
+	}
296 296
 }
Please login to merge, or discard this patch.
core/services/notifications/PersistentAdminNoticeManager.php 1 patch
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -31,387 +31,387 @@
 block discarded – undo
31 31
 class PersistentAdminNoticeManager
32 32
 {
33 33
 
34
-    const WP_OPTION_KEY = 'ee_pers_admin_notices';
35
-
36
-    /**
37
-     * @var Collection|PersistentAdminNotice[] $notice_collection
38
-     */
39
-    private $notice_collection;
40
-
41
-    /**
42
-     * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the
43
-     * persistent admin notice was displayed, and ultimately dismissed from.
44
-     *
45
-     * @var string $return_url
46
-     */
47
-    private $return_url;
48
-
49
-    /**
50
-     * @var CapabilitiesChecker $capabilities_checker
51
-     */
52
-    private $capabilities_checker;
53
-
54
-    /**
55
-     * @var RequestInterface $request
56
-     */
57
-    private $request;
58
-
59
-
60
-    /**
61
-     * PersistentAdminNoticeManager constructor
62
-     *
63
-     * @param string              $return_url where to  redirect to after dismissing notices
64
-     * @param CapabilitiesChecker $capabilities_checker
65
-     * @param RequestInterface          $request
66
-     * @throws InvalidDataTypeException
67
-     */
68
-    public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request)
69
-    {
70
-        $this->setReturnUrl($return_url);
71
-        $this->capabilities_checker = $capabilities_checker;
72
-        $this->request = $request;
73
-        // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10,
74
-        // and we want to retrieve and generate any nag notices at the last possible moment
75
-        add_action('admin_notices', array($this, 'displayNotices'), 9);
76
-        add_action('network_admin_notices', array($this, 'displayNotices'), 9);
77
-        add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice'));
78
-        add_action('shutdown', array($this, 'registerAndSaveNotices'), 998);
79
-    }
80
-
81
-
82
-    /**
83
-     * @param string $return_url
84
-     * @throws InvalidDataTypeException
85
-     */
86
-    public function setReturnUrl($return_url)
87
-    {
88
-        if (! is_string($return_url)) {
89
-            throw new InvalidDataTypeException('$return_url', $return_url, 'string');
90
-        }
91
-        $this->return_url = $return_url;
92
-    }
93
-
94
-
95
-    /**
96
-     * @return Collection
97
-     * @throws InvalidEntityException
98
-     * @throws InvalidInterfaceException
99
-     * @throws InvalidDataTypeException
100
-     * @throws DomainException
101
-     * @throws DuplicateCollectionIdentifierException
102
-     */
103
-    protected function getPersistentAdminNoticeCollection()
104
-    {
105
-        if (! $this->notice_collection instanceof Collection) {
106
-            $this->notice_collection = new Collection(
107
-                'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
108
-            );
109
-            $this->retrieveStoredNotices();
110
-            $this->registerNotices();
111
-        }
112
-        return $this->notice_collection;
113
-    }
114
-
115
-
116
-    /**
117
-     * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db
118
-     *
119
-     * @return void
120
-     * @throws InvalidEntityException
121
-     * @throws DomainException
122
-     * @throws InvalidDataTypeException
123
-     * @throws DuplicateCollectionIdentifierException
124
-     */
125
-    protected function retrieveStoredNotices()
126
-    {
127
-        $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
128
-        if (! empty($persistent_admin_notices)) {
129
-            foreach ($persistent_admin_notices as $name => $details) {
130
-                if (is_array($details)) {
131
-                    if (! isset(
132
-                        $details['message'],
133
-                        $details['capability'],
134
-                        $details['cap_context'],
135
-                        $details['dismissed']
136
-                    )) {
137
-                        throw new DomainException(
138
-                            sprintf(
139
-                                esc_html__(
140
-                                    'The "%1$s" PersistentAdminNotice could not be retrieved from the database.',
141
-                                    'event_espresso'
142
-                                ),
143
-                                $name
144
-                            )
145
-                        );
146
-                    }
147
-                    // new format for nag notices
148
-                    $this->notice_collection->add(
149
-                        new PersistentAdminNotice(
150
-                            $name,
151
-                            $details['message'],
152
-                            false,
153
-                            $details['capability'],
154
-                            $details['cap_context'],
155
-                            $details['dismissed']
156
-                        ),
157
-                        sanitize_key($name)
158
-                    );
159
-                } else {
160
-                    try {
161
-                        // old nag notices, that we want to convert to the new format
162
-                        $this->notice_collection->add(
163
-                            new PersistentAdminNotice(
164
-                                $name,
165
-                                (string) $details,
166
-                                false,
167
-                                '',
168
-                                '',
169
-                                empty($details)
170
-                            ),
171
-                            sanitize_key($name)
172
-                        );
173
-                    } catch (Exception $e) {
174
-                        EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
175
-                    }
176
-                }
177
-                // each notice will self register when the action hook in registerNotices is triggered
178
-            }
179
-        }
180
-    }
181
-
182
-
183
-    /**
184
-     * exposes the Persistent Admin Notice Collection via an action
185
-     * so that PersistentAdminNotice objects can be added and/or removed
186
-     * without compromising the actual collection like a filter would
187
-     */
188
-    protected function registerNotices()
189
-    {
190
-        do_action(
191
-            'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
192
-            $this->notice_collection
193
-        );
194
-    }
195
-
196
-
197
-    /**
198
-     * @throws DomainException
199
-     * @throws InvalidClassException
200
-     * @throws InvalidDataTypeException
201
-     * @throws InvalidInterfaceException
202
-     * @throws InvalidEntityException
203
-     * @throws DuplicateCollectionIdentifierException
204
-     */
205
-    public function displayNotices()
206
-    {
207
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
208
-        if ($this->notice_collection->hasObjects()) {
209
-            $enqueue_assets = false;
210
-            // and display notices
211
-            foreach ($this->notice_collection as $persistent_admin_notice) {
212
-                /** @var PersistentAdminNotice $persistent_admin_notice */
213
-                // don't display notices that have already been dismissed
214
-                if ($persistent_admin_notice->getDismissed()) {
215
-                    continue;
216
-                }
217
-                try {
218
-                    $this->capabilities_checker->processCapCheck(
219
-                        $persistent_admin_notice->getCapCheck()
220
-                    );
221
-                } catch (InsufficientPermissionsException $e) {
222
-                    // user does not have required cap, so skip to next notice
223
-                    // and just eat the exception - nom nom nom nom
224
-                    continue;
225
-                }
226
-                if ($persistent_admin_notice->getMessage() === '') {
227
-                    continue;
228
-                }
229
-                $this->displayPersistentAdminNotice($persistent_admin_notice);
230
-                $enqueue_assets = true;
231
-            }
232
-            if ($enqueue_assets) {
233
-                $this->enqueueAssets();
234
-            }
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * does what it's named
241
-     *
242
-     * @return void
243
-     */
244
-    public function enqueueAssets()
245
-    {
246
-        wp_register_script(
247
-            'espresso_core',
248
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
249
-            array('jquery'),
250
-            EVENT_ESPRESSO_VERSION,
251
-            true
252
-        );
253
-        wp_register_script(
254
-            'ee_error_js',
255
-            EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
256
-            array('espresso_core'),
257
-            EVENT_ESPRESSO_VERSION,
258
-            true
259
-        );
260
-        wp_localize_script(
261
-            'ee_error_js',
262
-            'ee_dismiss',
263
-            array(
264
-                'return_url'    => urlencode($this->return_url),
265
-                'ajax_url'      => WP_AJAX_URL,
266
-                'unknown_error' => wp_strip_all_tags(
267
-                    __(
268
-                        'An unknown error has occurred on the server while attempting to dismiss this notice.',
269
-                        'event_espresso'
270
-                    )
271
-                ),
272
-            )
273
-        );
274
-        wp_enqueue_script('ee_error_js');
275
-    }
276
-
277
-
278
-    /**
279
-     * displayPersistentAdminNoticeHtml
280
-     *
281
-     * @param  PersistentAdminNotice $persistent_admin_notice
282
-     */
283
-    protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice)
284
-    {
285
-        // used in template
286
-        $persistent_admin_notice_name = $persistent_admin_notice->getName();
287
-        $persistent_admin_notice_message = $persistent_admin_notice->getMessage();
288
-        require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php';
289
-    }
290
-
291
-
292
-    /**
293
-     * dismissNotice
294
-     *
295
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
296
-     * @param bool   $purge    if true, then delete it from the db
297
-     * @param bool   $return   forget all of this AJAX or redirect nonsense, and just return
298
-     * @return void
299
-     * @throws InvalidEntityException
300
-     * @throws InvalidInterfaceException
301
-     * @throws InvalidDataTypeException
302
-     * @throws DomainException
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidArgumentException
306
-     * @throws InvalidArgumentException
307
-     * @throws DuplicateCollectionIdentifierException
308
-     */
309
-    public function dismissNotice($pan_name = '', $purge = false, $return = false)
310
-    {
311
-        $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name);
312
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
313
-        if (! empty($pan_name) && $this->notice_collection->has($pan_name)) {
314
-            /** @var PersistentAdminNotice $persistent_admin_notice */
315
-            $persistent_admin_notice = $this->notice_collection->get($pan_name);
316
-            $persistent_admin_notice->setDismissed(true);
317
-            $persistent_admin_notice->setPurge($purge);
318
-            $this->saveNotices();
319
-        }
320
-        if ($return) {
321
-            return;
322
-        }
323
-        if ($this->request->isAjax()) {
324
-            // grab any notices and concatenate into string
325
-            echo wp_json_encode(
326
-                array(
327
-                    'errors' => implode('<br />', EE_Error::get_notices(false)),
328
-                )
329
-            );
330
-            exit();
331
-        }
332
-        // save errors to a transient to be displayed on next request (after redirect)
333
-        EE_Error::get_notices(false, true);
334
-        wp_safe_redirect(
335
-            urldecode(
336
-                $this->request->getRequestParam('return_url', '')
337
-            )
338
-        );
339
-    }
340
-
341
-
342
-    /**
343
-     * saveNotices
344
-     *
345
-     * @throws DomainException
346
-     * @throws InvalidDataTypeException
347
-     * @throws InvalidInterfaceException
348
-     * @throws InvalidEntityException
349
-     * @throws DuplicateCollectionIdentifierException
350
-     */
351
-    public function saveNotices()
352
-    {
353
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
354
-        if ($this->notice_collection->hasObjects()) {
355
-            $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
356
-            // maybe initialize persistent_admin_notices
357
-            if (empty($persistent_admin_notices)) {
358
-                add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no');
359
-            }
360
-            foreach ($this->notice_collection as $persistent_admin_notice) {
361
-                // are we deleting this notice ?
362
-                if ($persistent_admin_notice->getPurge()) {
363
-                    unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]);
364
-                } else {
365
-                    /** @var PersistentAdminNotice $persistent_admin_notice */
366
-                    $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array(
367
-                        'message'     => $persistent_admin_notice->getMessage(),
368
-                        'capability'  => $persistent_admin_notice->getCapability(),
369
-                        'cap_context' => $persistent_admin_notice->getCapContext(),
370
-                        'dismissed'   => $persistent_admin_notice->getDismissed(),
371
-                    );
372
-                }
373
-            }
374
-            update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices);
375
-        }
376
-    }
377
-
378
-
379
-    /**
380
-     * @throws DomainException
381
-     * @throws InvalidDataTypeException
382
-     * @throws InvalidEntityException
383
-     * @throws InvalidInterfaceException
384
-     * @throws DuplicateCollectionIdentifierException
385
-     */
386
-    public function registerAndSaveNotices()
387
-    {
388
-        $this->getPersistentAdminNoticeCollection();
389
-        $this->registerNotices();
390
-        $this->saveNotices();
391
-        add_filter(
392
-            'PersistentAdminNoticeManager__registerAndSaveNotices__complete',
393
-            '__return_true'
394
-        );
395
-    }
396
-
397
-
398
-    /**
399
-     * @throws DomainException
400
-     * @throws InvalidDataTypeException
401
-     * @throws InvalidEntityException
402
-     * @throws InvalidInterfaceException
403
-     * @throws InvalidArgumentException
404
-     * @throws DuplicateCollectionIdentifierException
405
-     */
406
-    public static function loadRegisterAndSaveNotices()
407
-    {
408
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
409
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
410
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
411
-        );
412
-        // if shutdown has already run, then call registerAndSaveNotices() manually
413
-        if (did_action('shutdown')) {
414
-            $persistent_admin_notice_manager->registerAndSaveNotices();
415
-        }
416
-    }
34
+	const WP_OPTION_KEY = 'ee_pers_admin_notices';
35
+
36
+	/**
37
+	 * @var Collection|PersistentAdminNotice[] $notice_collection
38
+	 */
39
+	private $notice_collection;
40
+
41
+	/**
42
+	 * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the
43
+	 * persistent admin notice was displayed, and ultimately dismissed from.
44
+	 *
45
+	 * @var string $return_url
46
+	 */
47
+	private $return_url;
48
+
49
+	/**
50
+	 * @var CapabilitiesChecker $capabilities_checker
51
+	 */
52
+	private $capabilities_checker;
53
+
54
+	/**
55
+	 * @var RequestInterface $request
56
+	 */
57
+	private $request;
58
+
59
+
60
+	/**
61
+	 * PersistentAdminNoticeManager constructor
62
+	 *
63
+	 * @param string              $return_url where to  redirect to after dismissing notices
64
+	 * @param CapabilitiesChecker $capabilities_checker
65
+	 * @param RequestInterface          $request
66
+	 * @throws InvalidDataTypeException
67
+	 */
68
+	public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request)
69
+	{
70
+		$this->setReturnUrl($return_url);
71
+		$this->capabilities_checker = $capabilities_checker;
72
+		$this->request = $request;
73
+		// setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10,
74
+		// and we want to retrieve and generate any nag notices at the last possible moment
75
+		add_action('admin_notices', array($this, 'displayNotices'), 9);
76
+		add_action('network_admin_notices', array($this, 'displayNotices'), 9);
77
+		add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice'));
78
+		add_action('shutdown', array($this, 'registerAndSaveNotices'), 998);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @param string $return_url
84
+	 * @throws InvalidDataTypeException
85
+	 */
86
+	public function setReturnUrl($return_url)
87
+	{
88
+		if (! is_string($return_url)) {
89
+			throw new InvalidDataTypeException('$return_url', $return_url, 'string');
90
+		}
91
+		$this->return_url = $return_url;
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return Collection
97
+	 * @throws InvalidEntityException
98
+	 * @throws InvalidInterfaceException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws DomainException
101
+	 * @throws DuplicateCollectionIdentifierException
102
+	 */
103
+	protected function getPersistentAdminNoticeCollection()
104
+	{
105
+		if (! $this->notice_collection instanceof Collection) {
106
+			$this->notice_collection = new Collection(
107
+				'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
108
+			);
109
+			$this->retrieveStoredNotices();
110
+			$this->registerNotices();
111
+		}
112
+		return $this->notice_collection;
113
+	}
114
+
115
+
116
+	/**
117
+	 * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db
118
+	 *
119
+	 * @return void
120
+	 * @throws InvalidEntityException
121
+	 * @throws DomainException
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws DuplicateCollectionIdentifierException
124
+	 */
125
+	protected function retrieveStoredNotices()
126
+	{
127
+		$persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
128
+		if (! empty($persistent_admin_notices)) {
129
+			foreach ($persistent_admin_notices as $name => $details) {
130
+				if (is_array($details)) {
131
+					if (! isset(
132
+						$details['message'],
133
+						$details['capability'],
134
+						$details['cap_context'],
135
+						$details['dismissed']
136
+					)) {
137
+						throw new DomainException(
138
+							sprintf(
139
+								esc_html__(
140
+									'The "%1$s" PersistentAdminNotice could not be retrieved from the database.',
141
+									'event_espresso'
142
+								),
143
+								$name
144
+							)
145
+						);
146
+					}
147
+					// new format for nag notices
148
+					$this->notice_collection->add(
149
+						new PersistentAdminNotice(
150
+							$name,
151
+							$details['message'],
152
+							false,
153
+							$details['capability'],
154
+							$details['cap_context'],
155
+							$details['dismissed']
156
+						),
157
+						sanitize_key($name)
158
+					);
159
+				} else {
160
+					try {
161
+						// old nag notices, that we want to convert to the new format
162
+						$this->notice_collection->add(
163
+							new PersistentAdminNotice(
164
+								$name,
165
+								(string) $details,
166
+								false,
167
+								'',
168
+								'',
169
+								empty($details)
170
+							),
171
+							sanitize_key($name)
172
+						);
173
+					} catch (Exception $e) {
174
+						EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
175
+					}
176
+				}
177
+				// each notice will self register when the action hook in registerNotices is triggered
178
+			}
179
+		}
180
+	}
181
+
182
+
183
+	/**
184
+	 * exposes the Persistent Admin Notice Collection via an action
185
+	 * so that PersistentAdminNotice objects can be added and/or removed
186
+	 * without compromising the actual collection like a filter would
187
+	 */
188
+	protected function registerNotices()
189
+	{
190
+		do_action(
191
+			'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
192
+			$this->notice_collection
193
+		);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @throws DomainException
199
+	 * @throws InvalidClassException
200
+	 * @throws InvalidDataTypeException
201
+	 * @throws InvalidInterfaceException
202
+	 * @throws InvalidEntityException
203
+	 * @throws DuplicateCollectionIdentifierException
204
+	 */
205
+	public function displayNotices()
206
+	{
207
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
208
+		if ($this->notice_collection->hasObjects()) {
209
+			$enqueue_assets = false;
210
+			// and display notices
211
+			foreach ($this->notice_collection as $persistent_admin_notice) {
212
+				/** @var PersistentAdminNotice $persistent_admin_notice */
213
+				// don't display notices that have already been dismissed
214
+				if ($persistent_admin_notice->getDismissed()) {
215
+					continue;
216
+				}
217
+				try {
218
+					$this->capabilities_checker->processCapCheck(
219
+						$persistent_admin_notice->getCapCheck()
220
+					);
221
+				} catch (InsufficientPermissionsException $e) {
222
+					// user does not have required cap, so skip to next notice
223
+					// and just eat the exception - nom nom nom nom
224
+					continue;
225
+				}
226
+				if ($persistent_admin_notice->getMessage() === '') {
227
+					continue;
228
+				}
229
+				$this->displayPersistentAdminNotice($persistent_admin_notice);
230
+				$enqueue_assets = true;
231
+			}
232
+			if ($enqueue_assets) {
233
+				$this->enqueueAssets();
234
+			}
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * does what it's named
241
+	 *
242
+	 * @return void
243
+	 */
244
+	public function enqueueAssets()
245
+	{
246
+		wp_register_script(
247
+			'espresso_core',
248
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
249
+			array('jquery'),
250
+			EVENT_ESPRESSO_VERSION,
251
+			true
252
+		);
253
+		wp_register_script(
254
+			'ee_error_js',
255
+			EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
256
+			array('espresso_core'),
257
+			EVENT_ESPRESSO_VERSION,
258
+			true
259
+		);
260
+		wp_localize_script(
261
+			'ee_error_js',
262
+			'ee_dismiss',
263
+			array(
264
+				'return_url'    => urlencode($this->return_url),
265
+				'ajax_url'      => WP_AJAX_URL,
266
+				'unknown_error' => wp_strip_all_tags(
267
+					__(
268
+						'An unknown error has occurred on the server while attempting to dismiss this notice.',
269
+						'event_espresso'
270
+					)
271
+				),
272
+			)
273
+		);
274
+		wp_enqueue_script('ee_error_js');
275
+	}
276
+
277
+
278
+	/**
279
+	 * displayPersistentAdminNoticeHtml
280
+	 *
281
+	 * @param  PersistentAdminNotice $persistent_admin_notice
282
+	 */
283
+	protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice)
284
+	{
285
+		// used in template
286
+		$persistent_admin_notice_name = $persistent_admin_notice->getName();
287
+		$persistent_admin_notice_message = $persistent_admin_notice->getMessage();
288
+		require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php';
289
+	}
290
+
291
+
292
+	/**
293
+	 * dismissNotice
294
+	 *
295
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
296
+	 * @param bool   $purge    if true, then delete it from the db
297
+	 * @param bool   $return   forget all of this AJAX or redirect nonsense, and just return
298
+	 * @return void
299
+	 * @throws InvalidEntityException
300
+	 * @throws InvalidInterfaceException
301
+	 * @throws InvalidDataTypeException
302
+	 * @throws DomainException
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidArgumentException
306
+	 * @throws InvalidArgumentException
307
+	 * @throws DuplicateCollectionIdentifierException
308
+	 */
309
+	public function dismissNotice($pan_name = '', $purge = false, $return = false)
310
+	{
311
+		$pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name);
312
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
313
+		if (! empty($pan_name) && $this->notice_collection->has($pan_name)) {
314
+			/** @var PersistentAdminNotice $persistent_admin_notice */
315
+			$persistent_admin_notice = $this->notice_collection->get($pan_name);
316
+			$persistent_admin_notice->setDismissed(true);
317
+			$persistent_admin_notice->setPurge($purge);
318
+			$this->saveNotices();
319
+		}
320
+		if ($return) {
321
+			return;
322
+		}
323
+		if ($this->request->isAjax()) {
324
+			// grab any notices and concatenate into string
325
+			echo wp_json_encode(
326
+				array(
327
+					'errors' => implode('<br />', EE_Error::get_notices(false)),
328
+				)
329
+			);
330
+			exit();
331
+		}
332
+		// save errors to a transient to be displayed on next request (after redirect)
333
+		EE_Error::get_notices(false, true);
334
+		wp_safe_redirect(
335
+			urldecode(
336
+				$this->request->getRequestParam('return_url', '')
337
+			)
338
+		);
339
+	}
340
+
341
+
342
+	/**
343
+	 * saveNotices
344
+	 *
345
+	 * @throws DomainException
346
+	 * @throws InvalidDataTypeException
347
+	 * @throws InvalidInterfaceException
348
+	 * @throws InvalidEntityException
349
+	 * @throws DuplicateCollectionIdentifierException
350
+	 */
351
+	public function saveNotices()
352
+	{
353
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
354
+		if ($this->notice_collection->hasObjects()) {
355
+			$persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
356
+			// maybe initialize persistent_admin_notices
357
+			if (empty($persistent_admin_notices)) {
358
+				add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no');
359
+			}
360
+			foreach ($this->notice_collection as $persistent_admin_notice) {
361
+				// are we deleting this notice ?
362
+				if ($persistent_admin_notice->getPurge()) {
363
+					unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]);
364
+				} else {
365
+					/** @var PersistentAdminNotice $persistent_admin_notice */
366
+					$persistent_admin_notices[ $persistent_admin_notice->getName() ] = array(
367
+						'message'     => $persistent_admin_notice->getMessage(),
368
+						'capability'  => $persistent_admin_notice->getCapability(),
369
+						'cap_context' => $persistent_admin_notice->getCapContext(),
370
+						'dismissed'   => $persistent_admin_notice->getDismissed(),
371
+					);
372
+				}
373
+			}
374
+			update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices);
375
+		}
376
+	}
377
+
378
+
379
+	/**
380
+	 * @throws DomainException
381
+	 * @throws InvalidDataTypeException
382
+	 * @throws InvalidEntityException
383
+	 * @throws InvalidInterfaceException
384
+	 * @throws DuplicateCollectionIdentifierException
385
+	 */
386
+	public function registerAndSaveNotices()
387
+	{
388
+		$this->getPersistentAdminNoticeCollection();
389
+		$this->registerNotices();
390
+		$this->saveNotices();
391
+		add_filter(
392
+			'PersistentAdminNoticeManager__registerAndSaveNotices__complete',
393
+			'__return_true'
394
+		);
395
+	}
396
+
397
+
398
+	/**
399
+	 * @throws DomainException
400
+	 * @throws InvalidDataTypeException
401
+	 * @throws InvalidEntityException
402
+	 * @throws InvalidInterfaceException
403
+	 * @throws InvalidArgumentException
404
+	 * @throws DuplicateCollectionIdentifierException
405
+	 */
406
+	public static function loadRegisterAndSaveNotices()
407
+	{
408
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
409
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
410
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
411
+		);
412
+		// if shutdown has already run, then call registerAndSaveNotices() manually
413
+		if (did_action('shutdown')) {
414
+			$persistent_admin_notice_manager->registerAndSaveNotices();
415
+		}
416
+	}
417 417
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      */
165 165
     protected function getLoader()
166 166
     {
167
-        if (! $this->loader instanceof LoaderInterface) {
167
+        if ( ! $this->loader instanceof LoaderInterface) {
168 168
             $this->loader = LoaderFactory::getLoader();
169 169
         }
170 170
         return $this->loader;
@@ -188,11 +188,11 @@  discard block
 block discarded – undo
188 188
             $this->_cpt_routes
189 189
         );
190 190
         // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
191
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
192
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
191
+        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
192
+            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
193 193
             : get_post_type_object($page);
194 194
         // tweak pagenow for page loading.
195
-        if (! $this->_pagenow_map) {
195
+        if ( ! $this->_pagenow_map) {
196 196
             $this->_pagenow_map = array(
197 197
                 'create_new' => 'post-new.php',
198 198
                 'edit'       => 'post.php',
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
     {
227 227
         global $pagenow, $hook_suffix;
228 228
         // possibly reset pagenow.
229
-        if (! empty($this->_req_data['page'])
229
+        if ( ! empty($this->_req_data['page'])
230 230
             && $this->_req_data['page'] == $this->page_slug
231 231
             && ! empty($this->_req_data['action'])
232
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
232
+            && isset($this->_pagenow_map[$this->_req_data['action']])
233 233
         ) {
234
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
234
+            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
235 235
             $hook_suffix = $pagenow;
236 236
         }
237 237
     }
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
         if (empty($wp_meta_boxes)) {
264 264
             return;
265 265
         }
266
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
266
+        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
267 267
         foreach ($current_metaboxes as $box_context) {
268 268
             foreach ($box_context as $box_details) {
269 269
                 foreach ($box_details as $box) {
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
             $this
297 297
         );
298 298
         $containers = apply_filters(
299
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
299
+            'FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
300 300
             $containers,
301 301
             $this
302 302
         );
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
     protected function _load_page_dependencies()
343 343
     {
344 344
         // we only add stuff if this is a cpt_route!
345
-        if (! $this->_cpt_route) {
345
+        if ( ! $this->_cpt_route) {
346 346
             parent::_load_page_dependencies();
347 347
             return;
348 348
         }
@@ -366,16 +366,16 @@  discard block
 block discarded – undo
366 366
         add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
367 367
         // This basically allows us to change the title of the "publish" metabox area
368 368
         // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
369
-        if (! empty($this->_labels['publishbox'])) {
369
+        if ( ! empty($this->_labels['publishbox'])) {
370 370
             $box_label = is_array($this->_labels['publishbox'])
371
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
372
-                ? $this->_labels['publishbox'][ $this->_req_action ]
371
+                         && isset($this->_labels['publishbox'][$this->_req_action])
372
+                ? $this->_labels['publishbox'][$this->_req_action]
373 373
                 : $this->_labels['publishbox'];
374 374
             add_meta_box(
375 375
                 'submitdiv',
376 376
                 $box_label,
377 377
                 'post_submit_meta_box',
378
-                $this->_cpt_routes[ $this->_req_action ],
378
+                $this->_cpt_routes[$this->_req_action],
379 379
                 'side',
380 380
                 'core'
381 381
             );
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
                 'page_templates',
387 387
                 __('Page Template', 'event_espresso'),
388 388
                 array($this, 'page_template_meta_box'),
389
-                $this->_cpt_routes[ $this->_req_action ],
389
+                $this->_cpt_routes[$this->_req_action],
390 390
                 'side',
391 391
                 'default'
392 392
             );
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
         // This is for any plugins that are doing things properly
419 419
         // and hooking into the load page hook for core wp cpt routes.
420 420
         global $pagenow;
421
-        add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
422
-        do_action('load-' . $pagenow);
421
+        add_action('load-'.$pagenow, array($this, 'modify_current_screen'), 20);
422
+        do_action('load-'.$pagenow);
423 423
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
424 424
         // we route REALLY early.
425 425
         try {
@@ -448,8 +448,8 @@  discard block
 block discarded – undo
448 448
                 'admin.php?page=espresso_registrations&action=contact_list',
449 449
             ),
450 450
             1 => array(
451
-                'edit.php?post_type=' . $this->_cpt_object->name,
452
-                'admin.php?page=' . $this->_cpt_object->name,
451
+                'edit.php?post_type='.$this->_cpt_object->name,
452
+                'admin.php?page='.$this->_cpt_object->name,
453 453
             ),
454 454
         );
455 455
         foreach ($routes_to_match as $route_matches) {
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
             'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
479 479
         );
480 480
         $cpt_args = $custom_post_types->getDefinitions();
481
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
481
+        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
482 482
         $cpt_has_support = ! empty($cpt_args['page_templates']);
483 483
 
484 484
         // if the installed version of WP is > 4.7 we do some additional checks.
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
             // if there are $post_templates for this cpt, then we return false for this method because
488 488
             // that means we aren't going to load our page template manager and leave that up to the native
489 489
             // cpt template manager.
490
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
490
+            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
491 491
         }
492 492
 
493 493
         return $cpt_has_support;
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 
562 562
         $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
563 563
         $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
564
-            ? $statuses[ $this->_cpt_model_obj->status() ]
564
+            ? $statuses[$this->_cpt_model_obj->status()]
565 565
             : '';
566 566
         $template_args = array(
567 567
             'cur_status'            => $this->_cpt_model_obj->status(),
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
             $template_args['statuses'] = $statuses;
577 577
         }
578 578
 
579
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
579
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
580 580
         EEH_Template::display_template($template, $template_args);
581 581
     }
582 582
 
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
             : null;
618 618
         $this->_verify_nonce($nonce, 'autosave');
619 619
         // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
620
-        if (! defined('DOING_AUTOSAVE')) {
620
+        if ( ! defined('DOING_AUTOSAVE')) {
621 621
             define('DOING_AUTOSAVE', true);
622 622
         }
623 623
         // if we made it here then the nonce checked out.  Let's run our methods and actions
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
             $this->_template_args['success'] = true;
629 629
         }
630 630
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
631
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
631
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
632 632
         // now let's return json
633 633
         $this->_return_json();
634 634
     }
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
             return;
651 651
         }
652 652
         // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
653
-        if (! empty($this->_cpt_object)) {
653
+        if ( ! empty($this->_cpt_object)) {
654 654
             $this->_page_routes = array_merge(
655 655
                 array(
656 656
                     'create_new' => '_create_new_cpt_item',
@@ -681,10 +681,10 @@  discard block
 block discarded – undo
681 681
             );
682 682
         }
683 683
         // load the next section only if this is a matching cpt route as set in the cpt routes array.
684
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
684
+        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
685 685
             return;
686 686
         }
687
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
687
+        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
688 688
         // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
689 689
         if (empty($this->_cpt_object)) {
690 690
             $msg = sprintf(
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
         if (empty($this->_cpt_model_names)
725 725
             || (
726 726
                 ! $ignore_route_check
727
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
727
+                && ! isset($this->_cpt_routes[$this->_req_action])
728 728
             ) || (
729 729
                 $this->_cpt_model_obj instanceof EE_CPT_Base
730 730
                 && $this->_cpt_model_obj->ID() === $id
@@ -741,11 +741,11 @@  discard block
 block discarded – undo
741 741
                 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
742 742
             );
743 743
             $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
744
-            if (isset($model_names[ $post_type ])) {
745
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
744
+            if (isset($model_names[$post_type])) {
745
+                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
746 746
             }
747 747
         } else {
748
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
748
+            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
749 749
         }
750 750
         if ($model instanceof EEM_Base) {
751 751
             $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
         $current_route = isset($this->_req_data['current_route'])
776 776
             ? $this->_req_data['current_route']
777 777
             : 'shouldneverwork';
778
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
779
-            ? $this->_cpt_routes[ $current_route ]
778
+        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
779
+            ? $this->_cpt_routes[$current_route]
780 780
             : '';
781 781
         add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
782 782
         add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
@@ -785,10 +785,10 @@  discard block
 block discarded – undo
785 785
         }
786 786
         // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
787 787
         $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
788
-        if (! empty($revision)) {
788
+        if ( ! empty($revision)) {
789 789
             $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
790 790
             // doing a restore?
791
-            if (! empty($action) && $action === 'restore') {
791
+            if ( ! empty($action) && $action === 'restore') {
792 792
                 // get post for revision
793 793
                 $rev_post = get_post($revision);
794 794
                 $rev_parent = get_post($rev_post->post_parent);
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
     {
825 825
         $this->_set_model_object($post_id, true, 'trash');
826 826
         // if our cpt object isn't existent then get out immediately.
827
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
827
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
828 828
             return;
829 829
         }
830 830
         $this->trash_cpt_item($post_id);
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     {
843 843
         $this->_set_model_object($post_id, true, 'restore');
844 844
         // if our cpt object isn't existent then get out immediately.
845
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
845
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
846 846
             return;
847 847
         }
848 848
         $this->restore_cpt_item($post_id);
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
     {
861 861
         $this->_set_model_object($post_id, true, 'delete');
862 862
         // if our cpt object isn't existent then get out immediately.
863
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
863
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
864 864
             return;
865 865
         }
866 866
         $this->delete_cpt_item($post_id);
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
     {
880 880
         $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
881 881
         // verify event object
882
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
882
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
883 883
             throw new EE_Error(
884 884
                 sprintf(
885 885
                     __(
@@ -935,13 +935,13 @@  discard block
 block discarded – undo
935 935
         if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
936 936
             // setup custom post status object for localize script but only if we've got a cpt object
937 937
             $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
938
-            if (! empty($statuses)) {
938
+            if ( ! empty($statuses)) {
939 939
                 // get ALL statuses!
940 940
                 $statuses = $this->_cpt_model_obj->get_all_post_statuses();
941 941
                 // setup object
942 942
                 $ee_cpt_statuses = array();
943 943
                 foreach ($statuses as $status => $label) {
944
-                    $ee_cpt_statuses[ $status ] = array(
944
+                    $ee_cpt_statuses[$status] = array(
945 945
                         'label'      => $label,
946 946
                         'save_label' => sprintf(
947 947
                             wp_strip_all_tags(__('Save as %s', 'event_espresso')),
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
                 $post->page_template = $this->_req_data['page_template'];
1007 1007
                 $page_templates = wp_get_theme()->get_page_templates($post);
1008 1008
             }
1009
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1009
+            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
1010 1010
                 EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1011 1011
             } else {
1012 1012
                 update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
     {
1032 1032
         // only do this if we're actually processing one of our CPTs
1033 1033
         // if our cpt object isn't existent then get out immediately.
1034
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1034
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1035 1035
             return;
1036 1036
         }
1037 1037
         delete_post_meta($post_id, '_wp_trash_meta_status');
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
         // global action
1057 1057
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1058 1058
         // class specific action so you can limit hooking into a specific page.
1059
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1059
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
1060 1060
     }
1061 1061
 
1062 1062
 
@@ -1083,11 +1083,11 @@  discard block
 block discarded – undo
1083 1083
     public function modify_current_screen()
1084 1084
     {
1085 1085
         // ONLY do this if the current page_route IS a cpt route
1086
-        if (! $this->_cpt_route) {
1086
+        if ( ! $this->_cpt_route) {
1087 1087
             return;
1088 1088
         }
1089 1089
         // routing things REALLY early b/c this is a cpt admin page
1090
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1090
+        set_current_screen($this->_cpt_routes[$this->_req_action]);
1091 1091
         $this->_current_screen = get_current_screen();
1092 1092
         $this->_current_screen->base = 'event-espresso';
1093 1093
         $this->_add_help_tabs(); // we make sure we add any help tabs back in!
@@ -1110,8 +1110,8 @@  discard block
 block discarded – undo
1110 1110
      */
1111 1111
     public function add_custom_editor_default_title($title)
1112 1112
     {
1113
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1114
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1113
+        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1114
+            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1115 1115
             : $title;
1116 1116
     }
1117 1117
 
@@ -1127,10 +1127,10 @@  discard block
 block discarded – undo
1127 1127
      */
1128 1128
     public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1129 1129
     {
1130
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1130
+        if ( ! empty($id) && get_option('permalink_structure') !== '') {
1131 1131
             $post = get_post($id);
1132 1132
             if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1133
-                $shortlink = home_url('?p=' . $post->ID);
1133
+                $shortlink = home_url('?p='.$post->ID);
1134 1134
             }
1135 1135
         }
1136 1136
         return $shortlink;
@@ -1163,11 +1163,11 @@  discard block
 block discarded – undo
1163 1163
      */
1164 1164
     public function cpt_post_form_hidden_input()
1165 1165
     {
1166
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1166
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1167 1167
         // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1168 1168
         echo '<div id="ee-cpt-hidden-inputs">';
1169
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1170
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1169
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1170
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1171 1171
         echo '</div>';
1172 1172
     }
1173 1173
 
@@ -1212,15 +1212,15 @@  discard block
 block discarded – undo
1212 1212
     public function modify_edit_post_link($link, $id, $context)
1213 1213
     {
1214 1214
         $post = get_post($id);
1215
-        if (! isset($this->_req_data['action'])
1216
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1217
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1215
+        if ( ! isset($this->_req_data['action'])
1216
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1217
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1218 1218
         ) {
1219 1219
             return $link;
1220 1220
         }
1221 1221
         $query_args = array(
1222
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1223
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1222
+            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1223
+                ? $this->_cpt_edit_routes[$post->post_type]
1224 1224
                 : 'edit',
1225 1225
             'post'   => $id,
1226 1226
         );
@@ -1243,16 +1243,16 @@  discard block
 block discarded – undo
1243 1243
         $post = get_post($post_id);
1244 1244
 
1245 1245
         if (empty($this->_req_data['action'])
1246
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1246
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1247 1247
             || ! $post instanceof WP_Post
1248
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1248
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1249 1249
         ) {
1250 1250
             return $delete_link;
1251 1251
         }
1252 1252
         $this->_set_model_object($post->ID, true);
1253 1253
 
1254 1254
         // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1255
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1255
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1256 1256
 
1257 1257
         return EE_Admin_Page::add_query_args_and_nonce(
1258 1258
             array(
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
         // we DO have a match so let's setup the url
1281 1281
         // we have to get the post to determine our route
1282 1282
         $post = get_post($post_id);
1283
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1283
+        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1284 1284
         // shared query_args
1285 1285
         $query_args = array('action' => $edit_route, 'post' => $post_id);
1286 1286
         $admin_url = $this->_admin_base_url;
@@ -1352,12 +1352,12 @@  discard block
 block discarded – undo
1352 1352
         /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1353 1353
 
1354 1354
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1355
-        $messages[ $post->post_type ] = array(
1355
+        $messages[$post->post_type] = array(
1356 1356
             0  => '', // Unused. Messages start at index 1.
1357 1357
             1  => sprintf(
1358 1358
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1359 1359
                 $this->_cpt_object->labels->singular_name,
1360
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1360
+                '<a href="'.esc_url(get_permalink($id)).'">',
1361 1361
                 '</a>'
1362 1362
             ),
1363 1363
             2  => __('Custom field updated', 'event_espresso'),
@@ -1372,27 +1372,27 @@  discard block
 block discarded – undo
1372 1372
             6  => sprintf(
1373 1373
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1374 1374
                 $this->_cpt_object->labels->singular_name,
1375
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1375
+                '<a href="'.esc_url(get_permalink($id)).'">',
1376 1376
                 '</a>'
1377 1377
             ),
1378 1378
             7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1379 1379
             8  => sprintf(
1380 1380
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1381 1381
                 $this->_cpt_object->labels->singular_name,
1382
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1382
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1383 1383
                 '</a>'
1384 1384
             ),
1385 1385
             9  => sprintf(
1386 1386
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1387 1387
                 $this->_cpt_object->labels->singular_name,
1388
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1389
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1388
+                '<strong>'.date_i18n('M j, Y @ G:i', strtotime($post->post_date)).'</strong>',
1389
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1390 1390
                 '</a>'
1391 1391
             ),
1392 1392
             10 => sprintf(
1393 1393
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1394 1394
                 $this->_cpt_object->labels->singular_name,
1395
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1395
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1396 1396
                 '</a>'
1397 1397
             ),
1398 1398
         );
@@ -1411,10 +1411,10 @@  discard block
 block discarded – undo
1411 1411
     {
1412 1412
         // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1413 1413
         global $post, $title, $is_IE, $post_type, $post_type_object;
1414
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1414
+        $post_type = $this->_cpt_routes[$this->_req_action];
1415 1415
         $post_type_object = $this->_cpt_object;
1416 1416
         $title = $post_type_object->labels->add_new_item;
1417
-        $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1417
+        $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1418 1418
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1419 1419
         // modify the default editor title field with default title.
1420 1420
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
@@ -1439,8 +1439,8 @@  discard block
 block discarded – undo
1439 1439
             if ($creating) {
1440 1440
                 wp_enqueue_script('autosave');
1441 1441
             } else {
1442
-                if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1443
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1442
+                if (isset($this->_cpt_routes[$this->_req_data['action']])
1443
+                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1444 1444
                 ) {
1445 1445
                     $create_new_action = apply_filters(
1446 1446
                         'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
@@ -1456,7 +1456,7 @@  discard block
 block discarded – undo
1456 1456
                     );
1457 1457
                 }
1458 1458
             }
1459
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1459
+            include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1460 1460
         }
1461 1461
     }
1462 1462
 
@@ -1487,21 +1487,21 @@  discard block
 block discarded – undo
1487 1487
         if (empty($post)) {
1488 1488
             wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1489 1489
         }
1490
-        if (! empty($_GET['get-post-lock'])) {
1490
+        if ( ! empty($_GET['get-post-lock'])) {
1491 1491
             wp_set_post_lock($post_id);
1492 1492
             wp_redirect(get_edit_post_link($post_id, 'url'));
1493 1493
             exit();
1494 1494
         }
1495 1495
 
1496 1496
         // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1497
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1497
+        $post_type = $this->_cpt_routes[$this->_req_action];
1498 1498
         $post_type_object = $this->_cpt_object;
1499 1499
 
1500
-        if (! wp_check_post_lock($post->ID)) {
1500
+        if ( ! wp_check_post_lock($post->ID)) {
1501 1501
             wp_set_post_lock($post->ID);
1502 1502
         }
1503 1503
         add_action('admin_footer', '_admin_notice_post_locked');
1504
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1504
+        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1505 1505
             wp_enqueue_script('admin-comments');
1506 1506
             enqueue_comment_hotkeys_js();
1507 1507
         }
Please login to merge, or discard this patch.
Indentation   +1469 added lines, -1469 removed lines patch added patch discarded remove patch
@@ -28,494 +28,494 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * This gets set in _setup_cpt
33
-     * It will contain the object for the custom post type.
34
-     *
35
-     * @var EE_CPT_Base
36
-     */
37
-    protected $_cpt_object;
38
-
39
-
40
-    /**
41
-     * a boolean flag to set whether the current route is a cpt route or not.
42
-     *
43
-     * @var bool
44
-     */
45
-    protected $_cpt_route = false;
46
-
47
-
48
-    /**
49
-     * This property allows cpt classes to define multiple routes as cpt routes.
50
-     * //in this array we define what the custom post type for this route is.
51
-     * array(
52
-     * 'route_name' => 'custom_post_type_slug'
53
-     * )
54
-     *
55
-     * @var array
56
-     */
57
-    protected $_cpt_routes = array();
58
-
59
-
60
-    /**
61
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
-     * in this format:
63
-     * array(
64
-     * 'post_type_slug' => 'edit_route'
65
-     * )
66
-     *
67
-     * @var array
68
-     */
69
-    protected $_cpt_edit_routes = array();
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-    /**
89
-     * @var LoaderInterface $loader ;
90
-     */
91
-    protected $loader;
92
-
93
-    /**
94
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
95
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
96
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
97
-     * Registration of containers should be done before load_page_dependencies() is run.
98
-     *
99
-     * @var array()
100
-     */
101
-    protected $_autosave_containers = array();
102
-    protected $_autosave_fields = array();
103
-
104
-    /**
105
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
106
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
107
-     *
108
-     * @var array
109
-     */
110
-    protected $_pagenow_map;
111
-
112
-
113
-    /**
114
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
115
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
116
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
117
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
118
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
119
-     *
120
-     * @access protected
121
-     * @abstract
122
-     * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
123
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
124
-     * @return void
125
-     */
126
-    abstract protected function _insert_update_cpt_item($post_id, $post);
127
-
128
-
129
-    /**
130
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
131
-     *
132
-     * @abstract
133
-     * @access public
134
-     * @param  string $post_id The ID of the cpt that was trashed
135
-     * @return void
136
-     */
137
-    abstract public function trash_cpt_item($post_id);
138
-
139
-
140
-    /**
141
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
-     *
143
-     * @param  string $post_id theID of the cpt that was untrashed
144
-     * @return void
145
-     */
146
-    abstract public function restore_cpt_item($post_id);
147
-
148
-
149
-    /**
150
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
151
-     * from the db
152
-     *
153
-     * @param  string $post_id the ID of the cpt that was deleted
154
-     * @return void
155
-     */
156
-    abstract public function delete_cpt_item($post_id);
157
-
158
-
159
-    /**
160
-     * @return LoaderInterface
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     */
165
-    protected function getLoader()
166
-    {
167
-        if (! $this->loader instanceof LoaderInterface) {
168
-            $this->loader = LoaderFactory::getLoader();
169
-        }
170
-        return $this->loader;
171
-    }
172
-
173
-    /**
174
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
175
-     *
176
-     * @access protected
177
-     * @return void
178
-     */
179
-    protected function _before_page_setup()
180
-    {
181
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
182
-        $this->_cpt_routes = array_merge(
183
-            array(
184
-                'create_new' => $this->page_slug,
185
-                'edit'       => $this->page_slug,
186
-                'trash'      => $this->page_slug,
187
-            ),
188
-            $this->_cpt_routes
189
-        );
190
-        // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
191
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
192
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
193
-            : get_post_type_object($page);
194
-        // tweak pagenow for page loading.
195
-        if (! $this->_pagenow_map) {
196
-            $this->_pagenow_map = array(
197
-                'create_new' => 'post-new.php',
198
-                'edit'       => 'post.php',
199
-                'trash'      => 'post.php',
200
-            );
201
-        }
202
-        add_action('current_screen', array($this, 'modify_pagenow'));
203
-        // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
204
-        // get current page from autosave
205
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
206
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
207
-            : null;
208
-        $this->_current_page = isset($this->_req_data['current_page'])
209
-            ? $this->_req_data['current_page']
210
-            : $current_page;
211
-        // autosave... make sure its only for the correct page
212
-        // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
213
-        // setup autosave ajax hook
214
-        // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
215
-        // }
216
-    }
217
-
218
-
219
-    /**
220
-     * Simply ensure that we simulate the correct post route for cpt screens
221
-     *
222
-     * @param WP_Screen $current_screen
223
-     * @return void
224
-     */
225
-    public function modify_pagenow($current_screen)
226
-    {
227
-        global $pagenow, $hook_suffix;
228
-        // possibly reset pagenow.
229
-        if (! empty($this->_req_data['page'])
230
-            && $this->_req_data['page'] == $this->page_slug
231
-            && ! empty($this->_req_data['action'])
232
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
233
-        ) {
234
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
235
-            $hook_suffix = $pagenow;
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * This method is used to register additional autosave containers to the _autosave_containers property.
242
-     *
243
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
244
-     *       automatically register the id for the post metabox as a container.
245
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
246
-     *                    you would send along the id of a metabox container.
247
-     * @return void
248
-     */
249
-    protected function _register_autosave_containers($ids)
250
-    {
251
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
252
-    }
253
-
254
-
255
-    /**
256
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
257
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
258
-     */
259
-    protected function _set_autosave_containers()
260
-    {
261
-        global $wp_meta_boxes;
262
-        $containers = array();
263
-        if (empty($wp_meta_boxes)) {
264
-            return;
265
-        }
266
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
267
-        foreach ($current_metaboxes as $box_context) {
268
-            foreach ($box_context as $box_details) {
269
-                foreach ($box_details as $box) {
270
-                    if (is_array($box) && is_array($box['callback'])
271
-                        && (
272
-                            $box['callback'][0] instanceof EE_Admin_Page
273
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
274
-                        )
275
-                    ) {
276
-                        $containers[] = $box['id'];
277
-                    }
278
-                }
279
-            }
280
-        }
281
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
282
-        // add hidden inputs container
283
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
284
-    }
285
-
286
-
287
-    protected function _load_autosave_scripts_styles()
288
-    {
289
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
31
+	/**
32
+	 * This gets set in _setup_cpt
33
+	 * It will contain the object for the custom post type.
34
+	 *
35
+	 * @var EE_CPT_Base
36
+	 */
37
+	protected $_cpt_object;
38
+
39
+
40
+	/**
41
+	 * a boolean flag to set whether the current route is a cpt route or not.
42
+	 *
43
+	 * @var bool
44
+	 */
45
+	protected $_cpt_route = false;
46
+
47
+
48
+	/**
49
+	 * This property allows cpt classes to define multiple routes as cpt routes.
50
+	 * //in this array we define what the custom post type for this route is.
51
+	 * array(
52
+	 * 'route_name' => 'custom_post_type_slug'
53
+	 * )
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected $_cpt_routes = array();
58
+
59
+
60
+	/**
61
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
+	 * in this format:
63
+	 * array(
64
+	 * 'post_type_slug' => 'edit_route'
65
+	 * )
66
+	 *
67
+	 * @var array
68
+	 */
69
+	protected $_cpt_edit_routes = array();
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+	/**
89
+	 * @var LoaderInterface $loader ;
90
+	 */
91
+	protected $loader;
92
+
93
+	/**
94
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
95
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
96
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
97
+	 * Registration of containers should be done before load_page_dependencies() is run.
98
+	 *
99
+	 * @var array()
100
+	 */
101
+	protected $_autosave_containers = array();
102
+	protected $_autosave_fields = array();
103
+
104
+	/**
105
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
106
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
107
+	 *
108
+	 * @var array
109
+	 */
110
+	protected $_pagenow_map;
111
+
112
+
113
+	/**
114
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
115
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
116
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
117
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
118
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
119
+	 *
120
+	 * @access protected
121
+	 * @abstract
122
+	 * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
123
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
124
+	 * @return void
125
+	 */
126
+	abstract protected function _insert_update_cpt_item($post_id, $post);
127
+
128
+
129
+	/**
130
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
131
+	 *
132
+	 * @abstract
133
+	 * @access public
134
+	 * @param  string $post_id The ID of the cpt that was trashed
135
+	 * @return void
136
+	 */
137
+	abstract public function trash_cpt_item($post_id);
138
+
139
+
140
+	/**
141
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
+	 *
143
+	 * @param  string $post_id theID of the cpt that was untrashed
144
+	 * @return void
145
+	 */
146
+	abstract public function restore_cpt_item($post_id);
147
+
148
+
149
+	/**
150
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
151
+	 * from the db
152
+	 *
153
+	 * @param  string $post_id the ID of the cpt that was deleted
154
+	 * @return void
155
+	 */
156
+	abstract public function delete_cpt_item($post_id);
157
+
158
+
159
+	/**
160
+	 * @return LoaderInterface
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 */
165
+	protected function getLoader()
166
+	{
167
+		if (! $this->loader instanceof LoaderInterface) {
168
+			$this->loader = LoaderFactory::getLoader();
169
+		}
170
+		return $this->loader;
171
+	}
172
+
173
+	/**
174
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
175
+	 *
176
+	 * @access protected
177
+	 * @return void
178
+	 */
179
+	protected function _before_page_setup()
180
+	{
181
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
182
+		$this->_cpt_routes = array_merge(
183
+			array(
184
+				'create_new' => $this->page_slug,
185
+				'edit'       => $this->page_slug,
186
+				'trash'      => $this->page_slug,
187
+			),
188
+			$this->_cpt_routes
189
+		);
190
+		// let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
191
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
192
+			? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
193
+			: get_post_type_object($page);
194
+		// tweak pagenow for page loading.
195
+		if (! $this->_pagenow_map) {
196
+			$this->_pagenow_map = array(
197
+				'create_new' => 'post-new.php',
198
+				'edit'       => 'post.php',
199
+				'trash'      => 'post.php',
200
+			);
201
+		}
202
+		add_action('current_screen', array($this, 'modify_pagenow'));
203
+		// TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
204
+		// get current page from autosave
205
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
206
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
207
+			: null;
208
+		$this->_current_page = isset($this->_req_data['current_page'])
209
+			? $this->_req_data['current_page']
210
+			: $current_page;
211
+		// autosave... make sure its only for the correct page
212
+		// if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
213
+		// setup autosave ajax hook
214
+		// add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
215
+		// }
216
+	}
217
+
218
+
219
+	/**
220
+	 * Simply ensure that we simulate the correct post route for cpt screens
221
+	 *
222
+	 * @param WP_Screen $current_screen
223
+	 * @return void
224
+	 */
225
+	public function modify_pagenow($current_screen)
226
+	{
227
+		global $pagenow, $hook_suffix;
228
+		// possibly reset pagenow.
229
+		if (! empty($this->_req_data['page'])
230
+			&& $this->_req_data['page'] == $this->page_slug
231
+			&& ! empty($this->_req_data['action'])
232
+			&& isset($this->_pagenow_map[ $this->_req_data['action'] ])
233
+		) {
234
+			$pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
235
+			$hook_suffix = $pagenow;
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
242
+	 *
243
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
244
+	 *       automatically register the id for the post metabox as a container.
245
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
246
+	 *                    you would send along the id of a metabox container.
247
+	 * @return void
248
+	 */
249
+	protected function _register_autosave_containers($ids)
250
+	{
251
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
252
+	}
253
+
254
+
255
+	/**
256
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
257
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
258
+	 */
259
+	protected function _set_autosave_containers()
260
+	{
261
+		global $wp_meta_boxes;
262
+		$containers = array();
263
+		if (empty($wp_meta_boxes)) {
264
+			return;
265
+		}
266
+		$current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
267
+		foreach ($current_metaboxes as $box_context) {
268
+			foreach ($box_context as $box_details) {
269
+				foreach ($box_details as $box) {
270
+					if (is_array($box) && is_array($box['callback'])
271
+						&& (
272
+							$box['callback'][0] instanceof EE_Admin_Page
273
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
274
+						)
275
+					) {
276
+						$containers[] = $box['id'];
277
+					}
278
+				}
279
+			}
280
+		}
281
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
282
+		// add hidden inputs container
283
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
284
+	}
285
+
286
+
287
+	protected function _load_autosave_scripts_styles()
288
+	{
289
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
290 290
         wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2
291 291
 
292
-        // filter _autosave_containers
293
-        $containers = apply_filters(
294
-            'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
295
-            $this->_autosave_containers,
296
-            $this
297
-        );
298
-        $containers = apply_filters(
299
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
300
-            $containers,
301
-            $this
302
-        );
303
-
304
-        wp_localize_script(
305
-            'event_editor_js',
306
-            'EE_AUTOSAVE_IDS',
307
-            $containers
308
-        ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
309
-
310
-        $unsaved_data_msg = array(
311
-            'eventmsg'     => sprintf(
312
-                wp_strip_all_tags(
313
-                    __(
314
-                        "The changes you made to this %s will be lost if you navigate away from this page.",
315
-                        'event_espresso'
316
-                    )
317
-                ),
318
-                $this->_cpt_object->labels->singular_name
319
-            ),
320
-            'inputChanged' => 0,
321
-        );
322
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
323
-    }
324
-
325
-
326
-    public function load_page_dependencies()
327
-    {
328
-        try {
329
-            $this->_load_page_dependencies();
330
-        } catch (EE_Error $e) {
331
-            $e->get_error();
332
-        }
333
-    }
334
-
335
-
336
-    /**
337
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
338
-     *
339
-     * @access protected
340
-     * @return void
341
-     */
342
-    protected function _load_page_dependencies()
343
-    {
344
-        // we only add stuff if this is a cpt_route!
345
-        if (! $this->_cpt_route) {
346
-            parent::_load_page_dependencies();
347
-            return;
348
-        }
349
-        // now let's do some automatic filters into the wp_system
350
-        // and we'll check to make sure the CHILD class
351
-        // automatically has the required methods in place.
352
-        // the following filters are for setting all the redirects
353
-        // on DEFAULT WP custom post type actions
354
-        // let's add a hidden input to the post-edit form
355
-        // so we know when we have to trigger our custom redirects!
356
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
357
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
358
-        // inject our Admin page nav tabs...
359
-        // let's make sure the nav tabs are set if they aren't already
360
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
361
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
362
-        // modify the post_updated messages array
363
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
364
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
365
-        // cpts use the same format for shortlinks as posts!
366
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
367
-        // This basically allows us to change the title of the "publish" metabox area
368
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
369
-        if (! empty($this->_labels['publishbox'])) {
370
-            $box_label = is_array($this->_labels['publishbox'])
371
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
372
-                ? $this->_labels['publishbox'][ $this->_req_action ]
373
-                : $this->_labels['publishbox'];
374
-            add_meta_box(
375
-                'submitdiv',
376
-                $box_label,
377
-                'post_submit_meta_box',
378
-                $this->_cpt_routes[ $this->_req_action ],
379
-                'side',
380
-                'core'
381
-            );
382
-        }
383
-        // let's add page_templates metabox if this cpt added support for it.
384
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
385
-            add_meta_box(
386
-                'page_templates',
387
-                __('Page Template', 'event_espresso'),
388
-                array($this, 'page_template_meta_box'),
389
-                $this->_cpt_routes[ $this->_req_action ],
390
-                'side',
391
-                'default'
392
-            );
393
-        }
394
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
395
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
396
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
397
-        }
398
-        // add preview button
399
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
400
-        // insert our own post_stati dropdown
401
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
402
-        // This allows adding additional information to the publish post submitbox on the wp post edit form
403
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
404
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
405
-        }
406
-        // This allows for adding additional stuff after the title field on the wp post edit form.
407
-        // This is also before the wp_editor for post description field.
408
-        if (method_exists($this, 'edit_form_after_title')) {
409
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
410
-        }
411
-        /**
412
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
413
-         */
414
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
415
-        parent::_load_page_dependencies();
416
-        // notice we are ALSO going to load the pagenow hook set for this route
417
-        // (see _before_page_setup for the reset of the pagenow global ).
418
-        // This is for any plugins that are doing things properly
419
-        // and hooking into the load page hook for core wp cpt routes.
420
-        global $pagenow;
421
-        add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
422
-        do_action('load-' . $pagenow);
423
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
424
-        // we route REALLY early.
425
-        try {
426
-            $this->_route_admin_request();
427
-        } catch (EE_Error $e) {
428
-            $e->get_error();
429
-        }
430
-    }
431
-
432
-
433
-    /**
434
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
435
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
436
-     * route instead.
437
-     *
438
-     * @param string $good_protocol_url The escaped url.
439
-     * @param string $original_url      The original url.
440
-     * @param string $_context          The context sent to the esc_url method.
441
-     * @return string possibly a new url for our route.
442
-     */
443
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
444
-    {
445
-        $routes_to_match = array(
446
-            0 => array(
447
-                'edit.php?post_type=espresso_attendees',
448
-                'admin.php?page=espresso_registrations&action=contact_list',
449
-            ),
450
-            1 => array(
451
-                'edit.php?post_type=' . $this->_cpt_object->name,
452
-                'admin.php?page=' . $this->_cpt_object->name,
453
-            ),
454
-        );
455
-        foreach ($routes_to_match as $route_matches) {
456
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
457
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
458
-            }
459
-        }
460
-        return $good_protocol_url;
461
-    }
462
-
463
-
464
-    /**
465
-     * Determine whether the current cpt supports page templates or not.
466
-     *
467
-     * @since %VER%
468
-     * @param string $cpt_name The cpt slug we're checking on.
469
-     * @return bool True supported, false not.
470
-     * @throws InvalidArgumentException
471
-     * @throws InvalidDataTypeException
472
-     * @throws InvalidInterfaceException
473
-     */
474
-    private function _supports_page_templates($cpt_name)
475
-    {
476
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
477
-        $custom_post_types = $this->getLoader()->getShared(
478
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
479
-        );
480
-        $cpt_args = $custom_post_types->getDefinitions();
481
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
482
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
483
-
484
-        // if the installed version of WP is > 4.7 we do some additional checks.
485
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
486
-            $post_templates = wp_get_theme()->get_post_templates();
487
-            // if there are $post_templates for this cpt, then we return false for this method because
488
-            // that means we aren't going to load our page template manager and leave that up to the native
489
-            // cpt template manager.
490
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
491
-        }
492
-
493
-        return $cpt_has_support;
494
-    }
495
-
496
-
497
-    /**
498
-     * Callback for the page_templates metabox selector.
499
-     *
500
-     * @since %VER%
501
-     * @return void
502
-     */
503
-    public function page_template_meta_box()
504
-    {
505
-        global $post;
506
-        $template = '';
507
-
508
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
509
-            $page_template_count = count(get_page_templates());
510
-        } else {
511
-            $page_template_count = count(get_page_templates($post));
512
-        };
513
-
514
-        if ($page_template_count) {
515
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
516
-            $template = ! empty($page_template) ? $page_template : '';
517
-        }
518
-        ?>
292
+		// filter _autosave_containers
293
+		$containers = apply_filters(
294
+			'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
295
+			$this->_autosave_containers,
296
+			$this
297
+		);
298
+		$containers = apply_filters(
299
+			'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
300
+			$containers,
301
+			$this
302
+		);
303
+
304
+		wp_localize_script(
305
+			'event_editor_js',
306
+			'EE_AUTOSAVE_IDS',
307
+			$containers
308
+		); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
309
+
310
+		$unsaved_data_msg = array(
311
+			'eventmsg'     => sprintf(
312
+				wp_strip_all_tags(
313
+					__(
314
+						"The changes you made to this %s will be lost if you navigate away from this page.",
315
+						'event_espresso'
316
+					)
317
+				),
318
+				$this->_cpt_object->labels->singular_name
319
+			),
320
+			'inputChanged' => 0,
321
+		);
322
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
323
+	}
324
+
325
+
326
+	public function load_page_dependencies()
327
+	{
328
+		try {
329
+			$this->_load_page_dependencies();
330
+		} catch (EE_Error $e) {
331
+			$e->get_error();
332
+		}
333
+	}
334
+
335
+
336
+	/**
337
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
338
+	 *
339
+	 * @access protected
340
+	 * @return void
341
+	 */
342
+	protected function _load_page_dependencies()
343
+	{
344
+		// we only add stuff if this is a cpt_route!
345
+		if (! $this->_cpt_route) {
346
+			parent::_load_page_dependencies();
347
+			return;
348
+		}
349
+		// now let's do some automatic filters into the wp_system
350
+		// and we'll check to make sure the CHILD class
351
+		// automatically has the required methods in place.
352
+		// the following filters are for setting all the redirects
353
+		// on DEFAULT WP custom post type actions
354
+		// let's add a hidden input to the post-edit form
355
+		// so we know when we have to trigger our custom redirects!
356
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
357
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
358
+		// inject our Admin page nav tabs...
359
+		// let's make sure the nav tabs are set if they aren't already
360
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
361
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
362
+		// modify the post_updated messages array
363
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
364
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
365
+		// cpts use the same format for shortlinks as posts!
366
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
367
+		// This basically allows us to change the title of the "publish" metabox area
368
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
369
+		if (! empty($this->_labels['publishbox'])) {
370
+			$box_label = is_array($this->_labels['publishbox'])
371
+						 && isset($this->_labels['publishbox'][ $this->_req_action ])
372
+				? $this->_labels['publishbox'][ $this->_req_action ]
373
+				: $this->_labels['publishbox'];
374
+			add_meta_box(
375
+				'submitdiv',
376
+				$box_label,
377
+				'post_submit_meta_box',
378
+				$this->_cpt_routes[ $this->_req_action ],
379
+				'side',
380
+				'core'
381
+			);
382
+		}
383
+		// let's add page_templates metabox if this cpt added support for it.
384
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
385
+			add_meta_box(
386
+				'page_templates',
387
+				__('Page Template', 'event_espresso'),
388
+				array($this, 'page_template_meta_box'),
389
+				$this->_cpt_routes[ $this->_req_action ],
390
+				'side',
391
+				'default'
392
+			);
393
+		}
394
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
395
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
396
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
397
+		}
398
+		// add preview button
399
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
400
+		// insert our own post_stati dropdown
401
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
402
+		// This allows adding additional information to the publish post submitbox on the wp post edit form
403
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
404
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
405
+		}
406
+		// This allows for adding additional stuff after the title field on the wp post edit form.
407
+		// This is also before the wp_editor for post description field.
408
+		if (method_exists($this, 'edit_form_after_title')) {
409
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
410
+		}
411
+		/**
412
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
413
+		 */
414
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
415
+		parent::_load_page_dependencies();
416
+		// notice we are ALSO going to load the pagenow hook set for this route
417
+		// (see _before_page_setup for the reset of the pagenow global ).
418
+		// This is for any plugins that are doing things properly
419
+		// and hooking into the load page hook for core wp cpt routes.
420
+		global $pagenow;
421
+		add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
422
+		do_action('load-' . $pagenow);
423
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
424
+		// we route REALLY early.
425
+		try {
426
+			$this->_route_admin_request();
427
+		} catch (EE_Error $e) {
428
+			$e->get_error();
429
+		}
430
+	}
431
+
432
+
433
+	/**
434
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
435
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
436
+	 * route instead.
437
+	 *
438
+	 * @param string $good_protocol_url The escaped url.
439
+	 * @param string $original_url      The original url.
440
+	 * @param string $_context          The context sent to the esc_url method.
441
+	 * @return string possibly a new url for our route.
442
+	 */
443
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
444
+	{
445
+		$routes_to_match = array(
446
+			0 => array(
447
+				'edit.php?post_type=espresso_attendees',
448
+				'admin.php?page=espresso_registrations&action=contact_list',
449
+			),
450
+			1 => array(
451
+				'edit.php?post_type=' . $this->_cpt_object->name,
452
+				'admin.php?page=' . $this->_cpt_object->name,
453
+			),
454
+		);
455
+		foreach ($routes_to_match as $route_matches) {
456
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
457
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
458
+			}
459
+		}
460
+		return $good_protocol_url;
461
+	}
462
+
463
+
464
+	/**
465
+	 * Determine whether the current cpt supports page templates or not.
466
+	 *
467
+	 * @since %VER%
468
+	 * @param string $cpt_name The cpt slug we're checking on.
469
+	 * @return bool True supported, false not.
470
+	 * @throws InvalidArgumentException
471
+	 * @throws InvalidDataTypeException
472
+	 * @throws InvalidInterfaceException
473
+	 */
474
+	private function _supports_page_templates($cpt_name)
475
+	{
476
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
477
+		$custom_post_types = $this->getLoader()->getShared(
478
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
479
+		);
480
+		$cpt_args = $custom_post_types->getDefinitions();
481
+		$cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
482
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
483
+
484
+		// if the installed version of WP is > 4.7 we do some additional checks.
485
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
486
+			$post_templates = wp_get_theme()->get_post_templates();
487
+			// if there are $post_templates for this cpt, then we return false for this method because
488
+			// that means we aren't going to load our page template manager and leave that up to the native
489
+			// cpt template manager.
490
+			$cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
491
+		}
492
+
493
+		return $cpt_has_support;
494
+	}
495
+
496
+
497
+	/**
498
+	 * Callback for the page_templates metabox selector.
499
+	 *
500
+	 * @since %VER%
501
+	 * @return void
502
+	 */
503
+	public function page_template_meta_box()
504
+	{
505
+		global $post;
506
+		$template = '';
507
+
508
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
509
+			$page_template_count = count(get_page_templates());
510
+		} else {
511
+			$page_template_count = count(get_page_templates($post));
512
+		};
513
+
514
+		if ($page_template_count) {
515
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
516
+			$template = ! empty($page_template) ? $page_template : '';
517
+		}
518
+		?>
519 519
         <p><strong><?php _e('Template', 'event_espresso') ?></strong></p>
520 520
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'event_espresso') ?></label><select
521 521
         name="page_template" id="page_template">
@@ -523,471 +523,471 @@  discard block
 block discarded – undo
523 523
         <?php page_template_dropdown($template); ?>
524 524
     </select>
525 525
         <?php
526
-    }
527
-
528
-
529
-    /**
530
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
531
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
532
-     *
533
-     * @param  string $return    the current html
534
-     * @param  int    $id        the post id for the page
535
-     * @param  string $new_title What the title is
536
-     * @param  string $new_slug  what the slug is
537
-     * @return string            The new html string for the permalink area
538
-     */
539
-    public function preview_button_html($return, $id, $new_title, $new_slug)
540
-    {
541
-        $post = get_post($id);
542
-        if ('publish' !== get_post_status($post)) {
543
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
544
-                       . get_preview_post_link($id)
545
-                       . '" class="button button-small">'
546
-                       . __('Preview', 'event_espresso')
547
-                       . '</a></span>'
548
-                       . "\n";
549
-        }
550
-        return $return;
551
-    }
552
-
553
-
554
-    /**
555
-     * add our custom post stati dropdown on the wp post page for this cpt
556
-     *
557
-     * @return void
558
-     */
559
-    public function custom_post_stati_dropdown()
560
-    {
561
-
562
-        $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
563
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
564
-            ? $statuses[ $this->_cpt_model_obj->status() ]
565
-            : '';
566
-        $template_args = array(
567
-            'cur_status'            => $this->_cpt_model_obj->status(),
568
-            'statuses'              => $statuses,
569
-            'cur_status_label'      => $cur_status_label,
570
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
571
-        );
572
-        // we'll add a trash post status (WP doesn't add one for some reason)
573
-        if ($this->_cpt_model_obj->status() === 'trash') {
574
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
575
-            $statuses['trash'] = __('Trashed', 'event_espresso');
576
-            $template_args['statuses'] = $statuses;
577
-        }
578
-
579
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
580
-        EEH_Template::display_template($template, $template_args);
581
-    }
582
-
583
-
584
-    public function setup_autosave_hooks()
585
-    {
586
-        $this->_set_autosave_containers();
587
-        $this->_load_autosave_scripts_styles();
588
-    }
589
-
590
-
591
-    /**
592
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
593
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
594
-     * for the nonce in here, but then this method looks for two things:
595
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
596
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
597
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
598
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
599
-     * template args.
600
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
601
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
602
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
603
-     *    $this->_template_args['data']['items'] = array(
604
-     *        'event-datetime-ids' => '1,2,3';
605
-     *    );
606
-     *    Keep in mind the following things:
607
-     *    - "where" index is for the input with the id as that string.
608
-     *    - "what" index is what will be used for the value of that input.
609
-     *
610
-     * @return void
611
-     */
612
-    public function do_extra_autosave_stuff()
613
-    {
614
-        // next let's check for the autosave nonce (we'll use _verify_nonce )
615
-        $nonce = isset($this->_req_data['autosavenonce'])
616
-            ? $this->_req_data['autosavenonce']
617
-            : null;
618
-        $this->_verify_nonce($nonce, 'autosave');
619
-        // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
620
-        if (! defined('DOING_AUTOSAVE')) {
621
-            define('DOING_AUTOSAVE', true);
622
-        }
623
-        // if we made it here then the nonce checked out.  Let's run our methods and actions
624
-        $autosave = "_ee_autosave_{$this->_current_view}";
625
-        if (method_exists($this, $autosave)) {
626
-            $this->$autosave();
627
-        } else {
628
-            $this->_template_args['success'] = true;
629
-        }
630
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
631
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
632
-        // now let's return json
633
-        $this->_return_json();
634
-    }
635
-
636
-
637
-    /**
638
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
639
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
640
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
641
-     *
642
-     * @access protected
643
-     * @throws EE_Error
644
-     * @return void
645
-     */
646
-    protected function _extend_page_config_for_cpt()
647
-    {
648
-        // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
649
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
650
-            return;
651
-        }
652
-        // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
653
-        if (! empty($this->_cpt_object)) {
654
-            $this->_page_routes = array_merge(
655
-                array(
656
-                    'create_new' => '_create_new_cpt_item',
657
-                    'edit'       => '_edit_cpt_item',
658
-                ),
659
-                $this->_page_routes
660
-            );
661
-            $this->_page_config = array_merge(
662
-                array(
663
-                    'create_new' => array(
664
-                        'nav'           => array(
665
-                            'label' => $this->_cpt_object->labels->add_new_item,
666
-                            'order' => 5,
667
-                        ),
668
-                        'require_nonce' => false,
669
-                    ),
670
-                    'edit'       => array(
671
-                        'nav'           => array(
672
-                            'label'      => $this->_cpt_object->labels->edit_item,
673
-                            'order'      => 5,
674
-                            'persistent' => false,
675
-                            'url'        => '',
676
-                        ),
677
-                        'require_nonce' => false,
678
-                    ),
679
-                ),
680
-                $this->_page_config
681
-            );
682
-        }
683
-        // load the next section only if this is a matching cpt route as set in the cpt routes array.
684
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
685
-            return;
686
-        }
687
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
688
-        // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
689
-        if (empty($this->_cpt_object)) {
690
-            $msg = sprintf(
691
-                __(
692
-                    'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
693
-                    'event_espresso'
694
-                ),
695
-                $this->page_slug,
696
-                $this->_req_action,
697
-                get_class($this)
698
-            );
699
-            throw new EE_Error($msg);
700
-        }
701
-        if ($this->_cpt_route) {
702
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
703
-            $this->_set_model_object($id);
704
-        }
705
-    }
706
-
707
-
708
-    /**
709
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
710
-     *
711
-     * @access protected
712
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
713
-     * @param bool   $ignore_route_check
714
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
715
-     * @throws EE_Error
716
-     * @throws InvalidArgumentException
717
-     * @throws InvalidDataTypeException
718
-     * @throws InvalidInterfaceException
719
-     * @throws ReflectionException
720
-     */
721
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
722
-    {
723
-        $model = null;
724
-        if (empty($this->_cpt_model_names)
725
-            || (
726
-                ! $ignore_route_check
727
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
728
-            ) || (
729
-                $this->_cpt_model_obj instanceof EE_CPT_Base
730
-                && $this->_cpt_model_obj->ID() === $id
731
-            )
732
-        ) {
733
-            // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
734
-            return;
735
-        }
736
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
737
-        if ($ignore_route_check) {
738
-            $post_type = get_post_type($id);
739
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
740
-            $custom_post_types = $this->getLoader()->getShared(
741
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
742
-            );
743
-            $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
744
-            if (isset($model_names[ $post_type ])) {
745
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
746
-            }
747
-        } else {
748
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
749
-        }
750
-        if ($model instanceof EEM_Base) {
751
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
752
-        }
753
-        do_action(
754
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
755
-            $this->_cpt_model_obj,
756
-            $req_type
757
-        );
758
-    }
759
-
760
-
761
-    /**
762
-     * admin_init_global
763
-     * This runs all the code that we want executed within the WP admin_init hook.
764
-     * This method executes for ALL EE Admin pages.
765
-     *
766
-     * @access public
767
-     * @return void
768
-     */
769
-    public function admin_init_global()
770
-    {
771
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
772
-        // its possible this is a new save so let's catch that instead
773
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
774
-        $post_type = $post ? $post->post_type : false;
775
-        $current_route = isset($this->_req_data['current_route'])
776
-            ? $this->_req_data['current_route']
777
-            : 'shouldneverwork';
778
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
779
-            ? $this->_cpt_routes[ $current_route ]
780
-            : '';
781
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
782
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
783
-        if ($post_type === $route_to_check) {
784
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
785
-        }
786
-        // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
787
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
788
-        if (! empty($revision)) {
789
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
790
-            // doing a restore?
791
-            if (! empty($action) && $action === 'restore') {
792
-                // get post for revision
793
-                $rev_post = get_post($revision);
794
-                $rev_parent = get_post($rev_post->post_parent);
795
-                // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
796
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
797
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
798
-                    // restores of revisions
799
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
800
-                }
801
-            }
802
-        }
803
-        // NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
804
-        if ($post_type && $post_type === $route_to_check) {
805
-            // $post_id, $post
806
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
807
-            // $post_id
808
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
809
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
810
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
811
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
812
-        }
813
-    }
814
-
815
-
816
-    /**
817
-     * Callback for the WordPress trashed_post hook.
818
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
819
-     *
820
-     * @param int $post_id
821
-     * @throws \EE_Error
822
-     */
823
-    public function before_trash_cpt_item($post_id)
824
-    {
825
-        $this->_set_model_object($post_id, true, 'trash');
826
-        // if our cpt object isn't existent then get out immediately.
827
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
828
-            return;
829
-        }
830
-        $this->trash_cpt_item($post_id);
831
-    }
832
-
833
-
834
-    /**
835
-     * Callback for the WordPress untrashed_post hook.
836
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
837
-     *
838
-     * @param $post_id
839
-     * @throws \EE_Error
840
-     */
841
-    public function before_restore_cpt_item($post_id)
842
-    {
843
-        $this->_set_model_object($post_id, true, 'restore');
844
-        // if our cpt object isn't existent then get out immediately.
845
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
846
-            return;
847
-        }
848
-        $this->restore_cpt_item($post_id);
849
-    }
850
-
851
-
852
-    /**
853
-     * Callback for the WordPress after_delete_post hook.
854
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
855
-     *
856
-     * @param $post_id
857
-     * @throws \EE_Error
858
-     */
859
-    public function before_delete_cpt_item($post_id)
860
-    {
861
-        $this->_set_model_object($post_id, true, 'delete');
862
-        // if our cpt object isn't existent then get out immediately.
863
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
864
-            return;
865
-        }
866
-        $this->delete_cpt_item($post_id);
867
-    }
868
-
869
-
870
-    /**
871
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
872
-     * accordingly.
873
-     *
874
-     * @access public
875
-     * @throws EE_Error
876
-     * @return void
877
-     */
878
-    public function verify_cpt_object()
879
-    {
880
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
881
-        // verify event object
882
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
883
-            throw new EE_Error(
884
-                sprintf(
885
-                    __(
886
-                        'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
887
-                        'event_espresso'
888
-                    ),
889
-                    $label
890
-                )
891
-            );
892
-        }
893
-        // if auto-draft then throw an error
894
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
895
-            EE_Error::overwrite_errors();
896
-            EE_Error::add_error(
897
-                sprintf(
898
-                    __(
899
-                        'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
900
-                        'event_espresso'
901
-                    ),
902
-                    $label
903
-                ),
904
-                __FILE__,
905
-                __FUNCTION__,
906
-                __LINE__
907
-            );
908
-        }
909
-    }
910
-
911
-
912
-    /**
913
-     * admin_footer_scripts_global
914
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
915
-     * will apply on ALL EE_Admin pages.
916
-     *
917
-     * @access public
918
-     * @return void
919
-     */
920
-    public function admin_footer_scripts_global()
921
-    {
922
-        $this->_add_admin_page_ajax_loading_img();
923
-        $this->_add_admin_page_overlay();
924
-    }
925
-
926
-
927
-    /**
928
-     * add in any global scripts for cpt routes
929
-     *
930
-     * @return void
931
-     */
932
-    public function load_global_scripts_styles()
933
-    {
934
-        parent::load_global_scripts_styles();
935
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
936
-            // setup custom post status object for localize script but only if we've got a cpt object
937
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
938
-            if (! empty($statuses)) {
939
-                // get ALL statuses!
940
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
941
-                // setup object
942
-                $ee_cpt_statuses = array();
943
-                foreach ($statuses as $status => $label) {
944
-                    $ee_cpt_statuses[ $status ] = array(
945
-                        'label'      => $label,
946
-                        'save_label' => sprintf(
947
-                            wp_strip_all_tags(__('Save as %s', 'event_espresso')),
948
-                            $label
949
-                        ),
950
-                    );
951
-                }
952
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
953
-            }
954
-        }
955
-    }
956
-
957
-
958
-    /**
959
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
960
-     * insert/updates
961
-     *
962
-     * @param  int     $post_id ID of post being updated
963
-     * @param  WP_Post $post    Post object from WP
964
-     * @param  bool    $update  Whether this is an update or a new save.
965
-     * @return void
966
-     * @throws \EE_Error
967
-     */
968
-    public function insert_update($post_id, $post, $update)
969
-    {
970
-        // make sure that if this is a revision OR trash action that we don't do any updates!
971
-        if (isset($this->_req_data['action'])
972
-            && (
973
-                $this->_req_data['action'] === 'restore'
974
-                || $this->_req_data['action'] === 'trash'
975
-            )
976
-        ) {
977
-            return;
978
-        }
979
-        $this->_set_model_object($post_id, true, 'insert_update');
980
-        // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
981
-        if ($update
982
-            && (
983
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
984
-                || $this->_cpt_model_obj->ID() !== $post_id
985
-            )
986
-        ) {
987
-            return;
988
-        }
989
-        // check for autosave and update our req_data property accordingly.
990
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
526
+	}
527
+
528
+
529
+	/**
530
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
531
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
532
+	 *
533
+	 * @param  string $return    the current html
534
+	 * @param  int    $id        the post id for the page
535
+	 * @param  string $new_title What the title is
536
+	 * @param  string $new_slug  what the slug is
537
+	 * @return string            The new html string for the permalink area
538
+	 */
539
+	public function preview_button_html($return, $id, $new_title, $new_slug)
540
+	{
541
+		$post = get_post($id);
542
+		if ('publish' !== get_post_status($post)) {
543
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
544
+					   . get_preview_post_link($id)
545
+					   . '" class="button button-small">'
546
+					   . __('Preview', 'event_espresso')
547
+					   . '</a></span>'
548
+					   . "\n";
549
+		}
550
+		return $return;
551
+	}
552
+
553
+
554
+	/**
555
+	 * add our custom post stati dropdown on the wp post page for this cpt
556
+	 *
557
+	 * @return void
558
+	 */
559
+	public function custom_post_stati_dropdown()
560
+	{
561
+
562
+		$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
563
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
564
+			? $statuses[ $this->_cpt_model_obj->status() ]
565
+			: '';
566
+		$template_args = array(
567
+			'cur_status'            => $this->_cpt_model_obj->status(),
568
+			'statuses'              => $statuses,
569
+			'cur_status_label'      => $cur_status_label,
570
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
571
+		);
572
+		// we'll add a trash post status (WP doesn't add one for some reason)
573
+		if ($this->_cpt_model_obj->status() === 'trash') {
574
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
575
+			$statuses['trash'] = __('Trashed', 'event_espresso');
576
+			$template_args['statuses'] = $statuses;
577
+		}
578
+
579
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
580
+		EEH_Template::display_template($template, $template_args);
581
+	}
582
+
583
+
584
+	public function setup_autosave_hooks()
585
+	{
586
+		$this->_set_autosave_containers();
587
+		$this->_load_autosave_scripts_styles();
588
+	}
589
+
590
+
591
+	/**
592
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
593
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
594
+	 * for the nonce in here, but then this method looks for two things:
595
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
596
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
597
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
598
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
599
+	 * template args.
600
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
601
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
602
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
603
+	 *    $this->_template_args['data']['items'] = array(
604
+	 *        'event-datetime-ids' => '1,2,3';
605
+	 *    );
606
+	 *    Keep in mind the following things:
607
+	 *    - "where" index is for the input with the id as that string.
608
+	 *    - "what" index is what will be used for the value of that input.
609
+	 *
610
+	 * @return void
611
+	 */
612
+	public function do_extra_autosave_stuff()
613
+	{
614
+		// next let's check for the autosave nonce (we'll use _verify_nonce )
615
+		$nonce = isset($this->_req_data['autosavenonce'])
616
+			? $this->_req_data['autosavenonce']
617
+			: null;
618
+		$this->_verify_nonce($nonce, 'autosave');
619
+		// make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
620
+		if (! defined('DOING_AUTOSAVE')) {
621
+			define('DOING_AUTOSAVE', true);
622
+		}
623
+		// if we made it here then the nonce checked out.  Let's run our methods and actions
624
+		$autosave = "_ee_autosave_{$this->_current_view}";
625
+		if (method_exists($this, $autosave)) {
626
+			$this->$autosave();
627
+		} else {
628
+			$this->_template_args['success'] = true;
629
+		}
630
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
631
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
632
+		// now let's return json
633
+		$this->_return_json();
634
+	}
635
+
636
+
637
+	/**
638
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
639
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
640
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
641
+	 *
642
+	 * @access protected
643
+	 * @throws EE_Error
644
+	 * @return void
645
+	 */
646
+	protected function _extend_page_config_for_cpt()
647
+	{
648
+		// before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
649
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
650
+			return;
651
+		}
652
+		// set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
653
+		if (! empty($this->_cpt_object)) {
654
+			$this->_page_routes = array_merge(
655
+				array(
656
+					'create_new' => '_create_new_cpt_item',
657
+					'edit'       => '_edit_cpt_item',
658
+				),
659
+				$this->_page_routes
660
+			);
661
+			$this->_page_config = array_merge(
662
+				array(
663
+					'create_new' => array(
664
+						'nav'           => array(
665
+							'label' => $this->_cpt_object->labels->add_new_item,
666
+							'order' => 5,
667
+						),
668
+						'require_nonce' => false,
669
+					),
670
+					'edit'       => array(
671
+						'nav'           => array(
672
+							'label'      => $this->_cpt_object->labels->edit_item,
673
+							'order'      => 5,
674
+							'persistent' => false,
675
+							'url'        => '',
676
+						),
677
+						'require_nonce' => false,
678
+					),
679
+				),
680
+				$this->_page_config
681
+			);
682
+		}
683
+		// load the next section only if this is a matching cpt route as set in the cpt routes array.
684
+		if (! isset($this->_cpt_routes[ $this->_req_action ])) {
685
+			return;
686
+		}
687
+		$this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
688
+		// add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
689
+		if (empty($this->_cpt_object)) {
690
+			$msg = sprintf(
691
+				__(
692
+					'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
693
+					'event_espresso'
694
+				),
695
+				$this->page_slug,
696
+				$this->_req_action,
697
+				get_class($this)
698
+			);
699
+			throw new EE_Error($msg);
700
+		}
701
+		if ($this->_cpt_route) {
702
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
703
+			$this->_set_model_object($id);
704
+		}
705
+	}
706
+
707
+
708
+	/**
709
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
710
+	 *
711
+	 * @access protected
712
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
713
+	 * @param bool   $ignore_route_check
714
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
715
+	 * @throws EE_Error
716
+	 * @throws InvalidArgumentException
717
+	 * @throws InvalidDataTypeException
718
+	 * @throws InvalidInterfaceException
719
+	 * @throws ReflectionException
720
+	 */
721
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
722
+	{
723
+		$model = null;
724
+		if (empty($this->_cpt_model_names)
725
+			|| (
726
+				! $ignore_route_check
727
+				&& ! isset($this->_cpt_routes[ $this->_req_action ])
728
+			) || (
729
+				$this->_cpt_model_obj instanceof EE_CPT_Base
730
+				&& $this->_cpt_model_obj->ID() === $id
731
+			)
732
+		) {
733
+			// get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
734
+			return;
735
+		}
736
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
737
+		if ($ignore_route_check) {
738
+			$post_type = get_post_type($id);
739
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
740
+			$custom_post_types = $this->getLoader()->getShared(
741
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
742
+			);
743
+			$model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
744
+			if (isset($model_names[ $post_type ])) {
745
+				$model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
746
+			}
747
+		} else {
748
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
749
+		}
750
+		if ($model instanceof EEM_Base) {
751
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
752
+		}
753
+		do_action(
754
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
755
+			$this->_cpt_model_obj,
756
+			$req_type
757
+		);
758
+	}
759
+
760
+
761
+	/**
762
+	 * admin_init_global
763
+	 * This runs all the code that we want executed within the WP admin_init hook.
764
+	 * This method executes for ALL EE Admin pages.
765
+	 *
766
+	 * @access public
767
+	 * @return void
768
+	 */
769
+	public function admin_init_global()
770
+	{
771
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
772
+		// its possible this is a new save so let's catch that instead
773
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
774
+		$post_type = $post ? $post->post_type : false;
775
+		$current_route = isset($this->_req_data['current_route'])
776
+			? $this->_req_data['current_route']
777
+			: 'shouldneverwork';
778
+		$route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
779
+			? $this->_cpt_routes[ $current_route ]
780
+			: '';
781
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
782
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
783
+		if ($post_type === $route_to_check) {
784
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
785
+		}
786
+		// now let's filter redirect if we're on a revision page and the revision is for an event CPT.
787
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
788
+		if (! empty($revision)) {
789
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
790
+			// doing a restore?
791
+			if (! empty($action) && $action === 'restore') {
792
+				// get post for revision
793
+				$rev_post = get_post($revision);
794
+				$rev_parent = get_post($rev_post->post_parent);
795
+				// only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
796
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
797
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
798
+					// restores of revisions
799
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
800
+				}
801
+			}
802
+		}
803
+		// NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
804
+		if ($post_type && $post_type === $route_to_check) {
805
+			// $post_id, $post
806
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
807
+			// $post_id
808
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
809
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
810
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
811
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
812
+		}
813
+	}
814
+
815
+
816
+	/**
817
+	 * Callback for the WordPress trashed_post hook.
818
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
819
+	 *
820
+	 * @param int $post_id
821
+	 * @throws \EE_Error
822
+	 */
823
+	public function before_trash_cpt_item($post_id)
824
+	{
825
+		$this->_set_model_object($post_id, true, 'trash');
826
+		// if our cpt object isn't existent then get out immediately.
827
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
828
+			return;
829
+		}
830
+		$this->trash_cpt_item($post_id);
831
+	}
832
+
833
+
834
+	/**
835
+	 * Callback for the WordPress untrashed_post hook.
836
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
837
+	 *
838
+	 * @param $post_id
839
+	 * @throws \EE_Error
840
+	 */
841
+	public function before_restore_cpt_item($post_id)
842
+	{
843
+		$this->_set_model_object($post_id, true, 'restore');
844
+		// if our cpt object isn't existent then get out immediately.
845
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
846
+			return;
847
+		}
848
+		$this->restore_cpt_item($post_id);
849
+	}
850
+
851
+
852
+	/**
853
+	 * Callback for the WordPress after_delete_post hook.
854
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
855
+	 *
856
+	 * @param $post_id
857
+	 * @throws \EE_Error
858
+	 */
859
+	public function before_delete_cpt_item($post_id)
860
+	{
861
+		$this->_set_model_object($post_id, true, 'delete');
862
+		// if our cpt object isn't existent then get out immediately.
863
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
864
+			return;
865
+		}
866
+		$this->delete_cpt_item($post_id);
867
+	}
868
+
869
+
870
+	/**
871
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
872
+	 * accordingly.
873
+	 *
874
+	 * @access public
875
+	 * @throws EE_Error
876
+	 * @return void
877
+	 */
878
+	public function verify_cpt_object()
879
+	{
880
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
881
+		// verify event object
882
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
883
+			throw new EE_Error(
884
+				sprintf(
885
+					__(
886
+						'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
887
+						'event_espresso'
888
+					),
889
+					$label
890
+				)
891
+			);
892
+		}
893
+		// if auto-draft then throw an error
894
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
895
+			EE_Error::overwrite_errors();
896
+			EE_Error::add_error(
897
+				sprintf(
898
+					__(
899
+						'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
900
+						'event_espresso'
901
+					),
902
+					$label
903
+				),
904
+				__FILE__,
905
+				__FUNCTION__,
906
+				__LINE__
907
+			);
908
+		}
909
+	}
910
+
911
+
912
+	/**
913
+	 * admin_footer_scripts_global
914
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
915
+	 * will apply on ALL EE_Admin pages.
916
+	 *
917
+	 * @access public
918
+	 * @return void
919
+	 */
920
+	public function admin_footer_scripts_global()
921
+	{
922
+		$this->_add_admin_page_ajax_loading_img();
923
+		$this->_add_admin_page_overlay();
924
+	}
925
+
926
+
927
+	/**
928
+	 * add in any global scripts for cpt routes
929
+	 *
930
+	 * @return void
931
+	 */
932
+	public function load_global_scripts_styles()
933
+	{
934
+		parent::load_global_scripts_styles();
935
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
936
+			// setup custom post status object for localize script but only if we've got a cpt object
937
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
938
+			if (! empty($statuses)) {
939
+				// get ALL statuses!
940
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
941
+				// setup object
942
+				$ee_cpt_statuses = array();
943
+				foreach ($statuses as $status => $label) {
944
+					$ee_cpt_statuses[ $status ] = array(
945
+						'label'      => $label,
946
+						'save_label' => sprintf(
947
+							wp_strip_all_tags(__('Save as %s', 'event_espresso')),
948
+							$label
949
+						),
950
+					);
951
+				}
952
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
953
+			}
954
+		}
955
+	}
956
+
957
+
958
+	/**
959
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
960
+	 * insert/updates
961
+	 *
962
+	 * @param  int     $post_id ID of post being updated
963
+	 * @param  WP_Post $post    Post object from WP
964
+	 * @param  bool    $update  Whether this is an update or a new save.
965
+	 * @return void
966
+	 * @throws \EE_Error
967
+	 */
968
+	public function insert_update($post_id, $post, $update)
969
+	{
970
+		// make sure that if this is a revision OR trash action that we don't do any updates!
971
+		if (isset($this->_req_data['action'])
972
+			&& (
973
+				$this->_req_data['action'] === 'restore'
974
+				|| $this->_req_data['action'] === 'trash'
975
+			)
976
+		) {
977
+			return;
978
+		}
979
+		$this->_set_model_object($post_id, true, 'insert_update');
980
+		// if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
981
+		if ($update
982
+			&& (
983
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
984
+				|| $this->_cpt_model_obj->ID() !== $post_id
985
+			)
986
+		) {
987
+			return;
988
+		}
989
+		// check for autosave and update our req_data property accordingly.
990
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
991 991
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
992 992
 
993 993
                 foreach ( (array) $values as $key => $value ) {
@@ -997,532 +997,532 @@  discard block
 block discarded – undo
997 997
 
998 998
         }/**/ // TODO reactivate after autosave is implemented in 4.2
999 999
 
1000
-        // take care of updating any selected page_template IF this cpt supports it.
1001
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1002
-            // wp version aware.
1003
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1004
-                $page_templates = wp_get_theme()->get_page_templates();
1005
-            } else {
1006
-                $post->page_template = $this->_req_data['page_template'];
1007
-                $page_templates = wp_get_theme()->get_page_templates($post);
1008
-            }
1009
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1010
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1011
-            } else {
1012
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1013
-            }
1014
-        }
1015
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1016
-            return;
1017
-        } //TODO we'll remove this after reimplementing autosave in 4.2
1018
-        $this->_insert_update_cpt_item($post_id, $post);
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1024
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1025
-     * so we don't have to check for our CPT.
1026
-     *
1027
-     * @param  int $post_id ID of the post
1028
-     * @return void
1029
-     */
1030
-    public function dont_permanently_delete_ee_cpts($post_id)
1031
-    {
1032
-        // only do this if we're actually processing one of our CPTs
1033
-        // if our cpt object isn't existent then get out immediately.
1034
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1035
-            return;
1036
-        }
1037
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1038
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1039
-        // our cpts may have comments so let's take care of that too
1040
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1046
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1047
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1048
-     *
1049
-     * @param  int $post_id     ID of cpt item
1050
-     * @param  int $revision_id ID of revision being restored
1051
-     * @return void
1052
-     */
1053
-    public function restore_revision($post_id, $revision_id)
1054
-    {
1055
-        $this->_restore_cpt_item($post_id, $revision_id);
1056
-        // global action
1057
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1058
-        // class specific action so you can limit hooking into a specific page.
1059
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     * @see restore_revision() for details
1065
-     * @param  int $post_id     ID of cpt item
1066
-     * @param  int $revision_id ID of revision for item
1067
-     * @return void
1068
-     */
1069
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1070
-
1071
-
1072
-    /**
1073
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1074
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1075
-     * To fix we have to reset the current_screen using the page_slug
1076
-     * (which is identical - or should be - to our registered_post_type id.)
1077
-     * Also, since the core WP file loads the admin_header.php for WP
1078
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1079
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1080
-     *
1081
-     * @return void
1082
-     */
1083
-    public function modify_current_screen()
1084
-    {
1085
-        // ONLY do this if the current page_route IS a cpt route
1086
-        if (! $this->_cpt_route) {
1087
-            return;
1088
-        }
1089
-        // routing things REALLY early b/c this is a cpt admin page
1090
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1091
-        $this->_current_screen = get_current_screen();
1092
-        $this->_current_screen->base = 'event-espresso';
1093
-        $this->_add_help_tabs(); // we make sure we add any help tabs back in!
1094
-        /*try {
1000
+		// take care of updating any selected page_template IF this cpt supports it.
1001
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1002
+			// wp version aware.
1003
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1004
+				$page_templates = wp_get_theme()->get_page_templates();
1005
+			} else {
1006
+				$post->page_template = $this->_req_data['page_template'];
1007
+				$page_templates = wp_get_theme()->get_page_templates($post);
1008
+			}
1009
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1010
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1011
+			} else {
1012
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1013
+			}
1014
+		}
1015
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1016
+			return;
1017
+		} //TODO we'll remove this after reimplementing autosave in 4.2
1018
+		$this->_insert_update_cpt_item($post_id, $post);
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1024
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1025
+	 * so we don't have to check for our CPT.
1026
+	 *
1027
+	 * @param  int $post_id ID of the post
1028
+	 * @return void
1029
+	 */
1030
+	public function dont_permanently_delete_ee_cpts($post_id)
1031
+	{
1032
+		// only do this if we're actually processing one of our CPTs
1033
+		// if our cpt object isn't existent then get out immediately.
1034
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1035
+			return;
1036
+		}
1037
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1038
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1039
+		// our cpts may have comments so let's take care of that too
1040
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1046
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1047
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1048
+	 *
1049
+	 * @param  int $post_id     ID of cpt item
1050
+	 * @param  int $revision_id ID of revision being restored
1051
+	 * @return void
1052
+	 */
1053
+	public function restore_revision($post_id, $revision_id)
1054
+	{
1055
+		$this->_restore_cpt_item($post_id, $revision_id);
1056
+		// global action
1057
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1058
+		// class specific action so you can limit hooking into a specific page.
1059
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 * @see restore_revision() for details
1065
+	 * @param  int $post_id     ID of cpt item
1066
+	 * @param  int $revision_id ID of revision for item
1067
+	 * @return void
1068
+	 */
1069
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1070
+
1071
+
1072
+	/**
1073
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1074
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1075
+	 * To fix we have to reset the current_screen using the page_slug
1076
+	 * (which is identical - or should be - to our registered_post_type id.)
1077
+	 * Also, since the core WP file loads the admin_header.php for WP
1078
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1079
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1080
+	 *
1081
+	 * @return void
1082
+	 */
1083
+	public function modify_current_screen()
1084
+	{
1085
+		// ONLY do this if the current page_route IS a cpt route
1086
+		if (! $this->_cpt_route) {
1087
+			return;
1088
+		}
1089
+		// routing things REALLY early b/c this is a cpt admin page
1090
+		set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1091
+		$this->_current_screen = get_current_screen();
1092
+		$this->_current_screen->base = 'event-espresso';
1093
+		$this->_add_help_tabs(); // we make sure we add any help tabs back in!
1094
+		/*try {
1095 1095
             $this->_route_admin_request();
1096 1096
         } catch ( EE_Error $e ) {
1097 1097
             $e->get_error();
1098 1098
         }/**/
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1104
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1105
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1106
-     * default to be.
1107
-     *
1108
-     * @param string $title The new title (or existing if there is no editor_title defined)
1109
-     * @return string
1110
-     */
1111
-    public function add_custom_editor_default_title($title)
1112
-    {
1113
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1114
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1115
-            : $title;
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1121
-     *
1122
-     * @param string $shortlink   The already generated shortlink
1123
-     * @param int    $id          Post ID for this item
1124
-     * @param string $context     The context for the link
1125
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1126
-     * @return string
1127
-     */
1128
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1129
-    {
1130
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1131
-            $post = get_post($id);
1132
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1133
-                $shortlink = home_url('?p=' . $post->ID);
1134
-            }
1135
-        }
1136
-        return $shortlink;
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1142
-     * already run in modify_current_screen())
1143
-     *
1144
-     * @return void
1145
-     */
1146
-    public function route_admin_request()
1147
-    {
1148
-        if ($this->_cpt_route) {
1149
-            return;
1150
-        }
1151
-        try {
1152
-            $this->_route_admin_request();
1153
-        } catch (EE_Error $e) {
1154
-            $e->get_error();
1155
-        }
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1161
-     *
1162
-     * @return void
1163
-     */
1164
-    public function cpt_post_form_hidden_input()
1165
-    {
1166
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1167
-        // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1168
-        echo '<div id="ee-cpt-hidden-inputs">';
1169
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1170
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1171
-        echo '</div>';
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1177
-     *
1178
-     * @param  string $location Original location url
1179
-     * @param  int    $status   Status for http header
1180
-     * @return string           new (or original) url to redirect to.
1181
-     */
1182
-    public function revision_redirect($location, $status)
1183
-    {
1184
-        // get revision
1185
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1186
-        // can't do anything without revision so let's get out if not present
1187
-        if (empty($rev_id)) {
1188
-            return $location;
1189
-        }
1190
-        // get rev_post_data
1191
-        $rev = get_post($rev_id);
1192
-        $admin_url = $this->_admin_base_url;
1193
-        $query_args = array(
1194
-            'action'   => 'edit',
1195
-            'post'     => $rev->post_parent,
1196
-            'revision' => $rev_id,
1197
-            'message'  => 5,
1198
-        );
1199
-        $this->_process_notices($query_args, true);
1200
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1206
-     *
1207
-     * @param  string $link    the original generated link
1208
-     * @param  int    $id      post id
1209
-     * @param  string $context optional, defaults to display.  How to write the '&'
1210
-     * @return string          the link
1211
-     */
1212
-    public function modify_edit_post_link($link, $id, $context)
1213
-    {
1214
-        $post = get_post($id);
1215
-        if (! isset($this->_req_data['action'])
1216
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1217
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1218
-        ) {
1219
-            return $link;
1220
-        }
1221
-        $query_args = array(
1222
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1223
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1224
-                : 'edit',
1225
-            'post'   => $id,
1226
-        );
1227
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1228
-    }
1229
-
1230
-
1231
-    /**
1232
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1233
-     * our routes.
1234
-     *
1235
-     * @param  string $delete_link  original delete link
1236
-     * @param  int    $post_id      id of cpt object
1237
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1238
-     * @return string new delete link
1239
-     * @throws EE_Error
1240
-     */
1241
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1242
-    {
1243
-        $post = get_post($post_id);
1244
-
1245
-        if (empty($this->_req_data['action'])
1246
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1247
-            || ! $post instanceof WP_Post
1248
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1249
-        ) {
1250
-            return $delete_link;
1251
-        }
1252
-        $this->_set_model_object($post->ID, true);
1253
-
1254
-        // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1255
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1256
-
1257
-        return EE_Admin_Page::add_query_args_and_nonce(
1258
-            array(
1259
-                'page'   => $this->_req_data['page'],
1260
-                'action' => $action,
1261
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1262
-                         => $post->ID,
1263
-            ),
1264
-            admin_url()
1265
-        );
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1271
-     * so that we can hijack the default redirect locations for wp custom post types
1272
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1273
-     *
1274
-     * @param  string $location This is the incoming currently set redirect location
1275
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1276
-     * @return string           the new location to redirect to
1277
-     */
1278
-    public function cpt_post_location_redirect($location, $post_id)
1279
-    {
1280
-        // we DO have a match so let's setup the url
1281
-        // we have to get the post to determine our route
1282
-        $post = get_post($post_id);
1283
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1284
-        // shared query_args
1285
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1286
-        $admin_url = $this->_admin_base_url;
1287
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1288
-            $status = get_post_status($post_id);
1289
-            if (isset($this->_req_data['publish'])) {
1290
-                switch ($status) {
1291
-                    case 'pending':
1292
-                        $message = 8;
1293
-                        break;
1294
-                    case 'future':
1295
-                        $message = 9;
1296
-                        break;
1297
-                    default:
1298
-                        $message = 6;
1299
-                }
1300
-            } else {
1301
-                $message = 'draft' === $status ? 10 : 1;
1302
-            }
1303
-        } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1304
-            $message = 2;
1305
-        } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1306
-            $message = 3;
1307
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1308
-            $message = 7;
1309
-        } else {
1310
-            $message = 4;
1311
-        }
1312
-        // change the message if the post type is not viewable on the frontend
1313
-        $this->_cpt_object = get_post_type_object($post->post_type);
1314
-        $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1315
-        $query_args = array_merge(array('message' => $message), $query_args);
1316
-        $this->_process_notices($query_args, true);
1317
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1318
-    }
1319
-
1320
-
1321
-    /**
1322
-     * This method is called to inject nav tabs on core WP cpt pages
1323
-     *
1324
-     * @access public
1325
-     * @return void
1326
-     */
1327
-    public function inject_nav_tabs()
1328
-    {
1329
-        // can we hijack and insert the nav_tabs?
1330
-        $nav_tabs = $this->_get_main_nav_tabs();
1331
-        // first close off existing form tag
1332
-        $html = '>';
1333
-        $html .= $nav_tabs;
1334
-        // now let's handle the remaining tag ( missing ">" is CORRECT )
1335
-        $html .= '<span></span';
1336
-        echo $html;
1337
-    }
1338
-
1339
-
1340
-    /**
1341
-     * This just sets up the post update messages when an update form is loaded
1342
-     *
1343
-     * @access public
1344
-     * @param  array $messages the original messages array
1345
-     * @return array           the new messages array
1346
-     */
1347
-    public function post_update_messages($messages)
1348
-    {
1349
-        global $post;
1350
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1351
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1352
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1104
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1105
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1106
+	 * default to be.
1107
+	 *
1108
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1109
+	 * @return string
1110
+	 */
1111
+	public function add_custom_editor_default_title($title)
1112
+	{
1113
+		return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1114
+			? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1115
+			: $title;
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1121
+	 *
1122
+	 * @param string $shortlink   The already generated shortlink
1123
+	 * @param int    $id          Post ID for this item
1124
+	 * @param string $context     The context for the link
1125
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1126
+	 * @return string
1127
+	 */
1128
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1129
+	{
1130
+		if (! empty($id) && get_option('permalink_structure') !== '') {
1131
+			$post = get_post($id);
1132
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1133
+				$shortlink = home_url('?p=' . $post->ID);
1134
+			}
1135
+		}
1136
+		return $shortlink;
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1142
+	 * already run in modify_current_screen())
1143
+	 *
1144
+	 * @return void
1145
+	 */
1146
+	public function route_admin_request()
1147
+	{
1148
+		if ($this->_cpt_route) {
1149
+			return;
1150
+		}
1151
+		try {
1152
+			$this->_route_admin_request();
1153
+		} catch (EE_Error $e) {
1154
+			$e->get_error();
1155
+		}
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1161
+	 *
1162
+	 * @return void
1163
+	 */
1164
+	public function cpt_post_form_hidden_input()
1165
+	{
1166
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1167
+		// we're also going to add the route value and the current page so we can direct autosave parsing correctly
1168
+		echo '<div id="ee-cpt-hidden-inputs">';
1169
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1170
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1171
+		echo '</div>';
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1177
+	 *
1178
+	 * @param  string $location Original location url
1179
+	 * @param  int    $status   Status for http header
1180
+	 * @return string           new (or original) url to redirect to.
1181
+	 */
1182
+	public function revision_redirect($location, $status)
1183
+	{
1184
+		// get revision
1185
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1186
+		// can't do anything without revision so let's get out if not present
1187
+		if (empty($rev_id)) {
1188
+			return $location;
1189
+		}
1190
+		// get rev_post_data
1191
+		$rev = get_post($rev_id);
1192
+		$admin_url = $this->_admin_base_url;
1193
+		$query_args = array(
1194
+			'action'   => 'edit',
1195
+			'post'     => $rev->post_parent,
1196
+			'revision' => $rev_id,
1197
+			'message'  => 5,
1198
+		);
1199
+		$this->_process_notices($query_args, true);
1200
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1206
+	 *
1207
+	 * @param  string $link    the original generated link
1208
+	 * @param  int    $id      post id
1209
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1210
+	 * @return string          the link
1211
+	 */
1212
+	public function modify_edit_post_link($link, $id, $context)
1213
+	{
1214
+		$post = get_post($id);
1215
+		if (! isset($this->_req_data['action'])
1216
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1217
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1218
+		) {
1219
+			return $link;
1220
+		}
1221
+		$query_args = array(
1222
+			'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1223
+				? $this->_cpt_edit_routes[ $post->post_type ]
1224
+				: 'edit',
1225
+			'post'   => $id,
1226
+		);
1227
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1228
+	}
1229
+
1230
+
1231
+	/**
1232
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1233
+	 * our routes.
1234
+	 *
1235
+	 * @param  string $delete_link  original delete link
1236
+	 * @param  int    $post_id      id of cpt object
1237
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1238
+	 * @return string new delete link
1239
+	 * @throws EE_Error
1240
+	 */
1241
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1242
+	{
1243
+		$post = get_post($post_id);
1244
+
1245
+		if (empty($this->_req_data['action'])
1246
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1247
+			|| ! $post instanceof WP_Post
1248
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1249
+		) {
1250
+			return $delete_link;
1251
+		}
1252
+		$this->_set_model_object($post->ID, true);
1253
+
1254
+		// returns something like `trash_event` or `trash_attendee` or `trash_venue`
1255
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1256
+
1257
+		return EE_Admin_Page::add_query_args_and_nonce(
1258
+			array(
1259
+				'page'   => $this->_req_data['page'],
1260
+				'action' => $action,
1261
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1262
+						 => $post->ID,
1263
+			),
1264
+			admin_url()
1265
+		);
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1271
+	 * so that we can hijack the default redirect locations for wp custom post types
1272
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1273
+	 *
1274
+	 * @param  string $location This is the incoming currently set redirect location
1275
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1276
+	 * @return string           the new location to redirect to
1277
+	 */
1278
+	public function cpt_post_location_redirect($location, $post_id)
1279
+	{
1280
+		// we DO have a match so let's setup the url
1281
+		// we have to get the post to determine our route
1282
+		$post = get_post($post_id);
1283
+		$edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1284
+		// shared query_args
1285
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1286
+		$admin_url = $this->_admin_base_url;
1287
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1288
+			$status = get_post_status($post_id);
1289
+			if (isset($this->_req_data['publish'])) {
1290
+				switch ($status) {
1291
+					case 'pending':
1292
+						$message = 8;
1293
+						break;
1294
+					case 'future':
1295
+						$message = 9;
1296
+						break;
1297
+					default:
1298
+						$message = 6;
1299
+				}
1300
+			} else {
1301
+				$message = 'draft' === $status ? 10 : 1;
1302
+			}
1303
+		} elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1304
+			$message = 2;
1305
+		} elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1306
+			$message = 3;
1307
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1308
+			$message = 7;
1309
+		} else {
1310
+			$message = 4;
1311
+		}
1312
+		// change the message if the post type is not viewable on the frontend
1313
+		$this->_cpt_object = get_post_type_object($post->post_type);
1314
+		$message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1315
+		$query_args = array_merge(array('message' => $message), $query_args);
1316
+		$this->_process_notices($query_args, true);
1317
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1318
+	}
1319
+
1320
+
1321
+	/**
1322
+	 * This method is called to inject nav tabs on core WP cpt pages
1323
+	 *
1324
+	 * @access public
1325
+	 * @return void
1326
+	 */
1327
+	public function inject_nav_tabs()
1328
+	{
1329
+		// can we hijack and insert the nav_tabs?
1330
+		$nav_tabs = $this->_get_main_nav_tabs();
1331
+		// first close off existing form tag
1332
+		$html = '>';
1333
+		$html .= $nav_tabs;
1334
+		// now let's handle the remaining tag ( missing ">" is CORRECT )
1335
+		$html .= '<span></span';
1336
+		echo $html;
1337
+	}
1338
+
1339
+
1340
+	/**
1341
+	 * This just sets up the post update messages when an update form is loaded
1342
+	 *
1343
+	 * @access public
1344
+	 * @param  array $messages the original messages array
1345
+	 * @return array           the new messages array
1346
+	 */
1347
+	public function post_update_messages($messages)
1348
+	{
1349
+		global $post;
1350
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1351
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1352
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1353 1353
 
1354 1354
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1355
-        $messages[ $post->post_type ] = array(
1356
-            0  => '', // Unused. Messages start at index 1.
1357
-            1  => sprintf(
1358
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1359
-                $this->_cpt_object->labels->singular_name,
1360
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1361
-                '</a>'
1362
-            ),
1363
-            2  => __('Custom field updated', 'event_espresso'),
1364
-            3  => __('Custom field deleted.', 'event_espresso'),
1365
-            4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1366
-            5  => isset($_GET['revision']) ? sprintf(
1367
-                __('%s restored to revision from %s', 'event_espresso'),
1368
-                $this->_cpt_object->labels->singular_name,
1369
-                wp_post_revision_title((int) $_GET['revision'], false)
1370
-            )
1371
-                : false,
1372
-            6  => sprintf(
1373
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1374
-                $this->_cpt_object->labels->singular_name,
1375
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1376
-                '</a>'
1377
-            ),
1378
-            7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1379
-            8  => sprintf(
1380
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1381
-                $this->_cpt_object->labels->singular_name,
1382
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1383
-                '</a>'
1384
-            ),
1385
-            9  => sprintf(
1386
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1387
-                $this->_cpt_object->labels->singular_name,
1388
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1389
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1390
-                '</a>'
1391
-            ),
1392
-            10 => sprintf(
1393
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1394
-                $this->_cpt_object->labels->singular_name,
1395
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1396
-                '</a>'
1397
-            ),
1398
-        );
1399
-        return $messages;
1400
-    }
1401
-
1402
-
1403
-    /**
1404
-     * default method for the 'create_new' route for cpt admin pages.
1405
-     * For reference what to include in here, see wp-admin/post-new.php
1406
-     *
1407
-     * @access  protected
1408
-     * @return void
1409
-     */
1410
-    protected function _create_new_cpt_item()
1411
-    {
1412
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1413
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1414
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1415
-        $post_type_object = $this->_cpt_object;
1416
-        $title = $post_type_object->labels->add_new_item;
1417
-        $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1418
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1419
-        // modify the default editor title field with default title.
1420
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1421
-        $this->loadEditorTemplate(true);
1422
-    }
1423
-
1424
-
1425
-    /**
1426
-     * Enqueues auto-save and loads the editor template
1427
-     *
1428
-     * @param bool $creating
1429
-     */
1430
-    private function loadEditorTemplate($creating = true)
1431
-    {
1432
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1433
-        // these vars are used by the template
1434
-        $editing = true;
1435
-        $post_ID = $post->ID;
1436
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1437
-            // only enqueue autosave when creating event (necessary to get permalink/url generated)
1438
-            // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1439
-            if ($creating) {
1440
-                wp_enqueue_script('autosave');
1441
-            } else {
1442
-                if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1443
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1444
-                ) {
1445
-                    $create_new_action = apply_filters(
1446
-                        'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1447
-                        'create_new',
1448
-                        $this
1449
-                    );
1450
-                    $post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1451
-                        array(
1452
-                            'action' => $create_new_action,
1453
-                            'page'   => $this->page_slug,
1454
-                        ),
1455
-                        'admin.php'
1456
-                    );
1457
-                }
1458
-            }
1459
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1460
-        }
1461
-    }
1462
-
1463
-
1464
-    public function add_new_admin_page_global()
1465
-    {
1466
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1467
-        ?>
1355
+		$messages[ $post->post_type ] = array(
1356
+			0  => '', // Unused. Messages start at index 1.
1357
+			1  => sprintf(
1358
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1359
+				$this->_cpt_object->labels->singular_name,
1360
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1361
+				'</a>'
1362
+			),
1363
+			2  => __('Custom field updated', 'event_espresso'),
1364
+			3  => __('Custom field deleted.', 'event_espresso'),
1365
+			4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1366
+			5  => isset($_GET['revision']) ? sprintf(
1367
+				__('%s restored to revision from %s', 'event_espresso'),
1368
+				$this->_cpt_object->labels->singular_name,
1369
+				wp_post_revision_title((int) $_GET['revision'], false)
1370
+			)
1371
+				: false,
1372
+			6  => sprintf(
1373
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1374
+				$this->_cpt_object->labels->singular_name,
1375
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1376
+				'</a>'
1377
+			),
1378
+			7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1379
+			8  => sprintf(
1380
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1381
+				$this->_cpt_object->labels->singular_name,
1382
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1383
+				'</a>'
1384
+			),
1385
+			9  => sprintf(
1386
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1387
+				$this->_cpt_object->labels->singular_name,
1388
+				'<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1389
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1390
+				'</a>'
1391
+			),
1392
+			10 => sprintf(
1393
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1394
+				$this->_cpt_object->labels->singular_name,
1395
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1396
+				'</a>'
1397
+			),
1398
+		);
1399
+		return $messages;
1400
+	}
1401
+
1402
+
1403
+	/**
1404
+	 * default method for the 'create_new' route for cpt admin pages.
1405
+	 * For reference what to include in here, see wp-admin/post-new.php
1406
+	 *
1407
+	 * @access  protected
1408
+	 * @return void
1409
+	 */
1410
+	protected function _create_new_cpt_item()
1411
+	{
1412
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1413
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1414
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1415
+		$post_type_object = $this->_cpt_object;
1416
+		$title = $post_type_object->labels->add_new_item;
1417
+		$post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1418
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1419
+		// modify the default editor title field with default title.
1420
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1421
+		$this->loadEditorTemplate(true);
1422
+	}
1423
+
1424
+
1425
+	/**
1426
+	 * Enqueues auto-save and loads the editor template
1427
+	 *
1428
+	 * @param bool $creating
1429
+	 */
1430
+	private function loadEditorTemplate($creating = true)
1431
+	{
1432
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1433
+		// these vars are used by the template
1434
+		$editing = true;
1435
+		$post_ID = $post->ID;
1436
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1437
+			// only enqueue autosave when creating event (necessary to get permalink/url generated)
1438
+			// otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1439
+			if ($creating) {
1440
+				wp_enqueue_script('autosave');
1441
+			} else {
1442
+				if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1443
+					&& ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1444
+				) {
1445
+					$create_new_action = apply_filters(
1446
+						'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1447
+						'create_new',
1448
+						$this
1449
+					);
1450
+					$post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1451
+						array(
1452
+							'action' => $create_new_action,
1453
+							'page'   => $this->page_slug,
1454
+						),
1455
+						'admin.php'
1456
+					);
1457
+				}
1458
+			}
1459
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1460
+		}
1461
+	}
1462
+
1463
+
1464
+	public function add_new_admin_page_global()
1465
+	{
1466
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1467
+		?>
1468 1468
         <script type="text/javascript">
1469 1469
             adminpage = '<?php echo $admin_page; ?>';
1470 1470
         </script>
1471 1471
         <?php
1472
-    }
1473
-
1474
-
1475
-    /**
1476
-     * default method for the 'edit' route for cpt admin pages
1477
-     * For reference on what to put in here, refer to wp-admin/post.php
1478
-     *
1479
-     * @access protected
1480
-     * @return string   template for edit cpt form
1481
-     */
1482
-    protected function _edit_cpt_item()
1483
-    {
1484
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1485
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1486
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1487
-        if (empty($post)) {
1488
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1489
-        }
1490
-        if (! empty($_GET['get-post-lock'])) {
1491
-            wp_set_post_lock($post_id);
1492
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1493
-            exit();
1494
-        }
1495
-
1496
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1497
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1498
-        $post_type_object = $this->_cpt_object;
1499
-
1500
-        if (! wp_check_post_lock($post->ID)) {
1501
-            wp_set_post_lock($post->ID);
1502
-        }
1503
-        add_action('admin_footer', '_admin_notice_post_locked');
1504
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1505
-            wp_enqueue_script('admin-comments');
1506
-            enqueue_comment_hotkeys_js();
1507
-        }
1508
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1509
-        // modify the default editor title field with default title.
1510
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1511
-        $this->loadEditorTemplate(false);
1512
-    }
1513
-
1514
-
1515
-
1516
-    /**
1517
-     * some getters
1518
-     */
1519
-    /**
1520
-     * This returns the protected _cpt_model_obj property
1521
-     *
1522
-     * @return EE_CPT_Base
1523
-     */
1524
-    public function get_cpt_model_obj()
1525
-    {
1526
-        return $this->_cpt_model_obj;
1527
-    }
1472
+	}
1473
+
1474
+
1475
+	/**
1476
+	 * default method for the 'edit' route for cpt admin pages
1477
+	 * For reference on what to put in here, refer to wp-admin/post.php
1478
+	 *
1479
+	 * @access protected
1480
+	 * @return string   template for edit cpt form
1481
+	 */
1482
+	protected function _edit_cpt_item()
1483
+	{
1484
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1485
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1486
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1487
+		if (empty($post)) {
1488
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1489
+		}
1490
+		if (! empty($_GET['get-post-lock'])) {
1491
+			wp_set_post_lock($post_id);
1492
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1493
+			exit();
1494
+		}
1495
+
1496
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1497
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1498
+		$post_type_object = $this->_cpt_object;
1499
+
1500
+		if (! wp_check_post_lock($post->ID)) {
1501
+			wp_set_post_lock($post->ID);
1502
+		}
1503
+		add_action('admin_footer', '_admin_notice_post_locked');
1504
+		if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1505
+			wp_enqueue_script('admin-comments');
1506
+			enqueue_comment_hotkeys_js();
1507
+		}
1508
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1509
+		// modify the default editor title field with default title.
1510
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1511
+		$this->loadEditorTemplate(false);
1512
+	}
1513
+
1514
+
1515
+
1516
+	/**
1517
+	 * some getters
1518
+	 */
1519
+	/**
1520
+	 * This returns the protected _cpt_model_obj property
1521
+	 *
1522
+	 * @return EE_CPT_Base
1523
+	 */
1524
+	public function get_cpt_model_obj()
1525
+	{
1526
+		return $this->_cpt_model_obj;
1527
+	}
1528 1528
 }
Please login to merge, or discard this patch.
modules/batch/EED_Batch.module.php 2 patches
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -29,360 +29,360 @@
 block discarded – undo
29 29
 class EED_Batch extends EED_Module
30 30
 {
31 31
 
32
-    /**
33
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
34
-     * processes data only
35
-     */
36
-    const batch_job = 'job';
37
-    /**
38
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
39
-     * produces a file for download
40
-     */
41
-    const batch_file_job = 'file';
42
-    /**
43
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
44
-     * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
45
-     * at all
46
-     */
47
-    const batch_not_job = 'none';
32
+	/**
33
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
34
+	 * processes data only
35
+	 */
36
+	const batch_job = 'job';
37
+	/**
38
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
39
+	 * produces a file for download
40
+	 */
41
+	const batch_file_job = 'file';
42
+	/**
43
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
44
+	 * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
45
+	 * at all
46
+	 */
47
+	const batch_not_job = 'none';
48 48
 
49
-    /**
50
-     *
51
-     * @var string 'file', or 'job', or false to indicate its not a batch request at all
52
-     */
53
-    protected $_batch_request_type = null;
49
+	/**
50
+	 *
51
+	 * @var string 'file', or 'job', or false to indicate its not a batch request at all
52
+	 */
53
+	protected $_batch_request_type = null;
54 54
 
55
-    /**
56
-     * Because we want to use the response in both the localized JS and in the body
57
-     * we need to make this response available between method calls
58
-     *
59
-     * @var \EventEspressoBatchRequest\Helpers\JobStepResponse
60
-     */
61
-    protected $_job_step_response = null;
55
+	/**
56
+	 * Because we want to use the response in both the localized JS and in the body
57
+	 * we need to make this response available between method calls
58
+	 *
59
+	 * @var \EventEspressoBatchRequest\Helpers\JobStepResponse
60
+	 */
61
+	protected $_job_step_response = null;
62 62
 
63
-    /**
64
-     * @var LoaderInterface
65
-     */
66
-    protected $loader;
63
+	/**
64
+	 * @var LoaderInterface
65
+	 */
66
+	protected $loader;
67 67
 
68
-    /**
69
-     * Gets the batch instance
70
-     *
71
-     * @return EED_Batch
72
-     */
73
-    public static function instance()
74
-    {
75
-        return self::get_instance();
76
-    }
68
+	/**
69
+	 * Gets the batch instance
70
+	 *
71
+	 * @return EED_Batch
72
+	 */
73
+	public static function instance()
74
+	{
75
+		return self::get_instance();
76
+	}
77 77
 
78
-    /**
79
-     * Sets hooks to enable batch jobs on the frontend. Disabled by default
80
-     * because it's an attack vector and there are currently no implementations
81
-     */
82
-    public static function set_hooks()
83
-    {
84
-        // because this is a possibel attack vector, let's have this disabled until
85
-        // we at least have a real use for it on the frontend
86
-        if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
87
-            add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
88
-            add_filter('template_include', array(self::instance(), 'override_template'), 99);
89
-        }
90
-    }
78
+	/**
79
+	 * Sets hooks to enable batch jobs on the frontend. Disabled by default
80
+	 * because it's an attack vector and there are currently no implementations
81
+	 */
82
+	public static function set_hooks()
83
+	{
84
+		// because this is a possibel attack vector, let's have this disabled until
85
+		// we at least have a real use for it on the frontend
86
+		if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
87
+			add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
88
+			add_filter('template_include', array(self::instance(), 'override_template'), 99);
89
+		}
90
+	}
91 91
 
92
-    /**
93
-     * Initializes some hooks for the admin in order to run batch jobs
94
-     */
95
-    public static function set_hooks_admin()
96
-    {
97
-        add_action('admin_menu', array(self::instance(), 'register_admin_pages'));
98
-        add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
92
+	/**
93
+	 * Initializes some hooks for the admin in order to run batch jobs
94
+	 */
95
+	public static function set_hooks_admin()
96
+	{
97
+		add_action('admin_menu', array(self::instance(), 'register_admin_pages'));
98
+		add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
99 99
 
100
-        // ajax
101
-        add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue'));
102
-        add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
103
-        add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue'));
104
-        add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
105
-    }
100
+		// ajax
101
+		add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue'));
102
+		add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
103
+		add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue'));
104
+		add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
105
+	}
106 106
 
107
-    /**
108
-     * @since 4.9.80.p
109
-     * @return LoaderInterface
110
-     * @throws InvalidArgumentException
111
-     * @throws InvalidDataTypeException
112
-     * @throws InvalidInterfaceException
113
-     */
114
-    protected function getLoader()
115
-    {
116
-        if (!$this->loader instanceof LoaderInterface) {
117
-            $this->loader = LoaderFactory::getLoader();
118
-        }
119
-        return $this->loader;
120
-    }
107
+	/**
108
+	 * @since 4.9.80.p
109
+	 * @return LoaderInterface
110
+	 * @throws InvalidArgumentException
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws InvalidInterfaceException
113
+	 */
114
+	protected function getLoader()
115
+	{
116
+		if (!$this->loader instanceof LoaderInterface) {
117
+			$this->loader = LoaderFactory::getLoader();
118
+		}
119
+		return $this->loader;
120
+	}
121 121
 
122
-    /**
123
-     * Enqueues batch scripts on the frontend or admin, and creates a job
124
-     */
125
-    public function enqueue_scripts()
126
-    {
127
-        if (isset($_REQUEST['espresso_batch'])
128
-            ||
129
-            (
130
-                isset($_REQUEST['page'])
131
-                && $_REQUEST['page'] == 'espresso_batch'
132
-            )
133
-        ) {
134
-            if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
135
-                wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso'));
136
-            }
137
-            switch ($this->batch_request_type()) {
138
-                case self::batch_job:
139
-                    $this->enqueue_scripts_styles_batch_create();
140
-                    break;
141
-                case self::batch_file_job:
142
-                    $this->enqueue_scripts_styles_batch_file_create();
143
-                    break;
144
-            }
145
-        }
146
-    }
122
+	/**
123
+	 * Enqueues batch scripts on the frontend or admin, and creates a job
124
+	 */
125
+	public function enqueue_scripts()
126
+	{
127
+		if (isset($_REQUEST['espresso_batch'])
128
+			||
129
+			(
130
+				isset($_REQUEST['page'])
131
+				&& $_REQUEST['page'] == 'espresso_batch'
132
+			)
133
+		) {
134
+			if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
135
+				wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso'));
136
+			}
137
+			switch ($this->batch_request_type()) {
138
+				case self::batch_job:
139
+					$this->enqueue_scripts_styles_batch_create();
140
+					break;
141
+				case self::batch_file_job:
142
+					$this->enqueue_scripts_styles_batch_file_create();
143
+					break;
144
+			}
145
+		}
146
+	}
147 147
 
148
-    /**
149
-     * Create a batch job, enqueues a script to run it, and localizes some data for it
150
-     */
151
-    public function enqueue_scripts_styles_batch_create()
152
-    {
153
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
154
-        wp_enqueue_script(
155
-            'batch_runner_init',
156
-            BATCH_URL . 'assets/batch_runner_init.js',
157
-            array('batch_runner'),
158
-            EVENT_ESPRESSO_VERSION,
159
-            true
160
-        );
161
-        wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
162
-        wp_localize_script(
163
-            'batch_runner_init',
164
-            'ee_job_i18n',
165
-            array(
166
-                'return_url' => $_REQUEST['return_url'],
167
-            )
168
-        );
169
-    }
148
+	/**
149
+	 * Create a batch job, enqueues a script to run it, and localizes some data for it
150
+	 */
151
+	public function enqueue_scripts_styles_batch_create()
152
+	{
153
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
154
+		wp_enqueue_script(
155
+			'batch_runner_init',
156
+			BATCH_URL . 'assets/batch_runner_init.js',
157
+			array('batch_runner'),
158
+			EVENT_ESPRESSO_VERSION,
159
+			true
160
+		);
161
+		wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
162
+		wp_localize_script(
163
+			'batch_runner_init',
164
+			'ee_job_i18n',
165
+			array(
166
+				'return_url' => $_REQUEST['return_url'],
167
+			)
168
+		);
169
+	}
170 170
 
171
-    /**
172
-     * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
173
-     */
174
-    public function enqueue_scripts_styles_batch_file_create()
175
-    {
176
-        // creates a job based on the request variable
177
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
178
-        wp_enqueue_script(
179
-            'batch_file_runner_init',
180
-            BATCH_URL . 'assets/batch_file_runner_init.js',
181
-            array('batch_runner'),
182
-            EVENT_ESPRESSO_VERSION,
183
-            true
184
-        );
185
-        wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
186
-        wp_localize_script(
187
-            'batch_file_runner_init',
188
-            'ee_job_i18n',
189
-            array(
190
-                'download_and_redirecting' => sprintf(
191
-                    wp_strip_all_tags(
192
-                        __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso')
193
-                    ),
194
-                    '<a href="' . $_REQUEST['return_url'] . '">',
195
-                    '</a>'
196
-                ),
197
-                'return_url'               => $_REQUEST['return_url'],
198
-            )
199
-        );
200
-    }
171
+	/**
172
+	 * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
173
+	 */
174
+	public function enqueue_scripts_styles_batch_file_create()
175
+	{
176
+		// creates a job based on the request variable
177
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
178
+		wp_enqueue_script(
179
+			'batch_file_runner_init',
180
+			BATCH_URL . 'assets/batch_file_runner_init.js',
181
+			array('batch_runner'),
182
+			EVENT_ESPRESSO_VERSION,
183
+			true
184
+		);
185
+		wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
186
+		wp_localize_script(
187
+			'batch_file_runner_init',
188
+			'ee_job_i18n',
189
+			array(
190
+				'download_and_redirecting' => sprintf(
191
+					wp_strip_all_tags(
192
+						__('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso')
193
+					),
194
+					'<a href="' . $_REQUEST['return_url'] . '">',
195
+					'</a>'
196
+				),
197
+				'return_url'               => $_REQUEST['return_url'],
198
+			)
199
+		);
200
+	}
201 201
 
202
-    /**
203
-     * Enqueues scripts and styles common to any batch job, and creates
204
-     * a job from the request data, and stores the response in the
205
-     * $this->_job_step_response property
206
-     *
207
-     * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
208
-     */
209
-    protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
210
-    {
211
-        // just copy the bits of EE admin's eei18n that we need in the JS
212
-        EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
213
-            'An error occurred and the job has been stopped. Please refresh the page to try again.',
214
-            'event_espresso'
215
-        );
216
-        wp_register_script(
217
-            'progress_bar',
218
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
219
-            array('jquery'),
220
-            EVENT_ESPRESSO_VERSION,
221
-            true
222
-        );
223
-        wp_enqueue_style(
224
-            'progress_bar',
225
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
226
-            array(),
227
-            EVENT_ESPRESSO_VERSION
228
-        );
229
-        wp_enqueue_script(
230
-            'batch_runner',
231
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
232
-            array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
233
-            EVENT_ESPRESSO_VERSION,
234
-            true
235
-        );
236
-        $job_handler_classname = stripslashes($_GET['job_handler']);
237
-        $request_data = array_diff_key(
238
-            $_REQUEST,
239
-            array_flip(array('action', 'page', 'ee', 'batch'))
240
-        );
241
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
242
-        // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
243
-        $job_response = $batch_runner->create_job($job_handler_classname, $request_data);
244
-        // remember the response for later. We need it to display the page body
245
-        $this->_job_step_response = $job_response;
246
-        return $job_response;
247
-    }
202
+	/**
203
+	 * Enqueues scripts and styles common to any batch job, and creates
204
+	 * a job from the request data, and stores the response in the
205
+	 * $this->_job_step_response property
206
+	 *
207
+	 * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
208
+	 */
209
+	protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
210
+	{
211
+		// just copy the bits of EE admin's eei18n that we need in the JS
212
+		EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
213
+			'An error occurred and the job has been stopped. Please refresh the page to try again.',
214
+			'event_espresso'
215
+		);
216
+		wp_register_script(
217
+			'progress_bar',
218
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
219
+			array('jquery'),
220
+			EVENT_ESPRESSO_VERSION,
221
+			true
222
+		);
223
+		wp_enqueue_style(
224
+			'progress_bar',
225
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
226
+			array(),
227
+			EVENT_ESPRESSO_VERSION
228
+		);
229
+		wp_enqueue_script(
230
+			'batch_runner',
231
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
232
+			array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
233
+			EVENT_ESPRESSO_VERSION,
234
+			true
235
+		);
236
+		$job_handler_classname = stripslashes($_GET['job_handler']);
237
+		$request_data = array_diff_key(
238
+			$_REQUEST,
239
+			array_flip(array('action', 'page', 'ee', 'batch'))
240
+		);
241
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
242
+		// eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
243
+		$job_response = $batch_runner->create_job($job_handler_classname, $request_data);
244
+		// remember the response for later. We need it to display the page body
245
+		$this->_job_step_response = $job_response;
246
+		return $job_response;
247
+	}
248 248
 
249
-    /**
250
-     * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
251
-     *
252
-     * @param string $template
253
-     * @return string
254
-     */
255
-    public function override_template($template)
256
-    {
257
-        if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
258
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html';
259
-        }
260
-        return $template;
261
-    }
249
+	/**
250
+	 * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
251
+	 *
252
+	 * @param string $template
253
+	 * @return string
254
+	 */
255
+	public function override_template($template)
256
+	{
257
+		if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
258
+			return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html';
259
+		}
260
+		return $template;
261
+	}
262 262
 
263
-    /**
264
-     * Adds an admin page which doesn't appear in the admin menu
265
-     */
266
-    public function register_admin_pages()
267
-    {
268
-        add_submenu_page(
269
-            '', // parent slug. we don't want this to actually appear in the menu
270
-            __('Batch Job', 'event_espresso'), // page title
271
-            'n/a', // menu title
272
-            'read', // we want this page to actually be accessible to anyone,
273
-            'espresso_batch', // menu slug
274
-            array(self::instance(), 'show_admin_page')
275
-        );
276
-    }
263
+	/**
264
+	 * Adds an admin page which doesn't appear in the admin menu
265
+	 */
266
+	public function register_admin_pages()
267
+	{
268
+		add_submenu_page(
269
+			'', // parent slug. we don't want this to actually appear in the menu
270
+			__('Batch Job', 'event_espresso'), // page title
271
+			'n/a', // menu title
272
+			'read', // we want this page to actually be accessible to anyone,
273
+			'espresso_batch', // menu slug
274
+			array(self::instance(), 'show_admin_page')
275
+		);
276
+	}
277 277
 
278
-    /**
279
-     * Renders the admin page, after most of the work was already done during enqueuing scripts
280
-     * of creating the job and localizing some data
281
-     */
282
-    public function show_admin_page()
283
-    {
284
-        echo EEH_Template::locate_template(
285
-            EE_MODULES . 'batch/templates/batch_wrapper.template.html',
286
-            array('batch_request_type' => $this->batch_request_type())
287
-        );
288
-    }
278
+	/**
279
+	 * Renders the admin page, after most of the work was already done during enqueuing scripts
280
+	 * of creating the job and localizing some data
281
+	 */
282
+	public function show_admin_page()
283
+	{
284
+		echo EEH_Template::locate_template(
285
+			EE_MODULES . 'batch/templates/batch_wrapper.template.html',
286
+			array('batch_request_type' => $this->batch_request_type())
287
+		);
288
+	}
289 289
 
290
-    /**
291
-     * Receives ajax calls for continuing a job
292
-     */
293
-    public function batch_continue()
294
-    {
295
-        $job_id = sanitize_text_field($_REQUEST['job_id']);
296
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
297
-        $response_obj = $batch_runner->continue_job($job_id);
298
-        $this->_return_json($response_obj->to_array());
299
-    }
290
+	/**
291
+	 * Receives ajax calls for continuing a job
292
+	 */
293
+	public function batch_continue()
294
+	{
295
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
296
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
297
+		$response_obj = $batch_runner->continue_job($job_id);
298
+		$this->_return_json($response_obj->to_array());
299
+	}
300 300
 
301
-    /**
302
-     * Receives the ajax call to cleanup a job
303
-     *
304
-     * @return type
305
-     */
306
-    public function batch_cleanup()
307
-    {
308
-        $job_id = sanitize_text_field($_REQUEST['job_id']);
309
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
310
-        $response_obj = $batch_runner->cleanup_job($job_id);
311
-        $this->_return_json($response_obj->to_array());
312
-    }
301
+	/**
302
+	 * Receives the ajax call to cleanup a job
303
+	 *
304
+	 * @return type
305
+	 */
306
+	public function batch_cleanup()
307
+	{
308
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
309
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
310
+		$response_obj = $batch_runner->cleanup_job($job_id);
311
+		$this->_return_json($response_obj->to_array());
312
+	}
313 313
 
314 314
 
315
-    /**
316
-     * Returns a json response
317
-     *
318
-     * @param array $data The data we want to send echo via in the JSON response's "data" element
319
-     *
320
-     * The returned json object is created from an array in the following format:
321
-     * array(
322
-     *    'notices' => '', // - contains any EE_Error formatted notices
323
-     *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
324
-     *    We're also going to include the template args with every package (so js can pick out any specific template
325
-     *    args that might be included in here)
326
-     *    'isEEajax' => true,//indicates this is a response from EE
327
-     * )
328
-     */
329
-    protected function _return_json($data)
330
-    {
331
-        $json = array(
332
-            'notices'  => EE_Error::get_notices(),
333
-            'data'     => $data,
334
-            'isEEajax' => true
335
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
336
-        );
315
+	/**
316
+	 * Returns a json response
317
+	 *
318
+	 * @param array $data The data we want to send echo via in the JSON response's "data" element
319
+	 *
320
+	 * The returned json object is created from an array in the following format:
321
+	 * array(
322
+	 *    'notices' => '', // - contains any EE_Error formatted notices
323
+	 *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
324
+	 *    We're also going to include the template args with every package (so js can pick out any specific template
325
+	 *    args that might be included in here)
326
+	 *    'isEEajax' => true,//indicates this is a response from EE
327
+	 * )
328
+	 */
329
+	protected function _return_json($data)
330
+	{
331
+		$json = array(
332
+			'notices'  => EE_Error::get_notices(),
333
+			'data'     => $data,
334
+			'isEEajax' => true
335
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
336
+		);
337 337
 
338 338
 
339
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
340
-        if (null === error_get_last() || ! headers_sent()) {
341
-            header('Content-Type: application/json; charset=UTF-8');
342
-        }
343
-        echo wp_json_encode($json);
344
-        exit();
345
-    }
339
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
340
+		if (null === error_get_last() || ! headers_sent()) {
341
+			header('Content-Type: application/json; charset=UTF-8');
342
+		}
343
+		echo wp_json_encode($json);
344
+		exit();
345
+	}
346 346
 
347
-    /**
348
-     * Gets the job step response which was done during the enqueuing of scripts
349
-     *
350
-     * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
351
-     */
352
-    public function job_step_response()
353
-    {
354
-        return $this->_job_step_response;
355
-    }
347
+	/**
348
+	 * Gets the job step response which was done during the enqueuing of scripts
349
+	 *
350
+	 * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
351
+	 */
352
+	public function job_step_response()
353
+	{
354
+		return $this->_job_step_response;
355
+	}
356 356
 
357
-    /**
358
-     * Gets the batch request type indicated in the $_REQUEST
359
-     *
360
-     * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
361
-     */
362
-    public function batch_request_type()
363
-    {
364
-        if ($this->_batch_request_type === null) {
365
-            if (isset($_GET['batch'])) {
366
-                if ($_GET['batch'] == self::batch_job) {
367
-                    $this->_batch_request_type = self::batch_job;
368
-                } elseif ($_GET['batch'] == self::batch_file_job) {
369
-                    $this->_batch_request_type = self::batch_file_job;
370
-                }
371
-            }
372
-            // if we didn't find that it was a batch request, indicate it wasn't
373
-            if ($this->_batch_request_type === null) {
374
-                $this->_batch_request_type = self::batch_not_job;
375
-            }
376
-        }
377
-        return $this->_batch_request_type;
378
-    }
357
+	/**
358
+	 * Gets the batch request type indicated in the $_REQUEST
359
+	 *
360
+	 * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
361
+	 */
362
+	public function batch_request_type()
363
+	{
364
+		if ($this->_batch_request_type === null) {
365
+			if (isset($_GET['batch'])) {
366
+				if ($_GET['batch'] == self::batch_job) {
367
+					$this->_batch_request_type = self::batch_job;
368
+				} elseif ($_GET['batch'] == self::batch_file_job) {
369
+					$this->_batch_request_type = self::batch_file_job;
370
+				}
371
+			}
372
+			// if we didn't find that it was a batch request, indicate it wasn't
373
+			if ($this->_batch_request_type === null) {
374
+				$this->_batch_request_type = self::batch_not_job;
375
+			}
376
+		}
377
+		return $this->_batch_request_type;
378
+	}
379 379
 
380
-    /**
381
-     * Unnecessary
382
-     *
383
-     * @param type $WP
384
-     */
385
-    public function run($WP)
386
-    {
387
-    }
380
+	/**
381
+	 * Unnecessary
382
+	 *
383
+	 * @param type $WP
384
+	 */
385
+	public function run($WP)
386
+	{
387
+	}
388 388
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     protected function getLoader()
115 115
     {
116
-        if (!$this->loader instanceof LoaderInterface) {
116
+        if ( ! $this->loader instanceof LoaderInterface) {
117 117
             $this->loader = LoaderFactory::getLoader();
118 118
         }
119 119
         return $this->loader;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
                 && $_REQUEST['page'] == 'espresso_batch'
132 132
             )
133 133
         ) {
134
-            if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
134
+            if ( ! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
135 135
                 wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso'));
136 136
             }
137 137
             switch ($this->batch_request_type()) {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
154 154
         wp_enqueue_script(
155 155
             'batch_runner_init',
156
-            BATCH_URL . 'assets/batch_runner_init.js',
156
+            BATCH_URL.'assets/batch_runner_init.js',
157 157
             array('batch_runner'),
158 158
             EVENT_ESPRESSO_VERSION,
159 159
             true
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
178 178
         wp_enqueue_script(
179 179
             'batch_file_runner_init',
180
-            BATCH_URL . 'assets/batch_file_runner_init.js',
180
+            BATCH_URL.'assets/batch_file_runner_init.js',
181 181
             array('batch_runner'),
182 182
             EVENT_ESPRESSO_VERSION,
183 183
             true
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                     wp_strip_all_tags(
192 192
                         __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso')
193 193
                     ),
194
-                    '<a href="' . $_REQUEST['return_url'] . '">',
194
+                    '<a href="'.$_REQUEST['return_url'].'">',
195 195
                     '</a>'
196 196
                 ),
197 197
                 'return_url'               => $_REQUEST['return_url'],
@@ -209,26 +209,26 @@  discard block
 block discarded – undo
209 209
     protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
210 210
     {
211 211
         // just copy the bits of EE admin's eei18n that we need in the JS
212
-        EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
212
+        EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__(
213 213
             'An error occurred and the job has been stopped. Please refresh the page to try again.',
214 214
             'event_espresso'
215 215
         );
216 216
         wp_register_script(
217 217
             'progress_bar',
218
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
218
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js',
219 219
             array('jquery'),
220 220
             EVENT_ESPRESSO_VERSION,
221 221
             true
222 222
         );
223 223
         wp_enqueue_style(
224 224
             'progress_bar',
225
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
225
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css',
226 226
             array(),
227 227
             EVENT_ESPRESSO_VERSION
228 228
         );
229 229
         wp_enqueue_script(
230 230
             'batch_runner',
231
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
231
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js',
232 232
             array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
233 233
             EVENT_ESPRESSO_VERSION,
234 234
             true
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     public function override_template($template)
256 256
     {
257 257
         if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
258
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.html';
258
+            return EE_MODULES.'batch/templates/batch_frontend_wrapper.template.html';
259 259
         }
260 260
         return $template;
261 261
     }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
     public function show_admin_page()
283 283
     {
284 284
         echo EEH_Template::locate_template(
285
-            EE_MODULES . 'batch/templates/batch_wrapper.template.html',
285
+            EE_MODULES.'batch/templates/batch_wrapper.template.html',
286 286
             array('batch_request_type' => $this->batch_request_type())
287 287
         );
288 288
     }
Please login to merge, or discard this patch.
core/domain/services/custom_post_types/RewriteRules.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -13,35 +13,35 @@
 block discarded – undo
13 13
 class RewriteRules
14 14
 {
15 15
 
16
-    const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules';
16
+	const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules';
17 17
 
18 18
 
19
-    /**
20
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
21
-     *
22
-     * @return void
23
-     */
24
-    public function flush()
25
-    {
26
-        update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true);
27
-    }
19
+	/**
20
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
21
+	 *
22
+	 * @return void
23
+	 */
24
+	public function flush()
25
+	{
26
+		update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true);
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
32
-     *
33
-     * @return void
34
-     */
35
-    public function flushRewriteRules()
36
-    {
37
-        if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) {
38
-            add_action(
39
-                'shutdown',
40
-                static function () {
41
-                    flush_rewrite_rules();
42
-                    update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false);
43
-                }
44
-            );
45
-        }
46
-    }
30
+	/**
31
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
32
+	 *
33
+	 * @return void
34
+	 */
35
+	public function flushRewriteRules()
36
+	{
37
+		if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) {
38
+			add_action(
39
+				'shutdown',
40
+				static function () {
41
+					flush_rewrite_rules();
42
+					update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false);
43
+				}
44
+			);
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
         if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) {
38 38
             add_action(
39 39
                 'shutdown',
40
-                static function () {
40
+                static function() {
41 41
                     flush_rewrite_rules();
42 42
                     update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false);
43 43
                 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +735 added lines, -735 removed lines patch added patch discarded remove patch
@@ -18,182 +18,182 @@  discard block
 block discarded – undo
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
-     * This property gets set by the _set_default_message_types() method.
24
-     *
25
-     * @var array
26
-     */
27
-    protected $_default_message_types = array();
21
+	/**
22
+	 * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
+	 * This property gets set by the _set_default_message_types() method.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected $_default_message_types = array();
28 28
 
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * This property holds the message types that are valid for use with this messenger.
34
-     * It gets set by the _set_valid_message_types() method.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $_valid_message_types = array();
32
+	/**
33
+	 * This property holds the message types that are valid for use with this messenger.
34
+	 * It gets set by the _set_valid_message_types() method.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $_valid_message_types = array();
39 39
 
40 40
 
41 41
 
42
-    /**
43
-     * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
-     *
45
-     * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
-     *
47
-     * Array should be in this format:
48
-     *
49
-     * array(
50
-     *  'field_name(i.e.to)' => array(
51
-     *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
-     *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
-     *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
-     *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
-     *  )
56
-     * )
57
-     *
58
-     * @var array
59
-     */
60
-    protected $_validator_config = array();
42
+	/**
43
+	 * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
+	 *
45
+	 * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
+	 *
47
+	 * Array should be in this format:
48
+	 *
49
+	 * array(
50
+	 *  'field_name(i.e.to)' => array(
51
+	 *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
+	 *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
+	 *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
+	 *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
+	 *  )
56
+	 * )
57
+	 *
58
+	 * @var array
59
+	 */
60
+	protected $_validator_config = array();
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
-     * @var object
67
-     */
68
-    protected $_EEM_data;
64
+	/**
65
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
+	 * @var object
67
+	 */
68
+	protected $_EEM_data;
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * this property just holds an array of the various template refs.
74
-     * @var array
75
-     */
76
-    protected $_template_fields = array();
72
+	/**
73
+	 * this property just holds an array of the various template refs.
74
+	 * @var array
75
+	 */
76
+	protected $_template_fields = array();
77 77
 
78 78
 
79 79
 
80 80
 
81
-    /**
82
-     * This holds an array of the arguments used in parsing a template for the sender.
83
-     * @var array
84
-     */
85
-    protected $_template_args = array();
81
+	/**
82
+	 * This holds an array of the arguments used in parsing a template for the sender.
83
+	 * @var array
84
+	 */
85
+	protected $_template_args = array();
86 86
 
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92
-    /**
93
-     * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
-     *
95
-     * @protected
96
-     * @var array
97
-     */
98
-    protected $_test_settings_fields = array();
92
+	/**
93
+	 * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
+	 *
95
+	 * @protected
96
+	 * @var array
97
+	 */
98
+	protected $_test_settings_fields = array();
99 99
 
100 100
 
101 101
 
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
-     *
108
-     * @since 4.5.0
109
-     *
110
-     * @var EE_Messages_Template_Pack
111
-     */
112
-    protected $_tmp_pack;
105
+	/**
106
+	 * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
+	 *
108
+	 * @since 4.5.0
109
+	 *
110
+	 * @var EE_Messages_Template_Pack
111
+	 */
112
+	protected $_tmp_pack;
113 113
 
114 114
 
115 115
 
116 116
 
117
-    /**
118
-     * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
-     *
120
-     * @since 4.5.0
121
-     *
122
-     * @var string
123
-     */
124
-    protected $_variation;
117
+	/**
118
+	 * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
+	 *
120
+	 * @since 4.5.0
121
+	 *
122
+	 * @var string
123
+	 */
124
+	protected $_variation;
125 125
 
126 126
 
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
-     *
133
-     *  - template pack
134
-     *  - template variation
135
-     *
136
-     * @since 4.5.0
137
-     *
138
-     * @var stdClass
139
-     */
140
-    protected $_supports_labels;
130
+	/**
131
+	 * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
+	 *
133
+	 *  - template pack
134
+	 *  - template variation
135
+	 *
136
+	 * @since 4.5.0
137
+	 *
138
+	 * @var stdClass
139
+	 */
140
+	protected $_supports_labels;
141 141
 
142 142
 
143 143
 
144 144
 
145 145
 
146
-    /**
147
-     * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
-     *
149
-     * @var EE_message_type
150
-     */
151
-    protected $_incoming_message_type;
146
+	/**
147
+	 * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
+	 *
149
+	 * @var EE_message_type
150
+	 */
151
+	protected $_incoming_message_type;
152 152
 
153 153
 
154 154
 
155
-    /**
156
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
-     *
158
-     * @var bool
159
-     */
160
-    public $activate_on_install = false;
155
+	/**
156
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
+	 *
158
+	 * @var bool
159
+	 */
160
+	public $activate_on_install = false;
161 161
 
162 162
 
163 163
 
164 164
 
165 165
 
166
-    public function __construct()
167
-    {
168
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
169
-        $this->_messages_item_type = 'messenger';
166
+	public function __construct()
167
+	{
168
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
169
+		$this->_messages_item_type = 'messenger';
170 170
 
171
-        parent::__construct();
171
+		parent::__construct();
172 172
 
173
-        $this->_set_test_settings_fields();
174
-        $this->_set_template_fields();
175
-        $this->_set_default_message_types();
176
-        $this->_set_valid_message_types();
177
-        $this->_set_validator_config();
173
+		$this->_set_test_settings_fields();
174
+		$this->_set_template_fields();
175
+		$this->_set_default_message_types();
176
+		$this->_set_valid_message_types();
177
+		$this->_set_validator_config();
178 178
 
179 179
 
180
-        $this->_supports_labels = new stdClass();
181
-        $this->_set_supports_labels();
182
-    }
180
+		$this->_supports_labels = new stdClass();
181
+		$this->_set_supports_labels();
182
+	}
183 183
 
184 184
 
185 185
 
186 186
 
187 187
 
188
-    /**
189
-     * _set_template_fields
190
-     * This sets up the fields that a messenger requires for the message to go out.
191
-     *
192
-     * @abstract
193
-     * @access  protected
194
-     * @return void
195
-     */
196
-    abstract protected function _set_template_fields();
188
+	/**
189
+	 * _set_template_fields
190
+	 * This sets up the fields that a messenger requires for the message to go out.
191
+	 *
192
+	 * @abstract
193
+	 * @access  protected
194
+	 * @return void
195
+	 */
196
+	abstract protected function _set_template_fields();
197 197
 
198 198
 
199 199
 
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
 
206
-    /**
207
-     * This method sets the _default_message_type property (see definition in docs attached to property)
208
-     *
209
-     * @abstract
210
-     * @access protected
211
-     * @return void
212
-     */
213
-    abstract protected function _set_default_message_types();
206
+	/**
207
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
208
+	 *
209
+	 * @abstract
210
+	 * @access protected
211
+	 * @return void
212
+	 */
213
+	abstract protected function _set_default_message_types();
214 214
 
215 215
 
216 216
 
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
 
219 219
 
220 220
 
221
-    /**
222
-     * Sets the _valid_message_types property (see definition in cods attached to property)
223
-     *
224
-     * @since 4.5.0
225
-     *
226
-     * @abstract
227
-     * @return void
228
-     */
229
-    abstract protected function _set_valid_message_types();
221
+	/**
222
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
223
+	 *
224
+	 * @since 4.5.0
225
+	 *
226
+	 * @abstract
227
+	 * @return void
228
+	 */
229
+	abstract protected function _set_valid_message_types();
230 230
 
231 231
 
232 232
 
@@ -234,171 +234,171 @@  discard block
 block discarded – undo
234 234
 
235 235
 
236 236
 
237
-    /**
238
-     * Child classes must declare the $_validator_config property using this method.
239
-     * See comments for $_validator_config for details on what it is used for.
240
-     *
241
-     * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
-     *
243
-     * @access protected
244
-     * @return void
245
-     */
246
-    abstract protected function _set_validator_config();
237
+	/**
238
+	 * Child classes must declare the $_validator_config property using this method.
239
+	 * See comments for $_validator_config for details on what it is used for.
240
+	 *
241
+	 * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
+	 *
243
+	 * @access protected
244
+	 * @return void
245
+	 */
246
+	abstract protected function _set_validator_config();
247 247
 
248 248
 
249 249
 
250 250
 
251 251
 
252 252
 
253
-    /**
254
-     * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
-     *
256
-     * @return bool|WP_Error
257
-     * @throw \Exception
258
-     */
259
-    abstract protected function _send_message();
253
+	/**
254
+	 * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
+	 *
256
+	 * @return bool|WP_Error
257
+	 * @throw \Exception
258
+	 */
259
+	abstract protected function _send_message();
260 260
 
261 261
 
262 262
 
263 263
 
264
-    /**
265
-     * We give you pretty previews of the messages!
266
-     * @return string html body for message content.
267
-     */
268
-    abstract protected function _preview();
264
+	/**
265
+	 * We give you pretty previews of the messages!
266
+	 * @return string html body for message content.
267
+	 */
268
+	abstract protected function _preview();
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
-     *
276
-     * @since 4.5.0
277
-     *
278
-     * @return void
279
-     */
280
-    public function enqueue_scripts_styles()
281
-    {
282
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
-    }
273
+	/**
274
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
+	 *
276
+	 * @since 4.5.0
277
+	 *
278
+	 * @return void
279
+	 */
280
+	public function enqueue_scripts_styles()
281
+	{
282
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
+	}
284 284
 
285 285
 
286 286
 
287 287
 
288 288
 
289
-    /**
290
-     * This is used to indicate whether a messenger must be sent immediately or not.
291
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
-     * away.  The PDF messenger is similar.
293
-     *
294
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
-     *
296
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
-     *
298
-     * @since  4.9.0
299
-     * @return bool
300
-     */
301
-    public function send_now()
302
-    {
303
-        return false;
304
-    }
289
+	/**
290
+	 * This is used to indicate whether a messenger must be sent immediately or not.
291
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
+	 * away.  The PDF messenger is similar.
293
+	 *
294
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
+	 *
296
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
+	 *
298
+	 * @since  4.9.0
299
+	 * @return bool
300
+	 */
301
+	public function send_now()
302
+	{
303
+		return false;
304
+	}
305 305
 
306 306
 
307 307
 
308 308
 
309 309
 
310
-    /**
311
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
-     * Note: If the generated message is a for a preview, this value is ignored.
313
-     * @since 4.9.0
314
-     * @return bool
315
-     */
316
-    public function allow_empty_to_field()
317
-    {
318
-        return false;
319
-    }
310
+	/**
311
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
+	 * Note: If the generated message is a for a preview, this value is ignored.
313
+	 * @since 4.9.0
314
+	 * @return bool
315
+	 */
316
+	public function allow_empty_to_field()
317
+	{
318
+		return false;
319
+	}
320 320
 
321 321
 
322 322
 
323 323
 
324 324
 
325
-    /**
326
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
-     * @see property definition for info on how its formatted.
328
-     *
329
-     * @since 4.5.0;
330
-     * @return void
331
-     */
332
-    protected function _set_supports_labels()
333
-    {
334
-        $this->_set_supports_labels_defaults();
335
-    }
325
+	/**
326
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
+	 * @see property definition for info on how its formatted.
328
+	 *
329
+	 * @since 4.5.0;
330
+	 * @return void
331
+	 */
332
+	protected function _set_supports_labels()
333
+	{
334
+		$this->_set_supports_labels_defaults();
335
+	}
336 336
 
337 337
 
338 338
 
339 339
 
340 340
 
341
-    /**
342
-     * Sets the defaults for the _supports_labels property.
343
-     *
344
-     * @since 4.5.0
345
-     *
346
-     * @return void
347
-     */
348
-    private function _set_supports_labels_defaults()
349
-    {
350
-        $this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
-        $this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
-        $this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
341
+	/**
342
+	 * Sets the defaults for the _supports_labels property.
343
+	 *
344
+	 * @since 4.5.0
345
+	 *
346
+	 * @return void
347
+	 */
348
+	private function _set_supports_labels_defaults()
349
+	{
350
+		$this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
+		$this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
+		$this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
353 353
 
354
-        $this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
354
+		$this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
355 355
 
356
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
-    }
356
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
+	}
358 358
 
359 359
 
360 360
 
361 361
 
362 362
 
363
-    /**
364
-     * This returns the _supports_labels property.
365
-     *
366
-     * @since 4.5.0
367
-     *
368
-     * @return stdClass
369
-     */
370
-    public function get_supports_labels()
371
-    {
372
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
-            $this->_set_supports_labels_defaults();
374
-        }
375
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
-    }
363
+	/**
364
+	 * This returns the _supports_labels property.
365
+	 *
366
+	 * @since 4.5.0
367
+	 *
368
+	 * @return stdClass
369
+	 */
370
+	public function get_supports_labels()
371
+	{
372
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
+			$this->_set_supports_labels_defaults();
374
+		}
375
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
+	}
377 377
 
378 378
 
379 379
 
380 380
 
381
-    /**
382
-     * Used to retrieve a variation (typically the path/url to a css file)
383
-     *
384
-     * @since 4.5.0
385
-     *
386
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
-     * @param string                    $type What variation type to return. Default is 'main'.
390
-     * @param string               $variation What variation for the template pack
391
-     * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
-     *
393
-     * @return string                    path or url for the requested variation.
394
-     */
395
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
-    {
397
-        $this->_tmp_pack = $pack;
398
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
-        return $variation_path;
401
-    }
381
+	/**
382
+	 * Used to retrieve a variation (typically the path/url to a css file)
383
+	 *
384
+	 * @since 4.5.0
385
+	 *
386
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
+	 * @param string                    $type What variation type to return. Default is 'main'.
390
+	 * @param string               $variation What variation for the template pack
391
+	 * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
+	 *
393
+	 * @return string                    path or url for the requested variation.
394
+	 */
395
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
+	{
397
+		$this->_tmp_pack = $pack;
398
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
+		return $variation_path;
401
+	}
402 402
 
403 403
 
404 404
 
@@ -406,492 +406,492 @@  discard block
 block discarded – undo
406 406
 
407 407
 
408 408
 
409
-    /**
410
-     * This just returns the default message types associated with this messenger when it is first activated.
411
-     *
412
-     * @access public
413
-     * @return array
414
-     */
415
-    public function get_default_message_types()
416
-    {
417
-        $class = get_class($this);
409
+	/**
410
+	 * This just returns the default message types associated with this messenger when it is first activated.
411
+	 *
412
+	 * @access public
413
+	 * @return array
414
+	 */
415
+	public function get_default_message_types()
416
+	{
417
+		$class = get_class($this);
418 418
 
419
-        // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
419
+		// messenger specific filter
420
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422
-        // all messengers filter
423
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
-        return $default_types;
425
-    }
422
+		// all messengers filter
423
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
+		return $default_types;
425
+	}
426 426
 
427 427
 
428 428
 
429 429
 
430
-    /**
431
-     * Returns the valid message types associated with this messenger.
432
-     *
433
-     * @since 4.5.0
434
-     *
435
-     * @return array
436
-     */
437
-    public function get_valid_message_types()
438
-    {
439
-        $class = get_class($this);
440
-
441
-        // messenger specific filter
442
-        // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
-
445
-        // all messengers filter
446
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
-        return $valid_types;
448
-    }
449
-
450
-
451
-
452
-
453
-
454
-    /**
455
-     * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
-     *
457
-     * @access public
458
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
459
-     */
460
-    public function set_validator_config($new_config)
461
-    {
462
-        $this->_validator_config = $new_config;
463
-    }
464
-
465
-
466
-
467
-
468
-    /**
469
-     * This returns the _validator_config property
470
-     *
471
-     * @access public
472
-     * @return array
473
-     */
474
-    public function get_validator_config()
475
-    {
476
-        $class = get_class($this);
477
-
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
-        return $config;
481
-    }
482
-
483
-
484
-
485
-
486
-    /**
487
-     * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
-     *
489
-     * @param string $page the slug of the EE admin page
490
-     * @param array $message_types an array of active message type objects
491
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
-     * @access public
494
-     * @return string content for page
495
-     */
496
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
-    {
498
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * @param $message_types
505
-     * @param array $extra
506
-     * @return mixed|string
507
-     */
508
-    protected function _get_admin_content_events_edit($message_types, $extra)
509
-    {
510
-        // defaults
511
-        $template_args = array();
512
-        $selector_rows = '';
513
-
514
-        // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
516
-
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
-
520
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
-        );
524
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
-            $event_id,
526
-            array(
527
-                'MTP_messenger' => $this->name,
528
-                'MTP_is_active' => true
529
-            )
530
-        );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
-
533
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
-        foreach ($global_templates as $mtpgID => $mtpg) {
535
-            if ($mtpg instanceof EE_Message_Template_Group) {
536
-                // verify this message type is supposed to show on this page
537
-                $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
539
-                    continue;
540
-                }
541
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
-                    continue;
544
-                }
545
-                $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
-                // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
550
-                    // any custom templates for this message type?
551
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
554
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
-                    }
556
-                }
557
-                // if there is no $default_value then we set it as the global
558
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url_query_args = [
560
-                    'page' => 'espresso_messages',
561
-                    'action' => 'edit_message_template',
562
-                    'id' => $default_value,
563
-                    'evt_id' => $event_id
564
-                ];
565
-                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
566
-                $create_url_query_args = [
567
-                    'page' => 'espresso_messages',
568
-                    'action' => 'add_new_message_template',
569
-                    'GRP_ID' => $default_value
570
-                ];
571
-                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
572
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
573
-                $st_args['mt_slug'] = $mtpg->message_type();
574
-                $st_args['messenger_slug'] = $this->name;
575
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
576
-                // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
577
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
578
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
579
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
580
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
581
-            }
582
-        }
583
-
584
-        // if no selectors present then get out.
585
-        if (empty($selector_rows)) {
586
-            return '';
587
-        }
588
-
589
-        $template_args['selector_rows'] = $selector_rows;
590
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
591
-    }
592
-
593
-
594
-
595
-
596
-
597
-
598
-    /**
599
-     * get_template_fields
600
-     *
601
-     * @access public
602
-     * @return array $this->_template_fields
603
-     */
604
-    public function get_template_fields()
605
-    {
606
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
607
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
608
-        return $template_fields;
609
-    }
610
-
611
-
612
-
613
-
614
-    /** SETUP METHODS **/
615
-    /**
616
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
617
-     * @param string $item
618
-     * @param mixed $value
619
-     */
620
-    protected function _set_template_value($item, $value)
621
-    {
622
-        if (array_key_exists($item, $this->_template_fields)) {
623
-            $prop = '_' . $item;
624
-            $this->{$prop}= $value;
625
-        }
626
-    }
627
-
628
-    /**
629
-     * Sets up the message for sending.
630
-     *
631
-     * @param  EE_message $message the message object that contains details about the message.
632
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
633
-     *
634
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
635
-     *              added to EE_Error.
636
-     *              true = message sent successfully
637
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
638
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
639
-     *
640
-     * @throws SendMessageException
641
-     */
642
-    final public function send_message($message, EE_message_type $message_type)
643
-    {
644
-        try {
645
-            $this->_validate_and_setup($message);
646
-            $this->_incoming_message_type = $message_type;
647
-            $response = $this->_send_message();
648
-            if ($response instanceof WP_Error) {
649
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
650
-                $response = false;
651
-            }
652
-        } catch (\Exception $e) {
653
-            // convert to an instance of SendMessageException
654
-            throw new SendMessageException($e->getMessage());
655
-        }
656
-        return $response;
657
-    }
658
-
659
-
660
-
661
-    /**
662
-     * Sets up and returns message preview
663
-     * @param  EE_Message $message incoming message object
664
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
665
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
666
-     * @return string          return the message html content
667
-     */
668
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
669
-    {
670
-        $this->_validate_and_setup($message);
671
-
672
-        $this->_incoming_message_type = $message_type;
673
-
674
-        if ($send) {
675
-            // are we overriding any existing template fields?
676
-            $settings = apply_filters(
677
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
678
-                $this->get_existing_test_settings(),
679
-                $this,
680
-                $send,
681
-                $message,
682
-                $message_type
683
-            );
684
-            if (! empty($settings)) {
685
-                foreach ($settings as $field => $value) {
686
-                    $this->_set_template_value($field, $value);
687
-                }
688
-            }
689
-        }
690
-
691
-        // enqueue preview js so that any links/buttons on the page are disabled.
692
-        if (! $send) {
693
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
694
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
695
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
696
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
698
-        }
699
-
700
-        return $send ? $this->_send_message() : $this->_preview();
701
-    }
702
-
703
-
704
-
705
-
706
-    /**
707
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
708
-     *
709
-     * @since 4.5.0
710
-     *
711
-     * @return void
712
-     */
713
-    public function add_preview_script()
714
-    {
715
-        // error message
716
-        EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
717
-            __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
718
-        );
719
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
720
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
721
-        wp_enqueue_script('ee-messages-preview-js');
722
-    }
723
-
724
-
725
-
726
-
727
-    /**
728
-     * simply validates the incoming message object and then sets up the properties for the messenger
729
-     * @param  EE_Message $message
730
-     * @throws EE_Error
731
-     */
732
-    protected function _validate_and_setup(EE_Message $message)
733
-    {
734
-        $template_pack = $message->get_template_pack();
735
-        $variation = $message->get_template_pack_variation();
736
-
737
-        // verify we have the required template pack value on the $message object.
738
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
739
-            throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
740
-        }
741
-
742
-        $this->_tmp_pack = $template_pack;
743
-
744
-        $this->_variation = $variation ? $variation : 'default';
745
-
746
-        $template_fields = $this->get_template_fields();
747
-
748
-        foreach ($template_fields as $template => $value) {
749
-            if ($template !== 'extra') {
750
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
751
-                $message_template_value = $column_value ? $column_value : null;
752
-                $this->_set_template_value($template, $message_template_value);
753
-            }
754
-        }
755
-    }
756
-
757
-
758
-
759
-    /**
760
-     * Utility method for child classes to get the contents of a template file and return
761
-     *
762
-     * We're assuming the child messenger class has already setup template args!
763
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
764
-     * @return string
765
-     * @throws \EE_Error
766
-     */
767
-    protected function _get_main_template($preview = false)
768
-    {
769
-        $type = $preview ? 'preview' : 'main';
770
-
771
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
772
-
773
-        // check file exists and is readable
774
-        if (!is_readable($wrapper_template)) {
775
-            throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
776
-        }
777
-
778
-        // add message type to template args
779
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
780
-
781
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * set the _test_settings_fields property
788
-     *
789
-     * @access protected
790
-     * @return void
791
-     */
792
-    protected function _set_test_settings_fields()
793
-    {
794
-        $this->_test_settings_fields = array();
795
-    }
796
-
797
-
798
-
799
-    /**
800
-     * return the _test_settings_fields property
801
-     * @return array
802
-     */
803
-    public function get_test_settings_fields()
804
-    {
805
-        return $this->_test_settings_fields;
806
-    }
807
-
808
-
809
-
810
-
811
-    /**
812
-     * This just returns any existing test settings that might be saved in the database
813
-     *
814
-     * @access public
815
-     * @return array
816
-     */
817
-    public function get_existing_test_settings()
818
-    {
819
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
820
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
821
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
822
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
823
-    }
824
-
825
-
826
-
827
-    /**
828
-     * All this does is set the existing test settings (in the db) for the messenger
829
-     *
830
-     * @access public
831
-     * @param $settings
832
-     * @return bool success/fail
833
-     */
834
-    public function set_existing_test_settings($settings)
835
-    {
836
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
837
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
838
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
839
-        $existing[ $this->name ]['test_settings'] = $settings;
840
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
841
-    }
842
-
843
-
844
-
845
-    /**
846
-     * This just returns the field label for a given field setup in the _template_fields property.
847
-     *
848
-     * @since   4.3.0
849
-     *
850
-     * @param string $field The field to retrieve the label for
851
-     * @return string             The label
852
-     */
853
-    public function get_field_label($field)
854
-    {
855
-        // first let's see if the field requests is in the top level array.
856
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
857
-            return $this->_template[ $field ]['label'];
858
-        }
859
-
860
-        // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
861
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
862
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
863
-        }
864
-
865
-        // now it's possible this field may just be existing in any of the extra array items.
866
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
867
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
868
-                if (!is_array($subfields)) {
869
-                    continue;
870
-                }
871
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
872
-                    return $subfields[ $field ]['label'];
873
-                }
874
-            }
875
-        }
876
-
877
-        // if we made it here then there's no label set so let's just return the $field.
878
-        return $field;
879
-    }
880
-
881
-
882
-
883
-
884
-    /**
885
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
886
-     *
887
-     * @since 4.5.0
888
-     *
889
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
890
-     *
891
-     * @return void
892
-     */
893
-    public function do_secondary_messenger_hooks($sending_messenger_name)
894
-    {
895
-        return;
896
-    }
430
+	/**
431
+	 * Returns the valid message types associated with this messenger.
432
+	 *
433
+	 * @since 4.5.0
434
+	 *
435
+	 * @return array
436
+	 */
437
+	public function get_valid_message_types()
438
+	{
439
+		$class = get_class($this);
440
+
441
+		// messenger specific filter
442
+		// messenger specific filter
443
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
+
445
+		// all messengers filter
446
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
+		return $valid_types;
448
+	}
449
+
450
+
451
+
452
+
453
+
454
+	/**
455
+	 * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
+	 *
457
+	 * @access public
458
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
459
+	 */
460
+	public function set_validator_config($new_config)
461
+	{
462
+		$this->_validator_config = $new_config;
463
+	}
464
+
465
+
466
+
467
+
468
+	/**
469
+	 * This returns the _validator_config property
470
+	 *
471
+	 * @access public
472
+	 * @return array
473
+	 */
474
+	public function get_validator_config()
475
+	{
476
+		$class = get_class($this);
477
+
478
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
+		return $config;
481
+	}
482
+
483
+
484
+
485
+
486
+	/**
487
+	 * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
+	 *
489
+	 * @param string $page the slug of the EE admin page
490
+	 * @param array $message_types an array of active message type objects
491
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
+	 * @access public
494
+	 * @return string content for page
495
+	 */
496
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
+	{
498
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * @param $message_types
505
+	 * @param array $extra
506
+	 * @return mixed|string
507
+	 */
508
+	protected function _get_admin_content_events_edit($message_types, $extra)
509
+	{
510
+		// defaults
511
+		$template_args = array();
512
+		$selector_rows = '';
513
+
514
+		// we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
516
+
517
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
+
520
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
522
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
+		);
524
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
+			$event_id,
526
+			array(
527
+				'MTP_messenger' => $this->name,
528
+				'MTP_is_active' => true
529
+			)
530
+		);
531
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
+
533
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
+		foreach ($global_templates as $mtpgID => $mtpg) {
535
+			if ($mtpg instanceof EE_Message_Template_Group) {
536
+				// verify this message type is supposed to show on this page
537
+				$mtp_obj = $mtpg->message_type_obj();
538
+				if (! $mtp_obj instanceof EE_message_type) {
539
+					continue;
540
+				}
541
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
+					continue;
544
+				}
545
+				$select_values = array();
546
+				$select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
+				// if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
+				if (! $mtpg->get('MTP_is_override')) {
550
+					// any custom templates for this message type?
551
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
+						$select_values[ $cmtpgID ] = $cmtpg->name();
554
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
+					}
556
+				}
557
+				// if there is no $default_value then we set it as the global
558
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
559
+				$edit_url_query_args = [
560
+					'page' => 'espresso_messages',
561
+					'action' => 'edit_message_template',
562
+					'id' => $default_value,
563
+					'evt_id' => $event_id
564
+				];
565
+				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
566
+				$create_url_query_args = [
567
+					'page' => 'espresso_messages',
568
+					'action' => 'add_new_message_template',
569
+					'GRP_ID' => $default_value
570
+				];
571
+				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
572
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
573
+				$st_args['mt_slug'] = $mtpg->message_type();
574
+				$st_args['messenger_slug'] = $this->name;
575
+				$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
576
+				// note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
577
+				$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
578
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
579
+				$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
580
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
581
+			}
582
+		}
583
+
584
+		// if no selectors present then get out.
585
+		if (empty($selector_rows)) {
586
+			return '';
587
+		}
588
+
589
+		$template_args['selector_rows'] = $selector_rows;
590
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
591
+	}
592
+
593
+
594
+
595
+
596
+
597
+
598
+	/**
599
+	 * get_template_fields
600
+	 *
601
+	 * @access public
602
+	 * @return array $this->_template_fields
603
+	 */
604
+	public function get_template_fields()
605
+	{
606
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
607
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
608
+		return $template_fields;
609
+	}
610
+
611
+
612
+
613
+
614
+	/** SETUP METHODS **/
615
+	/**
616
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
617
+	 * @param string $item
618
+	 * @param mixed $value
619
+	 */
620
+	protected function _set_template_value($item, $value)
621
+	{
622
+		if (array_key_exists($item, $this->_template_fields)) {
623
+			$prop = '_' . $item;
624
+			$this->{$prop}= $value;
625
+		}
626
+	}
627
+
628
+	/**
629
+	 * Sets up the message for sending.
630
+	 *
631
+	 * @param  EE_message $message the message object that contains details about the message.
632
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
633
+	 *
634
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
635
+	 *              added to EE_Error.
636
+	 *              true = message sent successfully
637
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
638
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
639
+	 *
640
+	 * @throws SendMessageException
641
+	 */
642
+	final public function send_message($message, EE_message_type $message_type)
643
+	{
644
+		try {
645
+			$this->_validate_and_setup($message);
646
+			$this->_incoming_message_type = $message_type;
647
+			$response = $this->_send_message();
648
+			if ($response instanceof WP_Error) {
649
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
650
+				$response = false;
651
+			}
652
+		} catch (\Exception $e) {
653
+			// convert to an instance of SendMessageException
654
+			throw new SendMessageException($e->getMessage());
655
+		}
656
+		return $response;
657
+	}
658
+
659
+
660
+
661
+	/**
662
+	 * Sets up and returns message preview
663
+	 * @param  EE_Message $message incoming message object
664
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
665
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
666
+	 * @return string          return the message html content
667
+	 */
668
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
669
+	{
670
+		$this->_validate_and_setup($message);
671
+
672
+		$this->_incoming_message_type = $message_type;
673
+
674
+		if ($send) {
675
+			// are we overriding any existing template fields?
676
+			$settings = apply_filters(
677
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
678
+				$this->get_existing_test_settings(),
679
+				$this,
680
+				$send,
681
+				$message,
682
+				$message_type
683
+			);
684
+			if (! empty($settings)) {
685
+				foreach ($settings as $field => $value) {
686
+					$this->_set_template_value($field, $value);
687
+				}
688
+			}
689
+		}
690
+
691
+		// enqueue preview js so that any links/buttons on the page are disabled.
692
+		if (! $send) {
693
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
694
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
695
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
696
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
698
+		}
699
+
700
+		return $send ? $this->_send_message() : $this->_preview();
701
+	}
702
+
703
+
704
+
705
+
706
+	/**
707
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
708
+	 *
709
+	 * @since 4.5.0
710
+	 *
711
+	 * @return void
712
+	 */
713
+	public function add_preview_script()
714
+	{
715
+		// error message
716
+		EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
717
+			__('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
718
+		);
719
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
720
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
721
+		wp_enqueue_script('ee-messages-preview-js');
722
+	}
723
+
724
+
725
+
726
+
727
+	/**
728
+	 * simply validates the incoming message object and then sets up the properties for the messenger
729
+	 * @param  EE_Message $message
730
+	 * @throws EE_Error
731
+	 */
732
+	protected function _validate_and_setup(EE_Message $message)
733
+	{
734
+		$template_pack = $message->get_template_pack();
735
+		$variation = $message->get_template_pack_variation();
736
+
737
+		// verify we have the required template pack value on the $message object.
738
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
739
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
740
+		}
741
+
742
+		$this->_tmp_pack = $template_pack;
743
+
744
+		$this->_variation = $variation ? $variation : 'default';
745
+
746
+		$template_fields = $this->get_template_fields();
747
+
748
+		foreach ($template_fields as $template => $value) {
749
+			if ($template !== 'extra') {
750
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
751
+				$message_template_value = $column_value ? $column_value : null;
752
+				$this->_set_template_value($template, $message_template_value);
753
+			}
754
+		}
755
+	}
756
+
757
+
758
+
759
+	/**
760
+	 * Utility method for child classes to get the contents of a template file and return
761
+	 *
762
+	 * We're assuming the child messenger class has already setup template args!
763
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
764
+	 * @return string
765
+	 * @throws \EE_Error
766
+	 */
767
+	protected function _get_main_template($preview = false)
768
+	{
769
+		$type = $preview ? 'preview' : 'main';
770
+
771
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
772
+
773
+		// check file exists and is readable
774
+		if (!is_readable($wrapper_template)) {
775
+			throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
776
+		}
777
+
778
+		// add message type to template args
779
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
780
+
781
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * set the _test_settings_fields property
788
+	 *
789
+	 * @access protected
790
+	 * @return void
791
+	 */
792
+	protected function _set_test_settings_fields()
793
+	{
794
+		$this->_test_settings_fields = array();
795
+	}
796
+
797
+
798
+
799
+	/**
800
+	 * return the _test_settings_fields property
801
+	 * @return array
802
+	 */
803
+	public function get_test_settings_fields()
804
+	{
805
+		return $this->_test_settings_fields;
806
+	}
807
+
808
+
809
+
810
+
811
+	/**
812
+	 * This just returns any existing test settings that might be saved in the database
813
+	 *
814
+	 * @access public
815
+	 * @return array
816
+	 */
817
+	public function get_existing_test_settings()
818
+	{
819
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
820
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
821
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
822
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
823
+	}
824
+
825
+
826
+
827
+	/**
828
+	 * All this does is set the existing test settings (in the db) for the messenger
829
+	 *
830
+	 * @access public
831
+	 * @param $settings
832
+	 * @return bool success/fail
833
+	 */
834
+	public function set_existing_test_settings($settings)
835
+	{
836
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
837
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
838
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
839
+		$existing[ $this->name ]['test_settings'] = $settings;
840
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
841
+	}
842
+
843
+
844
+
845
+	/**
846
+	 * This just returns the field label for a given field setup in the _template_fields property.
847
+	 *
848
+	 * @since   4.3.0
849
+	 *
850
+	 * @param string $field The field to retrieve the label for
851
+	 * @return string             The label
852
+	 */
853
+	public function get_field_label($field)
854
+	{
855
+		// first let's see if the field requests is in the top level array.
856
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
857
+			return $this->_template[ $field ]['label'];
858
+		}
859
+
860
+		// nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
861
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
862
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
863
+		}
864
+
865
+		// now it's possible this field may just be existing in any of the extra array items.
866
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
867
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
868
+				if (!is_array($subfields)) {
869
+					continue;
870
+				}
871
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
872
+					return $subfields[ $field ]['label'];
873
+				}
874
+			}
875
+		}
876
+
877
+		// if we made it here then there's no label set so let's just return the $field.
878
+		return $field;
879
+	}
880
+
881
+
882
+
883
+
884
+	/**
885
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
886
+	 *
887
+	 * @since 4.5.0
888
+	 *
889
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
890
+	 *
891
+	 * @return void
892
+	 */
893
+	public function do_secondary_messenger_hooks($sending_messenger_name)
894
+	{
895
+		return;
896
+	}
897 897
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         $class = get_class($this);
418 418
 
419 419
         // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
420
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422 422
         // all messengers filter
423 423
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
         // messenger specific filter
442 442
         // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
443
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444 444
 
445 445
         // all messengers filter
446 446
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
     {
476 476
         $class = get_class($this);
477 477
 
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
478
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
479 479
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480 480
         return $config;
481 481
     }
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
514 514
         // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515 515
         $event_id = isset($extra['event']) ? $extra['event'] : null;
516 516
 
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
517
+        $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+        $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
519 519
 
520 520
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521 521
         $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
522
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
523 523
         );
524 524
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525 525
             $event_id,
@@ -528,29 +528,29 @@  discard block
 block discarded – undo
528 528
                 'MTP_is_active' => true
529 529
             )
530 530
         );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
531
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
532 532
 
533 533
         // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534 534
         foreach ($global_templates as $mtpgID => $mtpg) {
535 535
             if ($mtpg instanceof EE_Message_Template_Group) {
536 536
                 // verify this message type is supposed to show on this page
537 537
                 $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
538
+                if ( ! $mtp_obj instanceof EE_message_type) {
539 539
                     continue;
540 540
                 }
541 541
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
542
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543 543
                     continue;
544 544
                 }
545 545
                 $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
546
+                $select_values[$mtpgID] = __('Global', 'event_espresso');
547 547
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548 548
                 // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
549
+                if ( ! $mtpg->get('MTP_is_override')) {
550 550
                     // any custom templates for this message type?
551 551
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552 552
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
553
+                        $select_values[$cmtpgID] = $cmtpg->name();
554 554
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555 555
                     }
556 556
                 }
@@ -572,11 +572,11 @@  discard block
 block discarded – undo
572 572
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
573 573
                 $st_args['mt_slug'] = $mtpg->message_type();
574 574
                 $st_args['messenger_slug'] = $this->name;
575
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
575
+                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector');
576 576
                 // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
577
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
577
+                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>';
578 578
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
579
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
579
+                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : '';
580 580
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
581 581
             }
582 582
         }
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      */
604 604
     public function get_template_fields()
605 605
     {
606
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
606
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
607 607
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
608 608
         return $template_fields;
609 609
     }
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
     protected function _set_template_value($item, $value)
621 621
     {
622 622
         if (array_key_exists($item, $this->_template_fields)) {
623
-            $prop = '_' . $item;
624
-            $this->{$prop}= $value;
623
+            $prop = '_'.$item;
624
+            $this->{$prop} = $value;
625 625
         }
626 626
     }
627 627
 
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
                 $message,
682 682
                 $message_type
683 683
             );
684
-            if (! empty($settings)) {
684
+            if ( ! empty($settings)) {
685 685
                 foreach ($settings as $field => $value) {
686 686
                     $this->_set_template_value($field, $value);
687 687
                 }
@@ -689,12 +689,12 @@  discard block
 block discarded – undo
689 689
         }
690 690
 
691 691
         // enqueue preview js so that any links/buttons on the page are disabled.
692
-        if (! $send) {
692
+        if ( ! $send) {
693 693
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
694 694
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
695
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
696
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
695
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
696
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
697
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
698 698
         }
699 699
 
700 700
         return $send ? $this->_send_message() : $this->_preview();
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
         EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
717 717
             __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
718 718
         );
719
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
719
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
720 720
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
721 721
         wp_enqueue_script('ee-messages-preview-js');
722 722
     }
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
         $variation = $message->get_template_pack_variation();
736 736
 
737 737
         // verify we have the required template pack value on the $message object.
738
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
738
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
739 739
             throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
740 740
         }
741 741
 
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 
748 748
         foreach ($template_fields as $template => $value) {
749 749
             if ($template !== 'extra') {
750
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
750
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
751 751
                 $message_template_value = $column_value ? $column_value : null;
752 752
                 $this->_set_template_value($template, $message_template_value);
753 753
             }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
772 772
 
773 773
         // check file exists and is readable
774
-        if (!is_readable($wrapper_template)) {
774
+        if ( ! is_readable($wrapper_template)) {
775 775
             throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
776 776
         }
777 777
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
820 820
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
821 821
         $settings = $Message_Resource_Manager->get_active_messengers_option();
822
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
822
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
823 823
     }
824 824
 
825 825
 
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
837 837
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
838 838
         $existing = $Message_Resource_Manager->get_active_messengers_option();
839
-        $existing[ $this->name ]['test_settings'] = $settings;
839
+        $existing[$this->name]['test_settings'] = $settings;
840 840
         return $Message_Resource_Manager->update_active_messengers_option($existing);
841 841
     }
842 842
 
@@ -853,23 +853,23 @@  discard block
 block discarded – undo
853 853
     public function get_field_label($field)
854 854
     {
855 855
         // first let's see if the field requests is in the top level array.
856
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
857
-            return $this->_template[ $field ]['label'];
856
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
857
+            return $this->_template[$field]['label'];
858 858
         }
859 859
 
860 860
         // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
861
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
862
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
861
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
862
+            return $this->_template_fields['extra'][$field]['main']['label'];
863 863
         }
864 864
 
865 865
         // now it's possible this field may just be existing in any of the extra array items.
866
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
866
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
867 867
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
868
-                if (!is_array($subfields)) {
868
+                if ( ! is_array($subfields)) {
869 869
                     continue;
870 870
                 }
871
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
872
-                    return $subfields[ $field ]['label'];
871
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
872
+                    return $subfields[$field]['label'];
873 873
                 }
874 874
             }
875 875
         }
Please login to merge, or discard this patch.